app/testpmd: support extended RSS offload types
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port X rss reta (size) (mask0,mask1,...)\n"
170                         "    Display the rss redirection table entry indicated"
171                         " by masks on port X. size is used to indicate the"
172                         " hardware supported reta size\n\n"
173
174                         "show port (port_id) rss-hash [key]\n"
175                         "    Display the RSS hash functions and RSS hash key of port\n\n"
176
177                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
178                         "    Clear information for port_id, or all.\n\n"
179
180                         "show (rxq|txq) info (port_id) (queue_id)\n"
181                         "    Display information for configured RX/TX queue.\n\n"
182
183                         "show config (rxtx|cores|fwd|txpkts)\n"
184                         "    Display the given configuration.\n\n"
185
186                         "read rxd (port_id) (queue_id) (rxd_id)\n"
187                         "    Display an RX descriptor of a port RX queue.\n\n"
188
189                         "read txd (port_id) (queue_id) (txd_id)\n"
190                         "    Display a TX descriptor of a port TX queue.\n\n"
191
192                         "ddp get list (port_id)\n"
193                         "    Get ddp profile info list\n\n"
194
195                         "ddp get info (profile_path)\n"
196                         "    Get ddp profile information.\n\n"
197
198                         "show vf stats (port_id) (vf_id)\n"
199                         "    Display a VF's statistics.\n\n"
200
201                         "clear vf stats (port_id) (vf_id)\n"
202                         "    Reset a VF's statistics.\n\n"
203
204                         "show port (port_id) pctype mapping\n"
205                         "    Get flow ptype to pctype mapping on a port\n\n"
206
207                         "show port meter stats (port_id) (meter_id) (clear)\n"
208                         "    Get meter stats on a port\n\n"
209
210                         "show fwd stats all\n"
211                         "    Display statistics for all fwd engines.\n\n"
212
213                         "clear fwd stats all\n"
214                         "    Clear statistics for all fwd engines.\n\n"
215
216                         "show port (port_id) rx_offload capabilities\n"
217                         "    List all per queue and per port Rx offloading"
218                         " capabilities of a port\n\n"
219
220                         "show port (port_id) rx_offload configuration\n"
221                         "    List port level and all queue level"
222                         " Rx offloading configuration\n\n"
223
224                         "show port (port_id) tx_offload capabilities\n"
225                         "    List all per queue and per port"
226                         " Tx offloading capabilities of a port\n\n"
227
228                         "show port (port_id) tx_offload configuration\n"
229                         "    List port level and all queue level"
230                         " Tx offloading configuration\n\n"
231
232                         "show port (port_id) tx_metadata\n"
233                         "    Show Tx metadata value set"
234                         " for a specific port\n\n"
235
236                         "show port (port_id) ptypes\n"
237                         "    Show port supported ptypes"
238                         " for a specific port\n\n"
239
240                         "show device info (<identifier>|all)"
241                         "       Show general information about devices probed.\n\n"
242
243                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
244                         "       Show status of rx|tx descriptor.\n\n"
245
246                         "show port (port_id) macs|mcast_macs"
247                         "       Display list of mac addresses added to port.\n\n"
248                 );
249         }
250
251         if (show_all || !strcmp(res->section, "config")) {
252                 cmdline_printf(
253                         cl,
254                         "\n"
255                         "Configuration:\n"
256                         "--------------\n"
257                         "Configuration changes only become active when"
258                         " forwarding is started/restarted.\n\n"
259
260                         "set default\n"
261                         "    Reset forwarding to the default configuration.\n\n"
262
263                         "set verbose (level)\n"
264                         "    Set the debug verbosity level X.\n\n"
265
266                         "set log global|(type) (level)\n"
267                         "    Set the log level.\n\n"
268
269                         "set nbport (num)\n"
270                         "    Set number of ports.\n\n"
271
272                         "set nbcore (num)\n"
273                         "    Set number of cores.\n\n"
274
275                         "set coremask (mask)\n"
276                         "    Set the forwarding cores hexadecimal mask.\n\n"
277
278                         "set portmask (mask)\n"
279                         "    Set the forwarding ports hexadecimal mask.\n\n"
280
281                         "set burst (num)\n"
282                         "    Set number of packets per burst.\n\n"
283
284                         "set burst tx delay (microseconds) retry (num)\n"
285                         "    Set the transmit delay time and number of retries,"
286                         " effective when retry is enabled.\n\n"
287
288                         "set txpkts (x[,y]*)\n"
289                         "    Set the length of each segment of TXONLY"
290                         " and optionally CSUM packets.\n\n"
291
292                         "set txsplit (off|on|rand)\n"
293                         "    Set the split policy for the TX packets."
294                         " Right now only applicable for CSUM and TXONLY"
295                         " modes\n\n"
296
297                         "set corelist (x[,y]*)\n"
298                         "    Set the list of forwarding cores.\n\n"
299
300                         "set portlist (x[,y]*)\n"
301                         "    Set the list of forwarding ports.\n\n"
302
303                         "set port setup on (iterator|event)\n"
304                         "    Select how attached port is retrieved for setup.\n\n"
305
306                         "set tx loopback (port_id) (on|off)\n"
307                         "    Enable or disable tx loopback.\n\n"
308
309                         "set all queues drop (port_id) (on|off)\n"
310                         "    Set drop enable bit for all queues.\n\n"
311
312                         "set vf split drop (port_id) (vf_id) (on|off)\n"
313                         "    Set split drop enable bit for a VF from the PF.\n\n"
314
315                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
316                         "    Set MAC antispoof for a VF from the PF.\n\n"
317
318                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
319                         "    Enable MACsec offload.\n\n"
320
321                         "set macsec offload (port_id) off\n"
322                         "    Disable MACsec offload.\n\n"
323
324                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
325                         "    Configure MACsec secure connection (SC).\n\n"
326
327                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
328                         "    Configure MACsec secure association (SA).\n\n"
329
330                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
331                         "    Set VF broadcast for a VF from the PF.\n\n"
332
333                         "vlan set stripq (on|off) (port_id,queue_id)\n"
334                         "    Set the VLAN strip for a queue on a port.\n\n"
335
336                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
337                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
338
339                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
340                         "    Set VLAN insert for a VF from the PF.\n\n"
341
342                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
343                         "    Set VLAN antispoof for a VF from the PF.\n\n"
344
345                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
346                         "    Set VLAN tag for a VF from the PF.\n\n"
347
348                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
349                         "    Set a VF's max bandwidth(Mbps).\n\n"
350
351                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
352                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
353
354                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
355                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
356
357                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
358                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
359
360                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
361                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
362
363                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
364                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
365
366                         "vlan set (inner|outer) tpid (value) (port_id)\n"
367                         "    Set the VLAN TPID for Packet Filtering on"
368                         " a port\n\n"
369
370                         "rx_vlan add (vlan_id|all) (port_id)\n"
371                         "    Add a vlan_id, or all identifiers, to the set"
372                         " of VLAN identifiers filtered by port_id.\n\n"
373
374                         "rx_vlan rm (vlan_id|all) (port_id)\n"
375                         "    Remove a vlan_id, or all identifiers, from the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
379                         "    Add a vlan_id, to the set of VLAN identifiers"
380                         "filtered for VF(s) from port_id.\n\n"
381
382                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Remove a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
387                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
388                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
389                         "   add a tunnel filter of a port.\n\n"
390
391                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
392                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
393                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
394                         "   remove a tunnel filter of a port.\n\n"
395
396                         "rx_vxlan_port add (udp_port) (port_id)\n"
397                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
398
399                         "rx_vxlan_port rm (udp_port) (port_id)\n"
400                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
401
402                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
403                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
404                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
405
406                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
407                         "    Set port based TX VLAN insertion.\n\n"
408
409                         "tx_vlan reset (port_id)\n"
410                         "    Disable hardware insertion of a VLAN header in"
411                         " packets sent on a port.\n\n"
412
413                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
414                         "    Select hardware or software calculation of the"
415                         " checksum when transmitting a packet using the"
416                         " csum forward engine.\n"
417                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
418                         "    outer-ip concerns the outer IP layer in"
419                         "    outer-udp concerns the outer UDP layer in"
420                         " case the packet is recognized as a tunnel packet by"
421                         " the forward engine (vxlan, gre and ipip are supported)\n"
422                         "    Please check the NIC datasheet for HW limits.\n\n"
423
424                         "csum parse-tunnel (on|off) (tx_port_id)\n"
425                         "    If disabled, treat tunnel packets as non-tunneled"
426                         " packets (treat inner headers as payload). The port\n"
427                         "    argument is the port used for TX in csum forward"
428                         " engine.\n\n"
429
430                         "csum show (port_id)\n"
431                         "    Display tx checksum offload configuration\n\n"
432
433                         "tso set (segsize) (portid)\n"
434                         "    Enable TCP Segmentation Offload in csum forward"
435                         " engine.\n"
436                         "    Please check the NIC datasheet for HW limits.\n\n"
437
438                         "tso show (portid)"
439                         "    Display the status of TCP Segmentation Offload.\n\n"
440
441                         "set port (port_id) gro on|off\n"
442                         "    Enable or disable Generic Receive Offload in"
443                         " csum forwarding engine.\n\n"
444
445                         "show port (port_id) gro\n"
446                         "    Display GRO configuration.\n\n"
447
448                         "set gro flush (cycles)\n"
449                         "    Set the cycle to flush GROed packets from"
450                         " reassembly tables.\n\n"
451
452                         "set port (port_id) gso (on|off)"
453                         "    Enable or disable Generic Segmentation Offload in"
454                         " csum forwarding engine.\n\n"
455
456                         "set gso segsz (length)\n"
457                         "    Set max packet length for output GSO segments,"
458                         " including packet header and payload.\n\n"
459
460                         "show port (port_id) gso\n"
461                         "    Show GSO configuration.\n\n"
462
463                         "set fwd (%s)\n"
464                         "    Set packet forwarding mode.\n\n"
465
466                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
467                         "    Add a MAC address on port_id.\n\n"
468
469                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
470                         "    Remove a MAC address from port_id.\n\n"
471
472                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
473                         "    Set the default MAC address for port_id.\n\n"
474
475                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
476                         "    Add a MAC address for a VF on the port.\n\n"
477
478                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
479                         "    Set the MAC address for a VF from the PF.\n\n"
480
481                         "set eth-peer (port_id) (peer_addr)\n"
482                         "    set the peer address for certain port.\n\n"
483
484                         "set port (port_id) uta (mac_address|all) (on|off)\n"
485                         "    Add/Remove a or all unicast hash filter(s)"
486                         "from port X.\n\n"
487
488                         "set promisc (port_id|all) (on|off)\n"
489                         "    Set the promiscuous mode on port_id, or all.\n\n"
490
491                         "set allmulti (port_id|all) (on|off)\n"
492                         "    Set the allmulti mode on port_id, or all.\n\n"
493
494                         "set vf promisc (port_id) (vf_id) (on|off)\n"
495                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
496
497                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
498                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
499
500                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
501                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
502                         " (on|off) autoneg (on|off) (port_id)\n"
503                         "set flow_ctrl rx (on|off) (portid)\n"
504                         "set flow_ctrl tx (on|off) (portid)\n"
505                         "set flow_ctrl high_water (high_water) (portid)\n"
506                         "set flow_ctrl low_water (low_water) (portid)\n"
507                         "set flow_ctrl pause_time (pause_time) (portid)\n"
508                         "set flow_ctrl send_xon (send_xon) (portid)\n"
509                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
510                         "set flow_ctrl autoneg (on|off) (port_id)\n"
511                         "    Set the link flow control parameter on a port.\n\n"
512
513                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (priority) (port_id)\n"
515                         "    Set the priority flow control parameter on a"
516                         " port.\n\n"
517
518                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
519                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
520                         " queue on port.\n"
521                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
522                         " on port 0 to mapping 5.\n\n"
523
524                         "set xstats-hide-zero on|off\n"
525                         "    Set the option to hide the zero values"
526                         " for xstats display.\n"
527
528                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
529                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
530
531                         "set port (port_id) vf (vf_id) (mac_addr)"
532                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
533                         "   Add/Remove unicast or multicast MAC addr filter"
534                         " for a VF.\n\n"
535
536                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
537                         "|MPE) (on|off)\n"
538                         "    AUPE:accepts untagged VLAN;"
539                         "ROPE:accept unicast hash\n\n"
540                         "    BAM:accepts broadcast packets;"
541                         "MPE:accepts all multicast packets\n\n"
542                         "    Enable/Disable a VF receive mode of a port\n\n"
543
544                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
545                         "    Set rate limit for a queue of a port\n\n"
546
547                         "set port (port_id) vf (vf_id) rate (rate_num) "
548                         "queue_mask (queue_mask_value)\n"
549                         "    Set rate limit for queues in VF of a port\n\n"
550
551                         "set port (port_id) mirror-rule (rule_id)"
552                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
553                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
554                         "   Set pool or vlan type mirror rule on a port.\n"
555                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
556                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
557                         " to pool 0.\n\n"
558
559                         "set port (port_id) mirror-rule (rule_id)"
560                         " (uplink-mirror|downlink-mirror) dst-pool"
561                         " (pool_id) (on|off)\n"
562                         "   Set uplink or downlink type mirror rule on a port.\n"
563                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
564                         " 0 on' enable mirror income traffic to pool 0.\n\n"
565
566                         "reset port (port_id) mirror-rule (rule_id)\n"
567                         "   Reset a mirror rule.\n\n"
568
569                         "set flush_rx (on|off)\n"
570                         "   Flush (default) or don't flush RX streams before"
571                         " forwarding. Mainly used with PCAP drivers.\n\n"
572
573                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
574                         "   Set the bypass mode for the lowest port on bypass enabled"
575                         " NIC.\n\n"
576
577                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
578                         "mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the event required to initiate specified bypass mode for"
580                         " the lowest port on a bypass enabled NIC where:\n"
581                         "       timeout   = enable bypass after watchdog timeout.\n"
582                         "       os_on     = enable bypass when OS/board is powered on.\n"
583                         "       os_off    = enable bypass when OS/board is powered off.\n"
584                         "       power_on  = enable bypass when power supply is turned on.\n"
585                         "       power_off = enable bypass when power supply is turned off."
586                         "\n\n"
587
588                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
589                         "   Set the bypass watchdog timeout to 'n' seconds"
590                         " where 0 = instant.\n\n"
591
592                         "show bypass config (port_id)\n"
593                         "   Show the bypass configuration for a bypass enabled NIC"
594                         " using the lowest port on the NIC.\n\n"
595
596 #ifdef RTE_LIBRTE_PMD_BOND
597                         "create bonded device (mode) (socket)\n"
598                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
599
600                         "add bonding slave (slave_id) (port_id)\n"
601                         "       Add a slave device to a bonded device.\n\n"
602
603                         "remove bonding slave (slave_id) (port_id)\n"
604                         "       Remove a slave device from a bonded device.\n\n"
605
606                         "set bonding mode (value) (port_id)\n"
607                         "       Set the bonding mode on a bonded device.\n\n"
608
609                         "set bonding primary (slave_id) (port_id)\n"
610                         "       Set the primary slave for a bonded device.\n\n"
611
612                         "show bonding config (port_id)\n"
613                         "       Show the bonding config for port_id.\n\n"
614
615                         "set bonding mac_addr (port_id) (address)\n"
616                         "       Set the MAC address of a bonded device.\n\n"
617
618                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
619                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
620
621                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
622                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
623
624                         "set bonding mon_period (port_id) (value)\n"
625                         "       Set the bonding link status monitoring polling period in ms.\n\n"
626
627                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
628                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
629
630 #endif
631                         "set link-up port (port_id)\n"
632                         "       Set link up for a port.\n\n"
633
634                         "set link-down port (port_id)\n"
635                         "       Set link down for a port.\n\n"
636
637                         "E-tag set insertion on port-tag-id (value)"
638                         " port (port_id) vf (vf_id)\n"
639                         "    Enable E-tag insertion for a VF on a port\n\n"
640
641                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
642                         "    Disable E-tag insertion for a VF on a port\n\n"
643
644                         "E-tag set stripping (on|off) port (port_id)\n"
645                         "    Enable/disable E-tag stripping on a port\n\n"
646
647                         "E-tag set forwarding (on|off) port (port_id)\n"
648                         "    Enable/disable E-tag based forwarding"
649                         " on a port\n\n"
650
651                         "E-tag set filter add e-tag-id (value) dst-pool"
652                         " (pool_id) port (port_id)\n"
653                         "    Add an E-tag forwarding filter on a port\n\n"
654
655                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
656                         "    Delete an E-tag forwarding filter on a port\n\n"
657
658                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
659                         "    Load a profile package on a port\n\n"
660
661                         "ddp del (port_id) (backup_profile_path)\n"
662                         "    Delete a profile package from a port\n\n"
663
664                         "ptype mapping get (port_id) (valid_only)\n"
665                         "    Get ptype mapping on a port\n\n"
666
667                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
668                         "    Replace target with the pkt_type in ptype mapping\n\n"
669
670                         "ptype mapping reset (port_id)\n"
671                         "    Reset ptype mapping on a port\n\n"
672
673                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
674                         "    Update a ptype mapping item on a port\n\n"
675
676                         "set port (port_id) ptype_mask (ptype_mask)\n"
677                         "    set packet types classification for a specific port\n\n"
678
679                         "set port (port_id) queue-region region_id (value) "
680                         "queue_start_index (value) queue_num (value)\n"
681                         "    Set a queue region on a port\n\n"
682
683                         "set port (port_id) queue-region region_id (value) "
684                         "flowtype (value)\n"
685                         "    Set a flowtype region index on a port\n\n"
686
687                         "set port (port_id) queue-region UP (value) region_id (value)\n"
688                         "    Set the mapping of User Priority to "
689                         "queue region on a port\n\n"
690
691                         "set port (port_id) queue-region flush (on|off)\n"
692                         "    flush all queue region related configuration\n\n"
693
694                         "show port meter cap (port_id)\n"
695                         "    Show port meter capability information\n\n"
696
697                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
698                         "    meter profile add - srtcm rfc 2697\n\n"
699
700                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
701                         "    meter profile add - trtcm rfc 2698\n\n"
702
703                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
704                         "    meter profile add - trtcm rfc 4115\n\n"
705
706                         "del port meter profile (port_id) (profile_id)\n"
707                         "    meter profile delete\n\n"
708
709                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
710                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
711                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
712                         "(dscp_tbl_entry63)]\n"
713                         "    meter create\n\n"
714
715                         "enable port meter (port_id) (mtr_id)\n"
716                         "    meter enable\n\n"
717
718                         "disable port meter (port_id) (mtr_id)\n"
719                         "    meter disable\n\n"
720
721                         "del port meter (port_id) (mtr_id)\n"
722                         "    meter delete\n\n"
723
724                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
725                         "    meter update meter profile\n\n"
726
727                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
728                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
729                         "    update meter dscp table entries\n\n"
730
731                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
732                         "(action0) [(action1) (action2)]\n"
733                         "    meter update policer action\n\n"
734
735                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
736                         "    meter update stats\n\n"
737
738                         "show port (port_id) queue-region\n"
739                         "    show all queue region related configuration info\n\n"
740
741                         , list_pkt_forwarding_modes()
742                 );
743         }
744
745         if (show_all || !strcmp(res->section, "ports")) {
746
747                 cmdline_printf(
748                         cl,
749                         "\n"
750                         "Port Operations:\n"
751                         "----------------\n\n"
752
753                         "port start (port_id|all)\n"
754                         "    Start all ports or port_id.\n\n"
755
756                         "port stop (port_id|all)\n"
757                         "    Stop all ports or port_id.\n\n"
758
759                         "port close (port_id|all)\n"
760                         "    Close all ports or port_id.\n\n"
761
762                         "port reset (port_id|all)\n"
763                         "    Reset all ports or port_id.\n\n"
764
765                         "port attach (ident)\n"
766                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
767
768                         "port detach (port_id)\n"
769                         "    Detach physical or virtual dev by port_id\n\n"
770
771                         "port config (port_id|all)"
772                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
773                         " duplex (half|full|auto)\n"
774                         "    Set speed and duplex for all ports or port_id\n\n"
775
776                         "port config (port_id|all) loopback (mode)\n"
777                         "    Set loopback mode for all ports or port_id\n\n"
778
779                         "port config all (rxq|txq|rxd|txd) (value)\n"
780                         "    Set number for rxq/txq/rxd/txd.\n\n"
781
782                         "port config all max-pkt-len (value)\n"
783                         "    Set the max packet length.\n\n"
784
785                         "port config all max-lro-pkt-size (value)\n"
786                         "    Set the max LRO aggregated packet size.\n\n"
787
788                         "port config all drop-en (on|off)\n"
789                         "    Enable or disable packet drop on all RX queues of all ports when no "
790                         "receive buffers available.\n\n"
791
792                         "port config all rss (all|default|ip|tcp|udp|sctp|"
793                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
794                         "    Set the RSS mode.\n\n"
795
796                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
797                         "    Set the RSS redirection table.\n\n"
798
799                         "port config (port_id) dcb vt (on|off) (traffic_class)"
800                         " pfc (on|off)\n"
801                         "    Set the DCB mode.\n\n"
802
803                         "port config all burst (value)\n"
804                         "    Set the number of packets per burst.\n\n"
805
806                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
807                         " (value)\n"
808                         "    Set the ring prefetch/host/writeback threshold"
809                         " for tx/rx queue.\n\n"
810
811                         "port config all (txfreet|txrst|rxfreet) (value)\n"
812                         "    Set free threshold for rx/tx, or set"
813                         " tx rs bit threshold.\n\n"
814                         "port config mtu X value\n"
815                         "    Set the MTU of port X to a given value\n\n"
816
817                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
818                         "    Set a rx/tx queue's ring size configuration, the new"
819                         " value will take effect after command that (re-)start the port"
820                         " or command that setup the specific queue\n\n"
821
822                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
823                         "    Start/stop a rx/tx queue of port X. Only take effect"
824                         " when port X is started\n\n"
825
826                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
827                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
828                         " take effect when port X is stopped.\n\n"
829
830                         "port (port_id) (rxq|txq) (queue_id) setup\n"
831                         "    Setup a rx/tx queue of port X.\n\n"
832
833                         "port config (port_id|all) l2-tunnel E-tag ether-type"
834                         " (value)\n"
835                         "    Set the value of E-tag ether-type.\n\n"
836
837                         "port config (port_id|all) l2-tunnel E-tag"
838                         " (enable|disable)\n"
839                         "    Enable/disable the E-tag support.\n\n"
840
841                         "port config (port_id) pctype mapping reset\n"
842                         "    Reset flow type to pctype mapping on a port\n\n"
843
844                         "port config (port_id) pctype mapping update"
845                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
846                         "    Update a flow type to pctype mapping item on a port\n\n"
847
848                         "port config (port_id) pctype (pctype_id) hash_inset|"
849                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
850                         " (field_idx)\n"
851                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
852
853                         "port config (port_id) pctype (pctype_id) hash_inset|"
854                         "fdir_inset|fdir_flx_inset clear all"
855                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
856
857                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
858                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
859
860                         "port config <port_id> rx_offload vlan_strip|"
861                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
862                         "outer_ipv4_cksum|macsec_strip|header_split|"
863                         "vlan_filter|vlan_extend|jumbo_frame|"
864                         "scatter|timestamp|security|keep_crc on|off\n"
865                         "     Enable or disable a per port Rx offloading"
866                         " on all Rx queues of a port\n\n"
867
868                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
869                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
870                         "outer_ipv4_cksum|macsec_strip|header_split|"
871                         "vlan_filter|vlan_extend|jumbo_frame|"
872                         "scatter|timestamp|security|keep_crc on|off\n"
873                         "    Enable or disable a per queue Rx offloading"
874                         " only on a specific Rx queue\n\n"
875
876                         "port config (port_id) tx_offload vlan_insert|"
877                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
878                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
879                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
880                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
881                         "security on|off\n"
882                         "    Enable or disable a per port Tx offloading"
883                         " on all Tx queues of a port\n\n"
884
885                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
886                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
887                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
888                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
889                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
890                         " on|off\n"
891                         "    Enable or disable a per queue Tx offloading"
892                         " only on a specific Tx queue\n\n"
893
894                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
895                         "    Load an eBPF program as a callback"
896                         " for particular RX/TX queue\n\n"
897
898                         "bpf-unload rx|tx (port) (queue)\n"
899                         "    Unload previously loaded eBPF program"
900                         " for particular RX/TX queue\n\n"
901
902                         "port config (port_id) tx_metadata (value)\n"
903                         "    Set Tx metadata value per port. Testpmd will add this value"
904                         " to any Tx packet sent from this port\n\n"
905
906                         "port config (port_id) dynf (name) set|clear\n"
907                         "    Register a dynf and Set/clear this flag on Tx. "
908                         "Testpmd will set this value to any Tx packet "
909                         "sent from this port\n\n"
910                 );
911         }
912
913         if (show_all || !strcmp(res->section, "registers")) {
914
915                 cmdline_printf(
916                         cl,
917                         "\n"
918                         "Registers:\n"
919                         "----------\n\n"
920
921                         "read reg (port_id) (address)\n"
922                         "    Display value of a port register.\n\n"
923
924                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
925                         "    Display a port register bit field.\n\n"
926
927                         "read regbit (port_id) (address) (bit_x)\n"
928                         "    Display a single port register bit.\n\n"
929
930                         "write reg (port_id) (address) (value)\n"
931                         "    Set value of a port register.\n\n"
932
933                         "write regfield (port_id) (address) (bit_x) (bit_y)"
934                         " (value)\n"
935                         "    Set bit field of a port register.\n\n"
936
937                         "write regbit (port_id) (address) (bit_x) (value)\n"
938                         "    Set single bit value of a port register.\n\n"
939                 );
940         }
941         if (show_all || !strcmp(res->section, "filters")) {
942
943                 cmdline_printf(
944                         cl,
945                         "\n"
946                         "filters:\n"
947                         "--------\n\n"
948
949                         "ethertype_filter (port_id) (add|del)"
950                         " (mac_addr|mac_ignr) (mac_address) ethertype"
951                         " (ether_type) (drop|fwd) queue (queue_id)\n"
952                         "    Add/Del an ethertype filter.\n\n"
953
954                         "2tuple_filter (port_id) (add|del)"
955                         " dst_port (dst_port_value) protocol (protocol_value)"
956                         " mask (mask_value) tcp_flags (tcp_flags_value)"
957                         " priority (prio_value) queue (queue_id)\n"
958                         "    Add/Del a 2tuple filter.\n\n"
959
960                         "5tuple_filter (port_id) (add|del)"
961                         " dst_ip (dst_address) src_ip (src_address)"
962                         " dst_port (dst_port_value) src_port (src_port_value)"
963                         " protocol (protocol_value)"
964                         " mask (mask_value) tcp_flags (tcp_flags_value)"
965                         " priority (prio_value) queue (queue_id)\n"
966                         "    Add/Del a 5tuple filter.\n\n"
967
968                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
969                         "    Add/Del syn filter.\n\n"
970
971                         "flex_filter (port_id) (add|del) len (len_value)"
972                         " bytes (bytes_value) mask (mask_value)"
973                         " priority (prio_value) queue (queue_id)\n"
974                         "    Add/Del a flex filter.\n\n"
975
976                         "flow_director_filter (port_id) mode IP (add|del|update)"
977                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
978                         " src (src_ip_address) dst (dst_ip_address)"
979                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
980                         " vlan (vlan_value) flexbytes (flexbytes_value)"
981                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
982                         " fd_id (fd_id_value)\n"
983                         "    Add/Del an IP type flow director filter.\n\n"
984
985                         "flow_director_filter (port_id) mode IP (add|del|update)"
986                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
987                         " src (src_ip_address) (src_port)"
988                         " dst (dst_ip_address) (dst_port)"
989                         " tos (tos_value) ttl (ttl_value)"
990                         " vlan (vlan_value) flexbytes (flexbytes_value)"
991                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
992                         " fd_id (fd_id_value)\n"
993                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-sctp|ipv6-sctp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tag (verification_tag) "
1000                         " tos (tos_value) ttl (ttl_value)"
1001                         " vlan (vlan_value)"
1002                         " flexbytes (flexbytes_value) (drop|fwd)"
1003                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1004                         "    Add/Del a SCTP type flow director filter.\n\n"
1005
1006                         "flow_director_filter (port_id) mode IP (add|del|update)"
1007                         " flow l2_payload ether (ethertype)"
1008                         " flexbytes (flexbytes_value) (drop|fwd)"
1009                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1010                         "    Add/Del a l2 payload type flow director filter.\n\n"
1011
1012                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1013                         " mac (mac_address) vlan (vlan_value)"
1014                         " flexbytes (flexbytes_value) (drop|fwd)"
1015                         " queue (queue_id) fd_id (fd_id_value)\n"
1016                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1019                         " mac (mac_address) vlan (vlan_value)"
1020                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1021                         " flexbytes (flexbytes_value) (drop|fwd)"
1022                         " queue (queue_id) fd_id (fd_id_value)\n"
1023                         "    Add/Del a Tunnel flow director filter.\n\n"
1024
1025                         "flow_director_filter (port_id) mode raw (add|del|update)"
1026                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1027                         " fd_id (fd_id_value) packet (packet file name)\n"
1028                         "    Add/Del a raw type flow director filter.\n\n"
1029
1030                         "flush_flow_director (port_id)\n"
1031                         "    Flush all flow director entries of a device.\n\n"
1032
1033                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1034                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1035                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1036                         "    Set flow director IP mask.\n\n"
1037
1038                         "flow_director_mask (port_id) mode MAC-VLAN"
1039                         " vlan (vlan_value)\n"
1040                         "    Set flow director MAC-VLAN mask.\n\n"
1041
1042                         "flow_director_mask (port_id) mode Tunnel"
1043                         " vlan (vlan_value) mac (mac_value)"
1044                         " tunnel-type (tunnel_type_value)"
1045                         " tunnel-id (tunnel_id_value)\n"
1046                         "    Set flow director Tunnel mask.\n\n"
1047
1048                         "flow_director_flex_mask (port_id)"
1049                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1050                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1051                         " (mask)\n"
1052                         "    Configure mask of flex payload.\n\n"
1053
1054                         "flow_director_flex_payload (port_id)"
1055                         " (raw|l2|l3|l4) (config)\n"
1056                         "    Configure flex payload selection.\n\n"
1057
1058                         "get_sym_hash_ena_per_port (port_id)\n"
1059                         "    get symmetric hash enable configuration per port.\n\n"
1060
1061                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1062                         "    set symmetric hash enable configuration per port"
1063                         " to enable or disable.\n\n"
1064
1065                         "get_hash_global_config (port_id)\n"
1066                         "    Get the global configurations of hash filters.\n\n"
1067
1068                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1069                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1070                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1071                         " (enable|disable)\n"
1072                         "    Set the global configurations of hash filters.\n\n"
1073
1074                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1075                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1076                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1077                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1078                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1079                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1080                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1081                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1082                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1083                         "fld-8th|none) (select|add)\n"
1084                         "    Set the input set for hash.\n\n"
1085
1086                         "set_fdir_input_set (port_id) "
1087                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1088                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1089                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1090                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1091                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1092                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1093                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1094                         " (select|add)\n"
1095                         "    Set the input set for FDir.\n\n"
1096
1097                         "flow validate {port_id}"
1098                         " [group {group_id}] [priority {level}]"
1099                         " [ingress] [egress]"
1100                         " pattern {item} [/ {item} [...]] / end"
1101                         " actions {action} [/ {action} [...]] / end\n"
1102                         "    Check whether a flow rule can be created.\n\n"
1103
1104                         "flow create {port_id}"
1105                         " [group {group_id}] [priority {level}]"
1106                         " [ingress] [egress]"
1107                         " pattern {item} [/ {item} [...]] / end"
1108                         " actions {action} [/ {action} [...]] / end\n"
1109                         "    Create a flow rule.\n\n"
1110
1111                         "flow destroy {port_id} rule {rule_id} [...]\n"
1112                         "    Destroy specific flow rules.\n\n"
1113
1114                         "flow flush {port_id}\n"
1115                         "    Destroy all flow rules.\n\n"
1116
1117                         "flow query {port_id} {rule_id} {action}\n"
1118                         "    Query an existing flow rule.\n\n"
1119
1120                         "flow list {port_id} [group {group_id}] [...]\n"
1121                         "    List existing flow rules sorted by priority,"
1122                         " filtered by group identifiers.\n\n"
1123
1124                         "flow isolate {port_id} {boolean}\n"
1125                         "    Restrict ingress traffic to the defined"
1126                         " flow rules\n\n"
1127
1128                         "flow aged {port_id} [destroy]\n"
1129                         "    List and destroy aged flows"
1130                         " flow rules\n\n"
1131
1132                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1133                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1134                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1135                         "       Configure the VXLAN encapsulation for flows.\n\n"
1136
1137                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1138                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1139                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1140                         " eth-dst (eth-dst)\n"
1141                         "       Configure the VXLAN encapsulation for flows.\n\n"
1142
1143                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1144                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1145                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1146                         " eth-dst (eth-dst)\n"
1147                         "       Configure the VXLAN encapsulation for flows.\n\n"
1148
1149                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1150                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1151                         " (eth-dst)\n"
1152                         "       Configure the NVGRE encapsulation for flows.\n\n"
1153
1154                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1155                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1156                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1157                         "       Configure the NVGRE encapsulation for flows.\n\n"
1158
1159                         "set raw_encap {flow items}\n"
1160                         "       Configure the encapsulation with raw data.\n\n"
1161
1162                         "set raw_decap {flow items}\n"
1163                         "       Configure the decapsulation with raw data.\n\n"
1164
1165                 );
1166         }
1167
1168         if (show_all || !strcmp(res->section, "traffic_management")) {
1169                 cmdline_printf(
1170                         cl,
1171                         "\n"
1172                         "Traffic Management:\n"
1173                         "--------------\n"
1174                         "show port tm cap (port_id)\n"
1175                         "       Display the port TM capability.\n\n"
1176
1177                         "show port tm level cap (port_id) (level_id)\n"
1178                         "       Display the port TM hierarchical level capability.\n\n"
1179
1180                         "show port tm node cap (port_id) (node_id)\n"
1181                         "       Display the port TM node capability.\n\n"
1182
1183                         "show port tm node type (port_id) (node_id)\n"
1184                         "       Display the port TM node type.\n\n"
1185
1186                         "show port tm node stats (port_id) (node_id) (clear)\n"
1187                         "       Display the port TM node stats.\n\n"
1188
1189 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
1190                         "set port tm hierarchy default (port_id)\n"
1191                         "       Set default traffic Management hierarchy on a port\n\n"
1192 #endif
1193
1194                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1195                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1196                         " (packet_length_adjust)\n"
1197                         "       Add port tm node private shaper profile.\n\n"
1198
1199                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1200                         "       Delete port tm node private shaper profile.\n\n"
1201
1202                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1203                         " (shaper_profile_id)\n"
1204                         "       Add/update port tm node shared shaper.\n\n"
1205
1206                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1207                         "       Delete port tm node shared shaper.\n\n"
1208
1209                         "set port tm node shaper profile (port_id) (node_id)"
1210                         " (shaper_profile_id)\n"
1211                         "       Set port tm node shaper profile.\n\n"
1212
1213                         "add port tm node wred profile (port_id) (wred_profile_id)"
1214                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1215                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1216                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1217                         "       Add port tm node wred profile.\n\n"
1218
1219                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1220                         "       Delete port tm node wred profile.\n\n"
1221
1222                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1223                         " (priority) (weight) (level_id) (shaper_profile_id)"
1224                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1225                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1226                         "       Add port tm nonleaf node.\n\n"
1227
1228                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1229                         " (priority) (weight) (level_id) (shaper_profile_id)"
1230                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1231                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1232                         "       Add port tm leaf node.\n\n"
1233
1234                         "del port tm node (port_id) (node_id)\n"
1235                         "       Delete port tm node.\n\n"
1236
1237                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1238                         " (priority) (weight)\n"
1239                         "       Set port tm node parent.\n\n"
1240
1241                         "suspend port tm node (port_id) (node_id)"
1242                         "       Suspend tm node.\n\n"
1243
1244                         "resume port tm node (port_id) (node_id)"
1245                         "       Resume tm node.\n\n"
1246
1247                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1248                         "       Commit tm hierarchy.\n\n"
1249
1250                         "set port tm mark ip_ecn (port) (green) (yellow)"
1251                         " (red)\n"
1252                         "    Enables/Disables the traffic management marking"
1253                         " for IP ECN (Explicit Congestion Notification)"
1254                         " packets on a given port\n\n"
1255
1256                         "set port tm mark ip_dscp (port) (green) (yellow)"
1257                         " (red)\n"
1258                         "    Enables/Disables the traffic management marking"
1259                         " on the port for IP dscp packets\n\n"
1260
1261                         "set port tm mark vlan_dei (port) (green) (yellow)"
1262                         " (red)\n"
1263                         "    Enables/Disables the traffic management marking"
1264                         " on the port for VLAN packets with DEI enabled\n\n"
1265                 );
1266         }
1267
1268         if (show_all || !strcmp(res->section, "devices")) {
1269                 cmdline_printf(
1270                         cl,
1271                         "\n"
1272                         "Device Operations:\n"
1273                         "--------------\n"
1274                         "device detach (identifier)\n"
1275                         "       Detach device by identifier.\n\n"
1276                 );
1277         }
1278
1279 }
1280
1281 cmdline_parse_token_string_t cmd_help_long_help =
1282         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1283
1284 cmdline_parse_token_string_t cmd_help_long_section =
1285         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1286                         "all#control#display#config#"
1287                         "ports#registers#filters#traffic_management#devices");
1288
1289 cmdline_parse_inst_t cmd_help_long = {
1290         .f = cmd_help_long_parsed,
1291         .data = NULL,
1292         .help_str = "help all|control|display|config|ports|register|"
1293                 "filters|traffic_management|devices: "
1294                 "Show help",
1295         .tokens = {
1296                 (void *)&cmd_help_long_help,
1297                 (void *)&cmd_help_long_section,
1298                 NULL,
1299         },
1300 };
1301
1302
1303 /* *** start/stop/close all ports *** */
1304 struct cmd_operate_port_result {
1305         cmdline_fixed_string_t keyword;
1306         cmdline_fixed_string_t name;
1307         cmdline_fixed_string_t value;
1308 };
1309
1310 static void cmd_operate_port_parsed(void *parsed_result,
1311                                 __rte_unused struct cmdline *cl,
1312                                 __rte_unused void *data)
1313 {
1314         struct cmd_operate_port_result *res = parsed_result;
1315
1316         if (!strcmp(res->name, "start"))
1317                 start_port(RTE_PORT_ALL);
1318         else if (!strcmp(res->name, "stop"))
1319                 stop_port(RTE_PORT_ALL);
1320         else if (!strcmp(res->name, "close"))
1321                 close_port(RTE_PORT_ALL);
1322         else if (!strcmp(res->name, "reset"))
1323                 reset_port(RTE_PORT_ALL);
1324         else
1325                 printf("Unknown parameter\n");
1326 }
1327
1328 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1329         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1330                                                                 "port");
1331 cmdline_parse_token_string_t cmd_operate_port_all_port =
1332         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1333                                                 "start#stop#close#reset");
1334 cmdline_parse_token_string_t cmd_operate_port_all_all =
1335         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1336
1337 cmdline_parse_inst_t cmd_operate_port = {
1338         .f = cmd_operate_port_parsed,
1339         .data = NULL,
1340         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1341         .tokens = {
1342                 (void *)&cmd_operate_port_all_cmd,
1343                 (void *)&cmd_operate_port_all_port,
1344                 (void *)&cmd_operate_port_all_all,
1345                 NULL,
1346         },
1347 };
1348
1349 /* *** start/stop/close specific port *** */
1350 struct cmd_operate_specific_port_result {
1351         cmdline_fixed_string_t keyword;
1352         cmdline_fixed_string_t name;
1353         uint8_t value;
1354 };
1355
1356 static void cmd_operate_specific_port_parsed(void *parsed_result,
1357                         __rte_unused struct cmdline *cl,
1358                                 __rte_unused void *data)
1359 {
1360         struct cmd_operate_specific_port_result *res = parsed_result;
1361
1362         if (!strcmp(res->name, "start"))
1363                 start_port(res->value);
1364         else if (!strcmp(res->name, "stop"))
1365                 stop_port(res->value);
1366         else if (!strcmp(res->name, "close"))
1367                 close_port(res->value);
1368         else if (!strcmp(res->name, "reset"))
1369                 reset_port(res->value);
1370         else
1371                 printf("Unknown parameter\n");
1372 }
1373
1374 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1375         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1376                                                         keyword, "port");
1377 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1378         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1379                                                 name, "start#stop#close#reset");
1380 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1381         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1382                                                         value, UINT8);
1383
1384 cmdline_parse_inst_t cmd_operate_specific_port = {
1385         .f = cmd_operate_specific_port_parsed,
1386         .data = NULL,
1387         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1388         .tokens = {
1389                 (void *)&cmd_operate_specific_port_cmd,
1390                 (void *)&cmd_operate_specific_port_port,
1391                 (void *)&cmd_operate_specific_port_id,
1392                 NULL,
1393         },
1394 };
1395
1396 /* *** enable port setup (after attach) via iterator or event *** */
1397 struct cmd_set_port_setup_on_result {
1398         cmdline_fixed_string_t set;
1399         cmdline_fixed_string_t port;
1400         cmdline_fixed_string_t setup;
1401         cmdline_fixed_string_t on;
1402         cmdline_fixed_string_t mode;
1403 };
1404
1405 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1406                                 __rte_unused struct cmdline *cl,
1407                                 __rte_unused void *data)
1408 {
1409         struct cmd_set_port_setup_on_result *res = parsed_result;
1410
1411         if (strcmp(res->mode, "event") == 0)
1412                 setup_on_probe_event = true;
1413         else if (strcmp(res->mode, "iterator") == 0)
1414                 setup_on_probe_event = false;
1415         else
1416                 printf("Unknown mode\n");
1417 }
1418
1419 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1420         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1421                         set, "set");
1422 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1423         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1424                         port, "port");
1425 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1426         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1427                         setup, "setup");
1428 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1429         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1430                         on, "on");
1431 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1432         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1433                         mode, "iterator#event");
1434
1435 cmdline_parse_inst_t cmd_set_port_setup_on = {
1436         .f = cmd_set_port_setup_on_parsed,
1437         .data = NULL,
1438         .help_str = "set port setup on iterator|event",
1439         .tokens = {
1440                 (void *)&cmd_set_port_setup_on_set,
1441                 (void *)&cmd_set_port_setup_on_port,
1442                 (void *)&cmd_set_port_setup_on_setup,
1443                 (void *)&cmd_set_port_setup_on_on,
1444                 (void *)&cmd_set_port_setup_on_mode,
1445                 NULL,
1446         },
1447 };
1448
1449 /* *** attach a specified port *** */
1450 struct cmd_operate_attach_port_result {
1451         cmdline_fixed_string_t port;
1452         cmdline_fixed_string_t keyword;
1453         cmdline_multi_string_t identifier;
1454 };
1455
1456 static void cmd_operate_attach_port_parsed(void *parsed_result,
1457                                 __rte_unused struct cmdline *cl,
1458                                 __rte_unused void *data)
1459 {
1460         struct cmd_operate_attach_port_result *res = parsed_result;
1461
1462         if (!strcmp(res->keyword, "attach"))
1463                 attach_port(res->identifier);
1464         else
1465                 printf("Unknown parameter\n");
1466 }
1467
1468 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1469         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1470                         port, "port");
1471 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1472         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1473                         keyword, "attach");
1474 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1475         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1476                         identifier, TOKEN_STRING_MULTI);
1477
1478 cmdline_parse_inst_t cmd_operate_attach_port = {
1479         .f = cmd_operate_attach_port_parsed,
1480         .data = NULL,
1481         .help_str = "port attach <identifier>: "
1482                 "(identifier: pci address or virtual dev name)",
1483         .tokens = {
1484                 (void *)&cmd_operate_attach_port_port,
1485                 (void *)&cmd_operate_attach_port_keyword,
1486                 (void *)&cmd_operate_attach_port_identifier,
1487                 NULL,
1488         },
1489 };
1490
1491 /* *** detach a specified port *** */
1492 struct cmd_operate_detach_port_result {
1493         cmdline_fixed_string_t port;
1494         cmdline_fixed_string_t keyword;
1495         portid_t port_id;
1496 };
1497
1498 static void cmd_operate_detach_port_parsed(void *parsed_result,
1499                                 __rte_unused struct cmdline *cl,
1500                                 __rte_unused void *data)
1501 {
1502         struct cmd_operate_detach_port_result *res = parsed_result;
1503
1504         if (!strcmp(res->keyword, "detach")) {
1505                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1506                 detach_port_device(res->port_id);
1507         } else {
1508                 printf("Unknown parameter\n");
1509         }
1510 }
1511
1512 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1513         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1514                         port, "port");
1515 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1516         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1517                         keyword, "detach");
1518 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1519         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1520                         port_id, UINT16);
1521
1522 cmdline_parse_inst_t cmd_operate_detach_port = {
1523         .f = cmd_operate_detach_port_parsed,
1524         .data = NULL,
1525         .help_str = "port detach <port_id>",
1526         .tokens = {
1527                 (void *)&cmd_operate_detach_port_port,
1528                 (void *)&cmd_operate_detach_port_keyword,
1529                 (void *)&cmd_operate_detach_port_port_id,
1530                 NULL,
1531         },
1532 };
1533
1534 /* *** detach device by identifier *** */
1535 struct cmd_operate_detach_device_result {
1536         cmdline_fixed_string_t device;
1537         cmdline_fixed_string_t keyword;
1538         cmdline_fixed_string_t identifier;
1539 };
1540
1541 static void cmd_operate_detach_device_parsed(void *parsed_result,
1542                                 __rte_unused struct cmdline *cl,
1543                                 __rte_unused void *data)
1544 {
1545         struct cmd_operate_detach_device_result *res = parsed_result;
1546
1547         if (!strcmp(res->keyword, "detach"))
1548                 detach_devargs(res->identifier);
1549         else
1550                 printf("Unknown parameter\n");
1551 }
1552
1553 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1554         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1555                         device, "device");
1556 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1557         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1558                         keyword, "detach");
1559 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1560         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1561                         identifier, NULL);
1562
1563 cmdline_parse_inst_t cmd_operate_detach_device = {
1564         .f = cmd_operate_detach_device_parsed,
1565         .data = NULL,
1566         .help_str = "device detach <identifier>:"
1567                 "(identifier: pci address or virtual dev name)",
1568         .tokens = {
1569                 (void *)&cmd_operate_detach_device_device,
1570                 (void *)&cmd_operate_detach_device_keyword,
1571                 (void *)&cmd_operate_detach_device_identifier,
1572                 NULL,
1573         },
1574 };
1575 /* *** configure speed for all ports *** */
1576 struct cmd_config_speed_all {
1577         cmdline_fixed_string_t port;
1578         cmdline_fixed_string_t keyword;
1579         cmdline_fixed_string_t all;
1580         cmdline_fixed_string_t item1;
1581         cmdline_fixed_string_t item2;
1582         cmdline_fixed_string_t value1;
1583         cmdline_fixed_string_t value2;
1584 };
1585
1586 static int
1587 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1588 {
1589
1590         int duplex;
1591
1592         if (!strcmp(duplexstr, "half")) {
1593                 duplex = ETH_LINK_HALF_DUPLEX;
1594         } else if (!strcmp(duplexstr, "full")) {
1595                 duplex = ETH_LINK_FULL_DUPLEX;
1596         } else if (!strcmp(duplexstr, "auto")) {
1597                 duplex = ETH_LINK_FULL_DUPLEX;
1598         } else {
1599                 printf("Unknown duplex parameter\n");
1600                 return -1;
1601         }
1602
1603         if (!strcmp(speedstr, "10")) {
1604                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1605                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1606         } else if (!strcmp(speedstr, "100")) {
1607                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1608                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1609         } else {
1610                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1611                         printf("Invalid speed/duplex parameters\n");
1612                         return -1;
1613                 }
1614                 if (!strcmp(speedstr, "1000")) {
1615                         *speed = ETH_LINK_SPEED_1G;
1616                 } else if (!strcmp(speedstr, "10000")) {
1617                         *speed = ETH_LINK_SPEED_10G;
1618                 } else if (!strcmp(speedstr, "25000")) {
1619                         *speed = ETH_LINK_SPEED_25G;
1620                 } else if (!strcmp(speedstr, "40000")) {
1621                         *speed = ETH_LINK_SPEED_40G;
1622                 } else if (!strcmp(speedstr, "50000")) {
1623                         *speed = ETH_LINK_SPEED_50G;
1624                 } else if (!strcmp(speedstr, "100000")) {
1625                         *speed = ETH_LINK_SPEED_100G;
1626                 } else if (!strcmp(speedstr, "200000")) {
1627                         *speed = ETH_LINK_SPEED_200G;
1628                 } else if (!strcmp(speedstr, "auto")) {
1629                         *speed = ETH_LINK_SPEED_AUTONEG;
1630                 } else {
1631                         printf("Unknown speed parameter\n");
1632                         return -1;
1633                 }
1634         }
1635
1636         return 0;
1637 }
1638
1639 static void
1640 cmd_config_speed_all_parsed(void *parsed_result,
1641                         __rte_unused struct cmdline *cl,
1642                         __rte_unused void *data)
1643 {
1644         struct cmd_config_speed_all *res = parsed_result;
1645         uint32_t link_speed;
1646         portid_t pid;
1647
1648         if (!all_ports_stopped()) {
1649                 printf("Please stop all ports first\n");
1650                 return;
1651         }
1652
1653         if (parse_and_check_speed_duplex(res->value1, res->value2,
1654                         &link_speed) < 0)
1655                 return;
1656
1657         RTE_ETH_FOREACH_DEV(pid) {
1658                 ports[pid].dev_conf.link_speeds = link_speed;
1659         }
1660
1661         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1662 }
1663
1664 cmdline_parse_token_string_t cmd_config_speed_all_port =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1666 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1668                                                         "config");
1669 cmdline_parse_token_string_t cmd_config_speed_all_all =
1670         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1671 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1673 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1675                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1676 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1678 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1680                                                 "half#full#auto");
1681
1682 cmdline_parse_inst_t cmd_config_speed_all = {
1683         .f = cmd_config_speed_all_parsed,
1684         .data = NULL,
1685         .help_str = "port config all speed "
1686                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1687                                                         "half|full|auto",
1688         .tokens = {
1689                 (void *)&cmd_config_speed_all_port,
1690                 (void *)&cmd_config_speed_all_keyword,
1691                 (void *)&cmd_config_speed_all_all,
1692                 (void *)&cmd_config_speed_all_item1,
1693                 (void *)&cmd_config_speed_all_value1,
1694                 (void *)&cmd_config_speed_all_item2,
1695                 (void *)&cmd_config_speed_all_value2,
1696                 NULL,
1697         },
1698 };
1699
1700 /* *** configure speed for specific port *** */
1701 struct cmd_config_speed_specific {
1702         cmdline_fixed_string_t port;
1703         cmdline_fixed_string_t keyword;
1704         portid_t id;
1705         cmdline_fixed_string_t item1;
1706         cmdline_fixed_string_t item2;
1707         cmdline_fixed_string_t value1;
1708         cmdline_fixed_string_t value2;
1709 };
1710
1711 static void
1712 cmd_config_speed_specific_parsed(void *parsed_result,
1713                                 __rte_unused struct cmdline *cl,
1714                                 __rte_unused void *data)
1715 {
1716         struct cmd_config_speed_specific *res = parsed_result;
1717         uint32_t link_speed;
1718
1719         if (!all_ports_stopped()) {
1720                 printf("Please stop all ports first\n");
1721                 return;
1722         }
1723
1724         if (port_id_is_invalid(res->id, ENABLED_WARN))
1725                 return;
1726
1727         if (parse_and_check_speed_duplex(res->value1, res->value2,
1728                         &link_speed) < 0)
1729                 return;
1730
1731         ports[res->id].dev_conf.link_speeds = link_speed;
1732
1733         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1734 }
1735
1736
1737 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1738         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1739                                                                 "port");
1740 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1742                                                                 "config");
1743 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1744         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1745 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1747                                                                 "speed");
1748 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1750                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1751 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1753                                                                 "duplex");
1754 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1755         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1756                                                         "half#full#auto");
1757
1758 cmdline_parse_inst_t cmd_config_speed_specific = {
1759         .f = cmd_config_speed_specific_parsed,
1760         .data = NULL,
1761         .help_str = "port config <port_id> speed "
1762                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1763                                                         "half|full|auto",
1764         .tokens = {
1765                 (void *)&cmd_config_speed_specific_port,
1766                 (void *)&cmd_config_speed_specific_keyword,
1767                 (void *)&cmd_config_speed_specific_id,
1768                 (void *)&cmd_config_speed_specific_item1,
1769                 (void *)&cmd_config_speed_specific_value1,
1770                 (void *)&cmd_config_speed_specific_item2,
1771                 (void *)&cmd_config_speed_specific_value2,
1772                 NULL,
1773         },
1774 };
1775
1776 /* *** configure loopback for all ports *** */
1777 struct cmd_config_loopback_all {
1778         cmdline_fixed_string_t port;
1779         cmdline_fixed_string_t keyword;
1780         cmdline_fixed_string_t all;
1781         cmdline_fixed_string_t item;
1782         uint32_t mode;
1783 };
1784
1785 static void
1786 cmd_config_loopback_all_parsed(void *parsed_result,
1787                         __rte_unused struct cmdline *cl,
1788                         __rte_unused void *data)
1789 {
1790         struct cmd_config_loopback_all *res = parsed_result;
1791         portid_t pid;
1792
1793         if (!all_ports_stopped()) {
1794                 printf("Please stop all ports first\n");
1795                 return;
1796         }
1797
1798         RTE_ETH_FOREACH_DEV(pid) {
1799                 ports[pid].dev_conf.lpbk_mode = res->mode;
1800         }
1801
1802         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1803 }
1804
1805 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1807 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1809                                                         "config");
1810 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1812 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1814                                                         "loopback");
1815 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1816         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1817
1818 cmdline_parse_inst_t cmd_config_loopback_all = {
1819         .f = cmd_config_loopback_all_parsed,
1820         .data = NULL,
1821         .help_str = "port config all loopback <mode>",
1822         .tokens = {
1823                 (void *)&cmd_config_loopback_all_port,
1824                 (void *)&cmd_config_loopback_all_keyword,
1825                 (void *)&cmd_config_loopback_all_all,
1826                 (void *)&cmd_config_loopback_all_item,
1827                 (void *)&cmd_config_loopback_all_mode,
1828                 NULL,
1829         },
1830 };
1831
1832 /* *** configure loopback for specific port *** */
1833 struct cmd_config_loopback_specific {
1834         cmdline_fixed_string_t port;
1835         cmdline_fixed_string_t keyword;
1836         uint16_t port_id;
1837         cmdline_fixed_string_t item;
1838         uint32_t mode;
1839 };
1840
1841 static void
1842 cmd_config_loopback_specific_parsed(void *parsed_result,
1843                                 __rte_unused struct cmdline *cl,
1844                                 __rte_unused void *data)
1845 {
1846         struct cmd_config_loopback_specific *res = parsed_result;
1847
1848         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1849                 return;
1850
1851         if (!port_is_stopped(res->port_id)) {
1852                 printf("Please stop port %u first\n", res->port_id);
1853                 return;
1854         }
1855
1856         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1857
1858         cmd_reconfig_device_queue(res->port_id, 1, 1);
1859 }
1860
1861
1862 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1863         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1864                                                                 "port");
1865 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1866         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1867                                                                 "config");
1868 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1869         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1870                                                                 UINT16);
1871 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1872         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1873                                                                 "loopback");
1874 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1875         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1876                               UINT32);
1877
1878 cmdline_parse_inst_t cmd_config_loopback_specific = {
1879         .f = cmd_config_loopback_specific_parsed,
1880         .data = NULL,
1881         .help_str = "port config <port_id> loopback <mode>",
1882         .tokens = {
1883                 (void *)&cmd_config_loopback_specific_port,
1884                 (void *)&cmd_config_loopback_specific_keyword,
1885                 (void *)&cmd_config_loopback_specific_id,
1886                 (void *)&cmd_config_loopback_specific_item,
1887                 (void *)&cmd_config_loopback_specific_mode,
1888                 NULL,
1889         },
1890 };
1891
1892 /* *** configure txq/rxq, txd/rxd *** */
1893 struct cmd_config_rx_tx {
1894         cmdline_fixed_string_t port;
1895         cmdline_fixed_string_t keyword;
1896         cmdline_fixed_string_t all;
1897         cmdline_fixed_string_t name;
1898         uint16_t value;
1899 };
1900
1901 static void
1902 cmd_config_rx_tx_parsed(void *parsed_result,
1903                         __rte_unused struct cmdline *cl,
1904                         __rte_unused void *data)
1905 {
1906         struct cmd_config_rx_tx *res = parsed_result;
1907
1908         if (!all_ports_stopped()) {
1909                 printf("Please stop all ports first\n");
1910                 return;
1911         }
1912         if (!strcmp(res->name, "rxq")) {
1913                 if (!res->value && !nb_txq) {
1914                         printf("Warning: Either rx or tx queues should be non zero\n");
1915                         return;
1916                 }
1917                 if (check_nb_rxq(res->value) != 0)
1918                         return;
1919                 nb_rxq = res->value;
1920         }
1921         else if (!strcmp(res->name, "txq")) {
1922                 if (!res->value && !nb_rxq) {
1923                         printf("Warning: Either rx or tx queues should be non zero\n");
1924                         return;
1925                 }
1926                 if (check_nb_txq(res->value) != 0)
1927                         return;
1928                 nb_txq = res->value;
1929         }
1930         else if (!strcmp(res->name, "rxd")) {
1931                 if (check_nb_rxd(res->value) != 0)
1932                         return;
1933                 nb_rxd = res->value;
1934         } else if (!strcmp(res->name, "txd")) {
1935                 if (check_nb_txd(res->value) != 0)
1936                         return;
1937
1938                 nb_txd = res->value;
1939         } else {
1940                 printf("Unknown parameter\n");
1941                 return;
1942         }
1943
1944         fwd_config_setup();
1945
1946         init_port_config();
1947
1948         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1949 }
1950
1951 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1952         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1953 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1954         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1955 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1956         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1957 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1958         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1959                                                 "rxq#txq#rxd#txd");
1960 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1961         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1962
1963 cmdline_parse_inst_t cmd_config_rx_tx = {
1964         .f = cmd_config_rx_tx_parsed,
1965         .data = NULL,
1966         .help_str = "port config all rxq|txq|rxd|txd <value>",
1967         .tokens = {
1968                 (void *)&cmd_config_rx_tx_port,
1969                 (void *)&cmd_config_rx_tx_keyword,
1970                 (void *)&cmd_config_rx_tx_all,
1971                 (void *)&cmd_config_rx_tx_name,
1972                 (void *)&cmd_config_rx_tx_value,
1973                 NULL,
1974         },
1975 };
1976
1977 /* *** config max packet length *** */
1978 struct cmd_config_max_pkt_len_result {
1979         cmdline_fixed_string_t port;
1980         cmdline_fixed_string_t keyword;
1981         cmdline_fixed_string_t all;
1982         cmdline_fixed_string_t name;
1983         uint32_t value;
1984 };
1985
1986 static void
1987 cmd_config_max_pkt_len_parsed(void *parsed_result,
1988                                 __rte_unused struct cmdline *cl,
1989                                 __rte_unused void *data)
1990 {
1991         struct cmd_config_max_pkt_len_result *res = parsed_result;
1992         portid_t pid;
1993
1994         if (!all_ports_stopped()) {
1995                 printf("Please stop all ports first\n");
1996                 return;
1997         }
1998
1999         RTE_ETH_FOREACH_DEV(pid) {
2000                 struct rte_port *port = &ports[pid];
2001                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2002
2003                 if (!strcmp(res->name, "max-pkt-len")) {
2004                         if (res->value < RTE_ETHER_MIN_LEN) {
2005                                 printf("max-pkt-len can not be less than %d\n",
2006                                                 RTE_ETHER_MIN_LEN);
2007                                 return;
2008                         }
2009                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2010                                 return;
2011
2012                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2013                         if (res->value > RTE_ETHER_MAX_LEN)
2014                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2015                         else
2016                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2017                         port->dev_conf.rxmode.offloads = rx_offloads;
2018                 } else {
2019                         printf("Unknown parameter\n");
2020                         return;
2021                 }
2022         }
2023
2024         init_port_config();
2025
2026         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2027 }
2028
2029 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2030         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2031                                                                 "port");
2032 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2033         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2034                                                                 "config");
2035 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2036         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2037                                                                 "all");
2038 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2039         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2040                                                                 "max-pkt-len");
2041 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2042         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2043                                                                 UINT32);
2044
2045 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2046         .f = cmd_config_max_pkt_len_parsed,
2047         .data = NULL,
2048         .help_str = "port config all max-pkt-len <value>",
2049         .tokens = {
2050                 (void *)&cmd_config_max_pkt_len_port,
2051                 (void *)&cmd_config_max_pkt_len_keyword,
2052                 (void *)&cmd_config_max_pkt_len_all,
2053                 (void *)&cmd_config_max_pkt_len_name,
2054                 (void *)&cmd_config_max_pkt_len_value,
2055                 NULL,
2056         },
2057 };
2058
2059 /* *** config max LRO aggregated packet size *** */
2060 struct cmd_config_max_lro_pkt_size_result {
2061         cmdline_fixed_string_t port;
2062         cmdline_fixed_string_t keyword;
2063         cmdline_fixed_string_t all;
2064         cmdline_fixed_string_t name;
2065         uint32_t value;
2066 };
2067
2068 static void
2069 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2070                                 __rte_unused struct cmdline *cl,
2071                                 __rte_unused void *data)
2072 {
2073         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2074         portid_t pid;
2075
2076         if (!all_ports_stopped()) {
2077                 printf("Please stop all ports first\n");
2078                 return;
2079         }
2080
2081         RTE_ETH_FOREACH_DEV(pid) {
2082                 struct rte_port *port = &ports[pid];
2083
2084                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2085                         if (res->value ==
2086                                         port->dev_conf.rxmode.max_lro_pkt_size)
2087                                 return;
2088
2089                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2090                 } else {
2091                         printf("Unknown parameter\n");
2092                         return;
2093                 }
2094         }
2095
2096         init_port_config();
2097
2098         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2099 }
2100
2101 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2102         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2103                                  port, "port");
2104 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2105         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2106                                  keyword, "config");
2107 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2108         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2109                                  all, "all");
2110 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2111         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2112                                  name, "max-lro-pkt-size");
2113 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2114         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2115                               value, UINT32);
2116
2117 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2118         .f = cmd_config_max_lro_pkt_size_parsed,
2119         .data = NULL,
2120         .help_str = "port config all max-lro-pkt-size <value>",
2121         .tokens = {
2122                 (void *)&cmd_config_max_lro_pkt_size_port,
2123                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2124                 (void *)&cmd_config_max_lro_pkt_size_all,
2125                 (void *)&cmd_config_max_lro_pkt_size_name,
2126                 (void *)&cmd_config_max_lro_pkt_size_value,
2127                 NULL,
2128         },
2129 };
2130
2131 /* *** configure port MTU *** */
2132 struct cmd_config_mtu_result {
2133         cmdline_fixed_string_t port;
2134         cmdline_fixed_string_t keyword;
2135         cmdline_fixed_string_t mtu;
2136         portid_t port_id;
2137         uint16_t value;
2138 };
2139
2140 static void
2141 cmd_config_mtu_parsed(void *parsed_result,
2142                       __rte_unused struct cmdline *cl,
2143                       __rte_unused void *data)
2144 {
2145         struct cmd_config_mtu_result *res = parsed_result;
2146
2147         if (res->value < RTE_ETHER_MIN_LEN) {
2148                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2149                 return;
2150         }
2151         port_mtu_set(res->port_id, res->value);
2152 }
2153
2154 cmdline_parse_token_string_t cmd_config_mtu_port =
2155         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2156                                  "port");
2157 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2158         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2159                                  "config");
2160 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2161         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2162                                  "mtu");
2163 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2164         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2165 cmdline_parse_token_num_t cmd_config_mtu_value =
2166         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2167
2168 cmdline_parse_inst_t cmd_config_mtu = {
2169         .f = cmd_config_mtu_parsed,
2170         .data = NULL,
2171         .help_str = "port config mtu <port_id> <value>",
2172         .tokens = {
2173                 (void *)&cmd_config_mtu_port,
2174                 (void *)&cmd_config_mtu_keyword,
2175                 (void *)&cmd_config_mtu_mtu,
2176                 (void *)&cmd_config_mtu_port_id,
2177                 (void *)&cmd_config_mtu_value,
2178                 NULL,
2179         },
2180 };
2181
2182 /* *** configure rx mode *** */
2183 struct cmd_config_rx_mode_flag {
2184         cmdline_fixed_string_t port;
2185         cmdline_fixed_string_t keyword;
2186         cmdline_fixed_string_t all;
2187         cmdline_fixed_string_t name;
2188         cmdline_fixed_string_t value;
2189 };
2190
2191 static void
2192 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2193                                 __rte_unused struct cmdline *cl,
2194                                 __rte_unused void *data)
2195 {
2196         struct cmd_config_rx_mode_flag *res = parsed_result;
2197
2198         if (!all_ports_stopped()) {
2199                 printf("Please stop all ports first\n");
2200                 return;
2201         }
2202
2203         if (!strcmp(res->name, "drop-en")) {
2204                 if (!strcmp(res->value, "on"))
2205                         rx_drop_en = 1;
2206                 else if (!strcmp(res->value, "off"))
2207                         rx_drop_en = 0;
2208                 else {
2209                         printf("Unknown parameter\n");
2210                         return;
2211                 }
2212         } else {
2213                 printf("Unknown parameter\n");
2214                 return;
2215         }
2216
2217         init_port_config();
2218
2219         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2220 }
2221
2222 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2223         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2226                                                                 "config");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2230         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2231                                         "drop-en");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2233         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2234                                                         "on#off");
2235
2236 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2237         .f = cmd_config_rx_mode_flag_parsed,
2238         .data = NULL,
2239         .help_str = "port config all drop-en on|off",
2240         .tokens = {
2241                 (void *)&cmd_config_rx_mode_flag_port,
2242                 (void *)&cmd_config_rx_mode_flag_keyword,
2243                 (void *)&cmd_config_rx_mode_flag_all,
2244                 (void *)&cmd_config_rx_mode_flag_name,
2245                 (void *)&cmd_config_rx_mode_flag_value,
2246                 NULL,
2247         },
2248 };
2249
2250 /* *** configure rss *** */
2251 struct cmd_config_rss {
2252         cmdline_fixed_string_t port;
2253         cmdline_fixed_string_t keyword;
2254         cmdline_fixed_string_t all;
2255         cmdline_fixed_string_t name;
2256         cmdline_fixed_string_t value;
2257 };
2258
2259 static void
2260 cmd_config_rss_parsed(void *parsed_result,
2261                         __rte_unused struct cmdline *cl,
2262                         __rte_unused void *data)
2263 {
2264         struct cmd_config_rss *res = parsed_result;
2265         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2266         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2267         int use_default = 0;
2268         int all_updated = 1;
2269         int diag;
2270         uint16_t i;
2271         int ret;
2272
2273         if (!strcmp(res->value, "all"))
2274                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2275                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2276                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2277                         ETH_RSS_AH | ETH_RSS_PFCP;
2278         else if (!strcmp(res->value, "eth"))
2279                 rss_conf.rss_hf = ETH_RSS_ETH;
2280         else if (!strcmp(res->value, "vlan"))
2281                 rss_conf.rss_hf = ETH_RSS_VLAN;
2282         else if (!strcmp(res->value, "ip"))
2283                 rss_conf.rss_hf = ETH_RSS_IP;
2284         else if (!strcmp(res->value, "udp"))
2285                 rss_conf.rss_hf = ETH_RSS_UDP;
2286         else if (!strcmp(res->value, "tcp"))
2287                 rss_conf.rss_hf = ETH_RSS_TCP;
2288         else if (!strcmp(res->value, "sctp"))
2289                 rss_conf.rss_hf = ETH_RSS_SCTP;
2290         else if (!strcmp(res->value, "ether"))
2291                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2292         else if (!strcmp(res->value, "port"))
2293                 rss_conf.rss_hf = ETH_RSS_PORT;
2294         else if (!strcmp(res->value, "vxlan"))
2295                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2296         else if (!strcmp(res->value, "geneve"))
2297                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2298         else if (!strcmp(res->value, "nvgre"))
2299                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2300         else if (!strcmp(res->value, "l3-src-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2302         else if (!strcmp(res->value, "l3-dst-only"))
2303                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2304         else if (!strcmp(res->value, "l4-src-only"))
2305                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2306         else if (!strcmp(res->value, "l4-dst-only"))
2307                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2308         else if (!strcmp(res->value, "l2-src-only"))
2309                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2310         else if (!strcmp(res->value, "l2-dst-only"))
2311                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2312         else if (!strcmp(res->value, "l2tpv3"))
2313                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2314         else if (!strcmp(res->value, "esp"))
2315                 rss_conf.rss_hf = ETH_RSS_ESP;
2316         else if (!strcmp(res->value, "ah"))
2317                 rss_conf.rss_hf = ETH_RSS_AH;
2318         else if (!strcmp(res->value, "pfcp"))
2319                 rss_conf.rss_hf = ETH_RSS_PFCP;
2320         else if (!strcmp(res->value, "pppoe"))
2321                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2322         else if (!strcmp(res->value, "none"))
2323                 rss_conf.rss_hf = 0;
2324         else if (!strcmp(res->value, "default"))
2325                 use_default = 1;
2326         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2327                                                 atoi(res->value) < 64)
2328                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2329         else {
2330                 printf("Unknown parameter\n");
2331                 return;
2332         }
2333         rss_conf.rss_key = NULL;
2334         /* Update global configuration for RSS types. */
2335         RTE_ETH_FOREACH_DEV(i) {
2336                 struct rte_eth_rss_conf local_rss_conf;
2337
2338                 ret = eth_dev_info_get_print_err(i, &dev_info);
2339                 if (ret != 0)
2340                         return;
2341
2342                 if (use_default)
2343                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2344
2345                 local_rss_conf = rss_conf;
2346                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2347                         dev_info.flow_type_rss_offloads;
2348                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2349                         printf("Port %u modified RSS hash function based on hardware support,"
2350                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2351                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2352                 }
2353                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2354                 if (diag < 0) {
2355                         all_updated = 0;
2356                         printf("Configuration of RSS hash at ethernet port %d "
2357                                 "failed with error (%d): %s.\n",
2358                                 i, -diag, strerror(-diag));
2359                 }
2360         }
2361         if (all_updated && !use_default) {
2362                 rss_hf = rss_conf.rss_hf;
2363                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2364         }
2365 }
2366
2367 cmdline_parse_token_string_t cmd_config_rss_port =
2368         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2369 cmdline_parse_token_string_t cmd_config_rss_keyword =
2370         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2371 cmdline_parse_token_string_t cmd_config_rss_all =
2372         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2373 cmdline_parse_token_string_t cmd_config_rss_name =
2374         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2375 cmdline_parse_token_string_t cmd_config_rss_value =
2376         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2377
2378 cmdline_parse_inst_t cmd_config_rss = {
2379         .f = cmd_config_rss_parsed,
2380         .data = NULL,
2381         .help_str = "port config all rss "
2382                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2383                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2384         .tokens = {
2385                 (void *)&cmd_config_rss_port,
2386                 (void *)&cmd_config_rss_keyword,
2387                 (void *)&cmd_config_rss_all,
2388                 (void *)&cmd_config_rss_name,
2389                 (void *)&cmd_config_rss_value,
2390                 NULL,
2391         },
2392 };
2393
2394 /* *** configure rss hash key *** */
2395 struct cmd_config_rss_hash_key {
2396         cmdline_fixed_string_t port;
2397         cmdline_fixed_string_t config;
2398         portid_t port_id;
2399         cmdline_fixed_string_t rss_hash_key;
2400         cmdline_fixed_string_t rss_type;
2401         cmdline_fixed_string_t key;
2402 };
2403
2404 static uint8_t
2405 hexa_digit_to_value(char hexa_digit)
2406 {
2407         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2408                 return (uint8_t) (hexa_digit - '0');
2409         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2410                 return (uint8_t) ((hexa_digit - 'a') + 10);
2411         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2412                 return (uint8_t) ((hexa_digit - 'A') + 10);
2413         /* Invalid hexa digit */
2414         return 0xFF;
2415 }
2416
2417 static uint8_t
2418 parse_and_check_key_hexa_digit(char *key, int idx)
2419 {
2420         uint8_t hexa_v;
2421
2422         hexa_v = hexa_digit_to_value(key[idx]);
2423         if (hexa_v == 0xFF)
2424                 printf("invalid key: character %c at position %d is not a "
2425                        "valid hexa digit\n", key[idx], idx);
2426         return hexa_v;
2427 }
2428
2429 static void
2430 cmd_config_rss_hash_key_parsed(void *parsed_result,
2431                                __rte_unused struct cmdline *cl,
2432                                __rte_unused void *data)
2433 {
2434         struct cmd_config_rss_hash_key *res = parsed_result;
2435         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2436         uint8_t xdgt0;
2437         uint8_t xdgt1;
2438         int i;
2439         struct rte_eth_dev_info dev_info;
2440         uint8_t hash_key_size;
2441         uint32_t key_len;
2442         int ret;
2443
2444         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2445         if (ret != 0)
2446                 return;
2447
2448         if (dev_info.hash_key_size > 0 &&
2449                         dev_info.hash_key_size <= sizeof(hash_key))
2450                 hash_key_size = dev_info.hash_key_size;
2451         else {
2452                 printf("dev_info did not provide a valid hash key size\n");
2453                 return;
2454         }
2455         /* Check the length of the RSS hash key */
2456         key_len = strlen(res->key);
2457         if (key_len != (hash_key_size * 2)) {
2458                 printf("key length: %d invalid - key must be a string of %d"
2459                            " hexa-decimal numbers\n",
2460                            (int) key_len, hash_key_size * 2);
2461                 return;
2462         }
2463         /* Translate RSS hash key into binary representation */
2464         for (i = 0; i < hash_key_size; i++) {
2465                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2466                 if (xdgt0 == 0xFF)
2467                         return;
2468                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2469                 if (xdgt1 == 0xFF)
2470                         return;
2471                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2472         }
2473         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2474                         hash_key_size);
2475 }
2476
2477 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2478         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2479 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2480         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2481                                  "config");
2482 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2483         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2484 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2485         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2486                                  rss_hash_key, "rss-hash-key");
2487 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2488         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2489                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2490                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2491                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2492                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2493                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2494                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2495                                  "l2tpv3#esp#ah#pfcp#pppoe");
2496 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2498
2499 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2500         .f = cmd_config_rss_hash_key_parsed,
2501         .data = NULL,
2502         .help_str = "port config <port_id> rss-hash-key "
2503                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2504                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2505                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2506                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2507                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2508                 "l2tpv3|esp|ah|pfcp|pppoe "
2509                 "<string of hex digits (variable length, NIC dependent)>",
2510         .tokens = {
2511                 (void *)&cmd_config_rss_hash_key_port,
2512                 (void *)&cmd_config_rss_hash_key_config,
2513                 (void *)&cmd_config_rss_hash_key_port_id,
2514                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2515                 (void *)&cmd_config_rss_hash_key_rss_type,
2516                 (void *)&cmd_config_rss_hash_key_value,
2517                 NULL,
2518         },
2519 };
2520
2521 /* *** configure port rxq/txq ring size *** */
2522 struct cmd_config_rxtx_ring_size {
2523         cmdline_fixed_string_t port;
2524         cmdline_fixed_string_t config;
2525         portid_t portid;
2526         cmdline_fixed_string_t rxtxq;
2527         uint16_t qid;
2528         cmdline_fixed_string_t rsize;
2529         uint16_t size;
2530 };
2531
2532 static void
2533 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2534                                  __rte_unused struct cmdline *cl,
2535                                  __rte_unused void *data)
2536 {
2537         struct cmd_config_rxtx_ring_size *res = parsed_result;
2538         struct rte_port *port;
2539         uint8_t isrx;
2540
2541         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2542                 return;
2543
2544         if (res->portid == (portid_t)RTE_PORT_ALL) {
2545                 printf("Invalid port id\n");
2546                 return;
2547         }
2548
2549         port = &ports[res->portid];
2550
2551         if (!strcmp(res->rxtxq, "rxq"))
2552                 isrx = 1;
2553         else if (!strcmp(res->rxtxq, "txq"))
2554                 isrx = 0;
2555         else {
2556                 printf("Unknown parameter\n");
2557                 return;
2558         }
2559
2560         if (isrx && rx_queue_id_is_invalid(res->qid))
2561                 return;
2562         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2563                 return;
2564
2565         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2566                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2567                        rx_free_thresh);
2568                 return;
2569         }
2570
2571         if (isrx)
2572                 port->nb_rx_desc[res->qid] = res->size;
2573         else
2574                 port->nb_tx_desc[res->qid] = res->size;
2575
2576         cmd_reconfig_device_queue(res->portid, 0, 1);
2577 }
2578
2579 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2580         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2581                                  port, "port");
2582 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2583         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2584                                  config, "config");
2585 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2586         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2587                                  portid, UINT16);
2588 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2589         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2590                                  rxtxq, "rxq#txq");
2591 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2592         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2593                               qid, UINT16);
2594 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2595         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2596                                  rsize, "ring_size");
2597 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2598         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2599                               size, UINT16);
2600
2601 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2602         .f = cmd_config_rxtx_ring_size_parsed,
2603         .data = NULL,
2604         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2605         .tokens = {
2606                 (void *)&cmd_config_rxtx_ring_size_port,
2607                 (void *)&cmd_config_rxtx_ring_size_config,
2608                 (void *)&cmd_config_rxtx_ring_size_portid,
2609                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2610                 (void *)&cmd_config_rxtx_ring_size_qid,
2611                 (void *)&cmd_config_rxtx_ring_size_rsize,
2612                 (void *)&cmd_config_rxtx_ring_size_size,
2613                 NULL,
2614         },
2615 };
2616
2617 /* *** configure port rxq/txq start/stop *** */
2618 struct cmd_config_rxtx_queue {
2619         cmdline_fixed_string_t port;
2620         portid_t portid;
2621         cmdline_fixed_string_t rxtxq;
2622         uint16_t qid;
2623         cmdline_fixed_string_t opname;
2624 };
2625
2626 static void
2627 cmd_config_rxtx_queue_parsed(void *parsed_result,
2628                         __rte_unused struct cmdline *cl,
2629                         __rte_unused void *data)
2630 {
2631         struct cmd_config_rxtx_queue *res = parsed_result;
2632         uint8_t isrx;
2633         uint8_t isstart;
2634         int ret = 0;
2635
2636         if (test_done == 0) {
2637                 printf("Please stop forwarding first\n");
2638                 return;
2639         }
2640
2641         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2642                 return;
2643
2644         if (port_is_started(res->portid) != 1) {
2645                 printf("Please start port %u first\n", res->portid);
2646                 return;
2647         }
2648
2649         if (!strcmp(res->rxtxq, "rxq"))
2650                 isrx = 1;
2651         else if (!strcmp(res->rxtxq, "txq"))
2652                 isrx = 0;
2653         else {
2654                 printf("Unknown parameter\n");
2655                 return;
2656         }
2657
2658         if (isrx && rx_queue_id_is_invalid(res->qid))
2659                 return;
2660         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2661                 return;
2662
2663         if (!strcmp(res->opname, "start"))
2664                 isstart = 1;
2665         else if (!strcmp(res->opname, "stop"))
2666                 isstart = 0;
2667         else {
2668                 printf("Unknown parameter\n");
2669                 return;
2670         }
2671
2672         if (isstart && isrx)
2673                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2674         else if (!isstart && isrx)
2675                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2676         else if (isstart && !isrx)
2677                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2678         else
2679                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2680
2681         if (ret == -ENOTSUP)
2682                 printf("Function not supported in PMD driver\n");
2683 }
2684
2685 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2686         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2687 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2688         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2689 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2690         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2691 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2692         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2693 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2695                                                 "start#stop");
2696
2697 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2698         .f = cmd_config_rxtx_queue_parsed,
2699         .data = NULL,
2700         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2701         .tokens = {
2702                 (void *)&cmd_config_rxtx_queue_port,
2703                 (void *)&cmd_config_rxtx_queue_portid,
2704                 (void *)&cmd_config_rxtx_queue_rxtxq,
2705                 (void *)&cmd_config_rxtx_queue_qid,
2706                 (void *)&cmd_config_rxtx_queue_opname,
2707                 NULL,
2708         },
2709 };
2710
2711 /* *** configure port rxq/txq deferred start on/off *** */
2712 struct cmd_config_deferred_start_rxtx_queue {
2713         cmdline_fixed_string_t port;
2714         portid_t port_id;
2715         cmdline_fixed_string_t rxtxq;
2716         uint16_t qid;
2717         cmdline_fixed_string_t opname;
2718         cmdline_fixed_string_t state;
2719 };
2720
2721 static void
2722 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2723                         __rte_unused struct cmdline *cl,
2724                         __rte_unused void *data)
2725 {
2726         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2727         struct rte_port *port;
2728         uint8_t isrx;
2729         uint8_t ison;
2730         uint8_t needreconfig = 0;
2731
2732         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2733                 return;
2734
2735         if (port_is_started(res->port_id) != 0) {
2736                 printf("Please stop port %u first\n", res->port_id);
2737                 return;
2738         }
2739
2740         port = &ports[res->port_id];
2741
2742         isrx = !strcmp(res->rxtxq, "rxq");
2743
2744         if (isrx && rx_queue_id_is_invalid(res->qid))
2745                 return;
2746         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2747                 return;
2748
2749         ison = !strcmp(res->state, "on");
2750
2751         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2752                 port->rx_conf[res->qid].rx_deferred_start = ison;
2753                 needreconfig = 1;
2754         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2755                 port->tx_conf[res->qid].tx_deferred_start = ison;
2756                 needreconfig = 1;
2757         }
2758
2759         if (needreconfig)
2760                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2761 }
2762
2763 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2764         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2765                                                 port, "port");
2766 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2767         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2768                                                 port_id, UINT16);
2769 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2770         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2771                                                 rxtxq, "rxq#txq");
2772 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2773         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2774                                                 qid, UINT16);
2775 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2776         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2777                                                 opname, "deferred_start");
2778 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2779         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2780                                                 state, "on#off");
2781
2782 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2783         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2784         .data = NULL,
2785         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2786         .tokens = {
2787                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2788                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2789                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2790                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2791                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2792                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2793                 NULL,
2794         },
2795 };
2796
2797 /* *** configure port rxq/txq setup *** */
2798 struct cmd_setup_rxtx_queue {
2799         cmdline_fixed_string_t port;
2800         portid_t portid;
2801         cmdline_fixed_string_t rxtxq;
2802         uint16_t qid;
2803         cmdline_fixed_string_t setup;
2804 };
2805
2806 /* Common CLI fields for queue setup */
2807 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2808         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2809 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2810         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2811 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2812         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2813 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2814         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2815 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2816         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2817
2818 static void
2819 cmd_setup_rxtx_queue_parsed(
2820         void *parsed_result,
2821         __rte_unused struct cmdline *cl,
2822         __rte_unused void *data)
2823 {
2824         struct cmd_setup_rxtx_queue *res = parsed_result;
2825         struct rte_port *port;
2826         struct rte_mempool *mp;
2827         unsigned int socket_id;
2828         uint8_t isrx = 0;
2829         int ret;
2830
2831         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2832                 return;
2833
2834         if (res->portid == (portid_t)RTE_PORT_ALL) {
2835                 printf("Invalid port id\n");
2836                 return;
2837         }
2838
2839         if (!strcmp(res->rxtxq, "rxq"))
2840                 isrx = 1;
2841         else if (!strcmp(res->rxtxq, "txq"))
2842                 isrx = 0;
2843         else {
2844                 printf("Unknown parameter\n");
2845                 return;
2846         }
2847
2848         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2849                 printf("Invalid rx queue\n");
2850                 return;
2851         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2852                 printf("Invalid tx queue\n");
2853                 return;
2854         }
2855
2856         port = &ports[res->portid];
2857         if (isrx) {
2858                 socket_id = rxring_numa[res->portid];
2859                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2860                         socket_id = port->socket_id;
2861
2862                 mp = mbuf_pool_find(socket_id);
2863                 if (mp == NULL) {
2864                         printf("Failed to setup RX queue: "
2865                                 "No mempool allocation"
2866                                 " on the socket %d\n",
2867                                 rxring_numa[res->portid]);
2868                         return;
2869                 }
2870                 ret = rte_eth_rx_queue_setup(res->portid,
2871                                              res->qid,
2872                                              port->nb_rx_desc[res->qid],
2873                                              socket_id,
2874                                              &port->rx_conf[res->qid],
2875                                              mp);
2876                 if (ret)
2877                         printf("Failed to setup RX queue\n");
2878         } else {
2879                 socket_id = txring_numa[res->portid];
2880                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2881                         socket_id = port->socket_id;
2882
2883                 ret = rte_eth_tx_queue_setup(res->portid,
2884                                              res->qid,
2885                                              port->nb_tx_desc[res->qid],
2886                                              socket_id,
2887                                              &port->tx_conf[res->qid]);
2888                 if (ret)
2889                         printf("Failed to setup TX queue\n");
2890         }
2891 }
2892
2893 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2894         .f = cmd_setup_rxtx_queue_parsed,
2895         .data = NULL,
2896         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2897         .tokens = {
2898                 (void *)&cmd_setup_rxtx_queue_port,
2899                 (void *)&cmd_setup_rxtx_queue_portid,
2900                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2901                 (void *)&cmd_setup_rxtx_queue_qid,
2902                 (void *)&cmd_setup_rxtx_queue_setup,
2903                 NULL,
2904         },
2905 };
2906
2907
2908 /* *** Configure RSS RETA *** */
2909 struct cmd_config_rss_reta {
2910         cmdline_fixed_string_t port;
2911         cmdline_fixed_string_t keyword;
2912         portid_t port_id;
2913         cmdline_fixed_string_t name;
2914         cmdline_fixed_string_t list_name;
2915         cmdline_fixed_string_t list_of_items;
2916 };
2917
2918 static int
2919 parse_reta_config(const char *str,
2920                   struct rte_eth_rss_reta_entry64 *reta_conf,
2921                   uint16_t nb_entries)
2922 {
2923         int i;
2924         unsigned size;
2925         uint16_t hash_index, idx, shift;
2926         uint16_t nb_queue;
2927         char s[256];
2928         const char *p, *p0 = str;
2929         char *end;
2930         enum fieldnames {
2931                 FLD_HASH_INDEX = 0,
2932                 FLD_QUEUE,
2933                 _NUM_FLD
2934         };
2935         unsigned long int_fld[_NUM_FLD];
2936         char *str_fld[_NUM_FLD];
2937
2938         while ((p = strchr(p0,'(')) != NULL) {
2939                 ++p;
2940                 if((p0 = strchr(p,')')) == NULL)
2941                         return -1;
2942
2943                 size = p0 - p;
2944                 if(size >= sizeof(s))
2945                         return -1;
2946
2947                 snprintf(s, sizeof(s), "%.*s", size, p);
2948                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2949                         return -1;
2950                 for (i = 0; i < _NUM_FLD; i++) {
2951                         errno = 0;
2952                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2953                         if (errno != 0 || end == str_fld[i] ||
2954                                         int_fld[i] > 65535)
2955                                 return -1;
2956                 }
2957
2958                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2959                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2960
2961                 if (hash_index >= nb_entries) {
2962                         printf("Invalid RETA hash index=%d\n", hash_index);
2963                         return -1;
2964                 }
2965
2966                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2967                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2968                 reta_conf[idx].mask |= (1ULL << shift);
2969                 reta_conf[idx].reta[shift] = nb_queue;
2970         }
2971
2972         return 0;
2973 }
2974
2975 static void
2976 cmd_set_rss_reta_parsed(void *parsed_result,
2977                         __rte_unused struct cmdline *cl,
2978                         __rte_unused void *data)
2979 {
2980         int ret;
2981         struct rte_eth_dev_info dev_info;
2982         struct rte_eth_rss_reta_entry64 reta_conf[8];
2983         struct cmd_config_rss_reta *res = parsed_result;
2984
2985         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2986         if (ret != 0)
2987                 return;
2988
2989         if (dev_info.reta_size == 0) {
2990                 printf("Redirection table size is 0 which is "
2991                                         "invalid for RSS\n");
2992                 return;
2993         } else
2994                 printf("The reta size of port %d is %u\n",
2995                         res->port_id, dev_info.reta_size);
2996         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2997                 printf("Currently do not support more than %u entries of "
2998                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2999                 return;
3000         }
3001
3002         memset(reta_conf, 0, sizeof(reta_conf));
3003         if (!strcmp(res->list_name, "reta")) {
3004                 if (parse_reta_config(res->list_of_items, reta_conf,
3005                                                 dev_info.reta_size)) {
3006                         printf("Invalid RSS Redirection Table "
3007                                         "config entered\n");
3008                         return;
3009                 }
3010                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3011                                 reta_conf, dev_info.reta_size);
3012                 if (ret != 0)
3013                         printf("Bad redirection table parameter, "
3014                                         "return code = %d \n", ret);
3015         }
3016 }
3017
3018 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3019         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3020 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3021         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3022 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3023         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3024 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3025         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3026 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3028 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3029         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3030                                  NULL);
3031 cmdline_parse_inst_t cmd_config_rss_reta = {
3032         .f = cmd_set_rss_reta_parsed,
3033         .data = NULL,
3034         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3035         .tokens = {
3036                 (void *)&cmd_config_rss_reta_port,
3037                 (void *)&cmd_config_rss_reta_keyword,
3038                 (void *)&cmd_config_rss_reta_port_id,
3039                 (void *)&cmd_config_rss_reta_name,
3040                 (void *)&cmd_config_rss_reta_list_name,
3041                 (void *)&cmd_config_rss_reta_list_of_items,
3042                 NULL,
3043         },
3044 };
3045
3046 /* *** SHOW PORT RETA INFO *** */
3047 struct cmd_showport_reta {
3048         cmdline_fixed_string_t show;
3049         cmdline_fixed_string_t port;
3050         portid_t port_id;
3051         cmdline_fixed_string_t rss;
3052         cmdline_fixed_string_t reta;
3053         uint16_t size;
3054         cmdline_fixed_string_t list_of_items;
3055 };
3056
3057 static int
3058 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3059                            uint16_t nb_entries,
3060                            char *str)
3061 {
3062         uint32_t size;
3063         const char *p, *p0 = str;
3064         char s[256];
3065         char *end;
3066         char *str_fld[8];
3067         uint16_t i;
3068         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3069                         RTE_RETA_GROUP_SIZE;
3070         int ret;
3071
3072         p = strchr(p0, '(');
3073         if (p == NULL)
3074                 return -1;
3075         p++;
3076         p0 = strchr(p, ')');
3077         if (p0 == NULL)
3078                 return -1;
3079         size = p0 - p;
3080         if (size >= sizeof(s)) {
3081                 printf("The string size exceeds the internal buffer size\n");
3082                 return -1;
3083         }
3084         snprintf(s, sizeof(s), "%.*s", size, p);
3085         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3086         if (ret <= 0 || ret != num) {
3087                 printf("The bits of masks do not match the number of "
3088                                         "reta entries: %u\n", num);
3089                 return -1;
3090         }
3091         for (i = 0; i < ret; i++)
3092                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3093
3094         return 0;
3095 }
3096
3097 static void
3098 cmd_showport_reta_parsed(void *parsed_result,
3099                          __rte_unused struct cmdline *cl,
3100                          __rte_unused void *data)
3101 {
3102         struct cmd_showport_reta *res = parsed_result;
3103         struct rte_eth_rss_reta_entry64 reta_conf[8];
3104         struct rte_eth_dev_info dev_info;
3105         uint16_t max_reta_size;
3106         int ret;
3107
3108         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3109         if (ret != 0)
3110                 return;
3111
3112         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3113         if (res->size == 0 || res->size > max_reta_size) {
3114                 printf("Invalid redirection table size: %u (1-%u)\n",
3115                         res->size, max_reta_size);
3116                 return;
3117         }
3118
3119         memset(reta_conf, 0, sizeof(reta_conf));
3120         if (showport_parse_reta_config(reta_conf, res->size,
3121                                 res->list_of_items) < 0) {
3122                 printf("Invalid string: %s for reta masks\n",
3123                                         res->list_of_items);
3124                 return;
3125         }
3126         port_rss_reta_info(res->port_id, reta_conf, res->size);
3127 }
3128
3129 cmdline_parse_token_string_t cmd_showport_reta_show =
3130         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3131 cmdline_parse_token_string_t cmd_showport_reta_port =
3132         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3133 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3134         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3135 cmdline_parse_token_string_t cmd_showport_reta_rss =
3136         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3137 cmdline_parse_token_string_t cmd_showport_reta_reta =
3138         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3139 cmdline_parse_token_num_t cmd_showport_reta_size =
3140         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3141 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3142         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3143                                         list_of_items, NULL);
3144
3145 cmdline_parse_inst_t cmd_showport_reta = {
3146         .f = cmd_showport_reta_parsed,
3147         .data = NULL,
3148         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3149         .tokens = {
3150                 (void *)&cmd_showport_reta_show,
3151                 (void *)&cmd_showport_reta_port,
3152                 (void *)&cmd_showport_reta_port_id,
3153                 (void *)&cmd_showport_reta_rss,
3154                 (void *)&cmd_showport_reta_reta,
3155                 (void *)&cmd_showport_reta_size,
3156                 (void *)&cmd_showport_reta_list_of_items,
3157                 NULL,
3158         },
3159 };
3160
3161 /* *** Show RSS hash configuration *** */
3162 struct cmd_showport_rss_hash {
3163         cmdline_fixed_string_t show;
3164         cmdline_fixed_string_t port;
3165         portid_t port_id;
3166         cmdline_fixed_string_t rss_hash;
3167         cmdline_fixed_string_t rss_type;
3168         cmdline_fixed_string_t key; /* optional argument */
3169 };
3170
3171 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3172                                 __rte_unused struct cmdline *cl,
3173                                 void *show_rss_key)
3174 {
3175         struct cmd_showport_rss_hash *res = parsed_result;
3176
3177         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3178 }
3179
3180 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3181         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3182 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3183         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3184 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3185         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3186 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3187         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3188                                  "rss-hash");
3189 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3190         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3191
3192 cmdline_parse_inst_t cmd_showport_rss_hash = {
3193         .f = cmd_showport_rss_hash_parsed,
3194         .data = NULL,
3195         .help_str = "show port <port_id> rss-hash",
3196         .tokens = {
3197                 (void *)&cmd_showport_rss_hash_show,
3198                 (void *)&cmd_showport_rss_hash_port,
3199                 (void *)&cmd_showport_rss_hash_port_id,
3200                 (void *)&cmd_showport_rss_hash_rss_hash,
3201                 NULL,
3202         },
3203 };
3204
3205 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3206         .f = cmd_showport_rss_hash_parsed,
3207         .data = (void *)1,
3208         .help_str = "show port <port_id> rss-hash key",
3209         .tokens = {
3210                 (void *)&cmd_showport_rss_hash_show,
3211                 (void *)&cmd_showport_rss_hash_port,
3212                 (void *)&cmd_showport_rss_hash_port_id,
3213                 (void *)&cmd_showport_rss_hash_rss_hash,
3214                 (void *)&cmd_showport_rss_hash_rss_key,
3215                 NULL,
3216         },
3217 };
3218
3219 /* *** Configure DCB *** */
3220 struct cmd_config_dcb {
3221         cmdline_fixed_string_t port;
3222         cmdline_fixed_string_t config;
3223         portid_t port_id;
3224         cmdline_fixed_string_t dcb;
3225         cmdline_fixed_string_t vt;
3226         cmdline_fixed_string_t vt_en;
3227         uint8_t num_tcs;
3228         cmdline_fixed_string_t pfc;
3229         cmdline_fixed_string_t pfc_en;
3230 };
3231
3232 static void
3233 cmd_config_dcb_parsed(void *parsed_result,
3234                         __rte_unused struct cmdline *cl,
3235                         __rte_unused void *data)
3236 {
3237         struct cmd_config_dcb *res = parsed_result;
3238         portid_t port_id = res->port_id;
3239         struct rte_port *port;
3240         uint8_t pfc_en;
3241         int ret;
3242
3243         port = &ports[port_id];
3244         /** Check if the port is not started **/
3245         if (port->port_status != RTE_PORT_STOPPED) {
3246                 printf("Please stop port %d first\n", port_id);
3247                 return;
3248         }
3249
3250         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3251                 printf("The invalid number of traffic class,"
3252                         " only 4 or 8 allowed.\n");
3253                 return;
3254         }
3255
3256         if (nb_fwd_lcores < res->num_tcs) {
3257                 printf("nb_cores shouldn't be less than number of TCs.\n");
3258                 return;
3259         }
3260         if (!strncmp(res->pfc_en, "on", 2))
3261                 pfc_en = 1;
3262         else
3263                 pfc_en = 0;
3264
3265         /* DCB in VT mode */
3266         if (!strncmp(res->vt_en, "on", 2))
3267                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3268                                 (enum rte_eth_nb_tcs)res->num_tcs,
3269                                 pfc_en);
3270         else
3271                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3272                                 (enum rte_eth_nb_tcs)res->num_tcs,
3273                                 pfc_en);
3274
3275
3276         if (ret != 0) {
3277                 printf("Cannot initialize network ports.\n");
3278                 return;
3279         }
3280
3281         cmd_reconfig_device_queue(port_id, 1, 1);
3282 }
3283
3284 cmdline_parse_token_string_t cmd_config_dcb_port =
3285         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3286 cmdline_parse_token_string_t cmd_config_dcb_config =
3287         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3288 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3289         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3290 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3291         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3292 cmdline_parse_token_string_t cmd_config_dcb_vt =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3294 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3295         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3296 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3297         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3298 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3299         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3300 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3302
3303 cmdline_parse_inst_t cmd_config_dcb = {
3304         .f = cmd_config_dcb_parsed,
3305         .data = NULL,
3306         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3307         .tokens = {
3308                 (void *)&cmd_config_dcb_port,
3309                 (void *)&cmd_config_dcb_config,
3310                 (void *)&cmd_config_dcb_port_id,
3311                 (void *)&cmd_config_dcb_dcb,
3312                 (void *)&cmd_config_dcb_vt,
3313                 (void *)&cmd_config_dcb_vt_en,
3314                 (void *)&cmd_config_dcb_num_tcs,
3315                 (void *)&cmd_config_dcb_pfc,
3316                 (void *)&cmd_config_dcb_pfc_en,
3317                 NULL,
3318         },
3319 };
3320
3321 /* *** configure number of packets per burst *** */
3322 struct cmd_config_burst {
3323         cmdline_fixed_string_t port;
3324         cmdline_fixed_string_t keyword;
3325         cmdline_fixed_string_t all;
3326         cmdline_fixed_string_t name;
3327         uint16_t value;
3328 };
3329
3330 static void
3331 cmd_config_burst_parsed(void *parsed_result,
3332                         __rte_unused struct cmdline *cl,
3333                         __rte_unused void *data)
3334 {
3335         struct cmd_config_burst *res = parsed_result;
3336         struct rte_eth_dev_info dev_info;
3337         uint16_t rec_nb_pkts;
3338         int ret;
3339
3340         if (!all_ports_stopped()) {
3341                 printf("Please stop all ports first\n");
3342                 return;
3343         }
3344
3345         if (!strcmp(res->name, "burst")) {
3346                 if (res->value == 0) {
3347                         /* If user gives a value of zero, query the PMD for
3348                          * its recommended Rx burst size. Testpmd uses a single
3349                          * size for all ports, so assume all ports are the same
3350                          * NIC model and use the values from Port 0.
3351                          */
3352                         ret = eth_dev_info_get_print_err(0, &dev_info);
3353                         if (ret != 0)
3354                                 return;
3355
3356                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3357
3358                         if (rec_nb_pkts == 0) {
3359                                 printf("PMD does not recommend a burst size.\n"
3360                                         "User provided value must be between"
3361                                         " 1 and %d\n", MAX_PKT_BURST);
3362                                 return;
3363                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3364                                 printf("PMD recommended burst size of %d"
3365                                         " exceeds maximum value of %d\n",
3366                                         rec_nb_pkts, MAX_PKT_BURST);
3367                                 return;
3368                         }
3369                         printf("Using PMD-provided burst value of %d\n",
3370                                 rec_nb_pkts);
3371                         nb_pkt_per_burst = rec_nb_pkts;
3372                 } else if (res->value > MAX_PKT_BURST) {
3373                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3374                         return;
3375                 } else
3376                         nb_pkt_per_burst = res->value;
3377         } else {
3378                 printf("Unknown parameter\n");
3379                 return;
3380         }
3381
3382         init_port_config();
3383
3384         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3385 }
3386
3387 cmdline_parse_token_string_t cmd_config_burst_port =
3388         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3389 cmdline_parse_token_string_t cmd_config_burst_keyword =
3390         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3391 cmdline_parse_token_string_t cmd_config_burst_all =
3392         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3393 cmdline_parse_token_string_t cmd_config_burst_name =
3394         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3395 cmdline_parse_token_num_t cmd_config_burst_value =
3396         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3397
3398 cmdline_parse_inst_t cmd_config_burst = {
3399         .f = cmd_config_burst_parsed,
3400         .data = NULL,
3401         .help_str = "port config all burst <value>",
3402         .tokens = {
3403                 (void *)&cmd_config_burst_port,
3404                 (void *)&cmd_config_burst_keyword,
3405                 (void *)&cmd_config_burst_all,
3406                 (void *)&cmd_config_burst_name,
3407                 (void *)&cmd_config_burst_value,
3408                 NULL,
3409         },
3410 };
3411
3412 /* *** configure rx/tx queues *** */
3413 struct cmd_config_thresh {
3414         cmdline_fixed_string_t port;
3415         cmdline_fixed_string_t keyword;
3416         cmdline_fixed_string_t all;
3417         cmdline_fixed_string_t name;
3418         uint8_t value;
3419 };
3420
3421 static void
3422 cmd_config_thresh_parsed(void *parsed_result,
3423                         __rte_unused struct cmdline *cl,
3424                         __rte_unused void *data)
3425 {
3426         struct cmd_config_thresh *res = parsed_result;
3427
3428         if (!all_ports_stopped()) {
3429                 printf("Please stop all ports first\n");
3430                 return;
3431         }
3432
3433         if (!strcmp(res->name, "txpt"))
3434                 tx_pthresh = res->value;
3435         else if(!strcmp(res->name, "txht"))
3436                 tx_hthresh = res->value;
3437         else if(!strcmp(res->name, "txwt"))
3438                 tx_wthresh = res->value;
3439         else if(!strcmp(res->name, "rxpt"))
3440                 rx_pthresh = res->value;
3441         else if(!strcmp(res->name, "rxht"))
3442                 rx_hthresh = res->value;
3443         else if(!strcmp(res->name, "rxwt"))
3444                 rx_wthresh = res->value;
3445         else {
3446                 printf("Unknown parameter\n");
3447                 return;
3448         }
3449
3450         init_port_config();
3451
3452         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3453 }
3454
3455 cmdline_parse_token_string_t cmd_config_thresh_port =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3457 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3459 cmdline_parse_token_string_t cmd_config_thresh_all =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3461 cmdline_parse_token_string_t cmd_config_thresh_name =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3463                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3464 cmdline_parse_token_num_t cmd_config_thresh_value =
3465         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3466
3467 cmdline_parse_inst_t cmd_config_thresh = {
3468         .f = cmd_config_thresh_parsed,
3469         .data = NULL,
3470         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3471         .tokens = {
3472                 (void *)&cmd_config_thresh_port,
3473                 (void *)&cmd_config_thresh_keyword,
3474                 (void *)&cmd_config_thresh_all,
3475                 (void *)&cmd_config_thresh_name,
3476                 (void *)&cmd_config_thresh_value,
3477                 NULL,
3478         },
3479 };
3480
3481 /* *** configure free/rs threshold *** */
3482 struct cmd_config_threshold {
3483         cmdline_fixed_string_t port;
3484         cmdline_fixed_string_t keyword;
3485         cmdline_fixed_string_t all;
3486         cmdline_fixed_string_t name;
3487         uint16_t value;
3488 };
3489
3490 static void
3491 cmd_config_threshold_parsed(void *parsed_result,
3492                         __rte_unused struct cmdline *cl,
3493                         __rte_unused void *data)
3494 {
3495         struct cmd_config_threshold *res = parsed_result;
3496
3497         if (!all_ports_stopped()) {
3498                 printf("Please stop all ports first\n");
3499                 return;
3500         }
3501
3502         if (!strcmp(res->name, "txfreet"))
3503                 tx_free_thresh = res->value;
3504         else if (!strcmp(res->name, "txrst"))
3505                 tx_rs_thresh = res->value;
3506         else if (!strcmp(res->name, "rxfreet"))
3507                 rx_free_thresh = res->value;
3508         else {
3509                 printf("Unknown parameter\n");
3510                 return;
3511         }
3512
3513         init_port_config();
3514
3515         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3516 }
3517
3518 cmdline_parse_token_string_t cmd_config_threshold_port =
3519         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3520 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3521         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3522                                                                 "config");
3523 cmdline_parse_token_string_t cmd_config_threshold_all =
3524         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3525 cmdline_parse_token_string_t cmd_config_threshold_name =
3526         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3527                                                 "txfreet#txrst#rxfreet");
3528 cmdline_parse_token_num_t cmd_config_threshold_value =
3529         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3530
3531 cmdline_parse_inst_t cmd_config_threshold = {
3532         .f = cmd_config_threshold_parsed,
3533         .data = NULL,
3534         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3535         .tokens = {
3536                 (void *)&cmd_config_threshold_port,
3537                 (void *)&cmd_config_threshold_keyword,
3538                 (void *)&cmd_config_threshold_all,
3539                 (void *)&cmd_config_threshold_name,
3540                 (void *)&cmd_config_threshold_value,
3541                 NULL,
3542         },
3543 };
3544
3545 /* *** stop *** */
3546 struct cmd_stop_result {
3547         cmdline_fixed_string_t stop;
3548 };
3549
3550 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3551                             __rte_unused struct cmdline *cl,
3552                             __rte_unused void *data)
3553 {
3554         stop_packet_forwarding();
3555 }
3556
3557 cmdline_parse_token_string_t cmd_stop_stop =
3558         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3559
3560 cmdline_parse_inst_t cmd_stop = {
3561         .f = cmd_stop_parsed,
3562         .data = NULL,
3563         .help_str = "stop: Stop packet forwarding",
3564         .tokens = {
3565                 (void *)&cmd_stop_stop,
3566                 NULL,
3567         },
3568 };
3569
3570 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3571
3572 unsigned int
3573 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3574                 unsigned int *parsed_items, int check_unique_values)
3575 {
3576         unsigned int nb_item;
3577         unsigned int value;
3578         unsigned int i;
3579         unsigned int j;
3580         int value_ok;
3581         char c;
3582
3583         /*
3584          * First parse all items in the list and store their value.
3585          */
3586         value = 0;
3587         nb_item = 0;
3588         value_ok = 0;
3589         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3590                 c = str[i];
3591                 if ((c >= '0') && (c <= '9')) {
3592                         value = (unsigned int) (value * 10 + (c - '0'));
3593                         value_ok = 1;
3594                         continue;
3595                 }
3596                 if (c != ',') {
3597                         printf("character %c is not a decimal digit\n", c);
3598                         return 0;
3599                 }
3600                 if (! value_ok) {
3601                         printf("No valid value before comma\n");
3602                         return 0;
3603                 }
3604                 if (nb_item < max_items) {
3605                         parsed_items[nb_item] = value;
3606                         value_ok = 0;
3607                         value = 0;
3608                 }
3609                 nb_item++;
3610         }
3611         if (nb_item >= max_items) {
3612                 printf("Number of %s = %u > %u (maximum items)\n",
3613                        item_name, nb_item + 1, max_items);
3614                 return 0;
3615         }
3616         parsed_items[nb_item++] = value;
3617         if (! check_unique_values)
3618                 return nb_item;
3619
3620         /*
3621          * Then, check that all values in the list are differents.
3622          * No optimization here...
3623          */
3624         for (i = 0; i < nb_item; i++) {
3625                 for (j = i + 1; j < nb_item; j++) {
3626                         if (parsed_items[j] == parsed_items[i]) {
3627                                 printf("duplicated %s %u at index %u and %u\n",
3628                                        item_name, parsed_items[i], i, j);
3629                                 return 0;
3630                         }
3631                 }
3632         }
3633         return nb_item;
3634 }
3635
3636 struct cmd_set_list_result {
3637         cmdline_fixed_string_t cmd_keyword;
3638         cmdline_fixed_string_t list_name;
3639         cmdline_fixed_string_t list_of_items;
3640 };
3641
3642 static void cmd_set_list_parsed(void *parsed_result,
3643                                 __rte_unused struct cmdline *cl,
3644                                 __rte_unused void *data)
3645 {
3646         struct cmd_set_list_result *res;
3647         union {
3648                 unsigned int lcorelist[RTE_MAX_LCORE];
3649                 unsigned int portlist[RTE_MAX_ETHPORTS];
3650         } parsed_items;
3651         unsigned int nb_item;
3652
3653         if (test_done == 0) {
3654                 printf("Please stop forwarding first\n");
3655                 return;
3656         }
3657
3658         res = parsed_result;
3659         if (!strcmp(res->list_name, "corelist")) {
3660                 nb_item = parse_item_list(res->list_of_items, "core",
3661                                           RTE_MAX_LCORE,
3662                                           parsed_items.lcorelist, 1);
3663                 if (nb_item > 0) {
3664                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3665                         fwd_config_setup();
3666                 }
3667                 return;
3668         }
3669         if (!strcmp(res->list_name, "portlist")) {
3670                 nb_item = parse_item_list(res->list_of_items, "port",
3671                                           RTE_MAX_ETHPORTS,
3672                                           parsed_items.portlist, 1);
3673                 if (nb_item > 0) {
3674                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3675                         fwd_config_setup();
3676                 }
3677         }
3678 }
3679
3680 cmdline_parse_token_string_t cmd_set_list_keyword =
3681         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3682                                  "set");
3683 cmdline_parse_token_string_t cmd_set_list_name =
3684         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3685                                  "corelist#portlist");
3686 cmdline_parse_token_string_t cmd_set_list_of_items =
3687         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3688                                  NULL);
3689
3690 cmdline_parse_inst_t cmd_set_fwd_list = {
3691         .f = cmd_set_list_parsed,
3692         .data = NULL,
3693         .help_str = "set corelist|portlist <list0[,list1]*>",
3694         .tokens = {
3695                 (void *)&cmd_set_list_keyword,
3696                 (void *)&cmd_set_list_name,
3697                 (void *)&cmd_set_list_of_items,
3698                 NULL,
3699         },
3700 };
3701
3702 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3703
3704 struct cmd_setmask_result {
3705         cmdline_fixed_string_t set;
3706         cmdline_fixed_string_t mask;
3707         uint64_t hexavalue;
3708 };
3709
3710 static void cmd_set_mask_parsed(void *parsed_result,
3711                                 __rte_unused struct cmdline *cl,
3712                                 __rte_unused void *data)
3713 {
3714         struct cmd_setmask_result *res = parsed_result;
3715
3716         if (test_done == 0) {
3717                 printf("Please stop forwarding first\n");
3718                 return;
3719         }
3720         if (!strcmp(res->mask, "coremask")) {
3721                 set_fwd_lcores_mask(res->hexavalue);
3722                 fwd_config_setup();
3723         } else if (!strcmp(res->mask, "portmask")) {
3724                 set_fwd_ports_mask(res->hexavalue);
3725                 fwd_config_setup();
3726         }
3727 }
3728
3729 cmdline_parse_token_string_t cmd_setmask_set =
3730         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3731 cmdline_parse_token_string_t cmd_setmask_mask =
3732         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3733                                  "coremask#portmask");
3734 cmdline_parse_token_num_t cmd_setmask_value =
3735         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3736
3737 cmdline_parse_inst_t cmd_set_fwd_mask = {
3738         .f = cmd_set_mask_parsed,
3739         .data = NULL,
3740         .help_str = "set coremask|portmask <hexadecimal value>",
3741         .tokens = {
3742                 (void *)&cmd_setmask_set,
3743                 (void *)&cmd_setmask_mask,
3744                 (void *)&cmd_setmask_value,
3745                 NULL,
3746         },
3747 };
3748
3749 /*
3750  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3751  */
3752 struct cmd_set_result {
3753         cmdline_fixed_string_t set;
3754         cmdline_fixed_string_t what;
3755         uint16_t value;
3756 };
3757
3758 static void cmd_set_parsed(void *parsed_result,
3759                            __rte_unused struct cmdline *cl,
3760                            __rte_unused void *data)
3761 {
3762         struct cmd_set_result *res = parsed_result;
3763         if (!strcmp(res->what, "nbport")) {
3764                 set_fwd_ports_number(res->value);
3765                 fwd_config_setup();
3766         } else if (!strcmp(res->what, "nbcore")) {
3767                 set_fwd_lcores_number(res->value);
3768                 fwd_config_setup();
3769         } else if (!strcmp(res->what, "burst"))
3770                 set_nb_pkt_per_burst(res->value);
3771         else if (!strcmp(res->what, "verbose"))
3772                 set_verbose_level(res->value);
3773 }
3774
3775 cmdline_parse_token_string_t cmd_set_set =
3776         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3777 cmdline_parse_token_string_t cmd_set_what =
3778         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3779                                  "nbport#nbcore#burst#verbose");
3780 cmdline_parse_token_num_t cmd_set_value =
3781         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3782
3783 cmdline_parse_inst_t cmd_set_numbers = {
3784         .f = cmd_set_parsed,
3785         .data = NULL,
3786         .help_str = "set nbport|nbcore|burst|verbose <value>",
3787         .tokens = {
3788                 (void *)&cmd_set_set,
3789                 (void *)&cmd_set_what,
3790                 (void *)&cmd_set_value,
3791                 NULL,
3792         },
3793 };
3794
3795 /* *** SET LOG LEVEL CONFIGURATION *** */
3796
3797 struct cmd_set_log_result {
3798         cmdline_fixed_string_t set;
3799         cmdline_fixed_string_t log;
3800         cmdline_fixed_string_t type;
3801         uint32_t level;
3802 };
3803
3804 static void
3805 cmd_set_log_parsed(void *parsed_result,
3806                    __rte_unused struct cmdline *cl,
3807                    __rte_unused void *data)
3808 {
3809         struct cmd_set_log_result *res;
3810         int ret;
3811
3812         res = parsed_result;
3813         if (!strcmp(res->type, "global"))
3814                 rte_log_set_global_level(res->level);
3815         else {
3816                 ret = rte_log_set_level_regexp(res->type, res->level);
3817                 if (ret < 0)
3818                         printf("Unable to set log level\n");
3819         }
3820 }
3821
3822 cmdline_parse_token_string_t cmd_set_log_set =
3823         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3824 cmdline_parse_token_string_t cmd_set_log_log =
3825         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3826 cmdline_parse_token_string_t cmd_set_log_type =
3827         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3828 cmdline_parse_token_num_t cmd_set_log_level =
3829         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3830
3831 cmdline_parse_inst_t cmd_set_log = {
3832         .f = cmd_set_log_parsed,
3833         .data = NULL,
3834         .help_str = "set log global|<type> <level>",
3835         .tokens = {
3836                 (void *)&cmd_set_log_set,
3837                 (void *)&cmd_set_log_log,
3838                 (void *)&cmd_set_log_type,
3839                 (void *)&cmd_set_log_level,
3840                 NULL,
3841         },
3842 };
3843
3844 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3845
3846 struct cmd_set_txpkts_result {
3847         cmdline_fixed_string_t cmd_keyword;
3848         cmdline_fixed_string_t txpkts;
3849         cmdline_fixed_string_t seg_lengths;
3850 };
3851
3852 static void
3853 cmd_set_txpkts_parsed(void *parsed_result,
3854                       __rte_unused struct cmdline *cl,
3855                       __rte_unused void *data)
3856 {
3857         struct cmd_set_txpkts_result *res;
3858         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3859         unsigned int nb_segs;
3860
3861         res = parsed_result;
3862         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3863                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3864         if (nb_segs > 0)
3865                 set_tx_pkt_segments(seg_lengths, nb_segs);
3866 }
3867
3868 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3869         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3870                                  cmd_keyword, "set");
3871 cmdline_parse_token_string_t cmd_set_txpkts_name =
3872         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3873                                  txpkts, "txpkts");
3874 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3875         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3876                                  seg_lengths, NULL);
3877
3878 cmdline_parse_inst_t cmd_set_txpkts = {
3879         .f = cmd_set_txpkts_parsed,
3880         .data = NULL,
3881         .help_str = "set txpkts <len0[,len1]*>",
3882         .tokens = {
3883                 (void *)&cmd_set_txpkts_keyword,
3884                 (void *)&cmd_set_txpkts_name,
3885                 (void *)&cmd_set_txpkts_lengths,
3886                 NULL,
3887         },
3888 };
3889
3890 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3891
3892 struct cmd_set_txsplit_result {
3893         cmdline_fixed_string_t cmd_keyword;
3894         cmdline_fixed_string_t txsplit;
3895         cmdline_fixed_string_t mode;
3896 };
3897
3898 static void
3899 cmd_set_txsplit_parsed(void *parsed_result,
3900                       __rte_unused struct cmdline *cl,
3901                       __rte_unused void *data)
3902 {
3903         struct cmd_set_txsplit_result *res;
3904
3905         res = parsed_result;
3906         set_tx_pkt_split(res->mode);
3907 }
3908
3909 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3910         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3911                                  cmd_keyword, "set");
3912 cmdline_parse_token_string_t cmd_set_txsplit_name =
3913         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3914                                  txsplit, "txsplit");
3915 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3916         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3917                                  mode, NULL);
3918
3919 cmdline_parse_inst_t cmd_set_txsplit = {
3920         .f = cmd_set_txsplit_parsed,
3921         .data = NULL,
3922         .help_str = "set txsplit on|off|rand",
3923         .tokens = {
3924                 (void *)&cmd_set_txsplit_keyword,
3925                 (void *)&cmd_set_txsplit_name,
3926                 (void *)&cmd_set_txsplit_mode,
3927                 NULL,
3928         },
3929 };
3930
3931 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3932 struct cmd_rx_vlan_filter_all_result {
3933         cmdline_fixed_string_t rx_vlan;
3934         cmdline_fixed_string_t what;
3935         cmdline_fixed_string_t all;
3936         portid_t port_id;
3937 };
3938
3939 static void
3940 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3941                               __rte_unused struct cmdline *cl,
3942                               __rte_unused void *data)
3943 {
3944         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3945
3946         if (!strcmp(res->what, "add"))
3947                 rx_vlan_all_filter_set(res->port_id, 1);
3948         else
3949                 rx_vlan_all_filter_set(res->port_id, 0);
3950 }
3951
3952 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3953         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3954                                  rx_vlan, "rx_vlan");
3955 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3956         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3957                                  what, "add#rm");
3958 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3959         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3960                                  all, "all");
3961 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3962         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3963                               port_id, UINT16);
3964
3965 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3966         .f = cmd_rx_vlan_filter_all_parsed,
3967         .data = NULL,
3968         .help_str = "rx_vlan add|rm all <port_id>: "
3969                 "Add/Remove all identifiers to/from the set of VLAN "
3970                 "identifiers filtered by a port",
3971         .tokens = {
3972                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3973                 (void *)&cmd_rx_vlan_filter_all_what,
3974                 (void *)&cmd_rx_vlan_filter_all_all,
3975                 (void *)&cmd_rx_vlan_filter_all_portid,
3976                 NULL,
3977         },
3978 };
3979
3980 /* *** VLAN OFFLOAD SET ON A PORT *** */
3981 struct cmd_vlan_offload_result {
3982         cmdline_fixed_string_t vlan;
3983         cmdline_fixed_string_t set;
3984         cmdline_fixed_string_t vlan_type;
3985         cmdline_fixed_string_t what;
3986         cmdline_fixed_string_t on;
3987         cmdline_fixed_string_t port_id;
3988 };
3989
3990 static void
3991 cmd_vlan_offload_parsed(void *parsed_result,
3992                           __rte_unused struct cmdline *cl,
3993                           __rte_unused void *data)
3994 {
3995         int on;
3996         struct cmd_vlan_offload_result *res = parsed_result;
3997         char *str;
3998         int i, len = 0;
3999         portid_t port_id = 0;
4000         unsigned int tmp;
4001
4002         str = res->port_id;
4003         len = strnlen(str, STR_TOKEN_SIZE);
4004         i = 0;
4005         /* Get port_id first */
4006         while(i < len){
4007                 if(str[i] == ',')
4008                         break;
4009
4010                 i++;
4011         }
4012         str[i]='\0';
4013         tmp = strtoul(str, NULL, 0);
4014         /* If port_id greater that what portid_t can represent, return */
4015         if(tmp >= RTE_MAX_ETHPORTS)
4016                 return;
4017         port_id = (portid_t)tmp;
4018
4019         if (!strcmp(res->on, "on"))
4020                 on = 1;
4021         else
4022                 on = 0;
4023
4024         if (!strcmp(res->what, "strip"))
4025                 rx_vlan_strip_set(port_id,  on);
4026         else if(!strcmp(res->what, "stripq")){
4027                 uint16_t queue_id = 0;
4028
4029                 /* No queue_id, return */
4030                 if(i + 1 >= len) {
4031                         printf("must specify (port,queue_id)\n");
4032                         return;
4033                 }
4034                 tmp = strtoul(str + i + 1, NULL, 0);
4035                 /* If queue_id greater that what 16-bits can represent, return */
4036                 if(tmp > 0xffff)
4037                         return;
4038
4039                 queue_id = (uint16_t)tmp;
4040                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4041         }
4042         else if (!strcmp(res->what, "filter"))
4043                 rx_vlan_filter_set(port_id, on);
4044         else if (!strcmp(res->what, "qinq_strip"))
4045                 rx_vlan_qinq_strip_set(port_id, on);
4046         else
4047                 vlan_extend_set(port_id, on);
4048
4049         return;
4050 }
4051
4052 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4053         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4054                                  vlan, "vlan");
4055 cmdline_parse_token_string_t cmd_vlan_offload_set =
4056         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4057                                  set, "set");
4058 cmdline_parse_token_string_t cmd_vlan_offload_what =
4059         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4060                                 what, "strip#filter#qinq_strip#extend#stripq");
4061 cmdline_parse_token_string_t cmd_vlan_offload_on =
4062         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4063                               on, "on#off");
4064 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4065         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4066                               port_id, NULL);
4067
4068 cmdline_parse_inst_t cmd_vlan_offload = {
4069         .f = cmd_vlan_offload_parsed,
4070         .data = NULL,
4071         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4072                 "<port_id[,queue_id]>: "
4073                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4074         .tokens = {
4075                 (void *)&cmd_vlan_offload_vlan,
4076                 (void *)&cmd_vlan_offload_set,
4077                 (void *)&cmd_vlan_offload_what,
4078                 (void *)&cmd_vlan_offload_on,
4079                 (void *)&cmd_vlan_offload_portid,
4080                 NULL,
4081         },
4082 };
4083
4084 /* *** VLAN TPID SET ON A PORT *** */
4085 struct cmd_vlan_tpid_result {
4086         cmdline_fixed_string_t vlan;
4087         cmdline_fixed_string_t set;
4088         cmdline_fixed_string_t vlan_type;
4089         cmdline_fixed_string_t what;
4090         uint16_t tp_id;
4091         portid_t port_id;
4092 };
4093
4094 static void
4095 cmd_vlan_tpid_parsed(void *parsed_result,
4096                           __rte_unused struct cmdline *cl,
4097                           __rte_unused void *data)
4098 {
4099         struct cmd_vlan_tpid_result *res = parsed_result;
4100         enum rte_vlan_type vlan_type;
4101
4102         if (!strcmp(res->vlan_type, "inner"))
4103                 vlan_type = ETH_VLAN_TYPE_INNER;
4104         else if (!strcmp(res->vlan_type, "outer"))
4105                 vlan_type = ETH_VLAN_TYPE_OUTER;
4106         else {
4107                 printf("Unknown vlan type\n");
4108                 return;
4109         }
4110         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4111 }
4112
4113 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4114         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4115                                  vlan, "vlan");
4116 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4117         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4118                                  set, "set");
4119 cmdline_parse_token_string_t cmd_vlan_type =
4120         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4121                                  vlan_type, "inner#outer");
4122 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4123         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4124                                  what, "tpid");
4125 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4126         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4127                               tp_id, UINT16);
4128 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4129         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4130                               port_id, UINT16);
4131
4132 cmdline_parse_inst_t cmd_vlan_tpid = {
4133         .f = cmd_vlan_tpid_parsed,
4134         .data = NULL,
4135         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4136                 "Set the VLAN Ether type",
4137         .tokens = {
4138                 (void *)&cmd_vlan_tpid_vlan,
4139                 (void *)&cmd_vlan_tpid_set,
4140                 (void *)&cmd_vlan_type,
4141                 (void *)&cmd_vlan_tpid_what,
4142                 (void *)&cmd_vlan_tpid_tpid,
4143                 (void *)&cmd_vlan_tpid_portid,
4144                 NULL,
4145         },
4146 };
4147
4148 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4149 struct cmd_rx_vlan_filter_result {
4150         cmdline_fixed_string_t rx_vlan;
4151         cmdline_fixed_string_t what;
4152         uint16_t vlan_id;
4153         portid_t port_id;
4154 };
4155
4156 static void
4157 cmd_rx_vlan_filter_parsed(void *parsed_result,
4158                           __rte_unused struct cmdline *cl,
4159                           __rte_unused void *data)
4160 {
4161         struct cmd_rx_vlan_filter_result *res = parsed_result;
4162
4163         if (!strcmp(res->what, "add"))
4164                 rx_vft_set(res->port_id, res->vlan_id, 1);
4165         else
4166                 rx_vft_set(res->port_id, res->vlan_id, 0);
4167 }
4168
4169 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4170         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4171                                  rx_vlan, "rx_vlan");
4172 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4173         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4174                                  what, "add#rm");
4175 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4176         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4177                               vlan_id, UINT16);
4178 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4179         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4180                               port_id, UINT16);
4181
4182 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4183         .f = cmd_rx_vlan_filter_parsed,
4184         .data = NULL,
4185         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4186                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4187                 "identifiers filtered by a port",
4188         .tokens = {
4189                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4190                 (void *)&cmd_rx_vlan_filter_what,
4191                 (void *)&cmd_rx_vlan_filter_vlanid,
4192                 (void *)&cmd_rx_vlan_filter_portid,
4193                 NULL,
4194         },
4195 };
4196
4197 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4198 struct cmd_tx_vlan_set_result {
4199         cmdline_fixed_string_t tx_vlan;
4200         cmdline_fixed_string_t set;
4201         portid_t port_id;
4202         uint16_t vlan_id;
4203 };
4204
4205 static void
4206 cmd_tx_vlan_set_parsed(void *parsed_result,
4207                        __rte_unused struct cmdline *cl,
4208                        __rte_unused void *data)
4209 {
4210         struct cmd_tx_vlan_set_result *res = parsed_result;
4211
4212         if (!port_is_stopped(res->port_id)) {
4213                 printf("Please stop port %d first\n", res->port_id);
4214                 return;
4215         }
4216
4217         tx_vlan_set(res->port_id, res->vlan_id);
4218
4219         cmd_reconfig_device_queue(res->port_id, 1, 1);
4220 }
4221
4222 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4223         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4224                                  tx_vlan, "tx_vlan");
4225 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4226         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4227                                  set, "set");
4228 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4229         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4230                               port_id, UINT16);
4231 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4232         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4233                               vlan_id, UINT16);
4234
4235 cmdline_parse_inst_t cmd_tx_vlan_set = {
4236         .f = cmd_tx_vlan_set_parsed,
4237         .data = NULL,
4238         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4239                 "Enable hardware insertion of a single VLAN header "
4240                 "with a given TAG Identifier in packets sent on a port",
4241         .tokens = {
4242                 (void *)&cmd_tx_vlan_set_tx_vlan,
4243                 (void *)&cmd_tx_vlan_set_set,
4244                 (void *)&cmd_tx_vlan_set_portid,
4245                 (void *)&cmd_tx_vlan_set_vlanid,
4246                 NULL,
4247         },
4248 };
4249
4250 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4251 struct cmd_tx_vlan_set_qinq_result {
4252         cmdline_fixed_string_t tx_vlan;
4253         cmdline_fixed_string_t set;
4254         portid_t port_id;
4255         uint16_t vlan_id;
4256         uint16_t vlan_id_outer;
4257 };
4258
4259 static void
4260 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4261                             __rte_unused struct cmdline *cl,
4262                             __rte_unused void *data)
4263 {
4264         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4265
4266         if (!port_is_stopped(res->port_id)) {
4267                 printf("Please stop port %d first\n", res->port_id);
4268                 return;
4269         }
4270
4271         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4272
4273         cmd_reconfig_device_queue(res->port_id, 1, 1);
4274 }
4275
4276 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4277         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4278                 tx_vlan, "tx_vlan");
4279 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4280         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4281                 set, "set");
4282 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4283         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4284                 port_id, UINT16);
4285 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4286         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4287                 vlan_id, UINT16);
4288 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4289         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4290                 vlan_id_outer, UINT16);
4291
4292 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4293         .f = cmd_tx_vlan_set_qinq_parsed,
4294         .data = NULL,
4295         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4296                 "Enable hardware insertion of double VLAN header "
4297                 "with given TAG Identifiers in packets sent on a port",
4298         .tokens = {
4299                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4300                 (void *)&cmd_tx_vlan_set_qinq_set,
4301                 (void *)&cmd_tx_vlan_set_qinq_portid,
4302                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4303                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4304                 NULL,
4305         },
4306 };
4307
4308 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4309 struct cmd_tx_vlan_set_pvid_result {
4310         cmdline_fixed_string_t tx_vlan;
4311         cmdline_fixed_string_t set;
4312         cmdline_fixed_string_t pvid;
4313         portid_t port_id;
4314         uint16_t vlan_id;
4315         cmdline_fixed_string_t mode;
4316 };
4317
4318 static void
4319 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4320                             __rte_unused struct cmdline *cl,
4321                             __rte_unused void *data)
4322 {
4323         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4324
4325         if (strcmp(res->mode, "on") == 0)
4326                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4327         else
4328                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4329 }
4330
4331 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4332         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4333                                  tx_vlan, "tx_vlan");
4334 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4335         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4336                                  set, "set");
4337 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4338         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4339                                  pvid, "pvid");
4340 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4341         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4342                              port_id, UINT16);
4343 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4344         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4345                               vlan_id, UINT16);
4346 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4347         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4348                                  mode, "on#off");
4349
4350 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4351         .f = cmd_tx_vlan_set_pvid_parsed,
4352         .data = NULL,
4353         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4354         .tokens = {
4355                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4356                 (void *)&cmd_tx_vlan_set_pvid_set,
4357                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4358                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4359                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4360                 (void *)&cmd_tx_vlan_set_pvid_mode,
4361                 NULL,
4362         },
4363 };
4364
4365 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4366 struct cmd_tx_vlan_reset_result {
4367         cmdline_fixed_string_t tx_vlan;
4368         cmdline_fixed_string_t reset;
4369         portid_t port_id;
4370 };
4371
4372 static void
4373 cmd_tx_vlan_reset_parsed(void *parsed_result,
4374                          __rte_unused struct cmdline *cl,
4375                          __rte_unused void *data)
4376 {
4377         struct cmd_tx_vlan_reset_result *res = parsed_result;
4378
4379         if (!port_is_stopped(res->port_id)) {
4380                 printf("Please stop port %d first\n", res->port_id);
4381                 return;
4382         }
4383
4384         tx_vlan_reset(res->port_id);
4385
4386         cmd_reconfig_device_queue(res->port_id, 1, 1);
4387 }
4388
4389 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4390         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4391                                  tx_vlan, "tx_vlan");
4392 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4393         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4394                                  reset, "reset");
4395 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4396         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4397                               port_id, UINT16);
4398
4399 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4400         .f = cmd_tx_vlan_reset_parsed,
4401         .data = NULL,
4402         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4403                 "VLAN header in packets sent on a port",
4404         .tokens = {
4405                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4406                 (void *)&cmd_tx_vlan_reset_reset,
4407                 (void *)&cmd_tx_vlan_reset_portid,
4408                 NULL,
4409         },
4410 };
4411
4412
4413 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4414 struct cmd_csum_result {
4415         cmdline_fixed_string_t csum;
4416         cmdline_fixed_string_t mode;
4417         cmdline_fixed_string_t proto;
4418         cmdline_fixed_string_t hwsw;
4419         portid_t port_id;
4420 };
4421
4422 static void
4423 csum_show(int port_id)
4424 {
4425         struct rte_eth_dev_info dev_info;
4426         uint64_t tx_offloads;
4427         int ret;
4428
4429         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4430         printf("Parse tunnel is %s\n",
4431                 (ports[port_id].parse_tunnel) ? "on" : "off");
4432         printf("IP checksum offload is %s\n",
4433                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4434         printf("UDP checksum offload is %s\n",
4435                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4436         printf("TCP checksum offload is %s\n",
4437                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4438         printf("SCTP checksum offload is %s\n",
4439                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4440         printf("Outer-Ip checksum offload is %s\n",
4441                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4442         printf("Outer-Udp checksum offload is %s\n",
4443                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4444
4445         /* display warnings if configuration is not supported by the NIC */
4446         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4447         if (ret != 0)
4448                 return;
4449
4450         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4451                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4452                 printf("Warning: hardware IP checksum enabled but not "
4453                         "supported by port %d\n", port_id);
4454         }
4455         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4456                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4457                 printf("Warning: hardware UDP checksum enabled but not "
4458                         "supported by port %d\n", port_id);
4459         }
4460         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4461                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4462                 printf("Warning: hardware TCP checksum enabled but not "
4463                         "supported by port %d\n", port_id);
4464         }
4465         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4466                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4467                 printf("Warning: hardware SCTP checksum enabled but not "
4468                         "supported by port %d\n", port_id);
4469         }
4470         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4471                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4472                 printf("Warning: hardware outer IP checksum enabled but not "
4473                         "supported by port %d\n", port_id);
4474         }
4475         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4476                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4477                         == 0) {
4478                 printf("Warning: hardware outer UDP checksum enabled but not "
4479                         "supported by port %d\n", port_id);
4480         }
4481 }
4482
4483 static void
4484 cmd_config_queue_tx_offloads(struct rte_port *port)
4485 {
4486         int k;
4487
4488         /* Apply queue tx offloads configuration */
4489         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4490                 port->tx_conf[k].offloads =
4491                         port->dev_conf.txmode.offloads;
4492 }
4493
4494 static void
4495 cmd_csum_parsed(void *parsed_result,
4496                        __rte_unused struct cmdline *cl,
4497                        __rte_unused void *data)
4498 {
4499         struct cmd_csum_result *res = parsed_result;
4500         int hw = 0;
4501         uint64_t csum_offloads = 0;
4502         struct rte_eth_dev_info dev_info;
4503         int ret;
4504
4505         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4506                 printf("invalid port %d\n", res->port_id);
4507                 return;
4508         }
4509         if (!port_is_stopped(res->port_id)) {
4510                 printf("Please stop port %d first\n", res->port_id);
4511                 return;
4512         }
4513
4514         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4515         if (ret != 0)
4516                 return;
4517
4518         if (!strcmp(res->mode, "set")) {
4519
4520                 if (!strcmp(res->hwsw, "hw"))
4521                         hw = 1;
4522
4523                 if (!strcmp(res->proto, "ip")) {
4524                         if (hw == 0 || (dev_info.tx_offload_capa &
4525                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4526                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4527                         } else {
4528                                 printf("IP checksum offload is not supported "
4529                                        "by port %u\n", res->port_id);
4530                         }
4531                 } else if (!strcmp(res->proto, "udp")) {
4532                         if (hw == 0 || (dev_info.tx_offload_capa &
4533                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4534                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4535                         } else {
4536                                 printf("UDP checksum offload is not supported "
4537                                        "by port %u\n", res->port_id);
4538                         }
4539                 } else if (!strcmp(res->proto, "tcp")) {
4540                         if (hw == 0 || (dev_info.tx_offload_capa &
4541                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4542                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4543                         } else {
4544                                 printf("TCP checksum offload is not supported "
4545                                        "by port %u\n", res->port_id);
4546                         }
4547                 } else if (!strcmp(res->proto, "sctp")) {
4548                         if (hw == 0 || (dev_info.tx_offload_capa &
4549                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4550                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4551                         } else {
4552                                 printf("SCTP checksum offload is not supported "
4553                                        "by port %u\n", res->port_id);
4554                         }
4555                 } else if (!strcmp(res->proto, "outer-ip")) {
4556                         if (hw == 0 || (dev_info.tx_offload_capa &
4557                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4558                                 csum_offloads |=
4559                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4560                         } else {
4561                                 printf("Outer IP checksum offload is not "
4562                                        "supported by port %u\n", res->port_id);
4563                         }
4564                 } else if (!strcmp(res->proto, "outer-udp")) {
4565                         if (hw == 0 || (dev_info.tx_offload_capa &
4566                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4567                                 csum_offloads |=
4568                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4569                         } else {
4570                                 printf("Outer UDP checksum offload is not "
4571                                        "supported by port %u\n", res->port_id);
4572                         }
4573                 }
4574
4575                 if (hw) {
4576                         ports[res->port_id].dev_conf.txmode.offloads |=
4577                                                         csum_offloads;
4578                 } else {
4579                         ports[res->port_id].dev_conf.txmode.offloads &=
4580                                                         (~csum_offloads);
4581                 }
4582                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4583         }
4584         csum_show(res->port_id);
4585
4586         cmd_reconfig_device_queue(res->port_id, 1, 1);
4587 }
4588
4589 cmdline_parse_token_string_t cmd_csum_csum =
4590         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4591                                 csum, "csum");
4592 cmdline_parse_token_string_t cmd_csum_mode =
4593         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4594                                 mode, "set");
4595 cmdline_parse_token_string_t cmd_csum_proto =
4596         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4597                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4598 cmdline_parse_token_string_t cmd_csum_hwsw =
4599         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4600                                 hwsw, "hw#sw");
4601 cmdline_parse_token_num_t cmd_csum_portid =
4602         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4603                                 port_id, UINT16);
4604
4605 cmdline_parse_inst_t cmd_csum_set = {
4606         .f = cmd_csum_parsed,
4607         .data = NULL,
4608         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4609                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4610                 "using csum forward engine",
4611         .tokens = {
4612                 (void *)&cmd_csum_csum,
4613                 (void *)&cmd_csum_mode,
4614                 (void *)&cmd_csum_proto,
4615                 (void *)&cmd_csum_hwsw,
4616                 (void *)&cmd_csum_portid,
4617                 NULL,
4618         },
4619 };
4620
4621 cmdline_parse_token_string_t cmd_csum_mode_show =
4622         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4623                                 mode, "show");
4624
4625 cmdline_parse_inst_t cmd_csum_show = {
4626         .f = cmd_csum_parsed,
4627         .data = NULL,
4628         .help_str = "csum show <port_id>: Show checksum offload configuration",
4629         .tokens = {
4630                 (void *)&cmd_csum_csum,
4631                 (void *)&cmd_csum_mode_show,
4632                 (void *)&cmd_csum_portid,
4633                 NULL,
4634         },
4635 };
4636
4637 /* Enable/disable tunnel parsing */
4638 struct cmd_csum_tunnel_result {
4639         cmdline_fixed_string_t csum;
4640         cmdline_fixed_string_t parse;
4641         cmdline_fixed_string_t onoff;
4642         portid_t port_id;
4643 };
4644
4645 static void
4646 cmd_csum_tunnel_parsed(void *parsed_result,
4647                        __rte_unused struct cmdline *cl,
4648                        __rte_unused void *data)
4649 {
4650         struct cmd_csum_tunnel_result *res = parsed_result;
4651
4652         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4653                 return;
4654
4655         if (!strcmp(res->onoff, "on"))
4656                 ports[res->port_id].parse_tunnel = 1;
4657         else
4658                 ports[res->port_id].parse_tunnel = 0;
4659
4660         csum_show(res->port_id);
4661 }
4662
4663 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4664         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4665                                 csum, "csum");
4666 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4667         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4668                                 parse, "parse-tunnel");
4669 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4670         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4671                                 onoff, "on#off");
4672 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4673         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4674                                 port_id, UINT16);
4675
4676 cmdline_parse_inst_t cmd_csum_tunnel = {
4677         .f = cmd_csum_tunnel_parsed,
4678         .data = NULL,
4679         .help_str = "csum parse-tunnel on|off <port_id>: "
4680                 "Enable/Disable parsing of tunnels for csum engine",
4681         .tokens = {
4682                 (void *)&cmd_csum_tunnel_csum,
4683                 (void *)&cmd_csum_tunnel_parse,
4684                 (void *)&cmd_csum_tunnel_onoff,
4685                 (void *)&cmd_csum_tunnel_portid,
4686                 NULL,
4687         },
4688 };
4689
4690 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4691 struct cmd_tso_set_result {
4692         cmdline_fixed_string_t tso;
4693         cmdline_fixed_string_t mode;
4694         uint16_t tso_segsz;
4695         portid_t port_id;
4696 };
4697
4698 static void
4699 cmd_tso_set_parsed(void *parsed_result,
4700                        __rte_unused struct cmdline *cl,
4701                        __rte_unused void *data)
4702 {
4703         struct cmd_tso_set_result *res = parsed_result;
4704         struct rte_eth_dev_info dev_info;
4705         int ret;
4706
4707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4708                 return;
4709         if (!port_is_stopped(res->port_id)) {
4710                 printf("Please stop port %d first\n", res->port_id);
4711                 return;
4712         }
4713
4714         if (!strcmp(res->mode, "set"))
4715                 ports[res->port_id].tso_segsz = res->tso_segsz;
4716
4717         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4718         if (ret != 0)
4719                 return;
4720
4721         if ((ports[res->port_id].tso_segsz != 0) &&
4722                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4723                 printf("Error: TSO is not supported by port %d\n",
4724                        res->port_id);
4725                 return;
4726         }
4727
4728         if (ports[res->port_id].tso_segsz == 0) {
4729                 ports[res->port_id].dev_conf.txmode.offloads &=
4730                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4731                 printf("TSO for non-tunneled packets is disabled\n");
4732         } else {
4733                 ports[res->port_id].dev_conf.txmode.offloads |=
4734                                                 DEV_TX_OFFLOAD_TCP_TSO;
4735                 printf("TSO segment size for non-tunneled packets is %d\n",
4736                         ports[res->port_id].tso_segsz);
4737         }
4738         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4739
4740         /* display warnings if configuration is not supported by the NIC */
4741         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4742         if (ret != 0)
4743                 return;
4744
4745         if ((ports[res->port_id].tso_segsz != 0) &&
4746                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4747                 printf("Warning: TSO enabled but not "
4748                         "supported by port %d\n", res->port_id);
4749         }
4750
4751         cmd_reconfig_device_queue(res->port_id, 1, 1);
4752 }
4753
4754 cmdline_parse_token_string_t cmd_tso_set_tso =
4755         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4756                                 tso, "tso");
4757 cmdline_parse_token_string_t cmd_tso_set_mode =
4758         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4759                                 mode, "set");
4760 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4761         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4762                                 tso_segsz, UINT16);
4763 cmdline_parse_token_num_t cmd_tso_set_portid =
4764         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4765                                 port_id, UINT16);
4766
4767 cmdline_parse_inst_t cmd_tso_set = {
4768         .f = cmd_tso_set_parsed,
4769         .data = NULL,
4770         .help_str = "tso set <tso_segsz> <port_id>: "
4771                 "Set TSO segment size of non-tunneled packets for csum engine "
4772                 "(0 to disable)",
4773         .tokens = {
4774                 (void *)&cmd_tso_set_tso,
4775                 (void *)&cmd_tso_set_mode,
4776                 (void *)&cmd_tso_set_tso_segsz,
4777                 (void *)&cmd_tso_set_portid,
4778                 NULL,
4779         },
4780 };
4781
4782 cmdline_parse_token_string_t cmd_tso_show_mode =
4783         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4784                                 mode, "show");
4785
4786
4787 cmdline_parse_inst_t cmd_tso_show = {
4788         .f = cmd_tso_set_parsed,
4789         .data = NULL,
4790         .help_str = "tso show <port_id>: "
4791                 "Show TSO segment size of non-tunneled packets for csum engine",
4792         .tokens = {
4793                 (void *)&cmd_tso_set_tso,
4794                 (void *)&cmd_tso_show_mode,
4795                 (void *)&cmd_tso_set_portid,
4796                 NULL,
4797         },
4798 };
4799
4800 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4801 struct cmd_tunnel_tso_set_result {
4802         cmdline_fixed_string_t tso;
4803         cmdline_fixed_string_t mode;
4804         uint16_t tso_segsz;
4805         portid_t port_id;
4806 };
4807
4808 static struct rte_eth_dev_info
4809 check_tunnel_tso_nic_support(portid_t port_id)
4810 {
4811         struct rte_eth_dev_info dev_info;
4812
4813         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4814                 return dev_info;
4815
4816         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4817                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4818                        "not enabled for port %d\n", port_id);
4819         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4820                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4821                        "not enabled for port %d\n", port_id);
4822         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4823                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4824                        "not enabled for port %d\n", port_id);
4825         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4826                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4827                        "not enabled for port %d\n", port_id);
4828         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4829                 printf("Warning: IP TUNNEL TSO not supported therefore "
4830                        "not enabled for port %d\n", port_id);
4831         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4832                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4833                        "not enabled for port %d\n", port_id);
4834         return dev_info;
4835 }
4836
4837 static void
4838 cmd_tunnel_tso_set_parsed(void *parsed_result,
4839                           __rte_unused struct cmdline *cl,
4840                           __rte_unused void *data)
4841 {
4842         struct cmd_tunnel_tso_set_result *res = parsed_result;
4843         struct rte_eth_dev_info dev_info;
4844
4845         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4846                 return;
4847         if (!port_is_stopped(res->port_id)) {
4848                 printf("Please stop port %d first\n", res->port_id);
4849                 return;
4850         }
4851
4852         if (!strcmp(res->mode, "set"))
4853                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4854
4855         dev_info = check_tunnel_tso_nic_support(res->port_id);
4856         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4857                 ports[res->port_id].dev_conf.txmode.offloads &=
4858                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4859                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4860                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4861                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4862                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4863                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4864                 printf("TSO for tunneled packets is disabled\n");
4865         } else {
4866                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4867                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4868                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4869                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4870                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4871                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4872
4873                 ports[res->port_id].dev_conf.txmode.offloads |=
4874                         (tso_offloads & dev_info.tx_offload_capa);
4875                 printf("TSO segment size for tunneled packets is %d\n",
4876                         ports[res->port_id].tunnel_tso_segsz);
4877
4878                 /* Below conditions are needed to make it work:
4879                  * (1) tunnel TSO is supported by the NIC;
4880                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4881                  * are recognized;
4882                  * (3) for tunneled pkts with outer L3 of IPv4,
4883                  * "csum set outer-ip" must be set to hw, because after tso,
4884                  * total_len of outer IP header is changed, and the checksum
4885                  * of outer IP header calculated by sw should be wrong; that
4886                  * is not necessary for IPv6 tunneled pkts because there's no
4887                  * checksum in IP header anymore.
4888                  */
4889
4890                 if (!ports[res->port_id].parse_tunnel)
4891                         printf("Warning: csum parse_tunnel must be set "
4892                                 "so that tunneled packets are recognized\n");
4893                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4894                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4895                         printf("Warning: csum set outer-ip must be set to hw "
4896                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4897         }
4898
4899         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4900         cmd_reconfig_device_queue(res->port_id, 1, 1);
4901 }
4902
4903 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4904         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4905                                 tso, "tunnel_tso");
4906 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4907         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4908                                 mode, "set");
4909 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4910         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4911                                 tso_segsz, UINT16);
4912 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4913         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4914                                 port_id, UINT16);
4915
4916 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4917         .f = cmd_tunnel_tso_set_parsed,
4918         .data = NULL,
4919         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4920                 "Set TSO segment size of tunneled packets for csum engine "
4921                 "(0 to disable)",
4922         .tokens = {
4923                 (void *)&cmd_tunnel_tso_set_tso,
4924                 (void *)&cmd_tunnel_tso_set_mode,
4925                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4926                 (void *)&cmd_tunnel_tso_set_portid,
4927                 NULL,
4928         },
4929 };
4930
4931 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4932         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4933                                 mode, "show");
4934
4935
4936 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4937         .f = cmd_tunnel_tso_set_parsed,
4938         .data = NULL,
4939         .help_str = "tunnel_tso show <port_id> "
4940                 "Show TSO segment size of tunneled packets for csum engine",
4941         .tokens = {
4942                 (void *)&cmd_tunnel_tso_set_tso,
4943                 (void *)&cmd_tunnel_tso_show_mode,
4944                 (void *)&cmd_tunnel_tso_set_portid,
4945                 NULL,
4946         },
4947 };
4948
4949 /* *** SET GRO FOR A PORT *** */
4950 struct cmd_gro_enable_result {
4951         cmdline_fixed_string_t cmd_set;
4952         cmdline_fixed_string_t cmd_port;
4953         cmdline_fixed_string_t cmd_keyword;
4954         cmdline_fixed_string_t cmd_onoff;
4955         portid_t cmd_pid;
4956 };
4957
4958 static void
4959 cmd_gro_enable_parsed(void *parsed_result,
4960                 __rte_unused struct cmdline *cl,
4961                 __rte_unused void *data)
4962 {
4963         struct cmd_gro_enable_result *res;
4964
4965         res = parsed_result;
4966         if (!strcmp(res->cmd_keyword, "gro"))
4967                 setup_gro(res->cmd_onoff, res->cmd_pid);
4968 }
4969
4970 cmdline_parse_token_string_t cmd_gro_enable_set =
4971         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4972                         cmd_set, "set");
4973 cmdline_parse_token_string_t cmd_gro_enable_port =
4974         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4975                         cmd_keyword, "port");
4976 cmdline_parse_token_num_t cmd_gro_enable_pid =
4977         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4978                         cmd_pid, UINT16);
4979 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4980         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4981                         cmd_keyword, "gro");
4982 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4983         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4984                         cmd_onoff, "on#off");
4985
4986 cmdline_parse_inst_t cmd_gro_enable = {
4987         .f = cmd_gro_enable_parsed,
4988         .data = NULL,
4989         .help_str = "set port <port_id> gro on|off",
4990         .tokens = {
4991                 (void *)&cmd_gro_enable_set,
4992                 (void *)&cmd_gro_enable_port,
4993                 (void *)&cmd_gro_enable_pid,
4994                 (void *)&cmd_gro_enable_keyword,
4995                 (void *)&cmd_gro_enable_onoff,
4996                 NULL,
4997         },
4998 };
4999
5000 /* *** DISPLAY GRO CONFIGURATION *** */
5001 struct cmd_gro_show_result {
5002         cmdline_fixed_string_t cmd_show;
5003         cmdline_fixed_string_t cmd_port;
5004         cmdline_fixed_string_t cmd_keyword;
5005         portid_t cmd_pid;
5006 };
5007
5008 static void
5009 cmd_gro_show_parsed(void *parsed_result,
5010                 __rte_unused struct cmdline *cl,
5011                 __rte_unused void *data)
5012 {
5013         struct cmd_gro_show_result *res;
5014
5015         res = parsed_result;
5016         if (!strcmp(res->cmd_keyword, "gro"))
5017                 show_gro(res->cmd_pid);
5018 }
5019
5020 cmdline_parse_token_string_t cmd_gro_show_show =
5021         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5022                         cmd_show, "show");
5023 cmdline_parse_token_string_t cmd_gro_show_port =
5024         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5025                         cmd_port, "port");
5026 cmdline_parse_token_num_t cmd_gro_show_pid =
5027         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5028                         cmd_pid, UINT16);
5029 cmdline_parse_token_string_t cmd_gro_show_keyword =
5030         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5031                         cmd_keyword, "gro");
5032
5033 cmdline_parse_inst_t cmd_gro_show = {
5034         .f = cmd_gro_show_parsed,
5035         .data = NULL,
5036         .help_str = "show port <port_id> gro",
5037         .tokens = {
5038                 (void *)&cmd_gro_show_show,
5039                 (void *)&cmd_gro_show_port,
5040                 (void *)&cmd_gro_show_pid,
5041                 (void *)&cmd_gro_show_keyword,
5042                 NULL,
5043         },
5044 };
5045
5046 /* *** SET FLUSH CYCLES FOR GRO *** */
5047 struct cmd_gro_flush_result {
5048         cmdline_fixed_string_t cmd_set;
5049         cmdline_fixed_string_t cmd_keyword;
5050         cmdline_fixed_string_t cmd_flush;
5051         uint8_t cmd_cycles;
5052 };
5053
5054 static void
5055 cmd_gro_flush_parsed(void *parsed_result,
5056                 __rte_unused struct cmdline *cl,
5057                 __rte_unused void *data)
5058 {
5059         struct cmd_gro_flush_result *res;
5060
5061         res = parsed_result;
5062         if ((!strcmp(res->cmd_keyword, "gro")) &&
5063                         (!strcmp(res->cmd_flush, "flush")))
5064                 setup_gro_flush_cycles(res->cmd_cycles);
5065 }
5066
5067 cmdline_parse_token_string_t cmd_gro_flush_set =
5068         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5069                         cmd_set, "set");
5070 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5071         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5072                         cmd_keyword, "gro");
5073 cmdline_parse_token_string_t cmd_gro_flush_flush =
5074         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5075                         cmd_flush, "flush");
5076 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5077         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5078                         cmd_cycles, UINT8);
5079
5080 cmdline_parse_inst_t cmd_gro_flush = {
5081         .f = cmd_gro_flush_parsed,
5082         .data = NULL,
5083         .help_str = "set gro flush <cycles>",
5084         .tokens = {
5085                 (void *)&cmd_gro_flush_set,
5086                 (void *)&cmd_gro_flush_keyword,
5087                 (void *)&cmd_gro_flush_flush,
5088                 (void *)&cmd_gro_flush_cycles,
5089                 NULL,
5090         },
5091 };
5092
5093 /* *** ENABLE/DISABLE GSO *** */
5094 struct cmd_gso_enable_result {
5095         cmdline_fixed_string_t cmd_set;
5096         cmdline_fixed_string_t cmd_port;
5097         cmdline_fixed_string_t cmd_keyword;
5098         cmdline_fixed_string_t cmd_mode;
5099         portid_t cmd_pid;
5100 };
5101
5102 static void
5103 cmd_gso_enable_parsed(void *parsed_result,
5104                 __rte_unused struct cmdline *cl,
5105                 __rte_unused void *data)
5106 {
5107         struct cmd_gso_enable_result *res;
5108
5109         res = parsed_result;
5110         if (!strcmp(res->cmd_keyword, "gso"))
5111                 setup_gso(res->cmd_mode, res->cmd_pid);
5112 }
5113
5114 cmdline_parse_token_string_t cmd_gso_enable_set =
5115         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5116                         cmd_set, "set");
5117 cmdline_parse_token_string_t cmd_gso_enable_port =
5118         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5119                         cmd_port, "port");
5120 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5121         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5122                         cmd_keyword, "gso");
5123 cmdline_parse_token_string_t cmd_gso_enable_mode =
5124         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5125                         cmd_mode, "on#off");
5126 cmdline_parse_token_num_t cmd_gso_enable_pid =
5127         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5128                         cmd_pid, UINT16);
5129
5130 cmdline_parse_inst_t cmd_gso_enable = {
5131         .f = cmd_gso_enable_parsed,
5132         .data = NULL,
5133         .help_str = "set port <port_id> gso on|off",
5134         .tokens = {
5135                 (void *)&cmd_gso_enable_set,
5136                 (void *)&cmd_gso_enable_port,
5137                 (void *)&cmd_gso_enable_pid,
5138                 (void *)&cmd_gso_enable_keyword,
5139                 (void *)&cmd_gso_enable_mode,
5140                 NULL,
5141         },
5142 };
5143
5144 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5145 struct cmd_gso_size_result {
5146         cmdline_fixed_string_t cmd_set;
5147         cmdline_fixed_string_t cmd_keyword;
5148         cmdline_fixed_string_t cmd_segsz;
5149         uint16_t cmd_size;
5150 };
5151
5152 static void
5153 cmd_gso_size_parsed(void *parsed_result,
5154                        __rte_unused struct cmdline *cl,
5155                        __rte_unused void *data)
5156 {
5157         struct cmd_gso_size_result *res = parsed_result;
5158
5159         if (test_done == 0) {
5160                 printf("Before setting GSO segsz, please first"
5161                                 " stop forwarding\n");
5162                 return;
5163         }
5164
5165         if (!strcmp(res->cmd_keyword, "gso") &&
5166                         !strcmp(res->cmd_segsz, "segsz")) {
5167                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5168                         printf("gso_size should be larger than %zu."
5169                                         " Please input a legal value\n",
5170                                         RTE_GSO_SEG_SIZE_MIN);
5171                 else
5172                         gso_max_segment_size = res->cmd_size;
5173         }
5174 }
5175
5176 cmdline_parse_token_string_t cmd_gso_size_set =
5177         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5178                                 cmd_set, "set");
5179 cmdline_parse_token_string_t cmd_gso_size_keyword =
5180         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5181                                 cmd_keyword, "gso");
5182 cmdline_parse_token_string_t cmd_gso_size_segsz =
5183         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5184                                 cmd_segsz, "segsz");
5185 cmdline_parse_token_num_t cmd_gso_size_size =
5186         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5187                                 cmd_size, UINT16);
5188
5189 cmdline_parse_inst_t cmd_gso_size = {
5190         .f = cmd_gso_size_parsed,
5191         .data = NULL,
5192         .help_str = "set gso segsz <length>",
5193         .tokens = {
5194                 (void *)&cmd_gso_size_set,
5195                 (void *)&cmd_gso_size_keyword,
5196                 (void *)&cmd_gso_size_segsz,
5197                 (void *)&cmd_gso_size_size,
5198                 NULL,
5199         },
5200 };
5201
5202 /* *** SHOW GSO CONFIGURATION *** */
5203 struct cmd_gso_show_result {
5204         cmdline_fixed_string_t cmd_show;
5205         cmdline_fixed_string_t cmd_port;
5206         cmdline_fixed_string_t cmd_keyword;
5207         portid_t cmd_pid;
5208 };
5209
5210 static void
5211 cmd_gso_show_parsed(void *parsed_result,
5212                        __rte_unused struct cmdline *cl,
5213                        __rte_unused void *data)
5214 {
5215         struct cmd_gso_show_result *res = parsed_result;
5216
5217         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5218                 printf("invalid port id %u\n", res->cmd_pid);
5219                 return;
5220         }
5221         if (!strcmp(res->cmd_keyword, "gso")) {
5222                 if (gso_ports[res->cmd_pid].enable) {
5223                         printf("Max GSO'd packet size: %uB\n"
5224                                         "Supported GSO types: TCP/IPv4, "
5225                                         "UDP/IPv4, VxLAN with inner "
5226                                         "TCP/IPv4 packet, GRE with inner "
5227                                         "TCP/IPv4 packet\n",
5228                                         gso_max_segment_size);
5229                 } else
5230                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5231         }
5232 }
5233
5234 cmdline_parse_token_string_t cmd_gso_show_show =
5235 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5236                 cmd_show, "show");
5237 cmdline_parse_token_string_t cmd_gso_show_port =
5238 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5239                 cmd_port, "port");
5240 cmdline_parse_token_string_t cmd_gso_show_keyword =
5241         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5242                                 cmd_keyword, "gso");
5243 cmdline_parse_token_num_t cmd_gso_show_pid =
5244         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5245                                 cmd_pid, UINT16);
5246
5247 cmdline_parse_inst_t cmd_gso_show = {
5248         .f = cmd_gso_show_parsed,
5249         .data = NULL,
5250         .help_str = "show port <port_id> gso",
5251         .tokens = {
5252                 (void *)&cmd_gso_show_show,
5253                 (void *)&cmd_gso_show_port,
5254                 (void *)&cmd_gso_show_pid,
5255                 (void *)&cmd_gso_show_keyword,
5256                 NULL,
5257         },
5258 };
5259
5260 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5261 struct cmd_set_flush_rx {
5262         cmdline_fixed_string_t set;
5263         cmdline_fixed_string_t flush_rx;
5264         cmdline_fixed_string_t mode;
5265 };
5266
5267 static void
5268 cmd_set_flush_rx_parsed(void *parsed_result,
5269                 __rte_unused struct cmdline *cl,
5270                 __rte_unused void *data)
5271 {
5272         struct cmd_set_flush_rx *res = parsed_result;
5273         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5274 }
5275
5276 cmdline_parse_token_string_t cmd_setflushrx_set =
5277         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5278                         set, "set");
5279 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5280         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5281                         flush_rx, "flush_rx");
5282 cmdline_parse_token_string_t cmd_setflushrx_mode =
5283         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5284                         mode, "on#off");
5285
5286
5287 cmdline_parse_inst_t cmd_set_flush_rx = {
5288         .f = cmd_set_flush_rx_parsed,
5289         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5290         .data = NULL,
5291         .tokens = {
5292                 (void *)&cmd_setflushrx_set,
5293                 (void *)&cmd_setflushrx_flush_rx,
5294                 (void *)&cmd_setflushrx_mode,
5295                 NULL,
5296         },
5297 };
5298
5299 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5300 struct cmd_set_link_check {
5301         cmdline_fixed_string_t set;
5302         cmdline_fixed_string_t link_check;
5303         cmdline_fixed_string_t mode;
5304 };
5305
5306 static void
5307 cmd_set_link_check_parsed(void *parsed_result,
5308                 __rte_unused struct cmdline *cl,
5309                 __rte_unused void *data)
5310 {
5311         struct cmd_set_link_check *res = parsed_result;
5312         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5313 }
5314
5315 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5316         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5317                         set, "set");
5318 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5319         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5320                         link_check, "link_check");
5321 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5322         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5323                         mode, "on#off");
5324
5325
5326 cmdline_parse_inst_t cmd_set_link_check = {
5327         .f = cmd_set_link_check_parsed,
5328         .help_str = "set link_check on|off: Enable/Disable link status check "
5329                     "when starting/stopping a port",
5330         .data = NULL,
5331         .tokens = {
5332                 (void *)&cmd_setlinkcheck_set,
5333                 (void *)&cmd_setlinkcheck_link_check,
5334                 (void *)&cmd_setlinkcheck_mode,
5335                 NULL,
5336         },
5337 };
5338
5339 /* *** SET NIC BYPASS MODE *** */
5340 struct cmd_set_bypass_mode_result {
5341         cmdline_fixed_string_t set;
5342         cmdline_fixed_string_t bypass;
5343         cmdline_fixed_string_t mode;
5344         cmdline_fixed_string_t value;
5345         portid_t port_id;
5346 };
5347
5348 static void
5349 cmd_set_bypass_mode_parsed(void *parsed_result,
5350                 __rte_unused struct cmdline *cl,
5351                 __rte_unused void *data)
5352 {
5353         struct cmd_set_bypass_mode_result *res = parsed_result;
5354         portid_t port_id = res->port_id;
5355         int32_t rc = -EINVAL;
5356
5357 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5358         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5359
5360         if (!strcmp(res->value, "bypass"))
5361                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5362         else if (!strcmp(res->value, "isolate"))
5363                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5364         else
5365                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5366
5367         /* Set the bypass mode for the relevant port. */
5368         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5369 #endif
5370         if (rc != 0)
5371                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5372 }
5373
5374 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5375         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5376                         set, "set");
5377 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5378         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5379                         bypass, "bypass");
5380 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5381         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5382                         mode, "mode");
5383 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5384         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5385                         value, "normal#bypass#isolate");
5386 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5387         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5388                                 port_id, UINT16);
5389
5390 cmdline_parse_inst_t cmd_set_bypass_mode = {
5391         .f = cmd_set_bypass_mode_parsed,
5392         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5393                     "Set the NIC bypass mode for port_id",
5394         .data = NULL,
5395         .tokens = {
5396                 (void *)&cmd_setbypass_mode_set,
5397                 (void *)&cmd_setbypass_mode_bypass,
5398                 (void *)&cmd_setbypass_mode_mode,
5399                 (void *)&cmd_setbypass_mode_value,
5400                 (void *)&cmd_setbypass_mode_port,
5401                 NULL,
5402         },
5403 };
5404
5405 /* *** SET NIC BYPASS EVENT *** */
5406 struct cmd_set_bypass_event_result {
5407         cmdline_fixed_string_t set;
5408         cmdline_fixed_string_t bypass;
5409         cmdline_fixed_string_t event;
5410         cmdline_fixed_string_t event_value;
5411         cmdline_fixed_string_t mode;
5412         cmdline_fixed_string_t mode_value;
5413         portid_t port_id;
5414 };
5415
5416 static void
5417 cmd_set_bypass_event_parsed(void *parsed_result,
5418                 __rte_unused struct cmdline *cl,
5419                 __rte_unused void *data)
5420 {
5421         int32_t rc = -EINVAL;
5422         struct cmd_set_bypass_event_result *res = parsed_result;
5423         portid_t port_id = res->port_id;
5424
5425 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5426         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5427         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5428
5429         if (!strcmp(res->event_value, "timeout"))
5430                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5431         else if (!strcmp(res->event_value, "os_on"))
5432                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5433         else if (!strcmp(res->event_value, "os_off"))
5434                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5435         else if (!strcmp(res->event_value, "power_on"))
5436                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5437         else if (!strcmp(res->event_value, "power_off"))
5438                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5439         else
5440                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5441
5442         if (!strcmp(res->mode_value, "bypass"))
5443                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5444         else if (!strcmp(res->mode_value, "isolate"))
5445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5446         else
5447                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5448
5449         /* Set the watchdog timeout. */
5450         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5451
5452                 rc = -EINVAL;
5453                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5454                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5455                                                            bypass_timeout);
5456                 }
5457                 if (rc != 0) {
5458                         printf("Failed to set timeout value %u "
5459                         "for port %d, errto code: %d.\n",
5460                         bypass_timeout, port_id, rc);
5461                 }
5462         }
5463
5464         /* Set the bypass event to transition to bypass mode. */
5465         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5466                                               bypass_mode);
5467 #endif
5468
5469         if (rc != 0)
5470                 printf("\t Failed to set bypass event for port = %d.\n",
5471                        port_id);
5472 }
5473
5474 cmdline_parse_token_string_t cmd_setbypass_event_set =
5475         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5476                         set, "set");
5477 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5478         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5479                         bypass, "bypass");
5480 cmdline_parse_token_string_t cmd_setbypass_event_event =
5481         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5482                         event, "event");
5483 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5484         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5485                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5486 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5488                         mode, "mode");
5489 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5490         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5491                         mode_value, "normal#bypass#isolate");
5492 cmdline_parse_token_num_t cmd_setbypass_event_port =
5493         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5494                                 port_id, UINT16);
5495
5496 cmdline_parse_inst_t cmd_set_bypass_event = {
5497         .f = cmd_set_bypass_event_parsed,
5498         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5499                 "power_off mode normal|bypass|isolate <port_id>: "
5500                 "Set the NIC bypass event mode for port_id",
5501         .data = NULL,
5502         .tokens = {
5503                 (void *)&cmd_setbypass_event_set,
5504                 (void *)&cmd_setbypass_event_bypass,
5505                 (void *)&cmd_setbypass_event_event,
5506                 (void *)&cmd_setbypass_event_event_value,
5507                 (void *)&cmd_setbypass_event_mode,
5508                 (void *)&cmd_setbypass_event_mode_value,
5509                 (void *)&cmd_setbypass_event_port,
5510                 NULL,
5511         },
5512 };
5513
5514
5515 /* *** SET NIC BYPASS TIMEOUT *** */
5516 struct cmd_set_bypass_timeout_result {
5517         cmdline_fixed_string_t set;
5518         cmdline_fixed_string_t bypass;
5519         cmdline_fixed_string_t timeout;
5520         cmdline_fixed_string_t value;
5521 };
5522
5523 static void
5524 cmd_set_bypass_timeout_parsed(void *parsed_result,
5525                 __rte_unused struct cmdline *cl,
5526                 __rte_unused void *data)
5527 {
5528         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5529
5530 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5531         if (!strcmp(res->value, "1.5"))
5532                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5533         else if (!strcmp(res->value, "2"))
5534                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5535         else if (!strcmp(res->value, "3"))
5536                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5537         else if (!strcmp(res->value, "4"))
5538                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5539         else if (!strcmp(res->value, "8"))
5540                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5541         else if (!strcmp(res->value, "16"))
5542                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5543         else if (!strcmp(res->value, "32"))
5544                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5545         else
5546                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5547 #endif
5548 }
5549
5550 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5551         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5552                         set, "set");
5553 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5554         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5555                         bypass, "bypass");
5556 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5558                         timeout, "timeout");
5559 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5560         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5561                         value, "0#1.5#2#3#4#8#16#32");
5562
5563 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5564         .f = cmd_set_bypass_timeout_parsed,
5565         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5566                 "Set the NIC bypass watchdog timeout in seconds",
5567         .data = NULL,
5568         .tokens = {
5569                 (void *)&cmd_setbypass_timeout_set,
5570                 (void *)&cmd_setbypass_timeout_bypass,
5571                 (void *)&cmd_setbypass_timeout_timeout,
5572                 (void *)&cmd_setbypass_timeout_value,
5573                 NULL,
5574         },
5575 };
5576
5577 /* *** SHOW NIC BYPASS MODE *** */
5578 struct cmd_show_bypass_config_result {
5579         cmdline_fixed_string_t show;
5580         cmdline_fixed_string_t bypass;
5581         cmdline_fixed_string_t config;
5582         portid_t port_id;
5583 };
5584
5585 static void
5586 cmd_show_bypass_config_parsed(void *parsed_result,
5587                 __rte_unused struct cmdline *cl,
5588                 __rte_unused void *data)
5589 {
5590         struct cmd_show_bypass_config_result *res = parsed_result;
5591         portid_t port_id = res->port_id;
5592         int rc = -EINVAL;
5593 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5594         uint32_t event_mode;
5595         uint32_t bypass_mode;
5596         uint32_t timeout = bypass_timeout;
5597         unsigned int i;
5598
5599         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5600                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5601         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5602                 {"UNKNOWN", "normal", "bypass", "isolate"};
5603         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5604                 "NONE",
5605                 "OS/board on",
5606                 "power supply on",
5607                 "OS/board off",
5608                 "power supply off",
5609                 "timeout"};
5610
5611         /* Display the bypass mode.*/
5612         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5613                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5614                 return;
5615         }
5616         else {
5617                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5618                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5619
5620                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5621         }
5622
5623         /* Display the bypass timeout.*/
5624         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5625                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5626
5627         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5628
5629         /* Display the bypass events and associated modes. */
5630         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5631
5632                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5633                         printf("\tFailed to get bypass mode for event = %s\n",
5634                                 events[i]);
5635                 } else {
5636                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5637                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5638
5639                         printf("\tbypass event: %-16s = %s\n", events[i],
5640                                 modes[event_mode]);
5641                 }
5642         }
5643 #endif
5644         if (rc != 0)
5645                 printf("\tFailed to get bypass configuration for port = %d\n",
5646                        port_id);
5647 }
5648
5649 cmdline_parse_token_string_t cmd_showbypass_config_show =
5650         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5651                         show, "show");
5652 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5653         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5654                         bypass, "bypass");
5655 cmdline_parse_token_string_t cmd_showbypass_config_config =
5656         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5657                         config, "config");
5658 cmdline_parse_token_num_t cmd_showbypass_config_port =
5659         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5660                                 port_id, UINT16);
5661
5662 cmdline_parse_inst_t cmd_show_bypass_config = {
5663         .f = cmd_show_bypass_config_parsed,
5664         .help_str = "show bypass config <port_id>: "
5665                     "Show the NIC bypass config for port_id",
5666         .data = NULL,
5667         .tokens = {
5668                 (void *)&cmd_showbypass_config_show,
5669                 (void *)&cmd_showbypass_config_bypass,
5670                 (void *)&cmd_showbypass_config_config,
5671                 (void *)&cmd_showbypass_config_port,
5672                 NULL,
5673         },
5674 };
5675
5676 #ifdef RTE_LIBRTE_PMD_BOND
5677 /* *** SET BONDING MODE *** */
5678 struct cmd_set_bonding_mode_result {
5679         cmdline_fixed_string_t set;
5680         cmdline_fixed_string_t bonding;
5681         cmdline_fixed_string_t mode;
5682         uint8_t value;
5683         portid_t port_id;
5684 };
5685
5686 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5687                 __rte_unused  struct cmdline *cl,
5688                 __rte_unused void *data)
5689 {
5690         struct cmd_set_bonding_mode_result *res = parsed_result;
5691         portid_t port_id = res->port_id;
5692
5693         /* Set the bonding mode for the relevant port. */
5694         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5695                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5696 }
5697
5698 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5699 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5700                 set, "set");
5701 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5702 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5703                 bonding, "bonding");
5704 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5705 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5706                 mode, "mode");
5707 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5708 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5709                 value, UINT8);
5710 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5711 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5712                 port_id, UINT16);
5713
5714 cmdline_parse_inst_t cmd_set_bonding_mode = {
5715                 .f = cmd_set_bonding_mode_parsed,
5716                 .help_str = "set bonding mode <mode_value> <port_id>: "
5717                         "Set the bonding mode for port_id",
5718                 .data = NULL,
5719                 .tokens = {
5720                                 (void *) &cmd_setbonding_mode_set,
5721                                 (void *) &cmd_setbonding_mode_bonding,
5722                                 (void *) &cmd_setbonding_mode_mode,
5723                                 (void *) &cmd_setbonding_mode_value,
5724                                 (void *) &cmd_setbonding_mode_port,
5725                                 NULL
5726                 }
5727 };
5728
5729 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5730 struct cmd_set_bonding_lacp_dedicated_queues_result {
5731         cmdline_fixed_string_t set;
5732         cmdline_fixed_string_t bonding;
5733         cmdline_fixed_string_t lacp;
5734         cmdline_fixed_string_t dedicated_queues;
5735         portid_t port_id;
5736         cmdline_fixed_string_t mode;
5737 };
5738
5739 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5740                 __rte_unused  struct cmdline *cl,
5741                 __rte_unused void *data)
5742 {
5743         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5744         portid_t port_id = res->port_id;
5745         struct rte_port *port;
5746
5747         port = &ports[port_id];
5748
5749         /** Check if the port is not started **/
5750         if (port->port_status != RTE_PORT_STOPPED) {
5751                 printf("Please stop port %d first\n", port_id);
5752                 return;
5753         }
5754
5755         if (!strcmp(res->mode, "enable")) {
5756                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5757                         printf("Dedicate queues for LACP control packets"
5758                                         " enabled\n");
5759                 else
5760                         printf("Enabling dedicate queues for LACP control "
5761                                         "packets on port %d failed\n", port_id);
5762         } else if (!strcmp(res->mode, "disable")) {
5763                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5764                         printf("Dedicated queues for LACP control packets "
5765                                         "disabled\n");
5766                 else
5767                         printf("Disabling dedicated queues for LACP control "
5768                                         "traffic on port %d failed\n", port_id);
5769         }
5770 }
5771
5772 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5774                 set, "set");
5775 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5776 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5777                 bonding, "bonding");
5778 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5779 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5780                 lacp, "lacp");
5781 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5783                 dedicated_queues, "dedicated_queues");
5784 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5785 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5786                 port_id, UINT16);
5787 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5788 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5789                 mode, "enable#disable");
5790
5791 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5792                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5793                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5794                         "enable|disable: "
5795                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5796                 .data = NULL,
5797                 .tokens = {
5798                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5799                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5800                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5801                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5802                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5803                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5804                         NULL
5805                 }
5806 };
5807
5808 /* *** SET BALANCE XMIT POLICY *** */
5809 struct cmd_set_bonding_balance_xmit_policy_result {
5810         cmdline_fixed_string_t set;
5811         cmdline_fixed_string_t bonding;
5812         cmdline_fixed_string_t balance_xmit_policy;
5813         portid_t port_id;
5814         cmdline_fixed_string_t policy;
5815 };
5816
5817 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5818                 __rte_unused  struct cmdline *cl,
5819                 __rte_unused void *data)
5820 {
5821         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5822         portid_t port_id = res->port_id;
5823         uint8_t policy;
5824
5825         if (!strcmp(res->policy, "l2")) {
5826                 policy = BALANCE_XMIT_POLICY_LAYER2;
5827         } else if (!strcmp(res->policy, "l23")) {
5828                 policy = BALANCE_XMIT_POLICY_LAYER23;
5829         } else if (!strcmp(res->policy, "l34")) {
5830                 policy = BALANCE_XMIT_POLICY_LAYER34;
5831         } else {
5832                 printf("\t Invalid xmit policy selection");
5833                 return;
5834         }
5835
5836         /* Set the bonding mode for the relevant port. */
5837         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5838                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5839                                 port_id);
5840         }
5841 }
5842
5843 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5844 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5845                 set, "set");
5846 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5848                 bonding, "bonding");
5849 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5851                 balance_xmit_policy, "balance_xmit_policy");
5852 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5853 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5854                 port_id, UINT16);
5855 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5857                 policy, "l2#l23#l34");
5858
5859 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5860                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5861                 .help_str = "set bonding balance_xmit_policy <port_id> "
5862                         "l2|l23|l34: "
5863                         "Set the bonding balance_xmit_policy for port_id",
5864                 .data = NULL,
5865                 .tokens = {
5866                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5867                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5868                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5869                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5870                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5871                                 NULL
5872                 }
5873 };
5874
5875 /* *** SHOW NIC BONDING CONFIGURATION *** */
5876 struct cmd_show_bonding_config_result {
5877         cmdline_fixed_string_t show;
5878         cmdline_fixed_string_t bonding;
5879         cmdline_fixed_string_t config;
5880         portid_t port_id;
5881 };
5882
5883 static void cmd_show_bonding_config_parsed(void *parsed_result,
5884                 __rte_unused  struct cmdline *cl,
5885                 __rte_unused void *data)
5886 {
5887         struct cmd_show_bonding_config_result *res = parsed_result;
5888         int bonding_mode, agg_mode;
5889         portid_t slaves[RTE_MAX_ETHPORTS];
5890         int num_slaves, num_active_slaves;
5891         int primary_id;
5892         int i;
5893         portid_t port_id = res->port_id;
5894
5895         /* Display the bonding mode.*/
5896         bonding_mode = rte_eth_bond_mode_get(port_id);
5897         if (bonding_mode < 0) {
5898                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5899                 return;
5900         } else
5901                 printf("\tBonding mode: %d\n", bonding_mode);
5902
5903         if (bonding_mode == BONDING_MODE_BALANCE) {
5904                 int balance_xmit_policy;
5905
5906                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5907                 if (balance_xmit_policy < 0) {
5908                         printf("\tFailed to get balance xmit policy for port = %d\n",
5909                                         port_id);
5910                         return;
5911                 } else {
5912                         printf("\tBalance Xmit Policy: ");
5913
5914                         switch (balance_xmit_policy) {
5915                         case BALANCE_XMIT_POLICY_LAYER2:
5916                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5917                                 break;
5918                         case BALANCE_XMIT_POLICY_LAYER23:
5919                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5920                                 break;
5921                         case BALANCE_XMIT_POLICY_LAYER34:
5922                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5923                                 break;
5924                         }
5925                         printf("\n");
5926                 }
5927         }
5928
5929         if (bonding_mode == BONDING_MODE_8023AD) {
5930                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5931                 printf("\tIEEE802.3AD Aggregator Mode: ");
5932                 switch (agg_mode) {
5933                 case AGG_BANDWIDTH:
5934                         printf("bandwidth");
5935                         break;
5936                 case AGG_STABLE:
5937                         printf("stable");
5938                         break;
5939                 case AGG_COUNT:
5940                         printf("count");
5941                         break;
5942                 }
5943                 printf("\n");
5944         }
5945
5946         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5947
5948         if (num_slaves < 0) {
5949                 printf("\tFailed to get slave list for port = %d\n", port_id);
5950                 return;
5951         }
5952         if (num_slaves > 0) {
5953                 printf("\tSlaves (%d): [", num_slaves);
5954                 for (i = 0; i < num_slaves - 1; i++)
5955                         printf("%d ", slaves[i]);
5956
5957                 printf("%d]\n", slaves[num_slaves - 1]);
5958         } else {
5959                 printf("\tSlaves: []\n");
5960
5961         }
5962
5963         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5964                         RTE_MAX_ETHPORTS);
5965
5966         if (num_active_slaves < 0) {
5967                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5968                 return;
5969         }
5970         if (num_active_slaves > 0) {
5971                 printf("\tActive Slaves (%d): [", num_active_slaves);
5972                 for (i = 0; i < num_active_slaves - 1; i++)
5973                         printf("%d ", slaves[i]);
5974
5975                 printf("%d]\n", slaves[num_active_slaves - 1]);
5976
5977         } else {
5978                 printf("\tActive Slaves: []\n");
5979
5980         }
5981
5982         primary_id = rte_eth_bond_primary_get(port_id);
5983         if (primary_id < 0) {
5984                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5985                 return;
5986         } else
5987                 printf("\tPrimary: [%d]\n", primary_id);
5988
5989 }
5990
5991 cmdline_parse_token_string_t cmd_showbonding_config_show =
5992 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5993                 show, "show");
5994 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5995 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5996                 bonding, "bonding");
5997 cmdline_parse_token_string_t cmd_showbonding_config_config =
5998 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5999                 config, "config");
6000 cmdline_parse_token_num_t cmd_showbonding_config_port =
6001 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6002                 port_id, UINT16);
6003
6004 cmdline_parse_inst_t cmd_show_bonding_config = {
6005                 .f = cmd_show_bonding_config_parsed,
6006                 .help_str = "show bonding config <port_id>: "
6007                         "Show the bonding config for port_id",
6008                 .data = NULL,
6009                 .tokens = {
6010                                 (void *)&cmd_showbonding_config_show,
6011                                 (void *)&cmd_showbonding_config_bonding,
6012                                 (void *)&cmd_showbonding_config_config,
6013                                 (void *)&cmd_showbonding_config_port,
6014                                 NULL
6015                 }
6016 };
6017
6018 /* *** SET BONDING PRIMARY *** */
6019 struct cmd_set_bonding_primary_result {
6020         cmdline_fixed_string_t set;
6021         cmdline_fixed_string_t bonding;
6022         cmdline_fixed_string_t primary;
6023         portid_t slave_id;
6024         portid_t port_id;
6025 };
6026
6027 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6028                 __rte_unused  struct cmdline *cl,
6029                 __rte_unused void *data)
6030 {
6031         struct cmd_set_bonding_primary_result *res = parsed_result;
6032         portid_t master_port_id = res->port_id;
6033         portid_t slave_port_id = res->slave_id;
6034
6035         /* Set the primary slave for a bonded device. */
6036         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6037                 printf("\t Failed to set primary slave for port = %d.\n",
6038                                 master_port_id);
6039                 return;
6040         }
6041         init_port_config();
6042 }
6043
6044 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6045 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6046                 set, "set");
6047 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6048 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6049                 bonding, "bonding");
6050 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6051 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6052                 primary, "primary");
6053 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6054 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6055                 slave_id, UINT16);
6056 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6057 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6058                 port_id, UINT16);
6059
6060 cmdline_parse_inst_t cmd_set_bonding_primary = {
6061                 .f = cmd_set_bonding_primary_parsed,
6062                 .help_str = "set bonding primary <slave_id> <port_id>: "
6063                         "Set the primary slave for port_id",
6064                 .data = NULL,
6065                 .tokens = {
6066                                 (void *)&cmd_setbonding_primary_set,
6067                                 (void *)&cmd_setbonding_primary_bonding,
6068                                 (void *)&cmd_setbonding_primary_primary,
6069                                 (void *)&cmd_setbonding_primary_slave,
6070                                 (void *)&cmd_setbonding_primary_port,
6071                                 NULL
6072                 }
6073 };
6074
6075 /* *** ADD SLAVE *** */
6076 struct cmd_add_bonding_slave_result {
6077         cmdline_fixed_string_t add;
6078         cmdline_fixed_string_t bonding;
6079         cmdline_fixed_string_t slave;
6080         portid_t slave_id;
6081         portid_t port_id;
6082 };
6083
6084 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6085                 __rte_unused  struct cmdline *cl,
6086                 __rte_unused void *data)
6087 {
6088         struct cmd_add_bonding_slave_result *res = parsed_result;
6089         portid_t master_port_id = res->port_id;
6090         portid_t slave_port_id = res->slave_id;
6091
6092         /* add the slave for a bonded device. */
6093         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6094                 printf("\t Failed to add slave %d to master port = %d.\n",
6095                                 slave_port_id, master_port_id);
6096                 return;
6097         }
6098         init_port_config();
6099         set_port_slave_flag(slave_port_id);
6100 }
6101
6102 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6103 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6104                 add, "add");
6105 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6106 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6107                 bonding, "bonding");
6108 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6109 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6110                 slave, "slave");
6111 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6112 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6113                 slave_id, UINT16);
6114 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6115 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6116                 port_id, UINT16);
6117
6118 cmdline_parse_inst_t cmd_add_bonding_slave = {
6119                 .f = cmd_add_bonding_slave_parsed,
6120                 .help_str = "add bonding slave <slave_id> <port_id>: "
6121                         "Add a slave device to a bonded device",
6122                 .data = NULL,
6123                 .tokens = {
6124                                 (void *)&cmd_addbonding_slave_add,
6125                                 (void *)&cmd_addbonding_slave_bonding,
6126                                 (void *)&cmd_addbonding_slave_slave,
6127                                 (void *)&cmd_addbonding_slave_slaveid,
6128                                 (void *)&cmd_addbonding_slave_port,
6129                                 NULL
6130                 }
6131 };
6132
6133 /* *** REMOVE SLAVE *** */
6134 struct cmd_remove_bonding_slave_result {
6135         cmdline_fixed_string_t remove;
6136         cmdline_fixed_string_t bonding;
6137         cmdline_fixed_string_t slave;
6138         portid_t slave_id;
6139         portid_t port_id;
6140 };
6141
6142 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6143                 __rte_unused  struct cmdline *cl,
6144                 __rte_unused void *data)
6145 {
6146         struct cmd_remove_bonding_slave_result *res = parsed_result;
6147         portid_t master_port_id = res->port_id;
6148         portid_t slave_port_id = res->slave_id;
6149
6150         /* remove the slave from a bonded device. */
6151         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6152                 printf("\t Failed to remove slave %d from master port = %d.\n",
6153                                 slave_port_id, master_port_id);
6154                 return;
6155         }
6156         init_port_config();
6157         clear_port_slave_flag(slave_port_id);
6158 }
6159
6160 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6161                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6162                                 remove, "remove");
6163 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6164                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6165                                 bonding, "bonding");
6166 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6167                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6168                                 slave, "slave");
6169 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6170                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6171                                 slave_id, UINT16);
6172 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6173                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6174                                 port_id, UINT16);
6175
6176 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6177                 .f = cmd_remove_bonding_slave_parsed,
6178                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6179                         "Remove a slave device from a bonded device",
6180                 .data = NULL,
6181                 .tokens = {
6182                                 (void *)&cmd_removebonding_slave_remove,
6183                                 (void *)&cmd_removebonding_slave_bonding,
6184                                 (void *)&cmd_removebonding_slave_slave,
6185                                 (void *)&cmd_removebonding_slave_slaveid,
6186                                 (void *)&cmd_removebonding_slave_port,
6187                                 NULL
6188                 }
6189 };
6190
6191 /* *** CREATE BONDED DEVICE *** */
6192 struct cmd_create_bonded_device_result {
6193         cmdline_fixed_string_t create;
6194         cmdline_fixed_string_t bonded;
6195         cmdline_fixed_string_t device;
6196         uint8_t mode;
6197         uint8_t socket;
6198 };
6199
6200 static int bond_dev_num = 0;
6201
6202 static void cmd_create_bonded_device_parsed(void *parsed_result,
6203                 __rte_unused  struct cmdline *cl,
6204                 __rte_unused void *data)
6205 {
6206         struct cmd_create_bonded_device_result *res = parsed_result;
6207         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6208         int port_id;
6209         int ret;
6210
6211         if (test_done == 0) {
6212                 printf("Please stop forwarding first\n");
6213                 return;
6214         }
6215
6216         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6217                         bond_dev_num++);
6218
6219         /* Create a new bonded device. */
6220         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6221         if (port_id < 0) {
6222                 printf("\t Failed to create bonded device.\n");
6223                 return;
6224         } else {
6225                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6226                                 port_id);
6227
6228                 /* Update number of ports */
6229                 nb_ports = rte_eth_dev_count_avail();
6230                 reconfig(port_id, res->socket);
6231                 ret = rte_eth_promiscuous_enable(port_id);
6232                 if (ret != 0)
6233                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6234                                 port_id, rte_strerror(-ret));
6235
6236                 ports[port_id].need_setup = 0;
6237                 ports[port_id].port_status = RTE_PORT_STOPPED;
6238         }
6239
6240 }
6241
6242 cmdline_parse_token_string_t cmd_createbonded_device_create =
6243                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6244                                 create, "create");
6245 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6246                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6247                                 bonded, "bonded");
6248 cmdline_parse_token_string_t cmd_createbonded_device_device =
6249                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6250                                 device, "device");
6251 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6252                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6253                                 mode, UINT8);
6254 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6255                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6256                                 socket, UINT8);
6257
6258 cmdline_parse_inst_t cmd_create_bonded_device = {
6259                 .f = cmd_create_bonded_device_parsed,
6260                 .help_str = "create bonded device <mode> <socket>: "
6261                         "Create a new bonded device with specific bonding mode and socket",
6262                 .data = NULL,
6263                 .tokens = {
6264                                 (void *)&cmd_createbonded_device_create,
6265                                 (void *)&cmd_createbonded_device_bonded,
6266                                 (void *)&cmd_createbonded_device_device,
6267                                 (void *)&cmd_createbonded_device_mode,
6268                                 (void *)&cmd_createbonded_device_socket,
6269                                 NULL
6270                 }
6271 };
6272
6273 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6274 struct cmd_set_bond_mac_addr_result {
6275         cmdline_fixed_string_t set;
6276         cmdline_fixed_string_t bonding;
6277         cmdline_fixed_string_t mac_addr;
6278         uint16_t port_num;
6279         struct rte_ether_addr address;
6280 };
6281
6282 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6283                 __rte_unused  struct cmdline *cl,
6284                 __rte_unused void *data)
6285 {
6286         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6287         int ret;
6288
6289         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6290                 return;
6291
6292         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6293
6294         /* check the return value and print it if is < 0 */
6295         if (ret < 0)
6296                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6297 }
6298
6299 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6300                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6301 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6302                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6303                                 "bonding");
6304 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6305                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6306                                 "mac_addr");
6307 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6308                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6309                                 port_num, UINT16);
6310 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6311                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6312
6313 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6314                 .f = cmd_set_bond_mac_addr_parsed,
6315                 .data = (void *) 0,
6316                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6317                 .tokens = {
6318                                 (void *)&cmd_set_bond_mac_addr_set,
6319                                 (void *)&cmd_set_bond_mac_addr_bonding,
6320                                 (void *)&cmd_set_bond_mac_addr_mac,
6321                                 (void *)&cmd_set_bond_mac_addr_portnum,
6322                                 (void *)&cmd_set_bond_mac_addr_addr,
6323                                 NULL
6324                 }
6325 };
6326
6327
6328 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6329 struct cmd_set_bond_mon_period_result {
6330         cmdline_fixed_string_t set;
6331         cmdline_fixed_string_t bonding;
6332         cmdline_fixed_string_t mon_period;
6333         uint16_t port_num;
6334         uint32_t period_ms;
6335 };
6336
6337 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6338                 __rte_unused  struct cmdline *cl,
6339                 __rte_unused void *data)
6340 {
6341         struct cmd_set_bond_mon_period_result *res = parsed_result;
6342         int ret;
6343
6344         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6345
6346         /* check the return value and print it if is < 0 */
6347         if (ret < 0)
6348                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6349 }
6350
6351 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6352                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6353                                 set, "set");
6354 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6355                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6356                                 bonding, "bonding");
6357 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6358                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6359                                 mon_period,     "mon_period");
6360 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6361                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6362                                 port_num, UINT16);
6363 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6364                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6365                                 period_ms, UINT32);
6366
6367 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6368                 .f = cmd_set_bond_mon_period_parsed,
6369                 .data = (void *) 0,
6370                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6371                 .tokens = {
6372                                 (void *)&cmd_set_bond_mon_period_set,
6373                                 (void *)&cmd_set_bond_mon_period_bonding,
6374                                 (void *)&cmd_set_bond_mon_period_mon_period,
6375                                 (void *)&cmd_set_bond_mon_period_portnum,
6376                                 (void *)&cmd_set_bond_mon_period_period_ms,
6377                                 NULL
6378                 }
6379 };
6380
6381
6382
6383 struct cmd_set_bonding_agg_mode_policy_result {
6384         cmdline_fixed_string_t set;
6385         cmdline_fixed_string_t bonding;
6386         cmdline_fixed_string_t agg_mode;
6387         uint16_t port_num;
6388         cmdline_fixed_string_t policy;
6389 };
6390
6391
6392 static void
6393 cmd_set_bonding_agg_mode(void *parsed_result,
6394                 __rte_unused struct cmdline *cl,
6395                 __rte_unused void *data)
6396 {
6397         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6398         uint8_t policy = AGG_BANDWIDTH;
6399
6400         if (!strcmp(res->policy, "bandwidth"))
6401                 policy = AGG_BANDWIDTH;
6402         else if (!strcmp(res->policy, "stable"))
6403                 policy = AGG_STABLE;
6404         else if (!strcmp(res->policy, "count"))
6405                 policy = AGG_COUNT;
6406
6407         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6408 }
6409
6410
6411 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6412         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6413                                 set, "set");
6414 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6415         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6416                                 bonding, "bonding");
6417
6418 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6419         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6420                                 agg_mode, "agg_mode");
6421
6422 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6423         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6424                                 port_num, UINT16);
6425
6426 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6427         TOKEN_STRING_INITIALIZER(
6428                         struct cmd_set_bonding_balance_xmit_policy_result,
6429                 policy, "stable#bandwidth#count");
6430
6431 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6432         .f = cmd_set_bonding_agg_mode,
6433         .data = (void *) 0,
6434         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6435         .tokens = {
6436                         (void *)&cmd_set_bonding_agg_mode_set,
6437                         (void *)&cmd_set_bonding_agg_mode_bonding,
6438                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6439                         (void *)&cmd_set_bonding_agg_mode_portnum,
6440                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6441                         NULL
6442                 }
6443 };
6444
6445
6446 #endif /* RTE_LIBRTE_PMD_BOND */
6447
6448 /* *** SET FORWARDING MODE *** */
6449 struct cmd_set_fwd_mode_result {
6450         cmdline_fixed_string_t set;
6451         cmdline_fixed_string_t fwd;
6452         cmdline_fixed_string_t mode;
6453 };
6454
6455 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6456                                     __rte_unused struct cmdline *cl,
6457                                     __rte_unused void *data)
6458 {
6459         struct cmd_set_fwd_mode_result *res = parsed_result;
6460
6461         retry_enabled = 0;
6462         set_pkt_forwarding_mode(res->mode);
6463 }
6464
6465 cmdline_parse_token_string_t cmd_setfwd_set =
6466         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6467 cmdline_parse_token_string_t cmd_setfwd_fwd =
6468         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6469 cmdline_parse_token_string_t cmd_setfwd_mode =
6470         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6471                 "" /* defined at init */);
6472
6473 cmdline_parse_inst_t cmd_set_fwd_mode = {
6474         .f = cmd_set_fwd_mode_parsed,
6475         .data = NULL,
6476         .help_str = NULL, /* defined at init */
6477         .tokens = {
6478                 (void *)&cmd_setfwd_set,
6479                 (void *)&cmd_setfwd_fwd,
6480                 (void *)&cmd_setfwd_mode,
6481                 NULL,
6482         },
6483 };
6484
6485 static void cmd_set_fwd_mode_init(void)
6486 {
6487         char *modes, *c;
6488         static char token[128];
6489         static char help[256];
6490         cmdline_parse_token_string_t *token_struct;
6491
6492         modes = list_pkt_forwarding_modes();
6493         snprintf(help, sizeof(help), "set fwd %s: "
6494                 "Set packet forwarding mode", modes);
6495         cmd_set_fwd_mode.help_str = help;
6496
6497         /* string token separator is # */
6498         for (c = token; *modes != '\0'; modes++)
6499                 if (*modes == '|')
6500                         *c++ = '#';
6501                 else
6502                         *c++ = *modes;
6503         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6504         token_struct->string_data.str = token;
6505 }
6506
6507 /* *** SET RETRY FORWARDING MODE *** */
6508 struct cmd_set_fwd_retry_mode_result {
6509         cmdline_fixed_string_t set;
6510         cmdline_fixed_string_t fwd;
6511         cmdline_fixed_string_t mode;
6512         cmdline_fixed_string_t retry;
6513 };
6514
6515 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6516                             __rte_unused struct cmdline *cl,
6517                             __rte_unused void *data)
6518 {
6519         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6520
6521         retry_enabled = 1;
6522         set_pkt_forwarding_mode(res->mode);
6523 }
6524
6525 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6526         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6527                         set, "set");
6528 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6529         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6530                         fwd, "fwd");
6531 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6532         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6533                         mode,
6534                 "" /* defined at init */);
6535 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6536         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6537                         retry, "retry");
6538
6539 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6540         .f = cmd_set_fwd_retry_mode_parsed,
6541         .data = NULL,
6542         .help_str = NULL, /* defined at init */
6543         .tokens = {
6544                 (void *)&cmd_setfwd_retry_set,
6545                 (void *)&cmd_setfwd_retry_fwd,
6546                 (void *)&cmd_setfwd_retry_mode,
6547                 (void *)&cmd_setfwd_retry_retry,
6548                 NULL,
6549         },
6550 };
6551
6552 static void cmd_set_fwd_retry_mode_init(void)
6553 {
6554         char *modes, *c;
6555         static char token[128];
6556         static char help[256];
6557         cmdline_parse_token_string_t *token_struct;
6558
6559         modes = list_pkt_forwarding_retry_modes();
6560         snprintf(help, sizeof(help), "set fwd %s retry: "
6561                 "Set packet forwarding mode with retry", modes);
6562         cmd_set_fwd_retry_mode.help_str = help;
6563
6564         /* string token separator is # */
6565         for (c = token; *modes != '\0'; modes++)
6566                 if (*modes == '|')
6567                         *c++ = '#';
6568                 else
6569                         *c++ = *modes;
6570         token_struct = (cmdline_parse_token_string_t *)
6571                 cmd_set_fwd_retry_mode.tokens[2];
6572         token_struct->string_data.str = token;
6573 }
6574
6575 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6576 struct cmd_set_burst_tx_retry_result {
6577         cmdline_fixed_string_t set;
6578         cmdline_fixed_string_t burst;
6579         cmdline_fixed_string_t tx;
6580         cmdline_fixed_string_t delay;
6581         uint32_t time;
6582         cmdline_fixed_string_t retry;
6583         uint32_t retry_num;
6584 };
6585
6586 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6587                                         __rte_unused struct cmdline *cl,
6588                                         __rte_unused void *data)
6589 {
6590         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6591
6592         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6593                 && !strcmp(res->tx, "tx")) {
6594                 if (!strcmp(res->delay, "delay"))
6595                         burst_tx_delay_time = res->time;
6596                 if (!strcmp(res->retry, "retry"))
6597                         burst_tx_retry_num = res->retry_num;
6598         }
6599
6600 }
6601
6602 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6603         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6604 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6605         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6606                                  "burst");
6607 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6608         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6609 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6610         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6611 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6612         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6613 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6614         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6615 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6616         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6617
6618 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6619         .f = cmd_set_burst_tx_retry_parsed,
6620         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6621         .tokens = {
6622                 (void *)&cmd_set_burst_tx_retry_set,
6623                 (void *)&cmd_set_burst_tx_retry_burst,
6624                 (void *)&cmd_set_burst_tx_retry_tx,
6625                 (void *)&cmd_set_burst_tx_retry_delay,
6626                 (void *)&cmd_set_burst_tx_retry_time,
6627                 (void *)&cmd_set_burst_tx_retry_retry,
6628                 (void *)&cmd_set_burst_tx_retry_retry_num,
6629                 NULL,
6630         },
6631 };
6632
6633 /* *** SET PROMISC MODE *** */
6634 struct cmd_set_promisc_mode_result {
6635         cmdline_fixed_string_t set;
6636         cmdline_fixed_string_t promisc;
6637         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6638         uint16_t port_num;               /* valid if "allports" argument == 0 */
6639         cmdline_fixed_string_t mode;
6640 };
6641
6642 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6643                                         __rte_unused struct cmdline *cl,
6644                                         void *allports)
6645 {
6646         struct cmd_set_promisc_mode_result *res = parsed_result;
6647         int enable;
6648         portid_t i;
6649
6650         if (!strcmp(res->mode, "on"))
6651                 enable = 1;
6652         else
6653                 enable = 0;
6654
6655         /* all ports */
6656         if (allports) {
6657                 RTE_ETH_FOREACH_DEV(i)
6658                         eth_set_promisc_mode(i, enable);
6659         } else {
6660                 eth_set_promisc_mode(res->port_num, enable);
6661         }
6662 }
6663
6664 cmdline_parse_token_string_t cmd_setpromisc_set =
6665         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6666 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6667         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6668                                  "promisc");
6669 cmdline_parse_token_string_t cmd_setpromisc_portall =
6670         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6671                                  "all");
6672 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6673         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6674                               UINT16);
6675 cmdline_parse_token_string_t cmd_setpromisc_mode =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6677                                  "on#off");
6678
6679 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6680         .f = cmd_set_promisc_mode_parsed,
6681         .data = (void *)1,
6682         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6683         .tokens = {
6684                 (void *)&cmd_setpromisc_set,
6685                 (void *)&cmd_setpromisc_promisc,
6686                 (void *)&cmd_setpromisc_portall,
6687                 (void *)&cmd_setpromisc_mode,
6688                 NULL,
6689         },
6690 };
6691
6692 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6693         .f = cmd_set_promisc_mode_parsed,
6694         .data = (void *)0,
6695         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6696         .tokens = {
6697                 (void *)&cmd_setpromisc_set,
6698                 (void *)&cmd_setpromisc_promisc,
6699                 (void *)&cmd_setpromisc_portnum,
6700                 (void *)&cmd_setpromisc_mode,
6701                 NULL,
6702         },
6703 };
6704
6705 /* *** SET ALLMULTI MODE *** */
6706 struct cmd_set_allmulti_mode_result {
6707         cmdline_fixed_string_t set;
6708         cmdline_fixed_string_t allmulti;
6709         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6710         uint16_t port_num;               /* valid if "allports" argument == 0 */
6711         cmdline_fixed_string_t mode;
6712 };
6713
6714 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6715                                         __rte_unused struct cmdline *cl,
6716                                         void *allports)
6717 {
6718         struct cmd_set_allmulti_mode_result *res = parsed_result;
6719         int enable;
6720         portid_t i;
6721
6722         if (!strcmp(res->mode, "on"))
6723                 enable = 1;
6724         else
6725                 enable = 0;
6726
6727         /* all ports */
6728         if (allports) {
6729                 RTE_ETH_FOREACH_DEV(i) {
6730                         eth_set_allmulticast_mode(i, enable);
6731                 }
6732         }
6733         else {
6734                 eth_set_allmulticast_mode(res->port_num, enable);
6735         }
6736 }
6737
6738 cmdline_parse_token_string_t cmd_setallmulti_set =
6739         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6740 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6742                                  "allmulti");
6743 cmdline_parse_token_string_t cmd_setallmulti_portall =
6744         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6745                                  "all");
6746 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6747         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6748                               UINT16);
6749 cmdline_parse_token_string_t cmd_setallmulti_mode =
6750         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6751                                  "on#off");
6752
6753 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6754         .f = cmd_set_allmulti_mode_parsed,
6755         .data = (void *)1,
6756         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6757         .tokens = {
6758                 (void *)&cmd_setallmulti_set,
6759                 (void *)&cmd_setallmulti_allmulti,
6760                 (void *)&cmd_setallmulti_portall,
6761                 (void *)&cmd_setallmulti_mode,
6762                 NULL,
6763         },
6764 };
6765
6766 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6767         .f = cmd_set_allmulti_mode_parsed,
6768         .data = (void *)0,
6769         .help_str = "set allmulti <port_id> on|off: "
6770                 "Set allmulti mode on port_id",
6771         .tokens = {
6772                 (void *)&cmd_setallmulti_set,
6773                 (void *)&cmd_setallmulti_allmulti,
6774                 (void *)&cmd_setallmulti_portnum,
6775                 (void *)&cmd_setallmulti_mode,
6776                 NULL,
6777         },
6778 };
6779
6780 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6781 struct cmd_link_flow_ctrl_set_result {
6782         cmdline_fixed_string_t set;
6783         cmdline_fixed_string_t flow_ctrl;
6784         cmdline_fixed_string_t rx;
6785         cmdline_fixed_string_t rx_lfc_mode;
6786         cmdline_fixed_string_t tx;
6787         cmdline_fixed_string_t tx_lfc_mode;
6788         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6789         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6790         cmdline_fixed_string_t autoneg_str;
6791         cmdline_fixed_string_t autoneg;
6792         cmdline_fixed_string_t hw_str;
6793         uint32_t high_water;
6794         cmdline_fixed_string_t lw_str;
6795         uint32_t low_water;
6796         cmdline_fixed_string_t pt_str;
6797         uint16_t pause_time;
6798         cmdline_fixed_string_t xon_str;
6799         uint16_t send_xon;
6800         portid_t port_id;
6801 };
6802
6803 cmdline_parse_token_string_t cmd_lfc_set_set =
6804         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6805                                 set, "set");
6806 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6807         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6808                                 flow_ctrl, "flow_ctrl");
6809 cmdline_parse_token_string_t cmd_lfc_set_rx =
6810         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6811                                 rx, "rx");
6812 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6813         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6814                                 rx_lfc_mode, "on#off");
6815 cmdline_parse_token_string_t cmd_lfc_set_tx =
6816         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6817                                 tx, "tx");
6818 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6819         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6820                                 tx_lfc_mode, "on#off");
6821 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6822         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6823                                 hw_str, "high_water");
6824 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6825         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6826                                 high_water, UINT32);
6827 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6828         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6829                                 lw_str, "low_water");
6830 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6831         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6832                                 low_water, UINT32);
6833 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6834         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6835                                 pt_str, "pause_time");
6836 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6837         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6838                                 pause_time, UINT16);
6839 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6840         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6841                                 xon_str, "send_xon");
6842 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6843         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6844                                 send_xon, UINT16);
6845 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6846         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6847                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6848 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6849         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6850                                 mac_ctrl_frame_fwd_mode, "on#off");
6851 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6852         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6853                                 autoneg_str, "autoneg");
6854 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6855         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6856                                 autoneg, "on#off");
6857 cmdline_parse_token_num_t cmd_lfc_set_portid =
6858         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6859                                 port_id, UINT16);
6860
6861 /* forward declaration */
6862 static void
6863 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6864                               void *data);
6865
6866 cmdline_parse_inst_t cmd_link_flow_control_set = {
6867         .f = cmd_link_flow_ctrl_set_parsed,
6868         .data = NULL,
6869         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6870                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6871                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6872         .tokens = {
6873                 (void *)&cmd_lfc_set_set,
6874                 (void *)&cmd_lfc_set_flow_ctrl,
6875                 (void *)&cmd_lfc_set_rx,
6876                 (void *)&cmd_lfc_set_rx_mode,
6877                 (void *)&cmd_lfc_set_tx,
6878                 (void *)&cmd_lfc_set_tx_mode,
6879                 (void *)&cmd_lfc_set_high_water,
6880                 (void *)&cmd_lfc_set_low_water,
6881                 (void *)&cmd_lfc_set_pause_time,
6882                 (void *)&cmd_lfc_set_send_xon,
6883                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6884                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6885                 (void *)&cmd_lfc_set_autoneg_str,
6886                 (void *)&cmd_lfc_set_autoneg,
6887                 (void *)&cmd_lfc_set_portid,
6888                 NULL,
6889         },
6890 };
6891
6892 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6893         .f = cmd_link_flow_ctrl_set_parsed,
6894         .data = (void *)&cmd_link_flow_control_set_rx,
6895         .help_str = "set flow_ctrl rx on|off <port_id>: "
6896                 "Change rx flow control parameter",
6897         .tokens = {
6898                 (void *)&cmd_lfc_set_set,
6899                 (void *)&cmd_lfc_set_flow_ctrl,
6900                 (void *)&cmd_lfc_set_rx,
6901                 (void *)&cmd_lfc_set_rx_mode,
6902                 (void *)&cmd_lfc_set_portid,
6903                 NULL,
6904         },
6905 };
6906
6907 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6908         .f = cmd_link_flow_ctrl_set_parsed,
6909         .data = (void *)&cmd_link_flow_control_set_tx,
6910         .help_str = "set flow_ctrl tx on|off <port_id>: "
6911                 "Change tx flow control parameter",
6912         .tokens = {
6913                 (void *)&cmd_lfc_set_set,
6914                 (void *)&cmd_lfc_set_flow_ctrl,
6915                 (void *)&cmd_lfc_set_tx,
6916                 (void *)&cmd_lfc_set_tx_mode,
6917                 (void *)&cmd_lfc_set_portid,
6918                 NULL,
6919         },
6920 };
6921
6922 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6923         .f = cmd_link_flow_ctrl_set_parsed,
6924         .data = (void *)&cmd_link_flow_control_set_hw,
6925         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6926                 "Change high water flow control parameter",
6927         .tokens = {
6928                 (void *)&cmd_lfc_set_set,
6929                 (void *)&cmd_lfc_set_flow_ctrl,
6930                 (void *)&cmd_lfc_set_high_water_str,
6931                 (void *)&cmd_lfc_set_high_water,
6932                 (void *)&cmd_lfc_set_portid,
6933                 NULL,
6934         },
6935 };
6936
6937 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6938         .f = cmd_link_flow_ctrl_set_parsed,
6939         .data = (void *)&cmd_link_flow_control_set_lw,
6940         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6941                 "Change low water flow control parameter",
6942         .tokens = {
6943                 (void *)&cmd_lfc_set_set,
6944                 (void *)&cmd_lfc_set_flow_ctrl,
6945                 (void *)&cmd_lfc_set_low_water_str,
6946                 (void *)&cmd_lfc_set_low_water,
6947                 (void *)&cmd_lfc_set_portid,
6948                 NULL,
6949         },
6950 };
6951
6952 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6953         .f = cmd_link_flow_ctrl_set_parsed,
6954         .data = (void *)&cmd_link_flow_control_set_pt,
6955         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6956                 "Change pause time flow control parameter",
6957         .tokens = {
6958                 (void *)&cmd_lfc_set_set,
6959                 (void *)&cmd_lfc_set_flow_ctrl,
6960                 (void *)&cmd_lfc_set_pause_time_str,
6961                 (void *)&cmd_lfc_set_pause_time,
6962                 (void *)&cmd_lfc_set_portid,
6963                 NULL,
6964         },
6965 };
6966
6967 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6968         .f = cmd_link_flow_ctrl_set_parsed,
6969         .data = (void *)&cmd_link_flow_control_set_xon,
6970         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6971                 "Change send_xon flow control parameter",
6972         .tokens = {
6973                 (void *)&cmd_lfc_set_set,
6974                 (void *)&cmd_lfc_set_flow_ctrl,
6975                 (void *)&cmd_lfc_set_send_xon_str,
6976                 (void *)&cmd_lfc_set_send_xon,
6977                 (void *)&cmd_lfc_set_portid,
6978                 NULL,
6979         },
6980 };
6981
6982 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6983         .f = cmd_link_flow_ctrl_set_parsed,
6984         .data = (void *)&cmd_link_flow_control_set_macfwd,
6985         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6986                 "Change mac ctrl fwd flow control parameter",
6987         .tokens = {
6988                 (void *)&cmd_lfc_set_set,
6989                 (void *)&cmd_lfc_set_flow_ctrl,
6990                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6991                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6992                 (void *)&cmd_lfc_set_portid,
6993                 NULL,
6994         },
6995 };
6996
6997 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6998         .f = cmd_link_flow_ctrl_set_parsed,
6999         .data = (void *)&cmd_link_flow_control_set_autoneg,
7000         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7001                 "Change autoneg flow control parameter",
7002         .tokens = {
7003                 (void *)&cmd_lfc_set_set,
7004                 (void *)&cmd_lfc_set_flow_ctrl,
7005                 (void *)&cmd_lfc_set_autoneg_str,
7006                 (void *)&cmd_lfc_set_autoneg,
7007                 (void *)&cmd_lfc_set_portid,
7008                 NULL,
7009         },
7010 };
7011
7012 static void
7013 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7014                               __rte_unused struct cmdline *cl,
7015                               void *data)
7016 {
7017         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7018         cmdline_parse_inst_t *cmd = data;
7019         struct rte_eth_fc_conf fc_conf;
7020         int rx_fc_en = 0;
7021         int tx_fc_en = 0;
7022         int ret;
7023
7024         /*
7025          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7026          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7027          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7028          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7029          */
7030         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7031                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7032         };
7033
7034         /* Partial command line, retrieve current configuration */
7035         if (cmd) {
7036                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7037                 if (ret != 0) {
7038                         printf("cannot get current flow ctrl parameters, return"
7039                                "code = %d\n", ret);
7040                         return;
7041                 }
7042
7043                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7044                     (fc_conf.mode == RTE_FC_FULL))
7045                         rx_fc_en = 1;
7046                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7047                     (fc_conf.mode == RTE_FC_FULL))
7048                         tx_fc_en = 1;
7049         }
7050
7051         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7052                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7053
7054         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7055                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7056
7057         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7058
7059         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7060                 fc_conf.high_water = res->high_water;
7061
7062         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7063                 fc_conf.low_water = res->low_water;
7064
7065         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7066                 fc_conf.pause_time = res->pause_time;
7067
7068         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7069                 fc_conf.send_xon = res->send_xon;
7070
7071         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7072                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7073                         fc_conf.mac_ctrl_frame_fwd = 1;
7074                 else
7075                         fc_conf.mac_ctrl_frame_fwd = 0;
7076         }
7077
7078         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7079                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7080
7081         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7082         if (ret != 0)
7083                 printf("bad flow contrl parameter, return code = %d \n", ret);
7084 }
7085
7086 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7087 struct cmd_priority_flow_ctrl_set_result {
7088         cmdline_fixed_string_t set;
7089         cmdline_fixed_string_t pfc_ctrl;
7090         cmdline_fixed_string_t rx;
7091         cmdline_fixed_string_t rx_pfc_mode;
7092         cmdline_fixed_string_t tx;
7093         cmdline_fixed_string_t tx_pfc_mode;
7094         uint32_t high_water;
7095         uint32_t low_water;
7096         uint16_t pause_time;
7097         uint8_t  priority;
7098         portid_t port_id;
7099 };
7100
7101 static void
7102 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7103                        __rte_unused struct cmdline *cl,
7104                        __rte_unused void *data)
7105 {
7106         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7107         struct rte_eth_pfc_conf pfc_conf;
7108         int rx_fc_enable, tx_fc_enable;
7109         int ret;
7110
7111         /*
7112          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7113          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7114          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7115          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7116          */
7117         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7118                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7119         };
7120
7121         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7122         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7123         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7124         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7125         pfc_conf.fc.high_water = res->high_water;
7126         pfc_conf.fc.low_water  = res->low_water;
7127         pfc_conf.fc.pause_time = res->pause_time;
7128         pfc_conf.priority      = res->priority;
7129
7130         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7131         if (ret != 0)
7132                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7133 }
7134
7135 cmdline_parse_token_string_t cmd_pfc_set_set =
7136         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7137                                 set, "set");
7138 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7139         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7140                                 pfc_ctrl, "pfc_ctrl");
7141 cmdline_parse_token_string_t cmd_pfc_set_rx =
7142         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7143                                 rx, "rx");
7144 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7145         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7146                                 rx_pfc_mode, "on#off");
7147 cmdline_parse_token_string_t cmd_pfc_set_tx =
7148         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7149                                 tx, "tx");
7150 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7151         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7152                                 tx_pfc_mode, "on#off");
7153 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7154         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7155                                 high_water, UINT32);
7156 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7157         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7158                                 low_water, UINT32);
7159 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7160         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7161                                 pause_time, UINT16);
7162 cmdline_parse_token_num_t cmd_pfc_set_priority =
7163         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7164                                 priority, UINT8);
7165 cmdline_parse_token_num_t cmd_pfc_set_portid =
7166         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7167                                 port_id, UINT16);
7168
7169 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7170         .f = cmd_priority_flow_ctrl_set_parsed,
7171         .data = NULL,
7172         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7173                 "<pause_time> <priority> <port_id>: "
7174                 "Configure the Ethernet priority flow control",
7175         .tokens = {
7176                 (void *)&cmd_pfc_set_set,
7177                 (void *)&cmd_pfc_set_flow_ctrl,
7178                 (void *)&cmd_pfc_set_rx,
7179                 (void *)&cmd_pfc_set_rx_mode,
7180                 (void *)&cmd_pfc_set_tx,
7181                 (void *)&cmd_pfc_set_tx_mode,
7182                 (void *)&cmd_pfc_set_high_water,
7183                 (void *)&cmd_pfc_set_low_water,
7184                 (void *)&cmd_pfc_set_pause_time,
7185                 (void *)&cmd_pfc_set_priority,
7186                 (void *)&cmd_pfc_set_portid,
7187                 NULL,
7188         },
7189 };
7190
7191 /* *** RESET CONFIGURATION *** */
7192 struct cmd_reset_result {
7193         cmdline_fixed_string_t reset;
7194         cmdline_fixed_string_t def;
7195 };
7196
7197 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7198                              struct cmdline *cl,
7199                              __rte_unused void *data)
7200 {
7201         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7202         set_def_fwd_config();
7203 }
7204
7205 cmdline_parse_token_string_t cmd_reset_set =
7206         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7207 cmdline_parse_token_string_t cmd_reset_def =
7208         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7209                                  "default");
7210
7211 cmdline_parse_inst_t cmd_reset = {
7212         .f = cmd_reset_parsed,
7213         .data = NULL,
7214         .help_str = "set default: Reset default forwarding configuration",
7215         .tokens = {
7216                 (void *)&cmd_reset_set,
7217                 (void *)&cmd_reset_def,
7218                 NULL,
7219         },
7220 };
7221
7222 /* *** START FORWARDING *** */
7223 struct cmd_start_result {
7224         cmdline_fixed_string_t start;
7225 };
7226
7227 cmdline_parse_token_string_t cmd_start_start =
7228         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7229
7230 static void cmd_start_parsed(__rte_unused void *parsed_result,
7231                              __rte_unused struct cmdline *cl,
7232                              __rte_unused void *data)
7233 {
7234         start_packet_forwarding(0);
7235 }
7236
7237 cmdline_parse_inst_t cmd_start = {
7238         .f = cmd_start_parsed,
7239         .data = NULL,
7240         .help_str = "start: Start packet forwarding",
7241         .tokens = {
7242                 (void *)&cmd_start_start,
7243                 NULL,
7244         },
7245 };
7246
7247 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7248 struct cmd_start_tx_first_result {
7249         cmdline_fixed_string_t start;
7250         cmdline_fixed_string_t tx_first;
7251 };
7252
7253 static void
7254 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7255                           __rte_unused struct cmdline *cl,
7256                           __rte_unused void *data)
7257 {
7258         start_packet_forwarding(1);
7259 }
7260
7261 cmdline_parse_token_string_t cmd_start_tx_first_start =
7262         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7263                                  "start");
7264 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7265         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7266                                  tx_first, "tx_first");
7267
7268 cmdline_parse_inst_t cmd_start_tx_first = {
7269         .f = cmd_start_tx_first_parsed,
7270         .data = NULL,
7271         .help_str = "start tx_first: Start packet forwarding, "
7272                 "after sending 1 burst of packets",
7273         .tokens = {
7274                 (void *)&cmd_start_tx_first_start,
7275                 (void *)&cmd_start_tx_first_tx_first,
7276                 NULL,
7277         },
7278 };
7279
7280 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7281 struct cmd_start_tx_first_n_result {
7282         cmdline_fixed_string_t start;
7283         cmdline_fixed_string_t tx_first;
7284         uint32_t tx_num;
7285 };
7286
7287 static void
7288 cmd_start_tx_first_n_parsed(void *parsed_result,
7289                           __rte_unused struct cmdline *cl,
7290                           __rte_unused void *data)
7291 {
7292         struct cmd_start_tx_first_n_result *res = parsed_result;
7293
7294         start_packet_forwarding(res->tx_num);
7295 }
7296
7297 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7298         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7299                         start, "start");
7300 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7301         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7302                         tx_first, "tx_first");
7303 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7304         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7305                         tx_num, UINT32);
7306
7307 cmdline_parse_inst_t cmd_start_tx_first_n = {
7308         .f = cmd_start_tx_first_n_parsed,
7309         .data = NULL,
7310         .help_str = "start tx_first <num>: "
7311                 "packet forwarding, after sending <num> bursts of packets",
7312         .tokens = {
7313                 (void *)&cmd_start_tx_first_n_start,
7314                 (void *)&cmd_start_tx_first_n_tx_first,
7315                 (void *)&cmd_start_tx_first_n_tx_num,
7316                 NULL,
7317         },
7318 };
7319
7320 /* *** SET LINK UP *** */
7321 struct cmd_set_link_up_result {
7322         cmdline_fixed_string_t set;
7323         cmdline_fixed_string_t link_up;
7324         cmdline_fixed_string_t port;
7325         portid_t port_id;
7326 };
7327
7328 cmdline_parse_token_string_t cmd_set_link_up_set =
7329         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7330 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7332                                 "link-up");
7333 cmdline_parse_token_string_t cmd_set_link_up_port =
7334         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7335 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7336         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7337
7338 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7339                              __rte_unused struct cmdline *cl,
7340                              __rte_unused void *data)
7341 {
7342         struct cmd_set_link_up_result *res = parsed_result;
7343         dev_set_link_up(res->port_id);
7344 }
7345
7346 cmdline_parse_inst_t cmd_set_link_up = {
7347         .f = cmd_set_link_up_parsed,
7348         .data = NULL,
7349         .help_str = "set link-up port <port id>",
7350         .tokens = {
7351                 (void *)&cmd_set_link_up_set,
7352                 (void *)&cmd_set_link_up_link_up,
7353                 (void *)&cmd_set_link_up_port,
7354                 (void *)&cmd_set_link_up_port_id,
7355                 NULL,
7356         },
7357 };
7358
7359 /* *** SET LINK DOWN *** */
7360 struct cmd_set_link_down_result {
7361         cmdline_fixed_string_t set;
7362         cmdline_fixed_string_t link_down;
7363         cmdline_fixed_string_t port;
7364         portid_t port_id;
7365 };
7366
7367 cmdline_parse_token_string_t cmd_set_link_down_set =
7368         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7369 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7370         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7371                                 "link-down");
7372 cmdline_parse_token_string_t cmd_set_link_down_port =
7373         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7374 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7375         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7376
7377 static void cmd_set_link_down_parsed(
7378                                 __rte_unused void *parsed_result,
7379                                 __rte_unused struct cmdline *cl,
7380                                 __rte_unused void *data)
7381 {
7382         struct cmd_set_link_down_result *res = parsed_result;
7383         dev_set_link_down(res->port_id);
7384 }
7385
7386 cmdline_parse_inst_t cmd_set_link_down = {
7387         .f = cmd_set_link_down_parsed,
7388         .data = NULL,
7389         .help_str = "set link-down port <port id>",
7390         .tokens = {
7391                 (void *)&cmd_set_link_down_set,
7392                 (void *)&cmd_set_link_down_link_down,
7393                 (void *)&cmd_set_link_down_port,
7394                 (void *)&cmd_set_link_down_port_id,
7395                 NULL,
7396         },
7397 };
7398
7399 /* *** SHOW CFG *** */
7400 struct cmd_showcfg_result {
7401         cmdline_fixed_string_t show;
7402         cmdline_fixed_string_t cfg;
7403         cmdline_fixed_string_t what;
7404 };
7405
7406 static void cmd_showcfg_parsed(void *parsed_result,
7407                                __rte_unused struct cmdline *cl,
7408                                __rte_unused void *data)
7409 {
7410         struct cmd_showcfg_result *res = parsed_result;
7411         if (!strcmp(res->what, "rxtx"))
7412                 rxtx_config_display();
7413         else if (!strcmp(res->what, "cores"))
7414                 fwd_lcores_config_display();
7415         else if (!strcmp(res->what, "fwd"))
7416                 pkt_fwd_config_display(&cur_fwd_config);
7417         else if (!strcmp(res->what, "txpkts"))
7418                 show_tx_pkt_segments();
7419 }
7420
7421 cmdline_parse_token_string_t cmd_showcfg_show =
7422         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7423 cmdline_parse_token_string_t cmd_showcfg_port =
7424         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7425 cmdline_parse_token_string_t cmd_showcfg_what =
7426         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7427                                  "rxtx#cores#fwd#txpkts");
7428
7429 cmdline_parse_inst_t cmd_showcfg = {
7430         .f = cmd_showcfg_parsed,
7431         .data = NULL,
7432         .help_str = "show config rxtx|cores|fwd|txpkts",
7433         .tokens = {
7434                 (void *)&cmd_showcfg_show,
7435                 (void *)&cmd_showcfg_port,
7436                 (void *)&cmd_showcfg_what,
7437                 NULL,
7438         },
7439 };
7440
7441 /* *** SHOW ALL PORT INFO *** */
7442 struct cmd_showportall_result {
7443         cmdline_fixed_string_t show;
7444         cmdline_fixed_string_t port;
7445         cmdline_fixed_string_t what;
7446         cmdline_fixed_string_t all;
7447 };
7448
7449 static void cmd_showportall_parsed(void *parsed_result,
7450                                 __rte_unused struct cmdline *cl,
7451                                 __rte_unused void *data)
7452 {
7453         portid_t i;
7454
7455         struct cmd_showportall_result *res = parsed_result;
7456         if (!strcmp(res->show, "clear")) {
7457                 if (!strcmp(res->what, "stats"))
7458                         RTE_ETH_FOREACH_DEV(i)
7459                                 nic_stats_clear(i);
7460                 else if (!strcmp(res->what, "xstats"))
7461                         RTE_ETH_FOREACH_DEV(i)
7462                                 nic_xstats_clear(i);
7463         } else if (!strcmp(res->what, "info"))
7464                 RTE_ETH_FOREACH_DEV(i)
7465                         port_infos_display(i);
7466         else if (!strcmp(res->what, "summary")) {
7467                 port_summary_header_display();
7468                 RTE_ETH_FOREACH_DEV(i)
7469                         port_summary_display(i);
7470         }
7471         else if (!strcmp(res->what, "stats"))
7472                 RTE_ETH_FOREACH_DEV(i)
7473                         nic_stats_display(i);
7474         else if (!strcmp(res->what, "xstats"))
7475                 RTE_ETH_FOREACH_DEV(i)
7476                         nic_xstats_display(i);
7477         else if (!strcmp(res->what, "fdir"))
7478                 RTE_ETH_FOREACH_DEV(i)
7479                         fdir_get_infos(i);
7480         else if (!strcmp(res->what, "stat_qmap"))
7481                 RTE_ETH_FOREACH_DEV(i)
7482                         nic_stats_mapping_display(i);
7483         else if (!strcmp(res->what, "dcb_tc"))
7484                 RTE_ETH_FOREACH_DEV(i)
7485                         port_dcb_info_display(i);
7486         else if (!strcmp(res->what, "cap"))
7487                 RTE_ETH_FOREACH_DEV(i)
7488                         port_offload_cap_display(i);
7489 }
7490
7491 cmdline_parse_token_string_t cmd_showportall_show =
7492         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7493                                  "show#clear");
7494 cmdline_parse_token_string_t cmd_showportall_port =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7496 cmdline_parse_token_string_t cmd_showportall_what =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7498                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7499 cmdline_parse_token_string_t cmd_showportall_all =
7500         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7501 cmdline_parse_inst_t cmd_showportall = {
7502         .f = cmd_showportall_parsed,
7503         .data = NULL,
7504         .help_str = "show|clear port "
7505                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7506         .tokens = {
7507                 (void *)&cmd_showportall_show,
7508                 (void *)&cmd_showportall_port,
7509                 (void *)&cmd_showportall_what,
7510                 (void *)&cmd_showportall_all,
7511                 NULL,
7512         },
7513 };
7514
7515 /* *** SHOW PORT INFO *** */
7516 struct cmd_showport_result {
7517         cmdline_fixed_string_t show;
7518         cmdline_fixed_string_t port;
7519         cmdline_fixed_string_t what;
7520         uint16_t portnum;
7521 };
7522
7523 static void cmd_showport_parsed(void *parsed_result,
7524                                 __rte_unused struct cmdline *cl,
7525                                 __rte_unused void *data)
7526 {
7527         struct cmd_showport_result *res = parsed_result;
7528         if (!strcmp(res->show, "clear")) {
7529                 if (!strcmp(res->what, "stats"))
7530                         nic_stats_clear(res->portnum);
7531                 else if (!strcmp(res->what, "xstats"))
7532                         nic_xstats_clear(res->portnum);
7533         } else if (!strcmp(res->what, "info"))
7534                 port_infos_display(res->portnum);
7535         else if (!strcmp(res->what, "summary")) {
7536                 port_summary_header_display();
7537                 port_summary_display(res->portnum);
7538         }
7539         else if (!strcmp(res->what, "stats"))
7540                 nic_stats_display(res->portnum);
7541         else if (!strcmp(res->what, "xstats"))
7542                 nic_xstats_display(res->portnum);
7543         else if (!strcmp(res->what, "fdir"))
7544                  fdir_get_infos(res->portnum);
7545         else if (!strcmp(res->what, "stat_qmap"))
7546                 nic_stats_mapping_display(res->portnum);
7547         else if (!strcmp(res->what, "dcb_tc"))
7548                 port_dcb_info_display(res->portnum);
7549         else if (!strcmp(res->what, "cap"))
7550                 port_offload_cap_display(res->portnum);
7551 }
7552
7553 cmdline_parse_token_string_t cmd_showport_show =
7554         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7555                                  "show#clear");
7556 cmdline_parse_token_string_t cmd_showport_port =
7557         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7558 cmdline_parse_token_string_t cmd_showport_what =
7559         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7560                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7561 cmdline_parse_token_num_t cmd_showport_portnum =
7562         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7563
7564 cmdline_parse_inst_t cmd_showport = {
7565         .f = cmd_showport_parsed,
7566         .data = NULL,
7567         .help_str = "show|clear port "
7568                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7569                 "<port_id>",
7570         .tokens = {
7571                 (void *)&cmd_showport_show,
7572                 (void *)&cmd_showport_port,
7573                 (void *)&cmd_showport_what,
7574                 (void *)&cmd_showport_portnum,
7575                 NULL,
7576         },
7577 };
7578
7579 /* *** SHOW DEVICE INFO *** */
7580 struct cmd_showdevice_result {
7581         cmdline_fixed_string_t show;
7582         cmdline_fixed_string_t device;
7583         cmdline_fixed_string_t what;
7584         cmdline_fixed_string_t identifier;
7585 };
7586
7587 static void cmd_showdevice_parsed(void *parsed_result,
7588                                 __rte_unused struct cmdline *cl,
7589                                 __rte_unused void *data)
7590 {
7591         struct cmd_showdevice_result *res = parsed_result;
7592         if (!strcmp(res->what, "info")) {
7593                 if (!strcmp(res->identifier, "all"))
7594                         device_infos_display(NULL);
7595                 else
7596                         device_infos_display(res->identifier);
7597         }
7598 }
7599
7600 cmdline_parse_token_string_t cmd_showdevice_show =
7601         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7602                                  "show");
7603 cmdline_parse_token_string_t cmd_showdevice_device =
7604         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7605 cmdline_parse_token_string_t cmd_showdevice_what =
7606         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7607                                  "info");
7608 cmdline_parse_token_string_t cmd_showdevice_identifier =
7609         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7610                         identifier, NULL);
7611
7612 cmdline_parse_inst_t cmd_showdevice = {
7613         .f = cmd_showdevice_parsed,
7614         .data = NULL,
7615         .help_str = "show device info <identifier>|all",
7616         .tokens = {
7617                 (void *)&cmd_showdevice_show,
7618                 (void *)&cmd_showdevice_device,
7619                 (void *)&cmd_showdevice_what,
7620                 (void *)&cmd_showdevice_identifier,
7621                 NULL,
7622         },
7623 };
7624 /* *** SHOW QUEUE INFO *** */
7625 struct cmd_showqueue_result {
7626         cmdline_fixed_string_t show;
7627         cmdline_fixed_string_t type;
7628         cmdline_fixed_string_t what;
7629         uint16_t portnum;
7630         uint16_t queuenum;
7631 };
7632
7633 static void
7634 cmd_showqueue_parsed(void *parsed_result,
7635         __rte_unused struct cmdline *cl,
7636         __rte_unused void *data)
7637 {
7638         struct cmd_showqueue_result *res = parsed_result;
7639
7640         if (!strcmp(res->type, "rxq"))
7641                 rx_queue_infos_display(res->portnum, res->queuenum);
7642         else if (!strcmp(res->type, "txq"))
7643                 tx_queue_infos_display(res->portnum, res->queuenum);
7644 }
7645
7646 cmdline_parse_token_string_t cmd_showqueue_show =
7647         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7648 cmdline_parse_token_string_t cmd_showqueue_type =
7649         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7650 cmdline_parse_token_string_t cmd_showqueue_what =
7651         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7652 cmdline_parse_token_num_t cmd_showqueue_portnum =
7653         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7654 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7655         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7656
7657 cmdline_parse_inst_t cmd_showqueue = {
7658         .f = cmd_showqueue_parsed,
7659         .data = NULL,
7660         .help_str = "show rxq|txq info <port_id> <queue_id>",
7661         .tokens = {
7662                 (void *)&cmd_showqueue_show,
7663                 (void *)&cmd_showqueue_type,
7664                 (void *)&cmd_showqueue_what,
7665                 (void *)&cmd_showqueue_portnum,
7666                 (void *)&cmd_showqueue_queuenum,
7667                 NULL,
7668         },
7669 };
7670
7671 /* show/clear fwd engine statistics */
7672 struct fwd_result {
7673         cmdline_fixed_string_t action;
7674         cmdline_fixed_string_t fwd;
7675         cmdline_fixed_string_t stats;
7676         cmdline_fixed_string_t all;
7677 };
7678
7679 cmdline_parse_token_string_t cmd_fwd_action =
7680         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7681 cmdline_parse_token_string_t cmd_fwd_fwd =
7682         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7683 cmdline_parse_token_string_t cmd_fwd_stats =
7684         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7685 cmdline_parse_token_string_t cmd_fwd_all =
7686         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7687
7688 static void
7689 cmd_showfwdall_parsed(void *parsed_result,
7690                       __rte_unused struct cmdline *cl,
7691                       __rte_unused void *data)
7692 {
7693         struct fwd_result *res = parsed_result;
7694
7695         if (!strcmp(res->action, "show"))
7696                 fwd_stats_display();
7697         else
7698                 fwd_stats_reset();
7699 }
7700
7701 static cmdline_parse_inst_t cmd_showfwdall = {
7702         .f = cmd_showfwdall_parsed,
7703         .data = NULL,
7704         .help_str = "show|clear fwd stats all",
7705         .tokens = {
7706                 (void *)&cmd_fwd_action,
7707                 (void *)&cmd_fwd_fwd,
7708                 (void *)&cmd_fwd_stats,
7709                 (void *)&cmd_fwd_all,
7710                 NULL,
7711         },
7712 };
7713
7714 /* *** READ PORT REGISTER *** */
7715 struct cmd_read_reg_result {
7716         cmdline_fixed_string_t read;
7717         cmdline_fixed_string_t reg;
7718         portid_t port_id;
7719         uint32_t reg_off;
7720 };
7721
7722 static void
7723 cmd_read_reg_parsed(void *parsed_result,
7724                     __rte_unused struct cmdline *cl,
7725                     __rte_unused void *data)
7726 {
7727         struct cmd_read_reg_result *res = parsed_result;
7728         port_reg_display(res->port_id, res->reg_off);
7729 }
7730
7731 cmdline_parse_token_string_t cmd_read_reg_read =
7732         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7733 cmdline_parse_token_string_t cmd_read_reg_reg =
7734         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7735 cmdline_parse_token_num_t cmd_read_reg_port_id =
7736         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7737 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7738         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7739
7740 cmdline_parse_inst_t cmd_read_reg = {
7741         .f = cmd_read_reg_parsed,
7742         .data = NULL,
7743         .help_str = "read reg <port_id> <reg_off>",
7744         .tokens = {
7745                 (void *)&cmd_read_reg_read,
7746                 (void *)&cmd_read_reg_reg,
7747                 (void *)&cmd_read_reg_port_id,
7748                 (void *)&cmd_read_reg_reg_off,
7749                 NULL,
7750         },
7751 };
7752
7753 /* *** READ PORT REGISTER BIT FIELD *** */
7754 struct cmd_read_reg_bit_field_result {
7755         cmdline_fixed_string_t read;
7756         cmdline_fixed_string_t regfield;
7757         portid_t port_id;
7758         uint32_t reg_off;
7759         uint8_t bit1_pos;
7760         uint8_t bit2_pos;
7761 };
7762
7763 static void
7764 cmd_read_reg_bit_field_parsed(void *parsed_result,
7765                               __rte_unused struct cmdline *cl,
7766                               __rte_unused void *data)
7767 {
7768         struct cmd_read_reg_bit_field_result *res = parsed_result;
7769         port_reg_bit_field_display(res->port_id, res->reg_off,
7770                                    res->bit1_pos, res->bit2_pos);
7771 }
7772
7773 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7774         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7775                                  "read");
7776 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7777         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7778                                  regfield, "regfield");
7779 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7780         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7781                               UINT16);
7782 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7783         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7784                               UINT32);
7785 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7786         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7787                               UINT8);
7788 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7789         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7790                               UINT8);
7791
7792 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7793         .f = cmd_read_reg_bit_field_parsed,
7794         .data = NULL,
7795         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7796         "Read register bit field between bit_x and bit_y included",
7797         .tokens = {
7798                 (void *)&cmd_read_reg_bit_field_read,
7799                 (void *)&cmd_read_reg_bit_field_regfield,
7800                 (void *)&cmd_read_reg_bit_field_port_id,
7801                 (void *)&cmd_read_reg_bit_field_reg_off,
7802                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7803                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7804                 NULL,
7805         },
7806 };
7807
7808 /* *** READ PORT REGISTER BIT *** */
7809 struct cmd_read_reg_bit_result {
7810         cmdline_fixed_string_t read;
7811         cmdline_fixed_string_t regbit;
7812         portid_t port_id;
7813         uint32_t reg_off;
7814         uint8_t bit_pos;
7815 };
7816
7817 static void
7818 cmd_read_reg_bit_parsed(void *parsed_result,
7819                         __rte_unused struct cmdline *cl,
7820                         __rte_unused void *data)
7821 {
7822         struct cmd_read_reg_bit_result *res = parsed_result;
7823         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7824 }
7825
7826 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7827         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7828 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7829         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7830                                  regbit, "regbit");
7831 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7832         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7833 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7834         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7835 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7836         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7837
7838 cmdline_parse_inst_t cmd_read_reg_bit = {
7839         .f = cmd_read_reg_bit_parsed,
7840         .data = NULL,
7841         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7842         .tokens = {
7843                 (void *)&cmd_read_reg_bit_read,
7844                 (void *)&cmd_read_reg_bit_regbit,
7845                 (void *)&cmd_read_reg_bit_port_id,
7846                 (void *)&cmd_read_reg_bit_reg_off,
7847                 (void *)&cmd_read_reg_bit_bit_pos,
7848                 NULL,
7849         },
7850 };
7851
7852 /* *** WRITE PORT REGISTER *** */
7853 struct cmd_write_reg_result {
7854         cmdline_fixed_string_t write;
7855         cmdline_fixed_string_t reg;
7856         portid_t port_id;
7857         uint32_t reg_off;
7858         uint32_t value;
7859 };
7860
7861 static void
7862 cmd_write_reg_parsed(void *parsed_result,
7863                      __rte_unused struct cmdline *cl,
7864                      __rte_unused void *data)
7865 {
7866         struct cmd_write_reg_result *res = parsed_result;
7867         port_reg_set(res->port_id, res->reg_off, res->value);
7868 }
7869
7870 cmdline_parse_token_string_t cmd_write_reg_write =
7871         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7872 cmdline_parse_token_string_t cmd_write_reg_reg =
7873         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7874 cmdline_parse_token_num_t cmd_write_reg_port_id =
7875         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7876 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7877         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7878 cmdline_parse_token_num_t cmd_write_reg_value =
7879         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7880
7881 cmdline_parse_inst_t cmd_write_reg = {
7882         .f = cmd_write_reg_parsed,
7883         .data = NULL,
7884         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7885         .tokens = {
7886                 (void *)&cmd_write_reg_write,
7887                 (void *)&cmd_write_reg_reg,
7888                 (void *)&cmd_write_reg_port_id,
7889                 (void *)&cmd_write_reg_reg_off,
7890                 (void *)&cmd_write_reg_value,
7891                 NULL,
7892         },
7893 };
7894
7895 /* *** WRITE PORT REGISTER BIT FIELD *** */
7896 struct cmd_write_reg_bit_field_result {
7897         cmdline_fixed_string_t write;
7898         cmdline_fixed_string_t regfield;
7899         portid_t port_id;
7900         uint32_t reg_off;
7901         uint8_t bit1_pos;
7902         uint8_t bit2_pos;
7903         uint32_t value;
7904 };
7905
7906 static void
7907 cmd_write_reg_bit_field_parsed(void *parsed_result,
7908                                __rte_unused struct cmdline *cl,
7909                                __rte_unused void *data)
7910 {
7911         struct cmd_write_reg_bit_field_result *res = parsed_result;
7912         port_reg_bit_field_set(res->port_id, res->reg_off,
7913                           res->bit1_pos, res->bit2_pos, res->value);
7914 }
7915
7916 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7917         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7918                                  "write");
7919 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7920         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7921                                  regfield, "regfield");
7922 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7923         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7924                               UINT16);
7925 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7926         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7927                               UINT32);
7928 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7929         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7930                               UINT8);
7931 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7932         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7933                               UINT8);
7934 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7935         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7936                               UINT32);
7937
7938 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7939         .f = cmd_write_reg_bit_field_parsed,
7940         .data = NULL,
7941         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7942                 "<reg_value>: "
7943                 "Set register bit field between bit_x and bit_y included",
7944         .tokens = {
7945                 (void *)&cmd_write_reg_bit_field_write,
7946                 (void *)&cmd_write_reg_bit_field_regfield,
7947                 (void *)&cmd_write_reg_bit_field_port_id,
7948                 (void *)&cmd_write_reg_bit_field_reg_off,
7949                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7950                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7951                 (void *)&cmd_write_reg_bit_field_value,
7952                 NULL,
7953         },
7954 };
7955
7956 /* *** WRITE PORT REGISTER BIT *** */
7957 struct cmd_write_reg_bit_result {
7958         cmdline_fixed_string_t write;
7959         cmdline_fixed_string_t regbit;
7960         portid_t port_id;
7961         uint32_t reg_off;
7962         uint8_t bit_pos;
7963         uint8_t value;
7964 };
7965
7966 static void
7967 cmd_write_reg_bit_parsed(void *parsed_result,
7968                          __rte_unused struct cmdline *cl,
7969                          __rte_unused void *data)
7970 {
7971         struct cmd_write_reg_bit_result *res = parsed_result;
7972         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7973 }
7974
7975 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7976         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7977                                  "write");
7978 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7979         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7980                                  regbit, "regbit");
7981 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7982         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7983 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7984         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7985 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7986         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7987 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7988         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7989
7990 cmdline_parse_inst_t cmd_write_reg_bit = {
7991         .f = cmd_write_reg_bit_parsed,
7992         .data = NULL,
7993         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
7994                 "0 <= bit_x <= 31",
7995         .tokens = {
7996                 (void *)&cmd_write_reg_bit_write,
7997                 (void *)&cmd_write_reg_bit_regbit,
7998                 (void *)&cmd_write_reg_bit_port_id,
7999                 (void *)&cmd_write_reg_bit_reg_off,
8000                 (void *)&cmd_write_reg_bit_bit_pos,
8001                 (void *)&cmd_write_reg_bit_value,
8002                 NULL,
8003         },
8004 };
8005
8006 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8007 struct cmd_read_rxd_txd_result {
8008         cmdline_fixed_string_t read;
8009         cmdline_fixed_string_t rxd_txd;
8010         portid_t port_id;
8011         uint16_t queue_id;
8012         uint16_t desc_id;
8013 };
8014
8015 static void
8016 cmd_read_rxd_txd_parsed(void *parsed_result,
8017                         __rte_unused struct cmdline *cl,
8018                         __rte_unused void *data)
8019 {
8020         struct cmd_read_rxd_txd_result *res = parsed_result;
8021
8022         if (!strcmp(res->rxd_txd, "rxd"))
8023                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8024         else if (!strcmp(res->rxd_txd, "txd"))
8025                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8026 }
8027
8028 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8029         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8030 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8031         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8032                                  "rxd#txd");
8033 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8034         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8035 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8036         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8037 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8038         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8039
8040 cmdline_parse_inst_t cmd_read_rxd_txd = {
8041         .f = cmd_read_rxd_txd_parsed,
8042         .data = NULL,
8043         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8044         .tokens = {
8045                 (void *)&cmd_read_rxd_txd_read,
8046                 (void *)&cmd_read_rxd_txd_rxd_txd,
8047                 (void *)&cmd_read_rxd_txd_port_id,
8048                 (void *)&cmd_read_rxd_txd_queue_id,
8049                 (void *)&cmd_read_rxd_txd_desc_id,
8050                 NULL,
8051         },
8052 };
8053
8054 /* *** QUIT *** */
8055 struct cmd_quit_result {
8056         cmdline_fixed_string_t quit;
8057 };
8058
8059 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8060                             struct cmdline *cl,
8061                             __rte_unused void *data)
8062 {
8063         cmdline_quit(cl);
8064 }
8065
8066 cmdline_parse_token_string_t cmd_quit_quit =
8067         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8068
8069 cmdline_parse_inst_t cmd_quit = {
8070         .f = cmd_quit_parsed,
8071         .data = NULL,
8072         .help_str = "quit: Exit application",
8073         .tokens = {
8074                 (void *)&cmd_quit_quit,
8075                 NULL,
8076         },
8077 };
8078
8079 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8080 struct cmd_mac_addr_result {
8081         cmdline_fixed_string_t mac_addr_cmd;
8082         cmdline_fixed_string_t what;
8083         uint16_t port_num;
8084         struct rte_ether_addr address;
8085 };
8086
8087 static void cmd_mac_addr_parsed(void *parsed_result,
8088                 __rte_unused struct cmdline *cl,
8089                 __rte_unused void *data)
8090 {
8091         struct cmd_mac_addr_result *res = parsed_result;
8092         int ret;
8093
8094         if (strcmp(res->what, "add") == 0)
8095                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8096         else if (strcmp(res->what, "set") == 0)
8097                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8098                                                        &res->address);
8099         else
8100                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8101
8102         /* check the return value and print it if is < 0 */
8103         if(ret < 0)
8104                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8105
8106 }
8107
8108 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8109         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8110                                 "mac_addr");
8111 cmdline_parse_token_string_t cmd_mac_addr_what =
8112         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8113                                 "add#remove#set");
8114 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8115                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8116                                         UINT16);
8117 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8118                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8119
8120 cmdline_parse_inst_t cmd_mac_addr = {
8121         .f = cmd_mac_addr_parsed,
8122         .data = (void *)0,
8123         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8124                         "Add/Remove/Set MAC address on port_id",
8125         .tokens = {
8126                 (void *)&cmd_mac_addr_cmd,
8127                 (void *)&cmd_mac_addr_what,
8128                 (void *)&cmd_mac_addr_portnum,
8129                 (void *)&cmd_mac_addr_addr,
8130                 NULL,
8131         },
8132 };
8133
8134 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8135 struct cmd_eth_peer_result {
8136         cmdline_fixed_string_t set;
8137         cmdline_fixed_string_t eth_peer;
8138         portid_t port_id;
8139         cmdline_fixed_string_t peer_addr;
8140 };
8141
8142 static void cmd_set_eth_peer_parsed(void *parsed_result,
8143                         __rte_unused struct cmdline *cl,
8144                         __rte_unused void *data)
8145 {
8146                 struct cmd_eth_peer_result *res = parsed_result;
8147
8148                 if (test_done == 0) {
8149                         printf("Please stop forwarding first\n");
8150                         return;
8151                 }
8152                 if (!strcmp(res->eth_peer, "eth-peer")) {
8153                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8154                         fwd_config_setup();
8155                 }
8156 }
8157 cmdline_parse_token_string_t cmd_eth_peer_set =
8158         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8159 cmdline_parse_token_string_t cmd_eth_peer =
8160         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8161 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8162         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8163 cmdline_parse_token_string_t cmd_eth_peer_addr =
8164         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8165
8166 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8167         .f = cmd_set_eth_peer_parsed,
8168         .data = NULL,
8169         .help_str = "set eth-peer <port_id> <peer_mac>",
8170         .tokens = {
8171                 (void *)&cmd_eth_peer_set,
8172                 (void *)&cmd_eth_peer,
8173                 (void *)&cmd_eth_peer_port_id,
8174                 (void *)&cmd_eth_peer_addr,
8175                 NULL,
8176         },
8177 };
8178
8179 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8180 struct cmd_set_qmap_result {
8181         cmdline_fixed_string_t set;
8182         cmdline_fixed_string_t qmap;
8183         cmdline_fixed_string_t what;
8184         portid_t port_id;
8185         uint16_t queue_id;
8186         uint8_t map_value;
8187 };
8188
8189 static void
8190 cmd_set_qmap_parsed(void *parsed_result,
8191                        __rte_unused struct cmdline *cl,
8192                        __rte_unused void *data)
8193 {
8194         struct cmd_set_qmap_result *res = parsed_result;
8195         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8196
8197         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8198 }
8199
8200 cmdline_parse_token_string_t cmd_setqmap_set =
8201         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8202                                  set, "set");
8203 cmdline_parse_token_string_t cmd_setqmap_qmap =
8204         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8205                                  qmap, "stat_qmap");
8206 cmdline_parse_token_string_t cmd_setqmap_what =
8207         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8208                                  what, "tx#rx");
8209 cmdline_parse_token_num_t cmd_setqmap_portid =
8210         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8211                               port_id, UINT16);
8212 cmdline_parse_token_num_t cmd_setqmap_queueid =
8213         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8214                               queue_id, UINT16);
8215 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8216         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8217                               map_value, UINT8);
8218
8219 cmdline_parse_inst_t cmd_set_qmap = {
8220         .f = cmd_set_qmap_parsed,
8221         .data = NULL,
8222         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8223                 "Set statistics mapping value on tx|rx queue_id of port_id",
8224         .tokens = {
8225                 (void *)&cmd_setqmap_set,
8226                 (void *)&cmd_setqmap_qmap,
8227                 (void *)&cmd_setqmap_what,
8228                 (void *)&cmd_setqmap_portid,
8229                 (void *)&cmd_setqmap_queueid,
8230                 (void *)&cmd_setqmap_mapvalue,
8231                 NULL,
8232         },
8233 };
8234
8235 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8236 struct cmd_set_xstats_hide_zero_result {
8237         cmdline_fixed_string_t keyword;
8238         cmdline_fixed_string_t name;
8239         cmdline_fixed_string_t on_off;
8240 };
8241
8242 static void
8243 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8244                         __rte_unused struct cmdline *cl,
8245                         __rte_unused void *data)
8246 {
8247         struct cmd_set_xstats_hide_zero_result *res;
8248         uint16_t on_off = 0;
8249
8250         res = parsed_result;
8251         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8252         set_xstats_hide_zero(on_off);
8253 }
8254
8255 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8256         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8257                                  keyword, "set");
8258 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8259         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8260                                  name, "xstats-hide-zero");
8261 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8262         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8263                                  on_off, "on#off");
8264
8265 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8266         .f = cmd_set_xstats_hide_zero_parsed,
8267         .data = NULL,
8268         .help_str = "set xstats-hide-zero on|off",
8269         .tokens = {
8270                 (void *)&cmd_set_xstats_hide_zero_keyword,
8271                 (void *)&cmd_set_xstats_hide_zero_name,
8272                 (void *)&cmd_set_xstats_hide_zero_on_off,
8273                 NULL,
8274         },
8275 };
8276
8277 /* *** CONFIGURE UNICAST HASH TABLE *** */
8278 struct cmd_set_uc_hash_table {
8279         cmdline_fixed_string_t set;
8280         cmdline_fixed_string_t port;
8281         portid_t port_id;
8282         cmdline_fixed_string_t what;
8283         struct rte_ether_addr address;
8284         cmdline_fixed_string_t mode;
8285 };
8286
8287 static void
8288 cmd_set_uc_hash_parsed(void *parsed_result,
8289                        __rte_unused struct cmdline *cl,
8290                        __rte_unused void *data)
8291 {
8292         int ret=0;
8293         struct cmd_set_uc_hash_table *res = parsed_result;
8294
8295         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8296
8297         if (strcmp(res->what, "uta") == 0)
8298                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8299                                                 &res->address,(uint8_t)is_on);
8300         if (ret < 0)
8301                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8302
8303 }
8304
8305 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8306         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8307                                  set, "set");
8308 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8309         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8310                                  port, "port");
8311 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8312         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8313                               port_id, UINT16);
8314 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8315         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8316                                  what, "uta");
8317 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8318         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8319                                 address);
8320 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8321         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8322                                  mode, "on#off");
8323
8324 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8325         .f = cmd_set_uc_hash_parsed,
8326         .data = NULL,
8327         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8328         .tokens = {
8329                 (void *)&cmd_set_uc_hash_set,
8330                 (void *)&cmd_set_uc_hash_port,
8331                 (void *)&cmd_set_uc_hash_portid,
8332                 (void *)&cmd_set_uc_hash_what,
8333                 (void *)&cmd_set_uc_hash_mac,
8334                 (void *)&cmd_set_uc_hash_mode,
8335                 NULL,
8336         },
8337 };
8338
8339 struct cmd_set_uc_all_hash_table {
8340         cmdline_fixed_string_t set;
8341         cmdline_fixed_string_t port;
8342         portid_t port_id;
8343         cmdline_fixed_string_t what;
8344         cmdline_fixed_string_t value;
8345         cmdline_fixed_string_t mode;
8346 };
8347
8348 static void
8349 cmd_set_uc_all_hash_parsed(void *parsed_result,
8350                        __rte_unused struct cmdline *cl,
8351                        __rte_unused void *data)
8352 {
8353         int ret=0;
8354         struct cmd_set_uc_all_hash_table *res = parsed_result;
8355
8356         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8357
8358         if ((strcmp(res->what, "uta") == 0) &&
8359                 (strcmp(res->value, "all") == 0))
8360                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8361         if (ret < 0)
8362                 printf("bad unicast hash table parameter,"
8363                         "return code = %d \n", ret);
8364 }
8365
8366 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8367         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8368                                  set, "set");
8369 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8370         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8371                                  port, "port");
8372 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8373         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8374                               port_id, UINT16);
8375 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8376         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8377                                  what, "uta");
8378 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8380                                 value,"all");
8381 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8382         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8383                                  mode, "on#off");
8384
8385 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8386         .f = cmd_set_uc_all_hash_parsed,
8387         .data = NULL,
8388         .help_str = "set port <port_id> uta all on|off",
8389         .tokens = {
8390                 (void *)&cmd_set_uc_all_hash_set,
8391                 (void *)&cmd_set_uc_all_hash_port,
8392                 (void *)&cmd_set_uc_all_hash_portid,
8393                 (void *)&cmd_set_uc_all_hash_what,
8394                 (void *)&cmd_set_uc_all_hash_value,
8395                 (void *)&cmd_set_uc_all_hash_mode,
8396                 NULL,
8397         },
8398 };
8399
8400 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8401 struct cmd_set_vf_macvlan_filter {
8402         cmdline_fixed_string_t set;
8403         cmdline_fixed_string_t port;
8404         portid_t port_id;
8405         cmdline_fixed_string_t vf;
8406         uint8_t vf_id;
8407         struct rte_ether_addr address;
8408         cmdline_fixed_string_t filter_type;
8409         cmdline_fixed_string_t mode;
8410 };
8411
8412 static void
8413 cmd_set_vf_macvlan_parsed(void *parsed_result,
8414                        __rte_unused struct cmdline *cl,
8415                        __rte_unused void *data)
8416 {
8417         int is_on, ret = 0;
8418         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8419         struct rte_eth_mac_filter filter;
8420
8421         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8422
8423         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8424
8425         /* set VF MAC filter */
8426         filter.is_vf = 1;
8427
8428         /* set VF ID */
8429         filter.dst_id = res->vf_id;
8430
8431         if (!strcmp(res->filter_type, "exact-mac"))
8432                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8433         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8434                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8435         else if (!strcmp(res->filter_type, "hashmac"))
8436                 filter.filter_type = RTE_MAC_HASH_MATCH;
8437         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8438                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8439
8440         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8441
8442         if (is_on)
8443                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8444                                         RTE_ETH_FILTER_MACVLAN,
8445                                         RTE_ETH_FILTER_ADD,
8446                                          &filter);
8447         else
8448                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8449                                         RTE_ETH_FILTER_MACVLAN,
8450                                         RTE_ETH_FILTER_DELETE,
8451                                         &filter);
8452
8453         if (ret < 0)
8454                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8455
8456 }
8457
8458 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8459         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8460                                  set, "set");
8461 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8462         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8463                                  port, "port");
8464 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8465         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8466                               port_id, UINT16);
8467 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8468         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8469                                  vf, "vf");
8470 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8471         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8472                                 vf_id, UINT8);
8473 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8474         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8475                                 address);
8476 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8477         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8478                                 filter_type, "exact-mac#exact-mac-vlan"
8479                                 "#hashmac#hashmac-vlan");
8480 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8481         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8482                                  mode, "on#off");
8483
8484 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8485         .f = cmd_set_vf_macvlan_parsed,
8486         .data = NULL,
8487         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8488                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8489                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8490                 "hash match rule: hash match of MAC and exact match of VLAN",
8491         .tokens = {
8492                 (void *)&cmd_set_vf_macvlan_set,
8493                 (void *)&cmd_set_vf_macvlan_port,
8494                 (void *)&cmd_set_vf_macvlan_portid,
8495                 (void *)&cmd_set_vf_macvlan_vf,
8496                 (void *)&cmd_set_vf_macvlan_vf_id,
8497                 (void *)&cmd_set_vf_macvlan_mac,
8498                 (void *)&cmd_set_vf_macvlan_filter_type,
8499                 (void *)&cmd_set_vf_macvlan_mode,
8500                 NULL,
8501         },
8502 };
8503
8504 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8505 struct cmd_set_vf_traffic {
8506         cmdline_fixed_string_t set;
8507         cmdline_fixed_string_t port;
8508         portid_t port_id;
8509         cmdline_fixed_string_t vf;
8510         uint8_t vf_id;
8511         cmdline_fixed_string_t what;
8512         cmdline_fixed_string_t mode;
8513 };
8514
8515 static void
8516 cmd_set_vf_traffic_parsed(void *parsed_result,
8517                        __rte_unused struct cmdline *cl,
8518                        __rte_unused void *data)
8519 {
8520         struct cmd_set_vf_traffic *res = parsed_result;
8521         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8522         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8523
8524         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8525 }
8526
8527 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8528         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8529                                  set, "set");
8530 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8531         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8532                                  port, "port");
8533 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8534         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8535                               port_id, UINT16);
8536 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8537         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8538                                  vf, "vf");
8539 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8540         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8541                               vf_id, UINT8);
8542 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8543         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8544                                  what, "tx#rx");
8545 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8547                                  mode, "on#off");
8548
8549 cmdline_parse_inst_t cmd_set_vf_traffic = {
8550         .f = cmd_set_vf_traffic_parsed,
8551         .data = NULL,
8552         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8553         .tokens = {
8554                 (void *)&cmd_setvf_traffic_set,
8555                 (void *)&cmd_setvf_traffic_port,
8556                 (void *)&cmd_setvf_traffic_portid,
8557                 (void *)&cmd_setvf_traffic_vf,
8558                 (void *)&cmd_setvf_traffic_vfid,
8559                 (void *)&cmd_setvf_traffic_what,
8560                 (void *)&cmd_setvf_traffic_mode,
8561                 NULL,
8562         },
8563 };
8564
8565 /* *** CONFIGURE VF RECEIVE MODE *** */
8566 struct cmd_set_vf_rxmode {
8567         cmdline_fixed_string_t set;
8568         cmdline_fixed_string_t port;
8569         portid_t port_id;
8570         cmdline_fixed_string_t vf;
8571         uint8_t vf_id;
8572         cmdline_fixed_string_t what;
8573         cmdline_fixed_string_t mode;
8574         cmdline_fixed_string_t on;
8575 };
8576
8577 static void
8578 cmd_set_vf_rxmode_parsed(void *parsed_result,
8579                        __rte_unused struct cmdline *cl,
8580                        __rte_unused void *data)
8581 {
8582         int ret = -ENOTSUP;
8583         uint16_t vf_rxmode = 0;
8584         struct cmd_set_vf_rxmode *res = parsed_result;
8585
8586         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8587         if (!strcmp(res->what,"rxmode")) {
8588                 if (!strcmp(res->mode, "AUPE"))
8589                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8590                 else if (!strcmp(res->mode, "ROPE"))
8591                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8592                 else if (!strcmp(res->mode, "BAM"))
8593                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8594                 else if (!strncmp(res->mode, "MPE",3))
8595                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8596         }
8597
8598         RTE_SET_USED(is_on);
8599
8600 #ifdef RTE_LIBRTE_IXGBE_PMD
8601         if (ret == -ENOTSUP)
8602                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8603                                                   vf_rxmode, (uint8_t)is_on);
8604 #endif
8605 #ifdef RTE_LIBRTE_BNXT_PMD
8606         if (ret == -ENOTSUP)
8607                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8608                                                  vf_rxmode, (uint8_t)is_on);
8609 #endif
8610         if (ret < 0)
8611                 printf("bad VF receive mode parameter, return code = %d \n",
8612                 ret);
8613 }
8614
8615 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8617                                  set, "set");
8618 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8620                                  port, "port");
8621 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8622         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8623                               port_id, UINT16);
8624 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8625         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8626                                  vf, "vf");
8627 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8628         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8629                               vf_id, UINT8);
8630 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8632                                  what, "rxmode");
8633 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8635                                  mode, "AUPE#ROPE#BAM#MPE");
8636 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8637         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8638                                  on, "on#off");
8639
8640 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8641         .f = cmd_set_vf_rxmode_parsed,
8642         .data = NULL,
8643         .help_str = "set port <port_id> vf <vf_id> rxmode "
8644                 "AUPE|ROPE|BAM|MPE on|off",
8645         .tokens = {
8646                 (void *)&cmd_set_vf_rxmode_set,
8647                 (void *)&cmd_set_vf_rxmode_port,
8648                 (void *)&cmd_set_vf_rxmode_portid,
8649                 (void *)&cmd_set_vf_rxmode_vf,
8650                 (void *)&cmd_set_vf_rxmode_vfid,
8651                 (void *)&cmd_set_vf_rxmode_what,
8652                 (void *)&cmd_set_vf_rxmode_mode,
8653                 (void *)&cmd_set_vf_rxmode_on,
8654                 NULL,
8655         },
8656 };
8657
8658 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8659 struct cmd_vf_mac_addr_result {
8660         cmdline_fixed_string_t mac_addr_cmd;
8661         cmdline_fixed_string_t what;
8662         cmdline_fixed_string_t port;
8663         uint16_t port_num;
8664         cmdline_fixed_string_t vf;
8665         uint8_t vf_num;
8666         struct rte_ether_addr address;
8667 };
8668
8669 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8670                 __rte_unused struct cmdline *cl,
8671                 __rte_unused void *data)
8672 {
8673         struct cmd_vf_mac_addr_result *res = parsed_result;
8674         int ret = -ENOTSUP;
8675
8676         if (strcmp(res->what, "add") != 0)
8677                 return;
8678
8679 #ifdef RTE_LIBRTE_I40E_PMD
8680         if (ret == -ENOTSUP)
8681                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8682                                                    &res->address);
8683 #endif
8684 #ifdef RTE_LIBRTE_BNXT_PMD
8685         if (ret == -ENOTSUP)
8686                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8687                                                 res->vf_num);
8688 #endif
8689
8690         if(ret < 0)
8691                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8692
8693 }
8694
8695 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8696         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8697                                 mac_addr_cmd,"mac_addr");
8698 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8699         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8700                                 what,"add");
8701 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8702         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8703                                 port,"port");
8704 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8705         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8706                                 port_num, UINT16);
8707 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8708         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8709                                 vf,"vf");
8710 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8711         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8712                                 vf_num, UINT8);
8713 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8714         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8715                                 address);
8716
8717 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8718         .f = cmd_vf_mac_addr_parsed,
8719         .data = (void *)0,
8720         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8721                 "Add MAC address filtering for a VF on port_id",
8722         .tokens = {
8723                 (void *)&cmd_vf_mac_addr_cmd,
8724                 (void *)&cmd_vf_mac_addr_what,
8725                 (void *)&cmd_vf_mac_addr_port,
8726                 (void *)&cmd_vf_mac_addr_portnum,
8727                 (void *)&cmd_vf_mac_addr_vf,
8728                 (void *)&cmd_vf_mac_addr_vfnum,
8729                 (void *)&cmd_vf_mac_addr_addr,
8730                 NULL,
8731         },
8732 };
8733
8734 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8735 struct cmd_vf_rx_vlan_filter {
8736         cmdline_fixed_string_t rx_vlan;
8737         cmdline_fixed_string_t what;
8738         uint16_t vlan_id;
8739         cmdline_fixed_string_t port;
8740         portid_t port_id;
8741         cmdline_fixed_string_t vf;
8742         uint64_t vf_mask;
8743 };
8744
8745 static void
8746 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8747                           __rte_unused struct cmdline *cl,
8748                           __rte_unused void *data)
8749 {
8750         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8751         int ret = -ENOTSUP;
8752
8753         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8754
8755 #ifdef RTE_LIBRTE_IXGBE_PMD
8756         if (ret == -ENOTSUP)
8757                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8758                                 res->vlan_id, res->vf_mask, is_add);
8759 #endif
8760 #ifdef RTE_LIBRTE_I40E_PMD
8761         if (ret == -ENOTSUP)
8762                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8763                                 res->vlan_id, res->vf_mask, is_add);
8764 #endif
8765 #ifdef RTE_LIBRTE_BNXT_PMD
8766         if (ret == -ENOTSUP)
8767                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8768                                 res->vlan_id, res->vf_mask, is_add);
8769 #endif
8770
8771         switch (ret) {
8772         case 0:
8773                 break;
8774         case -EINVAL:
8775                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8776                                 res->vlan_id, res->vf_mask);
8777                 break;
8778         case -ENODEV:
8779                 printf("invalid port_id %d\n", res->port_id);
8780                 break;
8781         case -ENOTSUP:
8782                 printf("function not implemented or supported\n");
8783                 break;
8784         default:
8785                 printf("programming error: (%s)\n", strerror(-ret));
8786         }
8787 }
8788
8789 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8790         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8791                                  rx_vlan, "rx_vlan");
8792 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8793         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8794                                  what, "add#rm");
8795 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8796         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8797                               vlan_id, UINT16);
8798 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8799         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8800                                  port, "port");
8801 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8802         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8803                               port_id, UINT16);
8804 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8805         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8806                                  vf, "vf");
8807 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8808         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8809                               vf_mask, UINT64);
8810
8811 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8812         .f = cmd_vf_rx_vlan_filter_parsed,
8813         .data = NULL,
8814         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8815                 "(vf_mask = hexadecimal VF mask)",
8816         .tokens = {
8817                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8818                 (void *)&cmd_vf_rx_vlan_filter_what,
8819                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8820                 (void *)&cmd_vf_rx_vlan_filter_port,
8821                 (void *)&cmd_vf_rx_vlan_filter_portid,
8822                 (void *)&cmd_vf_rx_vlan_filter_vf,
8823                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8824                 NULL,
8825         },
8826 };
8827
8828 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8829 struct cmd_queue_rate_limit_result {
8830         cmdline_fixed_string_t set;
8831         cmdline_fixed_string_t port;
8832         uint16_t port_num;
8833         cmdline_fixed_string_t queue;
8834         uint8_t queue_num;
8835         cmdline_fixed_string_t rate;
8836         uint16_t rate_num;
8837 };
8838
8839 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8840                 __rte_unused struct cmdline *cl,
8841                 __rte_unused void *data)
8842 {
8843         struct cmd_queue_rate_limit_result *res = parsed_result;
8844         int ret = 0;
8845
8846         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8847                 && (strcmp(res->queue, "queue") == 0)
8848                 && (strcmp(res->rate, "rate") == 0))
8849                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8850                                         res->rate_num);
8851         if (ret < 0)
8852                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8853
8854 }
8855
8856 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8857         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8858                                 set, "set");
8859 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8860         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8861                                 port, "port");
8862 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8863         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8864                                 port_num, UINT16);
8865 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8866         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8867                                 queue, "queue");
8868 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8869         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8870                                 queue_num, UINT8);
8871 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8872         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8873                                 rate, "rate");
8874 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8875         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8876                                 rate_num, UINT16);
8877
8878 cmdline_parse_inst_t cmd_queue_rate_limit = {
8879         .f = cmd_queue_rate_limit_parsed,
8880         .data = (void *)0,
8881         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8882                 "Set rate limit for a queue on port_id",
8883         .tokens = {
8884                 (void *)&cmd_queue_rate_limit_set,
8885                 (void *)&cmd_queue_rate_limit_port,
8886                 (void *)&cmd_queue_rate_limit_portnum,
8887                 (void *)&cmd_queue_rate_limit_queue,
8888                 (void *)&cmd_queue_rate_limit_queuenum,
8889                 (void *)&cmd_queue_rate_limit_rate,
8890                 (void *)&cmd_queue_rate_limit_ratenum,
8891                 NULL,
8892         },
8893 };
8894
8895 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8896 struct cmd_vf_rate_limit_result {
8897         cmdline_fixed_string_t set;
8898         cmdline_fixed_string_t port;
8899         uint16_t port_num;
8900         cmdline_fixed_string_t vf;
8901         uint8_t vf_num;
8902         cmdline_fixed_string_t rate;
8903         uint16_t rate_num;
8904         cmdline_fixed_string_t q_msk;
8905         uint64_t q_msk_val;
8906 };
8907
8908 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8909                 __rte_unused struct cmdline *cl,
8910                 __rte_unused void *data)
8911 {
8912         struct cmd_vf_rate_limit_result *res = parsed_result;
8913         int ret = 0;
8914
8915         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8916                 && (strcmp(res->vf, "vf") == 0)
8917                 && (strcmp(res->rate, "rate") == 0)
8918                 && (strcmp(res->q_msk, "queue_mask") == 0))
8919                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8920                                         res->rate_num, res->q_msk_val);
8921         if (ret < 0)
8922                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8923
8924 }
8925
8926 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8927         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8928                                 set, "set");
8929 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8930         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8931                                 port, "port");
8932 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8933         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8934                                 port_num, UINT16);
8935 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8936         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8937                                 vf, "vf");
8938 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8939         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8940                                 vf_num, UINT8);
8941 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8942         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8943                                 rate, "rate");
8944 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8945         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8946                                 rate_num, UINT16);
8947 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8948         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8949                                 q_msk, "queue_mask");
8950 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8951         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8952                                 q_msk_val, UINT64);
8953
8954 cmdline_parse_inst_t cmd_vf_rate_limit = {
8955         .f = cmd_vf_rate_limit_parsed,
8956         .data = (void *)0,
8957         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8958                 "queue_mask <queue_mask_value>: "
8959                 "Set rate limit for queues of VF on port_id",
8960         .tokens = {
8961                 (void *)&cmd_vf_rate_limit_set,
8962                 (void *)&cmd_vf_rate_limit_port,
8963                 (void *)&cmd_vf_rate_limit_portnum,
8964                 (void *)&cmd_vf_rate_limit_vf,
8965                 (void *)&cmd_vf_rate_limit_vfnum,
8966                 (void *)&cmd_vf_rate_limit_rate,
8967                 (void *)&cmd_vf_rate_limit_ratenum,
8968                 (void *)&cmd_vf_rate_limit_q_msk,
8969                 (void *)&cmd_vf_rate_limit_q_msk_val,
8970                 NULL,
8971         },
8972 };
8973
8974 /* *** ADD TUNNEL FILTER OF A PORT *** */
8975 struct cmd_tunnel_filter_result {
8976         cmdline_fixed_string_t cmd;
8977         cmdline_fixed_string_t what;
8978         portid_t port_id;
8979         struct rte_ether_addr outer_mac;
8980         struct rte_ether_addr inner_mac;
8981         cmdline_ipaddr_t ip_value;
8982         uint16_t inner_vlan;
8983         cmdline_fixed_string_t tunnel_type;
8984         cmdline_fixed_string_t filter_type;
8985         uint32_t tenant_id;
8986         uint16_t queue_num;
8987 };
8988
8989 static void
8990 cmd_tunnel_filter_parsed(void *parsed_result,
8991                           __rte_unused struct cmdline *cl,
8992                           __rte_unused void *data)
8993 {
8994         struct cmd_tunnel_filter_result *res = parsed_result;
8995         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
8996         int ret = 0;
8997
8998         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
8999
9000         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9001         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9002         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9003
9004         if (res->ip_value.family == AF_INET) {
9005                 tunnel_filter_conf.ip_addr.ipv4_addr =
9006                         res->ip_value.addr.ipv4.s_addr;
9007                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9008         } else {
9009                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9010                         &(res->ip_value.addr.ipv6),
9011                         sizeof(struct in6_addr));
9012                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9013         }
9014
9015         if (!strcmp(res->filter_type, "imac-ivlan"))
9016                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9017         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9018                 tunnel_filter_conf.filter_type =
9019                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9020         else if (!strcmp(res->filter_type, "imac-tenid"))
9021                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9022         else if (!strcmp(res->filter_type, "imac"))
9023                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9024         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9025                 tunnel_filter_conf.filter_type =
9026                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9027         else if (!strcmp(res->filter_type, "oip"))
9028                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9029         else if (!strcmp(res->filter_type, "iip"))
9030                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9031         else {
9032                 printf("The filter type is not supported");
9033                 return;
9034         }
9035
9036         if (!strcmp(res->tunnel_type, "vxlan"))
9037                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9038         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9039                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9040         else if (!strcmp(res->tunnel_type, "nvgre"))
9041                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9042         else if (!strcmp(res->tunnel_type, "ipingre"))
9043                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9044         else {
9045                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9046                 return;
9047         }
9048
9049         tunnel_filter_conf.tenant_id = res->tenant_id;
9050         tunnel_filter_conf.queue_id = res->queue_num;
9051         if (!strcmp(res->what, "add"))
9052                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9053                                         RTE_ETH_FILTER_TUNNEL,
9054                                         RTE_ETH_FILTER_ADD,
9055                                         &tunnel_filter_conf);
9056         else
9057                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9058                                         RTE_ETH_FILTER_TUNNEL,
9059                                         RTE_ETH_FILTER_DELETE,
9060                                         &tunnel_filter_conf);
9061         if (ret < 0)
9062                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9063                                 strerror(-ret));
9064
9065 }
9066 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9067         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9068         cmd, "tunnel_filter");
9069 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9070         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9071         what, "add#rm");
9072 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9073         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9074         port_id, UINT16);
9075 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9076         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9077         outer_mac);
9078 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9079         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9080         inner_mac);
9081 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9082         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9083         inner_vlan, UINT16);
9084 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9085         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9086         ip_value);
9087 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9088         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9089         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9090
9091 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9092         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9093         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9094                 "imac#omac-imac-tenid");
9095 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9096         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9097         tenant_id, UINT32);
9098 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9099         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9100         queue_num, UINT16);
9101
9102 cmdline_parse_inst_t cmd_tunnel_filter = {
9103         .f = cmd_tunnel_filter_parsed,
9104         .data = (void *)0,
9105         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9106                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9107                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9108                 "<queue_id>: Add/Rm tunnel filter of a port",
9109         .tokens = {
9110                 (void *)&cmd_tunnel_filter_cmd,
9111                 (void *)&cmd_tunnel_filter_what,
9112                 (void *)&cmd_tunnel_filter_port_id,
9113                 (void *)&cmd_tunnel_filter_outer_mac,
9114                 (void *)&cmd_tunnel_filter_inner_mac,
9115                 (void *)&cmd_tunnel_filter_ip_value,
9116                 (void *)&cmd_tunnel_filter_innner_vlan,
9117                 (void *)&cmd_tunnel_filter_tunnel_type,
9118                 (void *)&cmd_tunnel_filter_filter_type,
9119                 (void *)&cmd_tunnel_filter_tenant_id,
9120                 (void *)&cmd_tunnel_filter_queue_num,
9121                 NULL,
9122         },
9123 };
9124
9125 /* *** CONFIGURE TUNNEL UDP PORT *** */
9126 struct cmd_tunnel_udp_config {
9127         cmdline_fixed_string_t cmd;
9128         cmdline_fixed_string_t what;
9129         uint16_t udp_port;
9130         portid_t port_id;
9131 };
9132
9133 static void
9134 cmd_tunnel_udp_config_parsed(void *parsed_result,
9135                           __rte_unused struct cmdline *cl,
9136                           __rte_unused void *data)
9137 {
9138         struct cmd_tunnel_udp_config *res = parsed_result;
9139         struct rte_eth_udp_tunnel tunnel_udp;
9140         int ret;
9141
9142         tunnel_udp.udp_port = res->udp_port;
9143
9144         if (!strcmp(res->cmd, "rx_vxlan_port"))
9145                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9146
9147         if (!strcmp(res->what, "add"))
9148                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9149                                                       &tunnel_udp);
9150         else
9151                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9152                                                          &tunnel_udp);
9153
9154         if (ret < 0)
9155                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9156 }
9157
9158 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9159         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9160                                 cmd, "rx_vxlan_port");
9161 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9162         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9163                                 what, "add#rm");
9164 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9165         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9166                                 udp_port, UINT16);
9167 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9168         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9169                                 port_id, UINT16);
9170
9171 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9172         .f = cmd_tunnel_udp_config_parsed,
9173         .data = (void *)0,
9174         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9175                 "Add/Remove a tunneling UDP port filter",
9176         .tokens = {
9177                 (void *)&cmd_tunnel_udp_config_cmd,
9178                 (void *)&cmd_tunnel_udp_config_what,
9179                 (void *)&cmd_tunnel_udp_config_udp_port,
9180                 (void *)&cmd_tunnel_udp_config_port_id,
9181                 NULL,
9182         },
9183 };
9184
9185 struct cmd_config_tunnel_udp_port {
9186         cmdline_fixed_string_t port;
9187         cmdline_fixed_string_t config;
9188         portid_t port_id;
9189         cmdline_fixed_string_t udp_tunnel_port;
9190         cmdline_fixed_string_t action;
9191         cmdline_fixed_string_t tunnel_type;
9192         uint16_t udp_port;
9193 };
9194
9195 static void
9196 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9197                                __rte_unused struct cmdline *cl,
9198                                __rte_unused void *data)
9199 {
9200         struct cmd_config_tunnel_udp_port *res = parsed_result;
9201         struct rte_eth_udp_tunnel tunnel_udp;
9202         int ret = 0;
9203
9204         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9205                 return;
9206
9207         tunnel_udp.udp_port = res->udp_port;
9208
9209         if (!strcmp(res->tunnel_type, "vxlan")) {
9210                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9211         } else if (!strcmp(res->tunnel_type, "geneve")) {
9212                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9213         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9214                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9215         } else {
9216                 printf("Invalid tunnel type\n");
9217                 return;
9218         }
9219
9220         if (!strcmp(res->action, "add"))
9221                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9222                                                       &tunnel_udp);
9223         else
9224                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9225                                                          &tunnel_udp);
9226
9227         if (ret < 0)
9228                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9229 }
9230
9231 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9232         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9233                                  "port");
9234 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9235         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9236                                  "config");
9237 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9238         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9239                               UINT16);
9240 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9241         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9242                                  udp_tunnel_port,
9243                                  "udp_tunnel_port");
9244 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9245         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9246                                  "add#rm");
9247 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9248         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9249                                  "vxlan#geneve#vxlan-gpe");
9250 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9251         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9252                               UINT16);
9253
9254 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9255         .f = cmd_cfg_tunnel_udp_port_parsed,
9256         .data = NULL,
9257         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9258         .tokens = {
9259                 (void *)&cmd_config_tunnel_udp_port_port,
9260                 (void *)&cmd_config_tunnel_udp_port_config,
9261                 (void *)&cmd_config_tunnel_udp_port_port_id,
9262                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9263                 (void *)&cmd_config_tunnel_udp_port_action,
9264                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9265                 (void *)&cmd_config_tunnel_udp_port_value,
9266                 NULL,
9267         },
9268 };
9269
9270 /* *** GLOBAL CONFIG *** */
9271 struct cmd_global_config_result {
9272         cmdline_fixed_string_t cmd;
9273         portid_t port_id;
9274         cmdline_fixed_string_t cfg_type;
9275         uint8_t len;
9276 };
9277
9278 static void
9279 cmd_global_config_parsed(void *parsed_result,
9280                          __rte_unused struct cmdline *cl,
9281                          __rte_unused void *data)
9282 {
9283         struct cmd_global_config_result *res = parsed_result;
9284         struct rte_eth_global_cfg conf;
9285         int ret;
9286
9287         memset(&conf, 0, sizeof(conf));
9288         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9289         conf.cfg.gre_key_len = res->len;
9290         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9291                                       RTE_ETH_FILTER_SET, &conf);
9292         if (ret != 0)
9293                 printf("Global config error\n");
9294 }
9295
9296 cmdline_parse_token_string_t cmd_global_config_cmd =
9297         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9298                 "global_config");
9299 cmdline_parse_token_num_t cmd_global_config_port_id =
9300         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9301                                UINT16);
9302 cmdline_parse_token_string_t cmd_global_config_type =
9303         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9304                 cfg_type, "gre-key-len");
9305 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9306         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9307                 len, UINT8);
9308
9309 cmdline_parse_inst_t cmd_global_config = {
9310         .f = cmd_global_config_parsed,
9311         .data = (void *)NULL,
9312         .help_str = "global_config <port_id> gre-key-len <key_len>",
9313         .tokens = {
9314                 (void *)&cmd_global_config_cmd,
9315                 (void *)&cmd_global_config_port_id,
9316                 (void *)&cmd_global_config_type,
9317                 (void *)&cmd_global_config_gre_key_len,
9318                 NULL,
9319         },
9320 };
9321
9322 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9323 struct cmd_set_mirror_mask_result {
9324         cmdline_fixed_string_t set;
9325         cmdline_fixed_string_t port;
9326         portid_t port_id;
9327         cmdline_fixed_string_t mirror;
9328         uint8_t rule_id;
9329         cmdline_fixed_string_t what;
9330         cmdline_fixed_string_t value;
9331         cmdline_fixed_string_t dstpool;
9332         uint8_t dstpool_id;
9333         cmdline_fixed_string_t on;
9334 };
9335
9336 cmdline_parse_token_string_t cmd_mirror_mask_set =
9337         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9338                                 set, "set");
9339 cmdline_parse_token_string_t cmd_mirror_mask_port =
9340         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9341                                 port, "port");
9342 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9343         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9344                                 port_id, UINT16);
9345 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9346         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9347                                 mirror, "mirror-rule");
9348 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9349         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9350                                 rule_id, UINT8);
9351 cmdline_parse_token_string_t cmd_mirror_mask_what =
9352         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9353                                 what, "pool-mirror-up#pool-mirror-down"
9354                                       "#vlan-mirror");
9355 cmdline_parse_token_string_t cmd_mirror_mask_value =
9356         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9357                                 value, NULL);
9358 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9359         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9360                                 dstpool, "dst-pool");
9361 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9362         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9363                                 dstpool_id, UINT8);
9364 cmdline_parse_token_string_t cmd_mirror_mask_on =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9366                                 on, "on#off");
9367
9368 static void
9369 cmd_set_mirror_mask_parsed(void *parsed_result,
9370                        __rte_unused struct cmdline *cl,
9371                        __rte_unused void *data)
9372 {
9373         int ret,nb_item,i;
9374         struct cmd_set_mirror_mask_result *res = parsed_result;
9375         struct rte_eth_mirror_conf mr_conf;
9376
9377         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9378
9379         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9380
9381         mr_conf.dst_pool = res->dstpool_id;
9382
9383         if (!strcmp(res->what, "pool-mirror-up")) {
9384                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9385                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9386         } else if (!strcmp(res->what, "pool-mirror-down")) {
9387                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9388                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9389         } else if (!strcmp(res->what, "vlan-mirror")) {
9390                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9391                 nb_item = parse_item_list(res->value, "vlan",
9392                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9393                 if (nb_item <= 0)
9394                         return;
9395
9396                 for (i = 0; i < nb_item; i++) {
9397                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9398                                 printf("Invalid vlan_id: must be < 4096\n");
9399                                 return;
9400                         }
9401
9402                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9403                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9404                 }
9405         }
9406
9407         if (!strcmp(res->on, "on"))
9408                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9409                                                 res->rule_id, 1);
9410         else
9411                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9412                                                 res->rule_id, 0);
9413         if (ret < 0)
9414                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9415 }
9416
9417 cmdline_parse_inst_t cmd_set_mirror_mask = {
9418                 .f = cmd_set_mirror_mask_parsed,
9419                 .data = NULL,
9420                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9421                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9422                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9423                 .tokens = {
9424                         (void *)&cmd_mirror_mask_set,
9425                         (void *)&cmd_mirror_mask_port,
9426                         (void *)&cmd_mirror_mask_portid,
9427                         (void *)&cmd_mirror_mask_mirror,
9428                         (void *)&cmd_mirror_mask_ruleid,
9429                         (void *)&cmd_mirror_mask_what,
9430                         (void *)&cmd_mirror_mask_value,
9431                         (void *)&cmd_mirror_mask_dstpool,
9432                         (void *)&cmd_mirror_mask_poolid,
9433                         (void *)&cmd_mirror_mask_on,
9434                         NULL,
9435                 },
9436 };
9437
9438 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9439 struct cmd_set_mirror_link_result {
9440         cmdline_fixed_string_t set;
9441         cmdline_fixed_string_t port;
9442         portid_t port_id;
9443         cmdline_fixed_string_t mirror;
9444         uint8_t rule_id;
9445         cmdline_fixed_string_t what;
9446         cmdline_fixed_string_t dstpool;
9447         uint8_t dstpool_id;
9448         cmdline_fixed_string_t on;
9449 };
9450
9451 cmdline_parse_token_string_t cmd_mirror_link_set =
9452         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9453                                  set, "set");
9454 cmdline_parse_token_string_t cmd_mirror_link_port =
9455         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9456                                 port, "port");
9457 cmdline_parse_token_num_t cmd_mirror_link_portid =
9458         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9459                                 port_id, UINT16);
9460 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9461         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9462                                 mirror, "mirror-rule");
9463 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9464         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9465                             rule_id, UINT8);
9466 cmdline_parse_token_string_t cmd_mirror_link_what =
9467         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9468                                 what, "uplink-mirror#downlink-mirror");
9469 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9470         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9471                                 dstpool, "dst-pool");
9472 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9473         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9474                                 dstpool_id, UINT8);
9475 cmdline_parse_token_string_t cmd_mirror_link_on =
9476         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9477                                 on, "on#off");
9478
9479 static void
9480 cmd_set_mirror_link_parsed(void *parsed_result,
9481                        __rte_unused struct cmdline *cl,
9482                        __rte_unused void *data)
9483 {
9484         int ret;
9485         struct cmd_set_mirror_link_result *res = parsed_result;
9486         struct rte_eth_mirror_conf mr_conf;
9487
9488         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9489         if (!strcmp(res->what, "uplink-mirror"))
9490                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9491         else
9492                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9493
9494         mr_conf.dst_pool = res->dstpool_id;
9495
9496         if (!strcmp(res->on, "on"))
9497                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9498                                                 res->rule_id, 1);
9499         else
9500                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9501                                                 res->rule_id, 0);
9502
9503         /* check the return value and print it if is < 0 */
9504         if (ret < 0)
9505                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9506
9507 }
9508
9509 cmdline_parse_inst_t cmd_set_mirror_link = {
9510                 .f = cmd_set_mirror_link_parsed,
9511                 .data = NULL,
9512                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9513                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9514                 .tokens = {
9515                         (void *)&cmd_mirror_link_set,
9516                         (void *)&cmd_mirror_link_port,
9517                         (void *)&cmd_mirror_link_portid,
9518                         (void *)&cmd_mirror_link_mirror,
9519                         (void *)&cmd_mirror_link_ruleid,
9520                         (void *)&cmd_mirror_link_what,
9521                         (void *)&cmd_mirror_link_dstpool,
9522                         (void *)&cmd_mirror_link_poolid,
9523                         (void *)&cmd_mirror_link_on,
9524                         NULL,
9525                 },
9526 };
9527
9528 /* *** RESET VM MIRROR RULE *** */
9529 struct cmd_rm_mirror_rule_result {
9530         cmdline_fixed_string_t reset;
9531         cmdline_fixed_string_t port;
9532         portid_t port_id;
9533         cmdline_fixed_string_t mirror;
9534         uint8_t rule_id;
9535 };
9536
9537 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9538         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9539                                  reset, "reset");
9540 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9541         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9542                                 port, "port");
9543 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9544         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9545                                 port_id, UINT16);
9546 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9547         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9548                                 mirror, "mirror-rule");
9549 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9550         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9551                                 rule_id, UINT8);
9552
9553 static void
9554 cmd_reset_mirror_rule_parsed(void *parsed_result,
9555                        __rte_unused struct cmdline *cl,
9556                        __rte_unused void *data)
9557 {
9558         int ret;
9559         struct cmd_set_mirror_link_result *res = parsed_result;
9560         /* check rule_id */
9561         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9562         if(ret < 0)
9563                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9564 }
9565
9566 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9567                 .f = cmd_reset_mirror_rule_parsed,
9568                 .data = NULL,
9569                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9570                 .tokens = {
9571                         (void *)&cmd_rm_mirror_rule_reset,
9572                         (void *)&cmd_rm_mirror_rule_port,
9573                         (void *)&cmd_rm_mirror_rule_portid,
9574                         (void *)&cmd_rm_mirror_rule_mirror,
9575                         (void *)&cmd_rm_mirror_rule_ruleid,
9576                         NULL,
9577                 },
9578 };
9579
9580 /* ******************************************************************************** */
9581
9582 struct cmd_dump_result {
9583         cmdline_fixed_string_t dump;
9584 };
9585
9586 static void
9587 dump_struct_sizes(void)
9588 {
9589 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9590         DUMP_SIZE(struct rte_mbuf);
9591         DUMP_SIZE(struct rte_mempool);
9592         DUMP_SIZE(struct rte_ring);
9593 #undef DUMP_SIZE
9594 }
9595
9596
9597 /* Dump the socket memory statistics on console */
9598 static void
9599 dump_socket_mem(FILE *f)
9600 {
9601         struct rte_malloc_socket_stats socket_stats;
9602         unsigned int i;
9603         size_t total = 0;
9604         size_t alloc = 0;
9605         size_t free = 0;
9606         unsigned int n_alloc = 0;
9607         unsigned int n_free = 0;
9608         static size_t last_allocs;
9609         static size_t last_total;
9610
9611
9612         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9613                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9614                     !socket_stats.heap_totalsz_bytes)
9615                         continue;
9616                 total += socket_stats.heap_totalsz_bytes;
9617                 alloc += socket_stats.heap_allocsz_bytes;
9618                 free += socket_stats.heap_freesz_bytes;
9619                 n_alloc += socket_stats.alloc_count;
9620                 n_free += socket_stats.free_count;
9621                 fprintf(f,
9622                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9623                         i,
9624                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9625                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9626                         (double)socket_stats.heap_allocsz_bytes * 100 /
9627                         (double)socket_stats.heap_totalsz_bytes,
9628                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9629                         socket_stats.alloc_count,
9630                         socket_stats.free_count);
9631         }
9632         fprintf(f,
9633                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9634                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9635                 (double)alloc * 100 / (double)total,
9636                 (double)free / (1024 * 1024),
9637                 n_alloc, n_free);
9638         if (last_allocs)
9639                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9640                         ((double)total - (double)last_total) / (1024 * 1024),
9641                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9642         last_allocs = alloc;
9643         last_total = total;
9644 }
9645
9646 static void cmd_dump_parsed(void *parsed_result,
9647                             __rte_unused struct cmdline *cl,
9648                             __rte_unused void *data)
9649 {
9650         struct cmd_dump_result *res = parsed_result;
9651
9652         if (!strcmp(res->dump, "dump_physmem"))
9653                 rte_dump_physmem_layout(stdout);
9654         else if (!strcmp(res->dump, "dump_socket_mem"))
9655                 dump_socket_mem(stdout);
9656         else if (!strcmp(res->dump, "dump_memzone"))
9657                 rte_memzone_dump(stdout);
9658         else if (!strcmp(res->dump, "dump_struct_sizes"))
9659                 dump_struct_sizes();
9660         else if (!strcmp(res->dump, "dump_ring"))
9661                 rte_ring_list_dump(stdout);
9662         else if (!strcmp(res->dump, "dump_mempool"))
9663                 rte_mempool_list_dump(stdout);
9664         else if (!strcmp(res->dump, "dump_devargs"))
9665                 rte_devargs_dump(stdout);
9666         else if (!strcmp(res->dump, "dump_log_types"))
9667                 rte_log_dump(stdout);
9668 }
9669
9670 cmdline_parse_token_string_t cmd_dump_dump =
9671         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9672                 "dump_physmem#"
9673                 "dump_memzone#"
9674                 "dump_socket_mem#"
9675                 "dump_struct_sizes#"
9676                 "dump_ring#"
9677                 "dump_mempool#"
9678                 "dump_devargs#"
9679                 "dump_log_types");
9680
9681 cmdline_parse_inst_t cmd_dump = {
9682         .f = cmd_dump_parsed,  /* function to call */
9683         .data = NULL,      /* 2nd arg of func */
9684         .help_str = "Dump status",
9685         .tokens = {        /* token list, NULL terminated */
9686                 (void *)&cmd_dump_dump,
9687                 NULL,
9688         },
9689 };
9690
9691 /* ******************************************************************************** */
9692
9693 struct cmd_dump_one_result {
9694         cmdline_fixed_string_t dump;
9695         cmdline_fixed_string_t name;
9696 };
9697
9698 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9699                                 __rte_unused void *data)
9700 {
9701         struct cmd_dump_one_result *res = parsed_result;
9702
9703         if (!strcmp(res->dump, "dump_ring")) {
9704                 struct rte_ring *r;
9705                 r = rte_ring_lookup(res->name);
9706                 if (r == NULL) {
9707                         cmdline_printf(cl, "Cannot find ring\n");
9708                         return;
9709                 }
9710                 rte_ring_dump(stdout, r);
9711         } else if (!strcmp(res->dump, "dump_mempool")) {
9712                 struct rte_mempool *mp;
9713                 mp = rte_mempool_lookup(res->name);
9714                 if (mp == NULL) {
9715                         cmdline_printf(cl, "Cannot find mempool\n");
9716                         return;
9717                 }
9718                 rte_mempool_dump(stdout, mp);
9719         }
9720 }
9721
9722 cmdline_parse_token_string_t cmd_dump_one_dump =
9723         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9724                                  "dump_ring#dump_mempool");
9725
9726 cmdline_parse_token_string_t cmd_dump_one_name =
9727         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9728
9729 cmdline_parse_inst_t cmd_dump_one = {
9730         .f = cmd_dump_one_parsed,  /* function to call */
9731         .data = NULL,      /* 2nd arg of func */
9732         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9733         .tokens = {        /* token list, NULL terminated */
9734                 (void *)&cmd_dump_one_dump,
9735                 (void *)&cmd_dump_one_name,
9736                 NULL,
9737         },
9738 };
9739
9740 /* *** Add/Del syn filter *** */
9741 struct cmd_syn_filter_result {
9742         cmdline_fixed_string_t filter;
9743         portid_t port_id;
9744         cmdline_fixed_string_t ops;
9745         cmdline_fixed_string_t priority;
9746         cmdline_fixed_string_t high;
9747         cmdline_fixed_string_t queue;
9748         uint16_t queue_id;
9749 };
9750
9751 static void
9752 cmd_syn_filter_parsed(void *parsed_result,
9753                         __rte_unused struct cmdline *cl,
9754                         __rte_unused void *data)
9755 {
9756         struct cmd_syn_filter_result *res = parsed_result;
9757         struct rte_eth_syn_filter syn_filter;
9758         int ret = 0;
9759
9760         ret = rte_eth_dev_filter_supported(res->port_id,
9761                                         RTE_ETH_FILTER_SYN);
9762         if (ret < 0) {
9763                 printf("syn filter is not supported on port %u.\n",
9764                                 res->port_id);
9765                 return;
9766         }
9767
9768         memset(&syn_filter, 0, sizeof(syn_filter));
9769
9770         if (!strcmp(res->ops, "add")) {
9771                 if (!strcmp(res->high, "high"))
9772                         syn_filter.hig_pri = 1;
9773                 else
9774                         syn_filter.hig_pri = 0;
9775
9776                 syn_filter.queue = res->queue_id;
9777                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9778                                                 RTE_ETH_FILTER_SYN,
9779                                                 RTE_ETH_FILTER_ADD,
9780                                                 &syn_filter);
9781         } else
9782                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9783                                                 RTE_ETH_FILTER_SYN,
9784                                                 RTE_ETH_FILTER_DELETE,
9785                                                 &syn_filter);
9786
9787         if (ret < 0)
9788                 printf("syn filter programming error: (%s)\n",
9789                                 strerror(-ret));
9790 }
9791
9792 cmdline_parse_token_string_t cmd_syn_filter_filter =
9793         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9794         filter, "syn_filter");
9795 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9796         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9797         port_id, UINT16);
9798 cmdline_parse_token_string_t cmd_syn_filter_ops =
9799         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9800         ops, "add#del");
9801 cmdline_parse_token_string_t cmd_syn_filter_priority =
9802         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9803                                 priority, "priority");
9804 cmdline_parse_token_string_t cmd_syn_filter_high =
9805         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9806                                 high, "high#low");
9807 cmdline_parse_token_string_t cmd_syn_filter_queue =
9808         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9809                                 queue, "queue");
9810 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9811         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9812                                 queue_id, UINT16);
9813
9814 cmdline_parse_inst_t cmd_syn_filter = {
9815         .f = cmd_syn_filter_parsed,
9816         .data = NULL,
9817         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9818                 "<queue_id>: Add/Delete syn filter",
9819         .tokens = {
9820                 (void *)&cmd_syn_filter_filter,
9821                 (void *)&cmd_syn_filter_port_id,
9822                 (void *)&cmd_syn_filter_ops,
9823                 (void *)&cmd_syn_filter_priority,
9824                 (void *)&cmd_syn_filter_high,
9825                 (void *)&cmd_syn_filter_queue,
9826                 (void *)&cmd_syn_filter_queue_id,
9827                 NULL,
9828         },
9829 };
9830
9831 /* *** queue region set *** */
9832 struct cmd_queue_region_result {
9833         cmdline_fixed_string_t set;
9834         cmdline_fixed_string_t port;
9835         portid_t port_id;
9836         cmdline_fixed_string_t cmd;
9837         cmdline_fixed_string_t region;
9838         uint8_t  region_id;
9839         cmdline_fixed_string_t queue_start_index;
9840         uint8_t  queue_id;
9841         cmdline_fixed_string_t queue_num;
9842         uint8_t  queue_num_value;
9843 };
9844
9845 static void
9846 cmd_queue_region_parsed(void *parsed_result,
9847                         __rte_unused struct cmdline *cl,
9848                         __rte_unused void *data)
9849 {
9850         struct cmd_queue_region_result *res = parsed_result;
9851         int ret = -ENOTSUP;
9852 #ifdef RTE_LIBRTE_I40E_PMD
9853         struct rte_pmd_i40e_queue_region_conf region_conf;
9854         enum rte_pmd_i40e_queue_region_op op_type;
9855 #endif
9856
9857         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9858                 return;
9859
9860 #ifdef RTE_LIBRTE_I40E_PMD
9861         memset(&region_conf, 0, sizeof(region_conf));
9862         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9863         region_conf.region_id = res->region_id;
9864         region_conf.queue_num = res->queue_num_value;
9865         region_conf.queue_start_index = res->queue_id;
9866
9867         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9868                                 op_type, &region_conf);
9869 #endif
9870
9871         switch (ret) {
9872         case 0:
9873                 break;
9874         case -ENOTSUP:
9875                 printf("function not implemented or supported\n");
9876                 break;
9877         default:
9878                 printf("queue region config error: (%s)\n", strerror(-ret));
9879         }
9880 }
9881
9882 cmdline_parse_token_string_t cmd_queue_region_set =
9883 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9884                 set, "set");
9885 cmdline_parse_token_string_t cmd_queue_region_port =
9886         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9887 cmdline_parse_token_num_t cmd_queue_region_port_id =
9888         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9889                                 port_id, UINT16);
9890 cmdline_parse_token_string_t cmd_queue_region_cmd =
9891         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9892                                  cmd, "queue-region");
9893 cmdline_parse_token_string_t cmd_queue_region_id =
9894         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9895                                 region, "region_id");
9896 cmdline_parse_token_num_t cmd_queue_region_index =
9897         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9898                                 region_id, UINT8);
9899 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9900         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9901                                 queue_start_index, "queue_start_index");
9902 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9903         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9904                                 queue_id, UINT8);
9905 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9906         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9907                                 queue_num, "queue_num");
9908 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9909         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9910                                 queue_num_value, UINT8);
9911
9912 cmdline_parse_inst_t cmd_queue_region = {
9913         .f = cmd_queue_region_parsed,
9914         .data = NULL,
9915         .help_str = "set port <port_id> queue-region region_id <value> "
9916                 "queue_start_index <value> queue_num <value>: Set a queue region",
9917         .tokens = {
9918                 (void *)&cmd_queue_region_set,
9919                 (void *)&cmd_queue_region_port,
9920                 (void *)&cmd_queue_region_port_id,
9921                 (void *)&cmd_queue_region_cmd,
9922                 (void *)&cmd_queue_region_id,
9923                 (void *)&cmd_queue_region_index,
9924                 (void *)&cmd_queue_region_queue_start_index,
9925                 (void *)&cmd_queue_region_queue_id,
9926                 (void *)&cmd_queue_region_queue_num,
9927                 (void *)&cmd_queue_region_queue_num_value,
9928                 NULL,
9929         },
9930 };
9931
9932 /* *** queue region and flowtype set *** */
9933 struct cmd_region_flowtype_result {
9934         cmdline_fixed_string_t set;
9935         cmdline_fixed_string_t port;
9936         portid_t port_id;
9937         cmdline_fixed_string_t cmd;
9938         cmdline_fixed_string_t region;
9939         uint8_t  region_id;
9940         cmdline_fixed_string_t flowtype;
9941         uint8_t  flowtype_id;
9942 };
9943
9944 static void
9945 cmd_region_flowtype_parsed(void *parsed_result,
9946                         __rte_unused struct cmdline *cl,
9947                         __rte_unused void *data)
9948 {
9949         struct cmd_region_flowtype_result *res = parsed_result;
9950         int ret = -ENOTSUP;
9951 #ifdef RTE_LIBRTE_I40E_PMD
9952         struct rte_pmd_i40e_queue_region_conf region_conf;
9953         enum rte_pmd_i40e_queue_region_op op_type;
9954 #endif
9955
9956         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9957                 return;
9958
9959 #ifdef RTE_LIBRTE_I40E_PMD
9960         memset(&region_conf, 0, sizeof(region_conf));
9961
9962         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9963         region_conf.region_id = res->region_id;
9964         region_conf.hw_flowtype = res->flowtype_id;
9965
9966         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9967                         op_type, &region_conf);
9968 #endif
9969
9970         switch (ret) {
9971         case 0:
9972                 break;
9973         case -ENOTSUP:
9974                 printf("function not implemented or supported\n");
9975                 break;
9976         default:
9977                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9978         }
9979 }
9980
9981 cmdline_parse_token_string_t cmd_region_flowtype_set =
9982 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9983                                 set, "set");
9984 cmdline_parse_token_string_t cmd_region_flowtype_port =
9985         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9986                                 port, "port");
9987 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9988         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9989                                 port_id, UINT16);
9990 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9991         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9992                                 cmd, "queue-region");
9993 cmdline_parse_token_string_t cmd_region_flowtype_index =
9994         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9995                                 region, "region_id");
9996 cmdline_parse_token_num_t cmd_region_flowtype_id =
9997         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9998                                 region_id, UINT8);
9999 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10000         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10001                                 flowtype, "flowtype");
10002 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10003         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10004                                 flowtype_id, UINT8);
10005 cmdline_parse_inst_t cmd_region_flowtype = {
10006         .f = cmd_region_flowtype_parsed,
10007         .data = NULL,
10008         .help_str = "set port <port_id> queue-region region_id <value> "
10009                 "flowtype <value>: Set a flowtype region index",
10010         .tokens = {
10011                 (void *)&cmd_region_flowtype_set,
10012                 (void *)&cmd_region_flowtype_port,
10013                 (void *)&cmd_region_flowtype_port_index,
10014                 (void *)&cmd_region_flowtype_cmd,
10015                 (void *)&cmd_region_flowtype_index,
10016                 (void *)&cmd_region_flowtype_id,
10017                 (void *)&cmd_region_flowtype_flow_index,
10018                 (void *)&cmd_region_flowtype_flow_id,
10019                 NULL,
10020         },
10021 };
10022
10023 /* *** User Priority (UP) to queue region (region_id) set *** */
10024 struct cmd_user_priority_region_result {
10025         cmdline_fixed_string_t set;
10026         cmdline_fixed_string_t port;
10027         portid_t port_id;
10028         cmdline_fixed_string_t cmd;
10029         cmdline_fixed_string_t user_priority;
10030         uint8_t  user_priority_id;
10031         cmdline_fixed_string_t region;
10032         uint8_t  region_id;
10033 };
10034
10035 static void
10036 cmd_user_priority_region_parsed(void *parsed_result,
10037                         __rte_unused struct cmdline *cl,
10038                         __rte_unused void *data)
10039 {
10040         struct cmd_user_priority_region_result *res = parsed_result;
10041         int ret = -ENOTSUP;
10042 #ifdef RTE_LIBRTE_I40E_PMD
10043         struct rte_pmd_i40e_queue_region_conf region_conf;
10044         enum rte_pmd_i40e_queue_region_op op_type;
10045 #endif
10046
10047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10048                 return;
10049
10050 #ifdef RTE_LIBRTE_I40E_PMD
10051         memset(&region_conf, 0, sizeof(region_conf));
10052         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10053         region_conf.user_priority = res->user_priority_id;
10054         region_conf.region_id = res->region_id;
10055
10056         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10057                                 op_type, &region_conf);
10058 #endif
10059
10060         switch (ret) {
10061         case 0:
10062                 break;
10063         case -ENOTSUP:
10064                 printf("function not implemented or supported\n");
10065                 break;
10066         default:
10067                 printf("user_priority region config error: (%s)\n",
10068                                 strerror(-ret));
10069         }
10070 }
10071
10072 cmdline_parse_token_string_t cmd_user_priority_region_set =
10073         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10074                                 set, "set");
10075 cmdline_parse_token_string_t cmd_user_priority_region_port =
10076         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10077                                 port, "port");
10078 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10079         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10080                                 port_id, UINT16);
10081 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10082         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10083                                 cmd, "queue-region");
10084 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10085         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10086                                 user_priority, "UP");
10087 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10088         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10089                                 user_priority_id, UINT8);
10090 cmdline_parse_token_string_t cmd_user_priority_region_region =
10091         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10092                                 region, "region_id");
10093 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10094         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10095                                 region_id, UINT8);
10096
10097 cmdline_parse_inst_t cmd_user_priority_region = {
10098         .f = cmd_user_priority_region_parsed,
10099         .data = NULL,
10100         .help_str = "set port <port_id> queue-region UP <value> "
10101                 "region_id <value>: Set the mapping of User Priority (UP) "
10102                 "to queue region (region_id) ",
10103         .tokens = {
10104                 (void *)&cmd_user_priority_region_set,
10105                 (void *)&cmd_user_priority_region_port,
10106                 (void *)&cmd_user_priority_region_port_index,
10107                 (void *)&cmd_user_priority_region_cmd,
10108                 (void *)&cmd_user_priority_region_UP,
10109                 (void *)&cmd_user_priority_region_UP_id,
10110                 (void *)&cmd_user_priority_region_region,
10111                 (void *)&cmd_user_priority_region_region_id,
10112                 NULL,
10113         },
10114 };
10115
10116 /* *** flush all queue region related configuration *** */
10117 struct cmd_flush_queue_region_result {
10118         cmdline_fixed_string_t set;
10119         cmdline_fixed_string_t port;
10120         portid_t port_id;
10121         cmdline_fixed_string_t cmd;
10122         cmdline_fixed_string_t flush;
10123         cmdline_fixed_string_t what;
10124 };
10125
10126 static void
10127 cmd_flush_queue_region_parsed(void *parsed_result,
10128                         __rte_unused struct cmdline *cl,
10129                         __rte_unused void *data)
10130 {
10131         struct cmd_flush_queue_region_result *res = parsed_result;
10132         int ret = -ENOTSUP;
10133 #ifdef RTE_LIBRTE_I40E_PMD
10134         struct rte_pmd_i40e_queue_region_conf region_conf;
10135         enum rte_pmd_i40e_queue_region_op op_type;
10136 #endif
10137
10138         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10139                 return;
10140
10141 #ifdef RTE_LIBRTE_I40E_PMD
10142         memset(&region_conf, 0, sizeof(region_conf));
10143
10144         if (strcmp(res->what, "on") == 0)
10145                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10146         else
10147                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10148
10149         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10150                                 op_type, &region_conf);
10151 #endif
10152
10153         switch (ret) {
10154         case 0:
10155                 break;
10156         case -ENOTSUP:
10157                 printf("function not implemented or supported\n");
10158                 break;
10159         default:
10160                 printf("queue region config flush error: (%s)\n",
10161                                 strerror(-ret));
10162         }
10163 }
10164
10165 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10166         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10167                                 set, "set");
10168 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10169         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10170                                 port, "port");
10171 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10172         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10173                                 port_id, UINT16);
10174 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10175         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10176                                 cmd, "queue-region");
10177 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10178         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10179                                 flush, "flush");
10180 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10181         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10182                                 what, "on#off");
10183
10184 cmdline_parse_inst_t cmd_flush_queue_region = {
10185         .f = cmd_flush_queue_region_parsed,
10186         .data = NULL,
10187         .help_str = "set port <port_id> queue-region flush on|off"
10188                 ": flush all queue region related configuration",
10189         .tokens = {
10190                 (void *)&cmd_flush_queue_region_set,
10191                 (void *)&cmd_flush_queue_region_port,
10192                 (void *)&cmd_flush_queue_region_port_index,
10193                 (void *)&cmd_flush_queue_region_cmd,
10194                 (void *)&cmd_flush_queue_region_flush,
10195                 (void *)&cmd_flush_queue_region_what,
10196                 NULL,
10197         },
10198 };
10199
10200 /* *** get all queue region related configuration info *** */
10201 struct cmd_show_queue_region_info {
10202         cmdline_fixed_string_t show;
10203         cmdline_fixed_string_t port;
10204         portid_t port_id;
10205         cmdline_fixed_string_t cmd;
10206 };
10207
10208 static void
10209 cmd_show_queue_region_info_parsed(void *parsed_result,
10210                         __rte_unused struct cmdline *cl,
10211                         __rte_unused void *data)
10212 {
10213         struct cmd_show_queue_region_info *res = parsed_result;
10214         int ret = -ENOTSUP;
10215 #ifdef RTE_LIBRTE_I40E_PMD
10216         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10217         enum rte_pmd_i40e_queue_region_op op_type;
10218 #endif
10219
10220         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10221                 return;
10222
10223 #ifdef RTE_LIBRTE_I40E_PMD
10224         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10225
10226         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10227
10228         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10229                                         op_type, &rte_pmd_regions);
10230
10231         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10232 #endif
10233
10234         switch (ret) {
10235         case 0:
10236                 break;
10237         case -ENOTSUP:
10238                 printf("function not implemented or supported\n");
10239                 break;
10240         default:
10241                 printf("queue region config info show error: (%s)\n",
10242                                 strerror(-ret));
10243         }
10244 }
10245
10246 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10247 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10248                                 show, "show");
10249 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10250         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10251                                 port, "port");
10252 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10253         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10254                                 port_id, UINT16);
10255 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10256         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10257                                 cmd, "queue-region");
10258
10259 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10260         .f = cmd_show_queue_region_info_parsed,
10261         .data = NULL,
10262         .help_str = "show port <port_id> queue-region"
10263                 ": show all queue region related configuration info",
10264         .tokens = {
10265                 (void *)&cmd_show_queue_region_info_get,
10266                 (void *)&cmd_show_queue_region_info_port,
10267                 (void *)&cmd_show_queue_region_info_port_index,
10268                 (void *)&cmd_show_queue_region_info_cmd,
10269                 NULL,
10270         },
10271 };
10272
10273 /* *** ADD/REMOVE A 2tuple FILTER *** */
10274 struct cmd_2tuple_filter_result {
10275         cmdline_fixed_string_t filter;
10276         portid_t port_id;
10277         cmdline_fixed_string_t ops;
10278         cmdline_fixed_string_t dst_port;
10279         uint16_t dst_port_value;
10280         cmdline_fixed_string_t protocol;
10281         uint8_t protocol_value;
10282         cmdline_fixed_string_t mask;
10283         uint8_t  mask_value;
10284         cmdline_fixed_string_t tcp_flags;
10285         uint8_t tcp_flags_value;
10286         cmdline_fixed_string_t priority;
10287         uint8_t  priority_value;
10288         cmdline_fixed_string_t queue;
10289         uint16_t  queue_id;
10290 };
10291
10292 static void
10293 cmd_2tuple_filter_parsed(void *parsed_result,
10294                         __rte_unused struct cmdline *cl,
10295                         __rte_unused void *data)
10296 {
10297         struct rte_eth_ntuple_filter filter;
10298         struct cmd_2tuple_filter_result *res = parsed_result;
10299         int ret = 0;
10300
10301         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10302         if (ret < 0) {
10303                 printf("ntuple filter is not supported on port %u.\n",
10304                         res->port_id);
10305                 return;
10306         }
10307
10308         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10309
10310         filter.flags = RTE_2TUPLE_FLAGS;
10311         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10312         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10313         filter.proto = res->protocol_value;
10314         filter.priority = res->priority_value;
10315         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10316                 printf("nonzero tcp_flags is only meaningful"
10317                         " when protocol is TCP.\n");
10318                 return;
10319         }
10320         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10321                 printf("invalid TCP flags.\n");
10322                 return;
10323         }
10324
10325         if (res->tcp_flags_value != 0) {
10326                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10327                 filter.tcp_flags = res->tcp_flags_value;
10328         }
10329
10330         /* need convert to big endian. */
10331         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10332         filter.queue = res->queue_id;
10333
10334         if (!strcmp(res->ops, "add"))
10335                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10336                                 RTE_ETH_FILTER_NTUPLE,
10337                                 RTE_ETH_FILTER_ADD,
10338                                 &filter);
10339         else
10340                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10341                                 RTE_ETH_FILTER_NTUPLE,
10342                                 RTE_ETH_FILTER_DELETE,
10343                                 &filter);
10344         if (ret < 0)
10345                 printf("2tuple filter programming error: (%s)\n",
10346                         strerror(-ret));
10347
10348 }
10349
10350 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10351         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10352                                  filter, "2tuple_filter");
10353 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10354         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10355                                 port_id, UINT16);
10356 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10357         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10358                                  ops, "add#del");
10359 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10360         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10361                                 dst_port, "dst_port");
10362 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10363         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10364                                 dst_port_value, UINT16);
10365 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10366         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10367                                 protocol, "protocol");
10368 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10369         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10370                                 protocol_value, UINT8);
10371 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10372         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10373                                 mask, "mask");
10374 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10375         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10376                                 mask_value, INT8);
10377 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10378         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10379                                 tcp_flags, "tcp_flags");
10380 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10381         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10382                                 tcp_flags_value, UINT8);
10383 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10384         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10385                                 priority, "priority");
10386 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10387         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10388                                 priority_value, UINT8);
10389 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10390         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10391                                 queue, "queue");
10392 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10393         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10394                                 queue_id, UINT16);
10395
10396 cmdline_parse_inst_t cmd_2tuple_filter = {
10397         .f = cmd_2tuple_filter_parsed,
10398         .data = NULL,
10399         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10400                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10401                 "<queue_id>: Add a 2tuple filter",
10402         .tokens = {
10403                 (void *)&cmd_2tuple_filter_filter,
10404                 (void *)&cmd_2tuple_filter_port_id,
10405                 (void *)&cmd_2tuple_filter_ops,
10406                 (void *)&cmd_2tuple_filter_dst_port,
10407                 (void *)&cmd_2tuple_filter_dst_port_value,
10408                 (void *)&cmd_2tuple_filter_protocol,
10409                 (void *)&cmd_2tuple_filter_protocol_value,
10410                 (void *)&cmd_2tuple_filter_mask,
10411                 (void *)&cmd_2tuple_filter_mask_value,
10412                 (void *)&cmd_2tuple_filter_tcp_flags,
10413                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10414                 (void *)&cmd_2tuple_filter_priority,
10415                 (void *)&cmd_2tuple_filter_priority_value,
10416                 (void *)&cmd_2tuple_filter_queue,
10417                 (void *)&cmd_2tuple_filter_queue_id,
10418                 NULL,
10419         },
10420 };
10421
10422 /* *** ADD/REMOVE A 5tuple FILTER *** */
10423 struct cmd_5tuple_filter_result {
10424         cmdline_fixed_string_t filter;
10425         portid_t port_id;
10426         cmdline_fixed_string_t ops;
10427         cmdline_fixed_string_t dst_ip;
10428         cmdline_ipaddr_t dst_ip_value;
10429         cmdline_fixed_string_t src_ip;
10430         cmdline_ipaddr_t src_ip_value;
10431         cmdline_fixed_string_t dst_port;
10432         uint16_t dst_port_value;
10433         cmdline_fixed_string_t src_port;
10434         uint16_t src_port_value;
10435         cmdline_fixed_string_t protocol;
10436         uint8_t protocol_value;
10437         cmdline_fixed_string_t mask;
10438         uint8_t  mask_value;
10439         cmdline_fixed_string_t tcp_flags;
10440         uint8_t tcp_flags_value;
10441         cmdline_fixed_string_t priority;
10442         uint8_t  priority_value;
10443         cmdline_fixed_string_t queue;
10444         uint16_t  queue_id;
10445 };
10446
10447 static void
10448 cmd_5tuple_filter_parsed(void *parsed_result,
10449                         __rte_unused struct cmdline *cl,
10450                         __rte_unused void *data)
10451 {
10452         struct rte_eth_ntuple_filter filter;
10453         struct cmd_5tuple_filter_result *res = parsed_result;
10454         int ret = 0;
10455
10456         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10457         if (ret < 0) {
10458                 printf("ntuple filter is not supported on port %u.\n",
10459                         res->port_id);
10460                 return;
10461         }
10462
10463         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10464
10465         filter.flags = RTE_5TUPLE_FLAGS;
10466         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10467         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10468         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10469         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10470         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10471         filter.proto = res->protocol_value;
10472         filter.priority = res->priority_value;
10473         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10474                 printf("nonzero tcp_flags is only meaningful"
10475                         " when protocol is TCP.\n");
10476                 return;
10477         }
10478         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10479                 printf("invalid TCP flags.\n");
10480                 return;
10481         }
10482
10483         if (res->tcp_flags_value != 0) {
10484                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10485                 filter.tcp_flags = res->tcp_flags_value;
10486         }
10487
10488         if (res->dst_ip_value.family == AF_INET)
10489                 /* no need to convert, already big endian. */
10490                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10491         else {
10492                 if (filter.dst_ip_mask == 0) {
10493                         printf("can not support ipv6 involved compare.\n");
10494                         return;
10495                 }
10496                 filter.dst_ip = 0;
10497         }
10498
10499         if (res->src_ip_value.family == AF_INET)
10500                 /* no need to convert, already big endian. */
10501                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10502         else {
10503                 if (filter.src_ip_mask == 0) {
10504                         printf("can not support ipv6 involved compare.\n");
10505                         return;
10506                 }
10507                 filter.src_ip = 0;
10508         }
10509         /* need convert to big endian. */
10510         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10511         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10512         filter.queue = res->queue_id;
10513
10514         if (!strcmp(res->ops, "add"))
10515                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10516                                 RTE_ETH_FILTER_NTUPLE,
10517                                 RTE_ETH_FILTER_ADD,
10518                                 &filter);
10519         else
10520                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10521                                 RTE_ETH_FILTER_NTUPLE,
10522                                 RTE_ETH_FILTER_DELETE,
10523                                 &filter);
10524         if (ret < 0)
10525                 printf("5tuple filter programming error: (%s)\n",
10526                         strerror(-ret));
10527 }
10528
10529 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10530         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10531                                  filter, "5tuple_filter");
10532 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10533         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10534                                 port_id, UINT16);
10535 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10536         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10537                                  ops, "add#del");
10538 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10539         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10540                                 dst_ip, "dst_ip");
10541 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10542         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10543                                 dst_ip_value);
10544 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10545         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10546                                 src_ip, "src_ip");
10547 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10548         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10549                                 src_ip_value);
10550 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10551         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10552                                 dst_port, "dst_port");
10553 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10554         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10555                                 dst_port_value, UINT16);
10556 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10557         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10558                                 src_port, "src_port");
10559 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10560         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10561                                 src_port_value, UINT16);
10562 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10563         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10564                                 protocol, "protocol");
10565 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10566         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10567                                 protocol_value, UINT8);
10568 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10569         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10570                                 mask, "mask");
10571 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10572         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10573                                 mask_value, INT8);
10574 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10575         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10576                                 tcp_flags, "tcp_flags");
10577 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10578         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10579                                 tcp_flags_value, UINT8);
10580 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10581         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10582                                 priority, "priority");
10583 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10584         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10585                                 priority_value, UINT8);
10586 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10587         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10588                                 queue, "queue");
10589 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10590         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10591                                 queue_id, UINT16);
10592
10593 cmdline_parse_inst_t cmd_5tuple_filter = {
10594         .f = cmd_5tuple_filter_parsed,
10595         .data = NULL,
10596         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10597                 "src_ip <value> dst_port <value> src_port <value> "
10598                 "protocol <value>  mask <value> tcp_flags <value> "
10599                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10600         .tokens = {
10601                 (void *)&cmd_5tuple_filter_filter,
10602                 (void *)&cmd_5tuple_filter_port_id,
10603                 (void *)&cmd_5tuple_filter_ops,
10604                 (void *)&cmd_5tuple_filter_dst_ip,
10605                 (void *)&cmd_5tuple_filter_dst_ip_value,
10606                 (void *)&cmd_5tuple_filter_src_ip,
10607                 (void *)&cmd_5tuple_filter_src_ip_value,
10608                 (void *)&cmd_5tuple_filter_dst_port,
10609                 (void *)&cmd_5tuple_filter_dst_port_value,
10610                 (void *)&cmd_5tuple_filter_src_port,
10611                 (void *)&cmd_5tuple_filter_src_port_value,
10612                 (void *)&cmd_5tuple_filter_protocol,
10613                 (void *)&cmd_5tuple_filter_protocol_value,
10614                 (void *)&cmd_5tuple_filter_mask,
10615                 (void *)&cmd_5tuple_filter_mask_value,
10616                 (void *)&cmd_5tuple_filter_tcp_flags,
10617                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10618                 (void *)&cmd_5tuple_filter_priority,
10619                 (void *)&cmd_5tuple_filter_priority_value,
10620                 (void *)&cmd_5tuple_filter_queue,
10621                 (void *)&cmd_5tuple_filter_queue_id,
10622                 NULL,
10623         },
10624 };
10625
10626 /* *** ADD/REMOVE A flex FILTER *** */
10627 struct cmd_flex_filter_result {
10628         cmdline_fixed_string_t filter;
10629         cmdline_fixed_string_t ops;
10630         portid_t port_id;
10631         cmdline_fixed_string_t len;
10632         uint8_t len_value;
10633         cmdline_fixed_string_t bytes;
10634         cmdline_fixed_string_t bytes_value;
10635         cmdline_fixed_string_t mask;
10636         cmdline_fixed_string_t mask_value;
10637         cmdline_fixed_string_t priority;
10638         uint8_t priority_value;
10639         cmdline_fixed_string_t queue;
10640         uint16_t queue_id;
10641 };
10642
10643 static int xdigit2val(unsigned char c)
10644 {
10645         int val;
10646         if (isdigit(c))
10647                 val = c - '0';
10648         else if (isupper(c))
10649                 val = c - 'A' + 10;
10650         else
10651                 val = c - 'a' + 10;
10652         return val;
10653 }
10654
10655 static void
10656 cmd_flex_filter_parsed(void *parsed_result,
10657                           __rte_unused struct cmdline *cl,
10658                           __rte_unused void *data)
10659 {
10660         int ret = 0;
10661         struct rte_eth_flex_filter filter;
10662         struct cmd_flex_filter_result *res = parsed_result;
10663         char *bytes_ptr, *mask_ptr;
10664         uint16_t len, i, j = 0;
10665         char c;
10666         int val;
10667         uint8_t byte = 0;
10668
10669         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10670                 printf("the len exceed the max length 128\n");
10671                 return;
10672         }
10673         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10674         filter.len = res->len_value;
10675         filter.priority = res->priority_value;
10676         filter.queue = res->queue_id;
10677         bytes_ptr = res->bytes_value;
10678         mask_ptr = res->mask_value;
10679
10680          /* translate bytes string to array. */
10681         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10682                 (bytes_ptr[1] == 'X')))
10683                 bytes_ptr += 2;
10684         len = strnlen(bytes_ptr, res->len_value * 2);
10685         if (len == 0 || (len % 8 != 0)) {
10686                 printf("please check len and bytes input\n");
10687                 return;
10688         }
10689         for (i = 0; i < len; i++) {
10690                 c = bytes_ptr[i];
10691                 if (isxdigit(c) == 0) {
10692                         /* invalid characters. */
10693                         printf("invalid input\n");
10694                         return;
10695                 }
10696                 val = xdigit2val(c);
10697                 if (i % 2) {
10698                         byte |= val;
10699                         filter.bytes[j] = byte;
10700                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10701                         j++;
10702                         byte = 0;
10703                 } else
10704                         byte |= val << 4;
10705         }
10706         printf("\n");
10707          /* translate mask string to uint8_t array. */
10708         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10709                 (mask_ptr[1] == 'X')))
10710                 mask_ptr += 2;
10711         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10712         if (len == 0) {
10713                 printf("invalid input\n");
10714                 return;
10715         }
10716         j = 0;
10717         byte = 0;
10718         for (i = 0; i < len; i++) {
10719                 c = mask_ptr[i];
10720                 if (isxdigit(c) == 0) {
10721                         /* invalid characters. */
10722                         printf("invalid input\n");
10723                         return;
10724                 }
10725                 val = xdigit2val(c);
10726                 if (i % 2) {
10727                         byte |= val;
10728                         filter.mask[j] = byte;
10729                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10730                         j++;
10731                         byte = 0;
10732                 } else
10733                         byte |= val << 4;
10734         }
10735         printf("\n");
10736
10737         if (!strcmp(res->ops, "add"))
10738                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10739                                 RTE_ETH_FILTER_FLEXIBLE,
10740                                 RTE_ETH_FILTER_ADD,
10741                                 &filter);
10742         else
10743                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10744                                 RTE_ETH_FILTER_FLEXIBLE,
10745                                 RTE_ETH_FILTER_DELETE,
10746                                 &filter);
10747
10748         if (ret < 0)
10749                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10750 }
10751
10752 cmdline_parse_token_string_t cmd_flex_filter_filter =
10753         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10754                                 filter, "flex_filter");
10755 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10756         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10757                                 port_id, UINT16);
10758 cmdline_parse_token_string_t cmd_flex_filter_ops =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10760                                 ops, "add#del");
10761 cmdline_parse_token_string_t cmd_flex_filter_len =
10762         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10763                                 len, "len");
10764 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10765         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10766                                 len_value, UINT8);
10767 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10768         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10769                                 bytes, "bytes");
10770 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10772                                 bytes_value, NULL);
10773 cmdline_parse_token_string_t cmd_flex_filter_mask =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10775                                 mask, "mask");
10776 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10778                                 mask_value, NULL);
10779 cmdline_parse_token_string_t cmd_flex_filter_priority =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10781                                 priority, "priority");
10782 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10783         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10784                                 priority_value, UINT8);
10785 cmdline_parse_token_string_t cmd_flex_filter_queue =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10787                                 queue, "queue");
10788 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10789         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10790                                 queue_id, UINT16);
10791 cmdline_parse_inst_t cmd_flex_filter = {
10792         .f = cmd_flex_filter_parsed,
10793         .data = NULL,
10794         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10795                 "<value> mask <value> priority <value> queue <queue_id>: "
10796                 "Add/Del a flex filter",
10797         .tokens = {
10798                 (void *)&cmd_flex_filter_filter,
10799                 (void *)&cmd_flex_filter_port_id,
10800                 (void *)&cmd_flex_filter_ops,
10801                 (void *)&cmd_flex_filter_len,
10802                 (void *)&cmd_flex_filter_len_value,
10803                 (void *)&cmd_flex_filter_bytes,
10804                 (void *)&cmd_flex_filter_bytes_value,
10805                 (void *)&cmd_flex_filter_mask,
10806                 (void *)&cmd_flex_filter_mask_value,
10807                 (void *)&cmd_flex_filter_priority,
10808                 (void *)&cmd_flex_filter_priority_value,
10809                 (void *)&cmd_flex_filter_queue,
10810                 (void *)&cmd_flex_filter_queue_id,
10811                 NULL,
10812         },
10813 };
10814
10815 /* *** Filters Control *** */
10816
10817 /* *** deal with ethertype filter *** */
10818 struct cmd_ethertype_filter_result {
10819         cmdline_fixed_string_t filter;
10820         portid_t port_id;
10821         cmdline_fixed_string_t ops;
10822         cmdline_fixed_string_t mac;
10823         struct rte_ether_addr mac_addr;
10824         cmdline_fixed_string_t ethertype;
10825         uint16_t ethertype_value;
10826         cmdline_fixed_string_t drop;
10827         cmdline_fixed_string_t queue;
10828         uint16_t  queue_id;
10829 };
10830
10831 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10832         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10833                                  filter, "ethertype_filter");
10834 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10835         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10836                               port_id, UINT16);
10837 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10838         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10839                                  ops, "add#del");
10840 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10841         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10842                                  mac, "mac_addr#mac_ignr");
10843 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10844         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10845                                      mac_addr);
10846 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10847         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10848                                  ethertype, "ethertype");
10849 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10850         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10851                               ethertype_value, UINT16);
10852 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10853         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10854                                  drop, "drop#fwd");
10855 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10856         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10857                                  queue, "queue");
10858 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10859         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10860                               queue_id, UINT16);
10861
10862 static void
10863 cmd_ethertype_filter_parsed(void *parsed_result,
10864                           __rte_unused struct cmdline *cl,
10865                           __rte_unused void *data)
10866 {
10867         struct cmd_ethertype_filter_result *res = parsed_result;
10868         struct rte_eth_ethertype_filter filter;
10869         int ret = 0;
10870
10871         ret = rte_eth_dev_filter_supported(res->port_id,
10872                         RTE_ETH_FILTER_ETHERTYPE);
10873         if (ret < 0) {
10874                 printf("ethertype filter is not supported on port %u.\n",
10875                         res->port_id);
10876                 return;
10877         }
10878
10879         memset(&filter, 0, sizeof(filter));
10880         if (!strcmp(res->mac, "mac_addr")) {
10881                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10882                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10883                         sizeof(struct rte_ether_addr));
10884         }
10885         if (!strcmp(res->drop, "drop"))
10886                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10887         filter.ether_type = res->ethertype_value;
10888         filter.queue = res->queue_id;
10889
10890         if (!strcmp(res->ops, "add"))
10891                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10892                                 RTE_ETH_FILTER_ETHERTYPE,
10893                                 RTE_ETH_FILTER_ADD,
10894                                 &filter);
10895         else
10896                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10897                                 RTE_ETH_FILTER_ETHERTYPE,
10898                                 RTE_ETH_FILTER_DELETE,
10899                                 &filter);
10900         if (ret < 0)
10901                 printf("ethertype filter programming error: (%s)\n",
10902                         strerror(-ret));
10903 }
10904
10905 cmdline_parse_inst_t cmd_ethertype_filter = {
10906         .f = cmd_ethertype_filter_parsed,
10907         .data = NULL,
10908         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10909                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10910                 "Add or delete an ethertype filter entry",
10911         .tokens = {
10912                 (void *)&cmd_ethertype_filter_filter,
10913                 (void *)&cmd_ethertype_filter_port_id,
10914                 (void *)&cmd_ethertype_filter_ops,
10915                 (void *)&cmd_ethertype_filter_mac,
10916                 (void *)&cmd_ethertype_filter_mac_addr,
10917                 (void *)&cmd_ethertype_filter_ethertype,
10918                 (void *)&cmd_ethertype_filter_ethertype_value,
10919                 (void *)&cmd_ethertype_filter_drop,
10920                 (void *)&cmd_ethertype_filter_queue,
10921                 (void *)&cmd_ethertype_filter_queue_id,
10922                 NULL,
10923         },
10924 };
10925
10926 /* *** deal with flow director filter *** */
10927 struct cmd_flow_director_result {
10928         cmdline_fixed_string_t flow_director_filter;
10929         portid_t port_id;
10930         cmdline_fixed_string_t mode;
10931         cmdline_fixed_string_t mode_value;
10932         cmdline_fixed_string_t ops;
10933         cmdline_fixed_string_t flow;
10934         cmdline_fixed_string_t flow_type;
10935         cmdline_fixed_string_t ether;
10936         uint16_t ether_type;
10937         cmdline_fixed_string_t src;
10938         cmdline_ipaddr_t ip_src;
10939         uint16_t port_src;
10940         cmdline_fixed_string_t dst;
10941         cmdline_ipaddr_t ip_dst;
10942         uint16_t port_dst;
10943         cmdline_fixed_string_t verify_tag;
10944         uint32_t verify_tag_value;
10945         cmdline_fixed_string_t tos;
10946         uint8_t tos_value;
10947         cmdline_fixed_string_t proto;
10948         uint8_t proto_value;
10949         cmdline_fixed_string_t ttl;
10950         uint8_t ttl_value;
10951         cmdline_fixed_string_t vlan;
10952         uint16_t vlan_value;
10953         cmdline_fixed_string_t flexbytes;
10954         cmdline_fixed_string_t flexbytes_value;
10955         cmdline_fixed_string_t pf_vf;
10956         cmdline_fixed_string_t drop;
10957         cmdline_fixed_string_t queue;
10958         uint16_t  queue_id;
10959         cmdline_fixed_string_t fd_id;
10960         uint32_t  fd_id_value;
10961         cmdline_fixed_string_t mac;
10962         struct rte_ether_addr mac_addr;
10963         cmdline_fixed_string_t tunnel;
10964         cmdline_fixed_string_t tunnel_type;
10965         cmdline_fixed_string_t tunnel_id;
10966         uint32_t tunnel_id_value;
10967         cmdline_fixed_string_t packet;
10968         char filepath[];
10969 };
10970
10971 static inline int
10972 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10973 {
10974         char s[256];
10975         const char *p, *p0 = q_arg;
10976         char *end;
10977         unsigned long int_fld;
10978         char *str_fld[max_num];
10979         int i;
10980         unsigned size;
10981         int ret = -1;
10982
10983         p = strchr(p0, '(');
10984         if (p == NULL)
10985                 return -1;
10986         ++p;
10987         p0 = strchr(p, ')');
10988         if (p0 == NULL)
10989                 return -1;
10990
10991         size = p0 - p;
10992         if (size >= sizeof(s))
10993                 return -1;
10994
10995         snprintf(s, sizeof(s), "%.*s", size, p);
10996         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10997         if (ret < 0 || ret > max_num)
10998                 return -1;
10999         for (i = 0; i < ret; i++) {
11000                 errno = 0;
11001                 int_fld = strtoul(str_fld[i], &end, 0);
11002                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11003                         return -1;
11004                 flexbytes[i] = (uint8_t)int_fld;
11005         }
11006         return ret;
11007 }
11008
11009 static uint16_t
11010 str2flowtype(char *string)
11011 {
11012         uint8_t i = 0;
11013         static const struct {
11014                 char str[32];
11015                 uint16_t type;
11016         } flowtype_str[] = {
11017                 {"raw", RTE_ETH_FLOW_RAW},
11018                 {"ipv4", RTE_ETH_FLOW_IPV4},
11019                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11020                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11021                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11022                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11023                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11024                 {"ipv6", RTE_ETH_FLOW_IPV6},
11025                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11026                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11027                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11028                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11029                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11030                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11031         };
11032
11033         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11034                 if (!strcmp(flowtype_str[i].str, string))
11035                         return flowtype_str[i].type;
11036         }
11037
11038         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11039                 return (uint16_t)atoi(string);
11040
11041         return RTE_ETH_FLOW_UNKNOWN;
11042 }
11043
11044 static enum rte_eth_fdir_tunnel_type
11045 str2fdir_tunneltype(char *string)
11046 {
11047         uint8_t i = 0;
11048
11049         static const struct {
11050                 char str[32];
11051                 enum rte_eth_fdir_tunnel_type type;
11052         } tunneltype_str[] = {
11053                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11054                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11055         };
11056
11057         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11058                 if (!strcmp(tunneltype_str[i].str, string))
11059                         return tunneltype_str[i].type;
11060         }
11061         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11062 }
11063
11064 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11065 do { \
11066         if ((ip_addr).family == AF_INET) \
11067                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11068         else { \
11069                 printf("invalid parameter.\n"); \
11070                 return; \
11071         } \
11072 } while (0)
11073
11074 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11075 do { \
11076         if ((ip_addr).family == AF_INET6) \
11077                 rte_memcpy(&(ip), \
11078                                  &((ip_addr).addr.ipv6), \
11079                                  sizeof(struct in6_addr)); \
11080         else { \
11081                 printf("invalid parameter.\n"); \
11082                 return; \
11083         } \
11084 } while (0)
11085
11086 static void
11087 cmd_flow_director_filter_parsed(void *parsed_result,
11088                           __rte_unused struct cmdline *cl,
11089                           __rte_unused void *data)
11090 {
11091         struct cmd_flow_director_result *res = parsed_result;
11092         struct rte_eth_fdir_filter entry;
11093         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11094         char *end;
11095         unsigned long vf_id;
11096         int ret = 0;
11097
11098         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11099         if (ret < 0) {
11100                 printf("flow director is not supported on port %u.\n",
11101                         res->port_id);
11102                 return;
11103         }
11104         memset(flexbytes, 0, sizeof(flexbytes));
11105         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11106
11107         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11108                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11109                         printf("Please set mode to MAC-VLAN.\n");
11110                         return;
11111                 }
11112         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11113                 if (strcmp(res->mode_value, "Tunnel")) {
11114                         printf("Please set mode to Tunnel.\n");
11115                         return;
11116                 }
11117         } else {
11118                 if (!strcmp(res->mode_value, "raw")) {
11119 #ifdef RTE_LIBRTE_I40E_PMD
11120                         struct rte_pmd_i40e_flow_type_mapping
11121                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11122                         struct rte_pmd_i40e_pkt_template_conf conf;
11123                         uint16_t flow_type = str2flowtype(res->flow_type);
11124                         uint16_t i, port = res->port_id;
11125                         uint8_t add;
11126
11127                         memset(&conf, 0, sizeof(conf));
11128
11129                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11130                                 printf("Invalid flow type specified.\n");
11131                                 return;
11132                         }
11133                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11134                                                                  mapping);
11135                         if (ret)
11136                                 return;
11137                         if (mapping[flow_type].pctype == 0ULL) {
11138                                 printf("Invalid flow type specified.\n");
11139                                 return;
11140                         }
11141                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11142                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11143                                         conf.input.pctype = i;
11144                                         break;
11145                                 }
11146                         }
11147
11148                         conf.input.packet = open_file(res->filepath,
11149                                                 &conf.input.length);
11150                         if (!conf.input.packet)
11151                                 return;
11152                         if (!strcmp(res->drop, "drop"))
11153                                 conf.action.behavior =
11154                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11155                         else
11156                                 conf.action.behavior =
11157                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11158                         conf.action.report_status =
11159                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11160                         conf.action.rx_queue = res->queue_id;
11161                         conf.soft_id = res->fd_id_value;
11162                         add  = strcmp(res->ops, "del") ? 1 : 0;
11163                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11164                                                                         &conf,
11165                                                                         add);
11166                         if (ret < 0)
11167                                 printf("flow director config error: (%s)\n",
11168                                        strerror(-ret));
11169                         close_file(conf.input.packet);
11170 #endif
11171                         return;
11172                 } else if (strcmp(res->mode_value, "IP")) {
11173                         printf("Please set mode to IP or raw.\n");
11174                         return;
11175                 }
11176                 entry.input.flow_type = str2flowtype(res->flow_type);
11177         }
11178
11179         ret = parse_flexbytes(res->flexbytes_value,
11180                                         flexbytes,
11181                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11182         if (ret < 0) {
11183                 printf("error: Cannot parse flexbytes input.\n");
11184                 return;
11185         }
11186
11187         switch (entry.input.flow_type) {
11188         case RTE_ETH_FLOW_FRAG_IPV4:
11189         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11190                 entry.input.flow.ip4_flow.proto = res->proto_value;
11191                 /* fall-through */
11192         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11193         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11194                 IPV4_ADDR_TO_UINT(res->ip_dst,
11195                         entry.input.flow.ip4_flow.dst_ip);
11196                 IPV4_ADDR_TO_UINT(res->ip_src,
11197                         entry.input.flow.ip4_flow.src_ip);
11198                 entry.input.flow.ip4_flow.tos = res->tos_value;
11199                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11200                 /* need convert to big endian. */
11201                 entry.input.flow.udp4_flow.dst_port =
11202                                 rte_cpu_to_be_16(res->port_dst);
11203                 entry.input.flow.udp4_flow.src_port =
11204                                 rte_cpu_to_be_16(res->port_src);
11205                 break;
11206         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11207                 IPV4_ADDR_TO_UINT(res->ip_dst,
11208                         entry.input.flow.sctp4_flow.ip.dst_ip);
11209                 IPV4_ADDR_TO_UINT(res->ip_src,
11210                         entry.input.flow.sctp4_flow.ip.src_ip);
11211                 entry.input.flow.ip4_flow.tos = res->tos_value;
11212                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11213                 /* need convert to big endian. */
11214                 entry.input.flow.sctp4_flow.dst_port =
11215                                 rte_cpu_to_be_16(res->port_dst);
11216                 entry.input.flow.sctp4_flow.src_port =
11217                                 rte_cpu_to_be_16(res->port_src);
11218                 entry.input.flow.sctp4_flow.verify_tag =
11219                                 rte_cpu_to_be_32(res->verify_tag_value);
11220                 break;
11221         case RTE_ETH_FLOW_FRAG_IPV6:
11222         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11223                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11224                 /* fall-through */
11225         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11226         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11227                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11228                         entry.input.flow.ipv6_flow.dst_ip);
11229                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11230                         entry.input.flow.ipv6_flow.src_ip);
11231                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11232                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11233                 /* need convert to big endian. */
11234                 entry.input.flow.udp6_flow.dst_port =
11235                                 rte_cpu_to_be_16(res->port_dst);
11236                 entry.input.flow.udp6_flow.src_port =
11237                                 rte_cpu_to_be_16(res->port_src);
11238                 break;
11239         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11240                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11241                         entry.input.flow.sctp6_flow.ip.dst_ip);
11242                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11243                         entry.input.flow.sctp6_flow.ip.src_ip);
11244                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11245                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11246                 /* need convert to big endian. */
11247                 entry.input.flow.sctp6_flow.dst_port =
11248                                 rte_cpu_to_be_16(res->port_dst);
11249                 entry.input.flow.sctp6_flow.src_port =
11250                                 rte_cpu_to_be_16(res->port_src);
11251                 entry.input.flow.sctp6_flow.verify_tag =
11252                                 rte_cpu_to_be_32(res->verify_tag_value);
11253                 break;
11254         case RTE_ETH_FLOW_L2_PAYLOAD:
11255                 entry.input.flow.l2_flow.ether_type =
11256                         rte_cpu_to_be_16(res->ether_type);
11257                 break;
11258         default:
11259                 break;
11260         }
11261
11262         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11263                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11264                                  &res->mac_addr,
11265                                  sizeof(struct rte_ether_addr));
11266
11267         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11268                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11269                                  &res->mac_addr,
11270                                  sizeof(struct rte_ether_addr));
11271                 entry.input.flow.tunnel_flow.tunnel_type =
11272                         str2fdir_tunneltype(res->tunnel_type);
11273                 entry.input.flow.tunnel_flow.tunnel_id =
11274                         rte_cpu_to_be_32(res->tunnel_id_value);
11275         }
11276
11277         rte_memcpy(entry.input.flow_ext.flexbytes,
11278                    flexbytes,
11279                    RTE_ETH_FDIR_MAX_FLEXLEN);
11280
11281         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11282
11283         entry.action.flex_off = 0;  /*use 0 by default */
11284         if (!strcmp(res->drop, "drop"))
11285                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11286         else
11287                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11288
11289         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11290             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11291                 if (!strcmp(res->pf_vf, "pf"))
11292                         entry.input.flow_ext.is_vf = 0;
11293                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11294                         struct rte_eth_dev_info dev_info;
11295
11296                         ret = eth_dev_info_get_print_err(res->port_id,
11297                                                 &dev_info);
11298                         if (ret != 0)
11299                                 return;
11300
11301                         errno = 0;
11302                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11303                         if (errno != 0 || *end != '\0' ||
11304                             vf_id >= dev_info.max_vfs) {
11305                                 printf("invalid parameter %s.\n", res->pf_vf);
11306                                 return;
11307                         }
11308                         entry.input.flow_ext.is_vf = 1;
11309                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11310                 } else {
11311                         printf("invalid parameter %s.\n", res->pf_vf);
11312                         return;
11313                 }
11314         }
11315
11316         /* set to report FD ID by default */
11317         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11318         entry.action.rx_queue = res->queue_id;
11319         entry.soft_id = res->fd_id_value;
11320         if (!strcmp(res->ops, "add"))
11321                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11322                                              RTE_ETH_FILTER_ADD, &entry);
11323         else if (!strcmp(res->ops, "del"))
11324                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11325                                              RTE_ETH_FILTER_DELETE, &entry);
11326         else
11327                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11328                                              RTE_ETH_FILTER_UPDATE, &entry);
11329         if (ret < 0)
11330                 printf("flow director programming error: (%s)\n",
11331                         strerror(-ret));
11332 }
11333
11334 cmdline_parse_token_string_t cmd_flow_director_filter =
11335         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11336                                  flow_director_filter, "flow_director_filter");
11337 cmdline_parse_token_num_t cmd_flow_director_port_id =
11338         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11339                               port_id, UINT16);
11340 cmdline_parse_token_string_t cmd_flow_director_ops =
11341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11342                                  ops, "add#del#update");
11343 cmdline_parse_token_string_t cmd_flow_director_flow =
11344         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11345                                  flow, "flow");
11346 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11348                 flow_type, NULL);
11349 cmdline_parse_token_string_t cmd_flow_director_ether =
11350         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11351                                  ether, "ether");
11352 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11353         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11354                               ether_type, UINT16);
11355 cmdline_parse_token_string_t cmd_flow_director_src =
11356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11357                                  src, "src");
11358 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11359         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11360                                  ip_src);
11361 cmdline_parse_token_num_t cmd_flow_director_port_src =
11362         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11363                               port_src, UINT16);
11364 cmdline_parse_token_string_t cmd_flow_director_dst =
11365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11366                                  dst, "dst");
11367 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11368         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11369                                  ip_dst);
11370 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11371         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11372                               port_dst, UINT16);
11373 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11374         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11375                                   verify_tag, "verify_tag");
11376 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11377         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11378                               verify_tag_value, UINT32);
11379 cmdline_parse_token_string_t cmd_flow_director_tos =
11380         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11381                                  tos, "tos");
11382 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11383         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11384                               tos_value, UINT8);
11385 cmdline_parse_token_string_t cmd_flow_director_proto =
11386         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11387                                  proto, "proto");
11388 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11389         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11390                               proto_value, UINT8);
11391 cmdline_parse_token_string_t cmd_flow_director_ttl =
11392         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11393                                  ttl, "ttl");
11394 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11395         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11396                               ttl_value, UINT8);
11397 cmdline_parse_token_string_t cmd_flow_director_vlan =
11398         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11399                                  vlan, "vlan");
11400 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11401         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11402                               vlan_value, UINT16);
11403 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11405                                  flexbytes, "flexbytes");
11406 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11407         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11408                               flexbytes_value, NULL);
11409 cmdline_parse_token_string_t cmd_flow_director_drop =
11410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11411                                  drop, "drop#fwd");
11412 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11414                               pf_vf, NULL);
11415 cmdline_parse_token_string_t cmd_flow_director_queue =
11416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11417                                  queue, "queue");
11418 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11419         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11420                               queue_id, UINT16);
11421 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11423                                  fd_id, "fd_id");
11424 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11425         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11426                               fd_id_value, UINT32);
11427
11428 cmdline_parse_token_string_t cmd_flow_director_mode =
11429         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11430                                  mode, "mode");
11431 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11432         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11433                                  mode_value, "IP");
11434 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11435         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11436                                  mode_value, "MAC-VLAN");
11437 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11438         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11439                                  mode_value, "Tunnel");
11440 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11441         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11442                                  mode_value, "raw");
11443 cmdline_parse_token_string_t cmd_flow_director_mac =
11444         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11445                                  mac, "mac");
11446 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11447         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11448                                     mac_addr);
11449 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11451                                  tunnel, "tunnel");
11452 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11453         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11454                                  tunnel_type, "NVGRE#VxLAN");
11455 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11456         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11457                                  tunnel_id, "tunnel-id");
11458 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11459         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11460                               tunnel_id_value, UINT32);
11461 cmdline_parse_token_string_t cmd_flow_director_packet =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11463                                  packet, "packet");
11464 cmdline_parse_token_string_t cmd_flow_director_filepath =
11465         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11466                                  filepath, NULL);
11467
11468 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11469         .f = cmd_flow_director_filter_parsed,
11470         .data = NULL,
11471         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11472                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11473                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11474                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11475                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11476                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11477                 "fd_id <fd_id_value>: "
11478                 "Add or delete an ip flow director entry on NIC",
11479         .tokens = {
11480                 (void *)&cmd_flow_director_filter,
11481                 (void *)&cmd_flow_director_port_id,
11482                 (void *)&cmd_flow_director_mode,
11483                 (void *)&cmd_flow_director_mode_ip,
11484                 (void *)&cmd_flow_director_ops,
11485                 (void *)&cmd_flow_director_flow,
11486                 (void *)&cmd_flow_director_flow_type,
11487                 (void *)&cmd_flow_director_src,
11488                 (void *)&cmd_flow_director_ip_src,
11489                 (void *)&cmd_flow_director_dst,
11490                 (void *)&cmd_flow_director_ip_dst,
11491                 (void *)&cmd_flow_director_tos,
11492                 (void *)&cmd_flow_director_tos_value,
11493                 (void *)&cmd_flow_director_proto,
11494                 (void *)&cmd_flow_director_proto_value,
11495                 (void *)&cmd_flow_director_ttl,
11496                 (void *)&cmd_flow_director_ttl_value,
11497                 (void *)&cmd_flow_director_vlan,
11498                 (void *)&cmd_flow_director_vlan_value,
11499                 (void *)&cmd_flow_director_flexbytes,
11500                 (void *)&cmd_flow_director_flexbytes_value,
11501                 (void *)&cmd_flow_director_drop,
11502                 (void *)&cmd_flow_director_pf_vf,
11503                 (void *)&cmd_flow_director_queue,
11504                 (void *)&cmd_flow_director_queue_id,
11505                 (void *)&cmd_flow_director_fd_id,
11506                 (void *)&cmd_flow_director_fd_id_value,
11507                 NULL,
11508         },
11509 };
11510
11511 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11512         .f = cmd_flow_director_filter_parsed,
11513         .data = NULL,
11514         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11515                 "director entry on NIC",
11516         .tokens = {
11517                 (void *)&cmd_flow_director_filter,
11518                 (void *)&cmd_flow_director_port_id,
11519                 (void *)&cmd_flow_director_mode,
11520                 (void *)&cmd_flow_director_mode_ip,
11521                 (void *)&cmd_flow_director_ops,
11522                 (void *)&cmd_flow_director_flow,
11523                 (void *)&cmd_flow_director_flow_type,
11524                 (void *)&cmd_flow_director_src,
11525                 (void *)&cmd_flow_director_ip_src,
11526                 (void *)&cmd_flow_director_port_src,
11527                 (void *)&cmd_flow_director_dst,
11528                 (void *)&cmd_flow_director_ip_dst,
11529                 (void *)&cmd_flow_director_port_dst,
11530                 (void *)&cmd_flow_director_tos,
11531                 (void *)&cmd_flow_director_tos_value,
11532                 (void *)&cmd_flow_director_ttl,
11533                 (void *)&cmd_flow_director_ttl_value,
11534                 (void *)&cmd_flow_director_vlan,
11535                 (void *)&cmd_flow_director_vlan_value,
11536                 (void *)&cmd_flow_director_flexbytes,
11537                 (void *)&cmd_flow_director_flexbytes_value,
11538                 (void *)&cmd_flow_director_drop,
11539                 (void *)&cmd_flow_director_pf_vf,
11540                 (void *)&cmd_flow_director_queue,
11541                 (void *)&cmd_flow_director_queue_id,
11542                 (void *)&cmd_flow_director_fd_id,
11543                 (void *)&cmd_flow_director_fd_id_value,
11544                 NULL,
11545         },
11546 };
11547
11548 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11549         .f = cmd_flow_director_filter_parsed,
11550         .data = NULL,
11551         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11552                 "director entry on NIC",
11553         .tokens = {
11554                 (void *)&cmd_flow_director_filter,
11555                 (void *)&cmd_flow_director_port_id,
11556                 (void *)&cmd_flow_director_mode,
11557                 (void *)&cmd_flow_director_mode_ip,
11558                 (void *)&cmd_flow_director_ops,
11559                 (void *)&cmd_flow_director_flow,
11560                 (void *)&cmd_flow_director_flow_type,
11561                 (void *)&cmd_flow_director_src,
11562                 (void *)&cmd_flow_director_ip_src,
11563                 (void *)&cmd_flow_director_port_src,
11564                 (void *)&cmd_flow_director_dst,
11565                 (void *)&cmd_flow_director_ip_dst,
11566                 (void *)&cmd_flow_director_port_dst,
11567                 (void *)&cmd_flow_director_verify_tag,
11568                 (void *)&cmd_flow_director_verify_tag_value,
11569                 (void *)&cmd_flow_director_tos,
11570                 (void *)&cmd_flow_director_tos_value,
11571                 (void *)&cmd_flow_director_ttl,
11572                 (void *)&cmd_flow_director_ttl_value,
11573                 (void *)&cmd_flow_director_vlan,
11574                 (void *)&cmd_flow_director_vlan_value,
11575                 (void *)&cmd_flow_director_flexbytes,
11576                 (void *)&cmd_flow_director_flexbytes_value,
11577                 (void *)&cmd_flow_director_drop,
11578                 (void *)&cmd_flow_director_pf_vf,
11579                 (void *)&cmd_flow_director_queue,
11580                 (void *)&cmd_flow_director_queue_id,
11581                 (void *)&cmd_flow_director_fd_id,
11582                 (void *)&cmd_flow_director_fd_id_value,
11583                 NULL,
11584         },
11585 };
11586
11587 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11588         .f = cmd_flow_director_filter_parsed,
11589         .data = NULL,
11590         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11591                 "director entry on NIC",
11592         .tokens = {
11593                 (void *)&cmd_flow_director_filter,
11594                 (void *)&cmd_flow_director_port_id,
11595                 (void *)&cmd_flow_director_mode,
11596                 (void *)&cmd_flow_director_mode_ip,
11597                 (void *)&cmd_flow_director_ops,
11598                 (void *)&cmd_flow_director_flow,
11599                 (void *)&cmd_flow_director_flow_type,
11600                 (void *)&cmd_flow_director_ether,
11601                 (void *)&cmd_flow_director_ether_type,
11602                 (void *)&cmd_flow_director_flexbytes,
11603                 (void *)&cmd_flow_director_flexbytes_value,
11604                 (void *)&cmd_flow_director_drop,
11605                 (void *)&cmd_flow_director_pf_vf,
11606                 (void *)&cmd_flow_director_queue,
11607                 (void *)&cmd_flow_director_queue_id,
11608                 (void *)&cmd_flow_director_fd_id,
11609                 (void *)&cmd_flow_director_fd_id_value,
11610                 NULL,
11611         },
11612 };
11613
11614 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11615         .f = cmd_flow_director_filter_parsed,
11616         .data = NULL,
11617         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11618                 "director entry on NIC",
11619         .tokens = {
11620                 (void *)&cmd_flow_director_filter,
11621                 (void *)&cmd_flow_director_port_id,
11622                 (void *)&cmd_flow_director_mode,
11623                 (void *)&cmd_flow_director_mode_mac_vlan,
11624                 (void *)&cmd_flow_director_ops,
11625                 (void *)&cmd_flow_director_mac,
11626                 (void *)&cmd_flow_director_mac_addr,
11627                 (void *)&cmd_flow_director_vlan,
11628                 (void *)&cmd_flow_director_vlan_value,
11629                 (void *)&cmd_flow_director_flexbytes,
11630                 (void *)&cmd_flow_director_flexbytes_value,
11631                 (void *)&cmd_flow_director_drop,
11632                 (void *)&cmd_flow_director_queue,
11633                 (void *)&cmd_flow_director_queue_id,
11634                 (void *)&cmd_flow_director_fd_id,
11635                 (void *)&cmd_flow_director_fd_id_value,
11636                 NULL,
11637         },
11638 };
11639
11640 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11641         .f = cmd_flow_director_filter_parsed,
11642         .data = NULL,
11643         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11644                 "director entry on NIC",
11645         .tokens = {
11646                 (void *)&cmd_flow_director_filter,
11647                 (void *)&cmd_flow_director_port_id,
11648                 (void *)&cmd_flow_director_mode,
11649                 (void *)&cmd_flow_director_mode_tunnel,
11650                 (void *)&cmd_flow_director_ops,
11651                 (void *)&cmd_flow_director_mac,
11652                 (void *)&cmd_flow_director_mac_addr,
11653                 (void *)&cmd_flow_director_vlan,
11654                 (void *)&cmd_flow_director_vlan_value,
11655                 (void *)&cmd_flow_director_tunnel,
11656                 (void *)&cmd_flow_director_tunnel_type,
11657                 (void *)&cmd_flow_director_tunnel_id,
11658                 (void *)&cmd_flow_director_tunnel_id_value,
11659                 (void *)&cmd_flow_director_flexbytes,
11660                 (void *)&cmd_flow_director_flexbytes_value,
11661                 (void *)&cmd_flow_director_drop,
11662                 (void *)&cmd_flow_director_queue,
11663                 (void *)&cmd_flow_director_queue_id,
11664                 (void *)&cmd_flow_director_fd_id,
11665                 (void *)&cmd_flow_director_fd_id_value,
11666                 NULL,
11667         },
11668 };
11669
11670 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11671         .f = cmd_flow_director_filter_parsed,
11672         .data = NULL,
11673         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11674                 "director entry on NIC",
11675         .tokens = {
11676                 (void *)&cmd_flow_director_filter,
11677                 (void *)&cmd_flow_director_port_id,
11678                 (void *)&cmd_flow_director_mode,
11679                 (void *)&cmd_flow_director_mode_raw,
11680                 (void *)&cmd_flow_director_ops,
11681                 (void *)&cmd_flow_director_flow,
11682                 (void *)&cmd_flow_director_flow_type,
11683                 (void *)&cmd_flow_director_drop,
11684                 (void *)&cmd_flow_director_queue,
11685                 (void *)&cmd_flow_director_queue_id,
11686                 (void *)&cmd_flow_director_fd_id,
11687                 (void *)&cmd_flow_director_fd_id_value,
11688                 (void *)&cmd_flow_director_packet,
11689                 (void *)&cmd_flow_director_filepath,
11690                 NULL,
11691         },
11692 };
11693
11694 struct cmd_flush_flow_director_result {
11695         cmdline_fixed_string_t flush_flow_director;
11696         portid_t port_id;
11697 };
11698
11699 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11700         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11701                                  flush_flow_director, "flush_flow_director");
11702 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11703         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11704                               port_id, UINT16);
11705
11706 static void
11707 cmd_flush_flow_director_parsed(void *parsed_result,
11708                           __rte_unused struct cmdline *cl,
11709                           __rte_unused void *data)
11710 {
11711         struct cmd_flow_director_result *res = parsed_result;
11712         int ret = 0;
11713
11714         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11715         if (ret < 0) {
11716                 printf("flow director is not supported on port %u.\n",
11717                         res->port_id);
11718                 return;
11719         }
11720
11721         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11722                         RTE_ETH_FILTER_FLUSH, NULL);
11723         if (ret < 0)
11724                 printf("flow director table flushing error: (%s)\n",
11725                         strerror(-ret));
11726 }
11727
11728 cmdline_parse_inst_t cmd_flush_flow_director = {
11729         .f = cmd_flush_flow_director_parsed,
11730         .data = NULL,
11731         .help_str = "flush_flow_director <port_id>: "
11732                 "Flush all flow director entries of a device on NIC",
11733         .tokens = {
11734                 (void *)&cmd_flush_flow_director_flush,
11735                 (void *)&cmd_flush_flow_director_port_id,
11736                 NULL,
11737         },
11738 };
11739
11740 /* *** deal with flow director mask *** */
11741 struct cmd_flow_director_mask_result {
11742         cmdline_fixed_string_t flow_director_mask;
11743         portid_t port_id;
11744         cmdline_fixed_string_t mode;
11745         cmdline_fixed_string_t mode_value;
11746         cmdline_fixed_string_t vlan;
11747         uint16_t vlan_mask;
11748         cmdline_fixed_string_t src_mask;
11749         cmdline_ipaddr_t ipv4_src;
11750         cmdline_ipaddr_t ipv6_src;
11751         uint16_t port_src;
11752         cmdline_fixed_string_t dst_mask;
11753         cmdline_ipaddr_t ipv4_dst;
11754         cmdline_ipaddr_t ipv6_dst;
11755         uint16_t port_dst;
11756         cmdline_fixed_string_t mac;
11757         uint8_t mac_addr_byte_mask;
11758         cmdline_fixed_string_t tunnel_id;
11759         uint32_t tunnel_id_mask;
11760         cmdline_fixed_string_t tunnel_type;
11761         uint8_t tunnel_type_mask;
11762 };
11763
11764 static void
11765 cmd_flow_director_mask_parsed(void *parsed_result,
11766                           __rte_unused struct cmdline *cl,
11767                           __rte_unused void *data)
11768 {
11769         struct cmd_flow_director_mask_result *res = parsed_result;
11770         struct rte_eth_fdir_masks *mask;
11771         struct rte_port *port;
11772
11773         port = &ports[res->port_id];
11774         /** Check if the port is not started **/
11775         if (port->port_status != RTE_PORT_STOPPED) {
11776                 printf("Please stop port %d first\n", res->port_id);
11777                 return;
11778         }
11779
11780         mask = &port->dev_conf.fdir_conf.mask;
11781
11782         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11783                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11784                         printf("Please set mode to MAC-VLAN.\n");
11785                         return;
11786                 }
11787
11788                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11789         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11790                 if (strcmp(res->mode_value, "Tunnel")) {
11791                         printf("Please set mode to Tunnel.\n");
11792                         return;
11793                 }
11794
11795                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11796                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11797                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11798                 mask->tunnel_type_mask = res->tunnel_type_mask;
11799         } else {
11800                 if (strcmp(res->mode_value, "IP")) {
11801                         printf("Please set mode to IP.\n");
11802                         return;
11803                 }
11804
11805                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11806                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11807                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11808                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11809                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11810                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11811                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11812         }
11813
11814         cmd_reconfig_device_queue(res->port_id, 1, 1);
11815 }
11816
11817 cmdline_parse_token_string_t cmd_flow_director_mask =
11818         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11819                                  flow_director_mask, "flow_director_mask");
11820 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11821         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11822                               port_id, UINT16);
11823 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11824         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11825                                  vlan, "vlan");
11826 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11827         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11828                               vlan_mask, UINT16);
11829 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11830         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11831                                  src_mask, "src_mask");
11832 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11833         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11834                                  ipv4_src);
11835 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11836         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11837                                  ipv6_src);
11838 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11839         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11840                               port_src, UINT16);
11841 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11843                                  dst_mask, "dst_mask");
11844 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11845         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11846                                  ipv4_dst);
11847 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11848         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11849                                  ipv6_dst);
11850 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11851         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11852                               port_dst, UINT16);
11853
11854 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11856                                  mode, "mode");
11857 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11858         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11859                                  mode_value, "IP");
11860 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11861         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11862                                  mode_value, "MAC-VLAN");
11863 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11864         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11865                                  mode_value, "Tunnel");
11866 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11867         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11868                                  mac, "mac");
11869 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11870         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11871                               mac_addr_byte_mask, UINT8);
11872 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11874                                  tunnel_type, "tunnel-type");
11875 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11876         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11877                               tunnel_type_mask, UINT8);
11878 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11880                                  tunnel_id, "tunnel-id");
11881 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11882         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11883                               tunnel_id_mask, UINT32);
11884
11885 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11886         .f = cmd_flow_director_mask_parsed,
11887         .data = NULL,
11888         .help_str = "flow_director_mask ... : "
11889                 "Set IP mode flow director's mask on NIC",
11890         .tokens = {
11891                 (void *)&cmd_flow_director_mask,
11892                 (void *)&cmd_flow_director_mask_port_id,
11893                 (void *)&cmd_flow_director_mask_mode,
11894                 (void *)&cmd_flow_director_mask_mode_ip,
11895                 (void *)&cmd_flow_director_mask_vlan,
11896                 (void *)&cmd_flow_director_mask_vlan_value,
11897                 (void *)&cmd_flow_director_mask_src,
11898                 (void *)&cmd_flow_director_mask_ipv4_src,
11899                 (void *)&cmd_flow_director_mask_ipv6_src,
11900                 (void *)&cmd_flow_director_mask_port_src,
11901                 (void *)&cmd_flow_director_mask_dst,
11902                 (void *)&cmd_flow_director_mask_ipv4_dst,
11903                 (void *)&cmd_flow_director_mask_ipv6_dst,
11904                 (void *)&cmd_flow_director_mask_port_dst,
11905                 NULL,
11906         },
11907 };
11908
11909 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11910         .f = cmd_flow_director_mask_parsed,
11911         .data = NULL,
11912         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11913                 "flow director's mask on NIC",
11914         .tokens = {
11915                 (void *)&cmd_flow_director_mask,
11916                 (void *)&cmd_flow_director_mask_port_id,
11917                 (void *)&cmd_flow_director_mask_mode,
11918                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11919                 (void *)&cmd_flow_director_mask_vlan,
11920                 (void *)&cmd_flow_director_mask_vlan_value,
11921                 NULL,
11922         },
11923 };
11924
11925 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11926         .f = cmd_flow_director_mask_parsed,
11927         .data = NULL,
11928         .help_str = "flow_director_mask ... : Set tunnel mode "
11929                 "flow director's mask on NIC",
11930         .tokens = {
11931                 (void *)&cmd_flow_director_mask,
11932                 (void *)&cmd_flow_director_mask_port_id,
11933                 (void *)&cmd_flow_director_mask_mode,
11934                 (void *)&cmd_flow_director_mask_mode_tunnel,
11935                 (void *)&cmd_flow_director_mask_vlan,
11936                 (void *)&cmd_flow_director_mask_vlan_value,
11937                 (void *)&cmd_flow_director_mask_mac,
11938                 (void *)&cmd_flow_director_mask_mac_value,
11939                 (void *)&cmd_flow_director_mask_tunnel_type,
11940                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11941                 (void *)&cmd_flow_director_mask_tunnel_id,
11942                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11943                 NULL,
11944         },
11945 };
11946
11947 /* *** deal with flow director mask on flexible payload *** */
11948 struct cmd_flow_director_flex_mask_result {
11949         cmdline_fixed_string_t flow_director_flexmask;
11950         portid_t port_id;
11951         cmdline_fixed_string_t flow;
11952         cmdline_fixed_string_t flow_type;
11953         cmdline_fixed_string_t mask;
11954 };
11955
11956 static void
11957 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11958                           __rte_unused struct cmdline *cl,
11959                           __rte_unused void *data)
11960 {
11961         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11962         struct rte_eth_fdir_info fdir_info;
11963         struct rte_eth_fdir_flex_mask flex_mask;
11964         struct rte_port *port;
11965         uint64_t flow_type_mask;
11966         uint16_t i;
11967         int ret;
11968
11969         port = &ports[res->port_id];
11970         /** Check if the port is not started **/
11971         if (port->port_status != RTE_PORT_STOPPED) {
11972                 printf("Please stop port %d first\n", res->port_id);
11973                 return;
11974         }
11975
11976         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11977         ret = parse_flexbytes(res->mask,
11978                         flex_mask.mask,
11979                         RTE_ETH_FDIR_MAX_FLEXLEN);
11980         if (ret < 0) {
11981                 printf("error: Cannot parse mask input.\n");
11982                 return;
11983         }
11984
11985         memset(&fdir_info, 0, sizeof(fdir_info));
11986         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11987                                 RTE_ETH_FILTER_INFO, &fdir_info);
11988         if (ret < 0) {
11989                 printf("Cannot get FDir filter info\n");
11990                 return;
11991         }
11992
11993         if (!strcmp(res->flow_type, "none")) {
11994                 /* means don't specify the flow type */
11995                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11996                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11997                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11998                                0, sizeof(struct rte_eth_fdir_flex_mask));
11999                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12000                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12001                                  &flex_mask,
12002                                  sizeof(struct rte_eth_fdir_flex_mask));
12003                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12004                 return;
12005         }
12006         flow_type_mask = fdir_info.flow_types_mask[0];
12007         if (!strcmp(res->flow_type, "all")) {
12008                 if (!flow_type_mask) {
12009                         printf("No flow type supported\n");
12010                         return;
12011                 }
12012                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12013                         if (flow_type_mask & (1ULL << i)) {
12014                                 flex_mask.flow_type = i;
12015                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12016                         }
12017                 }
12018                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12019                 return;
12020         }
12021         flex_mask.flow_type = str2flowtype(res->flow_type);
12022         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12023                 printf("Flow type %s not supported on port %d\n",
12024                                 res->flow_type, res->port_id);
12025                 return;
12026         }
12027         fdir_set_flex_mask(res->port_id, &flex_mask);
12028         cmd_reconfig_device_queue(res->port_id, 1, 1);
12029 }
12030
12031 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12032         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12033                                  flow_director_flexmask,
12034                                  "flow_director_flex_mask");
12035 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12036         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12037                               port_id, UINT16);
12038 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12039         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12040                                  flow, "flow");
12041 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12042         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12043                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12044                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12045 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12046         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12047                                  mask, NULL);
12048
12049 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12050         .f = cmd_flow_director_flex_mask_parsed,
12051         .data = NULL,
12052         .help_str = "flow_director_flex_mask ... : "
12053                 "Set flow director's flex mask on NIC",
12054         .tokens = {
12055                 (void *)&cmd_flow_director_flexmask,
12056                 (void *)&cmd_flow_director_flexmask_port_id,
12057                 (void *)&cmd_flow_director_flexmask_flow,
12058                 (void *)&cmd_flow_director_flexmask_flow_type,
12059                 (void *)&cmd_flow_director_flexmask_mask,
12060                 NULL,
12061         },
12062 };
12063
12064 /* *** deal with flow director flexible payload configuration *** */
12065 struct cmd_flow_director_flexpayload_result {
12066         cmdline_fixed_string_t flow_director_flexpayload;
12067         portid_t port_id;
12068         cmdline_fixed_string_t payload_layer;
12069         cmdline_fixed_string_t payload_cfg;
12070 };
12071
12072 static inline int
12073 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12074 {
12075         char s[256];
12076         const char *p, *p0 = q_arg;
12077         char *end;
12078         unsigned long int_fld;
12079         char *str_fld[max_num];
12080         int i;
12081         unsigned size;
12082         int ret = -1;
12083
12084         p = strchr(p0, '(');
12085         if (p == NULL)
12086                 return -1;
12087         ++p;
12088         p0 = strchr(p, ')');
12089         if (p0 == NULL)
12090                 return -1;
12091
12092         size = p0 - p;
12093         if (size >= sizeof(s))
12094                 return -1;
12095
12096         snprintf(s, sizeof(s), "%.*s", size, p);
12097         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12098         if (ret < 0 || ret > max_num)
12099                 return -1;
12100         for (i = 0; i < ret; i++) {
12101                 errno = 0;
12102                 int_fld = strtoul(str_fld[i], &end, 0);
12103                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12104                         return -1;
12105                 offsets[i] = (uint16_t)int_fld;
12106         }
12107         return ret;
12108 }
12109
12110 static void
12111 cmd_flow_director_flxpld_parsed(void *parsed_result,
12112                           __rte_unused struct cmdline *cl,
12113                           __rte_unused void *data)
12114 {
12115         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12116         struct rte_eth_flex_payload_cfg flex_cfg;
12117         struct rte_port *port;
12118         int ret = 0;
12119
12120         port = &ports[res->port_id];
12121         /** Check if the port is not started **/
12122         if (port->port_status != RTE_PORT_STOPPED) {
12123                 printf("Please stop port %d first\n", res->port_id);
12124                 return;
12125         }
12126
12127         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12128
12129         if (!strcmp(res->payload_layer, "raw"))
12130                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12131         else if (!strcmp(res->payload_layer, "l2"))
12132                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12133         else if (!strcmp(res->payload_layer, "l3"))
12134                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12135         else if (!strcmp(res->payload_layer, "l4"))
12136                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12137
12138         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12139                             RTE_ETH_FDIR_MAX_FLEXLEN);
12140         if (ret < 0) {
12141                 printf("error: Cannot parse flex payload input.\n");
12142                 return;
12143         }
12144
12145         fdir_set_flex_payload(res->port_id, &flex_cfg);
12146         cmd_reconfig_device_queue(res->port_id, 1, 1);
12147 }
12148
12149 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12151                                  flow_director_flexpayload,
12152                                  "flow_director_flex_payload");
12153 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12154         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12155                               port_id, UINT16);
12156 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12157         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12158                                  payload_layer, "raw#l2#l3#l4");
12159 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12160         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12161                                  payload_cfg, NULL);
12162
12163 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12164         .f = cmd_flow_director_flxpld_parsed,
12165         .data = NULL,
12166         .help_str = "flow_director_flexpayload ... : "
12167                 "Set flow director's flex payload on NIC",
12168         .tokens = {
12169                 (void *)&cmd_flow_director_flexpayload,
12170                 (void *)&cmd_flow_director_flexpayload_port_id,
12171                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12172                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12173                 NULL,
12174         },
12175 };
12176
12177 /* Generic flow interface command. */
12178 extern cmdline_parse_inst_t cmd_flow;
12179
12180 /* *** Classification Filters Control *** */
12181 /* *** Get symmetric hash enable per port *** */
12182 struct cmd_get_sym_hash_ena_per_port_result {
12183         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12184         portid_t port_id;
12185 };
12186
12187 static void
12188 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12189                                  __rte_unused struct cmdline *cl,
12190                                  __rte_unused void *data)
12191 {
12192         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12193         struct rte_eth_hash_filter_info info;
12194         int ret;
12195
12196         if (rte_eth_dev_filter_supported(res->port_id,
12197                                 RTE_ETH_FILTER_HASH) < 0) {
12198                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12199                                                         res->port_id);
12200                 return;
12201         }
12202
12203         memset(&info, 0, sizeof(info));
12204         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12205         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12206                                                 RTE_ETH_FILTER_GET, &info);
12207
12208         if (ret < 0) {
12209                 printf("Cannot get symmetric hash enable per port "
12210                                         "on port %u\n", res->port_id);
12211                 return;
12212         }
12213
12214         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12215                                 "enabled" : "disabled", res->port_id);
12216 }
12217
12218 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12219         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12220                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12221 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12222         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12223                 port_id, UINT16);
12224
12225 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12226         .f = cmd_get_sym_hash_per_port_parsed,
12227         .data = NULL,
12228         .help_str = "get_sym_hash_ena_per_port <port_id>",
12229         .tokens = {
12230                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12231                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12232                 NULL,
12233         },
12234 };
12235
12236 /* *** Set symmetric hash enable per port *** */
12237 struct cmd_set_sym_hash_ena_per_port_result {
12238         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12239         cmdline_fixed_string_t enable;
12240         portid_t port_id;
12241 };
12242
12243 static void
12244 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12245                                  __rte_unused struct cmdline *cl,
12246                                  __rte_unused void *data)
12247 {
12248         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12249         struct rte_eth_hash_filter_info info;
12250         int ret;
12251
12252         if (rte_eth_dev_filter_supported(res->port_id,
12253                                 RTE_ETH_FILTER_HASH) < 0) {
12254                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12255                                                         res->port_id);
12256                 return;
12257         }
12258
12259         memset(&info, 0, sizeof(info));
12260         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12261         if (!strcmp(res->enable, "enable"))
12262                 info.info.enable = 1;
12263         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12264                                         RTE_ETH_FILTER_SET, &info);
12265         if (ret < 0) {
12266                 printf("Cannot set symmetric hash enable per port on "
12267                                         "port %u\n", res->port_id);
12268                 return;
12269         }
12270         printf("Symmetric hash has been set to %s on port %u\n",
12271                                         res->enable, res->port_id);
12272 }
12273
12274 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12275         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12276                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12277 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12278         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12279                 port_id, UINT16);
12280 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12281         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12282                 enable, "enable#disable");
12283
12284 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12285         .f = cmd_set_sym_hash_per_port_parsed,
12286         .data = NULL,
12287         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12288         .tokens = {
12289                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12290                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12291                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12292                 NULL,
12293         },
12294 };
12295
12296 /* Get global config of hash function */
12297 struct cmd_get_hash_global_config_result {
12298         cmdline_fixed_string_t get_hash_global_config;
12299         portid_t port_id;
12300 };
12301
12302 static char *
12303 flowtype_to_str(uint16_t ftype)
12304 {
12305         uint16_t i;
12306         static struct {
12307                 char str[16];
12308                 uint16_t ftype;
12309         } ftype_table[] = {
12310                 {"ipv4", RTE_ETH_FLOW_IPV4},
12311                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12312                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12313                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12314                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12315                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12316                 {"ipv6", RTE_ETH_FLOW_IPV6},
12317                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12318                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12319                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12320                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12321                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12322                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12323                 {"port", RTE_ETH_FLOW_PORT},
12324                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12325                 {"geneve", RTE_ETH_FLOW_GENEVE},
12326                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12327                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12328         };
12329
12330         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12331                 if (ftype_table[i].ftype == ftype)
12332                         return ftype_table[i].str;
12333         }
12334
12335         return NULL;
12336 }
12337
12338 static void
12339 cmd_get_hash_global_config_parsed(void *parsed_result,
12340                                   __rte_unused struct cmdline *cl,
12341                                   __rte_unused void *data)
12342 {
12343         struct cmd_get_hash_global_config_result *res = parsed_result;
12344         struct rte_eth_hash_filter_info info;
12345         uint32_t idx, offset;
12346         uint16_t i;
12347         char *str;
12348         int ret;
12349
12350         if (rte_eth_dev_filter_supported(res->port_id,
12351                         RTE_ETH_FILTER_HASH) < 0) {
12352                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12353                                                         res->port_id);
12354                 return;
12355         }
12356
12357         memset(&info, 0, sizeof(info));
12358         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12359         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12360                                         RTE_ETH_FILTER_GET, &info);
12361         if (ret < 0) {
12362                 printf("Cannot get hash global configurations by port %d\n",
12363                                                         res->port_id);
12364                 return;
12365         }
12366
12367         switch (info.info.global_conf.hash_func) {
12368         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12369                 printf("Hash function is Toeplitz\n");
12370                 break;
12371         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12372                 printf("Hash function is Simple XOR\n");
12373                 break;
12374         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12375                 printf("Hash function is Symmetric Toeplitz\n");
12376                 break;
12377         default:
12378                 printf("Unknown hash function\n");
12379                 break;
12380         }
12381
12382         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12383                 idx = i / UINT64_BIT;
12384                 offset = i % UINT64_BIT;
12385                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12386                                                 (1ULL << offset)))
12387                         continue;
12388                 str = flowtype_to_str(i);
12389                 if (!str)
12390                         continue;
12391                 printf("Symmetric hash is %s globally for flow type %s "
12392                                                         "by port %d\n",
12393                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12394                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12395                                                         res->port_id);
12396         }
12397 }
12398
12399 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12400         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12401                 get_hash_global_config, "get_hash_global_config");
12402 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12403         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12404                 port_id, UINT16);
12405
12406 cmdline_parse_inst_t cmd_get_hash_global_config = {
12407         .f = cmd_get_hash_global_config_parsed,
12408         .data = NULL,
12409         .help_str = "get_hash_global_config <port_id>",
12410         .tokens = {
12411                 (void *)&cmd_get_hash_global_config_all,
12412                 (void *)&cmd_get_hash_global_config_port_id,
12413                 NULL,
12414         },
12415 };
12416
12417 /* Set global config of hash function */
12418 struct cmd_set_hash_global_config_result {
12419         cmdline_fixed_string_t set_hash_global_config;
12420         portid_t port_id;
12421         cmdline_fixed_string_t hash_func;
12422         cmdline_fixed_string_t flow_type;
12423         cmdline_fixed_string_t enable;
12424 };
12425
12426 static void
12427 cmd_set_hash_global_config_parsed(void *parsed_result,
12428                                   __rte_unused struct cmdline *cl,
12429                                   __rte_unused void *data)
12430 {
12431         struct cmd_set_hash_global_config_result *res = parsed_result;
12432         struct rte_eth_hash_filter_info info;
12433         uint32_t ftype, idx, offset;
12434         int ret;
12435
12436         if (rte_eth_dev_filter_supported(res->port_id,
12437                                 RTE_ETH_FILTER_HASH) < 0) {
12438                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12439                                                         res->port_id);
12440                 return;
12441         }
12442         memset(&info, 0, sizeof(info));
12443         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12444         if (!strcmp(res->hash_func, "toeplitz"))
12445                 info.info.global_conf.hash_func =
12446                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12447         else if (!strcmp(res->hash_func, "simple_xor"))
12448                 info.info.global_conf.hash_func =
12449                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12450         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12451                 info.info.global_conf.hash_func =
12452                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12453         else if (!strcmp(res->hash_func, "default"))
12454                 info.info.global_conf.hash_func =
12455                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12456
12457         ftype = str2flowtype(res->flow_type);
12458         idx = ftype / UINT64_BIT;
12459         offset = ftype % UINT64_BIT;
12460         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12461         if (!strcmp(res->enable, "enable"))
12462                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12463                                                 (1ULL << offset);
12464         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12465                                         RTE_ETH_FILTER_SET, &info);
12466         if (ret < 0)
12467                 printf("Cannot set global hash configurations by port %d\n",
12468                                                         res->port_id);
12469         else
12470                 printf("Global hash configurations have been set "
12471                         "successfully by port %d\n", res->port_id);
12472 }
12473
12474 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12475         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12476                 set_hash_global_config, "set_hash_global_config");
12477 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12478         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12479                 port_id, UINT16);
12480 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12481         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12482                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12483 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12484         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12485                 flow_type,
12486                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12487                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12488 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12489         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12490                 enable, "enable#disable");
12491
12492 cmdline_parse_inst_t cmd_set_hash_global_config = {
12493         .f = cmd_set_hash_global_config_parsed,
12494         .data = NULL,
12495         .help_str = "set_hash_global_config <port_id> "
12496                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12497                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12498                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12499                 "l2_payload enable|disable",
12500         .tokens = {
12501                 (void *)&cmd_set_hash_global_config_all,
12502                 (void *)&cmd_set_hash_global_config_port_id,
12503                 (void *)&cmd_set_hash_global_config_hash_func,
12504                 (void *)&cmd_set_hash_global_config_flow_type,
12505                 (void *)&cmd_set_hash_global_config_enable,
12506                 NULL,
12507         },
12508 };
12509
12510 /* Set hash input set */
12511 struct cmd_set_hash_input_set_result {
12512         cmdline_fixed_string_t set_hash_input_set;
12513         portid_t port_id;
12514         cmdline_fixed_string_t flow_type;
12515         cmdline_fixed_string_t inset_field;
12516         cmdline_fixed_string_t select;
12517 };
12518
12519 static enum rte_eth_input_set_field
12520 str2inset(char *string)
12521 {
12522         uint16_t i;
12523
12524         static const struct {
12525                 char str[32];
12526                 enum rte_eth_input_set_field inset;
12527         } inset_table[] = {
12528                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12529                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12530                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12531                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12532                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12533                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12534                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12535                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12536                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12537                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12538                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12539                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12540                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12541                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12542                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12543                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12544                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12545                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12546                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12547                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12548                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12549                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12550                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12551                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12552                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12553                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12554                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12555                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12556                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12557                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12558                 {"none", RTE_ETH_INPUT_SET_NONE},
12559         };
12560
12561         for (i = 0; i < RTE_DIM(inset_table); i++) {
12562                 if (!strcmp(string, inset_table[i].str))
12563                         return inset_table[i].inset;
12564         }
12565
12566         return RTE_ETH_INPUT_SET_UNKNOWN;
12567 }
12568
12569 static void
12570 cmd_set_hash_input_set_parsed(void *parsed_result,
12571                               __rte_unused struct cmdline *cl,
12572                               __rte_unused void *data)
12573 {
12574         struct cmd_set_hash_input_set_result *res = parsed_result;
12575         struct rte_eth_hash_filter_info info;
12576
12577         memset(&info, 0, sizeof(info));
12578         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12579         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12580         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12581         info.info.input_set_conf.inset_size = 1;
12582         if (!strcmp(res->select, "select"))
12583                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12584         else if (!strcmp(res->select, "add"))
12585                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12586         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12587                                 RTE_ETH_FILTER_SET, &info);
12588 }
12589
12590 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12591         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12592                 set_hash_input_set, "set_hash_input_set");
12593 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12594         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12595                 port_id, UINT16);
12596 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12597         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12598                 flow_type, NULL);
12599 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12600         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12601                 inset_field,
12602                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12603                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12604                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12605                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12606                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12607                 "fld-8th#none");
12608 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12609         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12610                 select, "select#add");
12611
12612 cmdline_parse_inst_t cmd_set_hash_input_set = {
12613         .f = cmd_set_hash_input_set_parsed,
12614         .data = NULL,
12615         .help_str = "set_hash_input_set <port_id> "
12616         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12617         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12618         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12619         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12620         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12621         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12622         "fld-7th|fld-8th|none select|add",
12623         .tokens = {
12624                 (void *)&cmd_set_hash_input_set_cmd,
12625                 (void *)&cmd_set_hash_input_set_port_id,
12626                 (void *)&cmd_set_hash_input_set_flow_type,
12627                 (void *)&cmd_set_hash_input_set_field,
12628                 (void *)&cmd_set_hash_input_set_select,
12629                 NULL,
12630         },
12631 };
12632
12633 /* Set flow director input set */
12634 struct cmd_set_fdir_input_set_result {
12635         cmdline_fixed_string_t set_fdir_input_set;
12636         portid_t port_id;
12637         cmdline_fixed_string_t flow_type;
12638         cmdline_fixed_string_t inset_field;
12639         cmdline_fixed_string_t select;
12640 };
12641
12642 static void
12643 cmd_set_fdir_input_set_parsed(void *parsed_result,
12644         __rte_unused struct cmdline *cl,
12645         __rte_unused void *data)
12646 {
12647         struct cmd_set_fdir_input_set_result *res = parsed_result;
12648         struct rte_eth_fdir_filter_info info;
12649
12650         memset(&info, 0, sizeof(info));
12651         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12652         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12653         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12654         info.info.input_set_conf.inset_size = 1;
12655         if (!strcmp(res->select, "select"))
12656                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12657         else if (!strcmp(res->select, "add"))
12658                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12659         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12660                 RTE_ETH_FILTER_SET, &info);
12661 }
12662
12663 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12664         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12665         set_fdir_input_set, "set_fdir_input_set");
12666 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12667         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12668         port_id, UINT16);
12669 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12670         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12671         flow_type,
12672         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12673         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12674 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12675         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12676         inset_field,
12677         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12678         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12679         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12680         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12681         "sctp-veri-tag#none");
12682 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12683         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12684         select, "select#add");
12685
12686 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12687         .f = cmd_set_fdir_input_set_parsed,
12688         .data = NULL,
12689         .help_str = "set_fdir_input_set <port_id> "
12690         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12691         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12692         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12693         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12694         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12695         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12696         "sctp-veri-tag|none select|add",
12697         .tokens = {
12698                 (void *)&cmd_set_fdir_input_set_cmd,
12699                 (void *)&cmd_set_fdir_input_set_port_id,
12700                 (void *)&cmd_set_fdir_input_set_flow_type,
12701                 (void *)&cmd_set_fdir_input_set_field,
12702                 (void *)&cmd_set_fdir_input_set_select,
12703                 NULL,
12704         },
12705 };
12706
12707 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12708 struct cmd_mcast_addr_result {
12709         cmdline_fixed_string_t mcast_addr_cmd;
12710         cmdline_fixed_string_t what;
12711         uint16_t port_num;
12712         struct rte_ether_addr mc_addr;
12713 };
12714
12715 static void cmd_mcast_addr_parsed(void *parsed_result,
12716                 __rte_unused struct cmdline *cl,
12717                 __rte_unused void *data)
12718 {
12719         struct cmd_mcast_addr_result *res = parsed_result;
12720
12721         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12722                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12723                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12724                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12725                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12726                 return;
12727         }
12728         if (strcmp(res->what, "add") == 0)
12729                 mcast_addr_add(res->port_num, &res->mc_addr);
12730         else
12731                 mcast_addr_remove(res->port_num, &res->mc_addr);
12732 }
12733
12734 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12735         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12736                                  mcast_addr_cmd, "mcast_addr");
12737 cmdline_parse_token_string_t cmd_mcast_addr_what =
12738         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12739                                  "add#remove");
12740 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12741         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12742 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12743         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12744
12745 cmdline_parse_inst_t cmd_mcast_addr = {
12746         .f = cmd_mcast_addr_parsed,
12747         .data = (void *)0,
12748         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12749                 "Add/Remove multicast MAC address on port_id",
12750         .tokens = {
12751                 (void *)&cmd_mcast_addr_cmd,
12752                 (void *)&cmd_mcast_addr_what,
12753                 (void *)&cmd_mcast_addr_portnum,
12754                 (void *)&cmd_mcast_addr_addr,
12755                 NULL,
12756         },
12757 };
12758
12759 /* l2 tunnel config
12760  * only support E-tag now.
12761  */
12762
12763 /* Ether type config */
12764 struct cmd_config_l2_tunnel_eth_type_result {
12765         cmdline_fixed_string_t port;
12766         cmdline_fixed_string_t config;
12767         cmdline_fixed_string_t all;
12768         portid_t id;
12769         cmdline_fixed_string_t l2_tunnel;
12770         cmdline_fixed_string_t l2_tunnel_type;
12771         cmdline_fixed_string_t eth_type;
12772         uint16_t eth_type_val;
12773 };
12774
12775 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12776         TOKEN_STRING_INITIALIZER
12777                 (struct cmd_config_l2_tunnel_eth_type_result,
12778                  port, "port");
12779 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12780         TOKEN_STRING_INITIALIZER
12781                 (struct cmd_config_l2_tunnel_eth_type_result,
12782                  config, "config");
12783 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12784         TOKEN_STRING_INITIALIZER
12785                 (struct cmd_config_l2_tunnel_eth_type_result,
12786                  all, "all");
12787 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12788         TOKEN_NUM_INITIALIZER
12789                 (struct cmd_config_l2_tunnel_eth_type_result,
12790                  id, UINT16);
12791 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12792         TOKEN_STRING_INITIALIZER
12793                 (struct cmd_config_l2_tunnel_eth_type_result,
12794                  l2_tunnel, "l2-tunnel");
12795 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12796         TOKEN_STRING_INITIALIZER
12797                 (struct cmd_config_l2_tunnel_eth_type_result,
12798                  l2_tunnel_type, "E-tag");
12799 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12800         TOKEN_STRING_INITIALIZER
12801                 (struct cmd_config_l2_tunnel_eth_type_result,
12802                  eth_type, "ether-type");
12803 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12804         TOKEN_NUM_INITIALIZER
12805                 (struct cmd_config_l2_tunnel_eth_type_result,
12806                  eth_type_val, UINT16);
12807
12808 static enum rte_eth_tunnel_type
12809 str2fdir_l2_tunnel_type(char *string)
12810 {
12811         uint32_t i = 0;
12812
12813         static const struct {
12814                 char str[32];
12815                 enum rte_eth_tunnel_type type;
12816         } l2_tunnel_type_str[] = {
12817                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12818         };
12819
12820         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12821                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12822                         return l2_tunnel_type_str[i].type;
12823         }
12824         return RTE_TUNNEL_TYPE_NONE;
12825 }
12826
12827 /* ether type config for all ports */
12828 static void
12829 cmd_config_l2_tunnel_eth_type_all_parsed
12830         (void *parsed_result,
12831          __rte_unused struct cmdline *cl,
12832          __rte_unused void *data)
12833 {
12834         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12835         struct rte_eth_l2_tunnel_conf entry;
12836         portid_t pid;
12837
12838         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12839         entry.ether_type = res->eth_type_val;
12840
12841         RTE_ETH_FOREACH_DEV(pid) {
12842                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12843         }
12844 }
12845
12846 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12847         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12848         .data = NULL,
12849         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12850         .tokens = {
12851                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12852                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12853                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12854                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12855                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12856                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12857                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12858                 NULL,
12859         },
12860 };
12861
12862 /* ether type config for a specific port */
12863 static void
12864 cmd_config_l2_tunnel_eth_type_specific_parsed(
12865         void *parsed_result,
12866         __rte_unused struct cmdline *cl,
12867         __rte_unused void *data)
12868 {
12869         struct cmd_config_l2_tunnel_eth_type_result *res =
12870                  parsed_result;
12871         struct rte_eth_l2_tunnel_conf entry;
12872
12873         if (port_id_is_invalid(res->id, ENABLED_WARN))
12874                 return;
12875
12876         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12877         entry.ether_type = res->eth_type_val;
12878
12879         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12880 }
12881
12882 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12883         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12884         .data = NULL,
12885         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12886         .tokens = {
12887                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12888                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12889                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12890                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12891                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12892                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12893                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12894                 NULL,
12895         },
12896 };
12897
12898 /* Enable/disable l2 tunnel */
12899 struct cmd_config_l2_tunnel_en_dis_result {
12900         cmdline_fixed_string_t port;
12901         cmdline_fixed_string_t config;
12902         cmdline_fixed_string_t all;
12903         portid_t id;
12904         cmdline_fixed_string_t l2_tunnel;
12905         cmdline_fixed_string_t l2_tunnel_type;
12906         cmdline_fixed_string_t en_dis;
12907 };
12908
12909 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12910         TOKEN_STRING_INITIALIZER
12911                 (struct cmd_config_l2_tunnel_en_dis_result,
12912                  port, "port");
12913 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12914         TOKEN_STRING_INITIALIZER
12915                 (struct cmd_config_l2_tunnel_en_dis_result,
12916                  config, "config");
12917 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12918         TOKEN_STRING_INITIALIZER
12919                 (struct cmd_config_l2_tunnel_en_dis_result,
12920                  all, "all");
12921 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12922         TOKEN_NUM_INITIALIZER
12923                 (struct cmd_config_l2_tunnel_en_dis_result,
12924                  id, UINT16);
12925 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12926         TOKEN_STRING_INITIALIZER
12927                 (struct cmd_config_l2_tunnel_en_dis_result,
12928                  l2_tunnel, "l2-tunnel");
12929 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12930         TOKEN_STRING_INITIALIZER
12931                 (struct cmd_config_l2_tunnel_en_dis_result,
12932                  l2_tunnel_type, "E-tag");
12933 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12934         TOKEN_STRING_INITIALIZER
12935                 (struct cmd_config_l2_tunnel_en_dis_result,
12936                  en_dis, "enable#disable");
12937
12938 /* enable/disable l2 tunnel for all ports */
12939 static void
12940 cmd_config_l2_tunnel_en_dis_all_parsed(
12941         void *parsed_result,
12942         __rte_unused struct cmdline *cl,
12943         __rte_unused void *data)
12944 {
12945         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12946         struct rte_eth_l2_tunnel_conf entry;
12947         portid_t pid;
12948         uint8_t en;
12949
12950         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12951
12952         if (!strcmp("enable", res->en_dis))
12953                 en = 1;
12954         else
12955                 en = 0;
12956
12957         RTE_ETH_FOREACH_DEV(pid) {
12958                 rte_eth_dev_l2_tunnel_offload_set(pid,
12959                                                   &entry,
12960                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12961                                                   en);
12962         }
12963 }
12964
12965 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12966         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12967         .data = NULL,
12968         .help_str = "port config all l2-tunnel E-tag enable|disable",
12969         .tokens = {
12970                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12971                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12972                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12973                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12974                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12975                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12976                 NULL,
12977         },
12978 };
12979
12980 /* enable/disable l2 tunnel for a port */
12981 static void
12982 cmd_config_l2_tunnel_en_dis_specific_parsed(
12983         void *parsed_result,
12984         __rte_unused struct cmdline *cl,
12985         __rte_unused void *data)
12986 {
12987         struct cmd_config_l2_tunnel_en_dis_result *res =
12988                 parsed_result;
12989         struct rte_eth_l2_tunnel_conf entry;
12990
12991         if (port_id_is_invalid(res->id, ENABLED_WARN))
12992                 return;
12993
12994         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12995
12996         if (!strcmp("enable", res->en_dis))
12997                 rte_eth_dev_l2_tunnel_offload_set(res->id,
12998                                                   &entry,
12999                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13000                                                   1);
13001         else
13002                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13003                                                   &entry,
13004                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13005                                                   0);
13006 }
13007
13008 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13009         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13010         .data = NULL,
13011         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13012         .tokens = {
13013                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13014                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13015                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13016                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13017                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13018                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13019                 NULL,
13020         },
13021 };
13022
13023 /* E-tag configuration */
13024
13025 /* Common result structure for all E-tag configuration */
13026 struct cmd_config_e_tag_result {
13027         cmdline_fixed_string_t e_tag;
13028         cmdline_fixed_string_t set;
13029         cmdline_fixed_string_t insertion;
13030         cmdline_fixed_string_t stripping;
13031         cmdline_fixed_string_t forwarding;
13032         cmdline_fixed_string_t filter;
13033         cmdline_fixed_string_t add;
13034         cmdline_fixed_string_t del;
13035         cmdline_fixed_string_t on;
13036         cmdline_fixed_string_t off;
13037         cmdline_fixed_string_t on_off;
13038         cmdline_fixed_string_t port_tag_id;
13039         uint32_t port_tag_id_val;
13040         cmdline_fixed_string_t e_tag_id;
13041         uint16_t e_tag_id_val;
13042         cmdline_fixed_string_t dst_pool;
13043         uint8_t dst_pool_val;
13044         cmdline_fixed_string_t port;
13045         portid_t port_id;
13046         cmdline_fixed_string_t vf;
13047         uint8_t vf_id;
13048 };
13049
13050 /* Common CLI fields for all E-tag configuration */
13051 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13052         TOKEN_STRING_INITIALIZER
13053                 (struct cmd_config_e_tag_result,
13054                  e_tag, "E-tag");
13055 cmdline_parse_token_string_t cmd_config_e_tag_set =
13056         TOKEN_STRING_INITIALIZER
13057                 (struct cmd_config_e_tag_result,
13058                  set, "set");
13059 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13060         TOKEN_STRING_INITIALIZER
13061                 (struct cmd_config_e_tag_result,
13062                  insertion, "insertion");
13063 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13064         TOKEN_STRING_INITIALIZER
13065                 (struct cmd_config_e_tag_result,
13066                  stripping, "stripping");
13067 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13068         TOKEN_STRING_INITIALIZER
13069                 (struct cmd_config_e_tag_result,
13070                  forwarding, "forwarding");
13071 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13072         TOKEN_STRING_INITIALIZER
13073                 (struct cmd_config_e_tag_result,
13074                  filter, "filter");
13075 cmdline_parse_token_string_t cmd_config_e_tag_add =
13076         TOKEN_STRING_INITIALIZER
13077                 (struct cmd_config_e_tag_result,
13078                  add, "add");
13079 cmdline_parse_token_string_t cmd_config_e_tag_del =
13080         TOKEN_STRING_INITIALIZER
13081                 (struct cmd_config_e_tag_result,
13082                  del, "del");
13083 cmdline_parse_token_string_t cmd_config_e_tag_on =
13084         TOKEN_STRING_INITIALIZER
13085                 (struct cmd_config_e_tag_result,
13086                  on, "on");
13087 cmdline_parse_token_string_t cmd_config_e_tag_off =
13088         TOKEN_STRING_INITIALIZER
13089                 (struct cmd_config_e_tag_result,
13090                  off, "off");
13091 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13092         TOKEN_STRING_INITIALIZER
13093                 (struct cmd_config_e_tag_result,
13094                  on_off, "on#off");
13095 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13096         TOKEN_STRING_INITIALIZER
13097                 (struct cmd_config_e_tag_result,
13098                  port_tag_id, "port-tag-id");
13099 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13100         TOKEN_NUM_INITIALIZER
13101                 (struct cmd_config_e_tag_result,
13102                  port_tag_id_val, UINT32);
13103 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13104         TOKEN_STRING_INITIALIZER
13105                 (struct cmd_config_e_tag_result,
13106                  e_tag_id, "e-tag-id");
13107 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13108         TOKEN_NUM_INITIALIZER
13109                 (struct cmd_config_e_tag_result,
13110                  e_tag_id_val, UINT16);
13111 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13112         TOKEN_STRING_INITIALIZER
13113                 (struct cmd_config_e_tag_result,
13114                  dst_pool, "dst-pool");
13115 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13116         TOKEN_NUM_INITIALIZER
13117                 (struct cmd_config_e_tag_result,
13118                  dst_pool_val, UINT8);
13119 cmdline_parse_token_string_t cmd_config_e_tag_port =
13120         TOKEN_STRING_INITIALIZER
13121                 (struct cmd_config_e_tag_result,
13122                  port, "port");
13123 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13124         TOKEN_NUM_INITIALIZER
13125                 (struct cmd_config_e_tag_result,
13126                  port_id, UINT16);
13127 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13128         TOKEN_STRING_INITIALIZER
13129                 (struct cmd_config_e_tag_result,
13130                  vf, "vf");
13131 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13132         TOKEN_NUM_INITIALIZER
13133                 (struct cmd_config_e_tag_result,
13134                  vf_id, UINT8);
13135
13136 /* E-tag insertion configuration */
13137 static void
13138 cmd_config_e_tag_insertion_en_parsed(
13139         void *parsed_result,
13140         __rte_unused struct cmdline *cl,
13141         __rte_unused void *data)
13142 {
13143         struct cmd_config_e_tag_result *res =
13144                 parsed_result;
13145         struct rte_eth_l2_tunnel_conf entry;
13146
13147         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13148                 return;
13149
13150         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13151         entry.tunnel_id = res->port_tag_id_val;
13152         entry.vf_id = res->vf_id;
13153         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13154                                           &entry,
13155                                           ETH_L2_TUNNEL_INSERTION_MASK,
13156                                           1);
13157 }
13158
13159 static void
13160 cmd_config_e_tag_insertion_dis_parsed(
13161         void *parsed_result,
13162         __rte_unused struct cmdline *cl,
13163         __rte_unused void *data)
13164 {
13165         struct cmd_config_e_tag_result *res =
13166                 parsed_result;
13167         struct rte_eth_l2_tunnel_conf entry;
13168
13169         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13170                 return;
13171
13172         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13173         entry.vf_id = res->vf_id;
13174
13175         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13176                                           &entry,
13177                                           ETH_L2_TUNNEL_INSERTION_MASK,
13178                                           0);
13179 }
13180
13181 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13182         .f = cmd_config_e_tag_insertion_en_parsed,
13183         .data = NULL,
13184         .help_str = "E-tag ... : E-tag insertion enable",
13185         .tokens = {
13186                 (void *)&cmd_config_e_tag_e_tag,
13187                 (void *)&cmd_config_e_tag_set,
13188                 (void *)&cmd_config_e_tag_insertion,
13189                 (void *)&cmd_config_e_tag_on,
13190                 (void *)&cmd_config_e_tag_port_tag_id,
13191                 (void *)&cmd_config_e_tag_port_tag_id_val,
13192                 (void *)&cmd_config_e_tag_port,
13193                 (void *)&cmd_config_e_tag_port_id,
13194                 (void *)&cmd_config_e_tag_vf,
13195                 (void *)&cmd_config_e_tag_vf_id,
13196                 NULL,
13197         },
13198 };
13199
13200 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13201         .f = cmd_config_e_tag_insertion_dis_parsed,
13202         .data = NULL,
13203         .help_str = "E-tag ... : E-tag insertion disable",
13204         .tokens = {
13205                 (void *)&cmd_config_e_tag_e_tag,
13206                 (void *)&cmd_config_e_tag_set,
13207                 (void *)&cmd_config_e_tag_insertion,
13208                 (void *)&cmd_config_e_tag_off,
13209                 (void *)&cmd_config_e_tag_port,
13210                 (void *)&cmd_config_e_tag_port_id,
13211                 (void *)&cmd_config_e_tag_vf,
13212                 (void *)&cmd_config_e_tag_vf_id,
13213                 NULL,
13214         },
13215 };
13216
13217 /* E-tag stripping configuration */
13218 static void
13219 cmd_config_e_tag_stripping_parsed(
13220         void *parsed_result,
13221         __rte_unused struct cmdline *cl,
13222         __rte_unused void *data)
13223 {
13224         struct cmd_config_e_tag_result *res =
13225                 parsed_result;
13226         struct rte_eth_l2_tunnel_conf entry;
13227
13228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13229                 return;
13230
13231         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13232
13233         if (!strcmp(res->on_off, "on"))
13234                 rte_eth_dev_l2_tunnel_offload_set
13235                         (res->port_id,
13236                          &entry,
13237                          ETH_L2_TUNNEL_STRIPPING_MASK,
13238                          1);
13239         else
13240                 rte_eth_dev_l2_tunnel_offload_set
13241                         (res->port_id,
13242                          &entry,
13243                          ETH_L2_TUNNEL_STRIPPING_MASK,
13244                          0);
13245 }
13246
13247 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13248         .f = cmd_config_e_tag_stripping_parsed,
13249         .data = NULL,
13250         .help_str = "E-tag ... : E-tag stripping enable/disable",
13251         .tokens = {
13252                 (void *)&cmd_config_e_tag_e_tag,
13253                 (void *)&cmd_config_e_tag_set,
13254                 (void *)&cmd_config_e_tag_stripping,
13255                 (void *)&cmd_config_e_tag_on_off,
13256                 (void *)&cmd_config_e_tag_port,
13257                 (void *)&cmd_config_e_tag_port_id,
13258                 NULL,
13259         },
13260 };
13261
13262 /* E-tag forwarding configuration */
13263 static void
13264 cmd_config_e_tag_forwarding_parsed(
13265         void *parsed_result,
13266         __rte_unused struct cmdline *cl,
13267         __rte_unused void *data)
13268 {
13269         struct cmd_config_e_tag_result *res = parsed_result;
13270         struct rte_eth_l2_tunnel_conf entry;
13271
13272         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13273                 return;
13274
13275         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13276
13277         if (!strcmp(res->on_off, "on"))
13278                 rte_eth_dev_l2_tunnel_offload_set
13279                         (res->port_id,
13280                          &entry,
13281                          ETH_L2_TUNNEL_FORWARDING_MASK,
13282                          1);
13283         else
13284                 rte_eth_dev_l2_tunnel_offload_set
13285                         (res->port_id,
13286                          &entry,
13287                          ETH_L2_TUNNEL_FORWARDING_MASK,
13288                          0);
13289 }
13290
13291 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13292         .f = cmd_config_e_tag_forwarding_parsed,
13293         .data = NULL,
13294         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13295         .tokens = {
13296                 (void *)&cmd_config_e_tag_e_tag,
13297                 (void *)&cmd_config_e_tag_set,
13298                 (void *)&cmd_config_e_tag_forwarding,
13299                 (void *)&cmd_config_e_tag_on_off,
13300                 (void *)&cmd_config_e_tag_port,
13301                 (void *)&cmd_config_e_tag_port_id,
13302                 NULL,
13303         },
13304 };
13305
13306 /* E-tag filter configuration */
13307 static void
13308 cmd_config_e_tag_filter_add_parsed(
13309         void *parsed_result,
13310         __rte_unused struct cmdline *cl,
13311         __rte_unused void *data)
13312 {
13313         struct cmd_config_e_tag_result *res = parsed_result;
13314         struct rte_eth_l2_tunnel_conf entry;
13315         int ret = 0;
13316
13317         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13318                 return;
13319
13320         if (res->e_tag_id_val > 0x3fff) {
13321                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13322                 return;
13323         }
13324
13325         ret = rte_eth_dev_filter_supported(res->port_id,
13326                                            RTE_ETH_FILTER_L2_TUNNEL);
13327         if (ret < 0) {
13328                 printf("E-tag filter is not supported on port %u.\n",
13329                        res->port_id);
13330                 return;
13331         }
13332
13333         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13334         entry.tunnel_id = res->e_tag_id_val;
13335         entry.pool = res->dst_pool_val;
13336
13337         ret = rte_eth_dev_filter_ctrl(res->port_id,
13338                                       RTE_ETH_FILTER_L2_TUNNEL,
13339                                       RTE_ETH_FILTER_ADD,
13340                                       &entry);
13341         if (ret < 0)
13342                 printf("E-tag filter programming error: (%s)\n",
13343                        strerror(-ret));
13344 }
13345
13346 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13347         .f = cmd_config_e_tag_filter_add_parsed,
13348         .data = NULL,
13349         .help_str = "E-tag ... : E-tag filter add",
13350         .tokens = {
13351                 (void *)&cmd_config_e_tag_e_tag,
13352                 (void *)&cmd_config_e_tag_set,
13353                 (void *)&cmd_config_e_tag_filter,
13354                 (void *)&cmd_config_e_tag_add,
13355                 (void *)&cmd_config_e_tag_e_tag_id,
13356                 (void *)&cmd_config_e_tag_e_tag_id_val,
13357                 (void *)&cmd_config_e_tag_dst_pool,
13358                 (void *)&cmd_config_e_tag_dst_pool_val,
13359                 (void *)&cmd_config_e_tag_port,
13360                 (void *)&cmd_config_e_tag_port_id,
13361                 NULL,
13362         },
13363 };
13364
13365 static void
13366 cmd_config_e_tag_filter_del_parsed(
13367         void *parsed_result,
13368         __rte_unused struct cmdline *cl,
13369         __rte_unused void *data)
13370 {
13371         struct cmd_config_e_tag_result *res = parsed_result;
13372         struct rte_eth_l2_tunnel_conf entry;
13373         int ret = 0;
13374
13375         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13376                 return;
13377
13378         if (res->e_tag_id_val > 0x3fff) {
13379                 printf("e-tag-id must be less than 0x3fff.\n");
13380                 return;
13381         }
13382
13383         ret = rte_eth_dev_filter_supported(res->port_id,
13384                                            RTE_ETH_FILTER_L2_TUNNEL);
13385         if (ret < 0) {
13386                 printf("E-tag filter is not supported on port %u.\n",
13387                        res->port_id);
13388                 return;
13389         }
13390
13391         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13392         entry.tunnel_id = res->e_tag_id_val;
13393
13394         ret = rte_eth_dev_filter_ctrl(res->port_id,
13395                                       RTE_ETH_FILTER_L2_TUNNEL,
13396                                       RTE_ETH_FILTER_DELETE,
13397                                       &entry);
13398         if (ret < 0)
13399                 printf("E-tag filter programming error: (%s)\n",
13400                        strerror(-ret));
13401 }
13402
13403 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13404         .f = cmd_config_e_tag_filter_del_parsed,
13405         .data = NULL,
13406         .help_str = "E-tag ... : E-tag filter delete",
13407         .tokens = {
13408                 (void *)&cmd_config_e_tag_e_tag,
13409                 (void *)&cmd_config_e_tag_set,
13410                 (void *)&cmd_config_e_tag_filter,
13411                 (void *)&cmd_config_e_tag_del,
13412                 (void *)&cmd_config_e_tag_e_tag_id,
13413                 (void *)&cmd_config_e_tag_e_tag_id_val,
13414                 (void *)&cmd_config_e_tag_port,
13415                 (void *)&cmd_config_e_tag_port_id,
13416                 NULL,
13417         },
13418 };
13419
13420 /* vf vlan anti spoof configuration */
13421
13422 /* Common result structure for vf vlan anti spoof */
13423 struct cmd_vf_vlan_anti_spoof_result {
13424         cmdline_fixed_string_t set;
13425         cmdline_fixed_string_t vf;
13426         cmdline_fixed_string_t vlan;
13427         cmdline_fixed_string_t antispoof;
13428         portid_t port_id;
13429         uint32_t vf_id;
13430         cmdline_fixed_string_t on_off;
13431 };
13432
13433 /* Common CLI fields for vf vlan anti spoof enable disable */
13434 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13435         TOKEN_STRING_INITIALIZER
13436                 (struct cmd_vf_vlan_anti_spoof_result,
13437                  set, "set");
13438 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13439         TOKEN_STRING_INITIALIZER
13440                 (struct cmd_vf_vlan_anti_spoof_result,
13441                  vf, "vf");
13442 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13443         TOKEN_STRING_INITIALIZER
13444                 (struct cmd_vf_vlan_anti_spoof_result,
13445                  vlan, "vlan");
13446 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13447         TOKEN_STRING_INITIALIZER
13448                 (struct cmd_vf_vlan_anti_spoof_result,
13449                  antispoof, "antispoof");
13450 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13451         TOKEN_NUM_INITIALIZER
13452                 (struct cmd_vf_vlan_anti_spoof_result,
13453                  port_id, UINT16);
13454 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13455         TOKEN_NUM_INITIALIZER
13456                 (struct cmd_vf_vlan_anti_spoof_result,
13457                  vf_id, UINT32);
13458 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13459         TOKEN_STRING_INITIALIZER
13460                 (struct cmd_vf_vlan_anti_spoof_result,
13461                  on_off, "on#off");
13462
13463 static void
13464 cmd_set_vf_vlan_anti_spoof_parsed(
13465         void *parsed_result,
13466         __rte_unused struct cmdline *cl,
13467         __rte_unused void *data)
13468 {
13469         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13470         int ret = -ENOTSUP;
13471
13472         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13473
13474         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13475                 return;
13476
13477 #ifdef RTE_LIBRTE_IXGBE_PMD
13478         if (ret == -ENOTSUP)
13479                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13480                                 res->vf_id, is_on);
13481 #endif
13482 #ifdef RTE_LIBRTE_I40E_PMD
13483         if (ret == -ENOTSUP)
13484                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13485                                 res->vf_id, is_on);
13486 #endif
13487 #ifdef RTE_LIBRTE_BNXT_PMD
13488         if (ret == -ENOTSUP)
13489                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13490                                 res->vf_id, is_on);
13491 #endif
13492
13493         switch (ret) {
13494         case 0:
13495                 break;
13496         case -EINVAL:
13497                 printf("invalid vf_id %d\n", res->vf_id);
13498                 break;
13499         case -ENODEV:
13500                 printf("invalid port_id %d\n", res->port_id);
13501                 break;
13502         case -ENOTSUP:
13503                 printf("function not implemented\n");
13504                 break;
13505         default:
13506                 printf("programming error: (%s)\n", strerror(-ret));
13507         }
13508 }
13509
13510 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13511         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13512         .data = NULL,
13513         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13514         .tokens = {
13515                 (void *)&cmd_vf_vlan_anti_spoof_set,
13516                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13517                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13518                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13519                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13520                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13521                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13522                 NULL,
13523         },
13524 };
13525
13526 /* vf mac anti spoof configuration */
13527
13528 /* Common result structure for vf mac anti spoof */
13529 struct cmd_vf_mac_anti_spoof_result {
13530         cmdline_fixed_string_t set;
13531         cmdline_fixed_string_t vf;
13532         cmdline_fixed_string_t mac;
13533         cmdline_fixed_string_t antispoof;
13534         portid_t port_id;
13535         uint32_t vf_id;
13536         cmdline_fixed_string_t on_off;
13537 };
13538
13539 /* Common CLI fields for vf mac anti spoof enable disable */
13540 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13541         TOKEN_STRING_INITIALIZER
13542                 (struct cmd_vf_mac_anti_spoof_result,
13543                  set, "set");
13544 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13545         TOKEN_STRING_INITIALIZER
13546                 (struct cmd_vf_mac_anti_spoof_result,
13547                  vf, "vf");
13548 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13549         TOKEN_STRING_INITIALIZER
13550                 (struct cmd_vf_mac_anti_spoof_result,
13551                  mac, "mac");
13552 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13553         TOKEN_STRING_INITIALIZER
13554                 (struct cmd_vf_mac_anti_spoof_result,
13555                  antispoof, "antispoof");
13556 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13557         TOKEN_NUM_INITIALIZER
13558                 (struct cmd_vf_mac_anti_spoof_result,
13559                  port_id, UINT16);
13560 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13561         TOKEN_NUM_INITIALIZER
13562                 (struct cmd_vf_mac_anti_spoof_result,
13563                  vf_id, UINT32);
13564 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13565         TOKEN_STRING_INITIALIZER
13566                 (struct cmd_vf_mac_anti_spoof_result,
13567                  on_off, "on#off");
13568
13569 static void
13570 cmd_set_vf_mac_anti_spoof_parsed(
13571         void *parsed_result,
13572         __rte_unused struct cmdline *cl,
13573         __rte_unused void *data)
13574 {
13575         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13576         int ret = -ENOTSUP;
13577
13578         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13579
13580         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13581                 return;
13582
13583 #ifdef RTE_LIBRTE_IXGBE_PMD
13584         if (ret == -ENOTSUP)
13585                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13586                         res->vf_id, is_on);
13587 #endif
13588 #ifdef RTE_LIBRTE_I40E_PMD
13589         if (ret == -ENOTSUP)
13590                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13591                         res->vf_id, is_on);
13592 #endif
13593 #ifdef RTE_LIBRTE_BNXT_PMD
13594         if (ret == -ENOTSUP)
13595                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13596                         res->vf_id, is_on);
13597 #endif
13598
13599         switch (ret) {
13600         case 0:
13601                 break;
13602         case -EINVAL:
13603                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13604                 break;
13605         case -ENODEV:
13606                 printf("invalid port_id %d\n", res->port_id);
13607                 break;
13608         case -ENOTSUP:
13609                 printf("function not implemented\n");
13610                 break;
13611         default:
13612                 printf("programming error: (%s)\n", strerror(-ret));
13613         }
13614 }
13615
13616 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13617         .f = cmd_set_vf_mac_anti_spoof_parsed,
13618         .data = NULL,
13619         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13620         .tokens = {
13621                 (void *)&cmd_vf_mac_anti_spoof_set,
13622                 (void *)&cmd_vf_mac_anti_spoof_vf,
13623                 (void *)&cmd_vf_mac_anti_spoof_mac,
13624                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13625                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13626                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13627                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13628                 NULL,
13629         },
13630 };
13631
13632 /* vf vlan strip queue configuration */
13633
13634 /* Common result structure for vf mac anti spoof */
13635 struct cmd_vf_vlan_stripq_result {
13636         cmdline_fixed_string_t set;
13637         cmdline_fixed_string_t vf;
13638         cmdline_fixed_string_t vlan;
13639         cmdline_fixed_string_t stripq;
13640         portid_t port_id;
13641         uint16_t vf_id;
13642         cmdline_fixed_string_t on_off;
13643 };
13644
13645 /* Common CLI fields for vf vlan strip enable disable */
13646 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13647         TOKEN_STRING_INITIALIZER
13648                 (struct cmd_vf_vlan_stripq_result,
13649                  set, "set");
13650 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13651         TOKEN_STRING_INITIALIZER
13652                 (struct cmd_vf_vlan_stripq_result,
13653                  vf, "vf");
13654 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_vf_vlan_stripq_result,
13657                  vlan, "vlan");
13658 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13659         TOKEN_STRING_INITIALIZER
13660                 (struct cmd_vf_vlan_stripq_result,
13661                  stripq, "stripq");
13662 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13663         TOKEN_NUM_INITIALIZER
13664                 (struct cmd_vf_vlan_stripq_result,
13665                  port_id, UINT16);
13666 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13667         TOKEN_NUM_INITIALIZER
13668                 (struct cmd_vf_vlan_stripq_result,
13669                  vf_id, UINT16);
13670 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13671         TOKEN_STRING_INITIALIZER
13672                 (struct cmd_vf_vlan_stripq_result,
13673                  on_off, "on#off");
13674
13675 static void
13676 cmd_set_vf_vlan_stripq_parsed(
13677         void *parsed_result,
13678         __rte_unused struct cmdline *cl,
13679         __rte_unused void *data)
13680 {
13681         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13682         int ret = -ENOTSUP;
13683
13684         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13685
13686         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13687                 return;
13688
13689 #ifdef RTE_LIBRTE_IXGBE_PMD
13690         if (ret == -ENOTSUP)
13691                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13692                         res->vf_id, is_on);
13693 #endif
13694 #ifdef RTE_LIBRTE_I40E_PMD
13695         if (ret == -ENOTSUP)
13696                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13697                         res->vf_id, is_on);
13698 #endif
13699 #ifdef RTE_LIBRTE_BNXT_PMD
13700         if (ret == -ENOTSUP)
13701                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13702                         res->vf_id, is_on);
13703 #endif
13704
13705         switch (ret) {
13706         case 0:
13707                 break;
13708         case -EINVAL:
13709                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13710                 break;
13711         case -ENODEV:
13712                 printf("invalid port_id %d\n", res->port_id);
13713                 break;
13714         case -ENOTSUP:
13715                 printf("function not implemented\n");
13716                 break;
13717         default:
13718                 printf("programming error: (%s)\n", strerror(-ret));
13719         }
13720 }
13721
13722 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13723         .f = cmd_set_vf_vlan_stripq_parsed,
13724         .data = NULL,
13725         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13726         .tokens = {
13727                 (void *)&cmd_vf_vlan_stripq_set,
13728                 (void *)&cmd_vf_vlan_stripq_vf,
13729                 (void *)&cmd_vf_vlan_stripq_vlan,
13730                 (void *)&cmd_vf_vlan_stripq_stripq,
13731                 (void *)&cmd_vf_vlan_stripq_port_id,
13732                 (void *)&cmd_vf_vlan_stripq_vf_id,
13733                 (void *)&cmd_vf_vlan_stripq_on_off,
13734                 NULL,
13735         },
13736 };
13737
13738 /* vf vlan insert configuration */
13739
13740 /* Common result structure for vf vlan insert */
13741 struct cmd_vf_vlan_insert_result {
13742         cmdline_fixed_string_t set;
13743         cmdline_fixed_string_t vf;
13744         cmdline_fixed_string_t vlan;
13745         cmdline_fixed_string_t insert;
13746         portid_t port_id;
13747         uint16_t vf_id;
13748         uint16_t vlan_id;
13749 };
13750
13751 /* Common CLI fields for vf vlan insert enable disable */
13752 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13753         TOKEN_STRING_INITIALIZER
13754                 (struct cmd_vf_vlan_insert_result,
13755                  set, "set");
13756 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13757         TOKEN_STRING_INITIALIZER
13758                 (struct cmd_vf_vlan_insert_result,
13759                  vf, "vf");
13760 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13761         TOKEN_STRING_INITIALIZER
13762                 (struct cmd_vf_vlan_insert_result,
13763                  vlan, "vlan");
13764 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13765         TOKEN_STRING_INITIALIZER
13766                 (struct cmd_vf_vlan_insert_result,
13767                  insert, "insert");
13768 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13769         TOKEN_NUM_INITIALIZER
13770                 (struct cmd_vf_vlan_insert_result,
13771                  port_id, UINT16);
13772 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13773         TOKEN_NUM_INITIALIZER
13774                 (struct cmd_vf_vlan_insert_result,
13775                  vf_id, UINT16);
13776 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13777         TOKEN_NUM_INITIALIZER
13778                 (struct cmd_vf_vlan_insert_result,
13779                  vlan_id, UINT16);
13780
13781 static void
13782 cmd_set_vf_vlan_insert_parsed(
13783         void *parsed_result,
13784         __rte_unused struct cmdline *cl,
13785         __rte_unused void *data)
13786 {
13787         struct cmd_vf_vlan_insert_result *res = parsed_result;
13788         int ret = -ENOTSUP;
13789
13790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13791                 return;
13792
13793 #ifdef RTE_LIBRTE_IXGBE_PMD
13794         if (ret == -ENOTSUP)
13795                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13796                         res->vlan_id);
13797 #endif
13798 #ifdef RTE_LIBRTE_I40E_PMD
13799         if (ret == -ENOTSUP)
13800                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13801                         res->vlan_id);
13802 #endif
13803 #ifdef RTE_LIBRTE_BNXT_PMD
13804         if (ret == -ENOTSUP)
13805                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13806                         res->vlan_id);
13807 #endif
13808
13809         switch (ret) {
13810         case 0:
13811                 break;
13812         case -EINVAL:
13813                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13814                 break;
13815         case -ENODEV:
13816                 printf("invalid port_id %d\n", res->port_id);
13817                 break;
13818         case -ENOTSUP:
13819                 printf("function not implemented\n");
13820                 break;
13821         default:
13822                 printf("programming error: (%s)\n", strerror(-ret));
13823         }
13824 }
13825
13826 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13827         .f = cmd_set_vf_vlan_insert_parsed,
13828         .data = NULL,
13829         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13830         .tokens = {
13831                 (void *)&cmd_vf_vlan_insert_set,
13832                 (void *)&cmd_vf_vlan_insert_vf,
13833                 (void *)&cmd_vf_vlan_insert_vlan,
13834                 (void *)&cmd_vf_vlan_insert_insert,
13835                 (void *)&cmd_vf_vlan_insert_port_id,
13836                 (void *)&cmd_vf_vlan_insert_vf_id,
13837                 (void *)&cmd_vf_vlan_insert_vlan_id,
13838                 NULL,
13839         },
13840 };
13841
13842 /* tx loopback configuration */
13843
13844 /* Common result structure for tx loopback */
13845 struct cmd_tx_loopback_result {
13846         cmdline_fixed_string_t set;
13847         cmdline_fixed_string_t tx;
13848         cmdline_fixed_string_t loopback;
13849         portid_t port_id;
13850         cmdline_fixed_string_t on_off;
13851 };
13852
13853 /* Common CLI fields for tx loopback enable disable */
13854 cmdline_parse_token_string_t cmd_tx_loopback_set =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_tx_loopback_result,
13857                  set, "set");
13858 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_tx_loopback_result,
13861                  tx, "tx");
13862 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_tx_loopback_result,
13865                  loopback, "loopback");
13866 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13867         TOKEN_NUM_INITIALIZER
13868                 (struct cmd_tx_loopback_result,
13869                  port_id, UINT16);
13870 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13871         TOKEN_STRING_INITIALIZER
13872                 (struct cmd_tx_loopback_result,
13873                  on_off, "on#off");
13874
13875 static void
13876 cmd_set_tx_loopback_parsed(
13877         void *parsed_result,
13878         __rte_unused struct cmdline *cl,
13879         __rte_unused void *data)
13880 {
13881         struct cmd_tx_loopback_result *res = parsed_result;
13882         int ret = -ENOTSUP;
13883
13884         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13885
13886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13887                 return;
13888
13889 #ifdef RTE_LIBRTE_IXGBE_PMD
13890         if (ret == -ENOTSUP)
13891                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13892 #endif
13893 #ifdef RTE_LIBRTE_I40E_PMD
13894         if (ret == -ENOTSUP)
13895                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13896 #endif
13897 #ifdef RTE_LIBRTE_BNXT_PMD
13898         if (ret == -ENOTSUP)
13899                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13900 #endif
13901 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13902         if (ret == -ENOTSUP)
13903                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13904 #endif
13905
13906         switch (ret) {
13907         case 0:
13908                 break;
13909         case -EINVAL:
13910                 printf("invalid is_on %d\n", is_on);
13911                 break;
13912         case -ENODEV:
13913                 printf("invalid port_id %d\n", res->port_id);
13914                 break;
13915         case -ENOTSUP:
13916                 printf("function not implemented\n");
13917                 break;
13918         default:
13919                 printf("programming error: (%s)\n", strerror(-ret));
13920         }
13921 }
13922
13923 cmdline_parse_inst_t cmd_set_tx_loopback = {
13924         .f = cmd_set_tx_loopback_parsed,
13925         .data = NULL,
13926         .help_str = "set tx loopback <port_id> on|off",
13927         .tokens = {
13928                 (void *)&cmd_tx_loopback_set,
13929                 (void *)&cmd_tx_loopback_tx,
13930                 (void *)&cmd_tx_loopback_loopback,
13931                 (void *)&cmd_tx_loopback_port_id,
13932                 (void *)&cmd_tx_loopback_on_off,
13933                 NULL,
13934         },
13935 };
13936
13937 /* all queues drop enable configuration */
13938
13939 /* Common result structure for all queues drop enable */
13940 struct cmd_all_queues_drop_en_result {
13941         cmdline_fixed_string_t set;
13942         cmdline_fixed_string_t all;
13943         cmdline_fixed_string_t queues;
13944         cmdline_fixed_string_t drop;
13945         portid_t port_id;
13946         cmdline_fixed_string_t on_off;
13947 };
13948
13949 /* Common CLI fields for tx loopback enable disable */
13950 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13951         TOKEN_STRING_INITIALIZER
13952                 (struct cmd_all_queues_drop_en_result,
13953                  set, "set");
13954 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13955         TOKEN_STRING_INITIALIZER
13956                 (struct cmd_all_queues_drop_en_result,
13957                  all, "all");
13958 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13959         TOKEN_STRING_INITIALIZER
13960                 (struct cmd_all_queues_drop_en_result,
13961                  queues, "queues");
13962 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13963         TOKEN_STRING_INITIALIZER
13964                 (struct cmd_all_queues_drop_en_result,
13965                  drop, "drop");
13966 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13967         TOKEN_NUM_INITIALIZER
13968                 (struct cmd_all_queues_drop_en_result,
13969                  port_id, UINT16);
13970 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13971         TOKEN_STRING_INITIALIZER
13972                 (struct cmd_all_queues_drop_en_result,
13973                  on_off, "on#off");
13974
13975 static void
13976 cmd_set_all_queues_drop_en_parsed(
13977         void *parsed_result,
13978         __rte_unused struct cmdline *cl,
13979         __rte_unused void *data)
13980 {
13981         struct cmd_all_queues_drop_en_result *res = parsed_result;
13982         int ret = -ENOTSUP;
13983         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13984
13985         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13986                 return;
13987
13988 #ifdef RTE_LIBRTE_IXGBE_PMD
13989         if (ret == -ENOTSUP)
13990                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
13991 #endif
13992 #ifdef RTE_LIBRTE_BNXT_PMD
13993         if (ret == -ENOTSUP)
13994                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
13995 #endif
13996         switch (ret) {
13997         case 0:
13998                 break;
13999         case -EINVAL:
14000                 printf("invalid is_on %d\n", is_on);
14001                 break;
14002         case -ENODEV:
14003                 printf("invalid port_id %d\n", res->port_id);
14004                 break;
14005         case -ENOTSUP:
14006                 printf("function not implemented\n");
14007                 break;
14008         default:
14009                 printf("programming error: (%s)\n", strerror(-ret));
14010         }
14011 }
14012
14013 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14014         .f = cmd_set_all_queues_drop_en_parsed,
14015         .data = NULL,
14016         .help_str = "set all queues drop <port_id> on|off",
14017         .tokens = {
14018                 (void *)&cmd_all_queues_drop_en_set,
14019                 (void *)&cmd_all_queues_drop_en_all,
14020                 (void *)&cmd_all_queues_drop_en_queues,
14021                 (void *)&cmd_all_queues_drop_en_drop,
14022                 (void *)&cmd_all_queues_drop_en_port_id,
14023                 (void *)&cmd_all_queues_drop_en_on_off,
14024                 NULL,
14025         },
14026 };
14027
14028 /* vf split drop enable configuration */
14029
14030 /* Common result structure for vf split drop enable */
14031 struct cmd_vf_split_drop_en_result {
14032         cmdline_fixed_string_t set;
14033         cmdline_fixed_string_t vf;
14034         cmdline_fixed_string_t split;
14035         cmdline_fixed_string_t drop;
14036         portid_t port_id;
14037         uint16_t vf_id;
14038         cmdline_fixed_string_t on_off;
14039 };
14040
14041 /* Common CLI fields for vf split drop enable disable */
14042 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14043         TOKEN_STRING_INITIALIZER
14044                 (struct cmd_vf_split_drop_en_result,
14045                  set, "set");
14046 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14047         TOKEN_STRING_INITIALIZER
14048                 (struct cmd_vf_split_drop_en_result,
14049                  vf, "vf");
14050 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14051         TOKEN_STRING_INITIALIZER
14052                 (struct cmd_vf_split_drop_en_result,
14053                  split, "split");
14054 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14055         TOKEN_STRING_INITIALIZER
14056                 (struct cmd_vf_split_drop_en_result,
14057                  drop, "drop");
14058 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14059         TOKEN_NUM_INITIALIZER
14060                 (struct cmd_vf_split_drop_en_result,
14061                  port_id, UINT16);
14062 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14063         TOKEN_NUM_INITIALIZER
14064                 (struct cmd_vf_split_drop_en_result,
14065                  vf_id, UINT16);
14066 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14067         TOKEN_STRING_INITIALIZER
14068                 (struct cmd_vf_split_drop_en_result,
14069                  on_off, "on#off");
14070
14071 static void
14072 cmd_set_vf_split_drop_en_parsed(
14073         void *parsed_result,
14074         __rte_unused struct cmdline *cl,
14075         __rte_unused void *data)
14076 {
14077         struct cmd_vf_split_drop_en_result *res = parsed_result;
14078         int ret = -ENOTSUP;
14079         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14080
14081         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14082                 return;
14083
14084 #ifdef RTE_LIBRTE_IXGBE_PMD
14085         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14086                         is_on);
14087 #endif
14088         switch (ret) {
14089         case 0:
14090                 break;
14091         case -EINVAL:
14092                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14093                 break;
14094         case -ENODEV:
14095                 printf("invalid port_id %d\n", res->port_id);
14096                 break;
14097         case -ENOTSUP:
14098                 printf("not supported on port %d\n", res->port_id);
14099                 break;
14100         default:
14101                 printf("programming error: (%s)\n", strerror(-ret));
14102         }
14103 }
14104
14105 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14106         .f = cmd_set_vf_split_drop_en_parsed,
14107         .data = NULL,
14108         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14109         .tokens = {
14110                 (void *)&cmd_vf_split_drop_en_set,
14111                 (void *)&cmd_vf_split_drop_en_vf,
14112                 (void *)&cmd_vf_split_drop_en_split,
14113                 (void *)&cmd_vf_split_drop_en_drop,
14114                 (void *)&cmd_vf_split_drop_en_port_id,
14115                 (void *)&cmd_vf_split_drop_en_vf_id,
14116                 (void *)&cmd_vf_split_drop_en_on_off,
14117                 NULL,
14118         },
14119 };
14120
14121 /* vf mac address configuration */
14122
14123 /* Common result structure for vf mac address */
14124 struct cmd_set_vf_mac_addr_result {
14125         cmdline_fixed_string_t set;
14126         cmdline_fixed_string_t vf;
14127         cmdline_fixed_string_t mac;
14128         cmdline_fixed_string_t addr;
14129         portid_t port_id;
14130         uint16_t vf_id;
14131         struct rte_ether_addr mac_addr;
14132
14133 };
14134
14135 /* Common CLI fields for vf split drop enable disable */
14136 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14137         TOKEN_STRING_INITIALIZER
14138                 (struct cmd_set_vf_mac_addr_result,
14139                  set, "set");
14140 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14141         TOKEN_STRING_INITIALIZER
14142                 (struct cmd_set_vf_mac_addr_result,
14143                  vf, "vf");
14144 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14145         TOKEN_STRING_INITIALIZER
14146                 (struct cmd_set_vf_mac_addr_result,
14147                  mac, "mac");
14148 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14149         TOKEN_STRING_INITIALIZER
14150                 (struct cmd_set_vf_mac_addr_result,
14151                  addr, "addr");
14152 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14153         TOKEN_NUM_INITIALIZER
14154                 (struct cmd_set_vf_mac_addr_result,
14155                  port_id, UINT16);
14156 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14157         TOKEN_NUM_INITIALIZER
14158                 (struct cmd_set_vf_mac_addr_result,
14159                  vf_id, UINT16);
14160 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14161         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14162                  mac_addr);
14163
14164 static void
14165 cmd_set_vf_mac_addr_parsed(
14166         void *parsed_result,
14167         __rte_unused struct cmdline *cl,
14168         __rte_unused void *data)
14169 {
14170         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14171         int ret = -ENOTSUP;
14172
14173         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14174                 return;
14175
14176 #ifdef RTE_LIBRTE_IXGBE_PMD
14177         if (ret == -ENOTSUP)
14178                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14179                                 &res->mac_addr);
14180 #endif
14181 #ifdef RTE_LIBRTE_I40E_PMD
14182         if (ret == -ENOTSUP)
14183                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14184                                 &res->mac_addr);
14185 #endif
14186 #ifdef RTE_LIBRTE_BNXT_PMD
14187         if (ret == -ENOTSUP)
14188                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14189                                 &res->mac_addr);
14190 #endif
14191
14192         switch (ret) {
14193         case 0:
14194                 break;
14195         case -EINVAL:
14196                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14197                 break;
14198         case -ENODEV:
14199                 printf("invalid port_id %d\n", res->port_id);
14200                 break;
14201         case -ENOTSUP:
14202                 printf("function not implemented\n");
14203                 break;
14204         default:
14205                 printf("programming error: (%s)\n", strerror(-ret));
14206         }
14207 }
14208
14209 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14210         .f = cmd_set_vf_mac_addr_parsed,
14211         .data = NULL,
14212         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14213         .tokens = {
14214                 (void *)&cmd_set_vf_mac_addr_set,
14215                 (void *)&cmd_set_vf_mac_addr_vf,
14216                 (void *)&cmd_set_vf_mac_addr_mac,
14217                 (void *)&cmd_set_vf_mac_addr_addr,
14218                 (void *)&cmd_set_vf_mac_addr_port_id,
14219                 (void *)&cmd_set_vf_mac_addr_vf_id,
14220                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14221                 NULL,
14222         },
14223 };
14224
14225 /* MACsec configuration */
14226
14227 /* Common result structure for MACsec offload enable */
14228 struct cmd_macsec_offload_on_result {
14229         cmdline_fixed_string_t set;
14230         cmdline_fixed_string_t macsec;
14231         cmdline_fixed_string_t offload;
14232         portid_t port_id;
14233         cmdline_fixed_string_t on;
14234         cmdline_fixed_string_t encrypt;
14235         cmdline_fixed_string_t en_on_off;
14236         cmdline_fixed_string_t replay_protect;
14237         cmdline_fixed_string_t rp_on_off;
14238 };
14239
14240 /* Common CLI fields for MACsec offload disable */
14241 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14242         TOKEN_STRING_INITIALIZER
14243                 (struct cmd_macsec_offload_on_result,
14244                  set, "set");
14245 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14246         TOKEN_STRING_INITIALIZER
14247                 (struct cmd_macsec_offload_on_result,
14248                  macsec, "macsec");
14249 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14250         TOKEN_STRING_INITIALIZER
14251                 (struct cmd_macsec_offload_on_result,
14252                  offload, "offload");
14253 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14254         TOKEN_NUM_INITIALIZER
14255                 (struct cmd_macsec_offload_on_result,
14256                  port_id, UINT16);
14257 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14258         TOKEN_STRING_INITIALIZER
14259                 (struct cmd_macsec_offload_on_result,
14260                  on, "on");
14261 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14262         TOKEN_STRING_INITIALIZER
14263                 (struct cmd_macsec_offload_on_result,
14264                  encrypt, "encrypt");
14265 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14266         TOKEN_STRING_INITIALIZER
14267                 (struct cmd_macsec_offload_on_result,
14268                  en_on_off, "on#off");
14269 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14270         TOKEN_STRING_INITIALIZER
14271                 (struct cmd_macsec_offload_on_result,
14272                  replay_protect, "replay-protect");
14273 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14274         TOKEN_STRING_INITIALIZER
14275                 (struct cmd_macsec_offload_on_result,
14276                  rp_on_off, "on#off");
14277
14278 static void
14279 cmd_set_macsec_offload_on_parsed(
14280         void *parsed_result,
14281         __rte_unused struct cmdline *cl,
14282         __rte_unused void *data)
14283 {
14284         struct cmd_macsec_offload_on_result *res = parsed_result;
14285         int ret = -ENOTSUP;
14286         portid_t port_id = res->port_id;
14287         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14288         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14289         struct rte_eth_dev_info dev_info;
14290
14291         if (port_id_is_invalid(port_id, ENABLED_WARN))
14292                 return;
14293         if (!port_is_stopped(port_id)) {
14294                 printf("Please stop port %d first\n", port_id);
14295                 return;
14296         }
14297
14298         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14299         if (ret != 0)
14300                 return;
14301
14302         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14303 #ifdef RTE_LIBRTE_IXGBE_PMD
14304                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14305 #endif
14306         }
14307         RTE_SET_USED(en);
14308         RTE_SET_USED(rp);
14309
14310         switch (ret) {
14311         case 0:
14312                 ports[port_id].dev_conf.txmode.offloads |=
14313                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14314                 cmd_reconfig_device_queue(port_id, 1, 1);
14315                 break;
14316         case -ENODEV:
14317                 printf("invalid port_id %d\n", port_id);
14318                 break;
14319         case -ENOTSUP:
14320                 printf("not supported on port %d\n", port_id);
14321                 break;
14322         default:
14323                 printf("programming error: (%s)\n", strerror(-ret));
14324         }
14325 }
14326
14327 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14328         .f = cmd_set_macsec_offload_on_parsed,
14329         .data = NULL,
14330         .help_str = "set macsec offload <port_id> on "
14331                 "encrypt on|off replay-protect on|off",
14332         .tokens = {
14333                 (void *)&cmd_macsec_offload_on_set,
14334                 (void *)&cmd_macsec_offload_on_macsec,
14335                 (void *)&cmd_macsec_offload_on_offload,
14336                 (void *)&cmd_macsec_offload_on_port_id,
14337                 (void *)&cmd_macsec_offload_on_on,
14338                 (void *)&cmd_macsec_offload_on_encrypt,
14339                 (void *)&cmd_macsec_offload_on_en_on_off,
14340                 (void *)&cmd_macsec_offload_on_replay_protect,
14341                 (void *)&cmd_macsec_offload_on_rp_on_off,
14342                 NULL,
14343         },
14344 };
14345
14346 /* Common result structure for MACsec offload disable */
14347 struct cmd_macsec_offload_off_result {
14348         cmdline_fixed_string_t set;
14349         cmdline_fixed_string_t macsec;
14350         cmdline_fixed_string_t offload;
14351         portid_t port_id;
14352         cmdline_fixed_string_t off;
14353 };
14354
14355 /* Common CLI fields for MACsec offload disable */
14356 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14357         TOKEN_STRING_INITIALIZER
14358                 (struct cmd_macsec_offload_off_result,
14359                  set, "set");
14360 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14361         TOKEN_STRING_INITIALIZER
14362                 (struct cmd_macsec_offload_off_result,
14363                  macsec, "macsec");
14364 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14365         TOKEN_STRING_INITIALIZER
14366                 (struct cmd_macsec_offload_off_result,
14367                  offload, "offload");
14368 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14369         TOKEN_NUM_INITIALIZER
14370                 (struct cmd_macsec_offload_off_result,
14371                  port_id, UINT16);
14372 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14373         TOKEN_STRING_INITIALIZER
14374                 (struct cmd_macsec_offload_off_result,
14375                  off, "off");
14376
14377 static void
14378 cmd_set_macsec_offload_off_parsed(
14379         void *parsed_result,
14380         __rte_unused struct cmdline *cl,
14381         __rte_unused void *data)
14382 {
14383         struct cmd_macsec_offload_off_result *res = parsed_result;
14384         int ret = -ENOTSUP;
14385         struct rte_eth_dev_info dev_info;
14386         portid_t port_id = res->port_id;
14387
14388         if (port_id_is_invalid(port_id, ENABLED_WARN))
14389                 return;
14390         if (!port_is_stopped(port_id)) {
14391                 printf("Please stop port %d first\n", port_id);
14392                 return;
14393         }
14394
14395         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14396         if (ret != 0)
14397                 return;
14398
14399         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14400 #ifdef RTE_LIBRTE_IXGBE_PMD
14401                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14402 #endif
14403         }
14404         switch (ret) {
14405         case 0:
14406                 ports[port_id].dev_conf.txmode.offloads &=
14407                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14408                 cmd_reconfig_device_queue(port_id, 1, 1);
14409                 break;
14410         case -ENODEV:
14411                 printf("invalid port_id %d\n", port_id);
14412                 break;
14413         case -ENOTSUP:
14414                 printf("not supported on port %d\n", port_id);
14415                 break;
14416         default:
14417                 printf("programming error: (%s)\n", strerror(-ret));
14418         }
14419 }
14420
14421 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14422         .f = cmd_set_macsec_offload_off_parsed,
14423         .data = NULL,
14424         .help_str = "set macsec offload <port_id> off",
14425         .tokens = {
14426                 (void *)&cmd_macsec_offload_off_set,
14427                 (void *)&cmd_macsec_offload_off_macsec,
14428                 (void *)&cmd_macsec_offload_off_offload,
14429                 (void *)&cmd_macsec_offload_off_port_id,
14430                 (void *)&cmd_macsec_offload_off_off,
14431                 NULL,
14432         },
14433 };
14434
14435 /* Common result structure for MACsec secure connection configure */
14436 struct cmd_macsec_sc_result {
14437         cmdline_fixed_string_t set;
14438         cmdline_fixed_string_t macsec;
14439         cmdline_fixed_string_t sc;
14440         cmdline_fixed_string_t tx_rx;
14441         portid_t port_id;
14442         struct rte_ether_addr mac;
14443         uint16_t pi;
14444 };
14445
14446 /* Common CLI fields for MACsec secure connection configure */
14447 cmdline_parse_token_string_t cmd_macsec_sc_set =
14448         TOKEN_STRING_INITIALIZER
14449                 (struct cmd_macsec_sc_result,
14450                  set, "set");
14451 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14452         TOKEN_STRING_INITIALIZER
14453                 (struct cmd_macsec_sc_result,
14454                  macsec, "macsec");
14455 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14456         TOKEN_STRING_INITIALIZER
14457                 (struct cmd_macsec_sc_result,
14458                  sc, "sc");
14459 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14460         TOKEN_STRING_INITIALIZER
14461                 (struct cmd_macsec_sc_result,
14462                  tx_rx, "tx#rx");
14463 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14464         TOKEN_NUM_INITIALIZER
14465                 (struct cmd_macsec_sc_result,
14466                  port_id, UINT16);
14467 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14468         TOKEN_ETHERADDR_INITIALIZER
14469                 (struct cmd_macsec_sc_result,
14470                  mac);
14471 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14472         TOKEN_NUM_INITIALIZER
14473                 (struct cmd_macsec_sc_result,
14474                  pi, UINT16);
14475
14476 static void
14477 cmd_set_macsec_sc_parsed(
14478         void *parsed_result,
14479         __rte_unused struct cmdline *cl,
14480         __rte_unused void *data)
14481 {
14482         struct cmd_macsec_sc_result *res = parsed_result;
14483         int ret = -ENOTSUP;
14484         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14485
14486 #ifdef RTE_LIBRTE_IXGBE_PMD
14487         ret = is_tx ?
14488                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14489                                 res->mac.addr_bytes) :
14490                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14491                                 res->mac.addr_bytes, res->pi);
14492 #endif
14493         RTE_SET_USED(is_tx);
14494
14495         switch (ret) {
14496         case 0:
14497                 break;
14498         case -ENODEV:
14499                 printf("invalid port_id %d\n", res->port_id);
14500                 break;
14501         case -ENOTSUP:
14502                 printf("not supported on port %d\n", res->port_id);
14503                 break;
14504         default:
14505                 printf("programming error: (%s)\n", strerror(-ret));
14506         }
14507 }
14508
14509 cmdline_parse_inst_t cmd_set_macsec_sc = {
14510         .f = cmd_set_macsec_sc_parsed,
14511         .data = NULL,
14512         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14513         .tokens = {
14514                 (void *)&cmd_macsec_sc_set,
14515                 (void *)&cmd_macsec_sc_macsec,
14516                 (void *)&cmd_macsec_sc_sc,
14517                 (void *)&cmd_macsec_sc_tx_rx,
14518                 (void *)&cmd_macsec_sc_port_id,
14519                 (void *)&cmd_macsec_sc_mac,
14520                 (void *)&cmd_macsec_sc_pi,
14521                 NULL,
14522         },
14523 };
14524
14525 /* Common result structure for MACsec secure connection configure */
14526 struct cmd_macsec_sa_result {
14527         cmdline_fixed_string_t set;
14528         cmdline_fixed_string_t macsec;
14529         cmdline_fixed_string_t sa;
14530         cmdline_fixed_string_t tx_rx;
14531         portid_t port_id;
14532         uint8_t idx;
14533         uint8_t an;
14534         uint32_t pn;
14535         cmdline_fixed_string_t key;
14536 };
14537
14538 /* Common CLI fields for MACsec secure connection configure */
14539 cmdline_parse_token_string_t cmd_macsec_sa_set =
14540         TOKEN_STRING_INITIALIZER
14541                 (struct cmd_macsec_sa_result,
14542                  set, "set");
14543 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14544         TOKEN_STRING_INITIALIZER
14545                 (struct cmd_macsec_sa_result,
14546                  macsec, "macsec");
14547 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14548         TOKEN_STRING_INITIALIZER
14549                 (struct cmd_macsec_sa_result,
14550                  sa, "sa");
14551 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14552         TOKEN_STRING_INITIALIZER
14553                 (struct cmd_macsec_sa_result,
14554                  tx_rx, "tx#rx");
14555 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14556         TOKEN_NUM_INITIALIZER
14557                 (struct cmd_macsec_sa_result,
14558                  port_id, UINT16);
14559 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14560         TOKEN_NUM_INITIALIZER
14561                 (struct cmd_macsec_sa_result,
14562                  idx, UINT8);
14563 cmdline_parse_token_num_t cmd_macsec_sa_an =
14564         TOKEN_NUM_INITIALIZER
14565                 (struct cmd_macsec_sa_result,
14566                  an, UINT8);
14567 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14568         TOKEN_NUM_INITIALIZER
14569                 (struct cmd_macsec_sa_result,
14570                  pn, UINT32);
14571 cmdline_parse_token_string_t cmd_macsec_sa_key =
14572         TOKEN_STRING_INITIALIZER
14573                 (struct cmd_macsec_sa_result,
14574                  key, NULL);
14575
14576 static void
14577 cmd_set_macsec_sa_parsed(
14578         void *parsed_result,
14579         __rte_unused struct cmdline *cl,
14580         __rte_unused void *data)
14581 {
14582         struct cmd_macsec_sa_result *res = parsed_result;
14583         int ret = -ENOTSUP;
14584         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14585         uint8_t key[16] = { 0 };
14586         uint8_t xdgt0;
14587         uint8_t xdgt1;
14588         int key_len;
14589         int i;
14590
14591         key_len = strlen(res->key) / 2;
14592         if (key_len > 16)
14593                 key_len = 16;
14594
14595         for (i = 0; i < key_len; i++) {
14596                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14597                 if (xdgt0 == 0xFF)
14598                         return;
14599                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14600                 if (xdgt1 == 0xFF)
14601                         return;
14602                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14603         }
14604
14605 #ifdef RTE_LIBRTE_IXGBE_PMD
14606         ret = is_tx ?
14607                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14608                         res->idx, res->an, res->pn, key) :
14609                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14610                         res->idx, res->an, res->pn, key);
14611 #endif
14612         RTE_SET_USED(is_tx);
14613         RTE_SET_USED(key);
14614
14615         switch (ret) {
14616         case 0:
14617                 break;
14618         case -EINVAL:
14619                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14620                 break;
14621         case -ENODEV:
14622                 printf("invalid port_id %d\n", res->port_id);
14623                 break;
14624         case -ENOTSUP:
14625                 printf("not supported on port %d\n", res->port_id);
14626                 break;
14627         default:
14628                 printf("programming error: (%s)\n", strerror(-ret));
14629         }
14630 }
14631
14632 cmdline_parse_inst_t cmd_set_macsec_sa = {
14633         .f = cmd_set_macsec_sa_parsed,
14634         .data = NULL,
14635         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14636         .tokens = {
14637                 (void *)&cmd_macsec_sa_set,
14638                 (void *)&cmd_macsec_sa_macsec,
14639                 (void *)&cmd_macsec_sa_sa,
14640                 (void *)&cmd_macsec_sa_tx_rx,
14641                 (void *)&cmd_macsec_sa_port_id,
14642                 (void *)&cmd_macsec_sa_idx,
14643                 (void *)&cmd_macsec_sa_an,
14644                 (void *)&cmd_macsec_sa_pn,
14645                 (void *)&cmd_macsec_sa_key,
14646                 NULL,
14647         },
14648 };
14649
14650 /* VF unicast promiscuous mode configuration */
14651
14652 /* Common result structure for VF unicast promiscuous mode */
14653 struct cmd_vf_promisc_result {
14654         cmdline_fixed_string_t set;
14655         cmdline_fixed_string_t vf;
14656         cmdline_fixed_string_t promisc;
14657         portid_t port_id;
14658         uint32_t vf_id;
14659         cmdline_fixed_string_t on_off;
14660 };
14661
14662 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14663 cmdline_parse_token_string_t cmd_vf_promisc_set =
14664         TOKEN_STRING_INITIALIZER
14665                 (struct cmd_vf_promisc_result,
14666                  set, "set");
14667 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14668         TOKEN_STRING_INITIALIZER
14669                 (struct cmd_vf_promisc_result,
14670                  vf, "vf");
14671 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14672         TOKEN_STRING_INITIALIZER
14673                 (struct cmd_vf_promisc_result,
14674                  promisc, "promisc");
14675 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14676         TOKEN_NUM_INITIALIZER
14677                 (struct cmd_vf_promisc_result,
14678                  port_id, UINT16);
14679 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14680         TOKEN_NUM_INITIALIZER
14681                 (struct cmd_vf_promisc_result,
14682                  vf_id, UINT32);
14683 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14684         TOKEN_STRING_INITIALIZER
14685                 (struct cmd_vf_promisc_result,
14686                  on_off, "on#off");
14687
14688 static void
14689 cmd_set_vf_promisc_parsed(
14690         void *parsed_result,
14691         __rte_unused struct cmdline *cl,
14692         __rte_unused void *data)
14693 {
14694         struct cmd_vf_promisc_result *res = parsed_result;
14695         int ret = -ENOTSUP;
14696
14697         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14698
14699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14700                 return;
14701
14702 #ifdef RTE_LIBRTE_I40E_PMD
14703         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14704                                                   res->vf_id, is_on);
14705 #endif
14706
14707         switch (ret) {
14708         case 0:
14709                 break;
14710         case -EINVAL:
14711                 printf("invalid vf_id %d\n", res->vf_id);
14712                 break;
14713         case -ENODEV:
14714                 printf("invalid port_id %d\n", res->port_id);
14715                 break;
14716         case -ENOTSUP:
14717                 printf("function not implemented\n");
14718                 break;
14719         default:
14720                 printf("programming error: (%s)\n", strerror(-ret));
14721         }
14722 }
14723
14724 cmdline_parse_inst_t cmd_set_vf_promisc = {
14725         .f = cmd_set_vf_promisc_parsed,
14726         .data = NULL,
14727         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14728                 "Set unicast promiscuous mode for a VF from the PF",
14729         .tokens = {
14730                 (void *)&cmd_vf_promisc_set,
14731                 (void *)&cmd_vf_promisc_vf,
14732                 (void *)&cmd_vf_promisc_promisc,
14733                 (void *)&cmd_vf_promisc_port_id,
14734                 (void *)&cmd_vf_promisc_vf_id,
14735                 (void *)&cmd_vf_promisc_on_off,
14736                 NULL,
14737         },
14738 };
14739
14740 /* VF multicast promiscuous mode configuration */
14741
14742 /* Common result structure for VF multicast promiscuous mode */
14743 struct cmd_vf_allmulti_result {
14744         cmdline_fixed_string_t set;
14745         cmdline_fixed_string_t vf;
14746         cmdline_fixed_string_t allmulti;
14747         portid_t port_id;
14748         uint32_t vf_id;
14749         cmdline_fixed_string_t on_off;
14750 };
14751
14752 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14753 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14754         TOKEN_STRING_INITIALIZER
14755                 (struct cmd_vf_allmulti_result,
14756                  set, "set");
14757 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_vf_allmulti_result,
14760                  vf, "vf");
14761 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_vf_allmulti_result,
14764                  allmulti, "allmulti");
14765 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14766         TOKEN_NUM_INITIALIZER
14767                 (struct cmd_vf_allmulti_result,
14768                  port_id, UINT16);
14769 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14770         TOKEN_NUM_INITIALIZER
14771                 (struct cmd_vf_allmulti_result,
14772                  vf_id, UINT32);
14773 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14774         TOKEN_STRING_INITIALIZER
14775                 (struct cmd_vf_allmulti_result,
14776                  on_off, "on#off");
14777
14778 static void
14779 cmd_set_vf_allmulti_parsed(
14780         void *parsed_result,
14781         __rte_unused struct cmdline *cl,
14782         __rte_unused void *data)
14783 {
14784         struct cmd_vf_allmulti_result *res = parsed_result;
14785         int ret = -ENOTSUP;
14786
14787         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14788
14789         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14790                 return;
14791
14792 #ifdef RTE_LIBRTE_I40E_PMD
14793         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14794                                                     res->vf_id, is_on);
14795 #endif
14796
14797         switch (ret) {
14798         case 0:
14799                 break;
14800         case -EINVAL:
14801                 printf("invalid vf_id %d\n", res->vf_id);
14802                 break;
14803         case -ENODEV:
14804                 printf("invalid port_id %d\n", res->port_id);
14805                 break;
14806         case -ENOTSUP:
14807                 printf("function not implemented\n");
14808                 break;
14809         default:
14810                 printf("programming error: (%s)\n", strerror(-ret));
14811         }
14812 }
14813
14814 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14815         .f = cmd_set_vf_allmulti_parsed,
14816         .data = NULL,
14817         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14818                 "Set multicast promiscuous mode for a VF from the PF",
14819         .tokens = {
14820                 (void *)&cmd_vf_allmulti_set,
14821                 (void *)&cmd_vf_allmulti_vf,
14822                 (void *)&cmd_vf_allmulti_allmulti,
14823                 (void *)&cmd_vf_allmulti_port_id,
14824                 (void *)&cmd_vf_allmulti_vf_id,
14825                 (void *)&cmd_vf_allmulti_on_off,
14826                 NULL,
14827         },
14828 };
14829
14830 /* vf broadcast mode configuration */
14831
14832 /* Common result structure for vf broadcast */
14833 struct cmd_set_vf_broadcast_result {
14834         cmdline_fixed_string_t set;
14835         cmdline_fixed_string_t vf;
14836         cmdline_fixed_string_t broadcast;
14837         portid_t port_id;
14838         uint16_t vf_id;
14839         cmdline_fixed_string_t on_off;
14840 };
14841
14842 /* Common CLI fields for vf broadcast enable disable */
14843 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14844         TOKEN_STRING_INITIALIZER
14845                 (struct cmd_set_vf_broadcast_result,
14846                  set, "set");
14847 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14848         TOKEN_STRING_INITIALIZER
14849                 (struct cmd_set_vf_broadcast_result,
14850                  vf, "vf");
14851 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14852         TOKEN_STRING_INITIALIZER
14853                 (struct cmd_set_vf_broadcast_result,
14854                  broadcast, "broadcast");
14855 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14856         TOKEN_NUM_INITIALIZER
14857                 (struct cmd_set_vf_broadcast_result,
14858                  port_id, UINT16);
14859 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14860         TOKEN_NUM_INITIALIZER
14861                 (struct cmd_set_vf_broadcast_result,
14862                  vf_id, UINT16);
14863 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14864         TOKEN_STRING_INITIALIZER
14865                 (struct cmd_set_vf_broadcast_result,
14866                  on_off, "on#off");
14867
14868 static void
14869 cmd_set_vf_broadcast_parsed(
14870         void *parsed_result,
14871         __rte_unused struct cmdline *cl,
14872         __rte_unused void *data)
14873 {
14874         struct cmd_set_vf_broadcast_result *res = parsed_result;
14875         int ret = -ENOTSUP;
14876
14877         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14878
14879         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14880                 return;
14881
14882 #ifdef RTE_LIBRTE_I40E_PMD
14883         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14884                                             res->vf_id, is_on);
14885 #endif
14886
14887         switch (ret) {
14888         case 0:
14889                 break;
14890         case -EINVAL:
14891                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14892                 break;
14893         case -ENODEV:
14894                 printf("invalid port_id %d\n", res->port_id);
14895                 break;
14896         case -ENOTSUP:
14897                 printf("function not implemented\n");
14898                 break;
14899         default:
14900                 printf("programming error: (%s)\n", strerror(-ret));
14901         }
14902 }
14903
14904 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14905         .f = cmd_set_vf_broadcast_parsed,
14906         .data = NULL,
14907         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14908         .tokens = {
14909                 (void *)&cmd_set_vf_broadcast_set,
14910                 (void *)&cmd_set_vf_broadcast_vf,
14911                 (void *)&cmd_set_vf_broadcast_broadcast,
14912                 (void *)&cmd_set_vf_broadcast_port_id,
14913                 (void *)&cmd_set_vf_broadcast_vf_id,
14914                 (void *)&cmd_set_vf_broadcast_on_off,
14915                 NULL,
14916         },
14917 };
14918
14919 /* vf vlan tag configuration */
14920
14921 /* Common result structure for vf vlan tag */
14922 struct cmd_set_vf_vlan_tag_result {
14923         cmdline_fixed_string_t set;
14924         cmdline_fixed_string_t vf;
14925         cmdline_fixed_string_t vlan;
14926         cmdline_fixed_string_t tag;
14927         portid_t port_id;
14928         uint16_t vf_id;
14929         cmdline_fixed_string_t on_off;
14930 };
14931
14932 /* Common CLI fields for vf vlan tag enable disable */
14933 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14934         TOKEN_STRING_INITIALIZER
14935                 (struct cmd_set_vf_vlan_tag_result,
14936                  set, "set");
14937 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14938         TOKEN_STRING_INITIALIZER
14939                 (struct cmd_set_vf_vlan_tag_result,
14940                  vf, "vf");
14941 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14942         TOKEN_STRING_INITIALIZER
14943                 (struct cmd_set_vf_vlan_tag_result,
14944                  vlan, "vlan");
14945 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14946         TOKEN_STRING_INITIALIZER
14947                 (struct cmd_set_vf_vlan_tag_result,
14948                  tag, "tag");
14949 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14950         TOKEN_NUM_INITIALIZER
14951                 (struct cmd_set_vf_vlan_tag_result,
14952                  port_id, UINT16);
14953 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14954         TOKEN_NUM_INITIALIZER
14955                 (struct cmd_set_vf_vlan_tag_result,
14956                  vf_id, UINT16);
14957 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14958         TOKEN_STRING_INITIALIZER
14959                 (struct cmd_set_vf_vlan_tag_result,
14960                  on_off, "on#off");
14961
14962 static void
14963 cmd_set_vf_vlan_tag_parsed(
14964         void *parsed_result,
14965         __rte_unused struct cmdline *cl,
14966         __rte_unused void *data)
14967 {
14968         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14969         int ret = -ENOTSUP;
14970
14971         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14972
14973         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14974                 return;
14975
14976 #ifdef RTE_LIBRTE_I40E_PMD
14977         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14978                                            res->vf_id, is_on);
14979 #endif
14980
14981         switch (ret) {
14982         case 0:
14983                 break;
14984         case -EINVAL:
14985                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14986                 break;
14987         case -ENODEV:
14988                 printf("invalid port_id %d\n", res->port_id);
14989                 break;
14990         case -ENOTSUP:
14991                 printf("function not implemented\n");
14992                 break;
14993         default:
14994                 printf("programming error: (%s)\n", strerror(-ret));
14995         }
14996 }
14997
14998 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
14999         .f = cmd_set_vf_vlan_tag_parsed,
15000         .data = NULL,
15001         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15002         .tokens = {
15003                 (void *)&cmd_set_vf_vlan_tag_set,
15004                 (void *)&cmd_set_vf_vlan_tag_vf,
15005                 (void *)&cmd_set_vf_vlan_tag_vlan,
15006                 (void *)&cmd_set_vf_vlan_tag_tag,
15007                 (void *)&cmd_set_vf_vlan_tag_port_id,
15008                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15009                 (void *)&cmd_set_vf_vlan_tag_on_off,
15010                 NULL,
15011         },
15012 };
15013
15014 /* Common definition of VF and TC TX bandwidth configuration */
15015 struct cmd_vf_tc_bw_result {
15016         cmdline_fixed_string_t set;
15017         cmdline_fixed_string_t vf;
15018         cmdline_fixed_string_t tc;
15019         cmdline_fixed_string_t tx;
15020         cmdline_fixed_string_t min_bw;
15021         cmdline_fixed_string_t max_bw;
15022         cmdline_fixed_string_t strict_link_prio;
15023         portid_t port_id;
15024         uint16_t vf_id;
15025         uint8_t tc_no;
15026         uint32_t bw;
15027         cmdline_fixed_string_t bw_list;
15028         uint8_t tc_map;
15029 };
15030
15031 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15032         TOKEN_STRING_INITIALIZER
15033                 (struct cmd_vf_tc_bw_result,
15034                  set, "set");
15035 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15036         TOKEN_STRING_INITIALIZER
15037                 (struct cmd_vf_tc_bw_result,
15038                  vf, "vf");
15039 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15040         TOKEN_STRING_INITIALIZER
15041                 (struct cmd_vf_tc_bw_result,
15042                  tc, "tc");
15043 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15044         TOKEN_STRING_INITIALIZER
15045                 (struct cmd_vf_tc_bw_result,
15046                  tx, "tx");
15047 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15048         TOKEN_STRING_INITIALIZER
15049                 (struct cmd_vf_tc_bw_result,
15050                  strict_link_prio, "strict-link-priority");
15051 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15052         TOKEN_STRING_INITIALIZER
15053                 (struct cmd_vf_tc_bw_result,
15054                  min_bw, "min-bandwidth");
15055 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15056         TOKEN_STRING_INITIALIZER
15057                 (struct cmd_vf_tc_bw_result,
15058                  max_bw, "max-bandwidth");
15059 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15060         TOKEN_NUM_INITIALIZER
15061                 (struct cmd_vf_tc_bw_result,
15062                  port_id, UINT16);
15063 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15064         TOKEN_NUM_INITIALIZER
15065                 (struct cmd_vf_tc_bw_result,
15066                  vf_id, UINT16);
15067 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15068         TOKEN_NUM_INITIALIZER
15069                 (struct cmd_vf_tc_bw_result,
15070                  tc_no, UINT8);
15071 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15072         TOKEN_NUM_INITIALIZER
15073                 (struct cmd_vf_tc_bw_result,
15074                  bw, UINT32);
15075 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15076         TOKEN_STRING_INITIALIZER
15077                 (struct cmd_vf_tc_bw_result,
15078                  bw_list, NULL);
15079 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15080         TOKEN_NUM_INITIALIZER
15081                 (struct cmd_vf_tc_bw_result,
15082                  tc_map, UINT8);
15083
15084 /* VF max bandwidth setting */
15085 static void
15086 cmd_vf_max_bw_parsed(
15087         void *parsed_result,
15088         __rte_unused struct cmdline *cl,
15089         __rte_unused void *data)
15090 {
15091         struct cmd_vf_tc_bw_result *res = parsed_result;
15092         int ret = -ENOTSUP;
15093
15094         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15095                 return;
15096
15097 #ifdef RTE_LIBRTE_I40E_PMD
15098         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15099                                          res->vf_id, res->bw);
15100 #endif
15101
15102         switch (ret) {
15103         case 0:
15104                 break;
15105         case -EINVAL:
15106                 printf("invalid vf_id %d or bandwidth %d\n",
15107                        res->vf_id, res->bw);
15108                 break;
15109         case -ENODEV:
15110                 printf("invalid port_id %d\n", res->port_id);
15111                 break;
15112         case -ENOTSUP:
15113                 printf("function not implemented\n");
15114                 break;
15115         default:
15116                 printf("programming error: (%s)\n", strerror(-ret));
15117         }
15118 }
15119
15120 cmdline_parse_inst_t cmd_vf_max_bw = {
15121         .f = cmd_vf_max_bw_parsed,
15122         .data = NULL,
15123         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15124         .tokens = {
15125                 (void *)&cmd_vf_tc_bw_set,
15126                 (void *)&cmd_vf_tc_bw_vf,
15127                 (void *)&cmd_vf_tc_bw_tx,
15128                 (void *)&cmd_vf_tc_bw_max_bw,
15129                 (void *)&cmd_vf_tc_bw_port_id,
15130                 (void *)&cmd_vf_tc_bw_vf_id,
15131                 (void *)&cmd_vf_tc_bw_bw,
15132                 NULL,
15133         },
15134 };
15135
15136 static int
15137 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15138                            uint8_t *tc_num,
15139                            char *str)
15140 {
15141         uint32_t size;
15142         const char *p, *p0 = str;
15143         char s[256];
15144         char *end;
15145         char *str_fld[16];
15146         uint16_t i;
15147         int ret;
15148
15149         p = strchr(p0, '(');
15150         if (p == NULL) {
15151                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15152                 return -1;
15153         }
15154         p++;
15155         p0 = strchr(p, ')');
15156         if (p0 == NULL) {
15157                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15158                 return -1;
15159         }
15160         size = p0 - p;
15161         if (size >= sizeof(s)) {
15162                 printf("The string size exceeds the internal buffer size\n");
15163                 return -1;
15164         }
15165         snprintf(s, sizeof(s), "%.*s", size, p);
15166         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15167         if (ret <= 0) {
15168                 printf("Failed to get the bandwidth list. ");
15169                 return -1;
15170         }
15171         *tc_num = ret;
15172         for (i = 0; i < ret; i++)
15173                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15174
15175         return 0;
15176 }
15177
15178 /* TC min bandwidth setting */
15179 static void
15180 cmd_vf_tc_min_bw_parsed(
15181         void *parsed_result,
15182         __rte_unused struct cmdline *cl,
15183         __rte_unused void *data)
15184 {
15185         struct cmd_vf_tc_bw_result *res = parsed_result;
15186         uint8_t tc_num;
15187         uint8_t bw[16];
15188         int ret = -ENOTSUP;
15189
15190         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15191                 return;
15192
15193         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15194         if (ret)
15195                 return;
15196
15197 #ifdef RTE_LIBRTE_I40E_PMD
15198         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15199                                               tc_num, bw);
15200 #endif
15201
15202         switch (ret) {
15203         case 0:
15204                 break;
15205         case -EINVAL:
15206                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15207                 break;
15208         case -ENODEV:
15209                 printf("invalid port_id %d\n", res->port_id);
15210                 break;
15211         case -ENOTSUP:
15212                 printf("function not implemented\n");
15213                 break;
15214         default:
15215                 printf("programming error: (%s)\n", strerror(-ret));
15216         }
15217 }
15218
15219 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15220         .f = cmd_vf_tc_min_bw_parsed,
15221         .data = NULL,
15222         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15223                     " <bw1, bw2, ...>",
15224         .tokens = {
15225                 (void *)&cmd_vf_tc_bw_set,
15226                 (void *)&cmd_vf_tc_bw_vf,
15227                 (void *)&cmd_vf_tc_bw_tc,
15228                 (void *)&cmd_vf_tc_bw_tx,
15229                 (void *)&cmd_vf_tc_bw_min_bw,
15230                 (void *)&cmd_vf_tc_bw_port_id,
15231                 (void *)&cmd_vf_tc_bw_vf_id,
15232                 (void *)&cmd_vf_tc_bw_bw_list,
15233                 NULL,
15234         },
15235 };
15236
15237 static void
15238 cmd_tc_min_bw_parsed(
15239         void *parsed_result,
15240         __rte_unused struct cmdline *cl,
15241         __rte_unused void *data)
15242 {
15243         struct cmd_vf_tc_bw_result *res = parsed_result;
15244         struct rte_port *port;
15245         uint8_t tc_num;
15246         uint8_t bw[16];
15247         int ret = -ENOTSUP;
15248
15249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15250                 return;
15251
15252         port = &ports[res->port_id];
15253         /** Check if the port is not started **/
15254         if (port->port_status != RTE_PORT_STOPPED) {
15255                 printf("Please stop port %d first\n", res->port_id);
15256                 return;
15257         }
15258
15259         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15260         if (ret)
15261                 return;
15262
15263 #ifdef RTE_LIBRTE_IXGBE_PMD
15264         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15265 #endif
15266
15267         switch (ret) {
15268         case 0:
15269                 break;
15270         case -EINVAL:
15271                 printf("invalid bandwidth\n");
15272                 break;
15273         case -ENODEV:
15274                 printf("invalid port_id %d\n", res->port_id);
15275                 break;
15276         case -ENOTSUP:
15277                 printf("function not implemented\n");
15278                 break;
15279         default:
15280                 printf("programming error: (%s)\n", strerror(-ret));
15281         }
15282 }
15283
15284 cmdline_parse_inst_t cmd_tc_min_bw = {
15285         .f = cmd_tc_min_bw_parsed,
15286         .data = NULL,
15287         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15288         .tokens = {
15289                 (void *)&cmd_vf_tc_bw_set,
15290                 (void *)&cmd_vf_tc_bw_tc,
15291                 (void *)&cmd_vf_tc_bw_tx,
15292                 (void *)&cmd_vf_tc_bw_min_bw,
15293                 (void *)&cmd_vf_tc_bw_port_id,
15294                 (void *)&cmd_vf_tc_bw_bw_list,
15295                 NULL,
15296         },
15297 };
15298
15299 /* TC max bandwidth setting */
15300 static void
15301 cmd_vf_tc_max_bw_parsed(
15302         void *parsed_result,
15303         __rte_unused struct cmdline *cl,
15304         __rte_unused void *data)
15305 {
15306         struct cmd_vf_tc_bw_result *res = parsed_result;
15307         int ret = -ENOTSUP;
15308
15309         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15310                 return;
15311
15312 #ifdef RTE_LIBRTE_I40E_PMD
15313         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15314                                             res->tc_no, res->bw);
15315 #endif
15316
15317         switch (ret) {
15318         case 0:
15319                 break;
15320         case -EINVAL:
15321                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15322                        res->vf_id, res->tc_no, res->bw);
15323                 break;
15324         case -ENODEV:
15325                 printf("invalid port_id %d\n", res->port_id);
15326                 break;
15327         case -ENOTSUP:
15328                 printf("function not implemented\n");
15329                 break;
15330         default:
15331                 printf("programming error: (%s)\n", strerror(-ret));
15332         }
15333 }
15334
15335 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15336         .f = cmd_vf_tc_max_bw_parsed,
15337         .data = NULL,
15338         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15339                     " <bandwidth>",
15340         .tokens = {
15341                 (void *)&cmd_vf_tc_bw_set,
15342                 (void *)&cmd_vf_tc_bw_vf,
15343                 (void *)&cmd_vf_tc_bw_tc,
15344                 (void *)&cmd_vf_tc_bw_tx,
15345                 (void *)&cmd_vf_tc_bw_max_bw,
15346                 (void *)&cmd_vf_tc_bw_port_id,
15347                 (void *)&cmd_vf_tc_bw_vf_id,
15348                 (void *)&cmd_vf_tc_bw_tc_no,
15349                 (void *)&cmd_vf_tc_bw_bw,
15350                 NULL,
15351         },
15352 };
15353
15354
15355 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15356
15357 /* *** Set Port default Traffic Management Hierarchy *** */
15358 struct cmd_set_port_tm_hierarchy_default_result {
15359         cmdline_fixed_string_t set;
15360         cmdline_fixed_string_t port;
15361         cmdline_fixed_string_t tm;
15362         cmdline_fixed_string_t hierarchy;
15363         cmdline_fixed_string_t def;
15364         portid_t port_id;
15365 };
15366
15367 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15368         TOKEN_STRING_INITIALIZER(
15369                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15370 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15371         TOKEN_STRING_INITIALIZER(
15372                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15373 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15374         TOKEN_STRING_INITIALIZER(
15375                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15376 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15377         TOKEN_STRING_INITIALIZER(
15378                 struct cmd_set_port_tm_hierarchy_default_result,
15379                         hierarchy, "hierarchy");
15380 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15381         TOKEN_STRING_INITIALIZER(
15382                 struct cmd_set_port_tm_hierarchy_default_result,
15383                         def, "default");
15384 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15385         TOKEN_NUM_INITIALIZER(
15386                 struct cmd_set_port_tm_hierarchy_default_result,
15387                         port_id, UINT16);
15388
15389 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15390         __rte_unused struct cmdline *cl,
15391         __rte_unused void *data)
15392 {
15393         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15394         struct rte_port *p;
15395         portid_t port_id = res->port_id;
15396
15397         if (port_id_is_invalid(port_id, ENABLED_WARN))
15398                 return;
15399
15400         p = &ports[port_id];
15401
15402         /* Forward mode: tm */
15403         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15404                 printf("  softnicfwd mode not enabled(error)\n");
15405                 return;
15406         }
15407
15408         /* Set the default tm hierarchy */
15409         p->softport.default_tm_hierarchy_enable = 1;
15410 }
15411
15412 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15413         .f = cmd_set_port_tm_hierarchy_default_parsed,
15414         .data = NULL,
15415         .help_str = "set port tm hierarchy default <port_id>",
15416         .tokens = {
15417                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15418                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15419                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15420                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15421                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15422                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15423                 NULL,
15424         },
15425 };
15426 #endif
15427
15428 /** Set VXLAN encapsulation details */
15429 struct cmd_set_vxlan_result {
15430         cmdline_fixed_string_t set;
15431         cmdline_fixed_string_t vxlan;
15432         cmdline_fixed_string_t pos_token;
15433         cmdline_fixed_string_t ip_version;
15434         uint32_t vlan_present:1;
15435         uint32_t vni;
15436         uint16_t udp_src;
15437         uint16_t udp_dst;
15438         cmdline_ipaddr_t ip_src;
15439         cmdline_ipaddr_t ip_dst;
15440         uint16_t tci;
15441         uint8_t tos;
15442         uint8_t ttl;
15443         struct rte_ether_addr eth_src;
15444         struct rte_ether_addr eth_dst;
15445 };
15446
15447 cmdline_parse_token_string_t cmd_set_vxlan_set =
15448         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15449 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15450         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15451 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15452         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15453                                  "vxlan-tos-ttl");
15454 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15455         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15456                                  "vxlan-with-vlan");
15457 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15458         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15459                                  "ip-version");
15460 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15461         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15462                                  "ipv4#ipv6");
15463 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15464         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15465                                  "vni");
15466 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15467         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15468 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15469         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15470                                  "udp-src");
15471 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15472         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15473 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15474         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15475                                  "udp-dst");
15476 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15477         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15478 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15479         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15480                                  "ip-tos");
15481 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15482         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15483 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15484         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15485                                  "ip-ttl");
15486 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15487         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15488 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15489         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15490                                  "ip-src");
15491 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15492         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15493 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15494         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15495                                  "ip-dst");
15496 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15497         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15498 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15499         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15500                                  "vlan-tci");
15501 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15502         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15503 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15504         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15505                                  "eth-src");
15506 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15507         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15508 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15509         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15510                                  "eth-dst");
15511 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15512         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15513
15514 static void cmd_set_vxlan_parsed(void *parsed_result,
15515         __rte_unused struct cmdline *cl,
15516         __rte_unused void *data)
15517 {
15518         struct cmd_set_vxlan_result *res = parsed_result;
15519         union {
15520                 uint32_t vxlan_id;
15521                 uint8_t vni[4];
15522         } id = {
15523                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15524         };
15525
15526         vxlan_encap_conf.select_tos_ttl = 0;
15527         if (strcmp(res->vxlan, "vxlan") == 0)
15528                 vxlan_encap_conf.select_vlan = 0;
15529         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15530                 vxlan_encap_conf.select_vlan = 1;
15531         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15532                 vxlan_encap_conf.select_vlan = 0;
15533                 vxlan_encap_conf.select_tos_ttl = 1;
15534         }
15535         if (strcmp(res->ip_version, "ipv4") == 0)
15536                 vxlan_encap_conf.select_ipv4 = 1;
15537         else if (strcmp(res->ip_version, "ipv6") == 0)
15538                 vxlan_encap_conf.select_ipv4 = 0;
15539         else
15540                 return;
15541         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15542         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15543         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15544         vxlan_encap_conf.ip_tos = res->tos;
15545         vxlan_encap_conf.ip_ttl = res->ttl;
15546         if (vxlan_encap_conf.select_ipv4) {
15547                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15548                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15549         } else {
15550                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15551                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15552         }
15553         if (vxlan_encap_conf.select_vlan)
15554                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15555         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15556                    RTE_ETHER_ADDR_LEN);
15557         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15558                    RTE_ETHER_ADDR_LEN);
15559 }
15560
15561 cmdline_parse_inst_t cmd_set_vxlan = {
15562         .f = cmd_set_vxlan_parsed,
15563         .data = NULL,
15564         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15565                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15566                 " eth-src <eth-src> eth-dst <eth-dst>",
15567         .tokens = {
15568                 (void *)&cmd_set_vxlan_set,
15569                 (void *)&cmd_set_vxlan_vxlan,
15570                 (void *)&cmd_set_vxlan_ip_version,
15571                 (void *)&cmd_set_vxlan_ip_version_value,
15572                 (void *)&cmd_set_vxlan_vni,
15573                 (void *)&cmd_set_vxlan_vni_value,
15574                 (void *)&cmd_set_vxlan_udp_src,
15575                 (void *)&cmd_set_vxlan_udp_src_value,
15576                 (void *)&cmd_set_vxlan_udp_dst,
15577                 (void *)&cmd_set_vxlan_udp_dst_value,
15578                 (void *)&cmd_set_vxlan_ip_src,
15579                 (void *)&cmd_set_vxlan_ip_src_value,
15580                 (void *)&cmd_set_vxlan_ip_dst,
15581                 (void *)&cmd_set_vxlan_ip_dst_value,
15582                 (void *)&cmd_set_vxlan_eth_src,
15583                 (void *)&cmd_set_vxlan_eth_src_value,
15584                 (void *)&cmd_set_vxlan_eth_dst,
15585                 (void *)&cmd_set_vxlan_eth_dst_value,
15586                 NULL,
15587         },
15588 };
15589
15590 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15591         .f = cmd_set_vxlan_parsed,
15592         .data = NULL,
15593         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15594                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15595                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15596                 " eth-dst <eth-dst>",
15597         .tokens = {
15598                 (void *)&cmd_set_vxlan_set,
15599                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15600                 (void *)&cmd_set_vxlan_ip_version,
15601                 (void *)&cmd_set_vxlan_ip_version_value,
15602                 (void *)&cmd_set_vxlan_vni,
15603                 (void *)&cmd_set_vxlan_vni_value,
15604                 (void *)&cmd_set_vxlan_udp_src,
15605                 (void *)&cmd_set_vxlan_udp_src_value,
15606                 (void *)&cmd_set_vxlan_udp_dst,
15607                 (void *)&cmd_set_vxlan_udp_dst_value,
15608                 (void *)&cmd_set_vxlan_ip_tos,
15609                 (void *)&cmd_set_vxlan_ip_tos_value,
15610                 (void *)&cmd_set_vxlan_ip_ttl,
15611                 (void *)&cmd_set_vxlan_ip_ttl_value,
15612                 (void *)&cmd_set_vxlan_ip_src,
15613                 (void *)&cmd_set_vxlan_ip_src_value,
15614                 (void *)&cmd_set_vxlan_ip_dst,
15615                 (void *)&cmd_set_vxlan_ip_dst_value,
15616                 (void *)&cmd_set_vxlan_eth_src,
15617                 (void *)&cmd_set_vxlan_eth_src_value,
15618                 (void *)&cmd_set_vxlan_eth_dst,
15619                 (void *)&cmd_set_vxlan_eth_dst_value,
15620                 NULL,
15621         },
15622 };
15623
15624 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15625         .f = cmd_set_vxlan_parsed,
15626         .data = NULL,
15627         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15628                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15629                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15630                 " <eth-dst>",
15631         .tokens = {
15632                 (void *)&cmd_set_vxlan_set,
15633                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15634                 (void *)&cmd_set_vxlan_ip_version,
15635                 (void *)&cmd_set_vxlan_ip_version_value,
15636                 (void *)&cmd_set_vxlan_vni,
15637                 (void *)&cmd_set_vxlan_vni_value,
15638                 (void *)&cmd_set_vxlan_udp_src,
15639                 (void *)&cmd_set_vxlan_udp_src_value,
15640                 (void *)&cmd_set_vxlan_udp_dst,
15641                 (void *)&cmd_set_vxlan_udp_dst_value,
15642                 (void *)&cmd_set_vxlan_ip_src,
15643                 (void *)&cmd_set_vxlan_ip_src_value,
15644                 (void *)&cmd_set_vxlan_ip_dst,
15645                 (void *)&cmd_set_vxlan_ip_dst_value,
15646                 (void *)&cmd_set_vxlan_vlan,
15647                 (void *)&cmd_set_vxlan_vlan_value,
15648                 (void *)&cmd_set_vxlan_eth_src,
15649                 (void *)&cmd_set_vxlan_eth_src_value,
15650                 (void *)&cmd_set_vxlan_eth_dst,
15651                 (void *)&cmd_set_vxlan_eth_dst_value,
15652                 NULL,
15653         },
15654 };
15655
15656 /** Set NVGRE encapsulation details */
15657 struct cmd_set_nvgre_result {
15658         cmdline_fixed_string_t set;
15659         cmdline_fixed_string_t nvgre;
15660         cmdline_fixed_string_t pos_token;
15661         cmdline_fixed_string_t ip_version;
15662         uint32_t tni;
15663         cmdline_ipaddr_t ip_src;
15664         cmdline_ipaddr_t ip_dst;
15665         uint16_t tci;
15666         struct rte_ether_addr eth_src;
15667         struct rte_ether_addr eth_dst;
15668 };
15669
15670 cmdline_parse_token_string_t cmd_set_nvgre_set =
15671         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15672 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15673         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15674 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15675         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15676                                  "nvgre-with-vlan");
15677 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15678         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15679                                  "ip-version");
15680 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15681         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15682                                  "ipv4#ipv6");
15683 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15684         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15685                                  "tni");
15686 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15687         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15688 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15689         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15690                                  "ip-src");
15691 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15692         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15693 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15694         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15695                                  "ip-dst");
15696 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15697         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15698 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15699         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15700                                  "vlan-tci");
15701 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15702         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15703 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15704         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15705                                  "eth-src");
15706 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15707         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15708 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15709         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15710                                  "eth-dst");
15711 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15712         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15713
15714 static void cmd_set_nvgre_parsed(void *parsed_result,
15715         __rte_unused struct cmdline *cl,
15716         __rte_unused void *data)
15717 {
15718         struct cmd_set_nvgre_result *res = parsed_result;
15719         union {
15720                 uint32_t nvgre_tni;
15721                 uint8_t tni[4];
15722         } id = {
15723                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15724         };
15725
15726         if (strcmp(res->nvgre, "nvgre") == 0)
15727                 nvgre_encap_conf.select_vlan = 0;
15728         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15729                 nvgre_encap_conf.select_vlan = 1;
15730         if (strcmp(res->ip_version, "ipv4") == 0)
15731                 nvgre_encap_conf.select_ipv4 = 1;
15732         else if (strcmp(res->ip_version, "ipv6") == 0)
15733                 nvgre_encap_conf.select_ipv4 = 0;
15734         else
15735                 return;
15736         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15737         if (nvgre_encap_conf.select_ipv4) {
15738                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15739                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15740         } else {
15741                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15742                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15743         }
15744         if (nvgre_encap_conf.select_vlan)
15745                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15746         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15747                    RTE_ETHER_ADDR_LEN);
15748         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15749                    RTE_ETHER_ADDR_LEN);
15750 }
15751
15752 cmdline_parse_inst_t cmd_set_nvgre = {
15753         .f = cmd_set_nvgre_parsed,
15754         .data = NULL,
15755         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15756                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15757                 " eth-dst <eth-dst>",
15758         .tokens = {
15759                 (void *)&cmd_set_nvgre_set,
15760                 (void *)&cmd_set_nvgre_nvgre,
15761                 (void *)&cmd_set_nvgre_ip_version,
15762                 (void *)&cmd_set_nvgre_ip_version_value,
15763                 (void *)&cmd_set_nvgre_tni,
15764                 (void *)&cmd_set_nvgre_tni_value,
15765                 (void *)&cmd_set_nvgre_ip_src,
15766                 (void *)&cmd_set_nvgre_ip_src_value,
15767                 (void *)&cmd_set_nvgre_ip_dst,
15768                 (void *)&cmd_set_nvgre_ip_dst_value,
15769                 (void *)&cmd_set_nvgre_eth_src,
15770                 (void *)&cmd_set_nvgre_eth_src_value,
15771                 (void *)&cmd_set_nvgre_eth_dst,
15772                 (void *)&cmd_set_nvgre_eth_dst_value,
15773                 NULL,
15774         },
15775 };
15776
15777 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15778         .f = cmd_set_nvgre_parsed,
15779         .data = NULL,
15780         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15781                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15782                 " eth-src <eth-src> eth-dst <eth-dst>",
15783         .tokens = {
15784                 (void *)&cmd_set_nvgre_set,
15785                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15786                 (void *)&cmd_set_nvgre_ip_version,
15787                 (void *)&cmd_set_nvgre_ip_version_value,
15788                 (void *)&cmd_set_nvgre_tni,
15789                 (void *)&cmd_set_nvgre_tni_value,
15790                 (void *)&cmd_set_nvgre_ip_src,
15791                 (void *)&cmd_set_nvgre_ip_src_value,
15792                 (void *)&cmd_set_nvgre_ip_dst,
15793                 (void *)&cmd_set_nvgre_ip_dst_value,
15794                 (void *)&cmd_set_nvgre_vlan,
15795                 (void *)&cmd_set_nvgre_vlan_value,
15796                 (void *)&cmd_set_nvgre_eth_src,
15797                 (void *)&cmd_set_nvgre_eth_src_value,
15798                 (void *)&cmd_set_nvgre_eth_dst,
15799                 (void *)&cmd_set_nvgre_eth_dst_value,
15800                 NULL,
15801         },
15802 };
15803
15804 /** Set L2 encapsulation details */
15805 struct cmd_set_l2_encap_result {
15806         cmdline_fixed_string_t set;
15807         cmdline_fixed_string_t l2_encap;
15808         cmdline_fixed_string_t pos_token;
15809         cmdline_fixed_string_t ip_version;
15810         uint32_t vlan_present:1;
15811         uint16_t tci;
15812         struct rte_ether_addr eth_src;
15813         struct rte_ether_addr eth_dst;
15814 };
15815
15816 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15817         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15818 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15819         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15820 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15821         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15822                                  "l2_encap-with-vlan");
15823 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15824         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15825                                  "ip-version");
15826 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15827         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15828                                  "ipv4#ipv6");
15829 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15830         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15831                                  "vlan-tci");
15832 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15833         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15834 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15835         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15836                                  "eth-src");
15837 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15838         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15839 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15840         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15841                                  "eth-dst");
15842 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15843         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15844
15845 static void cmd_set_l2_encap_parsed(void *parsed_result,
15846         __rte_unused struct cmdline *cl,
15847         __rte_unused void *data)
15848 {
15849         struct cmd_set_l2_encap_result *res = parsed_result;
15850
15851         if (strcmp(res->l2_encap, "l2_encap") == 0)
15852                 l2_encap_conf.select_vlan = 0;
15853         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15854                 l2_encap_conf.select_vlan = 1;
15855         if (strcmp(res->ip_version, "ipv4") == 0)
15856                 l2_encap_conf.select_ipv4 = 1;
15857         else if (strcmp(res->ip_version, "ipv6") == 0)
15858                 l2_encap_conf.select_ipv4 = 0;
15859         else
15860                 return;
15861         if (l2_encap_conf.select_vlan)
15862                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15863         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15864                    RTE_ETHER_ADDR_LEN);
15865         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15866                    RTE_ETHER_ADDR_LEN);
15867 }
15868
15869 cmdline_parse_inst_t cmd_set_l2_encap = {
15870         .f = cmd_set_l2_encap_parsed,
15871         .data = NULL,
15872         .help_str = "set l2_encap ip-version ipv4|ipv6"
15873                 " eth-src <eth-src> eth-dst <eth-dst>",
15874         .tokens = {
15875                 (void *)&cmd_set_l2_encap_set,
15876                 (void *)&cmd_set_l2_encap_l2_encap,
15877                 (void *)&cmd_set_l2_encap_ip_version,
15878                 (void *)&cmd_set_l2_encap_ip_version_value,
15879                 (void *)&cmd_set_l2_encap_eth_src,
15880                 (void *)&cmd_set_l2_encap_eth_src_value,
15881                 (void *)&cmd_set_l2_encap_eth_dst,
15882                 (void *)&cmd_set_l2_encap_eth_dst_value,
15883                 NULL,
15884         },
15885 };
15886
15887 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15888         .f = cmd_set_l2_encap_parsed,
15889         .data = NULL,
15890         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15891                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15892         .tokens = {
15893                 (void *)&cmd_set_l2_encap_set,
15894                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15895                 (void *)&cmd_set_l2_encap_ip_version,
15896                 (void *)&cmd_set_l2_encap_ip_version_value,
15897                 (void *)&cmd_set_l2_encap_vlan,
15898                 (void *)&cmd_set_l2_encap_vlan_value,
15899                 (void *)&cmd_set_l2_encap_eth_src,
15900                 (void *)&cmd_set_l2_encap_eth_src_value,
15901                 (void *)&cmd_set_l2_encap_eth_dst,
15902                 (void *)&cmd_set_l2_encap_eth_dst_value,
15903                 NULL,
15904         },
15905 };
15906
15907 /** Set L2 decapsulation details */
15908 struct cmd_set_l2_decap_result {
15909         cmdline_fixed_string_t set;
15910         cmdline_fixed_string_t l2_decap;
15911         cmdline_fixed_string_t pos_token;
15912         uint32_t vlan_present:1;
15913 };
15914
15915 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15916         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15917 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15918         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15919                                  "l2_decap");
15920 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15921         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15922                                  "l2_decap-with-vlan");
15923
15924 static void cmd_set_l2_decap_parsed(void *parsed_result,
15925         __rte_unused struct cmdline *cl,
15926         __rte_unused void *data)
15927 {
15928         struct cmd_set_l2_decap_result *res = parsed_result;
15929
15930         if (strcmp(res->l2_decap, "l2_decap") == 0)
15931                 l2_decap_conf.select_vlan = 0;
15932         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15933                 l2_decap_conf.select_vlan = 1;
15934 }
15935
15936 cmdline_parse_inst_t cmd_set_l2_decap = {
15937         .f = cmd_set_l2_decap_parsed,
15938         .data = NULL,
15939         .help_str = "set l2_decap",
15940         .tokens = {
15941                 (void *)&cmd_set_l2_decap_set,
15942                 (void *)&cmd_set_l2_decap_l2_decap,
15943                 NULL,
15944         },
15945 };
15946
15947 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15948         .f = cmd_set_l2_decap_parsed,
15949         .data = NULL,
15950         .help_str = "set l2_decap-with-vlan",
15951         .tokens = {
15952                 (void *)&cmd_set_l2_decap_set,
15953                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15954                 NULL,
15955         },
15956 };
15957
15958 /** Set MPLSoGRE encapsulation details */
15959 struct cmd_set_mplsogre_encap_result {
15960         cmdline_fixed_string_t set;
15961         cmdline_fixed_string_t mplsogre;
15962         cmdline_fixed_string_t pos_token;
15963         cmdline_fixed_string_t ip_version;
15964         uint32_t vlan_present:1;
15965         uint32_t label;
15966         cmdline_ipaddr_t ip_src;
15967         cmdline_ipaddr_t ip_dst;
15968         uint16_t tci;
15969         struct rte_ether_addr eth_src;
15970         struct rte_ether_addr eth_dst;
15971 };
15972
15973 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15974         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15975                                  "set");
15976 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15977         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15978                                  "mplsogre_encap");
15979 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15980         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15981                                  mplsogre, "mplsogre_encap-with-vlan");
15982 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15983         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15984                                  pos_token, "ip-version");
15985 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15986         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15987                                  ip_version, "ipv4#ipv6");
15988 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15990                                  pos_token, "label");
15991 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15992         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15993                               UINT32);
15994 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15995         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15996                                  pos_token, "ip-src");
15997 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15998         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15999 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16000         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16001                                  pos_token, "ip-dst");
16002 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16003         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16004 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16005         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16006                                  pos_token, "vlan-tci");
16007 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16008         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16009                               UINT16);
16010 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16011         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16012                                  pos_token, "eth-src");
16013 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16014         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16015                                     eth_src);
16016 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16017         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16018                                  pos_token, "eth-dst");
16019 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16020         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16021                                     eth_dst);
16022
16023 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16024         __rte_unused struct cmdline *cl,
16025         __rte_unused void *data)
16026 {
16027         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16028         union {
16029                 uint32_t mplsogre_label;
16030                 uint8_t label[4];
16031         } id = {
16032                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16033         };
16034
16035         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16036                 mplsogre_encap_conf.select_vlan = 0;
16037         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16038                 mplsogre_encap_conf.select_vlan = 1;
16039         if (strcmp(res->ip_version, "ipv4") == 0)
16040                 mplsogre_encap_conf.select_ipv4 = 1;
16041         else if (strcmp(res->ip_version, "ipv6") == 0)
16042                 mplsogre_encap_conf.select_ipv4 = 0;
16043         else
16044                 return;
16045         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16046         if (mplsogre_encap_conf.select_ipv4) {
16047                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16048                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16049         } else {
16050                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16051                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16052         }
16053         if (mplsogre_encap_conf.select_vlan)
16054                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16055         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16056                    RTE_ETHER_ADDR_LEN);
16057         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16058                    RTE_ETHER_ADDR_LEN);
16059 }
16060
16061 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16062         .f = cmd_set_mplsogre_encap_parsed,
16063         .data = NULL,
16064         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16065                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16066                 " eth-dst <eth-dst>",
16067         .tokens = {
16068                 (void *)&cmd_set_mplsogre_encap_set,
16069                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16070                 (void *)&cmd_set_mplsogre_encap_ip_version,
16071                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16072                 (void *)&cmd_set_mplsogre_encap_label,
16073                 (void *)&cmd_set_mplsogre_encap_label_value,
16074                 (void *)&cmd_set_mplsogre_encap_ip_src,
16075                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16076                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16077                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16078                 (void *)&cmd_set_mplsogre_encap_eth_src,
16079                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16080                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16081                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16082                 NULL,
16083         },
16084 };
16085
16086 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16087         .f = cmd_set_mplsogre_encap_parsed,
16088         .data = NULL,
16089         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16090                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16091                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16092         .tokens = {
16093                 (void *)&cmd_set_mplsogre_encap_set,
16094                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16095                 (void *)&cmd_set_mplsogre_encap_ip_version,
16096                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16097                 (void *)&cmd_set_mplsogre_encap_label,
16098                 (void *)&cmd_set_mplsogre_encap_label_value,
16099                 (void *)&cmd_set_mplsogre_encap_ip_src,
16100                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16101                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16102                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16103                 (void *)&cmd_set_mplsogre_encap_vlan,
16104                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16105                 (void *)&cmd_set_mplsogre_encap_eth_src,
16106                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16107                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16108                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16109                 NULL,
16110         },
16111 };
16112
16113 /** Set MPLSoGRE decapsulation details */
16114 struct cmd_set_mplsogre_decap_result {
16115         cmdline_fixed_string_t set;
16116         cmdline_fixed_string_t mplsogre;
16117         cmdline_fixed_string_t pos_token;
16118         cmdline_fixed_string_t ip_version;
16119         uint32_t vlan_present:1;
16120 };
16121
16122 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16123         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16124                                  "set");
16125 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16126         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16127                                  "mplsogre_decap");
16128 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16129         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16130                                  mplsogre, "mplsogre_decap-with-vlan");
16131 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16132         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16133                                  pos_token, "ip-version");
16134 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16135         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16136                                  ip_version, "ipv4#ipv6");
16137
16138 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16139         __rte_unused struct cmdline *cl,
16140         __rte_unused void *data)
16141 {
16142         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16143
16144         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16145                 mplsogre_decap_conf.select_vlan = 0;
16146         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16147                 mplsogre_decap_conf.select_vlan = 1;
16148         if (strcmp(res->ip_version, "ipv4") == 0)
16149                 mplsogre_decap_conf.select_ipv4 = 1;
16150         else if (strcmp(res->ip_version, "ipv6") == 0)
16151                 mplsogre_decap_conf.select_ipv4 = 0;
16152 }
16153
16154 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16155         .f = cmd_set_mplsogre_decap_parsed,
16156         .data = NULL,
16157         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16158         .tokens = {
16159                 (void *)&cmd_set_mplsogre_decap_set,
16160                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16161                 (void *)&cmd_set_mplsogre_decap_ip_version,
16162                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16163                 NULL,
16164         },
16165 };
16166
16167 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16168         .f = cmd_set_mplsogre_decap_parsed,
16169         .data = NULL,
16170         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16171         .tokens = {
16172                 (void *)&cmd_set_mplsogre_decap_set,
16173                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16174                 (void *)&cmd_set_mplsogre_decap_ip_version,
16175                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16176                 NULL,
16177         },
16178 };
16179
16180 /** Set MPLSoUDP encapsulation details */
16181 struct cmd_set_mplsoudp_encap_result {
16182         cmdline_fixed_string_t set;
16183         cmdline_fixed_string_t mplsoudp;
16184         cmdline_fixed_string_t pos_token;
16185         cmdline_fixed_string_t ip_version;
16186         uint32_t vlan_present:1;
16187         uint32_t label;
16188         uint16_t udp_src;
16189         uint16_t udp_dst;
16190         cmdline_ipaddr_t ip_src;
16191         cmdline_ipaddr_t ip_dst;
16192         uint16_t tci;
16193         struct rte_ether_addr eth_src;
16194         struct rte_ether_addr eth_dst;
16195 };
16196
16197 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16199                                  "set");
16200 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16202                                  "mplsoudp_encap");
16203 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16205                                  mplsoudp, "mplsoudp_encap-with-vlan");
16206 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16207         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16208                                  pos_token, "ip-version");
16209 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16211                                  ip_version, "ipv4#ipv6");
16212 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16213         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16214                                  pos_token, "label");
16215 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16216         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16217                               UINT32);
16218 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16219         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16220                                  pos_token, "udp-src");
16221 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16222         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16223                               UINT16);
16224 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16225         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16226                                  pos_token, "udp-dst");
16227 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16228         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16229                               UINT16);
16230 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16231         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16232                                  pos_token, "ip-src");
16233 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16234         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16235 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16236         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16237                                  pos_token, "ip-dst");
16238 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16239         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16240 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16241         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16242                                  pos_token, "vlan-tci");
16243 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16244         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16245                               UINT16);
16246 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16247         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16248                                  pos_token, "eth-src");
16249 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16250         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16251                                     eth_src);
16252 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16253         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16254                                  pos_token, "eth-dst");
16255 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16256         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16257                                     eth_dst);
16258
16259 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16260         __rte_unused struct cmdline *cl,
16261         __rte_unused void *data)
16262 {
16263         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16264         union {
16265                 uint32_t mplsoudp_label;
16266                 uint8_t label[4];
16267         } id = {
16268                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16269         };
16270
16271         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16272                 mplsoudp_encap_conf.select_vlan = 0;
16273         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16274                 mplsoudp_encap_conf.select_vlan = 1;
16275         if (strcmp(res->ip_version, "ipv4") == 0)
16276                 mplsoudp_encap_conf.select_ipv4 = 1;
16277         else if (strcmp(res->ip_version, "ipv6") == 0)
16278                 mplsoudp_encap_conf.select_ipv4 = 0;
16279         else
16280                 return;
16281         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16282         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16283         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16284         if (mplsoudp_encap_conf.select_ipv4) {
16285                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16286                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16287         } else {
16288                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16289                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16290         }
16291         if (mplsoudp_encap_conf.select_vlan)
16292                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16293         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16294                    RTE_ETHER_ADDR_LEN);
16295         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16296                    RTE_ETHER_ADDR_LEN);
16297 }
16298
16299 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16300         .f = cmd_set_mplsoudp_encap_parsed,
16301         .data = NULL,
16302         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16303                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16304                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16305         .tokens = {
16306                 (void *)&cmd_set_mplsoudp_encap_set,
16307                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16308                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16309                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16310                 (void *)&cmd_set_mplsoudp_encap_label,
16311                 (void *)&cmd_set_mplsoudp_encap_label_value,
16312                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16313                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16314                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16315                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16316                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16317                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16318                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16319                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16320                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16321                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16322                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16323                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16324                 NULL,
16325         },
16326 };
16327
16328 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16329         .f = cmd_set_mplsoudp_encap_parsed,
16330         .data = NULL,
16331         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16332                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16333                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16334                 " eth-src <eth-src> eth-dst <eth-dst>",
16335         .tokens = {
16336                 (void *)&cmd_set_mplsoudp_encap_set,
16337                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16338                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16339                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16340                 (void *)&cmd_set_mplsoudp_encap_label,
16341                 (void *)&cmd_set_mplsoudp_encap_label_value,
16342                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16343                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16344                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16345                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16346                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16347                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16348                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16349                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16350                 (void *)&cmd_set_mplsoudp_encap_vlan,
16351                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16352                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16353                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16354                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16355                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16356                 NULL,
16357         },
16358 };
16359
16360 /** Set MPLSoUDP decapsulation details */
16361 struct cmd_set_mplsoudp_decap_result {
16362         cmdline_fixed_string_t set;
16363         cmdline_fixed_string_t mplsoudp;
16364         cmdline_fixed_string_t pos_token;
16365         cmdline_fixed_string_t ip_version;
16366         uint32_t vlan_present:1;
16367 };
16368
16369 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16370         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16371                                  "set");
16372 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16373         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16374                                  "mplsoudp_decap");
16375 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16376         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16377                                  mplsoudp, "mplsoudp_decap-with-vlan");
16378 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16379         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16380                                  pos_token, "ip-version");
16381 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16382         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16383                                  ip_version, "ipv4#ipv6");
16384
16385 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16386         __rte_unused struct cmdline *cl,
16387         __rte_unused void *data)
16388 {
16389         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16390
16391         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16392                 mplsoudp_decap_conf.select_vlan = 0;
16393         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16394                 mplsoudp_decap_conf.select_vlan = 1;
16395         if (strcmp(res->ip_version, "ipv4") == 0)
16396                 mplsoudp_decap_conf.select_ipv4 = 1;
16397         else if (strcmp(res->ip_version, "ipv6") == 0)
16398                 mplsoudp_decap_conf.select_ipv4 = 0;
16399 }
16400
16401 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16402         .f = cmd_set_mplsoudp_decap_parsed,
16403         .data = NULL,
16404         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16405         .tokens = {
16406                 (void *)&cmd_set_mplsoudp_decap_set,
16407                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16408                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16409                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16410                 NULL,
16411         },
16412 };
16413
16414 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16415         .f = cmd_set_mplsoudp_decap_parsed,
16416         .data = NULL,
16417         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16418         .tokens = {
16419                 (void *)&cmd_set_mplsoudp_decap_set,
16420                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16421                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16422                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16423                 NULL,
16424         },
16425 };
16426
16427 /* Strict link priority scheduling mode setting */
16428 static void
16429 cmd_strict_link_prio_parsed(
16430         void *parsed_result,
16431         __rte_unused struct cmdline *cl,
16432         __rte_unused void *data)
16433 {
16434         struct cmd_vf_tc_bw_result *res = parsed_result;
16435         int ret = -ENOTSUP;
16436
16437         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16438                 return;
16439
16440 #ifdef RTE_LIBRTE_I40E_PMD
16441         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16442 #endif
16443
16444         switch (ret) {
16445         case 0:
16446                 break;
16447         case -EINVAL:
16448                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16449                 break;
16450         case -ENODEV:
16451                 printf("invalid port_id %d\n", res->port_id);
16452                 break;
16453         case -ENOTSUP:
16454                 printf("function not implemented\n");
16455                 break;
16456         default:
16457                 printf("programming error: (%s)\n", strerror(-ret));
16458         }
16459 }
16460
16461 cmdline_parse_inst_t cmd_strict_link_prio = {
16462         .f = cmd_strict_link_prio_parsed,
16463         .data = NULL,
16464         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16465         .tokens = {
16466                 (void *)&cmd_vf_tc_bw_set,
16467                 (void *)&cmd_vf_tc_bw_tx,
16468                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16469                 (void *)&cmd_vf_tc_bw_port_id,
16470                 (void *)&cmd_vf_tc_bw_tc_map,
16471                 NULL,
16472         },
16473 };
16474
16475 /* Load dynamic device personalization*/
16476 struct cmd_ddp_add_result {
16477         cmdline_fixed_string_t ddp;
16478         cmdline_fixed_string_t add;
16479         portid_t port_id;
16480         char filepath[];
16481 };
16482
16483 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16484         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16485 cmdline_parse_token_string_t cmd_ddp_add_add =
16486         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16487 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16488         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16489 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16490         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16491
16492 static void
16493 cmd_ddp_add_parsed(
16494         void *parsed_result,
16495         __rte_unused struct cmdline *cl,
16496         __rte_unused void *data)
16497 {
16498         struct cmd_ddp_add_result *res = parsed_result;
16499         uint8_t *buff;
16500         uint32_t size;
16501         char *filepath;
16502         char *file_fld[2];
16503         int file_num;
16504         int ret = -ENOTSUP;
16505
16506         if (!all_ports_stopped()) {
16507                 printf("Please stop all ports first\n");
16508                 return;
16509         }
16510
16511         filepath = strdup(res->filepath);
16512         if (filepath == NULL) {
16513                 printf("Failed to allocate memory\n");
16514                 return;
16515         }
16516         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16517
16518         buff = open_file(file_fld[0], &size);
16519         if (!buff) {
16520                 free((void *)filepath);
16521                 return;
16522         }
16523
16524 #ifdef RTE_LIBRTE_I40E_PMD
16525         if (ret == -ENOTSUP)
16526                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16527                                                buff, size,
16528                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16529 #endif
16530
16531         if (ret == -EEXIST)
16532                 printf("Profile has already existed.\n");
16533         else if (ret < 0)
16534                 printf("Failed to load profile.\n");
16535         else if (file_num == 2)
16536                 save_file(file_fld[1], buff, size);
16537
16538         close_file(buff);
16539         free((void *)filepath);
16540 }
16541
16542 cmdline_parse_inst_t cmd_ddp_add = {
16543         .f = cmd_ddp_add_parsed,
16544         .data = NULL,
16545         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16546         .tokens = {
16547                 (void *)&cmd_ddp_add_ddp,
16548                 (void *)&cmd_ddp_add_add,
16549                 (void *)&cmd_ddp_add_port_id,
16550                 (void *)&cmd_ddp_add_filepath,
16551                 NULL,
16552         },
16553 };
16554
16555 /* Delete dynamic device personalization*/
16556 struct cmd_ddp_del_result {
16557         cmdline_fixed_string_t ddp;
16558         cmdline_fixed_string_t del;
16559         portid_t port_id;
16560         char filepath[];
16561 };
16562
16563 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16564         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16565 cmdline_parse_token_string_t cmd_ddp_del_del =
16566         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16567 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16568         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16569 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16571
16572 static void
16573 cmd_ddp_del_parsed(
16574         void *parsed_result,
16575         __rte_unused struct cmdline *cl,
16576         __rte_unused void *data)
16577 {
16578         struct cmd_ddp_del_result *res = parsed_result;
16579         uint8_t *buff;
16580         uint32_t size;
16581         int ret = -ENOTSUP;
16582
16583         if (!all_ports_stopped()) {
16584                 printf("Please stop all ports first\n");
16585                 return;
16586         }
16587
16588         buff = open_file(res->filepath, &size);
16589         if (!buff)
16590                 return;
16591
16592 #ifdef RTE_LIBRTE_I40E_PMD
16593         if (ret == -ENOTSUP)
16594                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16595                                                buff, size,
16596                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16597 #endif
16598
16599         if (ret == -EACCES)
16600                 printf("Profile does not exist.\n");
16601         else if (ret < 0)
16602                 printf("Failed to delete profile.\n");
16603
16604         close_file(buff);
16605 }
16606
16607 cmdline_parse_inst_t cmd_ddp_del = {
16608         .f = cmd_ddp_del_parsed,
16609         .data = NULL,
16610         .help_str = "ddp del <port_id> <backup_profile_path>",
16611         .tokens = {
16612                 (void *)&cmd_ddp_del_ddp,
16613                 (void *)&cmd_ddp_del_del,
16614                 (void *)&cmd_ddp_del_port_id,
16615                 (void *)&cmd_ddp_del_filepath,
16616                 NULL,
16617         },
16618 };
16619
16620 /* Get dynamic device personalization profile info */
16621 struct cmd_ddp_info_result {
16622         cmdline_fixed_string_t ddp;
16623         cmdline_fixed_string_t get;
16624         cmdline_fixed_string_t info;
16625         char filepath[];
16626 };
16627
16628 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16629         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16630 cmdline_parse_token_string_t cmd_ddp_info_get =
16631         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16632 cmdline_parse_token_string_t cmd_ddp_info_info =
16633         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16634 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16635         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16636
16637 static void
16638 cmd_ddp_info_parsed(
16639         void *parsed_result,
16640         __rte_unused struct cmdline *cl,
16641         __rte_unused void *data)
16642 {
16643         struct cmd_ddp_info_result *res = parsed_result;
16644         uint8_t *pkg;
16645         uint32_t pkg_size;
16646         int ret = -ENOTSUP;
16647 #ifdef RTE_LIBRTE_I40E_PMD
16648         uint32_t i, j, n;
16649         uint8_t *buff;
16650         uint32_t buff_size = 0;
16651         struct rte_pmd_i40e_profile_info info;
16652         uint32_t dev_num = 0;
16653         struct rte_pmd_i40e_ddp_device_id *devs;
16654         uint32_t proto_num = 0;
16655         struct rte_pmd_i40e_proto_info *proto = NULL;
16656         uint32_t pctype_num = 0;
16657         struct rte_pmd_i40e_ptype_info *pctype;
16658         uint32_t ptype_num = 0;
16659         struct rte_pmd_i40e_ptype_info *ptype;
16660         uint8_t proto_id;
16661
16662 #endif
16663
16664         pkg = open_file(res->filepath, &pkg_size);
16665         if (!pkg)
16666                 return;
16667
16668 #ifdef RTE_LIBRTE_I40E_PMD
16669         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16670                                 (uint8_t *)&info, sizeof(info),
16671                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16672         if (!ret) {
16673                 printf("Global Track id:       0x%x\n", info.track_id);
16674                 printf("Global Version:        %d.%d.%d.%d\n",
16675                         info.version.major,
16676                         info.version.minor,
16677                         info.version.update,
16678                         info.version.draft);
16679                 printf("Global Package name:   %s\n\n", info.name);
16680         }
16681
16682         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16683                                 (uint8_t *)&info, sizeof(info),
16684                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16685         if (!ret) {
16686                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16687                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16688                         info.version.major,
16689                         info.version.minor,
16690                         info.version.update,
16691                         info.version.draft);
16692                 printf("i40e Profile name:     %s\n\n", info.name);
16693         }
16694
16695         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16696                                 (uint8_t *)&buff_size, sizeof(buff_size),
16697                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16698         if (!ret && buff_size) {
16699                 buff = (uint8_t *)malloc(buff_size);
16700                 if (buff) {
16701                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16702                                                 buff, buff_size,
16703                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16704                         if (!ret)
16705                                 printf("Package Notes:\n%s\n\n", buff);
16706                         free(buff);
16707                 }
16708         }
16709
16710         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16711                                 (uint8_t *)&dev_num, sizeof(dev_num),
16712                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16713         if (!ret && dev_num) {
16714                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16715                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16716                 if (devs) {
16717                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16718                                                 (uint8_t *)devs, buff_size,
16719                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16720                         if (!ret) {
16721                                 printf("List of supported devices:\n");
16722                                 for (i = 0; i < dev_num; i++) {
16723                                         printf("  %04X:%04X %04X:%04X\n",
16724                                                 devs[i].vendor_dev_id >> 16,
16725                                                 devs[i].vendor_dev_id & 0xFFFF,
16726                                                 devs[i].sub_vendor_dev_id >> 16,
16727                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16728                                 }
16729                                 printf("\n");
16730                         }
16731                         free(devs);
16732                 }
16733         }
16734
16735         /* get information about protocols and packet types */
16736         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16737                 (uint8_t *)&proto_num, sizeof(proto_num),
16738                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16739         if (ret || !proto_num)
16740                 goto no_print_return;
16741
16742         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16743         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16744         if (!proto)
16745                 goto no_print_return;
16746
16747         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16748                                         buff_size,
16749                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16750         if (!ret) {
16751                 printf("List of used protocols:\n");
16752                 for (i = 0; i < proto_num; i++)
16753                         printf("  %2u: %s\n", proto[i].proto_id,
16754                                proto[i].name);
16755                 printf("\n");
16756         }
16757         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16758                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16759                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16760         if (ret || !pctype_num)
16761                 goto no_print_pctypes;
16762
16763         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16764         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16765         if (!pctype)
16766                 goto no_print_pctypes;
16767
16768         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16769                                         buff_size,
16770                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16771         if (ret) {
16772                 free(pctype);
16773                 goto no_print_pctypes;
16774         }
16775
16776         printf("List of defined packet classification types:\n");
16777         for (i = 0; i < pctype_num; i++) {
16778                 printf("  %2u:", pctype[i].ptype_id);
16779                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16780                         proto_id = pctype[i].protocols[j];
16781                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16782                                 for (n = 0; n < proto_num; n++) {
16783                                         if (proto[n].proto_id == proto_id) {
16784                                                 printf(" %s", proto[n].name);
16785                                                 break;
16786                                         }
16787                                 }
16788                         }
16789                 }
16790                 printf("\n");
16791         }
16792         printf("\n");
16793         free(pctype);
16794
16795 no_print_pctypes:
16796
16797         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16798                                         sizeof(ptype_num),
16799                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16800         if (ret || !ptype_num)
16801                 goto no_print_return;
16802
16803         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16804         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16805         if (!ptype)
16806                 goto no_print_return;
16807
16808         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16809                                         buff_size,
16810                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16811         if (ret) {
16812                 free(ptype);
16813                 goto no_print_return;
16814         }
16815         printf("List of defined packet types:\n");
16816         for (i = 0; i < ptype_num; i++) {
16817                 printf("  %2u:", ptype[i].ptype_id);
16818                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16819                         proto_id = ptype[i].protocols[j];
16820                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16821                                 for (n = 0; n < proto_num; n++) {
16822                                         if (proto[n].proto_id == proto_id) {
16823                                                 printf(" %s", proto[n].name);
16824                                                 break;
16825                                         }
16826                                 }
16827                         }
16828                 }
16829                 printf("\n");
16830         }
16831         free(ptype);
16832         printf("\n");
16833
16834         ret = 0;
16835 no_print_return:
16836         if (proto)
16837                 free(proto);
16838 #endif
16839         if (ret == -ENOTSUP)
16840                 printf("Function not supported in PMD driver\n");
16841         close_file(pkg);
16842 }
16843
16844 cmdline_parse_inst_t cmd_ddp_get_info = {
16845         .f = cmd_ddp_info_parsed,
16846         .data = NULL,
16847         .help_str = "ddp get info <profile_path>",
16848         .tokens = {
16849                 (void *)&cmd_ddp_info_ddp,
16850                 (void *)&cmd_ddp_info_get,
16851                 (void *)&cmd_ddp_info_info,
16852                 (void *)&cmd_ddp_info_filepath,
16853                 NULL,
16854         },
16855 };
16856
16857 /* Get dynamic device personalization profile info list*/
16858 #define PROFILE_INFO_SIZE 48
16859 #define MAX_PROFILE_NUM 16
16860
16861 struct cmd_ddp_get_list_result {
16862         cmdline_fixed_string_t ddp;
16863         cmdline_fixed_string_t get;
16864         cmdline_fixed_string_t list;
16865         portid_t port_id;
16866 };
16867
16868 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16869         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16870 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16871         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16872 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16873         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16874 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16875         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16876
16877 static void
16878 cmd_ddp_get_list_parsed(
16879         __rte_unused void *parsed_result,
16880         __rte_unused struct cmdline *cl,
16881         __rte_unused void *data)
16882 {
16883 #ifdef RTE_LIBRTE_I40E_PMD
16884         struct cmd_ddp_get_list_result *res = parsed_result;
16885         struct rte_pmd_i40e_profile_list *p_list;
16886         struct rte_pmd_i40e_profile_info *p_info;
16887         uint32_t p_num;
16888         uint32_t size;
16889         uint32_t i;
16890 #endif
16891         int ret = -ENOTSUP;
16892
16893 #ifdef RTE_LIBRTE_I40E_PMD
16894         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16895         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16896         if (!p_list) {
16897                 printf("%s: Failed to malloc buffer\n", __func__);
16898                 return;
16899         }
16900
16901         if (ret == -ENOTSUP)
16902                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16903                                                 (uint8_t *)p_list, size);
16904
16905         if (!ret) {
16906                 p_num = p_list->p_count;
16907                 printf("Profile number is: %d\n\n", p_num);
16908
16909                 for (i = 0; i < p_num; i++) {
16910                         p_info = &p_list->p_info[i];
16911                         printf("Profile %d:\n", i);
16912                         printf("Track id:     0x%x\n", p_info->track_id);
16913                         printf("Version:      %d.%d.%d.%d\n",
16914                                p_info->version.major,
16915                                p_info->version.minor,
16916                                p_info->version.update,
16917                                p_info->version.draft);
16918                         printf("Profile name: %s\n\n", p_info->name);
16919                 }
16920         }
16921
16922         free(p_list);
16923 #endif
16924
16925         if (ret < 0)
16926                 printf("Failed to get ddp list\n");
16927 }
16928
16929 cmdline_parse_inst_t cmd_ddp_get_list = {
16930         .f = cmd_ddp_get_list_parsed,
16931         .data = NULL,
16932         .help_str = "ddp get list <port_id>",
16933         .tokens = {
16934                 (void *)&cmd_ddp_get_list_ddp,
16935                 (void *)&cmd_ddp_get_list_get,
16936                 (void *)&cmd_ddp_get_list_list,
16937                 (void *)&cmd_ddp_get_list_port_id,
16938                 NULL,
16939         },
16940 };
16941
16942 /* Configure input set */
16943 struct cmd_cfg_input_set_result {
16944         cmdline_fixed_string_t port;
16945         cmdline_fixed_string_t cfg;
16946         portid_t port_id;
16947         cmdline_fixed_string_t pctype;
16948         uint8_t pctype_id;
16949         cmdline_fixed_string_t inset_type;
16950         cmdline_fixed_string_t opt;
16951         cmdline_fixed_string_t field;
16952         uint8_t field_idx;
16953 };
16954
16955 static void
16956 cmd_cfg_input_set_parsed(
16957         __rte_unused void *parsed_result,
16958         __rte_unused struct cmdline *cl,
16959         __rte_unused void *data)
16960 {
16961 #ifdef RTE_LIBRTE_I40E_PMD
16962         struct cmd_cfg_input_set_result *res = parsed_result;
16963         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16964         struct rte_pmd_i40e_inset inset;
16965 #endif
16966         int ret = -ENOTSUP;
16967
16968         if (!all_ports_stopped()) {
16969                 printf("Please stop all ports first\n");
16970                 return;
16971         }
16972
16973 #ifdef RTE_LIBRTE_I40E_PMD
16974         if (!strcmp(res->inset_type, "hash_inset"))
16975                 inset_type = INSET_HASH;
16976         else if (!strcmp(res->inset_type, "fdir_inset"))
16977                 inset_type = INSET_FDIR;
16978         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16979                 inset_type = INSET_FDIR_FLX;
16980         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16981                                      &inset, inset_type);
16982         if (ret) {
16983                 printf("Failed to get input set.\n");
16984                 return;
16985         }
16986
16987         if (!strcmp(res->opt, "get")) {
16988                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16989                                                    res->field_idx);
16990                 if (ret)
16991                         printf("Field index %d is enabled.\n", res->field_idx);
16992                 else
16993                         printf("Field index %d is disabled.\n", res->field_idx);
16994                 return;
16995         } else if (!strcmp(res->opt, "set"))
16996                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16997                                                    res->field_idx);
16998         else if (!strcmp(res->opt, "clear"))
16999                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17000                                                      res->field_idx);
17001         if (ret) {
17002                 printf("Failed to configure input set field.\n");
17003                 return;
17004         }
17005
17006         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17007                                      &inset, inset_type);
17008         if (ret) {
17009                 printf("Failed to set input set.\n");
17010                 return;
17011         }
17012 #endif
17013
17014         if (ret == -ENOTSUP)
17015                 printf("Function not supported\n");
17016 }
17017
17018 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17019         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17020                                  port, "port");
17021 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17022         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17023                                  cfg, "config");
17024 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17025         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17026                               port_id, UINT16);
17027 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17028         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17029                                  pctype, "pctype");
17030 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17031         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17032                               pctype_id, UINT8);
17033 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17034         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17035                                  inset_type,
17036                                  "hash_inset#fdir_inset#fdir_flx_inset");
17037 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17038         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17039                                  opt, "get#set#clear");
17040 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17041         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17042                                  field, "field");
17043 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17044         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17045                               field_idx, UINT8);
17046
17047 cmdline_parse_inst_t cmd_cfg_input_set = {
17048         .f = cmd_cfg_input_set_parsed,
17049         .data = NULL,
17050         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17051                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17052         .tokens = {
17053                 (void *)&cmd_cfg_input_set_port,
17054                 (void *)&cmd_cfg_input_set_cfg,
17055                 (void *)&cmd_cfg_input_set_port_id,
17056                 (void *)&cmd_cfg_input_set_pctype,
17057                 (void *)&cmd_cfg_input_set_pctype_id,
17058                 (void *)&cmd_cfg_input_set_inset_type,
17059                 (void *)&cmd_cfg_input_set_opt,
17060                 (void *)&cmd_cfg_input_set_field,
17061                 (void *)&cmd_cfg_input_set_field_idx,
17062                 NULL,
17063         },
17064 };
17065
17066 /* Clear input set */
17067 struct cmd_clear_input_set_result {
17068         cmdline_fixed_string_t port;
17069         cmdline_fixed_string_t cfg;
17070         portid_t port_id;
17071         cmdline_fixed_string_t pctype;
17072         uint8_t pctype_id;
17073         cmdline_fixed_string_t inset_type;
17074         cmdline_fixed_string_t clear;
17075         cmdline_fixed_string_t all;
17076 };
17077
17078 static void
17079 cmd_clear_input_set_parsed(
17080         __rte_unused void *parsed_result,
17081         __rte_unused struct cmdline *cl,
17082         __rte_unused void *data)
17083 {
17084 #ifdef RTE_LIBRTE_I40E_PMD
17085         struct cmd_clear_input_set_result *res = parsed_result;
17086         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17087         struct rte_pmd_i40e_inset inset;
17088 #endif
17089         int ret = -ENOTSUP;
17090
17091         if (!all_ports_stopped()) {
17092                 printf("Please stop all ports first\n");
17093                 return;
17094         }
17095
17096 #ifdef RTE_LIBRTE_I40E_PMD
17097         if (!strcmp(res->inset_type, "hash_inset"))
17098                 inset_type = INSET_HASH;
17099         else if (!strcmp(res->inset_type, "fdir_inset"))
17100                 inset_type = INSET_FDIR;
17101         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17102                 inset_type = INSET_FDIR_FLX;
17103
17104         memset(&inset, 0, sizeof(inset));
17105
17106         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17107                                      &inset, inset_type);
17108         if (ret) {
17109                 printf("Failed to clear input set.\n");
17110                 return;
17111         }
17112
17113 #endif
17114
17115         if (ret == -ENOTSUP)
17116                 printf("Function not supported\n");
17117 }
17118
17119 cmdline_parse_token_string_t cmd_clear_input_set_port =
17120         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17121                                  port, "port");
17122 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17123         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17124                                  cfg, "config");
17125 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17126         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17127                               port_id, UINT16);
17128 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17129         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17130                                  pctype, "pctype");
17131 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17132         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17133                               pctype_id, UINT8);
17134 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17135         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17136                                  inset_type,
17137                                  "hash_inset#fdir_inset#fdir_flx_inset");
17138 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17139         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17140                                  clear, "clear");
17141 cmdline_parse_token_string_t cmd_clear_input_set_all =
17142         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17143                                  all, "all");
17144
17145 cmdline_parse_inst_t cmd_clear_input_set = {
17146         .f = cmd_clear_input_set_parsed,
17147         .data = NULL,
17148         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17149                     "fdir_inset|fdir_flx_inset clear all",
17150         .tokens = {
17151                 (void *)&cmd_clear_input_set_port,
17152                 (void *)&cmd_clear_input_set_cfg,
17153                 (void *)&cmd_clear_input_set_port_id,
17154                 (void *)&cmd_clear_input_set_pctype,
17155                 (void *)&cmd_clear_input_set_pctype_id,
17156                 (void *)&cmd_clear_input_set_inset_type,
17157                 (void *)&cmd_clear_input_set_clear,
17158                 (void *)&cmd_clear_input_set_all,
17159                 NULL,
17160         },
17161 };
17162
17163 /* show vf stats */
17164
17165 /* Common result structure for show vf stats */
17166 struct cmd_show_vf_stats_result {
17167         cmdline_fixed_string_t show;
17168         cmdline_fixed_string_t vf;
17169         cmdline_fixed_string_t stats;
17170         portid_t port_id;
17171         uint16_t vf_id;
17172 };
17173
17174 /* Common CLI fields show vf stats*/
17175 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17176         TOKEN_STRING_INITIALIZER
17177                 (struct cmd_show_vf_stats_result,
17178                  show, "show");
17179 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17180         TOKEN_STRING_INITIALIZER
17181                 (struct cmd_show_vf_stats_result,
17182                  vf, "vf");
17183 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17184         TOKEN_STRING_INITIALIZER
17185                 (struct cmd_show_vf_stats_result,
17186                  stats, "stats");
17187 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17188         TOKEN_NUM_INITIALIZER
17189                 (struct cmd_show_vf_stats_result,
17190                  port_id, UINT16);
17191 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17192         TOKEN_NUM_INITIALIZER
17193                 (struct cmd_show_vf_stats_result,
17194                  vf_id, UINT16);
17195
17196 static void
17197 cmd_show_vf_stats_parsed(
17198         void *parsed_result,
17199         __rte_unused struct cmdline *cl,
17200         __rte_unused void *data)
17201 {
17202         struct cmd_show_vf_stats_result *res = parsed_result;
17203         struct rte_eth_stats stats;
17204         int ret = -ENOTSUP;
17205         static const char *nic_stats_border = "########################";
17206
17207         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17208                 return;
17209
17210         memset(&stats, 0, sizeof(stats));
17211
17212 #ifdef RTE_LIBRTE_I40E_PMD
17213         if (ret == -ENOTSUP)
17214                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17215                                                 res->vf_id,
17216                                                 &stats);
17217 #endif
17218 #ifdef RTE_LIBRTE_BNXT_PMD
17219         if (ret == -ENOTSUP)
17220                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17221                                                 res->vf_id,
17222                                                 &stats);
17223 #endif
17224
17225         switch (ret) {
17226         case 0:
17227                 break;
17228         case -EINVAL:
17229                 printf("invalid vf_id %d\n", res->vf_id);
17230                 break;
17231         case -ENODEV:
17232                 printf("invalid port_id %d\n", res->port_id);
17233                 break;
17234         case -ENOTSUP:
17235                 printf("function not implemented\n");
17236                 break;
17237         default:
17238                 printf("programming error: (%s)\n", strerror(-ret));
17239         }
17240
17241         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17242                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17243
17244         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17245                "%-"PRIu64"\n",
17246                stats.ipackets, stats.imissed, stats.ibytes);
17247         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17248         printf("  RX-nombuf:  %-10"PRIu64"\n",
17249                stats.rx_nombuf);
17250         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17251                "%-"PRIu64"\n",
17252                stats.opackets, stats.oerrors, stats.obytes);
17253
17254         printf("  %s############################%s\n",
17255                                nic_stats_border, nic_stats_border);
17256 }
17257
17258 cmdline_parse_inst_t cmd_show_vf_stats = {
17259         .f = cmd_show_vf_stats_parsed,
17260         .data = NULL,
17261         .help_str = "show vf stats <port_id> <vf_id>",
17262         .tokens = {
17263                 (void *)&cmd_show_vf_stats_show,
17264                 (void *)&cmd_show_vf_stats_vf,
17265                 (void *)&cmd_show_vf_stats_stats,
17266                 (void *)&cmd_show_vf_stats_port_id,
17267                 (void *)&cmd_show_vf_stats_vf_id,
17268                 NULL,
17269         },
17270 };
17271
17272 /* clear vf stats */
17273
17274 /* Common result structure for clear vf stats */
17275 struct cmd_clear_vf_stats_result {
17276         cmdline_fixed_string_t clear;
17277         cmdline_fixed_string_t vf;
17278         cmdline_fixed_string_t stats;
17279         portid_t port_id;
17280         uint16_t vf_id;
17281 };
17282
17283 /* Common CLI fields clear vf stats*/
17284 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17285         TOKEN_STRING_INITIALIZER
17286                 (struct cmd_clear_vf_stats_result,
17287                  clear, "clear");
17288 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_clear_vf_stats_result,
17291                  vf, "vf");
17292 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17293         TOKEN_STRING_INITIALIZER
17294                 (struct cmd_clear_vf_stats_result,
17295                  stats, "stats");
17296 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17297         TOKEN_NUM_INITIALIZER
17298                 (struct cmd_clear_vf_stats_result,
17299                  port_id, UINT16);
17300 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17301         TOKEN_NUM_INITIALIZER
17302                 (struct cmd_clear_vf_stats_result,
17303                  vf_id, UINT16);
17304
17305 static void
17306 cmd_clear_vf_stats_parsed(
17307         void *parsed_result,
17308         __rte_unused struct cmdline *cl,
17309         __rte_unused void *data)
17310 {
17311         struct cmd_clear_vf_stats_result *res = parsed_result;
17312         int ret = -ENOTSUP;
17313
17314         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17315                 return;
17316
17317 #ifdef RTE_LIBRTE_I40E_PMD
17318         if (ret == -ENOTSUP)
17319                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17320                                                   res->vf_id);
17321 #endif
17322 #ifdef RTE_LIBRTE_BNXT_PMD
17323         if (ret == -ENOTSUP)
17324                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17325                                                   res->vf_id);
17326 #endif
17327
17328         switch (ret) {
17329         case 0:
17330                 break;
17331         case -EINVAL:
17332                 printf("invalid vf_id %d\n", res->vf_id);
17333                 break;
17334         case -ENODEV:
17335                 printf("invalid port_id %d\n", res->port_id);
17336                 break;
17337         case -ENOTSUP:
17338                 printf("function not implemented\n");
17339                 break;
17340         default:
17341                 printf("programming error: (%s)\n", strerror(-ret));
17342         }
17343 }
17344
17345 cmdline_parse_inst_t cmd_clear_vf_stats = {
17346         .f = cmd_clear_vf_stats_parsed,
17347         .data = NULL,
17348         .help_str = "clear vf stats <port_id> <vf_id>",
17349         .tokens = {
17350                 (void *)&cmd_clear_vf_stats_clear,
17351                 (void *)&cmd_clear_vf_stats_vf,
17352                 (void *)&cmd_clear_vf_stats_stats,
17353                 (void *)&cmd_clear_vf_stats_port_id,
17354                 (void *)&cmd_clear_vf_stats_vf_id,
17355                 NULL,
17356         },
17357 };
17358
17359 /* port config pctype mapping reset */
17360
17361 /* Common result structure for port config pctype mapping reset */
17362 struct cmd_pctype_mapping_reset_result {
17363         cmdline_fixed_string_t port;
17364         cmdline_fixed_string_t config;
17365         portid_t port_id;
17366         cmdline_fixed_string_t pctype;
17367         cmdline_fixed_string_t mapping;
17368         cmdline_fixed_string_t reset;
17369 };
17370
17371 /* Common CLI fields for port config pctype mapping reset*/
17372 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17373         TOKEN_STRING_INITIALIZER
17374                 (struct cmd_pctype_mapping_reset_result,
17375                  port, "port");
17376 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17377         TOKEN_STRING_INITIALIZER
17378                 (struct cmd_pctype_mapping_reset_result,
17379                  config, "config");
17380 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17381         TOKEN_NUM_INITIALIZER
17382                 (struct cmd_pctype_mapping_reset_result,
17383                  port_id, UINT16);
17384 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17385         TOKEN_STRING_INITIALIZER
17386                 (struct cmd_pctype_mapping_reset_result,
17387                  pctype, "pctype");
17388 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17389         TOKEN_STRING_INITIALIZER
17390                 (struct cmd_pctype_mapping_reset_result,
17391                  mapping, "mapping");
17392 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17393         TOKEN_STRING_INITIALIZER
17394                 (struct cmd_pctype_mapping_reset_result,
17395                  reset, "reset");
17396
17397 static void
17398 cmd_pctype_mapping_reset_parsed(
17399         void *parsed_result,
17400         __rte_unused struct cmdline *cl,
17401         __rte_unused void *data)
17402 {
17403         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17404         int ret = -ENOTSUP;
17405
17406         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17407                 return;
17408
17409 #ifdef RTE_LIBRTE_I40E_PMD
17410         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17411 #endif
17412
17413         switch (ret) {
17414         case 0:
17415                 break;
17416         case -ENODEV:
17417                 printf("invalid port_id %d\n", res->port_id);
17418                 break;
17419         case -ENOTSUP:
17420                 printf("function not implemented\n");
17421                 break;
17422         default:
17423                 printf("programming error: (%s)\n", strerror(-ret));
17424         }
17425 }
17426
17427 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17428         .f = cmd_pctype_mapping_reset_parsed,
17429         .data = NULL,
17430         .help_str = "port config <port_id> pctype mapping reset",
17431         .tokens = {
17432                 (void *)&cmd_pctype_mapping_reset_port,
17433                 (void *)&cmd_pctype_mapping_reset_config,
17434                 (void *)&cmd_pctype_mapping_reset_port_id,
17435                 (void *)&cmd_pctype_mapping_reset_pctype,
17436                 (void *)&cmd_pctype_mapping_reset_mapping,
17437                 (void *)&cmd_pctype_mapping_reset_reset,
17438                 NULL,
17439         },
17440 };
17441
17442 /* show port pctype mapping */
17443
17444 /* Common result structure for show port pctype mapping */
17445 struct cmd_pctype_mapping_get_result {
17446         cmdline_fixed_string_t show;
17447         cmdline_fixed_string_t port;
17448         portid_t port_id;
17449         cmdline_fixed_string_t pctype;
17450         cmdline_fixed_string_t mapping;
17451 };
17452
17453 /* Common CLI fields for pctype mapping get */
17454 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17455         TOKEN_STRING_INITIALIZER
17456                 (struct cmd_pctype_mapping_get_result,
17457                  show, "show");
17458 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17459         TOKEN_STRING_INITIALIZER
17460                 (struct cmd_pctype_mapping_get_result,
17461                  port, "port");
17462 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17463         TOKEN_NUM_INITIALIZER
17464                 (struct cmd_pctype_mapping_get_result,
17465                  port_id, UINT16);
17466 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17467         TOKEN_STRING_INITIALIZER
17468                 (struct cmd_pctype_mapping_get_result,
17469                  pctype, "pctype");
17470 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17471         TOKEN_STRING_INITIALIZER
17472                 (struct cmd_pctype_mapping_get_result,
17473                  mapping, "mapping");
17474
17475 static void
17476 cmd_pctype_mapping_get_parsed(
17477         void *parsed_result,
17478         __rte_unused struct cmdline *cl,
17479         __rte_unused void *data)
17480 {
17481         struct cmd_pctype_mapping_get_result *res = parsed_result;
17482         int ret = -ENOTSUP;
17483 #ifdef RTE_LIBRTE_I40E_PMD
17484         struct rte_pmd_i40e_flow_type_mapping
17485                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17486         int i, j, first_pctype;
17487 #endif
17488
17489         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17490                 return;
17491
17492 #ifdef RTE_LIBRTE_I40E_PMD
17493         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17494 #endif
17495
17496         switch (ret) {
17497         case 0:
17498                 break;
17499         case -ENODEV:
17500                 printf("invalid port_id %d\n", res->port_id);
17501                 return;
17502         case -ENOTSUP:
17503                 printf("function not implemented\n");
17504                 return;
17505         default:
17506                 printf("programming error: (%s)\n", strerror(-ret));
17507                 return;
17508         }
17509
17510 #ifdef RTE_LIBRTE_I40E_PMD
17511         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17512                 if (mapping[i].pctype != 0ULL) {
17513                         first_pctype = 1;
17514
17515                         printf("pctype: ");
17516                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17517                                 if (mapping[i].pctype & (1ULL << j)) {
17518                                         printf(first_pctype ?
17519                                                "%02d" : ",%02d", j);
17520                                         first_pctype = 0;
17521                                 }
17522                         }
17523                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17524                 }
17525         }
17526 #endif
17527 }
17528
17529 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17530         .f = cmd_pctype_mapping_get_parsed,
17531         .data = NULL,
17532         .help_str = "show port <port_id> pctype mapping",
17533         .tokens = {
17534                 (void *)&cmd_pctype_mapping_get_show,
17535                 (void *)&cmd_pctype_mapping_get_port,
17536                 (void *)&cmd_pctype_mapping_get_port_id,
17537                 (void *)&cmd_pctype_mapping_get_pctype,
17538                 (void *)&cmd_pctype_mapping_get_mapping,
17539                 NULL,
17540         },
17541 };
17542
17543 /* port config pctype mapping update */
17544
17545 /* Common result structure for port config pctype mapping update */
17546 struct cmd_pctype_mapping_update_result {
17547         cmdline_fixed_string_t port;
17548         cmdline_fixed_string_t config;
17549         portid_t port_id;
17550         cmdline_fixed_string_t pctype;
17551         cmdline_fixed_string_t mapping;
17552         cmdline_fixed_string_t update;
17553         cmdline_fixed_string_t pctype_list;
17554         uint16_t flow_type;
17555 };
17556
17557 /* Common CLI fields for pctype mapping update*/
17558 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17559         TOKEN_STRING_INITIALIZER
17560                 (struct cmd_pctype_mapping_update_result,
17561                  port, "port");
17562 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17563         TOKEN_STRING_INITIALIZER
17564                 (struct cmd_pctype_mapping_update_result,
17565                  config, "config");
17566 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17567         TOKEN_NUM_INITIALIZER
17568                 (struct cmd_pctype_mapping_update_result,
17569                  port_id, UINT16);
17570 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17571         TOKEN_STRING_INITIALIZER
17572                 (struct cmd_pctype_mapping_update_result,
17573                  pctype, "pctype");
17574 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17575         TOKEN_STRING_INITIALIZER
17576                 (struct cmd_pctype_mapping_update_result,
17577                  mapping, "mapping");
17578 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17579         TOKEN_STRING_INITIALIZER
17580                 (struct cmd_pctype_mapping_update_result,
17581                  update, "update");
17582 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17583         TOKEN_STRING_INITIALIZER
17584                 (struct cmd_pctype_mapping_update_result,
17585                  pctype_list, NULL);
17586 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17587         TOKEN_NUM_INITIALIZER
17588                 (struct cmd_pctype_mapping_update_result,
17589                  flow_type, UINT16);
17590
17591 static void
17592 cmd_pctype_mapping_update_parsed(
17593         void *parsed_result,
17594         __rte_unused struct cmdline *cl,
17595         __rte_unused void *data)
17596 {
17597         struct cmd_pctype_mapping_update_result *res = parsed_result;
17598         int ret = -ENOTSUP;
17599 #ifdef RTE_LIBRTE_I40E_PMD
17600         struct rte_pmd_i40e_flow_type_mapping mapping;
17601         unsigned int i;
17602         unsigned int nb_item;
17603         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17604 #endif
17605
17606         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17607                 return;
17608
17609 #ifdef RTE_LIBRTE_I40E_PMD
17610         nb_item = parse_item_list(res->pctype_list, "pctypes",
17611                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17612         mapping.flow_type = res->flow_type;
17613         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17614                 mapping.pctype |= (1ULL << pctype_list[i]);
17615         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17616                                                 &mapping,
17617                                                 1,
17618                                                 0);
17619 #endif
17620
17621         switch (ret) {
17622         case 0:
17623                 break;
17624         case -EINVAL:
17625                 printf("invalid pctype or flow type\n");
17626                 break;
17627         case -ENODEV:
17628                 printf("invalid port_id %d\n", res->port_id);
17629                 break;
17630         case -ENOTSUP:
17631                 printf("function not implemented\n");
17632                 break;
17633         default:
17634                 printf("programming error: (%s)\n", strerror(-ret));
17635         }
17636 }
17637
17638 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17639         .f = cmd_pctype_mapping_update_parsed,
17640         .data = NULL,
17641         .help_str = "port config <port_id> pctype mapping update"
17642         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17643         .tokens = {
17644                 (void *)&cmd_pctype_mapping_update_port,
17645                 (void *)&cmd_pctype_mapping_update_config,
17646                 (void *)&cmd_pctype_mapping_update_port_id,
17647                 (void *)&cmd_pctype_mapping_update_pctype,
17648                 (void *)&cmd_pctype_mapping_update_mapping,
17649                 (void *)&cmd_pctype_mapping_update_update,
17650                 (void *)&cmd_pctype_mapping_update_pc_type,
17651                 (void *)&cmd_pctype_mapping_update_flow_type,
17652                 NULL,
17653         },
17654 };
17655
17656 /* ptype mapping get */
17657
17658 /* Common result structure for ptype mapping get */
17659 struct cmd_ptype_mapping_get_result {
17660         cmdline_fixed_string_t ptype;
17661         cmdline_fixed_string_t mapping;
17662         cmdline_fixed_string_t get;
17663         portid_t port_id;
17664         uint8_t valid_only;
17665 };
17666
17667 /* Common CLI fields for ptype mapping get */
17668 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17669         TOKEN_STRING_INITIALIZER
17670                 (struct cmd_ptype_mapping_get_result,
17671                  ptype, "ptype");
17672 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17673         TOKEN_STRING_INITIALIZER
17674                 (struct cmd_ptype_mapping_get_result,
17675                  mapping, "mapping");
17676 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17677         TOKEN_STRING_INITIALIZER
17678                 (struct cmd_ptype_mapping_get_result,
17679                  get, "get");
17680 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17681         TOKEN_NUM_INITIALIZER
17682                 (struct cmd_ptype_mapping_get_result,
17683                  port_id, UINT16);
17684 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17685         TOKEN_NUM_INITIALIZER
17686                 (struct cmd_ptype_mapping_get_result,
17687                  valid_only, UINT8);
17688
17689 static void
17690 cmd_ptype_mapping_get_parsed(
17691         void *parsed_result,
17692         __rte_unused struct cmdline *cl,
17693         __rte_unused void *data)
17694 {
17695         struct cmd_ptype_mapping_get_result *res = parsed_result;
17696         int ret = -ENOTSUP;
17697 #ifdef RTE_LIBRTE_I40E_PMD
17698         int max_ptype_num = 256;
17699         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17700         uint16_t count;
17701         int i;
17702 #endif
17703
17704         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17705                 return;
17706
17707 #ifdef RTE_LIBRTE_I40E_PMD
17708         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17709                                         mapping,
17710                                         max_ptype_num,
17711                                         &count,
17712                                         res->valid_only);
17713 #endif
17714
17715         switch (ret) {
17716         case 0:
17717                 break;
17718         case -ENODEV:
17719                 printf("invalid port_id %d\n", res->port_id);
17720                 break;
17721         case -ENOTSUP:
17722                 printf("function not implemented\n");
17723                 break;
17724         default:
17725                 printf("programming error: (%s)\n", strerror(-ret));
17726         }
17727
17728 #ifdef RTE_LIBRTE_I40E_PMD
17729         if (!ret) {
17730                 for (i = 0; i < count; i++)
17731                         printf("%3d\t0x%08x\n",
17732                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17733         }
17734 #endif
17735 }
17736
17737 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17738         .f = cmd_ptype_mapping_get_parsed,
17739         .data = NULL,
17740         .help_str = "ptype mapping get <port_id> <valid_only>",
17741         .tokens = {
17742                 (void *)&cmd_ptype_mapping_get_ptype,
17743                 (void *)&cmd_ptype_mapping_get_mapping,
17744                 (void *)&cmd_ptype_mapping_get_get,
17745                 (void *)&cmd_ptype_mapping_get_port_id,
17746                 (void *)&cmd_ptype_mapping_get_valid_only,
17747                 NULL,
17748         },
17749 };
17750
17751 /* ptype mapping replace */
17752
17753 /* Common result structure for ptype mapping replace */
17754 struct cmd_ptype_mapping_replace_result {
17755         cmdline_fixed_string_t ptype;
17756         cmdline_fixed_string_t mapping;
17757         cmdline_fixed_string_t replace;
17758         portid_t port_id;
17759         uint32_t target;
17760         uint8_t mask;
17761         uint32_t pkt_type;
17762 };
17763
17764 /* Common CLI fields for ptype mapping replace */
17765 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17766         TOKEN_STRING_INITIALIZER
17767                 (struct cmd_ptype_mapping_replace_result,
17768                  ptype, "ptype");
17769 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17770         TOKEN_STRING_INITIALIZER
17771                 (struct cmd_ptype_mapping_replace_result,
17772                  mapping, "mapping");
17773 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17774         TOKEN_STRING_INITIALIZER
17775                 (struct cmd_ptype_mapping_replace_result,
17776                  replace, "replace");
17777 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17778         TOKEN_NUM_INITIALIZER
17779                 (struct cmd_ptype_mapping_replace_result,
17780                  port_id, UINT16);
17781 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17782         TOKEN_NUM_INITIALIZER
17783                 (struct cmd_ptype_mapping_replace_result,
17784                  target, UINT32);
17785 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17786         TOKEN_NUM_INITIALIZER
17787                 (struct cmd_ptype_mapping_replace_result,
17788                  mask, UINT8);
17789 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17790         TOKEN_NUM_INITIALIZER
17791                 (struct cmd_ptype_mapping_replace_result,
17792                  pkt_type, UINT32);
17793
17794 static void
17795 cmd_ptype_mapping_replace_parsed(
17796         void *parsed_result,
17797         __rte_unused struct cmdline *cl,
17798         __rte_unused void *data)
17799 {
17800         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17801         int ret = -ENOTSUP;
17802
17803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17804                 return;
17805
17806 #ifdef RTE_LIBRTE_I40E_PMD
17807         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17808                                         res->target,
17809                                         res->mask,
17810                                         res->pkt_type);
17811 #endif
17812
17813         switch (ret) {
17814         case 0:
17815                 break;
17816         case -EINVAL:
17817                 printf("invalid ptype 0x%8x or 0x%8x\n",
17818                                 res->target, res->pkt_type);
17819                 break;
17820         case -ENODEV:
17821                 printf("invalid port_id %d\n", res->port_id);
17822                 break;
17823         case -ENOTSUP:
17824                 printf("function not implemented\n");
17825                 break;
17826         default:
17827                 printf("programming error: (%s)\n", strerror(-ret));
17828         }
17829 }
17830
17831 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17832         .f = cmd_ptype_mapping_replace_parsed,
17833         .data = NULL,
17834         .help_str =
17835                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17836         .tokens = {
17837                 (void *)&cmd_ptype_mapping_replace_ptype,
17838                 (void *)&cmd_ptype_mapping_replace_mapping,
17839                 (void *)&cmd_ptype_mapping_replace_replace,
17840                 (void *)&cmd_ptype_mapping_replace_port_id,
17841                 (void *)&cmd_ptype_mapping_replace_target,
17842                 (void *)&cmd_ptype_mapping_replace_mask,
17843                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17844                 NULL,
17845         },
17846 };
17847
17848 /* ptype mapping reset */
17849
17850 /* Common result structure for ptype mapping reset */
17851 struct cmd_ptype_mapping_reset_result {
17852         cmdline_fixed_string_t ptype;
17853         cmdline_fixed_string_t mapping;
17854         cmdline_fixed_string_t reset;
17855         portid_t port_id;
17856 };
17857
17858 /* Common CLI fields for ptype mapping reset*/
17859 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17860         TOKEN_STRING_INITIALIZER
17861                 (struct cmd_ptype_mapping_reset_result,
17862                  ptype, "ptype");
17863 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17864         TOKEN_STRING_INITIALIZER
17865                 (struct cmd_ptype_mapping_reset_result,
17866                  mapping, "mapping");
17867 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17868         TOKEN_STRING_INITIALIZER
17869                 (struct cmd_ptype_mapping_reset_result,
17870                  reset, "reset");
17871 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17872         TOKEN_NUM_INITIALIZER
17873                 (struct cmd_ptype_mapping_reset_result,
17874                  port_id, UINT16);
17875
17876 static void
17877 cmd_ptype_mapping_reset_parsed(
17878         void *parsed_result,
17879         __rte_unused struct cmdline *cl,
17880         __rte_unused void *data)
17881 {
17882         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17883         int ret = -ENOTSUP;
17884
17885         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17886                 return;
17887
17888 #ifdef RTE_LIBRTE_I40E_PMD
17889         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17890 #endif
17891
17892         switch (ret) {
17893         case 0:
17894                 break;
17895         case -ENODEV:
17896                 printf("invalid port_id %d\n", res->port_id);
17897                 break;
17898         case -ENOTSUP:
17899                 printf("function not implemented\n");
17900                 break;
17901         default:
17902                 printf("programming error: (%s)\n", strerror(-ret));
17903         }
17904 }
17905
17906 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17907         .f = cmd_ptype_mapping_reset_parsed,
17908         .data = NULL,
17909         .help_str = "ptype mapping reset <port_id>",
17910         .tokens = {
17911                 (void *)&cmd_ptype_mapping_reset_ptype,
17912                 (void *)&cmd_ptype_mapping_reset_mapping,
17913                 (void *)&cmd_ptype_mapping_reset_reset,
17914                 (void *)&cmd_ptype_mapping_reset_port_id,
17915                 NULL,
17916         },
17917 };
17918
17919 /* ptype mapping update */
17920
17921 /* Common result structure for ptype mapping update */
17922 struct cmd_ptype_mapping_update_result {
17923         cmdline_fixed_string_t ptype;
17924         cmdline_fixed_string_t mapping;
17925         cmdline_fixed_string_t reset;
17926         portid_t port_id;
17927         uint8_t hw_ptype;
17928         uint32_t sw_ptype;
17929 };
17930
17931 /* Common CLI fields for ptype mapping update*/
17932 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17933         TOKEN_STRING_INITIALIZER
17934                 (struct cmd_ptype_mapping_update_result,
17935                  ptype, "ptype");
17936 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17937         TOKEN_STRING_INITIALIZER
17938                 (struct cmd_ptype_mapping_update_result,
17939                  mapping, "mapping");
17940 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17941         TOKEN_STRING_INITIALIZER
17942                 (struct cmd_ptype_mapping_update_result,
17943                  reset, "update");
17944 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17945         TOKEN_NUM_INITIALIZER
17946                 (struct cmd_ptype_mapping_update_result,
17947                  port_id, UINT16);
17948 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17949         TOKEN_NUM_INITIALIZER
17950                 (struct cmd_ptype_mapping_update_result,
17951                  hw_ptype, UINT8);
17952 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17953         TOKEN_NUM_INITIALIZER
17954                 (struct cmd_ptype_mapping_update_result,
17955                  sw_ptype, UINT32);
17956
17957 static void
17958 cmd_ptype_mapping_update_parsed(
17959         void *parsed_result,
17960         __rte_unused struct cmdline *cl,
17961         __rte_unused void *data)
17962 {
17963         struct cmd_ptype_mapping_update_result *res = parsed_result;
17964         int ret = -ENOTSUP;
17965 #ifdef RTE_LIBRTE_I40E_PMD
17966         struct rte_pmd_i40e_ptype_mapping mapping;
17967 #endif
17968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17969                 return;
17970
17971 #ifdef RTE_LIBRTE_I40E_PMD
17972         mapping.hw_ptype = res->hw_ptype;
17973         mapping.sw_ptype = res->sw_ptype;
17974         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17975                                                 &mapping,
17976                                                 1,
17977                                                 0);
17978 #endif
17979
17980         switch (ret) {
17981         case 0:
17982                 break;
17983         case -EINVAL:
17984                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17985                 break;
17986         case -ENODEV:
17987                 printf("invalid port_id %d\n", res->port_id);
17988                 break;
17989         case -ENOTSUP:
17990                 printf("function not implemented\n");
17991                 break;
17992         default:
17993                 printf("programming error: (%s)\n", strerror(-ret));
17994         }
17995 }
17996
17997 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17998         .f = cmd_ptype_mapping_update_parsed,
17999         .data = NULL,
18000         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18001         .tokens = {
18002                 (void *)&cmd_ptype_mapping_update_ptype,
18003                 (void *)&cmd_ptype_mapping_update_mapping,
18004                 (void *)&cmd_ptype_mapping_update_update,
18005                 (void *)&cmd_ptype_mapping_update_port_id,
18006                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18007                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18008                 NULL,
18009         },
18010 };
18011
18012 /* Common result structure for file commands */
18013 struct cmd_cmdfile_result {
18014         cmdline_fixed_string_t load;
18015         cmdline_fixed_string_t filename;
18016 };
18017
18018 /* Common CLI fields for file commands */
18019 cmdline_parse_token_string_t cmd_load_cmdfile =
18020         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18021 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18022         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18023
18024 static void
18025 cmd_load_from_file_parsed(
18026         void *parsed_result,
18027         __rte_unused struct cmdline *cl,
18028         __rte_unused void *data)
18029 {
18030         struct cmd_cmdfile_result *res = parsed_result;
18031
18032         cmdline_read_from_file(res->filename);
18033 }
18034
18035 cmdline_parse_inst_t cmd_load_from_file = {
18036         .f = cmd_load_from_file_parsed,
18037         .data = NULL,
18038         .help_str = "load <filename>",
18039         .tokens = {
18040                 (void *)&cmd_load_cmdfile,
18041                 (void *)&cmd_load_cmdfile_filename,
18042                 NULL,
18043         },
18044 };
18045
18046 /* Get Rx offloads capabilities */
18047 struct cmd_rx_offload_get_capa_result {
18048         cmdline_fixed_string_t show;
18049         cmdline_fixed_string_t port;
18050         portid_t port_id;
18051         cmdline_fixed_string_t rx_offload;
18052         cmdline_fixed_string_t capabilities;
18053 };
18054
18055 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18056         TOKEN_STRING_INITIALIZER
18057                 (struct cmd_rx_offload_get_capa_result,
18058                  show, "show");
18059 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18060         TOKEN_STRING_INITIALIZER
18061                 (struct cmd_rx_offload_get_capa_result,
18062                  port, "port");
18063 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18064         TOKEN_NUM_INITIALIZER
18065                 (struct cmd_rx_offload_get_capa_result,
18066                  port_id, UINT16);
18067 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18068         TOKEN_STRING_INITIALIZER
18069                 (struct cmd_rx_offload_get_capa_result,
18070                  rx_offload, "rx_offload");
18071 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18072         TOKEN_STRING_INITIALIZER
18073                 (struct cmd_rx_offload_get_capa_result,
18074                  capabilities, "capabilities");
18075
18076 static void
18077 print_rx_offloads(uint64_t offloads)
18078 {
18079         uint64_t single_offload;
18080         int begin;
18081         int end;
18082         int bit;
18083
18084         if (offloads == 0)
18085                 return;
18086
18087         begin = __builtin_ctzll(offloads);
18088         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18089
18090         single_offload = 1ULL << begin;
18091         for (bit = begin; bit < end; bit++) {
18092                 if (offloads & single_offload)
18093                         printf(" %s",
18094                                rte_eth_dev_rx_offload_name(single_offload));
18095                 single_offload <<= 1;
18096         }
18097 }
18098
18099 static void
18100 cmd_rx_offload_get_capa_parsed(
18101         void *parsed_result,
18102         __rte_unused struct cmdline *cl,
18103         __rte_unused void *data)
18104 {
18105         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18106         struct rte_eth_dev_info dev_info;
18107         portid_t port_id = res->port_id;
18108         uint64_t queue_offloads;
18109         uint64_t port_offloads;
18110         int ret;
18111
18112         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18113         if (ret != 0)
18114                 return;
18115
18116         queue_offloads = dev_info.rx_queue_offload_capa;
18117         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18118
18119         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18120         printf("  Per Queue :");
18121         print_rx_offloads(queue_offloads);
18122
18123         printf("\n");
18124         printf("  Per Port  :");
18125         print_rx_offloads(port_offloads);
18126         printf("\n\n");
18127 }
18128
18129 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18130         .f = cmd_rx_offload_get_capa_parsed,
18131         .data = NULL,
18132         .help_str = "show port <port_id> rx_offload capabilities",
18133         .tokens = {
18134                 (void *)&cmd_rx_offload_get_capa_show,
18135                 (void *)&cmd_rx_offload_get_capa_port,
18136                 (void *)&cmd_rx_offload_get_capa_port_id,
18137                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18138                 (void *)&cmd_rx_offload_get_capa_capabilities,
18139                 NULL,
18140         }
18141 };
18142
18143 /* Get Rx offloads configuration */
18144 struct cmd_rx_offload_get_configuration_result {
18145         cmdline_fixed_string_t show;
18146         cmdline_fixed_string_t port;
18147         portid_t port_id;
18148         cmdline_fixed_string_t rx_offload;
18149         cmdline_fixed_string_t configuration;
18150 };
18151
18152 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18153         TOKEN_STRING_INITIALIZER
18154                 (struct cmd_rx_offload_get_configuration_result,
18155                  show, "show");
18156 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18157         TOKEN_STRING_INITIALIZER
18158                 (struct cmd_rx_offload_get_configuration_result,
18159                  port, "port");
18160 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18161         TOKEN_NUM_INITIALIZER
18162                 (struct cmd_rx_offload_get_configuration_result,
18163                  port_id, UINT16);
18164 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18165         TOKEN_STRING_INITIALIZER
18166                 (struct cmd_rx_offload_get_configuration_result,
18167                  rx_offload, "rx_offload");
18168 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18169         TOKEN_STRING_INITIALIZER
18170                 (struct cmd_rx_offload_get_configuration_result,
18171                  configuration, "configuration");
18172
18173 static void
18174 cmd_rx_offload_get_configuration_parsed(
18175         void *parsed_result,
18176         __rte_unused struct cmdline *cl,
18177         __rte_unused void *data)
18178 {
18179         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18180         struct rte_eth_dev_info dev_info;
18181         portid_t port_id = res->port_id;
18182         struct rte_port *port = &ports[port_id];
18183         uint64_t port_offloads;
18184         uint64_t queue_offloads;
18185         uint16_t nb_rx_queues;
18186         int q;
18187         int ret;
18188
18189         printf("Rx Offloading Configuration of port %d :\n", port_id);
18190
18191         port_offloads = port->dev_conf.rxmode.offloads;
18192         printf("  Port :");
18193         print_rx_offloads(port_offloads);
18194         printf("\n");
18195
18196         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18197         if (ret != 0)
18198                 return;
18199
18200         nb_rx_queues = dev_info.nb_rx_queues;
18201         for (q = 0; q < nb_rx_queues; q++) {
18202                 queue_offloads = port->rx_conf[q].offloads;
18203                 printf("  Queue[%2d] :", q);
18204                 print_rx_offloads(queue_offloads);
18205                 printf("\n");
18206         }
18207         printf("\n");
18208 }
18209
18210 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18211         .f = cmd_rx_offload_get_configuration_parsed,
18212         .data = NULL,
18213         .help_str = "show port <port_id> rx_offload configuration",
18214         .tokens = {
18215                 (void *)&cmd_rx_offload_get_configuration_show,
18216                 (void *)&cmd_rx_offload_get_configuration_port,
18217                 (void *)&cmd_rx_offload_get_configuration_port_id,
18218                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18219                 (void *)&cmd_rx_offload_get_configuration_configuration,
18220                 NULL,
18221         }
18222 };
18223
18224 /* Enable/Disable a per port offloading */
18225 struct cmd_config_per_port_rx_offload_result {
18226         cmdline_fixed_string_t port;
18227         cmdline_fixed_string_t config;
18228         portid_t port_id;
18229         cmdline_fixed_string_t rx_offload;
18230         cmdline_fixed_string_t offload;
18231         cmdline_fixed_string_t on_off;
18232 };
18233
18234 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18235         TOKEN_STRING_INITIALIZER
18236                 (struct cmd_config_per_port_rx_offload_result,
18237                  port, "port");
18238 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18239         TOKEN_STRING_INITIALIZER
18240                 (struct cmd_config_per_port_rx_offload_result,
18241                  config, "config");
18242 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18243         TOKEN_NUM_INITIALIZER
18244                 (struct cmd_config_per_port_rx_offload_result,
18245                  port_id, UINT16);
18246 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18247         TOKEN_STRING_INITIALIZER
18248                 (struct cmd_config_per_port_rx_offload_result,
18249                  rx_offload, "rx_offload");
18250 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18251         TOKEN_STRING_INITIALIZER
18252                 (struct cmd_config_per_port_rx_offload_result,
18253                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18254                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18255                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18256                            "scatter#timestamp#security#keep_crc#rss_hash");
18257 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18258         TOKEN_STRING_INITIALIZER
18259                 (struct cmd_config_per_port_rx_offload_result,
18260                  on_off, "on#off");
18261
18262 static uint64_t
18263 search_rx_offload(const char *name)
18264 {
18265         uint64_t single_offload;
18266         const char *single_name;
18267         int found = 0;
18268         unsigned int bit;
18269
18270         single_offload = 1;
18271         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18272                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18273                 if (!strcasecmp(single_name, name)) {
18274                         found = 1;
18275                         break;
18276                 }
18277                 single_offload <<= 1;
18278         }
18279
18280         if (found)
18281                 return single_offload;
18282
18283         return 0;
18284 }
18285
18286 static void
18287 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18288                                 __rte_unused struct cmdline *cl,
18289                                 __rte_unused void *data)
18290 {
18291         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18292         portid_t port_id = res->port_id;
18293         struct rte_eth_dev_info dev_info;
18294         struct rte_port *port = &ports[port_id];
18295         uint64_t single_offload;
18296         uint16_t nb_rx_queues;
18297         int q;
18298         int ret;
18299
18300         if (port->port_status != RTE_PORT_STOPPED) {
18301                 printf("Error: Can't config offload when Port %d "
18302                        "is not stopped\n", port_id);
18303                 return;
18304         }
18305
18306         single_offload = search_rx_offload(res->offload);
18307         if (single_offload == 0) {
18308                 printf("Unknown offload name: %s\n", res->offload);
18309                 return;
18310         }
18311
18312         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18313         if (ret != 0)
18314                 return;
18315
18316         nb_rx_queues = dev_info.nb_rx_queues;
18317         if (!strcmp(res->on_off, "on")) {
18318                 port->dev_conf.rxmode.offloads |= single_offload;
18319                 for (q = 0; q < nb_rx_queues; q++)
18320                         port->rx_conf[q].offloads |= single_offload;
18321         } else {
18322                 port->dev_conf.rxmode.offloads &= ~single_offload;
18323                 for (q = 0; q < nb_rx_queues; q++)
18324                         port->rx_conf[q].offloads &= ~single_offload;
18325         }
18326
18327         cmd_reconfig_device_queue(port_id, 1, 1);
18328 }
18329
18330 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18331         .f = cmd_config_per_port_rx_offload_parsed,
18332         .data = NULL,
18333         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18334                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18335                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18336                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18337                     "on|off",
18338         .tokens = {
18339                 (void *)&cmd_config_per_port_rx_offload_result_port,
18340                 (void *)&cmd_config_per_port_rx_offload_result_config,
18341                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18342                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18343                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18344                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18345                 NULL,
18346         }
18347 };
18348
18349 /* Enable/Disable a per queue offloading */
18350 struct cmd_config_per_queue_rx_offload_result {
18351         cmdline_fixed_string_t port;
18352         portid_t port_id;
18353         cmdline_fixed_string_t rxq;
18354         uint16_t queue_id;
18355         cmdline_fixed_string_t rx_offload;
18356         cmdline_fixed_string_t offload;
18357         cmdline_fixed_string_t on_off;
18358 };
18359
18360 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18361         TOKEN_STRING_INITIALIZER
18362                 (struct cmd_config_per_queue_rx_offload_result,
18363                  port, "port");
18364 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18365         TOKEN_NUM_INITIALIZER
18366                 (struct cmd_config_per_queue_rx_offload_result,
18367                  port_id, UINT16);
18368 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18369         TOKEN_STRING_INITIALIZER
18370                 (struct cmd_config_per_queue_rx_offload_result,
18371                  rxq, "rxq");
18372 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18373         TOKEN_NUM_INITIALIZER
18374                 (struct cmd_config_per_queue_rx_offload_result,
18375                  queue_id, UINT16);
18376 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18377         TOKEN_STRING_INITIALIZER
18378                 (struct cmd_config_per_queue_rx_offload_result,
18379                  rx_offload, "rx_offload");
18380 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18381         TOKEN_STRING_INITIALIZER
18382                 (struct cmd_config_per_queue_rx_offload_result,
18383                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18384                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18385                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18386                            "scatter#timestamp#security#keep_crc");
18387 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18388         TOKEN_STRING_INITIALIZER
18389                 (struct cmd_config_per_queue_rx_offload_result,
18390                  on_off, "on#off");
18391
18392 static void
18393 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18394                                 __rte_unused struct cmdline *cl,
18395                                 __rte_unused void *data)
18396 {
18397         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18398         struct rte_eth_dev_info dev_info;
18399         portid_t port_id = res->port_id;
18400         uint16_t queue_id = res->queue_id;
18401         struct rte_port *port = &ports[port_id];
18402         uint64_t single_offload;
18403         int ret;
18404
18405         if (port->port_status != RTE_PORT_STOPPED) {
18406                 printf("Error: Can't config offload when Port %d "
18407                        "is not stopped\n", port_id);
18408                 return;
18409         }
18410
18411         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18412         if (ret != 0)
18413                 return;
18414
18415         if (queue_id >= dev_info.nb_rx_queues) {
18416                 printf("Error: input queue_id should be 0 ... "
18417                        "%d\n", dev_info.nb_rx_queues - 1);
18418                 return;
18419         }
18420
18421         single_offload = search_rx_offload(res->offload);
18422         if (single_offload == 0) {
18423                 printf("Unknown offload name: %s\n", res->offload);
18424                 return;
18425         }
18426
18427         if (!strcmp(res->on_off, "on"))
18428                 port->rx_conf[queue_id].offloads |= single_offload;
18429         else
18430                 port->rx_conf[queue_id].offloads &= ~single_offload;
18431
18432         cmd_reconfig_device_queue(port_id, 1, 1);
18433 }
18434
18435 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18436         .f = cmd_config_per_queue_rx_offload_parsed,
18437         .data = NULL,
18438         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18439                     "vlan_strip|ipv4_cksum|"
18440                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18441                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18442                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18443                     "on|off",
18444         .tokens = {
18445                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18446                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18447                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18448                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18449                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18450                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18451                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18452                 NULL,
18453         }
18454 };
18455
18456 /* Get Tx offloads capabilities */
18457 struct cmd_tx_offload_get_capa_result {
18458         cmdline_fixed_string_t show;
18459         cmdline_fixed_string_t port;
18460         portid_t port_id;
18461         cmdline_fixed_string_t tx_offload;
18462         cmdline_fixed_string_t capabilities;
18463 };
18464
18465 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18466         TOKEN_STRING_INITIALIZER
18467                 (struct cmd_tx_offload_get_capa_result,
18468                  show, "show");
18469 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18470         TOKEN_STRING_INITIALIZER
18471                 (struct cmd_tx_offload_get_capa_result,
18472                  port, "port");
18473 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18474         TOKEN_NUM_INITIALIZER
18475                 (struct cmd_tx_offload_get_capa_result,
18476                  port_id, UINT16);
18477 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18478         TOKEN_STRING_INITIALIZER
18479                 (struct cmd_tx_offload_get_capa_result,
18480                  tx_offload, "tx_offload");
18481 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18482         TOKEN_STRING_INITIALIZER
18483                 (struct cmd_tx_offload_get_capa_result,
18484                  capabilities, "capabilities");
18485
18486 static void
18487 print_tx_offloads(uint64_t offloads)
18488 {
18489         uint64_t single_offload;
18490         int begin;
18491         int end;
18492         int bit;
18493
18494         if (offloads == 0)
18495                 return;
18496
18497         begin = __builtin_ctzll(offloads);
18498         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18499
18500         single_offload = 1ULL << begin;
18501         for (bit = begin; bit < end; bit++) {
18502                 if (offloads & single_offload)
18503                         printf(" %s",
18504                                rte_eth_dev_tx_offload_name(single_offload));
18505                 single_offload <<= 1;
18506         }
18507 }
18508
18509 static void
18510 cmd_tx_offload_get_capa_parsed(
18511         void *parsed_result,
18512         __rte_unused struct cmdline *cl,
18513         __rte_unused void *data)
18514 {
18515         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18516         struct rte_eth_dev_info dev_info;
18517         portid_t port_id = res->port_id;
18518         uint64_t queue_offloads;
18519         uint64_t port_offloads;
18520         int ret;
18521
18522         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18523         if (ret != 0)
18524                 return;
18525
18526         queue_offloads = dev_info.tx_queue_offload_capa;
18527         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18528
18529         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18530         printf("  Per Queue :");
18531         print_tx_offloads(queue_offloads);
18532
18533         printf("\n");
18534         printf("  Per Port  :");
18535         print_tx_offloads(port_offloads);
18536         printf("\n\n");
18537 }
18538
18539 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18540         .f = cmd_tx_offload_get_capa_parsed,
18541         .data = NULL,
18542         .help_str = "show port <port_id> tx_offload capabilities",
18543         .tokens = {
18544                 (void *)&cmd_tx_offload_get_capa_show,
18545                 (void *)&cmd_tx_offload_get_capa_port,
18546                 (void *)&cmd_tx_offload_get_capa_port_id,
18547                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18548                 (void *)&cmd_tx_offload_get_capa_capabilities,
18549                 NULL,
18550         }
18551 };
18552
18553 /* Get Tx offloads configuration */
18554 struct cmd_tx_offload_get_configuration_result {
18555         cmdline_fixed_string_t show;
18556         cmdline_fixed_string_t port;
18557         portid_t port_id;
18558         cmdline_fixed_string_t tx_offload;
18559         cmdline_fixed_string_t configuration;
18560 };
18561
18562 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_tx_offload_get_configuration_result,
18565                  show, "show");
18566 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18567         TOKEN_STRING_INITIALIZER
18568                 (struct cmd_tx_offload_get_configuration_result,
18569                  port, "port");
18570 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18571         TOKEN_NUM_INITIALIZER
18572                 (struct cmd_tx_offload_get_configuration_result,
18573                  port_id, UINT16);
18574 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18575         TOKEN_STRING_INITIALIZER
18576                 (struct cmd_tx_offload_get_configuration_result,
18577                  tx_offload, "tx_offload");
18578 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18579         TOKEN_STRING_INITIALIZER
18580                 (struct cmd_tx_offload_get_configuration_result,
18581                  configuration, "configuration");
18582
18583 static void
18584 cmd_tx_offload_get_configuration_parsed(
18585         void *parsed_result,
18586         __rte_unused struct cmdline *cl,
18587         __rte_unused void *data)
18588 {
18589         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18590         struct rte_eth_dev_info dev_info;
18591         portid_t port_id = res->port_id;
18592         struct rte_port *port = &ports[port_id];
18593         uint64_t port_offloads;
18594         uint64_t queue_offloads;
18595         uint16_t nb_tx_queues;
18596         int q;
18597         int ret;
18598
18599         printf("Tx Offloading Configuration of port %d :\n", port_id);
18600
18601         port_offloads = port->dev_conf.txmode.offloads;
18602         printf("  Port :");
18603         print_tx_offloads(port_offloads);
18604         printf("\n");
18605
18606         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18607         if (ret != 0)
18608                 return;
18609
18610         nb_tx_queues = dev_info.nb_tx_queues;
18611         for (q = 0; q < nb_tx_queues; q++) {
18612                 queue_offloads = port->tx_conf[q].offloads;
18613                 printf("  Queue[%2d] :", q);
18614                 print_tx_offloads(queue_offloads);
18615                 printf("\n");
18616         }
18617         printf("\n");
18618 }
18619
18620 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18621         .f = cmd_tx_offload_get_configuration_parsed,
18622         .data = NULL,
18623         .help_str = "show port <port_id> tx_offload configuration",
18624         .tokens = {
18625                 (void *)&cmd_tx_offload_get_configuration_show,
18626                 (void *)&cmd_tx_offload_get_configuration_port,
18627                 (void *)&cmd_tx_offload_get_configuration_port_id,
18628                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18629                 (void *)&cmd_tx_offload_get_configuration_configuration,
18630                 NULL,
18631         }
18632 };
18633
18634 /* Enable/Disable a per port offloading */
18635 struct cmd_config_per_port_tx_offload_result {
18636         cmdline_fixed_string_t port;
18637         cmdline_fixed_string_t config;
18638         portid_t port_id;
18639         cmdline_fixed_string_t tx_offload;
18640         cmdline_fixed_string_t offload;
18641         cmdline_fixed_string_t on_off;
18642 };
18643
18644 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18645         TOKEN_STRING_INITIALIZER
18646                 (struct cmd_config_per_port_tx_offload_result,
18647                  port, "port");
18648 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18649         TOKEN_STRING_INITIALIZER
18650                 (struct cmd_config_per_port_tx_offload_result,
18651                  config, "config");
18652 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18653         TOKEN_NUM_INITIALIZER
18654                 (struct cmd_config_per_port_tx_offload_result,
18655                  port_id, UINT16);
18656 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18657         TOKEN_STRING_INITIALIZER
18658                 (struct cmd_config_per_port_tx_offload_result,
18659                  tx_offload, "tx_offload");
18660 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18661         TOKEN_STRING_INITIALIZER
18662                 (struct cmd_config_per_port_tx_offload_result,
18663                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18664                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18665                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18666                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18667                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18668 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18669         TOKEN_STRING_INITIALIZER
18670                 (struct cmd_config_per_port_tx_offload_result,
18671                  on_off, "on#off");
18672
18673 static uint64_t
18674 search_tx_offload(const char *name)
18675 {
18676         uint64_t single_offload;
18677         const char *single_name;
18678         int found = 0;
18679         unsigned int bit;
18680
18681         single_offload = 1;
18682         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18683                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18684                 if (single_name == NULL)
18685                         break;
18686                 if (!strcasecmp(single_name, name)) {
18687                         found = 1;
18688                         break;
18689                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18690                         break;
18691                 single_offload <<= 1;
18692         }
18693
18694         if (found)
18695                 return single_offload;
18696
18697         return 0;
18698 }
18699
18700 static void
18701 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18702                                 __rte_unused struct cmdline *cl,
18703                                 __rte_unused void *data)
18704 {
18705         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18706         portid_t port_id = res->port_id;
18707         struct rte_eth_dev_info dev_info;
18708         struct rte_port *port = &ports[port_id];
18709         uint64_t single_offload;
18710         uint16_t nb_tx_queues;
18711         int q;
18712         int ret;
18713
18714         if (port->port_status != RTE_PORT_STOPPED) {
18715                 printf("Error: Can't config offload when Port %d "
18716                        "is not stopped\n", port_id);
18717                 return;
18718         }
18719
18720         single_offload = search_tx_offload(res->offload);
18721         if (single_offload == 0) {
18722                 printf("Unknown offload name: %s\n", res->offload);
18723                 return;
18724         }
18725
18726         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18727         if (ret != 0)
18728                 return;
18729
18730         nb_tx_queues = dev_info.nb_tx_queues;
18731         if (!strcmp(res->on_off, "on")) {
18732                 port->dev_conf.txmode.offloads |= single_offload;
18733                 for (q = 0; q < nb_tx_queues; q++)
18734                         port->tx_conf[q].offloads |= single_offload;
18735         } else {
18736                 port->dev_conf.txmode.offloads &= ~single_offload;
18737                 for (q = 0; q < nb_tx_queues; q++)
18738                         port->tx_conf[q].offloads &= ~single_offload;
18739         }
18740
18741         cmd_reconfig_device_queue(port_id, 1, 1);
18742 }
18743
18744 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18745         .f = cmd_config_per_port_tx_offload_parsed,
18746         .data = NULL,
18747         .help_str = "port config <port_id> tx_offload "
18748                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18749                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18750                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18751                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18752                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18753         .tokens = {
18754                 (void *)&cmd_config_per_port_tx_offload_result_port,
18755                 (void *)&cmd_config_per_port_tx_offload_result_config,
18756                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18757                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18758                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18759                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18760                 NULL,
18761         }
18762 };
18763
18764 /* Enable/Disable a per queue offloading */
18765 struct cmd_config_per_queue_tx_offload_result {
18766         cmdline_fixed_string_t port;
18767         portid_t port_id;
18768         cmdline_fixed_string_t txq;
18769         uint16_t queue_id;
18770         cmdline_fixed_string_t tx_offload;
18771         cmdline_fixed_string_t offload;
18772         cmdline_fixed_string_t on_off;
18773 };
18774
18775 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18776         TOKEN_STRING_INITIALIZER
18777                 (struct cmd_config_per_queue_tx_offload_result,
18778                  port, "port");
18779 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18780         TOKEN_NUM_INITIALIZER
18781                 (struct cmd_config_per_queue_tx_offload_result,
18782                  port_id, UINT16);
18783 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18784         TOKEN_STRING_INITIALIZER
18785                 (struct cmd_config_per_queue_tx_offload_result,
18786                  txq, "txq");
18787 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18788         TOKEN_NUM_INITIALIZER
18789                 (struct cmd_config_per_queue_tx_offload_result,
18790                  queue_id, UINT16);
18791 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18792         TOKEN_STRING_INITIALIZER
18793                 (struct cmd_config_per_queue_tx_offload_result,
18794                  tx_offload, "tx_offload");
18795 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18796         TOKEN_STRING_INITIALIZER
18797                 (struct cmd_config_per_queue_tx_offload_result,
18798                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18799                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18800                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18801                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18802                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18803 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18804         TOKEN_STRING_INITIALIZER
18805                 (struct cmd_config_per_queue_tx_offload_result,
18806                  on_off, "on#off");
18807
18808 static void
18809 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18810                                 __rte_unused struct cmdline *cl,
18811                                 __rte_unused void *data)
18812 {
18813         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18814         struct rte_eth_dev_info dev_info;
18815         portid_t port_id = res->port_id;
18816         uint16_t queue_id = res->queue_id;
18817         struct rte_port *port = &ports[port_id];
18818         uint64_t single_offload;
18819         int ret;
18820
18821         if (port->port_status != RTE_PORT_STOPPED) {
18822                 printf("Error: Can't config offload when Port %d "
18823                        "is not stopped\n", port_id);
18824                 return;
18825         }
18826
18827         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18828         if (ret != 0)
18829                 return;
18830
18831         if (queue_id >= dev_info.nb_tx_queues) {
18832                 printf("Error: input queue_id should be 0 ... "
18833                        "%d\n", dev_info.nb_tx_queues - 1);
18834                 return;
18835         }
18836
18837         single_offload = search_tx_offload(res->offload);
18838         if (single_offload == 0) {
18839                 printf("Unknown offload name: %s\n", res->offload);
18840                 return;
18841         }
18842
18843         if (!strcmp(res->on_off, "on"))
18844                 port->tx_conf[queue_id].offloads |= single_offload;
18845         else
18846                 port->tx_conf[queue_id].offloads &= ~single_offload;
18847
18848         cmd_reconfig_device_queue(port_id, 1, 1);
18849 }
18850
18851 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18852         .f = cmd_config_per_queue_tx_offload_parsed,
18853         .data = NULL,
18854         .help_str = "port <port_id> txq <queue_id> tx_offload "
18855                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18856                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18857                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18858                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18859                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18860                     "on|off",
18861         .tokens = {
18862                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18863                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18864                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18865                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18866                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18867                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18868                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18869                 NULL,
18870         }
18871 };
18872
18873 /* *** configure tx_metadata for specific port *** */
18874 struct cmd_config_tx_metadata_specific_result {
18875         cmdline_fixed_string_t port;
18876         cmdline_fixed_string_t keyword;
18877         uint16_t port_id;
18878         cmdline_fixed_string_t item;
18879         uint32_t value;
18880 };
18881
18882 static void
18883 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18884                                 __rte_unused struct cmdline *cl,
18885                                 __rte_unused void *data)
18886 {
18887         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18888
18889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18890                 return;
18891         ports[res->port_id].tx_metadata = res->value;
18892         /* Add/remove callback to insert valid metadata in every Tx packet. */
18893         if (ports[res->port_id].tx_metadata)
18894                 add_tx_md_callback(res->port_id);
18895         else
18896                 remove_tx_md_callback(res->port_id);
18897         rte_flow_dynf_metadata_register();
18898 }
18899
18900 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18901         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18902                         port, "port");
18903 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18904         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18905                         keyword, "config");
18906 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18907         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18908                         port_id, UINT16);
18909 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18910         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18911                         item, "tx_metadata");
18912 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18913         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18914                         value, UINT32);
18915
18916 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18917         .f = cmd_config_tx_metadata_specific_parsed,
18918         .data = NULL,
18919         .help_str = "port config <port_id> tx_metadata <value>",
18920         .tokens = {
18921                 (void *)&cmd_config_tx_metadata_specific_port,
18922                 (void *)&cmd_config_tx_metadata_specific_keyword,
18923                 (void *)&cmd_config_tx_metadata_specific_id,
18924                 (void *)&cmd_config_tx_metadata_specific_item,
18925                 (void *)&cmd_config_tx_metadata_specific_value,
18926                 NULL,
18927         },
18928 };
18929
18930 /* *** set dynf *** */
18931 struct cmd_config_tx_dynf_specific_result {
18932         cmdline_fixed_string_t port;
18933         cmdline_fixed_string_t keyword;
18934         uint16_t port_id;
18935         cmdline_fixed_string_t item;
18936         cmdline_fixed_string_t name;
18937         cmdline_fixed_string_t value;
18938 };
18939
18940 static void
18941 cmd_config_dynf_specific_parsed(void *parsed_result,
18942                                 __rte_unused struct cmdline *cl,
18943                                 __rte_unused void *data)
18944 {
18945         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18946         struct rte_mbuf_dynflag desc_flag;
18947         int flag;
18948         uint64_t old_port_flags;
18949
18950         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18951                 return;
18952         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18953         if (flag <= 0) {
18954                 if (strlcpy(desc_flag.name, res->name,
18955                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18956                         printf("Flag name too long\n");
18957                         return;
18958                 }
18959                 desc_flag.flags = 0;
18960                 flag = rte_mbuf_dynflag_register(&desc_flag);
18961                 if (flag < 0) {
18962                         printf("Can't register flag\n");
18963                         return;
18964                 }
18965                 strcpy(dynf_names[flag], desc_flag.name);
18966         }
18967         old_port_flags = ports[res->port_id].mbuf_dynf;
18968         if (!strcmp(res->value, "set")) {
18969                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18970                 if (old_port_flags == 0)
18971                         add_tx_dynf_callback(res->port_id);
18972         } else {
18973                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18974                 if (ports[res->port_id].mbuf_dynf == 0)
18975                         remove_tx_dynf_callback(res->port_id);
18976         }
18977 }
18978
18979 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18980         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18981                         keyword, "port");
18982 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18983         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18984                         keyword, "config");
18985 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18986         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18987                         port_id, UINT16);
18988 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18989         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18990                         item, "dynf");
18991 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18992         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18993                         name, NULL);
18994 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18995         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18996                         value, "set#clear");
18997
18998 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18999         .f = cmd_config_dynf_specific_parsed,
19000         .data = NULL,
19001         .help_str = "port config <port id> dynf <name> set|clear",
19002         .tokens = {
19003                 (void *)&cmd_config_tx_dynf_specific_port,
19004                 (void *)&cmd_config_tx_dynf_specific_keyword,
19005                 (void *)&cmd_config_tx_dynf_specific_port_id,
19006                 (void *)&cmd_config_tx_dynf_specific_item,
19007                 (void *)&cmd_config_tx_dynf_specific_name,
19008                 (void *)&cmd_config_tx_dynf_specific_value,
19009                 NULL,
19010         },
19011 };
19012
19013 /* *** display tx_metadata per port configuration *** */
19014 struct cmd_show_tx_metadata_result {
19015         cmdline_fixed_string_t cmd_show;
19016         cmdline_fixed_string_t cmd_port;
19017         cmdline_fixed_string_t cmd_keyword;
19018         portid_t cmd_pid;
19019 };
19020
19021 static void
19022 cmd_show_tx_metadata_parsed(void *parsed_result,
19023                 __rte_unused struct cmdline *cl,
19024                 __rte_unused void *data)
19025 {
19026         struct cmd_show_tx_metadata_result *res = parsed_result;
19027
19028         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19029                 printf("invalid port id %u\n", res->cmd_pid);
19030                 return;
19031         }
19032         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19033                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19034                        ports[res->cmd_pid].tx_metadata);
19035         }
19036 }
19037
19038 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19039         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19040                         cmd_show, "show");
19041 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19042         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19043                         cmd_port, "port");
19044 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19045         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19046                         cmd_pid, UINT16);
19047 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19048         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19049                         cmd_keyword, "tx_metadata");
19050
19051 cmdline_parse_inst_t cmd_show_tx_metadata = {
19052         .f = cmd_show_tx_metadata_parsed,
19053         .data = NULL,
19054         .help_str = "show port <port_id> tx_metadata",
19055         .tokens = {
19056                 (void *)&cmd_show_tx_metadata_show,
19057                 (void *)&cmd_show_tx_metadata_port,
19058                 (void *)&cmd_show_tx_metadata_pid,
19059                 (void *)&cmd_show_tx_metadata_keyword,
19060                 NULL,
19061         },
19062 };
19063
19064 /* show port supported ptypes */
19065
19066 /* Common result structure for show port ptypes */
19067 struct cmd_show_port_supported_ptypes_result {
19068         cmdline_fixed_string_t show;
19069         cmdline_fixed_string_t port;
19070         portid_t port_id;
19071         cmdline_fixed_string_t ptypes;
19072 };
19073
19074 /* Common CLI fields for show port ptypes */
19075 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19076         TOKEN_STRING_INITIALIZER
19077                 (struct cmd_show_port_supported_ptypes_result,
19078                  show, "show");
19079 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19080         TOKEN_STRING_INITIALIZER
19081                 (struct cmd_show_port_supported_ptypes_result,
19082                  port, "port");
19083 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19084         TOKEN_NUM_INITIALIZER
19085                 (struct cmd_show_port_supported_ptypes_result,
19086                  port_id, UINT16);
19087 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19088         TOKEN_STRING_INITIALIZER
19089                 (struct cmd_show_port_supported_ptypes_result,
19090                  ptypes, "ptypes");
19091
19092 static void
19093 cmd_show_port_supported_ptypes_parsed(
19094         void *parsed_result,
19095         __rte_unused struct cmdline *cl,
19096         __rte_unused void *data)
19097 {
19098 #define RSVD_PTYPE_MASK       0xf0000000
19099 #define MAX_PTYPES_PER_LAYER  16
19100 #define LTYPE_NAMESIZE        32
19101 #define PTYPE_NAMESIZE        256
19102         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19103         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19104         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19105         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19106         uint16_t port_id = res->port_id;
19107         int ret, i;
19108
19109         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19110         if (ret < 0)
19111                 return;
19112
19113         while (ptype_mask != RSVD_PTYPE_MASK) {
19114
19115                 switch (ptype_mask) {
19116                 case RTE_PTYPE_L2_MASK:
19117                         strlcpy(ltype, "L2", sizeof(ltype));
19118                         break;
19119                 case RTE_PTYPE_L3_MASK:
19120                         strlcpy(ltype, "L3", sizeof(ltype));
19121                         break;
19122                 case RTE_PTYPE_L4_MASK:
19123                         strlcpy(ltype, "L4", sizeof(ltype));
19124                         break;
19125                 case RTE_PTYPE_TUNNEL_MASK:
19126                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19127                         break;
19128                 case RTE_PTYPE_INNER_L2_MASK:
19129                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19130                         break;
19131                 case RTE_PTYPE_INNER_L3_MASK:
19132                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19133                         break;
19134                 case RTE_PTYPE_INNER_L4_MASK:
19135                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19136                         break;
19137                 default:
19138                         return;
19139                 }
19140
19141                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19142                                                        ptype_mask, ptypes,
19143                                                        MAX_PTYPES_PER_LAYER);
19144
19145                 if (ret > 0)
19146                         printf("Supported %s ptypes:\n", ltype);
19147                 else
19148                         printf("%s ptypes unsupported\n", ltype);
19149
19150                 for (i = 0; i < ret; ++i) {
19151                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19152                         printf("%s\n", buf);
19153                 }
19154
19155                 ptype_mask <<= 4;
19156         }
19157 }
19158
19159 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19160         .f = cmd_show_port_supported_ptypes_parsed,
19161         .data = NULL,
19162         .help_str = "show port <port_id> ptypes",
19163         .tokens = {
19164                 (void *)&cmd_show_port_supported_ptypes_show,
19165                 (void *)&cmd_show_port_supported_ptypes_port,
19166                 (void *)&cmd_show_port_supported_ptypes_port_id,
19167                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19168                 NULL,
19169         },
19170 };
19171
19172 /* *** display rx/tx descriptor status *** */
19173 struct cmd_show_rx_tx_desc_status_result {
19174         cmdline_fixed_string_t cmd_show;
19175         cmdline_fixed_string_t cmd_port;
19176         cmdline_fixed_string_t cmd_keyword;
19177         cmdline_fixed_string_t cmd_desc;
19178         cmdline_fixed_string_t cmd_status;
19179         portid_t cmd_pid;
19180         portid_t cmd_qid;
19181         portid_t cmd_did;
19182 };
19183
19184 static void
19185 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19186                 __rte_unused struct cmdline *cl,
19187                 __rte_unused void *data)
19188 {
19189         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19190         int rc;
19191
19192         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19193                 printf("invalid port id %u\n", res->cmd_pid);
19194                 return;
19195         }
19196
19197         if (!strcmp(res->cmd_keyword, "rxq")) {
19198                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19199                                              res->cmd_did);
19200                 if (rc < 0) {
19201                         printf("Invalid queueid = %d\n", res->cmd_qid);
19202                         return;
19203                 }
19204                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19205                         printf("Desc status = AVAILABLE\n");
19206                 else if (rc == RTE_ETH_RX_DESC_DONE)
19207                         printf("Desc status = DONE\n");
19208                 else
19209                         printf("Desc status = UNAVAILABLE\n");
19210         } else if (!strcmp(res->cmd_keyword, "txq")) {
19211                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19212                                              res->cmd_did);
19213                 if (rc < 0) {
19214                         printf("Invalid queueid = %d\n", res->cmd_qid);
19215                         return;
19216                 }
19217                 if (rc == RTE_ETH_TX_DESC_FULL)
19218                         printf("Desc status = FULL\n");
19219                 else if (rc == RTE_ETH_TX_DESC_DONE)
19220                         printf("Desc status = DONE\n");
19221                 else
19222                         printf("Desc status = UNAVAILABLE\n");
19223         }
19224 }
19225
19226 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19227         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19228                         cmd_show, "show");
19229 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19230         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19231                         cmd_port, "port");
19232 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19233         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19234                         cmd_pid, UINT16);
19235 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19236         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19237                         cmd_keyword, "rxq#txq");
19238 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19239         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19240                         cmd_qid, UINT16);
19241 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19242         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19243                         cmd_desc, "desc");
19244 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19245         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19246                         cmd_did, UINT16);
19247 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19248         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19249                         cmd_status, "status");
19250 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19251         .f = cmd_show_rx_tx_desc_status_parsed,
19252         .data = NULL,
19253         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19254                 "status",
19255         .tokens = {
19256                 (void *)&cmd_show_rx_tx_desc_status_show,
19257                 (void *)&cmd_show_rx_tx_desc_status_port,
19258                 (void *)&cmd_show_rx_tx_desc_status_pid,
19259                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19260                 (void *)&cmd_show_rx_tx_desc_status_qid,
19261                 (void *)&cmd_show_rx_tx_desc_status_desc,
19262                 (void *)&cmd_show_rx_tx_desc_status_did,
19263                 (void *)&cmd_show_rx_tx_desc_status_status,
19264                 NULL,
19265         },
19266 };
19267
19268 /* Common result structure for set port ptypes */
19269 struct cmd_set_port_ptypes_result {
19270         cmdline_fixed_string_t set;
19271         cmdline_fixed_string_t port;
19272         portid_t port_id;
19273         cmdline_fixed_string_t ptype_mask;
19274         uint32_t mask;
19275 };
19276
19277 /* Common CLI fields for set port ptypes */
19278 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19279         TOKEN_STRING_INITIALIZER
19280                 (struct cmd_set_port_ptypes_result,
19281                  set, "set");
19282 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19283         TOKEN_STRING_INITIALIZER
19284                 (struct cmd_set_port_ptypes_result,
19285                  port, "port");
19286 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19287         TOKEN_NUM_INITIALIZER
19288                 (struct cmd_set_port_ptypes_result,
19289                  port_id, UINT16);
19290 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19291         TOKEN_STRING_INITIALIZER
19292                 (struct cmd_set_port_ptypes_result,
19293                  ptype_mask, "ptype_mask");
19294 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19295         TOKEN_NUM_INITIALIZER
19296                 (struct cmd_set_port_ptypes_result,
19297                  mask, UINT32);
19298
19299 static void
19300 cmd_set_port_ptypes_parsed(
19301         void *parsed_result,
19302         __rte_unused struct cmdline *cl,
19303         __rte_unused void *data)
19304 {
19305         struct cmd_set_port_ptypes_result *res = parsed_result;
19306 #define PTYPE_NAMESIZE        256
19307         char ptype_name[PTYPE_NAMESIZE];
19308         uint16_t port_id = res->port_id;
19309         uint32_t ptype_mask = res->mask;
19310         int ret, i;
19311
19312         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19313                                                NULL, 0);
19314         if (ret <= 0) {
19315                 printf("Port %d doesn't support any ptypes.\n", port_id);
19316                 return;
19317         }
19318
19319         uint32_t ptypes[ret];
19320
19321         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19322         if (ret < 0) {
19323                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19324                 return;
19325         }
19326
19327         printf("Successfully set following ptypes for Port %d\n", port_id);
19328         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19329                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19330                 printf("%s\n", ptype_name);
19331         }
19332
19333         clear_ptypes = false;
19334 }
19335
19336 cmdline_parse_inst_t cmd_set_port_ptypes = {
19337         .f = cmd_set_port_ptypes_parsed,
19338         .data = NULL,
19339         .help_str = "set port <port_id> ptype_mask <mask>",
19340         .tokens = {
19341                 (void *)&cmd_set_port_ptypes_set,
19342                 (void *)&cmd_set_port_ptypes_port,
19343                 (void *)&cmd_set_port_ptypes_port_id,
19344                 (void *)&cmd_set_port_ptypes_mask_str,
19345                 (void *)&cmd_set_port_ptypes_mask_u32,
19346                 NULL,
19347         },
19348 };
19349
19350 /* *** display mac addresses added to a port *** */
19351 struct cmd_showport_macs_result {
19352         cmdline_fixed_string_t cmd_show;
19353         cmdline_fixed_string_t cmd_port;
19354         cmdline_fixed_string_t cmd_keyword;
19355         portid_t cmd_pid;
19356 };
19357
19358 static void
19359 cmd_showport_macs_parsed(void *parsed_result,
19360                 __rte_unused struct cmdline *cl,
19361                 __rte_unused void *data)
19362 {
19363         struct cmd_showport_macs_result *res = parsed_result;
19364
19365         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19366                 return;
19367
19368         if (!strcmp(res->cmd_keyword, "macs"))
19369                 show_macs(res->cmd_pid);
19370         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19371                 show_mcast_macs(res->cmd_pid);
19372 }
19373
19374 cmdline_parse_token_string_t cmd_showport_macs_show =
19375         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19376                         cmd_show, "show");
19377 cmdline_parse_token_string_t cmd_showport_macs_port =
19378         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19379                         cmd_port, "port");
19380 cmdline_parse_token_num_t cmd_showport_macs_pid =
19381         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19382                         cmd_pid, UINT16);
19383 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19384         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19385                         cmd_keyword, "macs#mcast_macs");
19386
19387 cmdline_parse_inst_t cmd_showport_macs = {
19388         .f = cmd_showport_macs_parsed,
19389         .data = NULL,
19390         .help_str = "show port <port_id> macs|mcast_macs",
19391         .tokens = {
19392                 (void *)&cmd_showport_macs_show,
19393                 (void *)&cmd_showport_macs_port,
19394                 (void *)&cmd_showport_macs_pid,
19395                 (void *)&cmd_showport_macs_keyword,
19396                 NULL,
19397         },
19398 };
19399
19400 /* ******************************************************************************** */
19401
19402 /* list of instructions */
19403 cmdline_parse_ctx_t main_ctx[] = {
19404         (cmdline_parse_inst_t *)&cmd_help_brief,
19405         (cmdline_parse_inst_t *)&cmd_help_long,
19406         (cmdline_parse_inst_t *)&cmd_quit,
19407         (cmdline_parse_inst_t *)&cmd_load_from_file,
19408         (cmdline_parse_inst_t *)&cmd_showport,
19409         (cmdline_parse_inst_t *)&cmd_showqueue,
19410         (cmdline_parse_inst_t *)&cmd_showportall,
19411         (cmdline_parse_inst_t *)&cmd_showdevice,
19412         (cmdline_parse_inst_t *)&cmd_showcfg,
19413         (cmdline_parse_inst_t *)&cmd_showfwdall,
19414         (cmdline_parse_inst_t *)&cmd_start,
19415         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19416         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19417         (cmdline_parse_inst_t *)&cmd_set_link_up,
19418         (cmdline_parse_inst_t *)&cmd_set_link_down,
19419         (cmdline_parse_inst_t *)&cmd_reset,
19420         (cmdline_parse_inst_t *)&cmd_set_numbers,
19421         (cmdline_parse_inst_t *)&cmd_set_log,
19422         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19423         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19424         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19425         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19426         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19427         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19428         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19429         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19430         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19431         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19432         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19433         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19434         (cmdline_parse_inst_t *)&cmd_set_link_check,
19435         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19436         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19437         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19438         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19439 #ifdef RTE_LIBRTE_PMD_BOND
19440         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19441         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19442         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19443         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19444         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19445         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19446         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19447         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19448         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19449         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19450         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19451 #endif
19452         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19453         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19454         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19455         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19456         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19457         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19458         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19459         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19460         (cmdline_parse_inst_t *)&cmd_csum_set,
19461         (cmdline_parse_inst_t *)&cmd_csum_show,
19462         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19463         (cmdline_parse_inst_t *)&cmd_tso_set,
19464         (cmdline_parse_inst_t *)&cmd_tso_show,
19465         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19466         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19467         (cmdline_parse_inst_t *)&cmd_gro_enable,
19468         (cmdline_parse_inst_t *)&cmd_gro_flush,
19469         (cmdline_parse_inst_t *)&cmd_gro_show,
19470         (cmdline_parse_inst_t *)&cmd_gso_enable,
19471         (cmdline_parse_inst_t *)&cmd_gso_size,
19472         (cmdline_parse_inst_t *)&cmd_gso_show,
19473         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19474         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19475         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19476         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19477         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19478         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19479         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19480         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19481         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19482         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19483         (cmdline_parse_inst_t *)&cmd_config_dcb,
19484         (cmdline_parse_inst_t *)&cmd_read_reg,
19485         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19486         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19487         (cmdline_parse_inst_t *)&cmd_write_reg,
19488         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19489         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19490         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19491         (cmdline_parse_inst_t *)&cmd_stop,
19492         (cmdline_parse_inst_t *)&cmd_mac_addr,
19493         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19494         (cmdline_parse_inst_t *)&cmd_set_qmap,
19495         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19496         (cmdline_parse_inst_t *)&cmd_operate_port,
19497         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19498         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19499         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19500         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19501         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19502         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19503         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19504         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19505         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19506         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19507         (cmdline_parse_inst_t *)&cmd_config_mtu,
19508         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19509         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19510         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19511         (cmdline_parse_inst_t *)&cmd_config_rss,
19512         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19513         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19514         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19515         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19516         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19517         (cmdline_parse_inst_t *)&cmd_showport_reta,
19518         (cmdline_parse_inst_t *)&cmd_showport_macs,
19519         (cmdline_parse_inst_t *)&cmd_config_burst,
19520         (cmdline_parse_inst_t *)&cmd_config_thresh,
19521         (cmdline_parse_inst_t *)&cmd_config_threshold,
19522         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19523         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19524         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19525         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19526         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19527         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19528         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19529         (cmdline_parse_inst_t *)&cmd_global_config,
19530         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19531         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19532         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19533         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19534         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19535         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19536         (cmdline_parse_inst_t *)&cmd_dump,
19537         (cmdline_parse_inst_t *)&cmd_dump_one,
19538         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19539         (cmdline_parse_inst_t *)&cmd_syn_filter,
19540         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19541         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19542         (cmdline_parse_inst_t *)&cmd_flex_filter,
19543         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19544         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19545         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19546         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19547         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19548         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19549         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19550         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19551         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19552         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19553         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19554         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19555         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19556         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19557         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19558         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19559         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19560         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19561         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19562         (cmdline_parse_inst_t *)&cmd_flow,
19563         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19564         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19565         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19566         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19567         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19568         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19569         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19570         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19571         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19572         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19573         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19574         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19575         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19576         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19577         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19578         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19579         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19580         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19581         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19582         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19583         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19584         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19585         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19586         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19587         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19588         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19589         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19590         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19591         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19592         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19593         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19594         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19595         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19596         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19597         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19598         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19599         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19600         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19601         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19602         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19603         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19604         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19605         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19606         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19607         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19608         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19609         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19610         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19611         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19612 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19613         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19614 #endif
19615         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19616         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19617         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19618         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19619         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19620         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19621         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19622         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19623         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19624         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19625         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19626         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19627         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19628         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19629         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19630         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19631         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19632         (cmdline_parse_inst_t *)&cmd_ddp_add,
19633         (cmdline_parse_inst_t *)&cmd_ddp_del,
19634         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19635         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19636         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19637         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19638         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19639         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19640         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19641         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19642         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19643         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19644         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19645         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19646
19647         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19648         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19649         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19650         (cmdline_parse_inst_t *)&cmd_queue_region,
19651         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19652         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19653         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19654         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19655         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19656         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19657         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19658         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19659         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19660         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19661         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19662         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19663         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19664         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19665         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19666         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19667         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19668         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19669         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19670         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19671         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19672         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19673         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19674         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19675         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19676         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19677         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19678         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19679         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19680         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19681         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19682         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19683         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19684         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19685         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19686 #ifdef RTE_LIBRTE_BPF
19687         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19688         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19689 #endif
19690         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19691         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19692         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19693         (cmdline_parse_inst_t *)&cmd_set_raw,
19694         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19695         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19696         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19697         NULL,
19698 };
19699
19700 /* read cmdline commands from file */
19701 void
19702 cmdline_read_from_file(const char *filename)
19703 {
19704         struct cmdline *cl;
19705
19706         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19707         if (cl == NULL) {
19708                 printf("Failed to create file based cmdline context: %s\n",
19709                        filename);
19710                 return;
19711         }
19712
19713         cmdline_interact(cl);
19714         cmdline_quit(cl);
19715
19716         cmdline_free(cl);
19717
19718         printf("Read CLI commands from %s\n", filename);
19719 }
19720
19721 /* prompt function, called from main on MASTER lcore */
19722 void
19723 prompt(void)
19724 {
19725         /* initialize non-constant commands */
19726         cmd_set_fwd_mode_init();
19727         cmd_set_fwd_retry_mode_init();
19728
19729         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19730         if (testpmd_cl == NULL)
19731                 return;
19732         cmdline_interact(testpmd_cl);
19733         cmdline_stdin_exit(testpmd_cl);
19734 }
19735
19736 void
19737 prompt_exit(void)
19738 {
19739         if (testpmd_cl != NULL)
19740                 cmdline_quit(testpmd_cl);
19741 }
19742
19743 static void
19744 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19745 {
19746         if (id == (portid_t)RTE_PORT_ALL) {
19747                 portid_t pid;
19748
19749                 RTE_ETH_FOREACH_DEV(pid) {
19750                         /* check if need_reconfig has been set to 1 */
19751                         if (ports[pid].need_reconfig == 0)
19752                                 ports[pid].need_reconfig = dev;
19753                         /* check if need_reconfig_queues has been set to 1 */
19754                         if (ports[pid].need_reconfig_queues == 0)
19755                                 ports[pid].need_reconfig_queues = queue;
19756                 }
19757         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19758                 /* check if need_reconfig has been set to 1 */
19759                 if (ports[id].need_reconfig == 0)
19760                         ports[id].need_reconfig = dev;
19761                 /* check if need_reconfig_queues has been set to 1 */
19762                 if (ports[id].need_reconfig_queues == 0)
19763                         ports[id].need_reconfig_queues = queue;
19764         }
19765 }