app/testpmd: add new types to RSS hash commands
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commmands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port X rss reta (size) (mask0,mask1,...)\n"
170                         "    Display the rss redirection table entry indicated"
171                         " by masks on port X. size is used to indicate the"
172                         " hardware supported reta size\n\n"
173
174                         "show port (port_id) rss-hash [key]\n"
175                         "    Display the RSS hash functions and RSS hash key of port\n\n"
176
177                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178                         "    Clear information for port_id, or all.\n\n"
179
180                         "show (rxq|txq) info (port_id) (queue_id)\n"
181                         "    Display information for configured RX/TX queue.\n\n"
182
183                         "show config (rxtx|cores|fwd|txpkts)\n"
184                         "    Display the given configuration.\n\n"
185
186                         "read rxd (port_id) (queue_id) (rxd_id)\n"
187                         "    Display an RX descriptor of a port RX queue.\n\n"
188
189                         "read txd (port_id) (queue_id) (txd_id)\n"
190                         "    Display a TX descriptor of a port TX queue.\n\n"
191
192                         "ddp get list (port_id)\n"
193                         "    Get ddp profile info list\n\n"
194
195                         "ddp get info (profile_path)\n"
196                         "    Get ddp profile information.\n\n"
197
198                         "show vf stats (port_id) (vf_id)\n"
199                         "    Display a VF's statistics.\n\n"
200
201                         "clear vf stats (port_id) (vf_id)\n"
202                         "    Reset a VF's statistics.\n\n"
203
204                         "show port (port_id) pctype mapping\n"
205                         "    Get flow ptype to pctype mapping on a port\n\n"
206
207                         "show port meter stats (port_id) (meter_id) (clear)\n"
208                         "    Get meter stats on a port\n\n"
209
210                         "show fwd stats all\n"
211                         "    Display statistics for all fwd engines.\n\n"
212
213                         "clear fwd stats all\n"
214                         "    Clear statistics for all fwd engines.\n\n"
215
216                         "show port (port_id) rx_offload capabilities\n"
217                         "    List all per queue and per port Rx offloading"
218                         " capabilities of a port\n\n"
219
220                         "show port (port_id) rx_offload configuration\n"
221                         "    List port level and all queue level"
222                         " Rx offloading configuration\n\n"
223
224                         "show port (port_id) tx_offload capabilities\n"
225                         "    List all per queue and per port"
226                         " Tx offloading capabilities of a port\n\n"
227
228                         "show port (port_id) tx_offload configuration\n"
229                         "    List port level and all queue level"
230                         " Tx offloading configuration\n\n"
231
232                         "show port (port_id) tx_metadata\n"
233                         "    Show Tx metadata value set"
234                         " for a specific port\n\n"
235
236                         "show port (port_id) ptypes\n"
237                         "    Show port supported ptypes"
238                         " for a specific port\n\n"
239
240                         "show device info (<identifier>|all)"
241                         "       Show general information about devices probed.\n\n"
242
243                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244                         "       Show status of rx|tx descriptor.\n\n"
245
246                         "show port (port_id) macs|mcast_macs"
247                         "       Display list of mac addresses added to port.\n\n"
248                 );
249         }
250
251         if (show_all || !strcmp(res->section, "config")) {
252                 cmdline_printf(
253                         cl,
254                         "\n"
255                         "Configuration:\n"
256                         "--------------\n"
257                         "Configuration changes only become active when"
258                         " forwarding is started/restarted.\n\n"
259
260                         "set default\n"
261                         "    Reset forwarding to the default configuration.\n\n"
262
263                         "set verbose (level)\n"
264                         "    Set the debug verbosity level X.\n\n"
265
266                         "set log global|(type) (level)\n"
267                         "    Set the log level.\n\n"
268
269                         "set nbport (num)\n"
270                         "    Set number of ports.\n\n"
271
272                         "set nbcore (num)\n"
273                         "    Set number of cores.\n\n"
274
275                         "set coremask (mask)\n"
276                         "    Set the forwarding cores hexadecimal mask.\n\n"
277
278                         "set portmask (mask)\n"
279                         "    Set the forwarding ports hexadecimal mask.\n\n"
280
281                         "set burst (num)\n"
282                         "    Set number of packets per burst.\n\n"
283
284                         "set burst tx delay (microseconds) retry (num)\n"
285                         "    Set the transmit delay time and number of retries,"
286                         " effective when retry is enabled.\n\n"
287
288                         "set txpkts (x[,y]*)\n"
289                         "    Set the length of each segment of TXONLY"
290                         " and optionally CSUM packets.\n\n"
291
292                         "set txsplit (off|on|rand)\n"
293                         "    Set the split policy for the TX packets."
294                         " Right now only applicable for CSUM and TXONLY"
295                         " modes\n\n"
296
297                         "set corelist (x[,y]*)\n"
298                         "    Set the list of forwarding cores.\n\n"
299
300                         "set portlist (x[,y]*)\n"
301                         "    Set the list of forwarding ports.\n\n"
302
303                         "set port setup on (iterator|event)\n"
304                         "    Select how attached port is retrieved for setup.\n\n"
305
306                         "set tx loopback (port_id) (on|off)\n"
307                         "    Enable or disable tx loopback.\n\n"
308
309                         "set all queues drop (port_id) (on|off)\n"
310                         "    Set drop enable bit for all queues.\n\n"
311
312                         "set vf split drop (port_id) (vf_id) (on|off)\n"
313                         "    Set split drop enable bit for a VF from the PF.\n\n"
314
315                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316                         "    Set MAC antispoof for a VF from the PF.\n\n"
317
318                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319                         "    Enable MACsec offload.\n\n"
320
321                         "set macsec offload (port_id) off\n"
322                         "    Disable MACsec offload.\n\n"
323
324                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325                         "    Configure MACsec secure connection (SC).\n\n"
326
327                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328                         "    Configure MACsec secure association (SA).\n\n"
329
330                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
331                         "    Set VF broadcast for a VF from the PF.\n\n"
332
333                         "vlan set stripq (on|off) (port_id,queue_id)\n"
334                         "    Set the VLAN strip for a queue on a port.\n\n"
335
336                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338
339                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340                         "    Set VLAN insert for a VF from the PF.\n\n"
341
342                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343                         "    Set VLAN antispoof for a VF from the PF.\n\n"
344
345                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
346                         "    Set VLAN tag for a VF from the PF.\n\n"
347
348                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349                         "    Set a VF's max bandwidth(Mbps).\n\n"
350
351                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353
354                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356
357                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
358                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
359
360                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362
363                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
365
366                         "vlan set (inner|outer) tpid (value) (port_id)\n"
367                         "    Set the VLAN TPID for Packet Filtering on"
368                         " a port\n\n"
369
370                         "rx_vlan add (vlan_id|all) (port_id)\n"
371                         "    Add a vlan_id, or all identifiers, to the set"
372                         " of VLAN identifiers filtered by port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id|all) (port_id)\n"
375                         "    Remove a vlan_id, or all identifiers, from the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379                         "    Add a vlan_id, to the set of VLAN identifiers"
380                         "filtered for VF(s) from port_id.\n\n"
381
382                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Remove a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   add a tunnel filter of a port.\n\n"
390
391                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394                         "   remove a tunnel filter of a port.\n\n"
395
396                         "rx_vxlan_port add (udp_port) (port_id)\n"
397                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
398
399                         "rx_vxlan_port rm (udp_port) (port_id)\n"
400                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
401
402                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
404                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405
406                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
407                         "    Set port based TX VLAN insertion.\n\n"
408
409                         "tx_vlan reset (port_id)\n"
410                         "    Disable hardware insertion of a VLAN header in"
411                         " packets sent on a port.\n\n"
412
413                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414                         "    Select hardware or software calculation of the"
415                         " checksum when transmitting a packet using the"
416                         " csum forward engine.\n"
417                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
418                         "    outer-ip concerns the outer IP layer in"
419                         "    outer-udp concerns the outer UDP layer in"
420                         " case the packet is recognized as a tunnel packet by"
421                         " the forward engine (vxlan, gre and ipip are supported)\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "csum parse-tunnel (on|off) (tx_port_id)\n"
425                         "    If disabled, treat tunnel packets as non-tunneled"
426                         " packets (treat inner headers as payload). The port\n"
427                         "    argument is the port used for TX in csum forward"
428                         " engine.\n\n"
429
430                         "csum show (port_id)\n"
431                         "    Display tx checksum offload configuration\n\n"
432
433                         "tso set (segsize) (portid)\n"
434                         "    Enable TCP Segmentation Offload in csum forward"
435                         " engine.\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "tso show (portid)"
439                         "    Display the status of TCP Segmentation Offload.\n\n"
440
441                         "set port (port_id) gro on|off\n"
442                         "    Enable or disable Generic Receive Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "show port (port_id) gro\n"
446                         "    Display GRO configuration.\n\n"
447
448                         "set gro flush (cycles)\n"
449                         "    Set the cycle to flush GROed packets from"
450                         " reassembly tables.\n\n"
451
452                         "set port (port_id) gso (on|off)"
453                         "    Enable or disable Generic Segmentation Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "set gso segsz (length)\n"
457                         "    Set max packet length for output GSO segments,"
458                         " including packet header and payload.\n\n"
459
460                         "show port (port_id) gso\n"
461                         "    Show GSO configuration.\n\n"
462
463                         "set fwd (%s)\n"
464                         "    Set packet forwarding mode.\n\n"
465
466                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467                         "    Add a MAC address on port_id.\n\n"
468
469                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470                         "    Remove a MAC address from port_id.\n\n"
471
472                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473                         "    Set the default MAC address for port_id.\n\n"
474
475                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476                         "    Add a MAC address for a VF on the port.\n\n"
477
478                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479                         "    Set the MAC address for a VF from the PF.\n\n"
480
481                         "set eth-peer (port_id) (peer_addr)\n"
482                         "    set the peer address for certain port.\n\n"
483
484                         "set port (port_id) uta (mac_address|all) (on|off)\n"
485                         "    Add/Remove a or all unicast hash filter(s)"
486                         "from port X.\n\n"
487
488                         "set promisc (port_id|all) (on|off)\n"
489                         "    Set the promiscuous mode on port_id, or all.\n\n"
490
491                         "set allmulti (port_id|all) (on|off)\n"
492                         "    Set the allmulti mode on port_id, or all.\n\n"
493
494                         "set vf promisc (port_id) (vf_id) (on|off)\n"
495                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
496
497                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
498                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
499
500                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502                         " (on|off) autoneg (on|off) (port_id)\n"
503                         "set flow_ctrl rx (on|off) (portid)\n"
504                         "set flow_ctrl tx (on|off) (portid)\n"
505                         "set flow_ctrl high_water (high_water) (portid)\n"
506                         "set flow_ctrl low_water (low_water) (portid)\n"
507                         "set flow_ctrl pause_time (pause_time) (portid)\n"
508                         "set flow_ctrl send_xon (send_xon) (portid)\n"
509                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510                         "set flow_ctrl autoneg (on|off) (port_id)\n"
511                         "    Set the link flow control parameter on a port.\n\n"
512
513                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (priority) (port_id)\n"
515                         "    Set the priority flow control parameter on a"
516                         " port.\n\n"
517
518                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
520                         " queue on port.\n"
521                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522                         " on port 0 to mapping 5.\n\n"
523
524                         "set xstats-hide-zero on|off\n"
525                         "    Set the option to hide the zero values"
526                         " for xstats display.\n"
527
528                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
529                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
530
531                         "set port (port_id) vf (vf_id) (mac_addr)"
532                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533                         "   Add/Remove unicast or multicast MAC addr filter"
534                         " for a VF.\n\n"
535
536                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537                         "|MPE) (on|off)\n"
538                         "    AUPE:accepts untagged VLAN;"
539                         "ROPE:accept unicast hash\n\n"
540                         "    BAM:accepts broadcast packets;"
541                         "MPE:accepts all multicast packets\n\n"
542                         "    Enable/Disable a VF receive mode of a port\n\n"
543
544                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
545                         "    Set rate limit for a queue of a port\n\n"
546
547                         "set port (port_id) vf (vf_id) rate (rate_num) "
548                         "queue_mask (queue_mask_value)\n"
549                         "    Set rate limit for queues in VF of a port\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554                         "   Set pool or vlan type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
557                         " to pool 0.\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (uplink-mirror|downlink-mirror) dst-pool"
561                         " (pool_id) (on|off)\n"
562                         "   Set uplink or downlink type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564                         " 0 on' enable mirror income traffic to pool 0.\n\n"
565
566                         "reset port (port_id) mirror-rule (rule_id)\n"
567                         "   Reset a mirror rule.\n\n"
568
569                         "set flush_rx (on|off)\n"
570                         "   Flush (default) or don't flush RX streams before"
571                         " forwarding. Mainly used with PCAP drivers.\n\n"
572
573                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the bypass mode for the lowest port on bypass enabled"
575                         " NIC.\n\n"
576
577                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
578                         "mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the event required to initiate specified bypass mode for"
580                         " the lowest port on a bypass enabled NIC where:\n"
581                         "       timeout   = enable bypass after watchdog timeout.\n"
582                         "       os_on     = enable bypass when OS/board is powered on.\n"
583                         "       os_off    = enable bypass when OS/board is powered off.\n"
584                         "       power_on  = enable bypass when power supply is turned on.\n"
585                         "       power_off = enable bypass when power supply is turned off."
586                         "\n\n"
587
588                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589                         "   Set the bypass watchdog timeout to 'n' seconds"
590                         " where 0 = instant.\n\n"
591
592                         "show bypass config (port_id)\n"
593                         "   Show the bypass configuration for a bypass enabled NIC"
594                         " using the lowest port on the NIC.\n\n"
595
596 #ifdef RTE_LIBRTE_PMD_BOND
597                         "create bonded device (mode) (socket)\n"
598                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
599
600                         "add bonding slave (slave_id) (port_id)\n"
601                         "       Add a slave device to a bonded device.\n\n"
602
603                         "remove bonding slave (slave_id) (port_id)\n"
604                         "       Remove a slave device from a bonded device.\n\n"
605
606                         "set bonding mode (value) (port_id)\n"
607                         "       Set the bonding mode on a bonded device.\n\n"
608
609                         "set bonding primary (slave_id) (port_id)\n"
610                         "       Set the primary slave for a bonded device.\n\n"
611
612                         "show bonding config (port_id)\n"
613                         "       Show the bonding config for port_id.\n\n"
614
615                         "set bonding mac_addr (port_id) (address)\n"
616                         "       Set the MAC address of a bonded device.\n\n"
617
618                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
620
621                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
623
624                         "set bonding mon_period (port_id) (value)\n"
625                         "       Set the bonding link status monitoring polling period in ms.\n\n"
626
627                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
629
630 #endif
631                         "set link-up port (port_id)\n"
632                         "       Set link up for a port.\n\n"
633
634                         "set link-down port (port_id)\n"
635                         "       Set link down for a port.\n\n"
636
637                         "E-tag set insertion on port-tag-id (value)"
638                         " port (port_id) vf (vf_id)\n"
639                         "    Enable E-tag insertion for a VF on a port\n\n"
640
641                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
642                         "    Disable E-tag insertion for a VF on a port\n\n"
643
644                         "E-tag set stripping (on|off) port (port_id)\n"
645                         "    Enable/disable E-tag stripping on a port\n\n"
646
647                         "E-tag set forwarding (on|off) port (port_id)\n"
648                         "    Enable/disable E-tag based forwarding"
649                         " on a port\n\n"
650
651                         "E-tag set filter add e-tag-id (value) dst-pool"
652                         " (pool_id) port (port_id)\n"
653                         "    Add an E-tag forwarding filter on a port\n\n"
654
655                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
656                         "    Delete an E-tag forwarding filter on a port\n\n"
657
658                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
659                         "    Load a profile package on a port\n\n"
660
661                         "ddp del (port_id) (backup_profile_path)\n"
662                         "    Delete a profile package from a port\n\n"
663
664                         "ptype mapping get (port_id) (valid_only)\n"
665                         "    Get ptype mapping on a port\n\n"
666
667                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668                         "    Replace target with the pkt_type in ptype mapping\n\n"
669
670                         "ptype mapping reset (port_id)\n"
671                         "    Reset ptype mapping on a port\n\n"
672
673                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674                         "    Update a ptype mapping item on a port\n\n"
675
676                         "set port (port_id) ptype_mask (ptype_mask)\n"
677                         "    set packet types classification for a specific port\n\n"
678
679                         "set port (port_id) queue-region region_id (value) "
680                         "queue_start_index (value) queue_num (value)\n"
681                         "    Set a queue region on a port\n\n"
682
683                         "set port (port_id) queue-region region_id (value) "
684                         "flowtype (value)\n"
685                         "    Set a flowtype region index on a port\n\n"
686
687                         "set port (port_id) queue-region UP (value) region_id (value)\n"
688                         "    Set the mapping of User Priority to "
689                         "queue region on a port\n\n"
690
691                         "set port (port_id) queue-region flush (on|off)\n"
692                         "    flush all queue region related configuration\n\n"
693
694                         "show port meter cap (port_id)\n"
695                         "    Show port meter capability information\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712                         "(dscp_tbl_entry63)]\n"
713                         "    meter create\n\n"
714
715                         "enable port meter (port_id) (mtr_id)\n"
716                         "    meter enable\n\n"
717
718                         "disable port meter (port_id) (mtr_id)\n"
719                         "    meter disable\n\n"
720
721                         "del port meter (port_id) (mtr_id)\n"
722                         "    meter delete\n\n"
723
724                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
725                         "    meter update meter profile\n\n"
726
727                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729                         "    update meter dscp table entries\n\n"
730
731                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732                         "(action0) [(action1) (action2)]\n"
733                         "    meter update policer action\n\n"
734
735                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736                         "    meter update stats\n\n"
737
738                         "show port (port_id) queue-region\n"
739                         "    show all queue region related configuration info\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
773                         " duplex (half|full|auto)\n"
774                         "    Set speed and duplex for all ports or port_id\n\n"
775
776                         "port config (port_id|all) loopback (mode)\n"
777                         "    Set loopback mode for all ports or port_id\n\n"
778
779                         "port config all (rxq|txq|rxd|txd) (value)\n"
780                         "    Set number for rxq/txq/rxd/txd.\n\n"
781
782                         "port config all max-pkt-len (value)\n"
783                         "    Set the max packet length.\n\n"
784
785                         "port config all max-lro-pkt-size (value)\n"
786                         "    Set the max LRO aggregated packet size.\n\n"
787
788                         "port config all drop-en (on|off)\n"
789                         "    Enable or disable packet drop on all RX queues of all ports when no "
790                         "receive buffers available.\n\n"
791
792                         "port config all rss (all|default|ip|tcp|udp|sctp|"
793                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794                         "    Set the RSS mode.\n\n"
795
796                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797                         "    Set the RSS redirection table.\n\n"
798
799                         "port config (port_id) dcb vt (on|off) (traffic_class)"
800                         " pfc (on|off)\n"
801                         "    Set the DCB mode.\n\n"
802
803                         "port config all burst (value)\n"
804                         "    Set the number of packets per burst.\n\n"
805
806                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807                         " (value)\n"
808                         "    Set the ring prefetch/host/writeback threshold"
809                         " for tx/rx queue.\n\n"
810
811                         "port config all (txfreet|txrst|rxfreet) (value)\n"
812                         "    Set free threshold for rx/tx, or set"
813                         " tx rs bit threshold.\n\n"
814                         "port config mtu X value\n"
815                         "    Set the MTU of port X to a given value\n\n"
816
817                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818                         "    Set a rx/tx queue's ring size configuration, the new"
819                         " value will take effect after command that (re-)start the port"
820                         " or command that setup the specific queue\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823                         "    Start/stop a rx/tx queue of port X. Only take effect"
824                         " when port X is started\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
828                         " take effect when port X is stopped.\n\n"
829
830                         "port (port_id) (rxq|txq) (queue_id) setup\n"
831                         "    Setup a rx/tx queue of port X.\n\n"
832
833                         "port config (port_id|all) l2-tunnel E-tag ether-type"
834                         " (value)\n"
835                         "    Set the value of E-tag ether-type.\n\n"
836
837                         "port config (port_id|all) l2-tunnel E-tag"
838                         " (enable|disable)\n"
839                         "    Enable/disable the E-tag support.\n\n"
840
841                         "port config (port_id) pctype mapping reset\n"
842                         "    Reset flow type to pctype mapping on a port\n\n"
843
844                         "port config (port_id) pctype mapping update"
845                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846                         "    Update a flow type to pctype mapping item on a port\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
850                         " (field_idx)\n"
851                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852
853                         "port config (port_id) pctype (pctype_id) hash_inset|"
854                         "fdir_inset|fdir_flx_inset clear all"
855                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856
857                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
859
860                         "port config <port_id> rx_offload vlan_strip|"
861                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862                         "outer_ipv4_cksum|macsec_strip|header_split|"
863                         "vlan_filter|vlan_extend|jumbo_frame|"
864                         "scatter|timestamp|security|keep_crc on|off\n"
865                         "     Enable or disable a per port Rx offloading"
866                         " on all Rx queues of a port\n\n"
867
868                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|"
872                         "scatter|timestamp|security|keep_crc on|off\n"
873                         "    Enable or disable a per queue Rx offloading"
874                         " only on a specific Rx queue\n\n"
875
876                         "port config (port_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881                         "security on|off\n"
882                         "    Enable or disable a per port Tx offloading"
883                         " on all Tx queues of a port\n\n"
884
885                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
886                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
890                         " on|off\n"
891                         "    Enable or disable a per queue Tx offloading"
892                         " only on a specific Tx queue\n\n"
893
894                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895                         "    Load an eBPF program as a callback"
896                         " for particular RX/TX queue\n\n"
897
898                         "bpf-unload rx|tx (port) (queue)\n"
899                         "    Unload previously loaded eBPF program"
900                         " for particular RX/TX queue\n\n"
901
902                         "port config (port_id) tx_metadata (value)\n"
903                         "    Set Tx metadata value per port. Testpmd will add this value"
904                         " to any Tx packet sent from this port\n\n"
905
906                         "port config (port_id) dynf (name) set|clear\n"
907                         "    Register a dynf and Set/clear this flag on Tx. "
908                         "Testpmd will set this value to any Tx packet "
909                         "sent from this port\n\n"
910                 );
911         }
912
913         if (show_all || !strcmp(res->section, "registers")) {
914
915                 cmdline_printf(
916                         cl,
917                         "\n"
918                         "Registers:\n"
919                         "----------\n\n"
920
921                         "read reg (port_id) (address)\n"
922                         "    Display value of a port register.\n\n"
923
924                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
925                         "    Display a port register bit field.\n\n"
926
927                         "read regbit (port_id) (address) (bit_x)\n"
928                         "    Display a single port register bit.\n\n"
929
930                         "write reg (port_id) (address) (value)\n"
931                         "    Set value of a port register.\n\n"
932
933                         "write regfield (port_id) (address) (bit_x) (bit_y)"
934                         " (value)\n"
935                         "    Set bit field of a port register.\n\n"
936
937                         "write regbit (port_id) (address) (bit_x) (value)\n"
938                         "    Set single bit value of a port register.\n\n"
939                 );
940         }
941         if (show_all || !strcmp(res->section, "filters")) {
942
943                 cmdline_printf(
944                         cl,
945                         "\n"
946                         "filters:\n"
947                         "--------\n\n"
948
949                         "ethertype_filter (port_id) (add|del)"
950                         " (mac_addr|mac_ignr) (mac_address) ethertype"
951                         " (ether_type) (drop|fwd) queue (queue_id)\n"
952                         "    Add/Del an ethertype filter.\n\n"
953
954                         "2tuple_filter (port_id) (add|del)"
955                         " dst_port (dst_port_value) protocol (protocol_value)"
956                         " mask (mask_value) tcp_flags (tcp_flags_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a 2tuple filter.\n\n"
959
960                         "5tuple_filter (port_id) (add|del)"
961                         " dst_ip (dst_address) src_ip (src_address)"
962                         " dst_port (dst_port_value) src_port (src_port_value)"
963                         " protocol (protocol_value)"
964                         " mask (mask_value) tcp_flags (tcp_flags_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a 5tuple filter.\n\n"
967
968                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969                         "    Add/Del syn filter.\n\n"
970
971                         "flex_filter (port_id) (add|del) len (len_value)"
972                         " bytes (bytes_value) mask (mask_value)"
973                         " priority (prio_value) queue (queue_id)\n"
974                         "    Add/Del a flex filter.\n\n"
975
976                         "flow_director_filter (port_id) mode IP (add|del|update)"
977                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978                         " src (src_ip_address) dst (dst_ip_address)"
979                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
980                         " vlan (vlan_value) flexbytes (flexbytes_value)"
981                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982                         " fd_id (fd_id_value)\n"
983                         "    Add/Del an IP type flow director filter.\n\n"
984
985                         "flow_director_filter (port_id) mode IP (add|del|update)"
986                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987                         " src (src_ip_address) (src_port)"
988                         " dst (dst_ip_address) (dst_port)"
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value) flexbytes (flexbytes_value)"
991                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992                         " fd_id (fd_id_value)\n"
993                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-sctp|ipv6-sctp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tag (verification_tag) "
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a SCTP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow l2_payload ether (ethertype)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a l2 payload type flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013                         " mac (mac_address) vlan (vlan_value)"
1014                         " flexbytes (flexbytes_value) (drop|fwd)"
1015                         " queue (queue_id) fd_id (fd_id_value)\n"
1016                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019                         " mac (mac_address) vlan (vlan_value)"
1020                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a Tunnel flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode raw (add|del|update)"
1026                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1027                         " fd_id (fd_id_value) packet (packet file name)\n"
1028                         "    Add/Del a raw type flow director filter.\n\n"
1029
1030                         "flush_flow_director (port_id)\n"
1031                         "    Flush all flow director entries of a device.\n\n"
1032
1033                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1035                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036                         "    Set flow director IP mask.\n\n"
1037
1038                         "flow_director_mask (port_id) mode MAC-VLAN"
1039                         " vlan (vlan_value)\n"
1040                         "    Set flow director MAC-VLAN mask.\n\n"
1041
1042                         "flow_director_mask (port_id) mode Tunnel"
1043                         " vlan (vlan_value) mac (mac_value)"
1044                         " tunnel-type (tunnel_type_value)"
1045                         " tunnel-id (tunnel_id_value)\n"
1046                         "    Set flow director Tunnel mask.\n\n"
1047
1048                         "flow_director_flex_mask (port_id)"
1049                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051                         " (mask)\n"
1052                         "    Configure mask of flex payload.\n\n"
1053
1054                         "flow_director_flex_payload (port_id)"
1055                         " (raw|l2|l3|l4) (config)\n"
1056                         "    Configure flex payload selection.\n\n"
1057
1058                         "get_sym_hash_ena_per_port (port_id)\n"
1059                         "    get symmetric hash enable configuration per port.\n\n"
1060
1061                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062                         "    set symmetric hash enable configuration per port"
1063                         " to enable or disable.\n\n"
1064
1065                         "get_hash_global_config (port_id)\n"
1066                         "    Get the global configurations of hash filters.\n\n"
1067
1068                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071                         " (enable|disable)\n"
1072                         "    Set the global configurations of hash filters.\n\n"
1073
1074                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1080                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1081                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083                         "fld-8th|none) (select|add)\n"
1084                         "    Set the input set for hash.\n\n"
1085
1086                         "set_fdir_input_set (port_id) "
1087                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1093                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094                         " (select|add)\n"
1095                         "    Set the input set for FDir.\n\n"
1096
1097                         "flow validate {port_id}"
1098                         " [group {group_id}] [priority {level}]"
1099                         " [ingress] [egress]"
1100                         " pattern {item} [/ {item} [...]] / end"
1101                         " actions {action} [/ {action} [...]] / end\n"
1102                         "    Check whether a flow rule can be created.\n\n"
1103
1104                         "flow create {port_id}"
1105                         " [group {group_id}] [priority {level}]"
1106                         " [ingress] [egress]"
1107                         " pattern {item} [/ {item} [...]] / end"
1108                         " actions {action} [/ {action} [...]] / end\n"
1109                         "    Create a flow rule.\n\n"
1110
1111                         "flow destroy {port_id} rule {rule_id} [...]\n"
1112                         "    Destroy specific flow rules.\n\n"
1113
1114                         "flow flush {port_id}\n"
1115                         "    Destroy all flow rules.\n\n"
1116
1117                         "flow query {port_id} {rule_id} {action}\n"
1118                         "    Query an existing flow rule.\n\n"
1119
1120                         "flow list {port_id} [group {group_id}] [...]\n"
1121                         "    List existing flow rules sorted by priority,"
1122                         " filtered by group identifiers.\n\n"
1123
1124                         "flow isolate {port_id} {boolean}\n"
1125                         "    Restrict ingress traffic to the defined"
1126                         " flow rules\n\n"
1127
1128                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1129                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1130                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1131                         "       Configure the VXLAN encapsulation for flows.\n\n"
1132
1133                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1134                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1135                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1136                         " eth-dst (eth-dst)\n"
1137                         "       Configure the VXLAN encapsulation for flows.\n\n"
1138
1139                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1140                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1141                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1142                         " eth-dst (eth-dst)\n"
1143                         "       Configure the VXLAN encapsulation for flows.\n\n"
1144
1145                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1146                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1147                         " (eth-dst)\n"
1148                         "       Configure the NVGRE encapsulation for flows.\n\n"
1149
1150                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1151                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1152                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1153                         "       Configure the NVGRE encapsulation for flows.\n\n"
1154
1155                         "set raw_encap {flow items}\n"
1156                         "       Configure the encapsulation with raw data.\n\n"
1157
1158                         "set raw_decap {flow items}\n"
1159                         "       Configure the decapsulation with raw data.\n\n"
1160
1161                 );
1162         }
1163
1164         if (show_all || !strcmp(res->section, "traffic_management")) {
1165                 cmdline_printf(
1166                         cl,
1167                         "\n"
1168                         "Traffic Management:\n"
1169                         "--------------\n"
1170                         "show port tm cap (port_id)\n"
1171                         "       Display the port TM capability.\n\n"
1172
1173                         "show port tm level cap (port_id) (level_id)\n"
1174                         "       Display the port TM hierarchical level capability.\n\n"
1175
1176                         "show port tm node cap (port_id) (node_id)\n"
1177                         "       Display the port TM node capability.\n\n"
1178
1179                         "show port tm node type (port_id) (node_id)\n"
1180                         "       Display the port TM node type.\n\n"
1181
1182                         "show port tm node stats (port_id) (node_id) (clear)\n"
1183                         "       Display the port TM node stats.\n\n"
1184
1185 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1186                         "set port tm hierarchy default (port_id)\n"
1187                         "       Set default traffic Management hierarchy on a port\n\n"
1188 #endif
1189
1190                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1191                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1192                         " (packet_length_adjust)\n"
1193                         "       Add port tm node private shaper profile.\n\n"
1194
1195                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1196                         "       Delete port tm node private shaper profile.\n\n"
1197
1198                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1199                         " (shaper_profile_id)\n"
1200                         "       Add/update port tm node shared shaper.\n\n"
1201
1202                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1203                         "       Delete port tm node shared shaper.\n\n"
1204
1205                         "set port tm node shaper profile (port_id) (node_id)"
1206                         " (shaper_profile_id)\n"
1207                         "       Set port tm node shaper profile.\n\n"
1208
1209                         "add port tm node wred profile (port_id) (wred_profile_id)"
1210                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1211                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1212                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1213                         "       Add port tm node wred profile.\n\n"
1214
1215                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1216                         "       Delete port tm node wred profile.\n\n"
1217
1218                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1219                         " (priority) (weight) (level_id) (shaper_profile_id)"
1220                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1221                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1222                         "       Add port tm nonleaf node.\n\n"
1223
1224                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1225                         " (priority) (weight) (level_id) (shaper_profile_id)"
1226                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1227                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1228                         "       Add port tm leaf node.\n\n"
1229
1230                         "del port tm node (port_id) (node_id)\n"
1231                         "       Delete port tm node.\n\n"
1232
1233                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1234                         " (priority) (weight)\n"
1235                         "       Set port tm node parent.\n\n"
1236
1237                         "suspend port tm node (port_id) (node_id)"
1238                         "       Suspend tm node.\n\n"
1239
1240                         "resume port tm node (port_id) (node_id)"
1241                         "       Resume tm node.\n\n"
1242
1243                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1244                         "       Commit tm hierarchy.\n\n"
1245
1246                         "set port tm mark ip_ecn (port) (green) (yellow)"
1247                         " (red)\n"
1248                         "    Enables/Disables the traffic management marking"
1249                         " for IP ECN (Explicit Congestion Notification)"
1250                         " packets on a given port\n\n"
1251
1252                         "set port tm mark ip_dscp (port) (green) (yellow)"
1253                         " (red)\n"
1254                         "    Enables/Disables the traffic management marking"
1255                         " on the port for IP dscp packets\n\n"
1256
1257                         "set port tm mark vlan_dei (port) (green) (yellow)"
1258                         " (red)\n"
1259                         "    Enables/Disables the traffic management marking"
1260                         " on the port for VLAN packets with DEI enabled\n\n"
1261                 );
1262         }
1263
1264         if (show_all || !strcmp(res->section, "devices")) {
1265                 cmdline_printf(
1266                         cl,
1267                         "\n"
1268                         "Device Operations:\n"
1269                         "--------------\n"
1270                         "device detach (identifier)\n"
1271                         "       Detach device by identifier.\n\n"
1272                 );
1273         }
1274
1275 }
1276
1277 cmdline_parse_token_string_t cmd_help_long_help =
1278         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1279
1280 cmdline_parse_token_string_t cmd_help_long_section =
1281         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1282                         "all#control#display#config#"
1283                         "ports#registers#filters#traffic_management#devices");
1284
1285 cmdline_parse_inst_t cmd_help_long = {
1286         .f = cmd_help_long_parsed,
1287         .data = NULL,
1288         .help_str = "help all|control|display|config|ports|register|"
1289                 "filters|traffic_management|devices: "
1290                 "Show help",
1291         .tokens = {
1292                 (void *)&cmd_help_long_help,
1293                 (void *)&cmd_help_long_section,
1294                 NULL,
1295         },
1296 };
1297
1298
1299 /* *** start/stop/close all ports *** */
1300 struct cmd_operate_port_result {
1301         cmdline_fixed_string_t keyword;
1302         cmdline_fixed_string_t name;
1303         cmdline_fixed_string_t value;
1304 };
1305
1306 static void cmd_operate_port_parsed(void *parsed_result,
1307                                 __rte_unused struct cmdline *cl,
1308                                 __rte_unused void *data)
1309 {
1310         struct cmd_operate_port_result *res = parsed_result;
1311
1312         if (!strcmp(res->name, "start"))
1313                 start_port(RTE_PORT_ALL);
1314         else if (!strcmp(res->name, "stop"))
1315                 stop_port(RTE_PORT_ALL);
1316         else if (!strcmp(res->name, "close"))
1317                 close_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "reset"))
1319                 reset_port(RTE_PORT_ALL);
1320         else
1321                 printf("Unknown parameter\n");
1322 }
1323
1324 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1325         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1326                                                                 "port");
1327 cmdline_parse_token_string_t cmd_operate_port_all_port =
1328         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1329                                                 "start#stop#close#reset");
1330 cmdline_parse_token_string_t cmd_operate_port_all_all =
1331         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1332
1333 cmdline_parse_inst_t cmd_operate_port = {
1334         .f = cmd_operate_port_parsed,
1335         .data = NULL,
1336         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1337         .tokens = {
1338                 (void *)&cmd_operate_port_all_cmd,
1339                 (void *)&cmd_operate_port_all_port,
1340                 (void *)&cmd_operate_port_all_all,
1341                 NULL,
1342         },
1343 };
1344
1345 /* *** start/stop/close specific port *** */
1346 struct cmd_operate_specific_port_result {
1347         cmdline_fixed_string_t keyword;
1348         cmdline_fixed_string_t name;
1349         uint8_t value;
1350 };
1351
1352 static void cmd_operate_specific_port_parsed(void *parsed_result,
1353                         __rte_unused struct cmdline *cl,
1354                                 __rte_unused void *data)
1355 {
1356         struct cmd_operate_specific_port_result *res = parsed_result;
1357
1358         if (!strcmp(res->name, "start"))
1359                 start_port(res->value);
1360         else if (!strcmp(res->name, "stop"))
1361                 stop_port(res->value);
1362         else if (!strcmp(res->name, "close"))
1363                 close_port(res->value);
1364         else if (!strcmp(res->name, "reset"))
1365                 reset_port(res->value);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1372                                                         keyword, "port");
1373 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1375                                                 name, "start#stop#close#reset");
1376 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1377         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1378                                                         value, UINT8);
1379
1380 cmdline_parse_inst_t cmd_operate_specific_port = {
1381         .f = cmd_operate_specific_port_parsed,
1382         .data = NULL,
1383         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1384         .tokens = {
1385                 (void *)&cmd_operate_specific_port_cmd,
1386                 (void *)&cmd_operate_specific_port_port,
1387                 (void *)&cmd_operate_specific_port_id,
1388                 NULL,
1389         },
1390 };
1391
1392 /* *** enable port setup (after attach) via iterator or event *** */
1393 struct cmd_set_port_setup_on_result {
1394         cmdline_fixed_string_t set;
1395         cmdline_fixed_string_t port;
1396         cmdline_fixed_string_t setup;
1397         cmdline_fixed_string_t on;
1398         cmdline_fixed_string_t mode;
1399 };
1400
1401 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1402                                 __rte_unused struct cmdline *cl,
1403                                 __rte_unused void *data)
1404 {
1405         struct cmd_set_port_setup_on_result *res = parsed_result;
1406
1407         if (strcmp(res->mode, "event") == 0)
1408                 setup_on_probe_event = true;
1409         else if (strcmp(res->mode, "iterator") == 0)
1410                 setup_on_probe_event = false;
1411         else
1412                 printf("Unknown mode\n");
1413 }
1414
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         set, "set");
1418 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1419         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1420                         port, "port");
1421 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1422         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1423                         setup, "setup");
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1425         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426                         on, "on");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1428         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429                         mode, "iterator#event");
1430
1431 cmdline_parse_inst_t cmd_set_port_setup_on = {
1432         .f = cmd_set_port_setup_on_parsed,
1433         .data = NULL,
1434         .help_str = "set port setup on iterator|event",
1435         .tokens = {
1436                 (void *)&cmd_set_port_setup_on_set,
1437                 (void *)&cmd_set_port_setup_on_port,
1438                 (void *)&cmd_set_port_setup_on_setup,
1439                 (void *)&cmd_set_port_setup_on_on,
1440                 (void *)&cmd_set_port_setup_on_mode,
1441                 NULL,
1442         },
1443 };
1444
1445 /* *** attach a specified port *** */
1446 struct cmd_operate_attach_port_result {
1447         cmdline_fixed_string_t port;
1448         cmdline_fixed_string_t keyword;
1449         cmdline_multi_string_t identifier;
1450 };
1451
1452 static void cmd_operate_attach_port_parsed(void *parsed_result,
1453                                 __rte_unused struct cmdline *cl,
1454                                 __rte_unused void *data)
1455 {
1456         struct cmd_operate_attach_port_result *res = parsed_result;
1457
1458         if (!strcmp(res->keyword, "attach"))
1459                 attach_port(res->identifier);
1460         else
1461                 printf("Unknown parameter\n");
1462 }
1463
1464 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1465         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1466                         port, "port");
1467 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1468         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1469                         keyword, "attach");
1470 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1471         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1472                         identifier, TOKEN_STRING_MULTI);
1473
1474 cmdline_parse_inst_t cmd_operate_attach_port = {
1475         .f = cmd_operate_attach_port_parsed,
1476         .data = NULL,
1477         .help_str = "port attach <identifier>: "
1478                 "(identifier: pci address or virtual dev name)",
1479         .tokens = {
1480                 (void *)&cmd_operate_attach_port_port,
1481                 (void *)&cmd_operate_attach_port_keyword,
1482                 (void *)&cmd_operate_attach_port_identifier,
1483                 NULL,
1484         },
1485 };
1486
1487 /* *** detach a specified port *** */
1488 struct cmd_operate_detach_port_result {
1489         cmdline_fixed_string_t port;
1490         cmdline_fixed_string_t keyword;
1491         portid_t port_id;
1492 };
1493
1494 static void cmd_operate_detach_port_parsed(void *parsed_result,
1495                                 __rte_unused struct cmdline *cl,
1496                                 __rte_unused void *data)
1497 {
1498         struct cmd_operate_detach_port_result *res = parsed_result;
1499
1500         if (!strcmp(res->keyword, "detach")) {
1501                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1502                 detach_port_device(res->port_id);
1503         } else {
1504                 printf("Unknown parameter\n");
1505         }
1506 }
1507
1508 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1509         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1510                         port, "port");
1511 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1512         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1513                         keyword, "detach");
1514 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1515         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1516                         port_id, UINT16);
1517
1518 cmdline_parse_inst_t cmd_operate_detach_port = {
1519         .f = cmd_operate_detach_port_parsed,
1520         .data = NULL,
1521         .help_str = "port detach <port_id>",
1522         .tokens = {
1523                 (void *)&cmd_operate_detach_port_port,
1524                 (void *)&cmd_operate_detach_port_keyword,
1525                 (void *)&cmd_operate_detach_port_port_id,
1526                 NULL,
1527         },
1528 };
1529
1530 /* *** detach device by identifier *** */
1531 struct cmd_operate_detach_device_result {
1532         cmdline_fixed_string_t device;
1533         cmdline_fixed_string_t keyword;
1534         cmdline_fixed_string_t identifier;
1535 };
1536
1537 static void cmd_operate_detach_device_parsed(void *parsed_result,
1538                                 __rte_unused struct cmdline *cl,
1539                                 __rte_unused void *data)
1540 {
1541         struct cmd_operate_detach_device_result *res = parsed_result;
1542
1543         if (!strcmp(res->keyword, "detach"))
1544                 detach_devargs(res->identifier);
1545         else
1546                 printf("Unknown parameter\n");
1547 }
1548
1549 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1550         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1551                         device, "device");
1552 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1553         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1554                         keyword, "detach");
1555 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1556         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1557                         identifier, NULL);
1558
1559 cmdline_parse_inst_t cmd_operate_detach_device = {
1560         .f = cmd_operate_detach_device_parsed,
1561         .data = NULL,
1562         .help_str = "device detach <identifier>:"
1563                 "(identifier: pci address or virtual dev name)",
1564         .tokens = {
1565                 (void *)&cmd_operate_detach_device_device,
1566                 (void *)&cmd_operate_detach_device_keyword,
1567                 (void *)&cmd_operate_detach_device_identifier,
1568                 NULL,
1569         },
1570 };
1571 /* *** configure speed for all ports *** */
1572 struct cmd_config_speed_all {
1573         cmdline_fixed_string_t port;
1574         cmdline_fixed_string_t keyword;
1575         cmdline_fixed_string_t all;
1576         cmdline_fixed_string_t item1;
1577         cmdline_fixed_string_t item2;
1578         cmdline_fixed_string_t value1;
1579         cmdline_fixed_string_t value2;
1580 };
1581
1582 static int
1583 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1584 {
1585
1586         int duplex;
1587
1588         if (!strcmp(duplexstr, "half")) {
1589                 duplex = ETH_LINK_HALF_DUPLEX;
1590         } else if (!strcmp(duplexstr, "full")) {
1591                 duplex = ETH_LINK_FULL_DUPLEX;
1592         } else if (!strcmp(duplexstr, "auto")) {
1593                 duplex = ETH_LINK_FULL_DUPLEX;
1594         } else {
1595                 printf("Unknown duplex parameter\n");
1596                 return -1;
1597         }
1598
1599         if (!strcmp(speedstr, "10")) {
1600                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1601                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1602         } else if (!strcmp(speedstr, "100")) {
1603                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1604                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1605         } else {
1606                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1607                         printf("Invalid speed/duplex parameters\n");
1608                         return -1;
1609                 }
1610                 if (!strcmp(speedstr, "1000")) {
1611                         *speed = ETH_LINK_SPEED_1G;
1612                 } else if (!strcmp(speedstr, "10000")) {
1613                         *speed = ETH_LINK_SPEED_10G;
1614                 } else if (!strcmp(speedstr, "25000")) {
1615                         *speed = ETH_LINK_SPEED_25G;
1616                 } else if (!strcmp(speedstr, "40000")) {
1617                         *speed = ETH_LINK_SPEED_40G;
1618                 } else if (!strcmp(speedstr, "50000")) {
1619                         *speed = ETH_LINK_SPEED_50G;
1620                 } else if (!strcmp(speedstr, "100000")) {
1621                         *speed = ETH_LINK_SPEED_100G;
1622                 } else if (!strcmp(speedstr, "auto")) {
1623                         *speed = ETH_LINK_SPEED_AUTONEG;
1624                 } else {
1625                         printf("Unknown speed parameter\n");
1626                         return -1;
1627                 }
1628         }
1629
1630         return 0;
1631 }
1632
1633 static void
1634 cmd_config_speed_all_parsed(void *parsed_result,
1635                         __rte_unused struct cmdline *cl,
1636                         __rte_unused void *data)
1637 {
1638         struct cmd_config_speed_all *res = parsed_result;
1639         uint32_t link_speed;
1640         portid_t pid;
1641
1642         if (!all_ports_stopped()) {
1643                 printf("Please stop all ports first\n");
1644                 return;
1645         }
1646
1647         if (parse_and_check_speed_duplex(res->value1, res->value2,
1648                         &link_speed) < 0)
1649                 return;
1650
1651         RTE_ETH_FOREACH_DEV(pid) {
1652                 ports[pid].dev_conf.link_speeds = link_speed;
1653         }
1654
1655         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1656 }
1657
1658 cmdline_parse_token_string_t cmd_config_speed_all_port =
1659         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1660 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1662                                                         "config");
1663 cmdline_parse_token_string_t cmd_config_speed_all_all =
1664         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1665 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1666         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1667 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1669                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1670 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1672 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1673         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1674                                                 "half#full#auto");
1675
1676 cmdline_parse_inst_t cmd_config_speed_all = {
1677         .f = cmd_config_speed_all_parsed,
1678         .data = NULL,
1679         .help_str = "port config all speed "
1680                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1681                                                         "half|full|auto",
1682         .tokens = {
1683                 (void *)&cmd_config_speed_all_port,
1684                 (void *)&cmd_config_speed_all_keyword,
1685                 (void *)&cmd_config_speed_all_all,
1686                 (void *)&cmd_config_speed_all_item1,
1687                 (void *)&cmd_config_speed_all_value1,
1688                 (void *)&cmd_config_speed_all_item2,
1689                 (void *)&cmd_config_speed_all_value2,
1690                 NULL,
1691         },
1692 };
1693
1694 /* *** configure speed for specific port *** */
1695 struct cmd_config_speed_specific {
1696         cmdline_fixed_string_t port;
1697         cmdline_fixed_string_t keyword;
1698         portid_t id;
1699         cmdline_fixed_string_t item1;
1700         cmdline_fixed_string_t item2;
1701         cmdline_fixed_string_t value1;
1702         cmdline_fixed_string_t value2;
1703 };
1704
1705 static void
1706 cmd_config_speed_specific_parsed(void *parsed_result,
1707                                 __rte_unused struct cmdline *cl,
1708                                 __rte_unused void *data)
1709 {
1710         struct cmd_config_speed_specific *res = parsed_result;
1711         uint32_t link_speed;
1712
1713         if (!all_ports_stopped()) {
1714                 printf("Please stop all ports first\n");
1715                 return;
1716         }
1717
1718         if (port_id_is_invalid(res->id, ENABLED_WARN))
1719                 return;
1720
1721         if (parse_and_check_speed_duplex(res->value1, res->value2,
1722                         &link_speed) < 0)
1723                 return;
1724
1725         ports[res->id].dev_conf.link_speeds = link_speed;
1726
1727         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1728 }
1729
1730
1731 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1732         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1733                                                                 "port");
1734 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1735         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1736                                                                 "config");
1737 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1738         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1739 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1740         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1741                                                                 "speed");
1742 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1743         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1744                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1747                                                                 "duplex");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1750                                                         "half#full#auto");
1751
1752 cmdline_parse_inst_t cmd_config_speed_specific = {
1753         .f = cmd_config_speed_specific_parsed,
1754         .data = NULL,
1755         .help_str = "port config <port_id> speed "
1756                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1757                                                         "half|full|auto",
1758         .tokens = {
1759                 (void *)&cmd_config_speed_specific_port,
1760                 (void *)&cmd_config_speed_specific_keyword,
1761                 (void *)&cmd_config_speed_specific_id,
1762                 (void *)&cmd_config_speed_specific_item1,
1763                 (void *)&cmd_config_speed_specific_value1,
1764                 (void *)&cmd_config_speed_specific_item2,
1765                 (void *)&cmd_config_speed_specific_value2,
1766                 NULL,
1767         },
1768 };
1769
1770 /* *** configure loopback for all ports *** */
1771 struct cmd_config_loopback_all {
1772         cmdline_fixed_string_t port;
1773         cmdline_fixed_string_t keyword;
1774         cmdline_fixed_string_t all;
1775         cmdline_fixed_string_t item;
1776         uint32_t mode;
1777 };
1778
1779 static void
1780 cmd_config_loopback_all_parsed(void *parsed_result,
1781                         __rte_unused struct cmdline *cl,
1782                         __rte_unused void *data)
1783 {
1784         struct cmd_config_loopback_all *res = parsed_result;
1785         portid_t pid;
1786
1787         if (!all_ports_stopped()) {
1788                 printf("Please stop all ports first\n");
1789                 return;
1790         }
1791
1792         RTE_ETH_FOREACH_DEV(pid) {
1793                 ports[pid].dev_conf.lpbk_mode = res->mode;
1794         }
1795
1796         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1797 }
1798
1799 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1801 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1802         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1803                                                         "config");
1804 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1805         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1806 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1807         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1808                                                         "loopback");
1809 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1810         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1811
1812 cmdline_parse_inst_t cmd_config_loopback_all = {
1813         .f = cmd_config_loopback_all_parsed,
1814         .data = NULL,
1815         .help_str = "port config all loopback <mode>",
1816         .tokens = {
1817                 (void *)&cmd_config_loopback_all_port,
1818                 (void *)&cmd_config_loopback_all_keyword,
1819                 (void *)&cmd_config_loopback_all_all,
1820                 (void *)&cmd_config_loopback_all_item,
1821                 (void *)&cmd_config_loopback_all_mode,
1822                 NULL,
1823         },
1824 };
1825
1826 /* *** configure loopback for specific port *** */
1827 struct cmd_config_loopback_specific {
1828         cmdline_fixed_string_t port;
1829         cmdline_fixed_string_t keyword;
1830         uint16_t port_id;
1831         cmdline_fixed_string_t item;
1832         uint32_t mode;
1833 };
1834
1835 static void
1836 cmd_config_loopback_specific_parsed(void *parsed_result,
1837                                 __rte_unused struct cmdline *cl,
1838                                 __rte_unused void *data)
1839 {
1840         struct cmd_config_loopback_specific *res = parsed_result;
1841
1842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1843                 return;
1844
1845         if (!port_is_stopped(res->port_id)) {
1846                 printf("Please stop port %u first\n", res->port_id);
1847                 return;
1848         }
1849
1850         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1851
1852         cmd_reconfig_device_queue(res->port_id, 1, 1);
1853 }
1854
1855
1856 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1857         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1858                                                                 "port");
1859 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1861                                                                 "config");
1862 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1863         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1864                                                                 UINT16);
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1867                                                                 "loopback");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1870                               UINT32);
1871
1872 cmdline_parse_inst_t cmd_config_loopback_specific = {
1873         .f = cmd_config_loopback_specific_parsed,
1874         .data = NULL,
1875         .help_str = "port config <port_id> loopback <mode>",
1876         .tokens = {
1877                 (void *)&cmd_config_loopback_specific_port,
1878                 (void *)&cmd_config_loopback_specific_keyword,
1879                 (void *)&cmd_config_loopback_specific_id,
1880                 (void *)&cmd_config_loopback_specific_item,
1881                 (void *)&cmd_config_loopback_specific_mode,
1882                 NULL,
1883         },
1884 };
1885
1886 /* *** configure txq/rxq, txd/rxd *** */
1887 struct cmd_config_rx_tx {
1888         cmdline_fixed_string_t port;
1889         cmdline_fixed_string_t keyword;
1890         cmdline_fixed_string_t all;
1891         cmdline_fixed_string_t name;
1892         uint16_t value;
1893 };
1894
1895 static void
1896 cmd_config_rx_tx_parsed(void *parsed_result,
1897                         __rte_unused struct cmdline *cl,
1898                         __rte_unused void *data)
1899 {
1900         struct cmd_config_rx_tx *res = parsed_result;
1901
1902         if (!all_ports_stopped()) {
1903                 printf("Please stop all ports first\n");
1904                 return;
1905         }
1906         if (!strcmp(res->name, "rxq")) {
1907                 if (!res->value && !nb_txq) {
1908                         printf("Warning: Either rx or tx queues should be non zero\n");
1909                         return;
1910                 }
1911                 if (check_nb_rxq(res->value) != 0)
1912                         return;
1913                 nb_rxq = res->value;
1914         }
1915         else if (!strcmp(res->name, "txq")) {
1916                 if (!res->value && !nb_rxq) {
1917                         printf("Warning: Either rx or tx queues should be non zero\n");
1918                         return;
1919                 }
1920                 if (check_nb_txq(res->value) != 0)
1921                         return;
1922                 nb_txq = res->value;
1923         }
1924         else if (!strcmp(res->name, "rxd")) {
1925                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1926                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1927                                         res->value, RTE_TEST_RX_DESC_MAX);
1928                         return;
1929                 }
1930                 nb_rxd = res->value;
1931         } else if (!strcmp(res->name, "txd")) {
1932                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1933                         printf("txd %d invalid - must be > 0 && <= %d\n",
1934                                         res->value, RTE_TEST_TX_DESC_MAX);
1935                         return;
1936                 }
1937                 nb_txd = res->value;
1938         } else {
1939                 printf("Unknown parameter\n");
1940                 return;
1941         }
1942
1943         fwd_config_setup();
1944
1945         init_port_config();
1946
1947         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1948 }
1949
1950 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1954 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1955         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1956 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1958                                                 "rxq#txq#rxd#txd");
1959 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1960         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1961
1962 cmdline_parse_inst_t cmd_config_rx_tx = {
1963         .f = cmd_config_rx_tx_parsed,
1964         .data = NULL,
1965         .help_str = "port config all rxq|txq|rxd|txd <value>",
1966         .tokens = {
1967                 (void *)&cmd_config_rx_tx_port,
1968                 (void *)&cmd_config_rx_tx_keyword,
1969                 (void *)&cmd_config_rx_tx_all,
1970                 (void *)&cmd_config_rx_tx_name,
1971                 (void *)&cmd_config_rx_tx_value,
1972                 NULL,
1973         },
1974 };
1975
1976 /* *** config max packet length *** */
1977 struct cmd_config_max_pkt_len_result {
1978         cmdline_fixed_string_t port;
1979         cmdline_fixed_string_t keyword;
1980         cmdline_fixed_string_t all;
1981         cmdline_fixed_string_t name;
1982         uint32_t value;
1983 };
1984
1985 static void
1986 cmd_config_max_pkt_len_parsed(void *parsed_result,
1987                                 __rte_unused struct cmdline *cl,
1988                                 __rte_unused void *data)
1989 {
1990         struct cmd_config_max_pkt_len_result *res = parsed_result;
1991         portid_t pid;
1992
1993         if (!all_ports_stopped()) {
1994                 printf("Please stop all ports first\n");
1995                 return;
1996         }
1997
1998         RTE_ETH_FOREACH_DEV(pid) {
1999                 struct rte_port *port = &ports[pid];
2000                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2001
2002                 if (!strcmp(res->name, "max-pkt-len")) {
2003                         if (res->value < RTE_ETHER_MIN_LEN) {
2004                                 printf("max-pkt-len can not be less than %d\n",
2005                                                 RTE_ETHER_MIN_LEN);
2006                                 return;
2007                         }
2008                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2009                                 return;
2010
2011                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2012                         if (res->value > RTE_ETHER_MAX_LEN)
2013                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2014                         else
2015                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2016                         port->dev_conf.rxmode.offloads = rx_offloads;
2017                 } else {
2018                         printf("Unknown parameter\n");
2019                         return;
2020                 }
2021         }
2022
2023         init_port_config();
2024
2025         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2026 }
2027
2028 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2029         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2030                                                                 "port");
2031 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2032         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2033                                                                 "config");
2034 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2036                                                                 "all");
2037 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2038         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2039                                                                 "max-pkt-len");
2040 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2041         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2042                                                                 UINT32);
2043
2044 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2045         .f = cmd_config_max_pkt_len_parsed,
2046         .data = NULL,
2047         .help_str = "port config all max-pkt-len <value>",
2048         .tokens = {
2049                 (void *)&cmd_config_max_pkt_len_port,
2050                 (void *)&cmd_config_max_pkt_len_keyword,
2051                 (void *)&cmd_config_max_pkt_len_all,
2052                 (void *)&cmd_config_max_pkt_len_name,
2053                 (void *)&cmd_config_max_pkt_len_value,
2054                 NULL,
2055         },
2056 };
2057
2058 /* *** config max LRO aggregated packet size *** */
2059 struct cmd_config_max_lro_pkt_size_result {
2060         cmdline_fixed_string_t port;
2061         cmdline_fixed_string_t keyword;
2062         cmdline_fixed_string_t all;
2063         cmdline_fixed_string_t name;
2064         uint32_t value;
2065 };
2066
2067 static void
2068 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2069                                 __rte_unused struct cmdline *cl,
2070                                 __rte_unused void *data)
2071 {
2072         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2073         portid_t pid;
2074
2075         if (!all_ports_stopped()) {
2076                 printf("Please stop all ports first\n");
2077                 return;
2078         }
2079
2080         RTE_ETH_FOREACH_DEV(pid) {
2081                 struct rte_port *port = &ports[pid];
2082
2083                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2084                         if (res->value ==
2085                                         port->dev_conf.rxmode.max_lro_pkt_size)
2086                                 return;
2087
2088                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2089                 } else {
2090                         printf("Unknown parameter\n");
2091                         return;
2092                 }
2093         }
2094
2095         init_port_config();
2096
2097         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2098 }
2099
2100 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2101         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2102                                  port, "port");
2103 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2104         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2105                                  keyword, "config");
2106 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2107         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2108                                  all, "all");
2109 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2111                                  name, "max-lro-pkt-size");
2112 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2113         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114                               value, UINT32);
2115
2116 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2117         .f = cmd_config_max_lro_pkt_size_parsed,
2118         .data = NULL,
2119         .help_str = "port config all max-lro-pkt-size <value>",
2120         .tokens = {
2121                 (void *)&cmd_config_max_lro_pkt_size_port,
2122                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2123                 (void *)&cmd_config_max_lro_pkt_size_all,
2124                 (void *)&cmd_config_max_lro_pkt_size_name,
2125                 (void *)&cmd_config_max_lro_pkt_size_value,
2126                 NULL,
2127         },
2128 };
2129
2130 /* *** configure port MTU *** */
2131 struct cmd_config_mtu_result {
2132         cmdline_fixed_string_t port;
2133         cmdline_fixed_string_t keyword;
2134         cmdline_fixed_string_t mtu;
2135         portid_t port_id;
2136         uint16_t value;
2137 };
2138
2139 static void
2140 cmd_config_mtu_parsed(void *parsed_result,
2141                       __rte_unused struct cmdline *cl,
2142                       __rte_unused void *data)
2143 {
2144         struct cmd_config_mtu_result *res = parsed_result;
2145
2146         if (res->value < RTE_ETHER_MIN_LEN) {
2147                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2148                 return;
2149         }
2150         port_mtu_set(res->port_id, res->value);
2151 }
2152
2153 cmdline_parse_token_string_t cmd_config_mtu_port =
2154         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2155                                  "port");
2156 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2157         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2158                                  "config");
2159 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2161                                  "mtu");
2162 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2163         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2164 cmdline_parse_token_num_t cmd_config_mtu_value =
2165         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2166
2167 cmdline_parse_inst_t cmd_config_mtu = {
2168         .f = cmd_config_mtu_parsed,
2169         .data = NULL,
2170         .help_str = "port config mtu <port_id> <value>",
2171         .tokens = {
2172                 (void *)&cmd_config_mtu_port,
2173                 (void *)&cmd_config_mtu_keyword,
2174                 (void *)&cmd_config_mtu_mtu,
2175                 (void *)&cmd_config_mtu_port_id,
2176                 (void *)&cmd_config_mtu_value,
2177                 NULL,
2178         },
2179 };
2180
2181 /* *** configure rx mode *** */
2182 struct cmd_config_rx_mode_flag {
2183         cmdline_fixed_string_t port;
2184         cmdline_fixed_string_t keyword;
2185         cmdline_fixed_string_t all;
2186         cmdline_fixed_string_t name;
2187         cmdline_fixed_string_t value;
2188 };
2189
2190 static void
2191 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2192                                 __rte_unused struct cmdline *cl,
2193                                 __rte_unused void *data)
2194 {
2195         struct cmd_config_rx_mode_flag *res = parsed_result;
2196
2197         if (!all_ports_stopped()) {
2198                 printf("Please stop all ports first\n");
2199                 return;
2200         }
2201
2202         if (!strcmp(res->name, "drop-en")) {
2203                 if (!strcmp(res->value, "on"))
2204                         rx_drop_en = 1;
2205                 else if (!strcmp(res->value, "off"))
2206                         rx_drop_en = 0;
2207                 else {
2208                         printf("Unknown parameter\n");
2209                         return;
2210                 }
2211         } else {
2212                 printf("Unknown parameter\n");
2213                 return;
2214         }
2215
2216         init_port_config();
2217
2218         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2219 }
2220
2221 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2222         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2223 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2224         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2225                                                                 "config");
2226 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2227         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2228 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2229         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2230                                         "drop-en");
2231 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2232         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2233                                                         "on#off");
2234
2235 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2236         .f = cmd_config_rx_mode_flag_parsed,
2237         .data = NULL,
2238         .help_str = "port config all drop-en on|off",
2239         .tokens = {
2240                 (void *)&cmd_config_rx_mode_flag_port,
2241                 (void *)&cmd_config_rx_mode_flag_keyword,
2242                 (void *)&cmd_config_rx_mode_flag_all,
2243                 (void *)&cmd_config_rx_mode_flag_name,
2244                 (void *)&cmd_config_rx_mode_flag_value,
2245                 NULL,
2246         },
2247 };
2248
2249 /* *** configure rss *** */
2250 struct cmd_config_rss {
2251         cmdline_fixed_string_t port;
2252         cmdline_fixed_string_t keyword;
2253         cmdline_fixed_string_t all;
2254         cmdline_fixed_string_t name;
2255         cmdline_fixed_string_t value;
2256 };
2257
2258 static void
2259 cmd_config_rss_parsed(void *parsed_result,
2260                         __rte_unused struct cmdline *cl,
2261                         __rte_unused void *data)
2262 {
2263         struct cmd_config_rss *res = parsed_result;
2264         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2265         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2266         int use_default = 0;
2267         int all_updated = 1;
2268         int diag;
2269         uint16_t i;
2270         int ret;
2271
2272         if (!strcmp(res->value, "all"))
2273                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2274                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2275                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2276                         ETH_RSS_AH | ETH_RSS_PFCP;
2277         else if (!strcmp(res->value, "eth"))
2278                 rss_conf.rss_hf = ETH_RSS_ETH;
2279         else if (!strcmp(res->value, "vlan"))
2280                 rss_conf.rss_hf = ETH_RSS_VLAN;
2281         else if (!strcmp(res->value, "ip"))
2282                 rss_conf.rss_hf = ETH_RSS_IP;
2283         else if (!strcmp(res->value, "udp"))
2284                 rss_conf.rss_hf = ETH_RSS_UDP;
2285         else if (!strcmp(res->value, "tcp"))
2286                 rss_conf.rss_hf = ETH_RSS_TCP;
2287         else if (!strcmp(res->value, "sctp"))
2288                 rss_conf.rss_hf = ETH_RSS_SCTP;
2289         else if (!strcmp(res->value, "ether"))
2290                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2291         else if (!strcmp(res->value, "port"))
2292                 rss_conf.rss_hf = ETH_RSS_PORT;
2293         else if (!strcmp(res->value, "vxlan"))
2294                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2295         else if (!strcmp(res->value, "geneve"))
2296                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2297         else if (!strcmp(res->value, "nvgre"))
2298                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2299         else if (!strcmp(res->value, "l3-src-only"))
2300                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2301         else if (!strcmp(res->value, "l3-dst-only"))
2302                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2303         else if (!strcmp(res->value, "l4-src-only"))
2304                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2305         else if (!strcmp(res->value, "l4-dst-only"))
2306                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2307         else if (!strcmp(res->value, "l2-src-only"))
2308                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2309         else if (!strcmp(res->value, "l2-dst-only"))
2310                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2311         else if (!strcmp(res->value, "l2tpv3"))
2312                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2313         else if (!strcmp(res->value, "esp"))
2314                 rss_conf.rss_hf = ETH_RSS_ESP;
2315         else if (!strcmp(res->value, "ah"))
2316                 rss_conf.rss_hf = ETH_RSS_AH;
2317         else if (!strcmp(res->value, "pfcp"))
2318                 rss_conf.rss_hf = ETH_RSS_PFCP;
2319         else if (!strcmp(res->value, "none"))
2320                 rss_conf.rss_hf = 0;
2321         else if (!strcmp(res->value, "default"))
2322                 use_default = 1;
2323         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2324                                                 atoi(res->value) < 64)
2325                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2326         else {
2327                 printf("Unknown parameter\n");
2328                 return;
2329         }
2330         rss_conf.rss_key = NULL;
2331         /* Update global configuration for RSS types. */
2332         RTE_ETH_FOREACH_DEV(i) {
2333                 struct rte_eth_rss_conf local_rss_conf;
2334
2335                 ret = eth_dev_info_get_print_err(i, &dev_info);
2336                 if (ret != 0)
2337                         return;
2338
2339                 if (use_default)
2340                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2341
2342                 local_rss_conf = rss_conf;
2343                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2344                         dev_info.flow_type_rss_offloads;
2345                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2346                         printf("Port %u modified RSS hash function based on hardware support,"
2347                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2348                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2349                 }
2350                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2351                 if (diag < 0) {
2352                         all_updated = 0;
2353                         printf("Configuration of RSS hash at ethernet port %d "
2354                                 "failed with error (%d): %s.\n",
2355                                 i, -diag, strerror(-diag));
2356                 }
2357         }
2358         if (all_updated && !use_default) {
2359                 rss_hf = rss_conf.rss_hf;
2360                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2361         }
2362 }
2363
2364 cmdline_parse_token_string_t cmd_config_rss_port =
2365         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2366 cmdline_parse_token_string_t cmd_config_rss_keyword =
2367         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2368 cmdline_parse_token_string_t cmd_config_rss_all =
2369         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2370 cmdline_parse_token_string_t cmd_config_rss_name =
2371         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2372 cmdline_parse_token_string_t cmd_config_rss_value =
2373         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2374
2375 cmdline_parse_inst_t cmd_config_rss = {
2376         .f = cmd_config_rss_parsed,
2377         .data = NULL,
2378         .help_str = "port config all rss "
2379                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2380                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2381         .tokens = {
2382                 (void *)&cmd_config_rss_port,
2383                 (void *)&cmd_config_rss_keyword,
2384                 (void *)&cmd_config_rss_all,
2385                 (void *)&cmd_config_rss_name,
2386                 (void *)&cmd_config_rss_value,
2387                 NULL,
2388         },
2389 };
2390
2391 /* *** configure rss hash key *** */
2392 struct cmd_config_rss_hash_key {
2393         cmdline_fixed_string_t port;
2394         cmdline_fixed_string_t config;
2395         portid_t port_id;
2396         cmdline_fixed_string_t rss_hash_key;
2397         cmdline_fixed_string_t rss_type;
2398         cmdline_fixed_string_t key;
2399 };
2400
2401 static uint8_t
2402 hexa_digit_to_value(char hexa_digit)
2403 {
2404         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2405                 return (uint8_t) (hexa_digit - '0');
2406         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2407                 return (uint8_t) ((hexa_digit - 'a') + 10);
2408         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2409                 return (uint8_t) ((hexa_digit - 'A') + 10);
2410         /* Invalid hexa digit */
2411         return 0xFF;
2412 }
2413
2414 static uint8_t
2415 parse_and_check_key_hexa_digit(char *key, int idx)
2416 {
2417         uint8_t hexa_v;
2418
2419         hexa_v = hexa_digit_to_value(key[idx]);
2420         if (hexa_v == 0xFF)
2421                 printf("invalid key: character %c at position %d is not a "
2422                        "valid hexa digit\n", key[idx], idx);
2423         return hexa_v;
2424 }
2425
2426 static void
2427 cmd_config_rss_hash_key_parsed(void *parsed_result,
2428                                __rte_unused struct cmdline *cl,
2429                                __rte_unused void *data)
2430 {
2431         struct cmd_config_rss_hash_key *res = parsed_result;
2432         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2433         uint8_t xdgt0;
2434         uint8_t xdgt1;
2435         int i;
2436         struct rte_eth_dev_info dev_info;
2437         uint8_t hash_key_size;
2438         uint32_t key_len;
2439         int ret;
2440
2441         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2442         if (ret != 0)
2443                 return;
2444
2445         if (dev_info.hash_key_size > 0 &&
2446                         dev_info.hash_key_size <= sizeof(hash_key))
2447                 hash_key_size = dev_info.hash_key_size;
2448         else {
2449                 printf("dev_info did not provide a valid hash key size\n");
2450                 return;
2451         }
2452         /* Check the length of the RSS hash key */
2453         key_len = strlen(res->key);
2454         if (key_len != (hash_key_size * 2)) {
2455                 printf("key length: %d invalid - key must be a string of %d"
2456                            " hexa-decimal numbers\n",
2457                            (int) key_len, hash_key_size * 2);
2458                 return;
2459         }
2460         /* Translate RSS hash key into binary representation */
2461         for (i = 0; i < hash_key_size; i++) {
2462                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2463                 if (xdgt0 == 0xFF)
2464                         return;
2465                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2466                 if (xdgt1 == 0xFF)
2467                         return;
2468                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2469         }
2470         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2471                         hash_key_size);
2472 }
2473
2474 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2475         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2476 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2477         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2478                                  "config");
2479 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2480         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2481 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2482         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2483                                  rss_hash_key, "rss-hash-key");
2484 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2485         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2486                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2487                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2488                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2489                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2490                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2491                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2492                                  "l2tpv3#esp#ah#pfcp");
2493 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2494         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2495
2496 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2497         .f = cmd_config_rss_hash_key_parsed,
2498         .data = NULL,
2499         .help_str = "port config <port_id> rss-hash-key "
2500                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2501                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2502                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2503                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2504                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2505                 "l2tpv3|esp|ah|pfcp "
2506                 "<string of hex digits (variable length, NIC dependent)>",
2507         .tokens = {
2508                 (void *)&cmd_config_rss_hash_key_port,
2509                 (void *)&cmd_config_rss_hash_key_config,
2510                 (void *)&cmd_config_rss_hash_key_port_id,
2511                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2512                 (void *)&cmd_config_rss_hash_key_rss_type,
2513                 (void *)&cmd_config_rss_hash_key_value,
2514                 NULL,
2515         },
2516 };
2517
2518 /* *** configure port rxq/txq ring size *** */
2519 struct cmd_config_rxtx_ring_size {
2520         cmdline_fixed_string_t port;
2521         cmdline_fixed_string_t config;
2522         portid_t portid;
2523         cmdline_fixed_string_t rxtxq;
2524         uint16_t qid;
2525         cmdline_fixed_string_t rsize;
2526         uint16_t size;
2527 };
2528
2529 static void
2530 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2531                                  __rte_unused struct cmdline *cl,
2532                                  __rte_unused void *data)
2533 {
2534         struct cmd_config_rxtx_ring_size *res = parsed_result;
2535         struct rte_port *port;
2536         uint8_t isrx;
2537
2538         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2539                 return;
2540
2541         if (res->portid == (portid_t)RTE_PORT_ALL) {
2542                 printf("Invalid port id\n");
2543                 return;
2544         }
2545
2546         port = &ports[res->portid];
2547
2548         if (!strcmp(res->rxtxq, "rxq"))
2549                 isrx = 1;
2550         else if (!strcmp(res->rxtxq, "txq"))
2551                 isrx = 0;
2552         else {
2553                 printf("Unknown parameter\n");
2554                 return;
2555         }
2556
2557         if (isrx && rx_queue_id_is_invalid(res->qid))
2558                 return;
2559         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2560                 return;
2561
2562         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2563                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2564                        rx_free_thresh);
2565                 return;
2566         }
2567
2568         if (isrx)
2569                 port->nb_rx_desc[res->qid] = res->size;
2570         else
2571                 port->nb_tx_desc[res->qid] = res->size;
2572
2573         cmd_reconfig_device_queue(res->portid, 0, 1);
2574 }
2575
2576 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2577         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2578                                  port, "port");
2579 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2581                                  config, "config");
2582 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2583         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2584                                  portid, UINT16);
2585 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2586         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2587                                  rxtxq, "rxq#txq");
2588 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2589         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2590                               qid, UINT16);
2591 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2592         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2593                                  rsize, "ring_size");
2594 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2595         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2596                               size, UINT16);
2597
2598 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2599         .f = cmd_config_rxtx_ring_size_parsed,
2600         .data = NULL,
2601         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2602         .tokens = {
2603                 (void *)&cmd_config_rxtx_ring_size_port,
2604                 (void *)&cmd_config_rxtx_ring_size_config,
2605                 (void *)&cmd_config_rxtx_ring_size_portid,
2606                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2607                 (void *)&cmd_config_rxtx_ring_size_qid,
2608                 (void *)&cmd_config_rxtx_ring_size_rsize,
2609                 (void *)&cmd_config_rxtx_ring_size_size,
2610                 NULL,
2611         },
2612 };
2613
2614 /* *** configure port rxq/txq start/stop *** */
2615 struct cmd_config_rxtx_queue {
2616         cmdline_fixed_string_t port;
2617         portid_t portid;
2618         cmdline_fixed_string_t rxtxq;
2619         uint16_t qid;
2620         cmdline_fixed_string_t opname;
2621 };
2622
2623 static void
2624 cmd_config_rxtx_queue_parsed(void *parsed_result,
2625                         __rte_unused struct cmdline *cl,
2626                         __rte_unused void *data)
2627 {
2628         struct cmd_config_rxtx_queue *res = parsed_result;
2629         uint8_t isrx;
2630         uint8_t isstart;
2631         int ret = 0;
2632
2633         if (test_done == 0) {
2634                 printf("Please stop forwarding first\n");
2635                 return;
2636         }
2637
2638         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2639                 return;
2640
2641         if (port_is_started(res->portid) != 1) {
2642                 printf("Please start port %u first\n", res->portid);
2643                 return;
2644         }
2645
2646         if (!strcmp(res->rxtxq, "rxq"))
2647                 isrx = 1;
2648         else if (!strcmp(res->rxtxq, "txq"))
2649                 isrx = 0;
2650         else {
2651                 printf("Unknown parameter\n");
2652                 return;
2653         }
2654
2655         if (isrx && rx_queue_id_is_invalid(res->qid))
2656                 return;
2657         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2658                 return;
2659
2660         if (!strcmp(res->opname, "start"))
2661                 isstart = 1;
2662         else if (!strcmp(res->opname, "stop"))
2663                 isstart = 0;
2664         else {
2665                 printf("Unknown parameter\n");
2666                 return;
2667         }
2668
2669         if (isstart && isrx)
2670                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2671         else if (!isstart && isrx)
2672                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2673         else if (isstart && !isrx)
2674                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2675         else
2676                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2677
2678         if (ret == -ENOTSUP)
2679                 printf("Function not supported in PMD driver\n");
2680 }
2681
2682 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2683         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2684 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2685         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2686 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2687         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2688 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2689         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2690 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2691         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2692                                                 "start#stop");
2693
2694 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2695         .f = cmd_config_rxtx_queue_parsed,
2696         .data = NULL,
2697         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2698         .tokens = {
2699                 (void *)&cmd_config_rxtx_queue_port,
2700                 (void *)&cmd_config_rxtx_queue_portid,
2701                 (void *)&cmd_config_rxtx_queue_rxtxq,
2702                 (void *)&cmd_config_rxtx_queue_qid,
2703                 (void *)&cmd_config_rxtx_queue_opname,
2704                 NULL,
2705         },
2706 };
2707
2708 /* *** configure port rxq/txq deferred start on/off *** */
2709 struct cmd_config_deferred_start_rxtx_queue {
2710         cmdline_fixed_string_t port;
2711         portid_t port_id;
2712         cmdline_fixed_string_t rxtxq;
2713         uint16_t qid;
2714         cmdline_fixed_string_t opname;
2715         cmdline_fixed_string_t state;
2716 };
2717
2718 static void
2719 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2720                         __rte_unused struct cmdline *cl,
2721                         __rte_unused void *data)
2722 {
2723         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2724         struct rte_port *port;
2725         uint8_t isrx;
2726         uint8_t ison;
2727         uint8_t needreconfig = 0;
2728
2729         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2730                 return;
2731
2732         if (port_is_started(res->port_id) != 0) {
2733                 printf("Please stop port %u first\n", res->port_id);
2734                 return;
2735         }
2736
2737         port = &ports[res->port_id];
2738
2739         isrx = !strcmp(res->rxtxq, "rxq");
2740
2741         if (isrx && rx_queue_id_is_invalid(res->qid))
2742                 return;
2743         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2744                 return;
2745
2746         ison = !strcmp(res->state, "on");
2747
2748         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2749                 port->rx_conf[res->qid].rx_deferred_start = ison;
2750                 needreconfig = 1;
2751         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2752                 port->tx_conf[res->qid].tx_deferred_start = ison;
2753                 needreconfig = 1;
2754         }
2755
2756         if (needreconfig)
2757                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2758 }
2759
2760 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2761         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2762                                                 port, "port");
2763 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2764         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2765                                                 port_id, UINT16);
2766 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2767         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2768                                                 rxtxq, "rxq#txq");
2769 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2770         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2771                                                 qid, UINT16);
2772 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2773         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2774                                                 opname, "deferred_start");
2775 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2776         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2777                                                 state, "on#off");
2778
2779 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2780         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2781         .data = NULL,
2782         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2783         .tokens = {
2784                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2785                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2786                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2787                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2788                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2789                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2790                 NULL,
2791         },
2792 };
2793
2794 /* *** configure port rxq/txq setup *** */
2795 struct cmd_setup_rxtx_queue {
2796         cmdline_fixed_string_t port;
2797         portid_t portid;
2798         cmdline_fixed_string_t rxtxq;
2799         uint16_t qid;
2800         cmdline_fixed_string_t setup;
2801 };
2802
2803 /* Common CLI fields for queue setup */
2804 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2805         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2806 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2807         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2808 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2809         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2810 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2811         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2812 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2813         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2814
2815 static void
2816 cmd_setup_rxtx_queue_parsed(
2817         void *parsed_result,
2818         __rte_unused struct cmdline *cl,
2819         __rte_unused void *data)
2820 {
2821         struct cmd_setup_rxtx_queue *res = parsed_result;
2822         struct rte_port *port;
2823         struct rte_mempool *mp;
2824         unsigned int socket_id;
2825         uint8_t isrx = 0;
2826         int ret;
2827
2828         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2829                 return;
2830
2831         if (res->portid == (portid_t)RTE_PORT_ALL) {
2832                 printf("Invalid port id\n");
2833                 return;
2834         }
2835
2836         if (!strcmp(res->rxtxq, "rxq"))
2837                 isrx = 1;
2838         else if (!strcmp(res->rxtxq, "txq"))
2839                 isrx = 0;
2840         else {
2841                 printf("Unknown parameter\n");
2842                 return;
2843         }
2844
2845         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2846                 printf("Invalid rx queue\n");
2847                 return;
2848         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2849                 printf("Invalid tx queue\n");
2850                 return;
2851         }
2852
2853         port = &ports[res->portid];
2854         if (isrx) {
2855                 socket_id = rxring_numa[res->portid];
2856                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2857                         socket_id = port->socket_id;
2858
2859                 mp = mbuf_pool_find(socket_id);
2860                 if (mp == NULL) {
2861                         printf("Failed to setup RX queue: "
2862                                 "No mempool allocation"
2863                                 " on the socket %d\n",
2864                                 rxring_numa[res->portid]);
2865                         return;
2866                 }
2867                 ret = rte_eth_rx_queue_setup(res->portid,
2868                                              res->qid,
2869                                              port->nb_rx_desc[res->qid],
2870                                              socket_id,
2871                                              &port->rx_conf[res->qid],
2872                                              mp);
2873                 if (ret)
2874                         printf("Failed to setup RX queue\n");
2875         } else {
2876                 socket_id = txring_numa[res->portid];
2877                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2878                         socket_id = port->socket_id;
2879
2880                 ret = rte_eth_tx_queue_setup(res->portid,
2881                                              res->qid,
2882                                              port->nb_tx_desc[res->qid],
2883                                              socket_id,
2884                                              &port->tx_conf[res->qid]);
2885                 if (ret)
2886                         printf("Failed to setup TX queue\n");
2887         }
2888 }
2889
2890 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2891         .f = cmd_setup_rxtx_queue_parsed,
2892         .data = NULL,
2893         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2894         .tokens = {
2895                 (void *)&cmd_setup_rxtx_queue_port,
2896                 (void *)&cmd_setup_rxtx_queue_portid,
2897                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2898                 (void *)&cmd_setup_rxtx_queue_qid,
2899                 (void *)&cmd_setup_rxtx_queue_setup,
2900                 NULL,
2901         },
2902 };
2903
2904
2905 /* *** Configure RSS RETA *** */
2906 struct cmd_config_rss_reta {
2907         cmdline_fixed_string_t port;
2908         cmdline_fixed_string_t keyword;
2909         portid_t port_id;
2910         cmdline_fixed_string_t name;
2911         cmdline_fixed_string_t list_name;
2912         cmdline_fixed_string_t list_of_items;
2913 };
2914
2915 static int
2916 parse_reta_config(const char *str,
2917                   struct rte_eth_rss_reta_entry64 *reta_conf,
2918                   uint16_t nb_entries)
2919 {
2920         int i;
2921         unsigned size;
2922         uint16_t hash_index, idx, shift;
2923         uint16_t nb_queue;
2924         char s[256];
2925         const char *p, *p0 = str;
2926         char *end;
2927         enum fieldnames {
2928                 FLD_HASH_INDEX = 0,
2929                 FLD_QUEUE,
2930                 _NUM_FLD
2931         };
2932         unsigned long int_fld[_NUM_FLD];
2933         char *str_fld[_NUM_FLD];
2934
2935         while ((p = strchr(p0,'(')) != NULL) {
2936                 ++p;
2937                 if((p0 = strchr(p,')')) == NULL)
2938                         return -1;
2939
2940                 size = p0 - p;
2941                 if(size >= sizeof(s))
2942                         return -1;
2943
2944                 snprintf(s, sizeof(s), "%.*s", size, p);
2945                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2946                         return -1;
2947                 for (i = 0; i < _NUM_FLD; i++) {
2948                         errno = 0;
2949                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2950                         if (errno != 0 || end == str_fld[i] ||
2951                                         int_fld[i] > 65535)
2952                                 return -1;
2953                 }
2954
2955                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2956                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2957
2958                 if (hash_index >= nb_entries) {
2959                         printf("Invalid RETA hash index=%d\n", hash_index);
2960                         return -1;
2961                 }
2962
2963                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2964                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2965                 reta_conf[idx].mask |= (1ULL << shift);
2966                 reta_conf[idx].reta[shift] = nb_queue;
2967         }
2968
2969         return 0;
2970 }
2971
2972 static void
2973 cmd_set_rss_reta_parsed(void *parsed_result,
2974                         __rte_unused struct cmdline *cl,
2975                         __rte_unused void *data)
2976 {
2977         int ret;
2978         struct rte_eth_dev_info dev_info;
2979         struct rte_eth_rss_reta_entry64 reta_conf[8];
2980         struct cmd_config_rss_reta *res = parsed_result;
2981
2982         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2983         if (ret != 0)
2984                 return;
2985
2986         if (dev_info.reta_size == 0) {
2987                 printf("Redirection table size is 0 which is "
2988                                         "invalid for RSS\n");
2989                 return;
2990         } else
2991                 printf("The reta size of port %d is %u\n",
2992                         res->port_id, dev_info.reta_size);
2993         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2994                 printf("Currently do not support more than %u entries of "
2995                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2996                 return;
2997         }
2998
2999         memset(reta_conf, 0, sizeof(reta_conf));
3000         if (!strcmp(res->list_name, "reta")) {
3001                 if (parse_reta_config(res->list_of_items, reta_conf,
3002                                                 dev_info.reta_size)) {
3003                         printf("Invalid RSS Redirection Table "
3004                                         "config entered\n");
3005                         return;
3006                 }
3007                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3008                                 reta_conf, dev_info.reta_size);
3009                 if (ret != 0)
3010                         printf("Bad redirection table parameter, "
3011                                         "return code = %d \n", ret);
3012         }
3013 }
3014
3015 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3016         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3017 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3018         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3019 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3020         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3021 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3022         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3023 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3024         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3025 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3026         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3027                                  NULL);
3028 cmdline_parse_inst_t cmd_config_rss_reta = {
3029         .f = cmd_set_rss_reta_parsed,
3030         .data = NULL,
3031         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3032         .tokens = {
3033                 (void *)&cmd_config_rss_reta_port,
3034                 (void *)&cmd_config_rss_reta_keyword,
3035                 (void *)&cmd_config_rss_reta_port_id,
3036                 (void *)&cmd_config_rss_reta_name,
3037                 (void *)&cmd_config_rss_reta_list_name,
3038                 (void *)&cmd_config_rss_reta_list_of_items,
3039                 NULL,
3040         },
3041 };
3042
3043 /* *** SHOW PORT RETA INFO *** */
3044 struct cmd_showport_reta {
3045         cmdline_fixed_string_t show;
3046         cmdline_fixed_string_t port;
3047         portid_t port_id;
3048         cmdline_fixed_string_t rss;
3049         cmdline_fixed_string_t reta;
3050         uint16_t size;
3051         cmdline_fixed_string_t list_of_items;
3052 };
3053
3054 static int
3055 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3056                            uint16_t nb_entries,
3057                            char *str)
3058 {
3059         uint32_t size;
3060         const char *p, *p0 = str;
3061         char s[256];
3062         char *end;
3063         char *str_fld[8];
3064         uint16_t i;
3065         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3066                         RTE_RETA_GROUP_SIZE;
3067         int ret;
3068
3069         p = strchr(p0, '(');
3070         if (p == NULL)
3071                 return -1;
3072         p++;
3073         p0 = strchr(p, ')');
3074         if (p0 == NULL)
3075                 return -1;
3076         size = p0 - p;
3077         if (size >= sizeof(s)) {
3078                 printf("The string size exceeds the internal buffer size\n");
3079                 return -1;
3080         }
3081         snprintf(s, sizeof(s), "%.*s", size, p);
3082         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3083         if (ret <= 0 || ret != num) {
3084                 printf("The bits of masks do not match the number of "
3085                                         "reta entries: %u\n", num);
3086                 return -1;
3087         }
3088         for (i = 0; i < ret; i++)
3089                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3090
3091         return 0;
3092 }
3093
3094 static void
3095 cmd_showport_reta_parsed(void *parsed_result,
3096                          __rte_unused struct cmdline *cl,
3097                          __rte_unused void *data)
3098 {
3099         struct cmd_showport_reta *res = parsed_result;
3100         struct rte_eth_rss_reta_entry64 reta_conf[8];
3101         struct rte_eth_dev_info dev_info;
3102         uint16_t max_reta_size;
3103         int ret;
3104
3105         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3106         if (ret != 0)
3107                 return;
3108
3109         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3110         if (res->size == 0 || res->size > max_reta_size) {
3111                 printf("Invalid redirection table size: %u (1-%u)\n",
3112                         res->size, max_reta_size);
3113                 return;
3114         }
3115
3116         memset(reta_conf, 0, sizeof(reta_conf));
3117         if (showport_parse_reta_config(reta_conf, res->size,
3118                                 res->list_of_items) < 0) {
3119                 printf("Invalid string: %s for reta masks\n",
3120                                         res->list_of_items);
3121                 return;
3122         }
3123         port_rss_reta_info(res->port_id, reta_conf, res->size);
3124 }
3125
3126 cmdline_parse_token_string_t cmd_showport_reta_show =
3127         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3128 cmdline_parse_token_string_t cmd_showport_reta_port =
3129         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3130 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3131         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3132 cmdline_parse_token_string_t cmd_showport_reta_rss =
3133         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3134 cmdline_parse_token_string_t cmd_showport_reta_reta =
3135         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3136 cmdline_parse_token_num_t cmd_showport_reta_size =
3137         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3138 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3139         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3140                                         list_of_items, NULL);
3141
3142 cmdline_parse_inst_t cmd_showport_reta = {
3143         .f = cmd_showport_reta_parsed,
3144         .data = NULL,
3145         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3146         .tokens = {
3147                 (void *)&cmd_showport_reta_show,
3148                 (void *)&cmd_showport_reta_port,
3149                 (void *)&cmd_showport_reta_port_id,
3150                 (void *)&cmd_showport_reta_rss,
3151                 (void *)&cmd_showport_reta_reta,
3152                 (void *)&cmd_showport_reta_size,
3153                 (void *)&cmd_showport_reta_list_of_items,
3154                 NULL,
3155         },
3156 };
3157
3158 /* *** Show RSS hash configuration *** */
3159 struct cmd_showport_rss_hash {
3160         cmdline_fixed_string_t show;
3161         cmdline_fixed_string_t port;
3162         portid_t port_id;
3163         cmdline_fixed_string_t rss_hash;
3164         cmdline_fixed_string_t rss_type;
3165         cmdline_fixed_string_t key; /* optional argument */
3166 };
3167
3168 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3169                                 __rte_unused struct cmdline *cl,
3170                                 void *show_rss_key)
3171 {
3172         struct cmd_showport_rss_hash *res = parsed_result;
3173
3174         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3175 }
3176
3177 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3178         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3179 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3180         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3181 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3182         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3183 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3184         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3185                                  "rss-hash");
3186 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3187         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3188
3189 cmdline_parse_inst_t cmd_showport_rss_hash = {
3190         .f = cmd_showport_rss_hash_parsed,
3191         .data = NULL,
3192         .help_str = "show port <port_id> rss-hash",
3193         .tokens = {
3194                 (void *)&cmd_showport_rss_hash_show,
3195                 (void *)&cmd_showport_rss_hash_port,
3196                 (void *)&cmd_showport_rss_hash_port_id,
3197                 (void *)&cmd_showport_rss_hash_rss_hash,
3198                 NULL,
3199         },
3200 };
3201
3202 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3203         .f = cmd_showport_rss_hash_parsed,
3204         .data = (void *)1,
3205         .help_str = "show port <port_id> rss-hash key",
3206         .tokens = {
3207                 (void *)&cmd_showport_rss_hash_show,
3208                 (void *)&cmd_showport_rss_hash_port,
3209                 (void *)&cmd_showport_rss_hash_port_id,
3210                 (void *)&cmd_showport_rss_hash_rss_hash,
3211                 (void *)&cmd_showport_rss_hash_rss_key,
3212                 NULL,
3213         },
3214 };
3215
3216 /* *** Configure DCB *** */
3217 struct cmd_config_dcb {
3218         cmdline_fixed_string_t port;
3219         cmdline_fixed_string_t config;
3220         portid_t port_id;
3221         cmdline_fixed_string_t dcb;
3222         cmdline_fixed_string_t vt;
3223         cmdline_fixed_string_t vt_en;
3224         uint8_t num_tcs;
3225         cmdline_fixed_string_t pfc;
3226         cmdline_fixed_string_t pfc_en;
3227 };
3228
3229 static void
3230 cmd_config_dcb_parsed(void *parsed_result,
3231                         __rte_unused struct cmdline *cl,
3232                         __rte_unused void *data)
3233 {
3234         struct cmd_config_dcb *res = parsed_result;
3235         portid_t port_id = res->port_id;
3236         struct rte_port *port;
3237         uint8_t pfc_en;
3238         int ret;
3239
3240         port = &ports[port_id];
3241         /** Check if the port is not started **/
3242         if (port->port_status != RTE_PORT_STOPPED) {
3243                 printf("Please stop port %d first\n", port_id);
3244                 return;
3245         }
3246
3247         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3248                 printf("The invalid number of traffic class,"
3249                         " only 4 or 8 allowed.\n");
3250                 return;
3251         }
3252
3253         if (nb_fwd_lcores < res->num_tcs) {
3254                 printf("nb_cores shouldn't be less than number of TCs.\n");
3255                 return;
3256         }
3257         if (!strncmp(res->pfc_en, "on", 2))
3258                 pfc_en = 1;
3259         else
3260                 pfc_en = 0;
3261
3262         /* DCB in VT mode */
3263         if (!strncmp(res->vt_en, "on", 2))
3264                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3265                                 (enum rte_eth_nb_tcs)res->num_tcs,
3266                                 pfc_en);
3267         else
3268                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3269                                 (enum rte_eth_nb_tcs)res->num_tcs,
3270                                 pfc_en);
3271
3272
3273         if (ret != 0) {
3274                 printf("Cannot initialize network ports.\n");
3275                 return;
3276         }
3277
3278         cmd_reconfig_device_queue(port_id, 1, 1);
3279 }
3280
3281 cmdline_parse_token_string_t cmd_config_dcb_port =
3282         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3283 cmdline_parse_token_string_t cmd_config_dcb_config =
3284         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3285 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3286         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3287 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3288         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3289 cmdline_parse_token_string_t cmd_config_dcb_vt =
3290         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3291 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3292         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3293 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3294         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3295 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3296         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3297 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3298         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3299
3300 cmdline_parse_inst_t cmd_config_dcb = {
3301         .f = cmd_config_dcb_parsed,
3302         .data = NULL,
3303         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3304         .tokens = {
3305                 (void *)&cmd_config_dcb_port,
3306                 (void *)&cmd_config_dcb_config,
3307                 (void *)&cmd_config_dcb_port_id,
3308                 (void *)&cmd_config_dcb_dcb,
3309                 (void *)&cmd_config_dcb_vt,
3310                 (void *)&cmd_config_dcb_vt_en,
3311                 (void *)&cmd_config_dcb_num_tcs,
3312                 (void *)&cmd_config_dcb_pfc,
3313                 (void *)&cmd_config_dcb_pfc_en,
3314                 NULL,
3315         },
3316 };
3317
3318 /* *** configure number of packets per burst *** */
3319 struct cmd_config_burst {
3320         cmdline_fixed_string_t port;
3321         cmdline_fixed_string_t keyword;
3322         cmdline_fixed_string_t all;
3323         cmdline_fixed_string_t name;
3324         uint16_t value;
3325 };
3326
3327 static void
3328 cmd_config_burst_parsed(void *parsed_result,
3329                         __rte_unused struct cmdline *cl,
3330                         __rte_unused void *data)
3331 {
3332         struct cmd_config_burst *res = parsed_result;
3333         struct rte_eth_dev_info dev_info;
3334         uint16_t rec_nb_pkts;
3335         int ret;
3336
3337         if (!all_ports_stopped()) {
3338                 printf("Please stop all ports first\n");
3339                 return;
3340         }
3341
3342         if (!strcmp(res->name, "burst")) {
3343                 if (res->value == 0) {
3344                         /* If user gives a value of zero, query the PMD for
3345                          * its recommended Rx burst size. Testpmd uses a single
3346                          * size for all ports, so assume all ports are the same
3347                          * NIC model and use the values from Port 0.
3348                          */
3349                         ret = eth_dev_info_get_print_err(0, &dev_info);
3350                         if (ret != 0)
3351                                 return;
3352
3353                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3354
3355                         if (rec_nb_pkts == 0) {
3356                                 printf("PMD does not recommend a burst size.\n"
3357                                         "User provided value must be between"
3358                                         " 1 and %d\n", MAX_PKT_BURST);
3359                                 return;
3360                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3361                                 printf("PMD recommended burst size of %d"
3362                                         " exceeds maximum value of %d\n",
3363                                         rec_nb_pkts, MAX_PKT_BURST);
3364                                 return;
3365                         }
3366                         printf("Using PMD-provided burst value of %d\n",
3367                                 rec_nb_pkts);
3368                         nb_pkt_per_burst = rec_nb_pkts;
3369                 } else if (res->value > MAX_PKT_BURST) {
3370                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3371                         return;
3372                 } else
3373                         nb_pkt_per_burst = res->value;
3374         } else {
3375                 printf("Unknown parameter\n");
3376                 return;
3377         }
3378
3379         init_port_config();
3380
3381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3382 }
3383
3384 cmdline_parse_token_string_t cmd_config_burst_port =
3385         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3386 cmdline_parse_token_string_t cmd_config_burst_keyword =
3387         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3388 cmdline_parse_token_string_t cmd_config_burst_all =
3389         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3390 cmdline_parse_token_string_t cmd_config_burst_name =
3391         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3392 cmdline_parse_token_num_t cmd_config_burst_value =
3393         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3394
3395 cmdline_parse_inst_t cmd_config_burst = {
3396         .f = cmd_config_burst_parsed,
3397         .data = NULL,
3398         .help_str = "port config all burst <value>",
3399         .tokens = {
3400                 (void *)&cmd_config_burst_port,
3401                 (void *)&cmd_config_burst_keyword,
3402                 (void *)&cmd_config_burst_all,
3403                 (void *)&cmd_config_burst_name,
3404                 (void *)&cmd_config_burst_value,
3405                 NULL,
3406         },
3407 };
3408
3409 /* *** configure rx/tx queues *** */
3410 struct cmd_config_thresh {
3411         cmdline_fixed_string_t port;
3412         cmdline_fixed_string_t keyword;
3413         cmdline_fixed_string_t all;
3414         cmdline_fixed_string_t name;
3415         uint8_t value;
3416 };
3417
3418 static void
3419 cmd_config_thresh_parsed(void *parsed_result,
3420                         __rte_unused struct cmdline *cl,
3421                         __rte_unused void *data)
3422 {
3423         struct cmd_config_thresh *res = parsed_result;
3424
3425         if (!all_ports_stopped()) {
3426                 printf("Please stop all ports first\n");
3427                 return;
3428         }
3429
3430         if (!strcmp(res->name, "txpt"))
3431                 tx_pthresh = res->value;
3432         else if(!strcmp(res->name, "txht"))
3433                 tx_hthresh = res->value;
3434         else if(!strcmp(res->name, "txwt"))
3435                 tx_wthresh = res->value;
3436         else if(!strcmp(res->name, "rxpt"))
3437                 rx_pthresh = res->value;
3438         else if(!strcmp(res->name, "rxht"))
3439                 rx_hthresh = res->value;
3440         else if(!strcmp(res->name, "rxwt"))
3441                 rx_wthresh = res->value;
3442         else {
3443                 printf("Unknown parameter\n");
3444                 return;
3445         }
3446
3447         init_port_config();
3448
3449         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3450 }
3451
3452 cmdline_parse_token_string_t cmd_config_thresh_port =
3453         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3454 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3455         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3456 cmdline_parse_token_string_t cmd_config_thresh_all =
3457         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3458 cmdline_parse_token_string_t cmd_config_thresh_name =
3459         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3460                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3461 cmdline_parse_token_num_t cmd_config_thresh_value =
3462         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3463
3464 cmdline_parse_inst_t cmd_config_thresh = {
3465         .f = cmd_config_thresh_parsed,
3466         .data = NULL,
3467         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3468         .tokens = {
3469                 (void *)&cmd_config_thresh_port,
3470                 (void *)&cmd_config_thresh_keyword,
3471                 (void *)&cmd_config_thresh_all,
3472                 (void *)&cmd_config_thresh_name,
3473                 (void *)&cmd_config_thresh_value,
3474                 NULL,
3475         },
3476 };
3477
3478 /* *** configure free/rs threshold *** */
3479 struct cmd_config_threshold {
3480         cmdline_fixed_string_t port;
3481         cmdline_fixed_string_t keyword;
3482         cmdline_fixed_string_t all;
3483         cmdline_fixed_string_t name;
3484         uint16_t value;
3485 };
3486
3487 static void
3488 cmd_config_threshold_parsed(void *parsed_result,
3489                         __rte_unused struct cmdline *cl,
3490                         __rte_unused void *data)
3491 {
3492         struct cmd_config_threshold *res = parsed_result;
3493
3494         if (!all_ports_stopped()) {
3495                 printf("Please stop all ports first\n");
3496                 return;
3497         }
3498
3499         if (!strcmp(res->name, "txfreet"))
3500                 tx_free_thresh = res->value;
3501         else if (!strcmp(res->name, "txrst"))
3502                 tx_rs_thresh = res->value;
3503         else if (!strcmp(res->name, "rxfreet"))
3504                 rx_free_thresh = res->value;
3505         else {
3506                 printf("Unknown parameter\n");
3507                 return;
3508         }
3509
3510         init_port_config();
3511
3512         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3513 }
3514
3515 cmdline_parse_token_string_t cmd_config_threshold_port =
3516         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3517 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3518         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3519                                                                 "config");
3520 cmdline_parse_token_string_t cmd_config_threshold_all =
3521         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3522 cmdline_parse_token_string_t cmd_config_threshold_name =
3523         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3524                                                 "txfreet#txrst#rxfreet");
3525 cmdline_parse_token_num_t cmd_config_threshold_value =
3526         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3527
3528 cmdline_parse_inst_t cmd_config_threshold = {
3529         .f = cmd_config_threshold_parsed,
3530         .data = NULL,
3531         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3532         .tokens = {
3533                 (void *)&cmd_config_threshold_port,
3534                 (void *)&cmd_config_threshold_keyword,
3535                 (void *)&cmd_config_threshold_all,
3536                 (void *)&cmd_config_threshold_name,
3537                 (void *)&cmd_config_threshold_value,
3538                 NULL,
3539         },
3540 };
3541
3542 /* *** stop *** */
3543 struct cmd_stop_result {
3544         cmdline_fixed_string_t stop;
3545 };
3546
3547 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3548                             __rte_unused struct cmdline *cl,
3549                             __rte_unused void *data)
3550 {
3551         stop_packet_forwarding();
3552 }
3553
3554 cmdline_parse_token_string_t cmd_stop_stop =
3555         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3556
3557 cmdline_parse_inst_t cmd_stop = {
3558         .f = cmd_stop_parsed,
3559         .data = NULL,
3560         .help_str = "stop: Stop packet forwarding",
3561         .tokens = {
3562                 (void *)&cmd_stop_stop,
3563                 NULL,
3564         },
3565 };
3566
3567 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3568
3569 unsigned int
3570 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3571                 unsigned int *parsed_items, int check_unique_values)
3572 {
3573         unsigned int nb_item;
3574         unsigned int value;
3575         unsigned int i;
3576         unsigned int j;
3577         int value_ok;
3578         char c;
3579
3580         /*
3581          * First parse all items in the list and store their value.
3582          */
3583         value = 0;
3584         nb_item = 0;
3585         value_ok = 0;
3586         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3587                 c = str[i];
3588                 if ((c >= '0') && (c <= '9')) {
3589                         value = (unsigned int) (value * 10 + (c - '0'));
3590                         value_ok = 1;
3591                         continue;
3592                 }
3593                 if (c != ',') {
3594                         printf("character %c is not a decimal digit\n", c);
3595                         return 0;
3596                 }
3597                 if (! value_ok) {
3598                         printf("No valid value before comma\n");
3599                         return 0;
3600                 }
3601                 if (nb_item < max_items) {
3602                         parsed_items[nb_item] = value;
3603                         value_ok = 0;
3604                         value = 0;
3605                 }
3606                 nb_item++;
3607         }
3608         if (nb_item >= max_items) {
3609                 printf("Number of %s = %u > %u (maximum items)\n",
3610                        item_name, nb_item + 1, max_items);
3611                 return 0;
3612         }
3613         parsed_items[nb_item++] = value;
3614         if (! check_unique_values)
3615                 return nb_item;
3616
3617         /*
3618          * Then, check that all values in the list are differents.
3619          * No optimization here...
3620          */
3621         for (i = 0; i < nb_item; i++) {
3622                 for (j = i + 1; j < nb_item; j++) {
3623                         if (parsed_items[j] == parsed_items[i]) {
3624                                 printf("duplicated %s %u at index %u and %u\n",
3625                                        item_name, parsed_items[i], i, j);
3626                                 return 0;
3627                         }
3628                 }
3629         }
3630         return nb_item;
3631 }
3632
3633 struct cmd_set_list_result {
3634         cmdline_fixed_string_t cmd_keyword;
3635         cmdline_fixed_string_t list_name;
3636         cmdline_fixed_string_t list_of_items;
3637 };
3638
3639 static void cmd_set_list_parsed(void *parsed_result,
3640                                 __rte_unused struct cmdline *cl,
3641                                 __rte_unused void *data)
3642 {
3643         struct cmd_set_list_result *res;
3644         union {
3645                 unsigned int lcorelist[RTE_MAX_LCORE];
3646                 unsigned int portlist[RTE_MAX_ETHPORTS];
3647         } parsed_items;
3648         unsigned int nb_item;
3649
3650         if (test_done == 0) {
3651                 printf("Please stop forwarding first\n");
3652                 return;
3653         }
3654
3655         res = parsed_result;
3656         if (!strcmp(res->list_name, "corelist")) {
3657                 nb_item = parse_item_list(res->list_of_items, "core",
3658                                           RTE_MAX_LCORE,
3659                                           parsed_items.lcorelist, 1);
3660                 if (nb_item > 0) {
3661                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3662                         fwd_config_setup();
3663                 }
3664                 return;
3665         }
3666         if (!strcmp(res->list_name, "portlist")) {
3667                 nb_item = parse_item_list(res->list_of_items, "port",
3668                                           RTE_MAX_ETHPORTS,
3669                                           parsed_items.portlist, 1);
3670                 if (nb_item > 0) {
3671                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3672                         fwd_config_setup();
3673                 }
3674         }
3675 }
3676
3677 cmdline_parse_token_string_t cmd_set_list_keyword =
3678         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3679                                  "set");
3680 cmdline_parse_token_string_t cmd_set_list_name =
3681         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3682                                  "corelist#portlist");
3683 cmdline_parse_token_string_t cmd_set_list_of_items =
3684         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3685                                  NULL);
3686
3687 cmdline_parse_inst_t cmd_set_fwd_list = {
3688         .f = cmd_set_list_parsed,
3689         .data = NULL,
3690         .help_str = "set corelist|portlist <list0[,list1]*>",
3691         .tokens = {
3692                 (void *)&cmd_set_list_keyword,
3693                 (void *)&cmd_set_list_name,
3694                 (void *)&cmd_set_list_of_items,
3695                 NULL,
3696         },
3697 };
3698
3699 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3700
3701 struct cmd_setmask_result {
3702         cmdline_fixed_string_t set;
3703         cmdline_fixed_string_t mask;
3704         uint64_t hexavalue;
3705 };
3706
3707 static void cmd_set_mask_parsed(void *parsed_result,
3708                                 __rte_unused struct cmdline *cl,
3709                                 __rte_unused void *data)
3710 {
3711         struct cmd_setmask_result *res = parsed_result;
3712
3713         if (test_done == 0) {
3714                 printf("Please stop forwarding first\n");
3715                 return;
3716         }
3717         if (!strcmp(res->mask, "coremask")) {
3718                 set_fwd_lcores_mask(res->hexavalue);
3719                 fwd_config_setup();
3720         } else if (!strcmp(res->mask, "portmask")) {
3721                 set_fwd_ports_mask(res->hexavalue);
3722                 fwd_config_setup();
3723         }
3724 }
3725
3726 cmdline_parse_token_string_t cmd_setmask_set =
3727         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3728 cmdline_parse_token_string_t cmd_setmask_mask =
3729         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3730                                  "coremask#portmask");
3731 cmdline_parse_token_num_t cmd_setmask_value =
3732         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3733
3734 cmdline_parse_inst_t cmd_set_fwd_mask = {
3735         .f = cmd_set_mask_parsed,
3736         .data = NULL,
3737         .help_str = "set coremask|portmask <hexadecimal value>",
3738         .tokens = {
3739                 (void *)&cmd_setmask_set,
3740                 (void *)&cmd_setmask_mask,
3741                 (void *)&cmd_setmask_value,
3742                 NULL,
3743         },
3744 };
3745
3746 /*
3747  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3748  */
3749 struct cmd_set_result {
3750         cmdline_fixed_string_t set;
3751         cmdline_fixed_string_t what;
3752         uint16_t value;
3753 };
3754
3755 static void cmd_set_parsed(void *parsed_result,
3756                            __rte_unused struct cmdline *cl,
3757                            __rte_unused void *data)
3758 {
3759         struct cmd_set_result *res = parsed_result;
3760         if (!strcmp(res->what, "nbport")) {
3761                 set_fwd_ports_number(res->value);
3762                 fwd_config_setup();
3763         } else if (!strcmp(res->what, "nbcore")) {
3764                 set_fwd_lcores_number(res->value);
3765                 fwd_config_setup();
3766         } else if (!strcmp(res->what, "burst"))
3767                 set_nb_pkt_per_burst(res->value);
3768         else if (!strcmp(res->what, "verbose"))
3769                 set_verbose_level(res->value);
3770 }
3771
3772 cmdline_parse_token_string_t cmd_set_set =
3773         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3774 cmdline_parse_token_string_t cmd_set_what =
3775         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3776                                  "nbport#nbcore#burst#verbose");
3777 cmdline_parse_token_num_t cmd_set_value =
3778         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3779
3780 cmdline_parse_inst_t cmd_set_numbers = {
3781         .f = cmd_set_parsed,
3782         .data = NULL,
3783         .help_str = "set nbport|nbcore|burst|verbose <value>",
3784         .tokens = {
3785                 (void *)&cmd_set_set,
3786                 (void *)&cmd_set_what,
3787                 (void *)&cmd_set_value,
3788                 NULL,
3789         },
3790 };
3791
3792 /* *** SET LOG LEVEL CONFIGURATION *** */
3793
3794 struct cmd_set_log_result {
3795         cmdline_fixed_string_t set;
3796         cmdline_fixed_string_t log;
3797         cmdline_fixed_string_t type;
3798         uint32_t level;
3799 };
3800
3801 static void
3802 cmd_set_log_parsed(void *parsed_result,
3803                    __rte_unused struct cmdline *cl,
3804                    __rte_unused void *data)
3805 {
3806         struct cmd_set_log_result *res;
3807         int ret;
3808
3809         res = parsed_result;
3810         if (!strcmp(res->type, "global"))
3811                 rte_log_set_global_level(res->level);
3812         else {
3813                 ret = rte_log_set_level_regexp(res->type, res->level);
3814                 if (ret < 0)
3815                         printf("Unable to set log level\n");
3816         }
3817 }
3818
3819 cmdline_parse_token_string_t cmd_set_log_set =
3820         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3821 cmdline_parse_token_string_t cmd_set_log_log =
3822         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3823 cmdline_parse_token_string_t cmd_set_log_type =
3824         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3825 cmdline_parse_token_num_t cmd_set_log_level =
3826         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3827
3828 cmdline_parse_inst_t cmd_set_log = {
3829         .f = cmd_set_log_parsed,
3830         .data = NULL,
3831         .help_str = "set log global|<type> <level>",
3832         .tokens = {
3833                 (void *)&cmd_set_log_set,
3834                 (void *)&cmd_set_log_log,
3835                 (void *)&cmd_set_log_type,
3836                 (void *)&cmd_set_log_level,
3837                 NULL,
3838         },
3839 };
3840
3841 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3842
3843 struct cmd_set_txpkts_result {
3844         cmdline_fixed_string_t cmd_keyword;
3845         cmdline_fixed_string_t txpkts;
3846         cmdline_fixed_string_t seg_lengths;
3847 };
3848
3849 static void
3850 cmd_set_txpkts_parsed(void *parsed_result,
3851                       __rte_unused struct cmdline *cl,
3852                       __rte_unused void *data)
3853 {
3854         struct cmd_set_txpkts_result *res;
3855         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3856         unsigned int nb_segs;
3857
3858         res = parsed_result;
3859         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3860                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3861         if (nb_segs > 0)
3862                 set_tx_pkt_segments(seg_lengths, nb_segs);
3863 }
3864
3865 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3866         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3867                                  cmd_keyword, "set");
3868 cmdline_parse_token_string_t cmd_set_txpkts_name =
3869         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3870                                  txpkts, "txpkts");
3871 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3872         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3873                                  seg_lengths, NULL);
3874
3875 cmdline_parse_inst_t cmd_set_txpkts = {
3876         .f = cmd_set_txpkts_parsed,
3877         .data = NULL,
3878         .help_str = "set txpkts <len0[,len1]*>",
3879         .tokens = {
3880                 (void *)&cmd_set_txpkts_keyword,
3881                 (void *)&cmd_set_txpkts_name,
3882                 (void *)&cmd_set_txpkts_lengths,
3883                 NULL,
3884         },
3885 };
3886
3887 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3888
3889 struct cmd_set_txsplit_result {
3890         cmdline_fixed_string_t cmd_keyword;
3891         cmdline_fixed_string_t txsplit;
3892         cmdline_fixed_string_t mode;
3893 };
3894
3895 static void
3896 cmd_set_txsplit_parsed(void *parsed_result,
3897                       __rte_unused struct cmdline *cl,
3898                       __rte_unused void *data)
3899 {
3900         struct cmd_set_txsplit_result *res;
3901
3902         res = parsed_result;
3903         set_tx_pkt_split(res->mode);
3904 }
3905
3906 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3907         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3908                                  cmd_keyword, "set");
3909 cmdline_parse_token_string_t cmd_set_txsplit_name =
3910         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3911                                  txsplit, "txsplit");
3912 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3913         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3914                                  mode, NULL);
3915
3916 cmdline_parse_inst_t cmd_set_txsplit = {
3917         .f = cmd_set_txsplit_parsed,
3918         .data = NULL,
3919         .help_str = "set txsplit on|off|rand",
3920         .tokens = {
3921                 (void *)&cmd_set_txsplit_keyword,
3922                 (void *)&cmd_set_txsplit_name,
3923                 (void *)&cmd_set_txsplit_mode,
3924                 NULL,
3925         },
3926 };
3927
3928 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3929 struct cmd_rx_vlan_filter_all_result {
3930         cmdline_fixed_string_t rx_vlan;
3931         cmdline_fixed_string_t what;
3932         cmdline_fixed_string_t all;
3933         portid_t port_id;
3934 };
3935
3936 static void
3937 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3938                               __rte_unused struct cmdline *cl,
3939                               __rte_unused void *data)
3940 {
3941         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3942
3943         if (!strcmp(res->what, "add"))
3944                 rx_vlan_all_filter_set(res->port_id, 1);
3945         else
3946                 rx_vlan_all_filter_set(res->port_id, 0);
3947 }
3948
3949 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3950         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3951                                  rx_vlan, "rx_vlan");
3952 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3953         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3954                                  what, "add#rm");
3955 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3956         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3957                                  all, "all");
3958 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3959         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3960                               port_id, UINT16);
3961
3962 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3963         .f = cmd_rx_vlan_filter_all_parsed,
3964         .data = NULL,
3965         .help_str = "rx_vlan add|rm all <port_id>: "
3966                 "Add/Remove all identifiers to/from the set of VLAN "
3967                 "identifiers filtered by a port",
3968         .tokens = {
3969                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3970                 (void *)&cmd_rx_vlan_filter_all_what,
3971                 (void *)&cmd_rx_vlan_filter_all_all,
3972                 (void *)&cmd_rx_vlan_filter_all_portid,
3973                 NULL,
3974         },
3975 };
3976
3977 /* *** VLAN OFFLOAD SET ON A PORT *** */
3978 struct cmd_vlan_offload_result {
3979         cmdline_fixed_string_t vlan;
3980         cmdline_fixed_string_t set;
3981         cmdline_fixed_string_t vlan_type;
3982         cmdline_fixed_string_t what;
3983         cmdline_fixed_string_t on;
3984         cmdline_fixed_string_t port_id;
3985 };
3986
3987 static void
3988 cmd_vlan_offload_parsed(void *parsed_result,
3989                           __rte_unused struct cmdline *cl,
3990                           __rte_unused void *data)
3991 {
3992         int on;
3993         struct cmd_vlan_offload_result *res = parsed_result;
3994         char *str;
3995         int i, len = 0;
3996         portid_t port_id = 0;
3997         unsigned int tmp;
3998
3999         str = res->port_id;
4000         len = strnlen(str, STR_TOKEN_SIZE);
4001         i = 0;
4002         /* Get port_id first */
4003         while(i < len){
4004                 if(str[i] == ',')
4005                         break;
4006
4007                 i++;
4008         }
4009         str[i]='\0';
4010         tmp = strtoul(str, NULL, 0);
4011         /* If port_id greater that what portid_t can represent, return */
4012         if(tmp >= RTE_MAX_ETHPORTS)
4013                 return;
4014         port_id = (portid_t)tmp;
4015
4016         if (!strcmp(res->on, "on"))
4017                 on = 1;
4018         else
4019                 on = 0;
4020
4021         if (!strcmp(res->what, "strip"))
4022                 rx_vlan_strip_set(port_id,  on);
4023         else if(!strcmp(res->what, "stripq")){
4024                 uint16_t queue_id = 0;
4025
4026                 /* No queue_id, return */
4027                 if(i + 1 >= len) {
4028                         printf("must specify (port,queue_id)\n");
4029                         return;
4030                 }
4031                 tmp = strtoul(str + i + 1, NULL, 0);
4032                 /* If queue_id greater that what 16-bits can represent, return */
4033                 if(tmp > 0xffff)
4034                         return;
4035
4036                 queue_id = (uint16_t)tmp;
4037                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4038         }
4039         else if (!strcmp(res->what, "filter"))
4040                 rx_vlan_filter_set(port_id, on);
4041         else if (!strcmp(res->what, "qinq_strip"))
4042                 rx_vlan_qinq_strip_set(port_id, on);
4043         else
4044                 vlan_extend_set(port_id, on);
4045
4046         return;
4047 }
4048
4049 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4050         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4051                                  vlan, "vlan");
4052 cmdline_parse_token_string_t cmd_vlan_offload_set =
4053         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4054                                  set, "set");
4055 cmdline_parse_token_string_t cmd_vlan_offload_what =
4056         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4057                                 what, "strip#filter#qinq_strip#extend#stripq");
4058 cmdline_parse_token_string_t cmd_vlan_offload_on =
4059         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4060                               on, "on#off");
4061 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4062         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4063                               port_id, NULL);
4064
4065 cmdline_parse_inst_t cmd_vlan_offload = {
4066         .f = cmd_vlan_offload_parsed,
4067         .data = NULL,
4068         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4069                 "<port_id[,queue_id]>: "
4070                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4071         .tokens = {
4072                 (void *)&cmd_vlan_offload_vlan,
4073                 (void *)&cmd_vlan_offload_set,
4074                 (void *)&cmd_vlan_offload_what,
4075                 (void *)&cmd_vlan_offload_on,
4076                 (void *)&cmd_vlan_offload_portid,
4077                 NULL,
4078         },
4079 };
4080
4081 /* *** VLAN TPID SET ON A PORT *** */
4082 struct cmd_vlan_tpid_result {
4083         cmdline_fixed_string_t vlan;
4084         cmdline_fixed_string_t set;
4085         cmdline_fixed_string_t vlan_type;
4086         cmdline_fixed_string_t what;
4087         uint16_t tp_id;
4088         portid_t port_id;
4089 };
4090
4091 static void
4092 cmd_vlan_tpid_parsed(void *parsed_result,
4093                           __rte_unused struct cmdline *cl,
4094                           __rte_unused void *data)
4095 {
4096         struct cmd_vlan_tpid_result *res = parsed_result;
4097         enum rte_vlan_type vlan_type;
4098
4099         if (!strcmp(res->vlan_type, "inner"))
4100                 vlan_type = ETH_VLAN_TYPE_INNER;
4101         else if (!strcmp(res->vlan_type, "outer"))
4102                 vlan_type = ETH_VLAN_TYPE_OUTER;
4103         else {
4104                 printf("Unknown vlan type\n");
4105                 return;
4106         }
4107         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4108 }
4109
4110 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4111         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4112                                  vlan, "vlan");
4113 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4114         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4115                                  set, "set");
4116 cmdline_parse_token_string_t cmd_vlan_type =
4117         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4118                                  vlan_type, "inner#outer");
4119 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4120         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4121                                  what, "tpid");
4122 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4123         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4124                               tp_id, UINT16);
4125 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4126         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4127                               port_id, UINT16);
4128
4129 cmdline_parse_inst_t cmd_vlan_tpid = {
4130         .f = cmd_vlan_tpid_parsed,
4131         .data = NULL,
4132         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4133                 "Set the VLAN Ether type",
4134         .tokens = {
4135                 (void *)&cmd_vlan_tpid_vlan,
4136                 (void *)&cmd_vlan_tpid_set,
4137                 (void *)&cmd_vlan_type,
4138                 (void *)&cmd_vlan_tpid_what,
4139                 (void *)&cmd_vlan_tpid_tpid,
4140                 (void *)&cmd_vlan_tpid_portid,
4141                 NULL,
4142         },
4143 };
4144
4145 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4146 struct cmd_rx_vlan_filter_result {
4147         cmdline_fixed_string_t rx_vlan;
4148         cmdline_fixed_string_t what;
4149         uint16_t vlan_id;
4150         portid_t port_id;
4151 };
4152
4153 static void
4154 cmd_rx_vlan_filter_parsed(void *parsed_result,
4155                           __rte_unused struct cmdline *cl,
4156                           __rte_unused void *data)
4157 {
4158         struct cmd_rx_vlan_filter_result *res = parsed_result;
4159
4160         if (!strcmp(res->what, "add"))
4161                 rx_vft_set(res->port_id, res->vlan_id, 1);
4162         else
4163                 rx_vft_set(res->port_id, res->vlan_id, 0);
4164 }
4165
4166 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4167         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4168                                  rx_vlan, "rx_vlan");
4169 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4170         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4171                                  what, "add#rm");
4172 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4173         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4174                               vlan_id, UINT16);
4175 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4176         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4177                               port_id, UINT16);
4178
4179 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4180         .f = cmd_rx_vlan_filter_parsed,
4181         .data = NULL,
4182         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4183                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4184                 "identifiers filtered by a port",
4185         .tokens = {
4186                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4187                 (void *)&cmd_rx_vlan_filter_what,
4188                 (void *)&cmd_rx_vlan_filter_vlanid,
4189                 (void *)&cmd_rx_vlan_filter_portid,
4190                 NULL,
4191         },
4192 };
4193
4194 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4195 struct cmd_tx_vlan_set_result {
4196         cmdline_fixed_string_t tx_vlan;
4197         cmdline_fixed_string_t set;
4198         portid_t port_id;
4199         uint16_t vlan_id;
4200 };
4201
4202 static void
4203 cmd_tx_vlan_set_parsed(void *parsed_result,
4204                        __rte_unused struct cmdline *cl,
4205                        __rte_unused void *data)
4206 {
4207         struct cmd_tx_vlan_set_result *res = parsed_result;
4208
4209         if (!port_is_stopped(res->port_id)) {
4210                 printf("Please stop port %d first\n", res->port_id);
4211                 return;
4212         }
4213
4214         tx_vlan_set(res->port_id, res->vlan_id);
4215
4216         cmd_reconfig_device_queue(res->port_id, 1, 1);
4217 }
4218
4219 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4220         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4221                                  tx_vlan, "tx_vlan");
4222 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4223         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4224                                  set, "set");
4225 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4226         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4227                               port_id, UINT16);
4228 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4229         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4230                               vlan_id, UINT16);
4231
4232 cmdline_parse_inst_t cmd_tx_vlan_set = {
4233         .f = cmd_tx_vlan_set_parsed,
4234         .data = NULL,
4235         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4236                 "Enable hardware insertion of a single VLAN header "
4237                 "with a given TAG Identifier in packets sent on a port",
4238         .tokens = {
4239                 (void *)&cmd_tx_vlan_set_tx_vlan,
4240                 (void *)&cmd_tx_vlan_set_set,
4241                 (void *)&cmd_tx_vlan_set_portid,
4242                 (void *)&cmd_tx_vlan_set_vlanid,
4243                 NULL,
4244         },
4245 };
4246
4247 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4248 struct cmd_tx_vlan_set_qinq_result {
4249         cmdline_fixed_string_t tx_vlan;
4250         cmdline_fixed_string_t set;
4251         portid_t port_id;
4252         uint16_t vlan_id;
4253         uint16_t vlan_id_outer;
4254 };
4255
4256 static void
4257 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4258                             __rte_unused struct cmdline *cl,
4259                             __rte_unused void *data)
4260 {
4261         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4262
4263         if (!port_is_stopped(res->port_id)) {
4264                 printf("Please stop port %d first\n", res->port_id);
4265                 return;
4266         }
4267
4268         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4269
4270         cmd_reconfig_device_queue(res->port_id, 1, 1);
4271 }
4272
4273 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4274         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4275                 tx_vlan, "tx_vlan");
4276 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4277         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4278                 set, "set");
4279 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4280         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4281                 port_id, UINT16);
4282 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4283         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4284                 vlan_id, UINT16);
4285 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4286         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4287                 vlan_id_outer, UINT16);
4288
4289 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4290         .f = cmd_tx_vlan_set_qinq_parsed,
4291         .data = NULL,
4292         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4293                 "Enable hardware insertion of double VLAN header "
4294                 "with given TAG Identifiers in packets sent on a port",
4295         .tokens = {
4296                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4297                 (void *)&cmd_tx_vlan_set_qinq_set,
4298                 (void *)&cmd_tx_vlan_set_qinq_portid,
4299                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4300                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4301                 NULL,
4302         },
4303 };
4304
4305 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4306 struct cmd_tx_vlan_set_pvid_result {
4307         cmdline_fixed_string_t tx_vlan;
4308         cmdline_fixed_string_t set;
4309         cmdline_fixed_string_t pvid;
4310         portid_t port_id;
4311         uint16_t vlan_id;
4312         cmdline_fixed_string_t mode;
4313 };
4314
4315 static void
4316 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4317                             __rte_unused struct cmdline *cl,
4318                             __rte_unused void *data)
4319 {
4320         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4321
4322         if (strcmp(res->mode, "on") == 0)
4323                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4324         else
4325                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4326 }
4327
4328 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4329         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4330                                  tx_vlan, "tx_vlan");
4331 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4332         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4333                                  set, "set");
4334 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4335         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4336                                  pvid, "pvid");
4337 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4338         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4339                              port_id, UINT16);
4340 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4341         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4342                               vlan_id, UINT16);
4343 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4344         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4345                                  mode, "on#off");
4346
4347 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4348         .f = cmd_tx_vlan_set_pvid_parsed,
4349         .data = NULL,
4350         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4351         .tokens = {
4352                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4353                 (void *)&cmd_tx_vlan_set_pvid_set,
4354                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4355                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4356                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4357                 (void *)&cmd_tx_vlan_set_pvid_mode,
4358                 NULL,
4359         },
4360 };
4361
4362 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4363 struct cmd_tx_vlan_reset_result {
4364         cmdline_fixed_string_t tx_vlan;
4365         cmdline_fixed_string_t reset;
4366         portid_t port_id;
4367 };
4368
4369 static void
4370 cmd_tx_vlan_reset_parsed(void *parsed_result,
4371                          __rte_unused struct cmdline *cl,
4372                          __rte_unused void *data)
4373 {
4374         struct cmd_tx_vlan_reset_result *res = parsed_result;
4375
4376         if (!port_is_stopped(res->port_id)) {
4377                 printf("Please stop port %d first\n", res->port_id);
4378                 return;
4379         }
4380
4381         tx_vlan_reset(res->port_id);
4382
4383         cmd_reconfig_device_queue(res->port_id, 1, 1);
4384 }
4385
4386 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4387         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4388                                  tx_vlan, "tx_vlan");
4389 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4390         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4391                                  reset, "reset");
4392 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4393         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4394                               port_id, UINT16);
4395
4396 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4397         .f = cmd_tx_vlan_reset_parsed,
4398         .data = NULL,
4399         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4400                 "VLAN header in packets sent on a port",
4401         .tokens = {
4402                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4403                 (void *)&cmd_tx_vlan_reset_reset,
4404                 (void *)&cmd_tx_vlan_reset_portid,
4405                 NULL,
4406         },
4407 };
4408
4409
4410 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4411 struct cmd_csum_result {
4412         cmdline_fixed_string_t csum;
4413         cmdline_fixed_string_t mode;
4414         cmdline_fixed_string_t proto;
4415         cmdline_fixed_string_t hwsw;
4416         portid_t port_id;
4417 };
4418
4419 static void
4420 csum_show(int port_id)
4421 {
4422         struct rte_eth_dev_info dev_info;
4423         uint64_t tx_offloads;
4424         int ret;
4425
4426         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4427         printf("Parse tunnel is %s\n",
4428                 (ports[port_id].parse_tunnel) ? "on" : "off");
4429         printf("IP checksum offload is %s\n",
4430                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4431         printf("UDP checksum offload is %s\n",
4432                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4433         printf("TCP checksum offload is %s\n",
4434                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4435         printf("SCTP checksum offload is %s\n",
4436                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4437         printf("Outer-Ip checksum offload is %s\n",
4438                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4439         printf("Outer-Udp checksum offload is %s\n",
4440                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4441
4442         /* display warnings if configuration is not supported by the NIC */
4443         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4444         if (ret != 0)
4445                 return;
4446
4447         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4448                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4449                 printf("Warning: hardware IP checksum enabled but not "
4450                         "supported by port %d\n", port_id);
4451         }
4452         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4453                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4454                 printf("Warning: hardware UDP checksum enabled but not "
4455                         "supported by port %d\n", port_id);
4456         }
4457         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4458                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4459                 printf("Warning: hardware TCP checksum enabled but not "
4460                         "supported by port %d\n", port_id);
4461         }
4462         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4463                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4464                 printf("Warning: hardware SCTP checksum enabled but not "
4465                         "supported by port %d\n", port_id);
4466         }
4467         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4468                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4469                 printf("Warning: hardware outer IP checksum enabled but not "
4470                         "supported by port %d\n", port_id);
4471         }
4472         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4473                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4474                         == 0) {
4475                 printf("Warning: hardware outer UDP checksum enabled but not "
4476                         "supported by port %d\n", port_id);
4477         }
4478 }
4479
4480 static void
4481 cmd_config_queue_tx_offloads(struct rte_port *port)
4482 {
4483         int k;
4484
4485         /* Apply queue tx offloads configuration */
4486         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4487                 port->tx_conf[k].offloads =
4488                         port->dev_conf.txmode.offloads;
4489 }
4490
4491 static void
4492 cmd_csum_parsed(void *parsed_result,
4493                        __rte_unused struct cmdline *cl,
4494                        __rte_unused void *data)
4495 {
4496         struct cmd_csum_result *res = parsed_result;
4497         int hw = 0;
4498         uint64_t csum_offloads = 0;
4499         struct rte_eth_dev_info dev_info;
4500         int ret;
4501
4502         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4503                 printf("invalid port %d\n", res->port_id);
4504                 return;
4505         }
4506         if (!port_is_stopped(res->port_id)) {
4507                 printf("Please stop port %d first\n", res->port_id);
4508                 return;
4509         }
4510
4511         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4512         if (ret != 0)
4513                 return;
4514
4515         if (!strcmp(res->mode, "set")) {
4516
4517                 if (!strcmp(res->hwsw, "hw"))
4518                         hw = 1;
4519
4520                 if (!strcmp(res->proto, "ip")) {
4521                         if (hw == 0 || (dev_info.tx_offload_capa &
4522                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4523                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4524                         } else {
4525                                 printf("IP checksum offload is not supported "
4526                                        "by port %u\n", res->port_id);
4527                         }
4528                 } else if (!strcmp(res->proto, "udp")) {
4529                         if (hw == 0 || (dev_info.tx_offload_capa &
4530                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4531                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4532                         } else {
4533                                 printf("UDP checksum offload is not supported "
4534                                        "by port %u\n", res->port_id);
4535                         }
4536                 } else if (!strcmp(res->proto, "tcp")) {
4537                         if (hw == 0 || (dev_info.tx_offload_capa &
4538                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4539                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4540                         } else {
4541                                 printf("TCP checksum offload is not supported "
4542                                        "by port %u\n", res->port_id);
4543                         }
4544                 } else if (!strcmp(res->proto, "sctp")) {
4545                         if (hw == 0 || (dev_info.tx_offload_capa &
4546                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4547                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4548                         } else {
4549                                 printf("SCTP checksum offload is not supported "
4550                                        "by port %u\n", res->port_id);
4551                         }
4552                 } else if (!strcmp(res->proto, "outer-ip")) {
4553                         if (hw == 0 || (dev_info.tx_offload_capa &
4554                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4555                                 csum_offloads |=
4556                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4557                         } else {
4558                                 printf("Outer IP checksum offload is not "
4559                                        "supported by port %u\n", res->port_id);
4560                         }
4561                 } else if (!strcmp(res->proto, "outer-udp")) {
4562                         if (hw == 0 || (dev_info.tx_offload_capa &
4563                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4564                                 csum_offloads |=
4565                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4566                         } else {
4567                                 printf("Outer UDP checksum offload is not "
4568                                        "supported by port %u\n", res->port_id);
4569                         }
4570                 }
4571
4572                 if (hw) {
4573                         ports[res->port_id].dev_conf.txmode.offloads |=
4574                                                         csum_offloads;
4575                 } else {
4576                         ports[res->port_id].dev_conf.txmode.offloads &=
4577                                                         (~csum_offloads);
4578                 }
4579                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4580         }
4581         csum_show(res->port_id);
4582
4583         cmd_reconfig_device_queue(res->port_id, 1, 1);
4584 }
4585
4586 cmdline_parse_token_string_t cmd_csum_csum =
4587         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4588                                 csum, "csum");
4589 cmdline_parse_token_string_t cmd_csum_mode =
4590         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4591                                 mode, "set");
4592 cmdline_parse_token_string_t cmd_csum_proto =
4593         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4594                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4595 cmdline_parse_token_string_t cmd_csum_hwsw =
4596         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4597                                 hwsw, "hw#sw");
4598 cmdline_parse_token_num_t cmd_csum_portid =
4599         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4600                                 port_id, UINT16);
4601
4602 cmdline_parse_inst_t cmd_csum_set = {
4603         .f = cmd_csum_parsed,
4604         .data = NULL,
4605         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4606                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4607                 "using csum forward engine",
4608         .tokens = {
4609                 (void *)&cmd_csum_csum,
4610                 (void *)&cmd_csum_mode,
4611                 (void *)&cmd_csum_proto,
4612                 (void *)&cmd_csum_hwsw,
4613                 (void *)&cmd_csum_portid,
4614                 NULL,
4615         },
4616 };
4617
4618 cmdline_parse_token_string_t cmd_csum_mode_show =
4619         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4620                                 mode, "show");
4621
4622 cmdline_parse_inst_t cmd_csum_show = {
4623         .f = cmd_csum_parsed,
4624         .data = NULL,
4625         .help_str = "csum show <port_id>: Show checksum offload configuration",
4626         .tokens = {
4627                 (void *)&cmd_csum_csum,
4628                 (void *)&cmd_csum_mode_show,
4629                 (void *)&cmd_csum_portid,
4630                 NULL,
4631         },
4632 };
4633
4634 /* Enable/disable tunnel parsing */
4635 struct cmd_csum_tunnel_result {
4636         cmdline_fixed_string_t csum;
4637         cmdline_fixed_string_t parse;
4638         cmdline_fixed_string_t onoff;
4639         portid_t port_id;
4640 };
4641
4642 static void
4643 cmd_csum_tunnel_parsed(void *parsed_result,
4644                        __rte_unused struct cmdline *cl,
4645                        __rte_unused void *data)
4646 {
4647         struct cmd_csum_tunnel_result *res = parsed_result;
4648
4649         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4650                 return;
4651
4652         if (!strcmp(res->onoff, "on"))
4653                 ports[res->port_id].parse_tunnel = 1;
4654         else
4655                 ports[res->port_id].parse_tunnel = 0;
4656
4657         csum_show(res->port_id);
4658 }
4659
4660 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4661         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4662                                 csum, "csum");
4663 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4664         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4665                                 parse, "parse-tunnel");
4666 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4667         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4668                                 onoff, "on#off");
4669 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4670         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4671                                 port_id, UINT16);
4672
4673 cmdline_parse_inst_t cmd_csum_tunnel = {
4674         .f = cmd_csum_tunnel_parsed,
4675         .data = NULL,
4676         .help_str = "csum parse-tunnel on|off <port_id>: "
4677                 "Enable/Disable parsing of tunnels for csum engine",
4678         .tokens = {
4679                 (void *)&cmd_csum_tunnel_csum,
4680                 (void *)&cmd_csum_tunnel_parse,
4681                 (void *)&cmd_csum_tunnel_onoff,
4682                 (void *)&cmd_csum_tunnel_portid,
4683                 NULL,
4684         },
4685 };
4686
4687 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4688 struct cmd_tso_set_result {
4689         cmdline_fixed_string_t tso;
4690         cmdline_fixed_string_t mode;
4691         uint16_t tso_segsz;
4692         portid_t port_id;
4693 };
4694
4695 static void
4696 cmd_tso_set_parsed(void *parsed_result,
4697                        __rte_unused struct cmdline *cl,
4698                        __rte_unused void *data)
4699 {
4700         struct cmd_tso_set_result *res = parsed_result;
4701         struct rte_eth_dev_info dev_info;
4702         int ret;
4703
4704         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4705                 return;
4706         if (!port_is_stopped(res->port_id)) {
4707                 printf("Please stop port %d first\n", res->port_id);
4708                 return;
4709         }
4710
4711         if (!strcmp(res->mode, "set"))
4712                 ports[res->port_id].tso_segsz = res->tso_segsz;
4713
4714         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4715         if (ret != 0)
4716                 return;
4717
4718         if ((ports[res->port_id].tso_segsz != 0) &&
4719                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4720                 printf("Error: TSO is not supported by port %d\n",
4721                        res->port_id);
4722                 return;
4723         }
4724
4725         if (ports[res->port_id].tso_segsz == 0) {
4726                 ports[res->port_id].dev_conf.txmode.offloads &=
4727                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4728                 printf("TSO for non-tunneled packets is disabled\n");
4729         } else {
4730                 ports[res->port_id].dev_conf.txmode.offloads |=
4731                                                 DEV_TX_OFFLOAD_TCP_TSO;
4732                 printf("TSO segment size for non-tunneled packets is %d\n",
4733                         ports[res->port_id].tso_segsz);
4734         }
4735         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4736
4737         /* display warnings if configuration is not supported by the NIC */
4738         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4739         if (ret != 0)
4740                 return;
4741
4742         if ((ports[res->port_id].tso_segsz != 0) &&
4743                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4744                 printf("Warning: TSO enabled but not "
4745                         "supported by port %d\n", res->port_id);
4746         }
4747
4748         cmd_reconfig_device_queue(res->port_id, 1, 1);
4749 }
4750
4751 cmdline_parse_token_string_t cmd_tso_set_tso =
4752         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4753                                 tso, "tso");
4754 cmdline_parse_token_string_t cmd_tso_set_mode =
4755         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4756                                 mode, "set");
4757 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4758         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4759                                 tso_segsz, UINT16);
4760 cmdline_parse_token_num_t cmd_tso_set_portid =
4761         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4762                                 port_id, UINT16);
4763
4764 cmdline_parse_inst_t cmd_tso_set = {
4765         .f = cmd_tso_set_parsed,
4766         .data = NULL,
4767         .help_str = "tso set <tso_segsz> <port_id>: "
4768                 "Set TSO segment size of non-tunneled packets for csum engine "
4769                 "(0 to disable)",
4770         .tokens = {
4771                 (void *)&cmd_tso_set_tso,
4772                 (void *)&cmd_tso_set_mode,
4773                 (void *)&cmd_tso_set_tso_segsz,
4774                 (void *)&cmd_tso_set_portid,
4775                 NULL,
4776         },
4777 };
4778
4779 cmdline_parse_token_string_t cmd_tso_show_mode =
4780         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4781                                 mode, "show");
4782
4783
4784 cmdline_parse_inst_t cmd_tso_show = {
4785         .f = cmd_tso_set_parsed,
4786         .data = NULL,
4787         .help_str = "tso show <port_id>: "
4788                 "Show TSO segment size of non-tunneled packets for csum engine",
4789         .tokens = {
4790                 (void *)&cmd_tso_set_tso,
4791                 (void *)&cmd_tso_show_mode,
4792                 (void *)&cmd_tso_set_portid,
4793                 NULL,
4794         },
4795 };
4796
4797 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4798 struct cmd_tunnel_tso_set_result {
4799         cmdline_fixed_string_t tso;
4800         cmdline_fixed_string_t mode;
4801         uint16_t tso_segsz;
4802         portid_t port_id;
4803 };
4804
4805 static struct rte_eth_dev_info
4806 check_tunnel_tso_nic_support(portid_t port_id)
4807 {
4808         struct rte_eth_dev_info dev_info;
4809
4810         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4811                 return dev_info;
4812
4813         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4814                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4815                        "not enabled for port %d\n", port_id);
4816         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4817                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4818                        "not enabled for port %d\n", port_id);
4819         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4820                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4821                        "not enabled for port %d\n", port_id);
4822         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4823                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4824                        "not enabled for port %d\n", port_id);
4825         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4826                 printf("Warning: IP TUNNEL TSO not supported therefore "
4827                        "not enabled for port %d\n", port_id);
4828         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4829                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4830                        "not enabled for port %d\n", port_id);
4831         return dev_info;
4832 }
4833
4834 static void
4835 cmd_tunnel_tso_set_parsed(void *parsed_result,
4836                           __rte_unused struct cmdline *cl,
4837                           __rte_unused void *data)
4838 {
4839         struct cmd_tunnel_tso_set_result *res = parsed_result;
4840         struct rte_eth_dev_info dev_info;
4841
4842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4843                 return;
4844         if (!port_is_stopped(res->port_id)) {
4845                 printf("Please stop port %d first\n", res->port_id);
4846                 return;
4847         }
4848
4849         if (!strcmp(res->mode, "set"))
4850                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4851
4852         dev_info = check_tunnel_tso_nic_support(res->port_id);
4853         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4854                 ports[res->port_id].dev_conf.txmode.offloads &=
4855                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4856                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4857                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4858                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4859                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4860                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4861                 printf("TSO for tunneled packets is disabled\n");
4862         } else {
4863                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4864                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4865                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4866                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4867                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4868                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4869
4870                 ports[res->port_id].dev_conf.txmode.offloads |=
4871                         (tso_offloads & dev_info.tx_offload_capa);
4872                 printf("TSO segment size for tunneled packets is %d\n",
4873                         ports[res->port_id].tunnel_tso_segsz);
4874
4875                 /* Below conditions are needed to make it work:
4876                  * (1) tunnel TSO is supported by the NIC;
4877                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4878                  * are recognized;
4879                  * (3) for tunneled pkts with outer L3 of IPv4,
4880                  * "csum set outer-ip" must be set to hw, because after tso,
4881                  * total_len of outer IP header is changed, and the checksum
4882                  * of outer IP header calculated by sw should be wrong; that
4883                  * is not necessary for IPv6 tunneled pkts because there's no
4884                  * checksum in IP header anymore.
4885                  */
4886
4887                 if (!ports[res->port_id].parse_tunnel)
4888                         printf("Warning: csum parse_tunnel must be set "
4889                                 "so that tunneled packets are recognized\n");
4890                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4891                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4892                         printf("Warning: csum set outer-ip must be set to hw "
4893                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4894         }
4895
4896         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4897         cmd_reconfig_device_queue(res->port_id, 1, 1);
4898 }
4899
4900 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4901         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4902                                 tso, "tunnel_tso");
4903 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4904         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4905                                 mode, "set");
4906 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4907         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4908                                 tso_segsz, UINT16);
4909 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4910         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4911                                 port_id, UINT16);
4912
4913 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4914         .f = cmd_tunnel_tso_set_parsed,
4915         .data = NULL,
4916         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4917                 "Set TSO segment size of tunneled packets for csum engine "
4918                 "(0 to disable)",
4919         .tokens = {
4920                 (void *)&cmd_tunnel_tso_set_tso,
4921                 (void *)&cmd_tunnel_tso_set_mode,
4922                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4923                 (void *)&cmd_tunnel_tso_set_portid,
4924                 NULL,
4925         },
4926 };
4927
4928 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4929         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4930                                 mode, "show");
4931
4932
4933 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4934         .f = cmd_tunnel_tso_set_parsed,
4935         .data = NULL,
4936         .help_str = "tunnel_tso show <port_id> "
4937                 "Show TSO segment size of tunneled packets for csum engine",
4938         .tokens = {
4939                 (void *)&cmd_tunnel_tso_set_tso,
4940                 (void *)&cmd_tunnel_tso_show_mode,
4941                 (void *)&cmd_tunnel_tso_set_portid,
4942                 NULL,
4943         },
4944 };
4945
4946 /* *** SET GRO FOR A PORT *** */
4947 struct cmd_gro_enable_result {
4948         cmdline_fixed_string_t cmd_set;
4949         cmdline_fixed_string_t cmd_port;
4950         cmdline_fixed_string_t cmd_keyword;
4951         cmdline_fixed_string_t cmd_onoff;
4952         portid_t cmd_pid;
4953 };
4954
4955 static void
4956 cmd_gro_enable_parsed(void *parsed_result,
4957                 __rte_unused struct cmdline *cl,
4958                 __rte_unused void *data)
4959 {
4960         struct cmd_gro_enable_result *res;
4961
4962         res = parsed_result;
4963         if (!strcmp(res->cmd_keyword, "gro"))
4964                 setup_gro(res->cmd_onoff, res->cmd_pid);
4965 }
4966
4967 cmdline_parse_token_string_t cmd_gro_enable_set =
4968         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4969                         cmd_set, "set");
4970 cmdline_parse_token_string_t cmd_gro_enable_port =
4971         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4972                         cmd_keyword, "port");
4973 cmdline_parse_token_num_t cmd_gro_enable_pid =
4974         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4975                         cmd_pid, UINT16);
4976 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4977         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4978                         cmd_keyword, "gro");
4979 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4980         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4981                         cmd_onoff, "on#off");
4982
4983 cmdline_parse_inst_t cmd_gro_enable = {
4984         .f = cmd_gro_enable_parsed,
4985         .data = NULL,
4986         .help_str = "set port <port_id> gro on|off",
4987         .tokens = {
4988                 (void *)&cmd_gro_enable_set,
4989                 (void *)&cmd_gro_enable_port,
4990                 (void *)&cmd_gro_enable_pid,
4991                 (void *)&cmd_gro_enable_keyword,
4992                 (void *)&cmd_gro_enable_onoff,
4993                 NULL,
4994         },
4995 };
4996
4997 /* *** DISPLAY GRO CONFIGURATION *** */
4998 struct cmd_gro_show_result {
4999         cmdline_fixed_string_t cmd_show;
5000         cmdline_fixed_string_t cmd_port;
5001         cmdline_fixed_string_t cmd_keyword;
5002         portid_t cmd_pid;
5003 };
5004
5005 static void
5006 cmd_gro_show_parsed(void *parsed_result,
5007                 __rte_unused struct cmdline *cl,
5008                 __rte_unused void *data)
5009 {
5010         struct cmd_gro_show_result *res;
5011
5012         res = parsed_result;
5013         if (!strcmp(res->cmd_keyword, "gro"))
5014                 show_gro(res->cmd_pid);
5015 }
5016
5017 cmdline_parse_token_string_t cmd_gro_show_show =
5018         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5019                         cmd_show, "show");
5020 cmdline_parse_token_string_t cmd_gro_show_port =
5021         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5022                         cmd_port, "port");
5023 cmdline_parse_token_num_t cmd_gro_show_pid =
5024         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5025                         cmd_pid, UINT16);
5026 cmdline_parse_token_string_t cmd_gro_show_keyword =
5027         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5028                         cmd_keyword, "gro");
5029
5030 cmdline_parse_inst_t cmd_gro_show = {
5031         .f = cmd_gro_show_parsed,
5032         .data = NULL,
5033         .help_str = "show port <port_id> gro",
5034         .tokens = {
5035                 (void *)&cmd_gro_show_show,
5036                 (void *)&cmd_gro_show_port,
5037                 (void *)&cmd_gro_show_pid,
5038                 (void *)&cmd_gro_show_keyword,
5039                 NULL,
5040         },
5041 };
5042
5043 /* *** SET FLUSH CYCLES FOR GRO *** */
5044 struct cmd_gro_flush_result {
5045         cmdline_fixed_string_t cmd_set;
5046         cmdline_fixed_string_t cmd_keyword;
5047         cmdline_fixed_string_t cmd_flush;
5048         uint8_t cmd_cycles;
5049 };
5050
5051 static void
5052 cmd_gro_flush_parsed(void *parsed_result,
5053                 __rte_unused struct cmdline *cl,
5054                 __rte_unused void *data)
5055 {
5056         struct cmd_gro_flush_result *res;
5057
5058         res = parsed_result;
5059         if ((!strcmp(res->cmd_keyword, "gro")) &&
5060                         (!strcmp(res->cmd_flush, "flush")))
5061                 setup_gro_flush_cycles(res->cmd_cycles);
5062 }
5063
5064 cmdline_parse_token_string_t cmd_gro_flush_set =
5065         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5066                         cmd_set, "set");
5067 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5068         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5069                         cmd_keyword, "gro");
5070 cmdline_parse_token_string_t cmd_gro_flush_flush =
5071         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5072                         cmd_flush, "flush");
5073 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5074         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5075                         cmd_cycles, UINT8);
5076
5077 cmdline_parse_inst_t cmd_gro_flush = {
5078         .f = cmd_gro_flush_parsed,
5079         .data = NULL,
5080         .help_str = "set gro flush <cycles>",
5081         .tokens = {
5082                 (void *)&cmd_gro_flush_set,
5083                 (void *)&cmd_gro_flush_keyword,
5084                 (void *)&cmd_gro_flush_flush,
5085                 (void *)&cmd_gro_flush_cycles,
5086                 NULL,
5087         },
5088 };
5089
5090 /* *** ENABLE/DISABLE GSO *** */
5091 struct cmd_gso_enable_result {
5092         cmdline_fixed_string_t cmd_set;
5093         cmdline_fixed_string_t cmd_port;
5094         cmdline_fixed_string_t cmd_keyword;
5095         cmdline_fixed_string_t cmd_mode;
5096         portid_t cmd_pid;
5097 };
5098
5099 static void
5100 cmd_gso_enable_parsed(void *parsed_result,
5101                 __rte_unused struct cmdline *cl,
5102                 __rte_unused void *data)
5103 {
5104         struct cmd_gso_enable_result *res;
5105
5106         res = parsed_result;
5107         if (!strcmp(res->cmd_keyword, "gso"))
5108                 setup_gso(res->cmd_mode, res->cmd_pid);
5109 }
5110
5111 cmdline_parse_token_string_t cmd_gso_enable_set =
5112         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5113                         cmd_set, "set");
5114 cmdline_parse_token_string_t cmd_gso_enable_port =
5115         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5116                         cmd_port, "port");
5117 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5118         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5119                         cmd_keyword, "gso");
5120 cmdline_parse_token_string_t cmd_gso_enable_mode =
5121         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5122                         cmd_mode, "on#off");
5123 cmdline_parse_token_num_t cmd_gso_enable_pid =
5124         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5125                         cmd_pid, UINT16);
5126
5127 cmdline_parse_inst_t cmd_gso_enable = {
5128         .f = cmd_gso_enable_parsed,
5129         .data = NULL,
5130         .help_str = "set port <port_id> gso on|off",
5131         .tokens = {
5132                 (void *)&cmd_gso_enable_set,
5133                 (void *)&cmd_gso_enable_port,
5134                 (void *)&cmd_gso_enable_pid,
5135                 (void *)&cmd_gso_enable_keyword,
5136                 (void *)&cmd_gso_enable_mode,
5137                 NULL,
5138         },
5139 };
5140
5141 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5142 struct cmd_gso_size_result {
5143         cmdline_fixed_string_t cmd_set;
5144         cmdline_fixed_string_t cmd_keyword;
5145         cmdline_fixed_string_t cmd_segsz;
5146         uint16_t cmd_size;
5147 };
5148
5149 static void
5150 cmd_gso_size_parsed(void *parsed_result,
5151                        __rte_unused struct cmdline *cl,
5152                        __rte_unused void *data)
5153 {
5154         struct cmd_gso_size_result *res = parsed_result;
5155
5156         if (test_done == 0) {
5157                 printf("Before setting GSO segsz, please first"
5158                                 " stop fowarding\n");
5159                 return;
5160         }
5161
5162         if (!strcmp(res->cmd_keyword, "gso") &&
5163                         !strcmp(res->cmd_segsz, "segsz")) {
5164                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5165                         printf("gso_size should be larger than %zu."
5166                                         " Please input a legal value\n",
5167                                         RTE_GSO_SEG_SIZE_MIN);
5168                 else
5169                         gso_max_segment_size = res->cmd_size;
5170         }
5171 }
5172
5173 cmdline_parse_token_string_t cmd_gso_size_set =
5174         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5175                                 cmd_set, "set");
5176 cmdline_parse_token_string_t cmd_gso_size_keyword =
5177         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5178                                 cmd_keyword, "gso");
5179 cmdline_parse_token_string_t cmd_gso_size_segsz =
5180         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5181                                 cmd_segsz, "segsz");
5182 cmdline_parse_token_num_t cmd_gso_size_size =
5183         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5184                                 cmd_size, UINT16);
5185
5186 cmdline_parse_inst_t cmd_gso_size = {
5187         .f = cmd_gso_size_parsed,
5188         .data = NULL,
5189         .help_str = "set gso segsz <length>",
5190         .tokens = {
5191                 (void *)&cmd_gso_size_set,
5192                 (void *)&cmd_gso_size_keyword,
5193                 (void *)&cmd_gso_size_segsz,
5194                 (void *)&cmd_gso_size_size,
5195                 NULL,
5196         },
5197 };
5198
5199 /* *** SHOW GSO CONFIGURATION *** */
5200 struct cmd_gso_show_result {
5201         cmdline_fixed_string_t cmd_show;
5202         cmdline_fixed_string_t cmd_port;
5203         cmdline_fixed_string_t cmd_keyword;
5204         portid_t cmd_pid;
5205 };
5206
5207 static void
5208 cmd_gso_show_parsed(void *parsed_result,
5209                        __rte_unused struct cmdline *cl,
5210                        __rte_unused void *data)
5211 {
5212         struct cmd_gso_show_result *res = parsed_result;
5213
5214         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5215                 printf("invalid port id %u\n", res->cmd_pid);
5216                 return;
5217         }
5218         if (!strcmp(res->cmd_keyword, "gso")) {
5219                 if (gso_ports[res->cmd_pid].enable) {
5220                         printf("Max GSO'd packet size: %uB\n"
5221                                         "Supported GSO types: TCP/IPv4, "
5222                                         "UDP/IPv4, VxLAN with inner "
5223                                         "TCP/IPv4 packet, GRE with inner "
5224                                         "TCP/IPv4 packet\n",
5225                                         gso_max_segment_size);
5226                 } else
5227                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5228         }
5229 }
5230
5231 cmdline_parse_token_string_t cmd_gso_show_show =
5232 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5233                 cmd_show, "show");
5234 cmdline_parse_token_string_t cmd_gso_show_port =
5235 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5236                 cmd_port, "port");
5237 cmdline_parse_token_string_t cmd_gso_show_keyword =
5238         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5239                                 cmd_keyword, "gso");
5240 cmdline_parse_token_num_t cmd_gso_show_pid =
5241         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5242                                 cmd_pid, UINT16);
5243
5244 cmdline_parse_inst_t cmd_gso_show = {
5245         .f = cmd_gso_show_parsed,
5246         .data = NULL,
5247         .help_str = "show port <port_id> gso",
5248         .tokens = {
5249                 (void *)&cmd_gso_show_show,
5250                 (void *)&cmd_gso_show_port,
5251                 (void *)&cmd_gso_show_pid,
5252                 (void *)&cmd_gso_show_keyword,
5253                 NULL,
5254         },
5255 };
5256
5257 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5258 struct cmd_set_flush_rx {
5259         cmdline_fixed_string_t set;
5260         cmdline_fixed_string_t flush_rx;
5261         cmdline_fixed_string_t mode;
5262 };
5263
5264 static void
5265 cmd_set_flush_rx_parsed(void *parsed_result,
5266                 __rte_unused struct cmdline *cl,
5267                 __rte_unused void *data)
5268 {
5269         struct cmd_set_flush_rx *res = parsed_result;
5270         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5271 }
5272
5273 cmdline_parse_token_string_t cmd_setflushrx_set =
5274         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5275                         set, "set");
5276 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5277         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5278                         flush_rx, "flush_rx");
5279 cmdline_parse_token_string_t cmd_setflushrx_mode =
5280         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5281                         mode, "on#off");
5282
5283
5284 cmdline_parse_inst_t cmd_set_flush_rx = {
5285         .f = cmd_set_flush_rx_parsed,
5286         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5287         .data = NULL,
5288         .tokens = {
5289                 (void *)&cmd_setflushrx_set,
5290                 (void *)&cmd_setflushrx_flush_rx,
5291                 (void *)&cmd_setflushrx_mode,
5292                 NULL,
5293         },
5294 };
5295
5296 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5297 struct cmd_set_link_check {
5298         cmdline_fixed_string_t set;
5299         cmdline_fixed_string_t link_check;
5300         cmdline_fixed_string_t mode;
5301 };
5302
5303 static void
5304 cmd_set_link_check_parsed(void *parsed_result,
5305                 __rte_unused struct cmdline *cl,
5306                 __rte_unused void *data)
5307 {
5308         struct cmd_set_link_check *res = parsed_result;
5309         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5310 }
5311
5312 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5313         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5314                         set, "set");
5315 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5316         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5317                         link_check, "link_check");
5318 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5319         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5320                         mode, "on#off");
5321
5322
5323 cmdline_parse_inst_t cmd_set_link_check = {
5324         .f = cmd_set_link_check_parsed,
5325         .help_str = "set link_check on|off: Enable/Disable link status check "
5326                     "when starting/stopping a port",
5327         .data = NULL,
5328         .tokens = {
5329                 (void *)&cmd_setlinkcheck_set,
5330                 (void *)&cmd_setlinkcheck_link_check,
5331                 (void *)&cmd_setlinkcheck_mode,
5332                 NULL,
5333         },
5334 };
5335
5336 /* *** SET NIC BYPASS MODE *** */
5337 struct cmd_set_bypass_mode_result {
5338         cmdline_fixed_string_t set;
5339         cmdline_fixed_string_t bypass;
5340         cmdline_fixed_string_t mode;
5341         cmdline_fixed_string_t value;
5342         portid_t port_id;
5343 };
5344
5345 static void
5346 cmd_set_bypass_mode_parsed(void *parsed_result,
5347                 __rte_unused struct cmdline *cl,
5348                 __rte_unused void *data)
5349 {
5350         struct cmd_set_bypass_mode_result *res = parsed_result;
5351         portid_t port_id = res->port_id;
5352         int32_t rc = -EINVAL;
5353
5354 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5355         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5356
5357         if (!strcmp(res->value, "bypass"))
5358                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5359         else if (!strcmp(res->value, "isolate"))
5360                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5361         else
5362                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5363
5364         /* Set the bypass mode for the relevant port. */
5365         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5366 #endif
5367         if (rc != 0)
5368                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5369 }
5370
5371 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5372         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5373                         set, "set");
5374 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5375         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5376                         bypass, "bypass");
5377 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5378         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5379                         mode, "mode");
5380 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5381         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5382                         value, "normal#bypass#isolate");
5383 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5384         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5385                                 port_id, UINT16);
5386
5387 cmdline_parse_inst_t cmd_set_bypass_mode = {
5388         .f = cmd_set_bypass_mode_parsed,
5389         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5390                     "Set the NIC bypass mode for port_id",
5391         .data = NULL,
5392         .tokens = {
5393                 (void *)&cmd_setbypass_mode_set,
5394                 (void *)&cmd_setbypass_mode_bypass,
5395                 (void *)&cmd_setbypass_mode_mode,
5396                 (void *)&cmd_setbypass_mode_value,
5397                 (void *)&cmd_setbypass_mode_port,
5398                 NULL,
5399         },
5400 };
5401
5402 /* *** SET NIC BYPASS EVENT *** */
5403 struct cmd_set_bypass_event_result {
5404         cmdline_fixed_string_t set;
5405         cmdline_fixed_string_t bypass;
5406         cmdline_fixed_string_t event;
5407         cmdline_fixed_string_t event_value;
5408         cmdline_fixed_string_t mode;
5409         cmdline_fixed_string_t mode_value;
5410         portid_t port_id;
5411 };
5412
5413 static void
5414 cmd_set_bypass_event_parsed(void *parsed_result,
5415                 __rte_unused struct cmdline *cl,
5416                 __rte_unused void *data)
5417 {
5418         int32_t rc = -EINVAL;
5419         struct cmd_set_bypass_event_result *res = parsed_result;
5420         portid_t port_id = res->port_id;
5421
5422 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5423         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5424         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5425
5426         if (!strcmp(res->event_value, "timeout"))
5427                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5428         else if (!strcmp(res->event_value, "os_on"))
5429                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5430         else if (!strcmp(res->event_value, "os_off"))
5431                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5432         else if (!strcmp(res->event_value, "power_on"))
5433                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5434         else if (!strcmp(res->event_value, "power_off"))
5435                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5436         else
5437                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5438
5439         if (!strcmp(res->mode_value, "bypass"))
5440                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5441         else if (!strcmp(res->mode_value, "isolate"))
5442                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5443         else
5444                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5445
5446         /* Set the watchdog timeout. */
5447         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5448
5449                 rc = -EINVAL;
5450                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5451                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5452                                                            bypass_timeout);
5453                 }
5454                 if (rc != 0) {
5455                         printf("Failed to set timeout value %u "
5456                         "for port %d, errto code: %d.\n",
5457                         bypass_timeout, port_id, rc);
5458                 }
5459         }
5460
5461         /* Set the bypass event to transition to bypass mode. */
5462         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5463                                               bypass_mode);
5464 #endif
5465
5466         if (rc != 0)
5467                 printf("\t Failed to set bypass event for port = %d.\n",
5468                        port_id);
5469 }
5470
5471 cmdline_parse_token_string_t cmd_setbypass_event_set =
5472         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5473                         set, "set");
5474 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5475         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5476                         bypass, "bypass");
5477 cmdline_parse_token_string_t cmd_setbypass_event_event =
5478         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5479                         event, "event");
5480 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5481         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5482                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5483 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5484         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5485                         mode, "mode");
5486 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5488                         mode_value, "normal#bypass#isolate");
5489 cmdline_parse_token_num_t cmd_setbypass_event_port =
5490         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5491                                 port_id, UINT16);
5492
5493 cmdline_parse_inst_t cmd_set_bypass_event = {
5494         .f = cmd_set_bypass_event_parsed,
5495         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5496                 "power_off mode normal|bypass|isolate <port_id>: "
5497                 "Set the NIC bypass event mode for port_id",
5498         .data = NULL,
5499         .tokens = {
5500                 (void *)&cmd_setbypass_event_set,
5501                 (void *)&cmd_setbypass_event_bypass,
5502                 (void *)&cmd_setbypass_event_event,
5503                 (void *)&cmd_setbypass_event_event_value,
5504                 (void *)&cmd_setbypass_event_mode,
5505                 (void *)&cmd_setbypass_event_mode_value,
5506                 (void *)&cmd_setbypass_event_port,
5507                 NULL,
5508         },
5509 };
5510
5511
5512 /* *** SET NIC BYPASS TIMEOUT *** */
5513 struct cmd_set_bypass_timeout_result {
5514         cmdline_fixed_string_t set;
5515         cmdline_fixed_string_t bypass;
5516         cmdline_fixed_string_t timeout;
5517         cmdline_fixed_string_t value;
5518 };
5519
5520 static void
5521 cmd_set_bypass_timeout_parsed(void *parsed_result,
5522                 __rte_unused struct cmdline *cl,
5523                 __rte_unused void *data)
5524 {
5525         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5526
5527 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5528         if (!strcmp(res->value, "1.5"))
5529                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5530         else if (!strcmp(res->value, "2"))
5531                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5532         else if (!strcmp(res->value, "3"))
5533                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5534         else if (!strcmp(res->value, "4"))
5535                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5536         else if (!strcmp(res->value, "8"))
5537                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5538         else if (!strcmp(res->value, "16"))
5539                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5540         else if (!strcmp(res->value, "32"))
5541                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5542         else
5543                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5544 #endif
5545 }
5546
5547 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5549                         set, "set");
5550 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5551         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5552                         bypass, "bypass");
5553 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5554         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5555                         timeout, "timeout");
5556 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5558                         value, "0#1.5#2#3#4#8#16#32");
5559
5560 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5561         .f = cmd_set_bypass_timeout_parsed,
5562         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5563                 "Set the NIC bypass watchdog timeout in seconds",
5564         .data = NULL,
5565         .tokens = {
5566                 (void *)&cmd_setbypass_timeout_set,
5567                 (void *)&cmd_setbypass_timeout_bypass,
5568                 (void *)&cmd_setbypass_timeout_timeout,
5569                 (void *)&cmd_setbypass_timeout_value,
5570                 NULL,
5571         },
5572 };
5573
5574 /* *** SHOW NIC BYPASS MODE *** */
5575 struct cmd_show_bypass_config_result {
5576         cmdline_fixed_string_t show;
5577         cmdline_fixed_string_t bypass;
5578         cmdline_fixed_string_t config;
5579         portid_t port_id;
5580 };
5581
5582 static void
5583 cmd_show_bypass_config_parsed(void *parsed_result,
5584                 __rte_unused struct cmdline *cl,
5585                 __rte_unused void *data)
5586 {
5587         struct cmd_show_bypass_config_result *res = parsed_result;
5588         portid_t port_id = res->port_id;
5589         int rc = -EINVAL;
5590 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5591         uint32_t event_mode;
5592         uint32_t bypass_mode;
5593         uint32_t timeout = bypass_timeout;
5594         unsigned int i;
5595
5596         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5597                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5598         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5599                 {"UNKNOWN", "normal", "bypass", "isolate"};
5600         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5601                 "NONE",
5602                 "OS/board on",
5603                 "power supply on",
5604                 "OS/board off",
5605                 "power supply off",
5606                 "timeout"};
5607
5608         /* Display the bypass mode.*/
5609         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5610                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5611                 return;
5612         }
5613         else {
5614                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5615                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5616
5617                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5618         }
5619
5620         /* Display the bypass timeout.*/
5621         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5622                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5623
5624         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5625
5626         /* Display the bypass events and associated modes. */
5627         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5628
5629                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5630                         printf("\tFailed to get bypass mode for event = %s\n",
5631                                 events[i]);
5632                 } else {
5633                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5634                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5635
5636                         printf("\tbypass event: %-16s = %s\n", events[i],
5637                                 modes[event_mode]);
5638                 }
5639         }
5640 #endif
5641         if (rc != 0)
5642                 printf("\tFailed to get bypass configuration for port = %d\n",
5643                        port_id);
5644 }
5645
5646 cmdline_parse_token_string_t cmd_showbypass_config_show =
5647         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5648                         show, "show");
5649 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5650         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5651                         bypass, "bypass");
5652 cmdline_parse_token_string_t cmd_showbypass_config_config =
5653         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5654                         config, "config");
5655 cmdline_parse_token_num_t cmd_showbypass_config_port =
5656         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5657                                 port_id, UINT16);
5658
5659 cmdline_parse_inst_t cmd_show_bypass_config = {
5660         .f = cmd_show_bypass_config_parsed,
5661         .help_str = "show bypass config <port_id>: "
5662                     "Show the NIC bypass config for port_id",
5663         .data = NULL,
5664         .tokens = {
5665                 (void *)&cmd_showbypass_config_show,
5666                 (void *)&cmd_showbypass_config_bypass,
5667                 (void *)&cmd_showbypass_config_config,
5668                 (void *)&cmd_showbypass_config_port,
5669                 NULL,
5670         },
5671 };
5672
5673 #ifdef RTE_LIBRTE_PMD_BOND
5674 /* *** SET BONDING MODE *** */
5675 struct cmd_set_bonding_mode_result {
5676         cmdline_fixed_string_t set;
5677         cmdline_fixed_string_t bonding;
5678         cmdline_fixed_string_t mode;
5679         uint8_t value;
5680         portid_t port_id;
5681 };
5682
5683 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5684                 __rte_unused  struct cmdline *cl,
5685                 __rte_unused void *data)
5686 {
5687         struct cmd_set_bonding_mode_result *res = parsed_result;
5688         portid_t port_id = res->port_id;
5689
5690         /* Set the bonding mode for the relevant port. */
5691         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5692                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5693 }
5694
5695 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5696 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5697                 set, "set");
5698 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5699 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5700                 bonding, "bonding");
5701 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5702 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5703                 mode, "mode");
5704 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5705 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5706                 value, UINT8);
5707 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5708 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5709                 port_id, UINT16);
5710
5711 cmdline_parse_inst_t cmd_set_bonding_mode = {
5712                 .f = cmd_set_bonding_mode_parsed,
5713                 .help_str = "set bonding mode <mode_value> <port_id>: "
5714                         "Set the bonding mode for port_id",
5715                 .data = NULL,
5716                 .tokens = {
5717                                 (void *) &cmd_setbonding_mode_set,
5718                                 (void *) &cmd_setbonding_mode_bonding,
5719                                 (void *) &cmd_setbonding_mode_mode,
5720                                 (void *) &cmd_setbonding_mode_value,
5721                                 (void *) &cmd_setbonding_mode_port,
5722                                 NULL
5723                 }
5724 };
5725
5726 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5727 struct cmd_set_bonding_lacp_dedicated_queues_result {
5728         cmdline_fixed_string_t set;
5729         cmdline_fixed_string_t bonding;
5730         cmdline_fixed_string_t lacp;
5731         cmdline_fixed_string_t dedicated_queues;
5732         portid_t port_id;
5733         cmdline_fixed_string_t mode;
5734 };
5735
5736 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5737                 __rte_unused  struct cmdline *cl,
5738                 __rte_unused void *data)
5739 {
5740         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5741         portid_t port_id = res->port_id;
5742         struct rte_port *port;
5743
5744         port = &ports[port_id];
5745
5746         /** Check if the port is not started **/
5747         if (port->port_status != RTE_PORT_STOPPED) {
5748                 printf("Please stop port %d first\n", port_id);
5749                 return;
5750         }
5751
5752         if (!strcmp(res->mode, "enable")) {
5753                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5754                         printf("Dedicate queues for LACP control packets"
5755                                         " enabled\n");
5756                 else
5757                         printf("Enabling dedicate queues for LACP control "
5758                                         "packets on port %d failed\n", port_id);
5759         } else if (!strcmp(res->mode, "disable")) {
5760                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5761                         printf("Dedicated queues for LACP control packets "
5762                                         "disabled\n");
5763                 else
5764                         printf("Disabling dedicated queues for LACP control "
5765                                         "traffic on port %d failed\n", port_id);
5766         }
5767 }
5768
5769 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5771                 set, "set");
5772 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5774                 bonding, "bonding");
5775 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5776 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5777                 lacp, "lacp");
5778 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5779 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5780                 dedicated_queues, "dedicated_queues");
5781 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5782 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5783                 port_id, UINT16);
5784 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5785 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5786                 mode, "enable#disable");
5787
5788 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5789                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5790                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5791                         "enable|disable: "
5792                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5793                 .data = NULL,
5794                 .tokens = {
5795                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5796                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5797                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5798                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5799                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5800                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5801                         NULL
5802                 }
5803 };
5804
5805 /* *** SET BALANCE XMIT POLICY *** */
5806 struct cmd_set_bonding_balance_xmit_policy_result {
5807         cmdline_fixed_string_t set;
5808         cmdline_fixed_string_t bonding;
5809         cmdline_fixed_string_t balance_xmit_policy;
5810         portid_t port_id;
5811         cmdline_fixed_string_t policy;
5812 };
5813
5814 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5815                 __rte_unused  struct cmdline *cl,
5816                 __rte_unused void *data)
5817 {
5818         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5819         portid_t port_id = res->port_id;
5820         uint8_t policy;
5821
5822         if (!strcmp(res->policy, "l2")) {
5823                 policy = BALANCE_XMIT_POLICY_LAYER2;
5824         } else if (!strcmp(res->policy, "l23")) {
5825                 policy = BALANCE_XMIT_POLICY_LAYER23;
5826         } else if (!strcmp(res->policy, "l34")) {
5827                 policy = BALANCE_XMIT_POLICY_LAYER34;
5828         } else {
5829                 printf("\t Invalid xmit policy selection");
5830                 return;
5831         }
5832
5833         /* Set the bonding mode for the relevant port. */
5834         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5835                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5836                                 port_id);
5837         }
5838 }
5839
5840 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5841 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5842                 set, "set");
5843 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5844 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5845                 bonding, "bonding");
5846 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5848                 balance_xmit_policy, "balance_xmit_policy");
5849 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5850 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5851                 port_id, UINT16);
5852 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5854                 policy, "l2#l23#l34");
5855
5856 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5857                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5858                 .help_str = "set bonding balance_xmit_policy <port_id> "
5859                         "l2|l23|l34: "
5860                         "Set the bonding balance_xmit_policy for port_id",
5861                 .data = NULL,
5862                 .tokens = {
5863                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5864                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5865                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5866                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5867                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5868                                 NULL
5869                 }
5870 };
5871
5872 /* *** SHOW NIC BONDING CONFIGURATION *** */
5873 struct cmd_show_bonding_config_result {
5874         cmdline_fixed_string_t show;
5875         cmdline_fixed_string_t bonding;
5876         cmdline_fixed_string_t config;
5877         portid_t port_id;
5878 };
5879
5880 static void cmd_show_bonding_config_parsed(void *parsed_result,
5881                 __rte_unused  struct cmdline *cl,
5882                 __rte_unused void *data)
5883 {
5884         struct cmd_show_bonding_config_result *res = parsed_result;
5885         int bonding_mode, agg_mode;
5886         portid_t slaves[RTE_MAX_ETHPORTS];
5887         int num_slaves, num_active_slaves;
5888         int primary_id;
5889         int i;
5890         portid_t port_id = res->port_id;
5891
5892         /* Display the bonding mode.*/
5893         bonding_mode = rte_eth_bond_mode_get(port_id);
5894         if (bonding_mode < 0) {
5895                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5896                 return;
5897         } else
5898                 printf("\tBonding mode: %d\n", bonding_mode);
5899
5900         if (bonding_mode == BONDING_MODE_BALANCE) {
5901                 int balance_xmit_policy;
5902
5903                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5904                 if (balance_xmit_policy < 0) {
5905                         printf("\tFailed to get balance xmit policy for port = %d\n",
5906                                         port_id);
5907                         return;
5908                 } else {
5909                         printf("\tBalance Xmit Policy: ");
5910
5911                         switch (balance_xmit_policy) {
5912                         case BALANCE_XMIT_POLICY_LAYER2:
5913                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5914                                 break;
5915                         case BALANCE_XMIT_POLICY_LAYER23:
5916                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5917                                 break;
5918                         case BALANCE_XMIT_POLICY_LAYER34:
5919                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5920                                 break;
5921                         }
5922                         printf("\n");
5923                 }
5924         }
5925
5926         if (bonding_mode == BONDING_MODE_8023AD) {
5927                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5928                 printf("\tIEEE802.3AD Aggregator Mode: ");
5929                 switch (agg_mode) {
5930                 case AGG_BANDWIDTH:
5931                         printf("bandwidth");
5932                         break;
5933                 case AGG_STABLE:
5934                         printf("stable");
5935                         break;
5936                 case AGG_COUNT:
5937                         printf("count");
5938                         break;
5939                 }
5940                 printf("\n");
5941         }
5942
5943         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5944
5945         if (num_slaves < 0) {
5946                 printf("\tFailed to get slave list for port = %d\n", port_id);
5947                 return;
5948         }
5949         if (num_slaves > 0) {
5950                 printf("\tSlaves (%d): [", num_slaves);
5951                 for (i = 0; i < num_slaves - 1; i++)
5952                         printf("%d ", slaves[i]);
5953
5954                 printf("%d]\n", slaves[num_slaves - 1]);
5955         } else {
5956                 printf("\tSlaves: []\n");
5957
5958         }
5959
5960         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5961                         RTE_MAX_ETHPORTS);
5962
5963         if (num_active_slaves < 0) {
5964                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5965                 return;
5966         }
5967         if (num_active_slaves > 0) {
5968                 printf("\tActive Slaves (%d): [", num_active_slaves);
5969                 for (i = 0; i < num_active_slaves - 1; i++)
5970                         printf("%d ", slaves[i]);
5971
5972                 printf("%d]\n", slaves[num_active_slaves - 1]);
5973
5974         } else {
5975                 printf("\tActive Slaves: []\n");
5976
5977         }
5978
5979         primary_id = rte_eth_bond_primary_get(port_id);
5980         if (primary_id < 0) {
5981                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5982                 return;
5983         } else
5984                 printf("\tPrimary: [%d]\n", primary_id);
5985
5986 }
5987
5988 cmdline_parse_token_string_t cmd_showbonding_config_show =
5989 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5990                 show, "show");
5991 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5992 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5993                 bonding, "bonding");
5994 cmdline_parse_token_string_t cmd_showbonding_config_config =
5995 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5996                 config, "config");
5997 cmdline_parse_token_num_t cmd_showbonding_config_port =
5998 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5999                 port_id, UINT16);
6000
6001 cmdline_parse_inst_t cmd_show_bonding_config = {
6002                 .f = cmd_show_bonding_config_parsed,
6003                 .help_str = "show bonding config <port_id>: "
6004                         "Show the bonding config for port_id",
6005                 .data = NULL,
6006                 .tokens = {
6007                                 (void *)&cmd_showbonding_config_show,
6008                                 (void *)&cmd_showbonding_config_bonding,
6009                                 (void *)&cmd_showbonding_config_config,
6010                                 (void *)&cmd_showbonding_config_port,
6011                                 NULL
6012                 }
6013 };
6014
6015 /* *** SET BONDING PRIMARY *** */
6016 struct cmd_set_bonding_primary_result {
6017         cmdline_fixed_string_t set;
6018         cmdline_fixed_string_t bonding;
6019         cmdline_fixed_string_t primary;
6020         portid_t slave_id;
6021         portid_t port_id;
6022 };
6023
6024 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6025                 __rte_unused  struct cmdline *cl,
6026                 __rte_unused void *data)
6027 {
6028         struct cmd_set_bonding_primary_result *res = parsed_result;
6029         portid_t master_port_id = res->port_id;
6030         portid_t slave_port_id = res->slave_id;
6031
6032         /* Set the primary slave for a bonded device. */
6033         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6034                 printf("\t Failed to set primary slave for port = %d.\n",
6035                                 master_port_id);
6036                 return;
6037         }
6038         init_port_config();
6039 }
6040
6041 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6042 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6043                 set, "set");
6044 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6045 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6046                 bonding, "bonding");
6047 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6048 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6049                 primary, "primary");
6050 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6051 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6052                 slave_id, UINT16);
6053 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6054 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6055                 port_id, UINT16);
6056
6057 cmdline_parse_inst_t cmd_set_bonding_primary = {
6058                 .f = cmd_set_bonding_primary_parsed,
6059                 .help_str = "set bonding primary <slave_id> <port_id>: "
6060                         "Set the primary slave for port_id",
6061                 .data = NULL,
6062                 .tokens = {
6063                                 (void *)&cmd_setbonding_primary_set,
6064                                 (void *)&cmd_setbonding_primary_bonding,
6065                                 (void *)&cmd_setbonding_primary_primary,
6066                                 (void *)&cmd_setbonding_primary_slave,
6067                                 (void *)&cmd_setbonding_primary_port,
6068                                 NULL
6069                 }
6070 };
6071
6072 /* *** ADD SLAVE *** */
6073 struct cmd_add_bonding_slave_result {
6074         cmdline_fixed_string_t add;
6075         cmdline_fixed_string_t bonding;
6076         cmdline_fixed_string_t slave;
6077         portid_t slave_id;
6078         portid_t port_id;
6079 };
6080
6081 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6082                 __rte_unused  struct cmdline *cl,
6083                 __rte_unused void *data)
6084 {
6085         struct cmd_add_bonding_slave_result *res = parsed_result;
6086         portid_t master_port_id = res->port_id;
6087         portid_t slave_port_id = res->slave_id;
6088
6089         /* add the slave for a bonded device. */
6090         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6091                 printf("\t Failed to add slave %d to master port = %d.\n",
6092                                 slave_port_id, master_port_id);
6093                 return;
6094         }
6095         init_port_config();
6096         set_port_slave_flag(slave_port_id);
6097 }
6098
6099 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6100 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6101                 add, "add");
6102 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6103 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6104                 bonding, "bonding");
6105 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6106 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6107                 slave, "slave");
6108 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6109 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6110                 slave_id, UINT16);
6111 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6112 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6113                 port_id, UINT16);
6114
6115 cmdline_parse_inst_t cmd_add_bonding_slave = {
6116                 .f = cmd_add_bonding_slave_parsed,
6117                 .help_str = "add bonding slave <slave_id> <port_id>: "
6118                         "Add a slave device to a bonded device",
6119                 .data = NULL,
6120                 .tokens = {
6121                                 (void *)&cmd_addbonding_slave_add,
6122                                 (void *)&cmd_addbonding_slave_bonding,
6123                                 (void *)&cmd_addbonding_slave_slave,
6124                                 (void *)&cmd_addbonding_slave_slaveid,
6125                                 (void *)&cmd_addbonding_slave_port,
6126                                 NULL
6127                 }
6128 };
6129
6130 /* *** REMOVE SLAVE *** */
6131 struct cmd_remove_bonding_slave_result {
6132         cmdline_fixed_string_t remove;
6133         cmdline_fixed_string_t bonding;
6134         cmdline_fixed_string_t slave;
6135         portid_t slave_id;
6136         portid_t port_id;
6137 };
6138
6139 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6140                 __rte_unused  struct cmdline *cl,
6141                 __rte_unused void *data)
6142 {
6143         struct cmd_remove_bonding_slave_result *res = parsed_result;
6144         portid_t master_port_id = res->port_id;
6145         portid_t slave_port_id = res->slave_id;
6146
6147         /* remove the slave from a bonded device. */
6148         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6149                 printf("\t Failed to remove slave %d from master port = %d.\n",
6150                                 slave_port_id, master_port_id);
6151                 return;
6152         }
6153         init_port_config();
6154         clear_port_slave_flag(slave_port_id);
6155 }
6156
6157 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6158                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6159                                 remove, "remove");
6160 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6161                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6162                                 bonding, "bonding");
6163 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6164                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6165                                 slave, "slave");
6166 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6167                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6168                                 slave_id, UINT16);
6169 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6170                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6171                                 port_id, UINT16);
6172
6173 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6174                 .f = cmd_remove_bonding_slave_parsed,
6175                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6176                         "Remove a slave device from a bonded device",
6177                 .data = NULL,
6178                 .tokens = {
6179                                 (void *)&cmd_removebonding_slave_remove,
6180                                 (void *)&cmd_removebonding_slave_bonding,
6181                                 (void *)&cmd_removebonding_slave_slave,
6182                                 (void *)&cmd_removebonding_slave_slaveid,
6183                                 (void *)&cmd_removebonding_slave_port,
6184                                 NULL
6185                 }
6186 };
6187
6188 /* *** CREATE BONDED DEVICE *** */
6189 struct cmd_create_bonded_device_result {
6190         cmdline_fixed_string_t create;
6191         cmdline_fixed_string_t bonded;
6192         cmdline_fixed_string_t device;
6193         uint8_t mode;
6194         uint8_t socket;
6195 };
6196
6197 static int bond_dev_num = 0;
6198
6199 static void cmd_create_bonded_device_parsed(void *parsed_result,
6200                 __rte_unused  struct cmdline *cl,
6201                 __rte_unused void *data)
6202 {
6203         struct cmd_create_bonded_device_result *res = parsed_result;
6204         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6205         int port_id;
6206         int ret;
6207
6208         if (test_done == 0) {
6209                 printf("Please stop forwarding first\n");
6210                 return;
6211         }
6212
6213         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6214                         bond_dev_num++);
6215
6216         /* Create a new bonded device. */
6217         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6218         if (port_id < 0) {
6219                 printf("\t Failed to create bonded device.\n");
6220                 return;
6221         } else {
6222                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6223                                 port_id);
6224
6225                 /* Update number of ports */
6226                 nb_ports = rte_eth_dev_count_avail();
6227                 reconfig(port_id, res->socket);
6228                 ret = rte_eth_promiscuous_enable(port_id);
6229                 if (ret != 0)
6230                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6231                                 port_id, rte_strerror(-ret));
6232
6233                 ports[port_id].need_setup = 0;
6234                 ports[port_id].port_status = RTE_PORT_STOPPED;
6235         }
6236
6237 }
6238
6239 cmdline_parse_token_string_t cmd_createbonded_device_create =
6240                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6241                                 create, "create");
6242 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6243                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6244                                 bonded, "bonded");
6245 cmdline_parse_token_string_t cmd_createbonded_device_device =
6246                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6247                                 device, "device");
6248 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6249                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6250                                 mode, UINT8);
6251 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6252                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6253                                 socket, UINT8);
6254
6255 cmdline_parse_inst_t cmd_create_bonded_device = {
6256                 .f = cmd_create_bonded_device_parsed,
6257                 .help_str = "create bonded device <mode> <socket>: "
6258                         "Create a new bonded device with specific bonding mode and socket",
6259                 .data = NULL,
6260                 .tokens = {
6261                                 (void *)&cmd_createbonded_device_create,
6262                                 (void *)&cmd_createbonded_device_bonded,
6263                                 (void *)&cmd_createbonded_device_device,
6264                                 (void *)&cmd_createbonded_device_mode,
6265                                 (void *)&cmd_createbonded_device_socket,
6266                                 NULL
6267                 }
6268 };
6269
6270 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6271 struct cmd_set_bond_mac_addr_result {
6272         cmdline_fixed_string_t set;
6273         cmdline_fixed_string_t bonding;
6274         cmdline_fixed_string_t mac_addr;
6275         uint16_t port_num;
6276         struct rte_ether_addr address;
6277 };
6278
6279 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6280                 __rte_unused  struct cmdline *cl,
6281                 __rte_unused void *data)
6282 {
6283         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6284         int ret;
6285
6286         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6287                 return;
6288
6289         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6290
6291         /* check the return value and print it if is < 0 */
6292         if (ret < 0)
6293                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6294 }
6295
6296 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6297                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6298 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6299                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6300                                 "bonding");
6301 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6302                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6303                                 "mac_addr");
6304 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6305                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6306                                 port_num, UINT16);
6307 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6308                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6309
6310 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6311                 .f = cmd_set_bond_mac_addr_parsed,
6312                 .data = (void *) 0,
6313                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6314                 .tokens = {
6315                                 (void *)&cmd_set_bond_mac_addr_set,
6316                                 (void *)&cmd_set_bond_mac_addr_bonding,
6317                                 (void *)&cmd_set_bond_mac_addr_mac,
6318                                 (void *)&cmd_set_bond_mac_addr_portnum,
6319                                 (void *)&cmd_set_bond_mac_addr_addr,
6320                                 NULL
6321                 }
6322 };
6323
6324
6325 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6326 struct cmd_set_bond_mon_period_result {
6327         cmdline_fixed_string_t set;
6328         cmdline_fixed_string_t bonding;
6329         cmdline_fixed_string_t mon_period;
6330         uint16_t port_num;
6331         uint32_t period_ms;
6332 };
6333
6334 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6335                 __rte_unused  struct cmdline *cl,
6336                 __rte_unused void *data)
6337 {
6338         struct cmd_set_bond_mon_period_result *res = parsed_result;
6339         int ret;
6340
6341         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6342
6343         /* check the return value and print it if is < 0 */
6344         if (ret < 0)
6345                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6346 }
6347
6348 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6349                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6350                                 set, "set");
6351 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6352                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6353                                 bonding, "bonding");
6354 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6355                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6356                                 mon_period,     "mon_period");
6357 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6358                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6359                                 port_num, UINT16);
6360 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6361                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6362                                 period_ms, UINT32);
6363
6364 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6365                 .f = cmd_set_bond_mon_period_parsed,
6366                 .data = (void *) 0,
6367                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6368                 .tokens = {
6369                                 (void *)&cmd_set_bond_mon_period_set,
6370                                 (void *)&cmd_set_bond_mon_period_bonding,
6371                                 (void *)&cmd_set_bond_mon_period_mon_period,
6372                                 (void *)&cmd_set_bond_mon_period_portnum,
6373                                 (void *)&cmd_set_bond_mon_period_period_ms,
6374                                 NULL
6375                 }
6376 };
6377
6378
6379
6380 struct cmd_set_bonding_agg_mode_policy_result {
6381         cmdline_fixed_string_t set;
6382         cmdline_fixed_string_t bonding;
6383         cmdline_fixed_string_t agg_mode;
6384         uint16_t port_num;
6385         cmdline_fixed_string_t policy;
6386 };
6387
6388
6389 static void
6390 cmd_set_bonding_agg_mode(void *parsed_result,
6391                 __rte_unused struct cmdline *cl,
6392                 __rte_unused void *data)
6393 {
6394         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6395         uint8_t policy = AGG_BANDWIDTH;
6396
6397         if (!strcmp(res->policy, "bandwidth"))
6398                 policy = AGG_BANDWIDTH;
6399         else if (!strcmp(res->policy, "stable"))
6400                 policy = AGG_STABLE;
6401         else if (!strcmp(res->policy, "count"))
6402                 policy = AGG_COUNT;
6403
6404         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6405 }
6406
6407
6408 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6409         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6410                                 set, "set");
6411 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6413                                 bonding, "bonding");
6414
6415 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6416         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6417                                 agg_mode, "agg_mode");
6418
6419 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6420         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6421                                 port_num, UINT16);
6422
6423 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6424         TOKEN_STRING_INITIALIZER(
6425                         struct cmd_set_bonding_balance_xmit_policy_result,
6426                 policy, "stable#bandwidth#count");
6427
6428 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6429         .f = cmd_set_bonding_agg_mode,
6430         .data = (void *) 0,
6431         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6432         .tokens = {
6433                         (void *)&cmd_set_bonding_agg_mode_set,
6434                         (void *)&cmd_set_bonding_agg_mode_bonding,
6435                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6436                         (void *)&cmd_set_bonding_agg_mode_portnum,
6437                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6438                         NULL
6439                 }
6440 };
6441
6442
6443 #endif /* RTE_LIBRTE_PMD_BOND */
6444
6445 /* *** SET FORWARDING MODE *** */
6446 struct cmd_set_fwd_mode_result {
6447         cmdline_fixed_string_t set;
6448         cmdline_fixed_string_t fwd;
6449         cmdline_fixed_string_t mode;
6450 };
6451
6452 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6453                                     __rte_unused struct cmdline *cl,
6454                                     __rte_unused void *data)
6455 {
6456         struct cmd_set_fwd_mode_result *res = parsed_result;
6457
6458         retry_enabled = 0;
6459         set_pkt_forwarding_mode(res->mode);
6460 }
6461
6462 cmdline_parse_token_string_t cmd_setfwd_set =
6463         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6464 cmdline_parse_token_string_t cmd_setfwd_fwd =
6465         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6466 cmdline_parse_token_string_t cmd_setfwd_mode =
6467         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6468                 "" /* defined at init */);
6469
6470 cmdline_parse_inst_t cmd_set_fwd_mode = {
6471         .f = cmd_set_fwd_mode_parsed,
6472         .data = NULL,
6473         .help_str = NULL, /* defined at init */
6474         .tokens = {
6475                 (void *)&cmd_setfwd_set,
6476                 (void *)&cmd_setfwd_fwd,
6477                 (void *)&cmd_setfwd_mode,
6478                 NULL,
6479         },
6480 };
6481
6482 static void cmd_set_fwd_mode_init(void)
6483 {
6484         char *modes, *c;
6485         static char token[128];
6486         static char help[256];
6487         cmdline_parse_token_string_t *token_struct;
6488
6489         modes = list_pkt_forwarding_modes();
6490         snprintf(help, sizeof(help), "set fwd %s: "
6491                 "Set packet forwarding mode", modes);
6492         cmd_set_fwd_mode.help_str = help;
6493
6494         /* string token separator is # */
6495         for (c = token; *modes != '\0'; modes++)
6496                 if (*modes == '|')
6497                         *c++ = '#';
6498                 else
6499                         *c++ = *modes;
6500         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6501         token_struct->string_data.str = token;
6502 }
6503
6504 /* *** SET RETRY FORWARDING MODE *** */
6505 struct cmd_set_fwd_retry_mode_result {
6506         cmdline_fixed_string_t set;
6507         cmdline_fixed_string_t fwd;
6508         cmdline_fixed_string_t mode;
6509         cmdline_fixed_string_t retry;
6510 };
6511
6512 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6513                             __rte_unused struct cmdline *cl,
6514                             __rte_unused void *data)
6515 {
6516         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6517
6518         retry_enabled = 1;
6519         set_pkt_forwarding_mode(res->mode);
6520 }
6521
6522 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6523         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6524                         set, "set");
6525 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6526         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6527                         fwd, "fwd");
6528 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6529         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6530                         mode,
6531                 "" /* defined at init */);
6532 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6533         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6534                         retry, "retry");
6535
6536 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6537         .f = cmd_set_fwd_retry_mode_parsed,
6538         .data = NULL,
6539         .help_str = NULL, /* defined at init */
6540         .tokens = {
6541                 (void *)&cmd_setfwd_retry_set,
6542                 (void *)&cmd_setfwd_retry_fwd,
6543                 (void *)&cmd_setfwd_retry_mode,
6544                 (void *)&cmd_setfwd_retry_retry,
6545                 NULL,
6546         },
6547 };
6548
6549 static void cmd_set_fwd_retry_mode_init(void)
6550 {
6551         char *modes, *c;
6552         static char token[128];
6553         static char help[256];
6554         cmdline_parse_token_string_t *token_struct;
6555
6556         modes = list_pkt_forwarding_retry_modes();
6557         snprintf(help, sizeof(help), "set fwd %s retry: "
6558                 "Set packet forwarding mode with retry", modes);
6559         cmd_set_fwd_retry_mode.help_str = help;
6560
6561         /* string token separator is # */
6562         for (c = token; *modes != '\0'; modes++)
6563                 if (*modes == '|')
6564                         *c++ = '#';
6565                 else
6566                         *c++ = *modes;
6567         token_struct = (cmdline_parse_token_string_t *)
6568                 cmd_set_fwd_retry_mode.tokens[2];
6569         token_struct->string_data.str = token;
6570 }
6571
6572 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6573 struct cmd_set_burst_tx_retry_result {
6574         cmdline_fixed_string_t set;
6575         cmdline_fixed_string_t burst;
6576         cmdline_fixed_string_t tx;
6577         cmdline_fixed_string_t delay;
6578         uint32_t time;
6579         cmdline_fixed_string_t retry;
6580         uint32_t retry_num;
6581 };
6582
6583 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6584                                         __rte_unused struct cmdline *cl,
6585                                         __rte_unused void *data)
6586 {
6587         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6588
6589         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6590                 && !strcmp(res->tx, "tx")) {
6591                 if (!strcmp(res->delay, "delay"))
6592                         burst_tx_delay_time = res->time;
6593                 if (!strcmp(res->retry, "retry"))
6594                         burst_tx_retry_num = res->retry_num;
6595         }
6596
6597 }
6598
6599 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6600         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6601 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6602         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6603                                  "burst");
6604 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6605         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6606 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6608 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6609         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6610 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6611         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6612 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6613         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6614
6615 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6616         .f = cmd_set_burst_tx_retry_parsed,
6617         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6618         .tokens = {
6619                 (void *)&cmd_set_burst_tx_retry_set,
6620                 (void *)&cmd_set_burst_tx_retry_burst,
6621                 (void *)&cmd_set_burst_tx_retry_tx,
6622                 (void *)&cmd_set_burst_tx_retry_delay,
6623                 (void *)&cmd_set_burst_tx_retry_time,
6624                 (void *)&cmd_set_burst_tx_retry_retry,
6625                 (void *)&cmd_set_burst_tx_retry_retry_num,
6626                 NULL,
6627         },
6628 };
6629
6630 /* *** SET PROMISC MODE *** */
6631 struct cmd_set_promisc_mode_result {
6632         cmdline_fixed_string_t set;
6633         cmdline_fixed_string_t promisc;
6634         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6635         uint16_t port_num;               /* valid if "allports" argument == 0 */
6636         cmdline_fixed_string_t mode;
6637 };
6638
6639 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6640                                         __rte_unused struct cmdline *cl,
6641                                         void *allports)
6642 {
6643         struct cmd_set_promisc_mode_result *res = parsed_result;
6644         int enable;
6645         portid_t i;
6646
6647         if (!strcmp(res->mode, "on"))
6648                 enable = 1;
6649         else
6650                 enable = 0;
6651
6652         /* all ports */
6653         if (allports) {
6654                 RTE_ETH_FOREACH_DEV(i)
6655                         eth_set_promisc_mode(i, enable);
6656         } else {
6657                 eth_set_promisc_mode(res->port_num, enable);
6658         }
6659 }
6660
6661 cmdline_parse_token_string_t cmd_setpromisc_set =
6662         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6663 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6664         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6665                                  "promisc");
6666 cmdline_parse_token_string_t cmd_setpromisc_portall =
6667         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6668                                  "all");
6669 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6670         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6671                               UINT16);
6672 cmdline_parse_token_string_t cmd_setpromisc_mode =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6674                                  "on#off");
6675
6676 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6677         .f = cmd_set_promisc_mode_parsed,
6678         .data = (void *)1,
6679         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6680         .tokens = {
6681                 (void *)&cmd_setpromisc_set,
6682                 (void *)&cmd_setpromisc_promisc,
6683                 (void *)&cmd_setpromisc_portall,
6684                 (void *)&cmd_setpromisc_mode,
6685                 NULL,
6686         },
6687 };
6688
6689 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6690         .f = cmd_set_promisc_mode_parsed,
6691         .data = (void *)0,
6692         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6693         .tokens = {
6694                 (void *)&cmd_setpromisc_set,
6695                 (void *)&cmd_setpromisc_promisc,
6696                 (void *)&cmd_setpromisc_portnum,
6697                 (void *)&cmd_setpromisc_mode,
6698                 NULL,
6699         },
6700 };
6701
6702 /* *** SET ALLMULTI MODE *** */
6703 struct cmd_set_allmulti_mode_result {
6704         cmdline_fixed_string_t set;
6705         cmdline_fixed_string_t allmulti;
6706         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6707         uint16_t port_num;               /* valid if "allports" argument == 0 */
6708         cmdline_fixed_string_t mode;
6709 };
6710
6711 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6712                                         __rte_unused struct cmdline *cl,
6713                                         void *allports)
6714 {
6715         struct cmd_set_allmulti_mode_result *res = parsed_result;
6716         int enable;
6717         portid_t i;
6718
6719         if (!strcmp(res->mode, "on"))
6720                 enable = 1;
6721         else
6722                 enable = 0;
6723
6724         /* all ports */
6725         if (allports) {
6726                 RTE_ETH_FOREACH_DEV(i) {
6727                         eth_set_allmulticast_mode(i, enable);
6728                 }
6729         }
6730         else {
6731                 eth_set_allmulticast_mode(res->port_num, enable);
6732         }
6733 }
6734
6735 cmdline_parse_token_string_t cmd_setallmulti_set =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6737 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6738         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6739                                  "allmulti");
6740 cmdline_parse_token_string_t cmd_setallmulti_portall =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6742                                  "all");
6743 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6744         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6745                               UINT16);
6746 cmdline_parse_token_string_t cmd_setallmulti_mode =
6747         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6748                                  "on#off");
6749
6750 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6751         .f = cmd_set_allmulti_mode_parsed,
6752         .data = (void *)1,
6753         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6754         .tokens = {
6755                 (void *)&cmd_setallmulti_set,
6756                 (void *)&cmd_setallmulti_allmulti,
6757                 (void *)&cmd_setallmulti_portall,
6758                 (void *)&cmd_setallmulti_mode,
6759                 NULL,
6760         },
6761 };
6762
6763 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6764         .f = cmd_set_allmulti_mode_parsed,
6765         .data = (void *)0,
6766         .help_str = "set allmulti <port_id> on|off: "
6767                 "Set allmulti mode on port_id",
6768         .tokens = {
6769                 (void *)&cmd_setallmulti_set,
6770                 (void *)&cmd_setallmulti_allmulti,
6771                 (void *)&cmd_setallmulti_portnum,
6772                 (void *)&cmd_setallmulti_mode,
6773                 NULL,
6774         },
6775 };
6776
6777 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6778 struct cmd_link_flow_ctrl_set_result {
6779         cmdline_fixed_string_t set;
6780         cmdline_fixed_string_t flow_ctrl;
6781         cmdline_fixed_string_t rx;
6782         cmdline_fixed_string_t rx_lfc_mode;
6783         cmdline_fixed_string_t tx;
6784         cmdline_fixed_string_t tx_lfc_mode;
6785         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6786         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6787         cmdline_fixed_string_t autoneg_str;
6788         cmdline_fixed_string_t autoneg;
6789         cmdline_fixed_string_t hw_str;
6790         uint32_t high_water;
6791         cmdline_fixed_string_t lw_str;
6792         uint32_t low_water;
6793         cmdline_fixed_string_t pt_str;
6794         uint16_t pause_time;
6795         cmdline_fixed_string_t xon_str;
6796         uint16_t send_xon;
6797         portid_t port_id;
6798 };
6799
6800 cmdline_parse_token_string_t cmd_lfc_set_set =
6801         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6802                                 set, "set");
6803 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6804         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6805                                 flow_ctrl, "flow_ctrl");
6806 cmdline_parse_token_string_t cmd_lfc_set_rx =
6807         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6808                                 rx, "rx");
6809 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6810         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6811                                 rx_lfc_mode, "on#off");
6812 cmdline_parse_token_string_t cmd_lfc_set_tx =
6813         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6814                                 tx, "tx");
6815 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6816         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6817                                 tx_lfc_mode, "on#off");
6818 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6819         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6820                                 hw_str, "high_water");
6821 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6822         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6823                                 high_water, UINT32);
6824 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6825         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6826                                 lw_str, "low_water");
6827 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6828         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6829                                 low_water, UINT32);
6830 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6831         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6832                                 pt_str, "pause_time");
6833 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6834         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6835                                 pause_time, UINT16);
6836 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6837         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6838                                 xon_str, "send_xon");
6839 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6840         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6841                                 send_xon, UINT16);
6842 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6843         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6844                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6845 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6846         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6847                                 mac_ctrl_frame_fwd_mode, "on#off");
6848 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6849         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6850                                 autoneg_str, "autoneg");
6851 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6852         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6853                                 autoneg, "on#off");
6854 cmdline_parse_token_num_t cmd_lfc_set_portid =
6855         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6856                                 port_id, UINT16);
6857
6858 /* forward declaration */
6859 static void
6860 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6861                               void *data);
6862
6863 cmdline_parse_inst_t cmd_link_flow_control_set = {
6864         .f = cmd_link_flow_ctrl_set_parsed,
6865         .data = NULL,
6866         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6867                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6868                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6869         .tokens = {
6870                 (void *)&cmd_lfc_set_set,
6871                 (void *)&cmd_lfc_set_flow_ctrl,
6872                 (void *)&cmd_lfc_set_rx,
6873                 (void *)&cmd_lfc_set_rx_mode,
6874                 (void *)&cmd_lfc_set_tx,
6875                 (void *)&cmd_lfc_set_tx_mode,
6876                 (void *)&cmd_lfc_set_high_water,
6877                 (void *)&cmd_lfc_set_low_water,
6878                 (void *)&cmd_lfc_set_pause_time,
6879                 (void *)&cmd_lfc_set_send_xon,
6880                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6881                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6882                 (void *)&cmd_lfc_set_autoneg_str,
6883                 (void *)&cmd_lfc_set_autoneg,
6884                 (void *)&cmd_lfc_set_portid,
6885                 NULL,
6886         },
6887 };
6888
6889 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6890         .f = cmd_link_flow_ctrl_set_parsed,
6891         .data = (void *)&cmd_link_flow_control_set_rx,
6892         .help_str = "set flow_ctrl rx on|off <port_id>: "
6893                 "Change rx flow control parameter",
6894         .tokens = {
6895                 (void *)&cmd_lfc_set_set,
6896                 (void *)&cmd_lfc_set_flow_ctrl,
6897                 (void *)&cmd_lfc_set_rx,
6898                 (void *)&cmd_lfc_set_rx_mode,
6899                 (void *)&cmd_lfc_set_portid,
6900                 NULL,
6901         },
6902 };
6903
6904 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6905         .f = cmd_link_flow_ctrl_set_parsed,
6906         .data = (void *)&cmd_link_flow_control_set_tx,
6907         .help_str = "set flow_ctrl tx on|off <port_id>: "
6908                 "Change tx flow control parameter",
6909         .tokens = {
6910                 (void *)&cmd_lfc_set_set,
6911                 (void *)&cmd_lfc_set_flow_ctrl,
6912                 (void *)&cmd_lfc_set_tx,
6913                 (void *)&cmd_lfc_set_tx_mode,
6914                 (void *)&cmd_lfc_set_portid,
6915                 NULL,
6916         },
6917 };
6918
6919 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6920         .f = cmd_link_flow_ctrl_set_parsed,
6921         .data = (void *)&cmd_link_flow_control_set_hw,
6922         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6923                 "Change high water flow control parameter",
6924         .tokens = {
6925                 (void *)&cmd_lfc_set_set,
6926                 (void *)&cmd_lfc_set_flow_ctrl,
6927                 (void *)&cmd_lfc_set_high_water_str,
6928                 (void *)&cmd_lfc_set_high_water,
6929                 (void *)&cmd_lfc_set_portid,
6930                 NULL,
6931         },
6932 };
6933
6934 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6935         .f = cmd_link_flow_ctrl_set_parsed,
6936         .data = (void *)&cmd_link_flow_control_set_lw,
6937         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6938                 "Change low water flow control parameter",
6939         .tokens = {
6940                 (void *)&cmd_lfc_set_set,
6941                 (void *)&cmd_lfc_set_flow_ctrl,
6942                 (void *)&cmd_lfc_set_low_water_str,
6943                 (void *)&cmd_lfc_set_low_water,
6944                 (void *)&cmd_lfc_set_portid,
6945                 NULL,
6946         },
6947 };
6948
6949 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6950         .f = cmd_link_flow_ctrl_set_parsed,
6951         .data = (void *)&cmd_link_flow_control_set_pt,
6952         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6953                 "Change pause time flow control parameter",
6954         .tokens = {
6955                 (void *)&cmd_lfc_set_set,
6956                 (void *)&cmd_lfc_set_flow_ctrl,
6957                 (void *)&cmd_lfc_set_pause_time_str,
6958                 (void *)&cmd_lfc_set_pause_time,
6959                 (void *)&cmd_lfc_set_portid,
6960                 NULL,
6961         },
6962 };
6963
6964 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6965         .f = cmd_link_flow_ctrl_set_parsed,
6966         .data = (void *)&cmd_link_flow_control_set_xon,
6967         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6968                 "Change send_xon flow control parameter",
6969         .tokens = {
6970                 (void *)&cmd_lfc_set_set,
6971                 (void *)&cmd_lfc_set_flow_ctrl,
6972                 (void *)&cmd_lfc_set_send_xon_str,
6973                 (void *)&cmd_lfc_set_send_xon,
6974                 (void *)&cmd_lfc_set_portid,
6975                 NULL,
6976         },
6977 };
6978
6979 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6980         .f = cmd_link_flow_ctrl_set_parsed,
6981         .data = (void *)&cmd_link_flow_control_set_macfwd,
6982         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6983                 "Change mac ctrl fwd flow control parameter",
6984         .tokens = {
6985                 (void *)&cmd_lfc_set_set,
6986                 (void *)&cmd_lfc_set_flow_ctrl,
6987                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6988                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6989                 (void *)&cmd_lfc_set_portid,
6990                 NULL,
6991         },
6992 };
6993
6994 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6995         .f = cmd_link_flow_ctrl_set_parsed,
6996         .data = (void *)&cmd_link_flow_control_set_autoneg,
6997         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6998                 "Change autoneg flow control parameter",
6999         .tokens = {
7000                 (void *)&cmd_lfc_set_set,
7001                 (void *)&cmd_lfc_set_flow_ctrl,
7002                 (void *)&cmd_lfc_set_autoneg_str,
7003                 (void *)&cmd_lfc_set_autoneg,
7004                 (void *)&cmd_lfc_set_portid,
7005                 NULL,
7006         },
7007 };
7008
7009 static void
7010 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7011                               __rte_unused struct cmdline *cl,
7012                               void *data)
7013 {
7014         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7015         cmdline_parse_inst_t *cmd = data;
7016         struct rte_eth_fc_conf fc_conf;
7017         int rx_fc_en = 0;
7018         int tx_fc_en = 0;
7019         int ret;
7020
7021         /*
7022          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7023          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7024          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7025          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7026          */
7027         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7028                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7029         };
7030
7031         /* Partial command line, retrieve current configuration */
7032         if (cmd) {
7033                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7034                 if (ret != 0) {
7035                         printf("cannot get current flow ctrl parameters, return"
7036                                "code = %d\n", ret);
7037                         return;
7038                 }
7039
7040                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7041                     (fc_conf.mode == RTE_FC_FULL))
7042                         rx_fc_en = 1;
7043                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7044                     (fc_conf.mode == RTE_FC_FULL))
7045                         tx_fc_en = 1;
7046         }
7047
7048         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7049                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7050
7051         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7052                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7053
7054         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7055
7056         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7057                 fc_conf.high_water = res->high_water;
7058
7059         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7060                 fc_conf.low_water = res->low_water;
7061
7062         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7063                 fc_conf.pause_time = res->pause_time;
7064
7065         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7066                 fc_conf.send_xon = res->send_xon;
7067
7068         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7069                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7070                         fc_conf.mac_ctrl_frame_fwd = 1;
7071                 else
7072                         fc_conf.mac_ctrl_frame_fwd = 0;
7073         }
7074
7075         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7076                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7077
7078         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7079         if (ret != 0)
7080                 printf("bad flow contrl parameter, return code = %d \n", ret);
7081 }
7082
7083 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7084 struct cmd_priority_flow_ctrl_set_result {
7085         cmdline_fixed_string_t set;
7086         cmdline_fixed_string_t pfc_ctrl;
7087         cmdline_fixed_string_t rx;
7088         cmdline_fixed_string_t rx_pfc_mode;
7089         cmdline_fixed_string_t tx;
7090         cmdline_fixed_string_t tx_pfc_mode;
7091         uint32_t high_water;
7092         uint32_t low_water;
7093         uint16_t pause_time;
7094         uint8_t  priority;
7095         portid_t port_id;
7096 };
7097
7098 static void
7099 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7100                        __rte_unused struct cmdline *cl,
7101                        __rte_unused void *data)
7102 {
7103         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7104         struct rte_eth_pfc_conf pfc_conf;
7105         int rx_fc_enable, tx_fc_enable;
7106         int ret;
7107
7108         /*
7109          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7110          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7111          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7112          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7113          */
7114         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7115                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7116         };
7117
7118         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7119         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7120         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7121         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7122         pfc_conf.fc.high_water = res->high_water;
7123         pfc_conf.fc.low_water  = res->low_water;
7124         pfc_conf.fc.pause_time = res->pause_time;
7125         pfc_conf.priority      = res->priority;
7126
7127         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7128         if (ret != 0)
7129                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7130 }
7131
7132 cmdline_parse_token_string_t cmd_pfc_set_set =
7133         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7134                                 set, "set");
7135 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7136         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7137                                 pfc_ctrl, "pfc_ctrl");
7138 cmdline_parse_token_string_t cmd_pfc_set_rx =
7139         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7140                                 rx, "rx");
7141 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7142         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7143                                 rx_pfc_mode, "on#off");
7144 cmdline_parse_token_string_t cmd_pfc_set_tx =
7145         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7146                                 tx, "tx");
7147 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7148         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7149                                 tx_pfc_mode, "on#off");
7150 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7151         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7152                                 high_water, UINT32);
7153 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7154         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7155                                 low_water, UINT32);
7156 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7157         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7158                                 pause_time, UINT16);
7159 cmdline_parse_token_num_t cmd_pfc_set_priority =
7160         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7161                                 priority, UINT8);
7162 cmdline_parse_token_num_t cmd_pfc_set_portid =
7163         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7164                                 port_id, UINT16);
7165
7166 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7167         .f = cmd_priority_flow_ctrl_set_parsed,
7168         .data = NULL,
7169         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7170                 "<pause_time> <priority> <port_id>: "
7171                 "Configure the Ethernet priority flow control",
7172         .tokens = {
7173                 (void *)&cmd_pfc_set_set,
7174                 (void *)&cmd_pfc_set_flow_ctrl,
7175                 (void *)&cmd_pfc_set_rx,
7176                 (void *)&cmd_pfc_set_rx_mode,
7177                 (void *)&cmd_pfc_set_tx,
7178                 (void *)&cmd_pfc_set_tx_mode,
7179                 (void *)&cmd_pfc_set_high_water,
7180                 (void *)&cmd_pfc_set_low_water,
7181                 (void *)&cmd_pfc_set_pause_time,
7182                 (void *)&cmd_pfc_set_priority,
7183                 (void *)&cmd_pfc_set_portid,
7184                 NULL,
7185         },
7186 };
7187
7188 /* *** RESET CONFIGURATION *** */
7189 struct cmd_reset_result {
7190         cmdline_fixed_string_t reset;
7191         cmdline_fixed_string_t def;
7192 };
7193
7194 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7195                              struct cmdline *cl,
7196                              __rte_unused void *data)
7197 {
7198         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7199         set_def_fwd_config();
7200 }
7201
7202 cmdline_parse_token_string_t cmd_reset_set =
7203         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7204 cmdline_parse_token_string_t cmd_reset_def =
7205         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7206                                  "default");
7207
7208 cmdline_parse_inst_t cmd_reset = {
7209         .f = cmd_reset_parsed,
7210         .data = NULL,
7211         .help_str = "set default: Reset default forwarding configuration",
7212         .tokens = {
7213                 (void *)&cmd_reset_set,
7214                 (void *)&cmd_reset_def,
7215                 NULL,
7216         },
7217 };
7218
7219 /* *** START FORWARDING *** */
7220 struct cmd_start_result {
7221         cmdline_fixed_string_t start;
7222 };
7223
7224 cmdline_parse_token_string_t cmd_start_start =
7225         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7226
7227 static void cmd_start_parsed(__rte_unused void *parsed_result,
7228                              __rte_unused struct cmdline *cl,
7229                              __rte_unused void *data)
7230 {
7231         start_packet_forwarding(0);
7232 }
7233
7234 cmdline_parse_inst_t cmd_start = {
7235         .f = cmd_start_parsed,
7236         .data = NULL,
7237         .help_str = "start: Start packet forwarding",
7238         .tokens = {
7239                 (void *)&cmd_start_start,
7240                 NULL,
7241         },
7242 };
7243
7244 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7245 struct cmd_start_tx_first_result {
7246         cmdline_fixed_string_t start;
7247         cmdline_fixed_string_t tx_first;
7248 };
7249
7250 static void
7251 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7252                           __rte_unused struct cmdline *cl,
7253                           __rte_unused void *data)
7254 {
7255         start_packet_forwarding(1);
7256 }
7257
7258 cmdline_parse_token_string_t cmd_start_tx_first_start =
7259         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7260                                  "start");
7261 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7262         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7263                                  tx_first, "tx_first");
7264
7265 cmdline_parse_inst_t cmd_start_tx_first = {
7266         .f = cmd_start_tx_first_parsed,
7267         .data = NULL,
7268         .help_str = "start tx_first: Start packet forwarding, "
7269                 "after sending 1 burst of packets",
7270         .tokens = {
7271                 (void *)&cmd_start_tx_first_start,
7272                 (void *)&cmd_start_tx_first_tx_first,
7273                 NULL,
7274         },
7275 };
7276
7277 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7278 struct cmd_start_tx_first_n_result {
7279         cmdline_fixed_string_t start;
7280         cmdline_fixed_string_t tx_first;
7281         uint32_t tx_num;
7282 };
7283
7284 static void
7285 cmd_start_tx_first_n_parsed(void *parsed_result,
7286                           __rte_unused struct cmdline *cl,
7287                           __rte_unused void *data)
7288 {
7289         struct cmd_start_tx_first_n_result *res = parsed_result;
7290
7291         start_packet_forwarding(res->tx_num);
7292 }
7293
7294 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7295         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7296                         start, "start");
7297 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7298         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7299                         tx_first, "tx_first");
7300 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7301         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7302                         tx_num, UINT32);
7303
7304 cmdline_parse_inst_t cmd_start_tx_first_n = {
7305         .f = cmd_start_tx_first_n_parsed,
7306         .data = NULL,
7307         .help_str = "start tx_first <num>: "
7308                 "packet forwarding, after sending <num> bursts of packets",
7309         .tokens = {
7310                 (void *)&cmd_start_tx_first_n_start,
7311                 (void *)&cmd_start_tx_first_n_tx_first,
7312                 (void *)&cmd_start_tx_first_n_tx_num,
7313                 NULL,
7314         },
7315 };
7316
7317 /* *** SET LINK UP *** */
7318 struct cmd_set_link_up_result {
7319         cmdline_fixed_string_t set;
7320         cmdline_fixed_string_t link_up;
7321         cmdline_fixed_string_t port;
7322         portid_t port_id;
7323 };
7324
7325 cmdline_parse_token_string_t cmd_set_link_up_set =
7326         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7327 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7328         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7329                                 "link-up");
7330 cmdline_parse_token_string_t cmd_set_link_up_port =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7332 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7333         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7334
7335 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7336                              __rte_unused struct cmdline *cl,
7337                              __rte_unused void *data)
7338 {
7339         struct cmd_set_link_up_result *res = parsed_result;
7340         dev_set_link_up(res->port_id);
7341 }
7342
7343 cmdline_parse_inst_t cmd_set_link_up = {
7344         .f = cmd_set_link_up_parsed,
7345         .data = NULL,
7346         .help_str = "set link-up port <port id>",
7347         .tokens = {
7348                 (void *)&cmd_set_link_up_set,
7349                 (void *)&cmd_set_link_up_link_up,
7350                 (void *)&cmd_set_link_up_port,
7351                 (void *)&cmd_set_link_up_port_id,
7352                 NULL,
7353         },
7354 };
7355
7356 /* *** SET LINK DOWN *** */
7357 struct cmd_set_link_down_result {
7358         cmdline_fixed_string_t set;
7359         cmdline_fixed_string_t link_down;
7360         cmdline_fixed_string_t port;
7361         portid_t port_id;
7362 };
7363
7364 cmdline_parse_token_string_t cmd_set_link_down_set =
7365         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7366 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7367         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7368                                 "link-down");
7369 cmdline_parse_token_string_t cmd_set_link_down_port =
7370         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7371 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7372         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7373
7374 static void cmd_set_link_down_parsed(
7375                                 __rte_unused void *parsed_result,
7376                                 __rte_unused struct cmdline *cl,
7377                                 __rte_unused void *data)
7378 {
7379         struct cmd_set_link_down_result *res = parsed_result;
7380         dev_set_link_down(res->port_id);
7381 }
7382
7383 cmdline_parse_inst_t cmd_set_link_down = {
7384         .f = cmd_set_link_down_parsed,
7385         .data = NULL,
7386         .help_str = "set link-down port <port id>",
7387         .tokens = {
7388                 (void *)&cmd_set_link_down_set,
7389                 (void *)&cmd_set_link_down_link_down,
7390                 (void *)&cmd_set_link_down_port,
7391                 (void *)&cmd_set_link_down_port_id,
7392                 NULL,
7393         },
7394 };
7395
7396 /* *** SHOW CFG *** */
7397 struct cmd_showcfg_result {
7398         cmdline_fixed_string_t show;
7399         cmdline_fixed_string_t cfg;
7400         cmdline_fixed_string_t what;
7401 };
7402
7403 static void cmd_showcfg_parsed(void *parsed_result,
7404                                __rte_unused struct cmdline *cl,
7405                                __rte_unused void *data)
7406 {
7407         struct cmd_showcfg_result *res = parsed_result;
7408         if (!strcmp(res->what, "rxtx"))
7409                 rxtx_config_display();
7410         else if (!strcmp(res->what, "cores"))
7411                 fwd_lcores_config_display();
7412         else if (!strcmp(res->what, "fwd"))
7413                 pkt_fwd_config_display(&cur_fwd_config);
7414         else if (!strcmp(res->what, "txpkts"))
7415                 show_tx_pkt_segments();
7416 }
7417
7418 cmdline_parse_token_string_t cmd_showcfg_show =
7419         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7420 cmdline_parse_token_string_t cmd_showcfg_port =
7421         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7422 cmdline_parse_token_string_t cmd_showcfg_what =
7423         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7424                                  "rxtx#cores#fwd#txpkts");
7425
7426 cmdline_parse_inst_t cmd_showcfg = {
7427         .f = cmd_showcfg_parsed,
7428         .data = NULL,
7429         .help_str = "show config rxtx|cores|fwd|txpkts",
7430         .tokens = {
7431                 (void *)&cmd_showcfg_show,
7432                 (void *)&cmd_showcfg_port,
7433                 (void *)&cmd_showcfg_what,
7434                 NULL,
7435         },
7436 };
7437
7438 /* *** SHOW ALL PORT INFO *** */
7439 struct cmd_showportall_result {
7440         cmdline_fixed_string_t show;
7441         cmdline_fixed_string_t port;
7442         cmdline_fixed_string_t what;
7443         cmdline_fixed_string_t all;
7444 };
7445
7446 static void cmd_showportall_parsed(void *parsed_result,
7447                                 __rte_unused struct cmdline *cl,
7448                                 __rte_unused void *data)
7449 {
7450         portid_t i;
7451
7452         struct cmd_showportall_result *res = parsed_result;
7453         if (!strcmp(res->show, "clear")) {
7454                 if (!strcmp(res->what, "stats"))
7455                         RTE_ETH_FOREACH_DEV(i)
7456                                 nic_stats_clear(i);
7457                 else if (!strcmp(res->what, "xstats"))
7458                         RTE_ETH_FOREACH_DEV(i)
7459                                 nic_xstats_clear(i);
7460         } else if (!strcmp(res->what, "info"))
7461                 RTE_ETH_FOREACH_DEV(i)
7462                         port_infos_display(i);
7463         else if (!strcmp(res->what, "summary")) {
7464                 port_summary_header_display();
7465                 RTE_ETH_FOREACH_DEV(i)
7466                         port_summary_display(i);
7467         }
7468         else if (!strcmp(res->what, "stats"))
7469                 RTE_ETH_FOREACH_DEV(i)
7470                         nic_stats_display(i);
7471         else if (!strcmp(res->what, "xstats"))
7472                 RTE_ETH_FOREACH_DEV(i)
7473                         nic_xstats_display(i);
7474         else if (!strcmp(res->what, "fdir"))
7475                 RTE_ETH_FOREACH_DEV(i)
7476                         fdir_get_infos(i);
7477         else if (!strcmp(res->what, "stat_qmap"))
7478                 RTE_ETH_FOREACH_DEV(i)
7479                         nic_stats_mapping_display(i);
7480         else if (!strcmp(res->what, "dcb_tc"))
7481                 RTE_ETH_FOREACH_DEV(i)
7482                         port_dcb_info_display(i);
7483         else if (!strcmp(res->what, "cap"))
7484                 RTE_ETH_FOREACH_DEV(i)
7485                         port_offload_cap_display(i);
7486 }
7487
7488 cmdline_parse_token_string_t cmd_showportall_show =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7490                                  "show#clear");
7491 cmdline_parse_token_string_t cmd_showportall_port =
7492         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7493 cmdline_parse_token_string_t cmd_showportall_what =
7494         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7495                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7496 cmdline_parse_token_string_t cmd_showportall_all =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7498 cmdline_parse_inst_t cmd_showportall = {
7499         .f = cmd_showportall_parsed,
7500         .data = NULL,
7501         .help_str = "show|clear port "
7502                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7503         .tokens = {
7504                 (void *)&cmd_showportall_show,
7505                 (void *)&cmd_showportall_port,
7506                 (void *)&cmd_showportall_what,
7507                 (void *)&cmd_showportall_all,
7508                 NULL,
7509         },
7510 };
7511
7512 /* *** SHOW PORT INFO *** */
7513 struct cmd_showport_result {
7514         cmdline_fixed_string_t show;
7515         cmdline_fixed_string_t port;
7516         cmdline_fixed_string_t what;
7517         uint16_t portnum;
7518 };
7519
7520 static void cmd_showport_parsed(void *parsed_result,
7521                                 __rte_unused struct cmdline *cl,
7522                                 __rte_unused void *data)
7523 {
7524         struct cmd_showport_result *res = parsed_result;
7525         if (!strcmp(res->show, "clear")) {
7526                 if (!strcmp(res->what, "stats"))
7527                         nic_stats_clear(res->portnum);
7528                 else if (!strcmp(res->what, "xstats"))
7529                         nic_xstats_clear(res->portnum);
7530         } else if (!strcmp(res->what, "info"))
7531                 port_infos_display(res->portnum);
7532         else if (!strcmp(res->what, "summary")) {
7533                 port_summary_header_display();
7534                 port_summary_display(res->portnum);
7535         }
7536         else if (!strcmp(res->what, "stats"))
7537                 nic_stats_display(res->portnum);
7538         else if (!strcmp(res->what, "xstats"))
7539                 nic_xstats_display(res->portnum);
7540         else if (!strcmp(res->what, "fdir"))
7541                  fdir_get_infos(res->portnum);
7542         else if (!strcmp(res->what, "stat_qmap"))
7543                 nic_stats_mapping_display(res->portnum);
7544         else if (!strcmp(res->what, "dcb_tc"))
7545                 port_dcb_info_display(res->portnum);
7546         else if (!strcmp(res->what, "cap"))
7547                 port_offload_cap_display(res->portnum);
7548 }
7549
7550 cmdline_parse_token_string_t cmd_showport_show =
7551         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7552                                  "show#clear");
7553 cmdline_parse_token_string_t cmd_showport_port =
7554         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7555 cmdline_parse_token_string_t cmd_showport_what =
7556         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7557                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7558 cmdline_parse_token_num_t cmd_showport_portnum =
7559         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7560
7561 cmdline_parse_inst_t cmd_showport = {
7562         .f = cmd_showport_parsed,
7563         .data = NULL,
7564         .help_str = "show|clear port "
7565                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7566                 "<port_id>",
7567         .tokens = {
7568                 (void *)&cmd_showport_show,
7569                 (void *)&cmd_showport_port,
7570                 (void *)&cmd_showport_what,
7571                 (void *)&cmd_showport_portnum,
7572                 NULL,
7573         },
7574 };
7575
7576 /* *** SHOW DEVICE INFO *** */
7577 struct cmd_showdevice_result {
7578         cmdline_fixed_string_t show;
7579         cmdline_fixed_string_t device;
7580         cmdline_fixed_string_t what;
7581         cmdline_fixed_string_t identifier;
7582 };
7583
7584 static void cmd_showdevice_parsed(void *parsed_result,
7585                                 __rte_unused struct cmdline *cl,
7586                                 __rte_unused void *data)
7587 {
7588         struct cmd_showdevice_result *res = parsed_result;
7589         if (!strcmp(res->what, "info")) {
7590                 if (!strcmp(res->identifier, "all"))
7591                         device_infos_display(NULL);
7592                 else
7593                         device_infos_display(res->identifier);
7594         }
7595 }
7596
7597 cmdline_parse_token_string_t cmd_showdevice_show =
7598         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7599                                  "show");
7600 cmdline_parse_token_string_t cmd_showdevice_device =
7601         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7602 cmdline_parse_token_string_t cmd_showdevice_what =
7603         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7604                                  "info");
7605 cmdline_parse_token_string_t cmd_showdevice_identifier =
7606         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7607                         identifier, NULL);
7608
7609 cmdline_parse_inst_t cmd_showdevice = {
7610         .f = cmd_showdevice_parsed,
7611         .data = NULL,
7612         .help_str = "show device info <identifier>|all",
7613         .tokens = {
7614                 (void *)&cmd_showdevice_show,
7615                 (void *)&cmd_showdevice_device,
7616                 (void *)&cmd_showdevice_what,
7617                 (void *)&cmd_showdevice_identifier,
7618                 NULL,
7619         },
7620 };
7621 /* *** SHOW QUEUE INFO *** */
7622 struct cmd_showqueue_result {
7623         cmdline_fixed_string_t show;
7624         cmdline_fixed_string_t type;
7625         cmdline_fixed_string_t what;
7626         uint16_t portnum;
7627         uint16_t queuenum;
7628 };
7629
7630 static void
7631 cmd_showqueue_parsed(void *parsed_result,
7632         __rte_unused struct cmdline *cl,
7633         __rte_unused void *data)
7634 {
7635         struct cmd_showqueue_result *res = parsed_result;
7636
7637         if (!strcmp(res->type, "rxq"))
7638                 rx_queue_infos_display(res->portnum, res->queuenum);
7639         else if (!strcmp(res->type, "txq"))
7640                 tx_queue_infos_display(res->portnum, res->queuenum);
7641 }
7642
7643 cmdline_parse_token_string_t cmd_showqueue_show =
7644         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7645 cmdline_parse_token_string_t cmd_showqueue_type =
7646         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7647 cmdline_parse_token_string_t cmd_showqueue_what =
7648         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7649 cmdline_parse_token_num_t cmd_showqueue_portnum =
7650         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7651 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7652         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7653
7654 cmdline_parse_inst_t cmd_showqueue = {
7655         .f = cmd_showqueue_parsed,
7656         .data = NULL,
7657         .help_str = "show rxq|txq info <port_id> <queue_id>",
7658         .tokens = {
7659                 (void *)&cmd_showqueue_show,
7660                 (void *)&cmd_showqueue_type,
7661                 (void *)&cmd_showqueue_what,
7662                 (void *)&cmd_showqueue_portnum,
7663                 (void *)&cmd_showqueue_queuenum,
7664                 NULL,
7665         },
7666 };
7667
7668 /* show/clear fwd engine statistics */
7669 struct fwd_result {
7670         cmdline_fixed_string_t action;
7671         cmdline_fixed_string_t fwd;
7672         cmdline_fixed_string_t stats;
7673         cmdline_fixed_string_t all;
7674 };
7675
7676 cmdline_parse_token_string_t cmd_fwd_action =
7677         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7678 cmdline_parse_token_string_t cmd_fwd_fwd =
7679         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7680 cmdline_parse_token_string_t cmd_fwd_stats =
7681         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7682 cmdline_parse_token_string_t cmd_fwd_all =
7683         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7684
7685 static void
7686 cmd_showfwdall_parsed(void *parsed_result,
7687                       __rte_unused struct cmdline *cl,
7688                       __rte_unused void *data)
7689 {
7690         struct fwd_result *res = parsed_result;
7691
7692         if (!strcmp(res->action, "show"))
7693                 fwd_stats_display();
7694         else
7695                 fwd_stats_reset();
7696 }
7697
7698 static cmdline_parse_inst_t cmd_showfwdall = {
7699         .f = cmd_showfwdall_parsed,
7700         .data = NULL,
7701         .help_str = "show|clear fwd stats all",
7702         .tokens = {
7703                 (void *)&cmd_fwd_action,
7704                 (void *)&cmd_fwd_fwd,
7705                 (void *)&cmd_fwd_stats,
7706                 (void *)&cmd_fwd_all,
7707                 NULL,
7708         },
7709 };
7710
7711 /* *** READ PORT REGISTER *** */
7712 struct cmd_read_reg_result {
7713         cmdline_fixed_string_t read;
7714         cmdline_fixed_string_t reg;
7715         portid_t port_id;
7716         uint32_t reg_off;
7717 };
7718
7719 static void
7720 cmd_read_reg_parsed(void *parsed_result,
7721                     __rte_unused struct cmdline *cl,
7722                     __rte_unused void *data)
7723 {
7724         struct cmd_read_reg_result *res = parsed_result;
7725         port_reg_display(res->port_id, res->reg_off);
7726 }
7727
7728 cmdline_parse_token_string_t cmd_read_reg_read =
7729         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7730 cmdline_parse_token_string_t cmd_read_reg_reg =
7731         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7732 cmdline_parse_token_num_t cmd_read_reg_port_id =
7733         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7734 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7735         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7736
7737 cmdline_parse_inst_t cmd_read_reg = {
7738         .f = cmd_read_reg_parsed,
7739         .data = NULL,
7740         .help_str = "read reg <port_id> <reg_off>",
7741         .tokens = {
7742                 (void *)&cmd_read_reg_read,
7743                 (void *)&cmd_read_reg_reg,
7744                 (void *)&cmd_read_reg_port_id,
7745                 (void *)&cmd_read_reg_reg_off,
7746                 NULL,
7747         },
7748 };
7749
7750 /* *** READ PORT REGISTER BIT FIELD *** */
7751 struct cmd_read_reg_bit_field_result {
7752         cmdline_fixed_string_t read;
7753         cmdline_fixed_string_t regfield;
7754         portid_t port_id;
7755         uint32_t reg_off;
7756         uint8_t bit1_pos;
7757         uint8_t bit2_pos;
7758 };
7759
7760 static void
7761 cmd_read_reg_bit_field_parsed(void *parsed_result,
7762                               __rte_unused struct cmdline *cl,
7763                               __rte_unused void *data)
7764 {
7765         struct cmd_read_reg_bit_field_result *res = parsed_result;
7766         port_reg_bit_field_display(res->port_id, res->reg_off,
7767                                    res->bit1_pos, res->bit2_pos);
7768 }
7769
7770 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7771         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7772                                  "read");
7773 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7774         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7775                                  regfield, "regfield");
7776 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7777         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7778                               UINT16);
7779 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7780         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7781                               UINT32);
7782 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7783         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7784                               UINT8);
7785 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7786         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7787                               UINT8);
7788
7789 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7790         .f = cmd_read_reg_bit_field_parsed,
7791         .data = NULL,
7792         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7793         "Read register bit field between bit_x and bit_y included",
7794         .tokens = {
7795                 (void *)&cmd_read_reg_bit_field_read,
7796                 (void *)&cmd_read_reg_bit_field_regfield,
7797                 (void *)&cmd_read_reg_bit_field_port_id,
7798                 (void *)&cmd_read_reg_bit_field_reg_off,
7799                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7800                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7801                 NULL,
7802         },
7803 };
7804
7805 /* *** READ PORT REGISTER BIT *** */
7806 struct cmd_read_reg_bit_result {
7807         cmdline_fixed_string_t read;
7808         cmdline_fixed_string_t regbit;
7809         portid_t port_id;
7810         uint32_t reg_off;
7811         uint8_t bit_pos;
7812 };
7813
7814 static void
7815 cmd_read_reg_bit_parsed(void *parsed_result,
7816                         __rte_unused struct cmdline *cl,
7817                         __rte_unused void *data)
7818 {
7819         struct cmd_read_reg_bit_result *res = parsed_result;
7820         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7821 }
7822
7823 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7824         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7825 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7826         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7827                                  regbit, "regbit");
7828 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7829         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7830 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7831         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7832 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7833         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7834
7835 cmdline_parse_inst_t cmd_read_reg_bit = {
7836         .f = cmd_read_reg_bit_parsed,
7837         .data = NULL,
7838         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7839         .tokens = {
7840                 (void *)&cmd_read_reg_bit_read,
7841                 (void *)&cmd_read_reg_bit_regbit,
7842                 (void *)&cmd_read_reg_bit_port_id,
7843                 (void *)&cmd_read_reg_bit_reg_off,
7844                 (void *)&cmd_read_reg_bit_bit_pos,
7845                 NULL,
7846         },
7847 };
7848
7849 /* *** WRITE PORT REGISTER *** */
7850 struct cmd_write_reg_result {
7851         cmdline_fixed_string_t write;
7852         cmdline_fixed_string_t reg;
7853         portid_t port_id;
7854         uint32_t reg_off;
7855         uint32_t value;
7856 };
7857
7858 static void
7859 cmd_write_reg_parsed(void *parsed_result,
7860                      __rte_unused struct cmdline *cl,
7861                      __rte_unused void *data)
7862 {
7863         struct cmd_write_reg_result *res = parsed_result;
7864         port_reg_set(res->port_id, res->reg_off, res->value);
7865 }
7866
7867 cmdline_parse_token_string_t cmd_write_reg_write =
7868         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7869 cmdline_parse_token_string_t cmd_write_reg_reg =
7870         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7871 cmdline_parse_token_num_t cmd_write_reg_port_id =
7872         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7873 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7874         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7875 cmdline_parse_token_num_t cmd_write_reg_value =
7876         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7877
7878 cmdline_parse_inst_t cmd_write_reg = {
7879         .f = cmd_write_reg_parsed,
7880         .data = NULL,
7881         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7882         .tokens = {
7883                 (void *)&cmd_write_reg_write,
7884                 (void *)&cmd_write_reg_reg,
7885                 (void *)&cmd_write_reg_port_id,
7886                 (void *)&cmd_write_reg_reg_off,
7887                 (void *)&cmd_write_reg_value,
7888                 NULL,
7889         },
7890 };
7891
7892 /* *** WRITE PORT REGISTER BIT FIELD *** */
7893 struct cmd_write_reg_bit_field_result {
7894         cmdline_fixed_string_t write;
7895         cmdline_fixed_string_t regfield;
7896         portid_t port_id;
7897         uint32_t reg_off;
7898         uint8_t bit1_pos;
7899         uint8_t bit2_pos;
7900         uint32_t value;
7901 };
7902
7903 static void
7904 cmd_write_reg_bit_field_parsed(void *parsed_result,
7905                                __rte_unused struct cmdline *cl,
7906                                __rte_unused void *data)
7907 {
7908         struct cmd_write_reg_bit_field_result *res = parsed_result;
7909         port_reg_bit_field_set(res->port_id, res->reg_off,
7910                           res->bit1_pos, res->bit2_pos, res->value);
7911 }
7912
7913 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7914         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7915                                  "write");
7916 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7917         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7918                                  regfield, "regfield");
7919 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7920         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7921                               UINT16);
7922 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7923         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7924                               UINT32);
7925 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7926         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7927                               UINT8);
7928 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7929         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7930                               UINT8);
7931 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7932         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7933                               UINT32);
7934
7935 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7936         .f = cmd_write_reg_bit_field_parsed,
7937         .data = NULL,
7938         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7939                 "<reg_value>: "
7940                 "Set register bit field between bit_x and bit_y included",
7941         .tokens = {
7942                 (void *)&cmd_write_reg_bit_field_write,
7943                 (void *)&cmd_write_reg_bit_field_regfield,
7944                 (void *)&cmd_write_reg_bit_field_port_id,
7945                 (void *)&cmd_write_reg_bit_field_reg_off,
7946                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7947                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7948                 (void *)&cmd_write_reg_bit_field_value,
7949                 NULL,
7950         },
7951 };
7952
7953 /* *** WRITE PORT REGISTER BIT *** */
7954 struct cmd_write_reg_bit_result {
7955         cmdline_fixed_string_t write;
7956         cmdline_fixed_string_t regbit;
7957         portid_t port_id;
7958         uint32_t reg_off;
7959         uint8_t bit_pos;
7960         uint8_t value;
7961 };
7962
7963 static void
7964 cmd_write_reg_bit_parsed(void *parsed_result,
7965                          __rte_unused struct cmdline *cl,
7966                          __rte_unused void *data)
7967 {
7968         struct cmd_write_reg_bit_result *res = parsed_result;
7969         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7970 }
7971
7972 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7973         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7974                                  "write");
7975 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7976         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7977                                  regbit, "regbit");
7978 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7979         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7980 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7981         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7982 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7983         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7984 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7985         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7986
7987 cmdline_parse_inst_t cmd_write_reg_bit = {
7988         .f = cmd_write_reg_bit_parsed,
7989         .data = NULL,
7990         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7991                 "0 <= bit_x <= 31",
7992         .tokens = {
7993                 (void *)&cmd_write_reg_bit_write,
7994                 (void *)&cmd_write_reg_bit_regbit,
7995                 (void *)&cmd_write_reg_bit_port_id,
7996                 (void *)&cmd_write_reg_bit_reg_off,
7997                 (void *)&cmd_write_reg_bit_bit_pos,
7998                 (void *)&cmd_write_reg_bit_value,
7999                 NULL,
8000         },
8001 };
8002
8003 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8004 struct cmd_read_rxd_txd_result {
8005         cmdline_fixed_string_t read;
8006         cmdline_fixed_string_t rxd_txd;
8007         portid_t port_id;
8008         uint16_t queue_id;
8009         uint16_t desc_id;
8010 };
8011
8012 static void
8013 cmd_read_rxd_txd_parsed(void *parsed_result,
8014                         __rte_unused struct cmdline *cl,
8015                         __rte_unused void *data)
8016 {
8017         struct cmd_read_rxd_txd_result *res = parsed_result;
8018
8019         if (!strcmp(res->rxd_txd, "rxd"))
8020                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8021         else if (!strcmp(res->rxd_txd, "txd"))
8022                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8023 }
8024
8025 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8026         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8027 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8028         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8029                                  "rxd#txd");
8030 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8031         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8032 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8033         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8034 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8035         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8036
8037 cmdline_parse_inst_t cmd_read_rxd_txd = {
8038         .f = cmd_read_rxd_txd_parsed,
8039         .data = NULL,
8040         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8041         .tokens = {
8042                 (void *)&cmd_read_rxd_txd_read,
8043                 (void *)&cmd_read_rxd_txd_rxd_txd,
8044                 (void *)&cmd_read_rxd_txd_port_id,
8045                 (void *)&cmd_read_rxd_txd_queue_id,
8046                 (void *)&cmd_read_rxd_txd_desc_id,
8047                 NULL,
8048         },
8049 };
8050
8051 /* *** QUIT *** */
8052 struct cmd_quit_result {
8053         cmdline_fixed_string_t quit;
8054 };
8055
8056 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8057                             struct cmdline *cl,
8058                             __rte_unused void *data)
8059 {
8060         cmdline_quit(cl);
8061 }
8062
8063 cmdline_parse_token_string_t cmd_quit_quit =
8064         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8065
8066 cmdline_parse_inst_t cmd_quit = {
8067         .f = cmd_quit_parsed,
8068         .data = NULL,
8069         .help_str = "quit: Exit application",
8070         .tokens = {
8071                 (void *)&cmd_quit_quit,
8072                 NULL,
8073         },
8074 };
8075
8076 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8077 struct cmd_mac_addr_result {
8078         cmdline_fixed_string_t mac_addr_cmd;
8079         cmdline_fixed_string_t what;
8080         uint16_t port_num;
8081         struct rte_ether_addr address;
8082 };
8083
8084 static void cmd_mac_addr_parsed(void *parsed_result,
8085                 __rte_unused struct cmdline *cl,
8086                 __rte_unused void *data)
8087 {
8088         struct cmd_mac_addr_result *res = parsed_result;
8089         int ret;
8090
8091         if (strcmp(res->what, "add") == 0)
8092                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8093         else if (strcmp(res->what, "set") == 0)
8094                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8095                                                        &res->address);
8096         else
8097                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8098
8099         /* check the return value and print it if is < 0 */
8100         if(ret < 0)
8101                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8102
8103 }
8104
8105 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8106         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8107                                 "mac_addr");
8108 cmdline_parse_token_string_t cmd_mac_addr_what =
8109         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8110                                 "add#remove#set");
8111 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8112                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8113                                         UINT16);
8114 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8115                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8116
8117 cmdline_parse_inst_t cmd_mac_addr = {
8118         .f = cmd_mac_addr_parsed,
8119         .data = (void *)0,
8120         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8121                         "Add/Remove/Set MAC address on port_id",
8122         .tokens = {
8123                 (void *)&cmd_mac_addr_cmd,
8124                 (void *)&cmd_mac_addr_what,
8125                 (void *)&cmd_mac_addr_portnum,
8126                 (void *)&cmd_mac_addr_addr,
8127                 NULL,
8128         },
8129 };
8130
8131 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8132 struct cmd_eth_peer_result {
8133         cmdline_fixed_string_t set;
8134         cmdline_fixed_string_t eth_peer;
8135         portid_t port_id;
8136         cmdline_fixed_string_t peer_addr;
8137 };
8138
8139 static void cmd_set_eth_peer_parsed(void *parsed_result,
8140                         __rte_unused struct cmdline *cl,
8141                         __rte_unused void *data)
8142 {
8143                 struct cmd_eth_peer_result *res = parsed_result;
8144
8145                 if (test_done == 0) {
8146                         printf("Please stop forwarding first\n");
8147                         return;
8148                 }
8149                 if (!strcmp(res->eth_peer, "eth-peer")) {
8150                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8151                         fwd_config_setup();
8152                 }
8153 }
8154 cmdline_parse_token_string_t cmd_eth_peer_set =
8155         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8156 cmdline_parse_token_string_t cmd_eth_peer =
8157         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8158 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8159         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8160 cmdline_parse_token_string_t cmd_eth_peer_addr =
8161         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8162
8163 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8164         .f = cmd_set_eth_peer_parsed,
8165         .data = NULL,
8166         .help_str = "set eth-peer <port_id> <peer_mac>",
8167         .tokens = {
8168                 (void *)&cmd_eth_peer_set,
8169                 (void *)&cmd_eth_peer,
8170                 (void *)&cmd_eth_peer_port_id,
8171                 (void *)&cmd_eth_peer_addr,
8172                 NULL,
8173         },
8174 };
8175
8176 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8177 struct cmd_set_qmap_result {
8178         cmdline_fixed_string_t set;
8179         cmdline_fixed_string_t qmap;
8180         cmdline_fixed_string_t what;
8181         portid_t port_id;
8182         uint16_t queue_id;
8183         uint8_t map_value;
8184 };
8185
8186 static void
8187 cmd_set_qmap_parsed(void *parsed_result,
8188                        __rte_unused struct cmdline *cl,
8189                        __rte_unused void *data)
8190 {
8191         struct cmd_set_qmap_result *res = parsed_result;
8192         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8193
8194         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8195 }
8196
8197 cmdline_parse_token_string_t cmd_setqmap_set =
8198         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8199                                  set, "set");
8200 cmdline_parse_token_string_t cmd_setqmap_qmap =
8201         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8202                                  qmap, "stat_qmap");
8203 cmdline_parse_token_string_t cmd_setqmap_what =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8205                                  what, "tx#rx");
8206 cmdline_parse_token_num_t cmd_setqmap_portid =
8207         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8208                               port_id, UINT16);
8209 cmdline_parse_token_num_t cmd_setqmap_queueid =
8210         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8211                               queue_id, UINT16);
8212 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8213         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8214                               map_value, UINT8);
8215
8216 cmdline_parse_inst_t cmd_set_qmap = {
8217         .f = cmd_set_qmap_parsed,
8218         .data = NULL,
8219         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8220                 "Set statistics mapping value on tx|rx queue_id of port_id",
8221         .tokens = {
8222                 (void *)&cmd_setqmap_set,
8223                 (void *)&cmd_setqmap_qmap,
8224                 (void *)&cmd_setqmap_what,
8225                 (void *)&cmd_setqmap_portid,
8226                 (void *)&cmd_setqmap_queueid,
8227                 (void *)&cmd_setqmap_mapvalue,
8228                 NULL,
8229         },
8230 };
8231
8232 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8233 struct cmd_set_xstats_hide_zero_result {
8234         cmdline_fixed_string_t keyword;
8235         cmdline_fixed_string_t name;
8236         cmdline_fixed_string_t on_off;
8237 };
8238
8239 static void
8240 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8241                         __rte_unused struct cmdline *cl,
8242                         __rte_unused void *data)
8243 {
8244         struct cmd_set_xstats_hide_zero_result *res;
8245         uint16_t on_off = 0;
8246
8247         res = parsed_result;
8248         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8249         set_xstats_hide_zero(on_off);
8250 }
8251
8252 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8253         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8254                                  keyword, "set");
8255 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8256         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8257                                  name, "xstats-hide-zero");
8258 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8259         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8260                                  on_off, "on#off");
8261
8262 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8263         .f = cmd_set_xstats_hide_zero_parsed,
8264         .data = NULL,
8265         .help_str = "set xstats-hide-zero on|off",
8266         .tokens = {
8267                 (void *)&cmd_set_xstats_hide_zero_keyword,
8268                 (void *)&cmd_set_xstats_hide_zero_name,
8269                 (void *)&cmd_set_xstats_hide_zero_on_off,
8270                 NULL,
8271         },
8272 };
8273
8274 /* *** CONFIGURE UNICAST HASH TABLE *** */
8275 struct cmd_set_uc_hash_table {
8276         cmdline_fixed_string_t set;
8277         cmdline_fixed_string_t port;
8278         portid_t port_id;
8279         cmdline_fixed_string_t what;
8280         struct rte_ether_addr address;
8281         cmdline_fixed_string_t mode;
8282 };
8283
8284 static void
8285 cmd_set_uc_hash_parsed(void *parsed_result,
8286                        __rte_unused struct cmdline *cl,
8287                        __rte_unused void *data)
8288 {
8289         int ret=0;
8290         struct cmd_set_uc_hash_table *res = parsed_result;
8291
8292         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8293
8294         if (strcmp(res->what, "uta") == 0)
8295                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8296                                                 &res->address,(uint8_t)is_on);
8297         if (ret < 0)
8298                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8299
8300 }
8301
8302 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8303         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8304                                  set, "set");
8305 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8306         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8307                                  port, "port");
8308 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8309         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8310                               port_id, UINT16);
8311 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8312         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8313                                  what, "uta");
8314 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8315         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8316                                 address);
8317 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8318         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8319                                  mode, "on#off");
8320
8321 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8322         .f = cmd_set_uc_hash_parsed,
8323         .data = NULL,
8324         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8325         .tokens = {
8326                 (void *)&cmd_set_uc_hash_set,
8327                 (void *)&cmd_set_uc_hash_port,
8328                 (void *)&cmd_set_uc_hash_portid,
8329                 (void *)&cmd_set_uc_hash_what,
8330                 (void *)&cmd_set_uc_hash_mac,
8331                 (void *)&cmd_set_uc_hash_mode,
8332                 NULL,
8333         },
8334 };
8335
8336 struct cmd_set_uc_all_hash_table {
8337         cmdline_fixed_string_t set;
8338         cmdline_fixed_string_t port;
8339         portid_t port_id;
8340         cmdline_fixed_string_t what;
8341         cmdline_fixed_string_t value;
8342         cmdline_fixed_string_t mode;
8343 };
8344
8345 static void
8346 cmd_set_uc_all_hash_parsed(void *parsed_result,
8347                        __rte_unused struct cmdline *cl,
8348                        __rte_unused void *data)
8349 {
8350         int ret=0;
8351         struct cmd_set_uc_all_hash_table *res = parsed_result;
8352
8353         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8354
8355         if ((strcmp(res->what, "uta") == 0) &&
8356                 (strcmp(res->value, "all") == 0))
8357                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8358         if (ret < 0)
8359                 printf("bad unicast hash table parameter,"
8360                         "return code = %d \n", ret);
8361 }
8362
8363 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8364         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8365                                  set, "set");
8366 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8367         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8368                                  port, "port");
8369 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8370         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8371                               port_id, UINT16);
8372 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8373         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8374                                  what, "uta");
8375 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8376         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8377                                 value,"all");
8378 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8380                                  mode, "on#off");
8381
8382 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8383         .f = cmd_set_uc_all_hash_parsed,
8384         .data = NULL,
8385         .help_str = "set port <port_id> uta all on|off",
8386         .tokens = {
8387                 (void *)&cmd_set_uc_all_hash_set,
8388                 (void *)&cmd_set_uc_all_hash_port,
8389                 (void *)&cmd_set_uc_all_hash_portid,
8390                 (void *)&cmd_set_uc_all_hash_what,
8391                 (void *)&cmd_set_uc_all_hash_value,
8392                 (void *)&cmd_set_uc_all_hash_mode,
8393                 NULL,
8394         },
8395 };
8396
8397 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8398 struct cmd_set_vf_macvlan_filter {
8399         cmdline_fixed_string_t set;
8400         cmdline_fixed_string_t port;
8401         portid_t port_id;
8402         cmdline_fixed_string_t vf;
8403         uint8_t vf_id;
8404         struct rte_ether_addr address;
8405         cmdline_fixed_string_t filter_type;
8406         cmdline_fixed_string_t mode;
8407 };
8408
8409 static void
8410 cmd_set_vf_macvlan_parsed(void *parsed_result,
8411                        __rte_unused struct cmdline *cl,
8412                        __rte_unused void *data)
8413 {
8414         int is_on, ret = 0;
8415         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8416         struct rte_eth_mac_filter filter;
8417
8418         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8419
8420         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8421
8422         /* set VF MAC filter */
8423         filter.is_vf = 1;
8424
8425         /* set VF ID */
8426         filter.dst_id = res->vf_id;
8427
8428         if (!strcmp(res->filter_type, "exact-mac"))
8429                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8430         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8431                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8432         else if (!strcmp(res->filter_type, "hashmac"))
8433                 filter.filter_type = RTE_MAC_HASH_MATCH;
8434         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8435                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8436
8437         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8438
8439         if (is_on)
8440                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8441                                         RTE_ETH_FILTER_MACVLAN,
8442                                         RTE_ETH_FILTER_ADD,
8443                                          &filter);
8444         else
8445                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8446                                         RTE_ETH_FILTER_MACVLAN,
8447                                         RTE_ETH_FILTER_DELETE,
8448                                         &filter);
8449
8450         if (ret < 0)
8451                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8452
8453 }
8454
8455 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8456         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8457                                  set, "set");
8458 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8459         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8460                                  port, "port");
8461 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8462         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8463                               port_id, UINT16);
8464 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8465         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8466                                  vf, "vf");
8467 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8468         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8469                                 vf_id, UINT8);
8470 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8471         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8472                                 address);
8473 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8474         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8475                                 filter_type, "exact-mac#exact-mac-vlan"
8476                                 "#hashmac#hashmac-vlan");
8477 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8478         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8479                                  mode, "on#off");
8480
8481 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8482         .f = cmd_set_vf_macvlan_parsed,
8483         .data = NULL,
8484         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8485                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8486                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8487                 "hash match rule: hash match of MAC and exact match of VLAN",
8488         .tokens = {
8489                 (void *)&cmd_set_vf_macvlan_set,
8490                 (void *)&cmd_set_vf_macvlan_port,
8491                 (void *)&cmd_set_vf_macvlan_portid,
8492                 (void *)&cmd_set_vf_macvlan_vf,
8493                 (void *)&cmd_set_vf_macvlan_vf_id,
8494                 (void *)&cmd_set_vf_macvlan_mac,
8495                 (void *)&cmd_set_vf_macvlan_filter_type,
8496                 (void *)&cmd_set_vf_macvlan_mode,
8497                 NULL,
8498         },
8499 };
8500
8501 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8502 struct cmd_set_vf_traffic {
8503         cmdline_fixed_string_t set;
8504         cmdline_fixed_string_t port;
8505         portid_t port_id;
8506         cmdline_fixed_string_t vf;
8507         uint8_t vf_id;
8508         cmdline_fixed_string_t what;
8509         cmdline_fixed_string_t mode;
8510 };
8511
8512 static void
8513 cmd_set_vf_traffic_parsed(void *parsed_result,
8514                        __rte_unused struct cmdline *cl,
8515                        __rte_unused void *data)
8516 {
8517         struct cmd_set_vf_traffic *res = parsed_result;
8518         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8519         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8520
8521         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8522 }
8523
8524 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8525         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8526                                  set, "set");
8527 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8528         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8529                                  port, "port");
8530 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8531         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8532                               port_id, UINT16);
8533 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8534         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8535                                  vf, "vf");
8536 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8537         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8538                               vf_id, UINT8);
8539 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8540         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8541                                  what, "tx#rx");
8542 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8543         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8544                                  mode, "on#off");
8545
8546 cmdline_parse_inst_t cmd_set_vf_traffic = {
8547         .f = cmd_set_vf_traffic_parsed,
8548         .data = NULL,
8549         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8550         .tokens = {
8551                 (void *)&cmd_setvf_traffic_set,
8552                 (void *)&cmd_setvf_traffic_port,
8553                 (void *)&cmd_setvf_traffic_portid,
8554                 (void *)&cmd_setvf_traffic_vf,
8555                 (void *)&cmd_setvf_traffic_vfid,
8556                 (void *)&cmd_setvf_traffic_what,
8557                 (void *)&cmd_setvf_traffic_mode,
8558                 NULL,
8559         },
8560 };
8561
8562 /* *** CONFIGURE VF RECEIVE MODE *** */
8563 struct cmd_set_vf_rxmode {
8564         cmdline_fixed_string_t set;
8565         cmdline_fixed_string_t port;
8566         portid_t port_id;
8567         cmdline_fixed_string_t vf;
8568         uint8_t vf_id;
8569         cmdline_fixed_string_t what;
8570         cmdline_fixed_string_t mode;
8571         cmdline_fixed_string_t on;
8572 };
8573
8574 static void
8575 cmd_set_vf_rxmode_parsed(void *parsed_result,
8576                        __rte_unused struct cmdline *cl,
8577                        __rte_unused void *data)
8578 {
8579         int ret = -ENOTSUP;
8580         uint16_t vf_rxmode = 0;
8581         struct cmd_set_vf_rxmode *res = parsed_result;
8582
8583         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8584         if (!strcmp(res->what,"rxmode")) {
8585                 if (!strcmp(res->mode, "AUPE"))
8586                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8587                 else if (!strcmp(res->mode, "ROPE"))
8588                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8589                 else if (!strcmp(res->mode, "BAM"))
8590                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8591                 else if (!strncmp(res->mode, "MPE",3))
8592                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8593         }
8594
8595         RTE_SET_USED(is_on);
8596
8597 #ifdef RTE_LIBRTE_IXGBE_PMD
8598         if (ret == -ENOTSUP)
8599                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8600                                                   vf_rxmode, (uint8_t)is_on);
8601 #endif
8602 #ifdef RTE_LIBRTE_BNXT_PMD
8603         if (ret == -ENOTSUP)
8604                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8605                                                  vf_rxmode, (uint8_t)is_on);
8606 #endif
8607         if (ret < 0)
8608                 printf("bad VF receive mode parameter, return code = %d \n",
8609                 ret);
8610 }
8611
8612 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8614                                  set, "set");
8615 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8617                                  port, "port");
8618 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8619         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8620                               port_id, UINT16);
8621 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8623                                  vf, "vf");
8624 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8625         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8626                               vf_id, UINT8);
8627 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8628         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8629                                  what, "rxmode");
8630 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8632                                  mode, "AUPE#ROPE#BAM#MPE");
8633 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8635                                  on, "on#off");
8636
8637 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8638         .f = cmd_set_vf_rxmode_parsed,
8639         .data = NULL,
8640         .help_str = "set port <port_id> vf <vf_id> rxmode "
8641                 "AUPE|ROPE|BAM|MPE on|off",
8642         .tokens = {
8643                 (void *)&cmd_set_vf_rxmode_set,
8644                 (void *)&cmd_set_vf_rxmode_port,
8645                 (void *)&cmd_set_vf_rxmode_portid,
8646                 (void *)&cmd_set_vf_rxmode_vf,
8647                 (void *)&cmd_set_vf_rxmode_vfid,
8648                 (void *)&cmd_set_vf_rxmode_what,
8649                 (void *)&cmd_set_vf_rxmode_mode,
8650                 (void *)&cmd_set_vf_rxmode_on,
8651                 NULL,
8652         },
8653 };
8654
8655 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8656 struct cmd_vf_mac_addr_result {
8657         cmdline_fixed_string_t mac_addr_cmd;
8658         cmdline_fixed_string_t what;
8659         cmdline_fixed_string_t port;
8660         uint16_t port_num;
8661         cmdline_fixed_string_t vf;
8662         uint8_t vf_num;
8663         struct rte_ether_addr address;
8664 };
8665
8666 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8667                 __rte_unused struct cmdline *cl,
8668                 __rte_unused void *data)
8669 {
8670         struct cmd_vf_mac_addr_result *res = parsed_result;
8671         int ret = -ENOTSUP;
8672
8673         if (strcmp(res->what, "add") != 0)
8674                 return;
8675
8676 #ifdef RTE_LIBRTE_I40E_PMD
8677         if (ret == -ENOTSUP)
8678                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8679                                                    &res->address);
8680 #endif
8681 #ifdef RTE_LIBRTE_BNXT_PMD
8682         if (ret == -ENOTSUP)
8683                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8684                                                 res->vf_num);
8685 #endif
8686
8687         if(ret < 0)
8688                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8689
8690 }
8691
8692 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8693         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8694                                 mac_addr_cmd,"mac_addr");
8695 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8696         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8697                                 what,"add");
8698 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8699         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8700                                 port,"port");
8701 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8702         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8703                                 port_num, UINT16);
8704 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8705         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8706                                 vf,"vf");
8707 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8708         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8709                                 vf_num, UINT8);
8710 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8711         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8712                                 address);
8713
8714 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8715         .f = cmd_vf_mac_addr_parsed,
8716         .data = (void *)0,
8717         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8718                 "Add MAC address filtering for a VF on port_id",
8719         .tokens = {
8720                 (void *)&cmd_vf_mac_addr_cmd,
8721                 (void *)&cmd_vf_mac_addr_what,
8722                 (void *)&cmd_vf_mac_addr_port,
8723                 (void *)&cmd_vf_mac_addr_portnum,
8724                 (void *)&cmd_vf_mac_addr_vf,
8725                 (void *)&cmd_vf_mac_addr_vfnum,
8726                 (void *)&cmd_vf_mac_addr_addr,
8727                 NULL,
8728         },
8729 };
8730
8731 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8732 struct cmd_vf_rx_vlan_filter {
8733         cmdline_fixed_string_t rx_vlan;
8734         cmdline_fixed_string_t what;
8735         uint16_t vlan_id;
8736         cmdline_fixed_string_t port;
8737         portid_t port_id;
8738         cmdline_fixed_string_t vf;
8739         uint64_t vf_mask;
8740 };
8741
8742 static void
8743 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8744                           __rte_unused struct cmdline *cl,
8745                           __rte_unused void *data)
8746 {
8747         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8748         int ret = -ENOTSUP;
8749
8750         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8751
8752 #ifdef RTE_LIBRTE_IXGBE_PMD
8753         if (ret == -ENOTSUP)
8754                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8755                                 res->vlan_id, res->vf_mask, is_add);
8756 #endif
8757 #ifdef RTE_LIBRTE_I40E_PMD
8758         if (ret == -ENOTSUP)
8759                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8760                                 res->vlan_id, res->vf_mask, is_add);
8761 #endif
8762 #ifdef RTE_LIBRTE_BNXT_PMD
8763         if (ret == -ENOTSUP)
8764                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8765                                 res->vlan_id, res->vf_mask, is_add);
8766 #endif
8767
8768         switch (ret) {
8769         case 0:
8770                 break;
8771         case -EINVAL:
8772                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8773                                 res->vlan_id, res->vf_mask);
8774                 break;
8775         case -ENODEV:
8776                 printf("invalid port_id %d\n", res->port_id);
8777                 break;
8778         case -ENOTSUP:
8779                 printf("function not implemented or supported\n");
8780                 break;
8781         default:
8782                 printf("programming error: (%s)\n", strerror(-ret));
8783         }
8784 }
8785
8786 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8787         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8788                                  rx_vlan, "rx_vlan");
8789 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8791                                  what, "add#rm");
8792 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8793         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8794                               vlan_id, UINT16);
8795 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8796         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8797                                  port, "port");
8798 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8799         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8800                               port_id, UINT16);
8801 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8802         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8803                                  vf, "vf");
8804 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8805         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8806                               vf_mask, UINT64);
8807
8808 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8809         .f = cmd_vf_rx_vlan_filter_parsed,
8810         .data = NULL,
8811         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8812                 "(vf_mask = hexadecimal VF mask)",
8813         .tokens = {
8814                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8815                 (void *)&cmd_vf_rx_vlan_filter_what,
8816                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8817                 (void *)&cmd_vf_rx_vlan_filter_port,
8818                 (void *)&cmd_vf_rx_vlan_filter_portid,
8819                 (void *)&cmd_vf_rx_vlan_filter_vf,
8820                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8821                 NULL,
8822         },
8823 };
8824
8825 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8826 struct cmd_queue_rate_limit_result {
8827         cmdline_fixed_string_t set;
8828         cmdline_fixed_string_t port;
8829         uint16_t port_num;
8830         cmdline_fixed_string_t queue;
8831         uint8_t queue_num;
8832         cmdline_fixed_string_t rate;
8833         uint16_t rate_num;
8834 };
8835
8836 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8837                 __rte_unused struct cmdline *cl,
8838                 __rte_unused void *data)
8839 {
8840         struct cmd_queue_rate_limit_result *res = parsed_result;
8841         int ret = 0;
8842
8843         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8844                 && (strcmp(res->queue, "queue") == 0)
8845                 && (strcmp(res->rate, "rate") == 0))
8846                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8847                                         res->rate_num);
8848         if (ret < 0)
8849                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8850
8851 }
8852
8853 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8854         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8855                                 set, "set");
8856 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8857         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8858                                 port, "port");
8859 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8860         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8861                                 port_num, UINT16);
8862 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8863         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8864                                 queue, "queue");
8865 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8866         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8867                                 queue_num, UINT8);
8868 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8869         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8870                                 rate, "rate");
8871 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8872         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8873                                 rate_num, UINT16);
8874
8875 cmdline_parse_inst_t cmd_queue_rate_limit = {
8876         .f = cmd_queue_rate_limit_parsed,
8877         .data = (void *)0,
8878         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8879                 "Set rate limit for a queue on port_id",
8880         .tokens = {
8881                 (void *)&cmd_queue_rate_limit_set,
8882                 (void *)&cmd_queue_rate_limit_port,
8883                 (void *)&cmd_queue_rate_limit_portnum,
8884                 (void *)&cmd_queue_rate_limit_queue,
8885                 (void *)&cmd_queue_rate_limit_queuenum,
8886                 (void *)&cmd_queue_rate_limit_rate,
8887                 (void *)&cmd_queue_rate_limit_ratenum,
8888                 NULL,
8889         },
8890 };
8891
8892 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8893 struct cmd_vf_rate_limit_result {
8894         cmdline_fixed_string_t set;
8895         cmdline_fixed_string_t port;
8896         uint16_t port_num;
8897         cmdline_fixed_string_t vf;
8898         uint8_t vf_num;
8899         cmdline_fixed_string_t rate;
8900         uint16_t rate_num;
8901         cmdline_fixed_string_t q_msk;
8902         uint64_t q_msk_val;
8903 };
8904
8905 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8906                 __rte_unused struct cmdline *cl,
8907                 __rte_unused void *data)
8908 {
8909         struct cmd_vf_rate_limit_result *res = parsed_result;
8910         int ret = 0;
8911
8912         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8913                 && (strcmp(res->vf, "vf") == 0)
8914                 && (strcmp(res->rate, "rate") == 0)
8915                 && (strcmp(res->q_msk, "queue_mask") == 0))
8916                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8917                                         res->rate_num, res->q_msk_val);
8918         if (ret < 0)
8919                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8920
8921 }
8922
8923 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8924         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8925                                 set, "set");
8926 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8927         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8928                                 port, "port");
8929 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8930         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8931                                 port_num, UINT16);
8932 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8933         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8934                                 vf, "vf");
8935 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8936         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8937                                 vf_num, UINT8);
8938 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8939         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8940                                 rate, "rate");
8941 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8942         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8943                                 rate_num, UINT16);
8944 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8945         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8946                                 q_msk, "queue_mask");
8947 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8948         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8949                                 q_msk_val, UINT64);
8950
8951 cmdline_parse_inst_t cmd_vf_rate_limit = {
8952         .f = cmd_vf_rate_limit_parsed,
8953         .data = (void *)0,
8954         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8955                 "queue_mask <queue_mask_value>: "
8956                 "Set rate limit for queues of VF on port_id",
8957         .tokens = {
8958                 (void *)&cmd_vf_rate_limit_set,
8959                 (void *)&cmd_vf_rate_limit_port,
8960                 (void *)&cmd_vf_rate_limit_portnum,
8961                 (void *)&cmd_vf_rate_limit_vf,
8962                 (void *)&cmd_vf_rate_limit_vfnum,
8963                 (void *)&cmd_vf_rate_limit_rate,
8964                 (void *)&cmd_vf_rate_limit_ratenum,
8965                 (void *)&cmd_vf_rate_limit_q_msk,
8966                 (void *)&cmd_vf_rate_limit_q_msk_val,
8967                 NULL,
8968         },
8969 };
8970
8971 /* *** ADD TUNNEL FILTER OF A PORT *** */
8972 struct cmd_tunnel_filter_result {
8973         cmdline_fixed_string_t cmd;
8974         cmdline_fixed_string_t what;
8975         portid_t port_id;
8976         struct rte_ether_addr outer_mac;
8977         struct rte_ether_addr inner_mac;
8978         cmdline_ipaddr_t ip_value;
8979         uint16_t inner_vlan;
8980         cmdline_fixed_string_t tunnel_type;
8981         cmdline_fixed_string_t filter_type;
8982         uint32_t tenant_id;
8983         uint16_t queue_num;
8984 };
8985
8986 static void
8987 cmd_tunnel_filter_parsed(void *parsed_result,
8988                           __rte_unused struct cmdline *cl,
8989                           __rte_unused void *data)
8990 {
8991         struct cmd_tunnel_filter_result *res = parsed_result;
8992         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8993         int ret = 0;
8994
8995         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8996
8997         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
8998         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
8999         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9000
9001         if (res->ip_value.family == AF_INET) {
9002                 tunnel_filter_conf.ip_addr.ipv4_addr =
9003                         res->ip_value.addr.ipv4.s_addr;
9004                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9005         } else {
9006                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9007                         &(res->ip_value.addr.ipv6),
9008                         sizeof(struct in6_addr));
9009                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9010         }
9011
9012         if (!strcmp(res->filter_type, "imac-ivlan"))
9013                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9014         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9015                 tunnel_filter_conf.filter_type =
9016                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9017         else if (!strcmp(res->filter_type, "imac-tenid"))
9018                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9019         else if (!strcmp(res->filter_type, "imac"))
9020                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9021         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9022                 tunnel_filter_conf.filter_type =
9023                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9024         else if (!strcmp(res->filter_type, "oip"))
9025                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9026         else if (!strcmp(res->filter_type, "iip"))
9027                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9028         else {
9029                 printf("The filter type is not supported");
9030                 return;
9031         }
9032
9033         if (!strcmp(res->tunnel_type, "vxlan"))
9034                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9035         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9036                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9037         else if (!strcmp(res->tunnel_type, "nvgre"))
9038                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9039         else if (!strcmp(res->tunnel_type, "ipingre"))
9040                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9041         else {
9042                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9043                 return;
9044         }
9045
9046         tunnel_filter_conf.tenant_id = res->tenant_id;
9047         tunnel_filter_conf.queue_id = res->queue_num;
9048         if (!strcmp(res->what, "add"))
9049                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9050                                         RTE_ETH_FILTER_TUNNEL,
9051                                         RTE_ETH_FILTER_ADD,
9052                                         &tunnel_filter_conf);
9053         else
9054                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9055                                         RTE_ETH_FILTER_TUNNEL,
9056                                         RTE_ETH_FILTER_DELETE,
9057                                         &tunnel_filter_conf);
9058         if (ret < 0)
9059                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9060                                 strerror(-ret));
9061
9062 }
9063 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9064         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9065         cmd, "tunnel_filter");
9066 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9067         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9068         what, "add#rm");
9069 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9070         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9071         port_id, UINT16);
9072 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9073         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9074         outer_mac);
9075 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9076         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9077         inner_mac);
9078 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9079         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9080         inner_vlan, UINT16);
9081 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9082         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9083         ip_value);
9084 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9085         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9086         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9087
9088 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9089         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9090         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9091                 "imac#omac-imac-tenid");
9092 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9093         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9094         tenant_id, UINT32);
9095 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9096         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9097         queue_num, UINT16);
9098
9099 cmdline_parse_inst_t cmd_tunnel_filter = {
9100         .f = cmd_tunnel_filter_parsed,
9101         .data = (void *)0,
9102         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9103                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9104                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9105                 "<queue_id>: Add/Rm tunnel filter of a port",
9106         .tokens = {
9107                 (void *)&cmd_tunnel_filter_cmd,
9108                 (void *)&cmd_tunnel_filter_what,
9109                 (void *)&cmd_tunnel_filter_port_id,
9110                 (void *)&cmd_tunnel_filter_outer_mac,
9111                 (void *)&cmd_tunnel_filter_inner_mac,
9112                 (void *)&cmd_tunnel_filter_ip_value,
9113                 (void *)&cmd_tunnel_filter_innner_vlan,
9114                 (void *)&cmd_tunnel_filter_tunnel_type,
9115                 (void *)&cmd_tunnel_filter_filter_type,
9116                 (void *)&cmd_tunnel_filter_tenant_id,
9117                 (void *)&cmd_tunnel_filter_queue_num,
9118                 NULL,
9119         },
9120 };
9121
9122 /* *** CONFIGURE TUNNEL UDP PORT *** */
9123 struct cmd_tunnel_udp_config {
9124         cmdline_fixed_string_t cmd;
9125         cmdline_fixed_string_t what;
9126         uint16_t udp_port;
9127         portid_t port_id;
9128 };
9129
9130 static void
9131 cmd_tunnel_udp_config_parsed(void *parsed_result,
9132                           __rte_unused struct cmdline *cl,
9133                           __rte_unused void *data)
9134 {
9135         struct cmd_tunnel_udp_config *res = parsed_result;
9136         struct rte_eth_udp_tunnel tunnel_udp;
9137         int ret;
9138
9139         tunnel_udp.udp_port = res->udp_port;
9140
9141         if (!strcmp(res->cmd, "rx_vxlan_port"))
9142                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9143
9144         if (!strcmp(res->what, "add"))
9145                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9146                                                       &tunnel_udp);
9147         else
9148                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9149                                                          &tunnel_udp);
9150
9151         if (ret < 0)
9152                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9153 }
9154
9155 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9156         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9157                                 cmd, "rx_vxlan_port");
9158 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9159         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9160                                 what, "add#rm");
9161 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9162         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9163                                 udp_port, UINT16);
9164 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9165         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9166                                 port_id, UINT16);
9167
9168 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9169         .f = cmd_tunnel_udp_config_parsed,
9170         .data = (void *)0,
9171         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9172                 "Add/Remove a tunneling UDP port filter",
9173         .tokens = {
9174                 (void *)&cmd_tunnel_udp_config_cmd,
9175                 (void *)&cmd_tunnel_udp_config_what,
9176                 (void *)&cmd_tunnel_udp_config_udp_port,
9177                 (void *)&cmd_tunnel_udp_config_port_id,
9178                 NULL,
9179         },
9180 };
9181
9182 struct cmd_config_tunnel_udp_port {
9183         cmdline_fixed_string_t port;
9184         cmdline_fixed_string_t config;
9185         portid_t port_id;
9186         cmdline_fixed_string_t udp_tunnel_port;
9187         cmdline_fixed_string_t action;
9188         cmdline_fixed_string_t tunnel_type;
9189         uint16_t udp_port;
9190 };
9191
9192 static void
9193 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9194                                __rte_unused struct cmdline *cl,
9195                                __rte_unused void *data)
9196 {
9197         struct cmd_config_tunnel_udp_port *res = parsed_result;
9198         struct rte_eth_udp_tunnel tunnel_udp;
9199         int ret = 0;
9200
9201         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9202                 return;
9203
9204         tunnel_udp.udp_port = res->udp_port;
9205
9206         if (!strcmp(res->tunnel_type, "vxlan")) {
9207                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9208         } else if (!strcmp(res->tunnel_type, "geneve")) {
9209                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9210         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9211                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9212         } else {
9213                 printf("Invalid tunnel type\n");
9214                 return;
9215         }
9216
9217         if (!strcmp(res->action, "add"))
9218                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9219                                                       &tunnel_udp);
9220         else
9221                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9222                                                          &tunnel_udp);
9223
9224         if (ret < 0)
9225                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9226 }
9227
9228 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9229         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9230                                  "port");
9231 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9232         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9233                                  "config");
9234 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9235         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9236                               UINT16);
9237 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9238         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9239                                  udp_tunnel_port,
9240                                  "udp_tunnel_port");
9241 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9242         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9243                                  "add#rm");
9244 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9245         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9246                                  "vxlan#geneve#vxlan-gpe");
9247 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9248         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9249                               UINT16);
9250
9251 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9252         .f = cmd_cfg_tunnel_udp_port_parsed,
9253         .data = NULL,
9254         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9255         .tokens = {
9256                 (void *)&cmd_config_tunnel_udp_port_port,
9257                 (void *)&cmd_config_tunnel_udp_port_config,
9258                 (void *)&cmd_config_tunnel_udp_port_port_id,
9259                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9260                 (void *)&cmd_config_tunnel_udp_port_action,
9261                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9262                 (void *)&cmd_config_tunnel_udp_port_value,
9263                 NULL,
9264         },
9265 };
9266
9267 /* *** GLOBAL CONFIG *** */
9268 struct cmd_global_config_result {
9269         cmdline_fixed_string_t cmd;
9270         portid_t port_id;
9271         cmdline_fixed_string_t cfg_type;
9272         uint8_t len;
9273 };
9274
9275 static void
9276 cmd_global_config_parsed(void *parsed_result,
9277                          __rte_unused struct cmdline *cl,
9278                          __rte_unused void *data)
9279 {
9280         struct cmd_global_config_result *res = parsed_result;
9281         struct rte_eth_global_cfg conf;
9282         int ret;
9283
9284         memset(&conf, 0, sizeof(conf));
9285         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9286         conf.cfg.gre_key_len = res->len;
9287         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9288                                       RTE_ETH_FILTER_SET, &conf);
9289         if (ret != 0)
9290                 printf("Global config error\n");
9291 }
9292
9293 cmdline_parse_token_string_t cmd_global_config_cmd =
9294         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9295                 "global_config");
9296 cmdline_parse_token_num_t cmd_global_config_port_id =
9297         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9298                                UINT16);
9299 cmdline_parse_token_string_t cmd_global_config_type =
9300         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9301                 cfg_type, "gre-key-len");
9302 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9303         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9304                 len, UINT8);
9305
9306 cmdline_parse_inst_t cmd_global_config = {
9307         .f = cmd_global_config_parsed,
9308         .data = (void *)NULL,
9309         .help_str = "global_config <port_id> gre-key-len <key_len>",
9310         .tokens = {
9311                 (void *)&cmd_global_config_cmd,
9312                 (void *)&cmd_global_config_port_id,
9313                 (void *)&cmd_global_config_type,
9314                 (void *)&cmd_global_config_gre_key_len,
9315                 NULL,
9316         },
9317 };
9318
9319 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9320 struct cmd_set_mirror_mask_result {
9321         cmdline_fixed_string_t set;
9322         cmdline_fixed_string_t port;
9323         portid_t port_id;
9324         cmdline_fixed_string_t mirror;
9325         uint8_t rule_id;
9326         cmdline_fixed_string_t what;
9327         cmdline_fixed_string_t value;
9328         cmdline_fixed_string_t dstpool;
9329         uint8_t dstpool_id;
9330         cmdline_fixed_string_t on;
9331 };
9332
9333 cmdline_parse_token_string_t cmd_mirror_mask_set =
9334         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9335                                 set, "set");
9336 cmdline_parse_token_string_t cmd_mirror_mask_port =
9337         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9338                                 port, "port");
9339 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9340         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9341                                 port_id, UINT16);
9342 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9343         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9344                                 mirror, "mirror-rule");
9345 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9346         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9347                                 rule_id, UINT8);
9348 cmdline_parse_token_string_t cmd_mirror_mask_what =
9349         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9350                                 what, "pool-mirror-up#pool-mirror-down"
9351                                       "#vlan-mirror");
9352 cmdline_parse_token_string_t cmd_mirror_mask_value =
9353         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9354                                 value, NULL);
9355 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9357                                 dstpool, "dst-pool");
9358 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9359         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9360                                 dstpool_id, UINT8);
9361 cmdline_parse_token_string_t cmd_mirror_mask_on =
9362         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9363                                 on, "on#off");
9364
9365 static void
9366 cmd_set_mirror_mask_parsed(void *parsed_result,
9367                        __rte_unused struct cmdline *cl,
9368                        __rte_unused void *data)
9369 {
9370         int ret,nb_item,i;
9371         struct cmd_set_mirror_mask_result *res = parsed_result;
9372         struct rte_eth_mirror_conf mr_conf;
9373
9374         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9375
9376         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9377
9378         mr_conf.dst_pool = res->dstpool_id;
9379
9380         if (!strcmp(res->what, "pool-mirror-up")) {
9381                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9382                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9383         } else if (!strcmp(res->what, "pool-mirror-down")) {
9384                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9385                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9386         } else if (!strcmp(res->what, "vlan-mirror")) {
9387                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9388                 nb_item = parse_item_list(res->value, "vlan",
9389                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9390                 if (nb_item <= 0)
9391                         return;
9392
9393                 for (i = 0; i < nb_item; i++) {
9394                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9395                                 printf("Invalid vlan_id: must be < 4096\n");
9396                                 return;
9397                         }
9398
9399                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9400                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9401                 }
9402         }
9403
9404         if (!strcmp(res->on, "on"))
9405                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9406                                                 res->rule_id, 1);
9407         else
9408                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9409                                                 res->rule_id, 0);
9410         if (ret < 0)
9411                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9412 }
9413
9414 cmdline_parse_inst_t cmd_set_mirror_mask = {
9415                 .f = cmd_set_mirror_mask_parsed,
9416                 .data = NULL,
9417                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9418                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9419                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9420                 .tokens = {
9421                         (void *)&cmd_mirror_mask_set,
9422                         (void *)&cmd_mirror_mask_port,
9423                         (void *)&cmd_mirror_mask_portid,
9424                         (void *)&cmd_mirror_mask_mirror,
9425                         (void *)&cmd_mirror_mask_ruleid,
9426                         (void *)&cmd_mirror_mask_what,
9427                         (void *)&cmd_mirror_mask_value,
9428                         (void *)&cmd_mirror_mask_dstpool,
9429                         (void *)&cmd_mirror_mask_poolid,
9430                         (void *)&cmd_mirror_mask_on,
9431                         NULL,
9432                 },
9433 };
9434
9435 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9436 struct cmd_set_mirror_link_result {
9437         cmdline_fixed_string_t set;
9438         cmdline_fixed_string_t port;
9439         portid_t port_id;
9440         cmdline_fixed_string_t mirror;
9441         uint8_t rule_id;
9442         cmdline_fixed_string_t what;
9443         cmdline_fixed_string_t dstpool;
9444         uint8_t dstpool_id;
9445         cmdline_fixed_string_t on;
9446 };
9447
9448 cmdline_parse_token_string_t cmd_mirror_link_set =
9449         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9450                                  set, "set");
9451 cmdline_parse_token_string_t cmd_mirror_link_port =
9452         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9453                                 port, "port");
9454 cmdline_parse_token_num_t cmd_mirror_link_portid =
9455         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9456                                 port_id, UINT16);
9457 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9458         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9459                                 mirror, "mirror-rule");
9460 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9461         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9462                             rule_id, UINT8);
9463 cmdline_parse_token_string_t cmd_mirror_link_what =
9464         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9465                                 what, "uplink-mirror#downlink-mirror");
9466 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9467         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9468                                 dstpool, "dst-pool");
9469 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9470         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9471                                 dstpool_id, UINT8);
9472 cmdline_parse_token_string_t cmd_mirror_link_on =
9473         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9474                                 on, "on#off");
9475
9476 static void
9477 cmd_set_mirror_link_parsed(void *parsed_result,
9478                        __rte_unused struct cmdline *cl,
9479                        __rte_unused void *data)
9480 {
9481         int ret;
9482         struct cmd_set_mirror_link_result *res = parsed_result;
9483         struct rte_eth_mirror_conf mr_conf;
9484
9485         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9486         if (!strcmp(res->what, "uplink-mirror"))
9487                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9488         else
9489                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9490
9491         mr_conf.dst_pool = res->dstpool_id;
9492
9493         if (!strcmp(res->on, "on"))
9494                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9495                                                 res->rule_id, 1);
9496         else
9497                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9498                                                 res->rule_id, 0);
9499
9500         /* check the return value and print it if is < 0 */
9501         if (ret < 0)
9502                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9503
9504 }
9505
9506 cmdline_parse_inst_t cmd_set_mirror_link = {
9507                 .f = cmd_set_mirror_link_parsed,
9508                 .data = NULL,
9509                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9510                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9511                 .tokens = {
9512                         (void *)&cmd_mirror_link_set,
9513                         (void *)&cmd_mirror_link_port,
9514                         (void *)&cmd_mirror_link_portid,
9515                         (void *)&cmd_mirror_link_mirror,
9516                         (void *)&cmd_mirror_link_ruleid,
9517                         (void *)&cmd_mirror_link_what,
9518                         (void *)&cmd_mirror_link_dstpool,
9519                         (void *)&cmd_mirror_link_poolid,
9520                         (void *)&cmd_mirror_link_on,
9521                         NULL,
9522                 },
9523 };
9524
9525 /* *** RESET VM MIRROR RULE *** */
9526 struct cmd_rm_mirror_rule_result {
9527         cmdline_fixed_string_t reset;
9528         cmdline_fixed_string_t port;
9529         portid_t port_id;
9530         cmdline_fixed_string_t mirror;
9531         uint8_t rule_id;
9532 };
9533
9534 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9535         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9536                                  reset, "reset");
9537 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9538         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9539                                 port, "port");
9540 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9541         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9542                                 port_id, UINT16);
9543 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9544         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9545                                 mirror, "mirror-rule");
9546 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9547         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9548                                 rule_id, UINT8);
9549
9550 static void
9551 cmd_reset_mirror_rule_parsed(void *parsed_result,
9552                        __rte_unused struct cmdline *cl,
9553                        __rte_unused void *data)
9554 {
9555         int ret;
9556         struct cmd_set_mirror_link_result *res = parsed_result;
9557         /* check rule_id */
9558         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9559         if(ret < 0)
9560                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9561 }
9562
9563 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9564                 .f = cmd_reset_mirror_rule_parsed,
9565                 .data = NULL,
9566                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9567                 .tokens = {
9568                         (void *)&cmd_rm_mirror_rule_reset,
9569                         (void *)&cmd_rm_mirror_rule_port,
9570                         (void *)&cmd_rm_mirror_rule_portid,
9571                         (void *)&cmd_rm_mirror_rule_mirror,
9572                         (void *)&cmd_rm_mirror_rule_ruleid,
9573                         NULL,
9574                 },
9575 };
9576
9577 /* ******************************************************************************** */
9578
9579 struct cmd_dump_result {
9580         cmdline_fixed_string_t dump;
9581 };
9582
9583 static void
9584 dump_struct_sizes(void)
9585 {
9586 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9587         DUMP_SIZE(struct rte_mbuf);
9588         DUMP_SIZE(struct rte_mempool);
9589         DUMP_SIZE(struct rte_ring);
9590 #undef DUMP_SIZE
9591 }
9592
9593
9594 /* Dump the socket memory statistics on console */
9595 static void
9596 dump_socket_mem(FILE *f)
9597 {
9598         struct rte_malloc_socket_stats socket_stats;
9599         unsigned int i;
9600         size_t total = 0;
9601         size_t alloc = 0;
9602         size_t free = 0;
9603         unsigned int n_alloc = 0;
9604         unsigned int n_free = 0;
9605         static size_t last_allocs;
9606         static size_t last_total;
9607
9608
9609         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9610                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9611                     !socket_stats.heap_totalsz_bytes)
9612                         continue;
9613                 total += socket_stats.heap_totalsz_bytes;
9614                 alloc += socket_stats.heap_allocsz_bytes;
9615                 free += socket_stats.heap_freesz_bytes;
9616                 n_alloc += socket_stats.alloc_count;
9617                 n_free += socket_stats.free_count;
9618                 fprintf(f,
9619                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9620                         i,
9621                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9622                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9623                         (double)socket_stats.heap_allocsz_bytes * 100 /
9624                         (double)socket_stats.heap_totalsz_bytes,
9625                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9626                         socket_stats.alloc_count,
9627                         socket_stats.free_count);
9628         }
9629         fprintf(f,
9630                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9631                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9632                 (double)alloc * 100 / (double)total,
9633                 (double)free / (1024 * 1024),
9634                 n_alloc, n_free);
9635         if (last_allocs)
9636                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9637                         ((double)total - (double)last_total) / (1024 * 1024),
9638                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9639         last_allocs = alloc;
9640         last_total = total;
9641 }
9642
9643 static void cmd_dump_parsed(void *parsed_result,
9644                             __rte_unused struct cmdline *cl,
9645                             __rte_unused void *data)
9646 {
9647         struct cmd_dump_result *res = parsed_result;
9648
9649         if (!strcmp(res->dump, "dump_physmem"))
9650                 rte_dump_physmem_layout(stdout);
9651         else if (!strcmp(res->dump, "dump_socket_mem"))
9652                 dump_socket_mem(stdout);
9653         else if (!strcmp(res->dump, "dump_memzone"))
9654                 rte_memzone_dump(stdout);
9655         else if (!strcmp(res->dump, "dump_struct_sizes"))
9656                 dump_struct_sizes();
9657         else if (!strcmp(res->dump, "dump_ring"))
9658                 rte_ring_list_dump(stdout);
9659         else if (!strcmp(res->dump, "dump_mempool"))
9660                 rte_mempool_list_dump(stdout);
9661         else if (!strcmp(res->dump, "dump_devargs"))
9662                 rte_devargs_dump(stdout);
9663         else if (!strcmp(res->dump, "dump_log_types"))
9664                 rte_log_dump(stdout);
9665 }
9666
9667 cmdline_parse_token_string_t cmd_dump_dump =
9668         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9669                 "dump_physmem#"
9670                 "dump_memzone#"
9671                 "dump_socket_mem#"
9672                 "dump_struct_sizes#"
9673                 "dump_ring#"
9674                 "dump_mempool#"
9675                 "dump_devargs#"
9676                 "dump_log_types");
9677
9678 cmdline_parse_inst_t cmd_dump = {
9679         .f = cmd_dump_parsed,  /* function to call */
9680         .data = NULL,      /* 2nd arg of func */
9681         .help_str = "Dump status",
9682         .tokens = {        /* token list, NULL terminated */
9683                 (void *)&cmd_dump_dump,
9684                 NULL,
9685         },
9686 };
9687
9688 /* ******************************************************************************** */
9689
9690 struct cmd_dump_one_result {
9691         cmdline_fixed_string_t dump;
9692         cmdline_fixed_string_t name;
9693 };
9694
9695 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9696                                 __rte_unused void *data)
9697 {
9698         struct cmd_dump_one_result *res = parsed_result;
9699
9700         if (!strcmp(res->dump, "dump_ring")) {
9701                 struct rte_ring *r;
9702                 r = rte_ring_lookup(res->name);
9703                 if (r == NULL) {
9704                         cmdline_printf(cl, "Cannot find ring\n");
9705                         return;
9706                 }
9707                 rte_ring_dump(stdout, r);
9708         } else if (!strcmp(res->dump, "dump_mempool")) {
9709                 struct rte_mempool *mp;
9710                 mp = rte_mempool_lookup(res->name);
9711                 if (mp == NULL) {
9712                         cmdline_printf(cl, "Cannot find mempool\n");
9713                         return;
9714                 }
9715                 rte_mempool_dump(stdout, mp);
9716         }
9717 }
9718
9719 cmdline_parse_token_string_t cmd_dump_one_dump =
9720         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9721                                  "dump_ring#dump_mempool");
9722
9723 cmdline_parse_token_string_t cmd_dump_one_name =
9724         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9725
9726 cmdline_parse_inst_t cmd_dump_one = {
9727         .f = cmd_dump_one_parsed,  /* function to call */
9728         .data = NULL,      /* 2nd arg of func */
9729         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9730         .tokens = {        /* token list, NULL terminated */
9731                 (void *)&cmd_dump_one_dump,
9732                 (void *)&cmd_dump_one_name,
9733                 NULL,
9734         },
9735 };
9736
9737 /* *** Add/Del syn filter *** */
9738 struct cmd_syn_filter_result {
9739         cmdline_fixed_string_t filter;
9740         portid_t port_id;
9741         cmdline_fixed_string_t ops;
9742         cmdline_fixed_string_t priority;
9743         cmdline_fixed_string_t high;
9744         cmdline_fixed_string_t queue;
9745         uint16_t queue_id;
9746 };
9747
9748 static void
9749 cmd_syn_filter_parsed(void *parsed_result,
9750                         __rte_unused struct cmdline *cl,
9751                         __rte_unused void *data)
9752 {
9753         struct cmd_syn_filter_result *res = parsed_result;
9754         struct rte_eth_syn_filter syn_filter;
9755         int ret = 0;
9756
9757         ret = rte_eth_dev_filter_supported(res->port_id,
9758                                         RTE_ETH_FILTER_SYN);
9759         if (ret < 0) {
9760                 printf("syn filter is not supported on port %u.\n",
9761                                 res->port_id);
9762                 return;
9763         }
9764
9765         memset(&syn_filter, 0, sizeof(syn_filter));
9766
9767         if (!strcmp(res->ops, "add")) {
9768                 if (!strcmp(res->high, "high"))
9769                         syn_filter.hig_pri = 1;
9770                 else
9771                         syn_filter.hig_pri = 0;
9772
9773                 syn_filter.queue = res->queue_id;
9774                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9775                                                 RTE_ETH_FILTER_SYN,
9776                                                 RTE_ETH_FILTER_ADD,
9777                                                 &syn_filter);
9778         } else
9779                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9780                                                 RTE_ETH_FILTER_SYN,
9781                                                 RTE_ETH_FILTER_DELETE,
9782                                                 &syn_filter);
9783
9784         if (ret < 0)
9785                 printf("syn filter programming error: (%s)\n",
9786                                 strerror(-ret));
9787 }
9788
9789 cmdline_parse_token_string_t cmd_syn_filter_filter =
9790         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9791         filter, "syn_filter");
9792 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9793         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9794         port_id, UINT16);
9795 cmdline_parse_token_string_t cmd_syn_filter_ops =
9796         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9797         ops, "add#del");
9798 cmdline_parse_token_string_t cmd_syn_filter_priority =
9799         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9800                                 priority, "priority");
9801 cmdline_parse_token_string_t cmd_syn_filter_high =
9802         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9803                                 high, "high#low");
9804 cmdline_parse_token_string_t cmd_syn_filter_queue =
9805         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9806                                 queue, "queue");
9807 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9808         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9809                                 queue_id, UINT16);
9810
9811 cmdline_parse_inst_t cmd_syn_filter = {
9812         .f = cmd_syn_filter_parsed,
9813         .data = NULL,
9814         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9815                 "<queue_id>: Add/Delete syn filter",
9816         .tokens = {
9817                 (void *)&cmd_syn_filter_filter,
9818                 (void *)&cmd_syn_filter_port_id,
9819                 (void *)&cmd_syn_filter_ops,
9820                 (void *)&cmd_syn_filter_priority,
9821                 (void *)&cmd_syn_filter_high,
9822                 (void *)&cmd_syn_filter_queue,
9823                 (void *)&cmd_syn_filter_queue_id,
9824                 NULL,
9825         },
9826 };
9827
9828 /* *** queue region set *** */
9829 struct cmd_queue_region_result {
9830         cmdline_fixed_string_t set;
9831         cmdline_fixed_string_t port;
9832         portid_t port_id;
9833         cmdline_fixed_string_t cmd;
9834         cmdline_fixed_string_t region;
9835         uint8_t  region_id;
9836         cmdline_fixed_string_t queue_start_index;
9837         uint8_t  queue_id;
9838         cmdline_fixed_string_t queue_num;
9839         uint8_t  queue_num_value;
9840 };
9841
9842 static void
9843 cmd_queue_region_parsed(void *parsed_result,
9844                         __rte_unused struct cmdline *cl,
9845                         __rte_unused void *data)
9846 {
9847         struct cmd_queue_region_result *res = parsed_result;
9848         int ret = -ENOTSUP;
9849 #ifdef RTE_LIBRTE_I40E_PMD
9850         struct rte_pmd_i40e_queue_region_conf region_conf;
9851         enum rte_pmd_i40e_queue_region_op op_type;
9852 #endif
9853
9854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9855                 return;
9856
9857 #ifdef RTE_LIBRTE_I40E_PMD
9858         memset(&region_conf, 0, sizeof(region_conf));
9859         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9860         region_conf.region_id = res->region_id;
9861         region_conf.queue_num = res->queue_num_value;
9862         region_conf.queue_start_index = res->queue_id;
9863
9864         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9865                                 op_type, &region_conf);
9866 #endif
9867
9868         switch (ret) {
9869         case 0:
9870                 break;
9871         case -ENOTSUP:
9872                 printf("function not implemented or supported\n");
9873                 break;
9874         default:
9875                 printf("queue region config error: (%s)\n", strerror(-ret));
9876         }
9877 }
9878
9879 cmdline_parse_token_string_t cmd_queue_region_set =
9880 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9881                 set, "set");
9882 cmdline_parse_token_string_t cmd_queue_region_port =
9883         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9884 cmdline_parse_token_num_t cmd_queue_region_port_id =
9885         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9886                                 port_id, UINT16);
9887 cmdline_parse_token_string_t cmd_queue_region_cmd =
9888         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9889                                  cmd, "queue-region");
9890 cmdline_parse_token_string_t cmd_queue_region_id =
9891         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9892                                 region, "region_id");
9893 cmdline_parse_token_num_t cmd_queue_region_index =
9894         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9895                                 region_id, UINT8);
9896 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9897         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9898                                 queue_start_index, "queue_start_index");
9899 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9900         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9901                                 queue_id, UINT8);
9902 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9903         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9904                                 queue_num, "queue_num");
9905 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9906         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9907                                 queue_num_value, UINT8);
9908
9909 cmdline_parse_inst_t cmd_queue_region = {
9910         .f = cmd_queue_region_parsed,
9911         .data = NULL,
9912         .help_str = "set port <port_id> queue-region region_id <value> "
9913                 "queue_start_index <value> queue_num <value>: Set a queue region",
9914         .tokens = {
9915                 (void *)&cmd_queue_region_set,
9916                 (void *)&cmd_queue_region_port,
9917                 (void *)&cmd_queue_region_port_id,
9918                 (void *)&cmd_queue_region_cmd,
9919                 (void *)&cmd_queue_region_id,
9920                 (void *)&cmd_queue_region_index,
9921                 (void *)&cmd_queue_region_queue_start_index,
9922                 (void *)&cmd_queue_region_queue_id,
9923                 (void *)&cmd_queue_region_queue_num,
9924                 (void *)&cmd_queue_region_queue_num_value,
9925                 NULL,
9926         },
9927 };
9928
9929 /* *** queue region and flowtype set *** */
9930 struct cmd_region_flowtype_result {
9931         cmdline_fixed_string_t set;
9932         cmdline_fixed_string_t port;
9933         portid_t port_id;
9934         cmdline_fixed_string_t cmd;
9935         cmdline_fixed_string_t region;
9936         uint8_t  region_id;
9937         cmdline_fixed_string_t flowtype;
9938         uint8_t  flowtype_id;
9939 };
9940
9941 static void
9942 cmd_region_flowtype_parsed(void *parsed_result,
9943                         __rte_unused struct cmdline *cl,
9944                         __rte_unused void *data)
9945 {
9946         struct cmd_region_flowtype_result *res = parsed_result;
9947         int ret = -ENOTSUP;
9948 #ifdef RTE_LIBRTE_I40E_PMD
9949         struct rte_pmd_i40e_queue_region_conf region_conf;
9950         enum rte_pmd_i40e_queue_region_op op_type;
9951 #endif
9952
9953         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9954                 return;
9955
9956 #ifdef RTE_LIBRTE_I40E_PMD
9957         memset(&region_conf, 0, sizeof(region_conf));
9958
9959         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9960         region_conf.region_id = res->region_id;
9961         region_conf.hw_flowtype = res->flowtype_id;
9962
9963         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9964                         op_type, &region_conf);
9965 #endif
9966
9967         switch (ret) {
9968         case 0:
9969                 break;
9970         case -ENOTSUP:
9971                 printf("function not implemented or supported\n");
9972                 break;
9973         default:
9974                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9975         }
9976 }
9977
9978 cmdline_parse_token_string_t cmd_region_flowtype_set =
9979 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9980                                 set, "set");
9981 cmdline_parse_token_string_t cmd_region_flowtype_port =
9982         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9983                                 port, "port");
9984 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9985         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9986                                 port_id, UINT16);
9987 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9988         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9989                                 cmd, "queue-region");
9990 cmdline_parse_token_string_t cmd_region_flowtype_index =
9991         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9992                                 region, "region_id");
9993 cmdline_parse_token_num_t cmd_region_flowtype_id =
9994         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9995                                 region_id, UINT8);
9996 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9997         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9998                                 flowtype, "flowtype");
9999 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10000         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10001                                 flowtype_id, UINT8);
10002 cmdline_parse_inst_t cmd_region_flowtype = {
10003         .f = cmd_region_flowtype_parsed,
10004         .data = NULL,
10005         .help_str = "set port <port_id> queue-region region_id <value> "
10006                 "flowtype <value>: Set a flowtype region index",
10007         .tokens = {
10008                 (void *)&cmd_region_flowtype_set,
10009                 (void *)&cmd_region_flowtype_port,
10010                 (void *)&cmd_region_flowtype_port_index,
10011                 (void *)&cmd_region_flowtype_cmd,
10012                 (void *)&cmd_region_flowtype_index,
10013                 (void *)&cmd_region_flowtype_id,
10014                 (void *)&cmd_region_flowtype_flow_index,
10015                 (void *)&cmd_region_flowtype_flow_id,
10016                 NULL,
10017         },
10018 };
10019
10020 /* *** User Priority (UP) to queue region (region_id) set *** */
10021 struct cmd_user_priority_region_result {
10022         cmdline_fixed_string_t set;
10023         cmdline_fixed_string_t port;
10024         portid_t port_id;
10025         cmdline_fixed_string_t cmd;
10026         cmdline_fixed_string_t user_priority;
10027         uint8_t  user_priority_id;
10028         cmdline_fixed_string_t region;
10029         uint8_t  region_id;
10030 };
10031
10032 static void
10033 cmd_user_priority_region_parsed(void *parsed_result,
10034                         __rte_unused struct cmdline *cl,
10035                         __rte_unused void *data)
10036 {
10037         struct cmd_user_priority_region_result *res = parsed_result;
10038         int ret = -ENOTSUP;
10039 #ifdef RTE_LIBRTE_I40E_PMD
10040         struct rte_pmd_i40e_queue_region_conf region_conf;
10041         enum rte_pmd_i40e_queue_region_op op_type;
10042 #endif
10043
10044         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10045                 return;
10046
10047 #ifdef RTE_LIBRTE_I40E_PMD
10048         memset(&region_conf, 0, sizeof(region_conf));
10049         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10050         region_conf.user_priority = res->user_priority_id;
10051         region_conf.region_id = res->region_id;
10052
10053         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10054                                 op_type, &region_conf);
10055 #endif
10056
10057         switch (ret) {
10058         case 0:
10059                 break;
10060         case -ENOTSUP:
10061                 printf("function not implemented or supported\n");
10062                 break;
10063         default:
10064                 printf("user_priority region config error: (%s)\n",
10065                                 strerror(-ret));
10066         }
10067 }
10068
10069 cmdline_parse_token_string_t cmd_user_priority_region_set =
10070         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10071                                 set, "set");
10072 cmdline_parse_token_string_t cmd_user_priority_region_port =
10073         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10074                                 port, "port");
10075 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10076         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10077                                 port_id, UINT16);
10078 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10079         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10080                                 cmd, "queue-region");
10081 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10082         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10083                                 user_priority, "UP");
10084 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10085         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10086                                 user_priority_id, UINT8);
10087 cmdline_parse_token_string_t cmd_user_priority_region_region =
10088         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10089                                 region, "region_id");
10090 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10091         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10092                                 region_id, UINT8);
10093
10094 cmdline_parse_inst_t cmd_user_priority_region = {
10095         .f = cmd_user_priority_region_parsed,
10096         .data = NULL,
10097         .help_str = "set port <port_id> queue-region UP <value> "
10098                 "region_id <value>: Set the mapping of User Priority (UP) "
10099                 "to queue region (region_id) ",
10100         .tokens = {
10101                 (void *)&cmd_user_priority_region_set,
10102                 (void *)&cmd_user_priority_region_port,
10103                 (void *)&cmd_user_priority_region_port_index,
10104                 (void *)&cmd_user_priority_region_cmd,
10105                 (void *)&cmd_user_priority_region_UP,
10106                 (void *)&cmd_user_priority_region_UP_id,
10107                 (void *)&cmd_user_priority_region_region,
10108                 (void *)&cmd_user_priority_region_region_id,
10109                 NULL,
10110         },
10111 };
10112
10113 /* *** flush all queue region related configuration *** */
10114 struct cmd_flush_queue_region_result {
10115         cmdline_fixed_string_t set;
10116         cmdline_fixed_string_t port;
10117         portid_t port_id;
10118         cmdline_fixed_string_t cmd;
10119         cmdline_fixed_string_t flush;
10120         cmdline_fixed_string_t what;
10121 };
10122
10123 static void
10124 cmd_flush_queue_region_parsed(void *parsed_result,
10125                         __rte_unused struct cmdline *cl,
10126                         __rte_unused void *data)
10127 {
10128         struct cmd_flush_queue_region_result *res = parsed_result;
10129         int ret = -ENOTSUP;
10130 #ifdef RTE_LIBRTE_I40E_PMD
10131         struct rte_pmd_i40e_queue_region_conf region_conf;
10132         enum rte_pmd_i40e_queue_region_op op_type;
10133 #endif
10134
10135         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10136                 return;
10137
10138 #ifdef RTE_LIBRTE_I40E_PMD
10139         memset(&region_conf, 0, sizeof(region_conf));
10140
10141         if (strcmp(res->what, "on") == 0)
10142                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10143         else
10144                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10145
10146         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10147                                 op_type, &region_conf);
10148 #endif
10149
10150         switch (ret) {
10151         case 0:
10152                 break;
10153         case -ENOTSUP:
10154                 printf("function not implemented or supported\n");
10155                 break;
10156         default:
10157                 printf("queue region config flush error: (%s)\n",
10158                                 strerror(-ret));
10159         }
10160 }
10161
10162 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10163         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10164                                 set, "set");
10165 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10166         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10167                                 port, "port");
10168 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10169         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10170                                 port_id, UINT16);
10171 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10172         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10173                                 cmd, "queue-region");
10174 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10175         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10176                                 flush, "flush");
10177 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10178         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10179                                 what, "on#off");
10180
10181 cmdline_parse_inst_t cmd_flush_queue_region = {
10182         .f = cmd_flush_queue_region_parsed,
10183         .data = NULL,
10184         .help_str = "set port <port_id> queue-region flush on|off"
10185                 ": flush all queue region related configuration",
10186         .tokens = {
10187                 (void *)&cmd_flush_queue_region_set,
10188                 (void *)&cmd_flush_queue_region_port,
10189                 (void *)&cmd_flush_queue_region_port_index,
10190                 (void *)&cmd_flush_queue_region_cmd,
10191                 (void *)&cmd_flush_queue_region_flush,
10192                 (void *)&cmd_flush_queue_region_what,
10193                 NULL,
10194         },
10195 };
10196
10197 /* *** get all queue region related configuration info *** */
10198 struct cmd_show_queue_region_info {
10199         cmdline_fixed_string_t show;
10200         cmdline_fixed_string_t port;
10201         portid_t port_id;
10202         cmdline_fixed_string_t cmd;
10203 };
10204
10205 static void
10206 cmd_show_queue_region_info_parsed(void *parsed_result,
10207                         __rte_unused struct cmdline *cl,
10208                         __rte_unused void *data)
10209 {
10210         struct cmd_show_queue_region_info *res = parsed_result;
10211         int ret = -ENOTSUP;
10212 #ifdef RTE_LIBRTE_I40E_PMD
10213         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10214         enum rte_pmd_i40e_queue_region_op op_type;
10215 #endif
10216
10217         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10218                 return;
10219
10220 #ifdef RTE_LIBRTE_I40E_PMD
10221         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10222
10223         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10224
10225         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10226                                         op_type, &rte_pmd_regions);
10227
10228         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10229 #endif
10230
10231         switch (ret) {
10232         case 0:
10233                 break;
10234         case -ENOTSUP:
10235                 printf("function not implemented or supported\n");
10236                 break;
10237         default:
10238                 printf("queue region config info show error: (%s)\n",
10239                                 strerror(-ret));
10240         }
10241 }
10242
10243 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10244 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10245                                 show, "show");
10246 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10247         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10248                                 port, "port");
10249 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10250         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10251                                 port_id, UINT16);
10252 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10253         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10254                                 cmd, "queue-region");
10255
10256 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10257         .f = cmd_show_queue_region_info_parsed,
10258         .data = NULL,
10259         .help_str = "show port <port_id> queue-region"
10260                 ": show all queue region related configuration info",
10261         .tokens = {
10262                 (void *)&cmd_show_queue_region_info_get,
10263                 (void *)&cmd_show_queue_region_info_port,
10264                 (void *)&cmd_show_queue_region_info_port_index,
10265                 (void *)&cmd_show_queue_region_info_cmd,
10266                 NULL,
10267         },
10268 };
10269
10270 /* *** ADD/REMOVE A 2tuple FILTER *** */
10271 struct cmd_2tuple_filter_result {
10272         cmdline_fixed_string_t filter;
10273         portid_t port_id;
10274         cmdline_fixed_string_t ops;
10275         cmdline_fixed_string_t dst_port;
10276         uint16_t dst_port_value;
10277         cmdline_fixed_string_t protocol;
10278         uint8_t protocol_value;
10279         cmdline_fixed_string_t mask;
10280         uint8_t  mask_value;
10281         cmdline_fixed_string_t tcp_flags;
10282         uint8_t tcp_flags_value;
10283         cmdline_fixed_string_t priority;
10284         uint8_t  priority_value;
10285         cmdline_fixed_string_t queue;
10286         uint16_t  queue_id;
10287 };
10288
10289 static void
10290 cmd_2tuple_filter_parsed(void *parsed_result,
10291                         __rte_unused struct cmdline *cl,
10292                         __rte_unused void *data)
10293 {
10294         struct rte_eth_ntuple_filter filter;
10295         struct cmd_2tuple_filter_result *res = parsed_result;
10296         int ret = 0;
10297
10298         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10299         if (ret < 0) {
10300                 printf("ntuple filter is not supported on port %u.\n",
10301                         res->port_id);
10302                 return;
10303         }
10304
10305         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10306
10307         filter.flags = RTE_2TUPLE_FLAGS;
10308         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10309         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10310         filter.proto = res->protocol_value;
10311         filter.priority = res->priority_value;
10312         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10313                 printf("nonzero tcp_flags is only meaningful"
10314                         " when protocol is TCP.\n");
10315                 return;
10316         }
10317         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10318                 printf("invalid TCP flags.\n");
10319                 return;
10320         }
10321
10322         if (res->tcp_flags_value != 0) {
10323                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10324                 filter.tcp_flags = res->tcp_flags_value;
10325         }
10326
10327         /* need convert to big endian. */
10328         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10329         filter.queue = res->queue_id;
10330
10331         if (!strcmp(res->ops, "add"))
10332                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10333                                 RTE_ETH_FILTER_NTUPLE,
10334                                 RTE_ETH_FILTER_ADD,
10335                                 &filter);
10336         else
10337                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10338                                 RTE_ETH_FILTER_NTUPLE,
10339                                 RTE_ETH_FILTER_DELETE,
10340                                 &filter);
10341         if (ret < 0)
10342                 printf("2tuple filter programming error: (%s)\n",
10343                         strerror(-ret));
10344
10345 }
10346
10347 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10348         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10349                                  filter, "2tuple_filter");
10350 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10351         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10352                                 port_id, UINT16);
10353 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10354         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10355                                  ops, "add#del");
10356 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10357         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10358                                 dst_port, "dst_port");
10359 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10360         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10361                                 dst_port_value, UINT16);
10362 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10363         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10364                                 protocol, "protocol");
10365 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10366         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10367                                 protocol_value, UINT8);
10368 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10369         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10370                                 mask, "mask");
10371 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10372         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10373                                 mask_value, INT8);
10374 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10375         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10376                                 tcp_flags, "tcp_flags");
10377 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10378         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10379                                 tcp_flags_value, UINT8);
10380 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10381         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10382                                 priority, "priority");
10383 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10384         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10385                                 priority_value, UINT8);
10386 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10387         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10388                                 queue, "queue");
10389 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10390         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10391                                 queue_id, UINT16);
10392
10393 cmdline_parse_inst_t cmd_2tuple_filter = {
10394         .f = cmd_2tuple_filter_parsed,
10395         .data = NULL,
10396         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10397                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10398                 "<queue_id>: Add a 2tuple filter",
10399         .tokens = {
10400                 (void *)&cmd_2tuple_filter_filter,
10401                 (void *)&cmd_2tuple_filter_port_id,
10402                 (void *)&cmd_2tuple_filter_ops,
10403                 (void *)&cmd_2tuple_filter_dst_port,
10404                 (void *)&cmd_2tuple_filter_dst_port_value,
10405                 (void *)&cmd_2tuple_filter_protocol,
10406                 (void *)&cmd_2tuple_filter_protocol_value,
10407                 (void *)&cmd_2tuple_filter_mask,
10408                 (void *)&cmd_2tuple_filter_mask_value,
10409                 (void *)&cmd_2tuple_filter_tcp_flags,
10410                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10411                 (void *)&cmd_2tuple_filter_priority,
10412                 (void *)&cmd_2tuple_filter_priority_value,
10413                 (void *)&cmd_2tuple_filter_queue,
10414                 (void *)&cmd_2tuple_filter_queue_id,
10415                 NULL,
10416         },
10417 };
10418
10419 /* *** ADD/REMOVE A 5tuple FILTER *** */
10420 struct cmd_5tuple_filter_result {
10421         cmdline_fixed_string_t filter;
10422         portid_t port_id;
10423         cmdline_fixed_string_t ops;
10424         cmdline_fixed_string_t dst_ip;
10425         cmdline_ipaddr_t dst_ip_value;
10426         cmdline_fixed_string_t src_ip;
10427         cmdline_ipaddr_t src_ip_value;
10428         cmdline_fixed_string_t dst_port;
10429         uint16_t dst_port_value;
10430         cmdline_fixed_string_t src_port;
10431         uint16_t src_port_value;
10432         cmdline_fixed_string_t protocol;
10433         uint8_t protocol_value;
10434         cmdline_fixed_string_t mask;
10435         uint8_t  mask_value;
10436         cmdline_fixed_string_t tcp_flags;
10437         uint8_t tcp_flags_value;
10438         cmdline_fixed_string_t priority;
10439         uint8_t  priority_value;
10440         cmdline_fixed_string_t queue;
10441         uint16_t  queue_id;
10442 };
10443
10444 static void
10445 cmd_5tuple_filter_parsed(void *parsed_result,
10446                         __rte_unused struct cmdline *cl,
10447                         __rte_unused void *data)
10448 {
10449         struct rte_eth_ntuple_filter filter;
10450         struct cmd_5tuple_filter_result *res = parsed_result;
10451         int ret = 0;
10452
10453         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10454         if (ret < 0) {
10455                 printf("ntuple filter is not supported on port %u.\n",
10456                         res->port_id);
10457                 return;
10458         }
10459
10460         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10461
10462         filter.flags = RTE_5TUPLE_FLAGS;
10463         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10464         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10465         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10466         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10467         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10468         filter.proto = res->protocol_value;
10469         filter.priority = res->priority_value;
10470         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10471                 printf("nonzero tcp_flags is only meaningful"
10472                         " when protocol is TCP.\n");
10473                 return;
10474         }
10475         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10476                 printf("invalid TCP flags.\n");
10477                 return;
10478         }
10479
10480         if (res->tcp_flags_value != 0) {
10481                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10482                 filter.tcp_flags = res->tcp_flags_value;
10483         }
10484
10485         if (res->dst_ip_value.family == AF_INET)
10486                 /* no need to convert, already big endian. */
10487                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10488         else {
10489                 if (filter.dst_ip_mask == 0) {
10490                         printf("can not support ipv6 involved compare.\n");
10491                         return;
10492                 }
10493                 filter.dst_ip = 0;
10494         }
10495
10496         if (res->src_ip_value.family == AF_INET)
10497                 /* no need to convert, already big endian. */
10498                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10499         else {
10500                 if (filter.src_ip_mask == 0) {
10501                         printf("can not support ipv6 involved compare.\n");
10502                         return;
10503                 }
10504                 filter.src_ip = 0;
10505         }
10506         /* need convert to big endian. */
10507         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10508         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10509         filter.queue = res->queue_id;
10510
10511         if (!strcmp(res->ops, "add"))
10512                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10513                                 RTE_ETH_FILTER_NTUPLE,
10514                                 RTE_ETH_FILTER_ADD,
10515                                 &filter);
10516         else
10517                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10518                                 RTE_ETH_FILTER_NTUPLE,
10519                                 RTE_ETH_FILTER_DELETE,
10520                                 &filter);
10521         if (ret < 0)
10522                 printf("5tuple filter programming error: (%s)\n",
10523                         strerror(-ret));
10524 }
10525
10526 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10527         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10528                                  filter, "5tuple_filter");
10529 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10530         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10531                                 port_id, UINT16);
10532 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10533         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10534                                  ops, "add#del");
10535 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10536         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10537                                 dst_ip, "dst_ip");
10538 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10539         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10540                                 dst_ip_value);
10541 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10542         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10543                                 src_ip, "src_ip");
10544 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10545         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10546                                 src_ip_value);
10547 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10548         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10549                                 dst_port, "dst_port");
10550 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10551         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10552                                 dst_port_value, UINT16);
10553 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10554         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10555                                 src_port, "src_port");
10556 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10557         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10558                                 src_port_value, UINT16);
10559 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10560         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10561                                 protocol, "protocol");
10562 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10563         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10564                                 protocol_value, UINT8);
10565 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10566         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10567                                 mask, "mask");
10568 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10569         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10570                                 mask_value, INT8);
10571 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10572         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10573                                 tcp_flags, "tcp_flags");
10574 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10575         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10576                                 tcp_flags_value, UINT8);
10577 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10578         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10579                                 priority, "priority");
10580 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10581         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10582                                 priority_value, UINT8);
10583 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10584         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10585                                 queue, "queue");
10586 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10587         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10588                                 queue_id, UINT16);
10589
10590 cmdline_parse_inst_t cmd_5tuple_filter = {
10591         .f = cmd_5tuple_filter_parsed,
10592         .data = NULL,
10593         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10594                 "src_ip <value> dst_port <value> src_port <value> "
10595                 "protocol <value>  mask <value> tcp_flags <value> "
10596                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10597         .tokens = {
10598                 (void *)&cmd_5tuple_filter_filter,
10599                 (void *)&cmd_5tuple_filter_port_id,
10600                 (void *)&cmd_5tuple_filter_ops,
10601                 (void *)&cmd_5tuple_filter_dst_ip,
10602                 (void *)&cmd_5tuple_filter_dst_ip_value,
10603                 (void *)&cmd_5tuple_filter_src_ip,
10604                 (void *)&cmd_5tuple_filter_src_ip_value,
10605                 (void *)&cmd_5tuple_filter_dst_port,
10606                 (void *)&cmd_5tuple_filter_dst_port_value,
10607                 (void *)&cmd_5tuple_filter_src_port,
10608                 (void *)&cmd_5tuple_filter_src_port_value,
10609                 (void *)&cmd_5tuple_filter_protocol,
10610                 (void *)&cmd_5tuple_filter_protocol_value,
10611                 (void *)&cmd_5tuple_filter_mask,
10612                 (void *)&cmd_5tuple_filter_mask_value,
10613                 (void *)&cmd_5tuple_filter_tcp_flags,
10614                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10615                 (void *)&cmd_5tuple_filter_priority,
10616                 (void *)&cmd_5tuple_filter_priority_value,
10617                 (void *)&cmd_5tuple_filter_queue,
10618                 (void *)&cmd_5tuple_filter_queue_id,
10619                 NULL,
10620         },
10621 };
10622
10623 /* *** ADD/REMOVE A flex FILTER *** */
10624 struct cmd_flex_filter_result {
10625         cmdline_fixed_string_t filter;
10626         cmdline_fixed_string_t ops;
10627         portid_t port_id;
10628         cmdline_fixed_string_t len;
10629         uint8_t len_value;
10630         cmdline_fixed_string_t bytes;
10631         cmdline_fixed_string_t bytes_value;
10632         cmdline_fixed_string_t mask;
10633         cmdline_fixed_string_t mask_value;
10634         cmdline_fixed_string_t priority;
10635         uint8_t priority_value;
10636         cmdline_fixed_string_t queue;
10637         uint16_t queue_id;
10638 };
10639
10640 static int xdigit2val(unsigned char c)
10641 {
10642         int val;
10643         if (isdigit(c))
10644                 val = c - '0';
10645         else if (isupper(c))
10646                 val = c - 'A' + 10;
10647         else
10648                 val = c - 'a' + 10;
10649         return val;
10650 }
10651
10652 static void
10653 cmd_flex_filter_parsed(void *parsed_result,
10654                           __rte_unused struct cmdline *cl,
10655                           __rte_unused void *data)
10656 {
10657         int ret = 0;
10658         struct rte_eth_flex_filter filter;
10659         struct cmd_flex_filter_result *res = parsed_result;
10660         char *bytes_ptr, *mask_ptr;
10661         uint16_t len, i, j = 0;
10662         char c;
10663         int val;
10664         uint8_t byte = 0;
10665
10666         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10667                 printf("the len exceed the max length 128\n");
10668                 return;
10669         }
10670         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10671         filter.len = res->len_value;
10672         filter.priority = res->priority_value;
10673         filter.queue = res->queue_id;
10674         bytes_ptr = res->bytes_value;
10675         mask_ptr = res->mask_value;
10676
10677          /* translate bytes string to array. */
10678         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10679                 (bytes_ptr[1] == 'X')))
10680                 bytes_ptr += 2;
10681         len = strnlen(bytes_ptr, res->len_value * 2);
10682         if (len == 0 || (len % 8 != 0)) {
10683                 printf("please check len and bytes input\n");
10684                 return;
10685         }
10686         for (i = 0; i < len; i++) {
10687                 c = bytes_ptr[i];
10688                 if (isxdigit(c) == 0) {
10689                         /* invalid characters. */
10690                         printf("invalid input\n");
10691                         return;
10692                 }
10693                 val = xdigit2val(c);
10694                 if (i % 2) {
10695                         byte |= val;
10696                         filter.bytes[j] = byte;
10697                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10698                         j++;
10699                         byte = 0;
10700                 } else
10701                         byte |= val << 4;
10702         }
10703         printf("\n");
10704          /* translate mask string to uint8_t array. */
10705         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10706                 (mask_ptr[1] == 'X')))
10707                 mask_ptr += 2;
10708         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10709         if (len == 0) {
10710                 printf("invalid input\n");
10711                 return;
10712         }
10713         j = 0;
10714         byte = 0;
10715         for (i = 0; i < len; i++) {
10716                 c = mask_ptr[i];
10717                 if (isxdigit(c) == 0) {
10718                         /* invalid characters. */
10719                         printf("invalid input\n");
10720                         return;
10721                 }
10722                 val = xdigit2val(c);
10723                 if (i % 2) {
10724                         byte |= val;
10725                         filter.mask[j] = byte;
10726                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10727                         j++;
10728                         byte = 0;
10729                 } else
10730                         byte |= val << 4;
10731         }
10732         printf("\n");
10733
10734         if (!strcmp(res->ops, "add"))
10735                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10736                                 RTE_ETH_FILTER_FLEXIBLE,
10737                                 RTE_ETH_FILTER_ADD,
10738                                 &filter);
10739         else
10740                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10741                                 RTE_ETH_FILTER_FLEXIBLE,
10742                                 RTE_ETH_FILTER_DELETE,
10743                                 &filter);
10744
10745         if (ret < 0)
10746                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10747 }
10748
10749 cmdline_parse_token_string_t cmd_flex_filter_filter =
10750         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10751                                 filter, "flex_filter");
10752 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10753         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10754                                 port_id, UINT16);
10755 cmdline_parse_token_string_t cmd_flex_filter_ops =
10756         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10757                                 ops, "add#del");
10758 cmdline_parse_token_string_t cmd_flex_filter_len =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10760                                 len, "len");
10761 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10762         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10763                                 len_value, UINT8);
10764 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10765         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10766                                 bytes, "bytes");
10767 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10768         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10769                                 bytes_value, NULL);
10770 cmdline_parse_token_string_t cmd_flex_filter_mask =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10772                                 mask, "mask");
10773 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10775                                 mask_value, NULL);
10776 cmdline_parse_token_string_t cmd_flex_filter_priority =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10778                                 priority, "priority");
10779 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10780         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10781                                 priority_value, UINT8);
10782 cmdline_parse_token_string_t cmd_flex_filter_queue =
10783         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10784                                 queue, "queue");
10785 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10786         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10787                                 queue_id, UINT16);
10788 cmdline_parse_inst_t cmd_flex_filter = {
10789         .f = cmd_flex_filter_parsed,
10790         .data = NULL,
10791         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10792                 "<value> mask <value> priority <value> queue <queue_id>: "
10793                 "Add/Del a flex filter",
10794         .tokens = {
10795                 (void *)&cmd_flex_filter_filter,
10796                 (void *)&cmd_flex_filter_port_id,
10797                 (void *)&cmd_flex_filter_ops,
10798                 (void *)&cmd_flex_filter_len,
10799                 (void *)&cmd_flex_filter_len_value,
10800                 (void *)&cmd_flex_filter_bytes,
10801                 (void *)&cmd_flex_filter_bytes_value,
10802                 (void *)&cmd_flex_filter_mask,
10803                 (void *)&cmd_flex_filter_mask_value,
10804                 (void *)&cmd_flex_filter_priority,
10805                 (void *)&cmd_flex_filter_priority_value,
10806                 (void *)&cmd_flex_filter_queue,
10807                 (void *)&cmd_flex_filter_queue_id,
10808                 NULL,
10809         },
10810 };
10811
10812 /* *** Filters Control *** */
10813
10814 /* *** deal with ethertype filter *** */
10815 struct cmd_ethertype_filter_result {
10816         cmdline_fixed_string_t filter;
10817         portid_t port_id;
10818         cmdline_fixed_string_t ops;
10819         cmdline_fixed_string_t mac;
10820         struct rte_ether_addr mac_addr;
10821         cmdline_fixed_string_t ethertype;
10822         uint16_t ethertype_value;
10823         cmdline_fixed_string_t drop;
10824         cmdline_fixed_string_t queue;
10825         uint16_t  queue_id;
10826 };
10827
10828 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10829         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10830                                  filter, "ethertype_filter");
10831 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10832         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10833                               port_id, UINT16);
10834 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10835         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10836                                  ops, "add#del");
10837 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10838         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10839                                  mac, "mac_addr#mac_ignr");
10840 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10841         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10842                                      mac_addr);
10843 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10844         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10845                                  ethertype, "ethertype");
10846 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10847         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10848                               ethertype_value, UINT16);
10849 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10850         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10851                                  drop, "drop#fwd");
10852 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10853         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10854                                  queue, "queue");
10855 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10856         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10857                               queue_id, UINT16);
10858
10859 static void
10860 cmd_ethertype_filter_parsed(void *parsed_result,
10861                           __rte_unused struct cmdline *cl,
10862                           __rte_unused void *data)
10863 {
10864         struct cmd_ethertype_filter_result *res = parsed_result;
10865         struct rte_eth_ethertype_filter filter;
10866         int ret = 0;
10867
10868         ret = rte_eth_dev_filter_supported(res->port_id,
10869                         RTE_ETH_FILTER_ETHERTYPE);
10870         if (ret < 0) {
10871                 printf("ethertype filter is not supported on port %u.\n",
10872                         res->port_id);
10873                 return;
10874         }
10875
10876         memset(&filter, 0, sizeof(filter));
10877         if (!strcmp(res->mac, "mac_addr")) {
10878                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10879                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10880                         sizeof(struct rte_ether_addr));
10881         }
10882         if (!strcmp(res->drop, "drop"))
10883                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10884         filter.ether_type = res->ethertype_value;
10885         filter.queue = res->queue_id;
10886
10887         if (!strcmp(res->ops, "add"))
10888                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10889                                 RTE_ETH_FILTER_ETHERTYPE,
10890                                 RTE_ETH_FILTER_ADD,
10891                                 &filter);
10892         else
10893                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10894                                 RTE_ETH_FILTER_ETHERTYPE,
10895                                 RTE_ETH_FILTER_DELETE,
10896                                 &filter);
10897         if (ret < 0)
10898                 printf("ethertype filter programming error: (%s)\n",
10899                         strerror(-ret));
10900 }
10901
10902 cmdline_parse_inst_t cmd_ethertype_filter = {
10903         .f = cmd_ethertype_filter_parsed,
10904         .data = NULL,
10905         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10906                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10907                 "Add or delete an ethertype filter entry",
10908         .tokens = {
10909                 (void *)&cmd_ethertype_filter_filter,
10910                 (void *)&cmd_ethertype_filter_port_id,
10911                 (void *)&cmd_ethertype_filter_ops,
10912                 (void *)&cmd_ethertype_filter_mac,
10913                 (void *)&cmd_ethertype_filter_mac_addr,
10914                 (void *)&cmd_ethertype_filter_ethertype,
10915                 (void *)&cmd_ethertype_filter_ethertype_value,
10916                 (void *)&cmd_ethertype_filter_drop,
10917                 (void *)&cmd_ethertype_filter_queue,
10918                 (void *)&cmd_ethertype_filter_queue_id,
10919                 NULL,
10920         },
10921 };
10922
10923 /* *** deal with flow director filter *** */
10924 struct cmd_flow_director_result {
10925         cmdline_fixed_string_t flow_director_filter;
10926         portid_t port_id;
10927         cmdline_fixed_string_t mode;
10928         cmdline_fixed_string_t mode_value;
10929         cmdline_fixed_string_t ops;
10930         cmdline_fixed_string_t flow;
10931         cmdline_fixed_string_t flow_type;
10932         cmdline_fixed_string_t ether;
10933         uint16_t ether_type;
10934         cmdline_fixed_string_t src;
10935         cmdline_ipaddr_t ip_src;
10936         uint16_t port_src;
10937         cmdline_fixed_string_t dst;
10938         cmdline_ipaddr_t ip_dst;
10939         uint16_t port_dst;
10940         cmdline_fixed_string_t verify_tag;
10941         uint32_t verify_tag_value;
10942         cmdline_fixed_string_t tos;
10943         uint8_t tos_value;
10944         cmdline_fixed_string_t proto;
10945         uint8_t proto_value;
10946         cmdline_fixed_string_t ttl;
10947         uint8_t ttl_value;
10948         cmdline_fixed_string_t vlan;
10949         uint16_t vlan_value;
10950         cmdline_fixed_string_t flexbytes;
10951         cmdline_fixed_string_t flexbytes_value;
10952         cmdline_fixed_string_t pf_vf;
10953         cmdline_fixed_string_t drop;
10954         cmdline_fixed_string_t queue;
10955         uint16_t  queue_id;
10956         cmdline_fixed_string_t fd_id;
10957         uint32_t  fd_id_value;
10958         cmdline_fixed_string_t mac;
10959         struct rte_ether_addr mac_addr;
10960         cmdline_fixed_string_t tunnel;
10961         cmdline_fixed_string_t tunnel_type;
10962         cmdline_fixed_string_t tunnel_id;
10963         uint32_t tunnel_id_value;
10964         cmdline_fixed_string_t packet;
10965         char filepath[];
10966 };
10967
10968 static inline int
10969 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10970 {
10971         char s[256];
10972         const char *p, *p0 = q_arg;
10973         char *end;
10974         unsigned long int_fld;
10975         char *str_fld[max_num];
10976         int i;
10977         unsigned size;
10978         int ret = -1;
10979
10980         p = strchr(p0, '(');
10981         if (p == NULL)
10982                 return -1;
10983         ++p;
10984         p0 = strchr(p, ')');
10985         if (p0 == NULL)
10986                 return -1;
10987
10988         size = p0 - p;
10989         if (size >= sizeof(s))
10990                 return -1;
10991
10992         snprintf(s, sizeof(s), "%.*s", size, p);
10993         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10994         if (ret < 0 || ret > max_num)
10995                 return -1;
10996         for (i = 0; i < ret; i++) {
10997                 errno = 0;
10998                 int_fld = strtoul(str_fld[i], &end, 0);
10999                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11000                         return -1;
11001                 flexbytes[i] = (uint8_t)int_fld;
11002         }
11003         return ret;
11004 }
11005
11006 static uint16_t
11007 str2flowtype(char *string)
11008 {
11009         uint8_t i = 0;
11010         static const struct {
11011                 char str[32];
11012                 uint16_t type;
11013         } flowtype_str[] = {
11014                 {"raw", RTE_ETH_FLOW_RAW},
11015                 {"ipv4", RTE_ETH_FLOW_IPV4},
11016                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11017                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11018                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11019                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11020                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11021                 {"ipv6", RTE_ETH_FLOW_IPV6},
11022                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11023                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11024                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11025                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11026                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11027                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11028         };
11029
11030         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11031                 if (!strcmp(flowtype_str[i].str, string))
11032                         return flowtype_str[i].type;
11033         }
11034
11035         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11036                 return (uint16_t)atoi(string);
11037
11038         return RTE_ETH_FLOW_UNKNOWN;
11039 }
11040
11041 static enum rte_eth_fdir_tunnel_type
11042 str2fdir_tunneltype(char *string)
11043 {
11044         uint8_t i = 0;
11045
11046         static const struct {
11047                 char str[32];
11048                 enum rte_eth_fdir_tunnel_type type;
11049         } tunneltype_str[] = {
11050                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11051                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11052         };
11053
11054         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11055                 if (!strcmp(tunneltype_str[i].str, string))
11056                         return tunneltype_str[i].type;
11057         }
11058         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11059 }
11060
11061 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11062 do { \
11063         if ((ip_addr).family == AF_INET) \
11064                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11065         else { \
11066                 printf("invalid parameter.\n"); \
11067                 return; \
11068         } \
11069 } while (0)
11070
11071 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11072 do { \
11073         if ((ip_addr).family == AF_INET6) \
11074                 rte_memcpy(&(ip), \
11075                                  &((ip_addr).addr.ipv6), \
11076                                  sizeof(struct in6_addr)); \
11077         else { \
11078                 printf("invalid parameter.\n"); \
11079                 return; \
11080         } \
11081 } while (0)
11082
11083 static void
11084 cmd_flow_director_filter_parsed(void *parsed_result,
11085                           __rte_unused struct cmdline *cl,
11086                           __rte_unused void *data)
11087 {
11088         struct cmd_flow_director_result *res = parsed_result;
11089         struct rte_eth_fdir_filter entry;
11090         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11091         char *end;
11092         unsigned long vf_id;
11093         int ret = 0;
11094
11095         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11096         if (ret < 0) {
11097                 printf("flow director is not supported on port %u.\n",
11098                         res->port_id);
11099                 return;
11100         }
11101         memset(flexbytes, 0, sizeof(flexbytes));
11102         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11103
11104         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11105                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11106                         printf("Please set mode to MAC-VLAN.\n");
11107                         return;
11108                 }
11109         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11110                 if (strcmp(res->mode_value, "Tunnel")) {
11111                         printf("Please set mode to Tunnel.\n");
11112                         return;
11113                 }
11114         } else {
11115                 if (!strcmp(res->mode_value, "raw")) {
11116 #ifdef RTE_LIBRTE_I40E_PMD
11117                         struct rte_pmd_i40e_flow_type_mapping
11118                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11119                         struct rte_pmd_i40e_pkt_template_conf conf;
11120                         uint16_t flow_type = str2flowtype(res->flow_type);
11121                         uint16_t i, port = res->port_id;
11122                         uint8_t add;
11123
11124                         memset(&conf, 0, sizeof(conf));
11125
11126                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11127                                 printf("Invalid flow type specified.\n");
11128                                 return;
11129                         }
11130                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11131                                                                  mapping);
11132                         if (ret)
11133                                 return;
11134                         if (mapping[flow_type].pctype == 0ULL) {
11135                                 printf("Invalid flow type specified.\n");
11136                                 return;
11137                         }
11138                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11139                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11140                                         conf.input.pctype = i;
11141                                         break;
11142                                 }
11143                         }
11144
11145                         conf.input.packet = open_file(res->filepath,
11146                                                 &conf.input.length);
11147                         if (!conf.input.packet)
11148                                 return;
11149                         if (!strcmp(res->drop, "drop"))
11150                                 conf.action.behavior =
11151                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11152                         else
11153                                 conf.action.behavior =
11154                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11155                         conf.action.report_status =
11156                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11157                         conf.action.rx_queue = res->queue_id;
11158                         conf.soft_id = res->fd_id_value;
11159                         add  = strcmp(res->ops, "del") ? 1 : 0;
11160                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11161                                                                         &conf,
11162                                                                         add);
11163                         if (ret < 0)
11164                                 printf("flow director config error: (%s)\n",
11165                                        strerror(-ret));
11166                         close_file(conf.input.packet);
11167 #endif
11168                         return;
11169                 } else if (strcmp(res->mode_value, "IP")) {
11170                         printf("Please set mode to IP or raw.\n");
11171                         return;
11172                 }
11173                 entry.input.flow_type = str2flowtype(res->flow_type);
11174         }
11175
11176         ret = parse_flexbytes(res->flexbytes_value,
11177                                         flexbytes,
11178                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11179         if (ret < 0) {
11180                 printf("error: Cannot parse flexbytes input.\n");
11181                 return;
11182         }
11183
11184         switch (entry.input.flow_type) {
11185         case RTE_ETH_FLOW_FRAG_IPV4:
11186         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11187                 entry.input.flow.ip4_flow.proto = res->proto_value;
11188                 /* fall-through */
11189         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11190         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11191                 IPV4_ADDR_TO_UINT(res->ip_dst,
11192                         entry.input.flow.ip4_flow.dst_ip);
11193                 IPV4_ADDR_TO_UINT(res->ip_src,
11194                         entry.input.flow.ip4_flow.src_ip);
11195                 entry.input.flow.ip4_flow.tos = res->tos_value;
11196                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11197                 /* need convert to big endian. */
11198                 entry.input.flow.udp4_flow.dst_port =
11199                                 rte_cpu_to_be_16(res->port_dst);
11200                 entry.input.flow.udp4_flow.src_port =
11201                                 rte_cpu_to_be_16(res->port_src);
11202                 break;
11203         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11204                 IPV4_ADDR_TO_UINT(res->ip_dst,
11205                         entry.input.flow.sctp4_flow.ip.dst_ip);
11206                 IPV4_ADDR_TO_UINT(res->ip_src,
11207                         entry.input.flow.sctp4_flow.ip.src_ip);
11208                 entry.input.flow.ip4_flow.tos = res->tos_value;
11209                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11210                 /* need convert to big endian. */
11211                 entry.input.flow.sctp4_flow.dst_port =
11212                                 rte_cpu_to_be_16(res->port_dst);
11213                 entry.input.flow.sctp4_flow.src_port =
11214                                 rte_cpu_to_be_16(res->port_src);
11215                 entry.input.flow.sctp4_flow.verify_tag =
11216                                 rte_cpu_to_be_32(res->verify_tag_value);
11217                 break;
11218         case RTE_ETH_FLOW_FRAG_IPV6:
11219         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11220                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11221                 /* fall-through */
11222         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11223         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11224                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11225                         entry.input.flow.ipv6_flow.dst_ip);
11226                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11227                         entry.input.flow.ipv6_flow.src_ip);
11228                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11229                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11230                 /* need convert to big endian. */
11231                 entry.input.flow.udp6_flow.dst_port =
11232                                 rte_cpu_to_be_16(res->port_dst);
11233                 entry.input.flow.udp6_flow.src_port =
11234                                 rte_cpu_to_be_16(res->port_src);
11235                 break;
11236         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11237                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11238                         entry.input.flow.sctp6_flow.ip.dst_ip);
11239                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11240                         entry.input.flow.sctp6_flow.ip.src_ip);
11241                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11242                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11243                 /* need convert to big endian. */
11244                 entry.input.flow.sctp6_flow.dst_port =
11245                                 rte_cpu_to_be_16(res->port_dst);
11246                 entry.input.flow.sctp6_flow.src_port =
11247                                 rte_cpu_to_be_16(res->port_src);
11248                 entry.input.flow.sctp6_flow.verify_tag =
11249                                 rte_cpu_to_be_32(res->verify_tag_value);
11250                 break;
11251         case RTE_ETH_FLOW_L2_PAYLOAD:
11252                 entry.input.flow.l2_flow.ether_type =
11253                         rte_cpu_to_be_16(res->ether_type);
11254                 break;
11255         default:
11256                 break;
11257         }
11258
11259         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11260                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11261                                  &res->mac_addr,
11262                                  sizeof(struct rte_ether_addr));
11263
11264         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11265                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11266                                  &res->mac_addr,
11267                                  sizeof(struct rte_ether_addr));
11268                 entry.input.flow.tunnel_flow.tunnel_type =
11269                         str2fdir_tunneltype(res->tunnel_type);
11270                 entry.input.flow.tunnel_flow.tunnel_id =
11271                         rte_cpu_to_be_32(res->tunnel_id_value);
11272         }
11273
11274         rte_memcpy(entry.input.flow_ext.flexbytes,
11275                    flexbytes,
11276                    RTE_ETH_FDIR_MAX_FLEXLEN);
11277
11278         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11279
11280         entry.action.flex_off = 0;  /*use 0 by default */
11281         if (!strcmp(res->drop, "drop"))
11282                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11283         else
11284                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11285
11286         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11287             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11288                 if (!strcmp(res->pf_vf, "pf"))
11289                         entry.input.flow_ext.is_vf = 0;
11290                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11291                         struct rte_eth_dev_info dev_info;
11292
11293                         ret = eth_dev_info_get_print_err(res->port_id,
11294                                                 &dev_info);
11295                         if (ret != 0)
11296                                 return;
11297
11298                         errno = 0;
11299                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11300                         if (errno != 0 || *end != '\0' ||
11301                             vf_id >= dev_info.max_vfs) {
11302                                 printf("invalid parameter %s.\n", res->pf_vf);
11303                                 return;
11304                         }
11305                         entry.input.flow_ext.is_vf = 1;
11306                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11307                 } else {
11308                         printf("invalid parameter %s.\n", res->pf_vf);
11309                         return;
11310                 }
11311         }
11312
11313         /* set to report FD ID by default */
11314         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11315         entry.action.rx_queue = res->queue_id;
11316         entry.soft_id = res->fd_id_value;
11317         if (!strcmp(res->ops, "add"))
11318                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11319                                              RTE_ETH_FILTER_ADD, &entry);
11320         else if (!strcmp(res->ops, "del"))
11321                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11322                                              RTE_ETH_FILTER_DELETE, &entry);
11323         else
11324                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11325                                              RTE_ETH_FILTER_UPDATE, &entry);
11326         if (ret < 0)
11327                 printf("flow director programming error: (%s)\n",
11328                         strerror(-ret));
11329 }
11330
11331 cmdline_parse_token_string_t cmd_flow_director_filter =
11332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11333                                  flow_director_filter, "flow_director_filter");
11334 cmdline_parse_token_num_t cmd_flow_director_port_id =
11335         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11336                               port_id, UINT16);
11337 cmdline_parse_token_string_t cmd_flow_director_ops =
11338         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11339                                  ops, "add#del#update");
11340 cmdline_parse_token_string_t cmd_flow_director_flow =
11341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11342                                  flow, "flow");
11343 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11345                 flow_type, NULL);
11346 cmdline_parse_token_string_t cmd_flow_director_ether =
11347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348                                  ether, "ether");
11349 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11350         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11351                               ether_type, UINT16);
11352 cmdline_parse_token_string_t cmd_flow_director_src =
11353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354                                  src, "src");
11355 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11356         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11357                                  ip_src);
11358 cmdline_parse_token_num_t cmd_flow_director_port_src =
11359         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11360                               port_src, UINT16);
11361 cmdline_parse_token_string_t cmd_flow_director_dst =
11362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11363                                  dst, "dst");
11364 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11365         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11366                                  ip_dst);
11367 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11368         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11369                               port_dst, UINT16);
11370 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11372                                   verify_tag, "verify_tag");
11373 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11374         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11375                               verify_tag_value, UINT32);
11376 cmdline_parse_token_string_t cmd_flow_director_tos =
11377         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11378                                  tos, "tos");
11379 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11380         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11381                               tos_value, UINT8);
11382 cmdline_parse_token_string_t cmd_flow_director_proto =
11383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11384                                  proto, "proto");
11385 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11386         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11387                               proto_value, UINT8);
11388 cmdline_parse_token_string_t cmd_flow_director_ttl =
11389         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11390                                  ttl, "ttl");
11391 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11392         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11393                               ttl_value, UINT8);
11394 cmdline_parse_token_string_t cmd_flow_director_vlan =
11395         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11396                                  vlan, "vlan");
11397 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11398         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11399                               vlan_value, UINT16);
11400 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11401         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11402                                  flexbytes, "flexbytes");
11403 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11405                               flexbytes_value, NULL);
11406 cmdline_parse_token_string_t cmd_flow_director_drop =
11407         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11408                                  drop, "drop#fwd");
11409 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11411                               pf_vf, NULL);
11412 cmdline_parse_token_string_t cmd_flow_director_queue =
11413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11414                                  queue, "queue");
11415 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11416         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11417                               queue_id, UINT16);
11418 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11419         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11420                                  fd_id, "fd_id");
11421 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11422         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11423                               fd_id_value, UINT32);
11424
11425 cmdline_parse_token_string_t cmd_flow_director_mode =
11426         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11427                                  mode, "mode");
11428 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11429         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11430                                  mode_value, "IP");
11431 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11432         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11433                                  mode_value, "MAC-VLAN");
11434 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11435         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11436                                  mode_value, "Tunnel");
11437 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11439                                  mode_value, "raw");
11440 cmdline_parse_token_string_t cmd_flow_director_mac =
11441         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11442                                  mac, "mac");
11443 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11444         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11445                                     mac_addr);
11446 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11448                                  tunnel, "tunnel");
11449 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11451                                  tunnel_type, "NVGRE#VxLAN");
11452 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11453         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11454                                  tunnel_id, "tunnel-id");
11455 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11456         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11457                               tunnel_id_value, UINT32);
11458 cmdline_parse_token_string_t cmd_flow_director_packet =
11459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11460                                  packet, "packet");
11461 cmdline_parse_token_string_t cmd_flow_director_filepath =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11463                                  filepath, NULL);
11464
11465 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11466         .f = cmd_flow_director_filter_parsed,
11467         .data = NULL,
11468         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11469                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11470                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11471                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11472                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11473                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11474                 "fd_id <fd_id_value>: "
11475                 "Add or delete an ip flow director entry on NIC",
11476         .tokens = {
11477                 (void *)&cmd_flow_director_filter,
11478                 (void *)&cmd_flow_director_port_id,
11479                 (void *)&cmd_flow_director_mode,
11480                 (void *)&cmd_flow_director_mode_ip,
11481                 (void *)&cmd_flow_director_ops,
11482                 (void *)&cmd_flow_director_flow,
11483                 (void *)&cmd_flow_director_flow_type,
11484                 (void *)&cmd_flow_director_src,
11485                 (void *)&cmd_flow_director_ip_src,
11486                 (void *)&cmd_flow_director_dst,
11487                 (void *)&cmd_flow_director_ip_dst,
11488                 (void *)&cmd_flow_director_tos,
11489                 (void *)&cmd_flow_director_tos_value,
11490                 (void *)&cmd_flow_director_proto,
11491                 (void *)&cmd_flow_director_proto_value,
11492                 (void *)&cmd_flow_director_ttl,
11493                 (void *)&cmd_flow_director_ttl_value,
11494                 (void *)&cmd_flow_director_vlan,
11495                 (void *)&cmd_flow_director_vlan_value,
11496                 (void *)&cmd_flow_director_flexbytes,
11497                 (void *)&cmd_flow_director_flexbytes_value,
11498                 (void *)&cmd_flow_director_drop,
11499                 (void *)&cmd_flow_director_pf_vf,
11500                 (void *)&cmd_flow_director_queue,
11501                 (void *)&cmd_flow_director_queue_id,
11502                 (void *)&cmd_flow_director_fd_id,
11503                 (void *)&cmd_flow_director_fd_id_value,
11504                 NULL,
11505         },
11506 };
11507
11508 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11509         .f = cmd_flow_director_filter_parsed,
11510         .data = NULL,
11511         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11512                 "director entry on NIC",
11513         .tokens = {
11514                 (void *)&cmd_flow_director_filter,
11515                 (void *)&cmd_flow_director_port_id,
11516                 (void *)&cmd_flow_director_mode,
11517                 (void *)&cmd_flow_director_mode_ip,
11518                 (void *)&cmd_flow_director_ops,
11519                 (void *)&cmd_flow_director_flow,
11520                 (void *)&cmd_flow_director_flow_type,
11521                 (void *)&cmd_flow_director_src,
11522                 (void *)&cmd_flow_director_ip_src,
11523                 (void *)&cmd_flow_director_port_src,
11524                 (void *)&cmd_flow_director_dst,
11525                 (void *)&cmd_flow_director_ip_dst,
11526                 (void *)&cmd_flow_director_port_dst,
11527                 (void *)&cmd_flow_director_tos,
11528                 (void *)&cmd_flow_director_tos_value,
11529                 (void *)&cmd_flow_director_ttl,
11530                 (void *)&cmd_flow_director_ttl_value,
11531                 (void *)&cmd_flow_director_vlan,
11532                 (void *)&cmd_flow_director_vlan_value,
11533                 (void *)&cmd_flow_director_flexbytes,
11534                 (void *)&cmd_flow_director_flexbytes_value,
11535                 (void *)&cmd_flow_director_drop,
11536                 (void *)&cmd_flow_director_pf_vf,
11537                 (void *)&cmd_flow_director_queue,
11538                 (void *)&cmd_flow_director_queue_id,
11539                 (void *)&cmd_flow_director_fd_id,
11540                 (void *)&cmd_flow_director_fd_id_value,
11541                 NULL,
11542         },
11543 };
11544
11545 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11546         .f = cmd_flow_director_filter_parsed,
11547         .data = NULL,
11548         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11549                 "director entry on NIC",
11550         .tokens = {
11551                 (void *)&cmd_flow_director_filter,
11552                 (void *)&cmd_flow_director_port_id,
11553                 (void *)&cmd_flow_director_mode,
11554                 (void *)&cmd_flow_director_mode_ip,
11555                 (void *)&cmd_flow_director_ops,
11556                 (void *)&cmd_flow_director_flow,
11557                 (void *)&cmd_flow_director_flow_type,
11558                 (void *)&cmd_flow_director_src,
11559                 (void *)&cmd_flow_director_ip_src,
11560                 (void *)&cmd_flow_director_port_src,
11561                 (void *)&cmd_flow_director_dst,
11562                 (void *)&cmd_flow_director_ip_dst,
11563                 (void *)&cmd_flow_director_port_dst,
11564                 (void *)&cmd_flow_director_verify_tag,
11565                 (void *)&cmd_flow_director_verify_tag_value,
11566                 (void *)&cmd_flow_director_tos,
11567                 (void *)&cmd_flow_director_tos_value,
11568                 (void *)&cmd_flow_director_ttl,
11569                 (void *)&cmd_flow_director_ttl_value,
11570                 (void *)&cmd_flow_director_vlan,
11571                 (void *)&cmd_flow_director_vlan_value,
11572                 (void *)&cmd_flow_director_flexbytes,
11573                 (void *)&cmd_flow_director_flexbytes_value,
11574                 (void *)&cmd_flow_director_drop,
11575                 (void *)&cmd_flow_director_pf_vf,
11576                 (void *)&cmd_flow_director_queue,
11577                 (void *)&cmd_flow_director_queue_id,
11578                 (void *)&cmd_flow_director_fd_id,
11579                 (void *)&cmd_flow_director_fd_id_value,
11580                 NULL,
11581         },
11582 };
11583
11584 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11585         .f = cmd_flow_director_filter_parsed,
11586         .data = NULL,
11587         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11588                 "director entry on NIC",
11589         .tokens = {
11590                 (void *)&cmd_flow_director_filter,
11591                 (void *)&cmd_flow_director_port_id,
11592                 (void *)&cmd_flow_director_mode,
11593                 (void *)&cmd_flow_director_mode_ip,
11594                 (void *)&cmd_flow_director_ops,
11595                 (void *)&cmd_flow_director_flow,
11596                 (void *)&cmd_flow_director_flow_type,
11597                 (void *)&cmd_flow_director_ether,
11598                 (void *)&cmd_flow_director_ether_type,
11599                 (void *)&cmd_flow_director_flexbytes,
11600                 (void *)&cmd_flow_director_flexbytes_value,
11601                 (void *)&cmd_flow_director_drop,
11602                 (void *)&cmd_flow_director_pf_vf,
11603                 (void *)&cmd_flow_director_queue,
11604                 (void *)&cmd_flow_director_queue_id,
11605                 (void *)&cmd_flow_director_fd_id,
11606                 (void *)&cmd_flow_director_fd_id_value,
11607                 NULL,
11608         },
11609 };
11610
11611 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11612         .f = cmd_flow_director_filter_parsed,
11613         .data = NULL,
11614         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11615                 "director entry on NIC",
11616         .tokens = {
11617                 (void *)&cmd_flow_director_filter,
11618                 (void *)&cmd_flow_director_port_id,
11619                 (void *)&cmd_flow_director_mode,
11620                 (void *)&cmd_flow_director_mode_mac_vlan,
11621                 (void *)&cmd_flow_director_ops,
11622                 (void *)&cmd_flow_director_mac,
11623                 (void *)&cmd_flow_director_mac_addr,
11624                 (void *)&cmd_flow_director_vlan,
11625                 (void *)&cmd_flow_director_vlan_value,
11626                 (void *)&cmd_flow_director_flexbytes,
11627                 (void *)&cmd_flow_director_flexbytes_value,
11628                 (void *)&cmd_flow_director_drop,
11629                 (void *)&cmd_flow_director_queue,
11630                 (void *)&cmd_flow_director_queue_id,
11631                 (void *)&cmd_flow_director_fd_id,
11632                 (void *)&cmd_flow_director_fd_id_value,
11633                 NULL,
11634         },
11635 };
11636
11637 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11638         .f = cmd_flow_director_filter_parsed,
11639         .data = NULL,
11640         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11641                 "director entry on NIC",
11642         .tokens = {
11643                 (void *)&cmd_flow_director_filter,
11644                 (void *)&cmd_flow_director_port_id,
11645                 (void *)&cmd_flow_director_mode,
11646                 (void *)&cmd_flow_director_mode_tunnel,
11647                 (void *)&cmd_flow_director_ops,
11648                 (void *)&cmd_flow_director_mac,
11649                 (void *)&cmd_flow_director_mac_addr,
11650                 (void *)&cmd_flow_director_vlan,
11651                 (void *)&cmd_flow_director_vlan_value,
11652                 (void *)&cmd_flow_director_tunnel,
11653                 (void *)&cmd_flow_director_tunnel_type,
11654                 (void *)&cmd_flow_director_tunnel_id,
11655                 (void *)&cmd_flow_director_tunnel_id_value,
11656                 (void *)&cmd_flow_director_flexbytes,
11657                 (void *)&cmd_flow_director_flexbytes_value,
11658                 (void *)&cmd_flow_director_drop,
11659                 (void *)&cmd_flow_director_queue,
11660                 (void *)&cmd_flow_director_queue_id,
11661                 (void *)&cmd_flow_director_fd_id,
11662                 (void *)&cmd_flow_director_fd_id_value,
11663                 NULL,
11664         },
11665 };
11666
11667 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11668         .f = cmd_flow_director_filter_parsed,
11669         .data = NULL,
11670         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11671                 "director entry on NIC",
11672         .tokens = {
11673                 (void *)&cmd_flow_director_filter,
11674                 (void *)&cmd_flow_director_port_id,
11675                 (void *)&cmd_flow_director_mode,
11676                 (void *)&cmd_flow_director_mode_raw,
11677                 (void *)&cmd_flow_director_ops,
11678                 (void *)&cmd_flow_director_flow,
11679                 (void *)&cmd_flow_director_flow_type,
11680                 (void *)&cmd_flow_director_drop,
11681                 (void *)&cmd_flow_director_queue,
11682                 (void *)&cmd_flow_director_queue_id,
11683                 (void *)&cmd_flow_director_fd_id,
11684                 (void *)&cmd_flow_director_fd_id_value,
11685                 (void *)&cmd_flow_director_packet,
11686                 (void *)&cmd_flow_director_filepath,
11687                 NULL,
11688         },
11689 };
11690
11691 struct cmd_flush_flow_director_result {
11692         cmdline_fixed_string_t flush_flow_director;
11693         portid_t port_id;
11694 };
11695
11696 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11697         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11698                                  flush_flow_director, "flush_flow_director");
11699 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11700         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11701                               port_id, UINT16);
11702
11703 static void
11704 cmd_flush_flow_director_parsed(void *parsed_result,
11705                           __rte_unused struct cmdline *cl,
11706                           __rte_unused void *data)
11707 {
11708         struct cmd_flow_director_result *res = parsed_result;
11709         int ret = 0;
11710
11711         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11712         if (ret < 0) {
11713                 printf("flow director is not supported on port %u.\n",
11714                         res->port_id);
11715                 return;
11716         }
11717
11718         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11719                         RTE_ETH_FILTER_FLUSH, NULL);
11720         if (ret < 0)
11721                 printf("flow director table flushing error: (%s)\n",
11722                         strerror(-ret));
11723 }
11724
11725 cmdline_parse_inst_t cmd_flush_flow_director = {
11726         .f = cmd_flush_flow_director_parsed,
11727         .data = NULL,
11728         .help_str = "flush_flow_director <port_id>: "
11729                 "Flush all flow director entries of a device on NIC",
11730         .tokens = {
11731                 (void *)&cmd_flush_flow_director_flush,
11732                 (void *)&cmd_flush_flow_director_port_id,
11733                 NULL,
11734         },
11735 };
11736
11737 /* *** deal with flow director mask *** */
11738 struct cmd_flow_director_mask_result {
11739         cmdline_fixed_string_t flow_director_mask;
11740         portid_t port_id;
11741         cmdline_fixed_string_t mode;
11742         cmdline_fixed_string_t mode_value;
11743         cmdline_fixed_string_t vlan;
11744         uint16_t vlan_mask;
11745         cmdline_fixed_string_t src_mask;
11746         cmdline_ipaddr_t ipv4_src;
11747         cmdline_ipaddr_t ipv6_src;
11748         uint16_t port_src;
11749         cmdline_fixed_string_t dst_mask;
11750         cmdline_ipaddr_t ipv4_dst;
11751         cmdline_ipaddr_t ipv6_dst;
11752         uint16_t port_dst;
11753         cmdline_fixed_string_t mac;
11754         uint8_t mac_addr_byte_mask;
11755         cmdline_fixed_string_t tunnel_id;
11756         uint32_t tunnel_id_mask;
11757         cmdline_fixed_string_t tunnel_type;
11758         uint8_t tunnel_type_mask;
11759 };
11760
11761 static void
11762 cmd_flow_director_mask_parsed(void *parsed_result,
11763                           __rte_unused struct cmdline *cl,
11764                           __rte_unused void *data)
11765 {
11766         struct cmd_flow_director_mask_result *res = parsed_result;
11767         struct rte_eth_fdir_masks *mask;
11768         struct rte_port *port;
11769
11770         port = &ports[res->port_id];
11771         /** Check if the port is not started **/
11772         if (port->port_status != RTE_PORT_STOPPED) {
11773                 printf("Please stop port %d first\n", res->port_id);
11774                 return;
11775         }
11776
11777         mask = &port->dev_conf.fdir_conf.mask;
11778
11779         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11780                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11781                         printf("Please set mode to MAC-VLAN.\n");
11782                         return;
11783                 }
11784
11785                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11786         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11787                 if (strcmp(res->mode_value, "Tunnel")) {
11788                         printf("Please set mode to Tunnel.\n");
11789                         return;
11790                 }
11791
11792                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11793                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11794                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11795                 mask->tunnel_type_mask = res->tunnel_type_mask;
11796         } else {
11797                 if (strcmp(res->mode_value, "IP")) {
11798                         printf("Please set mode to IP.\n");
11799                         return;
11800                 }
11801
11802                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11803                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11804                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11805                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11806                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11807                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11808                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11809         }
11810
11811         cmd_reconfig_device_queue(res->port_id, 1, 1);
11812 }
11813
11814 cmdline_parse_token_string_t cmd_flow_director_mask =
11815         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11816                                  flow_director_mask, "flow_director_mask");
11817 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11818         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11819                               port_id, UINT16);
11820 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11821         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11822                                  vlan, "vlan");
11823 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11824         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11825                               vlan_mask, UINT16);
11826 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11827         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11828                                  src_mask, "src_mask");
11829 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11830         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11831                                  ipv4_src);
11832 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11833         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11834                                  ipv6_src);
11835 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11836         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11837                               port_src, UINT16);
11838 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11839         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11840                                  dst_mask, "dst_mask");
11841 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11842         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11843                                  ipv4_dst);
11844 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11845         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11846                                  ipv6_dst);
11847 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11848         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11849                               port_dst, UINT16);
11850
11851 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11852         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11853                                  mode, "mode");
11854 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11856                                  mode_value, "IP");
11857 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11858         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11859                                  mode_value, "MAC-VLAN");
11860 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11862                                  mode_value, "Tunnel");
11863 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11865                                  mac, "mac");
11866 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11867         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11868                               mac_addr_byte_mask, UINT8);
11869 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11870         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11871                                  tunnel_type, "tunnel-type");
11872 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11873         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11874                               tunnel_type_mask, UINT8);
11875 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11877                                  tunnel_id, "tunnel-id");
11878 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11879         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11880                               tunnel_id_mask, UINT32);
11881
11882 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11883         .f = cmd_flow_director_mask_parsed,
11884         .data = NULL,
11885         .help_str = "flow_director_mask ... : "
11886                 "Set IP mode flow director's mask on NIC",
11887         .tokens = {
11888                 (void *)&cmd_flow_director_mask,
11889                 (void *)&cmd_flow_director_mask_port_id,
11890                 (void *)&cmd_flow_director_mask_mode,
11891                 (void *)&cmd_flow_director_mask_mode_ip,
11892                 (void *)&cmd_flow_director_mask_vlan,
11893                 (void *)&cmd_flow_director_mask_vlan_value,
11894                 (void *)&cmd_flow_director_mask_src,
11895                 (void *)&cmd_flow_director_mask_ipv4_src,
11896                 (void *)&cmd_flow_director_mask_ipv6_src,
11897                 (void *)&cmd_flow_director_mask_port_src,
11898                 (void *)&cmd_flow_director_mask_dst,
11899                 (void *)&cmd_flow_director_mask_ipv4_dst,
11900                 (void *)&cmd_flow_director_mask_ipv6_dst,
11901                 (void *)&cmd_flow_director_mask_port_dst,
11902                 NULL,
11903         },
11904 };
11905
11906 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11907         .f = cmd_flow_director_mask_parsed,
11908         .data = NULL,
11909         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11910                 "flow director's mask on NIC",
11911         .tokens = {
11912                 (void *)&cmd_flow_director_mask,
11913                 (void *)&cmd_flow_director_mask_port_id,
11914                 (void *)&cmd_flow_director_mask_mode,
11915                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11916                 (void *)&cmd_flow_director_mask_vlan,
11917                 (void *)&cmd_flow_director_mask_vlan_value,
11918                 NULL,
11919         },
11920 };
11921
11922 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11923         .f = cmd_flow_director_mask_parsed,
11924         .data = NULL,
11925         .help_str = "flow_director_mask ... : Set tunnel mode "
11926                 "flow director's mask on NIC",
11927         .tokens = {
11928                 (void *)&cmd_flow_director_mask,
11929                 (void *)&cmd_flow_director_mask_port_id,
11930                 (void *)&cmd_flow_director_mask_mode,
11931                 (void *)&cmd_flow_director_mask_mode_tunnel,
11932                 (void *)&cmd_flow_director_mask_vlan,
11933                 (void *)&cmd_flow_director_mask_vlan_value,
11934                 (void *)&cmd_flow_director_mask_mac,
11935                 (void *)&cmd_flow_director_mask_mac_value,
11936                 (void *)&cmd_flow_director_mask_tunnel_type,
11937                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11938                 (void *)&cmd_flow_director_mask_tunnel_id,
11939                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11940                 NULL,
11941         },
11942 };
11943
11944 /* *** deal with flow director mask on flexible payload *** */
11945 struct cmd_flow_director_flex_mask_result {
11946         cmdline_fixed_string_t flow_director_flexmask;
11947         portid_t port_id;
11948         cmdline_fixed_string_t flow;
11949         cmdline_fixed_string_t flow_type;
11950         cmdline_fixed_string_t mask;
11951 };
11952
11953 static void
11954 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11955                           __rte_unused struct cmdline *cl,
11956                           __rte_unused void *data)
11957 {
11958         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11959         struct rte_eth_fdir_info fdir_info;
11960         struct rte_eth_fdir_flex_mask flex_mask;
11961         struct rte_port *port;
11962         uint64_t flow_type_mask;
11963         uint16_t i;
11964         int ret;
11965
11966         port = &ports[res->port_id];
11967         /** Check if the port is not started **/
11968         if (port->port_status != RTE_PORT_STOPPED) {
11969                 printf("Please stop port %d first\n", res->port_id);
11970                 return;
11971         }
11972
11973         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11974         ret = parse_flexbytes(res->mask,
11975                         flex_mask.mask,
11976                         RTE_ETH_FDIR_MAX_FLEXLEN);
11977         if (ret < 0) {
11978                 printf("error: Cannot parse mask input.\n");
11979                 return;
11980         }
11981
11982         memset(&fdir_info, 0, sizeof(fdir_info));
11983         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11984                                 RTE_ETH_FILTER_INFO, &fdir_info);
11985         if (ret < 0) {
11986                 printf("Cannot get FDir filter info\n");
11987                 return;
11988         }
11989
11990         if (!strcmp(res->flow_type, "none")) {
11991                 /* means don't specify the flow type */
11992                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11993                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11994                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11995                                0, sizeof(struct rte_eth_fdir_flex_mask));
11996                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11997                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11998                                  &flex_mask,
11999                                  sizeof(struct rte_eth_fdir_flex_mask));
12000                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12001                 return;
12002         }
12003         flow_type_mask = fdir_info.flow_types_mask[0];
12004         if (!strcmp(res->flow_type, "all")) {
12005                 if (!flow_type_mask) {
12006                         printf("No flow type supported\n");
12007                         return;
12008                 }
12009                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12010                         if (flow_type_mask & (1ULL << i)) {
12011                                 flex_mask.flow_type = i;
12012                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12013                         }
12014                 }
12015                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12016                 return;
12017         }
12018         flex_mask.flow_type = str2flowtype(res->flow_type);
12019         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12020                 printf("Flow type %s not supported on port %d\n",
12021                                 res->flow_type, res->port_id);
12022                 return;
12023         }
12024         fdir_set_flex_mask(res->port_id, &flex_mask);
12025         cmd_reconfig_device_queue(res->port_id, 1, 1);
12026 }
12027
12028 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12029         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12030                                  flow_director_flexmask,
12031                                  "flow_director_flex_mask");
12032 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12033         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12034                               port_id, UINT16);
12035 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12036         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12037                                  flow, "flow");
12038 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12040                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12041                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12042 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12043         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12044                                  mask, NULL);
12045
12046 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12047         .f = cmd_flow_director_flex_mask_parsed,
12048         .data = NULL,
12049         .help_str = "flow_director_flex_mask ... : "
12050                 "Set flow director's flex mask on NIC",
12051         .tokens = {
12052                 (void *)&cmd_flow_director_flexmask,
12053                 (void *)&cmd_flow_director_flexmask_port_id,
12054                 (void *)&cmd_flow_director_flexmask_flow,
12055                 (void *)&cmd_flow_director_flexmask_flow_type,
12056                 (void *)&cmd_flow_director_flexmask_mask,
12057                 NULL,
12058         },
12059 };
12060
12061 /* *** deal with flow director flexible payload configuration *** */
12062 struct cmd_flow_director_flexpayload_result {
12063         cmdline_fixed_string_t flow_director_flexpayload;
12064         portid_t port_id;
12065         cmdline_fixed_string_t payload_layer;
12066         cmdline_fixed_string_t payload_cfg;
12067 };
12068
12069 static inline int
12070 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12071 {
12072         char s[256];
12073         const char *p, *p0 = q_arg;
12074         char *end;
12075         unsigned long int_fld;
12076         char *str_fld[max_num];
12077         int i;
12078         unsigned size;
12079         int ret = -1;
12080
12081         p = strchr(p0, '(');
12082         if (p == NULL)
12083                 return -1;
12084         ++p;
12085         p0 = strchr(p, ')');
12086         if (p0 == NULL)
12087                 return -1;
12088
12089         size = p0 - p;
12090         if (size >= sizeof(s))
12091                 return -1;
12092
12093         snprintf(s, sizeof(s), "%.*s", size, p);
12094         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12095         if (ret < 0 || ret > max_num)
12096                 return -1;
12097         for (i = 0; i < ret; i++) {
12098                 errno = 0;
12099                 int_fld = strtoul(str_fld[i], &end, 0);
12100                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12101                         return -1;
12102                 offsets[i] = (uint16_t)int_fld;
12103         }
12104         return ret;
12105 }
12106
12107 static void
12108 cmd_flow_director_flxpld_parsed(void *parsed_result,
12109                           __rte_unused struct cmdline *cl,
12110                           __rte_unused void *data)
12111 {
12112         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12113         struct rte_eth_flex_payload_cfg flex_cfg;
12114         struct rte_port *port;
12115         int ret = 0;
12116
12117         port = &ports[res->port_id];
12118         /** Check if the port is not started **/
12119         if (port->port_status != RTE_PORT_STOPPED) {
12120                 printf("Please stop port %d first\n", res->port_id);
12121                 return;
12122         }
12123
12124         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12125
12126         if (!strcmp(res->payload_layer, "raw"))
12127                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12128         else if (!strcmp(res->payload_layer, "l2"))
12129                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12130         else if (!strcmp(res->payload_layer, "l3"))
12131                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12132         else if (!strcmp(res->payload_layer, "l4"))
12133                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12134
12135         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12136                             RTE_ETH_FDIR_MAX_FLEXLEN);
12137         if (ret < 0) {
12138                 printf("error: Cannot parse flex payload input.\n");
12139                 return;
12140         }
12141
12142         fdir_set_flex_payload(res->port_id, &flex_cfg);
12143         cmd_reconfig_device_queue(res->port_id, 1, 1);
12144 }
12145
12146 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12147         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12148                                  flow_director_flexpayload,
12149                                  "flow_director_flex_payload");
12150 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12151         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12152                               port_id, UINT16);
12153 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12154         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12155                                  payload_layer, "raw#l2#l3#l4");
12156 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12158                                  payload_cfg, NULL);
12159
12160 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12161         .f = cmd_flow_director_flxpld_parsed,
12162         .data = NULL,
12163         .help_str = "flow_director_flexpayload ... : "
12164                 "Set flow director's flex payload on NIC",
12165         .tokens = {
12166                 (void *)&cmd_flow_director_flexpayload,
12167                 (void *)&cmd_flow_director_flexpayload_port_id,
12168                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12169                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12170                 NULL,
12171         },
12172 };
12173
12174 /* Generic flow interface command. */
12175 extern cmdline_parse_inst_t cmd_flow;
12176
12177 /* *** Classification Filters Control *** */
12178 /* *** Get symmetric hash enable per port *** */
12179 struct cmd_get_sym_hash_ena_per_port_result {
12180         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12181         portid_t port_id;
12182 };
12183
12184 static void
12185 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12186                                  __rte_unused struct cmdline *cl,
12187                                  __rte_unused void *data)
12188 {
12189         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12190         struct rte_eth_hash_filter_info info;
12191         int ret;
12192
12193         if (rte_eth_dev_filter_supported(res->port_id,
12194                                 RTE_ETH_FILTER_HASH) < 0) {
12195                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12196                                                         res->port_id);
12197                 return;
12198         }
12199
12200         memset(&info, 0, sizeof(info));
12201         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12202         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12203                                                 RTE_ETH_FILTER_GET, &info);
12204
12205         if (ret < 0) {
12206                 printf("Cannot get symmetric hash enable per port "
12207                                         "on port %u\n", res->port_id);
12208                 return;
12209         }
12210
12211         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12212                                 "enabled" : "disabled", res->port_id);
12213 }
12214
12215 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12216         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12217                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12218 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12219         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12220                 port_id, UINT16);
12221
12222 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12223         .f = cmd_get_sym_hash_per_port_parsed,
12224         .data = NULL,
12225         .help_str = "get_sym_hash_ena_per_port <port_id>",
12226         .tokens = {
12227                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12228                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12229                 NULL,
12230         },
12231 };
12232
12233 /* *** Set symmetric hash enable per port *** */
12234 struct cmd_set_sym_hash_ena_per_port_result {
12235         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12236         cmdline_fixed_string_t enable;
12237         portid_t port_id;
12238 };
12239
12240 static void
12241 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12242                                  __rte_unused struct cmdline *cl,
12243                                  __rte_unused void *data)
12244 {
12245         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12246         struct rte_eth_hash_filter_info info;
12247         int ret;
12248
12249         if (rte_eth_dev_filter_supported(res->port_id,
12250                                 RTE_ETH_FILTER_HASH) < 0) {
12251                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12252                                                         res->port_id);
12253                 return;
12254         }
12255
12256         memset(&info, 0, sizeof(info));
12257         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12258         if (!strcmp(res->enable, "enable"))
12259                 info.info.enable = 1;
12260         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12261                                         RTE_ETH_FILTER_SET, &info);
12262         if (ret < 0) {
12263                 printf("Cannot set symmetric hash enable per port on "
12264                                         "port %u\n", res->port_id);
12265                 return;
12266         }
12267         printf("Symmetric hash has been set to %s on port %u\n",
12268                                         res->enable, res->port_id);
12269 }
12270
12271 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12272         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12273                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12274 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12275         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12276                 port_id, UINT16);
12277 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12278         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12279                 enable, "enable#disable");
12280
12281 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12282         .f = cmd_set_sym_hash_per_port_parsed,
12283         .data = NULL,
12284         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12285         .tokens = {
12286                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12287                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12288                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12289                 NULL,
12290         },
12291 };
12292
12293 /* Get global config of hash function */
12294 struct cmd_get_hash_global_config_result {
12295         cmdline_fixed_string_t get_hash_global_config;
12296         portid_t port_id;
12297 };
12298
12299 static char *
12300 flowtype_to_str(uint16_t ftype)
12301 {
12302         uint16_t i;
12303         static struct {
12304                 char str[16];
12305                 uint16_t ftype;
12306         } ftype_table[] = {
12307                 {"ipv4", RTE_ETH_FLOW_IPV4},
12308                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12309                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12310                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12311                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12312                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12313                 {"ipv6", RTE_ETH_FLOW_IPV6},
12314                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12315                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12316                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12317                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12318                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12319                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12320                 {"port", RTE_ETH_FLOW_PORT},
12321                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12322                 {"geneve", RTE_ETH_FLOW_GENEVE},
12323                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12324                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12325         };
12326
12327         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12328                 if (ftype_table[i].ftype == ftype)
12329                         return ftype_table[i].str;
12330         }
12331
12332         return NULL;
12333 }
12334
12335 static void
12336 cmd_get_hash_global_config_parsed(void *parsed_result,
12337                                   __rte_unused struct cmdline *cl,
12338                                   __rte_unused void *data)
12339 {
12340         struct cmd_get_hash_global_config_result *res = parsed_result;
12341         struct rte_eth_hash_filter_info info;
12342         uint32_t idx, offset;
12343         uint16_t i;
12344         char *str;
12345         int ret;
12346
12347         if (rte_eth_dev_filter_supported(res->port_id,
12348                         RTE_ETH_FILTER_HASH) < 0) {
12349                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12350                                                         res->port_id);
12351                 return;
12352         }
12353
12354         memset(&info, 0, sizeof(info));
12355         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12356         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12357                                         RTE_ETH_FILTER_GET, &info);
12358         if (ret < 0) {
12359                 printf("Cannot get hash global configurations by port %d\n",
12360                                                         res->port_id);
12361                 return;
12362         }
12363
12364         switch (info.info.global_conf.hash_func) {
12365         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12366                 printf("Hash function is Toeplitz\n");
12367                 break;
12368         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12369                 printf("Hash function is Simple XOR\n");
12370                 break;
12371         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12372                 printf("Hash function is Symmetric Toeplitz\n");
12373                 break;
12374         default:
12375                 printf("Unknown hash function\n");
12376                 break;
12377         }
12378
12379         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12380                 idx = i / UINT64_BIT;
12381                 offset = i % UINT64_BIT;
12382                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12383                                                 (1ULL << offset)))
12384                         continue;
12385                 str = flowtype_to_str(i);
12386                 if (!str)
12387                         continue;
12388                 printf("Symmetric hash is %s globally for flow type %s "
12389                                                         "by port %d\n",
12390                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12391                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12392                                                         res->port_id);
12393         }
12394 }
12395
12396 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12397         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12398                 get_hash_global_config, "get_hash_global_config");
12399 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12400         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12401                 port_id, UINT16);
12402
12403 cmdline_parse_inst_t cmd_get_hash_global_config = {
12404         .f = cmd_get_hash_global_config_parsed,
12405         .data = NULL,
12406         .help_str = "get_hash_global_config <port_id>",
12407         .tokens = {
12408                 (void *)&cmd_get_hash_global_config_all,
12409                 (void *)&cmd_get_hash_global_config_port_id,
12410                 NULL,
12411         },
12412 };
12413
12414 /* Set global config of hash function */
12415 struct cmd_set_hash_global_config_result {
12416         cmdline_fixed_string_t set_hash_global_config;
12417         portid_t port_id;
12418         cmdline_fixed_string_t hash_func;
12419         cmdline_fixed_string_t flow_type;
12420         cmdline_fixed_string_t enable;
12421 };
12422
12423 static void
12424 cmd_set_hash_global_config_parsed(void *parsed_result,
12425                                   __rte_unused struct cmdline *cl,
12426                                   __rte_unused void *data)
12427 {
12428         struct cmd_set_hash_global_config_result *res = parsed_result;
12429         struct rte_eth_hash_filter_info info;
12430         uint32_t ftype, idx, offset;
12431         int ret;
12432
12433         if (rte_eth_dev_filter_supported(res->port_id,
12434                                 RTE_ETH_FILTER_HASH) < 0) {
12435                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12436                                                         res->port_id);
12437                 return;
12438         }
12439         memset(&info, 0, sizeof(info));
12440         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12441         if (!strcmp(res->hash_func, "toeplitz"))
12442                 info.info.global_conf.hash_func =
12443                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12444         else if (!strcmp(res->hash_func, "simple_xor"))
12445                 info.info.global_conf.hash_func =
12446                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12447         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12448                 info.info.global_conf.hash_func =
12449                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12450         else if (!strcmp(res->hash_func, "default"))
12451                 info.info.global_conf.hash_func =
12452                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12453
12454         ftype = str2flowtype(res->flow_type);
12455         idx = ftype / UINT64_BIT;
12456         offset = ftype % UINT64_BIT;
12457         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12458         if (!strcmp(res->enable, "enable"))
12459                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12460                                                 (1ULL << offset);
12461         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12462                                         RTE_ETH_FILTER_SET, &info);
12463         if (ret < 0)
12464                 printf("Cannot set global hash configurations by port %d\n",
12465                                                         res->port_id);
12466         else
12467                 printf("Global hash configurations have been set "
12468                         "successfully by port %d\n", res->port_id);
12469 }
12470
12471 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12472         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12473                 set_hash_global_config, "set_hash_global_config");
12474 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12475         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12476                 port_id, UINT16);
12477 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12478         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12479                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12480 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12481         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12482                 flow_type,
12483                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12484                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12485 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12486         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12487                 enable, "enable#disable");
12488
12489 cmdline_parse_inst_t cmd_set_hash_global_config = {
12490         .f = cmd_set_hash_global_config_parsed,
12491         .data = NULL,
12492         .help_str = "set_hash_global_config <port_id> "
12493                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12494                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12495                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12496                 "l2_payload enable|disable",
12497         .tokens = {
12498                 (void *)&cmd_set_hash_global_config_all,
12499                 (void *)&cmd_set_hash_global_config_port_id,
12500                 (void *)&cmd_set_hash_global_config_hash_func,
12501                 (void *)&cmd_set_hash_global_config_flow_type,
12502                 (void *)&cmd_set_hash_global_config_enable,
12503                 NULL,
12504         },
12505 };
12506
12507 /* Set hash input set */
12508 struct cmd_set_hash_input_set_result {
12509         cmdline_fixed_string_t set_hash_input_set;
12510         portid_t port_id;
12511         cmdline_fixed_string_t flow_type;
12512         cmdline_fixed_string_t inset_field;
12513         cmdline_fixed_string_t select;
12514 };
12515
12516 static enum rte_eth_input_set_field
12517 str2inset(char *string)
12518 {
12519         uint16_t i;
12520
12521         static const struct {
12522                 char str[32];
12523                 enum rte_eth_input_set_field inset;
12524         } inset_table[] = {
12525                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12526                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12527                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12528                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12529                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12530                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12531                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12532                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12533                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12534                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12535                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12536                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12537                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12538                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12539                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12540                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12541                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12542                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12543                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12544                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12545                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12546                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12547                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12548                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12549                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12550                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12551                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12552                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12553                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12554                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12555                 {"none", RTE_ETH_INPUT_SET_NONE},
12556         };
12557
12558         for (i = 0; i < RTE_DIM(inset_table); i++) {
12559                 if (!strcmp(string, inset_table[i].str))
12560                         return inset_table[i].inset;
12561         }
12562
12563         return RTE_ETH_INPUT_SET_UNKNOWN;
12564 }
12565
12566 static void
12567 cmd_set_hash_input_set_parsed(void *parsed_result,
12568                               __rte_unused struct cmdline *cl,
12569                               __rte_unused void *data)
12570 {
12571         struct cmd_set_hash_input_set_result *res = parsed_result;
12572         struct rte_eth_hash_filter_info info;
12573
12574         memset(&info, 0, sizeof(info));
12575         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12576         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12577         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12578         info.info.input_set_conf.inset_size = 1;
12579         if (!strcmp(res->select, "select"))
12580                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12581         else if (!strcmp(res->select, "add"))
12582                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12583         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12584                                 RTE_ETH_FILTER_SET, &info);
12585 }
12586
12587 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12588         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12589                 set_hash_input_set, "set_hash_input_set");
12590 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12591         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12592                 port_id, UINT16);
12593 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12594         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12595                 flow_type, NULL);
12596 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12597         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12598                 inset_field,
12599                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12600                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12601                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12602                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12603                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12604                 "fld-8th#none");
12605 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12606         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12607                 select, "select#add");
12608
12609 cmdline_parse_inst_t cmd_set_hash_input_set = {
12610         .f = cmd_set_hash_input_set_parsed,
12611         .data = NULL,
12612         .help_str = "set_hash_input_set <port_id> "
12613         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12614         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12615         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12616         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12617         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12618         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12619         "fld-7th|fld-8th|none select|add",
12620         .tokens = {
12621                 (void *)&cmd_set_hash_input_set_cmd,
12622                 (void *)&cmd_set_hash_input_set_port_id,
12623                 (void *)&cmd_set_hash_input_set_flow_type,
12624                 (void *)&cmd_set_hash_input_set_field,
12625                 (void *)&cmd_set_hash_input_set_select,
12626                 NULL,
12627         },
12628 };
12629
12630 /* Set flow director input set */
12631 struct cmd_set_fdir_input_set_result {
12632         cmdline_fixed_string_t set_fdir_input_set;
12633         portid_t port_id;
12634         cmdline_fixed_string_t flow_type;
12635         cmdline_fixed_string_t inset_field;
12636         cmdline_fixed_string_t select;
12637 };
12638
12639 static void
12640 cmd_set_fdir_input_set_parsed(void *parsed_result,
12641         __rte_unused struct cmdline *cl,
12642         __rte_unused void *data)
12643 {
12644         struct cmd_set_fdir_input_set_result *res = parsed_result;
12645         struct rte_eth_fdir_filter_info info;
12646
12647         memset(&info, 0, sizeof(info));
12648         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12649         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12650         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12651         info.info.input_set_conf.inset_size = 1;
12652         if (!strcmp(res->select, "select"))
12653                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12654         else if (!strcmp(res->select, "add"))
12655                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12656         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12657                 RTE_ETH_FILTER_SET, &info);
12658 }
12659
12660 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12661         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12662         set_fdir_input_set, "set_fdir_input_set");
12663 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12664         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12665         port_id, UINT16);
12666 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12667         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12668         flow_type,
12669         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12670         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12671 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12672         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12673         inset_field,
12674         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12675         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12676         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12677         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12678         "sctp-veri-tag#none");
12679 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12680         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12681         select, "select#add");
12682
12683 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12684         .f = cmd_set_fdir_input_set_parsed,
12685         .data = NULL,
12686         .help_str = "set_fdir_input_set <port_id> "
12687         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12688         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12689         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12690         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12691         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12692         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12693         "sctp-veri-tag|none select|add",
12694         .tokens = {
12695                 (void *)&cmd_set_fdir_input_set_cmd,
12696                 (void *)&cmd_set_fdir_input_set_port_id,
12697                 (void *)&cmd_set_fdir_input_set_flow_type,
12698                 (void *)&cmd_set_fdir_input_set_field,
12699                 (void *)&cmd_set_fdir_input_set_select,
12700                 NULL,
12701         },
12702 };
12703
12704 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12705 struct cmd_mcast_addr_result {
12706         cmdline_fixed_string_t mcast_addr_cmd;
12707         cmdline_fixed_string_t what;
12708         uint16_t port_num;
12709         struct rte_ether_addr mc_addr;
12710 };
12711
12712 static void cmd_mcast_addr_parsed(void *parsed_result,
12713                 __rte_unused struct cmdline *cl,
12714                 __rte_unused void *data)
12715 {
12716         struct cmd_mcast_addr_result *res = parsed_result;
12717
12718         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12719                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12720                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12721                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12722                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12723                 return;
12724         }
12725         if (strcmp(res->what, "add") == 0)
12726                 mcast_addr_add(res->port_num, &res->mc_addr);
12727         else
12728                 mcast_addr_remove(res->port_num, &res->mc_addr);
12729 }
12730
12731 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12732         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12733                                  mcast_addr_cmd, "mcast_addr");
12734 cmdline_parse_token_string_t cmd_mcast_addr_what =
12735         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12736                                  "add#remove");
12737 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12738         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12739 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12740         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12741
12742 cmdline_parse_inst_t cmd_mcast_addr = {
12743         .f = cmd_mcast_addr_parsed,
12744         .data = (void *)0,
12745         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12746                 "Add/Remove multicast MAC address on port_id",
12747         .tokens = {
12748                 (void *)&cmd_mcast_addr_cmd,
12749                 (void *)&cmd_mcast_addr_what,
12750                 (void *)&cmd_mcast_addr_portnum,
12751                 (void *)&cmd_mcast_addr_addr,
12752                 NULL,
12753         },
12754 };
12755
12756 /* l2 tunnel config
12757  * only support E-tag now.
12758  */
12759
12760 /* Ether type config */
12761 struct cmd_config_l2_tunnel_eth_type_result {
12762         cmdline_fixed_string_t port;
12763         cmdline_fixed_string_t config;
12764         cmdline_fixed_string_t all;
12765         portid_t id;
12766         cmdline_fixed_string_t l2_tunnel;
12767         cmdline_fixed_string_t l2_tunnel_type;
12768         cmdline_fixed_string_t eth_type;
12769         uint16_t eth_type_val;
12770 };
12771
12772 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_config_l2_tunnel_eth_type_result,
12775                  port, "port");
12776 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_config_l2_tunnel_eth_type_result,
12779                  config, "config");
12780 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12781         TOKEN_STRING_INITIALIZER
12782                 (struct cmd_config_l2_tunnel_eth_type_result,
12783                  all, "all");
12784 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12785         TOKEN_NUM_INITIALIZER
12786                 (struct cmd_config_l2_tunnel_eth_type_result,
12787                  id, UINT16);
12788 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_config_l2_tunnel_eth_type_result,
12791                  l2_tunnel, "l2-tunnel");
12792 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_config_l2_tunnel_eth_type_result,
12795                  l2_tunnel_type, "E-tag");
12796 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_config_l2_tunnel_eth_type_result,
12799                  eth_type, "ether-type");
12800 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12801         TOKEN_NUM_INITIALIZER
12802                 (struct cmd_config_l2_tunnel_eth_type_result,
12803                  eth_type_val, UINT16);
12804
12805 static enum rte_eth_tunnel_type
12806 str2fdir_l2_tunnel_type(char *string)
12807 {
12808         uint32_t i = 0;
12809
12810         static const struct {
12811                 char str[32];
12812                 enum rte_eth_tunnel_type type;
12813         } l2_tunnel_type_str[] = {
12814                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12815         };
12816
12817         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12818                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12819                         return l2_tunnel_type_str[i].type;
12820         }
12821         return RTE_TUNNEL_TYPE_NONE;
12822 }
12823
12824 /* ether type config for all ports */
12825 static void
12826 cmd_config_l2_tunnel_eth_type_all_parsed
12827         (void *parsed_result,
12828          __rte_unused struct cmdline *cl,
12829          __rte_unused void *data)
12830 {
12831         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12832         struct rte_eth_l2_tunnel_conf entry;
12833         portid_t pid;
12834
12835         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12836         entry.ether_type = res->eth_type_val;
12837
12838         RTE_ETH_FOREACH_DEV(pid) {
12839                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12840         }
12841 }
12842
12843 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12844         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12845         .data = NULL,
12846         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12847         .tokens = {
12848                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12849                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12850                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12851                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12852                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12853                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12854                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12855                 NULL,
12856         },
12857 };
12858
12859 /* ether type config for a specific port */
12860 static void
12861 cmd_config_l2_tunnel_eth_type_specific_parsed(
12862         void *parsed_result,
12863         __rte_unused struct cmdline *cl,
12864         __rte_unused void *data)
12865 {
12866         struct cmd_config_l2_tunnel_eth_type_result *res =
12867                  parsed_result;
12868         struct rte_eth_l2_tunnel_conf entry;
12869
12870         if (port_id_is_invalid(res->id, ENABLED_WARN))
12871                 return;
12872
12873         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12874         entry.ether_type = res->eth_type_val;
12875
12876         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12877 }
12878
12879 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12880         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12881         .data = NULL,
12882         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12883         .tokens = {
12884                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12885                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12886                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12887                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12888                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12889                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12890                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12891                 NULL,
12892         },
12893 };
12894
12895 /* Enable/disable l2 tunnel */
12896 struct cmd_config_l2_tunnel_en_dis_result {
12897         cmdline_fixed_string_t port;
12898         cmdline_fixed_string_t config;
12899         cmdline_fixed_string_t all;
12900         portid_t id;
12901         cmdline_fixed_string_t l2_tunnel;
12902         cmdline_fixed_string_t l2_tunnel_type;
12903         cmdline_fixed_string_t en_dis;
12904 };
12905
12906 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12907         TOKEN_STRING_INITIALIZER
12908                 (struct cmd_config_l2_tunnel_en_dis_result,
12909                  port, "port");
12910 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12911         TOKEN_STRING_INITIALIZER
12912                 (struct cmd_config_l2_tunnel_en_dis_result,
12913                  config, "config");
12914 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12915         TOKEN_STRING_INITIALIZER
12916                 (struct cmd_config_l2_tunnel_en_dis_result,
12917                  all, "all");
12918 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12919         TOKEN_NUM_INITIALIZER
12920                 (struct cmd_config_l2_tunnel_en_dis_result,
12921                  id, UINT16);
12922 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12923         TOKEN_STRING_INITIALIZER
12924                 (struct cmd_config_l2_tunnel_en_dis_result,
12925                  l2_tunnel, "l2-tunnel");
12926 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12927         TOKEN_STRING_INITIALIZER
12928                 (struct cmd_config_l2_tunnel_en_dis_result,
12929                  l2_tunnel_type, "E-tag");
12930 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12931         TOKEN_STRING_INITIALIZER
12932                 (struct cmd_config_l2_tunnel_en_dis_result,
12933                  en_dis, "enable#disable");
12934
12935 /* enable/disable l2 tunnel for all ports */
12936 static void
12937 cmd_config_l2_tunnel_en_dis_all_parsed(
12938         void *parsed_result,
12939         __rte_unused struct cmdline *cl,
12940         __rte_unused void *data)
12941 {
12942         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12943         struct rte_eth_l2_tunnel_conf entry;
12944         portid_t pid;
12945         uint8_t en;
12946
12947         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12948
12949         if (!strcmp("enable", res->en_dis))
12950                 en = 1;
12951         else
12952                 en = 0;
12953
12954         RTE_ETH_FOREACH_DEV(pid) {
12955                 rte_eth_dev_l2_tunnel_offload_set(pid,
12956                                                   &entry,
12957                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12958                                                   en);
12959         }
12960 }
12961
12962 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12963         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12964         .data = NULL,
12965         .help_str = "port config all l2-tunnel E-tag enable|disable",
12966         .tokens = {
12967                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12968                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12969                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12970                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12971                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12972                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12973                 NULL,
12974         },
12975 };
12976
12977 /* enable/disable l2 tunnel for a port */
12978 static void
12979 cmd_config_l2_tunnel_en_dis_specific_parsed(
12980         void *parsed_result,
12981         __rte_unused struct cmdline *cl,
12982         __rte_unused void *data)
12983 {
12984         struct cmd_config_l2_tunnel_en_dis_result *res =
12985                 parsed_result;
12986         struct rte_eth_l2_tunnel_conf entry;
12987
12988         if (port_id_is_invalid(res->id, ENABLED_WARN))
12989                 return;
12990
12991         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12992
12993         if (!strcmp("enable", res->en_dis))
12994                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12995                                                   &entry,
12996                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12997                                                   1);
12998         else
12999                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13000                                                   &entry,
13001                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13002                                                   0);
13003 }
13004
13005 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13006         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13007         .data = NULL,
13008         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13009         .tokens = {
13010                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13011                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13012                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13013                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13014                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13015                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13016                 NULL,
13017         },
13018 };
13019
13020 /* E-tag configuration */
13021
13022 /* Common result structure for all E-tag configuration */
13023 struct cmd_config_e_tag_result {
13024         cmdline_fixed_string_t e_tag;
13025         cmdline_fixed_string_t set;
13026         cmdline_fixed_string_t insertion;
13027         cmdline_fixed_string_t stripping;
13028         cmdline_fixed_string_t forwarding;
13029         cmdline_fixed_string_t filter;
13030         cmdline_fixed_string_t add;
13031         cmdline_fixed_string_t del;
13032         cmdline_fixed_string_t on;
13033         cmdline_fixed_string_t off;
13034         cmdline_fixed_string_t on_off;
13035         cmdline_fixed_string_t port_tag_id;
13036         uint32_t port_tag_id_val;
13037         cmdline_fixed_string_t e_tag_id;
13038         uint16_t e_tag_id_val;
13039         cmdline_fixed_string_t dst_pool;
13040         uint8_t dst_pool_val;
13041         cmdline_fixed_string_t port;
13042         portid_t port_id;
13043         cmdline_fixed_string_t vf;
13044         uint8_t vf_id;
13045 };
13046
13047 /* Common CLI fields for all E-tag configuration */
13048 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13049         TOKEN_STRING_INITIALIZER
13050                 (struct cmd_config_e_tag_result,
13051                  e_tag, "E-tag");
13052 cmdline_parse_token_string_t cmd_config_e_tag_set =
13053         TOKEN_STRING_INITIALIZER
13054                 (struct cmd_config_e_tag_result,
13055                  set, "set");
13056 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13057         TOKEN_STRING_INITIALIZER
13058                 (struct cmd_config_e_tag_result,
13059                  insertion, "insertion");
13060 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13061         TOKEN_STRING_INITIALIZER
13062                 (struct cmd_config_e_tag_result,
13063                  stripping, "stripping");
13064 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13065         TOKEN_STRING_INITIALIZER
13066                 (struct cmd_config_e_tag_result,
13067                  forwarding, "forwarding");
13068 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_config_e_tag_result,
13071                  filter, "filter");
13072 cmdline_parse_token_string_t cmd_config_e_tag_add =
13073         TOKEN_STRING_INITIALIZER
13074                 (struct cmd_config_e_tag_result,
13075                  add, "add");
13076 cmdline_parse_token_string_t cmd_config_e_tag_del =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_config_e_tag_result,
13079                  del, "del");
13080 cmdline_parse_token_string_t cmd_config_e_tag_on =
13081         TOKEN_STRING_INITIALIZER
13082                 (struct cmd_config_e_tag_result,
13083                  on, "on");
13084 cmdline_parse_token_string_t cmd_config_e_tag_off =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_config_e_tag_result,
13087                  off, "off");
13088 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_config_e_tag_result,
13091                  on_off, "on#off");
13092 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_config_e_tag_result,
13095                  port_tag_id, "port-tag-id");
13096 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13097         TOKEN_NUM_INITIALIZER
13098                 (struct cmd_config_e_tag_result,
13099                  port_tag_id_val, UINT32);
13100 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13101         TOKEN_STRING_INITIALIZER
13102                 (struct cmd_config_e_tag_result,
13103                  e_tag_id, "e-tag-id");
13104 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13105         TOKEN_NUM_INITIALIZER
13106                 (struct cmd_config_e_tag_result,
13107                  e_tag_id_val, UINT16);
13108 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13109         TOKEN_STRING_INITIALIZER
13110                 (struct cmd_config_e_tag_result,
13111                  dst_pool, "dst-pool");
13112 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13113         TOKEN_NUM_INITIALIZER
13114                 (struct cmd_config_e_tag_result,
13115                  dst_pool_val, UINT8);
13116 cmdline_parse_token_string_t cmd_config_e_tag_port =
13117         TOKEN_STRING_INITIALIZER
13118                 (struct cmd_config_e_tag_result,
13119                  port, "port");
13120 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13121         TOKEN_NUM_INITIALIZER
13122                 (struct cmd_config_e_tag_result,
13123                  port_id, UINT16);
13124 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13125         TOKEN_STRING_INITIALIZER
13126                 (struct cmd_config_e_tag_result,
13127                  vf, "vf");
13128 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13129         TOKEN_NUM_INITIALIZER
13130                 (struct cmd_config_e_tag_result,
13131                  vf_id, UINT8);
13132
13133 /* E-tag insertion configuration */
13134 static void
13135 cmd_config_e_tag_insertion_en_parsed(
13136         void *parsed_result,
13137         __rte_unused struct cmdline *cl,
13138         __rte_unused void *data)
13139 {
13140         struct cmd_config_e_tag_result *res =
13141                 parsed_result;
13142         struct rte_eth_l2_tunnel_conf entry;
13143
13144         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13145                 return;
13146
13147         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13148         entry.tunnel_id = res->port_tag_id_val;
13149         entry.vf_id = res->vf_id;
13150         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13151                                           &entry,
13152                                           ETH_L2_TUNNEL_INSERTION_MASK,
13153                                           1);
13154 }
13155
13156 static void
13157 cmd_config_e_tag_insertion_dis_parsed(
13158         void *parsed_result,
13159         __rte_unused struct cmdline *cl,
13160         __rte_unused void *data)
13161 {
13162         struct cmd_config_e_tag_result *res =
13163                 parsed_result;
13164         struct rte_eth_l2_tunnel_conf entry;
13165
13166         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13167                 return;
13168
13169         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13170         entry.vf_id = res->vf_id;
13171
13172         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13173                                           &entry,
13174                                           ETH_L2_TUNNEL_INSERTION_MASK,
13175                                           0);
13176 }
13177
13178 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13179         .f = cmd_config_e_tag_insertion_en_parsed,
13180         .data = NULL,
13181         .help_str = "E-tag ... : E-tag insertion enable",
13182         .tokens = {
13183                 (void *)&cmd_config_e_tag_e_tag,
13184                 (void *)&cmd_config_e_tag_set,
13185                 (void *)&cmd_config_e_tag_insertion,
13186                 (void *)&cmd_config_e_tag_on,
13187                 (void *)&cmd_config_e_tag_port_tag_id,
13188                 (void *)&cmd_config_e_tag_port_tag_id_val,
13189                 (void *)&cmd_config_e_tag_port,
13190                 (void *)&cmd_config_e_tag_port_id,
13191                 (void *)&cmd_config_e_tag_vf,
13192                 (void *)&cmd_config_e_tag_vf_id,
13193                 NULL,
13194         },
13195 };
13196
13197 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13198         .f = cmd_config_e_tag_insertion_dis_parsed,
13199         .data = NULL,
13200         .help_str = "E-tag ... : E-tag insertion disable",
13201         .tokens = {
13202                 (void *)&cmd_config_e_tag_e_tag,
13203                 (void *)&cmd_config_e_tag_set,
13204                 (void *)&cmd_config_e_tag_insertion,
13205                 (void *)&cmd_config_e_tag_off,
13206                 (void *)&cmd_config_e_tag_port,
13207                 (void *)&cmd_config_e_tag_port_id,
13208                 (void *)&cmd_config_e_tag_vf,
13209                 (void *)&cmd_config_e_tag_vf_id,
13210                 NULL,
13211         },
13212 };
13213
13214 /* E-tag stripping configuration */
13215 static void
13216 cmd_config_e_tag_stripping_parsed(
13217         void *parsed_result,
13218         __rte_unused struct cmdline *cl,
13219         __rte_unused void *data)
13220 {
13221         struct cmd_config_e_tag_result *res =
13222                 parsed_result;
13223         struct rte_eth_l2_tunnel_conf entry;
13224
13225         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13226                 return;
13227
13228         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13229
13230         if (!strcmp(res->on_off, "on"))
13231                 rte_eth_dev_l2_tunnel_offload_set
13232                         (res->port_id,
13233                          &entry,
13234                          ETH_L2_TUNNEL_STRIPPING_MASK,
13235                          1);
13236         else
13237                 rte_eth_dev_l2_tunnel_offload_set
13238                         (res->port_id,
13239                          &entry,
13240                          ETH_L2_TUNNEL_STRIPPING_MASK,
13241                          0);
13242 }
13243
13244 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13245         .f = cmd_config_e_tag_stripping_parsed,
13246         .data = NULL,
13247         .help_str = "E-tag ... : E-tag stripping enable/disable",
13248         .tokens = {
13249                 (void *)&cmd_config_e_tag_e_tag,
13250                 (void *)&cmd_config_e_tag_set,
13251                 (void *)&cmd_config_e_tag_stripping,
13252                 (void *)&cmd_config_e_tag_on_off,
13253                 (void *)&cmd_config_e_tag_port,
13254                 (void *)&cmd_config_e_tag_port_id,
13255                 NULL,
13256         },
13257 };
13258
13259 /* E-tag forwarding configuration */
13260 static void
13261 cmd_config_e_tag_forwarding_parsed(
13262         void *parsed_result,
13263         __rte_unused struct cmdline *cl,
13264         __rte_unused void *data)
13265 {
13266         struct cmd_config_e_tag_result *res = parsed_result;
13267         struct rte_eth_l2_tunnel_conf entry;
13268
13269         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13270                 return;
13271
13272         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13273
13274         if (!strcmp(res->on_off, "on"))
13275                 rte_eth_dev_l2_tunnel_offload_set
13276                         (res->port_id,
13277                          &entry,
13278                          ETH_L2_TUNNEL_FORWARDING_MASK,
13279                          1);
13280         else
13281                 rte_eth_dev_l2_tunnel_offload_set
13282                         (res->port_id,
13283                          &entry,
13284                          ETH_L2_TUNNEL_FORWARDING_MASK,
13285                          0);
13286 }
13287
13288 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13289         .f = cmd_config_e_tag_forwarding_parsed,
13290         .data = NULL,
13291         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13292         .tokens = {
13293                 (void *)&cmd_config_e_tag_e_tag,
13294                 (void *)&cmd_config_e_tag_set,
13295                 (void *)&cmd_config_e_tag_forwarding,
13296                 (void *)&cmd_config_e_tag_on_off,
13297                 (void *)&cmd_config_e_tag_port,
13298                 (void *)&cmd_config_e_tag_port_id,
13299                 NULL,
13300         },
13301 };
13302
13303 /* E-tag filter configuration */
13304 static void
13305 cmd_config_e_tag_filter_add_parsed(
13306         void *parsed_result,
13307         __rte_unused struct cmdline *cl,
13308         __rte_unused void *data)
13309 {
13310         struct cmd_config_e_tag_result *res = parsed_result;
13311         struct rte_eth_l2_tunnel_conf entry;
13312         int ret = 0;
13313
13314         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13315                 return;
13316
13317         if (res->e_tag_id_val > 0x3fff) {
13318                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13319                 return;
13320         }
13321
13322         ret = rte_eth_dev_filter_supported(res->port_id,
13323                                            RTE_ETH_FILTER_L2_TUNNEL);
13324         if (ret < 0) {
13325                 printf("E-tag filter is not supported on port %u.\n",
13326                        res->port_id);
13327                 return;
13328         }
13329
13330         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13331         entry.tunnel_id = res->e_tag_id_val;
13332         entry.pool = res->dst_pool_val;
13333
13334         ret = rte_eth_dev_filter_ctrl(res->port_id,
13335                                       RTE_ETH_FILTER_L2_TUNNEL,
13336                                       RTE_ETH_FILTER_ADD,
13337                                       &entry);
13338         if (ret < 0)
13339                 printf("E-tag filter programming error: (%s)\n",
13340                        strerror(-ret));
13341 }
13342
13343 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13344         .f = cmd_config_e_tag_filter_add_parsed,
13345         .data = NULL,
13346         .help_str = "E-tag ... : E-tag filter add",
13347         .tokens = {
13348                 (void *)&cmd_config_e_tag_e_tag,
13349                 (void *)&cmd_config_e_tag_set,
13350                 (void *)&cmd_config_e_tag_filter,
13351                 (void *)&cmd_config_e_tag_add,
13352                 (void *)&cmd_config_e_tag_e_tag_id,
13353                 (void *)&cmd_config_e_tag_e_tag_id_val,
13354                 (void *)&cmd_config_e_tag_dst_pool,
13355                 (void *)&cmd_config_e_tag_dst_pool_val,
13356                 (void *)&cmd_config_e_tag_port,
13357                 (void *)&cmd_config_e_tag_port_id,
13358                 NULL,
13359         },
13360 };
13361
13362 static void
13363 cmd_config_e_tag_filter_del_parsed(
13364         void *parsed_result,
13365         __rte_unused struct cmdline *cl,
13366         __rte_unused void *data)
13367 {
13368         struct cmd_config_e_tag_result *res = parsed_result;
13369         struct rte_eth_l2_tunnel_conf entry;
13370         int ret = 0;
13371
13372         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13373                 return;
13374
13375         if (res->e_tag_id_val > 0x3fff) {
13376                 printf("e-tag-id must be less than 0x3fff.\n");
13377                 return;
13378         }
13379
13380         ret = rte_eth_dev_filter_supported(res->port_id,
13381                                            RTE_ETH_FILTER_L2_TUNNEL);
13382         if (ret < 0) {
13383                 printf("E-tag filter is not supported on port %u.\n",
13384                        res->port_id);
13385                 return;
13386         }
13387
13388         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13389         entry.tunnel_id = res->e_tag_id_val;
13390
13391         ret = rte_eth_dev_filter_ctrl(res->port_id,
13392                                       RTE_ETH_FILTER_L2_TUNNEL,
13393                                       RTE_ETH_FILTER_DELETE,
13394                                       &entry);
13395         if (ret < 0)
13396                 printf("E-tag filter programming error: (%s)\n",
13397                        strerror(-ret));
13398 }
13399
13400 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13401         .f = cmd_config_e_tag_filter_del_parsed,
13402         .data = NULL,
13403         .help_str = "E-tag ... : E-tag filter delete",
13404         .tokens = {
13405                 (void *)&cmd_config_e_tag_e_tag,
13406                 (void *)&cmd_config_e_tag_set,
13407                 (void *)&cmd_config_e_tag_filter,
13408                 (void *)&cmd_config_e_tag_del,
13409                 (void *)&cmd_config_e_tag_e_tag_id,
13410                 (void *)&cmd_config_e_tag_e_tag_id_val,
13411                 (void *)&cmd_config_e_tag_port,
13412                 (void *)&cmd_config_e_tag_port_id,
13413                 NULL,
13414         },
13415 };
13416
13417 /* vf vlan anti spoof configuration */
13418
13419 /* Common result structure for vf vlan anti spoof */
13420 struct cmd_vf_vlan_anti_spoof_result {
13421         cmdline_fixed_string_t set;
13422         cmdline_fixed_string_t vf;
13423         cmdline_fixed_string_t vlan;
13424         cmdline_fixed_string_t antispoof;
13425         portid_t port_id;
13426         uint32_t vf_id;
13427         cmdline_fixed_string_t on_off;
13428 };
13429
13430 /* Common CLI fields for vf vlan anti spoof enable disable */
13431 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_vf_vlan_anti_spoof_result,
13434                  set, "set");
13435 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13436         TOKEN_STRING_INITIALIZER
13437                 (struct cmd_vf_vlan_anti_spoof_result,
13438                  vf, "vf");
13439 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_vf_vlan_anti_spoof_result,
13442                  vlan, "vlan");
13443 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_vf_vlan_anti_spoof_result,
13446                  antispoof, "antispoof");
13447 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13448         TOKEN_NUM_INITIALIZER
13449                 (struct cmd_vf_vlan_anti_spoof_result,
13450                  port_id, UINT16);
13451 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13452         TOKEN_NUM_INITIALIZER
13453                 (struct cmd_vf_vlan_anti_spoof_result,
13454                  vf_id, UINT32);
13455 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_vf_vlan_anti_spoof_result,
13458                  on_off, "on#off");
13459
13460 static void
13461 cmd_set_vf_vlan_anti_spoof_parsed(
13462         void *parsed_result,
13463         __rte_unused struct cmdline *cl,
13464         __rte_unused void *data)
13465 {
13466         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13467         int ret = -ENOTSUP;
13468
13469         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13470
13471         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13472                 return;
13473
13474 #ifdef RTE_LIBRTE_IXGBE_PMD
13475         if (ret == -ENOTSUP)
13476                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13477                                 res->vf_id, is_on);
13478 #endif
13479 #ifdef RTE_LIBRTE_I40E_PMD
13480         if (ret == -ENOTSUP)
13481                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13482                                 res->vf_id, is_on);
13483 #endif
13484 #ifdef RTE_LIBRTE_BNXT_PMD
13485         if (ret == -ENOTSUP)
13486                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13487                                 res->vf_id, is_on);
13488 #endif
13489
13490         switch (ret) {
13491         case 0:
13492                 break;
13493         case -EINVAL:
13494                 printf("invalid vf_id %d\n", res->vf_id);
13495                 break;
13496         case -ENODEV:
13497                 printf("invalid port_id %d\n", res->port_id);
13498                 break;
13499         case -ENOTSUP:
13500                 printf("function not implemented\n");
13501                 break;
13502         default:
13503                 printf("programming error: (%s)\n", strerror(-ret));
13504         }
13505 }
13506
13507 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13508         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13509         .data = NULL,
13510         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13511         .tokens = {
13512                 (void *)&cmd_vf_vlan_anti_spoof_set,
13513                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13514                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13515                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13516                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13517                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13518                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13519                 NULL,
13520         },
13521 };
13522
13523 /* vf mac anti spoof configuration */
13524
13525 /* Common result structure for vf mac anti spoof */
13526 struct cmd_vf_mac_anti_spoof_result {
13527         cmdline_fixed_string_t set;
13528         cmdline_fixed_string_t vf;
13529         cmdline_fixed_string_t mac;
13530         cmdline_fixed_string_t antispoof;
13531         portid_t port_id;
13532         uint32_t vf_id;
13533         cmdline_fixed_string_t on_off;
13534 };
13535
13536 /* Common CLI fields for vf mac anti spoof enable disable */
13537 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13538         TOKEN_STRING_INITIALIZER
13539                 (struct cmd_vf_mac_anti_spoof_result,
13540                  set, "set");
13541 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13542         TOKEN_STRING_INITIALIZER
13543                 (struct cmd_vf_mac_anti_spoof_result,
13544                  vf, "vf");
13545 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13546         TOKEN_STRING_INITIALIZER
13547                 (struct cmd_vf_mac_anti_spoof_result,
13548                  mac, "mac");
13549 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13550         TOKEN_STRING_INITIALIZER
13551                 (struct cmd_vf_mac_anti_spoof_result,
13552                  antispoof, "antispoof");
13553 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13554         TOKEN_NUM_INITIALIZER
13555                 (struct cmd_vf_mac_anti_spoof_result,
13556                  port_id, UINT16);
13557 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13558         TOKEN_NUM_INITIALIZER
13559                 (struct cmd_vf_mac_anti_spoof_result,
13560                  vf_id, UINT32);
13561 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13562         TOKEN_STRING_INITIALIZER
13563                 (struct cmd_vf_mac_anti_spoof_result,
13564                  on_off, "on#off");
13565
13566 static void
13567 cmd_set_vf_mac_anti_spoof_parsed(
13568         void *parsed_result,
13569         __rte_unused struct cmdline *cl,
13570         __rte_unused void *data)
13571 {
13572         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13573         int ret = -ENOTSUP;
13574
13575         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13576
13577         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13578                 return;
13579
13580 #ifdef RTE_LIBRTE_IXGBE_PMD
13581         if (ret == -ENOTSUP)
13582                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13583                         res->vf_id, is_on);
13584 #endif
13585 #ifdef RTE_LIBRTE_I40E_PMD
13586         if (ret == -ENOTSUP)
13587                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13588                         res->vf_id, is_on);
13589 #endif
13590 #ifdef RTE_LIBRTE_BNXT_PMD
13591         if (ret == -ENOTSUP)
13592                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13593                         res->vf_id, is_on);
13594 #endif
13595
13596         switch (ret) {
13597         case 0:
13598                 break;
13599         case -EINVAL:
13600                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13601                 break;
13602         case -ENODEV:
13603                 printf("invalid port_id %d\n", res->port_id);
13604                 break;
13605         case -ENOTSUP:
13606                 printf("function not implemented\n");
13607                 break;
13608         default:
13609                 printf("programming error: (%s)\n", strerror(-ret));
13610         }
13611 }
13612
13613 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13614         .f = cmd_set_vf_mac_anti_spoof_parsed,
13615         .data = NULL,
13616         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13617         .tokens = {
13618                 (void *)&cmd_vf_mac_anti_spoof_set,
13619                 (void *)&cmd_vf_mac_anti_spoof_vf,
13620                 (void *)&cmd_vf_mac_anti_spoof_mac,
13621                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13622                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13623                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13624                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13625                 NULL,
13626         },
13627 };
13628
13629 /* vf vlan strip queue configuration */
13630
13631 /* Common result structure for vf mac anti spoof */
13632 struct cmd_vf_vlan_stripq_result {
13633         cmdline_fixed_string_t set;
13634         cmdline_fixed_string_t vf;
13635         cmdline_fixed_string_t vlan;
13636         cmdline_fixed_string_t stripq;
13637         portid_t port_id;
13638         uint16_t vf_id;
13639         cmdline_fixed_string_t on_off;
13640 };
13641
13642 /* Common CLI fields for vf vlan strip enable disable */
13643 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_vf_vlan_stripq_result,
13646                  set, "set");
13647 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13648         TOKEN_STRING_INITIALIZER
13649                 (struct cmd_vf_vlan_stripq_result,
13650                  vf, "vf");
13651 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13652         TOKEN_STRING_INITIALIZER
13653                 (struct cmd_vf_vlan_stripq_result,
13654                  vlan, "vlan");
13655 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13656         TOKEN_STRING_INITIALIZER
13657                 (struct cmd_vf_vlan_stripq_result,
13658                  stripq, "stripq");
13659 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13660         TOKEN_NUM_INITIALIZER
13661                 (struct cmd_vf_vlan_stripq_result,
13662                  port_id, UINT16);
13663 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13664         TOKEN_NUM_INITIALIZER
13665                 (struct cmd_vf_vlan_stripq_result,
13666                  vf_id, UINT16);
13667 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13668         TOKEN_STRING_INITIALIZER
13669                 (struct cmd_vf_vlan_stripq_result,
13670                  on_off, "on#off");
13671
13672 static void
13673 cmd_set_vf_vlan_stripq_parsed(
13674         void *parsed_result,
13675         __rte_unused struct cmdline *cl,
13676         __rte_unused void *data)
13677 {
13678         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13679         int ret = -ENOTSUP;
13680
13681         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13682
13683         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13684                 return;
13685
13686 #ifdef RTE_LIBRTE_IXGBE_PMD
13687         if (ret == -ENOTSUP)
13688                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13689                         res->vf_id, is_on);
13690 #endif
13691 #ifdef RTE_LIBRTE_I40E_PMD
13692         if (ret == -ENOTSUP)
13693                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13694                         res->vf_id, is_on);
13695 #endif
13696 #ifdef RTE_LIBRTE_BNXT_PMD
13697         if (ret == -ENOTSUP)
13698                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13699                         res->vf_id, is_on);
13700 #endif
13701
13702         switch (ret) {
13703         case 0:
13704                 break;
13705         case -EINVAL:
13706                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13707                 break;
13708         case -ENODEV:
13709                 printf("invalid port_id %d\n", res->port_id);
13710                 break;
13711         case -ENOTSUP:
13712                 printf("function not implemented\n");
13713                 break;
13714         default:
13715                 printf("programming error: (%s)\n", strerror(-ret));
13716         }
13717 }
13718
13719 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13720         .f = cmd_set_vf_vlan_stripq_parsed,
13721         .data = NULL,
13722         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13723         .tokens = {
13724                 (void *)&cmd_vf_vlan_stripq_set,
13725                 (void *)&cmd_vf_vlan_stripq_vf,
13726                 (void *)&cmd_vf_vlan_stripq_vlan,
13727                 (void *)&cmd_vf_vlan_stripq_stripq,
13728                 (void *)&cmd_vf_vlan_stripq_port_id,
13729                 (void *)&cmd_vf_vlan_stripq_vf_id,
13730                 (void *)&cmd_vf_vlan_stripq_on_off,
13731                 NULL,
13732         },
13733 };
13734
13735 /* vf vlan insert configuration */
13736
13737 /* Common result structure for vf vlan insert */
13738 struct cmd_vf_vlan_insert_result {
13739         cmdline_fixed_string_t set;
13740         cmdline_fixed_string_t vf;
13741         cmdline_fixed_string_t vlan;
13742         cmdline_fixed_string_t insert;
13743         portid_t port_id;
13744         uint16_t vf_id;
13745         uint16_t vlan_id;
13746 };
13747
13748 /* Common CLI fields for vf vlan insert enable disable */
13749 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13750         TOKEN_STRING_INITIALIZER
13751                 (struct cmd_vf_vlan_insert_result,
13752                  set, "set");
13753 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13754         TOKEN_STRING_INITIALIZER
13755                 (struct cmd_vf_vlan_insert_result,
13756                  vf, "vf");
13757 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13758         TOKEN_STRING_INITIALIZER
13759                 (struct cmd_vf_vlan_insert_result,
13760                  vlan, "vlan");
13761 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13762         TOKEN_STRING_INITIALIZER
13763                 (struct cmd_vf_vlan_insert_result,
13764                  insert, "insert");
13765 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13766         TOKEN_NUM_INITIALIZER
13767                 (struct cmd_vf_vlan_insert_result,
13768                  port_id, UINT16);
13769 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13770         TOKEN_NUM_INITIALIZER
13771                 (struct cmd_vf_vlan_insert_result,
13772                  vf_id, UINT16);
13773 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13774         TOKEN_NUM_INITIALIZER
13775                 (struct cmd_vf_vlan_insert_result,
13776                  vlan_id, UINT16);
13777
13778 static void
13779 cmd_set_vf_vlan_insert_parsed(
13780         void *parsed_result,
13781         __rte_unused struct cmdline *cl,
13782         __rte_unused void *data)
13783 {
13784         struct cmd_vf_vlan_insert_result *res = parsed_result;
13785         int ret = -ENOTSUP;
13786
13787         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13788                 return;
13789
13790 #ifdef RTE_LIBRTE_IXGBE_PMD
13791         if (ret == -ENOTSUP)
13792                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13793                         res->vlan_id);
13794 #endif
13795 #ifdef RTE_LIBRTE_I40E_PMD
13796         if (ret == -ENOTSUP)
13797                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13798                         res->vlan_id);
13799 #endif
13800 #ifdef RTE_LIBRTE_BNXT_PMD
13801         if (ret == -ENOTSUP)
13802                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13803                         res->vlan_id);
13804 #endif
13805
13806         switch (ret) {
13807         case 0:
13808                 break;
13809         case -EINVAL:
13810                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13811                 break;
13812         case -ENODEV:
13813                 printf("invalid port_id %d\n", res->port_id);
13814                 break;
13815         case -ENOTSUP:
13816                 printf("function not implemented\n");
13817                 break;
13818         default:
13819                 printf("programming error: (%s)\n", strerror(-ret));
13820         }
13821 }
13822
13823 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13824         .f = cmd_set_vf_vlan_insert_parsed,
13825         .data = NULL,
13826         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13827         .tokens = {
13828                 (void *)&cmd_vf_vlan_insert_set,
13829                 (void *)&cmd_vf_vlan_insert_vf,
13830                 (void *)&cmd_vf_vlan_insert_vlan,
13831                 (void *)&cmd_vf_vlan_insert_insert,
13832                 (void *)&cmd_vf_vlan_insert_port_id,
13833                 (void *)&cmd_vf_vlan_insert_vf_id,
13834                 (void *)&cmd_vf_vlan_insert_vlan_id,
13835                 NULL,
13836         },
13837 };
13838
13839 /* tx loopback configuration */
13840
13841 /* Common result structure for tx loopback */
13842 struct cmd_tx_loopback_result {
13843         cmdline_fixed_string_t set;
13844         cmdline_fixed_string_t tx;
13845         cmdline_fixed_string_t loopback;
13846         portid_t port_id;
13847         cmdline_fixed_string_t on_off;
13848 };
13849
13850 /* Common CLI fields for tx loopback enable disable */
13851 cmdline_parse_token_string_t cmd_tx_loopback_set =
13852         TOKEN_STRING_INITIALIZER
13853                 (struct cmd_tx_loopback_result,
13854                  set, "set");
13855 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13856         TOKEN_STRING_INITIALIZER
13857                 (struct cmd_tx_loopback_result,
13858                  tx, "tx");
13859 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13860         TOKEN_STRING_INITIALIZER
13861                 (struct cmd_tx_loopback_result,
13862                  loopback, "loopback");
13863 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13864         TOKEN_NUM_INITIALIZER
13865                 (struct cmd_tx_loopback_result,
13866                  port_id, UINT16);
13867 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13868         TOKEN_STRING_INITIALIZER
13869                 (struct cmd_tx_loopback_result,
13870                  on_off, "on#off");
13871
13872 static void
13873 cmd_set_tx_loopback_parsed(
13874         void *parsed_result,
13875         __rte_unused struct cmdline *cl,
13876         __rte_unused void *data)
13877 {
13878         struct cmd_tx_loopback_result *res = parsed_result;
13879         int ret = -ENOTSUP;
13880
13881         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13882
13883         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13884                 return;
13885
13886 #ifdef RTE_LIBRTE_IXGBE_PMD
13887         if (ret == -ENOTSUP)
13888                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13889 #endif
13890 #ifdef RTE_LIBRTE_I40E_PMD
13891         if (ret == -ENOTSUP)
13892                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13893 #endif
13894 #ifdef RTE_LIBRTE_BNXT_PMD
13895         if (ret == -ENOTSUP)
13896                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13897 #endif
13898 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13899         if (ret == -ENOTSUP)
13900                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13901 #endif
13902
13903         switch (ret) {
13904         case 0:
13905                 break;
13906         case -EINVAL:
13907                 printf("invalid is_on %d\n", is_on);
13908                 break;
13909         case -ENODEV:
13910                 printf("invalid port_id %d\n", res->port_id);
13911                 break;
13912         case -ENOTSUP:
13913                 printf("function not implemented\n");
13914                 break;
13915         default:
13916                 printf("programming error: (%s)\n", strerror(-ret));
13917         }
13918 }
13919
13920 cmdline_parse_inst_t cmd_set_tx_loopback = {
13921         .f = cmd_set_tx_loopback_parsed,
13922         .data = NULL,
13923         .help_str = "set tx loopback <port_id> on|off",
13924         .tokens = {
13925                 (void *)&cmd_tx_loopback_set,
13926                 (void *)&cmd_tx_loopback_tx,
13927                 (void *)&cmd_tx_loopback_loopback,
13928                 (void *)&cmd_tx_loopback_port_id,
13929                 (void *)&cmd_tx_loopback_on_off,
13930                 NULL,
13931         },
13932 };
13933
13934 /* all queues drop enable configuration */
13935
13936 /* Common result structure for all queues drop enable */
13937 struct cmd_all_queues_drop_en_result {
13938         cmdline_fixed_string_t set;
13939         cmdline_fixed_string_t all;
13940         cmdline_fixed_string_t queues;
13941         cmdline_fixed_string_t drop;
13942         portid_t port_id;
13943         cmdline_fixed_string_t on_off;
13944 };
13945
13946 /* Common CLI fields for tx loopback enable disable */
13947 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13948         TOKEN_STRING_INITIALIZER
13949                 (struct cmd_all_queues_drop_en_result,
13950                  set, "set");
13951 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13952         TOKEN_STRING_INITIALIZER
13953                 (struct cmd_all_queues_drop_en_result,
13954                  all, "all");
13955 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13956         TOKEN_STRING_INITIALIZER
13957                 (struct cmd_all_queues_drop_en_result,
13958                  queues, "queues");
13959 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13960         TOKEN_STRING_INITIALIZER
13961                 (struct cmd_all_queues_drop_en_result,
13962                  drop, "drop");
13963 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13964         TOKEN_NUM_INITIALIZER
13965                 (struct cmd_all_queues_drop_en_result,
13966                  port_id, UINT16);
13967 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13968         TOKEN_STRING_INITIALIZER
13969                 (struct cmd_all_queues_drop_en_result,
13970                  on_off, "on#off");
13971
13972 static void
13973 cmd_set_all_queues_drop_en_parsed(
13974         void *parsed_result,
13975         __rte_unused struct cmdline *cl,
13976         __rte_unused void *data)
13977 {
13978         struct cmd_all_queues_drop_en_result *res = parsed_result;
13979         int ret = -ENOTSUP;
13980         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13981
13982         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13983                 return;
13984
13985 #ifdef RTE_LIBRTE_IXGBE_PMD
13986         if (ret == -ENOTSUP)
13987                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13988 #endif
13989 #ifdef RTE_LIBRTE_BNXT_PMD
13990         if (ret == -ENOTSUP)
13991                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13992 #endif
13993         switch (ret) {
13994         case 0:
13995                 break;
13996         case -EINVAL:
13997                 printf("invalid is_on %d\n", is_on);
13998                 break;
13999         case -ENODEV:
14000                 printf("invalid port_id %d\n", res->port_id);
14001                 break;
14002         case -ENOTSUP:
14003                 printf("function not implemented\n");
14004                 break;
14005         default:
14006                 printf("programming error: (%s)\n", strerror(-ret));
14007         }
14008 }
14009
14010 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14011         .f = cmd_set_all_queues_drop_en_parsed,
14012         .data = NULL,
14013         .help_str = "set all queues drop <port_id> on|off",
14014         .tokens = {
14015                 (void *)&cmd_all_queues_drop_en_set,
14016                 (void *)&cmd_all_queues_drop_en_all,
14017                 (void *)&cmd_all_queues_drop_en_queues,
14018                 (void *)&cmd_all_queues_drop_en_drop,
14019                 (void *)&cmd_all_queues_drop_en_port_id,
14020                 (void *)&cmd_all_queues_drop_en_on_off,
14021                 NULL,
14022         },
14023 };
14024
14025 /* vf split drop enable configuration */
14026
14027 /* Common result structure for vf split drop enable */
14028 struct cmd_vf_split_drop_en_result {
14029         cmdline_fixed_string_t set;
14030         cmdline_fixed_string_t vf;
14031         cmdline_fixed_string_t split;
14032         cmdline_fixed_string_t drop;
14033         portid_t port_id;
14034         uint16_t vf_id;
14035         cmdline_fixed_string_t on_off;
14036 };
14037
14038 /* Common CLI fields for vf split drop enable disable */
14039 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14040         TOKEN_STRING_INITIALIZER
14041                 (struct cmd_vf_split_drop_en_result,
14042                  set, "set");
14043 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14044         TOKEN_STRING_INITIALIZER
14045                 (struct cmd_vf_split_drop_en_result,
14046                  vf, "vf");
14047 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14048         TOKEN_STRING_INITIALIZER
14049                 (struct cmd_vf_split_drop_en_result,
14050                  split, "split");
14051 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14052         TOKEN_STRING_INITIALIZER
14053                 (struct cmd_vf_split_drop_en_result,
14054                  drop, "drop");
14055 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14056         TOKEN_NUM_INITIALIZER
14057                 (struct cmd_vf_split_drop_en_result,
14058                  port_id, UINT16);
14059 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14060         TOKEN_NUM_INITIALIZER
14061                 (struct cmd_vf_split_drop_en_result,
14062                  vf_id, UINT16);
14063 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14064         TOKEN_STRING_INITIALIZER
14065                 (struct cmd_vf_split_drop_en_result,
14066                  on_off, "on#off");
14067
14068 static void
14069 cmd_set_vf_split_drop_en_parsed(
14070         void *parsed_result,
14071         __rte_unused struct cmdline *cl,
14072         __rte_unused void *data)
14073 {
14074         struct cmd_vf_split_drop_en_result *res = parsed_result;
14075         int ret = -ENOTSUP;
14076         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14077
14078         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14079                 return;
14080
14081 #ifdef RTE_LIBRTE_IXGBE_PMD
14082         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14083                         is_on);
14084 #endif
14085         switch (ret) {
14086         case 0:
14087                 break;
14088         case -EINVAL:
14089                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14090                 break;
14091         case -ENODEV:
14092                 printf("invalid port_id %d\n", res->port_id);
14093                 break;
14094         case -ENOTSUP:
14095                 printf("not supported on port %d\n", res->port_id);
14096                 break;
14097         default:
14098                 printf("programming error: (%s)\n", strerror(-ret));
14099         }
14100 }
14101
14102 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14103         .f = cmd_set_vf_split_drop_en_parsed,
14104         .data = NULL,
14105         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14106         .tokens = {
14107                 (void *)&cmd_vf_split_drop_en_set,
14108                 (void *)&cmd_vf_split_drop_en_vf,
14109                 (void *)&cmd_vf_split_drop_en_split,
14110                 (void *)&cmd_vf_split_drop_en_drop,
14111                 (void *)&cmd_vf_split_drop_en_port_id,
14112                 (void *)&cmd_vf_split_drop_en_vf_id,
14113                 (void *)&cmd_vf_split_drop_en_on_off,
14114                 NULL,
14115         },
14116 };
14117
14118 /* vf mac address configuration */
14119
14120 /* Common result structure for vf mac address */
14121 struct cmd_set_vf_mac_addr_result {
14122         cmdline_fixed_string_t set;
14123         cmdline_fixed_string_t vf;
14124         cmdline_fixed_string_t mac;
14125         cmdline_fixed_string_t addr;
14126         portid_t port_id;
14127         uint16_t vf_id;
14128         struct rte_ether_addr mac_addr;
14129
14130 };
14131
14132 /* Common CLI fields for vf split drop enable disable */
14133 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14134         TOKEN_STRING_INITIALIZER
14135                 (struct cmd_set_vf_mac_addr_result,
14136                  set, "set");
14137 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14138         TOKEN_STRING_INITIALIZER
14139                 (struct cmd_set_vf_mac_addr_result,
14140                  vf, "vf");
14141 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14142         TOKEN_STRING_INITIALIZER
14143                 (struct cmd_set_vf_mac_addr_result,
14144                  mac, "mac");
14145 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14146         TOKEN_STRING_INITIALIZER
14147                 (struct cmd_set_vf_mac_addr_result,
14148                  addr, "addr");
14149 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14150         TOKEN_NUM_INITIALIZER
14151                 (struct cmd_set_vf_mac_addr_result,
14152                  port_id, UINT16);
14153 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14154         TOKEN_NUM_INITIALIZER
14155                 (struct cmd_set_vf_mac_addr_result,
14156                  vf_id, UINT16);
14157 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14158         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14159                  mac_addr);
14160
14161 static void
14162 cmd_set_vf_mac_addr_parsed(
14163         void *parsed_result,
14164         __rte_unused struct cmdline *cl,
14165         __rte_unused void *data)
14166 {
14167         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14168         int ret = -ENOTSUP;
14169
14170         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14171                 return;
14172
14173 #ifdef RTE_LIBRTE_IXGBE_PMD
14174         if (ret == -ENOTSUP)
14175                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14176                                 &res->mac_addr);
14177 #endif
14178 #ifdef RTE_LIBRTE_I40E_PMD
14179         if (ret == -ENOTSUP)
14180                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14181                                 &res->mac_addr);
14182 #endif
14183 #ifdef RTE_LIBRTE_BNXT_PMD
14184         if (ret == -ENOTSUP)
14185                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14186                                 &res->mac_addr);
14187 #endif
14188
14189         switch (ret) {
14190         case 0:
14191                 break;
14192         case -EINVAL:
14193                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14194                 break;
14195         case -ENODEV:
14196                 printf("invalid port_id %d\n", res->port_id);
14197                 break;
14198         case -ENOTSUP:
14199                 printf("function not implemented\n");
14200                 break;
14201         default:
14202                 printf("programming error: (%s)\n", strerror(-ret));
14203         }
14204 }
14205
14206 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14207         .f = cmd_set_vf_mac_addr_parsed,
14208         .data = NULL,
14209         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14210         .tokens = {
14211                 (void *)&cmd_set_vf_mac_addr_set,
14212                 (void *)&cmd_set_vf_mac_addr_vf,
14213                 (void *)&cmd_set_vf_mac_addr_mac,
14214                 (void *)&cmd_set_vf_mac_addr_addr,
14215                 (void *)&cmd_set_vf_mac_addr_port_id,
14216                 (void *)&cmd_set_vf_mac_addr_vf_id,
14217                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14218                 NULL,
14219         },
14220 };
14221
14222 /* MACsec configuration */
14223
14224 /* Common result structure for MACsec offload enable */
14225 struct cmd_macsec_offload_on_result {
14226         cmdline_fixed_string_t set;
14227         cmdline_fixed_string_t macsec;
14228         cmdline_fixed_string_t offload;
14229         portid_t port_id;
14230         cmdline_fixed_string_t on;
14231         cmdline_fixed_string_t encrypt;
14232         cmdline_fixed_string_t en_on_off;
14233         cmdline_fixed_string_t replay_protect;
14234         cmdline_fixed_string_t rp_on_off;
14235 };
14236
14237 /* Common CLI fields for MACsec offload disable */
14238 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14239         TOKEN_STRING_INITIALIZER
14240                 (struct cmd_macsec_offload_on_result,
14241                  set, "set");
14242 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14243         TOKEN_STRING_INITIALIZER
14244                 (struct cmd_macsec_offload_on_result,
14245                  macsec, "macsec");
14246 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14247         TOKEN_STRING_INITIALIZER
14248                 (struct cmd_macsec_offload_on_result,
14249                  offload, "offload");
14250 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14251         TOKEN_NUM_INITIALIZER
14252                 (struct cmd_macsec_offload_on_result,
14253                  port_id, UINT16);
14254 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14255         TOKEN_STRING_INITIALIZER
14256                 (struct cmd_macsec_offload_on_result,
14257                  on, "on");
14258 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14259         TOKEN_STRING_INITIALIZER
14260                 (struct cmd_macsec_offload_on_result,
14261                  encrypt, "encrypt");
14262 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14263         TOKEN_STRING_INITIALIZER
14264                 (struct cmd_macsec_offload_on_result,
14265                  en_on_off, "on#off");
14266 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14267         TOKEN_STRING_INITIALIZER
14268                 (struct cmd_macsec_offload_on_result,
14269                  replay_protect, "replay-protect");
14270 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14271         TOKEN_STRING_INITIALIZER
14272                 (struct cmd_macsec_offload_on_result,
14273                  rp_on_off, "on#off");
14274
14275 static void
14276 cmd_set_macsec_offload_on_parsed(
14277         void *parsed_result,
14278         __rte_unused struct cmdline *cl,
14279         __rte_unused void *data)
14280 {
14281         struct cmd_macsec_offload_on_result *res = parsed_result;
14282         int ret = -ENOTSUP;
14283         portid_t port_id = res->port_id;
14284         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14285         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14286         struct rte_eth_dev_info dev_info;
14287
14288         if (port_id_is_invalid(port_id, ENABLED_WARN))
14289                 return;
14290         if (!port_is_stopped(port_id)) {
14291                 printf("Please stop port %d first\n", port_id);
14292                 return;
14293         }
14294
14295         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14296         if (ret != 0)
14297                 return;
14298
14299         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14300 #ifdef RTE_LIBRTE_IXGBE_PMD
14301                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14302 #endif
14303         }
14304         RTE_SET_USED(en);
14305         RTE_SET_USED(rp);
14306
14307         switch (ret) {
14308         case 0:
14309                 ports[port_id].dev_conf.txmode.offloads |=
14310                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14311                 cmd_reconfig_device_queue(port_id, 1, 1);
14312                 break;
14313         case -ENODEV:
14314                 printf("invalid port_id %d\n", port_id);
14315                 break;
14316         case -ENOTSUP:
14317                 printf("not supported on port %d\n", port_id);
14318                 break;
14319         default:
14320                 printf("programming error: (%s)\n", strerror(-ret));
14321         }
14322 }
14323
14324 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14325         .f = cmd_set_macsec_offload_on_parsed,
14326         .data = NULL,
14327         .help_str = "set macsec offload <port_id> on "
14328                 "encrypt on|off replay-protect on|off",
14329         .tokens = {
14330                 (void *)&cmd_macsec_offload_on_set,
14331                 (void *)&cmd_macsec_offload_on_macsec,
14332                 (void *)&cmd_macsec_offload_on_offload,
14333                 (void *)&cmd_macsec_offload_on_port_id,
14334                 (void *)&cmd_macsec_offload_on_on,
14335                 (void *)&cmd_macsec_offload_on_encrypt,
14336                 (void *)&cmd_macsec_offload_on_en_on_off,
14337                 (void *)&cmd_macsec_offload_on_replay_protect,
14338                 (void *)&cmd_macsec_offload_on_rp_on_off,
14339                 NULL,
14340         },
14341 };
14342
14343 /* Common result structure for MACsec offload disable */
14344 struct cmd_macsec_offload_off_result {
14345         cmdline_fixed_string_t set;
14346         cmdline_fixed_string_t macsec;
14347         cmdline_fixed_string_t offload;
14348         portid_t port_id;
14349         cmdline_fixed_string_t off;
14350 };
14351
14352 /* Common CLI fields for MACsec offload disable */
14353 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14354         TOKEN_STRING_INITIALIZER
14355                 (struct cmd_macsec_offload_off_result,
14356                  set, "set");
14357 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14358         TOKEN_STRING_INITIALIZER
14359                 (struct cmd_macsec_offload_off_result,
14360                  macsec, "macsec");
14361 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14362         TOKEN_STRING_INITIALIZER
14363                 (struct cmd_macsec_offload_off_result,
14364                  offload, "offload");
14365 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14366         TOKEN_NUM_INITIALIZER
14367                 (struct cmd_macsec_offload_off_result,
14368                  port_id, UINT16);
14369 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_macsec_offload_off_result,
14372                  off, "off");
14373
14374 static void
14375 cmd_set_macsec_offload_off_parsed(
14376         void *parsed_result,
14377         __rte_unused struct cmdline *cl,
14378         __rte_unused void *data)
14379 {
14380         struct cmd_macsec_offload_off_result *res = parsed_result;
14381         int ret = -ENOTSUP;
14382         struct rte_eth_dev_info dev_info;
14383         portid_t port_id = res->port_id;
14384
14385         if (port_id_is_invalid(port_id, ENABLED_WARN))
14386                 return;
14387         if (!port_is_stopped(port_id)) {
14388                 printf("Please stop port %d first\n", port_id);
14389                 return;
14390         }
14391
14392         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14393         if (ret != 0)
14394                 return;
14395
14396         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14397 #ifdef RTE_LIBRTE_IXGBE_PMD
14398                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14399 #endif
14400         }
14401         switch (ret) {
14402         case 0:
14403                 ports[port_id].dev_conf.txmode.offloads &=
14404                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14405                 cmd_reconfig_device_queue(port_id, 1, 1);
14406                 break;
14407         case -ENODEV:
14408                 printf("invalid port_id %d\n", port_id);
14409                 break;
14410         case -ENOTSUP:
14411                 printf("not supported on port %d\n", port_id);
14412                 break;
14413         default:
14414                 printf("programming error: (%s)\n", strerror(-ret));
14415         }
14416 }
14417
14418 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14419         .f = cmd_set_macsec_offload_off_parsed,
14420         .data = NULL,
14421         .help_str = "set macsec offload <port_id> off",
14422         .tokens = {
14423                 (void *)&cmd_macsec_offload_off_set,
14424                 (void *)&cmd_macsec_offload_off_macsec,
14425                 (void *)&cmd_macsec_offload_off_offload,
14426                 (void *)&cmd_macsec_offload_off_port_id,
14427                 (void *)&cmd_macsec_offload_off_off,
14428                 NULL,
14429         },
14430 };
14431
14432 /* Common result structure for MACsec secure connection configure */
14433 struct cmd_macsec_sc_result {
14434         cmdline_fixed_string_t set;
14435         cmdline_fixed_string_t macsec;
14436         cmdline_fixed_string_t sc;
14437         cmdline_fixed_string_t tx_rx;
14438         portid_t port_id;
14439         struct rte_ether_addr mac;
14440         uint16_t pi;
14441 };
14442
14443 /* Common CLI fields for MACsec secure connection configure */
14444 cmdline_parse_token_string_t cmd_macsec_sc_set =
14445         TOKEN_STRING_INITIALIZER
14446                 (struct cmd_macsec_sc_result,
14447                  set, "set");
14448 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14449         TOKEN_STRING_INITIALIZER
14450                 (struct cmd_macsec_sc_result,
14451                  macsec, "macsec");
14452 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14453         TOKEN_STRING_INITIALIZER
14454                 (struct cmd_macsec_sc_result,
14455                  sc, "sc");
14456 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14457         TOKEN_STRING_INITIALIZER
14458                 (struct cmd_macsec_sc_result,
14459                  tx_rx, "tx#rx");
14460 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14461         TOKEN_NUM_INITIALIZER
14462                 (struct cmd_macsec_sc_result,
14463                  port_id, UINT16);
14464 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14465         TOKEN_ETHERADDR_INITIALIZER
14466                 (struct cmd_macsec_sc_result,
14467                  mac);
14468 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14469         TOKEN_NUM_INITIALIZER
14470                 (struct cmd_macsec_sc_result,
14471                  pi, UINT16);
14472
14473 static void
14474 cmd_set_macsec_sc_parsed(
14475         void *parsed_result,
14476         __rte_unused struct cmdline *cl,
14477         __rte_unused void *data)
14478 {
14479         struct cmd_macsec_sc_result *res = parsed_result;
14480         int ret = -ENOTSUP;
14481         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14482
14483 #ifdef RTE_LIBRTE_IXGBE_PMD
14484         ret = is_tx ?
14485                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14486                                 res->mac.addr_bytes) :
14487                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14488                                 res->mac.addr_bytes, res->pi);
14489 #endif
14490         RTE_SET_USED(is_tx);
14491
14492         switch (ret) {
14493         case 0:
14494                 break;
14495         case -ENODEV:
14496                 printf("invalid port_id %d\n", res->port_id);
14497                 break;
14498         case -ENOTSUP:
14499                 printf("not supported on port %d\n", res->port_id);
14500                 break;
14501         default:
14502                 printf("programming error: (%s)\n", strerror(-ret));
14503         }
14504 }
14505
14506 cmdline_parse_inst_t cmd_set_macsec_sc = {
14507         .f = cmd_set_macsec_sc_parsed,
14508         .data = NULL,
14509         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14510         .tokens = {
14511                 (void *)&cmd_macsec_sc_set,
14512                 (void *)&cmd_macsec_sc_macsec,
14513                 (void *)&cmd_macsec_sc_sc,
14514                 (void *)&cmd_macsec_sc_tx_rx,
14515                 (void *)&cmd_macsec_sc_port_id,
14516                 (void *)&cmd_macsec_sc_mac,
14517                 (void *)&cmd_macsec_sc_pi,
14518                 NULL,
14519         },
14520 };
14521
14522 /* Common result structure for MACsec secure connection configure */
14523 struct cmd_macsec_sa_result {
14524         cmdline_fixed_string_t set;
14525         cmdline_fixed_string_t macsec;
14526         cmdline_fixed_string_t sa;
14527         cmdline_fixed_string_t tx_rx;
14528         portid_t port_id;
14529         uint8_t idx;
14530         uint8_t an;
14531         uint32_t pn;
14532         cmdline_fixed_string_t key;
14533 };
14534
14535 /* Common CLI fields for MACsec secure connection configure */
14536 cmdline_parse_token_string_t cmd_macsec_sa_set =
14537         TOKEN_STRING_INITIALIZER
14538                 (struct cmd_macsec_sa_result,
14539                  set, "set");
14540 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14541         TOKEN_STRING_INITIALIZER
14542                 (struct cmd_macsec_sa_result,
14543                  macsec, "macsec");
14544 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14545         TOKEN_STRING_INITIALIZER
14546                 (struct cmd_macsec_sa_result,
14547                  sa, "sa");
14548 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14549         TOKEN_STRING_INITIALIZER
14550                 (struct cmd_macsec_sa_result,
14551                  tx_rx, "tx#rx");
14552 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14553         TOKEN_NUM_INITIALIZER
14554                 (struct cmd_macsec_sa_result,
14555                  port_id, UINT16);
14556 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14557         TOKEN_NUM_INITIALIZER
14558                 (struct cmd_macsec_sa_result,
14559                  idx, UINT8);
14560 cmdline_parse_token_num_t cmd_macsec_sa_an =
14561         TOKEN_NUM_INITIALIZER
14562                 (struct cmd_macsec_sa_result,
14563                  an, UINT8);
14564 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14565         TOKEN_NUM_INITIALIZER
14566                 (struct cmd_macsec_sa_result,
14567                  pn, UINT32);
14568 cmdline_parse_token_string_t cmd_macsec_sa_key =
14569         TOKEN_STRING_INITIALIZER
14570                 (struct cmd_macsec_sa_result,
14571                  key, NULL);
14572
14573 static void
14574 cmd_set_macsec_sa_parsed(
14575         void *parsed_result,
14576         __rte_unused struct cmdline *cl,
14577         __rte_unused void *data)
14578 {
14579         struct cmd_macsec_sa_result *res = parsed_result;
14580         int ret = -ENOTSUP;
14581         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14582         uint8_t key[16] = { 0 };
14583         uint8_t xdgt0;
14584         uint8_t xdgt1;
14585         int key_len;
14586         int i;
14587
14588         key_len = strlen(res->key) / 2;
14589         if (key_len > 16)
14590                 key_len = 16;
14591
14592         for (i = 0; i < key_len; i++) {
14593                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14594                 if (xdgt0 == 0xFF)
14595                         return;
14596                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14597                 if (xdgt1 == 0xFF)
14598                         return;
14599                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14600         }
14601
14602 #ifdef RTE_LIBRTE_IXGBE_PMD
14603         ret = is_tx ?
14604                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14605                         res->idx, res->an, res->pn, key) :
14606                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14607                         res->idx, res->an, res->pn, key);
14608 #endif
14609         RTE_SET_USED(is_tx);
14610         RTE_SET_USED(key);
14611
14612         switch (ret) {
14613         case 0:
14614                 break;
14615         case -EINVAL:
14616                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14617                 break;
14618         case -ENODEV:
14619                 printf("invalid port_id %d\n", res->port_id);
14620                 break;
14621         case -ENOTSUP:
14622                 printf("not supported on port %d\n", res->port_id);
14623                 break;
14624         default:
14625                 printf("programming error: (%s)\n", strerror(-ret));
14626         }
14627 }
14628
14629 cmdline_parse_inst_t cmd_set_macsec_sa = {
14630         .f = cmd_set_macsec_sa_parsed,
14631         .data = NULL,
14632         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14633         .tokens = {
14634                 (void *)&cmd_macsec_sa_set,
14635                 (void *)&cmd_macsec_sa_macsec,
14636                 (void *)&cmd_macsec_sa_sa,
14637                 (void *)&cmd_macsec_sa_tx_rx,
14638                 (void *)&cmd_macsec_sa_port_id,
14639                 (void *)&cmd_macsec_sa_idx,
14640                 (void *)&cmd_macsec_sa_an,
14641                 (void *)&cmd_macsec_sa_pn,
14642                 (void *)&cmd_macsec_sa_key,
14643                 NULL,
14644         },
14645 };
14646
14647 /* VF unicast promiscuous mode configuration */
14648
14649 /* Common result structure for VF unicast promiscuous mode */
14650 struct cmd_vf_promisc_result {
14651         cmdline_fixed_string_t set;
14652         cmdline_fixed_string_t vf;
14653         cmdline_fixed_string_t promisc;
14654         portid_t port_id;
14655         uint32_t vf_id;
14656         cmdline_fixed_string_t on_off;
14657 };
14658
14659 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14660 cmdline_parse_token_string_t cmd_vf_promisc_set =
14661         TOKEN_STRING_INITIALIZER
14662                 (struct cmd_vf_promisc_result,
14663                  set, "set");
14664 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14665         TOKEN_STRING_INITIALIZER
14666                 (struct cmd_vf_promisc_result,
14667                  vf, "vf");
14668 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14669         TOKEN_STRING_INITIALIZER
14670                 (struct cmd_vf_promisc_result,
14671                  promisc, "promisc");
14672 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14673         TOKEN_NUM_INITIALIZER
14674                 (struct cmd_vf_promisc_result,
14675                  port_id, UINT16);
14676 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14677         TOKEN_NUM_INITIALIZER
14678                 (struct cmd_vf_promisc_result,
14679                  vf_id, UINT32);
14680 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14681         TOKEN_STRING_INITIALIZER
14682                 (struct cmd_vf_promisc_result,
14683                  on_off, "on#off");
14684
14685 static void
14686 cmd_set_vf_promisc_parsed(
14687         void *parsed_result,
14688         __rte_unused struct cmdline *cl,
14689         __rte_unused void *data)
14690 {
14691         struct cmd_vf_promisc_result *res = parsed_result;
14692         int ret = -ENOTSUP;
14693
14694         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14695
14696         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14697                 return;
14698
14699 #ifdef RTE_LIBRTE_I40E_PMD
14700         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14701                                                   res->vf_id, is_on);
14702 #endif
14703
14704         switch (ret) {
14705         case 0:
14706                 break;
14707         case -EINVAL:
14708                 printf("invalid vf_id %d\n", res->vf_id);
14709                 break;
14710         case -ENODEV:
14711                 printf("invalid port_id %d\n", res->port_id);
14712                 break;
14713         case -ENOTSUP:
14714                 printf("function not implemented\n");
14715                 break;
14716         default:
14717                 printf("programming error: (%s)\n", strerror(-ret));
14718         }
14719 }
14720
14721 cmdline_parse_inst_t cmd_set_vf_promisc = {
14722         .f = cmd_set_vf_promisc_parsed,
14723         .data = NULL,
14724         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14725                 "Set unicast promiscuous mode for a VF from the PF",
14726         .tokens = {
14727                 (void *)&cmd_vf_promisc_set,
14728                 (void *)&cmd_vf_promisc_vf,
14729                 (void *)&cmd_vf_promisc_promisc,
14730                 (void *)&cmd_vf_promisc_port_id,
14731                 (void *)&cmd_vf_promisc_vf_id,
14732                 (void *)&cmd_vf_promisc_on_off,
14733                 NULL,
14734         },
14735 };
14736
14737 /* VF multicast promiscuous mode configuration */
14738
14739 /* Common result structure for VF multicast promiscuous mode */
14740 struct cmd_vf_allmulti_result {
14741         cmdline_fixed_string_t set;
14742         cmdline_fixed_string_t vf;
14743         cmdline_fixed_string_t allmulti;
14744         portid_t port_id;
14745         uint32_t vf_id;
14746         cmdline_fixed_string_t on_off;
14747 };
14748
14749 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14750 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14751         TOKEN_STRING_INITIALIZER
14752                 (struct cmd_vf_allmulti_result,
14753                  set, "set");
14754 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14755         TOKEN_STRING_INITIALIZER
14756                 (struct cmd_vf_allmulti_result,
14757                  vf, "vf");
14758 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14759         TOKEN_STRING_INITIALIZER
14760                 (struct cmd_vf_allmulti_result,
14761                  allmulti, "allmulti");
14762 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14763         TOKEN_NUM_INITIALIZER
14764                 (struct cmd_vf_allmulti_result,
14765                  port_id, UINT16);
14766 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14767         TOKEN_NUM_INITIALIZER
14768                 (struct cmd_vf_allmulti_result,
14769                  vf_id, UINT32);
14770 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_vf_allmulti_result,
14773                  on_off, "on#off");
14774
14775 static void
14776 cmd_set_vf_allmulti_parsed(
14777         void *parsed_result,
14778         __rte_unused struct cmdline *cl,
14779         __rte_unused void *data)
14780 {
14781         struct cmd_vf_allmulti_result *res = parsed_result;
14782         int ret = -ENOTSUP;
14783
14784         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14785
14786         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14787                 return;
14788
14789 #ifdef RTE_LIBRTE_I40E_PMD
14790         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14791                                                     res->vf_id, is_on);
14792 #endif
14793
14794         switch (ret) {
14795         case 0:
14796                 break;
14797         case -EINVAL:
14798                 printf("invalid vf_id %d\n", res->vf_id);
14799                 break;
14800         case -ENODEV:
14801                 printf("invalid port_id %d\n", res->port_id);
14802                 break;
14803         case -ENOTSUP:
14804                 printf("function not implemented\n");
14805                 break;
14806         default:
14807                 printf("programming error: (%s)\n", strerror(-ret));
14808         }
14809 }
14810
14811 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14812         .f = cmd_set_vf_allmulti_parsed,
14813         .data = NULL,
14814         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14815                 "Set multicast promiscuous mode for a VF from the PF",
14816         .tokens = {
14817                 (void *)&cmd_vf_allmulti_set,
14818                 (void *)&cmd_vf_allmulti_vf,
14819                 (void *)&cmd_vf_allmulti_allmulti,
14820                 (void *)&cmd_vf_allmulti_port_id,
14821                 (void *)&cmd_vf_allmulti_vf_id,
14822                 (void *)&cmd_vf_allmulti_on_off,
14823                 NULL,
14824         },
14825 };
14826
14827 /* vf broadcast mode configuration */
14828
14829 /* Common result structure for vf broadcast */
14830 struct cmd_set_vf_broadcast_result {
14831         cmdline_fixed_string_t set;
14832         cmdline_fixed_string_t vf;
14833         cmdline_fixed_string_t broadcast;
14834         portid_t port_id;
14835         uint16_t vf_id;
14836         cmdline_fixed_string_t on_off;
14837 };
14838
14839 /* Common CLI fields for vf broadcast enable disable */
14840 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14841         TOKEN_STRING_INITIALIZER
14842                 (struct cmd_set_vf_broadcast_result,
14843                  set, "set");
14844 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14845         TOKEN_STRING_INITIALIZER
14846                 (struct cmd_set_vf_broadcast_result,
14847                  vf, "vf");
14848 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14849         TOKEN_STRING_INITIALIZER
14850                 (struct cmd_set_vf_broadcast_result,
14851                  broadcast, "broadcast");
14852 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14853         TOKEN_NUM_INITIALIZER
14854                 (struct cmd_set_vf_broadcast_result,
14855                  port_id, UINT16);
14856 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14857         TOKEN_NUM_INITIALIZER
14858                 (struct cmd_set_vf_broadcast_result,
14859                  vf_id, UINT16);
14860 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14861         TOKEN_STRING_INITIALIZER
14862                 (struct cmd_set_vf_broadcast_result,
14863                  on_off, "on#off");
14864
14865 static void
14866 cmd_set_vf_broadcast_parsed(
14867         void *parsed_result,
14868         __rte_unused struct cmdline *cl,
14869         __rte_unused void *data)
14870 {
14871         struct cmd_set_vf_broadcast_result *res = parsed_result;
14872         int ret = -ENOTSUP;
14873
14874         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14875
14876         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14877                 return;
14878
14879 #ifdef RTE_LIBRTE_I40E_PMD
14880         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14881                                             res->vf_id, is_on);
14882 #endif
14883
14884         switch (ret) {
14885         case 0:
14886                 break;
14887         case -EINVAL:
14888                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14889                 break;
14890         case -ENODEV:
14891                 printf("invalid port_id %d\n", res->port_id);
14892                 break;
14893         case -ENOTSUP:
14894                 printf("function not implemented\n");
14895                 break;
14896         default:
14897                 printf("programming error: (%s)\n", strerror(-ret));
14898         }
14899 }
14900
14901 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14902         .f = cmd_set_vf_broadcast_parsed,
14903         .data = NULL,
14904         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14905         .tokens = {
14906                 (void *)&cmd_set_vf_broadcast_set,
14907                 (void *)&cmd_set_vf_broadcast_vf,
14908                 (void *)&cmd_set_vf_broadcast_broadcast,
14909                 (void *)&cmd_set_vf_broadcast_port_id,
14910                 (void *)&cmd_set_vf_broadcast_vf_id,
14911                 (void *)&cmd_set_vf_broadcast_on_off,
14912                 NULL,
14913         },
14914 };
14915
14916 /* vf vlan tag configuration */
14917
14918 /* Common result structure for vf vlan tag */
14919 struct cmd_set_vf_vlan_tag_result {
14920         cmdline_fixed_string_t set;
14921         cmdline_fixed_string_t vf;
14922         cmdline_fixed_string_t vlan;
14923         cmdline_fixed_string_t tag;
14924         portid_t port_id;
14925         uint16_t vf_id;
14926         cmdline_fixed_string_t on_off;
14927 };
14928
14929 /* Common CLI fields for vf vlan tag enable disable */
14930 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14931         TOKEN_STRING_INITIALIZER
14932                 (struct cmd_set_vf_vlan_tag_result,
14933                  set, "set");
14934 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14935         TOKEN_STRING_INITIALIZER
14936                 (struct cmd_set_vf_vlan_tag_result,
14937                  vf, "vf");
14938 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14939         TOKEN_STRING_INITIALIZER
14940                 (struct cmd_set_vf_vlan_tag_result,
14941                  vlan, "vlan");
14942 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14943         TOKEN_STRING_INITIALIZER
14944                 (struct cmd_set_vf_vlan_tag_result,
14945                  tag, "tag");
14946 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14947         TOKEN_NUM_INITIALIZER
14948                 (struct cmd_set_vf_vlan_tag_result,
14949                  port_id, UINT16);
14950 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14951         TOKEN_NUM_INITIALIZER
14952                 (struct cmd_set_vf_vlan_tag_result,
14953                  vf_id, UINT16);
14954 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14955         TOKEN_STRING_INITIALIZER
14956                 (struct cmd_set_vf_vlan_tag_result,
14957                  on_off, "on#off");
14958
14959 static void
14960 cmd_set_vf_vlan_tag_parsed(
14961         void *parsed_result,
14962         __rte_unused struct cmdline *cl,
14963         __rte_unused void *data)
14964 {
14965         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14966         int ret = -ENOTSUP;
14967
14968         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14969
14970         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14971                 return;
14972
14973 #ifdef RTE_LIBRTE_I40E_PMD
14974         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14975                                            res->vf_id, is_on);
14976 #endif
14977
14978         switch (ret) {
14979         case 0:
14980                 break;
14981         case -EINVAL:
14982                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14983                 break;
14984         case -ENODEV:
14985                 printf("invalid port_id %d\n", res->port_id);
14986                 break;
14987         case -ENOTSUP:
14988                 printf("function not implemented\n");
14989                 break;
14990         default:
14991                 printf("programming error: (%s)\n", strerror(-ret));
14992         }
14993 }
14994
14995 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14996         .f = cmd_set_vf_vlan_tag_parsed,
14997         .data = NULL,
14998         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
14999         .tokens = {
15000                 (void *)&cmd_set_vf_vlan_tag_set,
15001                 (void *)&cmd_set_vf_vlan_tag_vf,
15002                 (void *)&cmd_set_vf_vlan_tag_vlan,
15003                 (void *)&cmd_set_vf_vlan_tag_tag,
15004                 (void *)&cmd_set_vf_vlan_tag_port_id,
15005                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15006                 (void *)&cmd_set_vf_vlan_tag_on_off,
15007                 NULL,
15008         },
15009 };
15010
15011 /* Common definition of VF and TC TX bandwidth configuration */
15012 struct cmd_vf_tc_bw_result {
15013         cmdline_fixed_string_t set;
15014         cmdline_fixed_string_t vf;
15015         cmdline_fixed_string_t tc;
15016         cmdline_fixed_string_t tx;
15017         cmdline_fixed_string_t min_bw;
15018         cmdline_fixed_string_t max_bw;
15019         cmdline_fixed_string_t strict_link_prio;
15020         portid_t port_id;
15021         uint16_t vf_id;
15022         uint8_t tc_no;
15023         uint32_t bw;
15024         cmdline_fixed_string_t bw_list;
15025         uint8_t tc_map;
15026 };
15027
15028 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15029         TOKEN_STRING_INITIALIZER
15030                 (struct cmd_vf_tc_bw_result,
15031                  set, "set");
15032 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15033         TOKEN_STRING_INITIALIZER
15034                 (struct cmd_vf_tc_bw_result,
15035                  vf, "vf");
15036 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15037         TOKEN_STRING_INITIALIZER
15038                 (struct cmd_vf_tc_bw_result,
15039                  tc, "tc");
15040 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15041         TOKEN_STRING_INITIALIZER
15042                 (struct cmd_vf_tc_bw_result,
15043                  tx, "tx");
15044 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15045         TOKEN_STRING_INITIALIZER
15046                 (struct cmd_vf_tc_bw_result,
15047                  strict_link_prio, "strict-link-priority");
15048 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15049         TOKEN_STRING_INITIALIZER
15050                 (struct cmd_vf_tc_bw_result,
15051                  min_bw, "min-bandwidth");
15052 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15053         TOKEN_STRING_INITIALIZER
15054                 (struct cmd_vf_tc_bw_result,
15055                  max_bw, "max-bandwidth");
15056 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15057         TOKEN_NUM_INITIALIZER
15058                 (struct cmd_vf_tc_bw_result,
15059                  port_id, UINT16);
15060 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15061         TOKEN_NUM_INITIALIZER
15062                 (struct cmd_vf_tc_bw_result,
15063                  vf_id, UINT16);
15064 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15065         TOKEN_NUM_INITIALIZER
15066                 (struct cmd_vf_tc_bw_result,
15067                  tc_no, UINT8);
15068 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15069         TOKEN_NUM_INITIALIZER
15070                 (struct cmd_vf_tc_bw_result,
15071                  bw, UINT32);
15072 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15073         TOKEN_STRING_INITIALIZER
15074                 (struct cmd_vf_tc_bw_result,
15075                  bw_list, NULL);
15076 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15077         TOKEN_NUM_INITIALIZER
15078                 (struct cmd_vf_tc_bw_result,
15079                  tc_map, UINT8);
15080
15081 /* VF max bandwidth setting */
15082 static void
15083 cmd_vf_max_bw_parsed(
15084         void *parsed_result,
15085         __rte_unused struct cmdline *cl,
15086         __rte_unused void *data)
15087 {
15088         struct cmd_vf_tc_bw_result *res = parsed_result;
15089         int ret = -ENOTSUP;
15090
15091         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15092                 return;
15093
15094 #ifdef RTE_LIBRTE_I40E_PMD
15095         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15096                                          res->vf_id, res->bw);
15097 #endif
15098
15099         switch (ret) {
15100         case 0:
15101                 break;
15102         case -EINVAL:
15103                 printf("invalid vf_id %d or bandwidth %d\n",
15104                        res->vf_id, res->bw);
15105                 break;
15106         case -ENODEV:
15107                 printf("invalid port_id %d\n", res->port_id);
15108                 break;
15109         case -ENOTSUP:
15110                 printf("function not implemented\n");
15111                 break;
15112         default:
15113                 printf("programming error: (%s)\n", strerror(-ret));
15114         }
15115 }
15116
15117 cmdline_parse_inst_t cmd_vf_max_bw = {
15118         .f = cmd_vf_max_bw_parsed,
15119         .data = NULL,
15120         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15121         .tokens = {
15122                 (void *)&cmd_vf_tc_bw_set,
15123                 (void *)&cmd_vf_tc_bw_vf,
15124                 (void *)&cmd_vf_tc_bw_tx,
15125                 (void *)&cmd_vf_tc_bw_max_bw,
15126                 (void *)&cmd_vf_tc_bw_port_id,
15127                 (void *)&cmd_vf_tc_bw_vf_id,
15128                 (void *)&cmd_vf_tc_bw_bw,
15129                 NULL,
15130         },
15131 };
15132
15133 static int
15134 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15135                            uint8_t *tc_num,
15136                            char *str)
15137 {
15138         uint32_t size;
15139         const char *p, *p0 = str;
15140         char s[256];
15141         char *end;
15142         char *str_fld[16];
15143         uint16_t i;
15144         int ret;
15145
15146         p = strchr(p0, '(');
15147         if (p == NULL) {
15148                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15149                 return -1;
15150         }
15151         p++;
15152         p0 = strchr(p, ')');
15153         if (p0 == NULL) {
15154                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15155                 return -1;
15156         }
15157         size = p0 - p;
15158         if (size >= sizeof(s)) {
15159                 printf("The string size exceeds the internal buffer size\n");
15160                 return -1;
15161         }
15162         snprintf(s, sizeof(s), "%.*s", size, p);
15163         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15164         if (ret <= 0) {
15165                 printf("Failed to get the bandwidth list. ");
15166                 return -1;
15167         }
15168         *tc_num = ret;
15169         for (i = 0; i < ret; i++)
15170                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15171
15172         return 0;
15173 }
15174
15175 /* TC min bandwidth setting */
15176 static void
15177 cmd_vf_tc_min_bw_parsed(
15178         void *parsed_result,
15179         __rte_unused struct cmdline *cl,
15180         __rte_unused void *data)
15181 {
15182         struct cmd_vf_tc_bw_result *res = parsed_result;
15183         uint8_t tc_num;
15184         uint8_t bw[16];
15185         int ret = -ENOTSUP;
15186
15187         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15188                 return;
15189
15190         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15191         if (ret)
15192                 return;
15193
15194 #ifdef RTE_LIBRTE_I40E_PMD
15195         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15196                                               tc_num, bw);
15197 #endif
15198
15199         switch (ret) {
15200         case 0:
15201                 break;
15202         case -EINVAL:
15203                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15204                 break;
15205         case -ENODEV:
15206                 printf("invalid port_id %d\n", res->port_id);
15207                 break;
15208         case -ENOTSUP:
15209                 printf("function not implemented\n");
15210                 break;
15211         default:
15212                 printf("programming error: (%s)\n", strerror(-ret));
15213         }
15214 }
15215
15216 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15217         .f = cmd_vf_tc_min_bw_parsed,
15218         .data = NULL,
15219         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15220                     " <bw1, bw2, ...>",
15221         .tokens = {
15222                 (void *)&cmd_vf_tc_bw_set,
15223                 (void *)&cmd_vf_tc_bw_vf,
15224                 (void *)&cmd_vf_tc_bw_tc,
15225                 (void *)&cmd_vf_tc_bw_tx,
15226                 (void *)&cmd_vf_tc_bw_min_bw,
15227                 (void *)&cmd_vf_tc_bw_port_id,
15228                 (void *)&cmd_vf_tc_bw_vf_id,
15229                 (void *)&cmd_vf_tc_bw_bw_list,
15230                 NULL,
15231         },
15232 };
15233
15234 static void
15235 cmd_tc_min_bw_parsed(
15236         void *parsed_result,
15237         __rte_unused struct cmdline *cl,
15238         __rte_unused void *data)
15239 {
15240         struct cmd_vf_tc_bw_result *res = parsed_result;
15241         struct rte_port *port;
15242         uint8_t tc_num;
15243         uint8_t bw[16];
15244         int ret = -ENOTSUP;
15245
15246         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15247                 return;
15248
15249         port = &ports[res->port_id];
15250         /** Check if the port is not started **/
15251         if (port->port_status != RTE_PORT_STOPPED) {
15252                 printf("Please stop port %d first\n", res->port_id);
15253                 return;
15254         }
15255
15256         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15257         if (ret)
15258                 return;
15259
15260 #ifdef RTE_LIBRTE_IXGBE_PMD
15261         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15262 #endif
15263
15264         switch (ret) {
15265         case 0:
15266                 break;
15267         case -EINVAL:
15268                 printf("invalid bandwidth\n");
15269                 break;
15270         case -ENODEV:
15271                 printf("invalid port_id %d\n", res->port_id);
15272                 break;
15273         case -ENOTSUP:
15274                 printf("function not implemented\n");
15275                 break;
15276         default:
15277                 printf("programming error: (%s)\n", strerror(-ret));
15278         }
15279 }
15280
15281 cmdline_parse_inst_t cmd_tc_min_bw = {
15282         .f = cmd_tc_min_bw_parsed,
15283         .data = NULL,
15284         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15285         .tokens = {
15286                 (void *)&cmd_vf_tc_bw_set,
15287                 (void *)&cmd_vf_tc_bw_tc,
15288                 (void *)&cmd_vf_tc_bw_tx,
15289                 (void *)&cmd_vf_tc_bw_min_bw,
15290                 (void *)&cmd_vf_tc_bw_port_id,
15291                 (void *)&cmd_vf_tc_bw_bw_list,
15292                 NULL,
15293         },
15294 };
15295
15296 /* TC max bandwidth setting */
15297 static void
15298 cmd_vf_tc_max_bw_parsed(
15299         void *parsed_result,
15300         __rte_unused struct cmdline *cl,
15301         __rte_unused void *data)
15302 {
15303         struct cmd_vf_tc_bw_result *res = parsed_result;
15304         int ret = -ENOTSUP;
15305
15306         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15307                 return;
15308
15309 #ifdef RTE_LIBRTE_I40E_PMD
15310         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15311                                             res->tc_no, res->bw);
15312 #endif
15313
15314         switch (ret) {
15315         case 0:
15316                 break;
15317         case -EINVAL:
15318                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15319                        res->vf_id, res->tc_no, res->bw);
15320                 break;
15321         case -ENODEV:
15322                 printf("invalid port_id %d\n", res->port_id);
15323                 break;
15324         case -ENOTSUP:
15325                 printf("function not implemented\n");
15326                 break;
15327         default:
15328                 printf("programming error: (%s)\n", strerror(-ret));
15329         }
15330 }
15331
15332 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15333         .f = cmd_vf_tc_max_bw_parsed,
15334         .data = NULL,
15335         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15336                     " <bandwidth>",
15337         .tokens = {
15338                 (void *)&cmd_vf_tc_bw_set,
15339                 (void *)&cmd_vf_tc_bw_vf,
15340                 (void *)&cmd_vf_tc_bw_tc,
15341                 (void *)&cmd_vf_tc_bw_tx,
15342                 (void *)&cmd_vf_tc_bw_max_bw,
15343                 (void *)&cmd_vf_tc_bw_port_id,
15344                 (void *)&cmd_vf_tc_bw_vf_id,
15345                 (void *)&cmd_vf_tc_bw_tc_no,
15346                 (void *)&cmd_vf_tc_bw_bw,
15347                 NULL,
15348         },
15349 };
15350
15351
15352 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15353
15354 /* *** Set Port default Traffic Management Hierarchy *** */
15355 struct cmd_set_port_tm_hierarchy_default_result {
15356         cmdline_fixed_string_t set;
15357         cmdline_fixed_string_t port;
15358         cmdline_fixed_string_t tm;
15359         cmdline_fixed_string_t hierarchy;
15360         cmdline_fixed_string_t def;
15361         portid_t port_id;
15362 };
15363
15364 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15365         TOKEN_STRING_INITIALIZER(
15366                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15367 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15368         TOKEN_STRING_INITIALIZER(
15369                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15370 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15371         TOKEN_STRING_INITIALIZER(
15372                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15373 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15374         TOKEN_STRING_INITIALIZER(
15375                 struct cmd_set_port_tm_hierarchy_default_result,
15376                         hierarchy, "hierarchy");
15377 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15378         TOKEN_STRING_INITIALIZER(
15379                 struct cmd_set_port_tm_hierarchy_default_result,
15380                         def, "default");
15381 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15382         TOKEN_NUM_INITIALIZER(
15383                 struct cmd_set_port_tm_hierarchy_default_result,
15384                         port_id, UINT16);
15385
15386 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15387         __rte_unused struct cmdline *cl,
15388         __rte_unused void *data)
15389 {
15390         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15391         struct rte_port *p;
15392         portid_t port_id = res->port_id;
15393
15394         if (port_id_is_invalid(port_id, ENABLED_WARN))
15395                 return;
15396
15397         p = &ports[port_id];
15398
15399         /* Forward mode: tm */
15400         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15401                 printf("  softnicfwd mode not enabled(error)\n");
15402                 return;
15403         }
15404
15405         /* Set the default tm hierarchy */
15406         p->softport.default_tm_hierarchy_enable = 1;
15407 }
15408
15409 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15410         .f = cmd_set_port_tm_hierarchy_default_parsed,
15411         .data = NULL,
15412         .help_str = "set port tm hierarchy default <port_id>",
15413         .tokens = {
15414                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15415                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15416                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15417                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15418                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15419                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15420                 NULL,
15421         },
15422 };
15423 #endif
15424
15425 /** Set VXLAN encapsulation details */
15426 struct cmd_set_vxlan_result {
15427         cmdline_fixed_string_t set;
15428         cmdline_fixed_string_t vxlan;
15429         cmdline_fixed_string_t pos_token;
15430         cmdline_fixed_string_t ip_version;
15431         uint32_t vlan_present:1;
15432         uint32_t vni;
15433         uint16_t udp_src;
15434         uint16_t udp_dst;
15435         cmdline_ipaddr_t ip_src;
15436         cmdline_ipaddr_t ip_dst;
15437         uint16_t tci;
15438         uint8_t tos;
15439         uint8_t ttl;
15440         struct rte_ether_addr eth_src;
15441         struct rte_ether_addr eth_dst;
15442 };
15443
15444 cmdline_parse_token_string_t cmd_set_vxlan_set =
15445         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15446 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15447         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15448 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15449         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15450                                  "vxlan-tos-ttl");
15451 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15453                                  "vxlan-with-vlan");
15454 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15455         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15456                                  "ip-version");
15457 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15459                                  "ipv4#ipv6");
15460 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15462                                  "vni");
15463 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15464         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15465 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15466         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15467                                  "udp-src");
15468 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15469         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15470 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15471         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15472                                  "udp-dst");
15473 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15474         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15475 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15476         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15477                                  "ip-tos");
15478 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15479         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15480 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15481         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15482                                  "ip-ttl");
15483 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15484         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15485 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15486         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15487                                  "ip-src");
15488 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15489         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15490 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15491         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15492                                  "ip-dst");
15493 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15494         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15495 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15496         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15497                                  "vlan-tci");
15498 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15499         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15500 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15501         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15502                                  "eth-src");
15503 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15504         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15505 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15506         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15507                                  "eth-dst");
15508 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15509         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15510
15511 static void cmd_set_vxlan_parsed(void *parsed_result,
15512         __rte_unused struct cmdline *cl,
15513         __rte_unused void *data)
15514 {
15515         struct cmd_set_vxlan_result *res = parsed_result;
15516         union {
15517                 uint32_t vxlan_id;
15518                 uint8_t vni[4];
15519         } id = {
15520                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15521         };
15522
15523         vxlan_encap_conf.select_tos_ttl = 0;
15524         if (strcmp(res->vxlan, "vxlan") == 0)
15525                 vxlan_encap_conf.select_vlan = 0;
15526         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15527                 vxlan_encap_conf.select_vlan = 1;
15528         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15529                 vxlan_encap_conf.select_vlan = 0;
15530                 vxlan_encap_conf.select_tos_ttl = 1;
15531         }
15532         if (strcmp(res->ip_version, "ipv4") == 0)
15533                 vxlan_encap_conf.select_ipv4 = 1;
15534         else if (strcmp(res->ip_version, "ipv6") == 0)
15535                 vxlan_encap_conf.select_ipv4 = 0;
15536         else
15537                 return;
15538         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15539         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15540         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15541         vxlan_encap_conf.ip_tos = res->tos;
15542         vxlan_encap_conf.ip_ttl = res->ttl;
15543         if (vxlan_encap_conf.select_ipv4) {
15544                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15545                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15546         } else {
15547                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15548                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15549         }
15550         if (vxlan_encap_conf.select_vlan)
15551                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15552         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15553                    RTE_ETHER_ADDR_LEN);
15554         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15555                    RTE_ETHER_ADDR_LEN);
15556 }
15557
15558 cmdline_parse_inst_t cmd_set_vxlan = {
15559         .f = cmd_set_vxlan_parsed,
15560         .data = NULL,
15561         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15562                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15563                 " eth-src <eth-src> eth-dst <eth-dst>",
15564         .tokens = {
15565                 (void *)&cmd_set_vxlan_set,
15566                 (void *)&cmd_set_vxlan_vxlan,
15567                 (void *)&cmd_set_vxlan_ip_version,
15568                 (void *)&cmd_set_vxlan_ip_version_value,
15569                 (void *)&cmd_set_vxlan_vni,
15570                 (void *)&cmd_set_vxlan_vni_value,
15571                 (void *)&cmd_set_vxlan_udp_src,
15572                 (void *)&cmd_set_vxlan_udp_src_value,
15573                 (void *)&cmd_set_vxlan_udp_dst,
15574                 (void *)&cmd_set_vxlan_udp_dst_value,
15575                 (void *)&cmd_set_vxlan_ip_src,
15576                 (void *)&cmd_set_vxlan_ip_src_value,
15577                 (void *)&cmd_set_vxlan_ip_dst,
15578                 (void *)&cmd_set_vxlan_ip_dst_value,
15579                 (void *)&cmd_set_vxlan_eth_src,
15580                 (void *)&cmd_set_vxlan_eth_src_value,
15581                 (void *)&cmd_set_vxlan_eth_dst,
15582                 (void *)&cmd_set_vxlan_eth_dst_value,
15583                 NULL,
15584         },
15585 };
15586
15587 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15588         .f = cmd_set_vxlan_parsed,
15589         .data = NULL,
15590         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15591                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15592                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15593                 " eth-dst <eth-dst>",
15594         .tokens = {
15595                 (void *)&cmd_set_vxlan_set,
15596                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15597                 (void *)&cmd_set_vxlan_ip_version,
15598                 (void *)&cmd_set_vxlan_ip_version_value,
15599                 (void *)&cmd_set_vxlan_vni,
15600                 (void *)&cmd_set_vxlan_vni_value,
15601                 (void *)&cmd_set_vxlan_udp_src,
15602                 (void *)&cmd_set_vxlan_udp_src_value,
15603                 (void *)&cmd_set_vxlan_udp_dst,
15604                 (void *)&cmd_set_vxlan_udp_dst_value,
15605                 (void *)&cmd_set_vxlan_ip_tos,
15606                 (void *)&cmd_set_vxlan_ip_tos_value,
15607                 (void *)&cmd_set_vxlan_ip_ttl,
15608                 (void *)&cmd_set_vxlan_ip_ttl_value,
15609                 (void *)&cmd_set_vxlan_ip_src,
15610                 (void *)&cmd_set_vxlan_ip_src_value,
15611                 (void *)&cmd_set_vxlan_ip_dst,
15612                 (void *)&cmd_set_vxlan_ip_dst_value,
15613                 (void *)&cmd_set_vxlan_eth_src,
15614                 (void *)&cmd_set_vxlan_eth_src_value,
15615                 (void *)&cmd_set_vxlan_eth_dst,
15616                 (void *)&cmd_set_vxlan_eth_dst_value,
15617                 NULL,
15618         },
15619 };
15620
15621 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15622         .f = cmd_set_vxlan_parsed,
15623         .data = NULL,
15624         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15625                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15626                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15627                 " <eth-dst>",
15628         .tokens = {
15629                 (void *)&cmd_set_vxlan_set,
15630                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15631                 (void *)&cmd_set_vxlan_ip_version,
15632                 (void *)&cmd_set_vxlan_ip_version_value,
15633                 (void *)&cmd_set_vxlan_vni,
15634                 (void *)&cmd_set_vxlan_vni_value,
15635                 (void *)&cmd_set_vxlan_udp_src,
15636                 (void *)&cmd_set_vxlan_udp_src_value,
15637                 (void *)&cmd_set_vxlan_udp_dst,
15638                 (void *)&cmd_set_vxlan_udp_dst_value,
15639                 (void *)&cmd_set_vxlan_ip_src,
15640                 (void *)&cmd_set_vxlan_ip_src_value,
15641                 (void *)&cmd_set_vxlan_ip_dst,
15642                 (void *)&cmd_set_vxlan_ip_dst_value,
15643                 (void *)&cmd_set_vxlan_vlan,
15644                 (void *)&cmd_set_vxlan_vlan_value,
15645                 (void *)&cmd_set_vxlan_eth_src,
15646                 (void *)&cmd_set_vxlan_eth_src_value,
15647                 (void *)&cmd_set_vxlan_eth_dst,
15648                 (void *)&cmd_set_vxlan_eth_dst_value,
15649                 NULL,
15650         },
15651 };
15652
15653 /** Set NVGRE encapsulation details */
15654 struct cmd_set_nvgre_result {
15655         cmdline_fixed_string_t set;
15656         cmdline_fixed_string_t nvgre;
15657         cmdline_fixed_string_t pos_token;
15658         cmdline_fixed_string_t ip_version;
15659         uint32_t tni;
15660         cmdline_ipaddr_t ip_src;
15661         cmdline_ipaddr_t ip_dst;
15662         uint16_t tci;
15663         struct rte_ether_addr eth_src;
15664         struct rte_ether_addr eth_dst;
15665 };
15666
15667 cmdline_parse_token_string_t cmd_set_nvgre_set =
15668         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15669 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15670         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15671 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15672         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15673                                  "nvgre-with-vlan");
15674 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15675         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15676                                  "ip-version");
15677 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15678         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15679                                  "ipv4#ipv6");
15680 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15681         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15682                                  "tni");
15683 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15684         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15685 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15686         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15687                                  "ip-src");
15688 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15689         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15690 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15691         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15692                                  "ip-dst");
15693 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15694         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15695 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15696         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15697                                  "vlan-tci");
15698 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15699         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15700 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15701         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15702                                  "eth-src");
15703 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15704         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15705 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15706         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15707                                  "eth-dst");
15708 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15709         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15710
15711 static void cmd_set_nvgre_parsed(void *parsed_result,
15712         __rte_unused struct cmdline *cl,
15713         __rte_unused void *data)
15714 {
15715         struct cmd_set_nvgre_result *res = parsed_result;
15716         union {
15717                 uint32_t nvgre_tni;
15718                 uint8_t tni[4];
15719         } id = {
15720                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15721         };
15722
15723         if (strcmp(res->nvgre, "nvgre") == 0)
15724                 nvgre_encap_conf.select_vlan = 0;
15725         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15726                 nvgre_encap_conf.select_vlan = 1;
15727         if (strcmp(res->ip_version, "ipv4") == 0)
15728                 nvgre_encap_conf.select_ipv4 = 1;
15729         else if (strcmp(res->ip_version, "ipv6") == 0)
15730                 nvgre_encap_conf.select_ipv4 = 0;
15731         else
15732                 return;
15733         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15734         if (nvgre_encap_conf.select_ipv4) {
15735                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15736                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15737         } else {
15738                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15739                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15740         }
15741         if (nvgre_encap_conf.select_vlan)
15742                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15743         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15744                    RTE_ETHER_ADDR_LEN);
15745         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15746                    RTE_ETHER_ADDR_LEN);
15747 }
15748
15749 cmdline_parse_inst_t cmd_set_nvgre = {
15750         .f = cmd_set_nvgre_parsed,
15751         .data = NULL,
15752         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15753                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15754                 " eth-dst <eth-dst>",
15755         .tokens = {
15756                 (void *)&cmd_set_nvgre_set,
15757                 (void *)&cmd_set_nvgre_nvgre,
15758                 (void *)&cmd_set_nvgre_ip_version,
15759                 (void *)&cmd_set_nvgre_ip_version_value,
15760                 (void *)&cmd_set_nvgre_tni,
15761                 (void *)&cmd_set_nvgre_tni_value,
15762                 (void *)&cmd_set_nvgre_ip_src,
15763                 (void *)&cmd_set_nvgre_ip_src_value,
15764                 (void *)&cmd_set_nvgre_ip_dst,
15765                 (void *)&cmd_set_nvgre_ip_dst_value,
15766                 (void *)&cmd_set_nvgre_eth_src,
15767                 (void *)&cmd_set_nvgre_eth_src_value,
15768                 (void *)&cmd_set_nvgre_eth_dst,
15769                 (void *)&cmd_set_nvgre_eth_dst_value,
15770                 NULL,
15771         },
15772 };
15773
15774 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15775         .f = cmd_set_nvgre_parsed,
15776         .data = NULL,
15777         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15778                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15779                 " eth-src <eth-src> eth-dst <eth-dst>",
15780         .tokens = {
15781                 (void *)&cmd_set_nvgre_set,
15782                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15783                 (void *)&cmd_set_nvgre_ip_version,
15784                 (void *)&cmd_set_nvgre_ip_version_value,
15785                 (void *)&cmd_set_nvgre_tni,
15786                 (void *)&cmd_set_nvgre_tni_value,
15787                 (void *)&cmd_set_nvgre_ip_src,
15788                 (void *)&cmd_set_nvgre_ip_src_value,
15789                 (void *)&cmd_set_nvgre_ip_dst,
15790                 (void *)&cmd_set_nvgre_ip_dst_value,
15791                 (void *)&cmd_set_nvgre_vlan,
15792                 (void *)&cmd_set_nvgre_vlan_value,
15793                 (void *)&cmd_set_nvgre_eth_src,
15794                 (void *)&cmd_set_nvgre_eth_src_value,
15795                 (void *)&cmd_set_nvgre_eth_dst,
15796                 (void *)&cmd_set_nvgre_eth_dst_value,
15797                 NULL,
15798         },
15799 };
15800
15801 /** Set L2 encapsulation details */
15802 struct cmd_set_l2_encap_result {
15803         cmdline_fixed_string_t set;
15804         cmdline_fixed_string_t l2_encap;
15805         cmdline_fixed_string_t pos_token;
15806         cmdline_fixed_string_t ip_version;
15807         uint32_t vlan_present:1;
15808         uint16_t tci;
15809         struct rte_ether_addr eth_src;
15810         struct rte_ether_addr eth_dst;
15811 };
15812
15813 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15814         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15815 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15816         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15817 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15818         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15819                                  "l2_encap-with-vlan");
15820 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15821         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15822                                  "ip-version");
15823 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15824         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15825                                  "ipv4#ipv6");
15826 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15828                                  "vlan-tci");
15829 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15830         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15831 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15832         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15833                                  "eth-src");
15834 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15835         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15836 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15837         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15838                                  "eth-dst");
15839 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15840         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15841
15842 static void cmd_set_l2_encap_parsed(void *parsed_result,
15843         __rte_unused struct cmdline *cl,
15844         __rte_unused void *data)
15845 {
15846         struct cmd_set_l2_encap_result *res = parsed_result;
15847
15848         if (strcmp(res->l2_encap, "l2_encap") == 0)
15849                 l2_encap_conf.select_vlan = 0;
15850         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15851                 l2_encap_conf.select_vlan = 1;
15852         if (strcmp(res->ip_version, "ipv4") == 0)
15853                 l2_encap_conf.select_ipv4 = 1;
15854         else if (strcmp(res->ip_version, "ipv6") == 0)
15855                 l2_encap_conf.select_ipv4 = 0;
15856         else
15857                 return;
15858         if (l2_encap_conf.select_vlan)
15859                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15860         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15861                    RTE_ETHER_ADDR_LEN);
15862         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15863                    RTE_ETHER_ADDR_LEN);
15864 }
15865
15866 cmdline_parse_inst_t cmd_set_l2_encap = {
15867         .f = cmd_set_l2_encap_parsed,
15868         .data = NULL,
15869         .help_str = "set l2_encap ip-version ipv4|ipv6"
15870                 " eth-src <eth-src> eth-dst <eth-dst>",
15871         .tokens = {
15872                 (void *)&cmd_set_l2_encap_set,
15873                 (void *)&cmd_set_l2_encap_l2_encap,
15874                 (void *)&cmd_set_l2_encap_ip_version,
15875                 (void *)&cmd_set_l2_encap_ip_version_value,
15876                 (void *)&cmd_set_l2_encap_eth_src,
15877                 (void *)&cmd_set_l2_encap_eth_src_value,
15878                 (void *)&cmd_set_l2_encap_eth_dst,
15879                 (void *)&cmd_set_l2_encap_eth_dst_value,
15880                 NULL,
15881         },
15882 };
15883
15884 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15885         .f = cmd_set_l2_encap_parsed,
15886         .data = NULL,
15887         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15888                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15889         .tokens = {
15890                 (void *)&cmd_set_l2_encap_set,
15891                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15892                 (void *)&cmd_set_l2_encap_ip_version,
15893                 (void *)&cmd_set_l2_encap_ip_version_value,
15894                 (void *)&cmd_set_l2_encap_vlan,
15895                 (void *)&cmd_set_l2_encap_vlan_value,
15896                 (void *)&cmd_set_l2_encap_eth_src,
15897                 (void *)&cmd_set_l2_encap_eth_src_value,
15898                 (void *)&cmd_set_l2_encap_eth_dst,
15899                 (void *)&cmd_set_l2_encap_eth_dst_value,
15900                 NULL,
15901         },
15902 };
15903
15904 /** Set L2 decapsulation details */
15905 struct cmd_set_l2_decap_result {
15906         cmdline_fixed_string_t set;
15907         cmdline_fixed_string_t l2_decap;
15908         cmdline_fixed_string_t pos_token;
15909         uint32_t vlan_present:1;
15910 };
15911
15912 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15913         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15914 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15915         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15916                                  "l2_decap");
15917 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15918         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15919                                  "l2_decap-with-vlan");
15920
15921 static void cmd_set_l2_decap_parsed(void *parsed_result,
15922         __rte_unused struct cmdline *cl,
15923         __rte_unused void *data)
15924 {
15925         struct cmd_set_l2_decap_result *res = parsed_result;
15926
15927         if (strcmp(res->l2_decap, "l2_decap") == 0)
15928                 l2_decap_conf.select_vlan = 0;
15929         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15930                 l2_decap_conf.select_vlan = 1;
15931 }
15932
15933 cmdline_parse_inst_t cmd_set_l2_decap = {
15934         .f = cmd_set_l2_decap_parsed,
15935         .data = NULL,
15936         .help_str = "set l2_decap",
15937         .tokens = {
15938                 (void *)&cmd_set_l2_decap_set,
15939                 (void *)&cmd_set_l2_decap_l2_decap,
15940                 NULL,
15941         },
15942 };
15943
15944 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15945         .f = cmd_set_l2_decap_parsed,
15946         .data = NULL,
15947         .help_str = "set l2_decap-with-vlan",
15948         .tokens = {
15949                 (void *)&cmd_set_l2_decap_set,
15950                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15951                 NULL,
15952         },
15953 };
15954
15955 /** Set MPLSoGRE encapsulation details */
15956 struct cmd_set_mplsogre_encap_result {
15957         cmdline_fixed_string_t set;
15958         cmdline_fixed_string_t mplsogre;
15959         cmdline_fixed_string_t pos_token;
15960         cmdline_fixed_string_t ip_version;
15961         uint32_t vlan_present:1;
15962         uint32_t label;
15963         cmdline_ipaddr_t ip_src;
15964         cmdline_ipaddr_t ip_dst;
15965         uint16_t tci;
15966         struct rte_ether_addr eth_src;
15967         struct rte_ether_addr eth_dst;
15968 };
15969
15970 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15971         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15972                                  "set");
15973 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15974         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15975                                  "mplsogre_encap");
15976 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15977         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15978                                  mplsogre, "mplsogre_encap-with-vlan");
15979 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15981                                  pos_token, "ip-version");
15982 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15984                                  ip_version, "ipv4#ipv6");
15985 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15987                                  pos_token, "label");
15988 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15989         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15990                               UINT32);
15991 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15993                                  pos_token, "ip-src");
15994 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15995         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15996 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15997         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15998                                  pos_token, "ip-dst");
15999 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16000         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16001 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16002         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16003                                  pos_token, "vlan-tci");
16004 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16005         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16006                               UINT16);
16007 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16008         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16009                                  pos_token, "eth-src");
16010 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16011         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16012                                     eth_src);
16013 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16014         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16015                                  pos_token, "eth-dst");
16016 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16017         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16018                                     eth_dst);
16019
16020 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16021         __rte_unused struct cmdline *cl,
16022         __rte_unused void *data)
16023 {
16024         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16025         union {
16026                 uint32_t mplsogre_label;
16027                 uint8_t label[4];
16028         } id = {
16029                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16030         };
16031
16032         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16033                 mplsogre_encap_conf.select_vlan = 0;
16034         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16035                 mplsogre_encap_conf.select_vlan = 1;
16036         if (strcmp(res->ip_version, "ipv4") == 0)
16037                 mplsogre_encap_conf.select_ipv4 = 1;
16038         else if (strcmp(res->ip_version, "ipv6") == 0)
16039                 mplsogre_encap_conf.select_ipv4 = 0;
16040         else
16041                 return;
16042         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16043         if (mplsogre_encap_conf.select_ipv4) {
16044                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16045                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16046         } else {
16047                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16048                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16049         }
16050         if (mplsogre_encap_conf.select_vlan)
16051                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16052         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16053                    RTE_ETHER_ADDR_LEN);
16054         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16055                    RTE_ETHER_ADDR_LEN);
16056 }
16057
16058 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16059         .f = cmd_set_mplsogre_encap_parsed,
16060         .data = NULL,
16061         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16062                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16063                 " eth-dst <eth-dst>",
16064         .tokens = {
16065                 (void *)&cmd_set_mplsogre_encap_set,
16066                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16067                 (void *)&cmd_set_mplsogre_encap_ip_version,
16068                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16069                 (void *)&cmd_set_mplsogre_encap_label,
16070                 (void *)&cmd_set_mplsogre_encap_label_value,
16071                 (void *)&cmd_set_mplsogre_encap_ip_src,
16072                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16073                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16074                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16075                 (void *)&cmd_set_mplsogre_encap_eth_src,
16076                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16077                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16078                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16079                 NULL,
16080         },
16081 };
16082
16083 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16084         .f = cmd_set_mplsogre_encap_parsed,
16085         .data = NULL,
16086         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16087                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16088                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16089         .tokens = {
16090                 (void *)&cmd_set_mplsogre_encap_set,
16091                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16092                 (void *)&cmd_set_mplsogre_encap_ip_version,
16093                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16094                 (void *)&cmd_set_mplsogre_encap_label,
16095                 (void *)&cmd_set_mplsogre_encap_label_value,
16096                 (void *)&cmd_set_mplsogre_encap_ip_src,
16097                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16098                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16099                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16100                 (void *)&cmd_set_mplsogre_encap_vlan,
16101                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16102                 (void *)&cmd_set_mplsogre_encap_eth_src,
16103                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16104                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16105                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16106                 NULL,
16107         },
16108 };
16109
16110 /** Set MPLSoGRE decapsulation details */
16111 struct cmd_set_mplsogre_decap_result {
16112         cmdline_fixed_string_t set;
16113         cmdline_fixed_string_t mplsogre;
16114         cmdline_fixed_string_t pos_token;
16115         cmdline_fixed_string_t ip_version;
16116         uint32_t vlan_present:1;
16117 };
16118
16119 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16120         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16121                                  "set");
16122 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16123         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16124                                  "mplsogre_decap");
16125 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16126         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16127                                  mplsogre, "mplsogre_decap-with-vlan");
16128 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16129         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16130                                  pos_token, "ip-version");
16131 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16132         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16133                                  ip_version, "ipv4#ipv6");
16134
16135 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16136         __rte_unused struct cmdline *cl,
16137         __rte_unused void *data)
16138 {
16139         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16140
16141         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16142                 mplsogre_decap_conf.select_vlan = 0;
16143         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16144                 mplsogre_decap_conf.select_vlan = 1;
16145         if (strcmp(res->ip_version, "ipv4") == 0)
16146                 mplsogre_decap_conf.select_ipv4 = 1;
16147         else if (strcmp(res->ip_version, "ipv6") == 0)
16148                 mplsogre_decap_conf.select_ipv4 = 0;
16149 }
16150
16151 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16152         .f = cmd_set_mplsogre_decap_parsed,
16153         .data = NULL,
16154         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16155         .tokens = {
16156                 (void *)&cmd_set_mplsogre_decap_set,
16157                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16158                 (void *)&cmd_set_mplsogre_decap_ip_version,
16159                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16160                 NULL,
16161         },
16162 };
16163
16164 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16165         .f = cmd_set_mplsogre_decap_parsed,
16166         .data = NULL,
16167         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16168         .tokens = {
16169                 (void *)&cmd_set_mplsogre_decap_set,
16170                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16171                 (void *)&cmd_set_mplsogre_decap_ip_version,
16172                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16173                 NULL,
16174         },
16175 };
16176
16177 /** Set MPLSoUDP encapsulation details */
16178 struct cmd_set_mplsoudp_encap_result {
16179         cmdline_fixed_string_t set;
16180         cmdline_fixed_string_t mplsoudp;
16181         cmdline_fixed_string_t pos_token;
16182         cmdline_fixed_string_t ip_version;
16183         uint32_t vlan_present:1;
16184         uint32_t label;
16185         uint16_t udp_src;
16186         uint16_t udp_dst;
16187         cmdline_ipaddr_t ip_src;
16188         cmdline_ipaddr_t ip_dst;
16189         uint16_t tci;
16190         struct rte_ether_addr eth_src;
16191         struct rte_ether_addr eth_dst;
16192 };
16193
16194 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16196                                  "set");
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16199                                  "mplsoudp_encap");
16200 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16202                                  mplsoudp, "mplsoudp_encap-with-vlan");
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16205                                  pos_token, "ip-version");
16206 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16207         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16208                                  ip_version, "ipv4#ipv6");
16209 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16211                                  pos_token, "label");
16212 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16213         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16214                               UINT32);
16215 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16217                                  pos_token, "udp-src");
16218 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16219         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16220                               UINT16);
16221 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16222         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16223                                  pos_token, "udp-dst");
16224 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16225         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16226                               UINT16);
16227 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16228         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16229                                  pos_token, "ip-src");
16230 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16231         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16232 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16233         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16234                                  pos_token, "ip-dst");
16235 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16236         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16237 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16238         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16239                                  pos_token, "vlan-tci");
16240 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16241         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16242                               UINT16);
16243 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16244         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16245                                  pos_token, "eth-src");
16246 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16247         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16248                                     eth_src);
16249 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16250         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16251                                  pos_token, "eth-dst");
16252 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16253         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16254                                     eth_dst);
16255
16256 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16257         __rte_unused struct cmdline *cl,
16258         __rte_unused void *data)
16259 {
16260         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16261         union {
16262                 uint32_t mplsoudp_label;
16263                 uint8_t label[4];
16264         } id = {
16265                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16266         };
16267
16268         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16269                 mplsoudp_encap_conf.select_vlan = 0;
16270         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16271                 mplsoudp_encap_conf.select_vlan = 1;
16272         if (strcmp(res->ip_version, "ipv4") == 0)
16273                 mplsoudp_encap_conf.select_ipv4 = 1;
16274         else if (strcmp(res->ip_version, "ipv6") == 0)
16275                 mplsoudp_encap_conf.select_ipv4 = 0;
16276         else
16277                 return;
16278         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16279         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16280         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16281         if (mplsoudp_encap_conf.select_ipv4) {
16282                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16283                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16284         } else {
16285                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16286                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16287         }
16288         if (mplsoudp_encap_conf.select_vlan)
16289                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16290         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16291                    RTE_ETHER_ADDR_LEN);
16292         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16293                    RTE_ETHER_ADDR_LEN);
16294 }
16295
16296 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16297         .f = cmd_set_mplsoudp_encap_parsed,
16298         .data = NULL,
16299         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16300                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16301                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16302         .tokens = {
16303                 (void *)&cmd_set_mplsoudp_encap_set,
16304                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16305                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16306                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16307                 (void *)&cmd_set_mplsoudp_encap_label,
16308                 (void *)&cmd_set_mplsoudp_encap_label_value,
16309                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16310                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16311                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16312                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16313                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16314                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16315                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16316                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16317                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16318                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16319                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16320                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16321                 NULL,
16322         },
16323 };
16324
16325 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16326         .f = cmd_set_mplsoudp_encap_parsed,
16327         .data = NULL,
16328         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16329                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16330                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16331                 " eth-src <eth-src> eth-dst <eth-dst>",
16332         .tokens = {
16333                 (void *)&cmd_set_mplsoudp_encap_set,
16334                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16335                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16336                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16337                 (void *)&cmd_set_mplsoudp_encap_label,
16338                 (void *)&cmd_set_mplsoudp_encap_label_value,
16339                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16340                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16341                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16342                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16343                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16344                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16345                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16346                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16347                 (void *)&cmd_set_mplsoudp_encap_vlan,
16348                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16349                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16350                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16351                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16352                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16353                 NULL,
16354         },
16355 };
16356
16357 /** Set MPLSoUDP decapsulation details */
16358 struct cmd_set_mplsoudp_decap_result {
16359         cmdline_fixed_string_t set;
16360         cmdline_fixed_string_t mplsoudp;
16361         cmdline_fixed_string_t pos_token;
16362         cmdline_fixed_string_t ip_version;
16363         uint32_t vlan_present:1;
16364 };
16365
16366 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16367         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16368                                  "set");
16369 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16370         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16371                                  "mplsoudp_decap");
16372 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16373         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16374                                  mplsoudp, "mplsoudp_decap-with-vlan");
16375 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16376         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16377                                  pos_token, "ip-version");
16378 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16379         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16380                                  ip_version, "ipv4#ipv6");
16381
16382 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16383         __rte_unused struct cmdline *cl,
16384         __rte_unused void *data)
16385 {
16386         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16387
16388         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16389                 mplsoudp_decap_conf.select_vlan = 0;
16390         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16391                 mplsoudp_decap_conf.select_vlan = 1;
16392         if (strcmp(res->ip_version, "ipv4") == 0)
16393                 mplsoudp_decap_conf.select_ipv4 = 1;
16394         else if (strcmp(res->ip_version, "ipv6") == 0)
16395                 mplsoudp_decap_conf.select_ipv4 = 0;
16396 }
16397
16398 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16399         .f = cmd_set_mplsoudp_decap_parsed,
16400         .data = NULL,
16401         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16402         .tokens = {
16403                 (void *)&cmd_set_mplsoudp_decap_set,
16404                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16405                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16406                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16407                 NULL,
16408         },
16409 };
16410
16411 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16412         .f = cmd_set_mplsoudp_decap_parsed,
16413         .data = NULL,
16414         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16415         .tokens = {
16416                 (void *)&cmd_set_mplsoudp_decap_set,
16417                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16418                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16419                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16420                 NULL,
16421         },
16422 };
16423
16424 /* Strict link priority scheduling mode setting */
16425 static void
16426 cmd_strict_link_prio_parsed(
16427         void *parsed_result,
16428         __rte_unused struct cmdline *cl,
16429         __rte_unused void *data)
16430 {
16431         struct cmd_vf_tc_bw_result *res = parsed_result;
16432         int ret = -ENOTSUP;
16433
16434         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16435                 return;
16436
16437 #ifdef RTE_LIBRTE_I40E_PMD
16438         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16439 #endif
16440
16441         switch (ret) {
16442         case 0:
16443                 break;
16444         case -EINVAL:
16445                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16446                 break;
16447         case -ENODEV:
16448                 printf("invalid port_id %d\n", res->port_id);
16449                 break;
16450         case -ENOTSUP:
16451                 printf("function not implemented\n");
16452                 break;
16453         default:
16454                 printf("programming error: (%s)\n", strerror(-ret));
16455         }
16456 }
16457
16458 cmdline_parse_inst_t cmd_strict_link_prio = {
16459         .f = cmd_strict_link_prio_parsed,
16460         .data = NULL,
16461         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16462         .tokens = {
16463                 (void *)&cmd_vf_tc_bw_set,
16464                 (void *)&cmd_vf_tc_bw_tx,
16465                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16466                 (void *)&cmd_vf_tc_bw_port_id,
16467                 (void *)&cmd_vf_tc_bw_tc_map,
16468                 NULL,
16469         },
16470 };
16471
16472 /* Load dynamic device personalization*/
16473 struct cmd_ddp_add_result {
16474         cmdline_fixed_string_t ddp;
16475         cmdline_fixed_string_t add;
16476         portid_t port_id;
16477         char filepath[];
16478 };
16479
16480 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16481         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16482 cmdline_parse_token_string_t cmd_ddp_add_add =
16483         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16484 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16485         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16486 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16487         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16488
16489 static void
16490 cmd_ddp_add_parsed(
16491         void *parsed_result,
16492         __rte_unused struct cmdline *cl,
16493         __rte_unused void *data)
16494 {
16495         struct cmd_ddp_add_result *res = parsed_result;
16496         uint8_t *buff;
16497         uint32_t size;
16498         char *filepath;
16499         char *file_fld[2];
16500         int file_num;
16501         int ret = -ENOTSUP;
16502
16503         if (!all_ports_stopped()) {
16504                 printf("Please stop all ports first\n");
16505                 return;
16506         }
16507
16508         filepath = strdup(res->filepath);
16509         if (filepath == NULL) {
16510                 printf("Failed to allocate memory\n");
16511                 return;
16512         }
16513         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16514
16515         buff = open_file(file_fld[0], &size);
16516         if (!buff) {
16517                 free((void *)filepath);
16518                 return;
16519         }
16520
16521 #ifdef RTE_LIBRTE_I40E_PMD
16522         if (ret == -ENOTSUP)
16523                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16524                                                buff, size,
16525                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16526 #endif
16527
16528         if (ret == -EEXIST)
16529                 printf("Profile has already existed.\n");
16530         else if (ret < 0)
16531                 printf("Failed to load profile.\n");
16532         else if (file_num == 2)
16533                 save_file(file_fld[1], buff, size);
16534
16535         close_file(buff);
16536         free((void *)filepath);
16537 }
16538
16539 cmdline_parse_inst_t cmd_ddp_add = {
16540         .f = cmd_ddp_add_parsed,
16541         .data = NULL,
16542         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16543         .tokens = {
16544                 (void *)&cmd_ddp_add_ddp,
16545                 (void *)&cmd_ddp_add_add,
16546                 (void *)&cmd_ddp_add_port_id,
16547                 (void *)&cmd_ddp_add_filepath,
16548                 NULL,
16549         },
16550 };
16551
16552 /* Delete dynamic device personalization*/
16553 struct cmd_ddp_del_result {
16554         cmdline_fixed_string_t ddp;
16555         cmdline_fixed_string_t del;
16556         portid_t port_id;
16557         char filepath[];
16558 };
16559
16560 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16561         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16562 cmdline_parse_token_string_t cmd_ddp_del_del =
16563         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16564 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16565         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16566 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16567         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16568
16569 static void
16570 cmd_ddp_del_parsed(
16571         void *parsed_result,
16572         __rte_unused struct cmdline *cl,
16573         __rte_unused void *data)
16574 {
16575         struct cmd_ddp_del_result *res = parsed_result;
16576         uint8_t *buff;
16577         uint32_t size;
16578         int ret = -ENOTSUP;
16579
16580         if (!all_ports_stopped()) {
16581                 printf("Please stop all ports first\n");
16582                 return;
16583         }
16584
16585         buff = open_file(res->filepath, &size);
16586         if (!buff)
16587                 return;
16588
16589 #ifdef RTE_LIBRTE_I40E_PMD
16590         if (ret == -ENOTSUP)
16591                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16592                                                buff, size,
16593                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16594 #endif
16595
16596         if (ret == -EACCES)
16597                 printf("Profile does not exist.\n");
16598         else if (ret < 0)
16599                 printf("Failed to delete profile.\n");
16600
16601         close_file(buff);
16602 }
16603
16604 cmdline_parse_inst_t cmd_ddp_del = {
16605         .f = cmd_ddp_del_parsed,
16606         .data = NULL,
16607         .help_str = "ddp del <port_id> <backup_profile_path>",
16608         .tokens = {
16609                 (void *)&cmd_ddp_del_ddp,
16610                 (void *)&cmd_ddp_del_del,
16611                 (void *)&cmd_ddp_del_port_id,
16612                 (void *)&cmd_ddp_del_filepath,
16613                 NULL,
16614         },
16615 };
16616
16617 /* Get dynamic device personalization profile info */
16618 struct cmd_ddp_info_result {
16619         cmdline_fixed_string_t ddp;
16620         cmdline_fixed_string_t get;
16621         cmdline_fixed_string_t info;
16622         char filepath[];
16623 };
16624
16625 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16626         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16627 cmdline_parse_token_string_t cmd_ddp_info_get =
16628         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16629 cmdline_parse_token_string_t cmd_ddp_info_info =
16630         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16631 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16632         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16633
16634 static void
16635 cmd_ddp_info_parsed(
16636         void *parsed_result,
16637         __rte_unused struct cmdline *cl,
16638         __rte_unused void *data)
16639 {
16640         struct cmd_ddp_info_result *res = parsed_result;
16641         uint8_t *pkg;
16642         uint32_t pkg_size;
16643         int ret = -ENOTSUP;
16644 #ifdef RTE_LIBRTE_I40E_PMD
16645         uint32_t i, j, n;
16646         uint8_t *buff;
16647         uint32_t buff_size = 0;
16648         struct rte_pmd_i40e_profile_info info;
16649         uint32_t dev_num = 0;
16650         struct rte_pmd_i40e_ddp_device_id *devs;
16651         uint32_t proto_num = 0;
16652         struct rte_pmd_i40e_proto_info *proto = NULL;
16653         uint32_t pctype_num = 0;
16654         struct rte_pmd_i40e_ptype_info *pctype;
16655         uint32_t ptype_num = 0;
16656         struct rte_pmd_i40e_ptype_info *ptype;
16657         uint8_t proto_id;
16658
16659 #endif
16660
16661         pkg = open_file(res->filepath, &pkg_size);
16662         if (!pkg)
16663                 return;
16664
16665 #ifdef RTE_LIBRTE_I40E_PMD
16666         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16667                                 (uint8_t *)&info, sizeof(info),
16668                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16669         if (!ret) {
16670                 printf("Global Track id:       0x%x\n", info.track_id);
16671                 printf("Global Version:        %d.%d.%d.%d\n",
16672                         info.version.major,
16673                         info.version.minor,
16674                         info.version.update,
16675                         info.version.draft);
16676                 printf("Global Package name:   %s\n\n", info.name);
16677         }
16678
16679         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16680                                 (uint8_t *)&info, sizeof(info),
16681                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16682         if (!ret) {
16683                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16684                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16685                         info.version.major,
16686                         info.version.minor,
16687                         info.version.update,
16688                         info.version.draft);
16689                 printf("i40e Profile name:     %s\n\n", info.name);
16690         }
16691
16692         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16693                                 (uint8_t *)&buff_size, sizeof(buff_size),
16694                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16695         if (!ret && buff_size) {
16696                 buff = (uint8_t *)malloc(buff_size);
16697                 if (buff) {
16698                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16699                                                 buff, buff_size,
16700                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16701                         if (!ret)
16702                                 printf("Package Notes:\n%s\n\n", buff);
16703                         free(buff);
16704                 }
16705         }
16706
16707         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16708                                 (uint8_t *)&dev_num, sizeof(dev_num),
16709                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16710         if (!ret && dev_num) {
16711                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16712                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16713                 if (devs) {
16714                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16715                                                 (uint8_t *)devs, buff_size,
16716                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16717                         if (!ret) {
16718                                 printf("List of supported devices:\n");
16719                                 for (i = 0; i < dev_num; i++) {
16720                                         printf("  %04X:%04X %04X:%04X\n",
16721                                                 devs[i].vendor_dev_id >> 16,
16722                                                 devs[i].vendor_dev_id & 0xFFFF,
16723                                                 devs[i].sub_vendor_dev_id >> 16,
16724                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16725                                 }
16726                                 printf("\n");
16727                         }
16728                         free(devs);
16729                 }
16730         }
16731
16732         /* get information about protocols and packet types */
16733         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16734                 (uint8_t *)&proto_num, sizeof(proto_num),
16735                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16736         if (ret || !proto_num)
16737                 goto no_print_return;
16738
16739         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16740         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16741         if (!proto)
16742                 goto no_print_return;
16743
16744         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16745                                         buff_size,
16746                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16747         if (!ret) {
16748                 printf("List of used protocols:\n");
16749                 for (i = 0; i < proto_num; i++)
16750                         printf("  %2u: %s\n", proto[i].proto_id,
16751                                proto[i].name);
16752                 printf("\n");
16753         }
16754         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16755                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16756                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16757         if (ret || !pctype_num)
16758                 goto no_print_pctypes;
16759
16760         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16761         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16762         if (!pctype)
16763                 goto no_print_pctypes;
16764
16765         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16766                                         buff_size,
16767                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16768         if (ret) {
16769                 free(pctype);
16770                 goto no_print_pctypes;
16771         }
16772
16773         printf("List of defined packet classification types:\n");
16774         for (i = 0; i < pctype_num; i++) {
16775                 printf("  %2u:", pctype[i].ptype_id);
16776                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16777                         proto_id = pctype[i].protocols[j];
16778                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16779                                 for (n = 0; n < proto_num; n++) {
16780                                         if (proto[n].proto_id == proto_id) {
16781                                                 printf(" %s", proto[n].name);
16782                                                 break;
16783                                         }
16784                                 }
16785                         }
16786                 }
16787                 printf("\n");
16788         }
16789         printf("\n");
16790         free(pctype);
16791
16792 no_print_pctypes:
16793
16794         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16795                                         sizeof(ptype_num),
16796                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16797         if (ret || !ptype_num)
16798                 goto no_print_return;
16799
16800         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16801         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16802         if (!ptype)
16803                 goto no_print_return;
16804
16805         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16806                                         buff_size,
16807                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16808         if (ret) {
16809                 free(ptype);
16810                 goto no_print_return;
16811         }
16812         printf("List of defined packet types:\n");
16813         for (i = 0; i < ptype_num; i++) {
16814                 printf("  %2u:", ptype[i].ptype_id);
16815                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16816                         proto_id = ptype[i].protocols[j];
16817                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16818                                 for (n = 0; n < proto_num; n++) {
16819                                         if (proto[n].proto_id == proto_id) {
16820                                                 printf(" %s", proto[n].name);
16821                                                 break;
16822                                         }
16823                                 }
16824                         }
16825                 }
16826                 printf("\n");
16827         }
16828         free(ptype);
16829         printf("\n");
16830
16831         ret = 0;
16832 no_print_return:
16833         if (proto)
16834                 free(proto);
16835 #endif
16836         if (ret == -ENOTSUP)
16837                 printf("Function not supported in PMD driver\n");
16838         close_file(pkg);
16839 }
16840
16841 cmdline_parse_inst_t cmd_ddp_get_info = {
16842         .f = cmd_ddp_info_parsed,
16843         .data = NULL,
16844         .help_str = "ddp get info <profile_path>",
16845         .tokens = {
16846                 (void *)&cmd_ddp_info_ddp,
16847                 (void *)&cmd_ddp_info_get,
16848                 (void *)&cmd_ddp_info_info,
16849                 (void *)&cmd_ddp_info_filepath,
16850                 NULL,
16851         },
16852 };
16853
16854 /* Get dynamic device personalization profile info list*/
16855 #define PROFILE_INFO_SIZE 48
16856 #define MAX_PROFILE_NUM 16
16857
16858 struct cmd_ddp_get_list_result {
16859         cmdline_fixed_string_t ddp;
16860         cmdline_fixed_string_t get;
16861         cmdline_fixed_string_t list;
16862         portid_t port_id;
16863 };
16864
16865 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16866         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16867 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16868         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16869 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16870         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16871 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16872         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16873
16874 static void
16875 cmd_ddp_get_list_parsed(
16876         __rte_unused void *parsed_result,
16877         __rte_unused struct cmdline *cl,
16878         __rte_unused void *data)
16879 {
16880 #ifdef RTE_LIBRTE_I40E_PMD
16881         struct cmd_ddp_get_list_result *res = parsed_result;
16882         struct rte_pmd_i40e_profile_list *p_list;
16883         struct rte_pmd_i40e_profile_info *p_info;
16884         uint32_t p_num;
16885         uint32_t size;
16886         uint32_t i;
16887 #endif
16888         int ret = -ENOTSUP;
16889
16890 #ifdef RTE_LIBRTE_I40E_PMD
16891         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16892         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16893         if (!p_list)
16894                 printf("%s: Failed to malloc buffer\n", __func__);
16895
16896         if (ret == -ENOTSUP)
16897                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16898                                                 (uint8_t *)p_list, size);
16899
16900         if (!ret) {
16901                 p_num = p_list->p_count;
16902                 printf("Profile number is: %d\n\n", p_num);
16903
16904                 for (i = 0; i < p_num; i++) {
16905                         p_info = &p_list->p_info[i];
16906                         printf("Profile %d:\n", i);
16907                         printf("Track id:     0x%x\n", p_info->track_id);
16908                         printf("Version:      %d.%d.%d.%d\n",
16909                                p_info->version.major,
16910                                p_info->version.minor,
16911                                p_info->version.update,
16912                                p_info->version.draft);
16913                         printf("Profile name: %s\n\n", p_info->name);
16914                 }
16915         }
16916
16917         free(p_list);
16918 #endif
16919
16920         if (ret < 0)
16921                 printf("Failed to get ddp list\n");
16922 }
16923
16924 cmdline_parse_inst_t cmd_ddp_get_list = {
16925         .f = cmd_ddp_get_list_parsed,
16926         .data = NULL,
16927         .help_str = "ddp get list <port_id>",
16928         .tokens = {
16929                 (void *)&cmd_ddp_get_list_ddp,
16930                 (void *)&cmd_ddp_get_list_get,
16931                 (void *)&cmd_ddp_get_list_list,
16932                 (void *)&cmd_ddp_get_list_port_id,
16933                 NULL,
16934         },
16935 };
16936
16937 /* Configure input set */
16938 struct cmd_cfg_input_set_result {
16939         cmdline_fixed_string_t port;
16940         cmdline_fixed_string_t cfg;
16941         portid_t port_id;
16942         cmdline_fixed_string_t pctype;
16943         uint8_t pctype_id;
16944         cmdline_fixed_string_t inset_type;
16945         cmdline_fixed_string_t opt;
16946         cmdline_fixed_string_t field;
16947         uint8_t field_idx;
16948 };
16949
16950 static void
16951 cmd_cfg_input_set_parsed(
16952         __rte_unused void *parsed_result,
16953         __rte_unused struct cmdline *cl,
16954         __rte_unused void *data)
16955 {
16956 #ifdef RTE_LIBRTE_I40E_PMD
16957         struct cmd_cfg_input_set_result *res = parsed_result;
16958         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16959         struct rte_pmd_i40e_inset inset;
16960 #endif
16961         int ret = -ENOTSUP;
16962
16963         if (!all_ports_stopped()) {
16964                 printf("Please stop all ports first\n");
16965                 return;
16966         }
16967
16968 #ifdef RTE_LIBRTE_I40E_PMD
16969         if (!strcmp(res->inset_type, "hash_inset"))
16970                 inset_type = INSET_HASH;
16971         else if (!strcmp(res->inset_type, "fdir_inset"))
16972                 inset_type = INSET_FDIR;
16973         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16974                 inset_type = INSET_FDIR_FLX;
16975         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16976                                      &inset, inset_type);
16977         if (ret) {
16978                 printf("Failed to get input set.\n");
16979                 return;
16980         }
16981
16982         if (!strcmp(res->opt, "get")) {
16983                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16984                                                    res->field_idx);
16985                 if (ret)
16986                         printf("Field index %d is enabled.\n", res->field_idx);
16987                 else
16988                         printf("Field index %d is disabled.\n", res->field_idx);
16989                 return;
16990         } else if (!strcmp(res->opt, "set"))
16991                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16992                                                    res->field_idx);
16993         else if (!strcmp(res->opt, "clear"))
16994                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16995                                                      res->field_idx);
16996         if (ret) {
16997                 printf("Failed to configure input set field.\n");
16998                 return;
16999         }
17000
17001         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17002                                      &inset, inset_type);
17003         if (ret) {
17004                 printf("Failed to set input set.\n");
17005                 return;
17006         }
17007 #endif
17008
17009         if (ret == -ENOTSUP)
17010                 printf("Function not supported\n");
17011 }
17012
17013 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17014         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17015                                  port, "port");
17016 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17017         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17018                                  cfg, "config");
17019 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17020         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17021                               port_id, UINT16);
17022 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17023         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17024                                  pctype, "pctype");
17025 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17026         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17027                               pctype_id, UINT8);
17028 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17029         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17030                                  inset_type,
17031                                  "hash_inset#fdir_inset#fdir_flx_inset");
17032 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17033         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17034                                  opt, "get#set#clear");
17035 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17036         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17037                                  field, "field");
17038 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17039         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17040                               field_idx, UINT8);
17041
17042 cmdline_parse_inst_t cmd_cfg_input_set = {
17043         .f = cmd_cfg_input_set_parsed,
17044         .data = NULL,
17045         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17046                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17047         .tokens = {
17048                 (void *)&cmd_cfg_input_set_port,
17049                 (void *)&cmd_cfg_input_set_cfg,
17050                 (void *)&cmd_cfg_input_set_port_id,
17051                 (void *)&cmd_cfg_input_set_pctype,
17052                 (void *)&cmd_cfg_input_set_pctype_id,
17053                 (void *)&cmd_cfg_input_set_inset_type,
17054                 (void *)&cmd_cfg_input_set_opt,
17055                 (void *)&cmd_cfg_input_set_field,
17056                 (void *)&cmd_cfg_input_set_field_idx,
17057                 NULL,
17058         },
17059 };
17060
17061 /* Clear input set */
17062 struct cmd_clear_input_set_result {
17063         cmdline_fixed_string_t port;
17064         cmdline_fixed_string_t cfg;
17065         portid_t port_id;
17066         cmdline_fixed_string_t pctype;
17067         uint8_t pctype_id;
17068         cmdline_fixed_string_t inset_type;
17069         cmdline_fixed_string_t clear;
17070         cmdline_fixed_string_t all;
17071 };
17072
17073 static void
17074 cmd_clear_input_set_parsed(
17075         __rte_unused void *parsed_result,
17076         __rte_unused struct cmdline *cl,
17077         __rte_unused void *data)
17078 {
17079 #ifdef RTE_LIBRTE_I40E_PMD
17080         struct cmd_clear_input_set_result *res = parsed_result;
17081         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17082         struct rte_pmd_i40e_inset inset;
17083 #endif
17084         int ret = -ENOTSUP;
17085
17086         if (!all_ports_stopped()) {
17087                 printf("Please stop all ports first\n");
17088                 return;
17089         }
17090
17091 #ifdef RTE_LIBRTE_I40E_PMD
17092         if (!strcmp(res->inset_type, "hash_inset"))
17093                 inset_type = INSET_HASH;
17094         else if (!strcmp(res->inset_type, "fdir_inset"))
17095                 inset_type = INSET_FDIR;
17096         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17097                 inset_type = INSET_FDIR_FLX;
17098
17099         memset(&inset, 0, sizeof(inset));
17100
17101         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17102                                      &inset, inset_type);
17103         if (ret) {
17104                 printf("Failed to clear input set.\n");
17105                 return;
17106         }
17107
17108 #endif
17109
17110         if (ret == -ENOTSUP)
17111                 printf("Function not supported\n");
17112 }
17113
17114 cmdline_parse_token_string_t cmd_clear_input_set_port =
17115         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17116                                  port, "port");
17117 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17118         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17119                                  cfg, "config");
17120 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17121         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17122                               port_id, UINT16);
17123 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17124         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17125                                  pctype, "pctype");
17126 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17127         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17128                               pctype_id, UINT8);
17129 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17130         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17131                                  inset_type,
17132                                  "hash_inset#fdir_inset#fdir_flx_inset");
17133 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17134         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17135                                  clear, "clear");
17136 cmdline_parse_token_string_t cmd_clear_input_set_all =
17137         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17138                                  all, "all");
17139
17140 cmdline_parse_inst_t cmd_clear_input_set = {
17141         .f = cmd_clear_input_set_parsed,
17142         .data = NULL,
17143         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17144                     "fdir_inset|fdir_flx_inset clear all",
17145         .tokens = {
17146                 (void *)&cmd_clear_input_set_port,
17147                 (void *)&cmd_clear_input_set_cfg,
17148                 (void *)&cmd_clear_input_set_port_id,
17149                 (void *)&cmd_clear_input_set_pctype,
17150                 (void *)&cmd_clear_input_set_pctype_id,
17151                 (void *)&cmd_clear_input_set_inset_type,
17152                 (void *)&cmd_clear_input_set_clear,
17153                 (void *)&cmd_clear_input_set_all,
17154                 NULL,
17155         },
17156 };
17157
17158 /* show vf stats */
17159
17160 /* Common result structure for show vf stats */
17161 struct cmd_show_vf_stats_result {
17162         cmdline_fixed_string_t show;
17163         cmdline_fixed_string_t vf;
17164         cmdline_fixed_string_t stats;
17165         portid_t port_id;
17166         uint16_t vf_id;
17167 };
17168
17169 /* Common CLI fields show vf stats*/
17170 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17171         TOKEN_STRING_INITIALIZER
17172                 (struct cmd_show_vf_stats_result,
17173                  show, "show");
17174 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17175         TOKEN_STRING_INITIALIZER
17176                 (struct cmd_show_vf_stats_result,
17177                  vf, "vf");
17178 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17179         TOKEN_STRING_INITIALIZER
17180                 (struct cmd_show_vf_stats_result,
17181                  stats, "stats");
17182 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17183         TOKEN_NUM_INITIALIZER
17184                 (struct cmd_show_vf_stats_result,
17185                  port_id, UINT16);
17186 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17187         TOKEN_NUM_INITIALIZER
17188                 (struct cmd_show_vf_stats_result,
17189                  vf_id, UINT16);
17190
17191 static void
17192 cmd_show_vf_stats_parsed(
17193         void *parsed_result,
17194         __rte_unused struct cmdline *cl,
17195         __rte_unused void *data)
17196 {
17197         struct cmd_show_vf_stats_result *res = parsed_result;
17198         struct rte_eth_stats stats;
17199         int ret = -ENOTSUP;
17200         static const char *nic_stats_border = "########################";
17201
17202         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17203                 return;
17204
17205         memset(&stats, 0, sizeof(stats));
17206
17207 #ifdef RTE_LIBRTE_I40E_PMD
17208         if (ret == -ENOTSUP)
17209                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17210                                                 res->vf_id,
17211                                                 &stats);
17212 #endif
17213 #ifdef RTE_LIBRTE_BNXT_PMD
17214         if (ret == -ENOTSUP)
17215                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17216                                                 res->vf_id,
17217                                                 &stats);
17218 #endif
17219
17220         switch (ret) {
17221         case 0:
17222                 break;
17223         case -EINVAL:
17224                 printf("invalid vf_id %d\n", res->vf_id);
17225                 break;
17226         case -ENODEV:
17227                 printf("invalid port_id %d\n", res->port_id);
17228                 break;
17229         case -ENOTSUP:
17230                 printf("function not implemented\n");
17231                 break;
17232         default:
17233                 printf("programming error: (%s)\n", strerror(-ret));
17234         }
17235
17236         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17237                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17238
17239         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17240                "%-"PRIu64"\n",
17241                stats.ipackets, stats.imissed, stats.ibytes);
17242         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17243         printf("  RX-nombuf:  %-10"PRIu64"\n",
17244                stats.rx_nombuf);
17245         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17246                "%-"PRIu64"\n",
17247                stats.opackets, stats.oerrors, stats.obytes);
17248
17249         printf("  %s############################%s\n",
17250                                nic_stats_border, nic_stats_border);
17251 }
17252
17253 cmdline_parse_inst_t cmd_show_vf_stats = {
17254         .f = cmd_show_vf_stats_parsed,
17255         .data = NULL,
17256         .help_str = "show vf stats <port_id> <vf_id>",
17257         .tokens = {
17258                 (void *)&cmd_show_vf_stats_show,
17259                 (void *)&cmd_show_vf_stats_vf,
17260                 (void *)&cmd_show_vf_stats_stats,
17261                 (void *)&cmd_show_vf_stats_port_id,
17262                 (void *)&cmd_show_vf_stats_vf_id,
17263                 NULL,
17264         },
17265 };
17266
17267 /* clear vf stats */
17268
17269 /* Common result structure for clear vf stats */
17270 struct cmd_clear_vf_stats_result {
17271         cmdline_fixed_string_t clear;
17272         cmdline_fixed_string_t vf;
17273         cmdline_fixed_string_t stats;
17274         portid_t port_id;
17275         uint16_t vf_id;
17276 };
17277
17278 /* Common CLI fields clear vf stats*/
17279 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17280         TOKEN_STRING_INITIALIZER
17281                 (struct cmd_clear_vf_stats_result,
17282                  clear, "clear");
17283 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17284         TOKEN_STRING_INITIALIZER
17285                 (struct cmd_clear_vf_stats_result,
17286                  vf, "vf");
17287 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17288         TOKEN_STRING_INITIALIZER
17289                 (struct cmd_clear_vf_stats_result,
17290                  stats, "stats");
17291 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17292         TOKEN_NUM_INITIALIZER
17293                 (struct cmd_clear_vf_stats_result,
17294                  port_id, UINT16);
17295 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17296         TOKEN_NUM_INITIALIZER
17297                 (struct cmd_clear_vf_stats_result,
17298                  vf_id, UINT16);
17299
17300 static void
17301 cmd_clear_vf_stats_parsed(
17302         void *parsed_result,
17303         __rte_unused struct cmdline *cl,
17304         __rte_unused void *data)
17305 {
17306         struct cmd_clear_vf_stats_result *res = parsed_result;
17307         int ret = -ENOTSUP;
17308
17309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17310                 return;
17311
17312 #ifdef RTE_LIBRTE_I40E_PMD
17313         if (ret == -ENOTSUP)
17314                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17315                                                   res->vf_id);
17316 #endif
17317 #ifdef RTE_LIBRTE_BNXT_PMD
17318         if (ret == -ENOTSUP)
17319                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17320                                                   res->vf_id);
17321 #endif
17322
17323         switch (ret) {
17324         case 0:
17325                 break;
17326         case -EINVAL:
17327                 printf("invalid vf_id %d\n", res->vf_id);
17328                 break;
17329         case -ENODEV:
17330                 printf("invalid port_id %d\n", res->port_id);
17331                 break;
17332         case -ENOTSUP:
17333                 printf("function not implemented\n");
17334                 break;
17335         default:
17336                 printf("programming error: (%s)\n", strerror(-ret));
17337         }
17338 }
17339
17340 cmdline_parse_inst_t cmd_clear_vf_stats = {
17341         .f = cmd_clear_vf_stats_parsed,
17342         .data = NULL,
17343         .help_str = "clear vf stats <port_id> <vf_id>",
17344         .tokens = {
17345                 (void *)&cmd_clear_vf_stats_clear,
17346                 (void *)&cmd_clear_vf_stats_vf,
17347                 (void *)&cmd_clear_vf_stats_stats,
17348                 (void *)&cmd_clear_vf_stats_port_id,
17349                 (void *)&cmd_clear_vf_stats_vf_id,
17350                 NULL,
17351         },
17352 };
17353
17354 /* port config pctype mapping reset */
17355
17356 /* Common result structure for port config pctype mapping reset */
17357 struct cmd_pctype_mapping_reset_result {
17358         cmdline_fixed_string_t port;
17359         cmdline_fixed_string_t config;
17360         portid_t port_id;
17361         cmdline_fixed_string_t pctype;
17362         cmdline_fixed_string_t mapping;
17363         cmdline_fixed_string_t reset;
17364 };
17365
17366 /* Common CLI fields for port config pctype mapping reset*/
17367 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17368         TOKEN_STRING_INITIALIZER
17369                 (struct cmd_pctype_mapping_reset_result,
17370                  port, "port");
17371 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17372         TOKEN_STRING_INITIALIZER
17373                 (struct cmd_pctype_mapping_reset_result,
17374                  config, "config");
17375 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17376         TOKEN_NUM_INITIALIZER
17377                 (struct cmd_pctype_mapping_reset_result,
17378                  port_id, UINT16);
17379 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17380         TOKEN_STRING_INITIALIZER
17381                 (struct cmd_pctype_mapping_reset_result,
17382                  pctype, "pctype");
17383 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17384         TOKEN_STRING_INITIALIZER
17385                 (struct cmd_pctype_mapping_reset_result,
17386                  mapping, "mapping");
17387 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17388         TOKEN_STRING_INITIALIZER
17389                 (struct cmd_pctype_mapping_reset_result,
17390                  reset, "reset");
17391
17392 static void
17393 cmd_pctype_mapping_reset_parsed(
17394         void *parsed_result,
17395         __rte_unused struct cmdline *cl,
17396         __rte_unused void *data)
17397 {
17398         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17399         int ret = -ENOTSUP;
17400
17401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17402                 return;
17403
17404 #ifdef RTE_LIBRTE_I40E_PMD
17405         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17406 #endif
17407
17408         switch (ret) {
17409         case 0:
17410                 break;
17411         case -ENODEV:
17412                 printf("invalid port_id %d\n", res->port_id);
17413                 break;
17414         case -ENOTSUP:
17415                 printf("function not implemented\n");
17416                 break;
17417         default:
17418                 printf("programming error: (%s)\n", strerror(-ret));
17419         }
17420 }
17421
17422 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17423         .f = cmd_pctype_mapping_reset_parsed,
17424         .data = NULL,
17425         .help_str = "port config <port_id> pctype mapping reset",
17426         .tokens = {
17427                 (void *)&cmd_pctype_mapping_reset_port,
17428                 (void *)&cmd_pctype_mapping_reset_config,
17429                 (void *)&cmd_pctype_mapping_reset_port_id,
17430                 (void *)&cmd_pctype_mapping_reset_pctype,
17431                 (void *)&cmd_pctype_mapping_reset_mapping,
17432                 (void *)&cmd_pctype_mapping_reset_reset,
17433                 NULL,
17434         },
17435 };
17436
17437 /* show port pctype mapping */
17438
17439 /* Common result structure for show port pctype mapping */
17440 struct cmd_pctype_mapping_get_result {
17441         cmdline_fixed_string_t show;
17442         cmdline_fixed_string_t port;
17443         portid_t port_id;
17444         cmdline_fixed_string_t pctype;
17445         cmdline_fixed_string_t mapping;
17446 };
17447
17448 /* Common CLI fields for pctype mapping get */
17449 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17450         TOKEN_STRING_INITIALIZER
17451                 (struct cmd_pctype_mapping_get_result,
17452                  show, "show");
17453 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17454         TOKEN_STRING_INITIALIZER
17455                 (struct cmd_pctype_mapping_get_result,
17456                  port, "port");
17457 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17458         TOKEN_NUM_INITIALIZER
17459                 (struct cmd_pctype_mapping_get_result,
17460                  port_id, UINT16);
17461 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17462         TOKEN_STRING_INITIALIZER
17463                 (struct cmd_pctype_mapping_get_result,
17464                  pctype, "pctype");
17465 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17466         TOKEN_STRING_INITIALIZER
17467                 (struct cmd_pctype_mapping_get_result,
17468                  mapping, "mapping");
17469
17470 static void
17471 cmd_pctype_mapping_get_parsed(
17472         void *parsed_result,
17473         __rte_unused struct cmdline *cl,
17474         __rte_unused void *data)
17475 {
17476         struct cmd_pctype_mapping_get_result *res = parsed_result;
17477         int ret = -ENOTSUP;
17478 #ifdef RTE_LIBRTE_I40E_PMD
17479         struct rte_pmd_i40e_flow_type_mapping
17480                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17481         int i, j, first_pctype;
17482 #endif
17483
17484         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17485                 return;
17486
17487 #ifdef RTE_LIBRTE_I40E_PMD
17488         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17489 #endif
17490
17491         switch (ret) {
17492         case 0:
17493                 break;
17494         case -ENODEV:
17495                 printf("invalid port_id %d\n", res->port_id);
17496                 return;
17497         case -ENOTSUP:
17498                 printf("function not implemented\n");
17499                 return;
17500         default:
17501                 printf("programming error: (%s)\n", strerror(-ret));
17502                 return;
17503         }
17504
17505 #ifdef RTE_LIBRTE_I40E_PMD
17506         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17507                 if (mapping[i].pctype != 0ULL) {
17508                         first_pctype = 1;
17509
17510                         printf("pctype: ");
17511                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17512                                 if (mapping[i].pctype & (1ULL << j)) {
17513                                         printf(first_pctype ?
17514                                                "%02d" : ",%02d", j);
17515                                         first_pctype = 0;
17516                                 }
17517                         }
17518                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17519                 }
17520         }
17521 #endif
17522 }
17523
17524 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17525         .f = cmd_pctype_mapping_get_parsed,
17526         .data = NULL,
17527         .help_str = "show port <port_id> pctype mapping",
17528         .tokens = {
17529                 (void *)&cmd_pctype_mapping_get_show,
17530                 (void *)&cmd_pctype_mapping_get_port,
17531                 (void *)&cmd_pctype_mapping_get_port_id,
17532                 (void *)&cmd_pctype_mapping_get_pctype,
17533                 (void *)&cmd_pctype_mapping_get_mapping,
17534                 NULL,
17535         },
17536 };
17537
17538 /* port config pctype mapping update */
17539
17540 /* Common result structure for port config pctype mapping update */
17541 struct cmd_pctype_mapping_update_result {
17542         cmdline_fixed_string_t port;
17543         cmdline_fixed_string_t config;
17544         portid_t port_id;
17545         cmdline_fixed_string_t pctype;
17546         cmdline_fixed_string_t mapping;
17547         cmdline_fixed_string_t update;
17548         cmdline_fixed_string_t pctype_list;
17549         uint16_t flow_type;
17550 };
17551
17552 /* Common CLI fields for pctype mapping update*/
17553 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17554         TOKEN_STRING_INITIALIZER
17555                 (struct cmd_pctype_mapping_update_result,
17556                  port, "port");
17557 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17558         TOKEN_STRING_INITIALIZER
17559                 (struct cmd_pctype_mapping_update_result,
17560                  config, "config");
17561 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17562         TOKEN_NUM_INITIALIZER
17563                 (struct cmd_pctype_mapping_update_result,
17564                  port_id, UINT16);
17565 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17566         TOKEN_STRING_INITIALIZER
17567                 (struct cmd_pctype_mapping_update_result,
17568                  pctype, "pctype");
17569 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17570         TOKEN_STRING_INITIALIZER
17571                 (struct cmd_pctype_mapping_update_result,
17572                  mapping, "mapping");
17573 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17574         TOKEN_STRING_INITIALIZER
17575                 (struct cmd_pctype_mapping_update_result,
17576                  update, "update");
17577 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17578         TOKEN_STRING_INITIALIZER
17579                 (struct cmd_pctype_mapping_update_result,
17580                  pctype_list, NULL);
17581 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17582         TOKEN_NUM_INITIALIZER
17583                 (struct cmd_pctype_mapping_update_result,
17584                  flow_type, UINT16);
17585
17586 static void
17587 cmd_pctype_mapping_update_parsed(
17588         void *parsed_result,
17589         __rte_unused struct cmdline *cl,
17590         __rte_unused void *data)
17591 {
17592         struct cmd_pctype_mapping_update_result *res = parsed_result;
17593         int ret = -ENOTSUP;
17594 #ifdef RTE_LIBRTE_I40E_PMD
17595         struct rte_pmd_i40e_flow_type_mapping mapping;
17596         unsigned int i;
17597         unsigned int nb_item;
17598         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17599 #endif
17600
17601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17602                 return;
17603
17604 #ifdef RTE_LIBRTE_I40E_PMD
17605         nb_item = parse_item_list(res->pctype_list, "pctypes",
17606                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17607         mapping.flow_type = res->flow_type;
17608         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17609                 mapping.pctype |= (1ULL << pctype_list[i]);
17610         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17611                                                 &mapping,
17612                                                 1,
17613                                                 0);
17614 #endif
17615
17616         switch (ret) {
17617         case 0:
17618                 break;
17619         case -EINVAL:
17620                 printf("invalid pctype or flow type\n");
17621                 break;
17622         case -ENODEV:
17623                 printf("invalid port_id %d\n", res->port_id);
17624                 break;
17625         case -ENOTSUP:
17626                 printf("function not implemented\n");
17627                 break;
17628         default:
17629                 printf("programming error: (%s)\n", strerror(-ret));
17630         }
17631 }
17632
17633 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17634         .f = cmd_pctype_mapping_update_parsed,
17635         .data = NULL,
17636         .help_str = "port config <port_id> pctype mapping update"
17637         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17638         .tokens = {
17639                 (void *)&cmd_pctype_mapping_update_port,
17640                 (void *)&cmd_pctype_mapping_update_config,
17641                 (void *)&cmd_pctype_mapping_update_port_id,
17642                 (void *)&cmd_pctype_mapping_update_pctype,
17643                 (void *)&cmd_pctype_mapping_update_mapping,
17644                 (void *)&cmd_pctype_mapping_update_update,
17645                 (void *)&cmd_pctype_mapping_update_pc_type,
17646                 (void *)&cmd_pctype_mapping_update_flow_type,
17647                 NULL,
17648         },
17649 };
17650
17651 /* ptype mapping get */
17652
17653 /* Common result structure for ptype mapping get */
17654 struct cmd_ptype_mapping_get_result {
17655         cmdline_fixed_string_t ptype;
17656         cmdline_fixed_string_t mapping;
17657         cmdline_fixed_string_t get;
17658         portid_t port_id;
17659         uint8_t valid_only;
17660 };
17661
17662 /* Common CLI fields for ptype mapping get */
17663 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17664         TOKEN_STRING_INITIALIZER
17665                 (struct cmd_ptype_mapping_get_result,
17666                  ptype, "ptype");
17667 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17668         TOKEN_STRING_INITIALIZER
17669                 (struct cmd_ptype_mapping_get_result,
17670                  mapping, "mapping");
17671 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17672         TOKEN_STRING_INITIALIZER
17673                 (struct cmd_ptype_mapping_get_result,
17674                  get, "get");
17675 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17676         TOKEN_NUM_INITIALIZER
17677                 (struct cmd_ptype_mapping_get_result,
17678                  port_id, UINT16);
17679 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17680         TOKEN_NUM_INITIALIZER
17681                 (struct cmd_ptype_mapping_get_result,
17682                  valid_only, UINT8);
17683
17684 static void
17685 cmd_ptype_mapping_get_parsed(
17686         void *parsed_result,
17687         __rte_unused struct cmdline *cl,
17688         __rte_unused void *data)
17689 {
17690         struct cmd_ptype_mapping_get_result *res = parsed_result;
17691         int ret = -ENOTSUP;
17692 #ifdef RTE_LIBRTE_I40E_PMD
17693         int max_ptype_num = 256;
17694         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17695         uint16_t count;
17696         int i;
17697 #endif
17698
17699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17700                 return;
17701
17702 #ifdef RTE_LIBRTE_I40E_PMD
17703         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17704                                         mapping,
17705                                         max_ptype_num,
17706                                         &count,
17707                                         res->valid_only);
17708 #endif
17709
17710         switch (ret) {
17711         case 0:
17712                 break;
17713         case -ENODEV:
17714                 printf("invalid port_id %d\n", res->port_id);
17715                 break;
17716         case -ENOTSUP:
17717                 printf("function not implemented\n");
17718                 break;
17719         default:
17720                 printf("programming error: (%s)\n", strerror(-ret));
17721         }
17722
17723 #ifdef RTE_LIBRTE_I40E_PMD
17724         if (!ret) {
17725                 for (i = 0; i < count; i++)
17726                         printf("%3d\t0x%08x\n",
17727                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17728         }
17729 #endif
17730 }
17731
17732 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17733         .f = cmd_ptype_mapping_get_parsed,
17734         .data = NULL,
17735         .help_str = "ptype mapping get <port_id> <valid_only>",
17736         .tokens = {
17737                 (void *)&cmd_ptype_mapping_get_ptype,
17738                 (void *)&cmd_ptype_mapping_get_mapping,
17739                 (void *)&cmd_ptype_mapping_get_get,
17740                 (void *)&cmd_ptype_mapping_get_port_id,
17741                 (void *)&cmd_ptype_mapping_get_valid_only,
17742                 NULL,
17743         },
17744 };
17745
17746 /* ptype mapping replace */
17747
17748 /* Common result structure for ptype mapping replace */
17749 struct cmd_ptype_mapping_replace_result {
17750         cmdline_fixed_string_t ptype;
17751         cmdline_fixed_string_t mapping;
17752         cmdline_fixed_string_t replace;
17753         portid_t port_id;
17754         uint32_t target;
17755         uint8_t mask;
17756         uint32_t pkt_type;
17757 };
17758
17759 /* Common CLI fields for ptype mapping replace */
17760 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17761         TOKEN_STRING_INITIALIZER
17762                 (struct cmd_ptype_mapping_replace_result,
17763                  ptype, "ptype");
17764 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17765         TOKEN_STRING_INITIALIZER
17766                 (struct cmd_ptype_mapping_replace_result,
17767                  mapping, "mapping");
17768 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17769         TOKEN_STRING_INITIALIZER
17770                 (struct cmd_ptype_mapping_replace_result,
17771                  replace, "replace");
17772 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17773         TOKEN_NUM_INITIALIZER
17774                 (struct cmd_ptype_mapping_replace_result,
17775                  port_id, UINT16);
17776 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17777         TOKEN_NUM_INITIALIZER
17778                 (struct cmd_ptype_mapping_replace_result,
17779                  target, UINT32);
17780 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17781         TOKEN_NUM_INITIALIZER
17782                 (struct cmd_ptype_mapping_replace_result,
17783                  mask, UINT8);
17784 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17785         TOKEN_NUM_INITIALIZER
17786                 (struct cmd_ptype_mapping_replace_result,
17787                  pkt_type, UINT32);
17788
17789 static void
17790 cmd_ptype_mapping_replace_parsed(
17791         void *parsed_result,
17792         __rte_unused struct cmdline *cl,
17793         __rte_unused void *data)
17794 {
17795         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17796         int ret = -ENOTSUP;
17797
17798         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17799                 return;
17800
17801 #ifdef RTE_LIBRTE_I40E_PMD
17802         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17803                                         res->target,
17804                                         res->mask,
17805                                         res->pkt_type);
17806 #endif
17807
17808         switch (ret) {
17809         case 0:
17810                 break;
17811         case -EINVAL:
17812                 printf("invalid ptype 0x%8x or 0x%8x\n",
17813                                 res->target, res->pkt_type);
17814                 break;
17815         case -ENODEV:
17816                 printf("invalid port_id %d\n", res->port_id);
17817                 break;
17818         case -ENOTSUP:
17819                 printf("function not implemented\n");
17820                 break;
17821         default:
17822                 printf("programming error: (%s)\n", strerror(-ret));
17823         }
17824 }
17825
17826 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17827         .f = cmd_ptype_mapping_replace_parsed,
17828         .data = NULL,
17829         .help_str =
17830                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17831         .tokens = {
17832                 (void *)&cmd_ptype_mapping_replace_ptype,
17833                 (void *)&cmd_ptype_mapping_replace_mapping,
17834                 (void *)&cmd_ptype_mapping_replace_replace,
17835                 (void *)&cmd_ptype_mapping_replace_port_id,
17836                 (void *)&cmd_ptype_mapping_replace_target,
17837                 (void *)&cmd_ptype_mapping_replace_mask,
17838                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17839                 NULL,
17840         },
17841 };
17842
17843 /* ptype mapping reset */
17844
17845 /* Common result structure for ptype mapping reset */
17846 struct cmd_ptype_mapping_reset_result {
17847         cmdline_fixed_string_t ptype;
17848         cmdline_fixed_string_t mapping;
17849         cmdline_fixed_string_t reset;
17850         portid_t port_id;
17851 };
17852
17853 /* Common CLI fields for ptype mapping reset*/
17854 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17855         TOKEN_STRING_INITIALIZER
17856                 (struct cmd_ptype_mapping_reset_result,
17857                  ptype, "ptype");
17858 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17859         TOKEN_STRING_INITIALIZER
17860                 (struct cmd_ptype_mapping_reset_result,
17861                  mapping, "mapping");
17862 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17863         TOKEN_STRING_INITIALIZER
17864                 (struct cmd_ptype_mapping_reset_result,
17865                  reset, "reset");
17866 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17867         TOKEN_NUM_INITIALIZER
17868                 (struct cmd_ptype_mapping_reset_result,
17869                  port_id, UINT16);
17870
17871 static void
17872 cmd_ptype_mapping_reset_parsed(
17873         void *parsed_result,
17874         __rte_unused struct cmdline *cl,
17875         __rte_unused void *data)
17876 {
17877         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17878         int ret = -ENOTSUP;
17879
17880         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17881                 return;
17882
17883 #ifdef RTE_LIBRTE_I40E_PMD
17884         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17885 #endif
17886
17887         switch (ret) {
17888         case 0:
17889                 break;
17890         case -ENODEV:
17891                 printf("invalid port_id %d\n", res->port_id);
17892                 break;
17893         case -ENOTSUP:
17894                 printf("function not implemented\n");
17895                 break;
17896         default:
17897                 printf("programming error: (%s)\n", strerror(-ret));
17898         }
17899 }
17900
17901 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17902         .f = cmd_ptype_mapping_reset_parsed,
17903         .data = NULL,
17904         .help_str = "ptype mapping reset <port_id>",
17905         .tokens = {
17906                 (void *)&cmd_ptype_mapping_reset_ptype,
17907                 (void *)&cmd_ptype_mapping_reset_mapping,
17908                 (void *)&cmd_ptype_mapping_reset_reset,
17909                 (void *)&cmd_ptype_mapping_reset_port_id,
17910                 NULL,
17911         },
17912 };
17913
17914 /* ptype mapping update */
17915
17916 /* Common result structure for ptype mapping update */
17917 struct cmd_ptype_mapping_update_result {
17918         cmdline_fixed_string_t ptype;
17919         cmdline_fixed_string_t mapping;
17920         cmdline_fixed_string_t reset;
17921         portid_t port_id;
17922         uint8_t hw_ptype;
17923         uint32_t sw_ptype;
17924 };
17925
17926 /* Common CLI fields for ptype mapping update*/
17927 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17928         TOKEN_STRING_INITIALIZER
17929                 (struct cmd_ptype_mapping_update_result,
17930                  ptype, "ptype");
17931 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17932         TOKEN_STRING_INITIALIZER
17933                 (struct cmd_ptype_mapping_update_result,
17934                  mapping, "mapping");
17935 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17936         TOKEN_STRING_INITIALIZER
17937                 (struct cmd_ptype_mapping_update_result,
17938                  reset, "update");
17939 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17940         TOKEN_NUM_INITIALIZER
17941                 (struct cmd_ptype_mapping_update_result,
17942                  port_id, UINT16);
17943 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17944         TOKEN_NUM_INITIALIZER
17945                 (struct cmd_ptype_mapping_update_result,
17946                  hw_ptype, UINT8);
17947 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17948         TOKEN_NUM_INITIALIZER
17949                 (struct cmd_ptype_mapping_update_result,
17950                  sw_ptype, UINT32);
17951
17952 static void
17953 cmd_ptype_mapping_update_parsed(
17954         void *parsed_result,
17955         __rte_unused struct cmdline *cl,
17956         __rte_unused void *data)
17957 {
17958         struct cmd_ptype_mapping_update_result *res = parsed_result;
17959         int ret = -ENOTSUP;
17960 #ifdef RTE_LIBRTE_I40E_PMD
17961         struct rte_pmd_i40e_ptype_mapping mapping;
17962 #endif
17963         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17964                 return;
17965
17966 #ifdef RTE_LIBRTE_I40E_PMD
17967         mapping.hw_ptype = res->hw_ptype;
17968         mapping.sw_ptype = res->sw_ptype;
17969         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17970                                                 &mapping,
17971                                                 1,
17972                                                 0);
17973 #endif
17974
17975         switch (ret) {
17976         case 0:
17977                 break;
17978         case -EINVAL:
17979                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17980                 break;
17981         case -ENODEV:
17982                 printf("invalid port_id %d\n", res->port_id);
17983                 break;
17984         case -ENOTSUP:
17985                 printf("function not implemented\n");
17986                 break;
17987         default:
17988                 printf("programming error: (%s)\n", strerror(-ret));
17989         }
17990 }
17991
17992 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17993         .f = cmd_ptype_mapping_update_parsed,
17994         .data = NULL,
17995         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17996         .tokens = {
17997                 (void *)&cmd_ptype_mapping_update_ptype,
17998                 (void *)&cmd_ptype_mapping_update_mapping,
17999                 (void *)&cmd_ptype_mapping_update_update,
18000                 (void *)&cmd_ptype_mapping_update_port_id,
18001                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18002                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18003                 NULL,
18004         },
18005 };
18006
18007 /* Common result structure for file commands */
18008 struct cmd_cmdfile_result {
18009         cmdline_fixed_string_t load;
18010         cmdline_fixed_string_t filename;
18011 };
18012
18013 /* Common CLI fields for file commands */
18014 cmdline_parse_token_string_t cmd_load_cmdfile =
18015         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18016 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18017         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18018
18019 static void
18020 cmd_load_from_file_parsed(
18021         void *parsed_result,
18022         __rte_unused struct cmdline *cl,
18023         __rte_unused void *data)
18024 {
18025         struct cmd_cmdfile_result *res = parsed_result;
18026
18027         cmdline_read_from_file(res->filename);
18028 }
18029
18030 cmdline_parse_inst_t cmd_load_from_file = {
18031         .f = cmd_load_from_file_parsed,
18032         .data = NULL,
18033         .help_str = "load <filename>",
18034         .tokens = {
18035                 (void *)&cmd_load_cmdfile,
18036                 (void *)&cmd_load_cmdfile_filename,
18037                 NULL,
18038         },
18039 };
18040
18041 /* Get Rx offloads capabilities */
18042 struct cmd_rx_offload_get_capa_result {
18043         cmdline_fixed_string_t show;
18044         cmdline_fixed_string_t port;
18045         portid_t port_id;
18046         cmdline_fixed_string_t rx_offload;
18047         cmdline_fixed_string_t capabilities;
18048 };
18049
18050 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18051         TOKEN_STRING_INITIALIZER
18052                 (struct cmd_rx_offload_get_capa_result,
18053                  show, "show");
18054 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18055         TOKEN_STRING_INITIALIZER
18056                 (struct cmd_rx_offload_get_capa_result,
18057                  port, "port");
18058 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18059         TOKEN_NUM_INITIALIZER
18060                 (struct cmd_rx_offload_get_capa_result,
18061                  port_id, UINT16);
18062 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18063         TOKEN_STRING_INITIALIZER
18064                 (struct cmd_rx_offload_get_capa_result,
18065                  rx_offload, "rx_offload");
18066 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18067         TOKEN_STRING_INITIALIZER
18068                 (struct cmd_rx_offload_get_capa_result,
18069                  capabilities, "capabilities");
18070
18071 static void
18072 print_rx_offloads(uint64_t offloads)
18073 {
18074         uint64_t single_offload;
18075         int begin;
18076         int end;
18077         int bit;
18078
18079         if (offloads == 0)
18080                 return;
18081
18082         begin = __builtin_ctzll(offloads);
18083         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18084
18085         single_offload = 1ULL << begin;
18086         for (bit = begin; bit < end; bit++) {
18087                 if (offloads & single_offload)
18088                         printf(" %s",
18089                                rte_eth_dev_rx_offload_name(single_offload));
18090                 single_offload <<= 1;
18091         }
18092 }
18093
18094 static void
18095 cmd_rx_offload_get_capa_parsed(
18096         void *parsed_result,
18097         __rte_unused struct cmdline *cl,
18098         __rte_unused void *data)
18099 {
18100         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18101         struct rte_eth_dev_info dev_info;
18102         portid_t port_id = res->port_id;
18103         uint64_t queue_offloads;
18104         uint64_t port_offloads;
18105         int ret;
18106
18107         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18108         if (ret != 0)
18109                 return;
18110
18111         queue_offloads = dev_info.rx_queue_offload_capa;
18112         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18113
18114         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18115         printf("  Per Queue :");
18116         print_rx_offloads(queue_offloads);
18117
18118         printf("\n");
18119         printf("  Per Port  :");
18120         print_rx_offloads(port_offloads);
18121         printf("\n\n");
18122 }
18123
18124 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18125         .f = cmd_rx_offload_get_capa_parsed,
18126         .data = NULL,
18127         .help_str = "show port <port_id> rx_offload capabilities",
18128         .tokens = {
18129                 (void *)&cmd_rx_offload_get_capa_show,
18130                 (void *)&cmd_rx_offload_get_capa_port,
18131                 (void *)&cmd_rx_offload_get_capa_port_id,
18132                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18133                 (void *)&cmd_rx_offload_get_capa_capabilities,
18134                 NULL,
18135         }
18136 };
18137
18138 /* Get Rx offloads configuration */
18139 struct cmd_rx_offload_get_configuration_result {
18140         cmdline_fixed_string_t show;
18141         cmdline_fixed_string_t port;
18142         portid_t port_id;
18143         cmdline_fixed_string_t rx_offload;
18144         cmdline_fixed_string_t configuration;
18145 };
18146
18147 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18148         TOKEN_STRING_INITIALIZER
18149                 (struct cmd_rx_offload_get_configuration_result,
18150                  show, "show");
18151 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18152         TOKEN_STRING_INITIALIZER
18153                 (struct cmd_rx_offload_get_configuration_result,
18154                  port, "port");
18155 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18156         TOKEN_NUM_INITIALIZER
18157                 (struct cmd_rx_offload_get_configuration_result,
18158                  port_id, UINT16);
18159 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18160         TOKEN_STRING_INITIALIZER
18161                 (struct cmd_rx_offload_get_configuration_result,
18162                  rx_offload, "rx_offload");
18163 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18164         TOKEN_STRING_INITIALIZER
18165                 (struct cmd_rx_offload_get_configuration_result,
18166                  configuration, "configuration");
18167
18168 static void
18169 cmd_rx_offload_get_configuration_parsed(
18170         void *parsed_result,
18171         __rte_unused struct cmdline *cl,
18172         __rte_unused void *data)
18173 {
18174         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18175         struct rte_eth_dev_info dev_info;
18176         portid_t port_id = res->port_id;
18177         struct rte_port *port = &ports[port_id];
18178         uint64_t port_offloads;
18179         uint64_t queue_offloads;
18180         uint16_t nb_rx_queues;
18181         int q;
18182         int ret;
18183
18184         printf("Rx Offloading Configuration of port %d :\n", port_id);
18185
18186         port_offloads = port->dev_conf.rxmode.offloads;
18187         printf("  Port :");
18188         print_rx_offloads(port_offloads);
18189         printf("\n");
18190
18191         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18192         if (ret != 0)
18193                 return;
18194
18195         nb_rx_queues = dev_info.nb_rx_queues;
18196         for (q = 0; q < nb_rx_queues; q++) {
18197                 queue_offloads = port->rx_conf[q].offloads;
18198                 printf("  Queue[%2d] :", q);
18199                 print_rx_offloads(queue_offloads);
18200                 printf("\n");
18201         }
18202         printf("\n");
18203 }
18204
18205 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18206         .f = cmd_rx_offload_get_configuration_parsed,
18207         .data = NULL,
18208         .help_str = "show port <port_id> rx_offload configuration",
18209         .tokens = {
18210                 (void *)&cmd_rx_offload_get_configuration_show,
18211                 (void *)&cmd_rx_offload_get_configuration_port,
18212                 (void *)&cmd_rx_offload_get_configuration_port_id,
18213                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18214                 (void *)&cmd_rx_offload_get_configuration_configuration,
18215                 NULL,
18216         }
18217 };
18218
18219 /* Enable/Disable a per port offloading */
18220 struct cmd_config_per_port_rx_offload_result {
18221         cmdline_fixed_string_t port;
18222         cmdline_fixed_string_t config;
18223         portid_t port_id;
18224         cmdline_fixed_string_t rx_offload;
18225         cmdline_fixed_string_t offload;
18226         cmdline_fixed_string_t on_off;
18227 };
18228
18229 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18230         TOKEN_STRING_INITIALIZER
18231                 (struct cmd_config_per_port_rx_offload_result,
18232                  port, "port");
18233 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18234         TOKEN_STRING_INITIALIZER
18235                 (struct cmd_config_per_port_rx_offload_result,
18236                  config, "config");
18237 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18238         TOKEN_NUM_INITIALIZER
18239                 (struct cmd_config_per_port_rx_offload_result,
18240                  port_id, UINT16);
18241 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18242         TOKEN_STRING_INITIALIZER
18243                 (struct cmd_config_per_port_rx_offload_result,
18244                  rx_offload, "rx_offload");
18245 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18246         TOKEN_STRING_INITIALIZER
18247                 (struct cmd_config_per_port_rx_offload_result,
18248                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18249                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18250                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18251                            "scatter#timestamp#security#keep_crc#rss_hash");
18252 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18253         TOKEN_STRING_INITIALIZER
18254                 (struct cmd_config_per_port_rx_offload_result,
18255                  on_off, "on#off");
18256
18257 static uint64_t
18258 search_rx_offload(const char *name)
18259 {
18260         uint64_t single_offload;
18261         const char *single_name;
18262         int found = 0;
18263         unsigned int bit;
18264
18265         single_offload = 1;
18266         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18267                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18268                 if (!strcasecmp(single_name, name)) {
18269                         found = 1;
18270                         break;
18271                 }
18272                 single_offload <<= 1;
18273         }
18274
18275         if (found)
18276                 return single_offload;
18277
18278         return 0;
18279 }
18280
18281 static void
18282 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18283                                 __rte_unused struct cmdline *cl,
18284                                 __rte_unused void *data)
18285 {
18286         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18287         portid_t port_id = res->port_id;
18288         struct rte_eth_dev_info dev_info;
18289         struct rte_port *port = &ports[port_id];
18290         uint64_t single_offload;
18291         uint16_t nb_rx_queues;
18292         int q;
18293         int ret;
18294
18295         if (port->port_status != RTE_PORT_STOPPED) {
18296                 printf("Error: Can't config offload when Port %d "
18297                        "is not stopped\n", port_id);
18298                 return;
18299         }
18300
18301         single_offload = search_rx_offload(res->offload);
18302         if (single_offload == 0) {
18303                 printf("Unknown offload name: %s\n", res->offload);
18304                 return;
18305         }
18306
18307         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18308         if (ret != 0)
18309                 return;
18310
18311         nb_rx_queues = dev_info.nb_rx_queues;
18312         if (!strcmp(res->on_off, "on")) {
18313                 port->dev_conf.rxmode.offloads |= single_offload;
18314                 for (q = 0; q < nb_rx_queues; q++)
18315                         port->rx_conf[q].offloads |= single_offload;
18316         } else {
18317                 port->dev_conf.rxmode.offloads &= ~single_offload;
18318                 for (q = 0; q < nb_rx_queues; q++)
18319                         port->rx_conf[q].offloads &= ~single_offload;
18320         }
18321
18322         cmd_reconfig_device_queue(port_id, 1, 1);
18323 }
18324
18325 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18326         .f = cmd_config_per_port_rx_offload_parsed,
18327         .data = NULL,
18328         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18329                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18330                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18331                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18332                     "on|off",
18333         .tokens = {
18334                 (void *)&cmd_config_per_port_rx_offload_result_port,
18335                 (void *)&cmd_config_per_port_rx_offload_result_config,
18336                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18337                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18338                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18339                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18340                 NULL,
18341         }
18342 };
18343
18344 /* Enable/Disable a per queue offloading */
18345 struct cmd_config_per_queue_rx_offload_result {
18346         cmdline_fixed_string_t port;
18347         portid_t port_id;
18348         cmdline_fixed_string_t rxq;
18349         uint16_t queue_id;
18350         cmdline_fixed_string_t rx_offload;
18351         cmdline_fixed_string_t offload;
18352         cmdline_fixed_string_t on_off;
18353 };
18354
18355 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18356         TOKEN_STRING_INITIALIZER
18357                 (struct cmd_config_per_queue_rx_offload_result,
18358                  port, "port");
18359 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18360         TOKEN_NUM_INITIALIZER
18361                 (struct cmd_config_per_queue_rx_offload_result,
18362                  port_id, UINT16);
18363 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18364         TOKEN_STRING_INITIALIZER
18365                 (struct cmd_config_per_queue_rx_offload_result,
18366                  rxq, "rxq");
18367 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18368         TOKEN_NUM_INITIALIZER
18369                 (struct cmd_config_per_queue_rx_offload_result,
18370                  queue_id, UINT16);
18371 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18372         TOKEN_STRING_INITIALIZER
18373                 (struct cmd_config_per_queue_rx_offload_result,
18374                  rx_offload, "rx_offload");
18375 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18376         TOKEN_STRING_INITIALIZER
18377                 (struct cmd_config_per_queue_rx_offload_result,
18378                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18379                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18380                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18381                            "scatter#timestamp#security#keep_crc");
18382 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18383         TOKEN_STRING_INITIALIZER
18384                 (struct cmd_config_per_queue_rx_offload_result,
18385                  on_off, "on#off");
18386
18387 static void
18388 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18389                                 __rte_unused struct cmdline *cl,
18390                                 __rte_unused void *data)
18391 {
18392         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18393         struct rte_eth_dev_info dev_info;
18394         portid_t port_id = res->port_id;
18395         uint16_t queue_id = res->queue_id;
18396         struct rte_port *port = &ports[port_id];
18397         uint64_t single_offload;
18398         int ret;
18399
18400         if (port->port_status != RTE_PORT_STOPPED) {
18401                 printf("Error: Can't config offload when Port %d "
18402                        "is not stopped\n", port_id);
18403                 return;
18404         }
18405
18406         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18407         if (ret != 0)
18408                 return;
18409
18410         if (queue_id >= dev_info.nb_rx_queues) {
18411                 printf("Error: input queue_id should be 0 ... "
18412                        "%d\n", dev_info.nb_rx_queues - 1);
18413                 return;
18414         }
18415
18416         single_offload = search_rx_offload(res->offload);
18417         if (single_offload == 0) {
18418                 printf("Unknown offload name: %s\n", res->offload);
18419                 return;
18420         }
18421
18422         if (!strcmp(res->on_off, "on"))
18423                 port->rx_conf[queue_id].offloads |= single_offload;
18424         else
18425                 port->rx_conf[queue_id].offloads &= ~single_offload;
18426
18427         cmd_reconfig_device_queue(port_id, 1, 1);
18428 }
18429
18430 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18431         .f = cmd_config_per_queue_rx_offload_parsed,
18432         .data = NULL,
18433         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18434                     "vlan_strip|ipv4_cksum|"
18435                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18436                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18437                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18438                     "on|off",
18439         .tokens = {
18440                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18441                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18442                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18443                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18444                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18445                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18446                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18447                 NULL,
18448         }
18449 };
18450
18451 /* Get Tx offloads capabilities */
18452 struct cmd_tx_offload_get_capa_result {
18453         cmdline_fixed_string_t show;
18454         cmdline_fixed_string_t port;
18455         portid_t port_id;
18456         cmdline_fixed_string_t tx_offload;
18457         cmdline_fixed_string_t capabilities;
18458 };
18459
18460 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18461         TOKEN_STRING_INITIALIZER
18462                 (struct cmd_tx_offload_get_capa_result,
18463                  show, "show");
18464 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18465         TOKEN_STRING_INITIALIZER
18466                 (struct cmd_tx_offload_get_capa_result,
18467                  port, "port");
18468 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18469         TOKEN_NUM_INITIALIZER
18470                 (struct cmd_tx_offload_get_capa_result,
18471                  port_id, UINT16);
18472 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18473         TOKEN_STRING_INITIALIZER
18474                 (struct cmd_tx_offload_get_capa_result,
18475                  tx_offload, "tx_offload");
18476 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18477         TOKEN_STRING_INITIALIZER
18478                 (struct cmd_tx_offload_get_capa_result,
18479                  capabilities, "capabilities");
18480
18481 static void
18482 print_tx_offloads(uint64_t offloads)
18483 {
18484         uint64_t single_offload;
18485         int begin;
18486         int end;
18487         int bit;
18488
18489         if (offloads == 0)
18490                 return;
18491
18492         begin = __builtin_ctzll(offloads);
18493         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18494
18495         single_offload = 1ULL << begin;
18496         for (bit = begin; bit < end; bit++) {
18497                 if (offloads & single_offload)
18498                         printf(" %s",
18499                                rte_eth_dev_tx_offload_name(single_offload));
18500                 single_offload <<= 1;
18501         }
18502 }
18503
18504 static void
18505 cmd_tx_offload_get_capa_parsed(
18506         void *parsed_result,
18507         __rte_unused struct cmdline *cl,
18508         __rte_unused void *data)
18509 {
18510         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18511         struct rte_eth_dev_info dev_info;
18512         portid_t port_id = res->port_id;
18513         uint64_t queue_offloads;
18514         uint64_t port_offloads;
18515         int ret;
18516
18517         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18518         if (ret != 0)
18519                 return;
18520
18521         queue_offloads = dev_info.tx_queue_offload_capa;
18522         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18523
18524         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18525         printf("  Per Queue :");
18526         print_tx_offloads(queue_offloads);
18527
18528         printf("\n");
18529         printf("  Per Port  :");
18530         print_tx_offloads(port_offloads);
18531         printf("\n\n");
18532 }
18533
18534 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18535         .f = cmd_tx_offload_get_capa_parsed,
18536         .data = NULL,
18537         .help_str = "show port <port_id> tx_offload capabilities",
18538         .tokens = {
18539                 (void *)&cmd_tx_offload_get_capa_show,
18540                 (void *)&cmd_tx_offload_get_capa_port,
18541                 (void *)&cmd_tx_offload_get_capa_port_id,
18542                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18543                 (void *)&cmd_tx_offload_get_capa_capabilities,
18544                 NULL,
18545         }
18546 };
18547
18548 /* Get Tx offloads configuration */
18549 struct cmd_tx_offload_get_configuration_result {
18550         cmdline_fixed_string_t show;
18551         cmdline_fixed_string_t port;
18552         portid_t port_id;
18553         cmdline_fixed_string_t tx_offload;
18554         cmdline_fixed_string_t configuration;
18555 };
18556
18557 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18558         TOKEN_STRING_INITIALIZER
18559                 (struct cmd_tx_offload_get_configuration_result,
18560                  show, "show");
18561 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18562         TOKEN_STRING_INITIALIZER
18563                 (struct cmd_tx_offload_get_configuration_result,
18564                  port, "port");
18565 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18566         TOKEN_NUM_INITIALIZER
18567                 (struct cmd_tx_offload_get_configuration_result,
18568                  port_id, UINT16);
18569 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18570         TOKEN_STRING_INITIALIZER
18571                 (struct cmd_tx_offload_get_configuration_result,
18572                  tx_offload, "tx_offload");
18573 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18574         TOKEN_STRING_INITIALIZER
18575                 (struct cmd_tx_offload_get_configuration_result,
18576                  configuration, "configuration");
18577
18578 static void
18579 cmd_tx_offload_get_configuration_parsed(
18580         void *parsed_result,
18581         __rte_unused struct cmdline *cl,
18582         __rte_unused void *data)
18583 {
18584         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18585         struct rte_eth_dev_info dev_info;
18586         portid_t port_id = res->port_id;
18587         struct rte_port *port = &ports[port_id];
18588         uint64_t port_offloads;
18589         uint64_t queue_offloads;
18590         uint16_t nb_tx_queues;
18591         int q;
18592         int ret;
18593
18594         printf("Tx Offloading Configuration of port %d :\n", port_id);
18595
18596         port_offloads = port->dev_conf.txmode.offloads;
18597         printf("  Port :");
18598         print_tx_offloads(port_offloads);
18599         printf("\n");
18600
18601         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18602         if (ret != 0)
18603                 return;
18604
18605         nb_tx_queues = dev_info.nb_tx_queues;
18606         for (q = 0; q < nb_tx_queues; q++) {
18607                 queue_offloads = port->tx_conf[q].offloads;
18608                 printf("  Queue[%2d] :", q);
18609                 print_tx_offloads(queue_offloads);
18610                 printf("\n");
18611         }
18612         printf("\n");
18613 }
18614
18615 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18616         .f = cmd_tx_offload_get_configuration_parsed,
18617         .data = NULL,
18618         .help_str = "show port <port_id> tx_offload configuration",
18619         .tokens = {
18620                 (void *)&cmd_tx_offload_get_configuration_show,
18621                 (void *)&cmd_tx_offload_get_configuration_port,
18622                 (void *)&cmd_tx_offload_get_configuration_port_id,
18623                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18624                 (void *)&cmd_tx_offload_get_configuration_configuration,
18625                 NULL,
18626         }
18627 };
18628
18629 /* Enable/Disable a per port offloading */
18630 struct cmd_config_per_port_tx_offload_result {
18631         cmdline_fixed_string_t port;
18632         cmdline_fixed_string_t config;
18633         portid_t port_id;
18634         cmdline_fixed_string_t tx_offload;
18635         cmdline_fixed_string_t offload;
18636         cmdline_fixed_string_t on_off;
18637 };
18638
18639 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18640         TOKEN_STRING_INITIALIZER
18641                 (struct cmd_config_per_port_tx_offload_result,
18642                  port, "port");
18643 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18644         TOKEN_STRING_INITIALIZER
18645                 (struct cmd_config_per_port_tx_offload_result,
18646                  config, "config");
18647 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18648         TOKEN_NUM_INITIALIZER
18649                 (struct cmd_config_per_port_tx_offload_result,
18650                  port_id, UINT16);
18651 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18652         TOKEN_STRING_INITIALIZER
18653                 (struct cmd_config_per_port_tx_offload_result,
18654                  tx_offload, "tx_offload");
18655 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18656         TOKEN_STRING_INITIALIZER
18657                 (struct cmd_config_per_port_tx_offload_result,
18658                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18659                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18660                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18661                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18662                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18663 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18664         TOKEN_STRING_INITIALIZER
18665                 (struct cmd_config_per_port_tx_offload_result,
18666                  on_off, "on#off");
18667
18668 static uint64_t
18669 search_tx_offload(const char *name)
18670 {
18671         uint64_t single_offload;
18672         const char *single_name;
18673         int found = 0;
18674         unsigned int bit;
18675
18676         single_offload = 1;
18677         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18678                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18679                 if (single_name == NULL)
18680                         break;
18681                 if (!strcasecmp(single_name, name)) {
18682                         found = 1;
18683                         break;
18684                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18685                         break;
18686                 single_offload <<= 1;
18687         }
18688
18689         if (found)
18690                 return single_offload;
18691
18692         return 0;
18693 }
18694
18695 static void
18696 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18697                                 __rte_unused struct cmdline *cl,
18698                                 __rte_unused void *data)
18699 {
18700         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18701         portid_t port_id = res->port_id;
18702         struct rte_eth_dev_info dev_info;
18703         struct rte_port *port = &ports[port_id];
18704         uint64_t single_offload;
18705         uint16_t nb_tx_queues;
18706         int q;
18707         int ret;
18708
18709         if (port->port_status != RTE_PORT_STOPPED) {
18710                 printf("Error: Can't config offload when Port %d "
18711                        "is not stopped\n", port_id);
18712                 return;
18713         }
18714
18715         single_offload = search_tx_offload(res->offload);
18716         if (single_offload == 0) {
18717                 printf("Unknown offload name: %s\n", res->offload);
18718                 return;
18719         }
18720
18721         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18722         if (ret != 0)
18723                 return;
18724
18725         nb_tx_queues = dev_info.nb_tx_queues;
18726         if (!strcmp(res->on_off, "on")) {
18727                 port->dev_conf.txmode.offloads |= single_offload;
18728                 for (q = 0; q < nb_tx_queues; q++)
18729                         port->tx_conf[q].offloads |= single_offload;
18730         } else {
18731                 port->dev_conf.txmode.offloads &= ~single_offload;
18732                 for (q = 0; q < nb_tx_queues; q++)
18733                         port->tx_conf[q].offloads &= ~single_offload;
18734         }
18735
18736         cmd_reconfig_device_queue(port_id, 1, 1);
18737 }
18738
18739 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18740         .f = cmd_config_per_port_tx_offload_parsed,
18741         .data = NULL,
18742         .help_str = "port config <port_id> tx_offload "
18743                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18744                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18745                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18746                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18747                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18748         .tokens = {
18749                 (void *)&cmd_config_per_port_tx_offload_result_port,
18750                 (void *)&cmd_config_per_port_tx_offload_result_config,
18751                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18752                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18753                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18754                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18755                 NULL,
18756         }
18757 };
18758
18759 /* Enable/Disable a per queue offloading */
18760 struct cmd_config_per_queue_tx_offload_result {
18761         cmdline_fixed_string_t port;
18762         portid_t port_id;
18763         cmdline_fixed_string_t txq;
18764         uint16_t queue_id;
18765         cmdline_fixed_string_t tx_offload;
18766         cmdline_fixed_string_t offload;
18767         cmdline_fixed_string_t on_off;
18768 };
18769
18770 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18771         TOKEN_STRING_INITIALIZER
18772                 (struct cmd_config_per_queue_tx_offload_result,
18773                  port, "port");
18774 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18775         TOKEN_NUM_INITIALIZER
18776                 (struct cmd_config_per_queue_tx_offload_result,
18777                  port_id, UINT16);
18778 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18779         TOKEN_STRING_INITIALIZER
18780                 (struct cmd_config_per_queue_tx_offload_result,
18781                  txq, "txq");
18782 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18783         TOKEN_NUM_INITIALIZER
18784                 (struct cmd_config_per_queue_tx_offload_result,
18785                  queue_id, UINT16);
18786 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18787         TOKEN_STRING_INITIALIZER
18788                 (struct cmd_config_per_queue_tx_offload_result,
18789                  tx_offload, "tx_offload");
18790 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18791         TOKEN_STRING_INITIALIZER
18792                 (struct cmd_config_per_queue_tx_offload_result,
18793                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18794                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18795                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18796                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18797                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18798 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18799         TOKEN_STRING_INITIALIZER
18800                 (struct cmd_config_per_queue_tx_offload_result,
18801                  on_off, "on#off");
18802
18803 static void
18804 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18805                                 __rte_unused struct cmdline *cl,
18806                                 __rte_unused void *data)
18807 {
18808         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18809         struct rte_eth_dev_info dev_info;
18810         portid_t port_id = res->port_id;
18811         uint16_t queue_id = res->queue_id;
18812         struct rte_port *port = &ports[port_id];
18813         uint64_t single_offload;
18814         int ret;
18815
18816         if (port->port_status != RTE_PORT_STOPPED) {
18817                 printf("Error: Can't config offload when Port %d "
18818                        "is not stopped\n", port_id);
18819                 return;
18820         }
18821
18822         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18823         if (ret != 0)
18824                 return;
18825
18826         if (queue_id >= dev_info.nb_tx_queues) {
18827                 printf("Error: input queue_id should be 0 ... "
18828                        "%d\n", dev_info.nb_tx_queues - 1);
18829                 return;
18830         }
18831
18832         single_offload = search_tx_offload(res->offload);
18833         if (single_offload == 0) {
18834                 printf("Unknown offload name: %s\n", res->offload);
18835                 return;
18836         }
18837
18838         if (!strcmp(res->on_off, "on"))
18839                 port->tx_conf[queue_id].offloads |= single_offload;
18840         else
18841                 port->tx_conf[queue_id].offloads &= ~single_offload;
18842
18843         cmd_reconfig_device_queue(port_id, 1, 1);
18844 }
18845
18846 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18847         .f = cmd_config_per_queue_tx_offload_parsed,
18848         .data = NULL,
18849         .help_str = "port <port_id> txq <queue_id> tx_offload "
18850                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18851                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18852                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18853                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18854                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18855                     "on|off",
18856         .tokens = {
18857                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18858                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18859                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18860                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18861                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18862                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18863                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18864                 NULL,
18865         }
18866 };
18867
18868 /* *** configure tx_metadata for specific port *** */
18869 struct cmd_config_tx_metadata_specific_result {
18870         cmdline_fixed_string_t port;
18871         cmdline_fixed_string_t keyword;
18872         uint16_t port_id;
18873         cmdline_fixed_string_t item;
18874         uint32_t value;
18875 };
18876
18877 static void
18878 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18879                                 __rte_unused struct cmdline *cl,
18880                                 __rte_unused void *data)
18881 {
18882         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18883
18884         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18885                 return;
18886         ports[res->port_id].tx_metadata = res->value;
18887         /* Add/remove callback to insert valid metadata in every Tx packet. */
18888         if (ports[res->port_id].tx_metadata)
18889                 add_tx_md_callback(res->port_id);
18890         else
18891                 remove_tx_md_callback(res->port_id);
18892         rte_flow_dynf_metadata_register();
18893 }
18894
18895 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18896         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18897                         port, "port");
18898 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18899         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18900                         keyword, "config");
18901 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18902         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18903                         port_id, UINT16);
18904 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18905         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18906                         item, "tx_metadata");
18907 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18908         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18909                         value, UINT32);
18910
18911 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18912         .f = cmd_config_tx_metadata_specific_parsed,
18913         .data = NULL,
18914         .help_str = "port config <port_id> tx_metadata <value>",
18915         .tokens = {
18916                 (void *)&cmd_config_tx_metadata_specific_port,
18917                 (void *)&cmd_config_tx_metadata_specific_keyword,
18918                 (void *)&cmd_config_tx_metadata_specific_id,
18919                 (void *)&cmd_config_tx_metadata_specific_item,
18920                 (void *)&cmd_config_tx_metadata_specific_value,
18921                 NULL,
18922         },
18923 };
18924
18925 /* *** set dynf *** */
18926 struct cmd_config_tx_dynf_specific_result {
18927         cmdline_fixed_string_t port;
18928         cmdline_fixed_string_t keyword;
18929         uint16_t port_id;
18930         cmdline_fixed_string_t item;
18931         cmdline_fixed_string_t name;
18932         cmdline_fixed_string_t value;
18933 };
18934
18935 static void
18936 cmd_config_dynf_specific_parsed(void *parsed_result,
18937                                 __rte_unused struct cmdline *cl,
18938                                 __rte_unused void *data)
18939 {
18940         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18941         struct rte_mbuf_dynflag desc_flag;
18942         int flag;
18943         uint64_t old_port_flags;
18944
18945         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18946                 return;
18947         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18948         if (flag <= 0) {
18949                 if (strlcpy(desc_flag.name, res->name,
18950                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18951                         printf("Flag name too long\n");
18952                         return;
18953                 }
18954                 desc_flag.flags = 0;
18955                 flag = rte_mbuf_dynflag_register(&desc_flag);
18956                 if (flag < 0) {
18957                         printf("Can't register flag\n");
18958                         return;
18959                 }
18960                 strcpy(dynf_names[flag], desc_flag.name);
18961         }
18962         old_port_flags = ports[res->port_id].mbuf_dynf;
18963         if (!strcmp(res->value, "set")) {
18964                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18965                 if (old_port_flags == 0)
18966                         add_tx_dynf_callback(res->port_id);
18967         } else {
18968                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18969                 if (ports[res->port_id].mbuf_dynf == 0)
18970                         remove_tx_dynf_callback(res->port_id);
18971         }
18972 }
18973
18974 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18975         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18976                         keyword, "port");
18977 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18978         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18979                         keyword, "config");
18980 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18981         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18982                         port_id, UINT16);
18983 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18984         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18985                         item, "dynf");
18986 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18987         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18988                         name, NULL);
18989 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18990         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18991                         value, "set#clear");
18992
18993 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18994         .f = cmd_config_dynf_specific_parsed,
18995         .data = NULL,
18996         .help_str = "port config <port id> dynf <name> set|clear",
18997         .tokens = {
18998                 (void *)&cmd_config_tx_dynf_specific_port,
18999                 (void *)&cmd_config_tx_dynf_specific_keyword,
19000                 (void *)&cmd_config_tx_dynf_specific_port_id,
19001                 (void *)&cmd_config_tx_dynf_specific_item,
19002                 (void *)&cmd_config_tx_dynf_specific_name,
19003                 (void *)&cmd_config_tx_dynf_specific_value,
19004                 NULL,
19005         },
19006 };
19007
19008 /* *** display tx_metadata per port configuration *** */
19009 struct cmd_show_tx_metadata_result {
19010         cmdline_fixed_string_t cmd_show;
19011         cmdline_fixed_string_t cmd_port;
19012         cmdline_fixed_string_t cmd_keyword;
19013         portid_t cmd_pid;
19014 };
19015
19016 static void
19017 cmd_show_tx_metadata_parsed(void *parsed_result,
19018                 __rte_unused struct cmdline *cl,
19019                 __rte_unused void *data)
19020 {
19021         struct cmd_show_tx_metadata_result *res = parsed_result;
19022
19023         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19024                 printf("invalid port id %u\n", res->cmd_pid);
19025                 return;
19026         }
19027         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19028                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19029                        ports[res->cmd_pid].tx_metadata);
19030         }
19031 }
19032
19033 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19034         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19035                         cmd_show, "show");
19036 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19037         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19038                         cmd_port, "port");
19039 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19040         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19041                         cmd_pid, UINT16);
19042 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19043         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19044                         cmd_keyword, "tx_metadata");
19045
19046 cmdline_parse_inst_t cmd_show_tx_metadata = {
19047         .f = cmd_show_tx_metadata_parsed,
19048         .data = NULL,
19049         .help_str = "show port <port_id> tx_metadata",
19050         .tokens = {
19051                 (void *)&cmd_show_tx_metadata_show,
19052                 (void *)&cmd_show_tx_metadata_port,
19053                 (void *)&cmd_show_tx_metadata_pid,
19054                 (void *)&cmd_show_tx_metadata_keyword,
19055                 NULL,
19056         },
19057 };
19058
19059 /* show port supported ptypes */
19060
19061 /* Common result structure for show port ptypes */
19062 struct cmd_show_port_supported_ptypes_result {
19063         cmdline_fixed_string_t show;
19064         cmdline_fixed_string_t port;
19065         portid_t port_id;
19066         cmdline_fixed_string_t ptypes;
19067 };
19068
19069 /* Common CLI fields for show port ptypes */
19070 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19071         TOKEN_STRING_INITIALIZER
19072                 (struct cmd_show_port_supported_ptypes_result,
19073                  show, "show");
19074 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19075         TOKEN_STRING_INITIALIZER
19076                 (struct cmd_show_port_supported_ptypes_result,
19077                  port, "port");
19078 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19079         TOKEN_NUM_INITIALIZER
19080                 (struct cmd_show_port_supported_ptypes_result,
19081                  port_id, UINT16);
19082 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19083         TOKEN_STRING_INITIALIZER
19084                 (struct cmd_show_port_supported_ptypes_result,
19085                  ptypes, "ptypes");
19086
19087 static void
19088 cmd_show_port_supported_ptypes_parsed(
19089         void *parsed_result,
19090         __rte_unused struct cmdline *cl,
19091         __rte_unused void *data)
19092 {
19093 #define RSVD_PTYPE_MASK       0xf0000000
19094 #define MAX_PTYPES_PER_LAYER  16
19095 #define LTYPE_NAMESIZE        32
19096 #define PTYPE_NAMESIZE        256
19097         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19098         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19099         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19100         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19101         uint16_t port_id = res->port_id;
19102         int ret, i;
19103
19104         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19105         if (ret < 0)
19106                 return;
19107
19108         while (ptype_mask != RSVD_PTYPE_MASK) {
19109
19110                 switch (ptype_mask) {
19111                 case RTE_PTYPE_L2_MASK:
19112                         strlcpy(ltype, "L2", sizeof(ltype));
19113                         break;
19114                 case RTE_PTYPE_L3_MASK:
19115                         strlcpy(ltype, "L3", sizeof(ltype));
19116                         break;
19117                 case RTE_PTYPE_L4_MASK:
19118                         strlcpy(ltype, "L4", sizeof(ltype));
19119                         break;
19120                 case RTE_PTYPE_TUNNEL_MASK:
19121                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19122                         break;
19123                 case RTE_PTYPE_INNER_L2_MASK:
19124                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19125                         break;
19126                 case RTE_PTYPE_INNER_L3_MASK:
19127                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19128                         break;
19129                 case RTE_PTYPE_INNER_L4_MASK:
19130                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19131                         break;
19132                 default:
19133                         return;
19134                 }
19135
19136                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19137                                                        ptype_mask, ptypes,
19138                                                        MAX_PTYPES_PER_LAYER);
19139
19140                 if (ret > 0)
19141                         printf("Supported %s ptypes:\n", ltype);
19142                 else
19143                         printf("%s ptypes unsupported\n", ltype);
19144
19145                 for (i = 0; i < ret; ++i) {
19146                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19147                         printf("%s\n", buf);
19148                 }
19149
19150                 ptype_mask <<= 4;
19151         }
19152 }
19153
19154 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19155         .f = cmd_show_port_supported_ptypes_parsed,
19156         .data = NULL,
19157         .help_str = "show port <port_id> ptypes",
19158         .tokens = {
19159                 (void *)&cmd_show_port_supported_ptypes_show,
19160                 (void *)&cmd_show_port_supported_ptypes_port,
19161                 (void *)&cmd_show_port_supported_ptypes_port_id,
19162                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19163                 NULL,
19164         },
19165 };
19166
19167 /* *** display rx/tx descriptor status *** */
19168 struct cmd_show_rx_tx_desc_status_result {
19169         cmdline_fixed_string_t cmd_show;
19170         cmdline_fixed_string_t cmd_port;
19171         cmdline_fixed_string_t cmd_keyword;
19172         cmdline_fixed_string_t cmd_desc;
19173         cmdline_fixed_string_t cmd_status;
19174         portid_t cmd_pid;
19175         portid_t cmd_qid;
19176         portid_t cmd_did;
19177 };
19178
19179 static void
19180 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19181                 __rte_unused struct cmdline *cl,
19182                 __rte_unused void *data)
19183 {
19184         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19185         int rc;
19186
19187         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19188                 printf("invalid port id %u\n", res->cmd_pid);
19189                 return;
19190         }
19191
19192         if (!strcmp(res->cmd_keyword, "rxq")) {
19193                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19194                                              res->cmd_did);
19195                 if (rc < 0) {
19196                         printf("Invalid queueid = %d\n", res->cmd_qid);
19197                         return;
19198                 }
19199                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19200                         printf("Desc status = AVAILABLE\n");
19201                 else if (rc == RTE_ETH_RX_DESC_DONE)
19202                         printf("Desc status = DONE\n");
19203                 else
19204                         printf("Desc status = UNAVAILABLE\n");
19205         } else if (!strcmp(res->cmd_keyword, "txq")) {
19206                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19207                                              res->cmd_did);
19208                 if (rc < 0) {
19209                         printf("Invalid queueid = %d\n", res->cmd_qid);
19210                         return;
19211                 }
19212                 if (rc == RTE_ETH_TX_DESC_FULL)
19213                         printf("Desc status = FULL\n");
19214                 else if (rc == RTE_ETH_TX_DESC_DONE)
19215                         printf("Desc status = DONE\n");
19216                 else
19217                         printf("Desc status = UNAVAILABLE\n");
19218         }
19219 }
19220
19221 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19222         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19223                         cmd_show, "show");
19224 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19225         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19226                         cmd_port, "port");
19227 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19228         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19229                         cmd_pid, UINT16);
19230 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19231         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19232                         cmd_keyword, "rxq#txq");
19233 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19234         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19235                         cmd_qid, UINT16);
19236 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19237         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19238                         cmd_desc, "desc");
19239 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19240         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19241                         cmd_did, UINT16);
19242 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19243         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19244                         cmd_status, "status");
19245 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19246         .f = cmd_show_rx_tx_desc_status_parsed,
19247         .data = NULL,
19248         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19249                 "status",
19250         .tokens = {
19251                 (void *)&cmd_show_rx_tx_desc_status_show,
19252                 (void *)&cmd_show_rx_tx_desc_status_port,
19253                 (void *)&cmd_show_rx_tx_desc_status_pid,
19254                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19255                 (void *)&cmd_show_rx_tx_desc_status_qid,
19256                 (void *)&cmd_show_rx_tx_desc_status_desc,
19257                 (void *)&cmd_show_rx_tx_desc_status_did,
19258                 (void *)&cmd_show_rx_tx_desc_status_status,
19259                 NULL,
19260         },
19261 };
19262
19263 /* Common result structure for set port ptypes */
19264 struct cmd_set_port_ptypes_result {
19265         cmdline_fixed_string_t set;
19266         cmdline_fixed_string_t port;
19267         portid_t port_id;
19268         cmdline_fixed_string_t ptype_mask;
19269         uint32_t mask;
19270 };
19271
19272 /* Common CLI fields for set port ptypes */
19273 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19274         TOKEN_STRING_INITIALIZER
19275                 (struct cmd_set_port_ptypes_result,
19276                  set, "set");
19277 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19278         TOKEN_STRING_INITIALIZER
19279                 (struct cmd_set_port_ptypes_result,
19280                  port, "port");
19281 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19282         TOKEN_NUM_INITIALIZER
19283                 (struct cmd_set_port_ptypes_result,
19284                  port_id, UINT16);
19285 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19286         TOKEN_STRING_INITIALIZER
19287                 (struct cmd_set_port_ptypes_result,
19288                  ptype_mask, "ptype_mask");
19289 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19290         TOKEN_NUM_INITIALIZER
19291                 (struct cmd_set_port_ptypes_result,
19292                  mask, UINT32);
19293
19294 static void
19295 cmd_set_port_ptypes_parsed(
19296         void *parsed_result,
19297         __rte_unused struct cmdline *cl,
19298         __rte_unused void *data)
19299 {
19300         struct cmd_set_port_ptypes_result *res = parsed_result;
19301 #define PTYPE_NAMESIZE        256
19302         char ptype_name[PTYPE_NAMESIZE];
19303         uint16_t port_id = res->port_id;
19304         uint32_t ptype_mask = res->mask;
19305         int ret, i;
19306
19307         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19308                                                NULL, 0);
19309         if (ret <= 0) {
19310                 printf("Port %d doesn't support any ptypes.\n", port_id);
19311                 return;
19312         }
19313
19314         uint32_t ptypes[ret];
19315
19316         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19317         if (ret < 0) {
19318                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19319                 return;
19320         }
19321
19322         printf("Successfully set following ptypes for Port %d\n", port_id);
19323         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19324                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19325                 printf("%s\n", ptype_name);
19326         }
19327
19328         clear_ptypes = false;
19329 }
19330
19331 cmdline_parse_inst_t cmd_set_port_ptypes = {
19332         .f = cmd_set_port_ptypes_parsed,
19333         .data = NULL,
19334         .help_str = "set port <port_id> ptype_mask <mask>",
19335         .tokens = {
19336                 (void *)&cmd_set_port_ptypes_set,
19337                 (void *)&cmd_set_port_ptypes_port,
19338                 (void *)&cmd_set_port_ptypes_port_id,
19339                 (void *)&cmd_set_port_ptypes_mask_str,
19340                 (void *)&cmd_set_port_ptypes_mask_u32,
19341                 NULL,
19342         },
19343 };
19344
19345 /* *** display mac addresses added to a port *** */
19346 struct cmd_showport_macs_result {
19347         cmdline_fixed_string_t cmd_show;
19348         cmdline_fixed_string_t cmd_port;
19349         cmdline_fixed_string_t cmd_keyword;
19350         portid_t cmd_pid;
19351 };
19352
19353 static void
19354 cmd_showport_macs_parsed(void *parsed_result,
19355                 __rte_unused struct cmdline *cl,
19356                 __rte_unused void *data)
19357 {
19358         struct cmd_showport_macs_result *res = parsed_result;
19359
19360         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19361                 return;
19362
19363         if (!strcmp(res->cmd_keyword, "macs"))
19364                 show_macs(res->cmd_pid);
19365         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19366                 show_mcast_macs(res->cmd_pid);
19367 }
19368
19369 cmdline_parse_token_string_t cmd_showport_macs_show =
19370         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19371                         cmd_show, "show");
19372 cmdline_parse_token_string_t cmd_showport_macs_port =
19373         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19374                         cmd_port, "port");
19375 cmdline_parse_token_num_t cmd_showport_macs_pid =
19376         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19377                         cmd_pid, UINT16);
19378 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19379         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19380                         cmd_keyword, "macs#mcast_macs");
19381
19382 cmdline_parse_inst_t cmd_showport_macs = {
19383         .f = cmd_showport_macs_parsed,
19384         .data = NULL,
19385         .help_str = "show port <port_id> macs|mcast_macs",
19386         .tokens = {
19387                 (void *)&cmd_showport_macs_show,
19388                 (void *)&cmd_showport_macs_port,
19389                 (void *)&cmd_showport_macs_pid,
19390                 (void *)&cmd_showport_macs_keyword,
19391                 NULL,
19392         },
19393 };
19394
19395 /* ******************************************************************************** */
19396
19397 /* list of instructions */
19398 cmdline_parse_ctx_t main_ctx[] = {
19399         (cmdline_parse_inst_t *)&cmd_help_brief,
19400         (cmdline_parse_inst_t *)&cmd_help_long,
19401         (cmdline_parse_inst_t *)&cmd_quit,
19402         (cmdline_parse_inst_t *)&cmd_load_from_file,
19403         (cmdline_parse_inst_t *)&cmd_showport,
19404         (cmdline_parse_inst_t *)&cmd_showqueue,
19405         (cmdline_parse_inst_t *)&cmd_showportall,
19406         (cmdline_parse_inst_t *)&cmd_showdevice,
19407         (cmdline_parse_inst_t *)&cmd_showcfg,
19408         (cmdline_parse_inst_t *)&cmd_showfwdall,
19409         (cmdline_parse_inst_t *)&cmd_start,
19410         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19411         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19412         (cmdline_parse_inst_t *)&cmd_set_link_up,
19413         (cmdline_parse_inst_t *)&cmd_set_link_down,
19414         (cmdline_parse_inst_t *)&cmd_reset,
19415         (cmdline_parse_inst_t *)&cmd_set_numbers,
19416         (cmdline_parse_inst_t *)&cmd_set_log,
19417         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19418         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19419         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19420         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19421         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19422         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19423         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19424         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19425         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19426         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19427         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19428         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19429         (cmdline_parse_inst_t *)&cmd_set_link_check,
19430         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19431         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19432         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19433         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19434 #ifdef RTE_LIBRTE_PMD_BOND
19435         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19436         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19437         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19438         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19439         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19440         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19441         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19442         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19443         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19444         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19445         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19446 #endif
19447         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19448         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19449         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19450         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19451         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19452         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19453         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19454         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19455         (cmdline_parse_inst_t *)&cmd_csum_set,
19456         (cmdline_parse_inst_t *)&cmd_csum_show,
19457         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19458         (cmdline_parse_inst_t *)&cmd_tso_set,
19459         (cmdline_parse_inst_t *)&cmd_tso_show,
19460         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19461         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19462         (cmdline_parse_inst_t *)&cmd_gro_enable,
19463         (cmdline_parse_inst_t *)&cmd_gro_flush,
19464         (cmdline_parse_inst_t *)&cmd_gro_show,
19465         (cmdline_parse_inst_t *)&cmd_gso_enable,
19466         (cmdline_parse_inst_t *)&cmd_gso_size,
19467         (cmdline_parse_inst_t *)&cmd_gso_show,
19468         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19469         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19470         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19471         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19472         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19473         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19474         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19475         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19476         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19477         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19478         (cmdline_parse_inst_t *)&cmd_config_dcb,
19479         (cmdline_parse_inst_t *)&cmd_read_reg,
19480         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19481         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19482         (cmdline_parse_inst_t *)&cmd_write_reg,
19483         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19484         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19485         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19486         (cmdline_parse_inst_t *)&cmd_stop,
19487         (cmdline_parse_inst_t *)&cmd_mac_addr,
19488         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19489         (cmdline_parse_inst_t *)&cmd_set_qmap,
19490         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19491         (cmdline_parse_inst_t *)&cmd_operate_port,
19492         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19493         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19494         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19495         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19496         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19497         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19498         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19499         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19500         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19501         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19502         (cmdline_parse_inst_t *)&cmd_config_mtu,
19503         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19504         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19505         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19506         (cmdline_parse_inst_t *)&cmd_config_rss,
19507         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19508         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19509         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19510         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19511         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19512         (cmdline_parse_inst_t *)&cmd_showport_reta,
19513         (cmdline_parse_inst_t *)&cmd_showport_macs,
19514         (cmdline_parse_inst_t *)&cmd_config_burst,
19515         (cmdline_parse_inst_t *)&cmd_config_thresh,
19516         (cmdline_parse_inst_t *)&cmd_config_threshold,
19517         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19518         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19519         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19520         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19521         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19522         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19523         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19524         (cmdline_parse_inst_t *)&cmd_global_config,
19525         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19526         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19527         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19528         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19529         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19530         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19531         (cmdline_parse_inst_t *)&cmd_dump,
19532         (cmdline_parse_inst_t *)&cmd_dump_one,
19533         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19534         (cmdline_parse_inst_t *)&cmd_syn_filter,
19535         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19536         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19537         (cmdline_parse_inst_t *)&cmd_flex_filter,
19538         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19539         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19540         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19541         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19542         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19543         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19544         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19545         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19546         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19547         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19548         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19549         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19550         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19551         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19552         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19553         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19554         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19555         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19556         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19557         (cmdline_parse_inst_t *)&cmd_flow,
19558         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19559         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19560         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19561         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19562         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19563         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19564         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19565         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19566         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19567         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19568         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19569         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19570         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19571         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19572         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19573         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19574         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19575         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19576         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19577         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19578         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19579         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19580         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19581         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19582         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19583         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19584         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19585         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19586         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19587         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19588         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19589         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19590         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19591         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19592         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19593         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19594         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19595         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19596         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19597         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19598         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19599         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19600         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19601         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19602         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19603         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19604         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19605         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19606         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19607 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19608         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19609 #endif
19610         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19611         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19612         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19613         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19614         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19615         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19616         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19617         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19618         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19619         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19620         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19621         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19622         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19623         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19624         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19625         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19626         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19627         (cmdline_parse_inst_t *)&cmd_ddp_add,
19628         (cmdline_parse_inst_t *)&cmd_ddp_del,
19629         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19630         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19631         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19632         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19633         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19634         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19635         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19636         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19637         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19638         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19639         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19640         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19641
19642         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19643         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19644         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19645         (cmdline_parse_inst_t *)&cmd_queue_region,
19646         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19647         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19648         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19649         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19650         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19651         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19652         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19653         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19654         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19655         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19656         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19657         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19658         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19659         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19660         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19661         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19662         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19663         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19664         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19665         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19666         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19667         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19668         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19669         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19670         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19671         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19672         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19673         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19674         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19675         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19676         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19677         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19678         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19679         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19680         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19681 #ifdef RTE_LIBRTE_BPF
19682         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19683         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19684 #endif
19685         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19686         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19687         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19688         (cmdline_parse_inst_t *)&cmd_set_raw,
19689         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19690         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19691         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19692         NULL,
19693 };
19694
19695 /* read cmdline commands from file */
19696 void
19697 cmdline_read_from_file(const char *filename)
19698 {
19699         struct cmdline *cl;
19700
19701         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19702         if (cl == NULL) {
19703                 printf("Failed to create file based cmdline context: %s\n",
19704                        filename);
19705                 return;
19706         }
19707
19708         cmdline_interact(cl);
19709         cmdline_quit(cl);
19710
19711         cmdline_free(cl);
19712
19713         printf("Read CLI commands from %s\n", filename);
19714 }
19715
19716 /* prompt function, called from main on MASTER lcore */
19717 void
19718 prompt(void)
19719 {
19720         /* initialize non-constant commands */
19721         cmd_set_fwd_mode_init();
19722         cmd_set_fwd_retry_mode_init();
19723
19724         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19725         if (testpmd_cl == NULL)
19726                 return;
19727         cmdline_interact(testpmd_cl);
19728         cmdline_stdin_exit(testpmd_cl);
19729 }
19730
19731 void
19732 prompt_exit(void)
19733 {
19734         if (testpmd_cl != NULL)
19735                 cmdline_quit(testpmd_cl);
19736 }
19737
19738 static void
19739 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19740 {
19741         if (id == (portid_t)RTE_PORT_ALL) {
19742                 portid_t pid;
19743
19744                 RTE_ETH_FOREACH_DEV(pid) {
19745                         /* check if need_reconfig has been set to 1 */
19746                         if (ports[pid].need_reconfig == 0)
19747                                 ports[pid].need_reconfig = dev;
19748                         /* check if need_reconfig_queues has been set to 1 */
19749                         if (ports[pid].need_reconfig_queues == 0)
19750                                 ports[pid].need_reconfig_queues = queue;
19751                 }
19752         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19753                 /* check if need_reconfig has been set to 1 */
19754                 if (ports[id].need_reconfig == 0)
19755                         ports[id].need_reconfig = dev;
19756                 /* check if need_reconfig_queues has been set to 1 */
19757                 if (ports[id].need_reconfig_queues == 0)
19758                         ports[id].need_reconfig_queues = queue;
19759         }
19760 }