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 | ETH_RSS_GTPU;
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-pre32"))
2301                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2302         else if (!strcmp(res->value, "l3-pre40"))
2303                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2304         else if (!strcmp(res->value, "l3-pre48"))
2305                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2306         else if (!strcmp(res->value, "l3-pre56"))
2307                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2308         else if (!strcmp(res->value, "l3-pre64"))
2309                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2310         else if (!strcmp(res->value, "l3-pre96"))
2311                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2312         else if (!strcmp(res->value, "l3-src-only"))
2313                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2314         else if (!strcmp(res->value, "l3-dst-only"))
2315                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2316         else if (!strcmp(res->value, "l4-src-only"))
2317                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2318         else if (!strcmp(res->value, "l4-dst-only"))
2319                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2320         else if (!strcmp(res->value, "l2-src-only"))
2321                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2322         else if (!strcmp(res->value, "l2-dst-only"))
2323                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2324         else if (!strcmp(res->value, "l2tpv3"))
2325                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2326         else if (!strcmp(res->value, "esp"))
2327                 rss_conf.rss_hf = ETH_RSS_ESP;
2328         else if (!strcmp(res->value, "ah"))
2329                 rss_conf.rss_hf = ETH_RSS_AH;
2330         else if (!strcmp(res->value, "pfcp"))
2331                 rss_conf.rss_hf = ETH_RSS_PFCP;
2332         else if (!strcmp(res->value, "pppoe"))
2333                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2334         else if (!strcmp(res->value, "gtpu"))
2335                 rss_conf.rss_hf = ETH_RSS_GTPU;
2336         else if (!strcmp(res->value, "none"))
2337                 rss_conf.rss_hf = 0;
2338         else if (!strcmp(res->value, "default"))
2339                 use_default = 1;
2340         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2341                                                 atoi(res->value) < 64)
2342                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2343         else {
2344                 printf("Unknown parameter\n");
2345                 return;
2346         }
2347         rss_conf.rss_key = NULL;
2348         /* Update global configuration for RSS types. */
2349         RTE_ETH_FOREACH_DEV(i) {
2350                 struct rte_eth_rss_conf local_rss_conf;
2351
2352                 ret = eth_dev_info_get_print_err(i, &dev_info);
2353                 if (ret != 0)
2354                         return;
2355
2356                 if (use_default)
2357                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2358
2359                 local_rss_conf = rss_conf;
2360                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2361                         dev_info.flow_type_rss_offloads;
2362                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2363                         printf("Port %u modified RSS hash function based on hardware support,"
2364                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2365                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2366                 }
2367                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2368                 if (diag < 0) {
2369                         all_updated = 0;
2370                         printf("Configuration of RSS hash at ethernet port %d "
2371                                 "failed with error (%d): %s.\n",
2372                                 i, -diag, strerror(-diag));
2373                 }
2374         }
2375         if (all_updated && !use_default) {
2376                 rss_hf = rss_conf.rss_hf;
2377                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2378         }
2379 }
2380
2381 cmdline_parse_token_string_t cmd_config_rss_port =
2382         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2383 cmdline_parse_token_string_t cmd_config_rss_keyword =
2384         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2385 cmdline_parse_token_string_t cmd_config_rss_all =
2386         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2387 cmdline_parse_token_string_t cmd_config_rss_name =
2388         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2389 cmdline_parse_token_string_t cmd_config_rss_value =
2390         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2391
2392 cmdline_parse_inst_t cmd_config_rss = {
2393         .f = cmd_config_rss_parsed,
2394         .data = NULL,
2395         .help_str = "port config all rss "
2396                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2397                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2398         .tokens = {
2399                 (void *)&cmd_config_rss_port,
2400                 (void *)&cmd_config_rss_keyword,
2401                 (void *)&cmd_config_rss_all,
2402                 (void *)&cmd_config_rss_name,
2403                 (void *)&cmd_config_rss_value,
2404                 NULL,
2405         },
2406 };
2407
2408 /* *** configure rss hash key *** */
2409 struct cmd_config_rss_hash_key {
2410         cmdline_fixed_string_t port;
2411         cmdline_fixed_string_t config;
2412         portid_t port_id;
2413         cmdline_fixed_string_t rss_hash_key;
2414         cmdline_fixed_string_t rss_type;
2415         cmdline_fixed_string_t key;
2416 };
2417
2418 static uint8_t
2419 hexa_digit_to_value(char hexa_digit)
2420 {
2421         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2422                 return (uint8_t) (hexa_digit - '0');
2423         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2424                 return (uint8_t) ((hexa_digit - 'a') + 10);
2425         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2426                 return (uint8_t) ((hexa_digit - 'A') + 10);
2427         /* Invalid hexa digit */
2428         return 0xFF;
2429 }
2430
2431 static uint8_t
2432 parse_and_check_key_hexa_digit(char *key, int idx)
2433 {
2434         uint8_t hexa_v;
2435
2436         hexa_v = hexa_digit_to_value(key[idx]);
2437         if (hexa_v == 0xFF)
2438                 printf("invalid key: character %c at position %d is not a "
2439                        "valid hexa digit\n", key[idx], idx);
2440         return hexa_v;
2441 }
2442
2443 static void
2444 cmd_config_rss_hash_key_parsed(void *parsed_result,
2445                                __rte_unused struct cmdline *cl,
2446                                __rte_unused void *data)
2447 {
2448         struct cmd_config_rss_hash_key *res = parsed_result;
2449         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2450         uint8_t xdgt0;
2451         uint8_t xdgt1;
2452         int i;
2453         struct rte_eth_dev_info dev_info;
2454         uint8_t hash_key_size;
2455         uint32_t key_len;
2456         int ret;
2457
2458         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2459         if (ret != 0)
2460                 return;
2461
2462         if (dev_info.hash_key_size > 0 &&
2463                         dev_info.hash_key_size <= sizeof(hash_key))
2464                 hash_key_size = dev_info.hash_key_size;
2465         else {
2466                 printf("dev_info did not provide a valid hash key size\n");
2467                 return;
2468         }
2469         /* Check the length of the RSS hash key */
2470         key_len = strlen(res->key);
2471         if (key_len != (hash_key_size * 2)) {
2472                 printf("key length: %d invalid - key must be a string of %d"
2473                            " hexa-decimal numbers\n",
2474                            (int) key_len, hash_key_size * 2);
2475                 return;
2476         }
2477         /* Translate RSS hash key into binary representation */
2478         for (i = 0; i < hash_key_size; i++) {
2479                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2480                 if (xdgt0 == 0xFF)
2481                         return;
2482                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2483                 if (xdgt1 == 0xFF)
2484                         return;
2485                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2486         }
2487         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2488                         hash_key_size);
2489 }
2490
2491 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2492         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2493 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2494         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2495                                  "config");
2496 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2497         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2498 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2499         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2500                                  rss_hash_key, "rss-hash-key");
2501 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2502         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2503                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2504                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2505                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2506                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2507                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2508                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2509                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2510 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2511         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2512
2513 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2514         .f = cmd_config_rss_hash_key_parsed,
2515         .data = NULL,
2516         .help_str = "port config <port_id> rss-hash-key "
2517                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2518                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2519                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2520                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2521                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2522                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2523                 "<string of hex digits (variable length, NIC dependent)>",
2524         .tokens = {
2525                 (void *)&cmd_config_rss_hash_key_port,
2526                 (void *)&cmd_config_rss_hash_key_config,
2527                 (void *)&cmd_config_rss_hash_key_port_id,
2528                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2529                 (void *)&cmd_config_rss_hash_key_rss_type,
2530                 (void *)&cmd_config_rss_hash_key_value,
2531                 NULL,
2532         },
2533 };
2534
2535 /* *** configure port rxq/txq ring size *** */
2536 struct cmd_config_rxtx_ring_size {
2537         cmdline_fixed_string_t port;
2538         cmdline_fixed_string_t config;
2539         portid_t portid;
2540         cmdline_fixed_string_t rxtxq;
2541         uint16_t qid;
2542         cmdline_fixed_string_t rsize;
2543         uint16_t size;
2544 };
2545
2546 static void
2547 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2548                                  __rte_unused struct cmdline *cl,
2549                                  __rte_unused void *data)
2550 {
2551         struct cmd_config_rxtx_ring_size *res = parsed_result;
2552         struct rte_port *port;
2553         uint8_t isrx;
2554
2555         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2556                 return;
2557
2558         if (res->portid == (portid_t)RTE_PORT_ALL) {
2559                 printf("Invalid port id\n");
2560                 return;
2561         }
2562
2563         port = &ports[res->portid];
2564
2565         if (!strcmp(res->rxtxq, "rxq"))
2566                 isrx = 1;
2567         else if (!strcmp(res->rxtxq, "txq"))
2568                 isrx = 0;
2569         else {
2570                 printf("Unknown parameter\n");
2571                 return;
2572         }
2573
2574         if (isrx && rx_queue_id_is_invalid(res->qid))
2575                 return;
2576         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2577                 return;
2578
2579         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2580                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2581                        rx_free_thresh);
2582                 return;
2583         }
2584
2585         if (isrx)
2586                 port->nb_rx_desc[res->qid] = res->size;
2587         else
2588                 port->nb_tx_desc[res->qid] = res->size;
2589
2590         cmd_reconfig_device_queue(res->portid, 0, 1);
2591 }
2592
2593 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2594         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2595                                  port, "port");
2596 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2597         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2598                                  config, "config");
2599 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2601                                  portid, UINT16);
2602 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2603         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2604                                  rxtxq, "rxq#txq");
2605 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2607                               qid, UINT16);
2608 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2609         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2610                                  rsize, "ring_size");
2611 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2612         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2613                               size, UINT16);
2614
2615 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2616         .f = cmd_config_rxtx_ring_size_parsed,
2617         .data = NULL,
2618         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2619         .tokens = {
2620                 (void *)&cmd_config_rxtx_ring_size_port,
2621                 (void *)&cmd_config_rxtx_ring_size_config,
2622                 (void *)&cmd_config_rxtx_ring_size_portid,
2623                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2624                 (void *)&cmd_config_rxtx_ring_size_qid,
2625                 (void *)&cmd_config_rxtx_ring_size_rsize,
2626                 (void *)&cmd_config_rxtx_ring_size_size,
2627                 NULL,
2628         },
2629 };
2630
2631 /* *** configure port rxq/txq start/stop *** */
2632 struct cmd_config_rxtx_queue {
2633         cmdline_fixed_string_t port;
2634         portid_t portid;
2635         cmdline_fixed_string_t rxtxq;
2636         uint16_t qid;
2637         cmdline_fixed_string_t opname;
2638 };
2639
2640 static void
2641 cmd_config_rxtx_queue_parsed(void *parsed_result,
2642                         __rte_unused struct cmdline *cl,
2643                         __rte_unused void *data)
2644 {
2645         struct cmd_config_rxtx_queue *res = parsed_result;
2646         uint8_t isrx;
2647         uint8_t isstart;
2648         int ret = 0;
2649
2650         if (test_done == 0) {
2651                 printf("Please stop forwarding first\n");
2652                 return;
2653         }
2654
2655         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2656                 return;
2657
2658         if (port_is_started(res->portid) != 1) {
2659                 printf("Please start port %u first\n", res->portid);
2660                 return;
2661         }
2662
2663         if (!strcmp(res->rxtxq, "rxq"))
2664                 isrx = 1;
2665         else if (!strcmp(res->rxtxq, "txq"))
2666                 isrx = 0;
2667         else {
2668                 printf("Unknown parameter\n");
2669                 return;
2670         }
2671
2672         if (isrx && rx_queue_id_is_invalid(res->qid))
2673                 return;
2674         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2675                 return;
2676
2677         if (!strcmp(res->opname, "start"))
2678                 isstart = 1;
2679         else if (!strcmp(res->opname, "stop"))
2680                 isstart = 0;
2681         else {
2682                 printf("Unknown parameter\n");
2683                 return;
2684         }
2685
2686         if (isstart && isrx)
2687                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2688         else if (!isstart && isrx)
2689                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2690         else if (isstart && !isrx)
2691                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2692         else
2693                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2694
2695         if (ret == -ENOTSUP)
2696                 printf("Function not supported in PMD driver\n");
2697 }
2698
2699 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2700         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2701 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2702         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2703 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2704         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2705 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2706         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2707 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2708         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2709                                                 "start#stop");
2710
2711 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2712         .f = cmd_config_rxtx_queue_parsed,
2713         .data = NULL,
2714         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2715         .tokens = {
2716                 (void *)&cmd_config_rxtx_queue_port,
2717                 (void *)&cmd_config_rxtx_queue_portid,
2718                 (void *)&cmd_config_rxtx_queue_rxtxq,
2719                 (void *)&cmd_config_rxtx_queue_qid,
2720                 (void *)&cmd_config_rxtx_queue_opname,
2721                 NULL,
2722         },
2723 };
2724
2725 /* *** configure port rxq/txq deferred start on/off *** */
2726 struct cmd_config_deferred_start_rxtx_queue {
2727         cmdline_fixed_string_t port;
2728         portid_t port_id;
2729         cmdline_fixed_string_t rxtxq;
2730         uint16_t qid;
2731         cmdline_fixed_string_t opname;
2732         cmdline_fixed_string_t state;
2733 };
2734
2735 static void
2736 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2737                         __rte_unused struct cmdline *cl,
2738                         __rte_unused void *data)
2739 {
2740         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2741         struct rte_port *port;
2742         uint8_t isrx;
2743         uint8_t ison;
2744         uint8_t needreconfig = 0;
2745
2746         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2747                 return;
2748
2749         if (port_is_started(res->port_id) != 0) {
2750                 printf("Please stop port %u first\n", res->port_id);
2751                 return;
2752         }
2753
2754         port = &ports[res->port_id];
2755
2756         isrx = !strcmp(res->rxtxq, "rxq");
2757
2758         if (isrx && rx_queue_id_is_invalid(res->qid))
2759                 return;
2760         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2761                 return;
2762
2763         ison = !strcmp(res->state, "on");
2764
2765         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2766                 port->rx_conf[res->qid].rx_deferred_start = ison;
2767                 needreconfig = 1;
2768         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2769                 port->tx_conf[res->qid].tx_deferred_start = ison;
2770                 needreconfig = 1;
2771         }
2772
2773         if (needreconfig)
2774                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2775 }
2776
2777 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2779                                                 port, "port");
2780 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2781         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2782                                                 port_id, UINT16);
2783 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2784         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2785                                                 rxtxq, "rxq#txq");
2786 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2787         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2788                                                 qid, UINT16);
2789 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2790         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2791                                                 opname, "deferred_start");
2792 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2793         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2794                                                 state, "on#off");
2795
2796 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2797         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2798         .data = NULL,
2799         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2800         .tokens = {
2801                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2802                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2803                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2804                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2805                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2806                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2807                 NULL,
2808         },
2809 };
2810
2811 /* *** configure port rxq/txq setup *** */
2812 struct cmd_setup_rxtx_queue {
2813         cmdline_fixed_string_t port;
2814         portid_t portid;
2815         cmdline_fixed_string_t rxtxq;
2816         uint16_t qid;
2817         cmdline_fixed_string_t setup;
2818 };
2819
2820 /* Common CLI fields for queue setup */
2821 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2822         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2823 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2824         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2825 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2826         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2827 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2828         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2829 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2830         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2831
2832 static void
2833 cmd_setup_rxtx_queue_parsed(
2834         void *parsed_result,
2835         __rte_unused struct cmdline *cl,
2836         __rte_unused void *data)
2837 {
2838         struct cmd_setup_rxtx_queue *res = parsed_result;
2839         struct rte_port *port;
2840         struct rte_mempool *mp;
2841         unsigned int socket_id;
2842         uint8_t isrx = 0;
2843         int ret;
2844
2845         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2846                 return;
2847
2848         if (res->portid == (portid_t)RTE_PORT_ALL) {
2849                 printf("Invalid port id\n");
2850                 return;
2851         }
2852
2853         if (!strcmp(res->rxtxq, "rxq"))
2854                 isrx = 1;
2855         else if (!strcmp(res->rxtxq, "txq"))
2856                 isrx = 0;
2857         else {
2858                 printf("Unknown parameter\n");
2859                 return;
2860         }
2861
2862         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2863                 printf("Invalid rx queue\n");
2864                 return;
2865         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2866                 printf("Invalid tx queue\n");
2867                 return;
2868         }
2869
2870         port = &ports[res->portid];
2871         if (isrx) {
2872                 socket_id = rxring_numa[res->portid];
2873                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2874                         socket_id = port->socket_id;
2875
2876                 mp = mbuf_pool_find(socket_id);
2877                 if (mp == NULL) {
2878                         printf("Failed to setup RX queue: "
2879                                 "No mempool allocation"
2880                                 " on the socket %d\n",
2881                                 rxring_numa[res->portid]);
2882                         return;
2883                 }
2884                 ret = rte_eth_rx_queue_setup(res->portid,
2885                                              res->qid,
2886                                              port->nb_rx_desc[res->qid],
2887                                              socket_id,
2888                                              &port->rx_conf[res->qid],
2889                                              mp);
2890                 if (ret)
2891                         printf("Failed to setup RX queue\n");
2892         } else {
2893                 socket_id = txring_numa[res->portid];
2894                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2895                         socket_id = port->socket_id;
2896
2897                 ret = rte_eth_tx_queue_setup(res->portid,
2898                                              res->qid,
2899                                              port->nb_tx_desc[res->qid],
2900                                              socket_id,
2901                                              &port->tx_conf[res->qid]);
2902                 if (ret)
2903                         printf("Failed to setup TX queue\n");
2904         }
2905 }
2906
2907 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2908         .f = cmd_setup_rxtx_queue_parsed,
2909         .data = NULL,
2910         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2911         .tokens = {
2912                 (void *)&cmd_setup_rxtx_queue_port,
2913                 (void *)&cmd_setup_rxtx_queue_portid,
2914                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2915                 (void *)&cmd_setup_rxtx_queue_qid,
2916                 (void *)&cmd_setup_rxtx_queue_setup,
2917                 NULL,
2918         },
2919 };
2920
2921
2922 /* *** Configure RSS RETA *** */
2923 struct cmd_config_rss_reta {
2924         cmdline_fixed_string_t port;
2925         cmdline_fixed_string_t keyword;
2926         portid_t port_id;
2927         cmdline_fixed_string_t name;
2928         cmdline_fixed_string_t list_name;
2929         cmdline_fixed_string_t list_of_items;
2930 };
2931
2932 static int
2933 parse_reta_config(const char *str,
2934                   struct rte_eth_rss_reta_entry64 *reta_conf,
2935                   uint16_t nb_entries)
2936 {
2937         int i;
2938         unsigned size;
2939         uint16_t hash_index, idx, shift;
2940         uint16_t nb_queue;
2941         char s[256];
2942         const char *p, *p0 = str;
2943         char *end;
2944         enum fieldnames {
2945                 FLD_HASH_INDEX = 0,
2946                 FLD_QUEUE,
2947                 _NUM_FLD
2948         };
2949         unsigned long int_fld[_NUM_FLD];
2950         char *str_fld[_NUM_FLD];
2951
2952         while ((p = strchr(p0,'(')) != NULL) {
2953                 ++p;
2954                 if((p0 = strchr(p,')')) == NULL)
2955                         return -1;
2956
2957                 size = p0 - p;
2958                 if(size >= sizeof(s))
2959                         return -1;
2960
2961                 snprintf(s, sizeof(s), "%.*s", size, p);
2962                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2963                         return -1;
2964                 for (i = 0; i < _NUM_FLD; i++) {
2965                         errno = 0;
2966                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2967                         if (errno != 0 || end == str_fld[i] ||
2968                                         int_fld[i] > 65535)
2969                                 return -1;
2970                 }
2971
2972                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2973                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2974
2975                 if (hash_index >= nb_entries) {
2976                         printf("Invalid RETA hash index=%d\n", hash_index);
2977                         return -1;
2978                 }
2979
2980                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2981                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2982                 reta_conf[idx].mask |= (1ULL << shift);
2983                 reta_conf[idx].reta[shift] = nb_queue;
2984         }
2985
2986         return 0;
2987 }
2988
2989 static void
2990 cmd_set_rss_reta_parsed(void *parsed_result,
2991                         __rte_unused struct cmdline *cl,
2992                         __rte_unused void *data)
2993 {
2994         int ret;
2995         struct rte_eth_dev_info dev_info;
2996         struct rte_eth_rss_reta_entry64 reta_conf[8];
2997         struct cmd_config_rss_reta *res = parsed_result;
2998
2999         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3000         if (ret != 0)
3001                 return;
3002
3003         if (dev_info.reta_size == 0) {
3004                 printf("Redirection table size is 0 which is "
3005                                         "invalid for RSS\n");
3006                 return;
3007         } else
3008                 printf("The reta size of port %d is %u\n",
3009                         res->port_id, dev_info.reta_size);
3010         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3011                 printf("Currently do not support more than %u entries of "
3012                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3013                 return;
3014         }
3015
3016         memset(reta_conf, 0, sizeof(reta_conf));
3017         if (!strcmp(res->list_name, "reta")) {
3018                 if (parse_reta_config(res->list_of_items, reta_conf,
3019                                                 dev_info.reta_size)) {
3020                         printf("Invalid RSS Redirection Table "
3021                                         "config entered\n");
3022                         return;
3023                 }
3024                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3025                                 reta_conf, dev_info.reta_size);
3026                 if (ret != 0)
3027                         printf("Bad redirection table parameter, "
3028                                         "return code = %d \n", ret);
3029         }
3030 }
3031
3032 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3033         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3034 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3035         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3036 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3037         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3038 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3039         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3040 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3041         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3042 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3043         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3044                                  NULL);
3045 cmdline_parse_inst_t cmd_config_rss_reta = {
3046         .f = cmd_set_rss_reta_parsed,
3047         .data = NULL,
3048         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3049         .tokens = {
3050                 (void *)&cmd_config_rss_reta_port,
3051                 (void *)&cmd_config_rss_reta_keyword,
3052                 (void *)&cmd_config_rss_reta_port_id,
3053                 (void *)&cmd_config_rss_reta_name,
3054                 (void *)&cmd_config_rss_reta_list_name,
3055                 (void *)&cmd_config_rss_reta_list_of_items,
3056                 NULL,
3057         },
3058 };
3059
3060 /* *** SHOW PORT RETA INFO *** */
3061 struct cmd_showport_reta {
3062         cmdline_fixed_string_t show;
3063         cmdline_fixed_string_t port;
3064         portid_t port_id;
3065         cmdline_fixed_string_t rss;
3066         cmdline_fixed_string_t reta;
3067         uint16_t size;
3068         cmdline_fixed_string_t list_of_items;
3069 };
3070
3071 static int
3072 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3073                            uint16_t nb_entries,
3074                            char *str)
3075 {
3076         uint32_t size;
3077         const char *p, *p0 = str;
3078         char s[256];
3079         char *end;
3080         char *str_fld[8];
3081         uint16_t i;
3082         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3083                         RTE_RETA_GROUP_SIZE;
3084         int ret;
3085
3086         p = strchr(p0, '(');
3087         if (p == NULL)
3088                 return -1;
3089         p++;
3090         p0 = strchr(p, ')');
3091         if (p0 == NULL)
3092                 return -1;
3093         size = p0 - p;
3094         if (size >= sizeof(s)) {
3095                 printf("The string size exceeds the internal buffer size\n");
3096                 return -1;
3097         }
3098         snprintf(s, sizeof(s), "%.*s", size, p);
3099         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3100         if (ret <= 0 || ret != num) {
3101                 printf("The bits of masks do not match the number of "
3102                                         "reta entries: %u\n", num);
3103                 return -1;
3104         }
3105         for (i = 0; i < ret; i++)
3106                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3107
3108         return 0;
3109 }
3110
3111 static void
3112 cmd_showport_reta_parsed(void *parsed_result,
3113                          __rte_unused struct cmdline *cl,
3114                          __rte_unused void *data)
3115 {
3116         struct cmd_showport_reta *res = parsed_result;
3117         struct rte_eth_rss_reta_entry64 reta_conf[8];
3118         struct rte_eth_dev_info dev_info;
3119         uint16_t max_reta_size;
3120         int ret;
3121
3122         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3123         if (ret != 0)
3124                 return;
3125
3126         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3127         if (res->size == 0 || res->size > max_reta_size) {
3128                 printf("Invalid redirection table size: %u (1-%u)\n",
3129                         res->size, max_reta_size);
3130                 return;
3131         }
3132
3133         memset(reta_conf, 0, sizeof(reta_conf));
3134         if (showport_parse_reta_config(reta_conf, res->size,
3135                                 res->list_of_items) < 0) {
3136                 printf("Invalid string: %s for reta masks\n",
3137                                         res->list_of_items);
3138                 return;
3139         }
3140         port_rss_reta_info(res->port_id, reta_conf, res->size);
3141 }
3142
3143 cmdline_parse_token_string_t cmd_showport_reta_show =
3144         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3145 cmdline_parse_token_string_t cmd_showport_reta_port =
3146         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3147 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3148         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3149 cmdline_parse_token_string_t cmd_showport_reta_rss =
3150         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3151 cmdline_parse_token_string_t cmd_showport_reta_reta =
3152         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3153 cmdline_parse_token_num_t cmd_showport_reta_size =
3154         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3155 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3156         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3157                                         list_of_items, NULL);
3158
3159 cmdline_parse_inst_t cmd_showport_reta = {
3160         .f = cmd_showport_reta_parsed,
3161         .data = NULL,
3162         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3163         .tokens = {
3164                 (void *)&cmd_showport_reta_show,
3165                 (void *)&cmd_showport_reta_port,
3166                 (void *)&cmd_showport_reta_port_id,
3167                 (void *)&cmd_showport_reta_rss,
3168                 (void *)&cmd_showport_reta_reta,
3169                 (void *)&cmd_showport_reta_size,
3170                 (void *)&cmd_showport_reta_list_of_items,
3171                 NULL,
3172         },
3173 };
3174
3175 /* *** Show RSS hash configuration *** */
3176 struct cmd_showport_rss_hash {
3177         cmdline_fixed_string_t show;
3178         cmdline_fixed_string_t port;
3179         portid_t port_id;
3180         cmdline_fixed_string_t rss_hash;
3181         cmdline_fixed_string_t rss_type;
3182         cmdline_fixed_string_t key; /* optional argument */
3183 };
3184
3185 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3186                                 __rte_unused struct cmdline *cl,
3187                                 void *show_rss_key)
3188 {
3189         struct cmd_showport_rss_hash *res = parsed_result;
3190
3191         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3192 }
3193
3194 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3195         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3196 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3197         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3198 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3199         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3200 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3201         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3202                                  "rss-hash");
3203 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3204         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3205
3206 cmdline_parse_inst_t cmd_showport_rss_hash = {
3207         .f = cmd_showport_rss_hash_parsed,
3208         .data = NULL,
3209         .help_str = "show port <port_id> rss-hash",
3210         .tokens = {
3211                 (void *)&cmd_showport_rss_hash_show,
3212                 (void *)&cmd_showport_rss_hash_port,
3213                 (void *)&cmd_showport_rss_hash_port_id,
3214                 (void *)&cmd_showport_rss_hash_rss_hash,
3215                 NULL,
3216         },
3217 };
3218
3219 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3220         .f = cmd_showport_rss_hash_parsed,
3221         .data = (void *)1,
3222         .help_str = "show port <port_id> rss-hash key",
3223         .tokens = {
3224                 (void *)&cmd_showport_rss_hash_show,
3225                 (void *)&cmd_showport_rss_hash_port,
3226                 (void *)&cmd_showport_rss_hash_port_id,
3227                 (void *)&cmd_showport_rss_hash_rss_hash,
3228                 (void *)&cmd_showport_rss_hash_rss_key,
3229                 NULL,
3230         },
3231 };
3232
3233 /* *** Configure DCB *** */
3234 struct cmd_config_dcb {
3235         cmdline_fixed_string_t port;
3236         cmdline_fixed_string_t config;
3237         portid_t port_id;
3238         cmdline_fixed_string_t dcb;
3239         cmdline_fixed_string_t vt;
3240         cmdline_fixed_string_t vt_en;
3241         uint8_t num_tcs;
3242         cmdline_fixed_string_t pfc;
3243         cmdline_fixed_string_t pfc_en;
3244 };
3245
3246 static void
3247 cmd_config_dcb_parsed(void *parsed_result,
3248                         __rte_unused struct cmdline *cl,
3249                         __rte_unused void *data)
3250 {
3251         struct cmd_config_dcb *res = parsed_result;
3252         portid_t port_id = res->port_id;
3253         struct rte_port *port;
3254         uint8_t pfc_en;
3255         int ret;
3256
3257         port = &ports[port_id];
3258         /** Check if the port is not started **/
3259         if (port->port_status != RTE_PORT_STOPPED) {
3260                 printf("Please stop port %d first\n", port_id);
3261                 return;
3262         }
3263
3264         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3265                 printf("The invalid number of traffic class,"
3266                         " only 4 or 8 allowed.\n");
3267                 return;
3268         }
3269
3270         if (nb_fwd_lcores < res->num_tcs) {
3271                 printf("nb_cores shouldn't be less than number of TCs.\n");
3272                 return;
3273         }
3274         if (!strncmp(res->pfc_en, "on", 2))
3275                 pfc_en = 1;
3276         else
3277                 pfc_en = 0;
3278
3279         /* DCB in VT mode */
3280         if (!strncmp(res->vt_en, "on", 2))
3281                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3282                                 (enum rte_eth_nb_tcs)res->num_tcs,
3283                                 pfc_en);
3284         else
3285                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3286                                 (enum rte_eth_nb_tcs)res->num_tcs,
3287                                 pfc_en);
3288
3289
3290         if (ret != 0) {
3291                 printf("Cannot initialize network ports.\n");
3292                 return;
3293         }
3294
3295         cmd_reconfig_device_queue(port_id, 1, 1);
3296 }
3297
3298 cmdline_parse_token_string_t cmd_config_dcb_port =
3299         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3300 cmdline_parse_token_string_t cmd_config_dcb_config =
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3302 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3303         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3304 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3305         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3306 cmdline_parse_token_string_t cmd_config_dcb_vt =
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3308 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3309         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3310 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3311         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3312 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3313         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3314 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3315         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3316
3317 cmdline_parse_inst_t cmd_config_dcb = {
3318         .f = cmd_config_dcb_parsed,
3319         .data = NULL,
3320         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3321         .tokens = {
3322                 (void *)&cmd_config_dcb_port,
3323                 (void *)&cmd_config_dcb_config,
3324                 (void *)&cmd_config_dcb_port_id,
3325                 (void *)&cmd_config_dcb_dcb,
3326                 (void *)&cmd_config_dcb_vt,
3327                 (void *)&cmd_config_dcb_vt_en,
3328                 (void *)&cmd_config_dcb_num_tcs,
3329                 (void *)&cmd_config_dcb_pfc,
3330                 (void *)&cmd_config_dcb_pfc_en,
3331                 NULL,
3332         },
3333 };
3334
3335 /* *** configure number of packets per burst *** */
3336 struct cmd_config_burst {
3337         cmdline_fixed_string_t port;
3338         cmdline_fixed_string_t keyword;
3339         cmdline_fixed_string_t all;
3340         cmdline_fixed_string_t name;
3341         uint16_t value;
3342 };
3343
3344 static void
3345 cmd_config_burst_parsed(void *parsed_result,
3346                         __rte_unused struct cmdline *cl,
3347                         __rte_unused void *data)
3348 {
3349         struct cmd_config_burst *res = parsed_result;
3350         struct rte_eth_dev_info dev_info;
3351         uint16_t rec_nb_pkts;
3352         int ret;
3353
3354         if (!all_ports_stopped()) {
3355                 printf("Please stop all ports first\n");
3356                 return;
3357         }
3358
3359         if (!strcmp(res->name, "burst")) {
3360                 if (res->value == 0) {
3361                         /* If user gives a value of zero, query the PMD for
3362                          * its recommended Rx burst size. Testpmd uses a single
3363                          * size for all ports, so assume all ports are the same
3364                          * NIC model and use the values from Port 0.
3365                          */
3366                         ret = eth_dev_info_get_print_err(0, &dev_info);
3367                         if (ret != 0)
3368                                 return;
3369
3370                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3371
3372                         if (rec_nb_pkts == 0) {
3373                                 printf("PMD does not recommend a burst size.\n"
3374                                         "User provided value must be between"
3375                                         " 1 and %d\n", MAX_PKT_BURST);
3376                                 return;
3377                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3378                                 printf("PMD recommended burst size of %d"
3379                                         " exceeds maximum value of %d\n",
3380                                         rec_nb_pkts, MAX_PKT_BURST);
3381                                 return;
3382                         }
3383                         printf("Using PMD-provided burst value of %d\n",
3384                                 rec_nb_pkts);
3385                         nb_pkt_per_burst = rec_nb_pkts;
3386                 } else if (res->value > MAX_PKT_BURST) {
3387                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3388                         return;
3389                 } else
3390                         nb_pkt_per_burst = res->value;
3391         } else {
3392                 printf("Unknown parameter\n");
3393                 return;
3394         }
3395
3396         init_port_config();
3397
3398         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3399 }
3400
3401 cmdline_parse_token_string_t cmd_config_burst_port =
3402         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3403 cmdline_parse_token_string_t cmd_config_burst_keyword =
3404         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3405 cmdline_parse_token_string_t cmd_config_burst_all =
3406         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3407 cmdline_parse_token_string_t cmd_config_burst_name =
3408         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3409 cmdline_parse_token_num_t cmd_config_burst_value =
3410         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3411
3412 cmdline_parse_inst_t cmd_config_burst = {
3413         .f = cmd_config_burst_parsed,
3414         .data = NULL,
3415         .help_str = "port config all burst <value>",
3416         .tokens = {
3417                 (void *)&cmd_config_burst_port,
3418                 (void *)&cmd_config_burst_keyword,
3419                 (void *)&cmd_config_burst_all,
3420                 (void *)&cmd_config_burst_name,
3421                 (void *)&cmd_config_burst_value,
3422                 NULL,
3423         },
3424 };
3425
3426 /* *** configure rx/tx queues *** */
3427 struct cmd_config_thresh {
3428         cmdline_fixed_string_t port;
3429         cmdline_fixed_string_t keyword;
3430         cmdline_fixed_string_t all;
3431         cmdline_fixed_string_t name;
3432         uint8_t value;
3433 };
3434
3435 static void
3436 cmd_config_thresh_parsed(void *parsed_result,
3437                         __rte_unused struct cmdline *cl,
3438                         __rte_unused void *data)
3439 {
3440         struct cmd_config_thresh *res = parsed_result;
3441
3442         if (!all_ports_stopped()) {
3443                 printf("Please stop all ports first\n");
3444                 return;
3445         }
3446
3447         if (!strcmp(res->name, "txpt"))
3448                 tx_pthresh = res->value;
3449         else if(!strcmp(res->name, "txht"))
3450                 tx_hthresh = res->value;
3451         else if(!strcmp(res->name, "txwt"))
3452                 tx_wthresh = res->value;
3453         else if(!strcmp(res->name, "rxpt"))
3454                 rx_pthresh = res->value;
3455         else if(!strcmp(res->name, "rxht"))
3456                 rx_hthresh = res->value;
3457         else if(!strcmp(res->name, "rxwt"))
3458                 rx_wthresh = res->value;
3459         else {
3460                 printf("Unknown parameter\n");
3461                 return;
3462         }
3463
3464         init_port_config();
3465
3466         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3467 }
3468
3469 cmdline_parse_token_string_t cmd_config_thresh_port =
3470         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3471 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3472         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3473 cmdline_parse_token_string_t cmd_config_thresh_all =
3474         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3475 cmdline_parse_token_string_t cmd_config_thresh_name =
3476         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3477                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3478 cmdline_parse_token_num_t cmd_config_thresh_value =
3479         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3480
3481 cmdline_parse_inst_t cmd_config_thresh = {
3482         .f = cmd_config_thresh_parsed,
3483         .data = NULL,
3484         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3485         .tokens = {
3486                 (void *)&cmd_config_thresh_port,
3487                 (void *)&cmd_config_thresh_keyword,
3488                 (void *)&cmd_config_thresh_all,
3489                 (void *)&cmd_config_thresh_name,
3490                 (void *)&cmd_config_thresh_value,
3491                 NULL,
3492         },
3493 };
3494
3495 /* *** configure free/rs threshold *** */
3496 struct cmd_config_threshold {
3497         cmdline_fixed_string_t port;
3498         cmdline_fixed_string_t keyword;
3499         cmdline_fixed_string_t all;
3500         cmdline_fixed_string_t name;
3501         uint16_t value;
3502 };
3503
3504 static void
3505 cmd_config_threshold_parsed(void *parsed_result,
3506                         __rte_unused struct cmdline *cl,
3507                         __rte_unused void *data)
3508 {
3509         struct cmd_config_threshold *res = parsed_result;
3510
3511         if (!all_ports_stopped()) {
3512                 printf("Please stop all ports first\n");
3513                 return;
3514         }
3515
3516         if (!strcmp(res->name, "txfreet"))
3517                 tx_free_thresh = res->value;
3518         else if (!strcmp(res->name, "txrst"))
3519                 tx_rs_thresh = res->value;
3520         else if (!strcmp(res->name, "rxfreet"))
3521                 rx_free_thresh = res->value;
3522         else {
3523                 printf("Unknown parameter\n");
3524                 return;
3525         }
3526
3527         init_port_config();
3528
3529         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3530 }
3531
3532 cmdline_parse_token_string_t cmd_config_threshold_port =
3533         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3534 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3535         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3536                                                                 "config");
3537 cmdline_parse_token_string_t cmd_config_threshold_all =
3538         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3539 cmdline_parse_token_string_t cmd_config_threshold_name =
3540         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3541                                                 "txfreet#txrst#rxfreet");
3542 cmdline_parse_token_num_t cmd_config_threshold_value =
3543         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3544
3545 cmdline_parse_inst_t cmd_config_threshold = {
3546         .f = cmd_config_threshold_parsed,
3547         .data = NULL,
3548         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3549         .tokens = {
3550                 (void *)&cmd_config_threshold_port,
3551                 (void *)&cmd_config_threshold_keyword,
3552                 (void *)&cmd_config_threshold_all,
3553                 (void *)&cmd_config_threshold_name,
3554                 (void *)&cmd_config_threshold_value,
3555                 NULL,
3556         },
3557 };
3558
3559 /* *** stop *** */
3560 struct cmd_stop_result {
3561         cmdline_fixed_string_t stop;
3562 };
3563
3564 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3565                             __rte_unused struct cmdline *cl,
3566                             __rte_unused void *data)
3567 {
3568         stop_packet_forwarding();
3569 }
3570
3571 cmdline_parse_token_string_t cmd_stop_stop =
3572         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3573
3574 cmdline_parse_inst_t cmd_stop = {
3575         .f = cmd_stop_parsed,
3576         .data = NULL,
3577         .help_str = "stop: Stop packet forwarding",
3578         .tokens = {
3579                 (void *)&cmd_stop_stop,
3580                 NULL,
3581         },
3582 };
3583
3584 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3585
3586 unsigned int
3587 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3588                 unsigned int *parsed_items, int check_unique_values)
3589 {
3590         unsigned int nb_item;
3591         unsigned int value;
3592         unsigned int i;
3593         unsigned int j;
3594         int value_ok;
3595         char c;
3596
3597         /*
3598          * First parse all items in the list and store their value.
3599          */
3600         value = 0;
3601         nb_item = 0;
3602         value_ok = 0;
3603         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3604                 c = str[i];
3605                 if ((c >= '0') && (c <= '9')) {
3606                         value = (unsigned int) (value * 10 + (c - '0'));
3607                         value_ok = 1;
3608                         continue;
3609                 }
3610                 if (c != ',') {
3611                         printf("character %c is not a decimal digit\n", c);
3612                         return 0;
3613                 }
3614                 if (! value_ok) {
3615                         printf("No valid value before comma\n");
3616                         return 0;
3617                 }
3618                 if (nb_item < max_items) {
3619                         parsed_items[nb_item] = value;
3620                         value_ok = 0;
3621                         value = 0;
3622                 }
3623                 nb_item++;
3624         }
3625         if (nb_item >= max_items) {
3626                 printf("Number of %s = %u > %u (maximum items)\n",
3627                        item_name, nb_item + 1, max_items);
3628                 return 0;
3629         }
3630         parsed_items[nb_item++] = value;
3631         if (! check_unique_values)
3632                 return nb_item;
3633
3634         /*
3635          * Then, check that all values in the list are differents.
3636          * No optimization here...
3637          */
3638         for (i = 0; i < nb_item; i++) {
3639                 for (j = i + 1; j < nb_item; j++) {
3640                         if (parsed_items[j] == parsed_items[i]) {
3641                                 printf("duplicated %s %u at index %u and %u\n",
3642                                        item_name, parsed_items[i], i, j);
3643                                 return 0;
3644                         }
3645                 }
3646         }
3647         return nb_item;
3648 }
3649
3650 struct cmd_set_list_result {
3651         cmdline_fixed_string_t cmd_keyword;
3652         cmdline_fixed_string_t list_name;
3653         cmdline_fixed_string_t list_of_items;
3654 };
3655
3656 static void cmd_set_list_parsed(void *parsed_result,
3657                                 __rte_unused struct cmdline *cl,
3658                                 __rte_unused void *data)
3659 {
3660         struct cmd_set_list_result *res;
3661         union {
3662                 unsigned int lcorelist[RTE_MAX_LCORE];
3663                 unsigned int portlist[RTE_MAX_ETHPORTS];
3664         } parsed_items;
3665         unsigned int nb_item;
3666
3667         if (test_done == 0) {
3668                 printf("Please stop forwarding first\n");
3669                 return;
3670         }
3671
3672         res = parsed_result;
3673         if (!strcmp(res->list_name, "corelist")) {
3674                 nb_item = parse_item_list(res->list_of_items, "core",
3675                                           RTE_MAX_LCORE,
3676                                           parsed_items.lcorelist, 1);
3677                 if (nb_item > 0) {
3678                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3679                         fwd_config_setup();
3680                 }
3681                 return;
3682         }
3683         if (!strcmp(res->list_name, "portlist")) {
3684                 nb_item = parse_item_list(res->list_of_items, "port",
3685                                           RTE_MAX_ETHPORTS,
3686                                           parsed_items.portlist, 1);
3687                 if (nb_item > 0) {
3688                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3689                         fwd_config_setup();
3690                 }
3691         }
3692 }
3693
3694 cmdline_parse_token_string_t cmd_set_list_keyword =
3695         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3696                                  "set");
3697 cmdline_parse_token_string_t cmd_set_list_name =
3698         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3699                                  "corelist#portlist");
3700 cmdline_parse_token_string_t cmd_set_list_of_items =
3701         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3702                                  NULL);
3703
3704 cmdline_parse_inst_t cmd_set_fwd_list = {
3705         .f = cmd_set_list_parsed,
3706         .data = NULL,
3707         .help_str = "set corelist|portlist <list0[,list1]*>",
3708         .tokens = {
3709                 (void *)&cmd_set_list_keyword,
3710                 (void *)&cmd_set_list_name,
3711                 (void *)&cmd_set_list_of_items,
3712                 NULL,
3713         },
3714 };
3715
3716 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3717
3718 struct cmd_setmask_result {
3719         cmdline_fixed_string_t set;
3720         cmdline_fixed_string_t mask;
3721         uint64_t hexavalue;
3722 };
3723
3724 static void cmd_set_mask_parsed(void *parsed_result,
3725                                 __rte_unused struct cmdline *cl,
3726                                 __rte_unused void *data)
3727 {
3728         struct cmd_setmask_result *res = parsed_result;
3729
3730         if (test_done == 0) {
3731                 printf("Please stop forwarding first\n");
3732                 return;
3733         }
3734         if (!strcmp(res->mask, "coremask")) {
3735                 set_fwd_lcores_mask(res->hexavalue);
3736                 fwd_config_setup();
3737         } else if (!strcmp(res->mask, "portmask")) {
3738                 set_fwd_ports_mask(res->hexavalue);
3739                 fwd_config_setup();
3740         }
3741 }
3742
3743 cmdline_parse_token_string_t cmd_setmask_set =
3744         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3745 cmdline_parse_token_string_t cmd_setmask_mask =
3746         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3747                                  "coremask#portmask");
3748 cmdline_parse_token_num_t cmd_setmask_value =
3749         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3750
3751 cmdline_parse_inst_t cmd_set_fwd_mask = {
3752         .f = cmd_set_mask_parsed,
3753         .data = NULL,
3754         .help_str = "set coremask|portmask <hexadecimal value>",
3755         .tokens = {
3756                 (void *)&cmd_setmask_set,
3757                 (void *)&cmd_setmask_mask,
3758                 (void *)&cmd_setmask_value,
3759                 NULL,
3760         },
3761 };
3762
3763 /*
3764  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3765  */
3766 struct cmd_set_result {
3767         cmdline_fixed_string_t set;
3768         cmdline_fixed_string_t what;
3769         uint16_t value;
3770 };
3771
3772 static void cmd_set_parsed(void *parsed_result,
3773                            __rte_unused struct cmdline *cl,
3774                            __rte_unused void *data)
3775 {
3776         struct cmd_set_result *res = parsed_result;
3777         if (!strcmp(res->what, "nbport")) {
3778                 set_fwd_ports_number(res->value);
3779                 fwd_config_setup();
3780         } else if (!strcmp(res->what, "nbcore")) {
3781                 set_fwd_lcores_number(res->value);
3782                 fwd_config_setup();
3783         } else if (!strcmp(res->what, "burst"))
3784                 set_nb_pkt_per_burst(res->value);
3785         else if (!strcmp(res->what, "verbose"))
3786                 set_verbose_level(res->value);
3787 }
3788
3789 cmdline_parse_token_string_t cmd_set_set =
3790         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3791 cmdline_parse_token_string_t cmd_set_what =
3792         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3793                                  "nbport#nbcore#burst#verbose");
3794 cmdline_parse_token_num_t cmd_set_value =
3795         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3796
3797 cmdline_parse_inst_t cmd_set_numbers = {
3798         .f = cmd_set_parsed,
3799         .data = NULL,
3800         .help_str = "set nbport|nbcore|burst|verbose <value>",
3801         .tokens = {
3802                 (void *)&cmd_set_set,
3803                 (void *)&cmd_set_what,
3804                 (void *)&cmd_set_value,
3805                 NULL,
3806         },
3807 };
3808
3809 /* *** SET LOG LEVEL CONFIGURATION *** */
3810
3811 struct cmd_set_log_result {
3812         cmdline_fixed_string_t set;
3813         cmdline_fixed_string_t log;
3814         cmdline_fixed_string_t type;
3815         uint32_t level;
3816 };
3817
3818 static void
3819 cmd_set_log_parsed(void *parsed_result,
3820                    __rte_unused struct cmdline *cl,
3821                    __rte_unused void *data)
3822 {
3823         struct cmd_set_log_result *res;
3824         int ret;
3825
3826         res = parsed_result;
3827         if (!strcmp(res->type, "global"))
3828                 rte_log_set_global_level(res->level);
3829         else {
3830                 ret = rte_log_set_level_regexp(res->type, res->level);
3831                 if (ret < 0)
3832                         printf("Unable to set log level\n");
3833         }
3834 }
3835
3836 cmdline_parse_token_string_t cmd_set_log_set =
3837         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3838 cmdline_parse_token_string_t cmd_set_log_log =
3839         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3840 cmdline_parse_token_string_t cmd_set_log_type =
3841         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3842 cmdline_parse_token_num_t cmd_set_log_level =
3843         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3844
3845 cmdline_parse_inst_t cmd_set_log = {
3846         .f = cmd_set_log_parsed,
3847         .data = NULL,
3848         .help_str = "set log global|<type> <level>",
3849         .tokens = {
3850                 (void *)&cmd_set_log_set,
3851                 (void *)&cmd_set_log_log,
3852                 (void *)&cmd_set_log_type,
3853                 (void *)&cmd_set_log_level,
3854                 NULL,
3855         },
3856 };
3857
3858 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3859
3860 struct cmd_set_txpkts_result {
3861         cmdline_fixed_string_t cmd_keyword;
3862         cmdline_fixed_string_t txpkts;
3863         cmdline_fixed_string_t seg_lengths;
3864 };
3865
3866 static void
3867 cmd_set_txpkts_parsed(void *parsed_result,
3868                       __rte_unused struct cmdline *cl,
3869                       __rte_unused void *data)
3870 {
3871         struct cmd_set_txpkts_result *res;
3872         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3873         unsigned int nb_segs;
3874
3875         res = parsed_result;
3876         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3877                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3878         if (nb_segs > 0)
3879                 set_tx_pkt_segments(seg_lengths, nb_segs);
3880 }
3881
3882 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3884                                  cmd_keyword, "set");
3885 cmdline_parse_token_string_t cmd_set_txpkts_name =
3886         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3887                                  txpkts, "txpkts");
3888 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3889         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3890                                  seg_lengths, NULL);
3891
3892 cmdline_parse_inst_t cmd_set_txpkts = {
3893         .f = cmd_set_txpkts_parsed,
3894         .data = NULL,
3895         .help_str = "set txpkts <len0[,len1]*>",
3896         .tokens = {
3897                 (void *)&cmd_set_txpkts_keyword,
3898                 (void *)&cmd_set_txpkts_name,
3899                 (void *)&cmd_set_txpkts_lengths,
3900                 NULL,
3901         },
3902 };
3903
3904 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3905
3906 struct cmd_set_txsplit_result {
3907         cmdline_fixed_string_t cmd_keyword;
3908         cmdline_fixed_string_t txsplit;
3909         cmdline_fixed_string_t mode;
3910 };
3911
3912 static void
3913 cmd_set_txsplit_parsed(void *parsed_result,
3914                       __rte_unused struct cmdline *cl,
3915                       __rte_unused void *data)
3916 {
3917         struct cmd_set_txsplit_result *res;
3918
3919         res = parsed_result;
3920         set_tx_pkt_split(res->mode);
3921 }
3922
3923 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3924         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3925                                  cmd_keyword, "set");
3926 cmdline_parse_token_string_t cmd_set_txsplit_name =
3927         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3928                                  txsplit, "txsplit");
3929 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3930         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3931                                  mode, NULL);
3932
3933 cmdline_parse_inst_t cmd_set_txsplit = {
3934         .f = cmd_set_txsplit_parsed,
3935         .data = NULL,
3936         .help_str = "set txsplit on|off|rand",
3937         .tokens = {
3938                 (void *)&cmd_set_txsplit_keyword,
3939                 (void *)&cmd_set_txsplit_name,
3940                 (void *)&cmd_set_txsplit_mode,
3941                 NULL,
3942         },
3943 };
3944
3945 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3946 struct cmd_rx_vlan_filter_all_result {
3947         cmdline_fixed_string_t rx_vlan;
3948         cmdline_fixed_string_t what;
3949         cmdline_fixed_string_t all;
3950         portid_t port_id;
3951 };
3952
3953 static void
3954 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3955                               __rte_unused struct cmdline *cl,
3956                               __rte_unused void *data)
3957 {
3958         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3959
3960         if (!strcmp(res->what, "add"))
3961                 rx_vlan_all_filter_set(res->port_id, 1);
3962         else
3963                 rx_vlan_all_filter_set(res->port_id, 0);
3964 }
3965
3966 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3967         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3968                                  rx_vlan, "rx_vlan");
3969 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3970         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3971                                  what, "add#rm");
3972 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3973         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3974                                  all, "all");
3975 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3976         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3977                               port_id, UINT16);
3978
3979 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3980         .f = cmd_rx_vlan_filter_all_parsed,
3981         .data = NULL,
3982         .help_str = "rx_vlan add|rm all <port_id>: "
3983                 "Add/Remove all identifiers to/from the set of VLAN "
3984                 "identifiers filtered by a port",
3985         .tokens = {
3986                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3987                 (void *)&cmd_rx_vlan_filter_all_what,
3988                 (void *)&cmd_rx_vlan_filter_all_all,
3989                 (void *)&cmd_rx_vlan_filter_all_portid,
3990                 NULL,
3991         },
3992 };
3993
3994 /* *** VLAN OFFLOAD SET ON A PORT *** */
3995 struct cmd_vlan_offload_result {
3996         cmdline_fixed_string_t vlan;
3997         cmdline_fixed_string_t set;
3998         cmdline_fixed_string_t vlan_type;
3999         cmdline_fixed_string_t what;
4000         cmdline_fixed_string_t on;
4001         cmdline_fixed_string_t port_id;
4002 };
4003
4004 static void
4005 cmd_vlan_offload_parsed(void *parsed_result,
4006                           __rte_unused struct cmdline *cl,
4007                           __rte_unused void *data)
4008 {
4009         int on;
4010         struct cmd_vlan_offload_result *res = parsed_result;
4011         char *str;
4012         int i, len = 0;
4013         portid_t port_id = 0;
4014         unsigned int tmp;
4015
4016         str = res->port_id;
4017         len = strnlen(str, STR_TOKEN_SIZE);
4018         i = 0;
4019         /* Get port_id first */
4020         while(i < len){
4021                 if(str[i] == ',')
4022                         break;
4023
4024                 i++;
4025         }
4026         str[i]='\0';
4027         tmp = strtoul(str, NULL, 0);
4028         /* If port_id greater that what portid_t can represent, return */
4029         if(tmp >= RTE_MAX_ETHPORTS)
4030                 return;
4031         port_id = (portid_t)tmp;
4032
4033         if (!strcmp(res->on, "on"))
4034                 on = 1;
4035         else
4036                 on = 0;
4037
4038         if (!strcmp(res->what, "strip"))
4039                 rx_vlan_strip_set(port_id,  on);
4040         else if(!strcmp(res->what, "stripq")){
4041                 uint16_t queue_id = 0;
4042
4043                 /* No queue_id, return */
4044                 if(i + 1 >= len) {
4045                         printf("must specify (port,queue_id)\n");
4046                         return;
4047                 }
4048                 tmp = strtoul(str + i + 1, NULL, 0);
4049                 /* If queue_id greater that what 16-bits can represent, return */
4050                 if(tmp > 0xffff)
4051                         return;
4052
4053                 queue_id = (uint16_t)tmp;
4054                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4055         }
4056         else if (!strcmp(res->what, "filter"))
4057                 rx_vlan_filter_set(port_id, on);
4058         else if (!strcmp(res->what, "qinq_strip"))
4059                 rx_vlan_qinq_strip_set(port_id, on);
4060         else
4061                 vlan_extend_set(port_id, on);
4062
4063         return;
4064 }
4065
4066 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4067         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4068                                  vlan, "vlan");
4069 cmdline_parse_token_string_t cmd_vlan_offload_set =
4070         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4071                                  set, "set");
4072 cmdline_parse_token_string_t cmd_vlan_offload_what =
4073         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4074                                 what, "strip#filter#qinq_strip#extend#stripq");
4075 cmdline_parse_token_string_t cmd_vlan_offload_on =
4076         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4077                               on, "on#off");
4078 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4079         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4080                               port_id, NULL);
4081
4082 cmdline_parse_inst_t cmd_vlan_offload = {
4083         .f = cmd_vlan_offload_parsed,
4084         .data = NULL,
4085         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4086                 "<port_id[,queue_id]>: "
4087                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4088         .tokens = {
4089                 (void *)&cmd_vlan_offload_vlan,
4090                 (void *)&cmd_vlan_offload_set,
4091                 (void *)&cmd_vlan_offload_what,
4092                 (void *)&cmd_vlan_offload_on,
4093                 (void *)&cmd_vlan_offload_portid,
4094                 NULL,
4095         },
4096 };
4097
4098 /* *** VLAN TPID SET ON A PORT *** */
4099 struct cmd_vlan_tpid_result {
4100         cmdline_fixed_string_t vlan;
4101         cmdline_fixed_string_t set;
4102         cmdline_fixed_string_t vlan_type;
4103         cmdline_fixed_string_t what;
4104         uint16_t tp_id;
4105         portid_t port_id;
4106 };
4107
4108 static void
4109 cmd_vlan_tpid_parsed(void *parsed_result,
4110                           __rte_unused struct cmdline *cl,
4111                           __rte_unused void *data)
4112 {
4113         struct cmd_vlan_tpid_result *res = parsed_result;
4114         enum rte_vlan_type vlan_type;
4115
4116         if (!strcmp(res->vlan_type, "inner"))
4117                 vlan_type = ETH_VLAN_TYPE_INNER;
4118         else if (!strcmp(res->vlan_type, "outer"))
4119                 vlan_type = ETH_VLAN_TYPE_OUTER;
4120         else {
4121                 printf("Unknown vlan type\n");
4122                 return;
4123         }
4124         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4125 }
4126
4127 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4128         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4129                                  vlan, "vlan");
4130 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4131         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4132                                  set, "set");
4133 cmdline_parse_token_string_t cmd_vlan_type =
4134         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4135                                  vlan_type, "inner#outer");
4136 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4137         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4138                                  what, "tpid");
4139 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4140         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4141                               tp_id, UINT16);
4142 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4143         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4144                               port_id, UINT16);
4145
4146 cmdline_parse_inst_t cmd_vlan_tpid = {
4147         .f = cmd_vlan_tpid_parsed,
4148         .data = NULL,
4149         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4150                 "Set the VLAN Ether type",
4151         .tokens = {
4152                 (void *)&cmd_vlan_tpid_vlan,
4153                 (void *)&cmd_vlan_tpid_set,
4154                 (void *)&cmd_vlan_type,
4155                 (void *)&cmd_vlan_tpid_what,
4156                 (void *)&cmd_vlan_tpid_tpid,
4157                 (void *)&cmd_vlan_tpid_portid,
4158                 NULL,
4159         },
4160 };
4161
4162 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4163 struct cmd_rx_vlan_filter_result {
4164         cmdline_fixed_string_t rx_vlan;
4165         cmdline_fixed_string_t what;
4166         uint16_t vlan_id;
4167         portid_t port_id;
4168 };
4169
4170 static void
4171 cmd_rx_vlan_filter_parsed(void *parsed_result,
4172                           __rte_unused struct cmdline *cl,
4173                           __rte_unused void *data)
4174 {
4175         struct cmd_rx_vlan_filter_result *res = parsed_result;
4176
4177         if (!strcmp(res->what, "add"))
4178                 rx_vft_set(res->port_id, res->vlan_id, 1);
4179         else
4180                 rx_vft_set(res->port_id, res->vlan_id, 0);
4181 }
4182
4183 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4184         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4185                                  rx_vlan, "rx_vlan");
4186 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4187         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4188                                  what, "add#rm");
4189 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4190         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4191                               vlan_id, UINT16);
4192 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4193         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4194                               port_id, UINT16);
4195
4196 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4197         .f = cmd_rx_vlan_filter_parsed,
4198         .data = NULL,
4199         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4200                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4201                 "identifiers filtered by a port",
4202         .tokens = {
4203                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4204                 (void *)&cmd_rx_vlan_filter_what,
4205                 (void *)&cmd_rx_vlan_filter_vlanid,
4206                 (void *)&cmd_rx_vlan_filter_portid,
4207                 NULL,
4208         },
4209 };
4210
4211 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4212 struct cmd_tx_vlan_set_result {
4213         cmdline_fixed_string_t tx_vlan;
4214         cmdline_fixed_string_t set;
4215         portid_t port_id;
4216         uint16_t vlan_id;
4217 };
4218
4219 static void
4220 cmd_tx_vlan_set_parsed(void *parsed_result,
4221                        __rte_unused struct cmdline *cl,
4222                        __rte_unused void *data)
4223 {
4224         struct cmd_tx_vlan_set_result *res = parsed_result;
4225
4226         if (!port_is_stopped(res->port_id)) {
4227                 printf("Please stop port %d first\n", res->port_id);
4228                 return;
4229         }
4230
4231         tx_vlan_set(res->port_id, res->vlan_id);
4232
4233         cmd_reconfig_device_queue(res->port_id, 1, 1);
4234 }
4235
4236 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4237         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4238                                  tx_vlan, "tx_vlan");
4239 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4240         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4241                                  set, "set");
4242 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4243         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4244                               port_id, UINT16);
4245 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4246         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4247                               vlan_id, UINT16);
4248
4249 cmdline_parse_inst_t cmd_tx_vlan_set = {
4250         .f = cmd_tx_vlan_set_parsed,
4251         .data = NULL,
4252         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4253                 "Enable hardware insertion of a single VLAN header "
4254                 "with a given TAG Identifier in packets sent on a port",
4255         .tokens = {
4256                 (void *)&cmd_tx_vlan_set_tx_vlan,
4257                 (void *)&cmd_tx_vlan_set_set,
4258                 (void *)&cmd_tx_vlan_set_portid,
4259                 (void *)&cmd_tx_vlan_set_vlanid,
4260                 NULL,
4261         },
4262 };
4263
4264 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4265 struct cmd_tx_vlan_set_qinq_result {
4266         cmdline_fixed_string_t tx_vlan;
4267         cmdline_fixed_string_t set;
4268         portid_t port_id;
4269         uint16_t vlan_id;
4270         uint16_t vlan_id_outer;
4271 };
4272
4273 static void
4274 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4275                             __rte_unused struct cmdline *cl,
4276                             __rte_unused void *data)
4277 {
4278         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4279
4280         if (!port_is_stopped(res->port_id)) {
4281                 printf("Please stop port %d first\n", res->port_id);
4282                 return;
4283         }
4284
4285         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4286
4287         cmd_reconfig_device_queue(res->port_id, 1, 1);
4288 }
4289
4290 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4291         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4292                 tx_vlan, "tx_vlan");
4293 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4294         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4295                 set, "set");
4296 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4297         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4298                 port_id, UINT16);
4299 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4300         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4301                 vlan_id, UINT16);
4302 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4303         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4304                 vlan_id_outer, UINT16);
4305
4306 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4307         .f = cmd_tx_vlan_set_qinq_parsed,
4308         .data = NULL,
4309         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4310                 "Enable hardware insertion of double VLAN header "
4311                 "with given TAG Identifiers in packets sent on a port",
4312         .tokens = {
4313                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4314                 (void *)&cmd_tx_vlan_set_qinq_set,
4315                 (void *)&cmd_tx_vlan_set_qinq_portid,
4316                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4317                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4318                 NULL,
4319         },
4320 };
4321
4322 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4323 struct cmd_tx_vlan_set_pvid_result {
4324         cmdline_fixed_string_t tx_vlan;
4325         cmdline_fixed_string_t set;
4326         cmdline_fixed_string_t pvid;
4327         portid_t port_id;
4328         uint16_t vlan_id;
4329         cmdline_fixed_string_t mode;
4330 };
4331
4332 static void
4333 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4334                             __rte_unused struct cmdline *cl,
4335                             __rte_unused void *data)
4336 {
4337         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4338
4339         if (strcmp(res->mode, "on") == 0)
4340                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4341         else
4342                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4343 }
4344
4345 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4346         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4347                                  tx_vlan, "tx_vlan");
4348 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4349         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4350                                  set, "set");
4351 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4352         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4353                                  pvid, "pvid");
4354 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4355         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4356                              port_id, UINT16);
4357 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4358         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4359                               vlan_id, UINT16);
4360 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4361         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4362                                  mode, "on#off");
4363
4364 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4365         .f = cmd_tx_vlan_set_pvid_parsed,
4366         .data = NULL,
4367         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4368         .tokens = {
4369                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4370                 (void *)&cmd_tx_vlan_set_pvid_set,
4371                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4372                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4373                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4374                 (void *)&cmd_tx_vlan_set_pvid_mode,
4375                 NULL,
4376         },
4377 };
4378
4379 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4380 struct cmd_tx_vlan_reset_result {
4381         cmdline_fixed_string_t tx_vlan;
4382         cmdline_fixed_string_t reset;
4383         portid_t port_id;
4384 };
4385
4386 static void
4387 cmd_tx_vlan_reset_parsed(void *parsed_result,
4388                          __rte_unused struct cmdline *cl,
4389                          __rte_unused void *data)
4390 {
4391         struct cmd_tx_vlan_reset_result *res = parsed_result;
4392
4393         if (!port_is_stopped(res->port_id)) {
4394                 printf("Please stop port %d first\n", res->port_id);
4395                 return;
4396         }
4397
4398         tx_vlan_reset(res->port_id);
4399
4400         cmd_reconfig_device_queue(res->port_id, 1, 1);
4401 }
4402
4403 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4404         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4405                                  tx_vlan, "tx_vlan");
4406 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4407         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4408                                  reset, "reset");
4409 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4410         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4411                               port_id, UINT16);
4412
4413 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4414         .f = cmd_tx_vlan_reset_parsed,
4415         .data = NULL,
4416         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4417                 "VLAN header in packets sent on a port",
4418         .tokens = {
4419                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4420                 (void *)&cmd_tx_vlan_reset_reset,
4421                 (void *)&cmd_tx_vlan_reset_portid,
4422                 NULL,
4423         },
4424 };
4425
4426
4427 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4428 struct cmd_csum_result {
4429         cmdline_fixed_string_t csum;
4430         cmdline_fixed_string_t mode;
4431         cmdline_fixed_string_t proto;
4432         cmdline_fixed_string_t hwsw;
4433         portid_t port_id;
4434 };
4435
4436 static void
4437 csum_show(int port_id)
4438 {
4439         struct rte_eth_dev_info dev_info;
4440         uint64_t tx_offloads;
4441         int ret;
4442
4443         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4444         printf("Parse tunnel is %s\n",
4445                 (ports[port_id].parse_tunnel) ? "on" : "off");
4446         printf("IP checksum offload is %s\n",
4447                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4448         printf("UDP checksum offload is %s\n",
4449                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4450         printf("TCP checksum offload is %s\n",
4451                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4452         printf("SCTP checksum offload is %s\n",
4453                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4454         printf("Outer-Ip checksum offload is %s\n",
4455                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4456         printf("Outer-Udp checksum offload is %s\n",
4457                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4458
4459         /* display warnings if configuration is not supported by the NIC */
4460         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4461         if (ret != 0)
4462                 return;
4463
4464         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4465                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4466                 printf("Warning: hardware IP checksum enabled but not "
4467                         "supported by port %d\n", port_id);
4468         }
4469         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4470                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4471                 printf("Warning: hardware UDP checksum enabled but not "
4472                         "supported by port %d\n", port_id);
4473         }
4474         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4475                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4476                 printf("Warning: hardware TCP checksum enabled but not "
4477                         "supported by port %d\n", port_id);
4478         }
4479         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4480                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4481                 printf("Warning: hardware SCTP checksum enabled but not "
4482                         "supported by port %d\n", port_id);
4483         }
4484         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4485                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4486                 printf("Warning: hardware outer IP checksum enabled but not "
4487                         "supported by port %d\n", port_id);
4488         }
4489         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4490                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4491                         == 0) {
4492                 printf("Warning: hardware outer UDP checksum enabled but not "
4493                         "supported by port %d\n", port_id);
4494         }
4495 }
4496
4497 static void
4498 cmd_config_queue_tx_offloads(struct rte_port *port)
4499 {
4500         int k;
4501
4502         /* Apply queue tx offloads configuration */
4503         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4504                 port->tx_conf[k].offloads =
4505                         port->dev_conf.txmode.offloads;
4506 }
4507
4508 static void
4509 cmd_csum_parsed(void *parsed_result,
4510                        __rte_unused struct cmdline *cl,
4511                        __rte_unused void *data)
4512 {
4513         struct cmd_csum_result *res = parsed_result;
4514         int hw = 0;
4515         uint64_t csum_offloads = 0;
4516         struct rte_eth_dev_info dev_info;
4517         int ret;
4518
4519         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4520                 printf("invalid port %d\n", res->port_id);
4521                 return;
4522         }
4523         if (!port_is_stopped(res->port_id)) {
4524                 printf("Please stop port %d first\n", res->port_id);
4525                 return;
4526         }
4527
4528         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4529         if (ret != 0)
4530                 return;
4531
4532         if (!strcmp(res->mode, "set")) {
4533
4534                 if (!strcmp(res->hwsw, "hw"))
4535                         hw = 1;
4536
4537                 if (!strcmp(res->proto, "ip")) {
4538                         if (hw == 0 || (dev_info.tx_offload_capa &
4539                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4540                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4541                         } else {
4542                                 printf("IP checksum offload is not supported "
4543                                        "by port %u\n", res->port_id);
4544                         }
4545                 } else if (!strcmp(res->proto, "udp")) {
4546                         if (hw == 0 || (dev_info.tx_offload_capa &
4547                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4548                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4549                         } else {
4550                                 printf("UDP checksum offload is not supported "
4551                                        "by port %u\n", res->port_id);
4552                         }
4553                 } else if (!strcmp(res->proto, "tcp")) {
4554                         if (hw == 0 || (dev_info.tx_offload_capa &
4555                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4556                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4557                         } else {
4558                                 printf("TCP checksum offload is not supported "
4559                                        "by port %u\n", res->port_id);
4560                         }
4561                 } else if (!strcmp(res->proto, "sctp")) {
4562                         if (hw == 0 || (dev_info.tx_offload_capa &
4563                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4564                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4565                         } else {
4566                                 printf("SCTP checksum offload is not supported "
4567                                        "by port %u\n", res->port_id);
4568                         }
4569                 } else if (!strcmp(res->proto, "outer-ip")) {
4570                         if (hw == 0 || (dev_info.tx_offload_capa &
4571                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4572                                 csum_offloads |=
4573                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4574                         } else {
4575                                 printf("Outer IP checksum offload is not "
4576                                        "supported by port %u\n", res->port_id);
4577                         }
4578                 } else if (!strcmp(res->proto, "outer-udp")) {
4579                         if (hw == 0 || (dev_info.tx_offload_capa &
4580                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4581                                 csum_offloads |=
4582                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4583                         } else {
4584                                 printf("Outer UDP checksum offload is not "
4585                                        "supported by port %u\n", res->port_id);
4586                         }
4587                 }
4588
4589                 if (hw) {
4590                         ports[res->port_id].dev_conf.txmode.offloads |=
4591                                                         csum_offloads;
4592                 } else {
4593                         ports[res->port_id].dev_conf.txmode.offloads &=
4594                                                         (~csum_offloads);
4595                 }
4596                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4597         }
4598         csum_show(res->port_id);
4599
4600         cmd_reconfig_device_queue(res->port_id, 1, 1);
4601 }
4602
4603 cmdline_parse_token_string_t cmd_csum_csum =
4604         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4605                                 csum, "csum");
4606 cmdline_parse_token_string_t cmd_csum_mode =
4607         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4608                                 mode, "set");
4609 cmdline_parse_token_string_t cmd_csum_proto =
4610         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4611                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4612 cmdline_parse_token_string_t cmd_csum_hwsw =
4613         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4614                                 hwsw, "hw#sw");
4615 cmdline_parse_token_num_t cmd_csum_portid =
4616         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4617                                 port_id, UINT16);
4618
4619 cmdline_parse_inst_t cmd_csum_set = {
4620         .f = cmd_csum_parsed,
4621         .data = NULL,
4622         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4623                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4624                 "using csum forward engine",
4625         .tokens = {
4626                 (void *)&cmd_csum_csum,
4627                 (void *)&cmd_csum_mode,
4628                 (void *)&cmd_csum_proto,
4629                 (void *)&cmd_csum_hwsw,
4630                 (void *)&cmd_csum_portid,
4631                 NULL,
4632         },
4633 };
4634
4635 cmdline_parse_token_string_t cmd_csum_mode_show =
4636         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4637                                 mode, "show");
4638
4639 cmdline_parse_inst_t cmd_csum_show = {
4640         .f = cmd_csum_parsed,
4641         .data = NULL,
4642         .help_str = "csum show <port_id>: Show checksum offload configuration",
4643         .tokens = {
4644                 (void *)&cmd_csum_csum,
4645                 (void *)&cmd_csum_mode_show,
4646                 (void *)&cmd_csum_portid,
4647                 NULL,
4648         },
4649 };
4650
4651 /* Enable/disable tunnel parsing */
4652 struct cmd_csum_tunnel_result {
4653         cmdline_fixed_string_t csum;
4654         cmdline_fixed_string_t parse;
4655         cmdline_fixed_string_t onoff;
4656         portid_t port_id;
4657 };
4658
4659 static void
4660 cmd_csum_tunnel_parsed(void *parsed_result,
4661                        __rte_unused struct cmdline *cl,
4662                        __rte_unused void *data)
4663 {
4664         struct cmd_csum_tunnel_result *res = parsed_result;
4665
4666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4667                 return;
4668
4669         if (!strcmp(res->onoff, "on"))
4670                 ports[res->port_id].parse_tunnel = 1;
4671         else
4672                 ports[res->port_id].parse_tunnel = 0;
4673
4674         csum_show(res->port_id);
4675 }
4676
4677 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4678         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4679                                 csum, "csum");
4680 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4681         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4682                                 parse, "parse-tunnel");
4683 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4684         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4685                                 onoff, "on#off");
4686 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4687         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4688                                 port_id, UINT16);
4689
4690 cmdline_parse_inst_t cmd_csum_tunnel = {
4691         .f = cmd_csum_tunnel_parsed,
4692         .data = NULL,
4693         .help_str = "csum parse-tunnel on|off <port_id>: "
4694                 "Enable/Disable parsing of tunnels for csum engine",
4695         .tokens = {
4696                 (void *)&cmd_csum_tunnel_csum,
4697                 (void *)&cmd_csum_tunnel_parse,
4698                 (void *)&cmd_csum_tunnel_onoff,
4699                 (void *)&cmd_csum_tunnel_portid,
4700                 NULL,
4701         },
4702 };
4703
4704 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4705 struct cmd_tso_set_result {
4706         cmdline_fixed_string_t tso;
4707         cmdline_fixed_string_t mode;
4708         uint16_t tso_segsz;
4709         portid_t port_id;
4710 };
4711
4712 static void
4713 cmd_tso_set_parsed(void *parsed_result,
4714                        __rte_unused struct cmdline *cl,
4715                        __rte_unused void *data)
4716 {
4717         struct cmd_tso_set_result *res = parsed_result;
4718         struct rte_eth_dev_info dev_info;
4719         int ret;
4720
4721         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4722                 return;
4723         if (!port_is_stopped(res->port_id)) {
4724                 printf("Please stop port %d first\n", res->port_id);
4725                 return;
4726         }
4727
4728         if (!strcmp(res->mode, "set"))
4729                 ports[res->port_id].tso_segsz = res->tso_segsz;
4730
4731         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4732         if (ret != 0)
4733                 return;
4734
4735         if ((ports[res->port_id].tso_segsz != 0) &&
4736                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4737                 printf("Error: TSO is not supported by port %d\n",
4738                        res->port_id);
4739                 return;
4740         }
4741
4742         if (ports[res->port_id].tso_segsz == 0) {
4743                 ports[res->port_id].dev_conf.txmode.offloads &=
4744                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4745                 printf("TSO for non-tunneled packets is disabled\n");
4746         } else {
4747                 ports[res->port_id].dev_conf.txmode.offloads |=
4748                                                 DEV_TX_OFFLOAD_TCP_TSO;
4749                 printf("TSO segment size for non-tunneled packets is %d\n",
4750                         ports[res->port_id].tso_segsz);
4751         }
4752         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4753
4754         /* display warnings if configuration is not supported by the NIC */
4755         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4756         if (ret != 0)
4757                 return;
4758
4759         if ((ports[res->port_id].tso_segsz != 0) &&
4760                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4761                 printf("Warning: TSO enabled but not "
4762                         "supported by port %d\n", res->port_id);
4763         }
4764
4765         cmd_reconfig_device_queue(res->port_id, 1, 1);
4766 }
4767
4768 cmdline_parse_token_string_t cmd_tso_set_tso =
4769         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4770                                 tso, "tso");
4771 cmdline_parse_token_string_t cmd_tso_set_mode =
4772         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4773                                 mode, "set");
4774 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4775         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4776                                 tso_segsz, UINT16);
4777 cmdline_parse_token_num_t cmd_tso_set_portid =
4778         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4779                                 port_id, UINT16);
4780
4781 cmdline_parse_inst_t cmd_tso_set = {
4782         .f = cmd_tso_set_parsed,
4783         .data = NULL,
4784         .help_str = "tso set <tso_segsz> <port_id>: "
4785                 "Set TSO segment size of non-tunneled packets for csum engine "
4786                 "(0 to disable)",
4787         .tokens = {
4788                 (void *)&cmd_tso_set_tso,
4789                 (void *)&cmd_tso_set_mode,
4790                 (void *)&cmd_tso_set_tso_segsz,
4791                 (void *)&cmd_tso_set_portid,
4792                 NULL,
4793         },
4794 };
4795
4796 cmdline_parse_token_string_t cmd_tso_show_mode =
4797         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4798                                 mode, "show");
4799
4800
4801 cmdline_parse_inst_t cmd_tso_show = {
4802         .f = cmd_tso_set_parsed,
4803         .data = NULL,
4804         .help_str = "tso show <port_id>: "
4805                 "Show TSO segment size of non-tunneled packets for csum engine",
4806         .tokens = {
4807                 (void *)&cmd_tso_set_tso,
4808                 (void *)&cmd_tso_show_mode,
4809                 (void *)&cmd_tso_set_portid,
4810                 NULL,
4811         },
4812 };
4813
4814 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4815 struct cmd_tunnel_tso_set_result {
4816         cmdline_fixed_string_t tso;
4817         cmdline_fixed_string_t mode;
4818         uint16_t tso_segsz;
4819         portid_t port_id;
4820 };
4821
4822 static struct rte_eth_dev_info
4823 check_tunnel_tso_nic_support(portid_t port_id)
4824 {
4825         struct rte_eth_dev_info dev_info;
4826
4827         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4828                 return dev_info;
4829
4830         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4831                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4832                        "not enabled for port %d\n", port_id);
4833         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4834                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4835                        "not enabled for port %d\n", port_id);
4836         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4837                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4838                        "not enabled for port %d\n", port_id);
4839         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4840                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4841                        "not enabled for port %d\n", port_id);
4842         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4843                 printf("Warning: IP TUNNEL TSO not supported therefore "
4844                        "not enabled for port %d\n", port_id);
4845         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4846                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4847                        "not enabled for port %d\n", port_id);
4848         return dev_info;
4849 }
4850
4851 static void
4852 cmd_tunnel_tso_set_parsed(void *parsed_result,
4853                           __rte_unused struct cmdline *cl,
4854                           __rte_unused void *data)
4855 {
4856         struct cmd_tunnel_tso_set_result *res = parsed_result;
4857         struct rte_eth_dev_info dev_info;
4858
4859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4860                 return;
4861         if (!port_is_stopped(res->port_id)) {
4862                 printf("Please stop port %d first\n", res->port_id);
4863                 return;
4864         }
4865
4866         if (!strcmp(res->mode, "set"))
4867                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4868
4869         dev_info = check_tunnel_tso_nic_support(res->port_id);
4870         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4871                 ports[res->port_id].dev_conf.txmode.offloads &=
4872                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4873                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4874                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4875                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4876                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4877                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4878                 printf("TSO for tunneled packets is disabled\n");
4879         } else {
4880                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4881                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4882                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4883                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4884                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4885                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4886
4887                 ports[res->port_id].dev_conf.txmode.offloads |=
4888                         (tso_offloads & dev_info.tx_offload_capa);
4889                 printf("TSO segment size for tunneled packets is %d\n",
4890                         ports[res->port_id].tunnel_tso_segsz);
4891
4892                 /* Below conditions are needed to make it work:
4893                  * (1) tunnel TSO is supported by the NIC;
4894                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4895                  * are recognized;
4896                  * (3) for tunneled pkts with outer L3 of IPv4,
4897                  * "csum set outer-ip" must be set to hw, because after tso,
4898                  * total_len of outer IP header is changed, and the checksum
4899                  * of outer IP header calculated by sw should be wrong; that
4900                  * is not necessary for IPv6 tunneled pkts because there's no
4901                  * checksum in IP header anymore.
4902                  */
4903
4904                 if (!ports[res->port_id].parse_tunnel)
4905                         printf("Warning: csum parse_tunnel must be set "
4906                                 "so that tunneled packets are recognized\n");
4907                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4908                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4909                         printf("Warning: csum set outer-ip must be set to hw "
4910                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4911         }
4912
4913         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4914         cmd_reconfig_device_queue(res->port_id, 1, 1);
4915 }
4916
4917 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4918         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4919                                 tso, "tunnel_tso");
4920 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4921         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4922                                 mode, "set");
4923 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4924         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4925                                 tso_segsz, UINT16);
4926 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4927         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4928                                 port_id, UINT16);
4929
4930 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4931         .f = cmd_tunnel_tso_set_parsed,
4932         .data = NULL,
4933         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4934                 "Set TSO segment size of tunneled packets for csum engine "
4935                 "(0 to disable)",
4936         .tokens = {
4937                 (void *)&cmd_tunnel_tso_set_tso,
4938                 (void *)&cmd_tunnel_tso_set_mode,
4939                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4940                 (void *)&cmd_tunnel_tso_set_portid,
4941                 NULL,
4942         },
4943 };
4944
4945 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4946         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4947                                 mode, "show");
4948
4949
4950 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4951         .f = cmd_tunnel_tso_set_parsed,
4952         .data = NULL,
4953         .help_str = "tunnel_tso show <port_id> "
4954                 "Show TSO segment size of tunneled packets for csum engine",
4955         .tokens = {
4956                 (void *)&cmd_tunnel_tso_set_tso,
4957                 (void *)&cmd_tunnel_tso_show_mode,
4958                 (void *)&cmd_tunnel_tso_set_portid,
4959                 NULL,
4960         },
4961 };
4962
4963 /* *** SET GRO FOR A PORT *** */
4964 struct cmd_gro_enable_result {
4965         cmdline_fixed_string_t cmd_set;
4966         cmdline_fixed_string_t cmd_port;
4967         cmdline_fixed_string_t cmd_keyword;
4968         cmdline_fixed_string_t cmd_onoff;
4969         portid_t cmd_pid;
4970 };
4971
4972 static void
4973 cmd_gro_enable_parsed(void *parsed_result,
4974                 __rte_unused struct cmdline *cl,
4975                 __rte_unused void *data)
4976 {
4977         struct cmd_gro_enable_result *res;
4978
4979         res = parsed_result;
4980         if (!strcmp(res->cmd_keyword, "gro"))
4981                 setup_gro(res->cmd_onoff, res->cmd_pid);
4982 }
4983
4984 cmdline_parse_token_string_t cmd_gro_enable_set =
4985         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4986                         cmd_set, "set");
4987 cmdline_parse_token_string_t cmd_gro_enable_port =
4988         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4989                         cmd_keyword, "port");
4990 cmdline_parse_token_num_t cmd_gro_enable_pid =
4991         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4992                         cmd_pid, UINT16);
4993 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4994         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4995                         cmd_keyword, "gro");
4996 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4997         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4998                         cmd_onoff, "on#off");
4999
5000 cmdline_parse_inst_t cmd_gro_enable = {
5001         .f = cmd_gro_enable_parsed,
5002         .data = NULL,
5003         .help_str = "set port <port_id> gro on|off",
5004         .tokens = {
5005                 (void *)&cmd_gro_enable_set,
5006                 (void *)&cmd_gro_enable_port,
5007                 (void *)&cmd_gro_enable_pid,
5008                 (void *)&cmd_gro_enable_keyword,
5009                 (void *)&cmd_gro_enable_onoff,
5010                 NULL,
5011         },
5012 };
5013
5014 /* *** DISPLAY GRO CONFIGURATION *** */
5015 struct cmd_gro_show_result {
5016         cmdline_fixed_string_t cmd_show;
5017         cmdline_fixed_string_t cmd_port;
5018         cmdline_fixed_string_t cmd_keyword;
5019         portid_t cmd_pid;
5020 };
5021
5022 static void
5023 cmd_gro_show_parsed(void *parsed_result,
5024                 __rte_unused struct cmdline *cl,
5025                 __rte_unused void *data)
5026 {
5027         struct cmd_gro_show_result *res;
5028
5029         res = parsed_result;
5030         if (!strcmp(res->cmd_keyword, "gro"))
5031                 show_gro(res->cmd_pid);
5032 }
5033
5034 cmdline_parse_token_string_t cmd_gro_show_show =
5035         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5036                         cmd_show, "show");
5037 cmdline_parse_token_string_t cmd_gro_show_port =
5038         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5039                         cmd_port, "port");
5040 cmdline_parse_token_num_t cmd_gro_show_pid =
5041         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5042                         cmd_pid, UINT16);
5043 cmdline_parse_token_string_t cmd_gro_show_keyword =
5044         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5045                         cmd_keyword, "gro");
5046
5047 cmdline_parse_inst_t cmd_gro_show = {
5048         .f = cmd_gro_show_parsed,
5049         .data = NULL,
5050         .help_str = "show port <port_id> gro",
5051         .tokens = {
5052                 (void *)&cmd_gro_show_show,
5053                 (void *)&cmd_gro_show_port,
5054                 (void *)&cmd_gro_show_pid,
5055                 (void *)&cmd_gro_show_keyword,
5056                 NULL,
5057         },
5058 };
5059
5060 /* *** SET FLUSH CYCLES FOR GRO *** */
5061 struct cmd_gro_flush_result {
5062         cmdline_fixed_string_t cmd_set;
5063         cmdline_fixed_string_t cmd_keyword;
5064         cmdline_fixed_string_t cmd_flush;
5065         uint8_t cmd_cycles;
5066 };
5067
5068 static void
5069 cmd_gro_flush_parsed(void *parsed_result,
5070                 __rte_unused struct cmdline *cl,
5071                 __rte_unused void *data)
5072 {
5073         struct cmd_gro_flush_result *res;
5074
5075         res = parsed_result;
5076         if ((!strcmp(res->cmd_keyword, "gro")) &&
5077                         (!strcmp(res->cmd_flush, "flush")))
5078                 setup_gro_flush_cycles(res->cmd_cycles);
5079 }
5080
5081 cmdline_parse_token_string_t cmd_gro_flush_set =
5082         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5083                         cmd_set, "set");
5084 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5085         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5086                         cmd_keyword, "gro");
5087 cmdline_parse_token_string_t cmd_gro_flush_flush =
5088         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5089                         cmd_flush, "flush");
5090 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5091         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5092                         cmd_cycles, UINT8);
5093
5094 cmdline_parse_inst_t cmd_gro_flush = {
5095         .f = cmd_gro_flush_parsed,
5096         .data = NULL,
5097         .help_str = "set gro flush <cycles>",
5098         .tokens = {
5099                 (void *)&cmd_gro_flush_set,
5100                 (void *)&cmd_gro_flush_keyword,
5101                 (void *)&cmd_gro_flush_flush,
5102                 (void *)&cmd_gro_flush_cycles,
5103                 NULL,
5104         },
5105 };
5106
5107 /* *** ENABLE/DISABLE GSO *** */
5108 struct cmd_gso_enable_result {
5109         cmdline_fixed_string_t cmd_set;
5110         cmdline_fixed_string_t cmd_port;
5111         cmdline_fixed_string_t cmd_keyword;
5112         cmdline_fixed_string_t cmd_mode;
5113         portid_t cmd_pid;
5114 };
5115
5116 static void
5117 cmd_gso_enable_parsed(void *parsed_result,
5118                 __rte_unused struct cmdline *cl,
5119                 __rte_unused void *data)
5120 {
5121         struct cmd_gso_enable_result *res;
5122
5123         res = parsed_result;
5124         if (!strcmp(res->cmd_keyword, "gso"))
5125                 setup_gso(res->cmd_mode, res->cmd_pid);
5126 }
5127
5128 cmdline_parse_token_string_t cmd_gso_enable_set =
5129         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5130                         cmd_set, "set");
5131 cmdline_parse_token_string_t cmd_gso_enable_port =
5132         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5133                         cmd_port, "port");
5134 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5135         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5136                         cmd_keyword, "gso");
5137 cmdline_parse_token_string_t cmd_gso_enable_mode =
5138         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5139                         cmd_mode, "on#off");
5140 cmdline_parse_token_num_t cmd_gso_enable_pid =
5141         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5142                         cmd_pid, UINT16);
5143
5144 cmdline_parse_inst_t cmd_gso_enable = {
5145         .f = cmd_gso_enable_parsed,
5146         .data = NULL,
5147         .help_str = "set port <port_id> gso on|off",
5148         .tokens = {
5149                 (void *)&cmd_gso_enable_set,
5150                 (void *)&cmd_gso_enable_port,
5151                 (void *)&cmd_gso_enable_pid,
5152                 (void *)&cmd_gso_enable_keyword,
5153                 (void *)&cmd_gso_enable_mode,
5154                 NULL,
5155         },
5156 };
5157
5158 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5159 struct cmd_gso_size_result {
5160         cmdline_fixed_string_t cmd_set;
5161         cmdline_fixed_string_t cmd_keyword;
5162         cmdline_fixed_string_t cmd_segsz;
5163         uint16_t cmd_size;
5164 };
5165
5166 static void
5167 cmd_gso_size_parsed(void *parsed_result,
5168                        __rte_unused struct cmdline *cl,
5169                        __rte_unused void *data)
5170 {
5171         struct cmd_gso_size_result *res = parsed_result;
5172
5173         if (test_done == 0) {
5174                 printf("Before setting GSO segsz, please first"
5175                                 " stop forwarding\n");
5176                 return;
5177         }
5178
5179         if (!strcmp(res->cmd_keyword, "gso") &&
5180                         !strcmp(res->cmd_segsz, "segsz")) {
5181                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5182                         printf("gso_size should be larger than %zu."
5183                                         " Please input a legal value\n",
5184                                         RTE_GSO_SEG_SIZE_MIN);
5185                 else
5186                         gso_max_segment_size = res->cmd_size;
5187         }
5188 }
5189
5190 cmdline_parse_token_string_t cmd_gso_size_set =
5191         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5192                                 cmd_set, "set");
5193 cmdline_parse_token_string_t cmd_gso_size_keyword =
5194         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5195                                 cmd_keyword, "gso");
5196 cmdline_parse_token_string_t cmd_gso_size_segsz =
5197         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5198                                 cmd_segsz, "segsz");
5199 cmdline_parse_token_num_t cmd_gso_size_size =
5200         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5201                                 cmd_size, UINT16);
5202
5203 cmdline_parse_inst_t cmd_gso_size = {
5204         .f = cmd_gso_size_parsed,
5205         .data = NULL,
5206         .help_str = "set gso segsz <length>",
5207         .tokens = {
5208                 (void *)&cmd_gso_size_set,
5209                 (void *)&cmd_gso_size_keyword,
5210                 (void *)&cmd_gso_size_segsz,
5211                 (void *)&cmd_gso_size_size,
5212                 NULL,
5213         },
5214 };
5215
5216 /* *** SHOW GSO CONFIGURATION *** */
5217 struct cmd_gso_show_result {
5218         cmdline_fixed_string_t cmd_show;
5219         cmdline_fixed_string_t cmd_port;
5220         cmdline_fixed_string_t cmd_keyword;
5221         portid_t cmd_pid;
5222 };
5223
5224 static void
5225 cmd_gso_show_parsed(void *parsed_result,
5226                        __rte_unused struct cmdline *cl,
5227                        __rte_unused void *data)
5228 {
5229         struct cmd_gso_show_result *res = parsed_result;
5230
5231         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5232                 printf("invalid port id %u\n", res->cmd_pid);
5233                 return;
5234         }
5235         if (!strcmp(res->cmd_keyword, "gso")) {
5236                 if (gso_ports[res->cmd_pid].enable) {
5237                         printf("Max GSO'd packet size: %uB\n"
5238                                         "Supported GSO types: TCP/IPv4, "
5239                                         "UDP/IPv4, VxLAN with inner "
5240                                         "TCP/IPv4 packet, GRE with inner "
5241                                         "TCP/IPv4 packet\n",
5242                                         gso_max_segment_size);
5243                 } else
5244                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5245         }
5246 }
5247
5248 cmdline_parse_token_string_t cmd_gso_show_show =
5249 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5250                 cmd_show, "show");
5251 cmdline_parse_token_string_t cmd_gso_show_port =
5252 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5253                 cmd_port, "port");
5254 cmdline_parse_token_string_t cmd_gso_show_keyword =
5255         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5256                                 cmd_keyword, "gso");
5257 cmdline_parse_token_num_t cmd_gso_show_pid =
5258         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5259                                 cmd_pid, UINT16);
5260
5261 cmdline_parse_inst_t cmd_gso_show = {
5262         .f = cmd_gso_show_parsed,
5263         .data = NULL,
5264         .help_str = "show port <port_id> gso",
5265         .tokens = {
5266                 (void *)&cmd_gso_show_show,
5267                 (void *)&cmd_gso_show_port,
5268                 (void *)&cmd_gso_show_pid,
5269                 (void *)&cmd_gso_show_keyword,
5270                 NULL,
5271         },
5272 };
5273
5274 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5275 struct cmd_set_flush_rx {
5276         cmdline_fixed_string_t set;
5277         cmdline_fixed_string_t flush_rx;
5278         cmdline_fixed_string_t mode;
5279 };
5280
5281 static void
5282 cmd_set_flush_rx_parsed(void *parsed_result,
5283                 __rte_unused struct cmdline *cl,
5284                 __rte_unused void *data)
5285 {
5286         struct cmd_set_flush_rx *res = parsed_result;
5287         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5288 }
5289
5290 cmdline_parse_token_string_t cmd_setflushrx_set =
5291         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5292                         set, "set");
5293 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5294         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5295                         flush_rx, "flush_rx");
5296 cmdline_parse_token_string_t cmd_setflushrx_mode =
5297         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5298                         mode, "on#off");
5299
5300
5301 cmdline_parse_inst_t cmd_set_flush_rx = {
5302         .f = cmd_set_flush_rx_parsed,
5303         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5304         .data = NULL,
5305         .tokens = {
5306                 (void *)&cmd_setflushrx_set,
5307                 (void *)&cmd_setflushrx_flush_rx,
5308                 (void *)&cmd_setflushrx_mode,
5309                 NULL,
5310         },
5311 };
5312
5313 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5314 struct cmd_set_link_check {
5315         cmdline_fixed_string_t set;
5316         cmdline_fixed_string_t link_check;
5317         cmdline_fixed_string_t mode;
5318 };
5319
5320 static void
5321 cmd_set_link_check_parsed(void *parsed_result,
5322                 __rte_unused struct cmdline *cl,
5323                 __rte_unused void *data)
5324 {
5325         struct cmd_set_link_check *res = parsed_result;
5326         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5327 }
5328
5329 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5330         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5331                         set, "set");
5332 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5333         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5334                         link_check, "link_check");
5335 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5336         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5337                         mode, "on#off");
5338
5339
5340 cmdline_parse_inst_t cmd_set_link_check = {
5341         .f = cmd_set_link_check_parsed,
5342         .help_str = "set link_check on|off: Enable/Disable link status check "
5343                     "when starting/stopping a port",
5344         .data = NULL,
5345         .tokens = {
5346                 (void *)&cmd_setlinkcheck_set,
5347                 (void *)&cmd_setlinkcheck_link_check,
5348                 (void *)&cmd_setlinkcheck_mode,
5349                 NULL,
5350         },
5351 };
5352
5353 /* *** SET NIC BYPASS MODE *** */
5354 struct cmd_set_bypass_mode_result {
5355         cmdline_fixed_string_t set;
5356         cmdline_fixed_string_t bypass;
5357         cmdline_fixed_string_t mode;
5358         cmdline_fixed_string_t value;
5359         portid_t port_id;
5360 };
5361
5362 static void
5363 cmd_set_bypass_mode_parsed(void *parsed_result,
5364                 __rte_unused struct cmdline *cl,
5365                 __rte_unused void *data)
5366 {
5367         struct cmd_set_bypass_mode_result *res = parsed_result;
5368         portid_t port_id = res->port_id;
5369         int32_t rc = -EINVAL;
5370
5371 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5372         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5373
5374         if (!strcmp(res->value, "bypass"))
5375                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5376         else if (!strcmp(res->value, "isolate"))
5377                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5378         else
5379                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5380
5381         /* Set the bypass mode for the relevant port. */
5382         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5383 #endif
5384         if (rc != 0)
5385                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5386 }
5387
5388 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5389         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5390                         set, "set");
5391 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5392         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5393                         bypass, "bypass");
5394 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5395         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5396                         mode, "mode");
5397 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5398         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5399                         value, "normal#bypass#isolate");
5400 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5401         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5402                                 port_id, UINT16);
5403
5404 cmdline_parse_inst_t cmd_set_bypass_mode = {
5405         .f = cmd_set_bypass_mode_parsed,
5406         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5407                     "Set the NIC bypass mode for port_id",
5408         .data = NULL,
5409         .tokens = {
5410                 (void *)&cmd_setbypass_mode_set,
5411                 (void *)&cmd_setbypass_mode_bypass,
5412                 (void *)&cmd_setbypass_mode_mode,
5413                 (void *)&cmd_setbypass_mode_value,
5414                 (void *)&cmd_setbypass_mode_port,
5415                 NULL,
5416         },
5417 };
5418
5419 /* *** SET NIC BYPASS EVENT *** */
5420 struct cmd_set_bypass_event_result {
5421         cmdline_fixed_string_t set;
5422         cmdline_fixed_string_t bypass;
5423         cmdline_fixed_string_t event;
5424         cmdline_fixed_string_t event_value;
5425         cmdline_fixed_string_t mode;
5426         cmdline_fixed_string_t mode_value;
5427         portid_t port_id;
5428 };
5429
5430 static void
5431 cmd_set_bypass_event_parsed(void *parsed_result,
5432                 __rte_unused struct cmdline *cl,
5433                 __rte_unused void *data)
5434 {
5435         int32_t rc = -EINVAL;
5436         struct cmd_set_bypass_event_result *res = parsed_result;
5437         portid_t port_id = res->port_id;
5438
5439 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5440         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5441         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5442
5443         if (!strcmp(res->event_value, "timeout"))
5444                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5445         else if (!strcmp(res->event_value, "os_on"))
5446                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5447         else if (!strcmp(res->event_value, "os_off"))
5448                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5449         else if (!strcmp(res->event_value, "power_on"))
5450                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5451         else if (!strcmp(res->event_value, "power_off"))
5452                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5453         else
5454                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5455
5456         if (!strcmp(res->mode_value, "bypass"))
5457                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5458         else if (!strcmp(res->mode_value, "isolate"))
5459                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5460         else
5461                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5462
5463         /* Set the watchdog timeout. */
5464         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5465
5466                 rc = -EINVAL;
5467                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5468                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5469                                                            bypass_timeout);
5470                 }
5471                 if (rc != 0) {
5472                         printf("Failed to set timeout value %u "
5473                         "for port %d, errto code: %d.\n",
5474                         bypass_timeout, port_id, rc);
5475                 }
5476         }
5477
5478         /* Set the bypass event to transition to bypass mode. */
5479         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5480                                               bypass_mode);
5481 #endif
5482
5483         if (rc != 0)
5484                 printf("\t Failed to set bypass event for port = %d.\n",
5485                        port_id);
5486 }
5487
5488 cmdline_parse_token_string_t cmd_setbypass_event_set =
5489         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5490                         set, "set");
5491 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5493                         bypass, "bypass");
5494 cmdline_parse_token_string_t cmd_setbypass_event_event =
5495         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5496                         event, "event");
5497 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5498         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5499                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5500 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5501         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5502                         mode, "mode");
5503 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5504         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5505                         mode_value, "normal#bypass#isolate");
5506 cmdline_parse_token_num_t cmd_setbypass_event_port =
5507         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5508                                 port_id, UINT16);
5509
5510 cmdline_parse_inst_t cmd_set_bypass_event = {
5511         .f = cmd_set_bypass_event_parsed,
5512         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5513                 "power_off mode normal|bypass|isolate <port_id>: "
5514                 "Set the NIC bypass event mode for port_id",
5515         .data = NULL,
5516         .tokens = {
5517                 (void *)&cmd_setbypass_event_set,
5518                 (void *)&cmd_setbypass_event_bypass,
5519                 (void *)&cmd_setbypass_event_event,
5520                 (void *)&cmd_setbypass_event_event_value,
5521                 (void *)&cmd_setbypass_event_mode,
5522                 (void *)&cmd_setbypass_event_mode_value,
5523                 (void *)&cmd_setbypass_event_port,
5524                 NULL,
5525         },
5526 };
5527
5528
5529 /* *** SET NIC BYPASS TIMEOUT *** */
5530 struct cmd_set_bypass_timeout_result {
5531         cmdline_fixed_string_t set;
5532         cmdline_fixed_string_t bypass;
5533         cmdline_fixed_string_t timeout;
5534         cmdline_fixed_string_t value;
5535 };
5536
5537 static void
5538 cmd_set_bypass_timeout_parsed(void *parsed_result,
5539                 __rte_unused struct cmdline *cl,
5540                 __rte_unused void *data)
5541 {
5542         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5543
5544 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5545         if (!strcmp(res->value, "1.5"))
5546                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5547         else if (!strcmp(res->value, "2"))
5548                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5549         else if (!strcmp(res->value, "3"))
5550                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5551         else if (!strcmp(res->value, "4"))
5552                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5553         else if (!strcmp(res->value, "8"))
5554                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5555         else if (!strcmp(res->value, "16"))
5556                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5557         else if (!strcmp(res->value, "32"))
5558                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5559         else
5560                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5561 #endif
5562 }
5563
5564 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5566                         set, "set");
5567 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5569                         bypass, "bypass");
5570 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5572                         timeout, "timeout");
5573 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5574         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5575                         value, "0#1.5#2#3#4#8#16#32");
5576
5577 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5578         .f = cmd_set_bypass_timeout_parsed,
5579         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5580                 "Set the NIC bypass watchdog timeout in seconds",
5581         .data = NULL,
5582         .tokens = {
5583                 (void *)&cmd_setbypass_timeout_set,
5584                 (void *)&cmd_setbypass_timeout_bypass,
5585                 (void *)&cmd_setbypass_timeout_timeout,
5586                 (void *)&cmd_setbypass_timeout_value,
5587                 NULL,
5588         },
5589 };
5590
5591 /* *** SHOW NIC BYPASS MODE *** */
5592 struct cmd_show_bypass_config_result {
5593         cmdline_fixed_string_t show;
5594         cmdline_fixed_string_t bypass;
5595         cmdline_fixed_string_t config;
5596         portid_t port_id;
5597 };
5598
5599 static void
5600 cmd_show_bypass_config_parsed(void *parsed_result,
5601                 __rte_unused struct cmdline *cl,
5602                 __rte_unused void *data)
5603 {
5604         struct cmd_show_bypass_config_result *res = parsed_result;
5605         portid_t port_id = res->port_id;
5606         int rc = -EINVAL;
5607 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5608         uint32_t event_mode;
5609         uint32_t bypass_mode;
5610         uint32_t timeout = bypass_timeout;
5611         unsigned int i;
5612
5613         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5614                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5615         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5616                 {"UNKNOWN", "normal", "bypass", "isolate"};
5617         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5618                 "NONE",
5619                 "OS/board on",
5620                 "power supply on",
5621                 "OS/board off",
5622                 "power supply off",
5623                 "timeout"};
5624
5625         /* Display the bypass mode.*/
5626         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5627                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5628                 return;
5629         }
5630         else {
5631                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5632                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5633
5634                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5635         }
5636
5637         /* Display the bypass timeout.*/
5638         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5639                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5640
5641         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5642
5643         /* Display the bypass events and associated modes. */
5644         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5645
5646                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5647                         printf("\tFailed to get bypass mode for event = %s\n",
5648                                 events[i]);
5649                 } else {
5650                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5651                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5652
5653                         printf("\tbypass event: %-16s = %s\n", events[i],
5654                                 modes[event_mode]);
5655                 }
5656         }
5657 #endif
5658         if (rc != 0)
5659                 printf("\tFailed to get bypass configuration for port = %d\n",
5660                        port_id);
5661 }
5662
5663 cmdline_parse_token_string_t cmd_showbypass_config_show =
5664         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5665                         show, "show");
5666 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5667         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5668                         bypass, "bypass");
5669 cmdline_parse_token_string_t cmd_showbypass_config_config =
5670         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5671                         config, "config");
5672 cmdline_parse_token_num_t cmd_showbypass_config_port =
5673         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5674                                 port_id, UINT16);
5675
5676 cmdline_parse_inst_t cmd_show_bypass_config = {
5677         .f = cmd_show_bypass_config_parsed,
5678         .help_str = "show bypass config <port_id>: "
5679                     "Show the NIC bypass config for port_id",
5680         .data = NULL,
5681         .tokens = {
5682                 (void *)&cmd_showbypass_config_show,
5683                 (void *)&cmd_showbypass_config_bypass,
5684                 (void *)&cmd_showbypass_config_config,
5685                 (void *)&cmd_showbypass_config_port,
5686                 NULL,
5687         },
5688 };
5689
5690 #ifdef RTE_LIBRTE_PMD_BOND
5691 /* *** SET BONDING MODE *** */
5692 struct cmd_set_bonding_mode_result {
5693         cmdline_fixed_string_t set;
5694         cmdline_fixed_string_t bonding;
5695         cmdline_fixed_string_t mode;
5696         uint8_t value;
5697         portid_t port_id;
5698 };
5699
5700 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5701                 __rte_unused  struct cmdline *cl,
5702                 __rte_unused void *data)
5703 {
5704         struct cmd_set_bonding_mode_result *res = parsed_result;
5705         portid_t port_id = res->port_id;
5706
5707         /* Set the bonding mode for the relevant port. */
5708         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5709                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5710 }
5711
5712 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5713 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5714                 set, "set");
5715 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5716 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5717                 bonding, "bonding");
5718 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5719 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5720                 mode, "mode");
5721 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5722 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5723                 value, UINT8);
5724 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5725 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5726                 port_id, UINT16);
5727
5728 cmdline_parse_inst_t cmd_set_bonding_mode = {
5729                 .f = cmd_set_bonding_mode_parsed,
5730                 .help_str = "set bonding mode <mode_value> <port_id>: "
5731                         "Set the bonding mode for port_id",
5732                 .data = NULL,
5733                 .tokens = {
5734                                 (void *) &cmd_setbonding_mode_set,
5735                                 (void *) &cmd_setbonding_mode_bonding,
5736                                 (void *) &cmd_setbonding_mode_mode,
5737                                 (void *) &cmd_setbonding_mode_value,
5738                                 (void *) &cmd_setbonding_mode_port,
5739                                 NULL
5740                 }
5741 };
5742
5743 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5744 struct cmd_set_bonding_lacp_dedicated_queues_result {
5745         cmdline_fixed_string_t set;
5746         cmdline_fixed_string_t bonding;
5747         cmdline_fixed_string_t lacp;
5748         cmdline_fixed_string_t dedicated_queues;
5749         portid_t port_id;
5750         cmdline_fixed_string_t mode;
5751 };
5752
5753 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5754                 __rte_unused  struct cmdline *cl,
5755                 __rte_unused void *data)
5756 {
5757         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5758         portid_t port_id = res->port_id;
5759         struct rte_port *port;
5760
5761         port = &ports[port_id];
5762
5763         /** Check if the port is not started **/
5764         if (port->port_status != RTE_PORT_STOPPED) {
5765                 printf("Please stop port %d first\n", port_id);
5766                 return;
5767         }
5768
5769         if (!strcmp(res->mode, "enable")) {
5770                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5771                         printf("Dedicate queues for LACP control packets"
5772                                         " enabled\n");
5773                 else
5774                         printf("Enabling dedicate queues for LACP control "
5775                                         "packets on port %d failed\n", port_id);
5776         } else if (!strcmp(res->mode, "disable")) {
5777                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5778                         printf("Dedicated queues for LACP control packets "
5779                                         "disabled\n");
5780                 else
5781                         printf("Disabling dedicated queues for LACP control "
5782                                         "traffic on port %d failed\n", port_id);
5783         }
5784 }
5785
5786 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5787 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5788                 set, "set");
5789 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5790 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5791                 bonding, "bonding");
5792 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5793 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5794                 lacp, "lacp");
5795 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5796 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5797                 dedicated_queues, "dedicated_queues");
5798 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5799 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5800                 port_id, UINT16);
5801 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5802 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5803                 mode, "enable#disable");
5804
5805 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5806                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5807                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5808                         "enable|disable: "
5809                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5810                 .data = NULL,
5811                 .tokens = {
5812                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5813                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5814                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5815                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5816                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5817                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5818                         NULL
5819                 }
5820 };
5821
5822 /* *** SET BALANCE XMIT POLICY *** */
5823 struct cmd_set_bonding_balance_xmit_policy_result {
5824         cmdline_fixed_string_t set;
5825         cmdline_fixed_string_t bonding;
5826         cmdline_fixed_string_t balance_xmit_policy;
5827         portid_t port_id;
5828         cmdline_fixed_string_t policy;
5829 };
5830
5831 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5832                 __rte_unused  struct cmdline *cl,
5833                 __rte_unused void *data)
5834 {
5835         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5836         portid_t port_id = res->port_id;
5837         uint8_t policy;
5838
5839         if (!strcmp(res->policy, "l2")) {
5840                 policy = BALANCE_XMIT_POLICY_LAYER2;
5841         } else if (!strcmp(res->policy, "l23")) {
5842                 policy = BALANCE_XMIT_POLICY_LAYER23;
5843         } else if (!strcmp(res->policy, "l34")) {
5844                 policy = BALANCE_XMIT_POLICY_LAYER34;
5845         } else {
5846                 printf("\t Invalid xmit policy selection");
5847                 return;
5848         }
5849
5850         /* Set the bonding mode for the relevant port. */
5851         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5852                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5853                                 port_id);
5854         }
5855 }
5856
5857 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5858 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5859                 set, "set");
5860 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5861 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5862                 bonding, "bonding");
5863 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5864 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5865                 balance_xmit_policy, "balance_xmit_policy");
5866 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5867 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5868                 port_id, UINT16);
5869 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5870 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5871                 policy, "l2#l23#l34");
5872
5873 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5874                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5875                 .help_str = "set bonding balance_xmit_policy <port_id> "
5876                         "l2|l23|l34: "
5877                         "Set the bonding balance_xmit_policy for port_id",
5878                 .data = NULL,
5879                 .tokens = {
5880                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5881                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5882                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5883                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5884                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5885                                 NULL
5886                 }
5887 };
5888
5889 /* *** SHOW NIC BONDING CONFIGURATION *** */
5890 struct cmd_show_bonding_config_result {
5891         cmdline_fixed_string_t show;
5892         cmdline_fixed_string_t bonding;
5893         cmdline_fixed_string_t config;
5894         portid_t port_id;
5895 };
5896
5897 static void cmd_show_bonding_config_parsed(void *parsed_result,
5898                 __rte_unused  struct cmdline *cl,
5899                 __rte_unused void *data)
5900 {
5901         struct cmd_show_bonding_config_result *res = parsed_result;
5902         int bonding_mode, agg_mode;
5903         portid_t slaves[RTE_MAX_ETHPORTS];
5904         int num_slaves, num_active_slaves;
5905         int primary_id;
5906         int i;
5907         portid_t port_id = res->port_id;
5908
5909         /* Display the bonding mode.*/
5910         bonding_mode = rte_eth_bond_mode_get(port_id);
5911         if (bonding_mode < 0) {
5912                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5913                 return;
5914         } else
5915                 printf("\tBonding mode: %d\n", bonding_mode);
5916
5917         if (bonding_mode == BONDING_MODE_BALANCE) {
5918                 int balance_xmit_policy;
5919
5920                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5921                 if (balance_xmit_policy < 0) {
5922                         printf("\tFailed to get balance xmit policy for port = %d\n",
5923                                         port_id);
5924                         return;
5925                 } else {
5926                         printf("\tBalance Xmit Policy: ");
5927
5928                         switch (balance_xmit_policy) {
5929                         case BALANCE_XMIT_POLICY_LAYER2:
5930                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5931                                 break;
5932                         case BALANCE_XMIT_POLICY_LAYER23:
5933                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5934                                 break;
5935                         case BALANCE_XMIT_POLICY_LAYER34:
5936                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5937                                 break;
5938                         }
5939                         printf("\n");
5940                 }
5941         }
5942
5943         if (bonding_mode == BONDING_MODE_8023AD) {
5944                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5945                 printf("\tIEEE802.3AD Aggregator Mode: ");
5946                 switch (agg_mode) {
5947                 case AGG_BANDWIDTH:
5948                         printf("bandwidth");
5949                         break;
5950                 case AGG_STABLE:
5951                         printf("stable");
5952                         break;
5953                 case AGG_COUNT:
5954                         printf("count");
5955                         break;
5956                 }
5957                 printf("\n");
5958         }
5959
5960         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5961
5962         if (num_slaves < 0) {
5963                 printf("\tFailed to get slave list for port = %d\n", port_id);
5964                 return;
5965         }
5966         if (num_slaves > 0) {
5967                 printf("\tSlaves (%d): [", num_slaves);
5968                 for (i = 0; i < num_slaves - 1; i++)
5969                         printf("%d ", slaves[i]);
5970
5971                 printf("%d]\n", slaves[num_slaves - 1]);
5972         } else {
5973                 printf("\tSlaves: []\n");
5974
5975         }
5976
5977         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5978                         RTE_MAX_ETHPORTS);
5979
5980         if (num_active_slaves < 0) {
5981                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5982                 return;
5983         }
5984         if (num_active_slaves > 0) {
5985                 printf("\tActive Slaves (%d): [", num_active_slaves);
5986                 for (i = 0; i < num_active_slaves - 1; i++)
5987                         printf("%d ", slaves[i]);
5988
5989                 printf("%d]\n", slaves[num_active_slaves - 1]);
5990
5991         } else {
5992                 printf("\tActive Slaves: []\n");
5993
5994         }
5995
5996         primary_id = rte_eth_bond_primary_get(port_id);
5997         if (primary_id < 0) {
5998                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5999                 return;
6000         } else
6001                 printf("\tPrimary: [%d]\n", primary_id);
6002
6003 }
6004
6005 cmdline_parse_token_string_t cmd_showbonding_config_show =
6006 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6007                 show, "show");
6008 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6009 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6010                 bonding, "bonding");
6011 cmdline_parse_token_string_t cmd_showbonding_config_config =
6012 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6013                 config, "config");
6014 cmdline_parse_token_num_t cmd_showbonding_config_port =
6015 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6016                 port_id, UINT16);
6017
6018 cmdline_parse_inst_t cmd_show_bonding_config = {
6019                 .f = cmd_show_bonding_config_parsed,
6020                 .help_str = "show bonding config <port_id>: "
6021                         "Show the bonding config for port_id",
6022                 .data = NULL,
6023                 .tokens = {
6024                                 (void *)&cmd_showbonding_config_show,
6025                                 (void *)&cmd_showbonding_config_bonding,
6026                                 (void *)&cmd_showbonding_config_config,
6027                                 (void *)&cmd_showbonding_config_port,
6028                                 NULL
6029                 }
6030 };
6031
6032 /* *** SET BONDING PRIMARY *** */
6033 struct cmd_set_bonding_primary_result {
6034         cmdline_fixed_string_t set;
6035         cmdline_fixed_string_t bonding;
6036         cmdline_fixed_string_t primary;
6037         portid_t slave_id;
6038         portid_t port_id;
6039 };
6040
6041 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6042                 __rte_unused  struct cmdline *cl,
6043                 __rte_unused void *data)
6044 {
6045         struct cmd_set_bonding_primary_result *res = parsed_result;
6046         portid_t master_port_id = res->port_id;
6047         portid_t slave_port_id = res->slave_id;
6048
6049         /* Set the primary slave for a bonded device. */
6050         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6051                 printf("\t Failed to set primary slave for port = %d.\n",
6052                                 master_port_id);
6053                 return;
6054         }
6055         init_port_config();
6056 }
6057
6058 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6059 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6060                 set, "set");
6061 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6062 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6063                 bonding, "bonding");
6064 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6065 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6066                 primary, "primary");
6067 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6068 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6069                 slave_id, UINT16);
6070 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6071 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6072                 port_id, UINT16);
6073
6074 cmdline_parse_inst_t cmd_set_bonding_primary = {
6075                 .f = cmd_set_bonding_primary_parsed,
6076                 .help_str = "set bonding primary <slave_id> <port_id>: "
6077                         "Set the primary slave for port_id",
6078                 .data = NULL,
6079                 .tokens = {
6080                                 (void *)&cmd_setbonding_primary_set,
6081                                 (void *)&cmd_setbonding_primary_bonding,
6082                                 (void *)&cmd_setbonding_primary_primary,
6083                                 (void *)&cmd_setbonding_primary_slave,
6084                                 (void *)&cmd_setbonding_primary_port,
6085                                 NULL
6086                 }
6087 };
6088
6089 /* *** ADD SLAVE *** */
6090 struct cmd_add_bonding_slave_result {
6091         cmdline_fixed_string_t add;
6092         cmdline_fixed_string_t bonding;
6093         cmdline_fixed_string_t slave;
6094         portid_t slave_id;
6095         portid_t port_id;
6096 };
6097
6098 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6099                 __rte_unused  struct cmdline *cl,
6100                 __rte_unused void *data)
6101 {
6102         struct cmd_add_bonding_slave_result *res = parsed_result;
6103         portid_t master_port_id = res->port_id;
6104         portid_t slave_port_id = res->slave_id;
6105
6106         /* add the slave for a bonded device. */
6107         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6108                 printf("\t Failed to add slave %d to master port = %d.\n",
6109                                 slave_port_id, master_port_id);
6110                 return;
6111         }
6112         init_port_config();
6113         set_port_slave_flag(slave_port_id);
6114 }
6115
6116 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6117 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6118                 add, "add");
6119 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6120 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6121                 bonding, "bonding");
6122 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6123 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6124                 slave, "slave");
6125 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6126 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6127                 slave_id, UINT16);
6128 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6129 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6130                 port_id, UINT16);
6131
6132 cmdline_parse_inst_t cmd_add_bonding_slave = {
6133                 .f = cmd_add_bonding_slave_parsed,
6134                 .help_str = "add bonding slave <slave_id> <port_id>: "
6135                         "Add a slave device to a bonded device",
6136                 .data = NULL,
6137                 .tokens = {
6138                                 (void *)&cmd_addbonding_slave_add,
6139                                 (void *)&cmd_addbonding_slave_bonding,
6140                                 (void *)&cmd_addbonding_slave_slave,
6141                                 (void *)&cmd_addbonding_slave_slaveid,
6142                                 (void *)&cmd_addbonding_slave_port,
6143                                 NULL
6144                 }
6145 };
6146
6147 /* *** REMOVE SLAVE *** */
6148 struct cmd_remove_bonding_slave_result {
6149         cmdline_fixed_string_t remove;
6150         cmdline_fixed_string_t bonding;
6151         cmdline_fixed_string_t slave;
6152         portid_t slave_id;
6153         portid_t port_id;
6154 };
6155
6156 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6157                 __rte_unused  struct cmdline *cl,
6158                 __rte_unused void *data)
6159 {
6160         struct cmd_remove_bonding_slave_result *res = parsed_result;
6161         portid_t master_port_id = res->port_id;
6162         portid_t slave_port_id = res->slave_id;
6163
6164         /* remove the slave from a bonded device. */
6165         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6166                 printf("\t Failed to remove slave %d from master port = %d.\n",
6167                                 slave_port_id, master_port_id);
6168                 return;
6169         }
6170         init_port_config();
6171         clear_port_slave_flag(slave_port_id);
6172 }
6173
6174 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6175                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6176                                 remove, "remove");
6177 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6178                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6179                                 bonding, "bonding");
6180 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6181                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6182                                 slave, "slave");
6183 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6184                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6185                                 slave_id, UINT16);
6186 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6187                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6188                                 port_id, UINT16);
6189
6190 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6191                 .f = cmd_remove_bonding_slave_parsed,
6192                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6193                         "Remove a slave device from a bonded device",
6194                 .data = NULL,
6195                 .tokens = {
6196                                 (void *)&cmd_removebonding_slave_remove,
6197                                 (void *)&cmd_removebonding_slave_bonding,
6198                                 (void *)&cmd_removebonding_slave_slave,
6199                                 (void *)&cmd_removebonding_slave_slaveid,
6200                                 (void *)&cmd_removebonding_slave_port,
6201                                 NULL
6202                 }
6203 };
6204
6205 /* *** CREATE BONDED DEVICE *** */
6206 struct cmd_create_bonded_device_result {
6207         cmdline_fixed_string_t create;
6208         cmdline_fixed_string_t bonded;
6209         cmdline_fixed_string_t device;
6210         uint8_t mode;
6211         uint8_t socket;
6212 };
6213
6214 static int bond_dev_num = 0;
6215
6216 static void cmd_create_bonded_device_parsed(void *parsed_result,
6217                 __rte_unused  struct cmdline *cl,
6218                 __rte_unused void *data)
6219 {
6220         struct cmd_create_bonded_device_result *res = parsed_result;
6221         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6222         int port_id;
6223         int ret;
6224
6225         if (test_done == 0) {
6226                 printf("Please stop forwarding first\n");
6227                 return;
6228         }
6229
6230         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6231                         bond_dev_num++);
6232
6233         /* Create a new bonded device. */
6234         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6235         if (port_id < 0) {
6236                 printf("\t Failed to create bonded device.\n");
6237                 return;
6238         } else {
6239                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6240                                 port_id);
6241
6242                 /* Update number of ports */
6243                 nb_ports = rte_eth_dev_count_avail();
6244                 reconfig(port_id, res->socket);
6245                 ret = rte_eth_promiscuous_enable(port_id);
6246                 if (ret != 0)
6247                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6248                                 port_id, rte_strerror(-ret));
6249
6250                 ports[port_id].need_setup = 0;
6251                 ports[port_id].port_status = RTE_PORT_STOPPED;
6252         }
6253
6254 }
6255
6256 cmdline_parse_token_string_t cmd_createbonded_device_create =
6257                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6258                                 create, "create");
6259 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6260                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6261                                 bonded, "bonded");
6262 cmdline_parse_token_string_t cmd_createbonded_device_device =
6263                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6264                                 device, "device");
6265 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6266                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6267                                 mode, UINT8);
6268 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6269                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6270                                 socket, UINT8);
6271
6272 cmdline_parse_inst_t cmd_create_bonded_device = {
6273                 .f = cmd_create_bonded_device_parsed,
6274                 .help_str = "create bonded device <mode> <socket>: "
6275                         "Create a new bonded device with specific bonding mode and socket",
6276                 .data = NULL,
6277                 .tokens = {
6278                                 (void *)&cmd_createbonded_device_create,
6279                                 (void *)&cmd_createbonded_device_bonded,
6280                                 (void *)&cmd_createbonded_device_device,
6281                                 (void *)&cmd_createbonded_device_mode,
6282                                 (void *)&cmd_createbonded_device_socket,
6283                                 NULL
6284                 }
6285 };
6286
6287 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6288 struct cmd_set_bond_mac_addr_result {
6289         cmdline_fixed_string_t set;
6290         cmdline_fixed_string_t bonding;
6291         cmdline_fixed_string_t mac_addr;
6292         uint16_t port_num;
6293         struct rte_ether_addr address;
6294 };
6295
6296 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6297                 __rte_unused  struct cmdline *cl,
6298                 __rte_unused void *data)
6299 {
6300         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6301         int ret;
6302
6303         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6304                 return;
6305
6306         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6307
6308         /* check the return value and print it if is < 0 */
6309         if (ret < 0)
6310                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6311 }
6312
6313 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6314                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6315 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6316                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6317                                 "bonding");
6318 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6319                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6320                                 "mac_addr");
6321 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6322                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6323                                 port_num, UINT16);
6324 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6325                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6326
6327 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6328                 .f = cmd_set_bond_mac_addr_parsed,
6329                 .data = (void *) 0,
6330                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6331                 .tokens = {
6332                                 (void *)&cmd_set_bond_mac_addr_set,
6333                                 (void *)&cmd_set_bond_mac_addr_bonding,
6334                                 (void *)&cmd_set_bond_mac_addr_mac,
6335                                 (void *)&cmd_set_bond_mac_addr_portnum,
6336                                 (void *)&cmd_set_bond_mac_addr_addr,
6337                                 NULL
6338                 }
6339 };
6340
6341
6342 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6343 struct cmd_set_bond_mon_period_result {
6344         cmdline_fixed_string_t set;
6345         cmdline_fixed_string_t bonding;
6346         cmdline_fixed_string_t mon_period;
6347         uint16_t port_num;
6348         uint32_t period_ms;
6349 };
6350
6351 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6352                 __rte_unused  struct cmdline *cl,
6353                 __rte_unused void *data)
6354 {
6355         struct cmd_set_bond_mon_period_result *res = parsed_result;
6356         int ret;
6357
6358         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6359
6360         /* check the return value and print it if is < 0 */
6361         if (ret < 0)
6362                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6363 }
6364
6365 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6366                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6367                                 set, "set");
6368 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6369                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6370                                 bonding, "bonding");
6371 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6372                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6373                                 mon_period,     "mon_period");
6374 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6375                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6376                                 port_num, UINT16);
6377 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6378                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6379                                 period_ms, UINT32);
6380
6381 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6382                 .f = cmd_set_bond_mon_period_parsed,
6383                 .data = (void *) 0,
6384                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6385                 .tokens = {
6386                                 (void *)&cmd_set_bond_mon_period_set,
6387                                 (void *)&cmd_set_bond_mon_period_bonding,
6388                                 (void *)&cmd_set_bond_mon_period_mon_period,
6389                                 (void *)&cmd_set_bond_mon_period_portnum,
6390                                 (void *)&cmd_set_bond_mon_period_period_ms,
6391                                 NULL
6392                 }
6393 };
6394
6395
6396
6397 struct cmd_set_bonding_agg_mode_policy_result {
6398         cmdline_fixed_string_t set;
6399         cmdline_fixed_string_t bonding;
6400         cmdline_fixed_string_t agg_mode;
6401         uint16_t port_num;
6402         cmdline_fixed_string_t policy;
6403 };
6404
6405
6406 static void
6407 cmd_set_bonding_agg_mode(void *parsed_result,
6408                 __rte_unused struct cmdline *cl,
6409                 __rte_unused void *data)
6410 {
6411         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6412         uint8_t policy = AGG_BANDWIDTH;
6413
6414         if (!strcmp(res->policy, "bandwidth"))
6415                 policy = AGG_BANDWIDTH;
6416         else if (!strcmp(res->policy, "stable"))
6417                 policy = AGG_STABLE;
6418         else if (!strcmp(res->policy, "count"))
6419                 policy = AGG_COUNT;
6420
6421         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6422 }
6423
6424
6425 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6426         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6427                                 set, "set");
6428 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6429         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6430                                 bonding, "bonding");
6431
6432 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6433         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6434                                 agg_mode, "agg_mode");
6435
6436 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6437         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6438                                 port_num, UINT16);
6439
6440 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6441         TOKEN_STRING_INITIALIZER(
6442                         struct cmd_set_bonding_balance_xmit_policy_result,
6443                 policy, "stable#bandwidth#count");
6444
6445 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6446         .f = cmd_set_bonding_agg_mode,
6447         .data = (void *) 0,
6448         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6449         .tokens = {
6450                         (void *)&cmd_set_bonding_agg_mode_set,
6451                         (void *)&cmd_set_bonding_agg_mode_bonding,
6452                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6453                         (void *)&cmd_set_bonding_agg_mode_portnum,
6454                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6455                         NULL
6456                 }
6457 };
6458
6459
6460 #endif /* RTE_LIBRTE_PMD_BOND */
6461
6462 /* *** SET FORWARDING MODE *** */
6463 struct cmd_set_fwd_mode_result {
6464         cmdline_fixed_string_t set;
6465         cmdline_fixed_string_t fwd;
6466         cmdline_fixed_string_t mode;
6467 };
6468
6469 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6470                                     __rte_unused struct cmdline *cl,
6471                                     __rte_unused void *data)
6472 {
6473         struct cmd_set_fwd_mode_result *res = parsed_result;
6474
6475         retry_enabled = 0;
6476         set_pkt_forwarding_mode(res->mode);
6477 }
6478
6479 cmdline_parse_token_string_t cmd_setfwd_set =
6480         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6481 cmdline_parse_token_string_t cmd_setfwd_fwd =
6482         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6483 cmdline_parse_token_string_t cmd_setfwd_mode =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6485                 "" /* defined at init */);
6486
6487 cmdline_parse_inst_t cmd_set_fwd_mode = {
6488         .f = cmd_set_fwd_mode_parsed,
6489         .data = NULL,
6490         .help_str = NULL, /* defined at init */
6491         .tokens = {
6492                 (void *)&cmd_setfwd_set,
6493                 (void *)&cmd_setfwd_fwd,
6494                 (void *)&cmd_setfwd_mode,
6495                 NULL,
6496         },
6497 };
6498
6499 static void cmd_set_fwd_mode_init(void)
6500 {
6501         char *modes, *c;
6502         static char token[128];
6503         static char help[256];
6504         cmdline_parse_token_string_t *token_struct;
6505
6506         modes = list_pkt_forwarding_modes();
6507         snprintf(help, sizeof(help), "set fwd %s: "
6508                 "Set packet forwarding mode", modes);
6509         cmd_set_fwd_mode.help_str = help;
6510
6511         /* string token separator is # */
6512         for (c = token; *modes != '\0'; modes++)
6513                 if (*modes == '|')
6514                         *c++ = '#';
6515                 else
6516                         *c++ = *modes;
6517         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6518         token_struct->string_data.str = token;
6519 }
6520
6521 /* *** SET RETRY FORWARDING MODE *** */
6522 struct cmd_set_fwd_retry_mode_result {
6523         cmdline_fixed_string_t set;
6524         cmdline_fixed_string_t fwd;
6525         cmdline_fixed_string_t mode;
6526         cmdline_fixed_string_t retry;
6527 };
6528
6529 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6530                             __rte_unused struct cmdline *cl,
6531                             __rte_unused void *data)
6532 {
6533         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6534
6535         retry_enabled = 1;
6536         set_pkt_forwarding_mode(res->mode);
6537 }
6538
6539 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6540         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6541                         set, "set");
6542 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6543         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6544                         fwd, "fwd");
6545 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6546         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6547                         mode,
6548                 "" /* defined at init */);
6549 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6550         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6551                         retry, "retry");
6552
6553 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6554         .f = cmd_set_fwd_retry_mode_parsed,
6555         .data = NULL,
6556         .help_str = NULL, /* defined at init */
6557         .tokens = {
6558                 (void *)&cmd_setfwd_retry_set,
6559                 (void *)&cmd_setfwd_retry_fwd,
6560                 (void *)&cmd_setfwd_retry_mode,
6561                 (void *)&cmd_setfwd_retry_retry,
6562                 NULL,
6563         },
6564 };
6565
6566 static void cmd_set_fwd_retry_mode_init(void)
6567 {
6568         char *modes, *c;
6569         static char token[128];
6570         static char help[256];
6571         cmdline_parse_token_string_t *token_struct;
6572
6573         modes = list_pkt_forwarding_retry_modes();
6574         snprintf(help, sizeof(help), "set fwd %s retry: "
6575                 "Set packet forwarding mode with retry", modes);
6576         cmd_set_fwd_retry_mode.help_str = help;
6577
6578         /* string token separator is # */
6579         for (c = token; *modes != '\0'; modes++)
6580                 if (*modes == '|')
6581                         *c++ = '#';
6582                 else
6583                         *c++ = *modes;
6584         token_struct = (cmdline_parse_token_string_t *)
6585                 cmd_set_fwd_retry_mode.tokens[2];
6586         token_struct->string_data.str = token;
6587 }
6588
6589 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6590 struct cmd_set_burst_tx_retry_result {
6591         cmdline_fixed_string_t set;
6592         cmdline_fixed_string_t burst;
6593         cmdline_fixed_string_t tx;
6594         cmdline_fixed_string_t delay;
6595         uint32_t time;
6596         cmdline_fixed_string_t retry;
6597         uint32_t retry_num;
6598 };
6599
6600 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6601                                         __rte_unused struct cmdline *cl,
6602                                         __rte_unused void *data)
6603 {
6604         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6605
6606         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6607                 && !strcmp(res->tx, "tx")) {
6608                 if (!strcmp(res->delay, "delay"))
6609                         burst_tx_delay_time = res->time;
6610                 if (!strcmp(res->retry, "retry"))
6611                         burst_tx_retry_num = res->retry_num;
6612         }
6613
6614 }
6615
6616 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6617         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6618 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6619         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6620                                  "burst");
6621 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6622         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6623 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6624         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6625 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6626         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6627 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6628         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6629 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6630         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6631
6632 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6633         .f = cmd_set_burst_tx_retry_parsed,
6634         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6635         .tokens = {
6636                 (void *)&cmd_set_burst_tx_retry_set,
6637                 (void *)&cmd_set_burst_tx_retry_burst,
6638                 (void *)&cmd_set_burst_tx_retry_tx,
6639                 (void *)&cmd_set_burst_tx_retry_delay,
6640                 (void *)&cmd_set_burst_tx_retry_time,
6641                 (void *)&cmd_set_burst_tx_retry_retry,
6642                 (void *)&cmd_set_burst_tx_retry_retry_num,
6643                 NULL,
6644         },
6645 };
6646
6647 /* *** SET PROMISC MODE *** */
6648 struct cmd_set_promisc_mode_result {
6649         cmdline_fixed_string_t set;
6650         cmdline_fixed_string_t promisc;
6651         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6652         uint16_t port_num;               /* valid if "allports" argument == 0 */
6653         cmdline_fixed_string_t mode;
6654 };
6655
6656 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6657                                         __rte_unused struct cmdline *cl,
6658                                         void *allports)
6659 {
6660         struct cmd_set_promisc_mode_result *res = parsed_result;
6661         int enable;
6662         portid_t i;
6663
6664         if (!strcmp(res->mode, "on"))
6665                 enable = 1;
6666         else
6667                 enable = 0;
6668
6669         /* all ports */
6670         if (allports) {
6671                 RTE_ETH_FOREACH_DEV(i)
6672                         eth_set_promisc_mode(i, enable);
6673         } else {
6674                 eth_set_promisc_mode(res->port_num, enable);
6675         }
6676 }
6677
6678 cmdline_parse_token_string_t cmd_setpromisc_set =
6679         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6680 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6682                                  "promisc");
6683 cmdline_parse_token_string_t cmd_setpromisc_portall =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6685                                  "all");
6686 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6687         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6688                               UINT16);
6689 cmdline_parse_token_string_t cmd_setpromisc_mode =
6690         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6691                                  "on#off");
6692
6693 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6694         .f = cmd_set_promisc_mode_parsed,
6695         .data = (void *)1,
6696         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6697         .tokens = {
6698                 (void *)&cmd_setpromisc_set,
6699                 (void *)&cmd_setpromisc_promisc,
6700                 (void *)&cmd_setpromisc_portall,
6701                 (void *)&cmd_setpromisc_mode,
6702                 NULL,
6703         },
6704 };
6705
6706 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6707         .f = cmd_set_promisc_mode_parsed,
6708         .data = (void *)0,
6709         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6710         .tokens = {
6711                 (void *)&cmd_setpromisc_set,
6712                 (void *)&cmd_setpromisc_promisc,
6713                 (void *)&cmd_setpromisc_portnum,
6714                 (void *)&cmd_setpromisc_mode,
6715                 NULL,
6716         },
6717 };
6718
6719 /* *** SET ALLMULTI MODE *** */
6720 struct cmd_set_allmulti_mode_result {
6721         cmdline_fixed_string_t set;
6722         cmdline_fixed_string_t allmulti;
6723         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6724         uint16_t port_num;               /* valid if "allports" argument == 0 */
6725         cmdline_fixed_string_t mode;
6726 };
6727
6728 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6729                                         __rte_unused struct cmdline *cl,
6730                                         void *allports)
6731 {
6732         struct cmd_set_allmulti_mode_result *res = parsed_result;
6733         int enable;
6734         portid_t i;
6735
6736         if (!strcmp(res->mode, "on"))
6737                 enable = 1;
6738         else
6739                 enable = 0;
6740
6741         /* all ports */
6742         if (allports) {
6743                 RTE_ETH_FOREACH_DEV(i) {
6744                         eth_set_allmulticast_mode(i, enable);
6745                 }
6746         }
6747         else {
6748                 eth_set_allmulticast_mode(res->port_num, enable);
6749         }
6750 }
6751
6752 cmdline_parse_token_string_t cmd_setallmulti_set =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6754 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6755         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6756                                  "allmulti");
6757 cmdline_parse_token_string_t cmd_setallmulti_portall =
6758         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6759                                  "all");
6760 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6761         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6762                               UINT16);
6763 cmdline_parse_token_string_t cmd_setallmulti_mode =
6764         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6765                                  "on#off");
6766
6767 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6768         .f = cmd_set_allmulti_mode_parsed,
6769         .data = (void *)1,
6770         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6771         .tokens = {
6772                 (void *)&cmd_setallmulti_set,
6773                 (void *)&cmd_setallmulti_allmulti,
6774                 (void *)&cmd_setallmulti_portall,
6775                 (void *)&cmd_setallmulti_mode,
6776                 NULL,
6777         },
6778 };
6779
6780 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6781         .f = cmd_set_allmulti_mode_parsed,
6782         .data = (void *)0,
6783         .help_str = "set allmulti <port_id> on|off: "
6784                 "Set allmulti mode on port_id",
6785         .tokens = {
6786                 (void *)&cmd_setallmulti_set,
6787                 (void *)&cmd_setallmulti_allmulti,
6788                 (void *)&cmd_setallmulti_portnum,
6789                 (void *)&cmd_setallmulti_mode,
6790                 NULL,
6791         },
6792 };
6793
6794 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6795 struct cmd_link_flow_ctrl_set_result {
6796         cmdline_fixed_string_t set;
6797         cmdline_fixed_string_t flow_ctrl;
6798         cmdline_fixed_string_t rx;
6799         cmdline_fixed_string_t rx_lfc_mode;
6800         cmdline_fixed_string_t tx;
6801         cmdline_fixed_string_t tx_lfc_mode;
6802         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6803         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6804         cmdline_fixed_string_t autoneg_str;
6805         cmdline_fixed_string_t autoneg;
6806         cmdline_fixed_string_t hw_str;
6807         uint32_t high_water;
6808         cmdline_fixed_string_t lw_str;
6809         uint32_t low_water;
6810         cmdline_fixed_string_t pt_str;
6811         uint16_t pause_time;
6812         cmdline_fixed_string_t xon_str;
6813         uint16_t send_xon;
6814         portid_t port_id;
6815 };
6816
6817 cmdline_parse_token_string_t cmd_lfc_set_set =
6818         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6819                                 set, "set");
6820 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6821         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6822                                 flow_ctrl, "flow_ctrl");
6823 cmdline_parse_token_string_t cmd_lfc_set_rx =
6824         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6825                                 rx, "rx");
6826 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6827         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6828                                 rx_lfc_mode, "on#off");
6829 cmdline_parse_token_string_t cmd_lfc_set_tx =
6830         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6831                                 tx, "tx");
6832 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6833         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6834                                 tx_lfc_mode, "on#off");
6835 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6836         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6837                                 hw_str, "high_water");
6838 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6839         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6840                                 high_water, UINT32);
6841 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6842         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6843                                 lw_str, "low_water");
6844 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6845         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6846                                 low_water, UINT32);
6847 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6848         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6849                                 pt_str, "pause_time");
6850 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6851         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6852                                 pause_time, UINT16);
6853 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6854         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6855                                 xon_str, "send_xon");
6856 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6857         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6858                                 send_xon, UINT16);
6859 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6860         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6861                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6862 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6863         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6864                                 mac_ctrl_frame_fwd_mode, "on#off");
6865 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6866         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6867                                 autoneg_str, "autoneg");
6868 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6869         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6870                                 autoneg, "on#off");
6871 cmdline_parse_token_num_t cmd_lfc_set_portid =
6872         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 port_id, UINT16);
6874
6875 /* forward declaration */
6876 static void
6877 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6878                               void *data);
6879
6880 cmdline_parse_inst_t cmd_link_flow_control_set = {
6881         .f = cmd_link_flow_ctrl_set_parsed,
6882         .data = NULL,
6883         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6884                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6885                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6886         .tokens = {
6887                 (void *)&cmd_lfc_set_set,
6888                 (void *)&cmd_lfc_set_flow_ctrl,
6889                 (void *)&cmd_lfc_set_rx,
6890                 (void *)&cmd_lfc_set_rx_mode,
6891                 (void *)&cmd_lfc_set_tx,
6892                 (void *)&cmd_lfc_set_tx_mode,
6893                 (void *)&cmd_lfc_set_high_water,
6894                 (void *)&cmd_lfc_set_low_water,
6895                 (void *)&cmd_lfc_set_pause_time,
6896                 (void *)&cmd_lfc_set_send_xon,
6897                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6898                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6899                 (void *)&cmd_lfc_set_autoneg_str,
6900                 (void *)&cmd_lfc_set_autoneg,
6901                 (void *)&cmd_lfc_set_portid,
6902                 NULL,
6903         },
6904 };
6905
6906 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6907         .f = cmd_link_flow_ctrl_set_parsed,
6908         .data = (void *)&cmd_link_flow_control_set_rx,
6909         .help_str = "set flow_ctrl rx on|off <port_id>: "
6910                 "Change rx flow control parameter",
6911         .tokens = {
6912                 (void *)&cmd_lfc_set_set,
6913                 (void *)&cmd_lfc_set_flow_ctrl,
6914                 (void *)&cmd_lfc_set_rx,
6915                 (void *)&cmd_lfc_set_rx_mode,
6916                 (void *)&cmd_lfc_set_portid,
6917                 NULL,
6918         },
6919 };
6920
6921 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6922         .f = cmd_link_flow_ctrl_set_parsed,
6923         .data = (void *)&cmd_link_flow_control_set_tx,
6924         .help_str = "set flow_ctrl tx on|off <port_id>: "
6925                 "Change tx flow control parameter",
6926         .tokens = {
6927                 (void *)&cmd_lfc_set_set,
6928                 (void *)&cmd_lfc_set_flow_ctrl,
6929                 (void *)&cmd_lfc_set_tx,
6930                 (void *)&cmd_lfc_set_tx_mode,
6931                 (void *)&cmd_lfc_set_portid,
6932                 NULL,
6933         },
6934 };
6935
6936 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6937         .f = cmd_link_flow_ctrl_set_parsed,
6938         .data = (void *)&cmd_link_flow_control_set_hw,
6939         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6940                 "Change high water flow control parameter",
6941         .tokens = {
6942                 (void *)&cmd_lfc_set_set,
6943                 (void *)&cmd_lfc_set_flow_ctrl,
6944                 (void *)&cmd_lfc_set_high_water_str,
6945                 (void *)&cmd_lfc_set_high_water,
6946                 (void *)&cmd_lfc_set_portid,
6947                 NULL,
6948         },
6949 };
6950
6951 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6952         .f = cmd_link_flow_ctrl_set_parsed,
6953         .data = (void *)&cmd_link_flow_control_set_lw,
6954         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6955                 "Change low water flow control parameter",
6956         .tokens = {
6957                 (void *)&cmd_lfc_set_set,
6958                 (void *)&cmd_lfc_set_flow_ctrl,
6959                 (void *)&cmd_lfc_set_low_water_str,
6960                 (void *)&cmd_lfc_set_low_water,
6961                 (void *)&cmd_lfc_set_portid,
6962                 NULL,
6963         },
6964 };
6965
6966 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6967         .f = cmd_link_flow_ctrl_set_parsed,
6968         .data = (void *)&cmd_link_flow_control_set_pt,
6969         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6970                 "Change pause time flow control parameter",
6971         .tokens = {
6972                 (void *)&cmd_lfc_set_set,
6973                 (void *)&cmd_lfc_set_flow_ctrl,
6974                 (void *)&cmd_lfc_set_pause_time_str,
6975                 (void *)&cmd_lfc_set_pause_time,
6976                 (void *)&cmd_lfc_set_portid,
6977                 NULL,
6978         },
6979 };
6980
6981 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6982         .f = cmd_link_flow_ctrl_set_parsed,
6983         .data = (void *)&cmd_link_flow_control_set_xon,
6984         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6985                 "Change send_xon flow control parameter",
6986         .tokens = {
6987                 (void *)&cmd_lfc_set_set,
6988                 (void *)&cmd_lfc_set_flow_ctrl,
6989                 (void *)&cmd_lfc_set_send_xon_str,
6990                 (void *)&cmd_lfc_set_send_xon,
6991                 (void *)&cmd_lfc_set_portid,
6992                 NULL,
6993         },
6994 };
6995
6996 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6997         .f = cmd_link_flow_ctrl_set_parsed,
6998         .data = (void *)&cmd_link_flow_control_set_macfwd,
6999         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7000                 "Change mac ctrl fwd flow control parameter",
7001         .tokens = {
7002                 (void *)&cmd_lfc_set_set,
7003                 (void *)&cmd_lfc_set_flow_ctrl,
7004                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7005                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7006                 (void *)&cmd_lfc_set_portid,
7007                 NULL,
7008         },
7009 };
7010
7011 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7012         .f = cmd_link_flow_ctrl_set_parsed,
7013         .data = (void *)&cmd_link_flow_control_set_autoneg,
7014         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7015                 "Change autoneg flow control parameter",
7016         .tokens = {
7017                 (void *)&cmd_lfc_set_set,
7018                 (void *)&cmd_lfc_set_flow_ctrl,
7019                 (void *)&cmd_lfc_set_autoneg_str,
7020                 (void *)&cmd_lfc_set_autoneg,
7021                 (void *)&cmd_lfc_set_portid,
7022                 NULL,
7023         },
7024 };
7025
7026 static void
7027 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7028                               __rte_unused struct cmdline *cl,
7029                               void *data)
7030 {
7031         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7032         cmdline_parse_inst_t *cmd = data;
7033         struct rte_eth_fc_conf fc_conf;
7034         int rx_fc_en = 0;
7035         int tx_fc_en = 0;
7036         int ret;
7037
7038         /*
7039          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7040          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7041          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7042          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7043          */
7044         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7045                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7046         };
7047
7048         /* Partial command line, retrieve current configuration */
7049         if (cmd) {
7050                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7051                 if (ret != 0) {
7052                         printf("cannot get current flow ctrl parameters, return"
7053                                "code = %d\n", ret);
7054                         return;
7055                 }
7056
7057                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7058                     (fc_conf.mode == RTE_FC_FULL))
7059                         rx_fc_en = 1;
7060                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7061                     (fc_conf.mode == RTE_FC_FULL))
7062                         tx_fc_en = 1;
7063         }
7064
7065         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7066                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7067
7068         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7069                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7070
7071         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7072
7073         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7074                 fc_conf.high_water = res->high_water;
7075
7076         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7077                 fc_conf.low_water = res->low_water;
7078
7079         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7080                 fc_conf.pause_time = res->pause_time;
7081
7082         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7083                 fc_conf.send_xon = res->send_xon;
7084
7085         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7086                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7087                         fc_conf.mac_ctrl_frame_fwd = 1;
7088                 else
7089                         fc_conf.mac_ctrl_frame_fwd = 0;
7090         }
7091
7092         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7093                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7094
7095         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7096         if (ret != 0)
7097                 printf("bad flow contrl parameter, return code = %d \n", ret);
7098 }
7099
7100 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7101 struct cmd_priority_flow_ctrl_set_result {
7102         cmdline_fixed_string_t set;
7103         cmdline_fixed_string_t pfc_ctrl;
7104         cmdline_fixed_string_t rx;
7105         cmdline_fixed_string_t rx_pfc_mode;
7106         cmdline_fixed_string_t tx;
7107         cmdline_fixed_string_t tx_pfc_mode;
7108         uint32_t high_water;
7109         uint32_t low_water;
7110         uint16_t pause_time;
7111         uint8_t  priority;
7112         portid_t port_id;
7113 };
7114
7115 static void
7116 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7117                        __rte_unused struct cmdline *cl,
7118                        __rte_unused void *data)
7119 {
7120         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7121         struct rte_eth_pfc_conf pfc_conf;
7122         int rx_fc_enable, tx_fc_enable;
7123         int ret;
7124
7125         /*
7126          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7127          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7128          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7129          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7130          */
7131         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7132                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7133         };
7134
7135         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7136         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7137         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7138         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7139         pfc_conf.fc.high_water = res->high_water;
7140         pfc_conf.fc.low_water  = res->low_water;
7141         pfc_conf.fc.pause_time = res->pause_time;
7142         pfc_conf.priority      = res->priority;
7143
7144         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7145         if (ret != 0)
7146                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7147 }
7148
7149 cmdline_parse_token_string_t cmd_pfc_set_set =
7150         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7151                                 set, "set");
7152 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7153         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7154                                 pfc_ctrl, "pfc_ctrl");
7155 cmdline_parse_token_string_t cmd_pfc_set_rx =
7156         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7157                                 rx, "rx");
7158 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7159         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7160                                 rx_pfc_mode, "on#off");
7161 cmdline_parse_token_string_t cmd_pfc_set_tx =
7162         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7163                                 tx, "tx");
7164 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7165         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7166                                 tx_pfc_mode, "on#off");
7167 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7168         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7169                                 high_water, UINT32);
7170 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7171         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7172                                 low_water, UINT32);
7173 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7174         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7175                                 pause_time, UINT16);
7176 cmdline_parse_token_num_t cmd_pfc_set_priority =
7177         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7178                                 priority, UINT8);
7179 cmdline_parse_token_num_t cmd_pfc_set_portid =
7180         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7181                                 port_id, UINT16);
7182
7183 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7184         .f = cmd_priority_flow_ctrl_set_parsed,
7185         .data = NULL,
7186         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7187                 "<pause_time> <priority> <port_id>: "
7188                 "Configure the Ethernet priority flow control",
7189         .tokens = {
7190                 (void *)&cmd_pfc_set_set,
7191                 (void *)&cmd_pfc_set_flow_ctrl,
7192                 (void *)&cmd_pfc_set_rx,
7193                 (void *)&cmd_pfc_set_rx_mode,
7194                 (void *)&cmd_pfc_set_tx,
7195                 (void *)&cmd_pfc_set_tx_mode,
7196                 (void *)&cmd_pfc_set_high_water,
7197                 (void *)&cmd_pfc_set_low_water,
7198                 (void *)&cmd_pfc_set_pause_time,
7199                 (void *)&cmd_pfc_set_priority,
7200                 (void *)&cmd_pfc_set_portid,
7201                 NULL,
7202         },
7203 };
7204
7205 /* *** RESET CONFIGURATION *** */
7206 struct cmd_reset_result {
7207         cmdline_fixed_string_t reset;
7208         cmdline_fixed_string_t def;
7209 };
7210
7211 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7212                              struct cmdline *cl,
7213                              __rte_unused void *data)
7214 {
7215         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7216         set_def_fwd_config();
7217 }
7218
7219 cmdline_parse_token_string_t cmd_reset_set =
7220         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7221 cmdline_parse_token_string_t cmd_reset_def =
7222         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7223                                  "default");
7224
7225 cmdline_parse_inst_t cmd_reset = {
7226         .f = cmd_reset_parsed,
7227         .data = NULL,
7228         .help_str = "set default: Reset default forwarding configuration",
7229         .tokens = {
7230                 (void *)&cmd_reset_set,
7231                 (void *)&cmd_reset_def,
7232                 NULL,
7233         },
7234 };
7235
7236 /* *** START FORWARDING *** */
7237 struct cmd_start_result {
7238         cmdline_fixed_string_t start;
7239 };
7240
7241 cmdline_parse_token_string_t cmd_start_start =
7242         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7243
7244 static void cmd_start_parsed(__rte_unused void *parsed_result,
7245                              __rte_unused struct cmdline *cl,
7246                              __rte_unused void *data)
7247 {
7248         start_packet_forwarding(0);
7249 }
7250
7251 cmdline_parse_inst_t cmd_start = {
7252         .f = cmd_start_parsed,
7253         .data = NULL,
7254         .help_str = "start: Start packet forwarding",
7255         .tokens = {
7256                 (void *)&cmd_start_start,
7257                 NULL,
7258         },
7259 };
7260
7261 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7262 struct cmd_start_tx_first_result {
7263         cmdline_fixed_string_t start;
7264         cmdline_fixed_string_t tx_first;
7265 };
7266
7267 static void
7268 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7269                           __rte_unused struct cmdline *cl,
7270                           __rte_unused void *data)
7271 {
7272         start_packet_forwarding(1);
7273 }
7274
7275 cmdline_parse_token_string_t cmd_start_tx_first_start =
7276         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7277                                  "start");
7278 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7279         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7280                                  tx_first, "tx_first");
7281
7282 cmdline_parse_inst_t cmd_start_tx_first = {
7283         .f = cmd_start_tx_first_parsed,
7284         .data = NULL,
7285         .help_str = "start tx_first: Start packet forwarding, "
7286                 "after sending 1 burst of packets",
7287         .tokens = {
7288                 (void *)&cmd_start_tx_first_start,
7289                 (void *)&cmd_start_tx_first_tx_first,
7290                 NULL,
7291         },
7292 };
7293
7294 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7295 struct cmd_start_tx_first_n_result {
7296         cmdline_fixed_string_t start;
7297         cmdline_fixed_string_t tx_first;
7298         uint32_t tx_num;
7299 };
7300
7301 static void
7302 cmd_start_tx_first_n_parsed(void *parsed_result,
7303                           __rte_unused struct cmdline *cl,
7304                           __rte_unused void *data)
7305 {
7306         struct cmd_start_tx_first_n_result *res = parsed_result;
7307
7308         start_packet_forwarding(res->tx_num);
7309 }
7310
7311 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7312         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7313                         start, "start");
7314 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7315         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7316                         tx_first, "tx_first");
7317 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7318         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7319                         tx_num, UINT32);
7320
7321 cmdline_parse_inst_t cmd_start_tx_first_n = {
7322         .f = cmd_start_tx_first_n_parsed,
7323         .data = NULL,
7324         .help_str = "start tx_first <num>: "
7325                 "packet forwarding, after sending <num> bursts of packets",
7326         .tokens = {
7327                 (void *)&cmd_start_tx_first_n_start,
7328                 (void *)&cmd_start_tx_first_n_tx_first,
7329                 (void *)&cmd_start_tx_first_n_tx_num,
7330                 NULL,
7331         },
7332 };
7333
7334 /* *** SET LINK UP *** */
7335 struct cmd_set_link_up_result {
7336         cmdline_fixed_string_t set;
7337         cmdline_fixed_string_t link_up;
7338         cmdline_fixed_string_t port;
7339         portid_t port_id;
7340 };
7341
7342 cmdline_parse_token_string_t cmd_set_link_up_set =
7343         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7344 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7345         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7346                                 "link-up");
7347 cmdline_parse_token_string_t cmd_set_link_up_port =
7348         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7349 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7350         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7351
7352 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7353                              __rte_unused struct cmdline *cl,
7354                              __rte_unused void *data)
7355 {
7356         struct cmd_set_link_up_result *res = parsed_result;
7357         dev_set_link_up(res->port_id);
7358 }
7359
7360 cmdline_parse_inst_t cmd_set_link_up = {
7361         .f = cmd_set_link_up_parsed,
7362         .data = NULL,
7363         .help_str = "set link-up port <port id>",
7364         .tokens = {
7365                 (void *)&cmd_set_link_up_set,
7366                 (void *)&cmd_set_link_up_link_up,
7367                 (void *)&cmd_set_link_up_port,
7368                 (void *)&cmd_set_link_up_port_id,
7369                 NULL,
7370         },
7371 };
7372
7373 /* *** SET LINK DOWN *** */
7374 struct cmd_set_link_down_result {
7375         cmdline_fixed_string_t set;
7376         cmdline_fixed_string_t link_down;
7377         cmdline_fixed_string_t port;
7378         portid_t port_id;
7379 };
7380
7381 cmdline_parse_token_string_t cmd_set_link_down_set =
7382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7383 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7384         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7385                                 "link-down");
7386 cmdline_parse_token_string_t cmd_set_link_down_port =
7387         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7388 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7389         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7390
7391 static void cmd_set_link_down_parsed(
7392                                 __rte_unused void *parsed_result,
7393                                 __rte_unused struct cmdline *cl,
7394                                 __rte_unused void *data)
7395 {
7396         struct cmd_set_link_down_result *res = parsed_result;
7397         dev_set_link_down(res->port_id);
7398 }
7399
7400 cmdline_parse_inst_t cmd_set_link_down = {
7401         .f = cmd_set_link_down_parsed,
7402         .data = NULL,
7403         .help_str = "set link-down port <port id>",
7404         .tokens = {
7405                 (void *)&cmd_set_link_down_set,
7406                 (void *)&cmd_set_link_down_link_down,
7407                 (void *)&cmd_set_link_down_port,
7408                 (void *)&cmd_set_link_down_port_id,
7409                 NULL,
7410         },
7411 };
7412
7413 /* *** SHOW CFG *** */
7414 struct cmd_showcfg_result {
7415         cmdline_fixed_string_t show;
7416         cmdline_fixed_string_t cfg;
7417         cmdline_fixed_string_t what;
7418 };
7419
7420 static void cmd_showcfg_parsed(void *parsed_result,
7421                                __rte_unused struct cmdline *cl,
7422                                __rte_unused void *data)
7423 {
7424         struct cmd_showcfg_result *res = parsed_result;
7425         if (!strcmp(res->what, "rxtx"))
7426                 rxtx_config_display();
7427         else if (!strcmp(res->what, "cores"))
7428                 fwd_lcores_config_display();
7429         else if (!strcmp(res->what, "fwd"))
7430                 pkt_fwd_config_display(&cur_fwd_config);
7431         else if (!strcmp(res->what, "txpkts"))
7432                 show_tx_pkt_segments();
7433 }
7434
7435 cmdline_parse_token_string_t cmd_showcfg_show =
7436         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7437 cmdline_parse_token_string_t cmd_showcfg_port =
7438         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7439 cmdline_parse_token_string_t cmd_showcfg_what =
7440         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7441                                  "rxtx#cores#fwd#txpkts");
7442
7443 cmdline_parse_inst_t cmd_showcfg = {
7444         .f = cmd_showcfg_parsed,
7445         .data = NULL,
7446         .help_str = "show config rxtx|cores|fwd|txpkts",
7447         .tokens = {
7448                 (void *)&cmd_showcfg_show,
7449                 (void *)&cmd_showcfg_port,
7450                 (void *)&cmd_showcfg_what,
7451                 NULL,
7452         },
7453 };
7454
7455 /* *** SHOW ALL PORT INFO *** */
7456 struct cmd_showportall_result {
7457         cmdline_fixed_string_t show;
7458         cmdline_fixed_string_t port;
7459         cmdline_fixed_string_t what;
7460         cmdline_fixed_string_t all;
7461 };
7462
7463 static void cmd_showportall_parsed(void *parsed_result,
7464                                 __rte_unused struct cmdline *cl,
7465                                 __rte_unused void *data)
7466 {
7467         portid_t i;
7468
7469         struct cmd_showportall_result *res = parsed_result;
7470         if (!strcmp(res->show, "clear")) {
7471                 if (!strcmp(res->what, "stats"))
7472                         RTE_ETH_FOREACH_DEV(i)
7473                                 nic_stats_clear(i);
7474                 else if (!strcmp(res->what, "xstats"))
7475                         RTE_ETH_FOREACH_DEV(i)
7476                                 nic_xstats_clear(i);
7477         } else if (!strcmp(res->what, "info"))
7478                 RTE_ETH_FOREACH_DEV(i)
7479                         port_infos_display(i);
7480         else if (!strcmp(res->what, "summary")) {
7481                 port_summary_header_display();
7482                 RTE_ETH_FOREACH_DEV(i)
7483                         port_summary_display(i);
7484         }
7485         else if (!strcmp(res->what, "stats"))
7486                 RTE_ETH_FOREACH_DEV(i)
7487                         nic_stats_display(i);
7488         else if (!strcmp(res->what, "xstats"))
7489                 RTE_ETH_FOREACH_DEV(i)
7490                         nic_xstats_display(i);
7491         else if (!strcmp(res->what, "fdir"))
7492                 RTE_ETH_FOREACH_DEV(i)
7493                         fdir_get_infos(i);
7494         else if (!strcmp(res->what, "stat_qmap"))
7495                 RTE_ETH_FOREACH_DEV(i)
7496                         nic_stats_mapping_display(i);
7497         else if (!strcmp(res->what, "dcb_tc"))
7498                 RTE_ETH_FOREACH_DEV(i)
7499                         port_dcb_info_display(i);
7500         else if (!strcmp(res->what, "cap"))
7501                 RTE_ETH_FOREACH_DEV(i)
7502                         port_offload_cap_display(i);
7503 }
7504
7505 cmdline_parse_token_string_t cmd_showportall_show =
7506         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7507                                  "show#clear");
7508 cmdline_parse_token_string_t cmd_showportall_port =
7509         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7510 cmdline_parse_token_string_t cmd_showportall_what =
7511         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7512                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7513 cmdline_parse_token_string_t cmd_showportall_all =
7514         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7515 cmdline_parse_inst_t cmd_showportall = {
7516         .f = cmd_showportall_parsed,
7517         .data = NULL,
7518         .help_str = "show|clear port "
7519                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7520         .tokens = {
7521                 (void *)&cmd_showportall_show,
7522                 (void *)&cmd_showportall_port,
7523                 (void *)&cmd_showportall_what,
7524                 (void *)&cmd_showportall_all,
7525                 NULL,
7526         },
7527 };
7528
7529 /* *** SHOW PORT INFO *** */
7530 struct cmd_showport_result {
7531         cmdline_fixed_string_t show;
7532         cmdline_fixed_string_t port;
7533         cmdline_fixed_string_t what;
7534         uint16_t portnum;
7535 };
7536
7537 static void cmd_showport_parsed(void *parsed_result,
7538                                 __rte_unused struct cmdline *cl,
7539                                 __rte_unused void *data)
7540 {
7541         struct cmd_showport_result *res = parsed_result;
7542         if (!strcmp(res->show, "clear")) {
7543                 if (!strcmp(res->what, "stats"))
7544                         nic_stats_clear(res->portnum);
7545                 else if (!strcmp(res->what, "xstats"))
7546                         nic_xstats_clear(res->portnum);
7547         } else if (!strcmp(res->what, "info"))
7548                 port_infos_display(res->portnum);
7549         else if (!strcmp(res->what, "summary")) {
7550                 port_summary_header_display();
7551                 port_summary_display(res->portnum);
7552         }
7553         else if (!strcmp(res->what, "stats"))
7554                 nic_stats_display(res->portnum);
7555         else if (!strcmp(res->what, "xstats"))
7556                 nic_xstats_display(res->portnum);
7557         else if (!strcmp(res->what, "fdir"))
7558                  fdir_get_infos(res->portnum);
7559         else if (!strcmp(res->what, "stat_qmap"))
7560                 nic_stats_mapping_display(res->portnum);
7561         else if (!strcmp(res->what, "dcb_tc"))
7562                 port_dcb_info_display(res->portnum);
7563         else if (!strcmp(res->what, "cap"))
7564                 port_offload_cap_display(res->portnum);
7565 }
7566
7567 cmdline_parse_token_string_t cmd_showport_show =
7568         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7569                                  "show#clear");
7570 cmdline_parse_token_string_t cmd_showport_port =
7571         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7572 cmdline_parse_token_string_t cmd_showport_what =
7573         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7574                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7575 cmdline_parse_token_num_t cmd_showport_portnum =
7576         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7577
7578 cmdline_parse_inst_t cmd_showport = {
7579         .f = cmd_showport_parsed,
7580         .data = NULL,
7581         .help_str = "show|clear port "
7582                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7583                 "<port_id>",
7584         .tokens = {
7585                 (void *)&cmd_showport_show,
7586                 (void *)&cmd_showport_port,
7587                 (void *)&cmd_showport_what,
7588                 (void *)&cmd_showport_portnum,
7589                 NULL,
7590         },
7591 };
7592
7593 /* *** SHOW DEVICE INFO *** */
7594 struct cmd_showdevice_result {
7595         cmdline_fixed_string_t show;
7596         cmdline_fixed_string_t device;
7597         cmdline_fixed_string_t what;
7598         cmdline_fixed_string_t identifier;
7599 };
7600
7601 static void cmd_showdevice_parsed(void *parsed_result,
7602                                 __rte_unused struct cmdline *cl,
7603                                 __rte_unused void *data)
7604 {
7605         struct cmd_showdevice_result *res = parsed_result;
7606         if (!strcmp(res->what, "info")) {
7607                 if (!strcmp(res->identifier, "all"))
7608                         device_infos_display(NULL);
7609                 else
7610                         device_infos_display(res->identifier);
7611         }
7612 }
7613
7614 cmdline_parse_token_string_t cmd_showdevice_show =
7615         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7616                                  "show");
7617 cmdline_parse_token_string_t cmd_showdevice_device =
7618         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7619 cmdline_parse_token_string_t cmd_showdevice_what =
7620         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7621                                  "info");
7622 cmdline_parse_token_string_t cmd_showdevice_identifier =
7623         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7624                         identifier, NULL);
7625
7626 cmdline_parse_inst_t cmd_showdevice = {
7627         .f = cmd_showdevice_parsed,
7628         .data = NULL,
7629         .help_str = "show device info <identifier>|all",
7630         .tokens = {
7631                 (void *)&cmd_showdevice_show,
7632                 (void *)&cmd_showdevice_device,
7633                 (void *)&cmd_showdevice_what,
7634                 (void *)&cmd_showdevice_identifier,
7635                 NULL,
7636         },
7637 };
7638 /* *** SHOW QUEUE INFO *** */
7639 struct cmd_showqueue_result {
7640         cmdline_fixed_string_t show;
7641         cmdline_fixed_string_t type;
7642         cmdline_fixed_string_t what;
7643         uint16_t portnum;
7644         uint16_t queuenum;
7645 };
7646
7647 static void
7648 cmd_showqueue_parsed(void *parsed_result,
7649         __rte_unused struct cmdline *cl,
7650         __rte_unused void *data)
7651 {
7652         struct cmd_showqueue_result *res = parsed_result;
7653
7654         if (!strcmp(res->type, "rxq"))
7655                 rx_queue_infos_display(res->portnum, res->queuenum);
7656         else if (!strcmp(res->type, "txq"))
7657                 tx_queue_infos_display(res->portnum, res->queuenum);
7658 }
7659
7660 cmdline_parse_token_string_t cmd_showqueue_show =
7661         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7662 cmdline_parse_token_string_t cmd_showqueue_type =
7663         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7664 cmdline_parse_token_string_t cmd_showqueue_what =
7665         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7666 cmdline_parse_token_num_t cmd_showqueue_portnum =
7667         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7668 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7669         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7670
7671 cmdline_parse_inst_t cmd_showqueue = {
7672         .f = cmd_showqueue_parsed,
7673         .data = NULL,
7674         .help_str = "show rxq|txq info <port_id> <queue_id>",
7675         .tokens = {
7676                 (void *)&cmd_showqueue_show,
7677                 (void *)&cmd_showqueue_type,
7678                 (void *)&cmd_showqueue_what,
7679                 (void *)&cmd_showqueue_portnum,
7680                 (void *)&cmd_showqueue_queuenum,
7681                 NULL,
7682         },
7683 };
7684
7685 /* show/clear fwd engine statistics */
7686 struct fwd_result {
7687         cmdline_fixed_string_t action;
7688         cmdline_fixed_string_t fwd;
7689         cmdline_fixed_string_t stats;
7690         cmdline_fixed_string_t all;
7691 };
7692
7693 cmdline_parse_token_string_t cmd_fwd_action =
7694         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7695 cmdline_parse_token_string_t cmd_fwd_fwd =
7696         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7697 cmdline_parse_token_string_t cmd_fwd_stats =
7698         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7699 cmdline_parse_token_string_t cmd_fwd_all =
7700         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7701
7702 static void
7703 cmd_showfwdall_parsed(void *parsed_result,
7704                       __rte_unused struct cmdline *cl,
7705                       __rte_unused void *data)
7706 {
7707         struct fwd_result *res = parsed_result;
7708
7709         if (!strcmp(res->action, "show"))
7710                 fwd_stats_display();
7711         else
7712                 fwd_stats_reset();
7713 }
7714
7715 static cmdline_parse_inst_t cmd_showfwdall = {
7716         .f = cmd_showfwdall_parsed,
7717         .data = NULL,
7718         .help_str = "show|clear fwd stats all",
7719         .tokens = {
7720                 (void *)&cmd_fwd_action,
7721                 (void *)&cmd_fwd_fwd,
7722                 (void *)&cmd_fwd_stats,
7723                 (void *)&cmd_fwd_all,
7724                 NULL,
7725         },
7726 };
7727
7728 /* *** READ PORT REGISTER *** */
7729 struct cmd_read_reg_result {
7730         cmdline_fixed_string_t read;
7731         cmdline_fixed_string_t reg;
7732         portid_t port_id;
7733         uint32_t reg_off;
7734 };
7735
7736 static void
7737 cmd_read_reg_parsed(void *parsed_result,
7738                     __rte_unused struct cmdline *cl,
7739                     __rte_unused void *data)
7740 {
7741         struct cmd_read_reg_result *res = parsed_result;
7742         port_reg_display(res->port_id, res->reg_off);
7743 }
7744
7745 cmdline_parse_token_string_t cmd_read_reg_read =
7746         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7747 cmdline_parse_token_string_t cmd_read_reg_reg =
7748         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7749 cmdline_parse_token_num_t cmd_read_reg_port_id =
7750         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7751 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7752         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7753
7754 cmdline_parse_inst_t cmd_read_reg = {
7755         .f = cmd_read_reg_parsed,
7756         .data = NULL,
7757         .help_str = "read reg <port_id> <reg_off>",
7758         .tokens = {
7759                 (void *)&cmd_read_reg_read,
7760                 (void *)&cmd_read_reg_reg,
7761                 (void *)&cmd_read_reg_port_id,
7762                 (void *)&cmd_read_reg_reg_off,
7763                 NULL,
7764         },
7765 };
7766
7767 /* *** READ PORT REGISTER BIT FIELD *** */
7768 struct cmd_read_reg_bit_field_result {
7769         cmdline_fixed_string_t read;
7770         cmdline_fixed_string_t regfield;
7771         portid_t port_id;
7772         uint32_t reg_off;
7773         uint8_t bit1_pos;
7774         uint8_t bit2_pos;
7775 };
7776
7777 static void
7778 cmd_read_reg_bit_field_parsed(void *parsed_result,
7779                               __rte_unused struct cmdline *cl,
7780                               __rte_unused void *data)
7781 {
7782         struct cmd_read_reg_bit_field_result *res = parsed_result;
7783         port_reg_bit_field_display(res->port_id, res->reg_off,
7784                                    res->bit1_pos, res->bit2_pos);
7785 }
7786
7787 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7788         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7789                                  "read");
7790 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7791         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7792                                  regfield, "regfield");
7793 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7794         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7795                               UINT16);
7796 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7797         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7798                               UINT32);
7799 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7800         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7801                               UINT8);
7802 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7803         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7804                               UINT8);
7805
7806 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7807         .f = cmd_read_reg_bit_field_parsed,
7808         .data = NULL,
7809         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7810         "Read register bit field between bit_x and bit_y included",
7811         .tokens = {
7812                 (void *)&cmd_read_reg_bit_field_read,
7813                 (void *)&cmd_read_reg_bit_field_regfield,
7814                 (void *)&cmd_read_reg_bit_field_port_id,
7815                 (void *)&cmd_read_reg_bit_field_reg_off,
7816                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7817                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7818                 NULL,
7819         },
7820 };
7821
7822 /* *** READ PORT REGISTER BIT *** */
7823 struct cmd_read_reg_bit_result {
7824         cmdline_fixed_string_t read;
7825         cmdline_fixed_string_t regbit;
7826         portid_t port_id;
7827         uint32_t reg_off;
7828         uint8_t bit_pos;
7829 };
7830
7831 static void
7832 cmd_read_reg_bit_parsed(void *parsed_result,
7833                         __rte_unused struct cmdline *cl,
7834                         __rte_unused void *data)
7835 {
7836         struct cmd_read_reg_bit_result *res = parsed_result;
7837         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7838 }
7839
7840 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7841         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7842 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7843         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7844                                  regbit, "regbit");
7845 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7846         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7847 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7848         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7849 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7850         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7851
7852 cmdline_parse_inst_t cmd_read_reg_bit = {
7853         .f = cmd_read_reg_bit_parsed,
7854         .data = NULL,
7855         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7856         .tokens = {
7857                 (void *)&cmd_read_reg_bit_read,
7858                 (void *)&cmd_read_reg_bit_regbit,
7859                 (void *)&cmd_read_reg_bit_port_id,
7860                 (void *)&cmd_read_reg_bit_reg_off,
7861                 (void *)&cmd_read_reg_bit_bit_pos,
7862                 NULL,
7863         },
7864 };
7865
7866 /* *** WRITE PORT REGISTER *** */
7867 struct cmd_write_reg_result {
7868         cmdline_fixed_string_t write;
7869         cmdline_fixed_string_t reg;
7870         portid_t port_id;
7871         uint32_t reg_off;
7872         uint32_t value;
7873 };
7874
7875 static void
7876 cmd_write_reg_parsed(void *parsed_result,
7877                      __rte_unused struct cmdline *cl,
7878                      __rte_unused void *data)
7879 {
7880         struct cmd_write_reg_result *res = parsed_result;
7881         port_reg_set(res->port_id, res->reg_off, res->value);
7882 }
7883
7884 cmdline_parse_token_string_t cmd_write_reg_write =
7885         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7886 cmdline_parse_token_string_t cmd_write_reg_reg =
7887         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7888 cmdline_parse_token_num_t cmd_write_reg_port_id =
7889         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7890 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7891         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7892 cmdline_parse_token_num_t cmd_write_reg_value =
7893         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7894
7895 cmdline_parse_inst_t cmd_write_reg = {
7896         .f = cmd_write_reg_parsed,
7897         .data = NULL,
7898         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7899         .tokens = {
7900                 (void *)&cmd_write_reg_write,
7901                 (void *)&cmd_write_reg_reg,
7902                 (void *)&cmd_write_reg_port_id,
7903                 (void *)&cmd_write_reg_reg_off,
7904                 (void *)&cmd_write_reg_value,
7905                 NULL,
7906         },
7907 };
7908
7909 /* *** WRITE PORT REGISTER BIT FIELD *** */
7910 struct cmd_write_reg_bit_field_result {
7911         cmdline_fixed_string_t write;
7912         cmdline_fixed_string_t regfield;
7913         portid_t port_id;
7914         uint32_t reg_off;
7915         uint8_t bit1_pos;
7916         uint8_t bit2_pos;
7917         uint32_t value;
7918 };
7919
7920 static void
7921 cmd_write_reg_bit_field_parsed(void *parsed_result,
7922                                __rte_unused struct cmdline *cl,
7923                                __rte_unused void *data)
7924 {
7925         struct cmd_write_reg_bit_field_result *res = parsed_result;
7926         port_reg_bit_field_set(res->port_id, res->reg_off,
7927                           res->bit1_pos, res->bit2_pos, res->value);
7928 }
7929
7930 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7931         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7932                                  "write");
7933 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7934         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7935                                  regfield, "regfield");
7936 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7937         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7938                               UINT16);
7939 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7940         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7941                               UINT32);
7942 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7943         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7944                               UINT8);
7945 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7946         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7947                               UINT8);
7948 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7949         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7950                               UINT32);
7951
7952 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7953         .f = cmd_write_reg_bit_field_parsed,
7954         .data = NULL,
7955         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7956                 "<reg_value>: "
7957                 "Set register bit field between bit_x and bit_y included",
7958         .tokens = {
7959                 (void *)&cmd_write_reg_bit_field_write,
7960                 (void *)&cmd_write_reg_bit_field_regfield,
7961                 (void *)&cmd_write_reg_bit_field_port_id,
7962                 (void *)&cmd_write_reg_bit_field_reg_off,
7963                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7964                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7965                 (void *)&cmd_write_reg_bit_field_value,
7966                 NULL,
7967         },
7968 };
7969
7970 /* *** WRITE PORT REGISTER BIT *** */
7971 struct cmd_write_reg_bit_result {
7972         cmdline_fixed_string_t write;
7973         cmdline_fixed_string_t regbit;
7974         portid_t port_id;
7975         uint32_t reg_off;
7976         uint8_t bit_pos;
7977         uint8_t value;
7978 };
7979
7980 static void
7981 cmd_write_reg_bit_parsed(void *parsed_result,
7982                          __rte_unused struct cmdline *cl,
7983                          __rte_unused void *data)
7984 {
7985         struct cmd_write_reg_bit_result *res = parsed_result;
7986         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7987 }
7988
7989 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7990         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7991                                  "write");
7992 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7993         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7994                                  regbit, "regbit");
7995 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7997 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7998         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7999 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8000         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8001 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8002         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8003
8004 cmdline_parse_inst_t cmd_write_reg_bit = {
8005         .f = cmd_write_reg_bit_parsed,
8006         .data = NULL,
8007         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8008                 "0 <= bit_x <= 31",
8009         .tokens = {
8010                 (void *)&cmd_write_reg_bit_write,
8011                 (void *)&cmd_write_reg_bit_regbit,
8012                 (void *)&cmd_write_reg_bit_port_id,
8013                 (void *)&cmd_write_reg_bit_reg_off,
8014                 (void *)&cmd_write_reg_bit_bit_pos,
8015                 (void *)&cmd_write_reg_bit_value,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8021 struct cmd_read_rxd_txd_result {
8022         cmdline_fixed_string_t read;
8023         cmdline_fixed_string_t rxd_txd;
8024         portid_t port_id;
8025         uint16_t queue_id;
8026         uint16_t desc_id;
8027 };
8028
8029 static void
8030 cmd_read_rxd_txd_parsed(void *parsed_result,
8031                         __rte_unused struct cmdline *cl,
8032                         __rte_unused void *data)
8033 {
8034         struct cmd_read_rxd_txd_result *res = parsed_result;
8035
8036         if (!strcmp(res->rxd_txd, "rxd"))
8037                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8038         else if (!strcmp(res->rxd_txd, "txd"))
8039                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8040 }
8041
8042 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8043         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8044 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8045         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8046                                  "rxd#txd");
8047 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8048         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8049 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8050         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8051 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8052         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8053
8054 cmdline_parse_inst_t cmd_read_rxd_txd = {
8055         .f = cmd_read_rxd_txd_parsed,
8056         .data = NULL,
8057         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8058         .tokens = {
8059                 (void *)&cmd_read_rxd_txd_read,
8060                 (void *)&cmd_read_rxd_txd_rxd_txd,
8061                 (void *)&cmd_read_rxd_txd_port_id,
8062                 (void *)&cmd_read_rxd_txd_queue_id,
8063                 (void *)&cmd_read_rxd_txd_desc_id,
8064                 NULL,
8065         },
8066 };
8067
8068 /* *** QUIT *** */
8069 struct cmd_quit_result {
8070         cmdline_fixed_string_t quit;
8071 };
8072
8073 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8074                             struct cmdline *cl,
8075                             __rte_unused void *data)
8076 {
8077         cmdline_quit(cl);
8078 }
8079
8080 cmdline_parse_token_string_t cmd_quit_quit =
8081         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8082
8083 cmdline_parse_inst_t cmd_quit = {
8084         .f = cmd_quit_parsed,
8085         .data = NULL,
8086         .help_str = "quit: Exit application",
8087         .tokens = {
8088                 (void *)&cmd_quit_quit,
8089                 NULL,
8090         },
8091 };
8092
8093 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8094 struct cmd_mac_addr_result {
8095         cmdline_fixed_string_t mac_addr_cmd;
8096         cmdline_fixed_string_t what;
8097         uint16_t port_num;
8098         struct rte_ether_addr address;
8099 };
8100
8101 static void cmd_mac_addr_parsed(void *parsed_result,
8102                 __rte_unused struct cmdline *cl,
8103                 __rte_unused void *data)
8104 {
8105         struct cmd_mac_addr_result *res = parsed_result;
8106         int ret;
8107
8108         if (strcmp(res->what, "add") == 0)
8109                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8110         else if (strcmp(res->what, "set") == 0)
8111                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8112                                                        &res->address);
8113         else
8114                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8115
8116         /* check the return value and print it if is < 0 */
8117         if(ret < 0)
8118                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8119
8120 }
8121
8122 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8123         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8124                                 "mac_addr");
8125 cmdline_parse_token_string_t cmd_mac_addr_what =
8126         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8127                                 "add#remove#set");
8128 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8129                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8130                                         UINT16);
8131 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8132                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8133
8134 cmdline_parse_inst_t cmd_mac_addr = {
8135         .f = cmd_mac_addr_parsed,
8136         .data = (void *)0,
8137         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8138                         "Add/Remove/Set MAC address on port_id",
8139         .tokens = {
8140                 (void *)&cmd_mac_addr_cmd,
8141                 (void *)&cmd_mac_addr_what,
8142                 (void *)&cmd_mac_addr_portnum,
8143                 (void *)&cmd_mac_addr_addr,
8144                 NULL,
8145         },
8146 };
8147
8148 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8149 struct cmd_eth_peer_result {
8150         cmdline_fixed_string_t set;
8151         cmdline_fixed_string_t eth_peer;
8152         portid_t port_id;
8153         cmdline_fixed_string_t peer_addr;
8154 };
8155
8156 static void cmd_set_eth_peer_parsed(void *parsed_result,
8157                         __rte_unused struct cmdline *cl,
8158                         __rte_unused void *data)
8159 {
8160                 struct cmd_eth_peer_result *res = parsed_result;
8161
8162                 if (test_done == 0) {
8163                         printf("Please stop forwarding first\n");
8164                         return;
8165                 }
8166                 if (!strcmp(res->eth_peer, "eth-peer")) {
8167                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8168                         fwd_config_setup();
8169                 }
8170 }
8171 cmdline_parse_token_string_t cmd_eth_peer_set =
8172         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8173 cmdline_parse_token_string_t cmd_eth_peer =
8174         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8175 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8176         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8177 cmdline_parse_token_string_t cmd_eth_peer_addr =
8178         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8179
8180 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8181         .f = cmd_set_eth_peer_parsed,
8182         .data = NULL,
8183         .help_str = "set eth-peer <port_id> <peer_mac>",
8184         .tokens = {
8185                 (void *)&cmd_eth_peer_set,
8186                 (void *)&cmd_eth_peer,
8187                 (void *)&cmd_eth_peer_port_id,
8188                 (void *)&cmd_eth_peer_addr,
8189                 NULL,
8190         },
8191 };
8192
8193 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8194 struct cmd_set_qmap_result {
8195         cmdline_fixed_string_t set;
8196         cmdline_fixed_string_t qmap;
8197         cmdline_fixed_string_t what;
8198         portid_t port_id;
8199         uint16_t queue_id;
8200         uint8_t map_value;
8201 };
8202
8203 static void
8204 cmd_set_qmap_parsed(void *parsed_result,
8205                        __rte_unused struct cmdline *cl,
8206                        __rte_unused void *data)
8207 {
8208         struct cmd_set_qmap_result *res = parsed_result;
8209         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8210
8211         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8212 }
8213
8214 cmdline_parse_token_string_t cmd_setqmap_set =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8216                                  set, "set");
8217 cmdline_parse_token_string_t cmd_setqmap_qmap =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8219                                  qmap, "stat_qmap");
8220 cmdline_parse_token_string_t cmd_setqmap_what =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8222                                  what, "tx#rx");
8223 cmdline_parse_token_num_t cmd_setqmap_portid =
8224         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8225                               port_id, UINT16);
8226 cmdline_parse_token_num_t cmd_setqmap_queueid =
8227         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8228                               queue_id, UINT16);
8229 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8230         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8231                               map_value, UINT8);
8232
8233 cmdline_parse_inst_t cmd_set_qmap = {
8234         .f = cmd_set_qmap_parsed,
8235         .data = NULL,
8236         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8237                 "Set statistics mapping value on tx|rx queue_id of port_id",
8238         .tokens = {
8239                 (void *)&cmd_setqmap_set,
8240                 (void *)&cmd_setqmap_qmap,
8241                 (void *)&cmd_setqmap_what,
8242                 (void *)&cmd_setqmap_portid,
8243                 (void *)&cmd_setqmap_queueid,
8244                 (void *)&cmd_setqmap_mapvalue,
8245                 NULL,
8246         },
8247 };
8248
8249 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8250 struct cmd_set_xstats_hide_zero_result {
8251         cmdline_fixed_string_t keyword;
8252         cmdline_fixed_string_t name;
8253         cmdline_fixed_string_t on_off;
8254 };
8255
8256 static void
8257 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8258                         __rte_unused struct cmdline *cl,
8259                         __rte_unused void *data)
8260 {
8261         struct cmd_set_xstats_hide_zero_result *res;
8262         uint16_t on_off = 0;
8263
8264         res = parsed_result;
8265         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8266         set_xstats_hide_zero(on_off);
8267 }
8268
8269 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8270         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8271                                  keyword, "set");
8272 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8273         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8274                                  name, "xstats-hide-zero");
8275 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8276         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8277                                  on_off, "on#off");
8278
8279 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8280         .f = cmd_set_xstats_hide_zero_parsed,
8281         .data = NULL,
8282         .help_str = "set xstats-hide-zero on|off",
8283         .tokens = {
8284                 (void *)&cmd_set_xstats_hide_zero_keyword,
8285                 (void *)&cmd_set_xstats_hide_zero_name,
8286                 (void *)&cmd_set_xstats_hide_zero_on_off,
8287                 NULL,
8288         },
8289 };
8290
8291 /* *** CONFIGURE UNICAST HASH TABLE *** */
8292 struct cmd_set_uc_hash_table {
8293         cmdline_fixed_string_t set;
8294         cmdline_fixed_string_t port;
8295         portid_t port_id;
8296         cmdline_fixed_string_t what;
8297         struct rte_ether_addr address;
8298         cmdline_fixed_string_t mode;
8299 };
8300
8301 static void
8302 cmd_set_uc_hash_parsed(void *parsed_result,
8303                        __rte_unused struct cmdline *cl,
8304                        __rte_unused void *data)
8305 {
8306         int ret=0;
8307         struct cmd_set_uc_hash_table *res = parsed_result;
8308
8309         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8310
8311         if (strcmp(res->what, "uta") == 0)
8312                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8313                                                 &res->address,(uint8_t)is_on);
8314         if (ret < 0)
8315                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8316
8317 }
8318
8319 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8320         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8321                                  set, "set");
8322 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8324                                  port, "port");
8325 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8326         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8327                               port_id, UINT16);
8328 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8329         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8330                                  what, "uta");
8331 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8332         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8333                                 address);
8334 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8336                                  mode, "on#off");
8337
8338 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8339         .f = cmd_set_uc_hash_parsed,
8340         .data = NULL,
8341         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8342         .tokens = {
8343                 (void *)&cmd_set_uc_hash_set,
8344                 (void *)&cmd_set_uc_hash_port,
8345                 (void *)&cmd_set_uc_hash_portid,
8346                 (void *)&cmd_set_uc_hash_what,
8347                 (void *)&cmd_set_uc_hash_mac,
8348                 (void *)&cmd_set_uc_hash_mode,
8349                 NULL,
8350         },
8351 };
8352
8353 struct cmd_set_uc_all_hash_table {
8354         cmdline_fixed_string_t set;
8355         cmdline_fixed_string_t port;
8356         portid_t port_id;
8357         cmdline_fixed_string_t what;
8358         cmdline_fixed_string_t value;
8359         cmdline_fixed_string_t mode;
8360 };
8361
8362 static void
8363 cmd_set_uc_all_hash_parsed(void *parsed_result,
8364                        __rte_unused struct cmdline *cl,
8365                        __rte_unused void *data)
8366 {
8367         int ret=0;
8368         struct cmd_set_uc_all_hash_table *res = parsed_result;
8369
8370         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8371
8372         if ((strcmp(res->what, "uta") == 0) &&
8373                 (strcmp(res->value, "all") == 0))
8374                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8375         if (ret < 0)
8376                 printf("bad unicast hash table parameter,"
8377                         "return code = %d \n", ret);
8378 }
8379
8380 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8381         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8382                                  set, "set");
8383 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8384         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8385                                  port, "port");
8386 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8387         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8388                               port_id, UINT16);
8389 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8390         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8391                                  what, "uta");
8392 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8393         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8394                                 value,"all");
8395 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8396         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8397                                  mode, "on#off");
8398
8399 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8400         .f = cmd_set_uc_all_hash_parsed,
8401         .data = NULL,
8402         .help_str = "set port <port_id> uta all on|off",
8403         .tokens = {
8404                 (void *)&cmd_set_uc_all_hash_set,
8405                 (void *)&cmd_set_uc_all_hash_port,
8406                 (void *)&cmd_set_uc_all_hash_portid,
8407                 (void *)&cmd_set_uc_all_hash_what,
8408                 (void *)&cmd_set_uc_all_hash_value,
8409                 (void *)&cmd_set_uc_all_hash_mode,
8410                 NULL,
8411         },
8412 };
8413
8414 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8415 struct cmd_set_vf_macvlan_filter {
8416         cmdline_fixed_string_t set;
8417         cmdline_fixed_string_t port;
8418         portid_t port_id;
8419         cmdline_fixed_string_t vf;
8420         uint8_t vf_id;
8421         struct rte_ether_addr address;
8422         cmdline_fixed_string_t filter_type;
8423         cmdline_fixed_string_t mode;
8424 };
8425
8426 static void
8427 cmd_set_vf_macvlan_parsed(void *parsed_result,
8428                        __rte_unused struct cmdline *cl,
8429                        __rte_unused void *data)
8430 {
8431         int is_on, ret = 0;
8432         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8433         struct rte_eth_mac_filter filter;
8434
8435         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8436
8437         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8438
8439         /* set VF MAC filter */
8440         filter.is_vf = 1;
8441
8442         /* set VF ID */
8443         filter.dst_id = res->vf_id;
8444
8445         if (!strcmp(res->filter_type, "exact-mac"))
8446                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8447         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8448                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8449         else if (!strcmp(res->filter_type, "hashmac"))
8450                 filter.filter_type = RTE_MAC_HASH_MATCH;
8451         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8452                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8453
8454         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8455
8456         if (is_on)
8457                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8458                                         RTE_ETH_FILTER_MACVLAN,
8459                                         RTE_ETH_FILTER_ADD,
8460                                          &filter);
8461         else
8462                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8463                                         RTE_ETH_FILTER_MACVLAN,
8464                                         RTE_ETH_FILTER_DELETE,
8465                                         &filter);
8466
8467         if (ret < 0)
8468                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8469
8470 }
8471
8472 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8473         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8474                                  set, "set");
8475 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8476         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8477                                  port, "port");
8478 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8479         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8480                               port_id, UINT16);
8481 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8482         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8483                                  vf, "vf");
8484 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8485         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8486                                 vf_id, UINT8);
8487 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8488         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8489                                 address);
8490 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8491         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8492                                 filter_type, "exact-mac#exact-mac-vlan"
8493                                 "#hashmac#hashmac-vlan");
8494 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8495         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8496                                  mode, "on#off");
8497
8498 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8499         .f = cmd_set_vf_macvlan_parsed,
8500         .data = NULL,
8501         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8502                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8503                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8504                 "hash match rule: hash match of MAC and exact match of VLAN",
8505         .tokens = {
8506                 (void *)&cmd_set_vf_macvlan_set,
8507                 (void *)&cmd_set_vf_macvlan_port,
8508                 (void *)&cmd_set_vf_macvlan_portid,
8509                 (void *)&cmd_set_vf_macvlan_vf,
8510                 (void *)&cmd_set_vf_macvlan_vf_id,
8511                 (void *)&cmd_set_vf_macvlan_mac,
8512                 (void *)&cmd_set_vf_macvlan_filter_type,
8513                 (void *)&cmd_set_vf_macvlan_mode,
8514                 NULL,
8515         },
8516 };
8517
8518 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8519 struct cmd_set_vf_traffic {
8520         cmdline_fixed_string_t set;
8521         cmdline_fixed_string_t port;
8522         portid_t port_id;
8523         cmdline_fixed_string_t vf;
8524         uint8_t vf_id;
8525         cmdline_fixed_string_t what;
8526         cmdline_fixed_string_t mode;
8527 };
8528
8529 static void
8530 cmd_set_vf_traffic_parsed(void *parsed_result,
8531                        __rte_unused struct cmdline *cl,
8532                        __rte_unused void *data)
8533 {
8534         struct cmd_set_vf_traffic *res = parsed_result;
8535         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8536         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8537
8538         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8539 }
8540
8541 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8542         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8543                                  set, "set");
8544 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8545         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8546                                  port, "port");
8547 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8548         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8549                               port_id, UINT16);
8550 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8551         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8552                                  vf, "vf");
8553 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8554         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8555                               vf_id, UINT8);
8556 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8557         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8558                                  what, "tx#rx");
8559 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8560         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8561                                  mode, "on#off");
8562
8563 cmdline_parse_inst_t cmd_set_vf_traffic = {
8564         .f = cmd_set_vf_traffic_parsed,
8565         .data = NULL,
8566         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8567         .tokens = {
8568                 (void *)&cmd_setvf_traffic_set,
8569                 (void *)&cmd_setvf_traffic_port,
8570                 (void *)&cmd_setvf_traffic_portid,
8571                 (void *)&cmd_setvf_traffic_vf,
8572                 (void *)&cmd_setvf_traffic_vfid,
8573                 (void *)&cmd_setvf_traffic_what,
8574                 (void *)&cmd_setvf_traffic_mode,
8575                 NULL,
8576         },
8577 };
8578
8579 /* *** CONFIGURE VF RECEIVE MODE *** */
8580 struct cmd_set_vf_rxmode {
8581         cmdline_fixed_string_t set;
8582         cmdline_fixed_string_t port;
8583         portid_t port_id;
8584         cmdline_fixed_string_t vf;
8585         uint8_t vf_id;
8586         cmdline_fixed_string_t what;
8587         cmdline_fixed_string_t mode;
8588         cmdline_fixed_string_t on;
8589 };
8590
8591 static void
8592 cmd_set_vf_rxmode_parsed(void *parsed_result,
8593                        __rte_unused struct cmdline *cl,
8594                        __rte_unused void *data)
8595 {
8596         int ret = -ENOTSUP;
8597         uint16_t vf_rxmode = 0;
8598         struct cmd_set_vf_rxmode *res = parsed_result;
8599
8600         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8601         if (!strcmp(res->what,"rxmode")) {
8602                 if (!strcmp(res->mode, "AUPE"))
8603                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8604                 else if (!strcmp(res->mode, "ROPE"))
8605                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8606                 else if (!strcmp(res->mode, "BAM"))
8607                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8608                 else if (!strncmp(res->mode, "MPE",3))
8609                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8610         }
8611
8612         RTE_SET_USED(is_on);
8613
8614 #ifdef RTE_LIBRTE_IXGBE_PMD
8615         if (ret == -ENOTSUP)
8616                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8617                                                   vf_rxmode, (uint8_t)is_on);
8618 #endif
8619 #ifdef RTE_LIBRTE_BNXT_PMD
8620         if (ret == -ENOTSUP)
8621                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8622                                                  vf_rxmode, (uint8_t)is_on);
8623 #endif
8624         if (ret < 0)
8625                 printf("bad VF receive mode parameter, return code = %d \n",
8626                 ret);
8627 }
8628
8629 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8630         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8631                                  set, "set");
8632 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8633         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8634                                  port, "port");
8635 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8636         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8637                               port_id, UINT16);
8638 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8639         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8640                                  vf, "vf");
8641 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8642         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8643                               vf_id, UINT8);
8644 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8645         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8646                                  what, "rxmode");
8647 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8648         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8649                                  mode, "AUPE#ROPE#BAM#MPE");
8650 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8651         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8652                                  on, "on#off");
8653
8654 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8655         .f = cmd_set_vf_rxmode_parsed,
8656         .data = NULL,
8657         .help_str = "set port <port_id> vf <vf_id> rxmode "
8658                 "AUPE|ROPE|BAM|MPE on|off",
8659         .tokens = {
8660                 (void *)&cmd_set_vf_rxmode_set,
8661                 (void *)&cmd_set_vf_rxmode_port,
8662                 (void *)&cmd_set_vf_rxmode_portid,
8663                 (void *)&cmd_set_vf_rxmode_vf,
8664                 (void *)&cmd_set_vf_rxmode_vfid,
8665                 (void *)&cmd_set_vf_rxmode_what,
8666                 (void *)&cmd_set_vf_rxmode_mode,
8667                 (void *)&cmd_set_vf_rxmode_on,
8668                 NULL,
8669         },
8670 };
8671
8672 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8673 struct cmd_vf_mac_addr_result {
8674         cmdline_fixed_string_t mac_addr_cmd;
8675         cmdline_fixed_string_t what;
8676         cmdline_fixed_string_t port;
8677         uint16_t port_num;
8678         cmdline_fixed_string_t vf;
8679         uint8_t vf_num;
8680         struct rte_ether_addr address;
8681 };
8682
8683 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8684                 __rte_unused struct cmdline *cl,
8685                 __rte_unused void *data)
8686 {
8687         struct cmd_vf_mac_addr_result *res = parsed_result;
8688         int ret = -ENOTSUP;
8689
8690         if (strcmp(res->what, "add") != 0)
8691                 return;
8692
8693 #ifdef RTE_LIBRTE_I40E_PMD
8694         if (ret == -ENOTSUP)
8695                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8696                                                    &res->address);
8697 #endif
8698 #ifdef RTE_LIBRTE_BNXT_PMD
8699         if (ret == -ENOTSUP)
8700                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8701                                                 res->vf_num);
8702 #endif
8703
8704         if(ret < 0)
8705                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8706
8707 }
8708
8709 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8710         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8711                                 mac_addr_cmd,"mac_addr");
8712 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8713         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8714                                 what,"add");
8715 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8716         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8717                                 port,"port");
8718 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8719         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8720                                 port_num, UINT16);
8721 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8722         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8723                                 vf,"vf");
8724 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8725         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8726                                 vf_num, UINT8);
8727 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8728         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8729                                 address);
8730
8731 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8732         .f = cmd_vf_mac_addr_parsed,
8733         .data = (void *)0,
8734         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8735                 "Add MAC address filtering for a VF on port_id",
8736         .tokens = {
8737                 (void *)&cmd_vf_mac_addr_cmd,
8738                 (void *)&cmd_vf_mac_addr_what,
8739                 (void *)&cmd_vf_mac_addr_port,
8740                 (void *)&cmd_vf_mac_addr_portnum,
8741                 (void *)&cmd_vf_mac_addr_vf,
8742                 (void *)&cmd_vf_mac_addr_vfnum,
8743                 (void *)&cmd_vf_mac_addr_addr,
8744                 NULL,
8745         },
8746 };
8747
8748 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8749 struct cmd_vf_rx_vlan_filter {
8750         cmdline_fixed_string_t rx_vlan;
8751         cmdline_fixed_string_t what;
8752         uint16_t vlan_id;
8753         cmdline_fixed_string_t port;
8754         portid_t port_id;
8755         cmdline_fixed_string_t vf;
8756         uint64_t vf_mask;
8757 };
8758
8759 static void
8760 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8761                           __rte_unused struct cmdline *cl,
8762                           __rte_unused void *data)
8763 {
8764         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8765         int ret = -ENOTSUP;
8766
8767         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8768
8769 #ifdef RTE_LIBRTE_IXGBE_PMD
8770         if (ret == -ENOTSUP)
8771                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8772                                 res->vlan_id, res->vf_mask, is_add);
8773 #endif
8774 #ifdef RTE_LIBRTE_I40E_PMD
8775         if (ret == -ENOTSUP)
8776                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8777                                 res->vlan_id, res->vf_mask, is_add);
8778 #endif
8779 #ifdef RTE_LIBRTE_BNXT_PMD
8780         if (ret == -ENOTSUP)
8781                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8782                                 res->vlan_id, res->vf_mask, is_add);
8783 #endif
8784
8785         switch (ret) {
8786         case 0:
8787                 break;
8788         case -EINVAL:
8789                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8790                                 res->vlan_id, res->vf_mask);
8791                 break;
8792         case -ENODEV:
8793                 printf("invalid port_id %d\n", res->port_id);
8794                 break;
8795         case -ENOTSUP:
8796                 printf("function not implemented or supported\n");
8797                 break;
8798         default:
8799                 printf("programming error: (%s)\n", strerror(-ret));
8800         }
8801 }
8802
8803 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8804         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8805                                  rx_vlan, "rx_vlan");
8806 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8807         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8808                                  what, "add#rm");
8809 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8810         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8811                               vlan_id, UINT16);
8812 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8813         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8814                                  port, "port");
8815 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8816         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8817                               port_id, UINT16);
8818 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8819         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8820                                  vf, "vf");
8821 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8822         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8823                               vf_mask, UINT64);
8824
8825 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8826         .f = cmd_vf_rx_vlan_filter_parsed,
8827         .data = NULL,
8828         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8829                 "(vf_mask = hexadecimal VF mask)",
8830         .tokens = {
8831                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8832                 (void *)&cmd_vf_rx_vlan_filter_what,
8833                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8834                 (void *)&cmd_vf_rx_vlan_filter_port,
8835                 (void *)&cmd_vf_rx_vlan_filter_portid,
8836                 (void *)&cmd_vf_rx_vlan_filter_vf,
8837                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8838                 NULL,
8839         },
8840 };
8841
8842 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8843 struct cmd_queue_rate_limit_result {
8844         cmdline_fixed_string_t set;
8845         cmdline_fixed_string_t port;
8846         uint16_t port_num;
8847         cmdline_fixed_string_t queue;
8848         uint8_t queue_num;
8849         cmdline_fixed_string_t rate;
8850         uint16_t rate_num;
8851 };
8852
8853 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8854                 __rte_unused struct cmdline *cl,
8855                 __rte_unused void *data)
8856 {
8857         struct cmd_queue_rate_limit_result *res = parsed_result;
8858         int ret = 0;
8859
8860         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8861                 && (strcmp(res->queue, "queue") == 0)
8862                 && (strcmp(res->rate, "rate") == 0))
8863                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8864                                         res->rate_num);
8865         if (ret < 0)
8866                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8867
8868 }
8869
8870 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8871         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8872                                 set, "set");
8873 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8874         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8875                                 port, "port");
8876 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8877         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8878                                 port_num, UINT16);
8879 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8880         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8881                                 queue, "queue");
8882 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8883         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8884                                 queue_num, UINT8);
8885 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8886         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8887                                 rate, "rate");
8888 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8889         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8890                                 rate_num, UINT16);
8891
8892 cmdline_parse_inst_t cmd_queue_rate_limit = {
8893         .f = cmd_queue_rate_limit_parsed,
8894         .data = (void *)0,
8895         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8896                 "Set rate limit for a queue on port_id",
8897         .tokens = {
8898                 (void *)&cmd_queue_rate_limit_set,
8899                 (void *)&cmd_queue_rate_limit_port,
8900                 (void *)&cmd_queue_rate_limit_portnum,
8901                 (void *)&cmd_queue_rate_limit_queue,
8902                 (void *)&cmd_queue_rate_limit_queuenum,
8903                 (void *)&cmd_queue_rate_limit_rate,
8904                 (void *)&cmd_queue_rate_limit_ratenum,
8905                 NULL,
8906         },
8907 };
8908
8909 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8910 struct cmd_vf_rate_limit_result {
8911         cmdline_fixed_string_t set;
8912         cmdline_fixed_string_t port;
8913         uint16_t port_num;
8914         cmdline_fixed_string_t vf;
8915         uint8_t vf_num;
8916         cmdline_fixed_string_t rate;
8917         uint16_t rate_num;
8918         cmdline_fixed_string_t q_msk;
8919         uint64_t q_msk_val;
8920 };
8921
8922 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8923                 __rte_unused struct cmdline *cl,
8924                 __rte_unused void *data)
8925 {
8926         struct cmd_vf_rate_limit_result *res = parsed_result;
8927         int ret = 0;
8928
8929         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8930                 && (strcmp(res->vf, "vf") == 0)
8931                 && (strcmp(res->rate, "rate") == 0)
8932                 && (strcmp(res->q_msk, "queue_mask") == 0))
8933                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8934                                         res->rate_num, res->q_msk_val);
8935         if (ret < 0)
8936                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8937
8938 }
8939
8940 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8941         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8942                                 set, "set");
8943 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8944         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8945                                 port, "port");
8946 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8947         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8948                                 port_num, UINT16);
8949 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8950         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8951                                 vf, "vf");
8952 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8953         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8954                                 vf_num, UINT8);
8955 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8956         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8957                                 rate, "rate");
8958 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8959         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8960                                 rate_num, UINT16);
8961 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8962         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8963                                 q_msk, "queue_mask");
8964 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8965         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8966                                 q_msk_val, UINT64);
8967
8968 cmdline_parse_inst_t cmd_vf_rate_limit = {
8969         .f = cmd_vf_rate_limit_parsed,
8970         .data = (void *)0,
8971         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8972                 "queue_mask <queue_mask_value>: "
8973                 "Set rate limit for queues of VF on port_id",
8974         .tokens = {
8975                 (void *)&cmd_vf_rate_limit_set,
8976                 (void *)&cmd_vf_rate_limit_port,
8977                 (void *)&cmd_vf_rate_limit_portnum,
8978                 (void *)&cmd_vf_rate_limit_vf,
8979                 (void *)&cmd_vf_rate_limit_vfnum,
8980                 (void *)&cmd_vf_rate_limit_rate,
8981                 (void *)&cmd_vf_rate_limit_ratenum,
8982                 (void *)&cmd_vf_rate_limit_q_msk,
8983                 (void *)&cmd_vf_rate_limit_q_msk_val,
8984                 NULL,
8985         },
8986 };
8987
8988 /* *** ADD TUNNEL FILTER OF A PORT *** */
8989 struct cmd_tunnel_filter_result {
8990         cmdline_fixed_string_t cmd;
8991         cmdline_fixed_string_t what;
8992         portid_t port_id;
8993         struct rte_ether_addr outer_mac;
8994         struct rte_ether_addr inner_mac;
8995         cmdline_ipaddr_t ip_value;
8996         uint16_t inner_vlan;
8997         cmdline_fixed_string_t tunnel_type;
8998         cmdline_fixed_string_t filter_type;
8999         uint32_t tenant_id;
9000         uint16_t queue_num;
9001 };
9002
9003 static void
9004 cmd_tunnel_filter_parsed(void *parsed_result,
9005                           __rte_unused struct cmdline *cl,
9006                           __rte_unused void *data)
9007 {
9008         struct cmd_tunnel_filter_result *res = parsed_result;
9009         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9010         int ret = 0;
9011
9012         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9013
9014         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9015         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9016         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9017
9018         if (res->ip_value.family == AF_INET) {
9019                 tunnel_filter_conf.ip_addr.ipv4_addr =
9020                         res->ip_value.addr.ipv4.s_addr;
9021                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9022         } else {
9023                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9024                         &(res->ip_value.addr.ipv6),
9025                         sizeof(struct in6_addr));
9026                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9027         }
9028
9029         if (!strcmp(res->filter_type, "imac-ivlan"))
9030                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9031         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9032                 tunnel_filter_conf.filter_type =
9033                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9034         else if (!strcmp(res->filter_type, "imac-tenid"))
9035                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9036         else if (!strcmp(res->filter_type, "imac"))
9037                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9038         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9039                 tunnel_filter_conf.filter_type =
9040                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9041         else if (!strcmp(res->filter_type, "oip"))
9042                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9043         else if (!strcmp(res->filter_type, "iip"))
9044                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9045         else {
9046                 printf("The filter type is not supported");
9047                 return;
9048         }
9049
9050         if (!strcmp(res->tunnel_type, "vxlan"))
9051                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9052         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9053                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9054         else if (!strcmp(res->tunnel_type, "nvgre"))
9055                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9056         else if (!strcmp(res->tunnel_type, "ipingre"))
9057                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9058         else {
9059                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9060                 return;
9061         }
9062
9063         tunnel_filter_conf.tenant_id = res->tenant_id;
9064         tunnel_filter_conf.queue_id = res->queue_num;
9065         if (!strcmp(res->what, "add"))
9066                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9067                                         RTE_ETH_FILTER_TUNNEL,
9068                                         RTE_ETH_FILTER_ADD,
9069                                         &tunnel_filter_conf);
9070         else
9071                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9072                                         RTE_ETH_FILTER_TUNNEL,
9073                                         RTE_ETH_FILTER_DELETE,
9074                                         &tunnel_filter_conf);
9075         if (ret < 0)
9076                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9077                                 strerror(-ret));
9078
9079 }
9080 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9081         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9082         cmd, "tunnel_filter");
9083 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9084         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9085         what, "add#rm");
9086 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9087         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9088         port_id, UINT16);
9089 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9090         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9091         outer_mac);
9092 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9093         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9094         inner_mac);
9095 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9096         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9097         inner_vlan, UINT16);
9098 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9099         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9100         ip_value);
9101 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9102         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9103         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9104
9105 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9106         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9107         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9108                 "imac#omac-imac-tenid");
9109 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9110         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9111         tenant_id, UINT32);
9112 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9113         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9114         queue_num, UINT16);
9115
9116 cmdline_parse_inst_t cmd_tunnel_filter = {
9117         .f = cmd_tunnel_filter_parsed,
9118         .data = (void *)0,
9119         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9120                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9121                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9122                 "<queue_id>: Add/Rm tunnel filter of a port",
9123         .tokens = {
9124                 (void *)&cmd_tunnel_filter_cmd,
9125                 (void *)&cmd_tunnel_filter_what,
9126                 (void *)&cmd_tunnel_filter_port_id,
9127                 (void *)&cmd_tunnel_filter_outer_mac,
9128                 (void *)&cmd_tunnel_filter_inner_mac,
9129                 (void *)&cmd_tunnel_filter_ip_value,
9130                 (void *)&cmd_tunnel_filter_innner_vlan,
9131                 (void *)&cmd_tunnel_filter_tunnel_type,
9132                 (void *)&cmd_tunnel_filter_filter_type,
9133                 (void *)&cmd_tunnel_filter_tenant_id,
9134                 (void *)&cmd_tunnel_filter_queue_num,
9135                 NULL,
9136         },
9137 };
9138
9139 /* *** CONFIGURE TUNNEL UDP PORT *** */
9140 struct cmd_tunnel_udp_config {
9141         cmdline_fixed_string_t cmd;
9142         cmdline_fixed_string_t what;
9143         uint16_t udp_port;
9144         portid_t port_id;
9145 };
9146
9147 static void
9148 cmd_tunnel_udp_config_parsed(void *parsed_result,
9149                           __rte_unused struct cmdline *cl,
9150                           __rte_unused void *data)
9151 {
9152         struct cmd_tunnel_udp_config *res = parsed_result;
9153         struct rte_eth_udp_tunnel tunnel_udp;
9154         int ret;
9155
9156         tunnel_udp.udp_port = res->udp_port;
9157
9158         if (!strcmp(res->cmd, "rx_vxlan_port"))
9159                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9160
9161         if (!strcmp(res->what, "add"))
9162                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9163                                                       &tunnel_udp);
9164         else
9165                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9166                                                          &tunnel_udp);
9167
9168         if (ret < 0)
9169                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9170 }
9171
9172 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9173         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9174                                 cmd, "rx_vxlan_port");
9175 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9176         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9177                                 what, "add#rm");
9178 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9179         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9180                                 udp_port, UINT16);
9181 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9182         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9183                                 port_id, UINT16);
9184
9185 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9186         .f = cmd_tunnel_udp_config_parsed,
9187         .data = (void *)0,
9188         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9189                 "Add/Remove a tunneling UDP port filter",
9190         .tokens = {
9191                 (void *)&cmd_tunnel_udp_config_cmd,
9192                 (void *)&cmd_tunnel_udp_config_what,
9193                 (void *)&cmd_tunnel_udp_config_udp_port,
9194                 (void *)&cmd_tunnel_udp_config_port_id,
9195                 NULL,
9196         },
9197 };
9198
9199 struct cmd_config_tunnel_udp_port {
9200         cmdline_fixed_string_t port;
9201         cmdline_fixed_string_t config;
9202         portid_t port_id;
9203         cmdline_fixed_string_t udp_tunnel_port;
9204         cmdline_fixed_string_t action;
9205         cmdline_fixed_string_t tunnel_type;
9206         uint16_t udp_port;
9207 };
9208
9209 static void
9210 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9211                                __rte_unused struct cmdline *cl,
9212                                __rte_unused void *data)
9213 {
9214         struct cmd_config_tunnel_udp_port *res = parsed_result;
9215         struct rte_eth_udp_tunnel tunnel_udp;
9216         int ret = 0;
9217
9218         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9219                 return;
9220
9221         tunnel_udp.udp_port = res->udp_port;
9222
9223         if (!strcmp(res->tunnel_type, "vxlan")) {
9224                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9225         } else if (!strcmp(res->tunnel_type, "geneve")) {
9226                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9227         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9228                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9229         } else {
9230                 printf("Invalid tunnel type\n");
9231                 return;
9232         }
9233
9234         if (!strcmp(res->action, "add"))
9235                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9236                                                       &tunnel_udp);
9237         else
9238                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9239                                                          &tunnel_udp);
9240
9241         if (ret < 0)
9242                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9243 }
9244
9245 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9246         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9247                                  "port");
9248 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9249         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9250                                  "config");
9251 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9252         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9253                               UINT16);
9254 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9255         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9256                                  udp_tunnel_port,
9257                                  "udp_tunnel_port");
9258 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9259         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9260                                  "add#rm");
9261 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9262         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9263                                  "vxlan#geneve#vxlan-gpe");
9264 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9265         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9266                               UINT16);
9267
9268 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9269         .f = cmd_cfg_tunnel_udp_port_parsed,
9270         .data = NULL,
9271         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9272         .tokens = {
9273                 (void *)&cmd_config_tunnel_udp_port_port,
9274                 (void *)&cmd_config_tunnel_udp_port_config,
9275                 (void *)&cmd_config_tunnel_udp_port_port_id,
9276                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9277                 (void *)&cmd_config_tunnel_udp_port_action,
9278                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9279                 (void *)&cmd_config_tunnel_udp_port_value,
9280                 NULL,
9281         },
9282 };
9283
9284 /* *** GLOBAL CONFIG *** */
9285 struct cmd_global_config_result {
9286         cmdline_fixed_string_t cmd;
9287         portid_t port_id;
9288         cmdline_fixed_string_t cfg_type;
9289         uint8_t len;
9290 };
9291
9292 static void
9293 cmd_global_config_parsed(void *parsed_result,
9294                          __rte_unused struct cmdline *cl,
9295                          __rte_unused void *data)
9296 {
9297         struct cmd_global_config_result *res = parsed_result;
9298         struct rte_eth_global_cfg conf;
9299         int ret;
9300
9301         memset(&conf, 0, sizeof(conf));
9302         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9303         conf.cfg.gre_key_len = res->len;
9304         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9305                                       RTE_ETH_FILTER_SET, &conf);
9306 #ifdef RTE_LIBRTE_I40E_PMD
9307         if (ret == -ENOTSUP)
9308                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9309 #endif
9310         if (ret != 0)
9311                 printf("Global config error\n");
9312 }
9313
9314 cmdline_parse_token_string_t cmd_global_config_cmd =
9315         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9316                 "global_config");
9317 cmdline_parse_token_num_t cmd_global_config_port_id =
9318         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9319                                UINT16);
9320 cmdline_parse_token_string_t cmd_global_config_type =
9321         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9322                 cfg_type, "gre-key-len");
9323 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9324         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9325                 len, UINT8);
9326
9327 cmdline_parse_inst_t cmd_global_config = {
9328         .f = cmd_global_config_parsed,
9329         .data = (void *)NULL,
9330         .help_str = "global_config <port_id> gre-key-len <key_len>",
9331         .tokens = {
9332                 (void *)&cmd_global_config_cmd,
9333                 (void *)&cmd_global_config_port_id,
9334                 (void *)&cmd_global_config_type,
9335                 (void *)&cmd_global_config_gre_key_len,
9336                 NULL,
9337         },
9338 };
9339
9340 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9341 struct cmd_set_mirror_mask_result {
9342         cmdline_fixed_string_t set;
9343         cmdline_fixed_string_t port;
9344         portid_t port_id;
9345         cmdline_fixed_string_t mirror;
9346         uint8_t rule_id;
9347         cmdline_fixed_string_t what;
9348         cmdline_fixed_string_t value;
9349         cmdline_fixed_string_t dstpool;
9350         uint8_t dstpool_id;
9351         cmdline_fixed_string_t on;
9352 };
9353
9354 cmdline_parse_token_string_t cmd_mirror_mask_set =
9355         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9356                                 set, "set");
9357 cmdline_parse_token_string_t cmd_mirror_mask_port =
9358         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9359                                 port, "port");
9360 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9361         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9362                                 port_id, UINT16);
9363 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9364         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9365                                 mirror, "mirror-rule");
9366 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9367         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9368                                 rule_id, UINT8);
9369 cmdline_parse_token_string_t cmd_mirror_mask_what =
9370         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9371                                 what, "pool-mirror-up#pool-mirror-down"
9372                                       "#vlan-mirror");
9373 cmdline_parse_token_string_t cmd_mirror_mask_value =
9374         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9375                                 value, NULL);
9376 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9377         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9378                                 dstpool, "dst-pool");
9379 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9380         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9381                                 dstpool_id, UINT8);
9382 cmdline_parse_token_string_t cmd_mirror_mask_on =
9383         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9384                                 on, "on#off");
9385
9386 static void
9387 cmd_set_mirror_mask_parsed(void *parsed_result,
9388                        __rte_unused struct cmdline *cl,
9389                        __rte_unused void *data)
9390 {
9391         int ret,nb_item,i;
9392         struct cmd_set_mirror_mask_result *res = parsed_result;
9393         struct rte_eth_mirror_conf mr_conf;
9394
9395         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9396
9397         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9398
9399         mr_conf.dst_pool = res->dstpool_id;
9400
9401         if (!strcmp(res->what, "pool-mirror-up")) {
9402                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9403                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9404         } else if (!strcmp(res->what, "pool-mirror-down")) {
9405                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9406                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9407         } else if (!strcmp(res->what, "vlan-mirror")) {
9408                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9409                 nb_item = parse_item_list(res->value, "vlan",
9410                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9411                 if (nb_item <= 0)
9412                         return;
9413
9414                 for (i = 0; i < nb_item; i++) {
9415                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9416                                 printf("Invalid vlan_id: must be < 4096\n");
9417                                 return;
9418                         }
9419
9420                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9421                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9422                 }
9423         }
9424
9425         if (!strcmp(res->on, "on"))
9426                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9427                                                 res->rule_id, 1);
9428         else
9429                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9430                                                 res->rule_id, 0);
9431         if (ret < 0)
9432                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9433 }
9434
9435 cmdline_parse_inst_t cmd_set_mirror_mask = {
9436                 .f = cmd_set_mirror_mask_parsed,
9437                 .data = NULL,
9438                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9439                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9440                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9441                 .tokens = {
9442                         (void *)&cmd_mirror_mask_set,
9443                         (void *)&cmd_mirror_mask_port,
9444                         (void *)&cmd_mirror_mask_portid,
9445                         (void *)&cmd_mirror_mask_mirror,
9446                         (void *)&cmd_mirror_mask_ruleid,
9447                         (void *)&cmd_mirror_mask_what,
9448                         (void *)&cmd_mirror_mask_value,
9449                         (void *)&cmd_mirror_mask_dstpool,
9450                         (void *)&cmd_mirror_mask_poolid,
9451                         (void *)&cmd_mirror_mask_on,
9452                         NULL,
9453                 },
9454 };
9455
9456 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9457 struct cmd_set_mirror_link_result {
9458         cmdline_fixed_string_t set;
9459         cmdline_fixed_string_t port;
9460         portid_t port_id;
9461         cmdline_fixed_string_t mirror;
9462         uint8_t rule_id;
9463         cmdline_fixed_string_t what;
9464         cmdline_fixed_string_t dstpool;
9465         uint8_t dstpool_id;
9466         cmdline_fixed_string_t on;
9467 };
9468
9469 cmdline_parse_token_string_t cmd_mirror_link_set =
9470         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9471                                  set, "set");
9472 cmdline_parse_token_string_t cmd_mirror_link_port =
9473         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9474                                 port, "port");
9475 cmdline_parse_token_num_t cmd_mirror_link_portid =
9476         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9477                                 port_id, UINT16);
9478 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9479         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9480                                 mirror, "mirror-rule");
9481 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9482         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9483                             rule_id, UINT8);
9484 cmdline_parse_token_string_t cmd_mirror_link_what =
9485         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9486                                 what, "uplink-mirror#downlink-mirror");
9487 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9488         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9489                                 dstpool, "dst-pool");
9490 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9491         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9492                                 dstpool_id, UINT8);
9493 cmdline_parse_token_string_t cmd_mirror_link_on =
9494         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9495                                 on, "on#off");
9496
9497 static void
9498 cmd_set_mirror_link_parsed(void *parsed_result,
9499                        __rte_unused struct cmdline *cl,
9500                        __rte_unused void *data)
9501 {
9502         int ret;
9503         struct cmd_set_mirror_link_result *res = parsed_result;
9504         struct rte_eth_mirror_conf mr_conf;
9505
9506         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9507         if (!strcmp(res->what, "uplink-mirror"))
9508                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9509         else
9510                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9511
9512         mr_conf.dst_pool = res->dstpool_id;
9513
9514         if (!strcmp(res->on, "on"))
9515                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9516                                                 res->rule_id, 1);
9517         else
9518                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9519                                                 res->rule_id, 0);
9520
9521         /* check the return value and print it if is < 0 */
9522         if (ret < 0)
9523                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9524
9525 }
9526
9527 cmdline_parse_inst_t cmd_set_mirror_link = {
9528                 .f = cmd_set_mirror_link_parsed,
9529                 .data = NULL,
9530                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9531                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9532                 .tokens = {
9533                         (void *)&cmd_mirror_link_set,
9534                         (void *)&cmd_mirror_link_port,
9535                         (void *)&cmd_mirror_link_portid,
9536                         (void *)&cmd_mirror_link_mirror,
9537                         (void *)&cmd_mirror_link_ruleid,
9538                         (void *)&cmd_mirror_link_what,
9539                         (void *)&cmd_mirror_link_dstpool,
9540                         (void *)&cmd_mirror_link_poolid,
9541                         (void *)&cmd_mirror_link_on,
9542                         NULL,
9543                 },
9544 };
9545
9546 /* *** RESET VM MIRROR RULE *** */
9547 struct cmd_rm_mirror_rule_result {
9548         cmdline_fixed_string_t reset;
9549         cmdline_fixed_string_t port;
9550         portid_t port_id;
9551         cmdline_fixed_string_t mirror;
9552         uint8_t rule_id;
9553 };
9554
9555 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9556         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9557                                  reset, "reset");
9558 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9559         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9560                                 port, "port");
9561 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9562         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9563                                 port_id, UINT16);
9564 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9565         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9566                                 mirror, "mirror-rule");
9567 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9568         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9569                                 rule_id, UINT8);
9570
9571 static void
9572 cmd_reset_mirror_rule_parsed(void *parsed_result,
9573                        __rte_unused struct cmdline *cl,
9574                        __rte_unused void *data)
9575 {
9576         int ret;
9577         struct cmd_set_mirror_link_result *res = parsed_result;
9578         /* check rule_id */
9579         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9580         if(ret < 0)
9581                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9582 }
9583
9584 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9585                 .f = cmd_reset_mirror_rule_parsed,
9586                 .data = NULL,
9587                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9588                 .tokens = {
9589                         (void *)&cmd_rm_mirror_rule_reset,
9590                         (void *)&cmd_rm_mirror_rule_port,
9591                         (void *)&cmd_rm_mirror_rule_portid,
9592                         (void *)&cmd_rm_mirror_rule_mirror,
9593                         (void *)&cmd_rm_mirror_rule_ruleid,
9594                         NULL,
9595                 },
9596 };
9597
9598 /* ******************************************************************************** */
9599
9600 struct cmd_dump_result {
9601         cmdline_fixed_string_t dump;
9602 };
9603
9604 static void
9605 dump_struct_sizes(void)
9606 {
9607 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9608         DUMP_SIZE(struct rte_mbuf);
9609         DUMP_SIZE(struct rte_mempool);
9610         DUMP_SIZE(struct rte_ring);
9611 #undef DUMP_SIZE
9612 }
9613
9614
9615 /* Dump the socket memory statistics on console */
9616 static void
9617 dump_socket_mem(FILE *f)
9618 {
9619         struct rte_malloc_socket_stats socket_stats;
9620         unsigned int i;
9621         size_t total = 0;
9622         size_t alloc = 0;
9623         size_t free = 0;
9624         unsigned int n_alloc = 0;
9625         unsigned int n_free = 0;
9626         static size_t last_allocs;
9627         static size_t last_total;
9628
9629
9630         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9631                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9632                     !socket_stats.heap_totalsz_bytes)
9633                         continue;
9634                 total += socket_stats.heap_totalsz_bytes;
9635                 alloc += socket_stats.heap_allocsz_bytes;
9636                 free += socket_stats.heap_freesz_bytes;
9637                 n_alloc += socket_stats.alloc_count;
9638                 n_free += socket_stats.free_count;
9639                 fprintf(f,
9640                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9641                         i,
9642                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9643                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9644                         (double)socket_stats.heap_allocsz_bytes * 100 /
9645                         (double)socket_stats.heap_totalsz_bytes,
9646                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9647                         socket_stats.alloc_count,
9648                         socket_stats.free_count);
9649         }
9650         fprintf(f,
9651                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9652                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9653                 (double)alloc * 100 / (double)total,
9654                 (double)free / (1024 * 1024),
9655                 n_alloc, n_free);
9656         if (last_allocs)
9657                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9658                         ((double)total - (double)last_total) / (1024 * 1024),
9659                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9660         last_allocs = alloc;
9661         last_total = total;
9662 }
9663
9664 static void cmd_dump_parsed(void *parsed_result,
9665                             __rte_unused struct cmdline *cl,
9666                             __rte_unused void *data)
9667 {
9668         struct cmd_dump_result *res = parsed_result;
9669
9670         if (!strcmp(res->dump, "dump_physmem"))
9671                 rte_dump_physmem_layout(stdout);
9672         else if (!strcmp(res->dump, "dump_socket_mem"))
9673                 dump_socket_mem(stdout);
9674         else if (!strcmp(res->dump, "dump_memzone"))
9675                 rte_memzone_dump(stdout);
9676         else if (!strcmp(res->dump, "dump_struct_sizes"))
9677                 dump_struct_sizes();
9678         else if (!strcmp(res->dump, "dump_ring"))
9679                 rte_ring_list_dump(stdout);
9680         else if (!strcmp(res->dump, "dump_mempool"))
9681                 rte_mempool_list_dump(stdout);
9682         else if (!strcmp(res->dump, "dump_devargs"))
9683                 rte_devargs_dump(stdout);
9684         else if (!strcmp(res->dump, "dump_log_types"))
9685                 rte_log_dump(stdout);
9686 }
9687
9688 cmdline_parse_token_string_t cmd_dump_dump =
9689         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9690                 "dump_physmem#"
9691                 "dump_memzone#"
9692                 "dump_socket_mem#"
9693                 "dump_struct_sizes#"
9694                 "dump_ring#"
9695                 "dump_mempool#"
9696                 "dump_devargs#"
9697                 "dump_log_types");
9698
9699 cmdline_parse_inst_t cmd_dump = {
9700         .f = cmd_dump_parsed,  /* function to call */
9701         .data = NULL,      /* 2nd arg of func */
9702         .help_str = "Dump status",
9703         .tokens = {        /* token list, NULL terminated */
9704                 (void *)&cmd_dump_dump,
9705                 NULL,
9706         },
9707 };
9708
9709 /* ******************************************************************************** */
9710
9711 struct cmd_dump_one_result {
9712         cmdline_fixed_string_t dump;
9713         cmdline_fixed_string_t name;
9714 };
9715
9716 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9717                                 __rte_unused void *data)
9718 {
9719         struct cmd_dump_one_result *res = parsed_result;
9720
9721         if (!strcmp(res->dump, "dump_ring")) {
9722                 struct rte_ring *r;
9723                 r = rte_ring_lookup(res->name);
9724                 if (r == NULL) {
9725                         cmdline_printf(cl, "Cannot find ring\n");
9726                         return;
9727                 }
9728                 rte_ring_dump(stdout, r);
9729         } else if (!strcmp(res->dump, "dump_mempool")) {
9730                 struct rte_mempool *mp;
9731                 mp = rte_mempool_lookup(res->name);
9732                 if (mp == NULL) {
9733                         cmdline_printf(cl, "Cannot find mempool\n");
9734                         return;
9735                 }
9736                 rte_mempool_dump(stdout, mp);
9737         }
9738 }
9739
9740 cmdline_parse_token_string_t cmd_dump_one_dump =
9741         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9742                                  "dump_ring#dump_mempool");
9743
9744 cmdline_parse_token_string_t cmd_dump_one_name =
9745         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9746
9747 cmdline_parse_inst_t cmd_dump_one = {
9748         .f = cmd_dump_one_parsed,  /* function to call */
9749         .data = NULL,      /* 2nd arg of func */
9750         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9751         .tokens = {        /* token list, NULL terminated */
9752                 (void *)&cmd_dump_one_dump,
9753                 (void *)&cmd_dump_one_name,
9754                 NULL,
9755         },
9756 };
9757
9758 /* *** Add/Del syn filter *** */
9759 struct cmd_syn_filter_result {
9760         cmdline_fixed_string_t filter;
9761         portid_t port_id;
9762         cmdline_fixed_string_t ops;
9763         cmdline_fixed_string_t priority;
9764         cmdline_fixed_string_t high;
9765         cmdline_fixed_string_t queue;
9766         uint16_t queue_id;
9767 };
9768
9769 static void
9770 cmd_syn_filter_parsed(void *parsed_result,
9771                         __rte_unused struct cmdline *cl,
9772                         __rte_unused void *data)
9773 {
9774         struct cmd_syn_filter_result *res = parsed_result;
9775         struct rte_eth_syn_filter syn_filter;
9776         int ret = 0;
9777
9778         ret = rte_eth_dev_filter_supported(res->port_id,
9779                                         RTE_ETH_FILTER_SYN);
9780         if (ret < 0) {
9781                 printf("syn filter is not supported on port %u.\n",
9782                                 res->port_id);
9783                 return;
9784         }
9785
9786         memset(&syn_filter, 0, sizeof(syn_filter));
9787
9788         if (!strcmp(res->ops, "add")) {
9789                 if (!strcmp(res->high, "high"))
9790                         syn_filter.hig_pri = 1;
9791                 else
9792                         syn_filter.hig_pri = 0;
9793
9794                 syn_filter.queue = res->queue_id;
9795                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9796                                                 RTE_ETH_FILTER_SYN,
9797                                                 RTE_ETH_FILTER_ADD,
9798                                                 &syn_filter);
9799         } else
9800                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9801                                                 RTE_ETH_FILTER_SYN,
9802                                                 RTE_ETH_FILTER_DELETE,
9803                                                 &syn_filter);
9804
9805         if (ret < 0)
9806                 printf("syn filter programming error: (%s)\n",
9807                                 strerror(-ret));
9808 }
9809
9810 cmdline_parse_token_string_t cmd_syn_filter_filter =
9811         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9812         filter, "syn_filter");
9813 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9814         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9815         port_id, UINT16);
9816 cmdline_parse_token_string_t cmd_syn_filter_ops =
9817         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9818         ops, "add#del");
9819 cmdline_parse_token_string_t cmd_syn_filter_priority =
9820         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9821                                 priority, "priority");
9822 cmdline_parse_token_string_t cmd_syn_filter_high =
9823         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9824                                 high, "high#low");
9825 cmdline_parse_token_string_t cmd_syn_filter_queue =
9826         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9827                                 queue, "queue");
9828 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9829         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9830                                 queue_id, UINT16);
9831
9832 cmdline_parse_inst_t cmd_syn_filter = {
9833         .f = cmd_syn_filter_parsed,
9834         .data = NULL,
9835         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9836                 "<queue_id>: Add/Delete syn filter",
9837         .tokens = {
9838                 (void *)&cmd_syn_filter_filter,
9839                 (void *)&cmd_syn_filter_port_id,
9840                 (void *)&cmd_syn_filter_ops,
9841                 (void *)&cmd_syn_filter_priority,
9842                 (void *)&cmd_syn_filter_high,
9843                 (void *)&cmd_syn_filter_queue,
9844                 (void *)&cmd_syn_filter_queue_id,
9845                 NULL,
9846         },
9847 };
9848
9849 /* *** queue region set *** */
9850 struct cmd_queue_region_result {
9851         cmdline_fixed_string_t set;
9852         cmdline_fixed_string_t port;
9853         portid_t port_id;
9854         cmdline_fixed_string_t cmd;
9855         cmdline_fixed_string_t region;
9856         uint8_t  region_id;
9857         cmdline_fixed_string_t queue_start_index;
9858         uint8_t  queue_id;
9859         cmdline_fixed_string_t queue_num;
9860         uint8_t  queue_num_value;
9861 };
9862
9863 static void
9864 cmd_queue_region_parsed(void *parsed_result,
9865                         __rte_unused struct cmdline *cl,
9866                         __rte_unused void *data)
9867 {
9868         struct cmd_queue_region_result *res = parsed_result;
9869         int ret = -ENOTSUP;
9870 #ifdef RTE_LIBRTE_I40E_PMD
9871         struct rte_pmd_i40e_queue_region_conf region_conf;
9872         enum rte_pmd_i40e_queue_region_op op_type;
9873 #endif
9874
9875         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9876                 return;
9877
9878 #ifdef RTE_LIBRTE_I40E_PMD
9879         memset(&region_conf, 0, sizeof(region_conf));
9880         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9881         region_conf.region_id = res->region_id;
9882         region_conf.queue_num = res->queue_num_value;
9883         region_conf.queue_start_index = res->queue_id;
9884
9885         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9886                                 op_type, &region_conf);
9887 #endif
9888
9889         switch (ret) {
9890         case 0:
9891                 break;
9892         case -ENOTSUP:
9893                 printf("function not implemented or supported\n");
9894                 break;
9895         default:
9896                 printf("queue region config error: (%s)\n", strerror(-ret));
9897         }
9898 }
9899
9900 cmdline_parse_token_string_t cmd_queue_region_set =
9901 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9902                 set, "set");
9903 cmdline_parse_token_string_t cmd_queue_region_port =
9904         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9905 cmdline_parse_token_num_t cmd_queue_region_port_id =
9906         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9907                                 port_id, UINT16);
9908 cmdline_parse_token_string_t cmd_queue_region_cmd =
9909         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9910                                  cmd, "queue-region");
9911 cmdline_parse_token_string_t cmd_queue_region_id =
9912         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9913                                 region, "region_id");
9914 cmdline_parse_token_num_t cmd_queue_region_index =
9915         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9916                                 region_id, UINT8);
9917 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9918         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9919                                 queue_start_index, "queue_start_index");
9920 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9921         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9922                                 queue_id, UINT8);
9923 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9924         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9925                                 queue_num, "queue_num");
9926 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9927         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9928                                 queue_num_value, UINT8);
9929
9930 cmdline_parse_inst_t cmd_queue_region = {
9931         .f = cmd_queue_region_parsed,
9932         .data = NULL,
9933         .help_str = "set port <port_id> queue-region region_id <value> "
9934                 "queue_start_index <value> queue_num <value>: Set a queue region",
9935         .tokens = {
9936                 (void *)&cmd_queue_region_set,
9937                 (void *)&cmd_queue_region_port,
9938                 (void *)&cmd_queue_region_port_id,
9939                 (void *)&cmd_queue_region_cmd,
9940                 (void *)&cmd_queue_region_id,
9941                 (void *)&cmd_queue_region_index,
9942                 (void *)&cmd_queue_region_queue_start_index,
9943                 (void *)&cmd_queue_region_queue_id,
9944                 (void *)&cmd_queue_region_queue_num,
9945                 (void *)&cmd_queue_region_queue_num_value,
9946                 NULL,
9947         },
9948 };
9949
9950 /* *** queue region and flowtype set *** */
9951 struct cmd_region_flowtype_result {
9952         cmdline_fixed_string_t set;
9953         cmdline_fixed_string_t port;
9954         portid_t port_id;
9955         cmdline_fixed_string_t cmd;
9956         cmdline_fixed_string_t region;
9957         uint8_t  region_id;
9958         cmdline_fixed_string_t flowtype;
9959         uint8_t  flowtype_id;
9960 };
9961
9962 static void
9963 cmd_region_flowtype_parsed(void *parsed_result,
9964                         __rte_unused struct cmdline *cl,
9965                         __rte_unused void *data)
9966 {
9967         struct cmd_region_flowtype_result *res = parsed_result;
9968         int ret = -ENOTSUP;
9969 #ifdef RTE_LIBRTE_I40E_PMD
9970         struct rte_pmd_i40e_queue_region_conf region_conf;
9971         enum rte_pmd_i40e_queue_region_op op_type;
9972 #endif
9973
9974         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9975                 return;
9976
9977 #ifdef RTE_LIBRTE_I40E_PMD
9978         memset(&region_conf, 0, sizeof(region_conf));
9979
9980         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9981         region_conf.region_id = res->region_id;
9982         region_conf.hw_flowtype = res->flowtype_id;
9983
9984         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9985                         op_type, &region_conf);
9986 #endif
9987
9988         switch (ret) {
9989         case 0:
9990                 break;
9991         case -ENOTSUP:
9992                 printf("function not implemented or supported\n");
9993                 break;
9994         default:
9995                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9996         }
9997 }
9998
9999 cmdline_parse_token_string_t cmd_region_flowtype_set =
10000 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10001                                 set, "set");
10002 cmdline_parse_token_string_t cmd_region_flowtype_port =
10003         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10004                                 port, "port");
10005 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10006         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10007                                 port_id, UINT16);
10008 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10009         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10010                                 cmd, "queue-region");
10011 cmdline_parse_token_string_t cmd_region_flowtype_index =
10012         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10013                                 region, "region_id");
10014 cmdline_parse_token_num_t cmd_region_flowtype_id =
10015         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10016                                 region_id, UINT8);
10017 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10018         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10019                                 flowtype, "flowtype");
10020 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10021         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10022                                 flowtype_id, UINT8);
10023 cmdline_parse_inst_t cmd_region_flowtype = {
10024         .f = cmd_region_flowtype_parsed,
10025         .data = NULL,
10026         .help_str = "set port <port_id> queue-region region_id <value> "
10027                 "flowtype <value>: Set a flowtype region index",
10028         .tokens = {
10029                 (void *)&cmd_region_flowtype_set,
10030                 (void *)&cmd_region_flowtype_port,
10031                 (void *)&cmd_region_flowtype_port_index,
10032                 (void *)&cmd_region_flowtype_cmd,
10033                 (void *)&cmd_region_flowtype_index,
10034                 (void *)&cmd_region_flowtype_id,
10035                 (void *)&cmd_region_flowtype_flow_index,
10036                 (void *)&cmd_region_flowtype_flow_id,
10037                 NULL,
10038         },
10039 };
10040
10041 /* *** User Priority (UP) to queue region (region_id) set *** */
10042 struct cmd_user_priority_region_result {
10043         cmdline_fixed_string_t set;
10044         cmdline_fixed_string_t port;
10045         portid_t port_id;
10046         cmdline_fixed_string_t cmd;
10047         cmdline_fixed_string_t user_priority;
10048         uint8_t  user_priority_id;
10049         cmdline_fixed_string_t region;
10050         uint8_t  region_id;
10051 };
10052
10053 static void
10054 cmd_user_priority_region_parsed(void *parsed_result,
10055                         __rte_unused struct cmdline *cl,
10056                         __rte_unused void *data)
10057 {
10058         struct cmd_user_priority_region_result *res = parsed_result;
10059         int ret = -ENOTSUP;
10060 #ifdef RTE_LIBRTE_I40E_PMD
10061         struct rte_pmd_i40e_queue_region_conf region_conf;
10062         enum rte_pmd_i40e_queue_region_op op_type;
10063 #endif
10064
10065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10066                 return;
10067
10068 #ifdef RTE_LIBRTE_I40E_PMD
10069         memset(&region_conf, 0, sizeof(region_conf));
10070         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10071         region_conf.user_priority = res->user_priority_id;
10072         region_conf.region_id = res->region_id;
10073
10074         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10075                                 op_type, &region_conf);
10076 #endif
10077
10078         switch (ret) {
10079         case 0:
10080                 break;
10081         case -ENOTSUP:
10082                 printf("function not implemented or supported\n");
10083                 break;
10084         default:
10085                 printf("user_priority region config error: (%s)\n",
10086                                 strerror(-ret));
10087         }
10088 }
10089
10090 cmdline_parse_token_string_t cmd_user_priority_region_set =
10091         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10092                                 set, "set");
10093 cmdline_parse_token_string_t cmd_user_priority_region_port =
10094         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10095                                 port, "port");
10096 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10097         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10098                                 port_id, UINT16);
10099 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10100         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10101                                 cmd, "queue-region");
10102 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10103         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10104                                 user_priority, "UP");
10105 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10106         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10107                                 user_priority_id, UINT8);
10108 cmdline_parse_token_string_t cmd_user_priority_region_region =
10109         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10110                                 region, "region_id");
10111 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10112         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10113                                 region_id, UINT8);
10114
10115 cmdline_parse_inst_t cmd_user_priority_region = {
10116         .f = cmd_user_priority_region_parsed,
10117         .data = NULL,
10118         .help_str = "set port <port_id> queue-region UP <value> "
10119                 "region_id <value>: Set the mapping of User Priority (UP) "
10120                 "to queue region (region_id) ",
10121         .tokens = {
10122                 (void *)&cmd_user_priority_region_set,
10123                 (void *)&cmd_user_priority_region_port,
10124                 (void *)&cmd_user_priority_region_port_index,
10125                 (void *)&cmd_user_priority_region_cmd,
10126                 (void *)&cmd_user_priority_region_UP,
10127                 (void *)&cmd_user_priority_region_UP_id,
10128                 (void *)&cmd_user_priority_region_region,
10129                 (void *)&cmd_user_priority_region_region_id,
10130                 NULL,
10131         },
10132 };
10133
10134 /* *** flush all queue region related configuration *** */
10135 struct cmd_flush_queue_region_result {
10136         cmdline_fixed_string_t set;
10137         cmdline_fixed_string_t port;
10138         portid_t port_id;
10139         cmdline_fixed_string_t cmd;
10140         cmdline_fixed_string_t flush;
10141         cmdline_fixed_string_t what;
10142 };
10143
10144 static void
10145 cmd_flush_queue_region_parsed(void *parsed_result,
10146                         __rte_unused struct cmdline *cl,
10147                         __rte_unused void *data)
10148 {
10149         struct cmd_flush_queue_region_result *res = parsed_result;
10150         int ret = -ENOTSUP;
10151 #ifdef RTE_LIBRTE_I40E_PMD
10152         struct rte_pmd_i40e_queue_region_conf region_conf;
10153         enum rte_pmd_i40e_queue_region_op op_type;
10154 #endif
10155
10156         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10157                 return;
10158
10159 #ifdef RTE_LIBRTE_I40E_PMD
10160         memset(&region_conf, 0, sizeof(region_conf));
10161
10162         if (strcmp(res->what, "on") == 0)
10163                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10164         else
10165                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10166
10167         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10168                                 op_type, &region_conf);
10169 #endif
10170
10171         switch (ret) {
10172         case 0:
10173                 break;
10174         case -ENOTSUP:
10175                 printf("function not implemented or supported\n");
10176                 break;
10177         default:
10178                 printf("queue region config flush error: (%s)\n",
10179                                 strerror(-ret));
10180         }
10181 }
10182
10183 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10184         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10185                                 set, "set");
10186 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10187         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10188                                 port, "port");
10189 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10190         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10191                                 port_id, UINT16);
10192 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10193         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10194                                 cmd, "queue-region");
10195 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10197                                 flush, "flush");
10198 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10200                                 what, "on#off");
10201
10202 cmdline_parse_inst_t cmd_flush_queue_region = {
10203         .f = cmd_flush_queue_region_parsed,
10204         .data = NULL,
10205         .help_str = "set port <port_id> queue-region flush on|off"
10206                 ": flush all queue region related configuration",
10207         .tokens = {
10208                 (void *)&cmd_flush_queue_region_set,
10209                 (void *)&cmd_flush_queue_region_port,
10210                 (void *)&cmd_flush_queue_region_port_index,
10211                 (void *)&cmd_flush_queue_region_cmd,
10212                 (void *)&cmd_flush_queue_region_flush,
10213                 (void *)&cmd_flush_queue_region_what,
10214                 NULL,
10215         },
10216 };
10217
10218 /* *** get all queue region related configuration info *** */
10219 struct cmd_show_queue_region_info {
10220         cmdline_fixed_string_t show;
10221         cmdline_fixed_string_t port;
10222         portid_t port_id;
10223         cmdline_fixed_string_t cmd;
10224 };
10225
10226 static void
10227 cmd_show_queue_region_info_parsed(void *parsed_result,
10228                         __rte_unused struct cmdline *cl,
10229                         __rte_unused void *data)
10230 {
10231         struct cmd_show_queue_region_info *res = parsed_result;
10232         int ret = -ENOTSUP;
10233 #ifdef RTE_LIBRTE_I40E_PMD
10234         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10235         enum rte_pmd_i40e_queue_region_op op_type;
10236 #endif
10237
10238         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10239                 return;
10240
10241 #ifdef RTE_LIBRTE_I40E_PMD
10242         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10243
10244         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10245
10246         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10247                                         op_type, &rte_pmd_regions);
10248
10249         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10250 #endif
10251
10252         switch (ret) {
10253         case 0:
10254                 break;
10255         case -ENOTSUP:
10256                 printf("function not implemented or supported\n");
10257                 break;
10258         default:
10259                 printf("queue region config info show error: (%s)\n",
10260                                 strerror(-ret));
10261         }
10262 }
10263
10264 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10265 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10266                                 show, "show");
10267 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10268         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10269                                 port, "port");
10270 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10271         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10272                                 port_id, UINT16);
10273 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10274         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10275                                 cmd, "queue-region");
10276
10277 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10278         .f = cmd_show_queue_region_info_parsed,
10279         .data = NULL,
10280         .help_str = "show port <port_id> queue-region"
10281                 ": show all queue region related configuration info",
10282         .tokens = {
10283                 (void *)&cmd_show_queue_region_info_get,
10284                 (void *)&cmd_show_queue_region_info_port,
10285                 (void *)&cmd_show_queue_region_info_port_index,
10286                 (void *)&cmd_show_queue_region_info_cmd,
10287                 NULL,
10288         },
10289 };
10290
10291 /* *** ADD/REMOVE A 2tuple FILTER *** */
10292 struct cmd_2tuple_filter_result {
10293         cmdline_fixed_string_t filter;
10294         portid_t port_id;
10295         cmdline_fixed_string_t ops;
10296         cmdline_fixed_string_t dst_port;
10297         uint16_t dst_port_value;
10298         cmdline_fixed_string_t protocol;
10299         uint8_t protocol_value;
10300         cmdline_fixed_string_t mask;
10301         uint8_t  mask_value;
10302         cmdline_fixed_string_t tcp_flags;
10303         uint8_t tcp_flags_value;
10304         cmdline_fixed_string_t priority;
10305         uint8_t  priority_value;
10306         cmdline_fixed_string_t queue;
10307         uint16_t  queue_id;
10308 };
10309
10310 static void
10311 cmd_2tuple_filter_parsed(void *parsed_result,
10312                         __rte_unused struct cmdline *cl,
10313                         __rte_unused void *data)
10314 {
10315         struct rte_eth_ntuple_filter filter;
10316         struct cmd_2tuple_filter_result *res = parsed_result;
10317         int ret = 0;
10318
10319         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10320         if (ret < 0) {
10321                 printf("ntuple filter is not supported on port %u.\n",
10322                         res->port_id);
10323                 return;
10324         }
10325
10326         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10327
10328         filter.flags = RTE_2TUPLE_FLAGS;
10329         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10330         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10331         filter.proto = res->protocol_value;
10332         filter.priority = res->priority_value;
10333         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10334                 printf("nonzero tcp_flags is only meaningful"
10335                         " when protocol is TCP.\n");
10336                 return;
10337         }
10338         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10339                 printf("invalid TCP flags.\n");
10340                 return;
10341         }
10342
10343         if (res->tcp_flags_value != 0) {
10344                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10345                 filter.tcp_flags = res->tcp_flags_value;
10346         }
10347
10348         /* need convert to big endian. */
10349         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10350         filter.queue = res->queue_id;
10351
10352         if (!strcmp(res->ops, "add"))
10353                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10354                                 RTE_ETH_FILTER_NTUPLE,
10355                                 RTE_ETH_FILTER_ADD,
10356                                 &filter);
10357         else
10358                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10359                                 RTE_ETH_FILTER_NTUPLE,
10360                                 RTE_ETH_FILTER_DELETE,
10361                                 &filter);
10362         if (ret < 0)
10363                 printf("2tuple filter programming error: (%s)\n",
10364                         strerror(-ret));
10365
10366 }
10367
10368 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10369         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10370                                  filter, "2tuple_filter");
10371 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10372         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10373                                 port_id, UINT16);
10374 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10375         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10376                                  ops, "add#del");
10377 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10378         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10379                                 dst_port, "dst_port");
10380 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10381         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10382                                 dst_port_value, UINT16);
10383 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10384         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10385                                 protocol, "protocol");
10386 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10387         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10388                                 protocol_value, UINT8);
10389 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10390         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10391                                 mask, "mask");
10392 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10393         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10394                                 mask_value, INT8);
10395 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10396         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10397                                 tcp_flags, "tcp_flags");
10398 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10399         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10400                                 tcp_flags_value, UINT8);
10401 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10402         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10403                                 priority, "priority");
10404 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10405         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10406                                 priority_value, UINT8);
10407 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10408         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10409                                 queue, "queue");
10410 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10411         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10412                                 queue_id, UINT16);
10413
10414 cmdline_parse_inst_t cmd_2tuple_filter = {
10415         .f = cmd_2tuple_filter_parsed,
10416         .data = NULL,
10417         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10418                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10419                 "<queue_id>: Add a 2tuple filter",
10420         .tokens = {
10421                 (void *)&cmd_2tuple_filter_filter,
10422                 (void *)&cmd_2tuple_filter_port_id,
10423                 (void *)&cmd_2tuple_filter_ops,
10424                 (void *)&cmd_2tuple_filter_dst_port,
10425                 (void *)&cmd_2tuple_filter_dst_port_value,
10426                 (void *)&cmd_2tuple_filter_protocol,
10427                 (void *)&cmd_2tuple_filter_protocol_value,
10428                 (void *)&cmd_2tuple_filter_mask,
10429                 (void *)&cmd_2tuple_filter_mask_value,
10430                 (void *)&cmd_2tuple_filter_tcp_flags,
10431                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10432                 (void *)&cmd_2tuple_filter_priority,
10433                 (void *)&cmd_2tuple_filter_priority_value,
10434                 (void *)&cmd_2tuple_filter_queue,
10435                 (void *)&cmd_2tuple_filter_queue_id,
10436                 NULL,
10437         },
10438 };
10439
10440 /* *** ADD/REMOVE A 5tuple FILTER *** */
10441 struct cmd_5tuple_filter_result {
10442         cmdline_fixed_string_t filter;
10443         portid_t port_id;
10444         cmdline_fixed_string_t ops;
10445         cmdline_fixed_string_t dst_ip;
10446         cmdline_ipaddr_t dst_ip_value;
10447         cmdline_fixed_string_t src_ip;
10448         cmdline_ipaddr_t src_ip_value;
10449         cmdline_fixed_string_t dst_port;
10450         uint16_t dst_port_value;
10451         cmdline_fixed_string_t src_port;
10452         uint16_t src_port_value;
10453         cmdline_fixed_string_t protocol;
10454         uint8_t protocol_value;
10455         cmdline_fixed_string_t mask;
10456         uint8_t  mask_value;
10457         cmdline_fixed_string_t tcp_flags;
10458         uint8_t tcp_flags_value;
10459         cmdline_fixed_string_t priority;
10460         uint8_t  priority_value;
10461         cmdline_fixed_string_t queue;
10462         uint16_t  queue_id;
10463 };
10464
10465 static void
10466 cmd_5tuple_filter_parsed(void *parsed_result,
10467                         __rte_unused struct cmdline *cl,
10468                         __rte_unused void *data)
10469 {
10470         struct rte_eth_ntuple_filter filter;
10471         struct cmd_5tuple_filter_result *res = parsed_result;
10472         int ret = 0;
10473
10474         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10475         if (ret < 0) {
10476                 printf("ntuple filter is not supported on port %u.\n",
10477                         res->port_id);
10478                 return;
10479         }
10480
10481         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10482
10483         filter.flags = RTE_5TUPLE_FLAGS;
10484         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10485         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10486         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10487         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10488         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10489         filter.proto = res->protocol_value;
10490         filter.priority = res->priority_value;
10491         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10492                 printf("nonzero tcp_flags is only meaningful"
10493                         " when protocol is TCP.\n");
10494                 return;
10495         }
10496         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10497                 printf("invalid TCP flags.\n");
10498                 return;
10499         }
10500
10501         if (res->tcp_flags_value != 0) {
10502                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10503                 filter.tcp_flags = res->tcp_flags_value;
10504         }
10505
10506         if (res->dst_ip_value.family == AF_INET)
10507                 /* no need to convert, already big endian. */
10508                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10509         else {
10510                 if (filter.dst_ip_mask == 0) {
10511                         printf("can not support ipv6 involved compare.\n");
10512                         return;
10513                 }
10514                 filter.dst_ip = 0;
10515         }
10516
10517         if (res->src_ip_value.family == AF_INET)
10518                 /* no need to convert, already big endian. */
10519                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10520         else {
10521                 if (filter.src_ip_mask == 0) {
10522                         printf("can not support ipv6 involved compare.\n");
10523                         return;
10524                 }
10525                 filter.src_ip = 0;
10526         }
10527         /* need convert to big endian. */
10528         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10529         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10530         filter.queue = res->queue_id;
10531
10532         if (!strcmp(res->ops, "add"))
10533                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10534                                 RTE_ETH_FILTER_NTUPLE,
10535                                 RTE_ETH_FILTER_ADD,
10536                                 &filter);
10537         else
10538                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10539                                 RTE_ETH_FILTER_NTUPLE,
10540                                 RTE_ETH_FILTER_DELETE,
10541                                 &filter);
10542         if (ret < 0)
10543                 printf("5tuple filter programming error: (%s)\n",
10544                         strerror(-ret));
10545 }
10546
10547 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10548         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10549                                  filter, "5tuple_filter");
10550 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10551         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10552                                 port_id, UINT16);
10553 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10554         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10555                                  ops, "add#del");
10556 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10557         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10558                                 dst_ip, "dst_ip");
10559 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10560         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10561                                 dst_ip_value);
10562 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10563         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10564                                 src_ip, "src_ip");
10565 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10566         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10567                                 src_ip_value);
10568 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10569         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10570                                 dst_port, "dst_port");
10571 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10572         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10573                                 dst_port_value, UINT16);
10574 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10575         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10576                                 src_port, "src_port");
10577 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10578         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10579                                 src_port_value, UINT16);
10580 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10581         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10582                                 protocol, "protocol");
10583 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10584         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10585                                 protocol_value, UINT8);
10586 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10587         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10588                                 mask, "mask");
10589 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10590         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10591                                 mask_value, INT8);
10592 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10593         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10594                                 tcp_flags, "tcp_flags");
10595 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10596         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10597                                 tcp_flags_value, UINT8);
10598 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10599         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10600                                 priority, "priority");
10601 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10602         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10603                                 priority_value, UINT8);
10604 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10605         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10606                                 queue, "queue");
10607 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10608         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10609                                 queue_id, UINT16);
10610
10611 cmdline_parse_inst_t cmd_5tuple_filter = {
10612         .f = cmd_5tuple_filter_parsed,
10613         .data = NULL,
10614         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10615                 "src_ip <value> dst_port <value> src_port <value> "
10616                 "protocol <value>  mask <value> tcp_flags <value> "
10617                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10618         .tokens = {
10619                 (void *)&cmd_5tuple_filter_filter,
10620                 (void *)&cmd_5tuple_filter_port_id,
10621                 (void *)&cmd_5tuple_filter_ops,
10622                 (void *)&cmd_5tuple_filter_dst_ip,
10623                 (void *)&cmd_5tuple_filter_dst_ip_value,
10624                 (void *)&cmd_5tuple_filter_src_ip,
10625                 (void *)&cmd_5tuple_filter_src_ip_value,
10626                 (void *)&cmd_5tuple_filter_dst_port,
10627                 (void *)&cmd_5tuple_filter_dst_port_value,
10628                 (void *)&cmd_5tuple_filter_src_port,
10629                 (void *)&cmd_5tuple_filter_src_port_value,
10630                 (void *)&cmd_5tuple_filter_protocol,
10631                 (void *)&cmd_5tuple_filter_protocol_value,
10632                 (void *)&cmd_5tuple_filter_mask,
10633                 (void *)&cmd_5tuple_filter_mask_value,
10634                 (void *)&cmd_5tuple_filter_tcp_flags,
10635                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10636                 (void *)&cmd_5tuple_filter_priority,
10637                 (void *)&cmd_5tuple_filter_priority_value,
10638                 (void *)&cmd_5tuple_filter_queue,
10639                 (void *)&cmd_5tuple_filter_queue_id,
10640                 NULL,
10641         },
10642 };
10643
10644 /* *** ADD/REMOVE A flex FILTER *** */
10645 struct cmd_flex_filter_result {
10646         cmdline_fixed_string_t filter;
10647         cmdline_fixed_string_t ops;
10648         portid_t port_id;
10649         cmdline_fixed_string_t len;
10650         uint8_t len_value;
10651         cmdline_fixed_string_t bytes;
10652         cmdline_fixed_string_t bytes_value;
10653         cmdline_fixed_string_t mask;
10654         cmdline_fixed_string_t mask_value;
10655         cmdline_fixed_string_t priority;
10656         uint8_t priority_value;
10657         cmdline_fixed_string_t queue;
10658         uint16_t queue_id;
10659 };
10660
10661 static int xdigit2val(unsigned char c)
10662 {
10663         int val;
10664         if (isdigit(c))
10665                 val = c - '0';
10666         else if (isupper(c))
10667                 val = c - 'A' + 10;
10668         else
10669                 val = c - 'a' + 10;
10670         return val;
10671 }
10672
10673 static void
10674 cmd_flex_filter_parsed(void *parsed_result,
10675                           __rte_unused struct cmdline *cl,
10676                           __rte_unused void *data)
10677 {
10678         int ret = 0;
10679         struct rte_eth_flex_filter filter;
10680         struct cmd_flex_filter_result *res = parsed_result;
10681         char *bytes_ptr, *mask_ptr;
10682         uint16_t len, i, j = 0;
10683         char c;
10684         int val;
10685         uint8_t byte = 0;
10686
10687         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10688                 printf("the len exceed the max length 128\n");
10689                 return;
10690         }
10691         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10692         filter.len = res->len_value;
10693         filter.priority = res->priority_value;
10694         filter.queue = res->queue_id;
10695         bytes_ptr = res->bytes_value;
10696         mask_ptr = res->mask_value;
10697
10698          /* translate bytes string to array. */
10699         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10700                 (bytes_ptr[1] == 'X')))
10701                 bytes_ptr += 2;
10702         len = strnlen(bytes_ptr, res->len_value * 2);
10703         if (len == 0 || (len % 8 != 0)) {
10704                 printf("please check len and bytes input\n");
10705                 return;
10706         }
10707         for (i = 0; i < len; i++) {
10708                 c = bytes_ptr[i];
10709                 if (isxdigit(c) == 0) {
10710                         /* invalid characters. */
10711                         printf("invalid input\n");
10712                         return;
10713                 }
10714                 val = xdigit2val(c);
10715                 if (i % 2) {
10716                         byte |= val;
10717                         filter.bytes[j] = byte;
10718                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10719                         j++;
10720                         byte = 0;
10721                 } else
10722                         byte |= val << 4;
10723         }
10724         printf("\n");
10725          /* translate mask string to uint8_t array. */
10726         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10727                 (mask_ptr[1] == 'X')))
10728                 mask_ptr += 2;
10729         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10730         if (len == 0) {
10731                 printf("invalid input\n");
10732                 return;
10733         }
10734         j = 0;
10735         byte = 0;
10736         for (i = 0; i < len; i++) {
10737                 c = mask_ptr[i];
10738                 if (isxdigit(c) == 0) {
10739                         /* invalid characters. */
10740                         printf("invalid input\n");
10741                         return;
10742                 }
10743                 val = xdigit2val(c);
10744                 if (i % 2) {
10745                         byte |= val;
10746                         filter.mask[j] = byte;
10747                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10748                         j++;
10749                         byte = 0;
10750                 } else
10751                         byte |= val << 4;
10752         }
10753         printf("\n");
10754
10755         if (!strcmp(res->ops, "add"))
10756                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10757                                 RTE_ETH_FILTER_FLEXIBLE,
10758                                 RTE_ETH_FILTER_ADD,
10759                                 &filter);
10760         else
10761                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10762                                 RTE_ETH_FILTER_FLEXIBLE,
10763                                 RTE_ETH_FILTER_DELETE,
10764                                 &filter);
10765
10766         if (ret < 0)
10767                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10768 }
10769
10770 cmdline_parse_token_string_t cmd_flex_filter_filter =
10771         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10772                                 filter, "flex_filter");
10773 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10774         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10775                                 port_id, UINT16);
10776 cmdline_parse_token_string_t cmd_flex_filter_ops =
10777         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10778                                 ops, "add#del");
10779 cmdline_parse_token_string_t cmd_flex_filter_len =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10781                                 len, "len");
10782 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10783         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10784                                 len_value, UINT8);
10785 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10786         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10787                                 bytes, "bytes");
10788 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10789         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10790                                 bytes_value, NULL);
10791 cmdline_parse_token_string_t cmd_flex_filter_mask =
10792         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10793                                 mask, "mask");
10794 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10795         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10796                                 mask_value, NULL);
10797 cmdline_parse_token_string_t cmd_flex_filter_priority =
10798         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10799                                 priority, "priority");
10800 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10801         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10802                                 priority_value, UINT8);
10803 cmdline_parse_token_string_t cmd_flex_filter_queue =
10804         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10805                                 queue, "queue");
10806 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10807         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10808                                 queue_id, UINT16);
10809 cmdline_parse_inst_t cmd_flex_filter = {
10810         .f = cmd_flex_filter_parsed,
10811         .data = NULL,
10812         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10813                 "<value> mask <value> priority <value> queue <queue_id>: "
10814                 "Add/Del a flex filter",
10815         .tokens = {
10816                 (void *)&cmd_flex_filter_filter,
10817                 (void *)&cmd_flex_filter_port_id,
10818                 (void *)&cmd_flex_filter_ops,
10819                 (void *)&cmd_flex_filter_len,
10820                 (void *)&cmd_flex_filter_len_value,
10821                 (void *)&cmd_flex_filter_bytes,
10822                 (void *)&cmd_flex_filter_bytes_value,
10823                 (void *)&cmd_flex_filter_mask,
10824                 (void *)&cmd_flex_filter_mask_value,
10825                 (void *)&cmd_flex_filter_priority,
10826                 (void *)&cmd_flex_filter_priority_value,
10827                 (void *)&cmd_flex_filter_queue,
10828                 (void *)&cmd_flex_filter_queue_id,
10829                 NULL,
10830         },
10831 };
10832
10833 /* *** Filters Control *** */
10834
10835 /* *** deal with ethertype filter *** */
10836 struct cmd_ethertype_filter_result {
10837         cmdline_fixed_string_t filter;
10838         portid_t port_id;
10839         cmdline_fixed_string_t ops;
10840         cmdline_fixed_string_t mac;
10841         struct rte_ether_addr mac_addr;
10842         cmdline_fixed_string_t ethertype;
10843         uint16_t ethertype_value;
10844         cmdline_fixed_string_t drop;
10845         cmdline_fixed_string_t queue;
10846         uint16_t  queue_id;
10847 };
10848
10849 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10850         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10851                                  filter, "ethertype_filter");
10852 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10853         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10854                               port_id, UINT16);
10855 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10856         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10857                                  ops, "add#del");
10858 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10859         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10860                                  mac, "mac_addr#mac_ignr");
10861 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10862         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10863                                      mac_addr);
10864 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10865         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10866                                  ethertype, "ethertype");
10867 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10868         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10869                               ethertype_value, UINT16);
10870 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10871         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10872                                  drop, "drop#fwd");
10873 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10874         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10875                                  queue, "queue");
10876 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10877         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10878                               queue_id, UINT16);
10879
10880 static void
10881 cmd_ethertype_filter_parsed(void *parsed_result,
10882                           __rte_unused struct cmdline *cl,
10883                           __rte_unused void *data)
10884 {
10885         struct cmd_ethertype_filter_result *res = parsed_result;
10886         struct rte_eth_ethertype_filter filter;
10887         int ret = 0;
10888
10889         ret = rte_eth_dev_filter_supported(res->port_id,
10890                         RTE_ETH_FILTER_ETHERTYPE);
10891         if (ret < 0) {
10892                 printf("ethertype filter is not supported on port %u.\n",
10893                         res->port_id);
10894                 return;
10895         }
10896
10897         memset(&filter, 0, sizeof(filter));
10898         if (!strcmp(res->mac, "mac_addr")) {
10899                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10900                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10901                         sizeof(struct rte_ether_addr));
10902         }
10903         if (!strcmp(res->drop, "drop"))
10904                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10905         filter.ether_type = res->ethertype_value;
10906         filter.queue = res->queue_id;
10907
10908         if (!strcmp(res->ops, "add"))
10909                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10910                                 RTE_ETH_FILTER_ETHERTYPE,
10911                                 RTE_ETH_FILTER_ADD,
10912                                 &filter);
10913         else
10914                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10915                                 RTE_ETH_FILTER_ETHERTYPE,
10916                                 RTE_ETH_FILTER_DELETE,
10917                                 &filter);
10918         if (ret < 0)
10919                 printf("ethertype filter programming error: (%s)\n",
10920                         strerror(-ret));
10921 }
10922
10923 cmdline_parse_inst_t cmd_ethertype_filter = {
10924         .f = cmd_ethertype_filter_parsed,
10925         .data = NULL,
10926         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10927                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10928                 "Add or delete an ethertype filter entry",
10929         .tokens = {
10930                 (void *)&cmd_ethertype_filter_filter,
10931                 (void *)&cmd_ethertype_filter_port_id,
10932                 (void *)&cmd_ethertype_filter_ops,
10933                 (void *)&cmd_ethertype_filter_mac,
10934                 (void *)&cmd_ethertype_filter_mac_addr,
10935                 (void *)&cmd_ethertype_filter_ethertype,
10936                 (void *)&cmd_ethertype_filter_ethertype_value,
10937                 (void *)&cmd_ethertype_filter_drop,
10938                 (void *)&cmd_ethertype_filter_queue,
10939                 (void *)&cmd_ethertype_filter_queue_id,
10940                 NULL,
10941         },
10942 };
10943
10944 /* *** deal with flow director filter *** */
10945 struct cmd_flow_director_result {
10946         cmdline_fixed_string_t flow_director_filter;
10947         portid_t port_id;
10948         cmdline_fixed_string_t mode;
10949         cmdline_fixed_string_t mode_value;
10950         cmdline_fixed_string_t ops;
10951         cmdline_fixed_string_t flow;
10952         cmdline_fixed_string_t flow_type;
10953         cmdline_fixed_string_t ether;
10954         uint16_t ether_type;
10955         cmdline_fixed_string_t src;
10956         cmdline_ipaddr_t ip_src;
10957         uint16_t port_src;
10958         cmdline_fixed_string_t dst;
10959         cmdline_ipaddr_t ip_dst;
10960         uint16_t port_dst;
10961         cmdline_fixed_string_t verify_tag;
10962         uint32_t verify_tag_value;
10963         cmdline_fixed_string_t tos;
10964         uint8_t tos_value;
10965         cmdline_fixed_string_t proto;
10966         uint8_t proto_value;
10967         cmdline_fixed_string_t ttl;
10968         uint8_t ttl_value;
10969         cmdline_fixed_string_t vlan;
10970         uint16_t vlan_value;
10971         cmdline_fixed_string_t flexbytes;
10972         cmdline_fixed_string_t flexbytes_value;
10973         cmdline_fixed_string_t pf_vf;
10974         cmdline_fixed_string_t drop;
10975         cmdline_fixed_string_t queue;
10976         uint16_t  queue_id;
10977         cmdline_fixed_string_t fd_id;
10978         uint32_t  fd_id_value;
10979         cmdline_fixed_string_t mac;
10980         struct rte_ether_addr mac_addr;
10981         cmdline_fixed_string_t tunnel;
10982         cmdline_fixed_string_t tunnel_type;
10983         cmdline_fixed_string_t tunnel_id;
10984         uint32_t tunnel_id_value;
10985         cmdline_fixed_string_t packet;
10986         char filepath[];
10987 };
10988
10989 static inline int
10990 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10991 {
10992         char s[256];
10993         const char *p, *p0 = q_arg;
10994         char *end;
10995         unsigned long int_fld;
10996         char *str_fld[max_num];
10997         int i;
10998         unsigned size;
10999         int ret = -1;
11000
11001         p = strchr(p0, '(');
11002         if (p == NULL)
11003                 return -1;
11004         ++p;
11005         p0 = strchr(p, ')');
11006         if (p0 == NULL)
11007                 return -1;
11008
11009         size = p0 - p;
11010         if (size >= sizeof(s))
11011                 return -1;
11012
11013         snprintf(s, sizeof(s), "%.*s", size, p);
11014         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11015         if (ret < 0 || ret > max_num)
11016                 return -1;
11017         for (i = 0; i < ret; i++) {
11018                 errno = 0;
11019                 int_fld = strtoul(str_fld[i], &end, 0);
11020                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11021                         return -1;
11022                 flexbytes[i] = (uint8_t)int_fld;
11023         }
11024         return ret;
11025 }
11026
11027 static uint16_t
11028 str2flowtype(char *string)
11029 {
11030         uint8_t i = 0;
11031         static const struct {
11032                 char str[32];
11033                 uint16_t type;
11034         } flowtype_str[] = {
11035                 {"raw", RTE_ETH_FLOW_RAW},
11036                 {"ipv4", RTE_ETH_FLOW_IPV4},
11037                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11038                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11039                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11040                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11041                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11042                 {"ipv6", RTE_ETH_FLOW_IPV6},
11043                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11044                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11045                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11046                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11047                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11048                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11049         };
11050
11051         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11052                 if (!strcmp(flowtype_str[i].str, string))
11053                         return flowtype_str[i].type;
11054         }
11055
11056         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11057                 return (uint16_t)atoi(string);
11058
11059         return RTE_ETH_FLOW_UNKNOWN;
11060 }
11061
11062 static enum rte_eth_fdir_tunnel_type
11063 str2fdir_tunneltype(char *string)
11064 {
11065         uint8_t i = 0;
11066
11067         static const struct {
11068                 char str[32];
11069                 enum rte_eth_fdir_tunnel_type type;
11070         } tunneltype_str[] = {
11071                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11072                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11073         };
11074
11075         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11076                 if (!strcmp(tunneltype_str[i].str, string))
11077                         return tunneltype_str[i].type;
11078         }
11079         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11080 }
11081
11082 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11083 do { \
11084         if ((ip_addr).family == AF_INET) \
11085                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11086         else { \
11087                 printf("invalid parameter.\n"); \
11088                 return; \
11089         } \
11090 } while (0)
11091
11092 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11093 do { \
11094         if ((ip_addr).family == AF_INET6) \
11095                 rte_memcpy(&(ip), \
11096                                  &((ip_addr).addr.ipv6), \
11097                                  sizeof(struct in6_addr)); \
11098         else { \
11099                 printf("invalid parameter.\n"); \
11100                 return; \
11101         } \
11102 } while (0)
11103
11104 static void
11105 cmd_flow_director_filter_parsed(void *parsed_result,
11106                           __rte_unused struct cmdline *cl,
11107                           __rte_unused void *data)
11108 {
11109         struct cmd_flow_director_result *res = parsed_result;
11110         struct rte_eth_fdir_filter entry;
11111         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11112         char *end;
11113         unsigned long vf_id;
11114         int ret = 0;
11115
11116         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11117         if (ret < 0) {
11118                 printf("flow director is not supported on port %u.\n",
11119                         res->port_id);
11120                 return;
11121         }
11122         memset(flexbytes, 0, sizeof(flexbytes));
11123         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11124
11125         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11126                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11127                         printf("Please set mode to MAC-VLAN.\n");
11128                         return;
11129                 }
11130         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11131                 if (strcmp(res->mode_value, "Tunnel")) {
11132                         printf("Please set mode to Tunnel.\n");
11133                         return;
11134                 }
11135         } else {
11136                 if (!strcmp(res->mode_value, "raw")) {
11137 #ifdef RTE_LIBRTE_I40E_PMD
11138                         struct rte_pmd_i40e_flow_type_mapping
11139                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11140                         struct rte_pmd_i40e_pkt_template_conf conf;
11141                         uint16_t flow_type = str2flowtype(res->flow_type);
11142                         uint16_t i, port = res->port_id;
11143                         uint8_t add;
11144
11145                         memset(&conf, 0, sizeof(conf));
11146
11147                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11148                                 printf("Invalid flow type specified.\n");
11149                                 return;
11150                         }
11151                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11152                                                                  mapping);
11153                         if (ret)
11154                                 return;
11155                         if (mapping[flow_type].pctype == 0ULL) {
11156                                 printf("Invalid flow type specified.\n");
11157                                 return;
11158                         }
11159                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11160                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11161                                         conf.input.pctype = i;
11162                                         break;
11163                                 }
11164                         }
11165
11166                         conf.input.packet = open_file(res->filepath,
11167                                                 &conf.input.length);
11168                         if (!conf.input.packet)
11169                                 return;
11170                         if (!strcmp(res->drop, "drop"))
11171                                 conf.action.behavior =
11172                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11173                         else
11174                                 conf.action.behavior =
11175                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11176                         conf.action.report_status =
11177                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11178                         conf.action.rx_queue = res->queue_id;
11179                         conf.soft_id = res->fd_id_value;
11180                         add  = strcmp(res->ops, "del") ? 1 : 0;
11181                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11182                                                                         &conf,
11183                                                                         add);
11184                         if (ret < 0)
11185                                 printf("flow director config error: (%s)\n",
11186                                        strerror(-ret));
11187                         close_file(conf.input.packet);
11188 #endif
11189                         return;
11190                 } else if (strcmp(res->mode_value, "IP")) {
11191                         printf("Please set mode to IP or raw.\n");
11192                         return;
11193                 }
11194                 entry.input.flow_type = str2flowtype(res->flow_type);
11195         }
11196
11197         ret = parse_flexbytes(res->flexbytes_value,
11198                                         flexbytes,
11199                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11200         if (ret < 0) {
11201                 printf("error: Cannot parse flexbytes input.\n");
11202                 return;
11203         }
11204
11205         switch (entry.input.flow_type) {
11206         case RTE_ETH_FLOW_FRAG_IPV4:
11207         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11208                 entry.input.flow.ip4_flow.proto = res->proto_value;
11209                 /* fall-through */
11210         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11211         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11212                 IPV4_ADDR_TO_UINT(res->ip_dst,
11213                         entry.input.flow.ip4_flow.dst_ip);
11214                 IPV4_ADDR_TO_UINT(res->ip_src,
11215                         entry.input.flow.ip4_flow.src_ip);
11216                 entry.input.flow.ip4_flow.tos = res->tos_value;
11217                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11218                 /* need convert to big endian. */
11219                 entry.input.flow.udp4_flow.dst_port =
11220                                 rte_cpu_to_be_16(res->port_dst);
11221                 entry.input.flow.udp4_flow.src_port =
11222                                 rte_cpu_to_be_16(res->port_src);
11223                 break;
11224         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11225                 IPV4_ADDR_TO_UINT(res->ip_dst,
11226                         entry.input.flow.sctp4_flow.ip.dst_ip);
11227                 IPV4_ADDR_TO_UINT(res->ip_src,
11228                         entry.input.flow.sctp4_flow.ip.src_ip);
11229                 entry.input.flow.ip4_flow.tos = res->tos_value;
11230                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11231                 /* need convert to big endian. */
11232                 entry.input.flow.sctp4_flow.dst_port =
11233                                 rte_cpu_to_be_16(res->port_dst);
11234                 entry.input.flow.sctp4_flow.src_port =
11235                                 rte_cpu_to_be_16(res->port_src);
11236                 entry.input.flow.sctp4_flow.verify_tag =
11237                                 rte_cpu_to_be_32(res->verify_tag_value);
11238                 break;
11239         case RTE_ETH_FLOW_FRAG_IPV6:
11240         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11241                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11242                 /* fall-through */
11243         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11244         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11245                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11246                         entry.input.flow.ipv6_flow.dst_ip);
11247                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11248                         entry.input.flow.ipv6_flow.src_ip);
11249                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11250                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11251                 /* need convert to big endian. */
11252                 entry.input.flow.udp6_flow.dst_port =
11253                                 rte_cpu_to_be_16(res->port_dst);
11254                 entry.input.flow.udp6_flow.src_port =
11255                                 rte_cpu_to_be_16(res->port_src);
11256                 break;
11257         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11258                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11259                         entry.input.flow.sctp6_flow.ip.dst_ip);
11260                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11261                         entry.input.flow.sctp6_flow.ip.src_ip);
11262                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11263                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11264                 /* need convert to big endian. */
11265                 entry.input.flow.sctp6_flow.dst_port =
11266                                 rte_cpu_to_be_16(res->port_dst);
11267                 entry.input.flow.sctp6_flow.src_port =
11268                                 rte_cpu_to_be_16(res->port_src);
11269                 entry.input.flow.sctp6_flow.verify_tag =
11270                                 rte_cpu_to_be_32(res->verify_tag_value);
11271                 break;
11272         case RTE_ETH_FLOW_L2_PAYLOAD:
11273                 entry.input.flow.l2_flow.ether_type =
11274                         rte_cpu_to_be_16(res->ether_type);
11275                 break;
11276         default:
11277                 break;
11278         }
11279
11280         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11281                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11282                                  &res->mac_addr,
11283                                  sizeof(struct rte_ether_addr));
11284
11285         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11286                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11287                                  &res->mac_addr,
11288                                  sizeof(struct rte_ether_addr));
11289                 entry.input.flow.tunnel_flow.tunnel_type =
11290                         str2fdir_tunneltype(res->tunnel_type);
11291                 entry.input.flow.tunnel_flow.tunnel_id =
11292                         rte_cpu_to_be_32(res->tunnel_id_value);
11293         }
11294
11295         rte_memcpy(entry.input.flow_ext.flexbytes,
11296                    flexbytes,
11297                    RTE_ETH_FDIR_MAX_FLEXLEN);
11298
11299         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11300
11301         entry.action.flex_off = 0;  /*use 0 by default */
11302         if (!strcmp(res->drop, "drop"))
11303                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11304         else
11305                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11306
11307         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11308             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11309                 if (!strcmp(res->pf_vf, "pf"))
11310                         entry.input.flow_ext.is_vf = 0;
11311                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11312                         struct rte_eth_dev_info dev_info;
11313
11314                         ret = eth_dev_info_get_print_err(res->port_id,
11315                                                 &dev_info);
11316                         if (ret != 0)
11317                                 return;
11318
11319                         errno = 0;
11320                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11321                         if (errno != 0 || *end != '\0' ||
11322                             vf_id >= dev_info.max_vfs) {
11323                                 printf("invalid parameter %s.\n", res->pf_vf);
11324                                 return;
11325                         }
11326                         entry.input.flow_ext.is_vf = 1;
11327                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11328                 } else {
11329                         printf("invalid parameter %s.\n", res->pf_vf);
11330                         return;
11331                 }
11332         }
11333
11334         /* set to report FD ID by default */
11335         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11336         entry.action.rx_queue = res->queue_id;
11337         entry.soft_id = res->fd_id_value;
11338         if (!strcmp(res->ops, "add"))
11339                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11340                                              RTE_ETH_FILTER_ADD, &entry);
11341         else if (!strcmp(res->ops, "del"))
11342                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11343                                              RTE_ETH_FILTER_DELETE, &entry);
11344         else
11345                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11346                                              RTE_ETH_FILTER_UPDATE, &entry);
11347         if (ret < 0)
11348                 printf("flow director programming error: (%s)\n",
11349                         strerror(-ret));
11350 }
11351
11352 cmdline_parse_token_string_t cmd_flow_director_filter =
11353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11354                                  flow_director_filter, "flow_director_filter");
11355 cmdline_parse_token_num_t cmd_flow_director_port_id =
11356         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11357                               port_id, UINT16);
11358 cmdline_parse_token_string_t cmd_flow_director_ops =
11359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11360                                  ops, "add#del#update");
11361 cmdline_parse_token_string_t cmd_flow_director_flow =
11362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11363                                  flow, "flow");
11364 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11366                 flow_type, NULL);
11367 cmdline_parse_token_string_t cmd_flow_director_ether =
11368         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11369                                  ether, "ether");
11370 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11371         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11372                               ether_type, UINT16);
11373 cmdline_parse_token_string_t cmd_flow_director_src =
11374         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11375                                  src, "src");
11376 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11377         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11378                                  ip_src);
11379 cmdline_parse_token_num_t cmd_flow_director_port_src =
11380         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11381                               port_src, UINT16);
11382 cmdline_parse_token_string_t cmd_flow_director_dst =
11383         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11384                                  dst, "dst");
11385 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11386         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11387                                  ip_dst);
11388 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11389         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11390                               port_dst, UINT16);
11391 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11392         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11393                                   verify_tag, "verify_tag");
11394 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11395         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11396                               verify_tag_value, UINT32);
11397 cmdline_parse_token_string_t cmd_flow_director_tos =
11398         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11399                                  tos, "tos");
11400 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11401         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11402                               tos_value, UINT8);
11403 cmdline_parse_token_string_t cmd_flow_director_proto =
11404         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11405                                  proto, "proto");
11406 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11407         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11408                               proto_value, UINT8);
11409 cmdline_parse_token_string_t cmd_flow_director_ttl =
11410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11411                                  ttl, "ttl");
11412 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11413         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11414                               ttl_value, UINT8);
11415 cmdline_parse_token_string_t cmd_flow_director_vlan =
11416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11417                                  vlan, "vlan");
11418 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11419         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11420                               vlan_value, UINT16);
11421 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11422         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11423                                  flexbytes, "flexbytes");
11424 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11425         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11426                               flexbytes_value, NULL);
11427 cmdline_parse_token_string_t cmd_flow_director_drop =
11428         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11429                                  drop, "drop#fwd");
11430 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11431         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11432                               pf_vf, NULL);
11433 cmdline_parse_token_string_t cmd_flow_director_queue =
11434         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11435                                  queue, "queue");
11436 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11437         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11438                               queue_id, UINT16);
11439 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11440         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11441                                  fd_id, "fd_id");
11442 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11443         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11444                               fd_id_value, UINT32);
11445
11446 cmdline_parse_token_string_t cmd_flow_director_mode =
11447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11448                                  mode, "mode");
11449 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11450         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11451                                  mode_value, "IP");
11452 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11453         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11454                                  mode_value, "MAC-VLAN");
11455 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11456         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11457                                  mode_value, "Tunnel");
11458 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11459         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11460                                  mode_value, "raw");
11461 cmdline_parse_token_string_t cmd_flow_director_mac =
11462         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11463                                  mac, "mac");
11464 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11465         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11466                                     mac_addr);
11467 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11468         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11469                                  tunnel, "tunnel");
11470 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11471         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11472                                  tunnel_type, "NVGRE#VxLAN");
11473 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11474         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11475                                  tunnel_id, "tunnel-id");
11476 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11477         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11478                               tunnel_id_value, UINT32);
11479 cmdline_parse_token_string_t cmd_flow_director_packet =
11480         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11481                                  packet, "packet");
11482 cmdline_parse_token_string_t cmd_flow_director_filepath =
11483         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11484                                  filepath, NULL);
11485
11486 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11487         .f = cmd_flow_director_filter_parsed,
11488         .data = NULL,
11489         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11490                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11491                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11492                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11493                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11494                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11495                 "fd_id <fd_id_value>: "
11496                 "Add or delete an ip flow director entry on NIC",
11497         .tokens = {
11498                 (void *)&cmd_flow_director_filter,
11499                 (void *)&cmd_flow_director_port_id,
11500                 (void *)&cmd_flow_director_mode,
11501                 (void *)&cmd_flow_director_mode_ip,
11502                 (void *)&cmd_flow_director_ops,
11503                 (void *)&cmd_flow_director_flow,
11504                 (void *)&cmd_flow_director_flow_type,
11505                 (void *)&cmd_flow_director_src,
11506                 (void *)&cmd_flow_director_ip_src,
11507                 (void *)&cmd_flow_director_dst,
11508                 (void *)&cmd_flow_director_ip_dst,
11509                 (void *)&cmd_flow_director_tos,
11510                 (void *)&cmd_flow_director_tos_value,
11511                 (void *)&cmd_flow_director_proto,
11512                 (void *)&cmd_flow_director_proto_value,
11513                 (void *)&cmd_flow_director_ttl,
11514                 (void *)&cmd_flow_director_ttl_value,
11515                 (void *)&cmd_flow_director_vlan,
11516                 (void *)&cmd_flow_director_vlan_value,
11517                 (void *)&cmd_flow_director_flexbytes,
11518                 (void *)&cmd_flow_director_flexbytes_value,
11519                 (void *)&cmd_flow_director_drop,
11520                 (void *)&cmd_flow_director_pf_vf,
11521                 (void *)&cmd_flow_director_queue,
11522                 (void *)&cmd_flow_director_queue_id,
11523                 (void *)&cmd_flow_director_fd_id,
11524                 (void *)&cmd_flow_director_fd_id_value,
11525                 NULL,
11526         },
11527 };
11528
11529 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11530         .f = cmd_flow_director_filter_parsed,
11531         .data = NULL,
11532         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11533                 "director entry on NIC",
11534         .tokens = {
11535                 (void *)&cmd_flow_director_filter,
11536                 (void *)&cmd_flow_director_port_id,
11537                 (void *)&cmd_flow_director_mode,
11538                 (void *)&cmd_flow_director_mode_ip,
11539                 (void *)&cmd_flow_director_ops,
11540                 (void *)&cmd_flow_director_flow,
11541                 (void *)&cmd_flow_director_flow_type,
11542                 (void *)&cmd_flow_director_src,
11543                 (void *)&cmd_flow_director_ip_src,
11544                 (void *)&cmd_flow_director_port_src,
11545                 (void *)&cmd_flow_director_dst,
11546                 (void *)&cmd_flow_director_ip_dst,
11547                 (void *)&cmd_flow_director_port_dst,
11548                 (void *)&cmd_flow_director_tos,
11549                 (void *)&cmd_flow_director_tos_value,
11550                 (void *)&cmd_flow_director_ttl,
11551                 (void *)&cmd_flow_director_ttl_value,
11552                 (void *)&cmd_flow_director_vlan,
11553                 (void *)&cmd_flow_director_vlan_value,
11554                 (void *)&cmd_flow_director_flexbytes,
11555                 (void *)&cmd_flow_director_flexbytes_value,
11556                 (void *)&cmd_flow_director_drop,
11557                 (void *)&cmd_flow_director_pf_vf,
11558                 (void *)&cmd_flow_director_queue,
11559                 (void *)&cmd_flow_director_queue_id,
11560                 (void *)&cmd_flow_director_fd_id,
11561                 (void *)&cmd_flow_director_fd_id_value,
11562                 NULL,
11563         },
11564 };
11565
11566 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11567         .f = cmd_flow_director_filter_parsed,
11568         .data = NULL,
11569         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11570                 "director entry on NIC",
11571         .tokens = {
11572                 (void *)&cmd_flow_director_filter,
11573                 (void *)&cmd_flow_director_port_id,
11574                 (void *)&cmd_flow_director_mode,
11575                 (void *)&cmd_flow_director_mode_ip,
11576                 (void *)&cmd_flow_director_ops,
11577                 (void *)&cmd_flow_director_flow,
11578                 (void *)&cmd_flow_director_flow_type,
11579                 (void *)&cmd_flow_director_src,
11580                 (void *)&cmd_flow_director_ip_src,
11581                 (void *)&cmd_flow_director_port_src,
11582                 (void *)&cmd_flow_director_dst,
11583                 (void *)&cmd_flow_director_ip_dst,
11584                 (void *)&cmd_flow_director_port_dst,
11585                 (void *)&cmd_flow_director_verify_tag,
11586                 (void *)&cmd_flow_director_verify_tag_value,
11587                 (void *)&cmd_flow_director_tos,
11588                 (void *)&cmd_flow_director_tos_value,
11589                 (void *)&cmd_flow_director_ttl,
11590                 (void *)&cmd_flow_director_ttl_value,
11591                 (void *)&cmd_flow_director_vlan,
11592                 (void *)&cmd_flow_director_vlan_value,
11593                 (void *)&cmd_flow_director_flexbytes,
11594                 (void *)&cmd_flow_director_flexbytes_value,
11595                 (void *)&cmd_flow_director_drop,
11596                 (void *)&cmd_flow_director_pf_vf,
11597                 (void *)&cmd_flow_director_queue,
11598                 (void *)&cmd_flow_director_queue_id,
11599                 (void *)&cmd_flow_director_fd_id,
11600                 (void *)&cmd_flow_director_fd_id_value,
11601                 NULL,
11602         },
11603 };
11604
11605 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11606         .f = cmd_flow_director_filter_parsed,
11607         .data = NULL,
11608         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11609                 "director entry on NIC",
11610         .tokens = {
11611                 (void *)&cmd_flow_director_filter,
11612                 (void *)&cmd_flow_director_port_id,
11613                 (void *)&cmd_flow_director_mode,
11614                 (void *)&cmd_flow_director_mode_ip,
11615                 (void *)&cmd_flow_director_ops,
11616                 (void *)&cmd_flow_director_flow,
11617                 (void *)&cmd_flow_director_flow_type,
11618                 (void *)&cmd_flow_director_ether,
11619                 (void *)&cmd_flow_director_ether_type,
11620                 (void *)&cmd_flow_director_flexbytes,
11621                 (void *)&cmd_flow_director_flexbytes_value,
11622                 (void *)&cmd_flow_director_drop,
11623                 (void *)&cmd_flow_director_pf_vf,
11624                 (void *)&cmd_flow_director_queue,
11625                 (void *)&cmd_flow_director_queue_id,
11626                 (void *)&cmd_flow_director_fd_id,
11627                 (void *)&cmd_flow_director_fd_id_value,
11628                 NULL,
11629         },
11630 };
11631
11632 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11633         .f = cmd_flow_director_filter_parsed,
11634         .data = NULL,
11635         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11636                 "director entry on NIC",
11637         .tokens = {
11638                 (void *)&cmd_flow_director_filter,
11639                 (void *)&cmd_flow_director_port_id,
11640                 (void *)&cmd_flow_director_mode,
11641                 (void *)&cmd_flow_director_mode_mac_vlan,
11642                 (void *)&cmd_flow_director_ops,
11643                 (void *)&cmd_flow_director_mac,
11644                 (void *)&cmd_flow_director_mac_addr,
11645                 (void *)&cmd_flow_director_vlan,
11646                 (void *)&cmd_flow_director_vlan_value,
11647                 (void *)&cmd_flow_director_flexbytes,
11648                 (void *)&cmd_flow_director_flexbytes_value,
11649                 (void *)&cmd_flow_director_drop,
11650                 (void *)&cmd_flow_director_queue,
11651                 (void *)&cmd_flow_director_queue_id,
11652                 (void *)&cmd_flow_director_fd_id,
11653                 (void *)&cmd_flow_director_fd_id_value,
11654                 NULL,
11655         },
11656 };
11657
11658 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11659         .f = cmd_flow_director_filter_parsed,
11660         .data = NULL,
11661         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11662                 "director entry on NIC",
11663         .tokens = {
11664                 (void *)&cmd_flow_director_filter,
11665                 (void *)&cmd_flow_director_port_id,
11666                 (void *)&cmd_flow_director_mode,
11667                 (void *)&cmd_flow_director_mode_tunnel,
11668                 (void *)&cmd_flow_director_ops,
11669                 (void *)&cmd_flow_director_mac,
11670                 (void *)&cmd_flow_director_mac_addr,
11671                 (void *)&cmd_flow_director_vlan,
11672                 (void *)&cmd_flow_director_vlan_value,
11673                 (void *)&cmd_flow_director_tunnel,
11674                 (void *)&cmd_flow_director_tunnel_type,
11675                 (void *)&cmd_flow_director_tunnel_id,
11676                 (void *)&cmd_flow_director_tunnel_id_value,
11677                 (void *)&cmd_flow_director_flexbytes,
11678                 (void *)&cmd_flow_director_flexbytes_value,
11679                 (void *)&cmd_flow_director_drop,
11680                 (void *)&cmd_flow_director_queue,
11681                 (void *)&cmd_flow_director_queue_id,
11682                 (void *)&cmd_flow_director_fd_id,
11683                 (void *)&cmd_flow_director_fd_id_value,
11684                 NULL,
11685         },
11686 };
11687
11688 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11689         .f = cmd_flow_director_filter_parsed,
11690         .data = NULL,
11691         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11692                 "director entry on NIC",
11693         .tokens = {
11694                 (void *)&cmd_flow_director_filter,
11695                 (void *)&cmd_flow_director_port_id,
11696                 (void *)&cmd_flow_director_mode,
11697                 (void *)&cmd_flow_director_mode_raw,
11698                 (void *)&cmd_flow_director_ops,
11699                 (void *)&cmd_flow_director_flow,
11700                 (void *)&cmd_flow_director_flow_type,
11701                 (void *)&cmd_flow_director_drop,
11702                 (void *)&cmd_flow_director_queue,
11703                 (void *)&cmd_flow_director_queue_id,
11704                 (void *)&cmd_flow_director_fd_id,
11705                 (void *)&cmd_flow_director_fd_id_value,
11706                 (void *)&cmd_flow_director_packet,
11707                 (void *)&cmd_flow_director_filepath,
11708                 NULL,
11709         },
11710 };
11711
11712 struct cmd_flush_flow_director_result {
11713         cmdline_fixed_string_t flush_flow_director;
11714         portid_t port_id;
11715 };
11716
11717 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11718         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11719                                  flush_flow_director, "flush_flow_director");
11720 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11721         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11722                               port_id, UINT16);
11723
11724 static void
11725 cmd_flush_flow_director_parsed(void *parsed_result,
11726                           __rte_unused struct cmdline *cl,
11727                           __rte_unused void *data)
11728 {
11729         struct cmd_flow_director_result *res = parsed_result;
11730         int ret = 0;
11731
11732         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11733         if (ret < 0) {
11734                 printf("flow director is not supported on port %u.\n",
11735                         res->port_id);
11736                 return;
11737         }
11738
11739         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11740                         RTE_ETH_FILTER_FLUSH, NULL);
11741         if (ret < 0)
11742                 printf("flow director table flushing error: (%s)\n",
11743                         strerror(-ret));
11744 }
11745
11746 cmdline_parse_inst_t cmd_flush_flow_director = {
11747         .f = cmd_flush_flow_director_parsed,
11748         .data = NULL,
11749         .help_str = "flush_flow_director <port_id>: "
11750                 "Flush all flow director entries of a device on NIC",
11751         .tokens = {
11752                 (void *)&cmd_flush_flow_director_flush,
11753                 (void *)&cmd_flush_flow_director_port_id,
11754                 NULL,
11755         },
11756 };
11757
11758 /* *** deal with flow director mask *** */
11759 struct cmd_flow_director_mask_result {
11760         cmdline_fixed_string_t flow_director_mask;
11761         portid_t port_id;
11762         cmdline_fixed_string_t mode;
11763         cmdline_fixed_string_t mode_value;
11764         cmdline_fixed_string_t vlan;
11765         uint16_t vlan_mask;
11766         cmdline_fixed_string_t src_mask;
11767         cmdline_ipaddr_t ipv4_src;
11768         cmdline_ipaddr_t ipv6_src;
11769         uint16_t port_src;
11770         cmdline_fixed_string_t dst_mask;
11771         cmdline_ipaddr_t ipv4_dst;
11772         cmdline_ipaddr_t ipv6_dst;
11773         uint16_t port_dst;
11774         cmdline_fixed_string_t mac;
11775         uint8_t mac_addr_byte_mask;
11776         cmdline_fixed_string_t tunnel_id;
11777         uint32_t tunnel_id_mask;
11778         cmdline_fixed_string_t tunnel_type;
11779         uint8_t tunnel_type_mask;
11780 };
11781
11782 static void
11783 cmd_flow_director_mask_parsed(void *parsed_result,
11784                           __rte_unused struct cmdline *cl,
11785                           __rte_unused void *data)
11786 {
11787         struct cmd_flow_director_mask_result *res = parsed_result;
11788         struct rte_eth_fdir_masks *mask;
11789         struct rte_port *port;
11790
11791         port = &ports[res->port_id];
11792         /** Check if the port is not started **/
11793         if (port->port_status != RTE_PORT_STOPPED) {
11794                 printf("Please stop port %d first\n", res->port_id);
11795                 return;
11796         }
11797
11798         mask = &port->dev_conf.fdir_conf.mask;
11799
11800         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11801                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11802                         printf("Please set mode to MAC-VLAN.\n");
11803                         return;
11804                 }
11805
11806                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11807         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11808                 if (strcmp(res->mode_value, "Tunnel")) {
11809                         printf("Please set mode to Tunnel.\n");
11810                         return;
11811                 }
11812
11813                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11814                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11815                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11816                 mask->tunnel_type_mask = res->tunnel_type_mask;
11817         } else {
11818                 if (strcmp(res->mode_value, "IP")) {
11819                         printf("Please set mode to IP.\n");
11820                         return;
11821                 }
11822
11823                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11824                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11825                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11826                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11827                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11828                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11829                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11830         }
11831
11832         cmd_reconfig_device_queue(res->port_id, 1, 1);
11833 }
11834
11835 cmdline_parse_token_string_t cmd_flow_director_mask =
11836         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11837                                  flow_director_mask, "flow_director_mask");
11838 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11839         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11840                               port_id, UINT16);
11841 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11842         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11843                                  vlan, "vlan");
11844 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11845         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11846                               vlan_mask, UINT16);
11847 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11848         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11849                                  src_mask, "src_mask");
11850 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11851         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11852                                  ipv4_src);
11853 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11854         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11855                                  ipv6_src);
11856 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11857         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11858                               port_src, UINT16);
11859 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11860         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11861                                  dst_mask, "dst_mask");
11862 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11863         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11864                                  ipv4_dst);
11865 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11866         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11867                                  ipv6_dst);
11868 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11869         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11870                               port_dst, UINT16);
11871
11872 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11873         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11874                                  mode, "mode");
11875 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11876         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11877                                  mode_value, "IP");
11878 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11879         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11880                                  mode_value, "MAC-VLAN");
11881 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11882         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11883                                  mode_value, "Tunnel");
11884 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11885         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11886                                  mac, "mac");
11887 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11888         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11889                               mac_addr_byte_mask, UINT8);
11890 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11891         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11892                                  tunnel_type, "tunnel-type");
11893 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11894         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11895                               tunnel_type_mask, UINT8);
11896 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11897         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11898                                  tunnel_id, "tunnel-id");
11899 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11900         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11901                               tunnel_id_mask, UINT32);
11902
11903 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11904         .f = cmd_flow_director_mask_parsed,
11905         .data = NULL,
11906         .help_str = "flow_director_mask ... : "
11907                 "Set IP mode flow director's mask on NIC",
11908         .tokens = {
11909                 (void *)&cmd_flow_director_mask,
11910                 (void *)&cmd_flow_director_mask_port_id,
11911                 (void *)&cmd_flow_director_mask_mode,
11912                 (void *)&cmd_flow_director_mask_mode_ip,
11913                 (void *)&cmd_flow_director_mask_vlan,
11914                 (void *)&cmd_flow_director_mask_vlan_value,
11915                 (void *)&cmd_flow_director_mask_src,
11916                 (void *)&cmd_flow_director_mask_ipv4_src,
11917                 (void *)&cmd_flow_director_mask_ipv6_src,
11918                 (void *)&cmd_flow_director_mask_port_src,
11919                 (void *)&cmd_flow_director_mask_dst,
11920                 (void *)&cmd_flow_director_mask_ipv4_dst,
11921                 (void *)&cmd_flow_director_mask_ipv6_dst,
11922                 (void *)&cmd_flow_director_mask_port_dst,
11923                 NULL,
11924         },
11925 };
11926
11927 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11928         .f = cmd_flow_director_mask_parsed,
11929         .data = NULL,
11930         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11931                 "flow director's mask on NIC",
11932         .tokens = {
11933                 (void *)&cmd_flow_director_mask,
11934                 (void *)&cmd_flow_director_mask_port_id,
11935                 (void *)&cmd_flow_director_mask_mode,
11936                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11937                 (void *)&cmd_flow_director_mask_vlan,
11938                 (void *)&cmd_flow_director_mask_vlan_value,
11939                 NULL,
11940         },
11941 };
11942
11943 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11944         .f = cmd_flow_director_mask_parsed,
11945         .data = NULL,
11946         .help_str = "flow_director_mask ... : Set tunnel mode "
11947                 "flow director's mask on NIC",
11948         .tokens = {
11949                 (void *)&cmd_flow_director_mask,
11950                 (void *)&cmd_flow_director_mask_port_id,
11951                 (void *)&cmd_flow_director_mask_mode,
11952                 (void *)&cmd_flow_director_mask_mode_tunnel,
11953                 (void *)&cmd_flow_director_mask_vlan,
11954                 (void *)&cmd_flow_director_mask_vlan_value,
11955                 (void *)&cmd_flow_director_mask_mac,
11956                 (void *)&cmd_flow_director_mask_mac_value,
11957                 (void *)&cmd_flow_director_mask_tunnel_type,
11958                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11959                 (void *)&cmd_flow_director_mask_tunnel_id,
11960                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11961                 NULL,
11962         },
11963 };
11964
11965 /* *** deal with flow director mask on flexible payload *** */
11966 struct cmd_flow_director_flex_mask_result {
11967         cmdline_fixed_string_t flow_director_flexmask;
11968         portid_t port_id;
11969         cmdline_fixed_string_t flow;
11970         cmdline_fixed_string_t flow_type;
11971         cmdline_fixed_string_t mask;
11972 };
11973
11974 static void
11975 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11976                           __rte_unused struct cmdline *cl,
11977                           __rte_unused void *data)
11978 {
11979         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11980         struct rte_eth_fdir_info fdir_info;
11981         struct rte_eth_fdir_flex_mask flex_mask;
11982         struct rte_port *port;
11983         uint64_t flow_type_mask;
11984         uint16_t i;
11985         int ret;
11986
11987         port = &ports[res->port_id];
11988         /** Check if the port is not started **/
11989         if (port->port_status != RTE_PORT_STOPPED) {
11990                 printf("Please stop port %d first\n", res->port_id);
11991                 return;
11992         }
11993
11994         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11995         ret = parse_flexbytes(res->mask,
11996                         flex_mask.mask,
11997                         RTE_ETH_FDIR_MAX_FLEXLEN);
11998         if (ret < 0) {
11999                 printf("error: Cannot parse mask input.\n");
12000                 return;
12001         }
12002
12003         memset(&fdir_info, 0, sizeof(fdir_info));
12004         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12005                                 RTE_ETH_FILTER_INFO, &fdir_info);
12006         if (ret < 0) {
12007                 printf("Cannot get FDir filter info\n");
12008                 return;
12009         }
12010
12011         if (!strcmp(res->flow_type, "none")) {
12012                 /* means don't specify the flow type */
12013                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12014                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12015                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12016                                0, sizeof(struct rte_eth_fdir_flex_mask));
12017                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12018                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12019                                  &flex_mask,
12020                                  sizeof(struct rte_eth_fdir_flex_mask));
12021                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12022                 return;
12023         }
12024         flow_type_mask = fdir_info.flow_types_mask[0];
12025         if (!strcmp(res->flow_type, "all")) {
12026                 if (!flow_type_mask) {
12027                         printf("No flow type supported\n");
12028                         return;
12029                 }
12030                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12031                         if (flow_type_mask & (1ULL << i)) {
12032                                 flex_mask.flow_type = i;
12033                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12034                         }
12035                 }
12036                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12037                 return;
12038         }
12039         flex_mask.flow_type = str2flowtype(res->flow_type);
12040         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12041                 printf("Flow type %s not supported on port %d\n",
12042                                 res->flow_type, res->port_id);
12043                 return;
12044         }
12045         fdir_set_flex_mask(res->port_id, &flex_mask);
12046         cmd_reconfig_device_queue(res->port_id, 1, 1);
12047 }
12048
12049 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12050         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12051                                  flow_director_flexmask,
12052                                  "flow_director_flex_mask");
12053 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12054         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12055                               port_id, UINT16);
12056 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12057         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12058                                  flow, "flow");
12059 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12060         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12061                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12062                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12063 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12064         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12065                                  mask, NULL);
12066
12067 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12068         .f = cmd_flow_director_flex_mask_parsed,
12069         .data = NULL,
12070         .help_str = "flow_director_flex_mask ... : "
12071                 "Set flow director's flex mask on NIC",
12072         .tokens = {
12073                 (void *)&cmd_flow_director_flexmask,
12074                 (void *)&cmd_flow_director_flexmask_port_id,
12075                 (void *)&cmd_flow_director_flexmask_flow,
12076                 (void *)&cmd_flow_director_flexmask_flow_type,
12077                 (void *)&cmd_flow_director_flexmask_mask,
12078                 NULL,
12079         },
12080 };
12081
12082 /* *** deal with flow director flexible payload configuration *** */
12083 struct cmd_flow_director_flexpayload_result {
12084         cmdline_fixed_string_t flow_director_flexpayload;
12085         portid_t port_id;
12086         cmdline_fixed_string_t payload_layer;
12087         cmdline_fixed_string_t payload_cfg;
12088 };
12089
12090 static inline int
12091 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12092 {
12093         char s[256];
12094         const char *p, *p0 = q_arg;
12095         char *end;
12096         unsigned long int_fld;
12097         char *str_fld[max_num];
12098         int i;
12099         unsigned size;
12100         int ret = -1;
12101
12102         p = strchr(p0, '(');
12103         if (p == NULL)
12104                 return -1;
12105         ++p;
12106         p0 = strchr(p, ')');
12107         if (p0 == NULL)
12108                 return -1;
12109
12110         size = p0 - p;
12111         if (size >= sizeof(s))
12112                 return -1;
12113
12114         snprintf(s, sizeof(s), "%.*s", size, p);
12115         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12116         if (ret < 0 || ret > max_num)
12117                 return -1;
12118         for (i = 0; i < ret; i++) {
12119                 errno = 0;
12120                 int_fld = strtoul(str_fld[i], &end, 0);
12121                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12122                         return -1;
12123                 offsets[i] = (uint16_t)int_fld;
12124         }
12125         return ret;
12126 }
12127
12128 static void
12129 cmd_flow_director_flxpld_parsed(void *parsed_result,
12130                           __rte_unused struct cmdline *cl,
12131                           __rte_unused void *data)
12132 {
12133         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12134         struct rte_eth_flex_payload_cfg flex_cfg;
12135         struct rte_port *port;
12136         int ret = 0;
12137
12138         port = &ports[res->port_id];
12139         /** Check if the port is not started **/
12140         if (port->port_status != RTE_PORT_STOPPED) {
12141                 printf("Please stop port %d first\n", res->port_id);
12142                 return;
12143         }
12144
12145         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12146
12147         if (!strcmp(res->payload_layer, "raw"))
12148                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12149         else if (!strcmp(res->payload_layer, "l2"))
12150                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12151         else if (!strcmp(res->payload_layer, "l3"))
12152                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12153         else if (!strcmp(res->payload_layer, "l4"))
12154                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12155
12156         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12157                             RTE_ETH_FDIR_MAX_FLEXLEN);
12158         if (ret < 0) {
12159                 printf("error: Cannot parse flex payload input.\n");
12160                 return;
12161         }
12162
12163         fdir_set_flex_payload(res->port_id, &flex_cfg);
12164         cmd_reconfig_device_queue(res->port_id, 1, 1);
12165 }
12166
12167 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12169                                  flow_director_flexpayload,
12170                                  "flow_director_flex_payload");
12171 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12172         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12173                               port_id, UINT16);
12174 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12175         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12176                                  payload_layer, "raw#l2#l3#l4");
12177 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12178         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12179                                  payload_cfg, NULL);
12180
12181 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12182         .f = cmd_flow_director_flxpld_parsed,
12183         .data = NULL,
12184         .help_str = "flow_director_flexpayload ... : "
12185                 "Set flow director's flex payload on NIC",
12186         .tokens = {
12187                 (void *)&cmd_flow_director_flexpayload,
12188                 (void *)&cmd_flow_director_flexpayload_port_id,
12189                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12190                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12191                 NULL,
12192         },
12193 };
12194
12195 /* Generic flow interface command. */
12196 extern cmdline_parse_inst_t cmd_flow;
12197
12198 /* *** Classification Filters Control *** */
12199 /* *** Get symmetric hash enable per port *** */
12200 struct cmd_get_sym_hash_ena_per_port_result {
12201         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12202         portid_t port_id;
12203 };
12204
12205 static void
12206 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12207                                  __rte_unused struct cmdline *cl,
12208                                  __rte_unused void *data)
12209 {
12210         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12211         struct rte_eth_hash_filter_info info;
12212         int ret;
12213
12214         if (rte_eth_dev_filter_supported(res->port_id,
12215                                 RTE_ETH_FILTER_HASH) < 0) {
12216                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12217                                                         res->port_id);
12218                 return;
12219         }
12220
12221         memset(&info, 0, sizeof(info));
12222         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12223         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12224                                                 RTE_ETH_FILTER_GET, &info);
12225
12226         if (ret < 0) {
12227                 printf("Cannot get symmetric hash enable per port "
12228                                         "on port %u\n", res->port_id);
12229                 return;
12230         }
12231
12232         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12233                                 "enabled" : "disabled", res->port_id);
12234 }
12235
12236 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12237         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12238                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12239 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12240         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12241                 port_id, UINT16);
12242
12243 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12244         .f = cmd_get_sym_hash_per_port_parsed,
12245         .data = NULL,
12246         .help_str = "get_sym_hash_ena_per_port <port_id>",
12247         .tokens = {
12248                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12249                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12250                 NULL,
12251         },
12252 };
12253
12254 /* *** Set symmetric hash enable per port *** */
12255 struct cmd_set_sym_hash_ena_per_port_result {
12256         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12257         cmdline_fixed_string_t enable;
12258         portid_t port_id;
12259 };
12260
12261 static void
12262 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12263                                  __rte_unused struct cmdline *cl,
12264                                  __rte_unused void *data)
12265 {
12266         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12267         struct rte_eth_hash_filter_info info;
12268         int ret;
12269
12270         if (rte_eth_dev_filter_supported(res->port_id,
12271                                 RTE_ETH_FILTER_HASH) < 0) {
12272                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12273                                                         res->port_id);
12274                 return;
12275         }
12276
12277         memset(&info, 0, sizeof(info));
12278         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12279         if (!strcmp(res->enable, "enable"))
12280                 info.info.enable = 1;
12281         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12282                                         RTE_ETH_FILTER_SET, &info);
12283         if (ret < 0) {
12284                 printf("Cannot set symmetric hash enable per port on "
12285                                         "port %u\n", res->port_id);
12286                 return;
12287         }
12288         printf("Symmetric hash has been set to %s on port %u\n",
12289                                         res->enable, res->port_id);
12290 }
12291
12292 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12293         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12294                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12295 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12296         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12297                 port_id, UINT16);
12298 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12299         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12300                 enable, "enable#disable");
12301
12302 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12303         .f = cmd_set_sym_hash_per_port_parsed,
12304         .data = NULL,
12305         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12306         .tokens = {
12307                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12308                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12309                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12310                 NULL,
12311         },
12312 };
12313
12314 /* Get global config of hash function */
12315 struct cmd_get_hash_global_config_result {
12316         cmdline_fixed_string_t get_hash_global_config;
12317         portid_t port_id;
12318 };
12319
12320 static char *
12321 flowtype_to_str(uint16_t ftype)
12322 {
12323         uint16_t i;
12324         static struct {
12325                 char str[16];
12326                 uint16_t ftype;
12327         } ftype_table[] = {
12328                 {"ipv4", RTE_ETH_FLOW_IPV4},
12329                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12330                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12331                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12332                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12333                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12334                 {"ipv6", RTE_ETH_FLOW_IPV6},
12335                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12336                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12337                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12338                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12339                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12340                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12341                 {"port", RTE_ETH_FLOW_PORT},
12342                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12343                 {"geneve", RTE_ETH_FLOW_GENEVE},
12344                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12345                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12346         };
12347
12348         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12349                 if (ftype_table[i].ftype == ftype)
12350                         return ftype_table[i].str;
12351         }
12352
12353         return NULL;
12354 }
12355
12356 static void
12357 cmd_get_hash_global_config_parsed(void *parsed_result,
12358                                   __rte_unused struct cmdline *cl,
12359                                   __rte_unused void *data)
12360 {
12361         struct cmd_get_hash_global_config_result *res = parsed_result;
12362         struct rte_eth_hash_filter_info info;
12363         uint32_t idx, offset;
12364         uint16_t i;
12365         char *str;
12366         int ret;
12367
12368         if (rte_eth_dev_filter_supported(res->port_id,
12369                         RTE_ETH_FILTER_HASH) < 0) {
12370                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12371                                                         res->port_id);
12372                 return;
12373         }
12374
12375         memset(&info, 0, sizeof(info));
12376         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12377         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12378                                         RTE_ETH_FILTER_GET, &info);
12379         if (ret < 0) {
12380                 printf("Cannot get hash global configurations by port %d\n",
12381                                                         res->port_id);
12382                 return;
12383         }
12384
12385         switch (info.info.global_conf.hash_func) {
12386         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12387                 printf("Hash function is Toeplitz\n");
12388                 break;
12389         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12390                 printf("Hash function is Simple XOR\n");
12391                 break;
12392         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12393                 printf("Hash function is Symmetric Toeplitz\n");
12394                 break;
12395         default:
12396                 printf("Unknown hash function\n");
12397                 break;
12398         }
12399
12400         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12401                 idx = i / UINT64_BIT;
12402                 offset = i % UINT64_BIT;
12403                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12404                                                 (1ULL << offset)))
12405                         continue;
12406                 str = flowtype_to_str(i);
12407                 if (!str)
12408                         continue;
12409                 printf("Symmetric hash is %s globally for flow type %s "
12410                                                         "by port %d\n",
12411                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12412                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12413                                                         res->port_id);
12414         }
12415 }
12416
12417 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12418         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12419                 get_hash_global_config, "get_hash_global_config");
12420 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12421         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12422                 port_id, UINT16);
12423
12424 cmdline_parse_inst_t cmd_get_hash_global_config = {
12425         .f = cmd_get_hash_global_config_parsed,
12426         .data = NULL,
12427         .help_str = "get_hash_global_config <port_id>",
12428         .tokens = {
12429                 (void *)&cmd_get_hash_global_config_all,
12430                 (void *)&cmd_get_hash_global_config_port_id,
12431                 NULL,
12432         },
12433 };
12434
12435 /* Set global config of hash function */
12436 struct cmd_set_hash_global_config_result {
12437         cmdline_fixed_string_t set_hash_global_config;
12438         portid_t port_id;
12439         cmdline_fixed_string_t hash_func;
12440         cmdline_fixed_string_t flow_type;
12441         cmdline_fixed_string_t enable;
12442 };
12443
12444 static void
12445 cmd_set_hash_global_config_parsed(void *parsed_result,
12446                                   __rte_unused struct cmdline *cl,
12447                                   __rte_unused void *data)
12448 {
12449         struct cmd_set_hash_global_config_result *res = parsed_result;
12450         struct rte_eth_hash_filter_info info;
12451         uint32_t ftype, idx, offset;
12452         int ret;
12453
12454         if (rte_eth_dev_filter_supported(res->port_id,
12455                                 RTE_ETH_FILTER_HASH) < 0) {
12456                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12457                                                         res->port_id);
12458                 return;
12459         }
12460         memset(&info, 0, sizeof(info));
12461         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12462         if (!strcmp(res->hash_func, "toeplitz"))
12463                 info.info.global_conf.hash_func =
12464                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12465         else if (!strcmp(res->hash_func, "simple_xor"))
12466                 info.info.global_conf.hash_func =
12467                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12468         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12469                 info.info.global_conf.hash_func =
12470                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12471         else if (!strcmp(res->hash_func, "default"))
12472                 info.info.global_conf.hash_func =
12473                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12474
12475         ftype = str2flowtype(res->flow_type);
12476         idx = ftype / UINT64_BIT;
12477         offset = ftype % UINT64_BIT;
12478         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12479         if (!strcmp(res->enable, "enable"))
12480                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12481                                                 (1ULL << offset);
12482         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12483                                         RTE_ETH_FILTER_SET, &info);
12484         if (ret < 0)
12485                 printf("Cannot set global hash configurations by port %d\n",
12486                                                         res->port_id);
12487         else
12488                 printf("Global hash configurations have been set "
12489                         "successfully by port %d\n", res->port_id);
12490 }
12491
12492 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12493         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12494                 set_hash_global_config, "set_hash_global_config");
12495 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12496         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12497                 port_id, UINT16);
12498 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12499         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12500                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12501 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12502         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12503                 flow_type,
12504                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12505                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12506 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12507         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12508                 enable, "enable#disable");
12509
12510 cmdline_parse_inst_t cmd_set_hash_global_config = {
12511         .f = cmd_set_hash_global_config_parsed,
12512         .data = NULL,
12513         .help_str = "set_hash_global_config <port_id> "
12514                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12515                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12516                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12517                 "l2_payload enable|disable",
12518         .tokens = {
12519                 (void *)&cmd_set_hash_global_config_all,
12520                 (void *)&cmd_set_hash_global_config_port_id,
12521                 (void *)&cmd_set_hash_global_config_hash_func,
12522                 (void *)&cmd_set_hash_global_config_flow_type,
12523                 (void *)&cmd_set_hash_global_config_enable,
12524                 NULL,
12525         },
12526 };
12527
12528 /* Set hash input set */
12529 struct cmd_set_hash_input_set_result {
12530         cmdline_fixed_string_t set_hash_input_set;
12531         portid_t port_id;
12532         cmdline_fixed_string_t flow_type;
12533         cmdline_fixed_string_t inset_field;
12534         cmdline_fixed_string_t select;
12535 };
12536
12537 static enum rte_eth_input_set_field
12538 str2inset(char *string)
12539 {
12540         uint16_t i;
12541
12542         static const struct {
12543                 char str[32];
12544                 enum rte_eth_input_set_field inset;
12545         } inset_table[] = {
12546                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12547                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12548                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12549                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12550                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12551                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12552                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12553                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12554                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12555                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12556                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12557                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12558                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12559                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12560                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12561                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12562                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12563                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12564                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12565                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12566                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12567                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12568                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12569                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12570                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12571                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12572                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12573                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12574                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12575                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12576                 {"none", RTE_ETH_INPUT_SET_NONE},
12577         };
12578
12579         for (i = 0; i < RTE_DIM(inset_table); i++) {
12580                 if (!strcmp(string, inset_table[i].str))
12581                         return inset_table[i].inset;
12582         }
12583
12584         return RTE_ETH_INPUT_SET_UNKNOWN;
12585 }
12586
12587 static void
12588 cmd_set_hash_input_set_parsed(void *parsed_result,
12589                               __rte_unused struct cmdline *cl,
12590                               __rte_unused void *data)
12591 {
12592         struct cmd_set_hash_input_set_result *res = parsed_result;
12593         struct rte_eth_hash_filter_info info;
12594
12595         memset(&info, 0, sizeof(info));
12596         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12597         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12598         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12599         info.info.input_set_conf.inset_size = 1;
12600         if (!strcmp(res->select, "select"))
12601                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12602         else if (!strcmp(res->select, "add"))
12603                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12604         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12605                                 RTE_ETH_FILTER_SET, &info);
12606 }
12607
12608 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12609         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12610                 set_hash_input_set, "set_hash_input_set");
12611 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12612         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12613                 port_id, UINT16);
12614 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12615         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12616                 flow_type, NULL);
12617 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12618         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12619                 inset_field,
12620                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12621                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12622                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12623                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12624                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12625                 "fld-8th#none");
12626 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12627         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12628                 select, "select#add");
12629
12630 cmdline_parse_inst_t cmd_set_hash_input_set = {
12631         .f = cmd_set_hash_input_set_parsed,
12632         .data = NULL,
12633         .help_str = "set_hash_input_set <port_id> "
12634         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12635         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12636         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12637         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12638         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12639         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12640         "fld-7th|fld-8th|none select|add",
12641         .tokens = {
12642                 (void *)&cmd_set_hash_input_set_cmd,
12643                 (void *)&cmd_set_hash_input_set_port_id,
12644                 (void *)&cmd_set_hash_input_set_flow_type,
12645                 (void *)&cmd_set_hash_input_set_field,
12646                 (void *)&cmd_set_hash_input_set_select,
12647                 NULL,
12648         },
12649 };
12650
12651 /* Set flow director input set */
12652 struct cmd_set_fdir_input_set_result {
12653         cmdline_fixed_string_t set_fdir_input_set;
12654         portid_t port_id;
12655         cmdline_fixed_string_t flow_type;
12656         cmdline_fixed_string_t inset_field;
12657         cmdline_fixed_string_t select;
12658 };
12659
12660 static void
12661 cmd_set_fdir_input_set_parsed(void *parsed_result,
12662         __rte_unused struct cmdline *cl,
12663         __rte_unused void *data)
12664 {
12665         struct cmd_set_fdir_input_set_result *res = parsed_result;
12666         struct rte_eth_fdir_filter_info info;
12667
12668         memset(&info, 0, sizeof(info));
12669         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12670         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12671         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12672         info.info.input_set_conf.inset_size = 1;
12673         if (!strcmp(res->select, "select"))
12674                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12675         else if (!strcmp(res->select, "add"))
12676                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12677         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12678                 RTE_ETH_FILTER_SET, &info);
12679 }
12680
12681 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12682         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12683         set_fdir_input_set, "set_fdir_input_set");
12684 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12685         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12686         port_id, UINT16);
12687 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12688         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12689         flow_type,
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 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12693         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12694         inset_field,
12695         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12696         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12697         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12698         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12699         "sctp-veri-tag#none");
12700 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12701         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12702         select, "select#add");
12703
12704 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12705         .f = cmd_set_fdir_input_set_parsed,
12706         .data = NULL,
12707         .help_str = "set_fdir_input_set <port_id> "
12708         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12709         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12710         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12711         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12712         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12713         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12714         "sctp-veri-tag|none select|add",
12715         .tokens = {
12716                 (void *)&cmd_set_fdir_input_set_cmd,
12717                 (void *)&cmd_set_fdir_input_set_port_id,
12718                 (void *)&cmd_set_fdir_input_set_flow_type,
12719                 (void *)&cmd_set_fdir_input_set_field,
12720                 (void *)&cmd_set_fdir_input_set_select,
12721                 NULL,
12722         },
12723 };
12724
12725 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12726 struct cmd_mcast_addr_result {
12727         cmdline_fixed_string_t mcast_addr_cmd;
12728         cmdline_fixed_string_t what;
12729         uint16_t port_num;
12730         struct rte_ether_addr mc_addr;
12731 };
12732
12733 static void cmd_mcast_addr_parsed(void *parsed_result,
12734                 __rte_unused struct cmdline *cl,
12735                 __rte_unused void *data)
12736 {
12737         struct cmd_mcast_addr_result *res = parsed_result;
12738
12739         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12740                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12741                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12742                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12743                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12744                 return;
12745         }
12746         if (strcmp(res->what, "add") == 0)
12747                 mcast_addr_add(res->port_num, &res->mc_addr);
12748         else
12749                 mcast_addr_remove(res->port_num, &res->mc_addr);
12750 }
12751
12752 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12753         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12754                                  mcast_addr_cmd, "mcast_addr");
12755 cmdline_parse_token_string_t cmd_mcast_addr_what =
12756         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12757                                  "add#remove");
12758 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12759         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12760 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12761         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12762
12763 cmdline_parse_inst_t cmd_mcast_addr = {
12764         .f = cmd_mcast_addr_parsed,
12765         .data = (void *)0,
12766         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12767                 "Add/Remove multicast MAC address on port_id",
12768         .tokens = {
12769                 (void *)&cmd_mcast_addr_cmd,
12770                 (void *)&cmd_mcast_addr_what,
12771                 (void *)&cmd_mcast_addr_portnum,
12772                 (void *)&cmd_mcast_addr_addr,
12773                 NULL,
12774         },
12775 };
12776
12777 /* l2 tunnel config
12778  * only support E-tag now.
12779  */
12780
12781 /* Ether type config */
12782 struct cmd_config_l2_tunnel_eth_type_result {
12783         cmdline_fixed_string_t port;
12784         cmdline_fixed_string_t config;
12785         cmdline_fixed_string_t all;
12786         portid_t id;
12787         cmdline_fixed_string_t l2_tunnel;
12788         cmdline_fixed_string_t l2_tunnel_type;
12789         cmdline_fixed_string_t eth_type;
12790         uint16_t eth_type_val;
12791 };
12792
12793 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12794         TOKEN_STRING_INITIALIZER
12795                 (struct cmd_config_l2_tunnel_eth_type_result,
12796                  port, "port");
12797 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12798         TOKEN_STRING_INITIALIZER
12799                 (struct cmd_config_l2_tunnel_eth_type_result,
12800                  config, "config");
12801 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12802         TOKEN_STRING_INITIALIZER
12803                 (struct cmd_config_l2_tunnel_eth_type_result,
12804                  all, "all");
12805 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12806         TOKEN_NUM_INITIALIZER
12807                 (struct cmd_config_l2_tunnel_eth_type_result,
12808                  id, UINT16);
12809 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12810         TOKEN_STRING_INITIALIZER
12811                 (struct cmd_config_l2_tunnel_eth_type_result,
12812                  l2_tunnel, "l2-tunnel");
12813 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12814         TOKEN_STRING_INITIALIZER
12815                 (struct cmd_config_l2_tunnel_eth_type_result,
12816                  l2_tunnel_type, "E-tag");
12817 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12818         TOKEN_STRING_INITIALIZER
12819                 (struct cmd_config_l2_tunnel_eth_type_result,
12820                  eth_type, "ether-type");
12821 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12822         TOKEN_NUM_INITIALIZER
12823                 (struct cmd_config_l2_tunnel_eth_type_result,
12824                  eth_type_val, UINT16);
12825
12826 static enum rte_eth_tunnel_type
12827 str2fdir_l2_tunnel_type(char *string)
12828 {
12829         uint32_t i = 0;
12830
12831         static const struct {
12832                 char str[32];
12833                 enum rte_eth_tunnel_type type;
12834         } l2_tunnel_type_str[] = {
12835                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12836         };
12837
12838         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12839                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12840                         return l2_tunnel_type_str[i].type;
12841         }
12842         return RTE_TUNNEL_TYPE_NONE;
12843 }
12844
12845 /* ether type config for all ports */
12846 static void
12847 cmd_config_l2_tunnel_eth_type_all_parsed
12848         (void *parsed_result,
12849          __rte_unused struct cmdline *cl,
12850          __rte_unused void *data)
12851 {
12852         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12853         struct rte_eth_l2_tunnel_conf entry;
12854         portid_t pid;
12855
12856         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12857         entry.ether_type = res->eth_type_val;
12858
12859         RTE_ETH_FOREACH_DEV(pid) {
12860                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12861         }
12862 }
12863
12864 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12865         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12866         .data = NULL,
12867         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12868         .tokens = {
12869                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12870                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12871                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12872                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12873                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12874                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12875                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12876                 NULL,
12877         },
12878 };
12879
12880 /* ether type config for a specific port */
12881 static void
12882 cmd_config_l2_tunnel_eth_type_specific_parsed(
12883         void *parsed_result,
12884         __rte_unused struct cmdline *cl,
12885         __rte_unused void *data)
12886 {
12887         struct cmd_config_l2_tunnel_eth_type_result *res =
12888                  parsed_result;
12889         struct rte_eth_l2_tunnel_conf entry;
12890
12891         if (port_id_is_invalid(res->id, ENABLED_WARN))
12892                 return;
12893
12894         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12895         entry.ether_type = res->eth_type_val;
12896
12897         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12898 }
12899
12900 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12901         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12902         .data = NULL,
12903         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12904         .tokens = {
12905                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12906                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12907                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12908                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12909                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12910                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12911                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12912                 NULL,
12913         },
12914 };
12915
12916 /* Enable/disable l2 tunnel */
12917 struct cmd_config_l2_tunnel_en_dis_result {
12918         cmdline_fixed_string_t port;
12919         cmdline_fixed_string_t config;
12920         cmdline_fixed_string_t all;
12921         portid_t id;
12922         cmdline_fixed_string_t l2_tunnel;
12923         cmdline_fixed_string_t l2_tunnel_type;
12924         cmdline_fixed_string_t en_dis;
12925 };
12926
12927 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12928         TOKEN_STRING_INITIALIZER
12929                 (struct cmd_config_l2_tunnel_en_dis_result,
12930                  port, "port");
12931 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12932         TOKEN_STRING_INITIALIZER
12933                 (struct cmd_config_l2_tunnel_en_dis_result,
12934                  config, "config");
12935 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12936         TOKEN_STRING_INITIALIZER
12937                 (struct cmd_config_l2_tunnel_en_dis_result,
12938                  all, "all");
12939 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12940         TOKEN_NUM_INITIALIZER
12941                 (struct cmd_config_l2_tunnel_en_dis_result,
12942                  id, UINT16);
12943 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12944         TOKEN_STRING_INITIALIZER
12945                 (struct cmd_config_l2_tunnel_en_dis_result,
12946                  l2_tunnel, "l2-tunnel");
12947 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12948         TOKEN_STRING_INITIALIZER
12949                 (struct cmd_config_l2_tunnel_en_dis_result,
12950                  l2_tunnel_type, "E-tag");
12951 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12952         TOKEN_STRING_INITIALIZER
12953                 (struct cmd_config_l2_tunnel_en_dis_result,
12954                  en_dis, "enable#disable");
12955
12956 /* enable/disable l2 tunnel for all ports */
12957 static void
12958 cmd_config_l2_tunnel_en_dis_all_parsed(
12959         void *parsed_result,
12960         __rte_unused struct cmdline *cl,
12961         __rte_unused void *data)
12962 {
12963         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12964         struct rte_eth_l2_tunnel_conf entry;
12965         portid_t pid;
12966         uint8_t en;
12967
12968         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12969
12970         if (!strcmp("enable", res->en_dis))
12971                 en = 1;
12972         else
12973                 en = 0;
12974
12975         RTE_ETH_FOREACH_DEV(pid) {
12976                 rte_eth_dev_l2_tunnel_offload_set(pid,
12977                                                   &entry,
12978                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12979                                                   en);
12980         }
12981 }
12982
12983 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12984         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12985         .data = NULL,
12986         .help_str = "port config all l2-tunnel E-tag enable|disable",
12987         .tokens = {
12988                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12989                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12990                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12991                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12992                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12993                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12994                 NULL,
12995         },
12996 };
12997
12998 /* enable/disable l2 tunnel for a port */
12999 static void
13000 cmd_config_l2_tunnel_en_dis_specific_parsed(
13001         void *parsed_result,
13002         __rte_unused struct cmdline *cl,
13003         __rte_unused void *data)
13004 {
13005         struct cmd_config_l2_tunnel_en_dis_result *res =
13006                 parsed_result;
13007         struct rte_eth_l2_tunnel_conf entry;
13008
13009         if (port_id_is_invalid(res->id, ENABLED_WARN))
13010                 return;
13011
13012         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13013
13014         if (!strcmp("enable", res->en_dis))
13015                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13016                                                   &entry,
13017                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13018                                                   1);
13019         else
13020                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13021                                                   &entry,
13022                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13023                                                   0);
13024 }
13025
13026 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13027         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13028         .data = NULL,
13029         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13030         .tokens = {
13031                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13032                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13033                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13034                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13035                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13036                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13037                 NULL,
13038         },
13039 };
13040
13041 /* E-tag configuration */
13042
13043 /* Common result structure for all E-tag configuration */
13044 struct cmd_config_e_tag_result {
13045         cmdline_fixed_string_t e_tag;
13046         cmdline_fixed_string_t set;
13047         cmdline_fixed_string_t insertion;
13048         cmdline_fixed_string_t stripping;
13049         cmdline_fixed_string_t forwarding;
13050         cmdline_fixed_string_t filter;
13051         cmdline_fixed_string_t add;
13052         cmdline_fixed_string_t del;
13053         cmdline_fixed_string_t on;
13054         cmdline_fixed_string_t off;
13055         cmdline_fixed_string_t on_off;
13056         cmdline_fixed_string_t port_tag_id;
13057         uint32_t port_tag_id_val;
13058         cmdline_fixed_string_t e_tag_id;
13059         uint16_t e_tag_id_val;
13060         cmdline_fixed_string_t dst_pool;
13061         uint8_t dst_pool_val;
13062         cmdline_fixed_string_t port;
13063         portid_t port_id;
13064         cmdline_fixed_string_t vf;
13065         uint8_t vf_id;
13066 };
13067
13068 /* Common CLI fields for all E-tag configuration */
13069 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_config_e_tag_result,
13072                  e_tag, "E-tag");
13073 cmdline_parse_token_string_t cmd_config_e_tag_set =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_config_e_tag_result,
13076                  set, "set");
13077 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13078         TOKEN_STRING_INITIALIZER
13079                 (struct cmd_config_e_tag_result,
13080                  insertion, "insertion");
13081 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_config_e_tag_result,
13084                  stripping, "stripping");
13085 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13086         TOKEN_STRING_INITIALIZER
13087                 (struct cmd_config_e_tag_result,
13088                  forwarding, "forwarding");
13089 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13090         TOKEN_STRING_INITIALIZER
13091                 (struct cmd_config_e_tag_result,
13092                  filter, "filter");
13093 cmdline_parse_token_string_t cmd_config_e_tag_add =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_config_e_tag_result,
13096                  add, "add");
13097 cmdline_parse_token_string_t cmd_config_e_tag_del =
13098         TOKEN_STRING_INITIALIZER
13099                 (struct cmd_config_e_tag_result,
13100                  del, "del");
13101 cmdline_parse_token_string_t cmd_config_e_tag_on =
13102         TOKEN_STRING_INITIALIZER
13103                 (struct cmd_config_e_tag_result,
13104                  on, "on");
13105 cmdline_parse_token_string_t cmd_config_e_tag_off =
13106         TOKEN_STRING_INITIALIZER
13107                 (struct cmd_config_e_tag_result,
13108                  off, "off");
13109 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13110         TOKEN_STRING_INITIALIZER
13111                 (struct cmd_config_e_tag_result,
13112                  on_off, "on#off");
13113 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13114         TOKEN_STRING_INITIALIZER
13115                 (struct cmd_config_e_tag_result,
13116                  port_tag_id, "port-tag-id");
13117 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13118         TOKEN_NUM_INITIALIZER
13119                 (struct cmd_config_e_tag_result,
13120                  port_tag_id_val, UINT32);
13121 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13122         TOKEN_STRING_INITIALIZER
13123                 (struct cmd_config_e_tag_result,
13124                  e_tag_id, "e-tag-id");
13125 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13126         TOKEN_NUM_INITIALIZER
13127                 (struct cmd_config_e_tag_result,
13128                  e_tag_id_val, UINT16);
13129 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13130         TOKEN_STRING_INITIALIZER
13131                 (struct cmd_config_e_tag_result,
13132                  dst_pool, "dst-pool");
13133 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13134         TOKEN_NUM_INITIALIZER
13135                 (struct cmd_config_e_tag_result,
13136                  dst_pool_val, UINT8);
13137 cmdline_parse_token_string_t cmd_config_e_tag_port =
13138         TOKEN_STRING_INITIALIZER
13139                 (struct cmd_config_e_tag_result,
13140                  port, "port");
13141 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13142         TOKEN_NUM_INITIALIZER
13143                 (struct cmd_config_e_tag_result,
13144                  port_id, UINT16);
13145 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13146         TOKEN_STRING_INITIALIZER
13147                 (struct cmd_config_e_tag_result,
13148                  vf, "vf");
13149 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13150         TOKEN_NUM_INITIALIZER
13151                 (struct cmd_config_e_tag_result,
13152                  vf_id, UINT8);
13153
13154 /* E-tag insertion configuration */
13155 static void
13156 cmd_config_e_tag_insertion_en_parsed(
13157         void *parsed_result,
13158         __rte_unused struct cmdline *cl,
13159         __rte_unused void *data)
13160 {
13161         struct cmd_config_e_tag_result *res =
13162                 parsed_result;
13163         struct rte_eth_l2_tunnel_conf entry;
13164
13165         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13166                 return;
13167
13168         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13169         entry.tunnel_id = res->port_tag_id_val;
13170         entry.vf_id = res->vf_id;
13171         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13172                                           &entry,
13173                                           ETH_L2_TUNNEL_INSERTION_MASK,
13174                                           1);
13175 }
13176
13177 static void
13178 cmd_config_e_tag_insertion_dis_parsed(
13179         void *parsed_result,
13180         __rte_unused struct cmdline *cl,
13181         __rte_unused void *data)
13182 {
13183         struct cmd_config_e_tag_result *res =
13184                 parsed_result;
13185         struct rte_eth_l2_tunnel_conf entry;
13186
13187         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13188                 return;
13189
13190         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13191         entry.vf_id = res->vf_id;
13192
13193         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13194                                           &entry,
13195                                           ETH_L2_TUNNEL_INSERTION_MASK,
13196                                           0);
13197 }
13198
13199 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13200         .f = cmd_config_e_tag_insertion_en_parsed,
13201         .data = NULL,
13202         .help_str = "E-tag ... : E-tag insertion enable",
13203         .tokens = {
13204                 (void *)&cmd_config_e_tag_e_tag,
13205                 (void *)&cmd_config_e_tag_set,
13206                 (void *)&cmd_config_e_tag_insertion,
13207                 (void *)&cmd_config_e_tag_on,
13208                 (void *)&cmd_config_e_tag_port_tag_id,
13209                 (void *)&cmd_config_e_tag_port_tag_id_val,
13210                 (void *)&cmd_config_e_tag_port,
13211                 (void *)&cmd_config_e_tag_port_id,
13212                 (void *)&cmd_config_e_tag_vf,
13213                 (void *)&cmd_config_e_tag_vf_id,
13214                 NULL,
13215         },
13216 };
13217
13218 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13219         .f = cmd_config_e_tag_insertion_dis_parsed,
13220         .data = NULL,
13221         .help_str = "E-tag ... : E-tag insertion disable",
13222         .tokens = {
13223                 (void *)&cmd_config_e_tag_e_tag,
13224                 (void *)&cmd_config_e_tag_set,
13225                 (void *)&cmd_config_e_tag_insertion,
13226                 (void *)&cmd_config_e_tag_off,
13227                 (void *)&cmd_config_e_tag_port,
13228                 (void *)&cmd_config_e_tag_port_id,
13229                 (void *)&cmd_config_e_tag_vf,
13230                 (void *)&cmd_config_e_tag_vf_id,
13231                 NULL,
13232         },
13233 };
13234
13235 /* E-tag stripping configuration */
13236 static void
13237 cmd_config_e_tag_stripping_parsed(
13238         void *parsed_result,
13239         __rte_unused struct cmdline *cl,
13240         __rte_unused void *data)
13241 {
13242         struct cmd_config_e_tag_result *res =
13243                 parsed_result;
13244         struct rte_eth_l2_tunnel_conf entry;
13245
13246         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13247                 return;
13248
13249         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13250
13251         if (!strcmp(res->on_off, "on"))
13252                 rte_eth_dev_l2_tunnel_offload_set
13253                         (res->port_id,
13254                          &entry,
13255                          ETH_L2_TUNNEL_STRIPPING_MASK,
13256                          1);
13257         else
13258                 rte_eth_dev_l2_tunnel_offload_set
13259                         (res->port_id,
13260                          &entry,
13261                          ETH_L2_TUNNEL_STRIPPING_MASK,
13262                          0);
13263 }
13264
13265 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13266         .f = cmd_config_e_tag_stripping_parsed,
13267         .data = NULL,
13268         .help_str = "E-tag ... : E-tag stripping enable/disable",
13269         .tokens = {
13270                 (void *)&cmd_config_e_tag_e_tag,
13271                 (void *)&cmd_config_e_tag_set,
13272                 (void *)&cmd_config_e_tag_stripping,
13273                 (void *)&cmd_config_e_tag_on_off,
13274                 (void *)&cmd_config_e_tag_port,
13275                 (void *)&cmd_config_e_tag_port_id,
13276                 NULL,
13277         },
13278 };
13279
13280 /* E-tag forwarding configuration */
13281 static void
13282 cmd_config_e_tag_forwarding_parsed(
13283         void *parsed_result,
13284         __rte_unused struct cmdline *cl,
13285         __rte_unused void *data)
13286 {
13287         struct cmd_config_e_tag_result *res = parsed_result;
13288         struct rte_eth_l2_tunnel_conf entry;
13289
13290         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13291                 return;
13292
13293         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13294
13295         if (!strcmp(res->on_off, "on"))
13296                 rte_eth_dev_l2_tunnel_offload_set
13297                         (res->port_id,
13298                          &entry,
13299                          ETH_L2_TUNNEL_FORWARDING_MASK,
13300                          1);
13301         else
13302                 rte_eth_dev_l2_tunnel_offload_set
13303                         (res->port_id,
13304                          &entry,
13305                          ETH_L2_TUNNEL_FORWARDING_MASK,
13306                          0);
13307 }
13308
13309 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13310         .f = cmd_config_e_tag_forwarding_parsed,
13311         .data = NULL,
13312         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13313         .tokens = {
13314                 (void *)&cmd_config_e_tag_e_tag,
13315                 (void *)&cmd_config_e_tag_set,
13316                 (void *)&cmd_config_e_tag_forwarding,
13317                 (void *)&cmd_config_e_tag_on_off,
13318                 (void *)&cmd_config_e_tag_port,
13319                 (void *)&cmd_config_e_tag_port_id,
13320                 NULL,
13321         },
13322 };
13323
13324 /* E-tag filter configuration */
13325 static void
13326 cmd_config_e_tag_filter_add_parsed(
13327         void *parsed_result,
13328         __rte_unused struct cmdline *cl,
13329         __rte_unused void *data)
13330 {
13331         struct cmd_config_e_tag_result *res = parsed_result;
13332         struct rte_eth_l2_tunnel_conf entry;
13333         int ret = 0;
13334
13335         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13336                 return;
13337
13338         if (res->e_tag_id_val > 0x3fff) {
13339                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13340                 return;
13341         }
13342
13343         ret = rte_eth_dev_filter_supported(res->port_id,
13344                                            RTE_ETH_FILTER_L2_TUNNEL);
13345         if (ret < 0) {
13346                 printf("E-tag filter is not supported on port %u.\n",
13347                        res->port_id);
13348                 return;
13349         }
13350
13351         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13352         entry.tunnel_id = res->e_tag_id_val;
13353         entry.pool = res->dst_pool_val;
13354
13355         ret = rte_eth_dev_filter_ctrl(res->port_id,
13356                                       RTE_ETH_FILTER_L2_TUNNEL,
13357                                       RTE_ETH_FILTER_ADD,
13358                                       &entry);
13359         if (ret < 0)
13360                 printf("E-tag filter programming error: (%s)\n",
13361                        strerror(-ret));
13362 }
13363
13364 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13365         .f = cmd_config_e_tag_filter_add_parsed,
13366         .data = NULL,
13367         .help_str = "E-tag ... : E-tag filter add",
13368         .tokens = {
13369                 (void *)&cmd_config_e_tag_e_tag,
13370                 (void *)&cmd_config_e_tag_set,
13371                 (void *)&cmd_config_e_tag_filter,
13372                 (void *)&cmd_config_e_tag_add,
13373                 (void *)&cmd_config_e_tag_e_tag_id,
13374                 (void *)&cmd_config_e_tag_e_tag_id_val,
13375                 (void *)&cmd_config_e_tag_dst_pool,
13376                 (void *)&cmd_config_e_tag_dst_pool_val,
13377                 (void *)&cmd_config_e_tag_port,
13378                 (void *)&cmd_config_e_tag_port_id,
13379                 NULL,
13380         },
13381 };
13382
13383 static void
13384 cmd_config_e_tag_filter_del_parsed(
13385         void *parsed_result,
13386         __rte_unused struct cmdline *cl,
13387         __rte_unused void *data)
13388 {
13389         struct cmd_config_e_tag_result *res = parsed_result;
13390         struct rte_eth_l2_tunnel_conf entry;
13391         int ret = 0;
13392
13393         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13394                 return;
13395
13396         if (res->e_tag_id_val > 0x3fff) {
13397                 printf("e-tag-id must be less than 0x3fff.\n");
13398                 return;
13399         }
13400
13401         ret = rte_eth_dev_filter_supported(res->port_id,
13402                                            RTE_ETH_FILTER_L2_TUNNEL);
13403         if (ret < 0) {
13404                 printf("E-tag filter is not supported on port %u.\n",
13405                        res->port_id);
13406                 return;
13407         }
13408
13409         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13410         entry.tunnel_id = res->e_tag_id_val;
13411
13412         ret = rte_eth_dev_filter_ctrl(res->port_id,
13413                                       RTE_ETH_FILTER_L2_TUNNEL,
13414                                       RTE_ETH_FILTER_DELETE,
13415                                       &entry);
13416         if (ret < 0)
13417                 printf("E-tag filter programming error: (%s)\n",
13418                        strerror(-ret));
13419 }
13420
13421 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13422         .f = cmd_config_e_tag_filter_del_parsed,
13423         .data = NULL,
13424         .help_str = "E-tag ... : E-tag filter delete",
13425         .tokens = {
13426                 (void *)&cmd_config_e_tag_e_tag,
13427                 (void *)&cmd_config_e_tag_set,
13428                 (void *)&cmd_config_e_tag_filter,
13429                 (void *)&cmd_config_e_tag_del,
13430                 (void *)&cmd_config_e_tag_e_tag_id,
13431                 (void *)&cmd_config_e_tag_e_tag_id_val,
13432                 (void *)&cmd_config_e_tag_port,
13433                 (void *)&cmd_config_e_tag_port_id,
13434                 NULL,
13435         },
13436 };
13437
13438 /* vf vlan anti spoof configuration */
13439
13440 /* Common result structure for vf vlan anti spoof */
13441 struct cmd_vf_vlan_anti_spoof_result {
13442         cmdline_fixed_string_t set;
13443         cmdline_fixed_string_t vf;
13444         cmdline_fixed_string_t vlan;
13445         cmdline_fixed_string_t antispoof;
13446         portid_t port_id;
13447         uint32_t vf_id;
13448         cmdline_fixed_string_t on_off;
13449 };
13450
13451 /* Common CLI fields for vf vlan anti spoof enable disable */
13452 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13453         TOKEN_STRING_INITIALIZER
13454                 (struct cmd_vf_vlan_anti_spoof_result,
13455                  set, "set");
13456 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13457         TOKEN_STRING_INITIALIZER
13458                 (struct cmd_vf_vlan_anti_spoof_result,
13459                  vf, "vf");
13460 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13461         TOKEN_STRING_INITIALIZER
13462                 (struct cmd_vf_vlan_anti_spoof_result,
13463                  vlan, "vlan");
13464 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13465         TOKEN_STRING_INITIALIZER
13466                 (struct cmd_vf_vlan_anti_spoof_result,
13467                  antispoof, "antispoof");
13468 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13469         TOKEN_NUM_INITIALIZER
13470                 (struct cmd_vf_vlan_anti_spoof_result,
13471                  port_id, UINT16);
13472 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13473         TOKEN_NUM_INITIALIZER
13474                 (struct cmd_vf_vlan_anti_spoof_result,
13475                  vf_id, UINT32);
13476 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13477         TOKEN_STRING_INITIALIZER
13478                 (struct cmd_vf_vlan_anti_spoof_result,
13479                  on_off, "on#off");
13480
13481 static void
13482 cmd_set_vf_vlan_anti_spoof_parsed(
13483         void *parsed_result,
13484         __rte_unused struct cmdline *cl,
13485         __rte_unused void *data)
13486 {
13487         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13488         int ret = -ENOTSUP;
13489
13490         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13491
13492         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13493                 return;
13494
13495 #ifdef RTE_LIBRTE_IXGBE_PMD
13496         if (ret == -ENOTSUP)
13497                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13498                                 res->vf_id, is_on);
13499 #endif
13500 #ifdef RTE_LIBRTE_I40E_PMD
13501         if (ret == -ENOTSUP)
13502                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13503                                 res->vf_id, is_on);
13504 #endif
13505 #ifdef RTE_LIBRTE_BNXT_PMD
13506         if (ret == -ENOTSUP)
13507                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13508                                 res->vf_id, is_on);
13509 #endif
13510
13511         switch (ret) {
13512         case 0:
13513                 break;
13514         case -EINVAL:
13515                 printf("invalid vf_id %d\n", res->vf_id);
13516                 break;
13517         case -ENODEV:
13518                 printf("invalid port_id %d\n", res->port_id);
13519                 break;
13520         case -ENOTSUP:
13521                 printf("function not implemented\n");
13522                 break;
13523         default:
13524                 printf("programming error: (%s)\n", strerror(-ret));
13525         }
13526 }
13527
13528 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13529         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13530         .data = NULL,
13531         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13532         .tokens = {
13533                 (void *)&cmd_vf_vlan_anti_spoof_set,
13534                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13535                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13536                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13537                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13538                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13539                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13540                 NULL,
13541         },
13542 };
13543
13544 /* vf mac anti spoof configuration */
13545
13546 /* Common result structure for vf mac anti spoof */
13547 struct cmd_vf_mac_anti_spoof_result {
13548         cmdline_fixed_string_t set;
13549         cmdline_fixed_string_t vf;
13550         cmdline_fixed_string_t mac;
13551         cmdline_fixed_string_t antispoof;
13552         portid_t port_id;
13553         uint32_t vf_id;
13554         cmdline_fixed_string_t on_off;
13555 };
13556
13557 /* Common CLI fields for vf mac anti spoof enable disable */
13558 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13559         TOKEN_STRING_INITIALIZER
13560                 (struct cmd_vf_mac_anti_spoof_result,
13561                  set, "set");
13562 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13563         TOKEN_STRING_INITIALIZER
13564                 (struct cmd_vf_mac_anti_spoof_result,
13565                  vf, "vf");
13566 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13567         TOKEN_STRING_INITIALIZER
13568                 (struct cmd_vf_mac_anti_spoof_result,
13569                  mac, "mac");
13570 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13571         TOKEN_STRING_INITIALIZER
13572                 (struct cmd_vf_mac_anti_spoof_result,
13573                  antispoof, "antispoof");
13574 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13575         TOKEN_NUM_INITIALIZER
13576                 (struct cmd_vf_mac_anti_spoof_result,
13577                  port_id, UINT16);
13578 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13579         TOKEN_NUM_INITIALIZER
13580                 (struct cmd_vf_mac_anti_spoof_result,
13581                  vf_id, UINT32);
13582 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13583         TOKEN_STRING_INITIALIZER
13584                 (struct cmd_vf_mac_anti_spoof_result,
13585                  on_off, "on#off");
13586
13587 static void
13588 cmd_set_vf_mac_anti_spoof_parsed(
13589         void *parsed_result,
13590         __rte_unused struct cmdline *cl,
13591         __rte_unused void *data)
13592 {
13593         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13594         int ret = -ENOTSUP;
13595
13596         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13597
13598         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13599                 return;
13600
13601 #ifdef RTE_LIBRTE_IXGBE_PMD
13602         if (ret == -ENOTSUP)
13603                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13604                         res->vf_id, is_on);
13605 #endif
13606 #ifdef RTE_LIBRTE_I40E_PMD
13607         if (ret == -ENOTSUP)
13608                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13609                         res->vf_id, is_on);
13610 #endif
13611 #ifdef RTE_LIBRTE_BNXT_PMD
13612         if (ret == -ENOTSUP)
13613                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13614                         res->vf_id, is_on);
13615 #endif
13616
13617         switch (ret) {
13618         case 0:
13619                 break;
13620         case -EINVAL:
13621                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13622                 break;
13623         case -ENODEV:
13624                 printf("invalid port_id %d\n", res->port_id);
13625                 break;
13626         case -ENOTSUP:
13627                 printf("function not implemented\n");
13628                 break;
13629         default:
13630                 printf("programming error: (%s)\n", strerror(-ret));
13631         }
13632 }
13633
13634 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13635         .f = cmd_set_vf_mac_anti_spoof_parsed,
13636         .data = NULL,
13637         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13638         .tokens = {
13639                 (void *)&cmd_vf_mac_anti_spoof_set,
13640                 (void *)&cmd_vf_mac_anti_spoof_vf,
13641                 (void *)&cmd_vf_mac_anti_spoof_mac,
13642                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13643                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13644                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13645                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13646                 NULL,
13647         },
13648 };
13649
13650 /* vf vlan strip queue configuration */
13651
13652 /* Common result structure for vf mac anti spoof */
13653 struct cmd_vf_vlan_stripq_result {
13654         cmdline_fixed_string_t set;
13655         cmdline_fixed_string_t vf;
13656         cmdline_fixed_string_t vlan;
13657         cmdline_fixed_string_t stripq;
13658         portid_t port_id;
13659         uint16_t vf_id;
13660         cmdline_fixed_string_t on_off;
13661 };
13662
13663 /* Common CLI fields for vf vlan strip enable disable */
13664 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13665         TOKEN_STRING_INITIALIZER
13666                 (struct cmd_vf_vlan_stripq_result,
13667                  set, "set");
13668 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13669         TOKEN_STRING_INITIALIZER
13670                 (struct cmd_vf_vlan_stripq_result,
13671                  vf, "vf");
13672 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13673         TOKEN_STRING_INITIALIZER
13674                 (struct cmd_vf_vlan_stripq_result,
13675                  vlan, "vlan");
13676 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13677         TOKEN_STRING_INITIALIZER
13678                 (struct cmd_vf_vlan_stripq_result,
13679                  stripq, "stripq");
13680 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13681         TOKEN_NUM_INITIALIZER
13682                 (struct cmd_vf_vlan_stripq_result,
13683                  port_id, UINT16);
13684 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13685         TOKEN_NUM_INITIALIZER
13686                 (struct cmd_vf_vlan_stripq_result,
13687                  vf_id, UINT16);
13688 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13689         TOKEN_STRING_INITIALIZER
13690                 (struct cmd_vf_vlan_stripq_result,
13691                  on_off, "on#off");
13692
13693 static void
13694 cmd_set_vf_vlan_stripq_parsed(
13695         void *parsed_result,
13696         __rte_unused struct cmdline *cl,
13697         __rte_unused void *data)
13698 {
13699         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13700         int ret = -ENOTSUP;
13701
13702         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13703
13704         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13705                 return;
13706
13707 #ifdef RTE_LIBRTE_IXGBE_PMD
13708         if (ret == -ENOTSUP)
13709                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13710                         res->vf_id, is_on);
13711 #endif
13712 #ifdef RTE_LIBRTE_I40E_PMD
13713         if (ret == -ENOTSUP)
13714                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13715                         res->vf_id, is_on);
13716 #endif
13717 #ifdef RTE_LIBRTE_BNXT_PMD
13718         if (ret == -ENOTSUP)
13719                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13720                         res->vf_id, is_on);
13721 #endif
13722
13723         switch (ret) {
13724         case 0:
13725                 break;
13726         case -EINVAL:
13727                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13728                 break;
13729         case -ENODEV:
13730                 printf("invalid port_id %d\n", res->port_id);
13731                 break;
13732         case -ENOTSUP:
13733                 printf("function not implemented\n");
13734                 break;
13735         default:
13736                 printf("programming error: (%s)\n", strerror(-ret));
13737         }
13738 }
13739
13740 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13741         .f = cmd_set_vf_vlan_stripq_parsed,
13742         .data = NULL,
13743         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13744         .tokens = {
13745                 (void *)&cmd_vf_vlan_stripq_set,
13746                 (void *)&cmd_vf_vlan_stripq_vf,
13747                 (void *)&cmd_vf_vlan_stripq_vlan,
13748                 (void *)&cmd_vf_vlan_stripq_stripq,
13749                 (void *)&cmd_vf_vlan_stripq_port_id,
13750                 (void *)&cmd_vf_vlan_stripq_vf_id,
13751                 (void *)&cmd_vf_vlan_stripq_on_off,
13752                 NULL,
13753         },
13754 };
13755
13756 /* vf vlan insert configuration */
13757
13758 /* Common result structure for vf vlan insert */
13759 struct cmd_vf_vlan_insert_result {
13760         cmdline_fixed_string_t set;
13761         cmdline_fixed_string_t vf;
13762         cmdline_fixed_string_t vlan;
13763         cmdline_fixed_string_t insert;
13764         portid_t port_id;
13765         uint16_t vf_id;
13766         uint16_t vlan_id;
13767 };
13768
13769 /* Common CLI fields for vf vlan insert enable disable */
13770 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13771         TOKEN_STRING_INITIALIZER
13772                 (struct cmd_vf_vlan_insert_result,
13773                  set, "set");
13774 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13775         TOKEN_STRING_INITIALIZER
13776                 (struct cmd_vf_vlan_insert_result,
13777                  vf, "vf");
13778 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13779         TOKEN_STRING_INITIALIZER
13780                 (struct cmd_vf_vlan_insert_result,
13781                  vlan, "vlan");
13782 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13783         TOKEN_STRING_INITIALIZER
13784                 (struct cmd_vf_vlan_insert_result,
13785                  insert, "insert");
13786 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13787         TOKEN_NUM_INITIALIZER
13788                 (struct cmd_vf_vlan_insert_result,
13789                  port_id, UINT16);
13790 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13791         TOKEN_NUM_INITIALIZER
13792                 (struct cmd_vf_vlan_insert_result,
13793                  vf_id, UINT16);
13794 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13795         TOKEN_NUM_INITIALIZER
13796                 (struct cmd_vf_vlan_insert_result,
13797                  vlan_id, UINT16);
13798
13799 static void
13800 cmd_set_vf_vlan_insert_parsed(
13801         void *parsed_result,
13802         __rte_unused struct cmdline *cl,
13803         __rte_unused void *data)
13804 {
13805         struct cmd_vf_vlan_insert_result *res = parsed_result;
13806         int ret = -ENOTSUP;
13807
13808         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13809                 return;
13810
13811 #ifdef RTE_LIBRTE_IXGBE_PMD
13812         if (ret == -ENOTSUP)
13813                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13814                         res->vlan_id);
13815 #endif
13816 #ifdef RTE_LIBRTE_I40E_PMD
13817         if (ret == -ENOTSUP)
13818                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13819                         res->vlan_id);
13820 #endif
13821 #ifdef RTE_LIBRTE_BNXT_PMD
13822         if (ret == -ENOTSUP)
13823                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13824                         res->vlan_id);
13825 #endif
13826
13827         switch (ret) {
13828         case 0:
13829                 break;
13830         case -EINVAL:
13831                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13832                 break;
13833         case -ENODEV:
13834                 printf("invalid port_id %d\n", res->port_id);
13835                 break;
13836         case -ENOTSUP:
13837                 printf("function not implemented\n");
13838                 break;
13839         default:
13840                 printf("programming error: (%s)\n", strerror(-ret));
13841         }
13842 }
13843
13844 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13845         .f = cmd_set_vf_vlan_insert_parsed,
13846         .data = NULL,
13847         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13848         .tokens = {
13849                 (void *)&cmd_vf_vlan_insert_set,
13850                 (void *)&cmd_vf_vlan_insert_vf,
13851                 (void *)&cmd_vf_vlan_insert_vlan,
13852                 (void *)&cmd_vf_vlan_insert_insert,
13853                 (void *)&cmd_vf_vlan_insert_port_id,
13854                 (void *)&cmd_vf_vlan_insert_vf_id,
13855                 (void *)&cmd_vf_vlan_insert_vlan_id,
13856                 NULL,
13857         },
13858 };
13859
13860 /* tx loopback configuration */
13861
13862 /* Common result structure for tx loopback */
13863 struct cmd_tx_loopback_result {
13864         cmdline_fixed_string_t set;
13865         cmdline_fixed_string_t tx;
13866         cmdline_fixed_string_t loopback;
13867         portid_t port_id;
13868         cmdline_fixed_string_t on_off;
13869 };
13870
13871 /* Common CLI fields for tx loopback enable disable */
13872 cmdline_parse_token_string_t cmd_tx_loopback_set =
13873         TOKEN_STRING_INITIALIZER
13874                 (struct cmd_tx_loopback_result,
13875                  set, "set");
13876 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13877         TOKEN_STRING_INITIALIZER
13878                 (struct cmd_tx_loopback_result,
13879                  tx, "tx");
13880 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13881         TOKEN_STRING_INITIALIZER
13882                 (struct cmd_tx_loopback_result,
13883                  loopback, "loopback");
13884 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13885         TOKEN_NUM_INITIALIZER
13886                 (struct cmd_tx_loopback_result,
13887                  port_id, UINT16);
13888 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13889         TOKEN_STRING_INITIALIZER
13890                 (struct cmd_tx_loopback_result,
13891                  on_off, "on#off");
13892
13893 static void
13894 cmd_set_tx_loopback_parsed(
13895         void *parsed_result,
13896         __rte_unused struct cmdline *cl,
13897         __rte_unused void *data)
13898 {
13899         struct cmd_tx_loopback_result *res = parsed_result;
13900         int ret = -ENOTSUP;
13901
13902         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13903
13904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13905                 return;
13906
13907 #ifdef RTE_LIBRTE_IXGBE_PMD
13908         if (ret == -ENOTSUP)
13909                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13910 #endif
13911 #ifdef RTE_LIBRTE_I40E_PMD
13912         if (ret == -ENOTSUP)
13913                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13914 #endif
13915 #ifdef RTE_LIBRTE_BNXT_PMD
13916         if (ret == -ENOTSUP)
13917                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13918 #endif
13919 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13920         if (ret == -ENOTSUP)
13921                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13922 #endif
13923
13924         switch (ret) {
13925         case 0:
13926                 break;
13927         case -EINVAL:
13928                 printf("invalid is_on %d\n", is_on);
13929                 break;
13930         case -ENODEV:
13931                 printf("invalid port_id %d\n", res->port_id);
13932                 break;
13933         case -ENOTSUP:
13934                 printf("function not implemented\n");
13935                 break;
13936         default:
13937                 printf("programming error: (%s)\n", strerror(-ret));
13938         }
13939 }
13940
13941 cmdline_parse_inst_t cmd_set_tx_loopback = {
13942         .f = cmd_set_tx_loopback_parsed,
13943         .data = NULL,
13944         .help_str = "set tx loopback <port_id> on|off",
13945         .tokens = {
13946                 (void *)&cmd_tx_loopback_set,
13947                 (void *)&cmd_tx_loopback_tx,
13948                 (void *)&cmd_tx_loopback_loopback,
13949                 (void *)&cmd_tx_loopback_port_id,
13950                 (void *)&cmd_tx_loopback_on_off,
13951                 NULL,
13952         },
13953 };
13954
13955 /* all queues drop enable configuration */
13956
13957 /* Common result structure for all queues drop enable */
13958 struct cmd_all_queues_drop_en_result {
13959         cmdline_fixed_string_t set;
13960         cmdline_fixed_string_t all;
13961         cmdline_fixed_string_t queues;
13962         cmdline_fixed_string_t drop;
13963         portid_t port_id;
13964         cmdline_fixed_string_t on_off;
13965 };
13966
13967 /* Common CLI fields for tx loopback enable disable */
13968 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_all_queues_drop_en_result,
13971                  set, "set");
13972 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13973         TOKEN_STRING_INITIALIZER
13974                 (struct cmd_all_queues_drop_en_result,
13975                  all, "all");
13976 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13977         TOKEN_STRING_INITIALIZER
13978                 (struct cmd_all_queues_drop_en_result,
13979                  queues, "queues");
13980 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13981         TOKEN_STRING_INITIALIZER
13982                 (struct cmd_all_queues_drop_en_result,
13983                  drop, "drop");
13984 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13985         TOKEN_NUM_INITIALIZER
13986                 (struct cmd_all_queues_drop_en_result,
13987                  port_id, UINT16);
13988 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13989         TOKEN_STRING_INITIALIZER
13990                 (struct cmd_all_queues_drop_en_result,
13991                  on_off, "on#off");
13992
13993 static void
13994 cmd_set_all_queues_drop_en_parsed(
13995         void *parsed_result,
13996         __rte_unused struct cmdline *cl,
13997         __rte_unused void *data)
13998 {
13999         struct cmd_all_queues_drop_en_result *res = parsed_result;
14000         int ret = -ENOTSUP;
14001         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14002
14003         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14004                 return;
14005
14006 #ifdef RTE_LIBRTE_IXGBE_PMD
14007         if (ret == -ENOTSUP)
14008                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14009 #endif
14010 #ifdef RTE_LIBRTE_BNXT_PMD
14011         if (ret == -ENOTSUP)
14012                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14013 #endif
14014         switch (ret) {
14015         case 0:
14016                 break;
14017         case -EINVAL:
14018                 printf("invalid is_on %d\n", is_on);
14019                 break;
14020         case -ENODEV:
14021                 printf("invalid port_id %d\n", res->port_id);
14022                 break;
14023         case -ENOTSUP:
14024                 printf("function not implemented\n");
14025                 break;
14026         default:
14027                 printf("programming error: (%s)\n", strerror(-ret));
14028         }
14029 }
14030
14031 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14032         .f = cmd_set_all_queues_drop_en_parsed,
14033         .data = NULL,
14034         .help_str = "set all queues drop <port_id> on|off",
14035         .tokens = {
14036                 (void *)&cmd_all_queues_drop_en_set,
14037                 (void *)&cmd_all_queues_drop_en_all,
14038                 (void *)&cmd_all_queues_drop_en_queues,
14039                 (void *)&cmd_all_queues_drop_en_drop,
14040                 (void *)&cmd_all_queues_drop_en_port_id,
14041                 (void *)&cmd_all_queues_drop_en_on_off,
14042                 NULL,
14043         },
14044 };
14045
14046 /* vf split drop enable configuration */
14047
14048 /* Common result structure for vf split drop enable */
14049 struct cmd_vf_split_drop_en_result {
14050         cmdline_fixed_string_t set;
14051         cmdline_fixed_string_t vf;
14052         cmdline_fixed_string_t split;
14053         cmdline_fixed_string_t drop;
14054         portid_t port_id;
14055         uint16_t vf_id;
14056         cmdline_fixed_string_t on_off;
14057 };
14058
14059 /* Common CLI fields for vf split drop enable disable */
14060 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14061         TOKEN_STRING_INITIALIZER
14062                 (struct cmd_vf_split_drop_en_result,
14063                  set, "set");
14064 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14065         TOKEN_STRING_INITIALIZER
14066                 (struct cmd_vf_split_drop_en_result,
14067                  vf, "vf");
14068 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14069         TOKEN_STRING_INITIALIZER
14070                 (struct cmd_vf_split_drop_en_result,
14071                  split, "split");
14072 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14073         TOKEN_STRING_INITIALIZER
14074                 (struct cmd_vf_split_drop_en_result,
14075                  drop, "drop");
14076 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14077         TOKEN_NUM_INITIALIZER
14078                 (struct cmd_vf_split_drop_en_result,
14079                  port_id, UINT16);
14080 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14081         TOKEN_NUM_INITIALIZER
14082                 (struct cmd_vf_split_drop_en_result,
14083                  vf_id, UINT16);
14084 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14085         TOKEN_STRING_INITIALIZER
14086                 (struct cmd_vf_split_drop_en_result,
14087                  on_off, "on#off");
14088
14089 static void
14090 cmd_set_vf_split_drop_en_parsed(
14091         void *parsed_result,
14092         __rte_unused struct cmdline *cl,
14093         __rte_unused void *data)
14094 {
14095         struct cmd_vf_split_drop_en_result *res = parsed_result;
14096         int ret = -ENOTSUP;
14097         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14098
14099         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14100                 return;
14101
14102 #ifdef RTE_LIBRTE_IXGBE_PMD
14103         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14104                         is_on);
14105 #endif
14106         switch (ret) {
14107         case 0:
14108                 break;
14109         case -EINVAL:
14110                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14111                 break;
14112         case -ENODEV:
14113                 printf("invalid port_id %d\n", res->port_id);
14114                 break;
14115         case -ENOTSUP:
14116                 printf("not supported on port %d\n", res->port_id);
14117                 break;
14118         default:
14119                 printf("programming error: (%s)\n", strerror(-ret));
14120         }
14121 }
14122
14123 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14124         .f = cmd_set_vf_split_drop_en_parsed,
14125         .data = NULL,
14126         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14127         .tokens = {
14128                 (void *)&cmd_vf_split_drop_en_set,
14129                 (void *)&cmd_vf_split_drop_en_vf,
14130                 (void *)&cmd_vf_split_drop_en_split,
14131                 (void *)&cmd_vf_split_drop_en_drop,
14132                 (void *)&cmd_vf_split_drop_en_port_id,
14133                 (void *)&cmd_vf_split_drop_en_vf_id,
14134                 (void *)&cmd_vf_split_drop_en_on_off,
14135                 NULL,
14136         },
14137 };
14138
14139 /* vf mac address configuration */
14140
14141 /* Common result structure for vf mac address */
14142 struct cmd_set_vf_mac_addr_result {
14143         cmdline_fixed_string_t set;
14144         cmdline_fixed_string_t vf;
14145         cmdline_fixed_string_t mac;
14146         cmdline_fixed_string_t addr;
14147         portid_t port_id;
14148         uint16_t vf_id;
14149         struct rte_ether_addr mac_addr;
14150
14151 };
14152
14153 /* Common CLI fields for vf split drop enable disable */
14154 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14155         TOKEN_STRING_INITIALIZER
14156                 (struct cmd_set_vf_mac_addr_result,
14157                  set, "set");
14158 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14159         TOKEN_STRING_INITIALIZER
14160                 (struct cmd_set_vf_mac_addr_result,
14161                  vf, "vf");
14162 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14163         TOKEN_STRING_INITIALIZER
14164                 (struct cmd_set_vf_mac_addr_result,
14165                  mac, "mac");
14166 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14167         TOKEN_STRING_INITIALIZER
14168                 (struct cmd_set_vf_mac_addr_result,
14169                  addr, "addr");
14170 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14171         TOKEN_NUM_INITIALIZER
14172                 (struct cmd_set_vf_mac_addr_result,
14173                  port_id, UINT16);
14174 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14175         TOKEN_NUM_INITIALIZER
14176                 (struct cmd_set_vf_mac_addr_result,
14177                  vf_id, UINT16);
14178 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14179         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14180                  mac_addr);
14181
14182 static void
14183 cmd_set_vf_mac_addr_parsed(
14184         void *parsed_result,
14185         __rte_unused struct cmdline *cl,
14186         __rte_unused void *data)
14187 {
14188         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14189         int ret = -ENOTSUP;
14190
14191         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14192                 return;
14193
14194 #ifdef RTE_LIBRTE_IXGBE_PMD
14195         if (ret == -ENOTSUP)
14196                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14197                                 &res->mac_addr);
14198 #endif
14199 #ifdef RTE_LIBRTE_I40E_PMD
14200         if (ret == -ENOTSUP)
14201                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14202                                 &res->mac_addr);
14203 #endif
14204 #ifdef RTE_LIBRTE_BNXT_PMD
14205         if (ret == -ENOTSUP)
14206                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14207                                 &res->mac_addr);
14208 #endif
14209
14210         switch (ret) {
14211         case 0:
14212                 break;
14213         case -EINVAL:
14214                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14215                 break;
14216         case -ENODEV:
14217                 printf("invalid port_id %d\n", res->port_id);
14218                 break;
14219         case -ENOTSUP:
14220                 printf("function not implemented\n");
14221                 break;
14222         default:
14223                 printf("programming error: (%s)\n", strerror(-ret));
14224         }
14225 }
14226
14227 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14228         .f = cmd_set_vf_mac_addr_parsed,
14229         .data = NULL,
14230         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14231         .tokens = {
14232                 (void *)&cmd_set_vf_mac_addr_set,
14233                 (void *)&cmd_set_vf_mac_addr_vf,
14234                 (void *)&cmd_set_vf_mac_addr_mac,
14235                 (void *)&cmd_set_vf_mac_addr_addr,
14236                 (void *)&cmd_set_vf_mac_addr_port_id,
14237                 (void *)&cmd_set_vf_mac_addr_vf_id,
14238                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14239                 NULL,
14240         },
14241 };
14242
14243 /* MACsec configuration */
14244
14245 /* Common result structure for MACsec offload enable */
14246 struct cmd_macsec_offload_on_result {
14247         cmdline_fixed_string_t set;
14248         cmdline_fixed_string_t macsec;
14249         cmdline_fixed_string_t offload;
14250         portid_t port_id;
14251         cmdline_fixed_string_t on;
14252         cmdline_fixed_string_t encrypt;
14253         cmdline_fixed_string_t en_on_off;
14254         cmdline_fixed_string_t replay_protect;
14255         cmdline_fixed_string_t rp_on_off;
14256 };
14257
14258 /* Common CLI fields for MACsec offload disable */
14259 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14260         TOKEN_STRING_INITIALIZER
14261                 (struct cmd_macsec_offload_on_result,
14262                  set, "set");
14263 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14264         TOKEN_STRING_INITIALIZER
14265                 (struct cmd_macsec_offload_on_result,
14266                  macsec, "macsec");
14267 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14268         TOKEN_STRING_INITIALIZER
14269                 (struct cmd_macsec_offload_on_result,
14270                  offload, "offload");
14271 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14272         TOKEN_NUM_INITIALIZER
14273                 (struct cmd_macsec_offload_on_result,
14274                  port_id, UINT16);
14275 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14276         TOKEN_STRING_INITIALIZER
14277                 (struct cmd_macsec_offload_on_result,
14278                  on, "on");
14279 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14280         TOKEN_STRING_INITIALIZER
14281                 (struct cmd_macsec_offload_on_result,
14282                  encrypt, "encrypt");
14283 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14284         TOKEN_STRING_INITIALIZER
14285                 (struct cmd_macsec_offload_on_result,
14286                  en_on_off, "on#off");
14287 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14288         TOKEN_STRING_INITIALIZER
14289                 (struct cmd_macsec_offload_on_result,
14290                  replay_protect, "replay-protect");
14291 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14292         TOKEN_STRING_INITIALIZER
14293                 (struct cmd_macsec_offload_on_result,
14294                  rp_on_off, "on#off");
14295
14296 static void
14297 cmd_set_macsec_offload_on_parsed(
14298         void *parsed_result,
14299         __rte_unused struct cmdline *cl,
14300         __rte_unused void *data)
14301 {
14302         struct cmd_macsec_offload_on_result *res = parsed_result;
14303         int ret = -ENOTSUP;
14304         portid_t port_id = res->port_id;
14305         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14306         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14307         struct rte_eth_dev_info dev_info;
14308
14309         if (port_id_is_invalid(port_id, ENABLED_WARN))
14310                 return;
14311         if (!port_is_stopped(port_id)) {
14312                 printf("Please stop port %d first\n", port_id);
14313                 return;
14314         }
14315
14316         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14317         if (ret != 0)
14318                 return;
14319
14320         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14321 #ifdef RTE_LIBRTE_IXGBE_PMD
14322                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14323 #endif
14324         }
14325         RTE_SET_USED(en);
14326         RTE_SET_USED(rp);
14327
14328         switch (ret) {
14329         case 0:
14330                 ports[port_id].dev_conf.txmode.offloads |=
14331                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14332                 cmd_reconfig_device_queue(port_id, 1, 1);
14333                 break;
14334         case -ENODEV:
14335                 printf("invalid port_id %d\n", port_id);
14336                 break;
14337         case -ENOTSUP:
14338                 printf("not supported on port %d\n", port_id);
14339                 break;
14340         default:
14341                 printf("programming error: (%s)\n", strerror(-ret));
14342         }
14343 }
14344
14345 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14346         .f = cmd_set_macsec_offload_on_parsed,
14347         .data = NULL,
14348         .help_str = "set macsec offload <port_id> on "
14349                 "encrypt on|off replay-protect on|off",
14350         .tokens = {
14351                 (void *)&cmd_macsec_offload_on_set,
14352                 (void *)&cmd_macsec_offload_on_macsec,
14353                 (void *)&cmd_macsec_offload_on_offload,
14354                 (void *)&cmd_macsec_offload_on_port_id,
14355                 (void *)&cmd_macsec_offload_on_on,
14356                 (void *)&cmd_macsec_offload_on_encrypt,
14357                 (void *)&cmd_macsec_offload_on_en_on_off,
14358                 (void *)&cmd_macsec_offload_on_replay_protect,
14359                 (void *)&cmd_macsec_offload_on_rp_on_off,
14360                 NULL,
14361         },
14362 };
14363
14364 /* Common result structure for MACsec offload disable */
14365 struct cmd_macsec_offload_off_result {
14366         cmdline_fixed_string_t set;
14367         cmdline_fixed_string_t macsec;
14368         cmdline_fixed_string_t offload;
14369         portid_t port_id;
14370         cmdline_fixed_string_t off;
14371 };
14372
14373 /* Common CLI fields for MACsec offload disable */
14374 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14375         TOKEN_STRING_INITIALIZER
14376                 (struct cmd_macsec_offload_off_result,
14377                  set, "set");
14378 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14379         TOKEN_STRING_INITIALIZER
14380                 (struct cmd_macsec_offload_off_result,
14381                  macsec, "macsec");
14382 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14383         TOKEN_STRING_INITIALIZER
14384                 (struct cmd_macsec_offload_off_result,
14385                  offload, "offload");
14386 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14387         TOKEN_NUM_INITIALIZER
14388                 (struct cmd_macsec_offload_off_result,
14389                  port_id, UINT16);
14390 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14391         TOKEN_STRING_INITIALIZER
14392                 (struct cmd_macsec_offload_off_result,
14393                  off, "off");
14394
14395 static void
14396 cmd_set_macsec_offload_off_parsed(
14397         void *parsed_result,
14398         __rte_unused struct cmdline *cl,
14399         __rte_unused void *data)
14400 {
14401         struct cmd_macsec_offload_off_result *res = parsed_result;
14402         int ret = -ENOTSUP;
14403         struct rte_eth_dev_info dev_info;
14404         portid_t port_id = res->port_id;
14405
14406         if (port_id_is_invalid(port_id, ENABLED_WARN))
14407                 return;
14408         if (!port_is_stopped(port_id)) {
14409                 printf("Please stop port %d first\n", port_id);
14410                 return;
14411         }
14412
14413         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14414         if (ret != 0)
14415                 return;
14416
14417         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14418 #ifdef RTE_LIBRTE_IXGBE_PMD
14419                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14420 #endif
14421         }
14422         switch (ret) {
14423         case 0:
14424                 ports[port_id].dev_conf.txmode.offloads &=
14425                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14426                 cmd_reconfig_device_queue(port_id, 1, 1);
14427                 break;
14428         case -ENODEV:
14429                 printf("invalid port_id %d\n", port_id);
14430                 break;
14431         case -ENOTSUP:
14432                 printf("not supported on port %d\n", port_id);
14433                 break;
14434         default:
14435                 printf("programming error: (%s)\n", strerror(-ret));
14436         }
14437 }
14438
14439 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14440         .f = cmd_set_macsec_offload_off_parsed,
14441         .data = NULL,
14442         .help_str = "set macsec offload <port_id> off",
14443         .tokens = {
14444                 (void *)&cmd_macsec_offload_off_set,
14445                 (void *)&cmd_macsec_offload_off_macsec,
14446                 (void *)&cmd_macsec_offload_off_offload,
14447                 (void *)&cmd_macsec_offload_off_port_id,
14448                 (void *)&cmd_macsec_offload_off_off,
14449                 NULL,
14450         },
14451 };
14452
14453 /* Common result structure for MACsec secure connection configure */
14454 struct cmd_macsec_sc_result {
14455         cmdline_fixed_string_t set;
14456         cmdline_fixed_string_t macsec;
14457         cmdline_fixed_string_t sc;
14458         cmdline_fixed_string_t tx_rx;
14459         portid_t port_id;
14460         struct rte_ether_addr mac;
14461         uint16_t pi;
14462 };
14463
14464 /* Common CLI fields for MACsec secure connection configure */
14465 cmdline_parse_token_string_t cmd_macsec_sc_set =
14466         TOKEN_STRING_INITIALIZER
14467                 (struct cmd_macsec_sc_result,
14468                  set, "set");
14469 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14470         TOKEN_STRING_INITIALIZER
14471                 (struct cmd_macsec_sc_result,
14472                  macsec, "macsec");
14473 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14474         TOKEN_STRING_INITIALIZER
14475                 (struct cmd_macsec_sc_result,
14476                  sc, "sc");
14477 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14478         TOKEN_STRING_INITIALIZER
14479                 (struct cmd_macsec_sc_result,
14480                  tx_rx, "tx#rx");
14481 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14482         TOKEN_NUM_INITIALIZER
14483                 (struct cmd_macsec_sc_result,
14484                  port_id, UINT16);
14485 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14486         TOKEN_ETHERADDR_INITIALIZER
14487                 (struct cmd_macsec_sc_result,
14488                  mac);
14489 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14490         TOKEN_NUM_INITIALIZER
14491                 (struct cmd_macsec_sc_result,
14492                  pi, UINT16);
14493
14494 static void
14495 cmd_set_macsec_sc_parsed(
14496         void *parsed_result,
14497         __rte_unused struct cmdline *cl,
14498         __rte_unused void *data)
14499 {
14500         struct cmd_macsec_sc_result *res = parsed_result;
14501         int ret = -ENOTSUP;
14502         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14503
14504 #ifdef RTE_LIBRTE_IXGBE_PMD
14505         ret = is_tx ?
14506                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14507                                 res->mac.addr_bytes) :
14508                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14509                                 res->mac.addr_bytes, res->pi);
14510 #endif
14511         RTE_SET_USED(is_tx);
14512
14513         switch (ret) {
14514         case 0:
14515                 break;
14516         case -ENODEV:
14517                 printf("invalid port_id %d\n", res->port_id);
14518                 break;
14519         case -ENOTSUP:
14520                 printf("not supported on port %d\n", res->port_id);
14521                 break;
14522         default:
14523                 printf("programming error: (%s)\n", strerror(-ret));
14524         }
14525 }
14526
14527 cmdline_parse_inst_t cmd_set_macsec_sc = {
14528         .f = cmd_set_macsec_sc_parsed,
14529         .data = NULL,
14530         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14531         .tokens = {
14532                 (void *)&cmd_macsec_sc_set,
14533                 (void *)&cmd_macsec_sc_macsec,
14534                 (void *)&cmd_macsec_sc_sc,
14535                 (void *)&cmd_macsec_sc_tx_rx,
14536                 (void *)&cmd_macsec_sc_port_id,
14537                 (void *)&cmd_macsec_sc_mac,
14538                 (void *)&cmd_macsec_sc_pi,
14539                 NULL,
14540         },
14541 };
14542
14543 /* Common result structure for MACsec secure connection configure */
14544 struct cmd_macsec_sa_result {
14545         cmdline_fixed_string_t set;
14546         cmdline_fixed_string_t macsec;
14547         cmdline_fixed_string_t sa;
14548         cmdline_fixed_string_t tx_rx;
14549         portid_t port_id;
14550         uint8_t idx;
14551         uint8_t an;
14552         uint32_t pn;
14553         cmdline_fixed_string_t key;
14554 };
14555
14556 /* Common CLI fields for MACsec secure connection configure */
14557 cmdline_parse_token_string_t cmd_macsec_sa_set =
14558         TOKEN_STRING_INITIALIZER
14559                 (struct cmd_macsec_sa_result,
14560                  set, "set");
14561 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14562         TOKEN_STRING_INITIALIZER
14563                 (struct cmd_macsec_sa_result,
14564                  macsec, "macsec");
14565 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14566         TOKEN_STRING_INITIALIZER
14567                 (struct cmd_macsec_sa_result,
14568                  sa, "sa");
14569 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14570         TOKEN_STRING_INITIALIZER
14571                 (struct cmd_macsec_sa_result,
14572                  tx_rx, "tx#rx");
14573 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14574         TOKEN_NUM_INITIALIZER
14575                 (struct cmd_macsec_sa_result,
14576                  port_id, UINT16);
14577 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14578         TOKEN_NUM_INITIALIZER
14579                 (struct cmd_macsec_sa_result,
14580                  idx, UINT8);
14581 cmdline_parse_token_num_t cmd_macsec_sa_an =
14582         TOKEN_NUM_INITIALIZER
14583                 (struct cmd_macsec_sa_result,
14584                  an, UINT8);
14585 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14586         TOKEN_NUM_INITIALIZER
14587                 (struct cmd_macsec_sa_result,
14588                  pn, UINT32);
14589 cmdline_parse_token_string_t cmd_macsec_sa_key =
14590         TOKEN_STRING_INITIALIZER
14591                 (struct cmd_macsec_sa_result,
14592                  key, NULL);
14593
14594 static void
14595 cmd_set_macsec_sa_parsed(
14596         void *parsed_result,
14597         __rte_unused struct cmdline *cl,
14598         __rte_unused void *data)
14599 {
14600         struct cmd_macsec_sa_result *res = parsed_result;
14601         int ret = -ENOTSUP;
14602         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14603         uint8_t key[16] = { 0 };
14604         uint8_t xdgt0;
14605         uint8_t xdgt1;
14606         int key_len;
14607         int i;
14608
14609         key_len = strlen(res->key) / 2;
14610         if (key_len > 16)
14611                 key_len = 16;
14612
14613         for (i = 0; i < key_len; i++) {
14614                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14615                 if (xdgt0 == 0xFF)
14616                         return;
14617                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14618                 if (xdgt1 == 0xFF)
14619                         return;
14620                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14621         }
14622
14623 #ifdef RTE_LIBRTE_IXGBE_PMD
14624         ret = is_tx ?
14625                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14626                         res->idx, res->an, res->pn, key) :
14627                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14628                         res->idx, res->an, res->pn, key);
14629 #endif
14630         RTE_SET_USED(is_tx);
14631         RTE_SET_USED(key);
14632
14633         switch (ret) {
14634         case 0:
14635                 break;
14636         case -EINVAL:
14637                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14638                 break;
14639         case -ENODEV:
14640                 printf("invalid port_id %d\n", res->port_id);
14641                 break;
14642         case -ENOTSUP:
14643                 printf("not supported on port %d\n", res->port_id);
14644                 break;
14645         default:
14646                 printf("programming error: (%s)\n", strerror(-ret));
14647         }
14648 }
14649
14650 cmdline_parse_inst_t cmd_set_macsec_sa = {
14651         .f = cmd_set_macsec_sa_parsed,
14652         .data = NULL,
14653         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14654         .tokens = {
14655                 (void *)&cmd_macsec_sa_set,
14656                 (void *)&cmd_macsec_sa_macsec,
14657                 (void *)&cmd_macsec_sa_sa,
14658                 (void *)&cmd_macsec_sa_tx_rx,
14659                 (void *)&cmd_macsec_sa_port_id,
14660                 (void *)&cmd_macsec_sa_idx,
14661                 (void *)&cmd_macsec_sa_an,
14662                 (void *)&cmd_macsec_sa_pn,
14663                 (void *)&cmd_macsec_sa_key,
14664                 NULL,
14665         },
14666 };
14667
14668 /* VF unicast promiscuous mode configuration */
14669
14670 /* Common result structure for VF unicast promiscuous mode */
14671 struct cmd_vf_promisc_result {
14672         cmdline_fixed_string_t set;
14673         cmdline_fixed_string_t vf;
14674         cmdline_fixed_string_t promisc;
14675         portid_t port_id;
14676         uint32_t vf_id;
14677         cmdline_fixed_string_t on_off;
14678 };
14679
14680 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14681 cmdline_parse_token_string_t cmd_vf_promisc_set =
14682         TOKEN_STRING_INITIALIZER
14683                 (struct cmd_vf_promisc_result,
14684                  set, "set");
14685 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14686         TOKEN_STRING_INITIALIZER
14687                 (struct cmd_vf_promisc_result,
14688                  vf, "vf");
14689 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14690         TOKEN_STRING_INITIALIZER
14691                 (struct cmd_vf_promisc_result,
14692                  promisc, "promisc");
14693 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14694         TOKEN_NUM_INITIALIZER
14695                 (struct cmd_vf_promisc_result,
14696                  port_id, UINT16);
14697 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14698         TOKEN_NUM_INITIALIZER
14699                 (struct cmd_vf_promisc_result,
14700                  vf_id, UINT32);
14701 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14702         TOKEN_STRING_INITIALIZER
14703                 (struct cmd_vf_promisc_result,
14704                  on_off, "on#off");
14705
14706 static void
14707 cmd_set_vf_promisc_parsed(
14708         void *parsed_result,
14709         __rte_unused struct cmdline *cl,
14710         __rte_unused void *data)
14711 {
14712         struct cmd_vf_promisc_result *res = parsed_result;
14713         int ret = -ENOTSUP;
14714
14715         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14716
14717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14718                 return;
14719
14720 #ifdef RTE_LIBRTE_I40E_PMD
14721         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14722                                                   res->vf_id, is_on);
14723 #endif
14724
14725         switch (ret) {
14726         case 0:
14727                 break;
14728         case -EINVAL:
14729                 printf("invalid vf_id %d\n", res->vf_id);
14730                 break;
14731         case -ENODEV:
14732                 printf("invalid port_id %d\n", res->port_id);
14733                 break;
14734         case -ENOTSUP:
14735                 printf("function not implemented\n");
14736                 break;
14737         default:
14738                 printf("programming error: (%s)\n", strerror(-ret));
14739         }
14740 }
14741
14742 cmdline_parse_inst_t cmd_set_vf_promisc = {
14743         .f = cmd_set_vf_promisc_parsed,
14744         .data = NULL,
14745         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14746                 "Set unicast promiscuous mode for a VF from the PF",
14747         .tokens = {
14748                 (void *)&cmd_vf_promisc_set,
14749                 (void *)&cmd_vf_promisc_vf,
14750                 (void *)&cmd_vf_promisc_promisc,
14751                 (void *)&cmd_vf_promisc_port_id,
14752                 (void *)&cmd_vf_promisc_vf_id,
14753                 (void *)&cmd_vf_promisc_on_off,
14754                 NULL,
14755         },
14756 };
14757
14758 /* VF multicast promiscuous mode configuration */
14759
14760 /* Common result structure for VF multicast promiscuous mode */
14761 struct cmd_vf_allmulti_result {
14762         cmdline_fixed_string_t set;
14763         cmdline_fixed_string_t vf;
14764         cmdline_fixed_string_t allmulti;
14765         portid_t port_id;
14766         uint32_t vf_id;
14767         cmdline_fixed_string_t on_off;
14768 };
14769
14770 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14771 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14772         TOKEN_STRING_INITIALIZER
14773                 (struct cmd_vf_allmulti_result,
14774                  set, "set");
14775 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14776         TOKEN_STRING_INITIALIZER
14777                 (struct cmd_vf_allmulti_result,
14778                  vf, "vf");
14779 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14780         TOKEN_STRING_INITIALIZER
14781                 (struct cmd_vf_allmulti_result,
14782                  allmulti, "allmulti");
14783 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14784         TOKEN_NUM_INITIALIZER
14785                 (struct cmd_vf_allmulti_result,
14786                  port_id, UINT16);
14787 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14788         TOKEN_NUM_INITIALIZER
14789                 (struct cmd_vf_allmulti_result,
14790                  vf_id, UINT32);
14791 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14792         TOKEN_STRING_INITIALIZER
14793                 (struct cmd_vf_allmulti_result,
14794                  on_off, "on#off");
14795
14796 static void
14797 cmd_set_vf_allmulti_parsed(
14798         void *parsed_result,
14799         __rte_unused struct cmdline *cl,
14800         __rte_unused void *data)
14801 {
14802         struct cmd_vf_allmulti_result *res = parsed_result;
14803         int ret = -ENOTSUP;
14804
14805         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14806
14807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14808                 return;
14809
14810 #ifdef RTE_LIBRTE_I40E_PMD
14811         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14812                                                     res->vf_id, is_on);
14813 #endif
14814
14815         switch (ret) {
14816         case 0:
14817                 break;
14818         case -EINVAL:
14819                 printf("invalid vf_id %d\n", res->vf_id);
14820                 break;
14821         case -ENODEV:
14822                 printf("invalid port_id %d\n", res->port_id);
14823                 break;
14824         case -ENOTSUP:
14825                 printf("function not implemented\n");
14826                 break;
14827         default:
14828                 printf("programming error: (%s)\n", strerror(-ret));
14829         }
14830 }
14831
14832 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14833         .f = cmd_set_vf_allmulti_parsed,
14834         .data = NULL,
14835         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14836                 "Set multicast promiscuous mode for a VF from the PF",
14837         .tokens = {
14838                 (void *)&cmd_vf_allmulti_set,
14839                 (void *)&cmd_vf_allmulti_vf,
14840                 (void *)&cmd_vf_allmulti_allmulti,
14841                 (void *)&cmd_vf_allmulti_port_id,
14842                 (void *)&cmd_vf_allmulti_vf_id,
14843                 (void *)&cmd_vf_allmulti_on_off,
14844                 NULL,
14845         },
14846 };
14847
14848 /* vf broadcast mode configuration */
14849
14850 /* Common result structure for vf broadcast */
14851 struct cmd_set_vf_broadcast_result {
14852         cmdline_fixed_string_t set;
14853         cmdline_fixed_string_t vf;
14854         cmdline_fixed_string_t broadcast;
14855         portid_t port_id;
14856         uint16_t vf_id;
14857         cmdline_fixed_string_t on_off;
14858 };
14859
14860 /* Common CLI fields for vf broadcast enable disable */
14861 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_set_vf_broadcast_result,
14864                  set, "set");
14865 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14866         TOKEN_STRING_INITIALIZER
14867                 (struct cmd_set_vf_broadcast_result,
14868                  vf, "vf");
14869 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14870         TOKEN_STRING_INITIALIZER
14871                 (struct cmd_set_vf_broadcast_result,
14872                  broadcast, "broadcast");
14873 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14874         TOKEN_NUM_INITIALIZER
14875                 (struct cmd_set_vf_broadcast_result,
14876                  port_id, UINT16);
14877 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14878         TOKEN_NUM_INITIALIZER
14879                 (struct cmd_set_vf_broadcast_result,
14880                  vf_id, UINT16);
14881 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14882         TOKEN_STRING_INITIALIZER
14883                 (struct cmd_set_vf_broadcast_result,
14884                  on_off, "on#off");
14885
14886 static void
14887 cmd_set_vf_broadcast_parsed(
14888         void *parsed_result,
14889         __rte_unused struct cmdline *cl,
14890         __rte_unused void *data)
14891 {
14892         struct cmd_set_vf_broadcast_result *res = parsed_result;
14893         int ret = -ENOTSUP;
14894
14895         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14896
14897         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14898                 return;
14899
14900 #ifdef RTE_LIBRTE_I40E_PMD
14901         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14902                                             res->vf_id, is_on);
14903 #endif
14904
14905         switch (ret) {
14906         case 0:
14907                 break;
14908         case -EINVAL:
14909                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14910                 break;
14911         case -ENODEV:
14912                 printf("invalid port_id %d\n", res->port_id);
14913                 break;
14914         case -ENOTSUP:
14915                 printf("function not implemented\n");
14916                 break;
14917         default:
14918                 printf("programming error: (%s)\n", strerror(-ret));
14919         }
14920 }
14921
14922 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14923         .f = cmd_set_vf_broadcast_parsed,
14924         .data = NULL,
14925         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14926         .tokens = {
14927                 (void *)&cmd_set_vf_broadcast_set,
14928                 (void *)&cmd_set_vf_broadcast_vf,
14929                 (void *)&cmd_set_vf_broadcast_broadcast,
14930                 (void *)&cmd_set_vf_broadcast_port_id,
14931                 (void *)&cmd_set_vf_broadcast_vf_id,
14932                 (void *)&cmd_set_vf_broadcast_on_off,
14933                 NULL,
14934         },
14935 };
14936
14937 /* vf vlan tag configuration */
14938
14939 /* Common result structure for vf vlan tag */
14940 struct cmd_set_vf_vlan_tag_result {
14941         cmdline_fixed_string_t set;
14942         cmdline_fixed_string_t vf;
14943         cmdline_fixed_string_t vlan;
14944         cmdline_fixed_string_t tag;
14945         portid_t port_id;
14946         uint16_t vf_id;
14947         cmdline_fixed_string_t on_off;
14948 };
14949
14950 /* Common CLI fields for vf vlan tag enable disable */
14951 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14952         TOKEN_STRING_INITIALIZER
14953                 (struct cmd_set_vf_vlan_tag_result,
14954                  set, "set");
14955 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14956         TOKEN_STRING_INITIALIZER
14957                 (struct cmd_set_vf_vlan_tag_result,
14958                  vf, "vf");
14959 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14960         TOKEN_STRING_INITIALIZER
14961                 (struct cmd_set_vf_vlan_tag_result,
14962                  vlan, "vlan");
14963 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_set_vf_vlan_tag_result,
14966                  tag, "tag");
14967 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14968         TOKEN_NUM_INITIALIZER
14969                 (struct cmd_set_vf_vlan_tag_result,
14970                  port_id, UINT16);
14971 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14972         TOKEN_NUM_INITIALIZER
14973                 (struct cmd_set_vf_vlan_tag_result,
14974                  vf_id, UINT16);
14975 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14976         TOKEN_STRING_INITIALIZER
14977                 (struct cmd_set_vf_vlan_tag_result,
14978                  on_off, "on#off");
14979
14980 static void
14981 cmd_set_vf_vlan_tag_parsed(
14982         void *parsed_result,
14983         __rte_unused struct cmdline *cl,
14984         __rte_unused void *data)
14985 {
14986         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14987         int ret = -ENOTSUP;
14988
14989         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14990
14991         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14992                 return;
14993
14994 #ifdef RTE_LIBRTE_I40E_PMD
14995         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14996                                            res->vf_id, is_on);
14997 #endif
14998
14999         switch (ret) {
15000         case 0:
15001                 break;
15002         case -EINVAL:
15003                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15004                 break;
15005         case -ENODEV:
15006                 printf("invalid port_id %d\n", res->port_id);
15007                 break;
15008         case -ENOTSUP:
15009                 printf("function not implemented\n");
15010                 break;
15011         default:
15012                 printf("programming error: (%s)\n", strerror(-ret));
15013         }
15014 }
15015
15016 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15017         .f = cmd_set_vf_vlan_tag_parsed,
15018         .data = NULL,
15019         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15020         .tokens = {
15021                 (void *)&cmd_set_vf_vlan_tag_set,
15022                 (void *)&cmd_set_vf_vlan_tag_vf,
15023                 (void *)&cmd_set_vf_vlan_tag_vlan,
15024                 (void *)&cmd_set_vf_vlan_tag_tag,
15025                 (void *)&cmd_set_vf_vlan_tag_port_id,
15026                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15027                 (void *)&cmd_set_vf_vlan_tag_on_off,
15028                 NULL,
15029         },
15030 };
15031
15032 /* Common definition of VF and TC TX bandwidth configuration */
15033 struct cmd_vf_tc_bw_result {
15034         cmdline_fixed_string_t set;
15035         cmdline_fixed_string_t vf;
15036         cmdline_fixed_string_t tc;
15037         cmdline_fixed_string_t tx;
15038         cmdline_fixed_string_t min_bw;
15039         cmdline_fixed_string_t max_bw;
15040         cmdline_fixed_string_t strict_link_prio;
15041         portid_t port_id;
15042         uint16_t vf_id;
15043         uint8_t tc_no;
15044         uint32_t bw;
15045         cmdline_fixed_string_t bw_list;
15046         uint8_t tc_map;
15047 };
15048
15049 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15050         TOKEN_STRING_INITIALIZER
15051                 (struct cmd_vf_tc_bw_result,
15052                  set, "set");
15053 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15054         TOKEN_STRING_INITIALIZER
15055                 (struct cmd_vf_tc_bw_result,
15056                  vf, "vf");
15057 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15058         TOKEN_STRING_INITIALIZER
15059                 (struct cmd_vf_tc_bw_result,
15060                  tc, "tc");
15061 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15062         TOKEN_STRING_INITIALIZER
15063                 (struct cmd_vf_tc_bw_result,
15064                  tx, "tx");
15065 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15066         TOKEN_STRING_INITIALIZER
15067                 (struct cmd_vf_tc_bw_result,
15068                  strict_link_prio, "strict-link-priority");
15069 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15070         TOKEN_STRING_INITIALIZER
15071                 (struct cmd_vf_tc_bw_result,
15072                  min_bw, "min-bandwidth");
15073 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15074         TOKEN_STRING_INITIALIZER
15075                 (struct cmd_vf_tc_bw_result,
15076                  max_bw, "max-bandwidth");
15077 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15078         TOKEN_NUM_INITIALIZER
15079                 (struct cmd_vf_tc_bw_result,
15080                  port_id, UINT16);
15081 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15082         TOKEN_NUM_INITIALIZER
15083                 (struct cmd_vf_tc_bw_result,
15084                  vf_id, UINT16);
15085 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15086         TOKEN_NUM_INITIALIZER
15087                 (struct cmd_vf_tc_bw_result,
15088                  tc_no, UINT8);
15089 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15090         TOKEN_NUM_INITIALIZER
15091                 (struct cmd_vf_tc_bw_result,
15092                  bw, UINT32);
15093 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15094         TOKEN_STRING_INITIALIZER
15095                 (struct cmd_vf_tc_bw_result,
15096                  bw_list, NULL);
15097 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15098         TOKEN_NUM_INITIALIZER
15099                 (struct cmd_vf_tc_bw_result,
15100                  tc_map, UINT8);
15101
15102 /* VF max bandwidth setting */
15103 static void
15104 cmd_vf_max_bw_parsed(
15105         void *parsed_result,
15106         __rte_unused struct cmdline *cl,
15107         __rte_unused void *data)
15108 {
15109         struct cmd_vf_tc_bw_result *res = parsed_result;
15110         int ret = -ENOTSUP;
15111
15112         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15113                 return;
15114
15115 #ifdef RTE_LIBRTE_I40E_PMD
15116         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15117                                          res->vf_id, res->bw);
15118 #endif
15119
15120         switch (ret) {
15121         case 0:
15122                 break;
15123         case -EINVAL:
15124                 printf("invalid vf_id %d or bandwidth %d\n",
15125                        res->vf_id, res->bw);
15126                 break;
15127         case -ENODEV:
15128                 printf("invalid port_id %d\n", res->port_id);
15129                 break;
15130         case -ENOTSUP:
15131                 printf("function not implemented\n");
15132                 break;
15133         default:
15134                 printf("programming error: (%s)\n", strerror(-ret));
15135         }
15136 }
15137
15138 cmdline_parse_inst_t cmd_vf_max_bw = {
15139         .f = cmd_vf_max_bw_parsed,
15140         .data = NULL,
15141         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15142         .tokens = {
15143                 (void *)&cmd_vf_tc_bw_set,
15144                 (void *)&cmd_vf_tc_bw_vf,
15145                 (void *)&cmd_vf_tc_bw_tx,
15146                 (void *)&cmd_vf_tc_bw_max_bw,
15147                 (void *)&cmd_vf_tc_bw_port_id,
15148                 (void *)&cmd_vf_tc_bw_vf_id,
15149                 (void *)&cmd_vf_tc_bw_bw,
15150                 NULL,
15151         },
15152 };
15153
15154 static int
15155 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15156                            uint8_t *tc_num,
15157                            char *str)
15158 {
15159         uint32_t size;
15160         const char *p, *p0 = str;
15161         char s[256];
15162         char *end;
15163         char *str_fld[16];
15164         uint16_t i;
15165         int ret;
15166
15167         p = strchr(p0, '(');
15168         if (p == NULL) {
15169                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15170                 return -1;
15171         }
15172         p++;
15173         p0 = strchr(p, ')');
15174         if (p0 == NULL) {
15175                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15176                 return -1;
15177         }
15178         size = p0 - p;
15179         if (size >= sizeof(s)) {
15180                 printf("The string size exceeds the internal buffer size\n");
15181                 return -1;
15182         }
15183         snprintf(s, sizeof(s), "%.*s", size, p);
15184         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15185         if (ret <= 0) {
15186                 printf("Failed to get the bandwidth list. ");
15187                 return -1;
15188         }
15189         *tc_num = ret;
15190         for (i = 0; i < ret; i++)
15191                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15192
15193         return 0;
15194 }
15195
15196 /* TC min bandwidth setting */
15197 static void
15198 cmd_vf_tc_min_bw_parsed(
15199         void *parsed_result,
15200         __rte_unused struct cmdline *cl,
15201         __rte_unused void *data)
15202 {
15203         struct cmd_vf_tc_bw_result *res = parsed_result;
15204         uint8_t tc_num;
15205         uint8_t bw[16];
15206         int ret = -ENOTSUP;
15207
15208         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15209                 return;
15210
15211         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15212         if (ret)
15213                 return;
15214
15215 #ifdef RTE_LIBRTE_I40E_PMD
15216         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15217                                               tc_num, bw);
15218 #endif
15219
15220         switch (ret) {
15221         case 0:
15222                 break;
15223         case -EINVAL:
15224                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15225                 break;
15226         case -ENODEV:
15227                 printf("invalid port_id %d\n", res->port_id);
15228                 break;
15229         case -ENOTSUP:
15230                 printf("function not implemented\n");
15231                 break;
15232         default:
15233                 printf("programming error: (%s)\n", strerror(-ret));
15234         }
15235 }
15236
15237 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15238         .f = cmd_vf_tc_min_bw_parsed,
15239         .data = NULL,
15240         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15241                     " <bw1, bw2, ...>",
15242         .tokens = {
15243                 (void *)&cmd_vf_tc_bw_set,
15244                 (void *)&cmd_vf_tc_bw_vf,
15245                 (void *)&cmd_vf_tc_bw_tc,
15246                 (void *)&cmd_vf_tc_bw_tx,
15247                 (void *)&cmd_vf_tc_bw_min_bw,
15248                 (void *)&cmd_vf_tc_bw_port_id,
15249                 (void *)&cmd_vf_tc_bw_vf_id,
15250                 (void *)&cmd_vf_tc_bw_bw_list,
15251                 NULL,
15252         },
15253 };
15254
15255 static void
15256 cmd_tc_min_bw_parsed(
15257         void *parsed_result,
15258         __rte_unused struct cmdline *cl,
15259         __rte_unused void *data)
15260 {
15261         struct cmd_vf_tc_bw_result *res = parsed_result;
15262         struct rte_port *port;
15263         uint8_t tc_num;
15264         uint8_t bw[16];
15265         int ret = -ENOTSUP;
15266
15267         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15268                 return;
15269
15270         port = &ports[res->port_id];
15271         /** Check if the port is not started **/
15272         if (port->port_status != RTE_PORT_STOPPED) {
15273                 printf("Please stop port %d first\n", res->port_id);
15274                 return;
15275         }
15276
15277         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15278         if (ret)
15279                 return;
15280
15281 #ifdef RTE_LIBRTE_IXGBE_PMD
15282         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15283 #endif
15284
15285         switch (ret) {
15286         case 0:
15287                 break;
15288         case -EINVAL:
15289                 printf("invalid bandwidth\n");
15290                 break;
15291         case -ENODEV:
15292                 printf("invalid port_id %d\n", res->port_id);
15293                 break;
15294         case -ENOTSUP:
15295                 printf("function not implemented\n");
15296                 break;
15297         default:
15298                 printf("programming error: (%s)\n", strerror(-ret));
15299         }
15300 }
15301
15302 cmdline_parse_inst_t cmd_tc_min_bw = {
15303         .f = cmd_tc_min_bw_parsed,
15304         .data = NULL,
15305         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15306         .tokens = {
15307                 (void *)&cmd_vf_tc_bw_set,
15308                 (void *)&cmd_vf_tc_bw_tc,
15309                 (void *)&cmd_vf_tc_bw_tx,
15310                 (void *)&cmd_vf_tc_bw_min_bw,
15311                 (void *)&cmd_vf_tc_bw_port_id,
15312                 (void *)&cmd_vf_tc_bw_bw_list,
15313                 NULL,
15314         },
15315 };
15316
15317 /* TC max bandwidth setting */
15318 static void
15319 cmd_vf_tc_max_bw_parsed(
15320         void *parsed_result,
15321         __rte_unused struct cmdline *cl,
15322         __rte_unused void *data)
15323 {
15324         struct cmd_vf_tc_bw_result *res = parsed_result;
15325         int ret = -ENOTSUP;
15326
15327         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15328                 return;
15329
15330 #ifdef RTE_LIBRTE_I40E_PMD
15331         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15332                                             res->tc_no, res->bw);
15333 #endif
15334
15335         switch (ret) {
15336         case 0:
15337                 break;
15338         case -EINVAL:
15339                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15340                        res->vf_id, res->tc_no, res->bw);
15341                 break;
15342         case -ENODEV:
15343                 printf("invalid port_id %d\n", res->port_id);
15344                 break;
15345         case -ENOTSUP:
15346                 printf("function not implemented\n");
15347                 break;
15348         default:
15349                 printf("programming error: (%s)\n", strerror(-ret));
15350         }
15351 }
15352
15353 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15354         .f = cmd_vf_tc_max_bw_parsed,
15355         .data = NULL,
15356         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15357                     " <bandwidth>",
15358         .tokens = {
15359                 (void *)&cmd_vf_tc_bw_set,
15360                 (void *)&cmd_vf_tc_bw_vf,
15361                 (void *)&cmd_vf_tc_bw_tc,
15362                 (void *)&cmd_vf_tc_bw_tx,
15363                 (void *)&cmd_vf_tc_bw_max_bw,
15364                 (void *)&cmd_vf_tc_bw_port_id,
15365                 (void *)&cmd_vf_tc_bw_vf_id,
15366                 (void *)&cmd_vf_tc_bw_tc_no,
15367                 (void *)&cmd_vf_tc_bw_bw,
15368                 NULL,
15369         },
15370 };
15371
15372
15373 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15374
15375 /* *** Set Port default Traffic Management Hierarchy *** */
15376 struct cmd_set_port_tm_hierarchy_default_result {
15377         cmdline_fixed_string_t set;
15378         cmdline_fixed_string_t port;
15379         cmdline_fixed_string_t tm;
15380         cmdline_fixed_string_t hierarchy;
15381         cmdline_fixed_string_t def;
15382         portid_t port_id;
15383 };
15384
15385 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
15386         TOKEN_STRING_INITIALIZER(
15387                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
15388 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
15389         TOKEN_STRING_INITIALIZER(
15390                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
15391 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
15392         TOKEN_STRING_INITIALIZER(
15393                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
15394 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
15395         TOKEN_STRING_INITIALIZER(
15396                 struct cmd_set_port_tm_hierarchy_default_result,
15397                         hierarchy, "hierarchy");
15398 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
15399         TOKEN_STRING_INITIALIZER(
15400                 struct cmd_set_port_tm_hierarchy_default_result,
15401                         def, "default");
15402 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
15403         TOKEN_NUM_INITIALIZER(
15404                 struct cmd_set_port_tm_hierarchy_default_result,
15405                         port_id, UINT16);
15406
15407 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
15408         __rte_unused struct cmdline *cl,
15409         __rte_unused void *data)
15410 {
15411         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
15412         struct rte_port *p;
15413         portid_t port_id = res->port_id;
15414
15415         if (port_id_is_invalid(port_id, ENABLED_WARN))
15416                 return;
15417
15418         p = &ports[port_id];
15419
15420         /* Forward mode: tm */
15421         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "softnic")) {
15422                 printf("  softnicfwd mode not enabled(error)\n");
15423                 return;
15424         }
15425
15426         /* Set the default tm hierarchy */
15427         p->softport.default_tm_hierarchy_enable = 1;
15428 }
15429
15430 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
15431         .f = cmd_set_port_tm_hierarchy_default_parsed,
15432         .data = NULL,
15433         .help_str = "set port tm hierarchy default <port_id>",
15434         .tokens = {
15435                 (void *)&cmd_set_port_tm_hierarchy_default_set,
15436                 (void *)&cmd_set_port_tm_hierarchy_default_port,
15437                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
15438                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
15439                 (void *)&cmd_set_port_tm_hierarchy_default_default,
15440                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
15441                 NULL,
15442         },
15443 };
15444 #endif
15445
15446 /** Set VXLAN encapsulation details */
15447 struct cmd_set_vxlan_result {
15448         cmdline_fixed_string_t set;
15449         cmdline_fixed_string_t vxlan;
15450         cmdline_fixed_string_t pos_token;
15451         cmdline_fixed_string_t ip_version;
15452         uint32_t vlan_present:1;
15453         uint32_t vni;
15454         uint16_t udp_src;
15455         uint16_t udp_dst;
15456         cmdline_ipaddr_t ip_src;
15457         cmdline_ipaddr_t ip_dst;
15458         uint16_t tci;
15459         uint8_t tos;
15460         uint8_t ttl;
15461         struct rte_ether_addr eth_src;
15462         struct rte_ether_addr eth_dst;
15463 };
15464
15465 cmdline_parse_token_string_t cmd_set_vxlan_set =
15466         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15467 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15468         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15469 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15470         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15471                                  "vxlan-tos-ttl");
15472 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15473         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15474                                  "vxlan-with-vlan");
15475 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15476         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15477                                  "ip-version");
15478 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15479         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15480                                  "ipv4#ipv6");
15481 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15482         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15483                                  "vni");
15484 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15485         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15486 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15487         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15488                                  "udp-src");
15489 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15490         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15491 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15492         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15493                                  "udp-dst");
15494 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15495         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15496 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15497         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15498                                  "ip-tos");
15499 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15500         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15501 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15502         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15503                                  "ip-ttl");
15504 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15505         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15506 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15507         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15508                                  "ip-src");
15509 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15510         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15511 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15512         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15513                                  "ip-dst");
15514 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15515         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15516 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15517         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15518                                  "vlan-tci");
15519 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15520         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15521 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15522         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15523                                  "eth-src");
15524 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15525         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15526 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15527         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15528                                  "eth-dst");
15529 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15530         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15531
15532 static void cmd_set_vxlan_parsed(void *parsed_result,
15533         __rte_unused struct cmdline *cl,
15534         __rte_unused void *data)
15535 {
15536         struct cmd_set_vxlan_result *res = parsed_result;
15537         union {
15538                 uint32_t vxlan_id;
15539                 uint8_t vni[4];
15540         } id = {
15541                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15542         };
15543
15544         vxlan_encap_conf.select_tos_ttl = 0;
15545         if (strcmp(res->vxlan, "vxlan") == 0)
15546                 vxlan_encap_conf.select_vlan = 0;
15547         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15548                 vxlan_encap_conf.select_vlan = 1;
15549         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15550                 vxlan_encap_conf.select_vlan = 0;
15551                 vxlan_encap_conf.select_tos_ttl = 1;
15552         }
15553         if (strcmp(res->ip_version, "ipv4") == 0)
15554                 vxlan_encap_conf.select_ipv4 = 1;
15555         else if (strcmp(res->ip_version, "ipv6") == 0)
15556                 vxlan_encap_conf.select_ipv4 = 0;
15557         else
15558                 return;
15559         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15560         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15561         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15562         vxlan_encap_conf.ip_tos = res->tos;
15563         vxlan_encap_conf.ip_ttl = res->ttl;
15564         if (vxlan_encap_conf.select_ipv4) {
15565                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15566                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15567         } else {
15568                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15569                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15570         }
15571         if (vxlan_encap_conf.select_vlan)
15572                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15573         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15574                    RTE_ETHER_ADDR_LEN);
15575         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15576                    RTE_ETHER_ADDR_LEN);
15577 }
15578
15579 cmdline_parse_inst_t cmd_set_vxlan = {
15580         .f = cmd_set_vxlan_parsed,
15581         .data = NULL,
15582         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15583                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15584                 " eth-src <eth-src> eth-dst <eth-dst>",
15585         .tokens = {
15586                 (void *)&cmd_set_vxlan_set,
15587                 (void *)&cmd_set_vxlan_vxlan,
15588                 (void *)&cmd_set_vxlan_ip_version,
15589                 (void *)&cmd_set_vxlan_ip_version_value,
15590                 (void *)&cmd_set_vxlan_vni,
15591                 (void *)&cmd_set_vxlan_vni_value,
15592                 (void *)&cmd_set_vxlan_udp_src,
15593                 (void *)&cmd_set_vxlan_udp_src_value,
15594                 (void *)&cmd_set_vxlan_udp_dst,
15595                 (void *)&cmd_set_vxlan_udp_dst_value,
15596                 (void *)&cmd_set_vxlan_ip_src,
15597                 (void *)&cmd_set_vxlan_ip_src_value,
15598                 (void *)&cmd_set_vxlan_ip_dst,
15599                 (void *)&cmd_set_vxlan_ip_dst_value,
15600                 (void *)&cmd_set_vxlan_eth_src,
15601                 (void *)&cmd_set_vxlan_eth_src_value,
15602                 (void *)&cmd_set_vxlan_eth_dst,
15603                 (void *)&cmd_set_vxlan_eth_dst_value,
15604                 NULL,
15605         },
15606 };
15607
15608 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15609         .f = cmd_set_vxlan_parsed,
15610         .data = NULL,
15611         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15612                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15613                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15614                 " eth-dst <eth-dst>",
15615         .tokens = {
15616                 (void *)&cmd_set_vxlan_set,
15617                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15618                 (void *)&cmd_set_vxlan_ip_version,
15619                 (void *)&cmd_set_vxlan_ip_version_value,
15620                 (void *)&cmd_set_vxlan_vni,
15621                 (void *)&cmd_set_vxlan_vni_value,
15622                 (void *)&cmd_set_vxlan_udp_src,
15623                 (void *)&cmd_set_vxlan_udp_src_value,
15624                 (void *)&cmd_set_vxlan_udp_dst,
15625                 (void *)&cmd_set_vxlan_udp_dst_value,
15626                 (void *)&cmd_set_vxlan_ip_tos,
15627                 (void *)&cmd_set_vxlan_ip_tos_value,
15628                 (void *)&cmd_set_vxlan_ip_ttl,
15629                 (void *)&cmd_set_vxlan_ip_ttl_value,
15630                 (void *)&cmd_set_vxlan_ip_src,
15631                 (void *)&cmd_set_vxlan_ip_src_value,
15632                 (void *)&cmd_set_vxlan_ip_dst,
15633                 (void *)&cmd_set_vxlan_ip_dst_value,
15634                 (void *)&cmd_set_vxlan_eth_src,
15635                 (void *)&cmd_set_vxlan_eth_src_value,
15636                 (void *)&cmd_set_vxlan_eth_dst,
15637                 (void *)&cmd_set_vxlan_eth_dst_value,
15638                 NULL,
15639         },
15640 };
15641
15642 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15643         .f = cmd_set_vxlan_parsed,
15644         .data = NULL,
15645         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15646                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15647                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15648                 " <eth-dst>",
15649         .tokens = {
15650                 (void *)&cmd_set_vxlan_set,
15651                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15652                 (void *)&cmd_set_vxlan_ip_version,
15653                 (void *)&cmd_set_vxlan_ip_version_value,
15654                 (void *)&cmd_set_vxlan_vni,
15655                 (void *)&cmd_set_vxlan_vni_value,
15656                 (void *)&cmd_set_vxlan_udp_src,
15657                 (void *)&cmd_set_vxlan_udp_src_value,
15658                 (void *)&cmd_set_vxlan_udp_dst,
15659                 (void *)&cmd_set_vxlan_udp_dst_value,
15660                 (void *)&cmd_set_vxlan_ip_src,
15661                 (void *)&cmd_set_vxlan_ip_src_value,
15662                 (void *)&cmd_set_vxlan_ip_dst,
15663                 (void *)&cmd_set_vxlan_ip_dst_value,
15664                 (void *)&cmd_set_vxlan_vlan,
15665                 (void *)&cmd_set_vxlan_vlan_value,
15666                 (void *)&cmd_set_vxlan_eth_src,
15667                 (void *)&cmd_set_vxlan_eth_src_value,
15668                 (void *)&cmd_set_vxlan_eth_dst,
15669                 (void *)&cmd_set_vxlan_eth_dst_value,
15670                 NULL,
15671         },
15672 };
15673
15674 /** Set NVGRE encapsulation details */
15675 struct cmd_set_nvgre_result {
15676         cmdline_fixed_string_t set;
15677         cmdline_fixed_string_t nvgre;
15678         cmdline_fixed_string_t pos_token;
15679         cmdline_fixed_string_t ip_version;
15680         uint32_t tni;
15681         cmdline_ipaddr_t ip_src;
15682         cmdline_ipaddr_t ip_dst;
15683         uint16_t tci;
15684         struct rte_ether_addr eth_src;
15685         struct rte_ether_addr eth_dst;
15686 };
15687
15688 cmdline_parse_token_string_t cmd_set_nvgre_set =
15689         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15690 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15691         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15692 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15693         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15694                                  "nvgre-with-vlan");
15695 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15696         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15697                                  "ip-version");
15698 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15699         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15700                                  "ipv4#ipv6");
15701 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15702         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15703                                  "tni");
15704 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15705         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15706 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15707         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15708                                  "ip-src");
15709 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15710         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15711 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15712         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15713                                  "ip-dst");
15714 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15715         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15716 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15717         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15718                                  "vlan-tci");
15719 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15720         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15721 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15722         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15723                                  "eth-src");
15724 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15725         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15726 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15727         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15728                                  "eth-dst");
15729 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15730         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15731
15732 static void cmd_set_nvgre_parsed(void *parsed_result,
15733         __rte_unused struct cmdline *cl,
15734         __rte_unused void *data)
15735 {
15736         struct cmd_set_nvgre_result *res = parsed_result;
15737         union {
15738                 uint32_t nvgre_tni;
15739                 uint8_t tni[4];
15740         } id = {
15741                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15742         };
15743
15744         if (strcmp(res->nvgre, "nvgre") == 0)
15745                 nvgre_encap_conf.select_vlan = 0;
15746         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15747                 nvgre_encap_conf.select_vlan = 1;
15748         if (strcmp(res->ip_version, "ipv4") == 0)
15749                 nvgre_encap_conf.select_ipv4 = 1;
15750         else if (strcmp(res->ip_version, "ipv6") == 0)
15751                 nvgre_encap_conf.select_ipv4 = 0;
15752         else
15753                 return;
15754         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15755         if (nvgre_encap_conf.select_ipv4) {
15756                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15757                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15758         } else {
15759                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15760                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15761         }
15762         if (nvgre_encap_conf.select_vlan)
15763                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15764         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15765                    RTE_ETHER_ADDR_LEN);
15766         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15767                    RTE_ETHER_ADDR_LEN);
15768 }
15769
15770 cmdline_parse_inst_t cmd_set_nvgre = {
15771         .f = cmd_set_nvgre_parsed,
15772         .data = NULL,
15773         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15774                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15775                 " eth-dst <eth-dst>",
15776         .tokens = {
15777                 (void *)&cmd_set_nvgre_set,
15778                 (void *)&cmd_set_nvgre_nvgre,
15779                 (void *)&cmd_set_nvgre_ip_version,
15780                 (void *)&cmd_set_nvgre_ip_version_value,
15781                 (void *)&cmd_set_nvgre_tni,
15782                 (void *)&cmd_set_nvgre_tni_value,
15783                 (void *)&cmd_set_nvgre_ip_src,
15784                 (void *)&cmd_set_nvgre_ip_src_value,
15785                 (void *)&cmd_set_nvgre_ip_dst,
15786                 (void *)&cmd_set_nvgre_ip_dst_value,
15787                 (void *)&cmd_set_nvgre_eth_src,
15788                 (void *)&cmd_set_nvgre_eth_src_value,
15789                 (void *)&cmd_set_nvgre_eth_dst,
15790                 (void *)&cmd_set_nvgre_eth_dst_value,
15791                 NULL,
15792         },
15793 };
15794
15795 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15796         .f = cmd_set_nvgre_parsed,
15797         .data = NULL,
15798         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15799                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15800                 " eth-src <eth-src> eth-dst <eth-dst>",
15801         .tokens = {
15802                 (void *)&cmd_set_nvgre_set,
15803                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15804                 (void *)&cmd_set_nvgre_ip_version,
15805                 (void *)&cmd_set_nvgre_ip_version_value,
15806                 (void *)&cmd_set_nvgre_tni,
15807                 (void *)&cmd_set_nvgre_tni_value,
15808                 (void *)&cmd_set_nvgre_ip_src,
15809                 (void *)&cmd_set_nvgre_ip_src_value,
15810                 (void *)&cmd_set_nvgre_ip_dst,
15811                 (void *)&cmd_set_nvgre_ip_dst_value,
15812                 (void *)&cmd_set_nvgre_vlan,
15813                 (void *)&cmd_set_nvgre_vlan_value,
15814                 (void *)&cmd_set_nvgre_eth_src,
15815                 (void *)&cmd_set_nvgre_eth_src_value,
15816                 (void *)&cmd_set_nvgre_eth_dst,
15817                 (void *)&cmd_set_nvgre_eth_dst_value,
15818                 NULL,
15819         },
15820 };
15821
15822 /** Set L2 encapsulation details */
15823 struct cmd_set_l2_encap_result {
15824         cmdline_fixed_string_t set;
15825         cmdline_fixed_string_t l2_encap;
15826         cmdline_fixed_string_t pos_token;
15827         cmdline_fixed_string_t ip_version;
15828         uint32_t vlan_present:1;
15829         uint16_t tci;
15830         struct rte_ether_addr eth_src;
15831         struct rte_ether_addr eth_dst;
15832 };
15833
15834 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15835         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15836 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15837         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15838 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15839         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15840                                  "l2_encap-with-vlan");
15841 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15842         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15843                                  "ip-version");
15844 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15845         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15846                                  "ipv4#ipv6");
15847 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15848         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15849                                  "vlan-tci");
15850 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15851         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15852 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15853         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15854                                  "eth-src");
15855 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15856         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15857 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15858         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15859                                  "eth-dst");
15860 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15861         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15862
15863 static void cmd_set_l2_encap_parsed(void *parsed_result,
15864         __rte_unused struct cmdline *cl,
15865         __rte_unused void *data)
15866 {
15867         struct cmd_set_l2_encap_result *res = parsed_result;
15868
15869         if (strcmp(res->l2_encap, "l2_encap") == 0)
15870                 l2_encap_conf.select_vlan = 0;
15871         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15872                 l2_encap_conf.select_vlan = 1;
15873         if (strcmp(res->ip_version, "ipv4") == 0)
15874                 l2_encap_conf.select_ipv4 = 1;
15875         else if (strcmp(res->ip_version, "ipv6") == 0)
15876                 l2_encap_conf.select_ipv4 = 0;
15877         else
15878                 return;
15879         if (l2_encap_conf.select_vlan)
15880                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15881         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15882                    RTE_ETHER_ADDR_LEN);
15883         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15884                    RTE_ETHER_ADDR_LEN);
15885 }
15886
15887 cmdline_parse_inst_t cmd_set_l2_encap = {
15888         .f = cmd_set_l2_encap_parsed,
15889         .data = NULL,
15890         .help_str = "set l2_encap ip-version ipv4|ipv6"
15891                 " 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,
15895                 (void *)&cmd_set_l2_encap_ip_version,
15896                 (void *)&cmd_set_l2_encap_ip_version_value,
15897                 (void *)&cmd_set_l2_encap_eth_src,
15898                 (void *)&cmd_set_l2_encap_eth_src_value,
15899                 (void *)&cmd_set_l2_encap_eth_dst,
15900                 (void *)&cmd_set_l2_encap_eth_dst_value,
15901                 NULL,
15902         },
15903 };
15904
15905 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15906         .f = cmd_set_l2_encap_parsed,
15907         .data = NULL,
15908         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15909                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15910         .tokens = {
15911                 (void *)&cmd_set_l2_encap_set,
15912                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15913                 (void *)&cmd_set_l2_encap_ip_version,
15914                 (void *)&cmd_set_l2_encap_ip_version_value,
15915                 (void *)&cmd_set_l2_encap_vlan,
15916                 (void *)&cmd_set_l2_encap_vlan_value,
15917                 (void *)&cmd_set_l2_encap_eth_src,
15918                 (void *)&cmd_set_l2_encap_eth_src_value,
15919                 (void *)&cmd_set_l2_encap_eth_dst,
15920                 (void *)&cmd_set_l2_encap_eth_dst_value,
15921                 NULL,
15922         },
15923 };
15924
15925 /** Set L2 decapsulation details */
15926 struct cmd_set_l2_decap_result {
15927         cmdline_fixed_string_t set;
15928         cmdline_fixed_string_t l2_decap;
15929         cmdline_fixed_string_t pos_token;
15930         uint32_t vlan_present:1;
15931 };
15932
15933 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15934         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15935 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15936         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15937                                  "l2_decap");
15938 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15939         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15940                                  "l2_decap-with-vlan");
15941
15942 static void cmd_set_l2_decap_parsed(void *parsed_result,
15943         __rte_unused struct cmdline *cl,
15944         __rte_unused void *data)
15945 {
15946         struct cmd_set_l2_decap_result *res = parsed_result;
15947
15948         if (strcmp(res->l2_decap, "l2_decap") == 0)
15949                 l2_decap_conf.select_vlan = 0;
15950         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15951                 l2_decap_conf.select_vlan = 1;
15952 }
15953
15954 cmdline_parse_inst_t cmd_set_l2_decap = {
15955         .f = cmd_set_l2_decap_parsed,
15956         .data = NULL,
15957         .help_str = "set l2_decap",
15958         .tokens = {
15959                 (void *)&cmd_set_l2_decap_set,
15960                 (void *)&cmd_set_l2_decap_l2_decap,
15961                 NULL,
15962         },
15963 };
15964
15965 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15966         .f = cmd_set_l2_decap_parsed,
15967         .data = NULL,
15968         .help_str = "set l2_decap-with-vlan",
15969         .tokens = {
15970                 (void *)&cmd_set_l2_decap_set,
15971                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15972                 NULL,
15973         },
15974 };
15975
15976 /** Set MPLSoGRE encapsulation details */
15977 struct cmd_set_mplsogre_encap_result {
15978         cmdline_fixed_string_t set;
15979         cmdline_fixed_string_t mplsogre;
15980         cmdline_fixed_string_t pos_token;
15981         cmdline_fixed_string_t ip_version;
15982         uint32_t vlan_present:1;
15983         uint32_t label;
15984         cmdline_ipaddr_t ip_src;
15985         cmdline_ipaddr_t ip_dst;
15986         uint16_t tci;
15987         struct rte_ether_addr eth_src;
15988         struct rte_ether_addr eth_dst;
15989 };
15990
15991 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15992         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15993                                  "set");
15994 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15995         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15996                                  "mplsogre_encap");
15997 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15998         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15999                                  mplsogre, "mplsogre_encap-with-vlan");
16000 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16001         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16002                                  pos_token, "ip-version");
16003 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16004         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16005                                  ip_version, "ipv4#ipv6");
16006 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16007         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16008                                  pos_token, "label");
16009 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16010         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16011                               UINT32);
16012 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16013         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16014                                  pos_token, "ip-src");
16015 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16016         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16017 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16018         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16019                                  pos_token, "ip-dst");
16020 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16021         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16022 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16024                                  pos_token, "vlan-tci");
16025 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16026         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16027                               UINT16);
16028 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16029         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16030                                  pos_token, "eth-src");
16031 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16032         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16033                                     eth_src);
16034 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16035         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16036                                  pos_token, "eth-dst");
16037 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16038         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16039                                     eth_dst);
16040
16041 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16042         __rte_unused struct cmdline *cl,
16043         __rte_unused void *data)
16044 {
16045         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16046         union {
16047                 uint32_t mplsogre_label;
16048                 uint8_t label[4];
16049         } id = {
16050                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16051         };
16052
16053         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16054                 mplsogre_encap_conf.select_vlan = 0;
16055         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16056                 mplsogre_encap_conf.select_vlan = 1;
16057         if (strcmp(res->ip_version, "ipv4") == 0)
16058                 mplsogre_encap_conf.select_ipv4 = 1;
16059         else if (strcmp(res->ip_version, "ipv6") == 0)
16060                 mplsogre_encap_conf.select_ipv4 = 0;
16061         else
16062                 return;
16063         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16064         if (mplsogre_encap_conf.select_ipv4) {
16065                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16066                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16067         } else {
16068                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16069                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16070         }
16071         if (mplsogre_encap_conf.select_vlan)
16072                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16073         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16074                    RTE_ETHER_ADDR_LEN);
16075         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16076                    RTE_ETHER_ADDR_LEN);
16077 }
16078
16079 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16080         .f = cmd_set_mplsogre_encap_parsed,
16081         .data = NULL,
16082         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16083                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16084                 " eth-dst <eth-dst>",
16085         .tokens = {
16086                 (void *)&cmd_set_mplsogre_encap_set,
16087                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16088                 (void *)&cmd_set_mplsogre_encap_ip_version,
16089                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16090                 (void *)&cmd_set_mplsogre_encap_label,
16091                 (void *)&cmd_set_mplsogre_encap_label_value,
16092                 (void *)&cmd_set_mplsogre_encap_ip_src,
16093                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16094                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16095                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16096                 (void *)&cmd_set_mplsogre_encap_eth_src,
16097                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16098                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16099                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16100                 NULL,
16101         },
16102 };
16103
16104 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16105         .f = cmd_set_mplsogre_encap_parsed,
16106         .data = NULL,
16107         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16108                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16109                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16110         .tokens = {
16111                 (void *)&cmd_set_mplsogre_encap_set,
16112                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16113                 (void *)&cmd_set_mplsogre_encap_ip_version,
16114                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16115                 (void *)&cmd_set_mplsogre_encap_label,
16116                 (void *)&cmd_set_mplsogre_encap_label_value,
16117                 (void *)&cmd_set_mplsogre_encap_ip_src,
16118                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16119                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16120                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16121                 (void *)&cmd_set_mplsogre_encap_vlan,
16122                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16123                 (void *)&cmd_set_mplsogre_encap_eth_src,
16124                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16125                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16126                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16127                 NULL,
16128         },
16129 };
16130
16131 /** Set MPLSoGRE decapsulation details */
16132 struct cmd_set_mplsogre_decap_result {
16133         cmdline_fixed_string_t set;
16134         cmdline_fixed_string_t mplsogre;
16135         cmdline_fixed_string_t pos_token;
16136         cmdline_fixed_string_t ip_version;
16137         uint32_t vlan_present:1;
16138 };
16139
16140 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16141         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16142                                  "set");
16143 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16144         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16145                                  "mplsogre_decap");
16146 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16147         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16148                                  mplsogre, "mplsogre_decap-with-vlan");
16149 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16150         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16151                                  pos_token, "ip-version");
16152 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16153         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16154                                  ip_version, "ipv4#ipv6");
16155
16156 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16157         __rte_unused struct cmdline *cl,
16158         __rte_unused void *data)
16159 {
16160         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16161
16162         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16163                 mplsogre_decap_conf.select_vlan = 0;
16164         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16165                 mplsogre_decap_conf.select_vlan = 1;
16166         if (strcmp(res->ip_version, "ipv4") == 0)
16167                 mplsogre_decap_conf.select_ipv4 = 1;
16168         else if (strcmp(res->ip_version, "ipv6") == 0)
16169                 mplsogre_decap_conf.select_ipv4 = 0;
16170 }
16171
16172 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16173         .f = cmd_set_mplsogre_decap_parsed,
16174         .data = NULL,
16175         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16176         .tokens = {
16177                 (void *)&cmd_set_mplsogre_decap_set,
16178                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16179                 (void *)&cmd_set_mplsogre_decap_ip_version,
16180                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16181                 NULL,
16182         },
16183 };
16184
16185 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16186         .f = cmd_set_mplsogre_decap_parsed,
16187         .data = NULL,
16188         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16189         .tokens = {
16190                 (void *)&cmd_set_mplsogre_decap_set,
16191                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16192                 (void *)&cmd_set_mplsogre_decap_ip_version,
16193                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16194                 NULL,
16195         },
16196 };
16197
16198 /** Set MPLSoUDP encapsulation details */
16199 struct cmd_set_mplsoudp_encap_result {
16200         cmdline_fixed_string_t set;
16201         cmdline_fixed_string_t mplsoudp;
16202         cmdline_fixed_string_t pos_token;
16203         cmdline_fixed_string_t ip_version;
16204         uint32_t vlan_present:1;
16205         uint32_t label;
16206         uint16_t udp_src;
16207         uint16_t udp_dst;
16208         cmdline_ipaddr_t ip_src;
16209         cmdline_ipaddr_t ip_dst;
16210         uint16_t tci;
16211         struct rte_ether_addr eth_src;
16212         struct rte_ether_addr eth_dst;
16213 };
16214
16215 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16217                                  "set");
16218 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16219         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16220                                  "mplsoudp_encap");
16221 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16222         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16223                                  mplsoudp, "mplsoudp_encap-with-vlan");
16224 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16225         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16226                                  pos_token, "ip-version");
16227 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16228         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16229                                  ip_version, "ipv4#ipv6");
16230 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16231         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16232                                  pos_token, "label");
16233 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16234         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16235                               UINT32);
16236 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16237         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16238                                  pos_token, "udp-src");
16239 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16240         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16241                               UINT16);
16242 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16243         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16244                                  pos_token, "udp-dst");
16245 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16246         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16247                               UINT16);
16248 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16249         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16250                                  pos_token, "ip-src");
16251 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16252         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16253 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16254         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16255                                  pos_token, "ip-dst");
16256 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16257         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16258 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16259         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16260                                  pos_token, "vlan-tci");
16261 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16262         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16263                               UINT16);
16264 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16265         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16266                                  pos_token, "eth-src");
16267 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16268         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16269                                     eth_src);
16270 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16271         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16272                                  pos_token, "eth-dst");
16273 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16274         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16275                                     eth_dst);
16276
16277 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16278         __rte_unused struct cmdline *cl,
16279         __rte_unused void *data)
16280 {
16281         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16282         union {
16283                 uint32_t mplsoudp_label;
16284                 uint8_t label[4];
16285         } id = {
16286                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16287         };
16288
16289         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16290                 mplsoudp_encap_conf.select_vlan = 0;
16291         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16292                 mplsoudp_encap_conf.select_vlan = 1;
16293         if (strcmp(res->ip_version, "ipv4") == 0)
16294                 mplsoudp_encap_conf.select_ipv4 = 1;
16295         else if (strcmp(res->ip_version, "ipv6") == 0)
16296                 mplsoudp_encap_conf.select_ipv4 = 0;
16297         else
16298                 return;
16299         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16300         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16301         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16302         if (mplsoudp_encap_conf.select_ipv4) {
16303                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16304                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16305         } else {
16306                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16307                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16308         }
16309         if (mplsoudp_encap_conf.select_vlan)
16310                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16311         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16312                    RTE_ETHER_ADDR_LEN);
16313         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16314                    RTE_ETHER_ADDR_LEN);
16315 }
16316
16317 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16318         .f = cmd_set_mplsoudp_encap_parsed,
16319         .data = NULL,
16320         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16321                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16322                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16323         .tokens = {
16324                 (void *)&cmd_set_mplsoudp_encap_set,
16325                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16326                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16327                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16328                 (void *)&cmd_set_mplsoudp_encap_label,
16329                 (void *)&cmd_set_mplsoudp_encap_label_value,
16330                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16331                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16332                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16333                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16334                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16335                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16336                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16337                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16338                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16339                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16340                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16341                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16342                 NULL,
16343         },
16344 };
16345
16346 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16347         .f = cmd_set_mplsoudp_encap_parsed,
16348         .data = NULL,
16349         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16350                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16351                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16352                 " eth-src <eth-src> eth-dst <eth-dst>",
16353         .tokens = {
16354                 (void *)&cmd_set_mplsoudp_encap_set,
16355                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16356                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16357                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16358                 (void *)&cmd_set_mplsoudp_encap_label,
16359                 (void *)&cmd_set_mplsoudp_encap_label_value,
16360                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16361                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16362                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16363                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16364                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16365                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16366                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16367                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16368                 (void *)&cmd_set_mplsoudp_encap_vlan,
16369                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16370                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16371                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16372                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16373                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16374                 NULL,
16375         },
16376 };
16377
16378 /** Set MPLSoUDP decapsulation details */
16379 struct cmd_set_mplsoudp_decap_result {
16380         cmdline_fixed_string_t set;
16381         cmdline_fixed_string_t mplsoudp;
16382         cmdline_fixed_string_t pos_token;
16383         cmdline_fixed_string_t ip_version;
16384         uint32_t vlan_present:1;
16385 };
16386
16387 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16388         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16389                                  "set");
16390 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16391         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16392                                  "mplsoudp_decap");
16393 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16394         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16395                                  mplsoudp, "mplsoudp_decap-with-vlan");
16396 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16397         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16398                                  pos_token, "ip-version");
16399 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16400         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16401                                  ip_version, "ipv4#ipv6");
16402
16403 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16404         __rte_unused struct cmdline *cl,
16405         __rte_unused void *data)
16406 {
16407         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16408
16409         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16410                 mplsoudp_decap_conf.select_vlan = 0;
16411         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16412                 mplsoudp_decap_conf.select_vlan = 1;
16413         if (strcmp(res->ip_version, "ipv4") == 0)
16414                 mplsoudp_decap_conf.select_ipv4 = 1;
16415         else if (strcmp(res->ip_version, "ipv6") == 0)
16416                 mplsoudp_decap_conf.select_ipv4 = 0;
16417 }
16418
16419 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16420         .f = cmd_set_mplsoudp_decap_parsed,
16421         .data = NULL,
16422         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16423         .tokens = {
16424                 (void *)&cmd_set_mplsoudp_decap_set,
16425                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16426                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16427                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16428                 NULL,
16429         },
16430 };
16431
16432 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16433         .f = cmd_set_mplsoudp_decap_parsed,
16434         .data = NULL,
16435         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16436         .tokens = {
16437                 (void *)&cmd_set_mplsoudp_decap_set,
16438                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16439                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16440                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16441                 NULL,
16442         },
16443 };
16444
16445 /* Strict link priority scheduling mode setting */
16446 static void
16447 cmd_strict_link_prio_parsed(
16448         void *parsed_result,
16449         __rte_unused struct cmdline *cl,
16450         __rte_unused void *data)
16451 {
16452         struct cmd_vf_tc_bw_result *res = parsed_result;
16453         int ret = -ENOTSUP;
16454
16455         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16456                 return;
16457
16458 #ifdef RTE_LIBRTE_I40E_PMD
16459         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16460 #endif
16461
16462         switch (ret) {
16463         case 0:
16464                 break;
16465         case -EINVAL:
16466                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16467                 break;
16468         case -ENODEV:
16469                 printf("invalid port_id %d\n", res->port_id);
16470                 break;
16471         case -ENOTSUP:
16472                 printf("function not implemented\n");
16473                 break;
16474         default:
16475                 printf("programming error: (%s)\n", strerror(-ret));
16476         }
16477 }
16478
16479 cmdline_parse_inst_t cmd_strict_link_prio = {
16480         .f = cmd_strict_link_prio_parsed,
16481         .data = NULL,
16482         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16483         .tokens = {
16484                 (void *)&cmd_vf_tc_bw_set,
16485                 (void *)&cmd_vf_tc_bw_tx,
16486                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16487                 (void *)&cmd_vf_tc_bw_port_id,
16488                 (void *)&cmd_vf_tc_bw_tc_map,
16489                 NULL,
16490         },
16491 };
16492
16493 /* Load dynamic device personalization*/
16494 struct cmd_ddp_add_result {
16495         cmdline_fixed_string_t ddp;
16496         cmdline_fixed_string_t add;
16497         portid_t port_id;
16498         char filepath[];
16499 };
16500
16501 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16502         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16503 cmdline_parse_token_string_t cmd_ddp_add_add =
16504         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16505 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16506         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16507 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16508         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16509
16510 static void
16511 cmd_ddp_add_parsed(
16512         void *parsed_result,
16513         __rte_unused struct cmdline *cl,
16514         __rte_unused void *data)
16515 {
16516         struct cmd_ddp_add_result *res = parsed_result;
16517         uint8_t *buff;
16518         uint32_t size;
16519         char *filepath;
16520         char *file_fld[2];
16521         int file_num;
16522         int ret = -ENOTSUP;
16523
16524         if (!all_ports_stopped()) {
16525                 printf("Please stop all ports first\n");
16526                 return;
16527         }
16528
16529         filepath = strdup(res->filepath);
16530         if (filepath == NULL) {
16531                 printf("Failed to allocate memory\n");
16532                 return;
16533         }
16534         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16535
16536         buff = open_file(file_fld[0], &size);
16537         if (!buff) {
16538                 free((void *)filepath);
16539                 return;
16540         }
16541
16542 #ifdef RTE_LIBRTE_I40E_PMD
16543         if (ret == -ENOTSUP)
16544                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16545                                                buff, size,
16546                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16547 #endif
16548
16549         if (ret == -EEXIST)
16550                 printf("Profile has already existed.\n");
16551         else if (ret < 0)
16552                 printf("Failed to load profile.\n");
16553         else if (file_num == 2)
16554                 save_file(file_fld[1], buff, size);
16555
16556         close_file(buff);
16557         free((void *)filepath);
16558 }
16559
16560 cmdline_parse_inst_t cmd_ddp_add = {
16561         .f = cmd_ddp_add_parsed,
16562         .data = NULL,
16563         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16564         .tokens = {
16565                 (void *)&cmd_ddp_add_ddp,
16566                 (void *)&cmd_ddp_add_add,
16567                 (void *)&cmd_ddp_add_port_id,
16568                 (void *)&cmd_ddp_add_filepath,
16569                 NULL,
16570         },
16571 };
16572
16573 /* Delete dynamic device personalization*/
16574 struct cmd_ddp_del_result {
16575         cmdline_fixed_string_t ddp;
16576         cmdline_fixed_string_t del;
16577         portid_t port_id;
16578         char filepath[];
16579 };
16580
16581 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16582         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16583 cmdline_parse_token_string_t cmd_ddp_del_del =
16584         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16585 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16586         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16587 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16588         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16589
16590 static void
16591 cmd_ddp_del_parsed(
16592         void *parsed_result,
16593         __rte_unused struct cmdline *cl,
16594         __rte_unused void *data)
16595 {
16596         struct cmd_ddp_del_result *res = parsed_result;
16597         uint8_t *buff;
16598         uint32_t size;
16599         int ret = -ENOTSUP;
16600
16601         if (!all_ports_stopped()) {
16602                 printf("Please stop all ports first\n");
16603                 return;
16604         }
16605
16606         buff = open_file(res->filepath, &size);
16607         if (!buff)
16608                 return;
16609
16610 #ifdef RTE_LIBRTE_I40E_PMD
16611         if (ret == -ENOTSUP)
16612                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16613                                                buff, size,
16614                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16615 #endif
16616
16617         if (ret == -EACCES)
16618                 printf("Profile does not exist.\n");
16619         else if (ret < 0)
16620                 printf("Failed to delete profile.\n");
16621
16622         close_file(buff);
16623 }
16624
16625 cmdline_parse_inst_t cmd_ddp_del = {
16626         .f = cmd_ddp_del_parsed,
16627         .data = NULL,
16628         .help_str = "ddp del <port_id> <backup_profile_path>",
16629         .tokens = {
16630                 (void *)&cmd_ddp_del_ddp,
16631                 (void *)&cmd_ddp_del_del,
16632                 (void *)&cmd_ddp_del_port_id,
16633                 (void *)&cmd_ddp_del_filepath,
16634                 NULL,
16635         },
16636 };
16637
16638 /* Get dynamic device personalization profile info */
16639 struct cmd_ddp_info_result {
16640         cmdline_fixed_string_t ddp;
16641         cmdline_fixed_string_t get;
16642         cmdline_fixed_string_t info;
16643         char filepath[];
16644 };
16645
16646 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16647         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16648 cmdline_parse_token_string_t cmd_ddp_info_get =
16649         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16650 cmdline_parse_token_string_t cmd_ddp_info_info =
16651         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16652 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16653         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16654
16655 static void
16656 cmd_ddp_info_parsed(
16657         void *parsed_result,
16658         __rte_unused struct cmdline *cl,
16659         __rte_unused void *data)
16660 {
16661         struct cmd_ddp_info_result *res = parsed_result;
16662         uint8_t *pkg;
16663         uint32_t pkg_size;
16664         int ret = -ENOTSUP;
16665 #ifdef RTE_LIBRTE_I40E_PMD
16666         uint32_t i, j, n;
16667         uint8_t *buff;
16668         uint32_t buff_size = 0;
16669         struct rte_pmd_i40e_profile_info info;
16670         uint32_t dev_num = 0;
16671         struct rte_pmd_i40e_ddp_device_id *devs;
16672         uint32_t proto_num = 0;
16673         struct rte_pmd_i40e_proto_info *proto = NULL;
16674         uint32_t pctype_num = 0;
16675         struct rte_pmd_i40e_ptype_info *pctype;
16676         uint32_t ptype_num = 0;
16677         struct rte_pmd_i40e_ptype_info *ptype;
16678         uint8_t proto_id;
16679
16680 #endif
16681
16682         pkg = open_file(res->filepath, &pkg_size);
16683         if (!pkg)
16684                 return;
16685
16686 #ifdef RTE_LIBRTE_I40E_PMD
16687         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16688                                 (uint8_t *)&info, sizeof(info),
16689                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16690         if (!ret) {
16691                 printf("Global Track id:       0x%x\n", info.track_id);
16692                 printf("Global Version:        %d.%d.%d.%d\n",
16693                         info.version.major,
16694                         info.version.minor,
16695                         info.version.update,
16696                         info.version.draft);
16697                 printf("Global Package name:   %s\n\n", info.name);
16698         }
16699
16700         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16701                                 (uint8_t *)&info, sizeof(info),
16702                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16703         if (!ret) {
16704                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16705                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16706                         info.version.major,
16707                         info.version.minor,
16708                         info.version.update,
16709                         info.version.draft);
16710                 printf("i40e Profile name:     %s\n\n", info.name);
16711         }
16712
16713         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16714                                 (uint8_t *)&buff_size, sizeof(buff_size),
16715                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16716         if (!ret && buff_size) {
16717                 buff = (uint8_t *)malloc(buff_size);
16718                 if (buff) {
16719                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16720                                                 buff, buff_size,
16721                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16722                         if (!ret)
16723                                 printf("Package Notes:\n%s\n\n", buff);
16724                         free(buff);
16725                 }
16726         }
16727
16728         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16729                                 (uint8_t *)&dev_num, sizeof(dev_num),
16730                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16731         if (!ret && dev_num) {
16732                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16733                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16734                 if (devs) {
16735                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16736                                                 (uint8_t *)devs, buff_size,
16737                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16738                         if (!ret) {
16739                                 printf("List of supported devices:\n");
16740                                 for (i = 0; i < dev_num; i++) {
16741                                         printf("  %04X:%04X %04X:%04X\n",
16742                                                 devs[i].vendor_dev_id >> 16,
16743                                                 devs[i].vendor_dev_id & 0xFFFF,
16744                                                 devs[i].sub_vendor_dev_id >> 16,
16745                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16746                                 }
16747                                 printf("\n");
16748                         }
16749                         free(devs);
16750                 }
16751         }
16752
16753         /* get information about protocols and packet types */
16754         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16755                 (uint8_t *)&proto_num, sizeof(proto_num),
16756                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16757         if (ret || !proto_num)
16758                 goto no_print_return;
16759
16760         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16761         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16762         if (!proto)
16763                 goto no_print_return;
16764
16765         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16766                                         buff_size,
16767                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16768         if (!ret) {
16769                 printf("List of used protocols:\n");
16770                 for (i = 0; i < proto_num; i++)
16771                         printf("  %2u: %s\n", proto[i].proto_id,
16772                                proto[i].name);
16773                 printf("\n");
16774         }
16775         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16776                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16777                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16778         if (ret || !pctype_num)
16779                 goto no_print_pctypes;
16780
16781         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16782         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16783         if (!pctype)
16784                 goto no_print_pctypes;
16785
16786         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16787                                         buff_size,
16788                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16789         if (ret) {
16790                 free(pctype);
16791                 goto no_print_pctypes;
16792         }
16793
16794         printf("List of defined packet classification types:\n");
16795         for (i = 0; i < pctype_num; i++) {
16796                 printf("  %2u:", pctype[i].ptype_id);
16797                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16798                         proto_id = pctype[i].protocols[j];
16799                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16800                                 for (n = 0; n < proto_num; n++) {
16801                                         if (proto[n].proto_id == proto_id) {
16802                                                 printf(" %s", proto[n].name);
16803                                                 break;
16804                                         }
16805                                 }
16806                         }
16807                 }
16808                 printf("\n");
16809         }
16810         printf("\n");
16811         free(pctype);
16812
16813 no_print_pctypes:
16814
16815         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16816                                         sizeof(ptype_num),
16817                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16818         if (ret || !ptype_num)
16819                 goto no_print_return;
16820
16821         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16822         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16823         if (!ptype)
16824                 goto no_print_return;
16825
16826         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16827                                         buff_size,
16828                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16829         if (ret) {
16830                 free(ptype);
16831                 goto no_print_return;
16832         }
16833         printf("List of defined packet types:\n");
16834         for (i = 0; i < ptype_num; i++) {
16835                 printf("  %2u:", ptype[i].ptype_id);
16836                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16837                         proto_id = ptype[i].protocols[j];
16838                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16839                                 for (n = 0; n < proto_num; n++) {
16840                                         if (proto[n].proto_id == proto_id) {
16841                                                 printf(" %s", proto[n].name);
16842                                                 break;
16843                                         }
16844                                 }
16845                         }
16846                 }
16847                 printf("\n");
16848         }
16849         free(ptype);
16850         printf("\n");
16851
16852         ret = 0;
16853 no_print_return:
16854         if (proto)
16855                 free(proto);
16856 #endif
16857         if (ret == -ENOTSUP)
16858                 printf("Function not supported in PMD driver\n");
16859         close_file(pkg);
16860 }
16861
16862 cmdline_parse_inst_t cmd_ddp_get_info = {
16863         .f = cmd_ddp_info_parsed,
16864         .data = NULL,
16865         .help_str = "ddp get info <profile_path>",
16866         .tokens = {
16867                 (void *)&cmd_ddp_info_ddp,
16868                 (void *)&cmd_ddp_info_get,
16869                 (void *)&cmd_ddp_info_info,
16870                 (void *)&cmd_ddp_info_filepath,
16871                 NULL,
16872         },
16873 };
16874
16875 /* Get dynamic device personalization profile info list*/
16876 #define PROFILE_INFO_SIZE 48
16877 #define MAX_PROFILE_NUM 16
16878
16879 struct cmd_ddp_get_list_result {
16880         cmdline_fixed_string_t ddp;
16881         cmdline_fixed_string_t get;
16882         cmdline_fixed_string_t list;
16883         portid_t port_id;
16884 };
16885
16886 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16887         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16888 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16889         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16890 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16891         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16892 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16893         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16894
16895 static void
16896 cmd_ddp_get_list_parsed(
16897         __rte_unused void *parsed_result,
16898         __rte_unused struct cmdline *cl,
16899         __rte_unused void *data)
16900 {
16901 #ifdef RTE_LIBRTE_I40E_PMD
16902         struct cmd_ddp_get_list_result *res = parsed_result;
16903         struct rte_pmd_i40e_profile_list *p_list;
16904         struct rte_pmd_i40e_profile_info *p_info;
16905         uint32_t p_num;
16906         uint32_t size;
16907         uint32_t i;
16908 #endif
16909         int ret = -ENOTSUP;
16910
16911 #ifdef RTE_LIBRTE_I40E_PMD
16912         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16913         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16914         if (!p_list) {
16915                 printf("%s: Failed to malloc buffer\n", __func__);
16916                 return;
16917         }
16918
16919         if (ret == -ENOTSUP)
16920                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16921                                                 (uint8_t *)p_list, size);
16922
16923         if (!ret) {
16924                 p_num = p_list->p_count;
16925                 printf("Profile number is: %d\n\n", p_num);
16926
16927                 for (i = 0; i < p_num; i++) {
16928                         p_info = &p_list->p_info[i];
16929                         printf("Profile %d:\n", i);
16930                         printf("Track id:     0x%x\n", p_info->track_id);
16931                         printf("Version:      %d.%d.%d.%d\n",
16932                                p_info->version.major,
16933                                p_info->version.minor,
16934                                p_info->version.update,
16935                                p_info->version.draft);
16936                         printf("Profile name: %s\n\n", p_info->name);
16937                 }
16938         }
16939
16940         free(p_list);
16941 #endif
16942
16943         if (ret < 0)
16944                 printf("Failed to get ddp list\n");
16945 }
16946
16947 cmdline_parse_inst_t cmd_ddp_get_list = {
16948         .f = cmd_ddp_get_list_parsed,
16949         .data = NULL,
16950         .help_str = "ddp get list <port_id>",
16951         .tokens = {
16952                 (void *)&cmd_ddp_get_list_ddp,
16953                 (void *)&cmd_ddp_get_list_get,
16954                 (void *)&cmd_ddp_get_list_list,
16955                 (void *)&cmd_ddp_get_list_port_id,
16956                 NULL,
16957         },
16958 };
16959
16960 /* Configure input set */
16961 struct cmd_cfg_input_set_result {
16962         cmdline_fixed_string_t port;
16963         cmdline_fixed_string_t cfg;
16964         portid_t port_id;
16965         cmdline_fixed_string_t pctype;
16966         uint8_t pctype_id;
16967         cmdline_fixed_string_t inset_type;
16968         cmdline_fixed_string_t opt;
16969         cmdline_fixed_string_t field;
16970         uint8_t field_idx;
16971 };
16972
16973 static void
16974 cmd_cfg_input_set_parsed(
16975         __rte_unused void *parsed_result,
16976         __rte_unused struct cmdline *cl,
16977         __rte_unused void *data)
16978 {
16979 #ifdef RTE_LIBRTE_I40E_PMD
16980         struct cmd_cfg_input_set_result *res = parsed_result;
16981         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16982         struct rte_pmd_i40e_inset inset;
16983 #endif
16984         int ret = -ENOTSUP;
16985
16986         if (!all_ports_stopped()) {
16987                 printf("Please stop all ports first\n");
16988                 return;
16989         }
16990
16991 #ifdef RTE_LIBRTE_I40E_PMD
16992         if (!strcmp(res->inset_type, "hash_inset"))
16993                 inset_type = INSET_HASH;
16994         else if (!strcmp(res->inset_type, "fdir_inset"))
16995                 inset_type = INSET_FDIR;
16996         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16997                 inset_type = INSET_FDIR_FLX;
16998         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16999                                      &inset, inset_type);
17000         if (ret) {
17001                 printf("Failed to get input set.\n");
17002                 return;
17003         }
17004
17005         if (!strcmp(res->opt, "get")) {
17006                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17007                                                    res->field_idx);
17008                 if (ret)
17009                         printf("Field index %d is enabled.\n", res->field_idx);
17010                 else
17011                         printf("Field index %d is disabled.\n", res->field_idx);
17012                 return;
17013         } else if (!strcmp(res->opt, "set"))
17014                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17015                                                    res->field_idx);
17016         else if (!strcmp(res->opt, "clear"))
17017                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17018                                                      res->field_idx);
17019         if (ret) {
17020                 printf("Failed to configure input set field.\n");
17021                 return;
17022         }
17023
17024         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17025                                      &inset, inset_type);
17026         if (ret) {
17027                 printf("Failed to set input set.\n");
17028                 return;
17029         }
17030 #endif
17031
17032         if (ret == -ENOTSUP)
17033                 printf("Function not supported\n");
17034 }
17035
17036 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17037         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17038                                  port, "port");
17039 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17040         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17041                                  cfg, "config");
17042 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17043         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17044                               port_id, UINT16);
17045 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17046         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17047                                  pctype, "pctype");
17048 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17049         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17050                               pctype_id, UINT8);
17051 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17052         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17053                                  inset_type,
17054                                  "hash_inset#fdir_inset#fdir_flx_inset");
17055 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17056         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17057                                  opt, "get#set#clear");
17058 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17059         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17060                                  field, "field");
17061 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17062         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17063                               field_idx, UINT8);
17064
17065 cmdline_parse_inst_t cmd_cfg_input_set = {
17066         .f = cmd_cfg_input_set_parsed,
17067         .data = NULL,
17068         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17069                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17070         .tokens = {
17071                 (void *)&cmd_cfg_input_set_port,
17072                 (void *)&cmd_cfg_input_set_cfg,
17073                 (void *)&cmd_cfg_input_set_port_id,
17074                 (void *)&cmd_cfg_input_set_pctype,
17075                 (void *)&cmd_cfg_input_set_pctype_id,
17076                 (void *)&cmd_cfg_input_set_inset_type,
17077                 (void *)&cmd_cfg_input_set_opt,
17078                 (void *)&cmd_cfg_input_set_field,
17079                 (void *)&cmd_cfg_input_set_field_idx,
17080                 NULL,
17081         },
17082 };
17083
17084 /* Clear input set */
17085 struct cmd_clear_input_set_result {
17086         cmdline_fixed_string_t port;
17087         cmdline_fixed_string_t cfg;
17088         portid_t port_id;
17089         cmdline_fixed_string_t pctype;
17090         uint8_t pctype_id;
17091         cmdline_fixed_string_t inset_type;
17092         cmdline_fixed_string_t clear;
17093         cmdline_fixed_string_t all;
17094 };
17095
17096 static void
17097 cmd_clear_input_set_parsed(
17098         __rte_unused void *parsed_result,
17099         __rte_unused struct cmdline *cl,
17100         __rte_unused void *data)
17101 {
17102 #ifdef RTE_LIBRTE_I40E_PMD
17103         struct cmd_clear_input_set_result *res = parsed_result;
17104         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17105         struct rte_pmd_i40e_inset inset;
17106 #endif
17107         int ret = -ENOTSUP;
17108
17109         if (!all_ports_stopped()) {
17110                 printf("Please stop all ports first\n");
17111                 return;
17112         }
17113
17114 #ifdef RTE_LIBRTE_I40E_PMD
17115         if (!strcmp(res->inset_type, "hash_inset"))
17116                 inset_type = INSET_HASH;
17117         else if (!strcmp(res->inset_type, "fdir_inset"))
17118                 inset_type = INSET_FDIR;
17119         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17120                 inset_type = INSET_FDIR_FLX;
17121
17122         memset(&inset, 0, sizeof(inset));
17123
17124         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17125                                      &inset, inset_type);
17126         if (ret) {
17127                 printf("Failed to clear input set.\n");
17128                 return;
17129         }
17130
17131 #endif
17132
17133         if (ret == -ENOTSUP)
17134                 printf("Function not supported\n");
17135 }
17136
17137 cmdline_parse_token_string_t cmd_clear_input_set_port =
17138         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17139                                  port, "port");
17140 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17141         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17142                                  cfg, "config");
17143 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17144         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17145                               port_id, UINT16);
17146 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17147         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17148                                  pctype, "pctype");
17149 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17150         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17151                               pctype_id, UINT8);
17152 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17153         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17154                                  inset_type,
17155                                  "hash_inset#fdir_inset#fdir_flx_inset");
17156 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17157         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17158                                  clear, "clear");
17159 cmdline_parse_token_string_t cmd_clear_input_set_all =
17160         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17161                                  all, "all");
17162
17163 cmdline_parse_inst_t cmd_clear_input_set = {
17164         .f = cmd_clear_input_set_parsed,
17165         .data = NULL,
17166         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17167                     "fdir_inset|fdir_flx_inset clear all",
17168         .tokens = {
17169                 (void *)&cmd_clear_input_set_port,
17170                 (void *)&cmd_clear_input_set_cfg,
17171                 (void *)&cmd_clear_input_set_port_id,
17172                 (void *)&cmd_clear_input_set_pctype,
17173                 (void *)&cmd_clear_input_set_pctype_id,
17174                 (void *)&cmd_clear_input_set_inset_type,
17175                 (void *)&cmd_clear_input_set_clear,
17176                 (void *)&cmd_clear_input_set_all,
17177                 NULL,
17178         },
17179 };
17180
17181 /* show vf stats */
17182
17183 /* Common result structure for show vf stats */
17184 struct cmd_show_vf_stats_result {
17185         cmdline_fixed_string_t show;
17186         cmdline_fixed_string_t vf;
17187         cmdline_fixed_string_t stats;
17188         portid_t port_id;
17189         uint16_t vf_id;
17190 };
17191
17192 /* Common CLI fields show vf stats*/
17193 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17194         TOKEN_STRING_INITIALIZER
17195                 (struct cmd_show_vf_stats_result,
17196                  show, "show");
17197 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17198         TOKEN_STRING_INITIALIZER
17199                 (struct cmd_show_vf_stats_result,
17200                  vf, "vf");
17201 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17202         TOKEN_STRING_INITIALIZER
17203                 (struct cmd_show_vf_stats_result,
17204                  stats, "stats");
17205 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17206         TOKEN_NUM_INITIALIZER
17207                 (struct cmd_show_vf_stats_result,
17208                  port_id, UINT16);
17209 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17210         TOKEN_NUM_INITIALIZER
17211                 (struct cmd_show_vf_stats_result,
17212                  vf_id, UINT16);
17213
17214 static void
17215 cmd_show_vf_stats_parsed(
17216         void *parsed_result,
17217         __rte_unused struct cmdline *cl,
17218         __rte_unused void *data)
17219 {
17220         struct cmd_show_vf_stats_result *res = parsed_result;
17221         struct rte_eth_stats stats;
17222         int ret = -ENOTSUP;
17223         static const char *nic_stats_border = "########################";
17224
17225         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17226                 return;
17227
17228         memset(&stats, 0, sizeof(stats));
17229
17230 #ifdef RTE_LIBRTE_I40E_PMD
17231         if (ret == -ENOTSUP)
17232                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17233                                                 res->vf_id,
17234                                                 &stats);
17235 #endif
17236 #ifdef RTE_LIBRTE_BNXT_PMD
17237         if (ret == -ENOTSUP)
17238                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17239                                                 res->vf_id,
17240                                                 &stats);
17241 #endif
17242
17243         switch (ret) {
17244         case 0:
17245                 break;
17246         case -EINVAL:
17247                 printf("invalid vf_id %d\n", res->vf_id);
17248                 break;
17249         case -ENODEV:
17250                 printf("invalid port_id %d\n", res->port_id);
17251                 break;
17252         case -ENOTSUP:
17253                 printf("function not implemented\n");
17254                 break;
17255         default:
17256                 printf("programming error: (%s)\n", strerror(-ret));
17257         }
17258
17259         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17260                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17261
17262         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17263                "%-"PRIu64"\n",
17264                stats.ipackets, stats.imissed, stats.ibytes);
17265         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17266         printf("  RX-nombuf:  %-10"PRIu64"\n",
17267                stats.rx_nombuf);
17268         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17269                "%-"PRIu64"\n",
17270                stats.opackets, stats.oerrors, stats.obytes);
17271
17272         printf("  %s############################%s\n",
17273                                nic_stats_border, nic_stats_border);
17274 }
17275
17276 cmdline_parse_inst_t cmd_show_vf_stats = {
17277         .f = cmd_show_vf_stats_parsed,
17278         .data = NULL,
17279         .help_str = "show vf stats <port_id> <vf_id>",
17280         .tokens = {
17281                 (void *)&cmd_show_vf_stats_show,
17282                 (void *)&cmd_show_vf_stats_vf,
17283                 (void *)&cmd_show_vf_stats_stats,
17284                 (void *)&cmd_show_vf_stats_port_id,
17285                 (void *)&cmd_show_vf_stats_vf_id,
17286                 NULL,
17287         },
17288 };
17289
17290 /* clear vf stats */
17291
17292 /* Common result structure for clear vf stats */
17293 struct cmd_clear_vf_stats_result {
17294         cmdline_fixed_string_t clear;
17295         cmdline_fixed_string_t vf;
17296         cmdline_fixed_string_t stats;
17297         portid_t port_id;
17298         uint16_t vf_id;
17299 };
17300
17301 /* Common CLI fields clear vf stats*/
17302 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17303         TOKEN_STRING_INITIALIZER
17304                 (struct cmd_clear_vf_stats_result,
17305                  clear, "clear");
17306 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17307         TOKEN_STRING_INITIALIZER
17308                 (struct cmd_clear_vf_stats_result,
17309                  vf, "vf");
17310 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17311         TOKEN_STRING_INITIALIZER
17312                 (struct cmd_clear_vf_stats_result,
17313                  stats, "stats");
17314 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17315         TOKEN_NUM_INITIALIZER
17316                 (struct cmd_clear_vf_stats_result,
17317                  port_id, UINT16);
17318 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17319         TOKEN_NUM_INITIALIZER
17320                 (struct cmd_clear_vf_stats_result,
17321                  vf_id, UINT16);
17322
17323 static void
17324 cmd_clear_vf_stats_parsed(
17325         void *parsed_result,
17326         __rte_unused struct cmdline *cl,
17327         __rte_unused void *data)
17328 {
17329         struct cmd_clear_vf_stats_result *res = parsed_result;
17330         int ret = -ENOTSUP;
17331
17332         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17333                 return;
17334
17335 #ifdef RTE_LIBRTE_I40E_PMD
17336         if (ret == -ENOTSUP)
17337                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17338                                                   res->vf_id);
17339 #endif
17340 #ifdef RTE_LIBRTE_BNXT_PMD
17341         if (ret == -ENOTSUP)
17342                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17343                                                   res->vf_id);
17344 #endif
17345
17346         switch (ret) {
17347         case 0:
17348                 break;
17349         case -EINVAL:
17350                 printf("invalid vf_id %d\n", res->vf_id);
17351                 break;
17352         case -ENODEV:
17353                 printf("invalid port_id %d\n", res->port_id);
17354                 break;
17355         case -ENOTSUP:
17356                 printf("function not implemented\n");
17357                 break;
17358         default:
17359                 printf("programming error: (%s)\n", strerror(-ret));
17360         }
17361 }
17362
17363 cmdline_parse_inst_t cmd_clear_vf_stats = {
17364         .f = cmd_clear_vf_stats_parsed,
17365         .data = NULL,
17366         .help_str = "clear vf stats <port_id> <vf_id>",
17367         .tokens = {
17368                 (void *)&cmd_clear_vf_stats_clear,
17369                 (void *)&cmd_clear_vf_stats_vf,
17370                 (void *)&cmd_clear_vf_stats_stats,
17371                 (void *)&cmd_clear_vf_stats_port_id,
17372                 (void *)&cmd_clear_vf_stats_vf_id,
17373                 NULL,
17374         },
17375 };
17376
17377 /* port config pctype mapping reset */
17378
17379 /* Common result structure for port config pctype mapping reset */
17380 struct cmd_pctype_mapping_reset_result {
17381         cmdline_fixed_string_t port;
17382         cmdline_fixed_string_t config;
17383         portid_t port_id;
17384         cmdline_fixed_string_t pctype;
17385         cmdline_fixed_string_t mapping;
17386         cmdline_fixed_string_t reset;
17387 };
17388
17389 /* Common CLI fields for port config pctype mapping reset*/
17390 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17391         TOKEN_STRING_INITIALIZER
17392                 (struct cmd_pctype_mapping_reset_result,
17393                  port, "port");
17394 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17395         TOKEN_STRING_INITIALIZER
17396                 (struct cmd_pctype_mapping_reset_result,
17397                  config, "config");
17398 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17399         TOKEN_NUM_INITIALIZER
17400                 (struct cmd_pctype_mapping_reset_result,
17401                  port_id, UINT16);
17402 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17403         TOKEN_STRING_INITIALIZER
17404                 (struct cmd_pctype_mapping_reset_result,
17405                  pctype, "pctype");
17406 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17407         TOKEN_STRING_INITIALIZER
17408                 (struct cmd_pctype_mapping_reset_result,
17409                  mapping, "mapping");
17410 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17411         TOKEN_STRING_INITIALIZER
17412                 (struct cmd_pctype_mapping_reset_result,
17413                  reset, "reset");
17414
17415 static void
17416 cmd_pctype_mapping_reset_parsed(
17417         void *parsed_result,
17418         __rte_unused struct cmdline *cl,
17419         __rte_unused void *data)
17420 {
17421         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17422         int ret = -ENOTSUP;
17423
17424         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17425                 return;
17426
17427 #ifdef RTE_LIBRTE_I40E_PMD
17428         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17429 #endif
17430
17431         switch (ret) {
17432         case 0:
17433                 break;
17434         case -ENODEV:
17435                 printf("invalid port_id %d\n", res->port_id);
17436                 break;
17437         case -ENOTSUP:
17438                 printf("function not implemented\n");
17439                 break;
17440         default:
17441                 printf("programming error: (%s)\n", strerror(-ret));
17442         }
17443 }
17444
17445 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17446         .f = cmd_pctype_mapping_reset_parsed,
17447         .data = NULL,
17448         .help_str = "port config <port_id> pctype mapping reset",
17449         .tokens = {
17450                 (void *)&cmd_pctype_mapping_reset_port,
17451                 (void *)&cmd_pctype_mapping_reset_config,
17452                 (void *)&cmd_pctype_mapping_reset_port_id,
17453                 (void *)&cmd_pctype_mapping_reset_pctype,
17454                 (void *)&cmd_pctype_mapping_reset_mapping,
17455                 (void *)&cmd_pctype_mapping_reset_reset,
17456                 NULL,
17457         },
17458 };
17459
17460 /* show port pctype mapping */
17461
17462 /* Common result structure for show port pctype mapping */
17463 struct cmd_pctype_mapping_get_result {
17464         cmdline_fixed_string_t show;
17465         cmdline_fixed_string_t port;
17466         portid_t port_id;
17467         cmdline_fixed_string_t pctype;
17468         cmdline_fixed_string_t mapping;
17469 };
17470
17471 /* Common CLI fields for pctype mapping get */
17472 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17473         TOKEN_STRING_INITIALIZER
17474                 (struct cmd_pctype_mapping_get_result,
17475                  show, "show");
17476 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17477         TOKEN_STRING_INITIALIZER
17478                 (struct cmd_pctype_mapping_get_result,
17479                  port, "port");
17480 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17481         TOKEN_NUM_INITIALIZER
17482                 (struct cmd_pctype_mapping_get_result,
17483                  port_id, UINT16);
17484 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17485         TOKEN_STRING_INITIALIZER
17486                 (struct cmd_pctype_mapping_get_result,
17487                  pctype, "pctype");
17488 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17489         TOKEN_STRING_INITIALIZER
17490                 (struct cmd_pctype_mapping_get_result,
17491                  mapping, "mapping");
17492
17493 static void
17494 cmd_pctype_mapping_get_parsed(
17495         void *parsed_result,
17496         __rte_unused struct cmdline *cl,
17497         __rte_unused void *data)
17498 {
17499         struct cmd_pctype_mapping_get_result *res = parsed_result;
17500         int ret = -ENOTSUP;
17501 #ifdef RTE_LIBRTE_I40E_PMD
17502         struct rte_pmd_i40e_flow_type_mapping
17503                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17504         int i, j, first_pctype;
17505 #endif
17506
17507         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17508                 return;
17509
17510 #ifdef RTE_LIBRTE_I40E_PMD
17511         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17512 #endif
17513
17514         switch (ret) {
17515         case 0:
17516                 break;
17517         case -ENODEV:
17518                 printf("invalid port_id %d\n", res->port_id);
17519                 return;
17520         case -ENOTSUP:
17521                 printf("function not implemented\n");
17522                 return;
17523         default:
17524                 printf("programming error: (%s)\n", strerror(-ret));
17525                 return;
17526         }
17527
17528 #ifdef RTE_LIBRTE_I40E_PMD
17529         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17530                 if (mapping[i].pctype != 0ULL) {
17531                         first_pctype = 1;
17532
17533                         printf("pctype: ");
17534                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17535                                 if (mapping[i].pctype & (1ULL << j)) {
17536                                         printf(first_pctype ?
17537                                                "%02d" : ",%02d", j);
17538                                         first_pctype = 0;
17539                                 }
17540                         }
17541                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17542                 }
17543         }
17544 #endif
17545 }
17546
17547 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17548         .f = cmd_pctype_mapping_get_parsed,
17549         .data = NULL,
17550         .help_str = "show port <port_id> pctype mapping",
17551         .tokens = {
17552                 (void *)&cmd_pctype_mapping_get_show,
17553                 (void *)&cmd_pctype_mapping_get_port,
17554                 (void *)&cmd_pctype_mapping_get_port_id,
17555                 (void *)&cmd_pctype_mapping_get_pctype,
17556                 (void *)&cmd_pctype_mapping_get_mapping,
17557                 NULL,
17558         },
17559 };
17560
17561 /* port config pctype mapping update */
17562
17563 /* Common result structure for port config pctype mapping update */
17564 struct cmd_pctype_mapping_update_result {
17565         cmdline_fixed_string_t port;
17566         cmdline_fixed_string_t config;
17567         portid_t port_id;
17568         cmdline_fixed_string_t pctype;
17569         cmdline_fixed_string_t mapping;
17570         cmdline_fixed_string_t update;
17571         cmdline_fixed_string_t pctype_list;
17572         uint16_t flow_type;
17573 };
17574
17575 /* Common CLI fields for pctype mapping update*/
17576 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17577         TOKEN_STRING_INITIALIZER
17578                 (struct cmd_pctype_mapping_update_result,
17579                  port, "port");
17580 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17581         TOKEN_STRING_INITIALIZER
17582                 (struct cmd_pctype_mapping_update_result,
17583                  config, "config");
17584 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17585         TOKEN_NUM_INITIALIZER
17586                 (struct cmd_pctype_mapping_update_result,
17587                  port_id, UINT16);
17588 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17589         TOKEN_STRING_INITIALIZER
17590                 (struct cmd_pctype_mapping_update_result,
17591                  pctype, "pctype");
17592 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17593         TOKEN_STRING_INITIALIZER
17594                 (struct cmd_pctype_mapping_update_result,
17595                  mapping, "mapping");
17596 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17597         TOKEN_STRING_INITIALIZER
17598                 (struct cmd_pctype_mapping_update_result,
17599                  update, "update");
17600 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17601         TOKEN_STRING_INITIALIZER
17602                 (struct cmd_pctype_mapping_update_result,
17603                  pctype_list, NULL);
17604 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17605         TOKEN_NUM_INITIALIZER
17606                 (struct cmd_pctype_mapping_update_result,
17607                  flow_type, UINT16);
17608
17609 static void
17610 cmd_pctype_mapping_update_parsed(
17611         void *parsed_result,
17612         __rte_unused struct cmdline *cl,
17613         __rte_unused void *data)
17614 {
17615         struct cmd_pctype_mapping_update_result *res = parsed_result;
17616         int ret = -ENOTSUP;
17617 #ifdef RTE_LIBRTE_I40E_PMD
17618         struct rte_pmd_i40e_flow_type_mapping mapping;
17619         unsigned int i;
17620         unsigned int nb_item;
17621         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17622 #endif
17623
17624         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17625                 return;
17626
17627 #ifdef RTE_LIBRTE_I40E_PMD
17628         nb_item = parse_item_list(res->pctype_list, "pctypes",
17629                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17630         mapping.flow_type = res->flow_type;
17631         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17632                 mapping.pctype |= (1ULL << pctype_list[i]);
17633         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17634                                                 &mapping,
17635                                                 1,
17636                                                 0);
17637 #endif
17638
17639         switch (ret) {
17640         case 0:
17641                 break;
17642         case -EINVAL:
17643                 printf("invalid pctype or flow type\n");
17644                 break;
17645         case -ENODEV:
17646                 printf("invalid port_id %d\n", res->port_id);
17647                 break;
17648         case -ENOTSUP:
17649                 printf("function not implemented\n");
17650                 break;
17651         default:
17652                 printf("programming error: (%s)\n", strerror(-ret));
17653         }
17654 }
17655
17656 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17657         .f = cmd_pctype_mapping_update_parsed,
17658         .data = NULL,
17659         .help_str = "port config <port_id> pctype mapping update"
17660         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17661         .tokens = {
17662                 (void *)&cmd_pctype_mapping_update_port,
17663                 (void *)&cmd_pctype_mapping_update_config,
17664                 (void *)&cmd_pctype_mapping_update_port_id,
17665                 (void *)&cmd_pctype_mapping_update_pctype,
17666                 (void *)&cmd_pctype_mapping_update_mapping,
17667                 (void *)&cmd_pctype_mapping_update_update,
17668                 (void *)&cmd_pctype_mapping_update_pc_type,
17669                 (void *)&cmd_pctype_mapping_update_flow_type,
17670                 NULL,
17671         },
17672 };
17673
17674 /* ptype mapping get */
17675
17676 /* Common result structure for ptype mapping get */
17677 struct cmd_ptype_mapping_get_result {
17678         cmdline_fixed_string_t ptype;
17679         cmdline_fixed_string_t mapping;
17680         cmdline_fixed_string_t get;
17681         portid_t port_id;
17682         uint8_t valid_only;
17683 };
17684
17685 /* Common CLI fields for ptype mapping get */
17686 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17687         TOKEN_STRING_INITIALIZER
17688                 (struct cmd_ptype_mapping_get_result,
17689                  ptype, "ptype");
17690 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17691         TOKEN_STRING_INITIALIZER
17692                 (struct cmd_ptype_mapping_get_result,
17693                  mapping, "mapping");
17694 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17695         TOKEN_STRING_INITIALIZER
17696                 (struct cmd_ptype_mapping_get_result,
17697                  get, "get");
17698 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17699         TOKEN_NUM_INITIALIZER
17700                 (struct cmd_ptype_mapping_get_result,
17701                  port_id, UINT16);
17702 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17703         TOKEN_NUM_INITIALIZER
17704                 (struct cmd_ptype_mapping_get_result,
17705                  valid_only, UINT8);
17706
17707 static void
17708 cmd_ptype_mapping_get_parsed(
17709         void *parsed_result,
17710         __rte_unused struct cmdline *cl,
17711         __rte_unused void *data)
17712 {
17713         struct cmd_ptype_mapping_get_result *res = parsed_result;
17714         int ret = -ENOTSUP;
17715 #ifdef RTE_LIBRTE_I40E_PMD
17716         int max_ptype_num = 256;
17717         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17718         uint16_t count;
17719         int i;
17720 #endif
17721
17722         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17723                 return;
17724
17725 #ifdef RTE_LIBRTE_I40E_PMD
17726         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17727                                         mapping,
17728                                         max_ptype_num,
17729                                         &count,
17730                                         res->valid_only);
17731 #endif
17732
17733         switch (ret) {
17734         case 0:
17735                 break;
17736         case -ENODEV:
17737                 printf("invalid port_id %d\n", res->port_id);
17738                 break;
17739         case -ENOTSUP:
17740                 printf("function not implemented\n");
17741                 break;
17742         default:
17743                 printf("programming error: (%s)\n", strerror(-ret));
17744         }
17745
17746 #ifdef RTE_LIBRTE_I40E_PMD
17747         if (!ret) {
17748                 for (i = 0; i < count; i++)
17749                         printf("%3d\t0x%08x\n",
17750                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17751         }
17752 #endif
17753 }
17754
17755 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17756         .f = cmd_ptype_mapping_get_parsed,
17757         .data = NULL,
17758         .help_str = "ptype mapping get <port_id> <valid_only>",
17759         .tokens = {
17760                 (void *)&cmd_ptype_mapping_get_ptype,
17761                 (void *)&cmd_ptype_mapping_get_mapping,
17762                 (void *)&cmd_ptype_mapping_get_get,
17763                 (void *)&cmd_ptype_mapping_get_port_id,
17764                 (void *)&cmd_ptype_mapping_get_valid_only,
17765                 NULL,
17766         },
17767 };
17768
17769 /* ptype mapping replace */
17770
17771 /* Common result structure for ptype mapping replace */
17772 struct cmd_ptype_mapping_replace_result {
17773         cmdline_fixed_string_t ptype;
17774         cmdline_fixed_string_t mapping;
17775         cmdline_fixed_string_t replace;
17776         portid_t port_id;
17777         uint32_t target;
17778         uint8_t mask;
17779         uint32_t pkt_type;
17780 };
17781
17782 /* Common CLI fields for ptype mapping replace */
17783 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17784         TOKEN_STRING_INITIALIZER
17785                 (struct cmd_ptype_mapping_replace_result,
17786                  ptype, "ptype");
17787 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17788         TOKEN_STRING_INITIALIZER
17789                 (struct cmd_ptype_mapping_replace_result,
17790                  mapping, "mapping");
17791 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17792         TOKEN_STRING_INITIALIZER
17793                 (struct cmd_ptype_mapping_replace_result,
17794                  replace, "replace");
17795 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17796         TOKEN_NUM_INITIALIZER
17797                 (struct cmd_ptype_mapping_replace_result,
17798                  port_id, UINT16);
17799 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17800         TOKEN_NUM_INITIALIZER
17801                 (struct cmd_ptype_mapping_replace_result,
17802                  target, UINT32);
17803 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17804         TOKEN_NUM_INITIALIZER
17805                 (struct cmd_ptype_mapping_replace_result,
17806                  mask, UINT8);
17807 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17808         TOKEN_NUM_INITIALIZER
17809                 (struct cmd_ptype_mapping_replace_result,
17810                  pkt_type, UINT32);
17811
17812 static void
17813 cmd_ptype_mapping_replace_parsed(
17814         void *parsed_result,
17815         __rte_unused struct cmdline *cl,
17816         __rte_unused void *data)
17817 {
17818         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17819         int ret = -ENOTSUP;
17820
17821         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17822                 return;
17823
17824 #ifdef RTE_LIBRTE_I40E_PMD
17825         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17826                                         res->target,
17827                                         res->mask,
17828                                         res->pkt_type);
17829 #endif
17830
17831         switch (ret) {
17832         case 0:
17833                 break;
17834         case -EINVAL:
17835                 printf("invalid ptype 0x%8x or 0x%8x\n",
17836                                 res->target, res->pkt_type);
17837                 break;
17838         case -ENODEV:
17839                 printf("invalid port_id %d\n", res->port_id);
17840                 break;
17841         case -ENOTSUP:
17842                 printf("function not implemented\n");
17843                 break;
17844         default:
17845                 printf("programming error: (%s)\n", strerror(-ret));
17846         }
17847 }
17848
17849 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17850         .f = cmd_ptype_mapping_replace_parsed,
17851         .data = NULL,
17852         .help_str =
17853                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17854         .tokens = {
17855                 (void *)&cmd_ptype_mapping_replace_ptype,
17856                 (void *)&cmd_ptype_mapping_replace_mapping,
17857                 (void *)&cmd_ptype_mapping_replace_replace,
17858                 (void *)&cmd_ptype_mapping_replace_port_id,
17859                 (void *)&cmd_ptype_mapping_replace_target,
17860                 (void *)&cmd_ptype_mapping_replace_mask,
17861                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17862                 NULL,
17863         },
17864 };
17865
17866 /* ptype mapping reset */
17867
17868 /* Common result structure for ptype mapping reset */
17869 struct cmd_ptype_mapping_reset_result {
17870         cmdline_fixed_string_t ptype;
17871         cmdline_fixed_string_t mapping;
17872         cmdline_fixed_string_t reset;
17873         portid_t port_id;
17874 };
17875
17876 /* Common CLI fields for ptype mapping reset*/
17877 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17878         TOKEN_STRING_INITIALIZER
17879                 (struct cmd_ptype_mapping_reset_result,
17880                  ptype, "ptype");
17881 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17882         TOKEN_STRING_INITIALIZER
17883                 (struct cmd_ptype_mapping_reset_result,
17884                  mapping, "mapping");
17885 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17886         TOKEN_STRING_INITIALIZER
17887                 (struct cmd_ptype_mapping_reset_result,
17888                  reset, "reset");
17889 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17890         TOKEN_NUM_INITIALIZER
17891                 (struct cmd_ptype_mapping_reset_result,
17892                  port_id, UINT16);
17893
17894 static void
17895 cmd_ptype_mapping_reset_parsed(
17896         void *parsed_result,
17897         __rte_unused struct cmdline *cl,
17898         __rte_unused void *data)
17899 {
17900         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17901         int ret = -ENOTSUP;
17902
17903         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17904                 return;
17905
17906 #ifdef RTE_LIBRTE_I40E_PMD
17907         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17908 #endif
17909
17910         switch (ret) {
17911         case 0:
17912                 break;
17913         case -ENODEV:
17914                 printf("invalid port_id %d\n", res->port_id);
17915                 break;
17916         case -ENOTSUP:
17917                 printf("function not implemented\n");
17918                 break;
17919         default:
17920                 printf("programming error: (%s)\n", strerror(-ret));
17921         }
17922 }
17923
17924 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17925         .f = cmd_ptype_mapping_reset_parsed,
17926         .data = NULL,
17927         .help_str = "ptype mapping reset <port_id>",
17928         .tokens = {
17929                 (void *)&cmd_ptype_mapping_reset_ptype,
17930                 (void *)&cmd_ptype_mapping_reset_mapping,
17931                 (void *)&cmd_ptype_mapping_reset_reset,
17932                 (void *)&cmd_ptype_mapping_reset_port_id,
17933                 NULL,
17934         },
17935 };
17936
17937 /* ptype mapping update */
17938
17939 /* Common result structure for ptype mapping update */
17940 struct cmd_ptype_mapping_update_result {
17941         cmdline_fixed_string_t ptype;
17942         cmdline_fixed_string_t mapping;
17943         cmdline_fixed_string_t reset;
17944         portid_t port_id;
17945         uint8_t hw_ptype;
17946         uint32_t sw_ptype;
17947 };
17948
17949 /* Common CLI fields for ptype mapping update*/
17950 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17951         TOKEN_STRING_INITIALIZER
17952                 (struct cmd_ptype_mapping_update_result,
17953                  ptype, "ptype");
17954 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17955         TOKEN_STRING_INITIALIZER
17956                 (struct cmd_ptype_mapping_update_result,
17957                  mapping, "mapping");
17958 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17959         TOKEN_STRING_INITIALIZER
17960                 (struct cmd_ptype_mapping_update_result,
17961                  reset, "update");
17962 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17963         TOKEN_NUM_INITIALIZER
17964                 (struct cmd_ptype_mapping_update_result,
17965                  port_id, UINT16);
17966 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17967         TOKEN_NUM_INITIALIZER
17968                 (struct cmd_ptype_mapping_update_result,
17969                  hw_ptype, UINT8);
17970 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17971         TOKEN_NUM_INITIALIZER
17972                 (struct cmd_ptype_mapping_update_result,
17973                  sw_ptype, UINT32);
17974
17975 static void
17976 cmd_ptype_mapping_update_parsed(
17977         void *parsed_result,
17978         __rte_unused struct cmdline *cl,
17979         __rte_unused void *data)
17980 {
17981         struct cmd_ptype_mapping_update_result *res = parsed_result;
17982         int ret = -ENOTSUP;
17983 #ifdef RTE_LIBRTE_I40E_PMD
17984         struct rte_pmd_i40e_ptype_mapping mapping;
17985 #endif
17986         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17987                 return;
17988
17989 #ifdef RTE_LIBRTE_I40E_PMD
17990         mapping.hw_ptype = res->hw_ptype;
17991         mapping.sw_ptype = res->sw_ptype;
17992         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17993                                                 &mapping,
17994                                                 1,
17995                                                 0);
17996 #endif
17997
17998         switch (ret) {
17999         case 0:
18000                 break;
18001         case -EINVAL:
18002                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18003                 break;
18004         case -ENODEV:
18005                 printf("invalid port_id %d\n", res->port_id);
18006                 break;
18007         case -ENOTSUP:
18008                 printf("function not implemented\n");
18009                 break;
18010         default:
18011                 printf("programming error: (%s)\n", strerror(-ret));
18012         }
18013 }
18014
18015 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18016         .f = cmd_ptype_mapping_update_parsed,
18017         .data = NULL,
18018         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18019         .tokens = {
18020                 (void *)&cmd_ptype_mapping_update_ptype,
18021                 (void *)&cmd_ptype_mapping_update_mapping,
18022                 (void *)&cmd_ptype_mapping_update_update,
18023                 (void *)&cmd_ptype_mapping_update_port_id,
18024                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18025                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18026                 NULL,
18027         },
18028 };
18029
18030 /* Common result structure for file commands */
18031 struct cmd_cmdfile_result {
18032         cmdline_fixed_string_t load;
18033         cmdline_fixed_string_t filename;
18034 };
18035
18036 /* Common CLI fields for file commands */
18037 cmdline_parse_token_string_t cmd_load_cmdfile =
18038         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18039 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18040         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18041
18042 static void
18043 cmd_load_from_file_parsed(
18044         void *parsed_result,
18045         __rte_unused struct cmdline *cl,
18046         __rte_unused void *data)
18047 {
18048         struct cmd_cmdfile_result *res = parsed_result;
18049
18050         cmdline_read_from_file(res->filename);
18051 }
18052
18053 cmdline_parse_inst_t cmd_load_from_file = {
18054         .f = cmd_load_from_file_parsed,
18055         .data = NULL,
18056         .help_str = "load <filename>",
18057         .tokens = {
18058                 (void *)&cmd_load_cmdfile,
18059                 (void *)&cmd_load_cmdfile_filename,
18060                 NULL,
18061         },
18062 };
18063
18064 /* Get Rx offloads capabilities */
18065 struct cmd_rx_offload_get_capa_result {
18066         cmdline_fixed_string_t show;
18067         cmdline_fixed_string_t port;
18068         portid_t port_id;
18069         cmdline_fixed_string_t rx_offload;
18070         cmdline_fixed_string_t capabilities;
18071 };
18072
18073 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18074         TOKEN_STRING_INITIALIZER
18075                 (struct cmd_rx_offload_get_capa_result,
18076                  show, "show");
18077 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18078         TOKEN_STRING_INITIALIZER
18079                 (struct cmd_rx_offload_get_capa_result,
18080                  port, "port");
18081 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18082         TOKEN_NUM_INITIALIZER
18083                 (struct cmd_rx_offload_get_capa_result,
18084                  port_id, UINT16);
18085 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18086         TOKEN_STRING_INITIALIZER
18087                 (struct cmd_rx_offload_get_capa_result,
18088                  rx_offload, "rx_offload");
18089 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18090         TOKEN_STRING_INITIALIZER
18091                 (struct cmd_rx_offload_get_capa_result,
18092                  capabilities, "capabilities");
18093
18094 static void
18095 print_rx_offloads(uint64_t offloads)
18096 {
18097         uint64_t single_offload;
18098         int begin;
18099         int end;
18100         int bit;
18101
18102         if (offloads == 0)
18103                 return;
18104
18105         begin = __builtin_ctzll(offloads);
18106         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18107
18108         single_offload = 1ULL << begin;
18109         for (bit = begin; bit < end; bit++) {
18110                 if (offloads & single_offload)
18111                         printf(" %s",
18112                                rte_eth_dev_rx_offload_name(single_offload));
18113                 single_offload <<= 1;
18114         }
18115 }
18116
18117 static void
18118 cmd_rx_offload_get_capa_parsed(
18119         void *parsed_result,
18120         __rte_unused struct cmdline *cl,
18121         __rte_unused void *data)
18122 {
18123         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18124         struct rte_eth_dev_info dev_info;
18125         portid_t port_id = res->port_id;
18126         uint64_t queue_offloads;
18127         uint64_t port_offloads;
18128         int ret;
18129
18130         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18131         if (ret != 0)
18132                 return;
18133
18134         queue_offloads = dev_info.rx_queue_offload_capa;
18135         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18136
18137         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18138         printf("  Per Queue :");
18139         print_rx_offloads(queue_offloads);
18140
18141         printf("\n");
18142         printf("  Per Port  :");
18143         print_rx_offloads(port_offloads);
18144         printf("\n\n");
18145 }
18146
18147 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18148         .f = cmd_rx_offload_get_capa_parsed,
18149         .data = NULL,
18150         .help_str = "show port <port_id> rx_offload capabilities",
18151         .tokens = {
18152                 (void *)&cmd_rx_offload_get_capa_show,
18153                 (void *)&cmd_rx_offload_get_capa_port,
18154                 (void *)&cmd_rx_offload_get_capa_port_id,
18155                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18156                 (void *)&cmd_rx_offload_get_capa_capabilities,
18157                 NULL,
18158         }
18159 };
18160
18161 /* Get Rx offloads configuration */
18162 struct cmd_rx_offload_get_configuration_result {
18163         cmdline_fixed_string_t show;
18164         cmdline_fixed_string_t port;
18165         portid_t port_id;
18166         cmdline_fixed_string_t rx_offload;
18167         cmdline_fixed_string_t configuration;
18168 };
18169
18170 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18171         TOKEN_STRING_INITIALIZER
18172                 (struct cmd_rx_offload_get_configuration_result,
18173                  show, "show");
18174 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18175         TOKEN_STRING_INITIALIZER
18176                 (struct cmd_rx_offload_get_configuration_result,
18177                  port, "port");
18178 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18179         TOKEN_NUM_INITIALIZER
18180                 (struct cmd_rx_offload_get_configuration_result,
18181                  port_id, UINT16);
18182 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18183         TOKEN_STRING_INITIALIZER
18184                 (struct cmd_rx_offload_get_configuration_result,
18185                  rx_offload, "rx_offload");
18186 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18187         TOKEN_STRING_INITIALIZER
18188                 (struct cmd_rx_offload_get_configuration_result,
18189                  configuration, "configuration");
18190
18191 static void
18192 cmd_rx_offload_get_configuration_parsed(
18193         void *parsed_result,
18194         __rte_unused struct cmdline *cl,
18195         __rte_unused void *data)
18196 {
18197         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18198         struct rte_eth_dev_info dev_info;
18199         portid_t port_id = res->port_id;
18200         struct rte_port *port = &ports[port_id];
18201         uint64_t port_offloads;
18202         uint64_t queue_offloads;
18203         uint16_t nb_rx_queues;
18204         int q;
18205         int ret;
18206
18207         printf("Rx Offloading Configuration of port %d :\n", port_id);
18208
18209         port_offloads = port->dev_conf.rxmode.offloads;
18210         printf("  Port :");
18211         print_rx_offloads(port_offloads);
18212         printf("\n");
18213
18214         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18215         if (ret != 0)
18216                 return;
18217
18218         nb_rx_queues = dev_info.nb_rx_queues;
18219         for (q = 0; q < nb_rx_queues; q++) {
18220                 queue_offloads = port->rx_conf[q].offloads;
18221                 printf("  Queue[%2d] :", q);
18222                 print_rx_offloads(queue_offloads);
18223                 printf("\n");
18224         }
18225         printf("\n");
18226 }
18227
18228 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18229         .f = cmd_rx_offload_get_configuration_parsed,
18230         .data = NULL,
18231         .help_str = "show port <port_id> rx_offload configuration",
18232         .tokens = {
18233                 (void *)&cmd_rx_offload_get_configuration_show,
18234                 (void *)&cmd_rx_offload_get_configuration_port,
18235                 (void *)&cmd_rx_offload_get_configuration_port_id,
18236                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18237                 (void *)&cmd_rx_offload_get_configuration_configuration,
18238                 NULL,
18239         }
18240 };
18241
18242 /* Enable/Disable a per port offloading */
18243 struct cmd_config_per_port_rx_offload_result {
18244         cmdline_fixed_string_t port;
18245         cmdline_fixed_string_t config;
18246         portid_t port_id;
18247         cmdline_fixed_string_t rx_offload;
18248         cmdline_fixed_string_t offload;
18249         cmdline_fixed_string_t on_off;
18250 };
18251
18252 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18253         TOKEN_STRING_INITIALIZER
18254                 (struct cmd_config_per_port_rx_offload_result,
18255                  port, "port");
18256 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18257         TOKEN_STRING_INITIALIZER
18258                 (struct cmd_config_per_port_rx_offload_result,
18259                  config, "config");
18260 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18261         TOKEN_NUM_INITIALIZER
18262                 (struct cmd_config_per_port_rx_offload_result,
18263                  port_id, UINT16);
18264 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18265         TOKEN_STRING_INITIALIZER
18266                 (struct cmd_config_per_port_rx_offload_result,
18267                  rx_offload, "rx_offload");
18268 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18269         TOKEN_STRING_INITIALIZER
18270                 (struct cmd_config_per_port_rx_offload_result,
18271                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18272                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18273                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18274                            "scatter#timestamp#security#keep_crc#rss_hash");
18275 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18276         TOKEN_STRING_INITIALIZER
18277                 (struct cmd_config_per_port_rx_offload_result,
18278                  on_off, "on#off");
18279
18280 static uint64_t
18281 search_rx_offload(const char *name)
18282 {
18283         uint64_t single_offload;
18284         const char *single_name;
18285         int found = 0;
18286         unsigned int bit;
18287
18288         single_offload = 1;
18289         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18290                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18291                 if (!strcasecmp(single_name, name)) {
18292                         found = 1;
18293                         break;
18294                 }
18295                 single_offload <<= 1;
18296         }
18297
18298         if (found)
18299                 return single_offload;
18300
18301         return 0;
18302 }
18303
18304 static void
18305 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18306                                 __rte_unused struct cmdline *cl,
18307                                 __rte_unused void *data)
18308 {
18309         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18310         portid_t port_id = res->port_id;
18311         struct rte_eth_dev_info dev_info;
18312         struct rte_port *port = &ports[port_id];
18313         uint64_t single_offload;
18314         uint16_t nb_rx_queues;
18315         int q;
18316         int ret;
18317
18318         if (port->port_status != RTE_PORT_STOPPED) {
18319                 printf("Error: Can't config offload when Port %d "
18320                        "is not stopped\n", port_id);
18321                 return;
18322         }
18323
18324         single_offload = search_rx_offload(res->offload);
18325         if (single_offload == 0) {
18326                 printf("Unknown offload name: %s\n", res->offload);
18327                 return;
18328         }
18329
18330         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18331         if (ret != 0)
18332                 return;
18333
18334         nb_rx_queues = dev_info.nb_rx_queues;
18335         if (!strcmp(res->on_off, "on")) {
18336                 port->dev_conf.rxmode.offloads |= single_offload;
18337                 for (q = 0; q < nb_rx_queues; q++)
18338                         port->rx_conf[q].offloads |= single_offload;
18339         } else {
18340                 port->dev_conf.rxmode.offloads &= ~single_offload;
18341                 for (q = 0; q < nb_rx_queues; q++)
18342                         port->rx_conf[q].offloads &= ~single_offload;
18343         }
18344
18345         cmd_reconfig_device_queue(port_id, 1, 1);
18346 }
18347
18348 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18349         .f = cmd_config_per_port_rx_offload_parsed,
18350         .data = NULL,
18351         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18352                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18353                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18354                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18355                     "on|off",
18356         .tokens = {
18357                 (void *)&cmd_config_per_port_rx_offload_result_port,
18358                 (void *)&cmd_config_per_port_rx_offload_result_config,
18359                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18360                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18361                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18362                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18363                 NULL,
18364         }
18365 };
18366
18367 /* Enable/Disable a per queue offloading */
18368 struct cmd_config_per_queue_rx_offload_result {
18369         cmdline_fixed_string_t port;
18370         portid_t port_id;
18371         cmdline_fixed_string_t rxq;
18372         uint16_t queue_id;
18373         cmdline_fixed_string_t rx_offload;
18374         cmdline_fixed_string_t offload;
18375         cmdline_fixed_string_t on_off;
18376 };
18377
18378 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18379         TOKEN_STRING_INITIALIZER
18380                 (struct cmd_config_per_queue_rx_offload_result,
18381                  port, "port");
18382 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18383         TOKEN_NUM_INITIALIZER
18384                 (struct cmd_config_per_queue_rx_offload_result,
18385                  port_id, UINT16);
18386 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18387         TOKEN_STRING_INITIALIZER
18388                 (struct cmd_config_per_queue_rx_offload_result,
18389                  rxq, "rxq");
18390 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18391         TOKEN_NUM_INITIALIZER
18392                 (struct cmd_config_per_queue_rx_offload_result,
18393                  queue_id, UINT16);
18394 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18395         TOKEN_STRING_INITIALIZER
18396                 (struct cmd_config_per_queue_rx_offload_result,
18397                  rx_offload, "rx_offload");
18398 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18399         TOKEN_STRING_INITIALIZER
18400                 (struct cmd_config_per_queue_rx_offload_result,
18401                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18402                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18403                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18404                            "scatter#timestamp#security#keep_crc");
18405 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18406         TOKEN_STRING_INITIALIZER
18407                 (struct cmd_config_per_queue_rx_offload_result,
18408                  on_off, "on#off");
18409
18410 static void
18411 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18412                                 __rte_unused struct cmdline *cl,
18413                                 __rte_unused void *data)
18414 {
18415         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18416         struct rte_eth_dev_info dev_info;
18417         portid_t port_id = res->port_id;
18418         uint16_t queue_id = res->queue_id;
18419         struct rte_port *port = &ports[port_id];
18420         uint64_t single_offload;
18421         int ret;
18422
18423         if (port->port_status != RTE_PORT_STOPPED) {
18424                 printf("Error: Can't config offload when Port %d "
18425                        "is not stopped\n", port_id);
18426                 return;
18427         }
18428
18429         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18430         if (ret != 0)
18431                 return;
18432
18433         if (queue_id >= dev_info.nb_rx_queues) {
18434                 printf("Error: input queue_id should be 0 ... "
18435                        "%d\n", dev_info.nb_rx_queues - 1);
18436                 return;
18437         }
18438
18439         single_offload = search_rx_offload(res->offload);
18440         if (single_offload == 0) {
18441                 printf("Unknown offload name: %s\n", res->offload);
18442                 return;
18443         }
18444
18445         if (!strcmp(res->on_off, "on"))
18446                 port->rx_conf[queue_id].offloads |= single_offload;
18447         else
18448                 port->rx_conf[queue_id].offloads &= ~single_offload;
18449
18450         cmd_reconfig_device_queue(port_id, 1, 1);
18451 }
18452
18453 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18454         .f = cmd_config_per_queue_rx_offload_parsed,
18455         .data = NULL,
18456         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18457                     "vlan_strip|ipv4_cksum|"
18458                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18459                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18460                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18461                     "on|off",
18462         .tokens = {
18463                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18464                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18465                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18466                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18467                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18468                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18469                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18470                 NULL,
18471         }
18472 };
18473
18474 /* Get Tx offloads capabilities */
18475 struct cmd_tx_offload_get_capa_result {
18476         cmdline_fixed_string_t show;
18477         cmdline_fixed_string_t port;
18478         portid_t port_id;
18479         cmdline_fixed_string_t tx_offload;
18480         cmdline_fixed_string_t capabilities;
18481 };
18482
18483 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18484         TOKEN_STRING_INITIALIZER
18485                 (struct cmd_tx_offload_get_capa_result,
18486                  show, "show");
18487 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18488         TOKEN_STRING_INITIALIZER
18489                 (struct cmd_tx_offload_get_capa_result,
18490                  port, "port");
18491 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18492         TOKEN_NUM_INITIALIZER
18493                 (struct cmd_tx_offload_get_capa_result,
18494                  port_id, UINT16);
18495 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18496         TOKEN_STRING_INITIALIZER
18497                 (struct cmd_tx_offload_get_capa_result,
18498                  tx_offload, "tx_offload");
18499 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18500         TOKEN_STRING_INITIALIZER
18501                 (struct cmd_tx_offload_get_capa_result,
18502                  capabilities, "capabilities");
18503
18504 static void
18505 print_tx_offloads(uint64_t offloads)
18506 {
18507         uint64_t single_offload;
18508         int begin;
18509         int end;
18510         int bit;
18511
18512         if (offloads == 0)
18513                 return;
18514
18515         begin = __builtin_ctzll(offloads);
18516         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18517
18518         single_offload = 1ULL << begin;
18519         for (bit = begin; bit < end; bit++) {
18520                 if (offloads & single_offload)
18521                         printf(" %s",
18522                                rte_eth_dev_tx_offload_name(single_offload));
18523                 single_offload <<= 1;
18524         }
18525 }
18526
18527 static void
18528 cmd_tx_offload_get_capa_parsed(
18529         void *parsed_result,
18530         __rte_unused struct cmdline *cl,
18531         __rte_unused void *data)
18532 {
18533         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18534         struct rte_eth_dev_info dev_info;
18535         portid_t port_id = res->port_id;
18536         uint64_t queue_offloads;
18537         uint64_t port_offloads;
18538         int ret;
18539
18540         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18541         if (ret != 0)
18542                 return;
18543
18544         queue_offloads = dev_info.tx_queue_offload_capa;
18545         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18546
18547         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18548         printf("  Per Queue :");
18549         print_tx_offloads(queue_offloads);
18550
18551         printf("\n");
18552         printf("  Per Port  :");
18553         print_tx_offloads(port_offloads);
18554         printf("\n\n");
18555 }
18556
18557 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18558         .f = cmd_tx_offload_get_capa_parsed,
18559         .data = NULL,
18560         .help_str = "show port <port_id> tx_offload capabilities",
18561         .tokens = {
18562                 (void *)&cmd_tx_offload_get_capa_show,
18563                 (void *)&cmd_tx_offload_get_capa_port,
18564                 (void *)&cmd_tx_offload_get_capa_port_id,
18565                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18566                 (void *)&cmd_tx_offload_get_capa_capabilities,
18567                 NULL,
18568         }
18569 };
18570
18571 /* Get Tx offloads configuration */
18572 struct cmd_tx_offload_get_configuration_result {
18573         cmdline_fixed_string_t show;
18574         cmdline_fixed_string_t port;
18575         portid_t port_id;
18576         cmdline_fixed_string_t tx_offload;
18577         cmdline_fixed_string_t configuration;
18578 };
18579
18580 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18581         TOKEN_STRING_INITIALIZER
18582                 (struct cmd_tx_offload_get_configuration_result,
18583                  show, "show");
18584 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18585         TOKEN_STRING_INITIALIZER
18586                 (struct cmd_tx_offload_get_configuration_result,
18587                  port, "port");
18588 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18589         TOKEN_NUM_INITIALIZER
18590                 (struct cmd_tx_offload_get_configuration_result,
18591                  port_id, UINT16);
18592 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18593         TOKEN_STRING_INITIALIZER
18594                 (struct cmd_tx_offload_get_configuration_result,
18595                  tx_offload, "tx_offload");
18596 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18597         TOKEN_STRING_INITIALIZER
18598                 (struct cmd_tx_offload_get_configuration_result,
18599                  configuration, "configuration");
18600
18601 static void
18602 cmd_tx_offload_get_configuration_parsed(
18603         void *parsed_result,
18604         __rte_unused struct cmdline *cl,
18605         __rte_unused void *data)
18606 {
18607         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18608         struct rte_eth_dev_info dev_info;
18609         portid_t port_id = res->port_id;
18610         struct rte_port *port = &ports[port_id];
18611         uint64_t port_offloads;
18612         uint64_t queue_offloads;
18613         uint16_t nb_tx_queues;
18614         int q;
18615         int ret;
18616
18617         printf("Tx Offloading Configuration of port %d :\n", port_id);
18618
18619         port_offloads = port->dev_conf.txmode.offloads;
18620         printf("  Port :");
18621         print_tx_offloads(port_offloads);
18622         printf("\n");
18623
18624         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18625         if (ret != 0)
18626                 return;
18627
18628         nb_tx_queues = dev_info.nb_tx_queues;
18629         for (q = 0; q < nb_tx_queues; q++) {
18630                 queue_offloads = port->tx_conf[q].offloads;
18631                 printf("  Queue[%2d] :", q);
18632                 print_tx_offloads(queue_offloads);
18633                 printf("\n");
18634         }
18635         printf("\n");
18636 }
18637
18638 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18639         .f = cmd_tx_offload_get_configuration_parsed,
18640         .data = NULL,
18641         .help_str = "show port <port_id> tx_offload configuration",
18642         .tokens = {
18643                 (void *)&cmd_tx_offload_get_configuration_show,
18644                 (void *)&cmd_tx_offload_get_configuration_port,
18645                 (void *)&cmd_tx_offload_get_configuration_port_id,
18646                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18647                 (void *)&cmd_tx_offload_get_configuration_configuration,
18648                 NULL,
18649         }
18650 };
18651
18652 /* Enable/Disable a per port offloading */
18653 struct cmd_config_per_port_tx_offload_result {
18654         cmdline_fixed_string_t port;
18655         cmdline_fixed_string_t config;
18656         portid_t port_id;
18657         cmdline_fixed_string_t tx_offload;
18658         cmdline_fixed_string_t offload;
18659         cmdline_fixed_string_t on_off;
18660 };
18661
18662 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18663         TOKEN_STRING_INITIALIZER
18664                 (struct cmd_config_per_port_tx_offload_result,
18665                  port, "port");
18666 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18667         TOKEN_STRING_INITIALIZER
18668                 (struct cmd_config_per_port_tx_offload_result,
18669                  config, "config");
18670 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18671         TOKEN_NUM_INITIALIZER
18672                 (struct cmd_config_per_port_tx_offload_result,
18673                  port_id, UINT16);
18674 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18675         TOKEN_STRING_INITIALIZER
18676                 (struct cmd_config_per_port_tx_offload_result,
18677                  tx_offload, "tx_offload");
18678 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18679         TOKEN_STRING_INITIALIZER
18680                 (struct cmd_config_per_port_tx_offload_result,
18681                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18682                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18683                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18684                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18685                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18686 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18687         TOKEN_STRING_INITIALIZER
18688                 (struct cmd_config_per_port_tx_offload_result,
18689                  on_off, "on#off");
18690
18691 static uint64_t
18692 search_tx_offload(const char *name)
18693 {
18694         uint64_t single_offload;
18695         const char *single_name;
18696         int found = 0;
18697         unsigned int bit;
18698
18699         single_offload = 1;
18700         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18701                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18702                 if (single_name == NULL)
18703                         break;
18704                 if (!strcasecmp(single_name, name)) {
18705                         found = 1;
18706                         break;
18707                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18708                         break;
18709                 single_offload <<= 1;
18710         }
18711
18712         if (found)
18713                 return single_offload;
18714
18715         return 0;
18716 }
18717
18718 static void
18719 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18720                                 __rte_unused struct cmdline *cl,
18721                                 __rte_unused void *data)
18722 {
18723         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18724         portid_t port_id = res->port_id;
18725         struct rte_eth_dev_info dev_info;
18726         struct rte_port *port = &ports[port_id];
18727         uint64_t single_offload;
18728         uint16_t nb_tx_queues;
18729         int q;
18730         int ret;
18731
18732         if (port->port_status != RTE_PORT_STOPPED) {
18733                 printf("Error: Can't config offload when Port %d "
18734                        "is not stopped\n", port_id);
18735                 return;
18736         }
18737
18738         single_offload = search_tx_offload(res->offload);
18739         if (single_offload == 0) {
18740                 printf("Unknown offload name: %s\n", res->offload);
18741                 return;
18742         }
18743
18744         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18745         if (ret != 0)
18746                 return;
18747
18748         nb_tx_queues = dev_info.nb_tx_queues;
18749         if (!strcmp(res->on_off, "on")) {
18750                 port->dev_conf.txmode.offloads |= single_offload;
18751                 for (q = 0; q < nb_tx_queues; q++)
18752                         port->tx_conf[q].offloads |= single_offload;
18753         } else {
18754                 port->dev_conf.txmode.offloads &= ~single_offload;
18755                 for (q = 0; q < nb_tx_queues; q++)
18756                         port->tx_conf[q].offloads &= ~single_offload;
18757         }
18758
18759         cmd_reconfig_device_queue(port_id, 1, 1);
18760 }
18761
18762 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18763         .f = cmd_config_per_port_tx_offload_parsed,
18764         .data = NULL,
18765         .help_str = "port config <port_id> tx_offload "
18766                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18767                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18768                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18769                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18770                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18771         .tokens = {
18772                 (void *)&cmd_config_per_port_tx_offload_result_port,
18773                 (void *)&cmd_config_per_port_tx_offload_result_config,
18774                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18775                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18776                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18777                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18778                 NULL,
18779         }
18780 };
18781
18782 /* Enable/Disable a per queue offloading */
18783 struct cmd_config_per_queue_tx_offload_result {
18784         cmdline_fixed_string_t port;
18785         portid_t port_id;
18786         cmdline_fixed_string_t txq;
18787         uint16_t queue_id;
18788         cmdline_fixed_string_t tx_offload;
18789         cmdline_fixed_string_t offload;
18790         cmdline_fixed_string_t on_off;
18791 };
18792
18793 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18794         TOKEN_STRING_INITIALIZER
18795                 (struct cmd_config_per_queue_tx_offload_result,
18796                  port, "port");
18797 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18798         TOKEN_NUM_INITIALIZER
18799                 (struct cmd_config_per_queue_tx_offload_result,
18800                  port_id, UINT16);
18801 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18802         TOKEN_STRING_INITIALIZER
18803                 (struct cmd_config_per_queue_tx_offload_result,
18804                  txq, "txq");
18805 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18806         TOKEN_NUM_INITIALIZER
18807                 (struct cmd_config_per_queue_tx_offload_result,
18808                  queue_id, UINT16);
18809 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18810         TOKEN_STRING_INITIALIZER
18811                 (struct cmd_config_per_queue_tx_offload_result,
18812                  tx_offload, "tx_offload");
18813 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18814         TOKEN_STRING_INITIALIZER
18815                 (struct cmd_config_per_queue_tx_offload_result,
18816                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18817                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18818                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18819                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18820                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18821 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18822         TOKEN_STRING_INITIALIZER
18823                 (struct cmd_config_per_queue_tx_offload_result,
18824                  on_off, "on#off");
18825
18826 static void
18827 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18828                                 __rte_unused struct cmdline *cl,
18829                                 __rte_unused void *data)
18830 {
18831         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18832         struct rte_eth_dev_info dev_info;
18833         portid_t port_id = res->port_id;
18834         uint16_t queue_id = res->queue_id;
18835         struct rte_port *port = &ports[port_id];
18836         uint64_t single_offload;
18837         int ret;
18838
18839         if (port->port_status != RTE_PORT_STOPPED) {
18840                 printf("Error: Can't config offload when Port %d "
18841                        "is not stopped\n", port_id);
18842                 return;
18843         }
18844
18845         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18846         if (ret != 0)
18847                 return;
18848
18849         if (queue_id >= dev_info.nb_tx_queues) {
18850                 printf("Error: input queue_id should be 0 ... "
18851                        "%d\n", dev_info.nb_tx_queues - 1);
18852                 return;
18853         }
18854
18855         single_offload = search_tx_offload(res->offload);
18856         if (single_offload == 0) {
18857                 printf("Unknown offload name: %s\n", res->offload);
18858                 return;
18859         }
18860
18861         if (!strcmp(res->on_off, "on"))
18862                 port->tx_conf[queue_id].offloads |= single_offload;
18863         else
18864                 port->tx_conf[queue_id].offloads &= ~single_offload;
18865
18866         cmd_reconfig_device_queue(port_id, 1, 1);
18867 }
18868
18869 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18870         .f = cmd_config_per_queue_tx_offload_parsed,
18871         .data = NULL,
18872         .help_str = "port <port_id> txq <queue_id> tx_offload "
18873                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18874                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18875                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18876                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18877                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18878                     "on|off",
18879         .tokens = {
18880                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18881                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18882                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18883                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18884                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18885                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18886                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18887                 NULL,
18888         }
18889 };
18890
18891 /* *** configure tx_metadata for specific port *** */
18892 struct cmd_config_tx_metadata_specific_result {
18893         cmdline_fixed_string_t port;
18894         cmdline_fixed_string_t keyword;
18895         uint16_t port_id;
18896         cmdline_fixed_string_t item;
18897         uint32_t value;
18898 };
18899
18900 static void
18901 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18902                                 __rte_unused struct cmdline *cl,
18903                                 __rte_unused void *data)
18904 {
18905         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18906
18907         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18908                 return;
18909         ports[res->port_id].tx_metadata = res->value;
18910         /* Add/remove callback to insert valid metadata in every Tx packet. */
18911         if (ports[res->port_id].tx_metadata)
18912                 add_tx_md_callback(res->port_id);
18913         else
18914                 remove_tx_md_callback(res->port_id);
18915         rte_flow_dynf_metadata_register();
18916 }
18917
18918 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18919         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18920                         port, "port");
18921 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18922         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18923                         keyword, "config");
18924 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18925         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18926                         port_id, UINT16);
18927 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18928         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18929                         item, "tx_metadata");
18930 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18931         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18932                         value, UINT32);
18933
18934 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18935         .f = cmd_config_tx_metadata_specific_parsed,
18936         .data = NULL,
18937         .help_str = "port config <port_id> tx_metadata <value>",
18938         .tokens = {
18939                 (void *)&cmd_config_tx_metadata_specific_port,
18940                 (void *)&cmd_config_tx_metadata_specific_keyword,
18941                 (void *)&cmd_config_tx_metadata_specific_id,
18942                 (void *)&cmd_config_tx_metadata_specific_item,
18943                 (void *)&cmd_config_tx_metadata_specific_value,
18944                 NULL,
18945         },
18946 };
18947
18948 /* *** set dynf *** */
18949 struct cmd_config_tx_dynf_specific_result {
18950         cmdline_fixed_string_t port;
18951         cmdline_fixed_string_t keyword;
18952         uint16_t port_id;
18953         cmdline_fixed_string_t item;
18954         cmdline_fixed_string_t name;
18955         cmdline_fixed_string_t value;
18956 };
18957
18958 static void
18959 cmd_config_dynf_specific_parsed(void *parsed_result,
18960                                 __rte_unused struct cmdline *cl,
18961                                 __rte_unused void *data)
18962 {
18963         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18964         struct rte_mbuf_dynflag desc_flag;
18965         int flag;
18966         uint64_t old_port_flags;
18967
18968         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18969                 return;
18970         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18971         if (flag <= 0) {
18972                 if (strlcpy(desc_flag.name, res->name,
18973                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18974                         printf("Flag name too long\n");
18975                         return;
18976                 }
18977                 desc_flag.flags = 0;
18978                 flag = rte_mbuf_dynflag_register(&desc_flag);
18979                 if (flag < 0) {
18980                         printf("Can't register flag\n");
18981                         return;
18982                 }
18983                 strcpy(dynf_names[flag], desc_flag.name);
18984         }
18985         old_port_flags = ports[res->port_id].mbuf_dynf;
18986         if (!strcmp(res->value, "set")) {
18987                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18988                 if (old_port_flags == 0)
18989                         add_tx_dynf_callback(res->port_id);
18990         } else {
18991                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18992                 if (ports[res->port_id].mbuf_dynf == 0)
18993                         remove_tx_dynf_callback(res->port_id);
18994         }
18995 }
18996
18997 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18998         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18999                         keyword, "port");
19000 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19001         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19002                         keyword, "config");
19003 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19004         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19005                         port_id, UINT16);
19006 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19007         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19008                         item, "dynf");
19009 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19010         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19011                         name, NULL);
19012 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19013         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19014                         value, "set#clear");
19015
19016 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19017         .f = cmd_config_dynf_specific_parsed,
19018         .data = NULL,
19019         .help_str = "port config <port id> dynf <name> set|clear",
19020         .tokens = {
19021                 (void *)&cmd_config_tx_dynf_specific_port,
19022                 (void *)&cmd_config_tx_dynf_specific_keyword,
19023                 (void *)&cmd_config_tx_dynf_specific_port_id,
19024                 (void *)&cmd_config_tx_dynf_specific_item,
19025                 (void *)&cmd_config_tx_dynf_specific_name,
19026                 (void *)&cmd_config_tx_dynf_specific_value,
19027                 NULL,
19028         },
19029 };
19030
19031 /* *** display tx_metadata per port configuration *** */
19032 struct cmd_show_tx_metadata_result {
19033         cmdline_fixed_string_t cmd_show;
19034         cmdline_fixed_string_t cmd_port;
19035         cmdline_fixed_string_t cmd_keyword;
19036         portid_t cmd_pid;
19037 };
19038
19039 static void
19040 cmd_show_tx_metadata_parsed(void *parsed_result,
19041                 __rte_unused struct cmdline *cl,
19042                 __rte_unused void *data)
19043 {
19044         struct cmd_show_tx_metadata_result *res = parsed_result;
19045
19046         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19047                 printf("invalid port id %u\n", res->cmd_pid);
19048                 return;
19049         }
19050         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19051                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19052                        ports[res->cmd_pid].tx_metadata);
19053         }
19054 }
19055
19056 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19057         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19058                         cmd_show, "show");
19059 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19060         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19061                         cmd_port, "port");
19062 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19063         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19064                         cmd_pid, UINT16);
19065 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19066         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19067                         cmd_keyword, "tx_metadata");
19068
19069 cmdline_parse_inst_t cmd_show_tx_metadata = {
19070         .f = cmd_show_tx_metadata_parsed,
19071         .data = NULL,
19072         .help_str = "show port <port_id> tx_metadata",
19073         .tokens = {
19074                 (void *)&cmd_show_tx_metadata_show,
19075                 (void *)&cmd_show_tx_metadata_port,
19076                 (void *)&cmd_show_tx_metadata_pid,
19077                 (void *)&cmd_show_tx_metadata_keyword,
19078                 NULL,
19079         },
19080 };
19081
19082 /* show port supported ptypes */
19083
19084 /* Common result structure for show port ptypes */
19085 struct cmd_show_port_supported_ptypes_result {
19086         cmdline_fixed_string_t show;
19087         cmdline_fixed_string_t port;
19088         portid_t port_id;
19089         cmdline_fixed_string_t ptypes;
19090 };
19091
19092 /* Common CLI fields for show port ptypes */
19093 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19094         TOKEN_STRING_INITIALIZER
19095                 (struct cmd_show_port_supported_ptypes_result,
19096                  show, "show");
19097 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19098         TOKEN_STRING_INITIALIZER
19099                 (struct cmd_show_port_supported_ptypes_result,
19100                  port, "port");
19101 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19102         TOKEN_NUM_INITIALIZER
19103                 (struct cmd_show_port_supported_ptypes_result,
19104                  port_id, UINT16);
19105 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19106         TOKEN_STRING_INITIALIZER
19107                 (struct cmd_show_port_supported_ptypes_result,
19108                  ptypes, "ptypes");
19109
19110 static void
19111 cmd_show_port_supported_ptypes_parsed(
19112         void *parsed_result,
19113         __rte_unused struct cmdline *cl,
19114         __rte_unused void *data)
19115 {
19116 #define RSVD_PTYPE_MASK       0xf0000000
19117 #define MAX_PTYPES_PER_LAYER  16
19118 #define LTYPE_NAMESIZE        32
19119 #define PTYPE_NAMESIZE        256
19120         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19121         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19122         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19123         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19124         uint16_t port_id = res->port_id;
19125         int ret, i;
19126
19127         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19128         if (ret < 0)
19129                 return;
19130
19131         while (ptype_mask != RSVD_PTYPE_MASK) {
19132
19133                 switch (ptype_mask) {
19134                 case RTE_PTYPE_L2_MASK:
19135                         strlcpy(ltype, "L2", sizeof(ltype));
19136                         break;
19137                 case RTE_PTYPE_L3_MASK:
19138                         strlcpy(ltype, "L3", sizeof(ltype));
19139                         break;
19140                 case RTE_PTYPE_L4_MASK:
19141                         strlcpy(ltype, "L4", sizeof(ltype));
19142                         break;
19143                 case RTE_PTYPE_TUNNEL_MASK:
19144                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19145                         break;
19146                 case RTE_PTYPE_INNER_L2_MASK:
19147                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19148                         break;
19149                 case RTE_PTYPE_INNER_L3_MASK:
19150                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19151                         break;
19152                 case RTE_PTYPE_INNER_L4_MASK:
19153                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19154                         break;
19155                 default:
19156                         return;
19157                 }
19158
19159                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19160                                                        ptype_mask, ptypes,
19161                                                        MAX_PTYPES_PER_LAYER);
19162
19163                 if (ret > 0)
19164                         printf("Supported %s ptypes:\n", ltype);
19165                 else
19166                         printf("%s ptypes unsupported\n", ltype);
19167
19168                 for (i = 0; i < ret; ++i) {
19169                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19170                         printf("%s\n", buf);
19171                 }
19172
19173                 ptype_mask <<= 4;
19174         }
19175 }
19176
19177 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19178         .f = cmd_show_port_supported_ptypes_parsed,
19179         .data = NULL,
19180         .help_str = "show port <port_id> ptypes",
19181         .tokens = {
19182                 (void *)&cmd_show_port_supported_ptypes_show,
19183                 (void *)&cmd_show_port_supported_ptypes_port,
19184                 (void *)&cmd_show_port_supported_ptypes_port_id,
19185                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19186                 NULL,
19187         },
19188 };
19189
19190 /* *** display rx/tx descriptor status *** */
19191 struct cmd_show_rx_tx_desc_status_result {
19192         cmdline_fixed_string_t cmd_show;
19193         cmdline_fixed_string_t cmd_port;
19194         cmdline_fixed_string_t cmd_keyword;
19195         cmdline_fixed_string_t cmd_desc;
19196         cmdline_fixed_string_t cmd_status;
19197         portid_t cmd_pid;
19198         portid_t cmd_qid;
19199         portid_t cmd_did;
19200 };
19201
19202 static void
19203 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19204                 __rte_unused struct cmdline *cl,
19205                 __rte_unused void *data)
19206 {
19207         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19208         int rc;
19209
19210         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19211                 printf("invalid port id %u\n", res->cmd_pid);
19212                 return;
19213         }
19214
19215         if (!strcmp(res->cmd_keyword, "rxq")) {
19216                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19217                                              res->cmd_did);
19218                 if (rc < 0) {
19219                         printf("Invalid queueid = %d\n", res->cmd_qid);
19220                         return;
19221                 }
19222                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19223                         printf("Desc status = AVAILABLE\n");
19224                 else if (rc == RTE_ETH_RX_DESC_DONE)
19225                         printf("Desc status = DONE\n");
19226                 else
19227                         printf("Desc status = UNAVAILABLE\n");
19228         } else if (!strcmp(res->cmd_keyword, "txq")) {
19229                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19230                                              res->cmd_did);
19231                 if (rc < 0) {
19232                         printf("Invalid queueid = %d\n", res->cmd_qid);
19233                         return;
19234                 }
19235                 if (rc == RTE_ETH_TX_DESC_FULL)
19236                         printf("Desc status = FULL\n");
19237                 else if (rc == RTE_ETH_TX_DESC_DONE)
19238                         printf("Desc status = DONE\n");
19239                 else
19240                         printf("Desc status = UNAVAILABLE\n");
19241         }
19242 }
19243
19244 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19245         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19246                         cmd_show, "show");
19247 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19248         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19249                         cmd_port, "port");
19250 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19251         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19252                         cmd_pid, UINT16);
19253 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19254         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19255                         cmd_keyword, "rxq#txq");
19256 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19257         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19258                         cmd_qid, UINT16);
19259 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19260         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19261                         cmd_desc, "desc");
19262 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19263         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19264                         cmd_did, UINT16);
19265 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19266         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19267                         cmd_status, "status");
19268 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19269         .f = cmd_show_rx_tx_desc_status_parsed,
19270         .data = NULL,
19271         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19272                 "status",
19273         .tokens = {
19274                 (void *)&cmd_show_rx_tx_desc_status_show,
19275                 (void *)&cmd_show_rx_tx_desc_status_port,
19276                 (void *)&cmd_show_rx_tx_desc_status_pid,
19277                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19278                 (void *)&cmd_show_rx_tx_desc_status_qid,
19279                 (void *)&cmd_show_rx_tx_desc_status_desc,
19280                 (void *)&cmd_show_rx_tx_desc_status_did,
19281                 (void *)&cmd_show_rx_tx_desc_status_status,
19282                 NULL,
19283         },
19284 };
19285
19286 /* Common result structure for set port ptypes */
19287 struct cmd_set_port_ptypes_result {
19288         cmdline_fixed_string_t set;
19289         cmdline_fixed_string_t port;
19290         portid_t port_id;
19291         cmdline_fixed_string_t ptype_mask;
19292         uint32_t mask;
19293 };
19294
19295 /* Common CLI fields for set port ptypes */
19296 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19297         TOKEN_STRING_INITIALIZER
19298                 (struct cmd_set_port_ptypes_result,
19299                  set, "set");
19300 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19301         TOKEN_STRING_INITIALIZER
19302                 (struct cmd_set_port_ptypes_result,
19303                  port, "port");
19304 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19305         TOKEN_NUM_INITIALIZER
19306                 (struct cmd_set_port_ptypes_result,
19307                  port_id, UINT16);
19308 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19309         TOKEN_STRING_INITIALIZER
19310                 (struct cmd_set_port_ptypes_result,
19311                  ptype_mask, "ptype_mask");
19312 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19313         TOKEN_NUM_INITIALIZER
19314                 (struct cmd_set_port_ptypes_result,
19315                  mask, UINT32);
19316
19317 static void
19318 cmd_set_port_ptypes_parsed(
19319         void *parsed_result,
19320         __rte_unused struct cmdline *cl,
19321         __rte_unused void *data)
19322 {
19323         struct cmd_set_port_ptypes_result *res = parsed_result;
19324 #define PTYPE_NAMESIZE        256
19325         char ptype_name[PTYPE_NAMESIZE];
19326         uint16_t port_id = res->port_id;
19327         uint32_t ptype_mask = res->mask;
19328         int ret, i;
19329
19330         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19331                                                NULL, 0);
19332         if (ret <= 0) {
19333                 printf("Port %d doesn't support any ptypes.\n", port_id);
19334                 return;
19335         }
19336
19337         uint32_t ptypes[ret];
19338
19339         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19340         if (ret < 0) {
19341                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19342                 return;
19343         }
19344
19345         printf("Successfully set following ptypes for Port %d\n", port_id);
19346         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19347                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19348                 printf("%s\n", ptype_name);
19349         }
19350
19351         clear_ptypes = false;
19352 }
19353
19354 cmdline_parse_inst_t cmd_set_port_ptypes = {
19355         .f = cmd_set_port_ptypes_parsed,
19356         .data = NULL,
19357         .help_str = "set port <port_id> ptype_mask <mask>",
19358         .tokens = {
19359                 (void *)&cmd_set_port_ptypes_set,
19360                 (void *)&cmd_set_port_ptypes_port,
19361                 (void *)&cmd_set_port_ptypes_port_id,
19362                 (void *)&cmd_set_port_ptypes_mask_str,
19363                 (void *)&cmd_set_port_ptypes_mask_u32,
19364                 NULL,
19365         },
19366 };
19367
19368 /* *** display mac addresses added to a port *** */
19369 struct cmd_showport_macs_result {
19370         cmdline_fixed_string_t cmd_show;
19371         cmdline_fixed_string_t cmd_port;
19372         cmdline_fixed_string_t cmd_keyword;
19373         portid_t cmd_pid;
19374 };
19375
19376 static void
19377 cmd_showport_macs_parsed(void *parsed_result,
19378                 __rte_unused struct cmdline *cl,
19379                 __rte_unused void *data)
19380 {
19381         struct cmd_showport_macs_result *res = parsed_result;
19382
19383         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19384                 return;
19385
19386         if (!strcmp(res->cmd_keyword, "macs"))
19387                 show_macs(res->cmd_pid);
19388         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19389                 show_mcast_macs(res->cmd_pid);
19390 }
19391
19392 cmdline_parse_token_string_t cmd_showport_macs_show =
19393         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19394                         cmd_show, "show");
19395 cmdline_parse_token_string_t cmd_showport_macs_port =
19396         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19397                         cmd_port, "port");
19398 cmdline_parse_token_num_t cmd_showport_macs_pid =
19399         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19400                         cmd_pid, UINT16);
19401 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19402         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19403                         cmd_keyword, "macs#mcast_macs");
19404
19405 cmdline_parse_inst_t cmd_showport_macs = {
19406         .f = cmd_showport_macs_parsed,
19407         .data = NULL,
19408         .help_str = "show port <port_id> macs|mcast_macs",
19409         .tokens = {
19410                 (void *)&cmd_showport_macs_show,
19411                 (void *)&cmd_showport_macs_port,
19412                 (void *)&cmd_showport_macs_pid,
19413                 (void *)&cmd_showport_macs_keyword,
19414                 NULL,
19415         },
19416 };
19417
19418 /* ******************************************************************************** */
19419
19420 /* list of instructions */
19421 cmdline_parse_ctx_t main_ctx[] = {
19422         (cmdline_parse_inst_t *)&cmd_help_brief,
19423         (cmdline_parse_inst_t *)&cmd_help_long,
19424         (cmdline_parse_inst_t *)&cmd_quit,
19425         (cmdline_parse_inst_t *)&cmd_load_from_file,
19426         (cmdline_parse_inst_t *)&cmd_showport,
19427         (cmdline_parse_inst_t *)&cmd_showqueue,
19428         (cmdline_parse_inst_t *)&cmd_showportall,
19429         (cmdline_parse_inst_t *)&cmd_showdevice,
19430         (cmdline_parse_inst_t *)&cmd_showcfg,
19431         (cmdline_parse_inst_t *)&cmd_showfwdall,
19432         (cmdline_parse_inst_t *)&cmd_start,
19433         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19434         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19435         (cmdline_parse_inst_t *)&cmd_set_link_up,
19436         (cmdline_parse_inst_t *)&cmd_set_link_down,
19437         (cmdline_parse_inst_t *)&cmd_reset,
19438         (cmdline_parse_inst_t *)&cmd_set_numbers,
19439         (cmdline_parse_inst_t *)&cmd_set_log,
19440         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19441         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19442         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19443         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19444         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19445         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19446         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19447         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19448         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19449         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19450         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19451         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19452         (cmdline_parse_inst_t *)&cmd_set_link_check,
19453         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19454         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19455         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19456         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19457 #ifdef RTE_LIBRTE_PMD_BOND
19458         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19459         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19460         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19461         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19462         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19463         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19464         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19465         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19466         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19467         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19468         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19469 #endif
19470         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19471         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19472         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19473         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19474         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19475         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19476         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19477         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19478         (cmdline_parse_inst_t *)&cmd_csum_set,
19479         (cmdline_parse_inst_t *)&cmd_csum_show,
19480         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19481         (cmdline_parse_inst_t *)&cmd_tso_set,
19482         (cmdline_parse_inst_t *)&cmd_tso_show,
19483         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19484         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19485         (cmdline_parse_inst_t *)&cmd_gro_enable,
19486         (cmdline_parse_inst_t *)&cmd_gro_flush,
19487         (cmdline_parse_inst_t *)&cmd_gro_show,
19488         (cmdline_parse_inst_t *)&cmd_gso_enable,
19489         (cmdline_parse_inst_t *)&cmd_gso_size,
19490         (cmdline_parse_inst_t *)&cmd_gso_show,
19491         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19492         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19493         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19494         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19495         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19496         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19497         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19498         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19499         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19500         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19501         (cmdline_parse_inst_t *)&cmd_config_dcb,
19502         (cmdline_parse_inst_t *)&cmd_read_reg,
19503         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19504         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19505         (cmdline_parse_inst_t *)&cmd_write_reg,
19506         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19507         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19508         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19509         (cmdline_parse_inst_t *)&cmd_stop,
19510         (cmdline_parse_inst_t *)&cmd_mac_addr,
19511         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19512         (cmdline_parse_inst_t *)&cmd_set_qmap,
19513         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19514         (cmdline_parse_inst_t *)&cmd_operate_port,
19515         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19516         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19517         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19518         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19519         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19520         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19521         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19522         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19523         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19524         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19525         (cmdline_parse_inst_t *)&cmd_config_mtu,
19526         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19527         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19528         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19529         (cmdline_parse_inst_t *)&cmd_config_rss,
19530         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19531         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19532         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19533         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19534         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19535         (cmdline_parse_inst_t *)&cmd_showport_reta,
19536         (cmdline_parse_inst_t *)&cmd_showport_macs,
19537         (cmdline_parse_inst_t *)&cmd_config_burst,
19538         (cmdline_parse_inst_t *)&cmd_config_thresh,
19539         (cmdline_parse_inst_t *)&cmd_config_threshold,
19540         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19541         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19542         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19543         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19544         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19545         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19546         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19547         (cmdline_parse_inst_t *)&cmd_global_config,
19548         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19549         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19550         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19551         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19552         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19553         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19554         (cmdline_parse_inst_t *)&cmd_dump,
19555         (cmdline_parse_inst_t *)&cmd_dump_one,
19556         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19557         (cmdline_parse_inst_t *)&cmd_syn_filter,
19558         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19559         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19560         (cmdline_parse_inst_t *)&cmd_flex_filter,
19561         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19562         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19563         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19564         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19565         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19566         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19567         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19568         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19569         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19570         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19571         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19572         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19573         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19574         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19575         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19576         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19577         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19578         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19579         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19580         (cmdline_parse_inst_t *)&cmd_flow,
19581         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19582         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19583         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19584         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19585         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19586         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19587         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19588         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19589         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19590         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19591         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19592         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19593         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19594         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19595         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19596         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19597         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19598         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19599         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19600         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19601         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19602         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19603         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19604         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19605         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19606         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19607         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19608         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19609         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19610         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19611         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19612         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19613         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19614         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19615         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19616         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19617         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19618         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19619         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19620         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19621         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19622         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19623         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19624         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19625         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19626         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19627         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19628         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19629         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19630 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
19631         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
19632 #endif
19633         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19634         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19635         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19636         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19637         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19638         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19639         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19640         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19641         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19642         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19643         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19644         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19645         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19646         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19647         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19648         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19649         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19650         (cmdline_parse_inst_t *)&cmd_ddp_add,
19651         (cmdline_parse_inst_t *)&cmd_ddp_del,
19652         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19653         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19654         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19655         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19656         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19657         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19658         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19659         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19660         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19661         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19662         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19663         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19664
19665         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19666         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19667         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19668         (cmdline_parse_inst_t *)&cmd_queue_region,
19669         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19670         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19671         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19672         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19673         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19674         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19675         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19676         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19677         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19678         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19679         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19680         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19681         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19682         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19683         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19684         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19685         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19686         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19687         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19688         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19689         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19690         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19691         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19692         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19693         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19694         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19695         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19696         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19697         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19698         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19699         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19700         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19701         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19702         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19703         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19704 #ifdef RTE_LIBRTE_BPF
19705         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19706         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19707 #endif
19708         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19709         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19710         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19711         (cmdline_parse_inst_t *)&cmd_set_raw,
19712         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19713         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19714         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19715         NULL,
19716 };
19717
19718 /* read cmdline commands from file */
19719 void
19720 cmdline_read_from_file(const char *filename)
19721 {
19722         struct cmdline *cl;
19723
19724         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19725         if (cl == NULL) {
19726                 printf("Failed to create file based cmdline context: %s\n",
19727                        filename);
19728                 return;
19729         }
19730
19731         cmdline_interact(cl);
19732         cmdline_quit(cl);
19733
19734         cmdline_free(cl);
19735
19736         printf("Read CLI commands from %s\n", filename);
19737 }
19738
19739 /* prompt function, called from main on MASTER lcore */
19740 void
19741 prompt(void)
19742 {
19743         /* initialize non-constant commands */
19744         cmd_set_fwd_mode_init();
19745         cmd_set_fwd_retry_mode_init();
19746
19747         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19748         if (testpmd_cl == NULL)
19749                 return;
19750         cmdline_interact(testpmd_cl);
19751         cmdline_stdin_exit(testpmd_cl);
19752 }
19753
19754 void
19755 prompt_exit(void)
19756 {
19757         if (testpmd_cl != NULL)
19758                 cmdline_quit(testpmd_cl);
19759 }
19760
19761 static void
19762 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19763 {
19764         if (id == (portid_t)RTE_PORT_ALL) {
19765                 portid_t pid;
19766
19767                 RTE_ETH_FOREACH_DEV(pid) {
19768                         /* check if need_reconfig has been set to 1 */
19769                         if (ports[pid].need_reconfig == 0)
19770                                 ports[pid].need_reconfig = dev;
19771                         /* check if need_reconfig_queues has been set to 1 */
19772                         if (ports[pid].need_reconfig_queues == 0)
19773                                 ports[pid].need_reconfig_queues = queue;
19774                 }
19775         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19776                 /* check if need_reconfig has been set to 1 */
19777                 if (ports[id].need_reconfig == 0)
19778                         ports[id].need_reconfig = dev;
19779                 /* check if need_reconfig_queues has been set to 1 */
19780                 if (ports[id].need_reconfig_queues == 0)
19781                         ports[id].need_reconfig_queues = queue;
19782         }
19783 }