be1a98b9bccafefa148e3d9820830680e39cb541
[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                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1190                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1191                         " (packet_length_adjust)\n"
1192                         "       Add port tm node private shaper profile.\n\n"
1193
1194                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1195                         "       Delete port tm node private shaper profile.\n\n"
1196
1197                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1198                         " (shaper_profile_id)\n"
1199                         "       Add/update port tm node shared shaper.\n\n"
1200
1201                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1202                         "       Delete port tm node shared shaper.\n\n"
1203
1204                         "set port tm node shaper profile (port_id) (node_id)"
1205                         " (shaper_profile_id)\n"
1206                         "       Set port tm node shaper profile.\n\n"
1207
1208                         "add port tm node wred profile (port_id) (wred_profile_id)"
1209                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1210                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1211                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1212                         "       Add port tm node wred profile.\n\n"
1213
1214                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1215                         "       Delete port tm node wred profile.\n\n"
1216
1217                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1218                         " (priority) (weight) (level_id) (shaper_profile_id)"
1219                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1220                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1221                         "       Add port tm nonleaf node.\n\n"
1222
1223                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1224                         " (priority) (weight) (level_id) (shaper_profile_id)"
1225                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1226                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1227                         "       Add port tm leaf node.\n\n"
1228
1229                         "del port tm node (port_id) (node_id)\n"
1230                         "       Delete port tm node.\n\n"
1231
1232                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1233                         " (priority) (weight)\n"
1234                         "       Set port tm node parent.\n\n"
1235
1236                         "suspend port tm node (port_id) (node_id)"
1237                         "       Suspend tm node.\n\n"
1238
1239                         "resume port tm node (port_id) (node_id)"
1240                         "       Resume tm node.\n\n"
1241
1242                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1243                         "       Commit tm hierarchy.\n\n"
1244
1245                         "set port tm mark ip_ecn (port) (green) (yellow)"
1246                         " (red)\n"
1247                         "    Enables/Disables the traffic management marking"
1248                         " for IP ECN (Explicit Congestion Notification)"
1249                         " packets on a given port\n\n"
1250
1251                         "set port tm mark ip_dscp (port) (green) (yellow)"
1252                         " (red)\n"
1253                         "    Enables/Disables the traffic management marking"
1254                         " on the port for IP dscp packets\n\n"
1255
1256                         "set port tm mark vlan_dei (port) (green) (yellow)"
1257                         " (red)\n"
1258                         "    Enables/Disables the traffic management marking"
1259                         " on the port for VLAN packets with DEI enabled\n\n"
1260                 );
1261         }
1262
1263         if (show_all || !strcmp(res->section, "devices")) {
1264                 cmdline_printf(
1265                         cl,
1266                         "\n"
1267                         "Device Operations:\n"
1268                         "--------------\n"
1269                         "device detach (identifier)\n"
1270                         "       Detach device by identifier.\n\n"
1271                 );
1272         }
1273
1274 }
1275
1276 cmdline_parse_token_string_t cmd_help_long_help =
1277         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1278
1279 cmdline_parse_token_string_t cmd_help_long_section =
1280         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1281                         "all#control#display#config#"
1282                         "ports#registers#filters#traffic_management#devices");
1283
1284 cmdline_parse_inst_t cmd_help_long = {
1285         .f = cmd_help_long_parsed,
1286         .data = NULL,
1287         .help_str = "help all|control|display|config|ports|register|"
1288                 "filters|traffic_management|devices: "
1289                 "Show help",
1290         .tokens = {
1291                 (void *)&cmd_help_long_help,
1292                 (void *)&cmd_help_long_section,
1293                 NULL,
1294         },
1295 };
1296
1297
1298 /* *** start/stop/close all ports *** */
1299 struct cmd_operate_port_result {
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t name;
1302         cmdline_fixed_string_t value;
1303 };
1304
1305 static void cmd_operate_port_parsed(void *parsed_result,
1306                                 __rte_unused struct cmdline *cl,
1307                                 __rte_unused void *data)
1308 {
1309         struct cmd_operate_port_result *res = parsed_result;
1310
1311         if (!strcmp(res->name, "start"))
1312                 start_port(RTE_PORT_ALL);
1313         else if (!strcmp(res->name, "stop"))
1314                 stop_port(RTE_PORT_ALL);
1315         else if (!strcmp(res->name, "close"))
1316                 close_port(RTE_PORT_ALL);
1317         else if (!strcmp(res->name, "reset"))
1318                 reset_port(RTE_PORT_ALL);
1319         else
1320                 printf("Unknown parameter\n");
1321 }
1322
1323 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1324         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1325                                                                 "port");
1326 cmdline_parse_token_string_t cmd_operate_port_all_port =
1327         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1328                                                 "start#stop#close#reset");
1329 cmdline_parse_token_string_t cmd_operate_port_all_all =
1330         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1331
1332 cmdline_parse_inst_t cmd_operate_port = {
1333         .f = cmd_operate_port_parsed,
1334         .data = NULL,
1335         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1336         .tokens = {
1337                 (void *)&cmd_operate_port_all_cmd,
1338                 (void *)&cmd_operate_port_all_port,
1339                 (void *)&cmd_operate_port_all_all,
1340                 NULL,
1341         },
1342 };
1343
1344 /* *** start/stop/close specific port *** */
1345 struct cmd_operate_specific_port_result {
1346         cmdline_fixed_string_t keyword;
1347         cmdline_fixed_string_t name;
1348         uint8_t value;
1349 };
1350
1351 static void cmd_operate_specific_port_parsed(void *parsed_result,
1352                         __rte_unused struct cmdline *cl,
1353                                 __rte_unused void *data)
1354 {
1355         struct cmd_operate_specific_port_result *res = parsed_result;
1356
1357         if (!strcmp(res->name, "start"))
1358                 start_port(res->value);
1359         else if (!strcmp(res->name, "stop"))
1360                 stop_port(res->value);
1361         else if (!strcmp(res->name, "close"))
1362                 close_port(res->value);
1363         else if (!strcmp(res->name, "reset"))
1364                 reset_port(res->value);
1365         else
1366                 printf("Unknown parameter\n");
1367 }
1368
1369 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1370         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1371                                                         keyword, "port");
1372 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1373         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1374                                                 name, "start#stop#close#reset");
1375 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1376         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1377                                                         value, UINT8);
1378
1379 cmdline_parse_inst_t cmd_operate_specific_port = {
1380         .f = cmd_operate_specific_port_parsed,
1381         .data = NULL,
1382         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1383         .tokens = {
1384                 (void *)&cmd_operate_specific_port_cmd,
1385                 (void *)&cmd_operate_specific_port_port,
1386                 (void *)&cmd_operate_specific_port_id,
1387                 NULL,
1388         },
1389 };
1390
1391 /* *** enable port setup (after attach) via iterator or event *** */
1392 struct cmd_set_port_setup_on_result {
1393         cmdline_fixed_string_t set;
1394         cmdline_fixed_string_t port;
1395         cmdline_fixed_string_t setup;
1396         cmdline_fixed_string_t on;
1397         cmdline_fixed_string_t mode;
1398 };
1399
1400 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1401                                 __rte_unused struct cmdline *cl,
1402                                 __rte_unused void *data)
1403 {
1404         struct cmd_set_port_setup_on_result *res = parsed_result;
1405
1406         if (strcmp(res->mode, "event") == 0)
1407                 setup_on_probe_event = true;
1408         else if (strcmp(res->mode, "iterator") == 0)
1409                 setup_on_probe_event = false;
1410         else
1411                 printf("Unknown mode\n");
1412 }
1413
1414 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1415         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1416                         set, "set");
1417 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1418         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1419                         port, "port");
1420 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1421         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1422                         setup, "setup");
1423 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1424         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1425                         on, "on");
1426 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1427         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1428                         mode, "iterator#event");
1429
1430 cmdline_parse_inst_t cmd_set_port_setup_on = {
1431         .f = cmd_set_port_setup_on_parsed,
1432         .data = NULL,
1433         .help_str = "set port setup on iterator|event",
1434         .tokens = {
1435                 (void *)&cmd_set_port_setup_on_set,
1436                 (void *)&cmd_set_port_setup_on_port,
1437                 (void *)&cmd_set_port_setup_on_setup,
1438                 (void *)&cmd_set_port_setup_on_on,
1439                 (void *)&cmd_set_port_setup_on_mode,
1440                 NULL,
1441         },
1442 };
1443
1444 /* *** attach a specified port *** */
1445 struct cmd_operate_attach_port_result {
1446         cmdline_fixed_string_t port;
1447         cmdline_fixed_string_t keyword;
1448         cmdline_multi_string_t identifier;
1449 };
1450
1451 static void cmd_operate_attach_port_parsed(void *parsed_result,
1452                                 __rte_unused struct cmdline *cl,
1453                                 __rte_unused void *data)
1454 {
1455         struct cmd_operate_attach_port_result *res = parsed_result;
1456
1457         if (!strcmp(res->keyword, "attach"))
1458                 attach_port(res->identifier);
1459         else
1460                 printf("Unknown parameter\n");
1461 }
1462
1463 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1464         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1465                         port, "port");
1466 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1467         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1468                         keyword, "attach");
1469 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1470         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1471                         identifier, TOKEN_STRING_MULTI);
1472
1473 cmdline_parse_inst_t cmd_operate_attach_port = {
1474         .f = cmd_operate_attach_port_parsed,
1475         .data = NULL,
1476         .help_str = "port attach <identifier>: "
1477                 "(identifier: pci address or virtual dev name)",
1478         .tokens = {
1479                 (void *)&cmd_operate_attach_port_port,
1480                 (void *)&cmd_operate_attach_port_keyword,
1481                 (void *)&cmd_operate_attach_port_identifier,
1482                 NULL,
1483         },
1484 };
1485
1486 /* *** detach a specified port *** */
1487 struct cmd_operate_detach_port_result {
1488         cmdline_fixed_string_t port;
1489         cmdline_fixed_string_t keyword;
1490         portid_t port_id;
1491 };
1492
1493 static void cmd_operate_detach_port_parsed(void *parsed_result,
1494                                 __rte_unused struct cmdline *cl,
1495                                 __rte_unused void *data)
1496 {
1497         struct cmd_operate_detach_port_result *res = parsed_result;
1498
1499         if (!strcmp(res->keyword, "detach")) {
1500                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1501                 detach_port_device(res->port_id);
1502         } else {
1503                 printf("Unknown parameter\n");
1504         }
1505 }
1506
1507 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1508         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1509                         port, "port");
1510 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1511         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1512                         keyword, "detach");
1513 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1514         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1515                         port_id, UINT16);
1516
1517 cmdline_parse_inst_t cmd_operate_detach_port = {
1518         .f = cmd_operate_detach_port_parsed,
1519         .data = NULL,
1520         .help_str = "port detach <port_id>",
1521         .tokens = {
1522                 (void *)&cmd_operate_detach_port_port,
1523                 (void *)&cmd_operate_detach_port_keyword,
1524                 (void *)&cmd_operate_detach_port_port_id,
1525                 NULL,
1526         },
1527 };
1528
1529 /* *** detach device by identifier *** */
1530 struct cmd_operate_detach_device_result {
1531         cmdline_fixed_string_t device;
1532         cmdline_fixed_string_t keyword;
1533         cmdline_fixed_string_t identifier;
1534 };
1535
1536 static void cmd_operate_detach_device_parsed(void *parsed_result,
1537                                 __rte_unused struct cmdline *cl,
1538                                 __rte_unused void *data)
1539 {
1540         struct cmd_operate_detach_device_result *res = parsed_result;
1541
1542         if (!strcmp(res->keyword, "detach"))
1543                 detach_devargs(res->identifier);
1544         else
1545                 printf("Unknown parameter\n");
1546 }
1547
1548 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1549         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1550                         device, "device");
1551 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1552         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1553                         keyword, "detach");
1554 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1555         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1556                         identifier, NULL);
1557
1558 cmdline_parse_inst_t cmd_operate_detach_device = {
1559         .f = cmd_operate_detach_device_parsed,
1560         .data = NULL,
1561         .help_str = "device detach <identifier>:"
1562                 "(identifier: pci address or virtual dev name)",
1563         .tokens = {
1564                 (void *)&cmd_operate_detach_device_device,
1565                 (void *)&cmd_operate_detach_device_keyword,
1566                 (void *)&cmd_operate_detach_device_identifier,
1567                 NULL,
1568         },
1569 };
1570 /* *** configure speed for all ports *** */
1571 struct cmd_config_speed_all {
1572         cmdline_fixed_string_t port;
1573         cmdline_fixed_string_t keyword;
1574         cmdline_fixed_string_t all;
1575         cmdline_fixed_string_t item1;
1576         cmdline_fixed_string_t item2;
1577         cmdline_fixed_string_t value1;
1578         cmdline_fixed_string_t value2;
1579 };
1580
1581 static int
1582 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1583 {
1584
1585         int duplex;
1586
1587         if (!strcmp(duplexstr, "half")) {
1588                 duplex = ETH_LINK_HALF_DUPLEX;
1589         } else if (!strcmp(duplexstr, "full")) {
1590                 duplex = ETH_LINK_FULL_DUPLEX;
1591         } else if (!strcmp(duplexstr, "auto")) {
1592                 duplex = ETH_LINK_FULL_DUPLEX;
1593         } else {
1594                 printf("Unknown duplex parameter\n");
1595                 return -1;
1596         }
1597
1598         if (!strcmp(speedstr, "10")) {
1599                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1600                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1601         } else if (!strcmp(speedstr, "100")) {
1602                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1603                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1604         } else {
1605                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1606                         printf("Invalid speed/duplex parameters\n");
1607                         return -1;
1608                 }
1609                 if (!strcmp(speedstr, "1000")) {
1610                         *speed = ETH_LINK_SPEED_1G;
1611                 } else if (!strcmp(speedstr, "10000")) {
1612                         *speed = ETH_LINK_SPEED_10G;
1613                 } else if (!strcmp(speedstr, "25000")) {
1614                         *speed = ETH_LINK_SPEED_25G;
1615                 } else if (!strcmp(speedstr, "40000")) {
1616                         *speed = ETH_LINK_SPEED_40G;
1617                 } else if (!strcmp(speedstr, "50000")) {
1618                         *speed = ETH_LINK_SPEED_50G;
1619                 } else if (!strcmp(speedstr, "100000")) {
1620                         *speed = ETH_LINK_SPEED_100G;
1621                 } else if (!strcmp(speedstr, "200000")) {
1622                         *speed = ETH_LINK_SPEED_200G;
1623                 } else if (!strcmp(speedstr, "auto")) {
1624                         *speed = ETH_LINK_SPEED_AUTONEG;
1625                 } else {
1626                         printf("Unknown speed parameter\n");
1627                         return -1;
1628                 }
1629         }
1630
1631         return 0;
1632 }
1633
1634 static void
1635 cmd_config_speed_all_parsed(void *parsed_result,
1636                         __rte_unused struct cmdline *cl,
1637                         __rte_unused void *data)
1638 {
1639         struct cmd_config_speed_all *res = parsed_result;
1640         uint32_t link_speed;
1641         portid_t pid;
1642
1643         if (!all_ports_stopped()) {
1644                 printf("Please stop all ports first\n");
1645                 return;
1646         }
1647
1648         if (parse_and_check_speed_duplex(res->value1, res->value2,
1649                         &link_speed) < 0)
1650                 return;
1651
1652         RTE_ETH_FOREACH_DEV(pid) {
1653                 ports[pid].dev_conf.link_speeds = link_speed;
1654         }
1655
1656         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1657 }
1658
1659 cmdline_parse_token_string_t cmd_config_speed_all_port =
1660         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1661 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1662         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1663                                                         "config");
1664 cmdline_parse_token_string_t cmd_config_speed_all_all =
1665         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1666 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1667         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1668 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1669         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1670                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1671 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1673 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1675                                                 "half#full#auto");
1676
1677 cmdline_parse_inst_t cmd_config_speed_all = {
1678         .f = cmd_config_speed_all_parsed,
1679         .data = NULL,
1680         .help_str = "port config all speed "
1681                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1682                                                         "half|full|auto",
1683         .tokens = {
1684                 (void *)&cmd_config_speed_all_port,
1685                 (void *)&cmd_config_speed_all_keyword,
1686                 (void *)&cmd_config_speed_all_all,
1687                 (void *)&cmd_config_speed_all_item1,
1688                 (void *)&cmd_config_speed_all_value1,
1689                 (void *)&cmd_config_speed_all_item2,
1690                 (void *)&cmd_config_speed_all_value2,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure speed for specific port *** */
1696 struct cmd_config_speed_specific {
1697         cmdline_fixed_string_t port;
1698         cmdline_fixed_string_t keyword;
1699         portid_t id;
1700         cmdline_fixed_string_t item1;
1701         cmdline_fixed_string_t item2;
1702         cmdline_fixed_string_t value1;
1703         cmdline_fixed_string_t value2;
1704 };
1705
1706 static void
1707 cmd_config_speed_specific_parsed(void *parsed_result,
1708                                 __rte_unused struct cmdline *cl,
1709                                 __rte_unused void *data)
1710 {
1711         struct cmd_config_speed_specific *res = parsed_result;
1712         uint32_t link_speed;
1713
1714         if (!all_ports_stopped()) {
1715                 printf("Please stop all ports first\n");
1716                 return;
1717         }
1718
1719         if (port_id_is_invalid(res->id, ENABLED_WARN))
1720                 return;
1721
1722         if (parse_and_check_speed_duplex(res->value1, res->value2,
1723                         &link_speed) < 0)
1724                 return;
1725
1726         ports[res->id].dev_conf.link_speeds = link_speed;
1727
1728         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1729 }
1730
1731
1732 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1734                                                                 "port");
1735 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1736         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1737                                                                 "config");
1738 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1739         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1740 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1742                                                                 "speed");
1743 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1744         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1745                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1746 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1747         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1748                                                                 "duplex");
1749 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1750         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1751                                                         "half#full#auto");
1752
1753 cmdline_parse_inst_t cmd_config_speed_specific = {
1754         .f = cmd_config_speed_specific_parsed,
1755         .data = NULL,
1756         .help_str = "port config <port_id> speed "
1757                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1758                                                         "half|full|auto",
1759         .tokens = {
1760                 (void *)&cmd_config_speed_specific_port,
1761                 (void *)&cmd_config_speed_specific_keyword,
1762                 (void *)&cmd_config_speed_specific_id,
1763                 (void *)&cmd_config_speed_specific_item1,
1764                 (void *)&cmd_config_speed_specific_value1,
1765                 (void *)&cmd_config_speed_specific_item2,
1766                 (void *)&cmd_config_speed_specific_value2,
1767                 NULL,
1768         },
1769 };
1770
1771 /* *** configure loopback for all ports *** */
1772 struct cmd_config_loopback_all {
1773         cmdline_fixed_string_t port;
1774         cmdline_fixed_string_t keyword;
1775         cmdline_fixed_string_t all;
1776         cmdline_fixed_string_t item;
1777         uint32_t mode;
1778 };
1779
1780 static void
1781 cmd_config_loopback_all_parsed(void *parsed_result,
1782                         __rte_unused struct cmdline *cl,
1783                         __rte_unused void *data)
1784 {
1785         struct cmd_config_loopback_all *res = parsed_result;
1786         portid_t pid;
1787
1788         if (!all_ports_stopped()) {
1789                 printf("Please stop all ports first\n");
1790                 return;
1791         }
1792
1793         RTE_ETH_FOREACH_DEV(pid) {
1794                 ports[pid].dev_conf.lpbk_mode = res->mode;
1795         }
1796
1797         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1798 }
1799
1800 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1801         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1802 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1804                                                         "config");
1805 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1807 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1808         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1809                                                         "loopback");
1810 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1811         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1812
1813 cmdline_parse_inst_t cmd_config_loopback_all = {
1814         .f = cmd_config_loopback_all_parsed,
1815         .data = NULL,
1816         .help_str = "port config all loopback <mode>",
1817         .tokens = {
1818                 (void *)&cmd_config_loopback_all_port,
1819                 (void *)&cmd_config_loopback_all_keyword,
1820                 (void *)&cmd_config_loopback_all_all,
1821                 (void *)&cmd_config_loopback_all_item,
1822                 (void *)&cmd_config_loopback_all_mode,
1823                 NULL,
1824         },
1825 };
1826
1827 /* *** configure loopback for specific port *** */
1828 struct cmd_config_loopback_specific {
1829         cmdline_fixed_string_t port;
1830         cmdline_fixed_string_t keyword;
1831         uint16_t port_id;
1832         cmdline_fixed_string_t item;
1833         uint32_t mode;
1834 };
1835
1836 static void
1837 cmd_config_loopback_specific_parsed(void *parsed_result,
1838                                 __rte_unused struct cmdline *cl,
1839                                 __rte_unused void *data)
1840 {
1841         struct cmd_config_loopback_specific *res = parsed_result;
1842
1843         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1844                 return;
1845
1846         if (!port_is_stopped(res->port_id)) {
1847                 printf("Please stop port %u first\n", res->port_id);
1848                 return;
1849         }
1850
1851         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1852
1853         cmd_reconfig_device_queue(res->port_id, 1, 1);
1854 }
1855
1856
1857 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1858         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1859                                                                 "port");
1860 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1862                                                                 "config");
1863 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1864         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1865                                                                 UINT16);
1866 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1867         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1868                                                                 "loopback");
1869 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1870         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1871                               UINT32);
1872
1873 cmdline_parse_inst_t cmd_config_loopback_specific = {
1874         .f = cmd_config_loopback_specific_parsed,
1875         .data = NULL,
1876         .help_str = "port config <port_id> loopback <mode>",
1877         .tokens = {
1878                 (void *)&cmd_config_loopback_specific_port,
1879                 (void *)&cmd_config_loopback_specific_keyword,
1880                 (void *)&cmd_config_loopback_specific_id,
1881                 (void *)&cmd_config_loopback_specific_item,
1882                 (void *)&cmd_config_loopback_specific_mode,
1883                 NULL,
1884         },
1885 };
1886
1887 /* *** configure txq/rxq, txd/rxd *** */
1888 struct cmd_config_rx_tx {
1889         cmdline_fixed_string_t port;
1890         cmdline_fixed_string_t keyword;
1891         cmdline_fixed_string_t all;
1892         cmdline_fixed_string_t name;
1893         uint16_t value;
1894 };
1895
1896 static void
1897 cmd_config_rx_tx_parsed(void *parsed_result,
1898                         __rte_unused struct cmdline *cl,
1899                         __rte_unused void *data)
1900 {
1901         struct cmd_config_rx_tx *res = parsed_result;
1902
1903         if (!all_ports_stopped()) {
1904                 printf("Please stop all ports first\n");
1905                 return;
1906         }
1907         if (!strcmp(res->name, "rxq")) {
1908                 if (!res->value && !nb_txq) {
1909                         printf("Warning: Either rx or tx queues should be non zero\n");
1910                         return;
1911                 }
1912                 if (check_nb_rxq(res->value) != 0)
1913                         return;
1914                 nb_rxq = res->value;
1915         }
1916         else if (!strcmp(res->name, "txq")) {
1917                 if (!res->value && !nb_rxq) {
1918                         printf("Warning: Either rx or tx queues should be non zero\n");
1919                         return;
1920                 }
1921                 if (check_nb_txq(res->value) != 0)
1922                         return;
1923                 nb_txq = res->value;
1924         }
1925         else if (!strcmp(res->name, "rxd")) {
1926                 if (check_nb_rxd(res->value) != 0)
1927                         return;
1928                 nb_rxd = res->value;
1929         } else if (!strcmp(res->name, "txd")) {
1930                 if (check_nb_txd(res->value) != 0)
1931                         return;
1932
1933                 nb_txd = res->value;
1934         } else {
1935                 printf("Unknown parameter\n");
1936                 return;
1937         }
1938
1939         fwd_config_setup();
1940
1941         init_port_config();
1942
1943         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1944 }
1945
1946 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1947         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1948 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1949         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1950 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1951         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1952 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1953         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1954                                                 "rxq#txq#rxd#txd");
1955 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1956         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1957
1958 cmdline_parse_inst_t cmd_config_rx_tx = {
1959         .f = cmd_config_rx_tx_parsed,
1960         .data = NULL,
1961         .help_str = "port config all rxq|txq|rxd|txd <value>",
1962         .tokens = {
1963                 (void *)&cmd_config_rx_tx_port,
1964                 (void *)&cmd_config_rx_tx_keyword,
1965                 (void *)&cmd_config_rx_tx_all,
1966                 (void *)&cmd_config_rx_tx_name,
1967                 (void *)&cmd_config_rx_tx_value,
1968                 NULL,
1969         },
1970 };
1971
1972 /* *** config max packet length *** */
1973 struct cmd_config_max_pkt_len_result {
1974         cmdline_fixed_string_t port;
1975         cmdline_fixed_string_t keyword;
1976         cmdline_fixed_string_t all;
1977         cmdline_fixed_string_t name;
1978         uint32_t value;
1979 };
1980
1981 static void
1982 cmd_config_max_pkt_len_parsed(void *parsed_result,
1983                                 __rte_unused struct cmdline *cl,
1984                                 __rte_unused void *data)
1985 {
1986         struct cmd_config_max_pkt_len_result *res = parsed_result;
1987         portid_t pid;
1988
1989         if (!all_ports_stopped()) {
1990                 printf("Please stop all ports first\n");
1991                 return;
1992         }
1993
1994         RTE_ETH_FOREACH_DEV(pid) {
1995                 struct rte_port *port = &ports[pid];
1996                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1997
1998                 if (!strcmp(res->name, "max-pkt-len")) {
1999                         if (res->value < RTE_ETHER_MIN_LEN) {
2000                                 printf("max-pkt-len can not be less than %d\n",
2001                                                 RTE_ETHER_MIN_LEN);
2002                                 return;
2003                         }
2004                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2005                                 return;
2006
2007                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2008                         if (res->value > RTE_ETHER_MAX_LEN)
2009                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2010                         else
2011                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2012                         port->dev_conf.rxmode.offloads = rx_offloads;
2013                 } else {
2014                         printf("Unknown parameter\n");
2015                         return;
2016                 }
2017         }
2018
2019         init_port_config();
2020
2021         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2022 }
2023
2024 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2025         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2026                                                                 "port");
2027 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2028         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2029                                                                 "config");
2030 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2031         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2032                                                                 "all");
2033 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2034         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2035                                                                 "max-pkt-len");
2036 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2037         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2038                                                                 UINT32);
2039
2040 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2041         .f = cmd_config_max_pkt_len_parsed,
2042         .data = NULL,
2043         .help_str = "port config all max-pkt-len <value>",
2044         .tokens = {
2045                 (void *)&cmd_config_max_pkt_len_port,
2046                 (void *)&cmd_config_max_pkt_len_keyword,
2047                 (void *)&cmd_config_max_pkt_len_all,
2048                 (void *)&cmd_config_max_pkt_len_name,
2049                 (void *)&cmd_config_max_pkt_len_value,
2050                 NULL,
2051         },
2052 };
2053
2054 /* *** config max LRO aggregated packet size *** */
2055 struct cmd_config_max_lro_pkt_size_result {
2056         cmdline_fixed_string_t port;
2057         cmdline_fixed_string_t keyword;
2058         cmdline_fixed_string_t all;
2059         cmdline_fixed_string_t name;
2060         uint32_t value;
2061 };
2062
2063 static void
2064 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2065                                 __rte_unused struct cmdline *cl,
2066                                 __rte_unused void *data)
2067 {
2068         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2069         portid_t pid;
2070
2071         if (!all_ports_stopped()) {
2072                 printf("Please stop all ports first\n");
2073                 return;
2074         }
2075
2076         RTE_ETH_FOREACH_DEV(pid) {
2077                 struct rte_port *port = &ports[pid];
2078
2079                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2080                         if (res->value ==
2081                                         port->dev_conf.rxmode.max_lro_pkt_size)
2082                                 return;
2083
2084                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2085                 } else {
2086                         printf("Unknown parameter\n");
2087                         return;
2088                 }
2089         }
2090
2091         init_port_config();
2092
2093         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2094 }
2095
2096 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2097         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2098                                  port, "port");
2099 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2100         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2101                                  keyword, "config");
2102 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2103         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2104                                  all, "all");
2105 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2106         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2107                                  name, "max-lro-pkt-size");
2108 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2109         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2110                               value, UINT32);
2111
2112 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2113         .f = cmd_config_max_lro_pkt_size_parsed,
2114         .data = NULL,
2115         .help_str = "port config all max-lro-pkt-size <value>",
2116         .tokens = {
2117                 (void *)&cmd_config_max_lro_pkt_size_port,
2118                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2119                 (void *)&cmd_config_max_lro_pkt_size_all,
2120                 (void *)&cmd_config_max_lro_pkt_size_name,
2121                 (void *)&cmd_config_max_lro_pkt_size_value,
2122                 NULL,
2123         },
2124 };
2125
2126 /* *** configure port MTU *** */
2127 struct cmd_config_mtu_result {
2128         cmdline_fixed_string_t port;
2129         cmdline_fixed_string_t keyword;
2130         cmdline_fixed_string_t mtu;
2131         portid_t port_id;
2132         uint16_t value;
2133 };
2134
2135 static void
2136 cmd_config_mtu_parsed(void *parsed_result,
2137                       __rte_unused struct cmdline *cl,
2138                       __rte_unused void *data)
2139 {
2140         struct cmd_config_mtu_result *res = parsed_result;
2141
2142         if (res->value < RTE_ETHER_MIN_LEN) {
2143                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2144                 return;
2145         }
2146         port_mtu_set(res->port_id, res->value);
2147 }
2148
2149 cmdline_parse_token_string_t cmd_config_mtu_port =
2150         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2151                                  "port");
2152 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2154                                  "config");
2155 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2157                                  "mtu");
2158 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2159         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2160 cmdline_parse_token_num_t cmd_config_mtu_value =
2161         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2162
2163 cmdline_parse_inst_t cmd_config_mtu = {
2164         .f = cmd_config_mtu_parsed,
2165         .data = NULL,
2166         .help_str = "port config mtu <port_id> <value>",
2167         .tokens = {
2168                 (void *)&cmd_config_mtu_port,
2169                 (void *)&cmd_config_mtu_keyword,
2170                 (void *)&cmd_config_mtu_mtu,
2171                 (void *)&cmd_config_mtu_port_id,
2172                 (void *)&cmd_config_mtu_value,
2173                 NULL,
2174         },
2175 };
2176
2177 /* *** configure rx mode *** */
2178 struct cmd_config_rx_mode_flag {
2179         cmdline_fixed_string_t port;
2180         cmdline_fixed_string_t keyword;
2181         cmdline_fixed_string_t all;
2182         cmdline_fixed_string_t name;
2183         cmdline_fixed_string_t value;
2184 };
2185
2186 static void
2187 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2188                                 __rte_unused struct cmdline *cl,
2189                                 __rte_unused void *data)
2190 {
2191         struct cmd_config_rx_mode_flag *res = parsed_result;
2192
2193         if (!all_ports_stopped()) {
2194                 printf("Please stop all ports first\n");
2195                 return;
2196         }
2197
2198         if (!strcmp(res->name, "drop-en")) {
2199                 if (!strcmp(res->value, "on"))
2200                         rx_drop_en = 1;
2201                 else if (!strcmp(res->value, "off"))
2202                         rx_drop_en = 0;
2203                 else {
2204                         printf("Unknown parameter\n");
2205                         return;
2206                 }
2207         } else {
2208                 printf("Unknown parameter\n");
2209                 return;
2210         }
2211
2212         init_port_config();
2213
2214         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2215 }
2216
2217 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2218         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2219 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2220         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2221                                                                 "config");
2222 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2223         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2224 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2225         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2226                                         "drop-en");
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2229                                                         "on#off");
2230
2231 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2232         .f = cmd_config_rx_mode_flag_parsed,
2233         .data = NULL,
2234         .help_str = "port config all drop-en on|off",
2235         .tokens = {
2236                 (void *)&cmd_config_rx_mode_flag_port,
2237                 (void *)&cmd_config_rx_mode_flag_keyword,
2238                 (void *)&cmd_config_rx_mode_flag_all,
2239                 (void *)&cmd_config_rx_mode_flag_name,
2240                 (void *)&cmd_config_rx_mode_flag_value,
2241                 NULL,
2242         },
2243 };
2244
2245 /* *** configure rss *** */
2246 struct cmd_config_rss {
2247         cmdline_fixed_string_t port;
2248         cmdline_fixed_string_t keyword;
2249         cmdline_fixed_string_t all;
2250         cmdline_fixed_string_t name;
2251         cmdline_fixed_string_t value;
2252 };
2253
2254 static void
2255 cmd_config_rss_parsed(void *parsed_result,
2256                         __rte_unused struct cmdline *cl,
2257                         __rte_unused void *data)
2258 {
2259         struct cmd_config_rss *res = parsed_result;
2260         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2261         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2262         int use_default = 0;
2263         int all_updated = 1;
2264         int diag;
2265         uint16_t i;
2266         int ret;
2267
2268         if (!strcmp(res->value, "all"))
2269                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2270                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2271                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2272                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2273         else if (!strcmp(res->value, "eth"))
2274                 rss_conf.rss_hf = ETH_RSS_ETH;
2275         else if (!strcmp(res->value, "vlan"))
2276                 rss_conf.rss_hf = ETH_RSS_VLAN;
2277         else if (!strcmp(res->value, "ip"))
2278                 rss_conf.rss_hf = ETH_RSS_IP;
2279         else if (!strcmp(res->value, "udp"))
2280                 rss_conf.rss_hf = ETH_RSS_UDP;
2281         else if (!strcmp(res->value, "tcp"))
2282                 rss_conf.rss_hf = ETH_RSS_TCP;
2283         else if (!strcmp(res->value, "sctp"))
2284                 rss_conf.rss_hf = ETH_RSS_SCTP;
2285         else if (!strcmp(res->value, "ether"))
2286                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2287         else if (!strcmp(res->value, "port"))
2288                 rss_conf.rss_hf = ETH_RSS_PORT;
2289         else if (!strcmp(res->value, "vxlan"))
2290                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2291         else if (!strcmp(res->value, "geneve"))
2292                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2293         else if (!strcmp(res->value, "nvgre"))
2294                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2295         else if (!strcmp(res->value, "l3-pre32"))
2296                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2297         else if (!strcmp(res->value, "l3-pre40"))
2298                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2299         else if (!strcmp(res->value, "l3-pre48"))
2300                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2301         else if (!strcmp(res->value, "l3-pre56"))
2302                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2303         else if (!strcmp(res->value, "l3-pre64"))
2304                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2305         else if (!strcmp(res->value, "l3-pre96"))
2306                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2307         else if (!strcmp(res->value, "l3-src-only"))
2308                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2309         else if (!strcmp(res->value, "l3-dst-only"))
2310                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2311         else if (!strcmp(res->value, "l4-src-only"))
2312                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2313         else if (!strcmp(res->value, "l4-dst-only"))
2314                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2315         else if (!strcmp(res->value, "l2-src-only"))
2316                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2317         else if (!strcmp(res->value, "l2-dst-only"))
2318                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2319         else if (!strcmp(res->value, "l2tpv3"))
2320                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2321         else if (!strcmp(res->value, "esp"))
2322                 rss_conf.rss_hf = ETH_RSS_ESP;
2323         else if (!strcmp(res->value, "ah"))
2324                 rss_conf.rss_hf = ETH_RSS_AH;
2325         else if (!strcmp(res->value, "pfcp"))
2326                 rss_conf.rss_hf = ETH_RSS_PFCP;
2327         else if (!strcmp(res->value, "pppoe"))
2328                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2329         else if (!strcmp(res->value, "gtpu"))
2330                 rss_conf.rss_hf = ETH_RSS_GTPU;
2331         else if (!strcmp(res->value, "none"))
2332                 rss_conf.rss_hf = 0;
2333         else if (!strcmp(res->value, "default"))
2334                 use_default = 1;
2335         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2336                                                 atoi(res->value) < 64)
2337                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2338         else {
2339                 printf("Unknown parameter\n");
2340                 return;
2341         }
2342         rss_conf.rss_key = NULL;
2343         /* Update global configuration for RSS types. */
2344         RTE_ETH_FOREACH_DEV(i) {
2345                 struct rte_eth_rss_conf local_rss_conf;
2346
2347                 ret = eth_dev_info_get_print_err(i, &dev_info);
2348                 if (ret != 0)
2349                         return;
2350
2351                 if (use_default)
2352                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2353
2354                 local_rss_conf = rss_conf;
2355                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2356                         dev_info.flow_type_rss_offloads;
2357                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2358                         printf("Port %u modified RSS hash function based on hardware support,"
2359                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2360                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2361                 }
2362                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2363                 if (diag < 0) {
2364                         all_updated = 0;
2365                         printf("Configuration of RSS hash at ethernet port %d "
2366                                 "failed with error (%d): %s.\n",
2367                                 i, -diag, strerror(-diag));
2368                 }
2369         }
2370         if (all_updated && !use_default) {
2371                 rss_hf = rss_conf.rss_hf;
2372                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2373         }
2374 }
2375
2376 cmdline_parse_token_string_t cmd_config_rss_port =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2378 cmdline_parse_token_string_t cmd_config_rss_keyword =
2379         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2380 cmdline_parse_token_string_t cmd_config_rss_all =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2382 cmdline_parse_token_string_t cmd_config_rss_name =
2383         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2384 cmdline_parse_token_string_t cmd_config_rss_value =
2385         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2386
2387 cmdline_parse_inst_t cmd_config_rss = {
2388         .f = cmd_config_rss_parsed,
2389         .data = NULL,
2390         .help_str = "port config all rss "
2391                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2392                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2393         .tokens = {
2394                 (void *)&cmd_config_rss_port,
2395                 (void *)&cmd_config_rss_keyword,
2396                 (void *)&cmd_config_rss_all,
2397                 (void *)&cmd_config_rss_name,
2398                 (void *)&cmd_config_rss_value,
2399                 NULL,
2400         },
2401 };
2402
2403 /* *** configure rss hash key *** */
2404 struct cmd_config_rss_hash_key {
2405         cmdline_fixed_string_t port;
2406         cmdline_fixed_string_t config;
2407         portid_t port_id;
2408         cmdline_fixed_string_t rss_hash_key;
2409         cmdline_fixed_string_t rss_type;
2410         cmdline_fixed_string_t key;
2411 };
2412
2413 static uint8_t
2414 hexa_digit_to_value(char hexa_digit)
2415 {
2416         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2417                 return (uint8_t) (hexa_digit - '0');
2418         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2419                 return (uint8_t) ((hexa_digit - 'a') + 10);
2420         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2421                 return (uint8_t) ((hexa_digit - 'A') + 10);
2422         /* Invalid hexa digit */
2423         return 0xFF;
2424 }
2425
2426 static uint8_t
2427 parse_and_check_key_hexa_digit(char *key, int idx)
2428 {
2429         uint8_t hexa_v;
2430
2431         hexa_v = hexa_digit_to_value(key[idx]);
2432         if (hexa_v == 0xFF)
2433                 printf("invalid key: character %c at position %d is not a "
2434                        "valid hexa digit\n", key[idx], idx);
2435         return hexa_v;
2436 }
2437
2438 static void
2439 cmd_config_rss_hash_key_parsed(void *parsed_result,
2440                                __rte_unused struct cmdline *cl,
2441                                __rte_unused void *data)
2442 {
2443         struct cmd_config_rss_hash_key *res = parsed_result;
2444         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2445         uint8_t xdgt0;
2446         uint8_t xdgt1;
2447         int i;
2448         struct rte_eth_dev_info dev_info;
2449         uint8_t hash_key_size;
2450         uint32_t key_len;
2451         int ret;
2452
2453         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2454         if (ret != 0)
2455                 return;
2456
2457         if (dev_info.hash_key_size > 0 &&
2458                         dev_info.hash_key_size <= sizeof(hash_key))
2459                 hash_key_size = dev_info.hash_key_size;
2460         else {
2461                 printf("dev_info did not provide a valid hash key size\n");
2462                 return;
2463         }
2464         /* Check the length of the RSS hash key */
2465         key_len = strlen(res->key);
2466         if (key_len != (hash_key_size * 2)) {
2467                 printf("key length: %d invalid - key must be a string of %d"
2468                            " hexa-decimal numbers\n",
2469                            (int) key_len, hash_key_size * 2);
2470                 return;
2471         }
2472         /* Translate RSS hash key into binary representation */
2473         for (i = 0; i < hash_key_size; i++) {
2474                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2475                 if (xdgt0 == 0xFF)
2476                         return;
2477                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2478                 if (xdgt1 == 0xFF)
2479                         return;
2480                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2481         }
2482         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2483                         hash_key_size);
2484 }
2485
2486 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2487         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2488 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2489         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2490                                  "config");
2491 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2492         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2493 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2494         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2495                                  rss_hash_key, "rss-hash-key");
2496 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2498                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2499                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2500                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2501                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2502                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2503                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2504                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2505 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2506         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2507
2508 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2509         .f = cmd_config_rss_hash_key_parsed,
2510         .data = NULL,
2511         .help_str = "port config <port_id> rss-hash-key "
2512                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2513                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2514                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2515                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2516                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2517                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2518                 "<string of hex digits (variable length, NIC dependent)>",
2519         .tokens = {
2520                 (void *)&cmd_config_rss_hash_key_port,
2521                 (void *)&cmd_config_rss_hash_key_config,
2522                 (void *)&cmd_config_rss_hash_key_port_id,
2523                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2524                 (void *)&cmd_config_rss_hash_key_rss_type,
2525                 (void *)&cmd_config_rss_hash_key_value,
2526                 NULL,
2527         },
2528 };
2529
2530 /* *** configure port rxq/txq ring size *** */
2531 struct cmd_config_rxtx_ring_size {
2532         cmdline_fixed_string_t port;
2533         cmdline_fixed_string_t config;
2534         portid_t portid;
2535         cmdline_fixed_string_t rxtxq;
2536         uint16_t qid;
2537         cmdline_fixed_string_t rsize;
2538         uint16_t size;
2539 };
2540
2541 static void
2542 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2543                                  __rte_unused struct cmdline *cl,
2544                                  __rte_unused void *data)
2545 {
2546         struct cmd_config_rxtx_ring_size *res = parsed_result;
2547         struct rte_port *port;
2548         uint8_t isrx;
2549
2550         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2551                 return;
2552
2553         if (res->portid == (portid_t)RTE_PORT_ALL) {
2554                 printf("Invalid port id\n");
2555                 return;
2556         }
2557
2558         port = &ports[res->portid];
2559
2560         if (!strcmp(res->rxtxq, "rxq"))
2561                 isrx = 1;
2562         else if (!strcmp(res->rxtxq, "txq"))
2563                 isrx = 0;
2564         else {
2565                 printf("Unknown parameter\n");
2566                 return;
2567         }
2568
2569         if (isrx && rx_queue_id_is_invalid(res->qid))
2570                 return;
2571         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2572                 return;
2573
2574         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2575                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2576                        rx_free_thresh);
2577                 return;
2578         }
2579
2580         if (isrx)
2581                 port->nb_rx_desc[res->qid] = res->size;
2582         else
2583                 port->nb_tx_desc[res->qid] = res->size;
2584
2585         cmd_reconfig_device_queue(res->portid, 0, 1);
2586 }
2587
2588 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2589         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2590                                  port, "port");
2591 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2592         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2593                                  config, "config");
2594 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2595         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2596                                  portid, UINT16);
2597 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2598         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2599                                  rxtxq, "rxq#txq");
2600 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2601         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2602                               qid, UINT16);
2603 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2604         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2605                                  rsize, "ring_size");
2606 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2607         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2608                               size, UINT16);
2609
2610 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2611         .f = cmd_config_rxtx_ring_size_parsed,
2612         .data = NULL,
2613         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2614         .tokens = {
2615                 (void *)&cmd_config_rxtx_ring_size_port,
2616                 (void *)&cmd_config_rxtx_ring_size_config,
2617                 (void *)&cmd_config_rxtx_ring_size_portid,
2618                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2619                 (void *)&cmd_config_rxtx_ring_size_qid,
2620                 (void *)&cmd_config_rxtx_ring_size_rsize,
2621                 (void *)&cmd_config_rxtx_ring_size_size,
2622                 NULL,
2623         },
2624 };
2625
2626 /* *** configure port rxq/txq start/stop *** */
2627 struct cmd_config_rxtx_queue {
2628         cmdline_fixed_string_t port;
2629         portid_t portid;
2630         cmdline_fixed_string_t rxtxq;
2631         uint16_t qid;
2632         cmdline_fixed_string_t opname;
2633 };
2634
2635 static void
2636 cmd_config_rxtx_queue_parsed(void *parsed_result,
2637                         __rte_unused struct cmdline *cl,
2638                         __rte_unused void *data)
2639 {
2640         struct cmd_config_rxtx_queue *res = parsed_result;
2641         uint8_t isrx;
2642         uint8_t isstart;
2643         int ret = 0;
2644
2645         if (test_done == 0) {
2646                 printf("Please stop forwarding first\n");
2647                 return;
2648         }
2649
2650         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2651                 return;
2652
2653         if (port_is_started(res->portid) != 1) {
2654                 printf("Please start port %u first\n", res->portid);
2655                 return;
2656         }
2657
2658         if (!strcmp(res->rxtxq, "rxq"))
2659                 isrx = 1;
2660         else if (!strcmp(res->rxtxq, "txq"))
2661                 isrx = 0;
2662         else {
2663                 printf("Unknown parameter\n");
2664                 return;
2665         }
2666
2667         if (isrx && rx_queue_id_is_invalid(res->qid))
2668                 return;
2669         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2670                 return;
2671
2672         if (!strcmp(res->opname, "start"))
2673                 isstart = 1;
2674         else if (!strcmp(res->opname, "stop"))
2675                 isstart = 0;
2676         else {
2677                 printf("Unknown parameter\n");
2678                 return;
2679         }
2680
2681         if (isstart && isrx)
2682                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2683         else if (!isstart && isrx)
2684                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2685         else if (isstart && !isrx)
2686                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2687         else
2688                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2689
2690         if (ret == -ENOTSUP)
2691                 printf("Function not supported in PMD driver\n");
2692 }
2693
2694 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2695         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2696 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2697         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2698 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2699         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2700 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2701         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2702 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2703         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2704                                                 "start#stop");
2705
2706 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2707         .f = cmd_config_rxtx_queue_parsed,
2708         .data = NULL,
2709         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2710         .tokens = {
2711                 (void *)&cmd_config_rxtx_queue_port,
2712                 (void *)&cmd_config_rxtx_queue_portid,
2713                 (void *)&cmd_config_rxtx_queue_rxtxq,
2714                 (void *)&cmd_config_rxtx_queue_qid,
2715                 (void *)&cmd_config_rxtx_queue_opname,
2716                 NULL,
2717         },
2718 };
2719
2720 /* *** configure port rxq/txq deferred start on/off *** */
2721 struct cmd_config_deferred_start_rxtx_queue {
2722         cmdline_fixed_string_t port;
2723         portid_t port_id;
2724         cmdline_fixed_string_t rxtxq;
2725         uint16_t qid;
2726         cmdline_fixed_string_t opname;
2727         cmdline_fixed_string_t state;
2728 };
2729
2730 static void
2731 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2732                         __rte_unused struct cmdline *cl,
2733                         __rte_unused void *data)
2734 {
2735         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2736         struct rte_port *port;
2737         uint8_t isrx;
2738         uint8_t ison;
2739         uint8_t needreconfig = 0;
2740
2741         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2742                 return;
2743
2744         if (port_is_started(res->port_id) != 0) {
2745                 printf("Please stop port %u first\n", res->port_id);
2746                 return;
2747         }
2748
2749         port = &ports[res->port_id];
2750
2751         isrx = !strcmp(res->rxtxq, "rxq");
2752
2753         if (isrx && rx_queue_id_is_invalid(res->qid))
2754                 return;
2755         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2756                 return;
2757
2758         ison = !strcmp(res->state, "on");
2759
2760         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2761                 port->rx_conf[res->qid].rx_deferred_start = ison;
2762                 needreconfig = 1;
2763         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2764                 port->tx_conf[res->qid].tx_deferred_start = ison;
2765                 needreconfig = 1;
2766         }
2767
2768         if (needreconfig)
2769                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2770 }
2771
2772 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2773         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2774                                                 port, "port");
2775 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2776         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2777                                                 port_id, UINT16);
2778 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2779         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2780                                                 rxtxq, "rxq#txq");
2781 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2782         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2783                                                 qid, UINT16);
2784 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2785         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2786                                                 opname, "deferred_start");
2787 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2788         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2789                                                 state, "on#off");
2790
2791 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2792         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2793         .data = NULL,
2794         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2795         .tokens = {
2796                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2797                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2798                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2799                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2800                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2801                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2802                 NULL,
2803         },
2804 };
2805
2806 /* *** configure port rxq/txq setup *** */
2807 struct cmd_setup_rxtx_queue {
2808         cmdline_fixed_string_t port;
2809         portid_t portid;
2810         cmdline_fixed_string_t rxtxq;
2811         uint16_t qid;
2812         cmdline_fixed_string_t setup;
2813 };
2814
2815 /* Common CLI fields for queue setup */
2816 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2817         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2818 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2819         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2820 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2821         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2822 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2823         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2824 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2825         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2826
2827 static void
2828 cmd_setup_rxtx_queue_parsed(
2829         void *parsed_result,
2830         __rte_unused struct cmdline *cl,
2831         __rte_unused void *data)
2832 {
2833         struct cmd_setup_rxtx_queue *res = parsed_result;
2834         struct rte_port *port;
2835         struct rte_mempool *mp;
2836         unsigned int socket_id;
2837         uint8_t isrx = 0;
2838         int ret;
2839
2840         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2841                 return;
2842
2843         if (res->portid == (portid_t)RTE_PORT_ALL) {
2844                 printf("Invalid port id\n");
2845                 return;
2846         }
2847
2848         if (!strcmp(res->rxtxq, "rxq"))
2849                 isrx = 1;
2850         else if (!strcmp(res->rxtxq, "txq"))
2851                 isrx = 0;
2852         else {
2853                 printf("Unknown parameter\n");
2854                 return;
2855         }
2856
2857         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2858                 printf("Invalid rx queue\n");
2859                 return;
2860         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2861                 printf("Invalid tx queue\n");
2862                 return;
2863         }
2864
2865         port = &ports[res->portid];
2866         if (isrx) {
2867                 socket_id = rxring_numa[res->portid];
2868                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2869                         socket_id = port->socket_id;
2870
2871                 mp = mbuf_pool_find(socket_id);
2872                 if (mp == NULL) {
2873                         printf("Failed to setup RX queue: "
2874                                 "No mempool allocation"
2875                                 " on the socket %d\n",
2876                                 rxring_numa[res->portid]);
2877                         return;
2878                 }
2879                 ret = rte_eth_rx_queue_setup(res->portid,
2880                                              res->qid,
2881                                              port->nb_rx_desc[res->qid],
2882                                              socket_id,
2883                                              &port->rx_conf[res->qid],
2884                                              mp);
2885                 if (ret)
2886                         printf("Failed to setup RX queue\n");
2887         } else {
2888                 socket_id = txring_numa[res->portid];
2889                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2890                         socket_id = port->socket_id;
2891
2892                 ret = rte_eth_tx_queue_setup(res->portid,
2893                                              res->qid,
2894                                              port->nb_tx_desc[res->qid],
2895                                              socket_id,
2896                                              &port->tx_conf[res->qid]);
2897                 if (ret)
2898                         printf("Failed to setup TX queue\n");
2899         }
2900 }
2901
2902 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2903         .f = cmd_setup_rxtx_queue_parsed,
2904         .data = NULL,
2905         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2906         .tokens = {
2907                 (void *)&cmd_setup_rxtx_queue_port,
2908                 (void *)&cmd_setup_rxtx_queue_portid,
2909                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2910                 (void *)&cmd_setup_rxtx_queue_qid,
2911                 (void *)&cmd_setup_rxtx_queue_setup,
2912                 NULL,
2913         },
2914 };
2915
2916
2917 /* *** Configure RSS RETA *** */
2918 struct cmd_config_rss_reta {
2919         cmdline_fixed_string_t port;
2920         cmdline_fixed_string_t keyword;
2921         portid_t port_id;
2922         cmdline_fixed_string_t name;
2923         cmdline_fixed_string_t list_name;
2924         cmdline_fixed_string_t list_of_items;
2925 };
2926
2927 static int
2928 parse_reta_config(const char *str,
2929                   struct rte_eth_rss_reta_entry64 *reta_conf,
2930                   uint16_t nb_entries)
2931 {
2932         int i;
2933         unsigned size;
2934         uint16_t hash_index, idx, shift;
2935         uint16_t nb_queue;
2936         char s[256];
2937         const char *p, *p0 = str;
2938         char *end;
2939         enum fieldnames {
2940                 FLD_HASH_INDEX = 0,
2941                 FLD_QUEUE,
2942                 _NUM_FLD
2943         };
2944         unsigned long int_fld[_NUM_FLD];
2945         char *str_fld[_NUM_FLD];
2946
2947         while ((p = strchr(p0,'(')) != NULL) {
2948                 ++p;
2949                 if((p0 = strchr(p,')')) == NULL)
2950                         return -1;
2951
2952                 size = p0 - p;
2953                 if(size >= sizeof(s))
2954                         return -1;
2955
2956                 snprintf(s, sizeof(s), "%.*s", size, p);
2957                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2958                         return -1;
2959                 for (i = 0; i < _NUM_FLD; i++) {
2960                         errno = 0;
2961                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2962                         if (errno != 0 || end == str_fld[i] ||
2963                                         int_fld[i] > 65535)
2964                                 return -1;
2965                 }
2966
2967                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2968                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2969
2970                 if (hash_index >= nb_entries) {
2971                         printf("Invalid RETA hash index=%d\n", hash_index);
2972                         return -1;
2973                 }
2974
2975                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2976                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2977                 reta_conf[idx].mask |= (1ULL << shift);
2978                 reta_conf[idx].reta[shift] = nb_queue;
2979         }
2980
2981         return 0;
2982 }
2983
2984 static void
2985 cmd_set_rss_reta_parsed(void *parsed_result,
2986                         __rte_unused struct cmdline *cl,
2987                         __rte_unused void *data)
2988 {
2989         int ret;
2990         struct rte_eth_dev_info dev_info;
2991         struct rte_eth_rss_reta_entry64 reta_conf[8];
2992         struct cmd_config_rss_reta *res = parsed_result;
2993
2994         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2995         if (ret != 0)
2996                 return;
2997
2998         if (dev_info.reta_size == 0) {
2999                 printf("Redirection table size is 0 which is "
3000                                         "invalid for RSS\n");
3001                 return;
3002         } else
3003                 printf("The reta size of port %d is %u\n",
3004                         res->port_id, dev_info.reta_size);
3005         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3006                 printf("Currently do not support more than %u entries of "
3007                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3008                 return;
3009         }
3010
3011         memset(reta_conf, 0, sizeof(reta_conf));
3012         if (!strcmp(res->list_name, "reta")) {
3013                 if (parse_reta_config(res->list_of_items, reta_conf,
3014                                                 dev_info.reta_size)) {
3015                         printf("Invalid RSS Redirection Table "
3016                                         "config entered\n");
3017                         return;
3018                 }
3019                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3020                                 reta_conf, dev_info.reta_size);
3021                 if (ret != 0)
3022                         printf("Bad redirection table parameter, "
3023                                         "return code = %d \n", ret);
3024         }
3025 }
3026
3027 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3029 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3030         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3031 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3032         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3033 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3034         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3035 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3036         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3037 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3038         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3039                                  NULL);
3040 cmdline_parse_inst_t cmd_config_rss_reta = {
3041         .f = cmd_set_rss_reta_parsed,
3042         .data = NULL,
3043         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3044         .tokens = {
3045                 (void *)&cmd_config_rss_reta_port,
3046                 (void *)&cmd_config_rss_reta_keyword,
3047                 (void *)&cmd_config_rss_reta_port_id,
3048                 (void *)&cmd_config_rss_reta_name,
3049                 (void *)&cmd_config_rss_reta_list_name,
3050                 (void *)&cmd_config_rss_reta_list_of_items,
3051                 NULL,
3052         },
3053 };
3054
3055 /* *** SHOW PORT RETA INFO *** */
3056 struct cmd_showport_reta {
3057         cmdline_fixed_string_t show;
3058         cmdline_fixed_string_t port;
3059         portid_t port_id;
3060         cmdline_fixed_string_t rss;
3061         cmdline_fixed_string_t reta;
3062         uint16_t size;
3063         cmdline_fixed_string_t list_of_items;
3064 };
3065
3066 static int
3067 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3068                            uint16_t nb_entries,
3069                            char *str)
3070 {
3071         uint32_t size;
3072         const char *p, *p0 = str;
3073         char s[256];
3074         char *end;
3075         char *str_fld[8];
3076         uint16_t i;
3077         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3078                         RTE_RETA_GROUP_SIZE;
3079         int ret;
3080
3081         p = strchr(p0, '(');
3082         if (p == NULL)
3083                 return -1;
3084         p++;
3085         p0 = strchr(p, ')');
3086         if (p0 == NULL)
3087                 return -1;
3088         size = p0 - p;
3089         if (size >= sizeof(s)) {
3090                 printf("The string size exceeds the internal buffer size\n");
3091                 return -1;
3092         }
3093         snprintf(s, sizeof(s), "%.*s", size, p);
3094         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3095         if (ret <= 0 || ret != num) {
3096                 printf("The bits of masks do not match the number of "
3097                                         "reta entries: %u\n", num);
3098                 return -1;
3099         }
3100         for (i = 0; i < ret; i++)
3101                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3102
3103         return 0;
3104 }
3105
3106 static void
3107 cmd_showport_reta_parsed(void *parsed_result,
3108                          __rte_unused struct cmdline *cl,
3109                          __rte_unused void *data)
3110 {
3111         struct cmd_showport_reta *res = parsed_result;
3112         struct rte_eth_rss_reta_entry64 reta_conf[8];
3113         struct rte_eth_dev_info dev_info;
3114         uint16_t max_reta_size;
3115         int ret;
3116
3117         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3118         if (ret != 0)
3119                 return;
3120
3121         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3122         if (res->size == 0 || res->size > max_reta_size) {
3123                 printf("Invalid redirection table size: %u (1-%u)\n",
3124                         res->size, max_reta_size);
3125                 return;
3126         }
3127
3128         memset(reta_conf, 0, sizeof(reta_conf));
3129         if (showport_parse_reta_config(reta_conf, res->size,
3130                                 res->list_of_items) < 0) {
3131                 printf("Invalid string: %s for reta masks\n",
3132                                         res->list_of_items);
3133                 return;
3134         }
3135         port_rss_reta_info(res->port_id, reta_conf, res->size);
3136 }
3137
3138 cmdline_parse_token_string_t cmd_showport_reta_show =
3139         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3140 cmdline_parse_token_string_t cmd_showport_reta_port =
3141         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3142 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3143         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3144 cmdline_parse_token_string_t cmd_showport_reta_rss =
3145         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3146 cmdline_parse_token_string_t cmd_showport_reta_reta =
3147         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3148 cmdline_parse_token_num_t cmd_showport_reta_size =
3149         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3150 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3151         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3152                                         list_of_items, NULL);
3153
3154 cmdline_parse_inst_t cmd_showport_reta = {
3155         .f = cmd_showport_reta_parsed,
3156         .data = NULL,
3157         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3158         .tokens = {
3159                 (void *)&cmd_showport_reta_show,
3160                 (void *)&cmd_showport_reta_port,
3161                 (void *)&cmd_showport_reta_port_id,
3162                 (void *)&cmd_showport_reta_rss,
3163                 (void *)&cmd_showport_reta_reta,
3164                 (void *)&cmd_showport_reta_size,
3165                 (void *)&cmd_showport_reta_list_of_items,
3166                 NULL,
3167         },
3168 };
3169
3170 /* *** Show RSS hash configuration *** */
3171 struct cmd_showport_rss_hash {
3172         cmdline_fixed_string_t show;
3173         cmdline_fixed_string_t port;
3174         portid_t port_id;
3175         cmdline_fixed_string_t rss_hash;
3176         cmdline_fixed_string_t rss_type;
3177         cmdline_fixed_string_t key; /* optional argument */
3178 };
3179
3180 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3181                                 __rte_unused struct cmdline *cl,
3182                                 void *show_rss_key)
3183 {
3184         struct cmd_showport_rss_hash *res = parsed_result;
3185
3186         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3187 }
3188
3189 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3190         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3191 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3192         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3193 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3194         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3195 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3196         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3197                                  "rss-hash");
3198 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3199         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3200
3201 cmdline_parse_inst_t cmd_showport_rss_hash = {
3202         .f = cmd_showport_rss_hash_parsed,
3203         .data = NULL,
3204         .help_str = "show port <port_id> rss-hash",
3205         .tokens = {
3206                 (void *)&cmd_showport_rss_hash_show,
3207                 (void *)&cmd_showport_rss_hash_port,
3208                 (void *)&cmd_showport_rss_hash_port_id,
3209                 (void *)&cmd_showport_rss_hash_rss_hash,
3210                 NULL,
3211         },
3212 };
3213
3214 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3215         .f = cmd_showport_rss_hash_parsed,
3216         .data = (void *)1,
3217         .help_str = "show port <port_id> rss-hash key",
3218         .tokens = {
3219                 (void *)&cmd_showport_rss_hash_show,
3220                 (void *)&cmd_showport_rss_hash_port,
3221                 (void *)&cmd_showport_rss_hash_port_id,
3222                 (void *)&cmd_showport_rss_hash_rss_hash,
3223                 (void *)&cmd_showport_rss_hash_rss_key,
3224                 NULL,
3225         },
3226 };
3227
3228 /* *** Configure DCB *** */
3229 struct cmd_config_dcb {
3230         cmdline_fixed_string_t port;
3231         cmdline_fixed_string_t config;
3232         portid_t port_id;
3233         cmdline_fixed_string_t dcb;
3234         cmdline_fixed_string_t vt;
3235         cmdline_fixed_string_t vt_en;
3236         uint8_t num_tcs;
3237         cmdline_fixed_string_t pfc;
3238         cmdline_fixed_string_t pfc_en;
3239 };
3240
3241 static void
3242 cmd_config_dcb_parsed(void *parsed_result,
3243                         __rte_unused struct cmdline *cl,
3244                         __rte_unused void *data)
3245 {
3246         struct cmd_config_dcb *res = parsed_result;
3247         portid_t port_id = res->port_id;
3248         struct rte_port *port;
3249         uint8_t pfc_en;
3250         int ret;
3251
3252         port = &ports[port_id];
3253         /** Check if the port is not started **/
3254         if (port->port_status != RTE_PORT_STOPPED) {
3255                 printf("Please stop port %d first\n", port_id);
3256                 return;
3257         }
3258
3259         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3260                 printf("The invalid number of traffic class,"
3261                         " only 4 or 8 allowed.\n");
3262                 return;
3263         }
3264
3265         if (nb_fwd_lcores < res->num_tcs) {
3266                 printf("nb_cores shouldn't be less than number of TCs.\n");
3267                 return;
3268         }
3269         if (!strncmp(res->pfc_en, "on", 2))
3270                 pfc_en = 1;
3271         else
3272                 pfc_en = 0;
3273
3274         /* DCB in VT mode */
3275         if (!strncmp(res->vt_en, "on", 2))
3276                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3277                                 (enum rte_eth_nb_tcs)res->num_tcs,
3278                                 pfc_en);
3279         else
3280                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3281                                 (enum rte_eth_nb_tcs)res->num_tcs,
3282                                 pfc_en);
3283
3284
3285         if (ret != 0) {
3286                 printf("Cannot initialize network ports.\n");
3287                 return;
3288         }
3289
3290         cmd_reconfig_device_queue(port_id, 1, 1);
3291 }
3292
3293 cmdline_parse_token_string_t cmd_config_dcb_port =
3294         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3295 cmdline_parse_token_string_t cmd_config_dcb_config =
3296         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3297 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3298         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3299 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3300         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3301 cmdline_parse_token_string_t cmd_config_dcb_vt =
3302         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3303 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3305 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3306         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3307 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3308         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3309 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3310         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3311
3312 cmdline_parse_inst_t cmd_config_dcb = {
3313         .f = cmd_config_dcb_parsed,
3314         .data = NULL,
3315         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3316         .tokens = {
3317                 (void *)&cmd_config_dcb_port,
3318                 (void *)&cmd_config_dcb_config,
3319                 (void *)&cmd_config_dcb_port_id,
3320                 (void *)&cmd_config_dcb_dcb,
3321                 (void *)&cmd_config_dcb_vt,
3322                 (void *)&cmd_config_dcb_vt_en,
3323                 (void *)&cmd_config_dcb_num_tcs,
3324                 (void *)&cmd_config_dcb_pfc,
3325                 (void *)&cmd_config_dcb_pfc_en,
3326                 NULL,
3327         },
3328 };
3329
3330 /* *** configure number of packets per burst *** */
3331 struct cmd_config_burst {
3332         cmdline_fixed_string_t port;
3333         cmdline_fixed_string_t keyword;
3334         cmdline_fixed_string_t all;
3335         cmdline_fixed_string_t name;
3336         uint16_t value;
3337 };
3338
3339 static void
3340 cmd_config_burst_parsed(void *parsed_result,
3341                         __rte_unused struct cmdline *cl,
3342                         __rte_unused void *data)
3343 {
3344         struct cmd_config_burst *res = parsed_result;
3345         struct rte_eth_dev_info dev_info;
3346         uint16_t rec_nb_pkts;
3347         int ret;
3348
3349         if (!all_ports_stopped()) {
3350                 printf("Please stop all ports first\n");
3351                 return;
3352         }
3353
3354         if (!strcmp(res->name, "burst")) {
3355                 if (res->value == 0) {
3356                         /* If user gives a value of zero, query the PMD for
3357                          * its recommended Rx burst size. Testpmd uses a single
3358                          * size for all ports, so assume all ports are the same
3359                          * NIC model and use the values from Port 0.
3360                          */
3361                         ret = eth_dev_info_get_print_err(0, &dev_info);
3362                         if (ret != 0)
3363                                 return;
3364
3365                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3366
3367                         if (rec_nb_pkts == 0) {
3368                                 printf("PMD does not recommend a burst size.\n"
3369                                         "User provided value must be between"
3370                                         " 1 and %d\n", MAX_PKT_BURST);
3371                                 return;
3372                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3373                                 printf("PMD recommended burst size of %d"
3374                                         " exceeds maximum value of %d\n",
3375                                         rec_nb_pkts, MAX_PKT_BURST);
3376                                 return;
3377                         }
3378                         printf("Using PMD-provided burst value of %d\n",
3379                                 rec_nb_pkts);
3380                         nb_pkt_per_burst = rec_nb_pkts;
3381                 } else if (res->value > MAX_PKT_BURST) {
3382                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3383                         return;
3384                 } else
3385                         nb_pkt_per_burst = res->value;
3386         } else {
3387                 printf("Unknown parameter\n");
3388                 return;
3389         }
3390
3391         init_port_config();
3392
3393         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3394 }
3395
3396 cmdline_parse_token_string_t cmd_config_burst_port =
3397         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3398 cmdline_parse_token_string_t cmd_config_burst_keyword =
3399         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3400 cmdline_parse_token_string_t cmd_config_burst_all =
3401         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3402 cmdline_parse_token_string_t cmd_config_burst_name =
3403         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3404 cmdline_parse_token_num_t cmd_config_burst_value =
3405         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3406
3407 cmdline_parse_inst_t cmd_config_burst = {
3408         .f = cmd_config_burst_parsed,
3409         .data = NULL,
3410         .help_str = "port config all burst <value>",
3411         .tokens = {
3412                 (void *)&cmd_config_burst_port,
3413                 (void *)&cmd_config_burst_keyword,
3414                 (void *)&cmd_config_burst_all,
3415                 (void *)&cmd_config_burst_name,
3416                 (void *)&cmd_config_burst_value,
3417                 NULL,
3418         },
3419 };
3420
3421 /* *** configure rx/tx queues *** */
3422 struct cmd_config_thresh {
3423         cmdline_fixed_string_t port;
3424         cmdline_fixed_string_t keyword;
3425         cmdline_fixed_string_t all;
3426         cmdline_fixed_string_t name;
3427         uint8_t value;
3428 };
3429
3430 static void
3431 cmd_config_thresh_parsed(void *parsed_result,
3432                         __rte_unused struct cmdline *cl,
3433                         __rte_unused void *data)
3434 {
3435         struct cmd_config_thresh *res = parsed_result;
3436
3437         if (!all_ports_stopped()) {
3438                 printf("Please stop all ports first\n");
3439                 return;
3440         }
3441
3442         if (!strcmp(res->name, "txpt"))
3443                 tx_pthresh = res->value;
3444         else if(!strcmp(res->name, "txht"))
3445                 tx_hthresh = res->value;
3446         else if(!strcmp(res->name, "txwt"))
3447                 tx_wthresh = res->value;
3448         else if(!strcmp(res->name, "rxpt"))
3449                 rx_pthresh = res->value;
3450         else if(!strcmp(res->name, "rxht"))
3451                 rx_hthresh = res->value;
3452         else if(!strcmp(res->name, "rxwt"))
3453                 rx_wthresh = res->value;
3454         else {
3455                 printf("Unknown parameter\n");
3456                 return;
3457         }
3458
3459         init_port_config();
3460
3461         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3462 }
3463
3464 cmdline_parse_token_string_t cmd_config_thresh_port =
3465         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3466 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3467         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3468 cmdline_parse_token_string_t cmd_config_thresh_all =
3469         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3470 cmdline_parse_token_string_t cmd_config_thresh_name =
3471         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3472                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3473 cmdline_parse_token_num_t cmd_config_thresh_value =
3474         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3475
3476 cmdline_parse_inst_t cmd_config_thresh = {
3477         .f = cmd_config_thresh_parsed,
3478         .data = NULL,
3479         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3480         .tokens = {
3481                 (void *)&cmd_config_thresh_port,
3482                 (void *)&cmd_config_thresh_keyword,
3483                 (void *)&cmd_config_thresh_all,
3484                 (void *)&cmd_config_thresh_name,
3485                 (void *)&cmd_config_thresh_value,
3486                 NULL,
3487         },
3488 };
3489
3490 /* *** configure free/rs threshold *** */
3491 struct cmd_config_threshold {
3492         cmdline_fixed_string_t port;
3493         cmdline_fixed_string_t keyword;
3494         cmdline_fixed_string_t all;
3495         cmdline_fixed_string_t name;
3496         uint16_t value;
3497 };
3498
3499 static void
3500 cmd_config_threshold_parsed(void *parsed_result,
3501                         __rte_unused struct cmdline *cl,
3502                         __rte_unused void *data)
3503 {
3504         struct cmd_config_threshold *res = parsed_result;
3505
3506         if (!all_ports_stopped()) {
3507                 printf("Please stop all ports first\n");
3508                 return;
3509         }
3510
3511         if (!strcmp(res->name, "txfreet"))
3512                 tx_free_thresh = res->value;
3513         else if (!strcmp(res->name, "txrst"))
3514                 tx_rs_thresh = res->value;
3515         else if (!strcmp(res->name, "rxfreet"))
3516                 rx_free_thresh = res->value;
3517         else {
3518                 printf("Unknown parameter\n");
3519                 return;
3520         }
3521
3522         init_port_config();
3523
3524         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3525 }
3526
3527 cmdline_parse_token_string_t cmd_config_threshold_port =
3528         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3529 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3530         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3531                                                                 "config");
3532 cmdline_parse_token_string_t cmd_config_threshold_all =
3533         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3534 cmdline_parse_token_string_t cmd_config_threshold_name =
3535         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3536                                                 "txfreet#txrst#rxfreet");
3537 cmdline_parse_token_num_t cmd_config_threshold_value =
3538         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3539
3540 cmdline_parse_inst_t cmd_config_threshold = {
3541         .f = cmd_config_threshold_parsed,
3542         .data = NULL,
3543         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3544         .tokens = {
3545                 (void *)&cmd_config_threshold_port,
3546                 (void *)&cmd_config_threshold_keyword,
3547                 (void *)&cmd_config_threshold_all,
3548                 (void *)&cmd_config_threshold_name,
3549                 (void *)&cmd_config_threshold_value,
3550                 NULL,
3551         },
3552 };
3553
3554 /* *** stop *** */
3555 struct cmd_stop_result {
3556         cmdline_fixed_string_t stop;
3557 };
3558
3559 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3560                             __rte_unused struct cmdline *cl,
3561                             __rte_unused void *data)
3562 {
3563         stop_packet_forwarding();
3564 }
3565
3566 cmdline_parse_token_string_t cmd_stop_stop =
3567         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3568
3569 cmdline_parse_inst_t cmd_stop = {
3570         .f = cmd_stop_parsed,
3571         .data = NULL,
3572         .help_str = "stop: Stop packet forwarding",
3573         .tokens = {
3574                 (void *)&cmd_stop_stop,
3575                 NULL,
3576         },
3577 };
3578
3579 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3580
3581 unsigned int
3582 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3583                 unsigned int *parsed_items, int check_unique_values)
3584 {
3585         unsigned int nb_item;
3586         unsigned int value;
3587         unsigned int i;
3588         unsigned int j;
3589         int value_ok;
3590         char c;
3591
3592         /*
3593          * First parse all items in the list and store their value.
3594          */
3595         value = 0;
3596         nb_item = 0;
3597         value_ok = 0;
3598         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3599                 c = str[i];
3600                 if ((c >= '0') && (c <= '9')) {
3601                         value = (unsigned int) (value * 10 + (c - '0'));
3602                         value_ok = 1;
3603                         continue;
3604                 }
3605                 if (c != ',') {
3606                         printf("character %c is not a decimal digit\n", c);
3607                         return 0;
3608                 }
3609                 if (! value_ok) {
3610                         printf("No valid value before comma\n");
3611                         return 0;
3612                 }
3613                 if (nb_item < max_items) {
3614                         parsed_items[nb_item] = value;
3615                         value_ok = 0;
3616                         value = 0;
3617                 }
3618                 nb_item++;
3619         }
3620         if (nb_item >= max_items) {
3621                 printf("Number of %s = %u > %u (maximum items)\n",
3622                        item_name, nb_item + 1, max_items);
3623                 return 0;
3624         }
3625         parsed_items[nb_item++] = value;
3626         if (! check_unique_values)
3627                 return nb_item;
3628
3629         /*
3630          * Then, check that all values in the list are differents.
3631          * No optimization here...
3632          */
3633         for (i = 0; i < nb_item; i++) {
3634                 for (j = i + 1; j < nb_item; j++) {
3635                         if (parsed_items[j] == parsed_items[i]) {
3636                                 printf("duplicated %s %u at index %u and %u\n",
3637                                        item_name, parsed_items[i], i, j);
3638                                 return 0;
3639                         }
3640                 }
3641         }
3642         return nb_item;
3643 }
3644
3645 struct cmd_set_list_result {
3646         cmdline_fixed_string_t cmd_keyword;
3647         cmdline_fixed_string_t list_name;
3648         cmdline_fixed_string_t list_of_items;
3649 };
3650
3651 static void cmd_set_list_parsed(void *parsed_result,
3652                                 __rte_unused struct cmdline *cl,
3653                                 __rte_unused void *data)
3654 {
3655         struct cmd_set_list_result *res;
3656         union {
3657                 unsigned int lcorelist[RTE_MAX_LCORE];
3658                 unsigned int portlist[RTE_MAX_ETHPORTS];
3659         } parsed_items;
3660         unsigned int nb_item;
3661
3662         if (test_done == 0) {
3663                 printf("Please stop forwarding first\n");
3664                 return;
3665         }
3666
3667         res = parsed_result;
3668         if (!strcmp(res->list_name, "corelist")) {
3669                 nb_item = parse_item_list(res->list_of_items, "core",
3670                                           RTE_MAX_LCORE,
3671                                           parsed_items.lcorelist, 1);
3672                 if (nb_item > 0) {
3673                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3674                         fwd_config_setup();
3675                 }
3676                 return;
3677         }
3678         if (!strcmp(res->list_name, "portlist")) {
3679                 nb_item = parse_item_list(res->list_of_items, "port",
3680                                           RTE_MAX_ETHPORTS,
3681                                           parsed_items.portlist, 1);
3682                 if (nb_item > 0) {
3683                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3684                         fwd_config_setup();
3685                 }
3686         }
3687 }
3688
3689 cmdline_parse_token_string_t cmd_set_list_keyword =
3690         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3691                                  "set");
3692 cmdline_parse_token_string_t cmd_set_list_name =
3693         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3694                                  "corelist#portlist");
3695 cmdline_parse_token_string_t cmd_set_list_of_items =
3696         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3697                                  NULL);
3698
3699 cmdline_parse_inst_t cmd_set_fwd_list = {
3700         .f = cmd_set_list_parsed,
3701         .data = NULL,
3702         .help_str = "set corelist|portlist <list0[,list1]*>",
3703         .tokens = {
3704                 (void *)&cmd_set_list_keyword,
3705                 (void *)&cmd_set_list_name,
3706                 (void *)&cmd_set_list_of_items,
3707                 NULL,
3708         },
3709 };
3710
3711 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3712
3713 struct cmd_setmask_result {
3714         cmdline_fixed_string_t set;
3715         cmdline_fixed_string_t mask;
3716         uint64_t hexavalue;
3717 };
3718
3719 static void cmd_set_mask_parsed(void *parsed_result,
3720                                 __rte_unused struct cmdline *cl,
3721                                 __rte_unused void *data)
3722 {
3723         struct cmd_setmask_result *res = parsed_result;
3724
3725         if (test_done == 0) {
3726                 printf("Please stop forwarding first\n");
3727                 return;
3728         }
3729         if (!strcmp(res->mask, "coremask")) {
3730                 set_fwd_lcores_mask(res->hexavalue);
3731                 fwd_config_setup();
3732         } else if (!strcmp(res->mask, "portmask")) {
3733                 set_fwd_ports_mask(res->hexavalue);
3734                 fwd_config_setup();
3735         }
3736 }
3737
3738 cmdline_parse_token_string_t cmd_setmask_set =
3739         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3740 cmdline_parse_token_string_t cmd_setmask_mask =
3741         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3742                                  "coremask#portmask");
3743 cmdline_parse_token_num_t cmd_setmask_value =
3744         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3745
3746 cmdline_parse_inst_t cmd_set_fwd_mask = {
3747         .f = cmd_set_mask_parsed,
3748         .data = NULL,
3749         .help_str = "set coremask|portmask <hexadecimal value>",
3750         .tokens = {
3751                 (void *)&cmd_setmask_set,
3752                 (void *)&cmd_setmask_mask,
3753                 (void *)&cmd_setmask_value,
3754                 NULL,
3755         },
3756 };
3757
3758 /*
3759  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3760  */
3761 struct cmd_set_result {
3762         cmdline_fixed_string_t set;
3763         cmdline_fixed_string_t what;
3764         uint16_t value;
3765 };
3766
3767 static void cmd_set_parsed(void *parsed_result,
3768                            __rte_unused struct cmdline *cl,
3769                            __rte_unused void *data)
3770 {
3771         struct cmd_set_result *res = parsed_result;
3772         if (!strcmp(res->what, "nbport")) {
3773                 set_fwd_ports_number(res->value);
3774                 fwd_config_setup();
3775         } else if (!strcmp(res->what, "nbcore")) {
3776                 set_fwd_lcores_number(res->value);
3777                 fwd_config_setup();
3778         } else if (!strcmp(res->what, "burst"))
3779                 set_nb_pkt_per_burst(res->value);
3780         else if (!strcmp(res->what, "verbose"))
3781                 set_verbose_level(res->value);
3782 }
3783
3784 cmdline_parse_token_string_t cmd_set_set =
3785         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3786 cmdline_parse_token_string_t cmd_set_what =
3787         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3788                                  "nbport#nbcore#burst#verbose");
3789 cmdline_parse_token_num_t cmd_set_value =
3790         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3791
3792 cmdline_parse_inst_t cmd_set_numbers = {
3793         .f = cmd_set_parsed,
3794         .data = NULL,
3795         .help_str = "set nbport|nbcore|burst|verbose <value>",
3796         .tokens = {
3797                 (void *)&cmd_set_set,
3798                 (void *)&cmd_set_what,
3799                 (void *)&cmd_set_value,
3800                 NULL,
3801         },
3802 };
3803
3804 /* *** SET LOG LEVEL CONFIGURATION *** */
3805
3806 struct cmd_set_log_result {
3807         cmdline_fixed_string_t set;
3808         cmdline_fixed_string_t log;
3809         cmdline_fixed_string_t type;
3810         uint32_t level;
3811 };
3812
3813 static void
3814 cmd_set_log_parsed(void *parsed_result,
3815                    __rte_unused struct cmdline *cl,
3816                    __rte_unused void *data)
3817 {
3818         struct cmd_set_log_result *res;
3819         int ret;
3820
3821         res = parsed_result;
3822         if (!strcmp(res->type, "global"))
3823                 rte_log_set_global_level(res->level);
3824         else {
3825                 ret = rte_log_set_level_regexp(res->type, res->level);
3826                 if (ret < 0)
3827                         printf("Unable to set log level\n");
3828         }
3829 }
3830
3831 cmdline_parse_token_string_t cmd_set_log_set =
3832         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3833 cmdline_parse_token_string_t cmd_set_log_log =
3834         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3835 cmdline_parse_token_string_t cmd_set_log_type =
3836         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3837 cmdline_parse_token_num_t cmd_set_log_level =
3838         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3839
3840 cmdline_parse_inst_t cmd_set_log = {
3841         .f = cmd_set_log_parsed,
3842         .data = NULL,
3843         .help_str = "set log global|<type> <level>",
3844         .tokens = {
3845                 (void *)&cmd_set_log_set,
3846                 (void *)&cmd_set_log_log,
3847                 (void *)&cmd_set_log_type,
3848                 (void *)&cmd_set_log_level,
3849                 NULL,
3850         },
3851 };
3852
3853 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3854
3855 struct cmd_set_txpkts_result {
3856         cmdline_fixed_string_t cmd_keyword;
3857         cmdline_fixed_string_t txpkts;
3858         cmdline_fixed_string_t seg_lengths;
3859 };
3860
3861 static void
3862 cmd_set_txpkts_parsed(void *parsed_result,
3863                       __rte_unused struct cmdline *cl,
3864                       __rte_unused void *data)
3865 {
3866         struct cmd_set_txpkts_result *res;
3867         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3868         unsigned int nb_segs;
3869
3870         res = parsed_result;
3871         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3872                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3873         if (nb_segs > 0)
3874                 set_tx_pkt_segments(seg_lengths, nb_segs);
3875 }
3876
3877 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3878         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3879                                  cmd_keyword, "set");
3880 cmdline_parse_token_string_t cmd_set_txpkts_name =
3881         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3882                                  txpkts, "txpkts");
3883 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3884         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3885                                  seg_lengths, NULL);
3886
3887 cmdline_parse_inst_t cmd_set_txpkts = {
3888         .f = cmd_set_txpkts_parsed,
3889         .data = NULL,
3890         .help_str = "set txpkts <len0[,len1]*>",
3891         .tokens = {
3892                 (void *)&cmd_set_txpkts_keyword,
3893                 (void *)&cmd_set_txpkts_name,
3894                 (void *)&cmd_set_txpkts_lengths,
3895                 NULL,
3896         },
3897 };
3898
3899 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3900
3901 struct cmd_set_txsplit_result {
3902         cmdline_fixed_string_t cmd_keyword;
3903         cmdline_fixed_string_t txsplit;
3904         cmdline_fixed_string_t mode;
3905 };
3906
3907 static void
3908 cmd_set_txsplit_parsed(void *parsed_result,
3909                       __rte_unused struct cmdline *cl,
3910                       __rte_unused void *data)
3911 {
3912         struct cmd_set_txsplit_result *res;
3913
3914         res = parsed_result;
3915         set_tx_pkt_split(res->mode);
3916 }
3917
3918 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3919         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3920                                  cmd_keyword, "set");
3921 cmdline_parse_token_string_t cmd_set_txsplit_name =
3922         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3923                                  txsplit, "txsplit");
3924 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3925         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3926                                  mode, NULL);
3927
3928 cmdline_parse_inst_t cmd_set_txsplit = {
3929         .f = cmd_set_txsplit_parsed,
3930         .data = NULL,
3931         .help_str = "set txsplit on|off|rand",
3932         .tokens = {
3933                 (void *)&cmd_set_txsplit_keyword,
3934                 (void *)&cmd_set_txsplit_name,
3935                 (void *)&cmd_set_txsplit_mode,
3936                 NULL,
3937         },
3938 };
3939
3940 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3941 struct cmd_rx_vlan_filter_all_result {
3942         cmdline_fixed_string_t rx_vlan;
3943         cmdline_fixed_string_t what;
3944         cmdline_fixed_string_t all;
3945         portid_t port_id;
3946 };
3947
3948 static void
3949 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3950                               __rte_unused struct cmdline *cl,
3951                               __rte_unused void *data)
3952 {
3953         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3954
3955         if (!strcmp(res->what, "add"))
3956                 rx_vlan_all_filter_set(res->port_id, 1);
3957         else
3958                 rx_vlan_all_filter_set(res->port_id, 0);
3959 }
3960
3961 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3962         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3963                                  rx_vlan, "rx_vlan");
3964 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3965         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3966                                  what, "add#rm");
3967 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3968         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3969                                  all, "all");
3970 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3971         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3972                               port_id, UINT16);
3973
3974 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3975         .f = cmd_rx_vlan_filter_all_parsed,
3976         .data = NULL,
3977         .help_str = "rx_vlan add|rm all <port_id>: "
3978                 "Add/Remove all identifiers to/from the set of VLAN "
3979                 "identifiers filtered by a port",
3980         .tokens = {
3981                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3982                 (void *)&cmd_rx_vlan_filter_all_what,
3983                 (void *)&cmd_rx_vlan_filter_all_all,
3984                 (void *)&cmd_rx_vlan_filter_all_portid,
3985                 NULL,
3986         },
3987 };
3988
3989 /* *** VLAN OFFLOAD SET ON A PORT *** */
3990 struct cmd_vlan_offload_result {
3991         cmdline_fixed_string_t vlan;
3992         cmdline_fixed_string_t set;
3993         cmdline_fixed_string_t vlan_type;
3994         cmdline_fixed_string_t what;
3995         cmdline_fixed_string_t on;
3996         cmdline_fixed_string_t port_id;
3997 };
3998
3999 static void
4000 cmd_vlan_offload_parsed(void *parsed_result,
4001                           __rte_unused struct cmdline *cl,
4002                           __rte_unused void *data)
4003 {
4004         int on;
4005         struct cmd_vlan_offload_result *res = parsed_result;
4006         char *str;
4007         int i, len = 0;
4008         portid_t port_id = 0;
4009         unsigned int tmp;
4010
4011         str = res->port_id;
4012         len = strnlen(str, STR_TOKEN_SIZE);
4013         i = 0;
4014         /* Get port_id first */
4015         while(i < len){
4016                 if(str[i] == ',')
4017                         break;
4018
4019                 i++;
4020         }
4021         str[i]='\0';
4022         tmp = strtoul(str, NULL, 0);
4023         /* If port_id greater that what portid_t can represent, return */
4024         if(tmp >= RTE_MAX_ETHPORTS)
4025                 return;
4026         port_id = (portid_t)tmp;
4027
4028         if (!strcmp(res->on, "on"))
4029                 on = 1;
4030         else
4031                 on = 0;
4032
4033         if (!strcmp(res->what, "strip"))
4034                 rx_vlan_strip_set(port_id,  on);
4035         else if(!strcmp(res->what, "stripq")){
4036                 uint16_t queue_id = 0;
4037
4038                 /* No queue_id, return */
4039                 if(i + 1 >= len) {
4040                         printf("must specify (port,queue_id)\n");
4041                         return;
4042                 }
4043                 tmp = strtoul(str + i + 1, NULL, 0);
4044                 /* If queue_id greater that what 16-bits can represent, return */
4045                 if(tmp > 0xffff)
4046                         return;
4047
4048                 queue_id = (uint16_t)tmp;
4049                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4050         }
4051         else if (!strcmp(res->what, "filter"))
4052                 rx_vlan_filter_set(port_id, on);
4053         else if (!strcmp(res->what, "qinq_strip"))
4054                 rx_vlan_qinq_strip_set(port_id, on);
4055         else
4056                 vlan_extend_set(port_id, on);
4057
4058         return;
4059 }
4060
4061 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4062         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4063                                  vlan, "vlan");
4064 cmdline_parse_token_string_t cmd_vlan_offload_set =
4065         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4066                                  set, "set");
4067 cmdline_parse_token_string_t cmd_vlan_offload_what =
4068         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4069                                 what, "strip#filter#qinq_strip#extend#stripq");
4070 cmdline_parse_token_string_t cmd_vlan_offload_on =
4071         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4072                               on, "on#off");
4073 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4074         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4075                               port_id, NULL);
4076
4077 cmdline_parse_inst_t cmd_vlan_offload = {
4078         .f = cmd_vlan_offload_parsed,
4079         .data = NULL,
4080         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4081                 "<port_id[,queue_id]>: "
4082                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4083         .tokens = {
4084                 (void *)&cmd_vlan_offload_vlan,
4085                 (void *)&cmd_vlan_offload_set,
4086                 (void *)&cmd_vlan_offload_what,
4087                 (void *)&cmd_vlan_offload_on,
4088                 (void *)&cmd_vlan_offload_portid,
4089                 NULL,
4090         },
4091 };
4092
4093 /* *** VLAN TPID SET ON A PORT *** */
4094 struct cmd_vlan_tpid_result {
4095         cmdline_fixed_string_t vlan;
4096         cmdline_fixed_string_t set;
4097         cmdline_fixed_string_t vlan_type;
4098         cmdline_fixed_string_t what;
4099         uint16_t tp_id;
4100         portid_t port_id;
4101 };
4102
4103 static void
4104 cmd_vlan_tpid_parsed(void *parsed_result,
4105                           __rte_unused struct cmdline *cl,
4106                           __rte_unused void *data)
4107 {
4108         struct cmd_vlan_tpid_result *res = parsed_result;
4109         enum rte_vlan_type vlan_type;
4110
4111         if (!strcmp(res->vlan_type, "inner"))
4112                 vlan_type = ETH_VLAN_TYPE_INNER;
4113         else if (!strcmp(res->vlan_type, "outer"))
4114                 vlan_type = ETH_VLAN_TYPE_OUTER;
4115         else {
4116                 printf("Unknown vlan type\n");
4117                 return;
4118         }
4119         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4120 }
4121
4122 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4123         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4124                                  vlan, "vlan");
4125 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4126         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4127                                  set, "set");
4128 cmdline_parse_token_string_t cmd_vlan_type =
4129         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4130                                  vlan_type, "inner#outer");
4131 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4132         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4133                                  what, "tpid");
4134 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4135         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4136                               tp_id, UINT16);
4137 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4138         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4139                               port_id, UINT16);
4140
4141 cmdline_parse_inst_t cmd_vlan_tpid = {
4142         .f = cmd_vlan_tpid_parsed,
4143         .data = NULL,
4144         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4145                 "Set the VLAN Ether type",
4146         .tokens = {
4147                 (void *)&cmd_vlan_tpid_vlan,
4148                 (void *)&cmd_vlan_tpid_set,
4149                 (void *)&cmd_vlan_type,
4150                 (void *)&cmd_vlan_tpid_what,
4151                 (void *)&cmd_vlan_tpid_tpid,
4152                 (void *)&cmd_vlan_tpid_portid,
4153                 NULL,
4154         },
4155 };
4156
4157 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4158 struct cmd_rx_vlan_filter_result {
4159         cmdline_fixed_string_t rx_vlan;
4160         cmdline_fixed_string_t what;
4161         uint16_t vlan_id;
4162         portid_t port_id;
4163 };
4164
4165 static void
4166 cmd_rx_vlan_filter_parsed(void *parsed_result,
4167                           __rte_unused struct cmdline *cl,
4168                           __rte_unused void *data)
4169 {
4170         struct cmd_rx_vlan_filter_result *res = parsed_result;
4171
4172         if (!strcmp(res->what, "add"))
4173                 rx_vft_set(res->port_id, res->vlan_id, 1);
4174         else
4175                 rx_vft_set(res->port_id, res->vlan_id, 0);
4176 }
4177
4178 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4179         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4180                                  rx_vlan, "rx_vlan");
4181 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4182         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4183                                  what, "add#rm");
4184 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4185         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4186                               vlan_id, UINT16);
4187 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4188         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4189                               port_id, UINT16);
4190
4191 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4192         .f = cmd_rx_vlan_filter_parsed,
4193         .data = NULL,
4194         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4195                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4196                 "identifiers filtered by a port",
4197         .tokens = {
4198                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4199                 (void *)&cmd_rx_vlan_filter_what,
4200                 (void *)&cmd_rx_vlan_filter_vlanid,
4201                 (void *)&cmd_rx_vlan_filter_portid,
4202                 NULL,
4203         },
4204 };
4205
4206 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4207 struct cmd_tx_vlan_set_result {
4208         cmdline_fixed_string_t tx_vlan;
4209         cmdline_fixed_string_t set;
4210         portid_t port_id;
4211         uint16_t vlan_id;
4212 };
4213
4214 static void
4215 cmd_tx_vlan_set_parsed(void *parsed_result,
4216                        __rte_unused struct cmdline *cl,
4217                        __rte_unused void *data)
4218 {
4219         struct cmd_tx_vlan_set_result *res = parsed_result;
4220
4221         if (!port_is_stopped(res->port_id)) {
4222                 printf("Please stop port %d first\n", res->port_id);
4223                 return;
4224         }
4225
4226         tx_vlan_set(res->port_id, res->vlan_id);
4227
4228         cmd_reconfig_device_queue(res->port_id, 1, 1);
4229 }
4230
4231 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4232         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4233                                  tx_vlan, "tx_vlan");
4234 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4235         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4236                                  set, "set");
4237 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4238         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4239                               port_id, UINT16);
4240 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4241         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4242                               vlan_id, UINT16);
4243
4244 cmdline_parse_inst_t cmd_tx_vlan_set = {
4245         .f = cmd_tx_vlan_set_parsed,
4246         .data = NULL,
4247         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4248                 "Enable hardware insertion of a single VLAN header "
4249                 "with a given TAG Identifier in packets sent on a port",
4250         .tokens = {
4251                 (void *)&cmd_tx_vlan_set_tx_vlan,
4252                 (void *)&cmd_tx_vlan_set_set,
4253                 (void *)&cmd_tx_vlan_set_portid,
4254                 (void *)&cmd_tx_vlan_set_vlanid,
4255                 NULL,
4256         },
4257 };
4258
4259 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4260 struct cmd_tx_vlan_set_qinq_result {
4261         cmdline_fixed_string_t tx_vlan;
4262         cmdline_fixed_string_t set;
4263         portid_t port_id;
4264         uint16_t vlan_id;
4265         uint16_t vlan_id_outer;
4266 };
4267
4268 static void
4269 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4270                             __rte_unused struct cmdline *cl,
4271                             __rte_unused void *data)
4272 {
4273         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4274
4275         if (!port_is_stopped(res->port_id)) {
4276                 printf("Please stop port %d first\n", res->port_id);
4277                 return;
4278         }
4279
4280         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4281
4282         cmd_reconfig_device_queue(res->port_id, 1, 1);
4283 }
4284
4285 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4286         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4287                 tx_vlan, "tx_vlan");
4288 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4289         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4290                 set, "set");
4291 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4292         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4293                 port_id, UINT16);
4294 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4295         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4296                 vlan_id, UINT16);
4297 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4298         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4299                 vlan_id_outer, UINT16);
4300
4301 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4302         .f = cmd_tx_vlan_set_qinq_parsed,
4303         .data = NULL,
4304         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4305                 "Enable hardware insertion of double VLAN header "
4306                 "with given TAG Identifiers in packets sent on a port",
4307         .tokens = {
4308                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4309                 (void *)&cmd_tx_vlan_set_qinq_set,
4310                 (void *)&cmd_tx_vlan_set_qinq_portid,
4311                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4312                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4313                 NULL,
4314         },
4315 };
4316
4317 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4318 struct cmd_tx_vlan_set_pvid_result {
4319         cmdline_fixed_string_t tx_vlan;
4320         cmdline_fixed_string_t set;
4321         cmdline_fixed_string_t pvid;
4322         portid_t port_id;
4323         uint16_t vlan_id;
4324         cmdline_fixed_string_t mode;
4325 };
4326
4327 static void
4328 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4329                             __rte_unused struct cmdline *cl,
4330                             __rte_unused void *data)
4331 {
4332         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4333
4334         if (strcmp(res->mode, "on") == 0)
4335                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4336         else
4337                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4338 }
4339
4340 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4341         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4342                                  tx_vlan, "tx_vlan");
4343 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4344         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4345                                  set, "set");
4346 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4347         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4348                                  pvid, "pvid");
4349 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4350         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4351                              port_id, UINT16);
4352 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4353         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4354                               vlan_id, UINT16);
4355 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4356         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4357                                  mode, "on#off");
4358
4359 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4360         .f = cmd_tx_vlan_set_pvid_parsed,
4361         .data = NULL,
4362         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4363         .tokens = {
4364                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4365                 (void *)&cmd_tx_vlan_set_pvid_set,
4366                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4367                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4368                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4369                 (void *)&cmd_tx_vlan_set_pvid_mode,
4370                 NULL,
4371         },
4372 };
4373
4374 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4375 struct cmd_tx_vlan_reset_result {
4376         cmdline_fixed_string_t tx_vlan;
4377         cmdline_fixed_string_t reset;
4378         portid_t port_id;
4379 };
4380
4381 static void
4382 cmd_tx_vlan_reset_parsed(void *parsed_result,
4383                          __rte_unused struct cmdline *cl,
4384                          __rte_unused void *data)
4385 {
4386         struct cmd_tx_vlan_reset_result *res = parsed_result;
4387
4388         if (!port_is_stopped(res->port_id)) {
4389                 printf("Please stop port %d first\n", res->port_id);
4390                 return;
4391         }
4392
4393         tx_vlan_reset(res->port_id);
4394
4395         cmd_reconfig_device_queue(res->port_id, 1, 1);
4396 }
4397
4398 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4399         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4400                                  tx_vlan, "tx_vlan");
4401 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4402         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4403                                  reset, "reset");
4404 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4405         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4406                               port_id, UINT16);
4407
4408 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4409         .f = cmd_tx_vlan_reset_parsed,
4410         .data = NULL,
4411         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4412                 "VLAN header in packets sent on a port",
4413         .tokens = {
4414                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4415                 (void *)&cmd_tx_vlan_reset_reset,
4416                 (void *)&cmd_tx_vlan_reset_portid,
4417                 NULL,
4418         },
4419 };
4420
4421
4422 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4423 struct cmd_csum_result {
4424         cmdline_fixed_string_t csum;
4425         cmdline_fixed_string_t mode;
4426         cmdline_fixed_string_t proto;
4427         cmdline_fixed_string_t hwsw;
4428         portid_t port_id;
4429 };
4430
4431 static void
4432 csum_show(int port_id)
4433 {
4434         struct rte_eth_dev_info dev_info;
4435         uint64_t tx_offloads;
4436         int ret;
4437
4438         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4439         printf("Parse tunnel is %s\n",
4440                 (ports[port_id].parse_tunnel) ? "on" : "off");
4441         printf("IP checksum offload is %s\n",
4442                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4443         printf("UDP checksum offload is %s\n",
4444                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4445         printf("TCP checksum offload is %s\n",
4446                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4447         printf("SCTP checksum offload is %s\n",
4448                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4449         printf("Outer-Ip checksum offload is %s\n",
4450                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4451         printf("Outer-Udp checksum offload is %s\n",
4452                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4453
4454         /* display warnings if configuration is not supported by the NIC */
4455         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4456         if (ret != 0)
4457                 return;
4458
4459         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4460                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4461                 printf("Warning: hardware IP checksum enabled but not "
4462                         "supported by port %d\n", port_id);
4463         }
4464         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4465                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4466                 printf("Warning: hardware UDP checksum enabled but not "
4467                         "supported by port %d\n", port_id);
4468         }
4469         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4470                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4471                 printf("Warning: hardware TCP checksum enabled but not "
4472                         "supported by port %d\n", port_id);
4473         }
4474         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4475                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4476                 printf("Warning: hardware SCTP checksum enabled but not "
4477                         "supported by port %d\n", port_id);
4478         }
4479         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4480                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4481                 printf("Warning: hardware outer IP checksum enabled but not "
4482                         "supported by port %d\n", port_id);
4483         }
4484         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4485                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4486                         == 0) {
4487                 printf("Warning: hardware outer UDP checksum enabled but not "
4488                         "supported by port %d\n", port_id);
4489         }
4490 }
4491
4492 static void
4493 cmd_config_queue_tx_offloads(struct rte_port *port)
4494 {
4495         int k;
4496
4497         /* Apply queue tx offloads configuration */
4498         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4499                 port->tx_conf[k].offloads =
4500                         port->dev_conf.txmode.offloads;
4501 }
4502
4503 static void
4504 cmd_csum_parsed(void *parsed_result,
4505                        __rte_unused struct cmdline *cl,
4506                        __rte_unused void *data)
4507 {
4508         struct cmd_csum_result *res = parsed_result;
4509         int hw = 0;
4510         uint64_t csum_offloads = 0;
4511         struct rte_eth_dev_info dev_info;
4512         int ret;
4513
4514         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4515                 printf("invalid port %d\n", res->port_id);
4516                 return;
4517         }
4518         if (!port_is_stopped(res->port_id)) {
4519                 printf("Please stop port %d first\n", res->port_id);
4520                 return;
4521         }
4522
4523         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4524         if (ret != 0)
4525                 return;
4526
4527         if (!strcmp(res->mode, "set")) {
4528
4529                 if (!strcmp(res->hwsw, "hw"))
4530                         hw = 1;
4531
4532                 if (!strcmp(res->proto, "ip")) {
4533                         if (hw == 0 || (dev_info.tx_offload_capa &
4534                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4535                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4536                         } else {
4537                                 printf("IP checksum offload is not supported "
4538                                        "by port %u\n", res->port_id);
4539                         }
4540                 } else if (!strcmp(res->proto, "udp")) {
4541                         if (hw == 0 || (dev_info.tx_offload_capa &
4542                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4543                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4544                         } else {
4545                                 printf("UDP checksum offload is not supported "
4546                                        "by port %u\n", res->port_id);
4547                         }
4548                 } else if (!strcmp(res->proto, "tcp")) {
4549                         if (hw == 0 || (dev_info.tx_offload_capa &
4550                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4551                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4552                         } else {
4553                                 printf("TCP checksum offload is not supported "
4554                                        "by port %u\n", res->port_id);
4555                         }
4556                 } else if (!strcmp(res->proto, "sctp")) {
4557                         if (hw == 0 || (dev_info.tx_offload_capa &
4558                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4559                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4560                         } else {
4561                                 printf("SCTP checksum offload is not supported "
4562                                        "by port %u\n", res->port_id);
4563                         }
4564                 } else if (!strcmp(res->proto, "outer-ip")) {
4565                         if (hw == 0 || (dev_info.tx_offload_capa &
4566                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4567                                 csum_offloads |=
4568                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4569                         } else {
4570                                 printf("Outer IP checksum offload is not "
4571                                        "supported by port %u\n", res->port_id);
4572                         }
4573                 } else if (!strcmp(res->proto, "outer-udp")) {
4574                         if (hw == 0 || (dev_info.tx_offload_capa &
4575                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4576                                 csum_offloads |=
4577                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4578                         } else {
4579                                 printf("Outer UDP checksum offload is not "
4580                                        "supported by port %u\n", res->port_id);
4581                         }
4582                 }
4583
4584                 if (hw) {
4585                         ports[res->port_id].dev_conf.txmode.offloads |=
4586                                                         csum_offloads;
4587                 } else {
4588                         ports[res->port_id].dev_conf.txmode.offloads &=
4589                                                         (~csum_offloads);
4590                 }
4591                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4592         }
4593         csum_show(res->port_id);
4594
4595         cmd_reconfig_device_queue(res->port_id, 1, 1);
4596 }
4597
4598 cmdline_parse_token_string_t cmd_csum_csum =
4599         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4600                                 csum, "csum");
4601 cmdline_parse_token_string_t cmd_csum_mode =
4602         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4603                                 mode, "set");
4604 cmdline_parse_token_string_t cmd_csum_proto =
4605         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4606                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4607 cmdline_parse_token_string_t cmd_csum_hwsw =
4608         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4609                                 hwsw, "hw#sw");
4610 cmdline_parse_token_num_t cmd_csum_portid =
4611         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4612                                 port_id, UINT16);
4613
4614 cmdline_parse_inst_t cmd_csum_set = {
4615         .f = cmd_csum_parsed,
4616         .data = NULL,
4617         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4618                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4619                 "using csum forward engine",
4620         .tokens = {
4621                 (void *)&cmd_csum_csum,
4622                 (void *)&cmd_csum_mode,
4623                 (void *)&cmd_csum_proto,
4624                 (void *)&cmd_csum_hwsw,
4625                 (void *)&cmd_csum_portid,
4626                 NULL,
4627         },
4628 };
4629
4630 cmdline_parse_token_string_t cmd_csum_mode_show =
4631         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4632                                 mode, "show");
4633
4634 cmdline_parse_inst_t cmd_csum_show = {
4635         .f = cmd_csum_parsed,
4636         .data = NULL,
4637         .help_str = "csum show <port_id>: Show checksum offload configuration",
4638         .tokens = {
4639                 (void *)&cmd_csum_csum,
4640                 (void *)&cmd_csum_mode_show,
4641                 (void *)&cmd_csum_portid,
4642                 NULL,
4643         },
4644 };
4645
4646 /* Enable/disable tunnel parsing */
4647 struct cmd_csum_tunnel_result {
4648         cmdline_fixed_string_t csum;
4649         cmdline_fixed_string_t parse;
4650         cmdline_fixed_string_t onoff;
4651         portid_t port_id;
4652 };
4653
4654 static void
4655 cmd_csum_tunnel_parsed(void *parsed_result,
4656                        __rte_unused struct cmdline *cl,
4657                        __rte_unused void *data)
4658 {
4659         struct cmd_csum_tunnel_result *res = parsed_result;
4660
4661         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4662                 return;
4663
4664         if (!strcmp(res->onoff, "on"))
4665                 ports[res->port_id].parse_tunnel = 1;
4666         else
4667                 ports[res->port_id].parse_tunnel = 0;
4668
4669         csum_show(res->port_id);
4670 }
4671
4672 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4673         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4674                                 csum, "csum");
4675 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4676         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4677                                 parse, "parse-tunnel");
4678 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4679         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4680                                 onoff, "on#off");
4681 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4682         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4683                                 port_id, UINT16);
4684
4685 cmdline_parse_inst_t cmd_csum_tunnel = {
4686         .f = cmd_csum_tunnel_parsed,
4687         .data = NULL,
4688         .help_str = "csum parse-tunnel on|off <port_id>: "
4689                 "Enable/Disable parsing of tunnels for csum engine",
4690         .tokens = {
4691                 (void *)&cmd_csum_tunnel_csum,
4692                 (void *)&cmd_csum_tunnel_parse,
4693                 (void *)&cmd_csum_tunnel_onoff,
4694                 (void *)&cmd_csum_tunnel_portid,
4695                 NULL,
4696         },
4697 };
4698
4699 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4700 struct cmd_tso_set_result {
4701         cmdline_fixed_string_t tso;
4702         cmdline_fixed_string_t mode;
4703         uint16_t tso_segsz;
4704         portid_t port_id;
4705 };
4706
4707 static void
4708 cmd_tso_set_parsed(void *parsed_result,
4709                        __rte_unused struct cmdline *cl,
4710                        __rte_unused void *data)
4711 {
4712         struct cmd_tso_set_result *res = parsed_result;
4713         struct rte_eth_dev_info dev_info;
4714         int ret;
4715
4716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4717                 return;
4718         if (!port_is_stopped(res->port_id)) {
4719                 printf("Please stop port %d first\n", res->port_id);
4720                 return;
4721         }
4722
4723         if (!strcmp(res->mode, "set"))
4724                 ports[res->port_id].tso_segsz = res->tso_segsz;
4725
4726         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4727         if (ret != 0)
4728                 return;
4729
4730         if ((ports[res->port_id].tso_segsz != 0) &&
4731                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4732                 printf("Error: TSO is not supported by port %d\n",
4733                        res->port_id);
4734                 return;
4735         }
4736
4737         if (ports[res->port_id].tso_segsz == 0) {
4738                 ports[res->port_id].dev_conf.txmode.offloads &=
4739                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4740                 printf("TSO for non-tunneled packets is disabled\n");
4741         } else {
4742                 ports[res->port_id].dev_conf.txmode.offloads |=
4743                                                 DEV_TX_OFFLOAD_TCP_TSO;
4744                 printf("TSO segment size for non-tunneled packets is %d\n",
4745                         ports[res->port_id].tso_segsz);
4746         }
4747         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4748
4749         /* display warnings if configuration is not supported by the NIC */
4750         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4751         if (ret != 0)
4752                 return;
4753
4754         if ((ports[res->port_id].tso_segsz != 0) &&
4755                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4756                 printf("Warning: TSO enabled but not "
4757                         "supported by port %d\n", res->port_id);
4758         }
4759
4760         cmd_reconfig_device_queue(res->port_id, 1, 1);
4761 }
4762
4763 cmdline_parse_token_string_t cmd_tso_set_tso =
4764         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4765                                 tso, "tso");
4766 cmdline_parse_token_string_t cmd_tso_set_mode =
4767         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4768                                 mode, "set");
4769 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4770         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4771                                 tso_segsz, UINT16);
4772 cmdline_parse_token_num_t cmd_tso_set_portid =
4773         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4774                                 port_id, UINT16);
4775
4776 cmdline_parse_inst_t cmd_tso_set = {
4777         .f = cmd_tso_set_parsed,
4778         .data = NULL,
4779         .help_str = "tso set <tso_segsz> <port_id>: "
4780                 "Set TSO segment size of non-tunneled packets for csum engine "
4781                 "(0 to disable)",
4782         .tokens = {
4783                 (void *)&cmd_tso_set_tso,
4784                 (void *)&cmd_tso_set_mode,
4785                 (void *)&cmd_tso_set_tso_segsz,
4786                 (void *)&cmd_tso_set_portid,
4787                 NULL,
4788         },
4789 };
4790
4791 cmdline_parse_token_string_t cmd_tso_show_mode =
4792         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4793                                 mode, "show");
4794
4795
4796 cmdline_parse_inst_t cmd_tso_show = {
4797         .f = cmd_tso_set_parsed,
4798         .data = NULL,
4799         .help_str = "tso show <port_id>: "
4800                 "Show TSO segment size of non-tunneled packets for csum engine",
4801         .tokens = {
4802                 (void *)&cmd_tso_set_tso,
4803                 (void *)&cmd_tso_show_mode,
4804                 (void *)&cmd_tso_set_portid,
4805                 NULL,
4806         },
4807 };
4808
4809 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4810 struct cmd_tunnel_tso_set_result {
4811         cmdline_fixed_string_t tso;
4812         cmdline_fixed_string_t mode;
4813         uint16_t tso_segsz;
4814         portid_t port_id;
4815 };
4816
4817 static struct rte_eth_dev_info
4818 check_tunnel_tso_nic_support(portid_t port_id)
4819 {
4820         struct rte_eth_dev_info dev_info;
4821
4822         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4823                 return dev_info;
4824
4825         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4826                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4827                        "not enabled for port %d\n", port_id);
4828         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4829                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4830                        "not enabled for port %d\n", port_id);
4831         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4832                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4833                        "not enabled for port %d\n", port_id);
4834         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4835                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4836                        "not enabled for port %d\n", port_id);
4837         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4838                 printf("Warning: IP TUNNEL TSO not supported therefore "
4839                        "not enabled for port %d\n", port_id);
4840         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4841                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4842                        "not enabled for port %d\n", port_id);
4843         return dev_info;
4844 }
4845
4846 static void
4847 cmd_tunnel_tso_set_parsed(void *parsed_result,
4848                           __rte_unused struct cmdline *cl,
4849                           __rte_unused void *data)
4850 {
4851         struct cmd_tunnel_tso_set_result *res = parsed_result;
4852         struct rte_eth_dev_info dev_info;
4853
4854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4855                 return;
4856         if (!port_is_stopped(res->port_id)) {
4857                 printf("Please stop port %d first\n", res->port_id);
4858                 return;
4859         }
4860
4861         if (!strcmp(res->mode, "set"))
4862                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4863
4864         dev_info = check_tunnel_tso_nic_support(res->port_id);
4865         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4866                 ports[res->port_id].dev_conf.txmode.offloads &=
4867                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4868                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4869                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4870                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4871                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4872                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4873                 printf("TSO for tunneled packets is disabled\n");
4874         } else {
4875                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4876                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4877                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4878                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4879                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4880                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4881
4882                 ports[res->port_id].dev_conf.txmode.offloads |=
4883                         (tso_offloads & dev_info.tx_offload_capa);
4884                 printf("TSO segment size for tunneled packets is %d\n",
4885                         ports[res->port_id].tunnel_tso_segsz);
4886
4887                 /* Below conditions are needed to make it work:
4888                  * (1) tunnel TSO is supported by the NIC;
4889                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4890                  * are recognized;
4891                  * (3) for tunneled pkts with outer L3 of IPv4,
4892                  * "csum set outer-ip" must be set to hw, because after tso,
4893                  * total_len of outer IP header is changed, and the checksum
4894                  * of outer IP header calculated by sw should be wrong; that
4895                  * is not necessary for IPv6 tunneled pkts because there's no
4896                  * checksum in IP header anymore.
4897                  */
4898
4899                 if (!ports[res->port_id].parse_tunnel)
4900                         printf("Warning: csum parse_tunnel must be set "
4901                                 "so that tunneled packets are recognized\n");
4902                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4903                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4904                         printf("Warning: csum set outer-ip must be set to hw "
4905                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4906         }
4907
4908         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4909         cmd_reconfig_device_queue(res->port_id, 1, 1);
4910 }
4911
4912 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4913         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4914                                 tso, "tunnel_tso");
4915 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4916         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4917                                 mode, "set");
4918 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4919         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4920                                 tso_segsz, UINT16);
4921 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4922         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4923                                 port_id, UINT16);
4924
4925 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4926         .f = cmd_tunnel_tso_set_parsed,
4927         .data = NULL,
4928         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4929                 "Set TSO segment size of tunneled packets for csum engine "
4930                 "(0 to disable)",
4931         .tokens = {
4932                 (void *)&cmd_tunnel_tso_set_tso,
4933                 (void *)&cmd_tunnel_tso_set_mode,
4934                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4935                 (void *)&cmd_tunnel_tso_set_portid,
4936                 NULL,
4937         },
4938 };
4939
4940 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4941         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4942                                 mode, "show");
4943
4944
4945 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4946         .f = cmd_tunnel_tso_set_parsed,
4947         .data = NULL,
4948         .help_str = "tunnel_tso show <port_id> "
4949                 "Show TSO segment size of tunneled packets for csum engine",
4950         .tokens = {
4951                 (void *)&cmd_tunnel_tso_set_tso,
4952                 (void *)&cmd_tunnel_tso_show_mode,
4953                 (void *)&cmd_tunnel_tso_set_portid,
4954                 NULL,
4955         },
4956 };
4957
4958 /* *** SET GRO FOR A PORT *** */
4959 struct cmd_gro_enable_result {
4960         cmdline_fixed_string_t cmd_set;
4961         cmdline_fixed_string_t cmd_port;
4962         cmdline_fixed_string_t cmd_keyword;
4963         cmdline_fixed_string_t cmd_onoff;
4964         portid_t cmd_pid;
4965 };
4966
4967 static void
4968 cmd_gro_enable_parsed(void *parsed_result,
4969                 __rte_unused struct cmdline *cl,
4970                 __rte_unused void *data)
4971 {
4972         struct cmd_gro_enable_result *res;
4973
4974         res = parsed_result;
4975         if (!strcmp(res->cmd_keyword, "gro"))
4976                 setup_gro(res->cmd_onoff, res->cmd_pid);
4977 }
4978
4979 cmdline_parse_token_string_t cmd_gro_enable_set =
4980         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4981                         cmd_set, "set");
4982 cmdline_parse_token_string_t cmd_gro_enable_port =
4983         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4984                         cmd_keyword, "port");
4985 cmdline_parse_token_num_t cmd_gro_enable_pid =
4986         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4987                         cmd_pid, UINT16);
4988 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4989         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4990                         cmd_keyword, "gro");
4991 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4992         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4993                         cmd_onoff, "on#off");
4994
4995 cmdline_parse_inst_t cmd_gro_enable = {
4996         .f = cmd_gro_enable_parsed,
4997         .data = NULL,
4998         .help_str = "set port <port_id> gro on|off",
4999         .tokens = {
5000                 (void *)&cmd_gro_enable_set,
5001                 (void *)&cmd_gro_enable_port,
5002                 (void *)&cmd_gro_enable_pid,
5003                 (void *)&cmd_gro_enable_keyword,
5004                 (void *)&cmd_gro_enable_onoff,
5005                 NULL,
5006         },
5007 };
5008
5009 /* *** DISPLAY GRO CONFIGURATION *** */
5010 struct cmd_gro_show_result {
5011         cmdline_fixed_string_t cmd_show;
5012         cmdline_fixed_string_t cmd_port;
5013         cmdline_fixed_string_t cmd_keyword;
5014         portid_t cmd_pid;
5015 };
5016
5017 static void
5018 cmd_gro_show_parsed(void *parsed_result,
5019                 __rte_unused struct cmdline *cl,
5020                 __rte_unused void *data)
5021 {
5022         struct cmd_gro_show_result *res;
5023
5024         res = parsed_result;
5025         if (!strcmp(res->cmd_keyword, "gro"))
5026                 show_gro(res->cmd_pid);
5027 }
5028
5029 cmdline_parse_token_string_t cmd_gro_show_show =
5030         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5031                         cmd_show, "show");
5032 cmdline_parse_token_string_t cmd_gro_show_port =
5033         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5034                         cmd_port, "port");
5035 cmdline_parse_token_num_t cmd_gro_show_pid =
5036         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5037                         cmd_pid, UINT16);
5038 cmdline_parse_token_string_t cmd_gro_show_keyword =
5039         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5040                         cmd_keyword, "gro");
5041
5042 cmdline_parse_inst_t cmd_gro_show = {
5043         .f = cmd_gro_show_parsed,
5044         .data = NULL,
5045         .help_str = "show port <port_id> gro",
5046         .tokens = {
5047                 (void *)&cmd_gro_show_show,
5048                 (void *)&cmd_gro_show_port,
5049                 (void *)&cmd_gro_show_pid,
5050                 (void *)&cmd_gro_show_keyword,
5051                 NULL,
5052         },
5053 };
5054
5055 /* *** SET FLUSH CYCLES FOR GRO *** */
5056 struct cmd_gro_flush_result {
5057         cmdline_fixed_string_t cmd_set;
5058         cmdline_fixed_string_t cmd_keyword;
5059         cmdline_fixed_string_t cmd_flush;
5060         uint8_t cmd_cycles;
5061 };
5062
5063 static void
5064 cmd_gro_flush_parsed(void *parsed_result,
5065                 __rte_unused struct cmdline *cl,
5066                 __rte_unused void *data)
5067 {
5068         struct cmd_gro_flush_result *res;
5069
5070         res = parsed_result;
5071         if ((!strcmp(res->cmd_keyword, "gro")) &&
5072                         (!strcmp(res->cmd_flush, "flush")))
5073                 setup_gro_flush_cycles(res->cmd_cycles);
5074 }
5075
5076 cmdline_parse_token_string_t cmd_gro_flush_set =
5077         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5078                         cmd_set, "set");
5079 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5080         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5081                         cmd_keyword, "gro");
5082 cmdline_parse_token_string_t cmd_gro_flush_flush =
5083         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5084                         cmd_flush, "flush");
5085 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5086         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5087                         cmd_cycles, UINT8);
5088
5089 cmdline_parse_inst_t cmd_gro_flush = {
5090         .f = cmd_gro_flush_parsed,
5091         .data = NULL,
5092         .help_str = "set gro flush <cycles>",
5093         .tokens = {
5094                 (void *)&cmd_gro_flush_set,
5095                 (void *)&cmd_gro_flush_keyword,
5096                 (void *)&cmd_gro_flush_flush,
5097                 (void *)&cmd_gro_flush_cycles,
5098                 NULL,
5099         },
5100 };
5101
5102 /* *** ENABLE/DISABLE GSO *** */
5103 struct cmd_gso_enable_result {
5104         cmdline_fixed_string_t cmd_set;
5105         cmdline_fixed_string_t cmd_port;
5106         cmdline_fixed_string_t cmd_keyword;
5107         cmdline_fixed_string_t cmd_mode;
5108         portid_t cmd_pid;
5109 };
5110
5111 static void
5112 cmd_gso_enable_parsed(void *parsed_result,
5113                 __rte_unused struct cmdline *cl,
5114                 __rte_unused void *data)
5115 {
5116         struct cmd_gso_enable_result *res;
5117
5118         res = parsed_result;
5119         if (!strcmp(res->cmd_keyword, "gso"))
5120                 setup_gso(res->cmd_mode, res->cmd_pid);
5121 }
5122
5123 cmdline_parse_token_string_t cmd_gso_enable_set =
5124         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5125                         cmd_set, "set");
5126 cmdline_parse_token_string_t cmd_gso_enable_port =
5127         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5128                         cmd_port, "port");
5129 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5130         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5131                         cmd_keyword, "gso");
5132 cmdline_parse_token_string_t cmd_gso_enable_mode =
5133         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5134                         cmd_mode, "on#off");
5135 cmdline_parse_token_num_t cmd_gso_enable_pid =
5136         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5137                         cmd_pid, UINT16);
5138
5139 cmdline_parse_inst_t cmd_gso_enable = {
5140         .f = cmd_gso_enable_parsed,
5141         .data = NULL,
5142         .help_str = "set port <port_id> gso on|off",
5143         .tokens = {
5144                 (void *)&cmd_gso_enable_set,
5145                 (void *)&cmd_gso_enable_port,
5146                 (void *)&cmd_gso_enable_pid,
5147                 (void *)&cmd_gso_enable_keyword,
5148                 (void *)&cmd_gso_enable_mode,
5149                 NULL,
5150         },
5151 };
5152
5153 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5154 struct cmd_gso_size_result {
5155         cmdline_fixed_string_t cmd_set;
5156         cmdline_fixed_string_t cmd_keyword;
5157         cmdline_fixed_string_t cmd_segsz;
5158         uint16_t cmd_size;
5159 };
5160
5161 static void
5162 cmd_gso_size_parsed(void *parsed_result,
5163                        __rte_unused struct cmdline *cl,
5164                        __rte_unused void *data)
5165 {
5166         struct cmd_gso_size_result *res = parsed_result;
5167
5168         if (test_done == 0) {
5169                 printf("Before setting GSO segsz, please first"
5170                                 " stop forwarding\n");
5171                 return;
5172         }
5173
5174         if (!strcmp(res->cmd_keyword, "gso") &&
5175                         !strcmp(res->cmd_segsz, "segsz")) {
5176                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5177                         printf("gso_size should be larger than %zu."
5178                                         " Please input a legal value\n",
5179                                         RTE_GSO_SEG_SIZE_MIN);
5180                 else
5181                         gso_max_segment_size = res->cmd_size;
5182         }
5183 }
5184
5185 cmdline_parse_token_string_t cmd_gso_size_set =
5186         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5187                                 cmd_set, "set");
5188 cmdline_parse_token_string_t cmd_gso_size_keyword =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5190                                 cmd_keyword, "gso");
5191 cmdline_parse_token_string_t cmd_gso_size_segsz =
5192         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5193                                 cmd_segsz, "segsz");
5194 cmdline_parse_token_num_t cmd_gso_size_size =
5195         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5196                                 cmd_size, UINT16);
5197
5198 cmdline_parse_inst_t cmd_gso_size = {
5199         .f = cmd_gso_size_parsed,
5200         .data = NULL,
5201         .help_str = "set gso segsz <length>",
5202         .tokens = {
5203                 (void *)&cmd_gso_size_set,
5204                 (void *)&cmd_gso_size_keyword,
5205                 (void *)&cmd_gso_size_segsz,
5206                 (void *)&cmd_gso_size_size,
5207                 NULL,
5208         },
5209 };
5210
5211 /* *** SHOW GSO CONFIGURATION *** */
5212 struct cmd_gso_show_result {
5213         cmdline_fixed_string_t cmd_show;
5214         cmdline_fixed_string_t cmd_port;
5215         cmdline_fixed_string_t cmd_keyword;
5216         portid_t cmd_pid;
5217 };
5218
5219 static void
5220 cmd_gso_show_parsed(void *parsed_result,
5221                        __rte_unused struct cmdline *cl,
5222                        __rte_unused void *data)
5223 {
5224         struct cmd_gso_show_result *res = parsed_result;
5225
5226         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5227                 printf("invalid port id %u\n", res->cmd_pid);
5228                 return;
5229         }
5230         if (!strcmp(res->cmd_keyword, "gso")) {
5231                 if (gso_ports[res->cmd_pid].enable) {
5232                         printf("Max GSO'd packet size: %uB\n"
5233                                         "Supported GSO types: TCP/IPv4, "
5234                                         "UDP/IPv4, VxLAN with inner "
5235                                         "TCP/IPv4 packet, GRE with inner "
5236                                         "TCP/IPv4 packet\n",
5237                                         gso_max_segment_size);
5238                 } else
5239                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5240         }
5241 }
5242
5243 cmdline_parse_token_string_t cmd_gso_show_show =
5244 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5245                 cmd_show, "show");
5246 cmdline_parse_token_string_t cmd_gso_show_port =
5247 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5248                 cmd_port, "port");
5249 cmdline_parse_token_string_t cmd_gso_show_keyword =
5250         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5251                                 cmd_keyword, "gso");
5252 cmdline_parse_token_num_t cmd_gso_show_pid =
5253         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5254                                 cmd_pid, UINT16);
5255
5256 cmdline_parse_inst_t cmd_gso_show = {
5257         .f = cmd_gso_show_parsed,
5258         .data = NULL,
5259         .help_str = "show port <port_id> gso",
5260         .tokens = {
5261                 (void *)&cmd_gso_show_show,
5262                 (void *)&cmd_gso_show_port,
5263                 (void *)&cmd_gso_show_pid,
5264                 (void *)&cmd_gso_show_keyword,
5265                 NULL,
5266         },
5267 };
5268
5269 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5270 struct cmd_set_flush_rx {
5271         cmdline_fixed_string_t set;
5272         cmdline_fixed_string_t flush_rx;
5273         cmdline_fixed_string_t mode;
5274 };
5275
5276 static void
5277 cmd_set_flush_rx_parsed(void *parsed_result,
5278                 __rte_unused struct cmdline *cl,
5279                 __rte_unused void *data)
5280 {
5281         struct cmd_set_flush_rx *res = parsed_result;
5282         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5283 }
5284
5285 cmdline_parse_token_string_t cmd_setflushrx_set =
5286         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5287                         set, "set");
5288 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5289         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5290                         flush_rx, "flush_rx");
5291 cmdline_parse_token_string_t cmd_setflushrx_mode =
5292         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5293                         mode, "on#off");
5294
5295
5296 cmdline_parse_inst_t cmd_set_flush_rx = {
5297         .f = cmd_set_flush_rx_parsed,
5298         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5299         .data = NULL,
5300         .tokens = {
5301                 (void *)&cmd_setflushrx_set,
5302                 (void *)&cmd_setflushrx_flush_rx,
5303                 (void *)&cmd_setflushrx_mode,
5304                 NULL,
5305         },
5306 };
5307
5308 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5309 struct cmd_set_link_check {
5310         cmdline_fixed_string_t set;
5311         cmdline_fixed_string_t link_check;
5312         cmdline_fixed_string_t mode;
5313 };
5314
5315 static void
5316 cmd_set_link_check_parsed(void *parsed_result,
5317                 __rte_unused struct cmdline *cl,
5318                 __rte_unused void *data)
5319 {
5320         struct cmd_set_link_check *res = parsed_result;
5321         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5322 }
5323
5324 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5325         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5326                         set, "set");
5327 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5328         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5329                         link_check, "link_check");
5330 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5331         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5332                         mode, "on#off");
5333
5334
5335 cmdline_parse_inst_t cmd_set_link_check = {
5336         .f = cmd_set_link_check_parsed,
5337         .help_str = "set link_check on|off: Enable/Disable link status check "
5338                     "when starting/stopping a port",
5339         .data = NULL,
5340         .tokens = {
5341                 (void *)&cmd_setlinkcheck_set,
5342                 (void *)&cmd_setlinkcheck_link_check,
5343                 (void *)&cmd_setlinkcheck_mode,
5344                 NULL,
5345         },
5346 };
5347
5348 /* *** SET NIC BYPASS MODE *** */
5349 struct cmd_set_bypass_mode_result {
5350         cmdline_fixed_string_t set;
5351         cmdline_fixed_string_t bypass;
5352         cmdline_fixed_string_t mode;
5353         cmdline_fixed_string_t value;
5354         portid_t port_id;
5355 };
5356
5357 static void
5358 cmd_set_bypass_mode_parsed(void *parsed_result,
5359                 __rte_unused struct cmdline *cl,
5360                 __rte_unused void *data)
5361 {
5362         struct cmd_set_bypass_mode_result *res = parsed_result;
5363         portid_t port_id = res->port_id;
5364         int32_t rc = -EINVAL;
5365
5366 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5367         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5368
5369         if (!strcmp(res->value, "bypass"))
5370                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5371         else if (!strcmp(res->value, "isolate"))
5372                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5373         else
5374                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5375
5376         /* Set the bypass mode for the relevant port. */
5377         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5378 #endif
5379         if (rc != 0)
5380                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5381 }
5382
5383 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5384         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5385                         set, "set");
5386 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5387         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5388                         bypass, "bypass");
5389 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5390         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5391                         mode, "mode");
5392 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5393         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5394                         value, "normal#bypass#isolate");
5395 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5396         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5397                                 port_id, UINT16);
5398
5399 cmdline_parse_inst_t cmd_set_bypass_mode = {
5400         .f = cmd_set_bypass_mode_parsed,
5401         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5402                     "Set the NIC bypass mode for port_id",
5403         .data = NULL,
5404         .tokens = {
5405                 (void *)&cmd_setbypass_mode_set,
5406                 (void *)&cmd_setbypass_mode_bypass,
5407                 (void *)&cmd_setbypass_mode_mode,
5408                 (void *)&cmd_setbypass_mode_value,
5409                 (void *)&cmd_setbypass_mode_port,
5410                 NULL,
5411         },
5412 };
5413
5414 /* *** SET NIC BYPASS EVENT *** */
5415 struct cmd_set_bypass_event_result {
5416         cmdline_fixed_string_t set;
5417         cmdline_fixed_string_t bypass;
5418         cmdline_fixed_string_t event;
5419         cmdline_fixed_string_t event_value;
5420         cmdline_fixed_string_t mode;
5421         cmdline_fixed_string_t mode_value;
5422         portid_t port_id;
5423 };
5424
5425 static void
5426 cmd_set_bypass_event_parsed(void *parsed_result,
5427                 __rte_unused struct cmdline *cl,
5428                 __rte_unused void *data)
5429 {
5430         int32_t rc = -EINVAL;
5431         struct cmd_set_bypass_event_result *res = parsed_result;
5432         portid_t port_id = res->port_id;
5433
5434 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5435         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5436         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5437
5438         if (!strcmp(res->event_value, "timeout"))
5439                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5440         else if (!strcmp(res->event_value, "os_on"))
5441                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5442         else if (!strcmp(res->event_value, "os_off"))
5443                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5444         else if (!strcmp(res->event_value, "power_on"))
5445                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5446         else if (!strcmp(res->event_value, "power_off"))
5447                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5448         else
5449                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5450
5451         if (!strcmp(res->mode_value, "bypass"))
5452                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5453         else if (!strcmp(res->mode_value, "isolate"))
5454                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5455         else
5456                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5457
5458         /* Set the watchdog timeout. */
5459         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5460
5461                 rc = -EINVAL;
5462                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5463                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5464                                                            bypass_timeout);
5465                 }
5466                 if (rc != 0) {
5467                         printf("Failed to set timeout value %u "
5468                         "for port %d, errto code: %d.\n",
5469                         bypass_timeout, port_id, rc);
5470                 }
5471         }
5472
5473         /* Set the bypass event to transition to bypass mode. */
5474         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5475                                               bypass_mode);
5476 #endif
5477
5478         if (rc != 0)
5479                 printf("\t Failed to set bypass event for port = %d.\n",
5480                        port_id);
5481 }
5482
5483 cmdline_parse_token_string_t cmd_setbypass_event_set =
5484         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5485                         set, "set");
5486 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5487         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5488                         bypass, "bypass");
5489 cmdline_parse_token_string_t cmd_setbypass_event_event =
5490         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5491                         event, "event");
5492 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5493         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5494                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5495 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5496         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5497                         mode, "mode");
5498 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5500                         mode_value, "normal#bypass#isolate");
5501 cmdline_parse_token_num_t cmd_setbypass_event_port =
5502         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5503                                 port_id, UINT16);
5504
5505 cmdline_parse_inst_t cmd_set_bypass_event = {
5506         .f = cmd_set_bypass_event_parsed,
5507         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5508                 "power_off mode normal|bypass|isolate <port_id>: "
5509                 "Set the NIC bypass event mode for port_id",
5510         .data = NULL,
5511         .tokens = {
5512                 (void *)&cmd_setbypass_event_set,
5513                 (void *)&cmd_setbypass_event_bypass,
5514                 (void *)&cmd_setbypass_event_event,
5515                 (void *)&cmd_setbypass_event_event_value,
5516                 (void *)&cmd_setbypass_event_mode,
5517                 (void *)&cmd_setbypass_event_mode_value,
5518                 (void *)&cmd_setbypass_event_port,
5519                 NULL,
5520         },
5521 };
5522
5523
5524 /* *** SET NIC BYPASS TIMEOUT *** */
5525 struct cmd_set_bypass_timeout_result {
5526         cmdline_fixed_string_t set;
5527         cmdline_fixed_string_t bypass;
5528         cmdline_fixed_string_t timeout;
5529         cmdline_fixed_string_t value;
5530 };
5531
5532 static void
5533 cmd_set_bypass_timeout_parsed(void *parsed_result,
5534                 __rte_unused struct cmdline *cl,
5535                 __rte_unused void *data)
5536 {
5537         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5538
5539 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5540         if (!strcmp(res->value, "1.5"))
5541                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5542         else if (!strcmp(res->value, "2"))
5543                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5544         else if (!strcmp(res->value, "3"))
5545                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5546         else if (!strcmp(res->value, "4"))
5547                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5548         else if (!strcmp(res->value, "8"))
5549                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5550         else if (!strcmp(res->value, "16"))
5551                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5552         else if (!strcmp(res->value, "32"))
5553                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5554         else
5555                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5556 #endif
5557 }
5558
5559 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5560         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5561                         set, "set");
5562 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5563         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5564                         bypass, "bypass");
5565 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5566         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5567                         timeout, "timeout");
5568 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5569         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5570                         value, "0#1.5#2#3#4#8#16#32");
5571
5572 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5573         .f = cmd_set_bypass_timeout_parsed,
5574         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5575                 "Set the NIC bypass watchdog timeout in seconds",
5576         .data = NULL,
5577         .tokens = {
5578                 (void *)&cmd_setbypass_timeout_set,
5579                 (void *)&cmd_setbypass_timeout_bypass,
5580                 (void *)&cmd_setbypass_timeout_timeout,
5581                 (void *)&cmd_setbypass_timeout_value,
5582                 NULL,
5583         },
5584 };
5585
5586 /* *** SHOW NIC BYPASS MODE *** */
5587 struct cmd_show_bypass_config_result {
5588         cmdline_fixed_string_t show;
5589         cmdline_fixed_string_t bypass;
5590         cmdline_fixed_string_t config;
5591         portid_t port_id;
5592 };
5593
5594 static void
5595 cmd_show_bypass_config_parsed(void *parsed_result,
5596                 __rte_unused struct cmdline *cl,
5597                 __rte_unused void *data)
5598 {
5599         struct cmd_show_bypass_config_result *res = parsed_result;
5600         portid_t port_id = res->port_id;
5601         int rc = -EINVAL;
5602 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5603         uint32_t event_mode;
5604         uint32_t bypass_mode;
5605         uint32_t timeout = bypass_timeout;
5606         unsigned int i;
5607
5608         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5609                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5610         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5611                 {"UNKNOWN", "normal", "bypass", "isolate"};
5612         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5613                 "NONE",
5614                 "OS/board on",
5615                 "power supply on",
5616                 "OS/board off",
5617                 "power supply off",
5618                 "timeout"};
5619
5620         /* Display the bypass mode.*/
5621         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5622                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5623                 return;
5624         }
5625         else {
5626                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5627                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5628
5629                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5630         }
5631
5632         /* Display the bypass timeout.*/
5633         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5634                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5635
5636         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5637
5638         /* Display the bypass events and associated modes. */
5639         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5640
5641                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5642                         printf("\tFailed to get bypass mode for event = %s\n",
5643                                 events[i]);
5644                 } else {
5645                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5646                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5647
5648                         printf("\tbypass event: %-16s = %s\n", events[i],
5649                                 modes[event_mode]);
5650                 }
5651         }
5652 #endif
5653         if (rc != 0)
5654                 printf("\tFailed to get bypass configuration for port = %d\n",
5655                        port_id);
5656 }
5657
5658 cmdline_parse_token_string_t cmd_showbypass_config_show =
5659         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5660                         show, "show");
5661 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5662         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5663                         bypass, "bypass");
5664 cmdline_parse_token_string_t cmd_showbypass_config_config =
5665         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5666                         config, "config");
5667 cmdline_parse_token_num_t cmd_showbypass_config_port =
5668         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5669                                 port_id, UINT16);
5670
5671 cmdline_parse_inst_t cmd_show_bypass_config = {
5672         .f = cmd_show_bypass_config_parsed,
5673         .help_str = "show bypass config <port_id>: "
5674                     "Show the NIC bypass config for port_id",
5675         .data = NULL,
5676         .tokens = {
5677                 (void *)&cmd_showbypass_config_show,
5678                 (void *)&cmd_showbypass_config_bypass,
5679                 (void *)&cmd_showbypass_config_config,
5680                 (void *)&cmd_showbypass_config_port,
5681                 NULL,
5682         },
5683 };
5684
5685 #ifdef RTE_LIBRTE_PMD_BOND
5686 /* *** SET BONDING MODE *** */
5687 struct cmd_set_bonding_mode_result {
5688         cmdline_fixed_string_t set;
5689         cmdline_fixed_string_t bonding;
5690         cmdline_fixed_string_t mode;
5691         uint8_t value;
5692         portid_t port_id;
5693 };
5694
5695 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5696                 __rte_unused  struct cmdline *cl,
5697                 __rte_unused void *data)
5698 {
5699         struct cmd_set_bonding_mode_result *res = parsed_result;
5700         portid_t port_id = res->port_id;
5701
5702         /* Set the bonding mode for the relevant port. */
5703         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5704                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5705 }
5706
5707 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5708 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5709                 set, "set");
5710 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5711 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5712                 bonding, "bonding");
5713 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5714 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5715                 mode, "mode");
5716 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5717 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5718                 value, UINT8);
5719 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5720 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5721                 port_id, UINT16);
5722
5723 cmdline_parse_inst_t cmd_set_bonding_mode = {
5724                 .f = cmd_set_bonding_mode_parsed,
5725                 .help_str = "set bonding mode <mode_value> <port_id>: "
5726                         "Set the bonding mode for port_id",
5727                 .data = NULL,
5728                 .tokens = {
5729                                 (void *) &cmd_setbonding_mode_set,
5730                                 (void *) &cmd_setbonding_mode_bonding,
5731                                 (void *) &cmd_setbonding_mode_mode,
5732                                 (void *) &cmd_setbonding_mode_value,
5733                                 (void *) &cmd_setbonding_mode_port,
5734                                 NULL
5735                 }
5736 };
5737
5738 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5739 struct cmd_set_bonding_lacp_dedicated_queues_result {
5740         cmdline_fixed_string_t set;
5741         cmdline_fixed_string_t bonding;
5742         cmdline_fixed_string_t lacp;
5743         cmdline_fixed_string_t dedicated_queues;
5744         portid_t port_id;
5745         cmdline_fixed_string_t mode;
5746 };
5747
5748 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5749                 __rte_unused  struct cmdline *cl,
5750                 __rte_unused void *data)
5751 {
5752         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5753         portid_t port_id = res->port_id;
5754         struct rte_port *port;
5755
5756         port = &ports[port_id];
5757
5758         /** Check if the port is not started **/
5759         if (port->port_status != RTE_PORT_STOPPED) {
5760                 printf("Please stop port %d first\n", port_id);
5761                 return;
5762         }
5763
5764         if (!strcmp(res->mode, "enable")) {
5765                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5766                         printf("Dedicate queues for LACP control packets"
5767                                         " enabled\n");
5768                 else
5769                         printf("Enabling dedicate queues for LACP control "
5770                                         "packets on port %d failed\n", port_id);
5771         } else if (!strcmp(res->mode, "disable")) {
5772                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5773                         printf("Dedicated queues for LACP control packets "
5774                                         "disabled\n");
5775                 else
5776                         printf("Disabling dedicated queues for LACP control "
5777                                         "traffic on port %d failed\n", port_id);
5778         }
5779 }
5780
5781 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5782 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5783                 set, "set");
5784 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5785 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5786                 bonding, "bonding");
5787 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5788 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5789                 lacp, "lacp");
5790 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5791 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5792                 dedicated_queues, "dedicated_queues");
5793 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5794 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5795                 port_id, UINT16);
5796 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5797 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5798                 mode, "enable#disable");
5799
5800 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5801                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5802                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5803                         "enable|disable: "
5804                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5805                 .data = NULL,
5806                 .tokens = {
5807                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5808                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5809                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5810                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5811                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5812                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5813                         NULL
5814                 }
5815 };
5816
5817 /* *** SET BALANCE XMIT POLICY *** */
5818 struct cmd_set_bonding_balance_xmit_policy_result {
5819         cmdline_fixed_string_t set;
5820         cmdline_fixed_string_t bonding;
5821         cmdline_fixed_string_t balance_xmit_policy;
5822         portid_t port_id;
5823         cmdline_fixed_string_t policy;
5824 };
5825
5826 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5827                 __rte_unused  struct cmdline *cl,
5828                 __rte_unused void *data)
5829 {
5830         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5831         portid_t port_id = res->port_id;
5832         uint8_t policy;
5833
5834         if (!strcmp(res->policy, "l2")) {
5835                 policy = BALANCE_XMIT_POLICY_LAYER2;
5836         } else if (!strcmp(res->policy, "l23")) {
5837                 policy = BALANCE_XMIT_POLICY_LAYER23;
5838         } else if (!strcmp(res->policy, "l34")) {
5839                 policy = BALANCE_XMIT_POLICY_LAYER34;
5840         } else {
5841                 printf("\t Invalid xmit policy selection");
5842                 return;
5843         }
5844
5845         /* Set the bonding mode for the relevant port. */
5846         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5847                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5848                                 port_id);
5849         }
5850 }
5851
5852 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5854                 set, "set");
5855 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5856 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5857                 bonding, "bonding");
5858 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5859 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5860                 balance_xmit_policy, "balance_xmit_policy");
5861 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5862 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5863                 port_id, UINT16);
5864 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5865 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5866                 policy, "l2#l23#l34");
5867
5868 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5869                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5870                 .help_str = "set bonding balance_xmit_policy <port_id> "
5871                         "l2|l23|l34: "
5872                         "Set the bonding balance_xmit_policy for port_id",
5873                 .data = NULL,
5874                 .tokens = {
5875                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5876                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5877                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5878                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5879                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5880                                 NULL
5881                 }
5882 };
5883
5884 /* *** SHOW NIC BONDING CONFIGURATION *** */
5885 struct cmd_show_bonding_config_result {
5886         cmdline_fixed_string_t show;
5887         cmdline_fixed_string_t bonding;
5888         cmdline_fixed_string_t config;
5889         portid_t port_id;
5890 };
5891
5892 static void cmd_show_bonding_config_parsed(void *parsed_result,
5893                 __rte_unused  struct cmdline *cl,
5894                 __rte_unused void *data)
5895 {
5896         struct cmd_show_bonding_config_result *res = parsed_result;
5897         int bonding_mode, agg_mode;
5898         portid_t slaves[RTE_MAX_ETHPORTS];
5899         int num_slaves, num_active_slaves;
5900         int primary_id;
5901         int i;
5902         portid_t port_id = res->port_id;
5903
5904         /* Display the bonding mode.*/
5905         bonding_mode = rte_eth_bond_mode_get(port_id);
5906         if (bonding_mode < 0) {
5907                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5908                 return;
5909         } else
5910                 printf("\tBonding mode: %d\n", bonding_mode);
5911
5912         if (bonding_mode == BONDING_MODE_BALANCE) {
5913                 int balance_xmit_policy;
5914
5915                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5916                 if (balance_xmit_policy < 0) {
5917                         printf("\tFailed to get balance xmit policy for port = %d\n",
5918                                         port_id);
5919                         return;
5920                 } else {
5921                         printf("\tBalance Xmit Policy: ");
5922
5923                         switch (balance_xmit_policy) {
5924                         case BALANCE_XMIT_POLICY_LAYER2:
5925                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5926                                 break;
5927                         case BALANCE_XMIT_POLICY_LAYER23:
5928                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5929                                 break;
5930                         case BALANCE_XMIT_POLICY_LAYER34:
5931                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5932                                 break;
5933                         }
5934                         printf("\n");
5935                 }
5936         }
5937
5938         if (bonding_mode == BONDING_MODE_8023AD) {
5939                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5940                 printf("\tIEEE802.3AD Aggregator Mode: ");
5941                 switch (agg_mode) {
5942                 case AGG_BANDWIDTH:
5943                         printf("bandwidth");
5944                         break;
5945                 case AGG_STABLE:
5946                         printf("stable");
5947                         break;
5948                 case AGG_COUNT:
5949                         printf("count");
5950                         break;
5951                 }
5952                 printf("\n");
5953         }
5954
5955         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5956
5957         if (num_slaves < 0) {
5958                 printf("\tFailed to get slave list for port = %d\n", port_id);
5959                 return;
5960         }
5961         if (num_slaves > 0) {
5962                 printf("\tSlaves (%d): [", num_slaves);
5963                 for (i = 0; i < num_slaves - 1; i++)
5964                         printf("%d ", slaves[i]);
5965
5966                 printf("%d]\n", slaves[num_slaves - 1]);
5967         } else {
5968                 printf("\tSlaves: []\n");
5969
5970         }
5971
5972         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5973                         RTE_MAX_ETHPORTS);
5974
5975         if (num_active_slaves < 0) {
5976                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5977                 return;
5978         }
5979         if (num_active_slaves > 0) {
5980                 printf("\tActive Slaves (%d): [", num_active_slaves);
5981                 for (i = 0; i < num_active_slaves - 1; i++)
5982                         printf("%d ", slaves[i]);
5983
5984                 printf("%d]\n", slaves[num_active_slaves - 1]);
5985
5986         } else {
5987                 printf("\tActive Slaves: []\n");
5988
5989         }
5990
5991         primary_id = rte_eth_bond_primary_get(port_id);
5992         if (primary_id < 0) {
5993                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5994                 return;
5995         } else
5996                 printf("\tPrimary: [%d]\n", primary_id);
5997
5998 }
5999
6000 cmdline_parse_token_string_t cmd_showbonding_config_show =
6001 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6002                 show, "show");
6003 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6004 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6005                 bonding, "bonding");
6006 cmdline_parse_token_string_t cmd_showbonding_config_config =
6007 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6008                 config, "config");
6009 cmdline_parse_token_num_t cmd_showbonding_config_port =
6010 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6011                 port_id, UINT16);
6012
6013 cmdline_parse_inst_t cmd_show_bonding_config = {
6014                 .f = cmd_show_bonding_config_parsed,
6015                 .help_str = "show bonding config <port_id>: "
6016                         "Show the bonding config for port_id",
6017                 .data = NULL,
6018                 .tokens = {
6019                                 (void *)&cmd_showbonding_config_show,
6020                                 (void *)&cmd_showbonding_config_bonding,
6021                                 (void *)&cmd_showbonding_config_config,
6022                                 (void *)&cmd_showbonding_config_port,
6023                                 NULL
6024                 }
6025 };
6026
6027 /* *** SET BONDING PRIMARY *** */
6028 struct cmd_set_bonding_primary_result {
6029         cmdline_fixed_string_t set;
6030         cmdline_fixed_string_t bonding;
6031         cmdline_fixed_string_t primary;
6032         portid_t slave_id;
6033         portid_t port_id;
6034 };
6035
6036 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6037                 __rte_unused  struct cmdline *cl,
6038                 __rte_unused void *data)
6039 {
6040         struct cmd_set_bonding_primary_result *res = parsed_result;
6041         portid_t master_port_id = res->port_id;
6042         portid_t slave_port_id = res->slave_id;
6043
6044         /* Set the primary slave for a bonded device. */
6045         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6046                 printf("\t Failed to set primary slave for port = %d.\n",
6047                                 master_port_id);
6048                 return;
6049         }
6050         init_port_config();
6051 }
6052
6053 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6054 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6055                 set, "set");
6056 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6057 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6058                 bonding, "bonding");
6059 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6060 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6061                 primary, "primary");
6062 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6063 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6064                 slave_id, UINT16);
6065 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6066 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6067                 port_id, UINT16);
6068
6069 cmdline_parse_inst_t cmd_set_bonding_primary = {
6070                 .f = cmd_set_bonding_primary_parsed,
6071                 .help_str = "set bonding primary <slave_id> <port_id>: "
6072                         "Set the primary slave for port_id",
6073                 .data = NULL,
6074                 .tokens = {
6075                                 (void *)&cmd_setbonding_primary_set,
6076                                 (void *)&cmd_setbonding_primary_bonding,
6077                                 (void *)&cmd_setbonding_primary_primary,
6078                                 (void *)&cmd_setbonding_primary_slave,
6079                                 (void *)&cmd_setbonding_primary_port,
6080                                 NULL
6081                 }
6082 };
6083
6084 /* *** ADD SLAVE *** */
6085 struct cmd_add_bonding_slave_result {
6086         cmdline_fixed_string_t add;
6087         cmdline_fixed_string_t bonding;
6088         cmdline_fixed_string_t slave;
6089         portid_t slave_id;
6090         portid_t port_id;
6091 };
6092
6093 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6094                 __rte_unused  struct cmdline *cl,
6095                 __rte_unused void *data)
6096 {
6097         struct cmd_add_bonding_slave_result *res = parsed_result;
6098         portid_t master_port_id = res->port_id;
6099         portid_t slave_port_id = res->slave_id;
6100
6101         /* add the slave for a bonded device. */
6102         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6103                 printf("\t Failed to add slave %d to master port = %d.\n",
6104                                 slave_port_id, master_port_id);
6105                 return;
6106         }
6107         init_port_config();
6108         set_port_slave_flag(slave_port_id);
6109 }
6110
6111 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6112 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6113                 add, "add");
6114 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6115 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6116                 bonding, "bonding");
6117 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6118 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6119                 slave, "slave");
6120 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6121 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6122                 slave_id, UINT16);
6123 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6124 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6125                 port_id, UINT16);
6126
6127 cmdline_parse_inst_t cmd_add_bonding_slave = {
6128                 .f = cmd_add_bonding_slave_parsed,
6129                 .help_str = "add bonding slave <slave_id> <port_id>: "
6130                         "Add a slave device to a bonded device",
6131                 .data = NULL,
6132                 .tokens = {
6133                                 (void *)&cmd_addbonding_slave_add,
6134                                 (void *)&cmd_addbonding_slave_bonding,
6135                                 (void *)&cmd_addbonding_slave_slave,
6136                                 (void *)&cmd_addbonding_slave_slaveid,
6137                                 (void *)&cmd_addbonding_slave_port,
6138                                 NULL
6139                 }
6140 };
6141
6142 /* *** REMOVE SLAVE *** */
6143 struct cmd_remove_bonding_slave_result {
6144         cmdline_fixed_string_t remove;
6145         cmdline_fixed_string_t bonding;
6146         cmdline_fixed_string_t slave;
6147         portid_t slave_id;
6148         portid_t port_id;
6149 };
6150
6151 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6152                 __rte_unused  struct cmdline *cl,
6153                 __rte_unused void *data)
6154 {
6155         struct cmd_remove_bonding_slave_result *res = parsed_result;
6156         portid_t master_port_id = res->port_id;
6157         portid_t slave_port_id = res->slave_id;
6158
6159         /* remove the slave from a bonded device. */
6160         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6161                 printf("\t Failed to remove slave %d from master port = %d.\n",
6162                                 slave_port_id, master_port_id);
6163                 return;
6164         }
6165         init_port_config();
6166         clear_port_slave_flag(slave_port_id);
6167 }
6168
6169 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6170                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6171                                 remove, "remove");
6172 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6173                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6174                                 bonding, "bonding");
6175 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6176                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6177                                 slave, "slave");
6178 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6179                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6180                                 slave_id, UINT16);
6181 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6182                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6183                                 port_id, UINT16);
6184
6185 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6186                 .f = cmd_remove_bonding_slave_parsed,
6187                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6188                         "Remove a slave device from a bonded device",
6189                 .data = NULL,
6190                 .tokens = {
6191                                 (void *)&cmd_removebonding_slave_remove,
6192                                 (void *)&cmd_removebonding_slave_bonding,
6193                                 (void *)&cmd_removebonding_slave_slave,
6194                                 (void *)&cmd_removebonding_slave_slaveid,
6195                                 (void *)&cmd_removebonding_slave_port,
6196                                 NULL
6197                 }
6198 };
6199
6200 /* *** CREATE BONDED DEVICE *** */
6201 struct cmd_create_bonded_device_result {
6202         cmdline_fixed_string_t create;
6203         cmdline_fixed_string_t bonded;
6204         cmdline_fixed_string_t device;
6205         uint8_t mode;
6206         uint8_t socket;
6207 };
6208
6209 static int bond_dev_num = 0;
6210
6211 static void cmd_create_bonded_device_parsed(void *parsed_result,
6212                 __rte_unused  struct cmdline *cl,
6213                 __rte_unused void *data)
6214 {
6215         struct cmd_create_bonded_device_result *res = parsed_result;
6216         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6217         int port_id;
6218         int ret;
6219
6220         if (test_done == 0) {
6221                 printf("Please stop forwarding first\n");
6222                 return;
6223         }
6224
6225         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6226                         bond_dev_num++);
6227
6228         /* Create a new bonded device. */
6229         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6230         if (port_id < 0) {
6231                 printf("\t Failed to create bonded device.\n");
6232                 return;
6233         } else {
6234                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6235                                 port_id);
6236
6237                 /* Update number of ports */
6238                 nb_ports = rte_eth_dev_count_avail();
6239                 reconfig(port_id, res->socket);
6240                 ret = rte_eth_promiscuous_enable(port_id);
6241                 if (ret != 0)
6242                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6243                                 port_id, rte_strerror(-ret));
6244
6245                 ports[port_id].need_setup = 0;
6246                 ports[port_id].port_status = RTE_PORT_STOPPED;
6247         }
6248
6249 }
6250
6251 cmdline_parse_token_string_t cmd_createbonded_device_create =
6252                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6253                                 create, "create");
6254 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6255                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6256                                 bonded, "bonded");
6257 cmdline_parse_token_string_t cmd_createbonded_device_device =
6258                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6259                                 device, "device");
6260 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6261                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6262                                 mode, UINT8);
6263 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6264                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6265                                 socket, UINT8);
6266
6267 cmdline_parse_inst_t cmd_create_bonded_device = {
6268                 .f = cmd_create_bonded_device_parsed,
6269                 .help_str = "create bonded device <mode> <socket>: "
6270                         "Create a new bonded device with specific bonding mode and socket",
6271                 .data = NULL,
6272                 .tokens = {
6273                                 (void *)&cmd_createbonded_device_create,
6274                                 (void *)&cmd_createbonded_device_bonded,
6275                                 (void *)&cmd_createbonded_device_device,
6276                                 (void *)&cmd_createbonded_device_mode,
6277                                 (void *)&cmd_createbonded_device_socket,
6278                                 NULL
6279                 }
6280 };
6281
6282 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6283 struct cmd_set_bond_mac_addr_result {
6284         cmdline_fixed_string_t set;
6285         cmdline_fixed_string_t bonding;
6286         cmdline_fixed_string_t mac_addr;
6287         uint16_t port_num;
6288         struct rte_ether_addr address;
6289 };
6290
6291 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6292                 __rte_unused  struct cmdline *cl,
6293                 __rte_unused void *data)
6294 {
6295         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6296         int ret;
6297
6298         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6299                 return;
6300
6301         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6302
6303         /* check the return value and print it if is < 0 */
6304         if (ret < 0)
6305                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6306 }
6307
6308 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6309                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6310 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6311                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6312                                 "bonding");
6313 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6314                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6315                                 "mac_addr");
6316 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6317                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6318                                 port_num, UINT16);
6319 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6320                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6321
6322 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6323                 .f = cmd_set_bond_mac_addr_parsed,
6324                 .data = (void *) 0,
6325                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6326                 .tokens = {
6327                                 (void *)&cmd_set_bond_mac_addr_set,
6328                                 (void *)&cmd_set_bond_mac_addr_bonding,
6329                                 (void *)&cmd_set_bond_mac_addr_mac,
6330                                 (void *)&cmd_set_bond_mac_addr_portnum,
6331                                 (void *)&cmd_set_bond_mac_addr_addr,
6332                                 NULL
6333                 }
6334 };
6335
6336
6337 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6338 struct cmd_set_bond_mon_period_result {
6339         cmdline_fixed_string_t set;
6340         cmdline_fixed_string_t bonding;
6341         cmdline_fixed_string_t mon_period;
6342         uint16_t port_num;
6343         uint32_t period_ms;
6344 };
6345
6346 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6347                 __rte_unused  struct cmdline *cl,
6348                 __rte_unused void *data)
6349 {
6350         struct cmd_set_bond_mon_period_result *res = parsed_result;
6351         int ret;
6352
6353         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6354
6355         /* check the return value and print it if is < 0 */
6356         if (ret < 0)
6357                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6358 }
6359
6360 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6361                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6362                                 set, "set");
6363 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6364                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6365                                 bonding, "bonding");
6366 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6367                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6368                                 mon_period,     "mon_period");
6369 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6370                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6371                                 port_num, UINT16);
6372 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6373                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6374                                 period_ms, UINT32);
6375
6376 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6377                 .f = cmd_set_bond_mon_period_parsed,
6378                 .data = (void *) 0,
6379                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6380                 .tokens = {
6381                                 (void *)&cmd_set_bond_mon_period_set,
6382                                 (void *)&cmd_set_bond_mon_period_bonding,
6383                                 (void *)&cmd_set_bond_mon_period_mon_period,
6384                                 (void *)&cmd_set_bond_mon_period_portnum,
6385                                 (void *)&cmd_set_bond_mon_period_period_ms,
6386                                 NULL
6387                 }
6388 };
6389
6390
6391
6392 struct cmd_set_bonding_agg_mode_policy_result {
6393         cmdline_fixed_string_t set;
6394         cmdline_fixed_string_t bonding;
6395         cmdline_fixed_string_t agg_mode;
6396         uint16_t port_num;
6397         cmdline_fixed_string_t policy;
6398 };
6399
6400
6401 static void
6402 cmd_set_bonding_agg_mode(void *parsed_result,
6403                 __rte_unused struct cmdline *cl,
6404                 __rte_unused void *data)
6405 {
6406         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6407         uint8_t policy = AGG_BANDWIDTH;
6408
6409         if (!strcmp(res->policy, "bandwidth"))
6410                 policy = AGG_BANDWIDTH;
6411         else if (!strcmp(res->policy, "stable"))
6412                 policy = AGG_STABLE;
6413         else if (!strcmp(res->policy, "count"))
6414                 policy = AGG_COUNT;
6415
6416         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6417 }
6418
6419
6420 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6421         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6422                                 set, "set");
6423 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6424         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6425                                 bonding, "bonding");
6426
6427 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6428         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6429                                 agg_mode, "agg_mode");
6430
6431 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6432         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6433                                 port_num, UINT16);
6434
6435 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6436         TOKEN_STRING_INITIALIZER(
6437                         struct cmd_set_bonding_balance_xmit_policy_result,
6438                 policy, "stable#bandwidth#count");
6439
6440 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6441         .f = cmd_set_bonding_agg_mode,
6442         .data = (void *) 0,
6443         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6444         .tokens = {
6445                         (void *)&cmd_set_bonding_agg_mode_set,
6446                         (void *)&cmd_set_bonding_agg_mode_bonding,
6447                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6448                         (void *)&cmd_set_bonding_agg_mode_portnum,
6449                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6450                         NULL
6451                 }
6452 };
6453
6454
6455 #endif /* RTE_LIBRTE_PMD_BOND */
6456
6457 /* *** SET FORWARDING MODE *** */
6458 struct cmd_set_fwd_mode_result {
6459         cmdline_fixed_string_t set;
6460         cmdline_fixed_string_t fwd;
6461         cmdline_fixed_string_t mode;
6462 };
6463
6464 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6465                                     __rte_unused struct cmdline *cl,
6466                                     __rte_unused void *data)
6467 {
6468         struct cmd_set_fwd_mode_result *res = parsed_result;
6469
6470         retry_enabled = 0;
6471         set_pkt_forwarding_mode(res->mode);
6472 }
6473
6474 cmdline_parse_token_string_t cmd_setfwd_set =
6475         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6476 cmdline_parse_token_string_t cmd_setfwd_fwd =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6478 cmdline_parse_token_string_t cmd_setfwd_mode =
6479         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6480                 "" /* defined at init */);
6481
6482 cmdline_parse_inst_t cmd_set_fwd_mode = {
6483         .f = cmd_set_fwd_mode_parsed,
6484         .data = NULL,
6485         .help_str = NULL, /* defined at init */
6486         .tokens = {
6487                 (void *)&cmd_setfwd_set,
6488                 (void *)&cmd_setfwd_fwd,
6489                 (void *)&cmd_setfwd_mode,
6490                 NULL,
6491         },
6492 };
6493
6494 static void cmd_set_fwd_mode_init(void)
6495 {
6496         char *modes, *c;
6497         static char token[128];
6498         static char help[256];
6499         cmdline_parse_token_string_t *token_struct;
6500
6501         modes = list_pkt_forwarding_modes();
6502         snprintf(help, sizeof(help), "set fwd %s: "
6503                 "Set packet forwarding mode", modes);
6504         cmd_set_fwd_mode.help_str = help;
6505
6506         /* string token separator is # */
6507         for (c = token; *modes != '\0'; modes++)
6508                 if (*modes == '|')
6509                         *c++ = '#';
6510                 else
6511                         *c++ = *modes;
6512         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6513         token_struct->string_data.str = token;
6514 }
6515
6516 /* *** SET RETRY FORWARDING MODE *** */
6517 struct cmd_set_fwd_retry_mode_result {
6518         cmdline_fixed_string_t set;
6519         cmdline_fixed_string_t fwd;
6520         cmdline_fixed_string_t mode;
6521         cmdline_fixed_string_t retry;
6522 };
6523
6524 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6525                             __rte_unused struct cmdline *cl,
6526                             __rte_unused void *data)
6527 {
6528         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6529
6530         retry_enabled = 1;
6531         set_pkt_forwarding_mode(res->mode);
6532 }
6533
6534 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6535         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6536                         set, "set");
6537 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6538         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6539                         fwd, "fwd");
6540 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6542                         mode,
6543                 "" /* defined at init */);
6544 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6545         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6546                         retry, "retry");
6547
6548 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6549         .f = cmd_set_fwd_retry_mode_parsed,
6550         .data = NULL,
6551         .help_str = NULL, /* defined at init */
6552         .tokens = {
6553                 (void *)&cmd_setfwd_retry_set,
6554                 (void *)&cmd_setfwd_retry_fwd,
6555                 (void *)&cmd_setfwd_retry_mode,
6556                 (void *)&cmd_setfwd_retry_retry,
6557                 NULL,
6558         },
6559 };
6560
6561 static void cmd_set_fwd_retry_mode_init(void)
6562 {
6563         char *modes, *c;
6564         static char token[128];
6565         static char help[256];
6566         cmdline_parse_token_string_t *token_struct;
6567
6568         modes = list_pkt_forwarding_retry_modes();
6569         snprintf(help, sizeof(help), "set fwd %s retry: "
6570                 "Set packet forwarding mode with retry", modes);
6571         cmd_set_fwd_retry_mode.help_str = help;
6572
6573         /* string token separator is # */
6574         for (c = token; *modes != '\0'; modes++)
6575                 if (*modes == '|')
6576                         *c++ = '#';
6577                 else
6578                         *c++ = *modes;
6579         token_struct = (cmdline_parse_token_string_t *)
6580                 cmd_set_fwd_retry_mode.tokens[2];
6581         token_struct->string_data.str = token;
6582 }
6583
6584 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6585 struct cmd_set_burst_tx_retry_result {
6586         cmdline_fixed_string_t set;
6587         cmdline_fixed_string_t burst;
6588         cmdline_fixed_string_t tx;
6589         cmdline_fixed_string_t delay;
6590         uint32_t time;
6591         cmdline_fixed_string_t retry;
6592         uint32_t retry_num;
6593 };
6594
6595 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6596                                         __rte_unused struct cmdline *cl,
6597                                         __rte_unused void *data)
6598 {
6599         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6600
6601         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6602                 && !strcmp(res->tx, "tx")) {
6603                 if (!strcmp(res->delay, "delay"))
6604                         burst_tx_delay_time = res->time;
6605                 if (!strcmp(res->retry, "retry"))
6606                         burst_tx_retry_num = res->retry_num;
6607         }
6608
6609 }
6610
6611 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6612         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6613 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6614         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6615                                  "burst");
6616 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6617         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6618 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6619         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6620 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6621         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6622 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6624 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6625         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6626
6627 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6628         .f = cmd_set_burst_tx_retry_parsed,
6629         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6630         .tokens = {
6631                 (void *)&cmd_set_burst_tx_retry_set,
6632                 (void *)&cmd_set_burst_tx_retry_burst,
6633                 (void *)&cmd_set_burst_tx_retry_tx,
6634                 (void *)&cmd_set_burst_tx_retry_delay,
6635                 (void *)&cmd_set_burst_tx_retry_time,
6636                 (void *)&cmd_set_burst_tx_retry_retry,
6637                 (void *)&cmd_set_burst_tx_retry_retry_num,
6638                 NULL,
6639         },
6640 };
6641
6642 /* *** SET PROMISC MODE *** */
6643 struct cmd_set_promisc_mode_result {
6644         cmdline_fixed_string_t set;
6645         cmdline_fixed_string_t promisc;
6646         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6647         uint16_t port_num;               /* valid if "allports" argument == 0 */
6648         cmdline_fixed_string_t mode;
6649 };
6650
6651 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6652                                         __rte_unused struct cmdline *cl,
6653                                         void *allports)
6654 {
6655         struct cmd_set_promisc_mode_result *res = parsed_result;
6656         int enable;
6657         portid_t i;
6658
6659         if (!strcmp(res->mode, "on"))
6660                 enable = 1;
6661         else
6662                 enable = 0;
6663
6664         /* all ports */
6665         if (allports) {
6666                 RTE_ETH_FOREACH_DEV(i)
6667                         eth_set_promisc_mode(i, enable);
6668         } else {
6669                 eth_set_promisc_mode(res->port_num, enable);
6670         }
6671 }
6672
6673 cmdline_parse_token_string_t cmd_setpromisc_set =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6675 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6677                                  "promisc");
6678 cmdline_parse_token_string_t cmd_setpromisc_portall =
6679         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6680                                  "all");
6681 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6682         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6683                               UINT16);
6684 cmdline_parse_token_string_t cmd_setpromisc_mode =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6686                                  "on#off");
6687
6688 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6689         .f = cmd_set_promisc_mode_parsed,
6690         .data = (void *)1,
6691         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6692         .tokens = {
6693                 (void *)&cmd_setpromisc_set,
6694                 (void *)&cmd_setpromisc_promisc,
6695                 (void *)&cmd_setpromisc_portall,
6696                 (void *)&cmd_setpromisc_mode,
6697                 NULL,
6698         },
6699 };
6700
6701 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6702         .f = cmd_set_promisc_mode_parsed,
6703         .data = (void *)0,
6704         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6705         .tokens = {
6706                 (void *)&cmd_setpromisc_set,
6707                 (void *)&cmd_setpromisc_promisc,
6708                 (void *)&cmd_setpromisc_portnum,
6709                 (void *)&cmd_setpromisc_mode,
6710                 NULL,
6711         },
6712 };
6713
6714 /* *** SET ALLMULTI MODE *** */
6715 struct cmd_set_allmulti_mode_result {
6716         cmdline_fixed_string_t set;
6717         cmdline_fixed_string_t allmulti;
6718         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6719         uint16_t port_num;               /* valid if "allports" argument == 0 */
6720         cmdline_fixed_string_t mode;
6721 };
6722
6723 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6724                                         __rte_unused struct cmdline *cl,
6725                                         void *allports)
6726 {
6727         struct cmd_set_allmulti_mode_result *res = parsed_result;
6728         int enable;
6729         portid_t i;
6730
6731         if (!strcmp(res->mode, "on"))
6732                 enable = 1;
6733         else
6734                 enable = 0;
6735
6736         /* all ports */
6737         if (allports) {
6738                 RTE_ETH_FOREACH_DEV(i) {
6739                         eth_set_allmulticast_mode(i, enable);
6740                 }
6741         }
6742         else {
6743                 eth_set_allmulticast_mode(res->port_num, enable);
6744         }
6745 }
6746
6747 cmdline_parse_token_string_t cmd_setallmulti_set =
6748         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6749 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6750         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6751                                  "allmulti");
6752 cmdline_parse_token_string_t cmd_setallmulti_portall =
6753         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6754                                  "all");
6755 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6756         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6757                               UINT16);
6758 cmdline_parse_token_string_t cmd_setallmulti_mode =
6759         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6760                                  "on#off");
6761
6762 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6763         .f = cmd_set_allmulti_mode_parsed,
6764         .data = (void *)1,
6765         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6766         .tokens = {
6767                 (void *)&cmd_setallmulti_set,
6768                 (void *)&cmd_setallmulti_allmulti,
6769                 (void *)&cmd_setallmulti_portall,
6770                 (void *)&cmd_setallmulti_mode,
6771                 NULL,
6772         },
6773 };
6774
6775 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6776         .f = cmd_set_allmulti_mode_parsed,
6777         .data = (void *)0,
6778         .help_str = "set allmulti <port_id> on|off: "
6779                 "Set allmulti mode on port_id",
6780         .tokens = {
6781                 (void *)&cmd_setallmulti_set,
6782                 (void *)&cmd_setallmulti_allmulti,
6783                 (void *)&cmd_setallmulti_portnum,
6784                 (void *)&cmd_setallmulti_mode,
6785                 NULL,
6786         },
6787 };
6788
6789 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6790 struct cmd_link_flow_ctrl_set_result {
6791         cmdline_fixed_string_t set;
6792         cmdline_fixed_string_t flow_ctrl;
6793         cmdline_fixed_string_t rx;
6794         cmdline_fixed_string_t rx_lfc_mode;
6795         cmdline_fixed_string_t tx;
6796         cmdline_fixed_string_t tx_lfc_mode;
6797         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6798         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6799         cmdline_fixed_string_t autoneg_str;
6800         cmdline_fixed_string_t autoneg;
6801         cmdline_fixed_string_t hw_str;
6802         uint32_t high_water;
6803         cmdline_fixed_string_t lw_str;
6804         uint32_t low_water;
6805         cmdline_fixed_string_t pt_str;
6806         uint16_t pause_time;
6807         cmdline_fixed_string_t xon_str;
6808         uint16_t send_xon;
6809         portid_t port_id;
6810 };
6811
6812 cmdline_parse_token_string_t cmd_lfc_set_set =
6813         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6814                                 set, "set");
6815 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6816         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6817                                 flow_ctrl, "flow_ctrl");
6818 cmdline_parse_token_string_t cmd_lfc_set_rx =
6819         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6820                                 rx, "rx");
6821 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6822         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6823                                 rx_lfc_mode, "on#off");
6824 cmdline_parse_token_string_t cmd_lfc_set_tx =
6825         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6826                                 tx, "tx");
6827 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6828         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6829                                 tx_lfc_mode, "on#off");
6830 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6831         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6832                                 hw_str, "high_water");
6833 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6834         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6835                                 high_water, UINT32);
6836 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6837         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6838                                 lw_str, "low_water");
6839 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6840         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6841                                 low_water, UINT32);
6842 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6843         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6844                                 pt_str, "pause_time");
6845 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6846         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6847                                 pause_time, UINT16);
6848 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6849         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6850                                 xon_str, "send_xon");
6851 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6852         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6853                                 send_xon, UINT16);
6854 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6855         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6856                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6857 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6858         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6859                                 mac_ctrl_frame_fwd_mode, "on#off");
6860 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6861         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6862                                 autoneg_str, "autoneg");
6863 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6864         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6865                                 autoneg, "on#off");
6866 cmdline_parse_token_num_t cmd_lfc_set_portid =
6867         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6868                                 port_id, UINT16);
6869
6870 /* forward declaration */
6871 static void
6872 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6873                               void *data);
6874
6875 cmdline_parse_inst_t cmd_link_flow_control_set = {
6876         .f = cmd_link_flow_ctrl_set_parsed,
6877         .data = NULL,
6878         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6879                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6880                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6881         .tokens = {
6882                 (void *)&cmd_lfc_set_set,
6883                 (void *)&cmd_lfc_set_flow_ctrl,
6884                 (void *)&cmd_lfc_set_rx,
6885                 (void *)&cmd_lfc_set_rx_mode,
6886                 (void *)&cmd_lfc_set_tx,
6887                 (void *)&cmd_lfc_set_tx_mode,
6888                 (void *)&cmd_lfc_set_high_water,
6889                 (void *)&cmd_lfc_set_low_water,
6890                 (void *)&cmd_lfc_set_pause_time,
6891                 (void *)&cmd_lfc_set_send_xon,
6892                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6893                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6894                 (void *)&cmd_lfc_set_autoneg_str,
6895                 (void *)&cmd_lfc_set_autoneg,
6896                 (void *)&cmd_lfc_set_portid,
6897                 NULL,
6898         },
6899 };
6900
6901 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6902         .f = cmd_link_flow_ctrl_set_parsed,
6903         .data = (void *)&cmd_link_flow_control_set_rx,
6904         .help_str = "set flow_ctrl rx on|off <port_id>: "
6905                 "Change rx flow control parameter",
6906         .tokens = {
6907                 (void *)&cmd_lfc_set_set,
6908                 (void *)&cmd_lfc_set_flow_ctrl,
6909                 (void *)&cmd_lfc_set_rx,
6910                 (void *)&cmd_lfc_set_rx_mode,
6911                 (void *)&cmd_lfc_set_portid,
6912                 NULL,
6913         },
6914 };
6915
6916 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6917         .f = cmd_link_flow_ctrl_set_parsed,
6918         .data = (void *)&cmd_link_flow_control_set_tx,
6919         .help_str = "set flow_ctrl tx on|off <port_id>: "
6920                 "Change tx flow control parameter",
6921         .tokens = {
6922                 (void *)&cmd_lfc_set_set,
6923                 (void *)&cmd_lfc_set_flow_ctrl,
6924                 (void *)&cmd_lfc_set_tx,
6925                 (void *)&cmd_lfc_set_tx_mode,
6926                 (void *)&cmd_lfc_set_portid,
6927                 NULL,
6928         },
6929 };
6930
6931 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6932         .f = cmd_link_flow_ctrl_set_parsed,
6933         .data = (void *)&cmd_link_flow_control_set_hw,
6934         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6935                 "Change high water flow control parameter",
6936         .tokens = {
6937                 (void *)&cmd_lfc_set_set,
6938                 (void *)&cmd_lfc_set_flow_ctrl,
6939                 (void *)&cmd_lfc_set_high_water_str,
6940                 (void *)&cmd_lfc_set_high_water,
6941                 (void *)&cmd_lfc_set_portid,
6942                 NULL,
6943         },
6944 };
6945
6946 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6947         .f = cmd_link_flow_ctrl_set_parsed,
6948         .data = (void *)&cmd_link_flow_control_set_lw,
6949         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6950                 "Change low water flow control parameter",
6951         .tokens = {
6952                 (void *)&cmd_lfc_set_set,
6953                 (void *)&cmd_lfc_set_flow_ctrl,
6954                 (void *)&cmd_lfc_set_low_water_str,
6955                 (void *)&cmd_lfc_set_low_water,
6956                 (void *)&cmd_lfc_set_portid,
6957                 NULL,
6958         },
6959 };
6960
6961 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6962         .f = cmd_link_flow_ctrl_set_parsed,
6963         .data = (void *)&cmd_link_flow_control_set_pt,
6964         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6965                 "Change pause time flow control parameter",
6966         .tokens = {
6967                 (void *)&cmd_lfc_set_set,
6968                 (void *)&cmd_lfc_set_flow_ctrl,
6969                 (void *)&cmd_lfc_set_pause_time_str,
6970                 (void *)&cmd_lfc_set_pause_time,
6971                 (void *)&cmd_lfc_set_portid,
6972                 NULL,
6973         },
6974 };
6975
6976 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6977         .f = cmd_link_flow_ctrl_set_parsed,
6978         .data = (void *)&cmd_link_flow_control_set_xon,
6979         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6980                 "Change send_xon flow control parameter",
6981         .tokens = {
6982                 (void *)&cmd_lfc_set_set,
6983                 (void *)&cmd_lfc_set_flow_ctrl,
6984                 (void *)&cmd_lfc_set_send_xon_str,
6985                 (void *)&cmd_lfc_set_send_xon,
6986                 (void *)&cmd_lfc_set_portid,
6987                 NULL,
6988         },
6989 };
6990
6991 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6992         .f = cmd_link_flow_ctrl_set_parsed,
6993         .data = (void *)&cmd_link_flow_control_set_macfwd,
6994         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6995                 "Change mac ctrl fwd flow control parameter",
6996         .tokens = {
6997                 (void *)&cmd_lfc_set_set,
6998                 (void *)&cmd_lfc_set_flow_ctrl,
6999                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7000                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7001                 (void *)&cmd_lfc_set_portid,
7002                 NULL,
7003         },
7004 };
7005
7006 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7007         .f = cmd_link_flow_ctrl_set_parsed,
7008         .data = (void *)&cmd_link_flow_control_set_autoneg,
7009         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7010                 "Change autoneg flow control parameter",
7011         .tokens = {
7012                 (void *)&cmd_lfc_set_set,
7013                 (void *)&cmd_lfc_set_flow_ctrl,
7014                 (void *)&cmd_lfc_set_autoneg_str,
7015                 (void *)&cmd_lfc_set_autoneg,
7016                 (void *)&cmd_lfc_set_portid,
7017                 NULL,
7018         },
7019 };
7020
7021 static void
7022 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7023                               __rte_unused struct cmdline *cl,
7024                               void *data)
7025 {
7026         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7027         cmdline_parse_inst_t *cmd = data;
7028         struct rte_eth_fc_conf fc_conf;
7029         int rx_fc_en = 0;
7030         int tx_fc_en = 0;
7031         int ret;
7032
7033         /*
7034          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7035          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7036          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7037          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7038          */
7039         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7040                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7041         };
7042
7043         /* Partial command line, retrieve current configuration */
7044         if (cmd) {
7045                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7046                 if (ret != 0) {
7047                         printf("cannot get current flow ctrl parameters, return"
7048                                "code = %d\n", ret);
7049                         return;
7050                 }
7051
7052                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7053                     (fc_conf.mode == RTE_FC_FULL))
7054                         rx_fc_en = 1;
7055                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7056                     (fc_conf.mode == RTE_FC_FULL))
7057                         tx_fc_en = 1;
7058         }
7059
7060         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7061                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7062
7063         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7064                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7065
7066         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7067
7068         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7069                 fc_conf.high_water = res->high_water;
7070
7071         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7072                 fc_conf.low_water = res->low_water;
7073
7074         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7075                 fc_conf.pause_time = res->pause_time;
7076
7077         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7078                 fc_conf.send_xon = res->send_xon;
7079
7080         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7081                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7082                         fc_conf.mac_ctrl_frame_fwd = 1;
7083                 else
7084                         fc_conf.mac_ctrl_frame_fwd = 0;
7085         }
7086
7087         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7088                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7089
7090         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7091         if (ret != 0)
7092                 printf("bad flow contrl parameter, return code = %d \n", ret);
7093 }
7094
7095 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7096 struct cmd_priority_flow_ctrl_set_result {
7097         cmdline_fixed_string_t set;
7098         cmdline_fixed_string_t pfc_ctrl;
7099         cmdline_fixed_string_t rx;
7100         cmdline_fixed_string_t rx_pfc_mode;
7101         cmdline_fixed_string_t tx;
7102         cmdline_fixed_string_t tx_pfc_mode;
7103         uint32_t high_water;
7104         uint32_t low_water;
7105         uint16_t pause_time;
7106         uint8_t  priority;
7107         portid_t port_id;
7108 };
7109
7110 static void
7111 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7112                        __rte_unused struct cmdline *cl,
7113                        __rte_unused void *data)
7114 {
7115         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7116         struct rte_eth_pfc_conf pfc_conf;
7117         int rx_fc_enable, tx_fc_enable;
7118         int ret;
7119
7120         /*
7121          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7122          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7123          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7124          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7125          */
7126         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7127                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7128         };
7129
7130         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7131         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7132         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7133         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7134         pfc_conf.fc.high_water = res->high_water;
7135         pfc_conf.fc.low_water  = res->low_water;
7136         pfc_conf.fc.pause_time = res->pause_time;
7137         pfc_conf.priority      = res->priority;
7138
7139         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7140         if (ret != 0)
7141                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7142 }
7143
7144 cmdline_parse_token_string_t cmd_pfc_set_set =
7145         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7146                                 set, "set");
7147 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7148         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7149                                 pfc_ctrl, "pfc_ctrl");
7150 cmdline_parse_token_string_t cmd_pfc_set_rx =
7151         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7152                                 rx, "rx");
7153 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7154         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7155                                 rx_pfc_mode, "on#off");
7156 cmdline_parse_token_string_t cmd_pfc_set_tx =
7157         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7158                                 tx, "tx");
7159 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7160         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7161                                 tx_pfc_mode, "on#off");
7162 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7163         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7164                                 high_water, UINT32);
7165 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7166         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7167                                 low_water, UINT32);
7168 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7169         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7170                                 pause_time, UINT16);
7171 cmdline_parse_token_num_t cmd_pfc_set_priority =
7172         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7173                                 priority, UINT8);
7174 cmdline_parse_token_num_t cmd_pfc_set_portid =
7175         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7176                                 port_id, UINT16);
7177
7178 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7179         .f = cmd_priority_flow_ctrl_set_parsed,
7180         .data = NULL,
7181         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7182                 "<pause_time> <priority> <port_id>: "
7183                 "Configure the Ethernet priority flow control",
7184         .tokens = {
7185                 (void *)&cmd_pfc_set_set,
7186                 (void *)&cmd_pfc_set_flow_ctrl,
7187                 (void *)&cmd_pfc_set_rx,
7188                 (void *)&cmd_pfc_set_rx_mode,
7189                 (void *)&cmd_pfc_set_tx,
7190                 (void *)&cmd_pfc_set_tx_mode,
7191                 (void *)&cmd_pfc_set_high_water,
7192                 (void *)&cmd_pfc_set_low_water,
7193                 (void *)&cmd_pfc_set_pause_time,
7194                 (void *)&cmd_pfc_set_priority,
7195                 (void *)&cmd_pfc_set_portid,
7196                 NULL,
7197         },
7198 };
7199
7200 /* *** RESET CONFIGURATION *** */
7201 struct cmd_reset_result {
7202         cmdline_fixed_string_t reset;
7203         cmdline_fixed_string_t def;
7204 };
7205
7206 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7207                              struct cmdline *cl,
7208                              __rte_unused void *data)
7209 {
7210         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7211         set_def_fwd_config();
7212 }
7213
7214 cmdline_parse_token_string_t cmd_reset_set =
7215         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7216 cmdline_parse_token_string_t cmd_reset_def =
7217         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7218                                  "default");
7219
7220 cmdline_parse_inst_t cmd_reset = {
7221         .f = cmd_reset_parsed,
7222         .data = NULL,
7223         .help_str = "set default: Reset default forwarding configuration",
7224         .tokens = {
7225                 (void *)&cmd_reset_set,
7226                 (void *)&cmd_reset_def,
7227                 NULL,
7228         },
7229 };
7230
7231 /* *** START FORWARDING *** */
7232 struct cmd_start_result {
7233         cmdline_fixed_string_t start;
7234 };
7235
7236 cmdline_parse_token_string_t cmd_start_start =
7237         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7238
7239 static void cmd_start_parsed(__rte_unused void *parsed_result,
7240                              __rte_unused struct cmdline *cl,
7241                              __rte_unused void *data)
7242 {
7243         start_packet_forwarding(0);
7244 }
7245
7246 cmdline_parse_inst_t cmd_start = {
7247         .f = cmd_start_parsed,
7248         .data = NULL,
7249         .help_str = "start: Start packet forwarding",
7250         .tokens = {
7251                 (void *)&cmd_start_start,
7252                 NULL,
7253         },
7254 };
7255
7256 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7257 struct cmd_start_tx_first_result {
7258         cmdline_fixed_string_t start;
7259         cmdline_fixed_string_t tx_first;
7260 };
7261
7262 static void
7263 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7264                           __rte_unused struct cmdline *cl,
7265                           __rte_unused void *data)
7266 {
7267         start_packet_forwarding(1);
7268 }
7269
7270 cmdline_parse_token_string_t cmd_start_tx_first_start =
7271         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7272                                  "start");
7273 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7274         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7275                                  tx_first, "tx_first");
7276
7277 cmdline_parse_inst_t cmd_start_tx_first = {
7278         .f = cmd_start_tx_first_parsed,
7279         .data = NULL,
7280         .help_str = "start tx_first: Start packet forwarding, "
7281                 "after sending 1 burst of packets",
7282         .tokens = {
7283                 (void *)&cmd_start_tx_first_start,
7284                 (void *)&cmd_start_tx_first_tx_first,
7285                 NULL,
7286         },
7287 };
7288
7289 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7290 struct cmd_start_tx_first_n_result {
7291         cmdline_fixed_string_t start;
7292         cmdline_fixed_string_t tx_first;
7293         uint32_t tx_num;
7294 };
7295
7296 static void
7297 cmd_start_tx_first_n_parsed(void *parsed_result,
7298                           __rte_unused struct cmdline *cl,
7299                           __rte_unused void *data)
7300 {
7301         struct cmd_start_tx_first_n_result *res = parsed_result;
7302
7303         start_packet_forwarding(res->tx_num);
7304 }
7305
7306 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7307         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7308                         start, "start");
7309 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7310         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7311                         tx_first, "tx_first");
7312 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7313         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7314                         tx_num, UINT32);
7315
7316 cmdline_parse_inst_t cmd_start_tx_first_n = {
7317         .f = cmd_start_tx_first_n_parsed,
7318         .data = NULL,
7319         .help_str = "start tx_first <num>: "
7320                 "packet forwarding, after sending <num> bursts of packets",
7321         .tokens = {
7322                 (void *)&cmd_start_tx_first_n_start,
7323                 (void *)&cmd_start_tx_first_n_tx_first,
7324                 (void *)&cmd_start_tx_first_n_tx_num,
7325                 NULL,
7326         },
7327 };
7328
7329 /* *** SET LINK UP *** */
7330 struct cmd_set_link_up_result {
7331         cmdline_fixed_string_t set;
7332         cmdline_fixed_string_t link_up;
7333         cmdline_fixed_string_t port;
7334         portid_t port_id;
7335 };
7336
7337 cmdline_parse_token_string_t cmd_set_link_up_set =
7338         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7339 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7340         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7341                                 "link-up");
7342 cmdline_parse_token_string_t cmd_set_link_up_port =
7343         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7344 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7345         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7346
7347 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7348                              __rte_unused struct cmdline *cl,
7349                              __rte_unused void *data)
7350 {
7351         struct cmd_set_link_up_result *res = parsed_result;
7352         dev_set_link_up(res->port_id);
7353 }
7354
7355 cmdline_parse_inst_t cmd_set_link_up = {
7356         .f = cmd_set_link_up_parsed,
7357         .data = NULL,
7358         .help_str = "set link-up port <port id>",
7359         .tokens = {
7360                 (void *)&cmd_set_link_up_set,
7361                 (void *)&cmd_set_link_up_link_up,
7362                 (void *)&cmd_set_link_up_port,
7363                 (void *)&cmd_set_link_up_port_id,
7364                 NULL,
7365         },
7366 };
7367
7368 /* *** SET LINK DOWN *** */
7369 struct cmd_set_link_down_result {
7370         cmdline_fixed_string_t set;
7371         cmdline_fixed_string_t link_down;
7372         cmdline_fixed_string_t port;
7373         portid_t port_id;
7374 };
7375
7376 cmdline_parse_token_string_t cmd_set_link_down_set =
7377         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7378 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7379         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7380                                 "link-down");
7381 cmdline_parse_token_string_t cmd_set_link_down_port =
7382         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7383 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7384         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7385
7386 static void cmd_set_link_down_parsed(
7387                                 __rte_unused void *parsed_result,
7388                                 __rte_unused struct cmdline *cl,
7389                                 __rte_unused void *data)
7390 {
7391         struct cmd_set_link_down_result *res = parsed_result;
7392         dev_set_link_down(res->port_id);
7393 }
7394
7395 cmdline_parse_inst_t cmd_set_link_down = {
7396         .f = cmd_set_link_down_parsed,
7397         .data = NULL,
7398         .help_str = "set link-down port <port id>",
7399         .tokens = {
7400                 (void *)&cmd_set_link_down_set,
7401                 (void *)&cmd_set_link_down_link_down,
7402                 (void *)&cmd_set_link_down_port,
7403                 (void *)&cmd_set_link_down_port_id,
7404                 NULL,
7405         },
7406 };
7407
7408 /* *** SHOW CFG *** */
7409 struct cmd_showcfg_result {
7410         cmdline_fixed_string_t show;
7411         cmdline_fixed_string_t cfg;
7412         cmdline_fixed_string_t what;
7413 };
7414
7415 static void cmd_showcfg_parsed(void *parsed_result,
7416                                __rte_unused struct cmdline *cl,
7417                                __rte_unused void *data)
7418 {
7419         struct cmd_showcfg_result *res = parsed_result;
7420         if (!strcmp(res->what, "rxtx"))
7421                 rxtx_config_display();
7422         else if (!strcmp(res->what, "cores"))
7423                 fwd_lcores_config_display();
7424         else if (!strcmp(res->what, "fwd"))
7425                 pkt_fwd_config_display(&cur_fwd_config);
7426         else if (!strcmp(res->what, "txpkts"))
7427                 show_tx_pkt_segments();
7428 }
7429
7430 cmdline_parse_token_string_t cmd_showcfg_show =
7431         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7432 cmdline_parse_token_string_t cmd_showcfg_port =
7433         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7434 cmdline_parse_token_string_t cmd_showcfg_what =
7435         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7436                                  "rxtx#cores#fwd#txpkts");
7437
7438 cmdline_parse_inst_t cmd_showcfg = {
7439         .f = cmd_showcfg_parsed,
7440         .data = NULL,
7441         .help_str = "show config rxtx|cores|fwd|txpkts",
7442         .tokens = {
7443                 (void *)&cmd_showcfg_show,
7444                 (void *)&cmd_showcfg_port,
7445                 (void *)&cmd_showcfg_what,
7446                 NULL,
7447         },
7448 };
7449
7450 /* *** SHOW ALL PORT INFO *** */
7451 struct cmd_showportall_result {
7452         cmdline_fixed_string_t show;
7453         cmdline_fixed_string_t port;
7454         cmdline_fixed_string_t what;
7455         cmdline_fixed_string_t all;
7456 };
7457
7458 static void cmd_showportall_parsed(void *parsed_result,
7459                                 __rte_unused struct cmdline *cl,
7460                                 __rte_unused void *data)
7461 {
7462         portid_t i;
7463
7464         struct cmd_showportall_result *res = parsed_result;
7465         if (!strcmp(res->show, "clear")) {
7466                 if (!strcmp(res->what, "stats"))
7467                         RTE_ETH_FOREACH_DEV(i)
7468                                 nic_stats_clear(i);
7469                 else if (!strcmp(res->what, "xstats"))
7470                         RTE_ETH_FOREACH_DEV(i)
7471                                 nic_xstats_clear(i);
7472         } else if (!strcmp(res->what, "info"))
7473                 RTE_ETH_FOREACH_DEV(i)
7474                         port_infos_display(i);
7475         else if (!strcmp(res->what, "summary")) {
7476                 port_summary_header_display();
7477                 RTE_ETH_FOREACH_DEV(i)
7478                         port_summary_display(i);
7479         }
7480         else if (!strcmp(res->what, "stats"))
7481                 RTE_ETH_FOREACH_DEV(i)
7482                         nic_stats_display(i);
7483         else if (!strcmp(res->what, "xstats"))
7484                 RTE_ETH_FOREACH_DEV(i)
7485                         nic_xstats_display(i);
7486         else if (!strcmp(res->what, "fdir"))
7487                 RTE_ETH_FOREACH_DEV(i)
7488                         fdir_get_infos(i);
7489         else if (!strcmp(res->what, "stat_qmap"))
7490                 RTE_ETH_FOREACH_DEV(i)
7491                         nic_stats_mapping_display(i);
7492         else if (!strcmp(res->what, "dcb_tc"))
7493                 RTE_ETH_FOREACH_DEV(i)
7494                         port_dcb_info_display(i);
7495         else if (!strcmp(res->what, "cap"))
7496                 RTE_ETH_FOREACH_DEV(i)
7497                         port_offload_cap_display(i);
7498 }
7499
7500 cmdline_parse_token_string_t cmd_showportall_show =
7501         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7502                                  "show#clear");
7503 cmdline_parse_token_string_t cmd_showportall_port =
7504         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7505 cmdline_parse_token_string_t cmd_showportall_what =
7506         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7507                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7508 cmdline_parse_token_string_t cmd_showportall_all =
7509         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7510 cmdline_parse_inst_t cmd_showportall = {
7511         .f = cmd_showportall_parsed,
7512         .data = NULL,
7513         .help_str = "show|clear port "
7514                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7515         .tokens = {
7516                 (void *)&cmd_showportall_show,
7517                 (void *)&cmd_showportall_port,
7518                 (void *)&cmd_showportall_what,
7519                 (void *)&cmd_showportall_all,
7520                 NULL,
7521         },
7522 };
7523
7524 /* *** SHOW PORT INFO *** */
7525 struct cmd_showport_result {
7526         cmdline_fixed_string_t show;
7527         cmdline_fixed_string_t port;
7528         cmdline_fixed_string_t what;
7529         uint16_t portnum;
7530 };
7531
7532 static void cmd_showport_parsed(void *parsed_result,
7533                                 __rte_unused struct cmdline *cl,
7534                                 __rte_unused void *data)
7535 {
7536         struct cmd_showport_result *res = parsed_result;
7537         if (!strcmp(res->show, "clear")) {
7538                 if (!strcmp(res->what, "stats"))
7539                         nic_stats_clear(res->portnum);
7540                 else if (!strcmp(res->what, "xstats"))
7541                         nic_xstats_clear(res->portnum);
7542         } else if (!strcmp(res->what, "info"))
7543                 port_infos_display(res->portnum);
7544         else if (!strcmp(res->what, "summary")) {
7545                 port_summary_header_display();
7546                 port_summary_display(res->portnum);
7547         }
7548         else if (!strcmp(res->what, "stats"))
7549                 nic_stats_display(res->portnum);
7550         else if (!strcmp(res->what, "xstats"))
7551                 nic_xstats_display(res->portnum);
7552         else if (!strcmp(res->what, "fdir"))
7553                  fdir_get_infos(res->portnum);
7554         else if (!strcmp(res->what, "stat_qmap"))
7555                 nic_stats_mapping_display(res->portnum);
7556         else if (!strcmp(res->what, "dcb_tc"))
7557                 port_dcb_info_display(res->portnum);
7558         else if (!strcmp(res->what, "cap"))
7559                 port_offload_cap_display(res->portnum);
7560 }
7561
7562 cmdline_parse_token_string_t cmd_showport_show =
7563         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7564                                  "show#clear");
7565 cmdline_parse_token_string_t cmd_showport_port =
7566         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7567 cmdline_parse_token_string_t cmd_showport_what =
7568         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7569                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7570 cmdline_parse_token_num_t cmd_showport_portnum =
7571         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7572
7573 cmdline_parse_inst_t cmd_showport = {
7574         .f = cmd_showport_parsed,
7575         .data = NULL,
7576         .help_str = "show|clear port "
7577                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7578                 "<port_id>",
7579         .tokens = {
7580                 (void *)&cmd_showport_show,
7581                 (void *)&cmd_showport_port,
7582                 (void *)&cmd_showport_what,
7583                 (void *)&cmd_showport_portnum,
7584                 NULL,
7585         },
7586 };
7587
7588 /* *** SHOW DEVICE INFO *** */
7589 struct cmd_showdevice_result {
7590         cmdline_fixed_string_t show;
7591         cmdline_fixed_string_t device;
7592         cmdline_fixed_string_t what;
7593         cmdline_fixed_string_t identifier;
7594 };
7595
7596 static void cmd_showdevice_parsed(void *parsed_result,
7597                                 __rte_unused struct cmdline *cl,
7598                                 __rte_unused void *data)
7599 {
7600         struct cmd_showdevice_result *res = parsed_result;
7601         if (!strcmp(res->what, "info")) {
7602                 if (!strcmp(res->identifier, "all"))
7603                         device_infos_display(NULL);
7604                 else
7605                         device_infos_display(res->identifier);
7606         }
7607 }
7608
7609 cmdline_parse_token_string_t cmd_showdevice_show =
7610         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7611                                  "show");
7612 cmdline_parse_token_string_t cmd_showdevice_device =
7613         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7614 cmdline_parse_token_string_t cmd_showdevice_what =
7615         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7616                                  "info");
7617 cmdline_parse_token_string_t cmd_showdevice_identifier =
7618         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7619                         identifier, NULL);
7620
7621 cmdline_parse_inst_t cmd_showdevice = {
7622         .f = cmd_showdevice_parsed,
7623         .data = NULL,
7624         .help_str = "show device info <identifier>|all",
7625         .tokens = {
7626                 (void *)&cmd_showdevice_show,
7627                 (void *)&cmd_showdevice_device,
7628                 (void *)&cmd_showdevice_what,
7629                 (void *)&cmd_showdevice_identifier,
7630                 NULL,
7631         },
7632 };
7633 /* *** SHOW QUEUE INFO *** */
7634 struct cmd_showqueue_result {
7635         cmdline_fixed_string_t show;
7636         cmdline_fixed_string_t type;
7637         cmdline_fixed_string_t what;
7638         uint16_t portnum;
7639         uint16_t queuenum;
7640 };
7641
7642 static void
7643 cmd_showqueue_parsed(void *parsed_result,
7644         __rte_unused struct cmdline *cl,
7645         __rte_unused void *data)
7646 {
7647         struct cmd_showqueue_result *res = parsed_result;
7648
7649         if (!strcmp(res->type, "rxq"))
7650                 rx_queue_infos_display(res->portnum, res->queuenum);
7651         else if (!strcmp(res->type, "txq"))
7652                 tx_queue_infos_display(res->portnum, res->queuenum);
7653 }
7654
7655 cmdline_parse_token_string_t cmd_showqueue_show =
7656         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7657 cmdline_parse_token_string_t cmd_showqueue_type =
7658         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7659 cmdline_parse_token_string_t cmd_showqueue_what =
7660         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7661 cmdline_parse_token_num_t cmd_showqueue_portnum =
7662         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7663 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7664         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7665
7666 cmdline_parse_inst_t cmd_showqueue = {
7667         .f = cmd_showqueue_parsed,
7668         .data = NULL,
7669         .help_str = "show rxq|txq info <port_id> <queue_id>",
7670         .tokens = {
7671                 (void *)&cmd_showqueue_show,
7672                 (void *)&cmd_showqueue_type,
7673                 (void *)&cmd_showqueue_what,
7674                 (void *)&cmd_showqueue_portnum,
7675                 (void *)&cmd_showqueue_queuenum,
7676                 NULL,
7677         },
7678 };
7679
7680 /* show/clear fwd engine statistics */
7681 struct fwd_result {
7682         cmdline_fixed_string_t action;
7683         cmdline_fixed_string_t fwd;
7684         cmdline_fixed_string_t stats;
7685         cmdline_fixed_string_t all;
7686 };
7687
7688 cmdline_parse_token_string_t cmd_fwd_action =
7689         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7690 cmdline_parse_token_string_t cmd_fwd_fwd =
7691         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7692 cmdline_parse_token_string_t cmd_fwd_stats =
7693         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7694 cmdline_parse_token_string_t cmd_fwd_all =
7695         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7696
7697 static void
7698 cmd_showfwdall_parsed(void *parsed_result,
7699                       __rte_unused struct cmdline *cl,
7700                       __rte_unused void *data)
7701 {
7702         struct fwd_result *res = parsed_result;
7703
7704         if (!strcmp(res->action, "show"))
7705                 fwd_stats_display();
7706         else
7707                 fwd_stats_reset();
7708 }
7709
7710 static cmdline_parse_inst_t cmd_showfwdall = {
7711         .f = cmd_showfwdall_parsed,
7712         .data = NULL,
7713         .help_str = "show|clear fwd stats all",
7714         .tokens = {
7715                 (void *)&cmd_fwd_action,
7716                 (void *)&cmd_fwd_fwd,
7717                 (void *)&cmd_fwd_stats,
7718                 (void *)&cmd_fwd_all,
7719                 NULL,
7720         },
7721 };
7722
7723 /* *** READ PORT REGISTER *** */
7724 struct cmd_read_reg_result {
7725         cmdline_fixed_string_t read;
7726         cmdline_fixed_string_t reg;
7727         portid_t port_id;
7728         uint32_t reg_off;
7729 };
7730
7731 static void
7732 cmd_read_reg_parsed(void *parsed_result,
7733                     __rte_unused struct cmdline *cl,
7734                     __rte_unused void *data)
7735 {
7736         struct cmd_read_reg_result *res = parsed_result;
7737         port_reg_display(res->port_id, res->reg_off);
7738 }
7739
7740 cmdline_parse_token_string_t cmd_read_reg_read =
7741         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7742 cmdline_parse_token_string_t cmd_read_reg_reg =
7743         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7744 cmdline_parse_token_num_t cmd_read_reg_port_id =
7745         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7746 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7747         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7748
7749 cmdline_parse_inst_t cmd_read_reg = {
7750         .f = cmd_read_reg_parsed,
7751         .data = NULL,
7752         .help_str = "read reg <port_id> <reg_off>",
7753         .tokens = {
7754                 (void *)&cmd_read_reg_read,
7755                 (void *)&cmd_read_reg_reg,
7756                 (void *)&cmd_read_reg_port_id,
7757                 (void *)&cmd_read_reg_reg_off,
7758                 NULL,
7759         },
7760 };
7761
7762 /* *** READ PORT REGISTER BIT FIELD *** */
7763 struct cmd_read_reg_bit_field_result {
7764         cmdline_fixed_string_t read;
7765         cmdline_fixed_string_t regfield;
7766         portid_t port_id;
7767         uint32_t reg_off;
7768         uint8_t bit1_pos;
7769         uint8_t bit2_pos;
7770 };
7771
7772 static void
7773 cmd_read_reg_bit_field_parsed(void *parsed_result,
7774                               __rte_unused struct cmdline *cl,
7775                               __rte_unused void *data)
7776 {
7777         struct cmd_read_reg_bit_field_result *res = parsed_result;
7778         port_reg_bit_field_display(res->port_id, res->reg_off,
7779                                    res->bit1_pos, res->bit2_pos);
7780 }
7781
7782 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7783         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7784                                  "read");
7785 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7786         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7787                                  regfield, "regfield");
7788 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7789         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7790                               UINT16);
7791 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7792         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7793                               UINT32);
7794 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7795         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7796                               UINT8);
7797 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7798         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7799                               UINT8);
7800
7801 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7802         .f = cmd_read_reg_bit_field_parsed,
7803         .data = NULL,
7804         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7805         "Read register bit field between bit_x and bit_y included",
7806         .tokens = {
7807                 (void *)&cmd_read_reg_bit_field_read,
7808                 (void *)&cmd_read_reg_bit_field_regfield,
7809                 (void *)&cmd_read_reg_bit_field_port_id,
7810                 (void *)&cmd_read_reg_bit_field_reg_off,
7811                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7812                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7813                 NULL,
7814         },
7815 };
7816
7817 /* *** READ PORT REGISTER BIT *** */
7818 struct cmd_read_reg_bit_result {
7819         cmdline_fixed_string_t read;
7820         cmdline_fixed_string_t regbit;
7821         portid_t port_id;
7822         uint32_t reg_off;
7823         uint8_t bit_pos;
7824 };
7825
7826 static void
7827 cmd_read_reg_bit_parsed(void *parsed_result,
7828                         __rte_unused struct cmdline *cl,
7829                         __rte_unused void *data)
7830 {
7831         struct cmd_read_reg_bit_result *res = parsed_result;
7832         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7833 }
7834
7835 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7836         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7837 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7838         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7839                                  regbit, "regbit");
7840 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7841         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7842 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7843         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7844 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7845         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7846
7847 cmdline_parse_inst_t cmd_read_reg_bit = {
7848         .f = cmd_read_reg_bit_parsed,
7849         .data = NULL,
7850         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7851         .tokens = {
7852                 (void *)&cmd_read_reg_bit_read,
7853                 (void *)&cmd_read_reg_bit_regbit,
7854                 (void *)&cmd_read_reg_bit_port_id,
7855                 (void *)&cmd_read_reg_bit_reg_off,
7856                 (void *)&cmd_read_reg_bit_bit_pos,
7857                 NULL,
7858         },
7859 };
7860
7861 /* *** WRITE PORT REGISTER *** */
7862 struct cmd_write_reg_result {
7863         cmdline_fixed_string_t write;
7864         cmdline_fixed_string_t reg;
7865         portid_t port_id;
7866         uint32_t reg_off;
7867         uint32_t value;
7868 };
7869
7870 static void
7871 cmd_write_reg_parsed(void *parsed_result,
7872                      __rte_unused struct cmdline *cl,
7873                      __rte_unused void *data)
7874 {
7875         struct cmd_write_reg_result *res = parsed_result;
7876         port_reg_set(res->port_id, res->reg_off, res->value);
7877 }
7878
7879 cmdline_parse_token_string_t cmd_write_reg_write =
7880         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7881 cmdline_parse_token_string_t cmd_write_reg_reg =
7882         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7883 cmdline_parse_token_num_t cmd_write_reg_port_id =
7884         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7885 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7886         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7887 cmdline_parse_token_num_t cmd_write_reg_value =
7888         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7889
7890 cmdline_parse_inst_t cmd_write_reg = {
7891         .f = cmd_write_reg_parsed,
7892         .data = NULL,
7893         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7894         .tokens = {
7895                 (void *)&cmd_write_reg_write,
7896                 (void *)&cmd_write_reg_reg,
7897                 (void *)&cmd_write_reg_port_id,
7898                 (void *)&cmd_write_reg_reg_off,
7899                 (void *)&cmd_write_reg_value,
7900                 NULL,
7901         },
7902 };
7903
7904 /* *** WRITE PORT REGISTER BIT FIELD *** */
7905 struct cmd_write_reg_bit_field_result {
7906         cmdline_fixed_string_t write;
7907         cmdline_fixed_string_t regfield;
7908         portid_t port_id;
7909         uint32_t reg_off;
7910         uint8_t bit1_pos;
7911         uint8_t bit2_pos;
7912         uint32_t value;
7913 };
7914
7915 static void
7916 cmd_write_reg_bit_field_parsed(void *parsed_result,
7917                                __rte_unused struct cmdline *cl,
7918                                __rte_unused void *data)
7919 {
7920         struct cmd_write_reg_bit_field_result *res = parsed_result;
7921         port_reg_bit_field_set(res->port_id, res->reg_off,
7922                           res->bit1_pos, res->bit2_pos, res->value);
7923 }
7924
7925 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7926         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7927                                  "write");
7928 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7929         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7930                                  regfield, "regfield");
7931 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7932         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7933                               UINT16);
7934 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7935         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7936                               UINT32);
7937 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7938         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7939                               UINT8);
7940 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7941         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
7942                               UINT8);
7943 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
7944         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
7945                               UINT32);
7946
7947 cmdline_parse_inst_t cmd_write_reg_bit_field = {
7948         .f = cmd_write_reg_bit_field_parsed,
7949         .data = NULL,
7950         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
7951                 "<reg_value>: "
7952                 "Set register bit field between bit_x and bit_y included",
7953         .tokens = {
7954                 (void *)&cmd_write_reg_bit_field_write,
7955                 (void *)&cmd_write_reg_bit_field_regfield,
7956                 (void *)&cmd_write_reg_bit_field_port_id,
7957                 (void *)&cmd_write_reg_bit_field_reg_off,
7958                 (void *)&cmd_write_reg_bit_field_bit1_pos,
7959                 (void *)&cmd_write_reg_bit_field_bit2_pos,
7960                 (void *)&cmd_write_reg_bit_field_value,
7961                 NULL,
7962         },
7963 };
7964
7965 /* *** WRITE PORT REGISTER BIT *** */
7966 struct cmd_write_reg_bit_result {
7967         cmdline_fixed_string_t write;
7968         cmdline_fixed_string_t regbit;
7969         portid_t port_id;
7970         uint32_t reg_off;
7971         uint8_t bit_pos;
7972         uint8_t value;
7973 };
7974
7975 static void
7976 cmd_write_reg_bit_parsed(void *parsed_result,
7977                          __rte_unused struct cmdline *cl,
7978                          __rte_unused void *data)
7979 {
7980         struct cmd_write_reg_bit_result *res = parsed_result;
7981         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
7982 }
7983
7984 cmdline_parse_token_string_t cmd_write_reg_bit_write =
7985         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
7986                                  "write");
7987 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
7988         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
7989                                  regbit, "regbit");
7990 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
7991         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
7992 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
7993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
7994 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
7995         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
7996 cmdline_parse_token_num_t cmd_write_reg_bit_value =
7997         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
7998
7999 cmdline_parse_inst_t cmd_write_reg_bit = {
8000         .f = cmd_write_reg_bit_parsed,
8001         .data = NULL,
8002         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8003                 "0 <= bit_x <= 31",
8004         .tokens = {
8005                 (void *)&cmd_write_reg_bit_write,
8006                 (void *)&cmd_write_reg_bit_regbit,
8007                 (void *)&cmd_write_reg_bit_port_id,
8008                 (void *)&cmd_write_reg_bit_reg_off,
8009                 (void *)&cmd_write_reg_bit_bit_pos,
8010                 (void *)&cmd_write_reg_bit_value,
8011                 NULL,
8012         },
8013 };
8014
8015 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8016 struct cmd_read_rxd_txd_result {
8017         cmdline_fixed_string_t read;
8018         cmdline_fixed_string_t rxd_txd;
8019         portid_t port_id;
8020         uint16_t queue_id;
8021         uint16_t desc_id;
8022 };
8023
8024 static void
8025 cmd_read_rxd_txd_parsed(void *parsed_result,
8026                         __rte_unused struct cmdline *cl,
8027                         __rte_unused void *data)
8028 {
8029         struct cmd_read_rxd_txd_result *res = parsed_result;
8030
8031         if (!strcmp(res->rxd_txd, "rxd"))
8032                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8033         else if (!strcmp(res->rxd_txd, "txd"))
8034                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8035 }
8036
8037 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8038         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8039 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8040         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8041                                  "rxd#txd");
8042 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8043         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8044 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8045         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8046 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8047         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8048
8049 cmdline_parse_inst_t cmd_read_rxd_txd = {
8050         .f = cmd_read_rxd_txd_parsed,
8051         .data = NULL,
8052         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8053         .tokens = {
8054                 (void *)&cmd_read_rxd_txd_read,
8055                 (void *)&cmd_read_rxd_txd_rxd_txd,
8056                 (void *)&cmd_read_rxd_txd_port_id,
8057                 (void *)&cmd_read_rxd_txd_queue_id,
8058                 (void *)&cmd_read_rxd_txd_desc_id,
8059                 NULL,
8060         },
8061 };
8062
8063 /* *** QUIT *** */
8064 struct cmd_quit_result {
8065         cmdline_fixed_string_t quit;
8066 };
8067
8068 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8069                             struct cmdline *cl,
8070                             __rte_unused void *data)
8071 {
8072         cmdline_quit(cl);
8073 }
8074
8075 cmdline_parse_token_string_t cmd_quit_quit =
8076         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8077
8078 cmdline_parse_inst_t cmd_quit = {
8079         .f = cmd_quit_parsed,
8080         .data = NULL,
8081         .help_str = "quit: Exit application",
8082         .tokens = {
8083                 (void *)&cmd_quit_quit,
8084                 NULL,
8085         },
8086 };
8087
8088 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8089 struct cmd_mac_addr_result {
8090         cmdline_fixed_string_t mac_addr_cmd;
8091         cmdline_fixed_string_t what;
8092         uint16_t port_num;
8093         struct rte_ether_addr address;
8094 };
8095
8096 static void cmd_mac_addr_parsed(void *parsed_result,
8097                 __rte_unused struct cmdline *cl,
8098                 __rte_unused void *data)
8099 {
8100         struct cmd_mac_addr_result *res = parsed_result;
8101         int ret;
8102
8103         if (strcmp(res->what, "add") == 0)
8104                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8105         else if (strcmp(res->what, "set") == 0)
8106                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8107                                                        &res->address);
8108         else
8109                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8110
8111         /* check the return value and print it if is < 0 */
8112         if(ret < 0)
8113                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8114
8115 }
8116
8117 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8118         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8119                                 "mac_addr");
8120 cmdline_parse_token_string_t cmd_mac_addr_what =
8121         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8122                                 "add#remove#set");
8123 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8124                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8125                                         UINT16);
8126 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8127                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8128
8129 cmdline_parse_inst_t cmd_mac_addr = {
8130         .f = cmd_mac_addr_parsed,
8131         .data = (void *)0,
8132         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8133                         "Add/Remove/Set MAC address on port_id",
8134         .tokens = {
8135                 (void *)&cmd_mac_addr_cmd,
8136                 (void *)&cmd_mac_addr_what,
8137                 (void *)&cmd_mac_addr_portnum,
8138                 (void *)&cmd_mac_addr_addr,
8139                 NULL,
8140         },
8141 };
8142
8143 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8144 struct cmd_eth_peer_result {
8145         cmdline_fixed_string_t set;
8146         cmdline_fixed_string_t eth_peer;
8147         portid_t port_id;
8148         cmdline_fixed_string_t peer_addr;
8149 };
8150
8151 static void cmd_set_eth_peer_parsed(void *parsed_result,
8152                         __rte_unused struct cmdline *cl,
8153                         __rte_unused void *data)
8154 {
8155                 struct cmd_eth_peer_result *res = parsed_result;
8156
8157                 if (test_done == 0) {
8158                         printf("Please stop forwarding first\n");
8159                         return;
8160                 }
8161                 if (!strcmp(res->eth_peer, "eth-peer")) {
8162                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8163                         fwd_config_setup();
8164                 }
8165 }
8166 cmdline_parse_token_string_t cmd_eth_peer_set =
8167         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8168 cmdline_parse_token_string_t cmd_eth_peer =
8169         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8170 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8171         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8172 cmdline_parse_token_string_t cmd_eth_peer_addr =
8173         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8174
8175 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8176         .f = cmd_set_eth_peer_parsed,
8177         .data = NULL,
8178         .help_str = "set eth-peer <port_id> <peer_mac>",
8179         .tokens = {
8180                 (void *)&cmd_eth_peer_set,
8181                 (void *)&cmd_eth_peer,
8182                 (void *)&cmd_eth_peer_port_id,
8183                 (void *)&cmd_eth_peer_addr,
8184                 NULL,
8185         },
8186 };
8187
8188 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8189 struct cmd_set_qmap_result {
8190         cmdline_fixed_string_t set;
8191         cmdline_fixed_string_t qmap;
8192         cmdline_fixed_string_t what;
8193         portid_t port_id;
8194         uint16_t queue_id;
8195         uint8_t map_value;
8196 };
8197
8198 static void
8199 cmd_set_qmap_parsed(void *parsed_result,
8200                        __rte_unused struct cmdline *cl,
8201                        __rte_unused void *data)
8202 {
8203         struct cmd_set_qmap_result *res = parsed_result;
8204         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8205
8206         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8207 }
8208
8209 cmdline_parse_token_string_t cmd_setqmap_set =
8210         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8211                                  set, "set");
8212 cmdline_parse_token_string_t cmd_setqmap_qmap =
8213         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8214                                  qmap, "stat_qmap");
8215 cmdline_parse_token_string_t cmd_setqmap_what =
8216         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8217                                  what, "tx#rx");
8218 cmdline_parse_token_num_t cmd_setqmap_portid =
8219         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8220                               port_id, UINT16);
8221 cmdline_parse_token_num_t cmd_setqmap_queueid =
8222         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8223                               queue_id, UINT16);
8224 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8225         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8226                               map_value, UINT8);
8227
8228 cmdline_parse_inst_t cmd_set_qmap = {
8229         .f = cmd_set_qmap_parsed,
8230         .data = NULL,
8231         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8232                 "Set statistics mapping value on tx|rx queue_id of port_id",
8233         .tokens = {
8234                 (void *)&cmd_setqmap_set,
8235                 (void *)&cmd_setqmap_qmap,
8236                 (void *)&cmd_setqmap_what,
8237                 (void *)&cmd_setqmap_portid,
8238                 (void *)&cmd_setqmap_queueid,
8239                 (void *)&cmd_setqmap_mapvalue,
8240                 NULL,
8241         },
8242 };
8243
8244 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8245 struct cmd_set_xstats_hide_zero_result {
8246         cmdline_fixed_string_t keyword;
8247         cmdline_fixed_string_t name;
8248         cmdline_fixed_string_t on_off;
8249 };
8250
8251 static void
8252 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8253                         __rte_unused struct cmdline *cl,
8254                         __rte_unused void *data)
8255 {
8256         struct cmd_set_xstats_hide_zero_result *res;
8257         uint16_t on_off = 0;
8258
8259         res = parsed_result;
8260         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8261         set_xstats_hide_zero(on_off);
8262 }
8263
8264 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8265         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8266                                  keyword, "set");
8267 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8268         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8269                                  name, "xstats-hide-zero");
8270 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8271         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8272                                  on_off, "on#off");
8273
8274 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8275         .f = cmd_set_xstats_hide_zero_parsed,
8276         .data = NULL,
8277         .help_str = "set xstats-hide-zero on|off",
8278         .tokens = {
8279                 (void *)&cmd_set_xstats_hide_zero_keyword,
8280                 (void *)&cmd_set_xstats_hide_zero_name,
8281                 (void *)&cmd_set_xstats_hide_zero_on_off,
8282                 NULL,
8283         },
8284 };
8285
8286 /* *** CONFIGURE UNICAST HASH TABLE *** */
8287 struct cmd_set_uc_hash_table {
8288         cmdline_fixed_string_t set;
8289         cmdline_fixed_string_t port;
8290         portid_t port_id;
8291         cmdline_fixed_string_t what;
8292         struct rte_ether_addr address;
8293         cmdline_fixed_string_t mode;
8294 };
8295
8296 static void
8297 cmd_set_uc_hash_parsed(void *parsed_result,
8298                        __rte_unused struct cmdline *cl,
8299                        __rte_unused void *data)
8300 {
8301         int ret=0;
8302         struct cmd_set_uc_hash_table *res = parsed_result;
8303
8304         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8305
8306         if (strcmp(res->what, "uta") == 0)
8307                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8308                                                 &res->address,(uint8_t)is_on);
8309         if (ret < 0)
8310                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8311
8312 }
8313
8314 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8315         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8316                                  set, "set");
8317 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8318         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8319                                  port, "port");
8320 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8321         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8322                               port_id, UINT16);
8323 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8324         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8325                                  what, "uta");
8326 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8327         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8328                                 address);
8329 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8330         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8331                                  mode, "on#off");
8332
8333 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8334         .f = cmd_set_uc_hash_parsed,
8335         .data = NULL,
8336         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8337         .tokens = {
8338                 (void *)&cmd_set_uc_hash_set,
8339                 (void *)&cmd_set_uc_hash_port,
8340                 (void *)&cmd_set_uc_hash_portid,
8341                 (void *)&cmd_set_uc_hash_what,
8342                 (void *)&cmd_set_uc_hash_mac,
8343                 (void *)&cmd_set_uc_hash_mode,
8344                 NULL,
8345         },
8346 };
8347
8348 struct cmd_set_uc_all_hash_table {
8349         cmdline_fixed_string_t set;
8350         cmdline_fixed_string_t port;
8351         portid_t port_id;
8352         cmdline_fixed_string_t what;
8353         cmdline_fixed_string_t value;
8354         cmdline_fixed_string_t mode;
8355 };
8356
8357 static void
8358 cmd_set_uc_all_hash_parsed(void *parsed_result,
8359                        __rte_unused struct cmdline *cl,
8360                        __rte_unused void *data)
8361 {
8362         int ret=0;
8363         struct cmd_set_uc_all_hash_table *res = parsed_result;
8364
8365         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8366
8367         if ((strcmp(res->what, "uta") == 0) &&
8368                 (strcmp(res->value, "all") == 0))
8369                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8370         if (ret < 0)
8371                 printf("bad unicast hash table parameter,"
8372                         "return code = %d \n", ret);
8373 }
8374
8375 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8376         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8377                                  set, "set");
8378 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8379         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8380                                  port, "port");
8381 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8382         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8383                               port_id, UINT16);
8384 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8385         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8386                                  what, "uta");
8387 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8388         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8389                                 value,"all");
8390 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8391         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8392                                  mode, "on#off");
8393
8394 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8395         .f = cmd_set_uc_all_hash_parsed,
8396         .data = NULL,
8397         .help_str = "set port <port_id> uta all on|off",
8398         .tokens = {
8399                 (void *)&cmd_set_uc_all_hash_set,
8400                 (void *)&cmd_set_uc_all_hash_port,
8401                 (void *)&cmd_set_uc_all_hash_portid,
8402                 (void *)&cmd_set_uc_all_hash_what,
8403                 (void *)&cmd_set_uc_all_hash_value,
8404                 (void *)&cmd_set_uc_all_hash_mode,
8405                 NULL,
8406         },
8407 };
8408
8409 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8410 struct cmd_set_vf_macvlan_filter {
8411         cmdline_fixed_string_t set;
8412         cmdline_fixed_string_t port;
8413         portid_t port_id;
8414         cmdline_fixed_string_t vf;
8415         uint8_t vf_id;
8416         struct rte_ether_addr address;
8417         cmdline_fixed_string_t filter_type;
8418         cmdline_fixed_string_t mode;
8419 };
8420
8421 static void
8422 cmd_set_vf_macvlan_parsed(void *parsed_result,
8423                        __rte_unused struct cmdline *cl,
8424                        __rte_unused void *data)
8425 {
8426         int is_on, ret = 0;
8427         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8428         struct rte_eth_mac_filter filter;
8429
8430         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8431
8432         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8433
8434         /* set VF MAC filter */
8435         filter.is_vf = 1;
8436
8437         /* set VF ID */
8438         filter.dst_id = res->vf_id;
8439
8440         if (!strcmp(res->filter_type, "exact-mac"))
8441                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8442         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8443                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8444         else if (!strcmp(res->filter_type, "hashmac"))
8445                 filter.filter_type = RTE_MAC_HASH_MATCH;
8446         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8447                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8448
8449         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8450
8451         if (is_on)
8452                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8453                                         RTE_ETH_FILTER_MACVLAN,
8454                                         RTE_ETH_FILTER_ADD,
8455                                          &filter);
8456         else
8457                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8458                                         RTE_ETH_FILTER_MACVLAN,
8459                                         RTE_ETH_FILTER_DELETE,
8460                                         &filter);
8461
8462         if (ret < 0)
8463                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8464
8465 }
8466
8467 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8468         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8469                                  set, "set");
8470 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8471         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8472                                  port, "port");
8473 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8474         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8475                               port_id, UINT16);
8476 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8477         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8478                                  vf, "vf");
8479 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8480         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8481                                 vf_id, UINT8);
8482 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8483         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8484                                 address);
8485 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8486         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8487                                 filter_type, "exact-mac#exact-mac-vlan"
8488                                 "#hashmac#hashmac-vlan");
8489 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8490         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8491                                  mode, "on#off");
8492
8493 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8494         .f = cmd_set_vf_macvlan_parsed,
8495         .data = NULL,
8496         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8497                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8498                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8499                 "hash match rule: hash match of MAC and exact match of VLAN",
8500         .tokens = {
8501                 (void *)&cmd_set_vf_macvlan_set,
8502                 (void *)&cmd_set_vf_macvlan_port,
8503                 (void *)&cmd_set_vf_macvlan_portid,
8504                 (void *)&cmd_set_vf_macvlan_vf,
8505                 (void *)&cmd_set_vf_macvlan_vf_id,
8506                 (void *)&cmd_set_vf_macvlan_mac,
8507                 (void *)&cmd_set_vf_macvlan_filter_type,
8508                 (void *)&cmd_set_vf_macvlan_mode,
8509                 NULL,
8510         },
8511 };
8512
8513 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8514 struct cmd_set_vf_traffic {
8515         cmdline_fixed_string_t set;
8516         cmdline_fixed_string_t port;
8517         portid_t port_id;
8518         cmdline_fixed_string_t vf;
8519         uint8_t vf_id;
8520         cmdline_fixed_string_t what;
8521         cmdline_fixed_string_t mode;
8522 };
8523
8524 static void
8525 cmd_set_vf_traffic_parsed(void *parsed_result,
8526                        __rte_unused struct cmdline *cl,
8527                        __rte_unused void *data)
8528 {
8529         struct cmd_set_vf_traffic *res = parsed_result;
8530         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8531         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8532
8533         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8534 }
8535
8536 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8537         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8538                                  set, "set");
8539 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8540         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8541                                  port, "port");
8542 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8543         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8544                               port_id, UINT16);
8545 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8547                                  vf, "vf");
8548 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8549         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8550                               vf_id, UINT8);
8551 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8552         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8553                                  what, "tx#rx");
8554 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8555         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8556                                  mode, "on#off");
8557
8558 cmdline_parse_inst_t cmd_set_vf_traffic = {
8559         .f = cmd_set_vf_traffic_parsed,
8560         .data = NULL,
8561         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8562         .tokens = {
8563                 (void *)&cmd_setvf_traffic_set,
8564                 (void *)&cmd_setvf_traffic_port,
8565                 (void *)&cmd_setvf_traffic_portid,
8566                 (void *)&cmd_setvf_traffic_vf,
8567                 (void *)&cmd_setvf_traffic_vfid,
8568                 (void *)&cmd_setvf_traffic_what,
8569                 (void *)&cmd_setvf_traffic_mode,
8570                 NULL,
8571         },
8572 };
8573
8574 /* *** CONFIGURE VF RECEIVE MODE *** */
8575 struct cmd_set_vf_rxmode {
8576         cmdline_fixed_string_t set;
8577         cmdline_fixed_string_t port;
8578         portid_t port_id;
8579         cmdline_fixed_string_t vf;
8580         uint8_t vf_id;
8581         cmdline_fixed_string_t what;
8582         cmdline_fixed_string_t mode;
8583         cmdline_fixed_string_t on;
8584 };
8585
8586 static void
8587 cmd_set_vf_rxmode_parsed(void *parsed_result,
8588                        __rte_unused struct cmdline *cl,
8589                        __rte_unused void *data)
8590 {
8591         int ret = -ENOTSUP;
8592         uint16_t vf_rxmode = 0;
8593         struct cmd_set_vf_rxmode *res = parsed_result;
8594
8595         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8596         if (!strcmp(res->what,"rxmode")) {
8597                 if (!strcmp(res->mode, "AUPE"))
8598                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8599                 else if (!strcmp(res->mode, "ROPE"))
8600                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8601                 else if (!strcmp(res->mode, "BAM"))
8602                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8603                 else if (!strncmp(res->mode, "MPE",3))
8604                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8605         }
8606
8607         RTE_SET_USED(is_on);
8608
8609 #ifdef RTE_LIBRTE_IXGBE_PMD
8610         if (ret == -ENOTSUP)
8611                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8612                                                   vf_rxmode, (uint8_t)is_on);
8613 #endif
8614 #ifdef RTE_LIBRTE_BNXT_PMD
8615         if (ret == -ENOTSUP)
8616                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8617                                                  vf_rxmode, (uint8_t)is_on);
8618 #endif
8619         if (ret < 0)
8620                 printf("bad VF receive mode parameter, return code = %d \n",
8621                 ret);
8622 }
8623
8624 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8625         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8626                                  set, "set");
8627 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8628         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8629                                  port, "port");
8630 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8631         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8632                               port_id, UINT16);
8633 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8635                                  vf, "vf");
8636 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8637         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8638                               vf_id, UINT8);
8639 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8640         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8641                                  what, "rxmode");
8642 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8643         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8644                                  mode, "AUPE#ROPE#BAM#MPE");
8645 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8646         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8647                                  on, "on#off");
8648
8649 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8650         .f = cmd_set_vf_rxmode_parsed,
8651         .data = NULL,
8652         .help_str = "set port <port_id> vf <vf_id> rxmode "
8653                 "AUPE|ROPE|BAM|MPE on|off",
8654         .tokens = {
8655                 (void *)&cmd_set_vf_rxmode_set,
8656                 (void *)&cmd_set_vf_rxmode_port,
8657                 (void *)&cmd_set_vf_rxmode_portid,
8658                 (void *)&cmd_set_vf_rxmode_vf,
8659                 (void *)&cmd_set_vf_rxmode_vfid,
8660                 (void *)&cmd_set_vf_rxmode_what,
8661                 (void *)&cmd_set_vf_rxmode_mode,
8662                 (void *)&cmd_set_vf_rxmode_on,
8663                 NULL,
8664         },
8665 };
8666
8667 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8668 struct cmd_vf_mac_addr_result {
8669         cmdline_fixed_string_t mac_addr_cmd;
8670         cmdline_fixed_string_t what;
8671         cmdline_fixed_string_t port;
8672         uint16_t port_num;
8673         cmdline_fixed_string_t vf;
8674         uint8_t vf_num;
8675         struct rte_ether_addr address;
8676 };
8677
8678 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8679                 __rte_unused struct cmdline *cl,
8680                 __rte_unused void *data)
8681 {
8682         struct cmd_vf_mac_addr_result *res = parsed_result;
8683         int ret = -ENOTSUP;
8684
8685         if (strcmp(res->what, "add") != 0)
8686                 return;
8687
8688 #ifdef RTE_LIBRTE_I40E_PMD
8689         if (ret == -ENOTSUP)
8690                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8691                                                    &res->address);
8692 #endif
8693 #ifdef RTE_LIBRTE_BNXT_PMD
8694         if (ret == -ENOTSUP)
8695                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8696                                                 res->vf_num);
8697 #endif
8698
8699         if(ret < 0)
8700                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8701
8702 }
8703
8704 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8705         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8706                                 mac_addr_cmd,"mac_addr");
8707 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8708         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8709                                 what,"add");
8710 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8711         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8712                                 port,"port");
8713 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8714         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8715                                 port_num, UINT16);
8716 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8717         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8718                                 vf,"vf");
8719 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8720         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8721                                 vf_num, UINT8);
8722 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8723         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8724                                 address);
8725
8726 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8727         .f = cmd_vf_mac_addr_parsed,
8728         .data = (void *)0,
8729         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8730                 "Add MAC address filtering for a VF on port_id",
8731         .tokens = {
8732                 (void *)&cmd_vf_mac_addr_cmd,
8733                 (void *)&cmd_vf_mac_addr_what,
8734                 (void *)&cmd_vf_mac_addr_port,
8735                 (void *)&cmd_vf_mac_addr_portnum,
8736                 (void *)&cmd_vf_mac_addr_vf,
8737                 (void *)&cmd_vf_mac_addr_vfnum,
8738                 (void *)&cmd_vf_mac_addr_addr,
8739                 NULL,
8740         },
8741 };
8742
8743 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8744 struct cmd_vf_rx_vlan_filter {
8745         cmdline_fixed_string_t rx_vlan;
8746         cmdline_fixed_string_t what;
8747         uint16_t vlan_id;
8748         cmdline_fixed_string_t port;
8749         portid_t port_id;
8750         cmdline_fixed_string_t vf;
8751         uint64_t vf_mask;
8752 };
8753
8754 static void
8755 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8756                           __rte_unused struct cmdline *cl,
8757                           __rte_unused void *data)
8758 {
8759         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8760         int ret = -ENOTSUP;
8761
8762         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8763
8764 #ifdef RTE_LIBRTE_IXGBE_PMD
8765         if (ret == -ENOTSUP)
8766                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8767                                 res->vlan_id, res->vf_mask, is_add);
8768 #endif
8769 #ifdef RTE_LIBRTE_I40E_PMD
8770         if (ret == -ENOTSUP)
8771                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8772                                 res->vlan_id, res->vf_mask, is_add);
8773 #endif
8774 #ifdef RTE_LIBRTE_BNXT_PMD
8775         if (ret == -ENOTSUP)
8776                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8777                                 res->vlan_id, res->vf_mask, is_add);
8778 #endif
8779
8780         switch (ret) {
8781         case 0:
8782                 break;
8783         case -EINVAL:
8784                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8785                                 res->vlan_id, res->vf_mask);
8786                 break;
8787         case -ENODEV:
8788                 printf("invalid port_id %d\n", res->port_id);
8789                 break;
8790         case -ENOTSUP:
8791                 printf("function not implemented or supported\n");
8792                 break;
8793         default:
8794                 printf("programming error: (%s)\n", strerror(-ret));
8795         }
8796 }
8797
8798 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8799         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8800                                  rx_vlan, "rx_vlan");
8801 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8802         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8803                                  what, "add#rm");
8804 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8805         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8806                               vlan_id, UINT16);
8807 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8808         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8809                                  port, "port");
8810 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8811         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8812                               port_id, UINT16);
8813 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8814         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8815                                  vf, "vf");
8816 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8817         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8818                               vf_mask, UINT64);
8819
8820 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8821         .f = cmd_vf_rx_vlan_filter_parsed,
8822         .data = NULL,
8823         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8824                 "(vf_mask = hexadecimal VF mask)",
8825         .tokens = {
8826                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8827                 (void *)&cmd_vf_rx_vlan_filter_what,
8828                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8829                 (void *)&cmd_vf_rx_vlan_filter_port,
8830                 (void *)&cmd_vf_rx_vlan_filter_portid,
8831                 (void *)&cmd_vf_rx_vlan_filter_vf,
8832                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8833                 NULL,
8834         },
8835 };
8836
8837 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8838 struct cmd_queue_rate_limit_result {
8839         cmdline_fixed_string_t set;
8840         cmdline_fixed_string_t port;
8841         uint16_t port_num;
8842         cmdline_fixed_string_t queue;
8843         uint8_t queue_num;
8844         cmdline_fixed_string_t rate;
8845         uint16_t rate_num;
8846 };
8847
8848 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8849                 __rte_unused struct cmdline *cl,
8850                 __rte_unused void *data)
8851 {
8852         struct cmd_queue_rate_limit_result *res = parsed_result;
8853         int ret = 0;
8854
8855         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8856                 && (strcmp(res->queue, "queue") == 0)
8857                 && (strcmp(res->rate, "rate") == 0))
8858                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
8859                                         res->rate_num);
8860         if (ret < 0)
8861                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
8862
8863 }
8864
8865 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
8866         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8867                                 set, "set");
8868 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
8869         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8870                                 port, "port");
8871 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
8872         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8873                                 port_num, UINT16);
8874 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
8875         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8876                                 queue, "queue");
8877 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
8878         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8879                                 queue_num, UINT8);
8880 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
8881         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
8882                                 rate, "rate");
8883 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
8884         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
8885                                 rate_num, UINT16);
8886
8887 cmdline_parse_inst_t cmd_queue_rate_limit = {
8888         .f = cmd_queue_rate_limit_parsed,
8889         .data = (void *)0,
8890         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
8891                 "Set rate limit for a queue on port_id",
8892         .tokens = {
8893                 (void *)&cmd_queue_rate_limit_set,
8894                 (void *)&cmd_queue_rate_limit_port,
8895                 (void *)&cmd_queue_rate_limit_portnum,
8896                 (void *)&cmd_queue_rate_limit_queue,
8897                 (void *)&cmd_queue_rate_limit_queuenum,
8898                 (void *)&cmd_queue_rate_limit_rate,
8899                 (void *)&cmd_queue_rate_limit_ratenum,
8900                 NULL,
8901         },
8902 };
8903
8904 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
8905 struct cmd_vf_rate_limit_result {
8906         cmdline_fixed_string_t set;
8907         cmdline_fixed_string_t port;
8908         uint16_t port_num;
8909         cmdline_fixed_string_t vf;
8910         uint8_t vf_num;
8911         cmdline_fixed_string_t rate;
8912         uint16_t rate_num;
8913         cmdline_fixed_string_t q_msk;
8914         uint64_t q_msk_val;
8915 };
8916
8917 static void cmd_vf_rate_limit_parsed(void *parsed_result,
8918                 __rte_unused struct cmdline *cl,
8919                 __rte_unused void *data)
8920 {
8921         struct cmd_vf_rate_limit_result *res = parsed_result;
8922         int ret = 0;
8923
8924         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8925                 && (strcmp(res->vf, "vf") == 0)
8926                 && (strcmp(res->rate, "rate") == 0)
8927                 && (strcmp(res->q_msk, "queue_mask") == 0))
8928                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
8929                                         res->rate_num, res->q_msk_val);
8930         if (ret < 0)
8931                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
8932
8933 }
8934
8935 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
8936         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8937                                 set, "set");
8938 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
8939         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8940                                 port, "port");
8941 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
8942         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8943                                 port_num, UINT16);
8944 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
8945         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8946                                 vf, "vf");
8947 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
8948         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8949                                 vf_num, UINT8);
8950 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
8951         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8952                                 rate, "rate");
8953 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
8954         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8955                                 rate_num, UINT16);
8956 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
8957         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
8958                                 q_msk, "queue_mask");
8959 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
8960         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
8961                                 q_msk_val, UINT64);
8962
8963 cmdline_parse_inst_t cmd_vf_rate_limit = {
8964         .f = cmd_vf_rate_limit_parsed,
8965         .data = (void *)0,
8966         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
8967                 "queue_mask <queue_mask_value>: "
8968                 "Set rate limit for queues of VF on port_id",
8969         .tokens = {
8970                 (void *)&cmd_vf_rate_limit_set,
8971                 (void *)&cmd_vf_rate_limit_port,
8972                 (void *)&cmd_vf_rate_limit_portnum,
8973                 (void *)&cmd_vf_rate_limit_vf,
8974                 (void *)&cmd_vf_rate_limit_vfnum,
8975                 (void *)&cmd_vf_rate_limit_rate,
8976                 (void *)&cmd_vf_rate_limit_ratenum,
8977                 (void *)&cmd_vf_rate_limit_q_msk,
8978                 (void *)&cmd_vf_rate_limit_q_msk_val,
8979                 NULL,
8980         },
8981 };
8982
8983 /* *** ADD TUNNEL FILTER OF A PORT *** */
8984 struct cmd_tunnel_filter_result {
8985         cmdline_fixed_string_t cmd;
8986         cmdline_fixed_string_t what;
8987         portid_t port_id;
8988         struct rte_ether_addr outer_mac;
8989         struct rte_ether_addr inner_mac;
8990         cmdline_ipaddr_t ip_value;
8991         uint16_t inner_vlan;
8992         cmdline_fixed_string_t tunnel_type;
8993         cmdline_fixed_string_t filter_type;
8994         uint32_t tenant_id;
8995         uint16_t queue_num;
8996 };
8997
8998 static void
8999 cmd_tunnel_filter_parsed(void *parsed_result,
9000                           __rte_unused struct cmdline *cl,
9001                           __rte_unused void *data)
9002 {
9003         struct cmd_tunnel_filter_result *res = parsed_result;
9004         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9005         int ret = 0;
9006
9007         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9008
9009         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9010         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9011         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9012
9013         if (res->ip_value.family == AF_INET) {
9014                 tunnel_filter_conf.ip_addr.ipv4_addr =
9015                         res->ip_value.addr.ipv4.s_addr;
9016                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9017         } else {
9018                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9019                         &(res->ip_value.addr.ipv6),
9020                         sizeof(struct in6_addr));
9021                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9022         }
9023
9024         if (!strcmp(res->filter_type, "imac-ivlan"))
9025                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9026         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9027                 tunnel_filter_conf.filter_type =
9028                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9029         else if (!strcmp(res->filter_type, "imac-tenid"))
9030                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9031         else if (!strcmp(res->filter_type, "imac"))
9032                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9033         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9034                 tunnel_filter_conf.filter_type =
9035                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9036         else if (!strcmp(res->filter_type, "oip"))
9037                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9038         else if (!strcmp(res->filter_type, "iip"))
9039                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9040         else {
9041                 printf("The filter type is not supported");
9042                 return;
9043         }
9044
9045         if (!strcmp(res->tunnel_type, "vxlan"))
9046                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9047         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9048                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9049         else if (!strcmp(res->tunnel_type, "nvgre"))
9050                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9051         else if (!strcmp(res->tunnel_type, "ipingre"))
9052                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9053         else {
9054                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9055                 return;
9056         }
9057
9058         tunnel_filter_conf.tenant_id = res->tenant_id;
9059         tunnel_filter_conf.queue_id = res->queue_num;
9060         if (!strcmp(res->what, "add"))
9061                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9062                                         RTE_ETH_FILTER_TUNNEL,
9063                                         RTE_ETH_FILTER_ADD,
9064                                         &tunnel_filter_conf);
9065         else
9066                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9067                                         RTE_ETH_FILTER_TUNNEL,
9068                                         RTE_ETH_FILTER_DELETE,
9069                                         &tunnel_filter_conf);
9070         if (ret < 0)
9071                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9072                                 strerror(-ret));
9073
9074 }
9075 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9076         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9077         cmd, "tunnel_filter");
9078 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9079         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9080         what, "add#rm");
9081 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9082         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9083         port_id, UINT16);
9084 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9085         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9086         outer_mac);
9087 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9088         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9089         inner_mac);
9090 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9091         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9092         inner_vlan, UINT16);
9093 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9094         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9095         ip_value);
9096 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9097         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9098         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9099
9100 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9101         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9102         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9103                 "imac#omac-imac-tenid");
9104 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9105         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9106         tenant_id, UINT32);
9107 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9108         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9109         queue_num, UINT16);
9110
9111 cmdline_parse_inst_t cmd_tunnel_filter = {
9112         .f = cmd_tunnel_filter_parsed,
9113         .data = (void *)0,
9114         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9115                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9116                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9117                 "<queue_id>: Add/Rm tunnel filter of a port",
9118         .tokens = {
9119                 (void *)&cmd_tunnel_filter_cmd,
9120                 (void *)&cmd_tunnel_filter_what,
9121                 (void *)&cmd_tunnel_filter_port_id,
9122                 (void *)&cmd_tunnel_filter_outer_mac,
9123                 (void *)&cmd_tunnel_filter_inner_mac,
9124                 (void *)&cmd_tunnel_filter_ip_value,
9125                 (void *)&cmd_tunnel_filter_innner_vlan,
9126                 (void *)&cmd_tunnel_filter_tunnel_type,
9127                 (void *)&cmd_tunnel_filter_filter_type,
9128                 (void *)&cmd_tunnel_filter_tenant_id,
9129                 (void *)&cmd_tunnel_filter_queue_num,
9130                 NULL,
9131         },
9132 };
9133
9134 /* *** CONFIGURE TUNNEL UDP PORT *** */
9135 struct cmd_tunnel_udp_config {
9136         cmdline_fixed_string_t cmd;
9137         cmdline_fixed_string_t what;
9138         uint16_t udp_port;
9139         portid_t port_id;
9140 };
9141
9142 static void
9143 cmd_tunnel_udp_config_parsed(void *parsed_result,
9144                           __rte_unused struct cmdline *cl,
9145                           __rte_unused void *data)
9146 {
9147         struct cmd_tunnel_udp_config *res = parsed_result;
9148         struct rte_eth_udp_tunnel tunnel_udp;
9149         int ret;
9150
9151         tunnel_udp.udp_port = res->udp_port;
9152
9153         if (!strcmp(res->cmd, "rx_vxlan_port"))
9154                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9155
9156         if (!strcmp(res->what, "add"))
9157                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9158                                                       &tunnel_udp);
9159         else
9160                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9161                                                          &tunnel_udp);
9162
9163         if (ret < 0)
9164                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9165 }
9166
9167 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9168         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9169                                 cmd, "rx_vxlan_port");
9170 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9171         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9172                                 what, "add#rm");
9173 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9174         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9175                                 udp_port, UINT16);
9176 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9177         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9178                                 port_id, UINT16);
9179
9180 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9181         .f = cmd_tunnel_udp_config_parsed,
9182         .data = (void *)0,
9183         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9184                 "Add/Remove a tunneling UDP port filter",
9185         .tokens = {
9186                 (void *)&cmd_tunnel_udp_config_cmd,
9187                 (void *)&cmd_tunnel_udp_config_what,
9188                 (void *)&cmd_tunnel_udp_config_udp_port,
9189                 (void *)&cmd_tunnel_udp_config_port_id,
9190                 NULL,
9191         },
9192 };
9193
9194 struct cmd_config_tunnel_udp_port {
9195         cmdline_fixed_string_t port;
9196         cmdline_fixed_string_t config;
9197         portid_t port_id;
9198         cmdline_fixed_string_t udp_tunnel_port;
9199         cmdline_fixed_string_t action;
9200         cmdline_fixed_string_t tunnel_type;
9201         uint16_t udp_port;
9202 };
9203
9204 static void
9205 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9206                                __rte_unused struct cmdline *cl,
9207                                __rte_unused void *data)
9208 {
9209         struct cmd_config_tunnel_udp_port *res = parsed_result;
9210         struct rte_eth_udp_tunnel tunnel_udp;
9211         int ret = 0;
9212
9213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9214                 return;
9215
9216         tunnel_udp.udp_port = res->udp_port;
9217
9218         if (!strcmp(res->tunnel_type, "vxlan")) {
9219                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9220         } else if (!strcmp(res->tunnel_type, "geneve")) {
9221                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9222         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9223                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9224         } else {
9225                 printf("Invalid tunnel type\n");
9226                 return;
9227         }
9228
9229         if (!strcmp(res->action, "add"))
9230                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9231                                                       &tunnel_udp);
9232         else
9233                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9234                                                          &tunnel_udp);
9235
9236         if (ret < 0)
9237                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9238 }
9239
9240 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9241         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9242                                  "port");
9243 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9244         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9245                                  "config");
9246 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9247         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9248                               UINT16);
9249 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9250         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9251                                  udp_tunnel_port,
9252                                  "udp_tunnel_port");
9253 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9254         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9255                                  "add#rm");
9256 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9257         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9258                                  "vxlan#geneve#vxlan-gpe");
9259 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9260         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9261                               UINT16);
9262
9263 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9264         .f = cmd_cfg_tunnel_udp_port_parsed,
9265         .data = NULL,
9266         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9267         .tokens = {
9268                 (void *)&cmd_config_tunnel_udp_port_port,
9269                 (void *)&cmd_config_tunnel_udp_port_config,
9270                 (void *)&cmd_config_tunnel_udp_port_port_id,
9271                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9272                 (void *)&cmd_config_tunnel_udp_port_action,
9273                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9274                 (void *)&cmd_config_tunnel_udp_port_value,
9275                 NULL,
9276         },
9277 };
9278
9279 /* *** GLOBAL CONFIG *** */
9280 struct cmd_global_config_result {
9281         cmdline_fixed_string_t cmd;
9282         portid_t port_id;
9283         cmdline_fixed_string_t cfg_type;
9284         uint8_t len;
9285 };
9286
9287 static void
9288 cmd_global_config_parsed(void *parsed_result,
9289                          __rte_unused struct cmdline *cl,
9290                          __rte_unused void *data)
9291 {
9292         struct cmd_global_config_result *res = parsed_result;
9293         struct rte_eth_global_cfg conf;
9294         int ret;
9295
9296         memset(&conf, 0, sizeof(conf));
9297         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9298         conf.cfg.gre_key_len = res->len;
9299         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9300                                       RTE_ETH_FILTER_SET, &conf);
9301 #ifdef RTE_LIBRTE_I40E_PMD
9302         if (ret == -ENOTSUP)
9303                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9304 #endif
9305         if (ret != 0)
9306                 printf("Global config error\n");
9307 }
9308
9309 cmdline_parse_token_string_t cmd_global_config_cmd =
9310         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9311                 "global_config");
9312 cmdline_parse_token_num_t cmd_global_config_port_id =
9313         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9314                                UINT16);
9315 cmdline_parse_token_string_t cmd_global_config_type =
9316         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9317                 cfg_type, "gre-key-len");
9318 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9319         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9320                 len, UINT8);
9321
9322 cmdline_parse_inst_t cmd_global_config = {
9323         .f = cmd_global_config_parsed,
9324         .data = (void *)NULL,
9325         .help_str = "global_config <port_id> gre-key-len <key_len>",
9326         .tokens = {
9327                 (void *)&cmd_global_config_cmd,
9328                 (void *)&cmd_global_config_port_id,
9329                 (void *)&cmd_global_config_type,
9330                 (void *)&cmd_global_config_gre_key_len,
9331                 NULL,
9332         },
9333 };
9334
9335 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9336 struct cmd_set_mirror_mask_result {
9337         cmdline_fixed_string_t set;
9338         cmdline_fixed_string_t port;
9339         portid_t port_id;
9340         cmdline_fixed_string_t mirror;
9341         uint8_t rule_id;
9342         cmdline_fixed_string_t what;
9343         cmdline_fixed_string_t value;
9344         cmdline_fixed_string_t dstpool;
9345         uint8_t dstpool_id;
9346         cmdline_fixed_string_t on;
9347 };
9348
9349 cmdline_parse_token_string_t cmd_mirror_mask_set =
9350         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9351                                 set, "set");
9352 cmdline_parse_token_string_t cmd_mirror_mask_port =
9353         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9354                                 port, "port");
9355 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9356         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9357                                 port_id, UINT16);
9358 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9359         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9360                                 mirror, "mirror-rule");
9361 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9362         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9363                                 rule_id, UINT8);
9364 cmdline_parse_token_string_t cmd_mirror_mask_what =
9365         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9366                                 what, "pool-mirror-up#pool-mirror-down"
9367                                       "#vlan-mirror");
9368 cmdline_parse_token_string_t cmd_mirror_mask_value =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9370                                 value, NULL);
9371 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9372         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9373                                 dstpool, "dst-pool");
9374 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9375         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9376                                 dstpool_id, UINT8);
9377 cmdline_parse_token_string_t cmd_mirror_mask_on =
9378         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9379                                 on, "on#off");
9380
9381 static void
9382 cmd_set_mirror_mask_parsed(void *parsed_result,
9383                        __rte_unused struct cmdline *cl,
9384                        __rte_unused void *data)
9385 {
9386         int ret,nb_item,i;
9387         struct cmd_set_mirror_mask_result *res = parsed_result;
9388         struct rte_eth_mirror_conf mr_conf;
9389
9390         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9391
9392         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9393
9394         mr_conf.dst_pool = res->dstpool_id;
9395
9396         if (!strcmp(res->what, "pool-mirror-up")) {
9397                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9398                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9399         } else if (!strcmp(res->what, "pool-mirror-down")) {
9400                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9401                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9402         } else if (!strcmp(res->what, "vlan-mirror")) {
9403                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9404                 nb_item = parse_item_list(res->value, "vlan",
9405                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9406                 if (nb_item <= 0)
9407                         return;
9408
9409                 for (i = 0; i < nb_item; i++) {
9410                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9411                                 printf("Invalid vlan_id: must be < 4096\n");
9412                                 return;
9413                         }
9414
9415                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9416                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9417                 }
9418         }
9419
9420         if (!strcmp(res->on, "on"))
9421                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9422                                                 res->rule_id, 1);
9423         else
9424                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9425                                                 res->rule_id, 0);
9426         if (ret < 0)
9427                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9428 }
9429
9430 cmdline_parse_inst_t cmd_set_mirror_mask = {
9431                 .f = cmd_set_mirror_mask_parsed,
9432                 .data = NULL,
9433                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9434                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9435                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9436                 .tokens = {
9437                         (void *)&cmd_mirror_mask_set,
9438                         (void *)&cmd_mirror_mask_port,
9439                         (void *)&cmd_mirror_mask_portid,
9440                         (void *)&cmd_mirror_mask_mirror,
9441                         (void *)&cmd_mirror_mask_ruleid,
9442                         (void *)&cmd_mirror_mask_what,
9443                         (void *)&cmd_mirror_mask_value,
9444                         (void *)&cmd_mirror_mask_dstpool,
9445                         (void *)&cmd_mirror_mask_poolid,
9446                         (void *)&cmd_mirror_mask_on,
9447                         NULL,
9448                 },
9449 };
9450
9451 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9452 struct cmd_set_mirror_link_result {
9453         cmdline_fixed_string_t set;
9454         cmdline_fixed_string_t port;
9455         portid_t port_id;
9456         cmdline_fixed_string_t mirror;
9457         uint8_t rule_id;
9458         cmdline_fixed_string_t what;
9459         cmdline_fixed_string_t dstpool;
9460         uint8_t dstpool_id;
9461         cmdline_fixed_string_t on;
9462 };
9463
9464 cmdline_parse_token_string_t cmd_mirror_link_set =
9465         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9466                                  set, "set");
9467 cmdline_parse_token_string_t cmd_mirror_link_port =
9468         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9469                                 port, "port");
9470 cmdline_parse_token_num_t cmd_mirror_link_portid =
9471         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9472                                 port_id, UINT16);
9473 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9474         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9475                                 mirror, "mirror-rule");
9476 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9477         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9478                             rule_id, UINT8);
9479 cmdline_parse_token_string_t cmd_mirror_link_what =
9480         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9481                                 what, "uplink-mirror#downlink-mirror");
9482 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9483         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9484                                 dstpool, "dst-pool");
9485 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9486         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9487                                 dstpool_id, UINT8);
9488 cmdline_parse_token_string_t cmd_mirror_link_on =
9489         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9490                                 on, "on#off");
9491
9492 static void
9493 cmd_set_mirror_link_parsed(void *parsed_result,
9494                        __rte_unused struct cmdline *cl,
9495                        __rte_unused void *data)
9496 {
9497         int ret;
9498         struct cmd_set_mirror_link_result *res = parsed_result;
9499         struct rte_eth_mirror_conf mr_conf;
9500
9501         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9502         if (!strcmp(res->what, "uplink-mirror"))
9503                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9504         else
9505                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9506
9507         mr_conf.dst_pool = res->dstpool_id;
9508
9509         if (!strcmp(res->on, "on"))
9510                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9511                                                 res->rule_id, 1);
9512         else
9513                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9514                                                 res->rule_id, 0);
9515
9516         /* check the return value and print it if is < 0 */
9517         if (ret < 0)
9518                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9519
9520 }
9521
9522 cmdline_parse_inst_t cmd_set_mirror_link = {
9523                 .f = cmd_set_mirror_link_parsed,
9524                 .data = NULL,
9525                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9526                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9527                 .tokens = {
9528                         (void *)&cmd_mirror_link_set,
9529                         (void *)&cmd_mirror_link_port,
9530                         (void *)&cmd_mirror_link_portid,
9531                         (void *)&cmd_mirror_link_mirror,
9532                         (void *)&cmd_mirror_link_ruleid,
9533                         (void *)&cmd_mirror_link_what,
9534                         (void *)&cmd_mirror_link_dstpool,
9535                         (void *)&cmd_mirror_link_poolid,
9536                         (void *)&cmd_mirror_link_on,
9537                         NULL,
9538                 },
9539 };
9540
9541 /* *** RESET VM MIRROR RULE *** */
9542 struct cmd_rm_mirror_rule_result {
9543         cmdline_fixed_string_t reset;
9544         cmdline_fixed_string_t port;
9545         portid_t port_id;
9546         cmdline_fixed_string_t mirror;
9547         uint8_t rule_id;
9548 };
9549
9550 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9551         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9552                                  reset, "reset");
9553 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9554         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9555                                 port, "port");
9556 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9557         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9558                                 port_id, UINT16);
9559 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9560         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9561                                 mirror, "mirror-rule");
9562 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9563         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9564                                 rule_id, UINT8);
9565
9566 static void
9567 cmd_reset_mirror_rule_parsed(void *parsed_result,
9568                        __rte_unused struct cmdline *cl,
9569                        __rte_unused void *data)
9570 {
9571         int ret;
9572         struct cmd_set_mirror_link_result *res = parsed_result;
9573         /* check rule_id */
9574         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9575         if(ret < 0)
9576                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9577 }
9578
9579 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9580                 .f = cmd_reset_mirror_rule_parsed,
9581                 .data = NULL,
9582                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9583                 .tokens = {
9584                         (void *)&cmd_rm_mirror_rule_reset,
9585                         (void *)&cmd_rm_mirror_rule_port,
9586                         (void *)&cmd_rm_mirror_rule_portid,
9587                         (void *)&cmd_rm_mirror_rule_mirror,
9588                         (void *)&cmd_rm_mirror_rule_ruleid,
9589                         NULL,
9590                 },
9591 };
9592
9593 /* ******************************************************************************** */
9594
9595 struct cmd_dump_result {
9596         cmdline_fixed_string_t dump;
9597 };
9598
9599 static void
9600 dump_struct_sizes(void)
9601 {
9602 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9603         DUMP_SIZE(struct rte_mbuf);
9604         DUMP_SIZE(struct rte_mempool);
9605         DUMP_SIZE(struct rte_ring);
9606 #undef DUMP_SIZE
9607 }
9608
9609
9610 /* Dump the socket memory statistics on console */
9611 static void
9612 dump_socket_mem(FILE *f)
9613 {
9614         struct rte_malloc_socket_stats socket_stats;
9615         unsigned int i;
9616         size_t total = 0;
9617         size_t alloc = 0;
9618         size_t free = 0;
9619         unsigned int n_alloc = 0;
9620         unsigned int n_free = 0;
9621         static size_t last_allocs;
9622         static size_t last_total;
9623
9624
9625         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9626                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9627                     !socket_stats.heap_totalsz_bytes)
9628                         continue;
9629                 total += socket_stats.heap_totalsz_bytes;
9630                 alloc += socket_stats.heap_allocsz_bytes;
9631                 free += socket_stats.heap_freesz_bytes;
9632                 n_alloc += socket_stats.alloc_count;
9633                 n_free += socket_stats.free_count;
9634                 fprintf(f,
9635                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9636                         i,
9637                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9638                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9639                         (double)socket_stats.heap_allocsz_bytes * 100 /
9640                         (double)socket_stats.heap_totalsz_bytes,
9641                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9642                         socket_stats.alloc_count,
9643                         socket_stats.free_count);
9644         }
9645         fprintf(f,
9646                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9647                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9648                 (double)alloc * 100 / (double)total,
9649                 (double)free / (1024 * 1024),
9650                 n_alloc, n_free);
9651         if (last_allocs)
9652                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9653                         ((double)total - (double)last_total) / (1024 * 1024),
9654                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9655         last_allocs = alloc;
9656         last_total = total;
9657 }
9658
9659 static void cmd_dump_parsed(void *parsed_result,
9660                             __rte_unused struct cmdline *cl,
9661                             __rte_unused void *data)
9662 {
9663         struct cmd_dump_result *res = parsed_result;
9664
9665         if (!strcmp(res->dump, "dump_physmem"))
9666                 rte_dump_physmem_layout(stdout);
9667         else if (!strcmp(res->dump, "dump_socket_mem"))
9668                 dump_socket_mem(stdout);
9669         else if (!strcmp(res->dump, "dump_memzone"))
9670                 rte_memzone_dump(stdout);
9671         else if (!strcmp(res->dump, "dump_struct_sizes"))
9672                 dump_struct_sizes();
9673         else if (!strcmp(res->dump, "dump_ring"))
9674                 rte_ring_list_dump(stdout);
9675         else if (!strcmp(res->dump, "dump_mempool"))
9676                 rte_mempool_list_dump(stdout);
9677         else if (!strcmp(res->dump, "dump_devargs"))
9678                 rte_devargs_dump(stdout);
9679         else if (!strcmp(res->dump, "dump_log_types"))
9680                 rte_log_dump(stdout);
9681 }
9682
9683 cmdline_parse_token_string_t cmd_dump_dump =
9684         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9685                 "dump_physmem#"
9686                 "dump_memzone#"
9687                 "dump_socket_mem#"
9688                 "dump_struct_sizes#"
9689                 "dump_ring#"
9690                 "dump_mempool#"
9691                 "dump_devargs#"
9692                 "dump_log_types");
9693
9694 cmdline_parse_inst_t cmd_dump = {
9695         .f = cmd_dump_parsed,  /* function to call */
9696         .data = NULL,      /* 2nd arg of func */
9697         .help_str = "Dump status",
9698         .tokens = {        /* token list, NULL terminated */
9699                 (void *)&cmd_dump_dump,
9700                 NULL,
9701         },
9702 };
9703
9704 /* ******************************************************************************** */
9705
9706 struct cmd_dump_one_result {
9707         cmdline_fixed_string_t dump;
9708         cmdline_fixed_string_t name;
9709 };
9710
9711 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9712                                 __rte_unused void *data)
9713 {
9714         struct cmd_dump_one_result *res = parsed_result;
9715
9716         if (!strcmp(res->dump, "dump_ring")) {
9717                 struct rte_ring *r;
9718                 r = rte_ring_lookup(res->name);
9719                 if (r == NULL) {
9720                         cmdline_printf(cl, "Cannot find ring\n");
9721                         return;
9722                 }
9723                 rte_ring_dump(stdout, r);
9724         } else if (!strcmp(res->dump, "dump_mempool")) {
9725                 struct rte_mempool *mp;
9726                 mp = rte_mempool_lookup(res->name);
9727                 if (mp == NULL) {
9728                         cmdline_printf(cl, "Cannot find mempool\n");
9729                         return;
9730                 }
9731                 rte_mempool_dump(stdout, mp);
9732         }
9733 }
9734
9735 cmdline_parse_token_string_t cmd_dump_one_dump =
9736         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9737                                  "dump_ring#dump_mempool");
9738
9739 cmdline_parse_token_string_t cmd_dump_one_name =
9740         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9741
9742 cmdline_parse_inst_t cmd_dump_one = {
9743         .f = cmd_dump_one_parsed,  /* function to call */
9744         .data = NULL,      /* 2nd arg of func */
9745         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9746         .tokens = {        /* token list, NULL terminated */
9747                 (void *)&cmd_dump_one_dump,
9748                 (void *)&cmd_dump_one_name,
9749                 NULL,
9750         },
9751 };
9752
9753 /* *** Add/Del syn filter *** */
9754 struct cmd_syn_filter_result {
9755         cmdline_fixed_string_t filter;
9756         portid_t port_id;
9757         cmdline_fixed_string_t ops;
9758         cmdline_fixed_string_t priority;
9759         cmdline_fixed_string_t high;
9760         cmdline_fixed_string_t queue;
9761         uint16_t queue_id;
9762 };
9763
9764 static void
9765 cmd_syn_filter_parsed(void *parsed_result,
9766                         __rte_unused struct cmdline *cl,
9767                         __rte_unused void *data)
9768 {
9769         struct cmd_syn_filter_result *res = parsed_result;
9770         struct rte_eth_syn_filter syn_filter;
9771         int ret = 0;
9772
9773         ret = rte_eth_dev_filter_supported(res->port_id,
9774                                         RTE_ETH_FILTER_SYN);
9775         if (ret < 0) {
9776                 printf("syn filter is not supported on port %u.\n",
9777                                 res->port_id);
9778                 return;
9779         }
9780
9781         memset(&syn_filter, 0, sizeof(syn_filter));
9782
9783         if (!strcmp(res->ops, "add")) {
9784                 if (!strcmp(res->high, "high"))
9785                         syn_filter.hig_pri = 1;
9786                 else
9787                         syn_filter.hig_pri = 0;
9788
9789                 syn_filter.queue = res->queue_id;
9790                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9791                                                 RTE_ETH_FILTER_SYN,
9792                                                 RTE_ETH_FILTER_ADD,
9793                                                 &syn_filter);
9794         } else
9795                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9796                                                 RTE_ETH_FILTER_SYN,
9797                                                 RTE_ETH_FILTER_DELETE,
9798                                                 &syn_filter);
9799
9800         if (ret < 0)
9801                 printf("syn filter programming error: (%s)\n",
9802                                 strerror(-ret));
9803 }
9804
9805 cmdline_parse_token_string_t cmd_syn_filter_filter =
9806         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9807         filter, "syn_filter");
9808 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9809         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9810         port_id, UINT16);
9811 cmdline_parse_token_string_t cmd_syn_filter_ops =
9812         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9813         ops, "add#del");
9814 cmdline_parse_token_string_t cmd_syn_filter_priority =
9815         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9816                                 priority, "priority");
9817 cmdline_parse_token_string_t cmd_syn_filter_high =
9818         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9819                                 high, "high#low");
9820 cmdline_parse_token_string_t cmd_syn_filter_queue =
9821         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9822                                 queue, "queue");
9823 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9824         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9825                                 queue_id, UINT16);
9826
9827 cmdline_parse_inst_t cmd_syn_filter = {
9828         .f = cmd_syn_filter_parsed,
9829         .data = NULL,
9830         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9831                 "<queue_id>: Add/Delete syn filter",
9832         .tokens = {
9833                 (void *)&cmd_syn_filter_filter,
9834                 (void *)&cmd_syn_filter_port_id,
9835                 (void *)&cmd_syn_filter_ops,
9836                 (void *)&cmd_syn_filter_priority,
9837                 (void *)&cmd_syn_filter_high,
9838                 (void *)&cmd_syn_filter_queue,
9839                 (void *)&cmd_syn_filter_queue_id,
9840                 NULL,
9841         },
9842 };
9843
9844 /* *** queue region set *** */
9845 struct cmd_queue_region_result {
9846         cmdline_fixed_string_t set;
9847         cmdline_fixed_string_t port;
9848         portid_t port_id;
9849         cmdline_fixed_string_t cmd;
9850         cmdline_fixed_string_t region;
9851         uint8_t  region_id;
9852         cmdline_fixed_string_t queue_start_index;
9853         uint8_t  queue_id;
9854         cmdline_fixed_string_t queue_num;
9855         uint8_t  queue_num_value;
9856 };
9857
9858 static void
9859 cmd_queue_region_parsed(void *parsed_result,
9860                         __rte_unused struct cmdline *cl,
9861                         __rte_unused void *data)
9862 {
9863         struct cmd_queue_region_result *res = parsed_result;
9864         int ret = -ENOTSUP;
9865 #ifdef RTE_LIBRTE_I40E_PMD
9866         struct rte_pmd_i40e_queue_region_conf region_conf;
9867         enum rte_pmd_i40e_queue_region_op op_type;
9868 #endif
9869
9870         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9871                 return;
9872
9873 #ifdef RTE_LIBRTE_I40E_PMD
9874         memset(&region_conf, 0, sizeof(region_conf));
9875         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9876         region_conf.region_id = res->region_id;
9877         region_conf.queue_num = res->queue_num_value;
9878         region_conf.queue_start_index = res->queue_id;
9879
9880         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9881                                 op_type, &region_conf);
9882 #endif
9883
9884         switch (ret) {
9885         case 0:
9886                 break;
9887         case -ENOTSUP:
9888                 printf("function not implemented or supported\n");
9889                 break;
9890         default:
9891                 printf("queue region config error: (%s)\n", strerror(-ret));
9892         }
9893 }
9894
9895 cmdline_parse_token_string_t cmd_queue_region_set =
9896 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9897                 set, "set");
9898 cmdline_parse_token_string_t cmd_queue_region_port =
9899         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9900 cmdline_parse_token_num_t cmd_queue_region_port_id =
9901         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9902                                 port_id, UINT16);
9903 cmdline_parse_token_string_t cmd_queue_region_cmd =
9904         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9905                                  cmd, "queue-region");
9906 cmdline_parse_token_string_t cmd_queue_region_id =
9907         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9908                                 region, "region_id");
9909 cmdline_parse_token_num_t cmd_queue_region_index =
9910         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9911                                 region_id, UINT8);
9912 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9913         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9914                                 queue_start_index, "queue_start_index");
9915 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9916         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9917                                 queue_id, UINT8);
9918 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9919         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9920                                 queue_num, "queue_num");
9921 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9922         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9923                                 queue_num_value, UINT8);
9924
9925 cmdline_parse_inst_t cmd_queue_region = {
9926         .f = cmd_queue_region_parsed,
9927         .data = NULL,
9928         .help_str = "set port <port_id> queue-region region_id <value> "
9929                 "queue_start_index <value> queue_num <value>: Set a queue region",
9930         .tokens = {
9931                 (void *)&cmd_queue_region_set,
9932                 (void *)&cmd_queue_region_port,
9933                 (void *)&cmd_queue_region_port_id,
9934                 (void *)&cmd_queue_region_cmd,
9935                 (void *)&cmd_queue_region_id,
9936                 (void *)&cmd_queue_region_index,
9937                 (void *)&cmd_queue_region_queue_start_index,
9938                 (void *)&cmd_queue_region_queue_id,
9939                 (void *)&cmd_queue_region_queue_num,
9940                 (void *)&cmd_queue_region_queue_num_value,
9941                 NULL,
9942         },
9943 };
9944
9945 /* *** queue region and flowtype set *** */
9946 struct cmd_region_flowtype_result {
9947         cmdline_fixed_string_t set;
9948         cmdline_fixed_string_t port;
9949         portid_t port_id;
9950         cmdline_fixed_string_t cmd;
9951         cmdline_fixed_string_t region;
9952         uint8_t  region_id;
9953         cmdline_fixed_string_t flowtype;
9954         uint8_t  flowtype_id;
9955 };
9956
9957 static void
9958 cmd_region_flowtype_parsed(void *parsed_result,
9959                         __rte_unused struct cmdline *cl,
9960                         __rte_unused void *data)
9961 {
9962         struct cmd_region_flowtype_result *res = parsed_result;
9963         int ret = -ENOTSUP;
9964 #ifdef RTE_LIBRTE_I40E_PMD
9965         struct rte_pmd_i40e_queue_region_conf region_conf;
9966         enum rte_pmd_i40e_queue_region_op op_type;
9967 #endif
9968
9969         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9970                 return;
9971
9972 #ifdef RTE_LIBRTE_I40E_PMD
9973         memset(&region_conf, 0, sizeof(region_conf));
9974
9975         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9976         region_conf.region_id = res->region_id;
9977         region_conf.hw_flowtype = res->flowtype_id;
9978
9979         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9980                         op_type, &region_conf);
9981 #endif
9982
9983         switch (ret) {
9984         case 0:
9985                 break;
9986         case -ENOTSUP:
9987                 printf("function not implemented or supported\n");
9988                 break;
9989         default:
9990                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9991         }
9992 }
9993
9994 cmdline_parse_token_string_t cmd_region_flowtype_set =
9995 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9996                                 set, "set");
9997 cmdline_parse_token_string_t cmd_region_flowtype_port =
9998         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9999                                 port, "port");
10000 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10001         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10002                                 port_id, UINT16);
10003 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10004         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10005                                 cmd, "queue-region");
10006 cmdline_parse_token_string_t cmd_region_flowtype_index =
10007         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10008                                 region, "region_id");
10009 cmdline_parse_token_num_t cmd_region_flowtype_id =
10010         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10011                                 region_id, UINT8);
10012 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10013         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10014                                 flowtype, "flowtype");
10015 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10016         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10017                                 flowtype_id, UINT8);
10018 cmdline_parse_inst_t cmd_region_flowtype = {
10019         .f = cmd_region_flowtype_parsed,
10020         .data = NULL,
10021         .help_str = "set port <port_id> queue-region region_id <value> "
10022                 "flowtype <value>: Set a flowtype region index",
10023         .tokens = {
10024                 (void *)&cmd_region_flowtype_set,
10025                 (void *)&cmd_region_flowtype_port,
10026                 (void *)&cmd_region_flowtype_port_index,
10027                 (void *)&cmd_region_flowtype_cmd,
10028                 (void *)&cmd_region_flowtype_index,
10029                 (void *)&cmd_region_flowtype_id,
10030                 (void *)&cmd_region_flowtype_flow_index,
10031                 (void *)&cmd_region_flowtype_flow_id,
10032                 NULL,
10033         },
10034 };
10035
10036 /* *** User Priority (UP) to queue region (region_id) set *** */
10037 struct cmd_user_priority_region_result {
10038         cmdline_fixed_string_t set;
10039         cmdline_fixed_string_t port;
10040         portid_t port_id;
10041         cmdline_fixed_string_t cmd;
10042         cmdline_fixed_string_t user_priority;
10043         uint8_t  user_priority_id;
10044         cmdline_fixed_string_t region;
10045         uint8_t  region_id;
10046 };
10047
10048 static void
10049 cmd_user_priority_region_parsed(void *parsed_result,
10050                         __rte_unused struct cmdline *cl,
10051                         __rte_unused void *data)
10052 {
10053         struct cmd_user_priority_region_result *res = parsed_result;
10054         int ret = -ENOTSUP;
10055 #ifdef RTE_LIBRTE_I40E_PMD
10056         struct rte_pmd_i40e_queue_region_conf region_conf;
10057         enum rte_pmd_i40e_queue_region_op op_type;
10058 #endif
10059
10060         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10061                 return;
10062
10063 #ifdef RTE_LIBRTE_I40E_PMD
10064         memset(&region_conf, 0, sizeof(region_conf));
10065         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10066         region_conf.user_priority = res->user_priority_id;
10067         region_conf.region_id = res->region_id;
10068
10069         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10070                                 op_type, &region_conf);
10071 #endif
10072
10073         switch (ret) {
10074         case 0:
10075                 break;
10076         case -ENOTSUP:
10077                 printf("function not implemented or supported\n");
10078                 break;
10079         default:
10080                 printf("user_priority region config error: (%s)\n",
10081                                 strerror(-ret));
10082         }
10083 }
10084
10085 cmdline_parse_token_string_t cmd_user_priority_region_set =
10086         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10087                                 set, "set");
10088 cmdline_parse_token_string_t cmd_user_priority_region_port =
10089         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10090                                 port, "port");
10091 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10092         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10093                                 port_id, UINT16);
10094 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10095         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10096                                 cmd, "queue-region");
10097 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10098         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10099                                 user_priority, "UP");
10100 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10101         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10102                                 user_priority_id, UINT8);
10103 cmdline_parse_token_string_t cmd_user_priority_region_region =
10104         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10105                                 region, "region_id");
10106 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10107         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10108                                 region_id, UINT8);
10109
10110 cmdline_parse_inst_t cmd_user_priority_region = {
10111         .f = cmd_user_priority_region_parsed,
10112         .data = NULL,
10113         .help_str = "set port <port_id> queue-region UP <value> "
10114                 "region_id <value>: Set the mapping of User Priority (UP) "
10115                 "to queue region (region_id) ",
10116         .tokens = {
10117                 (void *)&cmd_user_priority_region_set,
10118                 (void *)&cmd_user_priority_region_port,
10119                 (void *)&cmd_user_priority_region_port_index,
10120                 (void *)&cmd_user_priority_region_cmd,
10121                 (void *)&cmd_user_priority_region_UP,
10122                 (void *)&cmd_user_priority_region_UP_id,
10123                 (void *)&cmd_user_priority_region_region,
10124                 (void *)&cmd_user_priority_region_region_id,
10125                 NULL,
10126         },
10127 };
10128
10129 /* *** flush all queue region related configuration *** */
10130 struct cmd_flush_queue_region_result {
10131         cmdline_fixed_string_t set;
10132         cmdline_fixed_string_t port;
10133         portid_t port_id;
10134         cmdline_fixed_string_t cmd;
10135         cmdline_fixed_string_t flush;
10136         cmdline_fixed_string_t what;
10137 };
10138
10139 static void
10140 cmd_flush_queue_region_parsed(void *parsed_result,
10141                         __rte_unused struct cmdline *cl,
10142                         __rte_unused void *data)
10143 {
10144         struct cmd_flush_queue_region_result *res = parsed_result;
10145         int ret = -ENOTSUP;
10146 #ifdef RTE_LIBRTE_I40E_PMD
10147         struct rte_pmd_i40e_queue_region_conf region_conf;
10148         enum rte_pmd_i40e_queue_region_op op_type;
10149 #endif
10150
10151         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10152                 return;
10153
10154 #ifdef RTE_LIBRTE_I40E_PMD
10155         memset(&region_conf, 0, sizeof(region_conf));
10156
10157         if (strcmp(res->what, "on") == 0)
10158                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10159         else
10160                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10161
10162         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10163                                 op_type, &region_conf);
10164 #endif
10165
10166         switch (ret) {
10167         case 0:
10168                 break;
10169         case -ENOTSUP:
10170                 printf("function not implemented or supported\n");
10171                 break;
10172         default:
10173                 printf("queue region config flush error: (%s)\n",
10174                                 strerror(-ret));
10175         }
10176 }
10177
10178 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10179         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10180                                 set, "set");
10181 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10182         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10183                                 port, "port");
10184 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10185         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10186                                 port_id, UINT16);
10187 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10188         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10189                                 cmd, "queue-region");
10190 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10191         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10192                                 flush, "flush");
10193 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10194         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10195                                 what, "on#off");
10196
10197 cmdline_parse_inst_t cmd_flush_queue_region = {
10198         .f = cmd_flush_queue_region_parsed,
10199         .data = NULL,
10200         .help_str = "set port <port_id> queue-region flush on|off"
10201                 ": flush all queue region related configuration",
10202         .tokens = {
10203                 (void *)&cmd_flush_queue_region_set,
10204                 (void *)&cmd_flush_queue_region_port,
10205                 (void *)&cmd_flush_queue_region_port_index,
10206                 (void *)&cmd_flush_queue_region_cmd,
10207                 (void *)&cmd_flush_queue_region_flush,
10208                 (void *)&cmd_flush_queue_region_what,
10209                 NULL,
10210         },
10211 };
10212
10213 /* *** get all queue region related configuration info *** */
10214 struct cmd_show_queue_region_info {
10215         cmdline_fixed_string_t show;
10216         cmdline_fixed_string_t port;
10217         portid_t port_id;
10218         cmdline_fixed_string_t cmd;
10219 };
10220
10221 static void
10222 cmd_show_queue_region_info_parsed(void *parsed_result,
10223                         __rte_unused struct cmdline *cl,
10224                         __rte_unused void *data)
10225 {
10226         struct cmd_show_queue_region_info *res = parsed_result;
10227         int ret = -ENOTSUP;
10228 #ifdef RTE_LIBRTE_I40E_PMD
10229         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10230         enum rte_pmd_i40e_queue_region_op op_type;
10231 #endif
10232
10233         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10234                 return;
10235
10236 #ifdef RTE_LIBRTE_I40E_PMD
10237         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10238
10239         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10240
10241         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10242                                         op_type, &rte_pmd_regions);
10243
10244         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10245 #endif
10246
10247         switch (ret) {
10248         case 0:
10249                 break;
10250         case -ENOTSUP:
10251                 printf("function not implemented or supported\n");
10252                 break;
10253         default:
10254                 printf("queue region config info show error: (%s)\n",
10255                                 strerror(-ret));
10256         }
10257 }
10258
10259 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10260 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10261                                 show, "show");
10262 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10263         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10264                                 port, "port");
10265 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10266         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10267                                 port_id, UINT16);
10268 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10269         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10270                                 cmd, "queue-region");
10271
10272 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10273         .f = cmd_show_queue_region_info_parsed,
10274         .data = NULL,
10275         .help_str = "show port <port_id> queue-region"
10276                 ": show all queue region related configuration info",
10277         .tokens = {
10278                 (void *)&cmd_show_queue_region_info_get,
10279                 (void *)&cmd_show_queue_region_info_port,
10280                 (void *)&cmd_show_queue_region_info_port_index,
10281                 (void *)&cmd_show_queue_region_info_cmd,
10282                 NULL,
10283         },
10284 };
10285
10286 /* *** ADD/REMOVE A 2tuple FILTER *** */
10287 struct cmd_2tuple_filter_result {
10288         cmdline_fixed_string_t filter;
10289         portid_t port_id;
10290         cmdline_fixed_string_t ops;
10291         cmdline_fixed_string_t dst_port;
10292         uint16_t dst_port_value;
10293         cmdline_fixed_string_t protocol;
10294         uint8_t protocol_value;
10295         cmdline_fixed_string_t mask;
10296         uint8_t  mask_value;
10297         cmdline_fixed_string_t tcp_flags;
10298         uint8_t tcp_flags_value;
10299         cmdline_fixed_string_t priority;
10300         uint8_t  priority_value;
10301         cmdline_fixed_string_t queue;
10302         uint16_t  queue_id;
10303 };
10304
10305 static void
10306 cmd_2tuple_filter_parsed(void *parsed_result,
10307                         __rte_unused struct cmdline *cl,
10308                         __rte_unused void *data)
10309 {
10310         struct rte_eth_ntuple_filter filter;
10311         struct cmd_2tuple_filter_result *res = parsed_result;
10312         int ret = 0;
10313
10314         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10315         if (ret < 0) {
10316                 printf("ntuple filter is not supported on port %u.\n",
10317                         res->port_id);
10318                 return;
10319         }
10320
10321         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10322
10323         filter.flags = RTE_2TUPLE_FLAGS;
10324         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10325         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10326         filter.proto = res->protocol_value;
10327         filter.priority = res->priority_value;
10328         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10329                 printf("nonzero tcp_flags is only meaningful"
10330                         " when protocol is TCP.\n");
10331                 return;
10332         }
10333         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10334                 printf("invalid TCP flags.\n");
10335                 return;
10336         }
10337
10338         if (res->tcp_flags_value != 0) {
10339                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10340                 filter.tcp_flags = res->tcp_flags_value;
10341         }
10342
10343         /* need convert to big endian. */
10344         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10345         filter.queue = res->queue_id;
10346
10347         if (!strcmp(res->ops, "add"))
10348                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10349                                 RTE_ETH_FILTER_NTUPLE,
10350                                 RTE_ETH_FILTER_ADD,
10351                                 &filter);
10352         else
10353                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10354                                 RTE_ETH_FILTER_NTUPLE,
10355                                 RTE_ETH_FILTER_DELETE,
10356                                 &filter);
10357         if (ret < 0)
10358                 printf("2tuple filter programming error: (%s)\n",
10359                         strerror(-ret));
10360
10361 }
10362
10363 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10364         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10365                                  filter, "2tuple_filter");
10366 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10367         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10368                                 port_id, UINT16);
10369 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10370         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10371                                  ops, "add#del");
10372 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10373         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10374                                 dst_port, "dst_port");
10375 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10376         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10377                                 dst_port_value, UINT16);
10378 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10379         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10380                                 protocol, "protocol");
10381 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10382         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10383                                 protocol_value, UINT8);
10384 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10385         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10386                                 mask, "mask");
10387 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10388         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10389                                 mask_value, INT8);
10390 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10391         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10392                                 tcp_flags, "tcp_flags");
10393 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10394         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10395                                 tcp_flags_value, UINT8);
10396 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10397         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10398                                 priority, "priority");
10399 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10400         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10401                                 priority_value, UINT8);
10402 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10403         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10404                                 queue, "queue");
10405 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10406         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10407                                 queue_id, UINT16);
10408
10409 cmdline_parse_inst_t cmd_2tuple_filter = {
10410         .f = cmd_2tuple_filter_parsed,
10411         .data = NULL,
10412         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10413                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10414                 "<queue_id>: Add a 2tuple filter",
10415         .tokens = {
10416                 (void *)&cmd_2tuple_filter_filter,
10417                 (void *)&cmd_2tuple_filter_port_id,
10418                 (void *)&cmd_2tuple_filter_ops,
10419                 (void *)&cmd_2tuple_filter_dst_port,
10420                 (void *)&cmd_2tuple_filter_dst_port_value,
10421                 (void *)&cmd_2tuple_filter_protocol,
10422                 (void *)&cmd_2tuple_filter_protocol_value,
10423                 (void *)&cmd_2tuple_filter_mask,
10424                 (void *)&cmd_2tuple_filter_mask_value,
10425                 (void *)&cmd_2tuple_filter_tcp_flags,
10426                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10427                 (void *)&cmd_2tuple_filter_priority,
10428                 (void *)&cmd_2tuple_filter_priority_value,
10429                 (void *)&cmd_2tuple_filter_queue,
10430                 (void *)&cmd_2tuple_filter_queue_id,
10431                 NULL,
10432         },
10433 };
10434
10435 /* *** ADD/REMOVE A 5tuple FILTER *** */
10436 struct cmd_5tuple_filter_result {
10437         cmdline_fixed_string_t filter;
10438         portid_t port_id;
10439         cmdline_fixed_string_t ops;
10440         cmdline_fixed_string_t dst_ip;
10441         cmdline_ipaddr_t dst_ip_value;
10442         cmdline_fixed_string_t src_ip;
10443         cmdline_ipaddr_t src_ip_value;
10444         cmdline_fixed_string_t dst_port;
10445         uint16_t dst_port_value;
10446         cmdline_fixed_string_t src_port;
10447         uint16_t src_port_value;
10448         cmdline_fixed_string_t protocol;
10449         uint8_t protocol_value;
10450         cmdline_fixed_string_t mask;
10451         uint8_t  mask_value;
10452         cmdline_fixed_string_t tcp_flags;
10453         uint8_t tcp_flags_value;
10454         cmdline_fixed_string_t priority;
10455         uint8_t  priority_value;
10456         cmdline_fixed_string_t queue;
10457         uint16_t  queue_id;
10458 };
10459
10460 static void
10461 cmd_5tuple_filter_parsed(void *parsed_result,
10462                         __rte_unused struct cmdline *cl,
10463                         __rte_unused void *data)
10464 {
10465         struct rte_eth_ntuple_filter filter;
10466         struct cmd_5tuple_filter_result *res = parsed_result;
10467         int ret = 0;
10468
10469         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10470         if (ret < 0) {
10471                 printf("ntuple filter is not supported on port %u.\n",
10472                         res->port_id);
10473                 return;
10474         }
10475
10476         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10477
10478         filter.flags = RTE_5TUPLE_FLAGS;
10479         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10480         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10481         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10482         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10483         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10484         filter.proto = res->protocol_value;
10485         filter.priority = res->priority_value;
10486         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10487                 printf("nonzero tcp_flags is only meaningful"
10488                         " when protocol is TCP.\n");
10489                 return;
10490         }
10491         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10492                 printf("invalid TCP flags.\n");
10493                 return;
10494         }
10495
10496         if (res->tcp_flags_value != 0) {
10497                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10498                 filter.tcp_flags = res->tcp_flags_value;
10499         }
10500
10501         if (res->dst_ip_value.family == AF_INET)
10502                 /* no need to convert, already big endian. */
10503                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10504         else {
10505                 if (filter.dst_ip_mask == 0) {
10506                         printf("can not support ipv6 involved compare.\n");
10507                         return;
10508                 }
10509                 filter.dst_ip = 0;
10510         }
10511
10512         if (res->src_ip_value.family == AF_INET)
10513                 /* no need to convert, already big endian. */
10514                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10515         else {
10516                 if (filter.src_ip_mask == 0) {
10517                         printf("can not support ipv6 involved compare.\n");
10518                         return;
10519                 }
10520                 filter.src_ip = 0;
10521         }
10522         /* need convert to big endian. */
10523         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10524         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10525         filter.queue = res->queue_id;
10526
10527         if (!strcmp(res->ops, "add"))
10528                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10529                                 RTE_ETH_FILTER_NTUPLE,
10530                                 RTE_ETH_FILTER_ADD,
10531                                 &filter);
10532         else
10533                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10534                                 RTE_ETH_FILTER_NTUPLE,
10535                                 RTE_ETH_FILTER_DELETE,
10536                                 &filter);
10537         if (ret < 0)
10538                 printf("5tuple filter programming error: (%s)\n",
10539                         strerror(-ret));
10540 }
10541
10542 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10543         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10544                                  filter, "5tuple_filter");
10545 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10546         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10547                                 port_id, UINT16);
10548 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10549         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10550                                  ops, "add#del");
10551 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10552         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10553                                 dst_ip, "dst_ip");
10554 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10555         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10556                                 dst_ip_value);
10557 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10558         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10559                                 src_ip, "src_ip");
10560 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10561         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10562                                 src_ip_value);
10563 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10564         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10565                                 dst_port, "dst_port");
10566 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10567         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10568                                 dst_port_value, UINT16);
10569 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10570         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10571                                 src_port, "src_port");
10572 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10573         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10574                                 src_port_value, UINT16);
10575 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10576         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10577                                 protocol, "protocol");
10578 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10579         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10580                                 protocol_value, UINT8);
10581 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10582         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10583                                 mask, "mask");
10584 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10585         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10586                                 mask_value, INT8);
10587 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10588         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10589                                 tcp_flags, "tcp_flags");
10590 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10591         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10592                                 tcp_flags_value, UINT8);
10593 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10594         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10595                                 priority, "priority");
10596 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10597         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10598                                 priority_value, UINT8);
10599 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10600         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10601                                 queue, "queue");
10602 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10603         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10604                                 queue_id, UINT16);
10605
10606 cmdline_parse_inst_t cmd_5tuple_filter = {
10607         .f = cmd_5tuple_filter_parsed,
10608         .data = NULL,
10609         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10610                 "src_ip <value> dst_port <value> src_port <value> "
10611                 "protocol <value>  mask <value> tcp_flags <value> "
10612                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10613         .tokens = {
10614                 (void *)&cmd_5tuple_filter_filter,
10615                 (void *)&cmd_5tuple_filter_port_id,
10616                 (void *)&cmd_5tuple_filter_ops,
10617                 (void *)&cmd_5tuple_filter_dst_ip,
10618                 (void *)&cmd_5tuple_filter_dst_ip_value,
10619                 (void *)&cmd_5tuple_filter_src_ip,
10620                 (void *)&cmd_5tuple_filter_src_ip_value,
10621                 (void *)&cmd_5tuple_filter_dst_port,
10622                 (void *)&cmd_5tuple_filter_dst_port_value,
10623                 (void *)&cmd_5tuple_filter_src_port,
10624                 (void *)&cmd_5tuple_filter_src_port_value,
10625                 (void *)&cmd_5tuple_filter_protocol,
10626                 (void *)&cmd_5tuple_filter_protocol_value,
10627                 (void *)&cmd_5tuple_filter_mask,
10628                 (void *)&cmd_5tuple_filter_mask_value,
10629                 (void *)&cmd_5tuple_filter_tcp_flags,
10630                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10631                 (void *)&cmd_5tuple_filter_priority,
10632                 (void *)&cmd_5tuple_filter_priority_value,
10633                 (void *)&cmd_5tuple_filter_queue,
10634                 (void *)&cmd_5tuple_filter_queue_id,
10635                 NULL,
10636         },
10637 };
10638
10639 /* *** ADD/REMOVE A flex FILTER *** */
10640 struct cmd_flex_filter_result {
10641         cmdline_fixed_string_t filter;
10642         cmdline_fixed_string_t ops;
10643         portid_t port_id;
10644         cmdline_fixed_string_t len;
10645         uint8_t len_value;
10646         cmdline_fixed_string_t bytes;
10647         cmdline_fixed_string_t bytes_value;
10648         cmdline_fixed_string_t mask;
10649         cmdline_fixed_string_t mask_value;
10650         cmdline_fixed_string_t priority;
10651         uint8_t priority_value;
10652         cmdline_fixed_string_t queue;
10653         uint16_t queue_id;
10654 };
10655
10656 static int xdigit2val(unsigned char c)
10657 {
10658         int val;
10659         if (isdigit(c))
10660                 val = c - '0';
10661         else if (isupper(c))
10662                 val = c - 'A' + 10;
10663         else
10664                 val = c - 'a' + 10;
10665         return val;
10666 }
10667
10668 static void
10669 cmd_flex_filter_parsed(void *parsed_result,
10670                           __rte_unused struct cmdline *cl,
10671                           __rte_unused void *data)
10672 {
10673         int ret = 0;
10674         struct rte_eth_flex_filter filter;
10675         struct cmd_flex_filter_result *res = parsed_result;
10676         char *bytes_ptr, *mask_ptr;
10677         uint16_t len, i, j = 0;
10678         char c;
10679         int val;
10680         uint8_t byte = 0;
10681
10682         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10683                 printf("the len exceed the max length 128\n");
10684                 return;
10685         }
10686         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10687         filter.len = res->len_value;
10688         filter.priority = res->priority_value;
10689         filter.queue = res->queue_id;
10690         bytes_ptr = res->bytes_value;
10691         mask_ptr = res->mask_value;
10692
10693          /* translate bytes string to array. */
10694         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10695                 (bytes_ptr[1] == 'X')))
10696                 bytes_ptr += 2;
10697         len = strnlen(bytes_ptr, res->len_value * 2);
10698         if (len == 0 || (len % 8 != 0)) {
10699                 printf("please check len and bytes input\n");
10700                 return;
10701         }
10702         for (i = 0; i < len; i++) {
10703                 c = bytes_ptr[i];
10704                 if (isxdigit(c) == 0) {
10705                         /* invalid characters. */
10706                         printf("invalid input\n");
10707                         return;
10708                 }
10709                 val = xdigit2val(c);
10710                 if (i % 2) {
10711                         byte |= val;
10712                         filter.bytes[j] = byte;
10713                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10714                         j++;
10715                         byte = 0;
10716                 } else
10717                         byte |= val << 4;
10718         }
10719         printf("\n");
10720          /* translate mask string to uint8_t array. */
10721         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10722                 (mask_ptr[1] == 'X')))
10723                 mask_ptr += 2;
10724         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10725         if (len == 0) {
10726                 printf("invalid input\n");
10727                 return;
10728         }
10729         j = 0;
10730         byte = 0;
10731         for (i = 0; i < len; i++) {
10732                 c = mask_ptr[i];
10733                 if (isxdigit(c) == 0) {
10734                         /* invalid characters. */
10735                         printf("invalid input\n");
10736                         return;
10737                 }
10738                 val = xdigit2val(c);
10739                 if (i % 2) {
10740                         byte |= val;
10741                         filter.mask[j] = byte;
10742                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10743                         j++;
10744                         byte = 0;
10745                 } else
10746                         byte |= val << 4;
10747         }
10748         printf("\n");
10749
10750         if (!strcmp(res->ops, "add"))
10751                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10752                                 RTE_ETH_FILTER_FLEXIBLE,
10753                                 RTE_ETH_FILTER_ADD,
10754                                 &filter);
10755         else
10756                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10757                                 RTE_ETH_FILTER_FLEXIBLE,
10758                                 RTE_ETH_FILTER_DELETE,
10759                                 &filter);
10760
10761         if (ret < 0)
10762                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10763 }
10764
10765 cmdline_parse_token_string_t cmd_flex_filter_filter =
10766         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10767                                 filter, "flex_filter");
10768 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10769         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10770                                 port_id, UINT16);
10771 cmdline_parse_token_string_t cmd_flex_filter_ops =
10772         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10773                                 ops, "add#del");
10774 cmdline_parse_token_string_t cmd_flex_filter_len =
10775         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10776                                 len, "len");
10777 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10778         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10779                                 len_value, UINT8);
10780 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10781         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10782                                 bytes, "bytes");
10783 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10784         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10785                                 bytes_value, NULL);
10786 cmdline_parse_token_string_t cmd_flex_filter_mask =
10787         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10788                                 mask, "mask");
10789 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10790         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10791                                 mask_value, NULL);
10792 cmdline_parse_token_string_t cmd_flex_filter_priority =
10793         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10794                                 priority, "priority");
10795 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10796         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10797                                 priority_value, UINT8);
10798 cmdline_parse_token_string_t cmd_flex_filter_queue =
10799         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10800                                 queue, "queue");
10801 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10802         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10803                                 queue_id, UINT16);
10804 cmdline_parse_inst_t cmd_flex_filter = {
10805         .f = cmd_flex_filter_parsed,
10806         .data = NULL,
10807         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10808                 "<value> mask <value> priority <value> queue <queue_id>: "
10809                 "Add/Del a flex filter",
10810         .tokens = {
10811                 (void *)&cmd_flex_filter_filter,
10812                 (void *)&cmd_flex_filter_port_id,
10813                 (void *)&cmd_flex_filter_ops,
10814                 (void *)&cmd_flex_filter_len,
10815                 (void *)&cmd_flex_filter_len_value,
10816                 (void *)&cmd_flex_filter_bytes,
10817                 (void *)&cmd_flex_filter_bytes_value,
10818                 (void *)&cmd_flex_filter_mask,
10819                 (void *)&cmd_flex_filter_mask_value,
10820                 (void *)&cmd_flex_filter_priority,
10821                 (void *)&cmd_flex_filter_priority_value,
10822                 (void *)&cmd_flex_filter_queue,
10823                 (void *)&cmd_flex_filter_queue_id,
10824                 NULL,
10825         },
10826 };
10827
10828 /* *** Filters Control *** */
10829
10830 /* *** deal with ethertype filter *** */
10831 struct cmd_ethertype_filter_result {
10832         cmdline_fixed_string_t filter;
10833         portid_t port_id;
10834         cmdline_fixed_string_t ops;
10835         cmdline_fixed_string_t mac;
10836         struct rte_ether_addr mac_addr;
10837         cmdline_fixed_string_t ethertype;
10838         uint16_t ethertype_value;
10839         cmdline_fixed_string_t drop;
10840         cmdline_fixed_string_t queue;
10841         uint16_t  queue_id;
10842 };
10843
10844 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10845         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10846                                  filter, "ethertype_filter");
10847 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10848         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10849                               port_id, UINT16);
10850 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10851         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10852                                  ops, "add#del");
10853 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10854         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10855                                  mac, "mac_addr#mac_ignr");
10856 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10857         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
10858                                      mac_addr);
10859 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
10860         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10861                                  ethertype, "ethertype");
10862 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
10863         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10864                               ethertype_value, UINT16);
10865 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
10866         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10867                                  drop, "drop#fwd");
10868 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
10869         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10870                                  queue, "queue");
10871 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
10872         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10873                               queue_id, UINT16);
10874
10875 static void
10876 cmd_ethertype_filter_parsed(void *parsed_result,
10877                           __rte_unused struct cmdline *cl,
10878                           __rte_unused void *data)
10879 {
10880         struct cmd_ethertype_filter_result *res = parsed_result;
10881         struct rte_eth_ethertype_filter filter;
10882         int ret = 0;
10883
10884         ret = rte_eth_dev_filter_supported(res->port_id,
10885                         RTE_ETH_FILTER_ETHERTYPE);
10886         if (ret < 0) {
10887                 printf("ethertype filter is not supported on port %u.\n",
10888                         res->port_id);
10889                 return;
10890         }
10891
10892         memset(&filter, 0, sizeof(filter));
10893         if (!strcmp(res->mac, "mac_addr")) {
10894                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
10895                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
10896                         sizeof(struct rte_ether_addr));
10897         }
10898         if (!strcmp(res->drop, "drop"))
10899                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
10900         filter.ether_type = res->ethertype_value;
10901         filter.queue = res->queue_id;
10902
10903         if (!strcmp(res->ops, "add"))
10904                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10905                                 RTE_ETH_FILTER_ETHERTYPE,
10906                                 RTE_ETH_FILTER_ADD,
10907                                 &filter);
10908         else
10909                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10910                                 RTE_ETH_FILTER_ETHERTYPE,
10911                                 RTE_ETH_FILTER_DELETE,
10912                                 &filter);
10913         if (ret < 0)
10914                 printf("ethertype filter programming error: (%s)\n",
10915                         strerror(-ret));
10916 }
10917
10918 cmdline_parse_inst_t cmd_ethertype_filter = {
10919         .f = cmd_ethertype_filter_parsed,
10920         .data = NULL,
10921         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
10922                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
10923                 "Add or delete an ethertype filter entry",
10924         .tokens = {
10925                 (void *)&cmd_ethertype_filter_filter,
10926                 (void *)&cmd_ethertype_filter_port_id,
10927                 (void *)&cmd_ethertype_filter_ops,
10928                 (void *)&cmd_ethertype_filter_mac,
10929                 (void *)&cmd_ethertype_filter_mac_addr,
10930                 (void *)&cmd_ethertype_filter_ethertype,
10931                 (void *)&cmd_ethertype_filter_ethertype_value,
10932                 (void *)&cmd_ethertype_filter_drop,
10933                 (void *)&cmd_ethertype_filter_queue,
10934                 (void *)&cmd_ethertype_filter_queue_id,
10935                 NULL,
10936         },
10937 };
10938
10939 /* *** deal with flow director filter *** */
10940 struct cmd_flow_director_result {
10941         cmdline_fixed_string_t flow_director_filter;
10942         portid_t port_id;
10943         cmdline_fixed_string_t mode;
10944         cmdline_fixed_string_t mode_value;
10945         cmdline_fixed_string_t ops;
10946         cmdline_fixed_string_t flow;
10947         cmdline_fixed_string_t flow_type;
10948         cmdline_fixed_string_t ether;
10949         uint16_t ether_type;
10950         cmdline_fixed_string_t src;
10951         cmdline_ipaddr_t ip_src;
10952         uint16_t port_src;
10953         cmdline_fixed_string_t dst;
10954         cmdline_ipaddr_t ip_dst;
10955         uint16_t port_dst;
10956         cmdline_fixed_string_t verify_tag;
10957         uint32_t verify_tag_value;
10958         cmdline_fixed_string_t tos;
10959         uint8_t tos_value;
10960         cmdline_fixed_string_t proto;
10961         uint8_t proto_value;
10962         cmdline_fixed_string_t ttl;
10963         uint8_t ttl_value;
10964         cmdline_fixed_string_t vlan;
10965         uint16_t vlan_value;
10966         cmdline_fixed_string_t flexbytes;
10967         cmdline_fixed_string_t flexbytes_value;
10968         cmdline_fixed_string_t pf_vf;
10969         cmdline_fixed_string_t drop;
10970         cmdline_fixed_string_t queue;
10971         uint16_t  queue_id;
10972         cmdline_fixed_string_t fd_id;
10973         uint32_t  fd_id_value;
10974         cmdline_fixed_string_t mac;
10975         struct rte_ether_addr mac_addr;
10976         cmdline_fixed_string_t tunnel;
10977         cmdline_fixed_string_t tunnel_type;
10978         cmdline_fixed_string_t tunnel_id;
10979         uint32_t tunnel_id_value;
10980         cmdline_fixed_string_t packet;
10981         char filepath[];
10982 };
10983
10984 static inline int
10985 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10986 {
10987         char s[256];
10988         const char *p, *p0 = q_arg;
10989         char *end;
10990         unsigned long int_fld;
10991         char *str_fld[max_num];
10992         int i;
10993         unsigned size;
10994         int ret = -1;
10995
10996         p = strchr(p0, '(');
10997         if (p == NULL)
10998                 return -1;
10999         ++p;
11000         p0 = strchr(p, ')');
11001         if (p0 == NULL)
11002                 return -1;
11003
11004         size = p0 - p;
11005         if (size >= sizeof(s))
11006                 return -1;
11007
11008         snprintf(s, sizeof(s), "%.*s", size, p);
11009         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11010         if (ret < 0 || ret > max_num)
11011                 return -1;
11012         for (i = 0; i < ret; i++) {
11013                 errno = 0;
11014                 int_fld = strtoul(str_fld[i], &end, 0);
11015                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11016                         return -1;
11017                 flexbytes[i] = (uint8_t)int_fld;
11018         }
11019         return ret;
11020 }
11021
11022 static uint16_t
11023 str2flowtype(char *string)
11024 {
11025         uint8_t i = 0;
11026         static const struct {
11027                 char str[32];
11028                 uint16_t type;
11029         } flowtype_str[] = {
11030                 {"raw", RTE_ETH_FLOW_RAW},
11031                 {"ipv4", RTE_ETH_FLOW_IPV4},
11032                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11033                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11034                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11035                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11036                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11037                 {"ipv6", RTE_ETH_FLOW_IPV6},
11038                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11039                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11040                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11041                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11042                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11043                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11044         };
11045
11046         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11047                 if (!strcmp(flowtype_str[i].str, string))
11048                         return flowtype_str[i].type;
11049         }
11050
11051         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11052                 return (uint16_t)atoi(string);
11053
11054         return RTE_ETH_FLOW_UNKNOWN;
11055 }
11056
11057 static enum rte_eth_fdir_tunnel_type
11058 str2fdir_tunneltype(char *string)
11059 {
11060         uint8_t i = 0;
11061
11062         static const struct {
11063                 char str[32];
11064                 enum rte_eth_fdir_tunnel_type type;
11065         } tunneltype_str[] = {
11066                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11067                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11068         };
11069
11070         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11071                 if (!strcmp(tunneltype_str[i].str, string))
11072                         return tunneltype_str[i].type;
11073         }
11074         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11075 }
11076
11077 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11078 do { \
11079         if ((ip_addr).family == AF_INET) \
11080                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11081         else { \
11082                 printf("invalid parameter.\n"); \
11083                 return; \
11084         } \
11085 } while (0)
11086
11087 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11088 do { \
11089         if ((ip_addr).family == AF_INET6) \
11090                 rte_memcpy(&(ip), \
11091                                  &((ip_addr).addr.ipv6), \
11092                                  sizeof(struct in6_addr)); \
11093         else { \
11094                 printf("invalid parameter.\n"); \
11095                 return; \
11096         } \
11097 } while (0)
11098
11099 static void
11100 cmd_flow_director_filter_parsed(void *parsed_result,
11101                           __rte_unused struct cmdline *cl,
11102                           __rte_unused void *data)
11103 {
11104         struct cmd_flow_director_result *res = parsed_result;
11105         struct rte_eth_fdir_filter entry;
11106         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11107         char *end;
11108         unsigned long vf_id;
11109         int ret = 0;
11110
11111         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11112         if (ret < 0) {
11113                 printf("flow director is not supported on port %u.\n",
11114                         res->port_id);
11115                 return;
11116         }
11117         memset(flexbytes, 0, sizeof(flexbytes));
11118         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11119
11120         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11121                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11122                         printf("Please set mode to MAC-VLAN.\n");
11123                         return;
11124                 }
11125         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11126                 if (strcmp(res->mode_value, "Tunnel")) {
11127                         printf("Please set mode to Tunnel.\n");
11128                         return;
11129                 }
11130         } else {
11131                 if (!strcmp(res->mode_value, "raw")) {
11132 #ifdef RTE_LIBRTE_I40E_PMD
11133                         struct rte_pmd_i40e_flow_type_mapping
11134                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11135                         struct rte_pmd_i40e_pkt_template_conf conf;
11136                         uint16_t flow_type = str2flowtype(res->flow_type);
11137                         uint16_t i, port = res->port_id;
11138                         uint8_t add;
11139
11140                         memset(&conf, 0, sizeof(conf));
11141
11142                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11143                                 printf("Invalid flow type specified.\n");
11144                                 return;
11145                         }
11146                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11147                                                                  mapping);
11148                         if (ret)
11149                                 return;
11150                         if (mapping[flow_type].pctype == 0ULL) {
11151                                 printf("Invalid flow type specified.\n");
11152                                 return;
11153                         }
11154                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11155                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11156                                         conf.input.pctype = i;
11157                                         break;
11158                                 }
11159                         }
11160
11161                         conf.input.packet = open_file(res->filepath,
11162                                                 &conf.input.length);
11163                         if (!conf.input.packet)
11164                                 return;
11165                         if (!strcmp(res->drop, "drop"))
11166                                 conf.action.behavior =
11167                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11168                         else
11169                                 conf.action.behavior =
11170                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11171                         conf.action.report_status =
11172                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11173                         conf.action.rx_queue = res->queue_id;
11174                         conf.soft_id = res->fd_id_value;
11175                         add  = strcmp(res->ops, "del") ? 1 : 0;
11176                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11177                                                                         &conf,
11178                                                                         add);
11179                         if (ret < 0)
11180                                 printf("flow director config error: (%s)\n",
11181                                        strerror(-ret));
11182                         close_file(conf.input.packet);
11183 #endif
11184                         return;
11185                 } else if (strcmp(res->mode_value, "IP")) {
11186                         printf("Please set mode to IP or raw.\n");
11187                         return;
11188                 }
11189                 entry.input.flow_type = str2flowtype(res->flow_type);
11190         }
11191
11192         ret = parse_flexbytes(res->flexbytes_value,
11193                                         flexbytes,
11194                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11195         if (ret < 0) {
11196                 printf("error: Cannot parse flexbytes input.\n");
11197                 return;
11198         }
11199
11200         switch (entry.input.flow_type) {
11201         case RTE_ETH_FLOW_FRAG_IPV4:
11202         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11203                 entry.input.flow.ip4_flow.proto = res->proto_value;
11204                 /* fall-through */
11205         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11206         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11207                 IPV4_ADDR_TO_UINT(res->ip_dst,
11208                         entry.input.flow.ip4_flow.dst_ip);
11209                 IPV4_ADDR_TO_UINT(res->ip_src,
11210                         entry.input.flow.ip4_flow.src_ip);
11211                 entry.input.flow.ip4_flow.tos = res->tos_value;
11212                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11213                 /* need convert to big endian. */
11214                 entry.input.flow.udp4_flow.dst_port =
11215                                 rte_cpu_to_be_16(res->port_dst);
11216                 entry.input.flow.udp4_flow.src_port =
11217                                 rte_cpu_to_be_16(res->port_src);
11218                 break;
11219         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11220                 IPV4_ADDR_TO_UINT(res->ip_dst,
11221                         entry.input.flow.sctp4_flow.ip.dst_ip);
11222                 IPV4_ADDR_TO_UINT(res->ip_src,
11223                         entry.input.flow.sctp4_flow.ip.src_ip);
11224                 entry.input.flow.ip4_flow.tos = res->tos_value;
11225                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11226                 /* need convert to big endian. */
11227                 entry.input.flow.sctp4_flow.dst_port =
11228                                 rte_cpu_to_be_16(res->port_dst);
11229                 entry.input.flow.sctp4_flow.src_port =
11230                                 rte_cpu_to_be_16(res->port_src);
11231                 entry.input.flow.sctp4_flow.verify_tag =
11232                                 rte_cpu_to_be_32(res->verify_tag_value);
11233                 break;
11234         case RTE_ETH_FLOW_FRAG_IPV6:
11235         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11236                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11237                 /* fall-through */
11238         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11239         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11240                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11241                         entry.input.flow.ipv6_flow.dst_ip);
11242                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11243                         entry.input.flow.ipv6_flow.src_ip);
11244                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11245                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11246                 /* need convert to big endian. */
11247                 entry.input.flow.udp6_flow.dst_port =
11248                                 rte_cpu_to_be_16(res->port_dst);
11249                 entry.input.flow.udp6_flow.src_port =
11250                                 rte_cpu_to_be_16(res->port_src);
11251                 break;
11252         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11253                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11254                         entry.input.flow.sctp6_flow.ip.dst_ip);
11255                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11256                         entry.input.flow.sctp6_flow.ip.src_ip);
11257                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11258                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11259                 /* need convert to big endian. */
11260                 entry.input.flow.sctp6_flow.dst_port =
11261                                 rte_cpu_to_be_16(res->port_dst);
11262                 entry.input.flow.sctp6_flow.src_port =
11263                                 rte_cpu_to_be_16(res->port_src);
11264                 entry.input.flow.sctp6_flow.verify_tag =
11265                                 rte_cpu_to_be_32(res->verify_tag_value);
11266                 break;
11267         case RTE_ETH_FLOW_L2_PAYLOAD:
11268                 entry.input.flow.l2_flow.ether_type =
11269                         rte_cpu_to_be_16(res->ether_type);
11270                 break;
11271         default:
11272                 break;
11273         }
11274
11275         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11276                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11277                                  &res->mac_addr,
11278                                  sizeof(struct rte_ether_addr));
11279
11280         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11281                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11282                                  &res->mac_addr,
11283                                  sizeof(struct rte_ether_addr));
11284                 entry.input.flow.tunnel_flow.tunnel_type =
11285                         str2fdir_tunneltype(res->tunnel_type);
11286                 entry.input.flow.tunnel_flow.tunnel_id =
11287                         rte_cpu_to_be_32(res->tunnel_id_value);
11288         }
11289
11290         rte_memcpy(entry.input.flow_ext.flexbytes,
11291                    flexbytes,
11292                    RTE_ETH_FDIR_MAX_FLEXLEN);
11293
11294         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11295
11296         entry.action.flex_off = 0;  /*use 0 by default */
11297         if (!strcmp(res->drop, "drop"))
11298                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11299         else
11300                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11301
11302         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11303             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11304                 if (!strcmp(res->pf_vf, "pf"))
11305                         entry.input.flow_ext.is_vf = 0;
11306                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11307                         struct rte_eth_dev_info dev_info;
11308
11309                         ret = eth_dev_info_get_print_err(res->port_id,
11310                                                 &dev_info);
11311                         if (ret != 0)
11312                                 return;
11313
11314                         errno = 0;
11315                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11316                         if (errno != 0 || *end != '\0' ||
11317                             vf_id >= dev_info.max_vfs) {
11318                                 printf("invalid parameter %s.\n", res->pf_vf);
11319                                 return;
11320                         }
11321                         entry.input.flow_ext.is_vf = 1;
11322                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11323                 } else {
11324                         printf("invalid parameter %s.\n", res->pf_vf);
11325                         return;
11326                 }
11327         }
11328
11329         /* set to report FD ID by default */
11330         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11331         entry.action.rx_queue = res->queue_id;
11332         entry.soft_id = res->fd_id_value;
11333         if (!strcmp(res->ops, "add"))
11334                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11335                                              RTE_ETH_FILTER_ADD, &entry);
11336         else if (!strcmp(res->ops, "del"))
11337                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11338                                              RTE_ETH_FILTER_DELETE, &entry);
11339         else
11340                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11341                                              RTE_ETH_FILTER_UPDATE, &entry);
11342         if (ret < 0)
11343                 printf("flow director programming error: (%s)\n",
11344                         strerror(-ret));
11345 }
11346
11347 cmdline_parse_token_string_t cmd_flow_director_filter =
11348         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11349                                  flow_director_filter, "flow_director_filter");
11350 cmdline_parse_token_num_t cmd_flow_director_port_id =
11351         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11352                               port_id, UINT16);
11353 cmdline_parse_token_string_t cmd_flow_director_ops =
11354         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11355                                  ops, "add#del#update");
11356 cmdline_parse_token_string_t cmd_flow_director_flow =
11357         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11358                                  flow, "flow");
11359 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11360         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11361                 flow_type, NULL);
11362 cmdline_parse_token_string_t cmd_flow_director_ether =
11363         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11364                                  ether, "ether");
11365 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11366         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11367                               ether_type, UINT16);
11368 cmdline_parse_token_string_t cmd_flow_director_src =
11369         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11370                                  src, "src");
11371 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11372         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11373                                  ip_src);
11374 cmdline_parse_token_num_t cmd_flow_director_port_src =
11375         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11376                               port_src, UINT16);
11377 cmdline_parse_token_string_t cmd_flow_director_dst =
11378         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11379                                  dst, "dst");
11380 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11381         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11382                                  ip_dst);
11383 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11384         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11385                               port_dst, UINT16);
11386 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11387         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11388                                   verify_tag, "verify_tag");
11389 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11390         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11391                               verify_tag_value, UINT32);
11392 cmdline_parse_token_string_t cmd_flow_director_tos =
11393         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11394                                  tos, "tos");
11395 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11396         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11397                               tos_value, UINT8);
11398 cmdline_parse_token_string_t cmd_flow_director_proto =
11399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11400                                  proto, "proto");
11401 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11402         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11403                               proto_value, UINT8);
11404 cmdline_parse_token_string_t cmd_flow_director_ttl =
11405         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11406                                  ttl, "ttl");
11407 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11408         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11409                               ttl_value, UINT8);
11410 cmdline_parse_token_string_t cmd_flow_director_vlan =
11411         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11412                                  vlan, "vlan");
11413 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11414         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11415                               vlan_value, UINT16);
11416 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11417         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11418                                  flexbytes, "flexbytes");
11419 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11420         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11421                               flexbytes_value, NULL);
11422 cmdline_parse_token_string_t cmd_flow_director_drop =
11423         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11424                                  drop, "drop#fwd");
11425 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11426         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11427                               pf_vf, NULL);
11428 cmdline_parse_token_string_t cmd_flow_director_queue =
11429         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11430                                  queue, "queue");
11431 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11432         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11433                               queue_id, UINT16);
11434 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11435         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11436                                  fd_id, "fd_id");
11437 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11438         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11439                               fd_id_value, UINT32);
11440
11441 cmdline_parse_token_string_t cmd_flow_director_mode =
11442         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11443                                  mode, "mode");
11444 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11445         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11446                                  mode_value, "IP");
11447 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11448         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11449                                  mode_value, "MAC-VLAN");
11450 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11451         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11452                                  mode_value, "Tunnel");
11453 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11455                                  mode_value, "raw");
11456 cmdline_parse_token_string_t cmd_flow_director_mac =
11457         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11458                                  mac, "mac");
11459 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11460         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11461                                     mac_addr);
11462 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11463         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11464                                  tunnel, "tunnel");
11465 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11466         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11467                                  tunnel_type, "NVGRE#VxLAN");
11468 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11469         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11470                                  tunnel_id, "tunnel-id");
11471 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11472         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11473                               tunnel_id_value, UINT32);
11474 cmdline_parse_token_string_t cmd_flow_director_packet =
11475         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11476                                  packet, "packet");
11477 cmdline_parse_token_string_t cmd_flow_director_filepath =
11478         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11479                                  filepath, NULL);
11480
11481 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11482         .f = cmd_flow_director_filter_parsed,
11483         .data = NULL,
11484         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11485                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11486                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11487                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11488                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11489                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11490                 "fd_id <fd_id_value>: "
11491                 "Add or delete an ip flow director entry on NIC",
11492         .tokens = {
11493                 (void *)&cmd_flow_director_filter,
11494                 (void *)&cmd_flow_director_port_id,
11495                 (void *)&cmd_flow_director_mode,
11496                 (void *)&cmd_flow_director_mode_ip,
11497                 (void *)&cmd_flow_director_ops,
11498                 (void *)&cmd_flow_director_flow,
11499                 (void *)&cmd_flow_director_flow_type,
11500                 (void *)&cmd_flow_director_src,
11501                 (void *)&cmd_flow_director_ip_src,
11502                 (void *)&cmd_flow_director_dst,
11503                 (void *)&cmd_flow_director_ip_dst,
11504                 (void *)&cmd_flow_director_tos,
11505                 (void *)&cmd_flow_director_tos_value,
11506                 (void *)&cmd_flow_director_proto,
11507                 (void *)&cmd_flow_director_proto_value,
11508                 (void *)&cmd_flow_director_ttl,
11509                 (void *)&cmd_flow_director_ttl_value,
11510                 (void *)&cmd_flow_director_vlan,
11511                 (void *)&cmd_flow_director_vlan_value,
11512                 (void *)&cmd_flow_director_flexbytes,
11513                 (void *)&cmd_flow_director_flexbytes_value,
11514                 (void *)&cmd_flow_director_drop,
11515                 (void *)&cmd_flow_director_pf_vf,
11516                 (void *)&cmd_flow_director_queue,
11517                 (void *)&cmd_flow_director_queue_id,
11518                 (void *)&cmd_flow_director_fd_id,
11519                 (void *)&cmd_flow_director_fd_id_value,
11520                 NULL,
11521         },
11522 };
11523
11524 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11525         .f = cmd_flow_director_filter_parsed,
11526         .data = NULL,
11527         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11528                 "director entry on NIC",
11529         .tokens = {
11530                 (void *)&cmd_flow_director_filter,
11531                 (void *)&cmd_flow_director_port_id,
11532                 (void *)&cmd_flow_director_mode,
11533                 (void *)&cmd_flow_director_mode_ip,
11534                 (void *)&cmd_flow_director_ops,
11535                 (void *)&cmd_flow_director_flow,
11536                 (void *)&cmd_flow_director_flow_type,
11537                 (void *)&cmd_flow_director_src,
11538                 (void *)&cmd_flow_director_ip_src,
11539                 (void *)&cmd_flow_director_port_src,
11540                 (void *)&cmd_flow_director_dst,
11541                 (void *)&cmd_flow_director_ip_dst,
11542                 (void *)&cmd_flow_director_port_dst,
11543                 (void *)&cmd_flow_director_tos,
11544                 (void *)&cmd_flow_director_tos_value,
11545                 (void *)&cmd_flow_director_ttl,
11546                 (void *)&cmd_flow_director_ttl_value,
11547                 (void *)&cmd_flow_director_vlan,
11548                 (void *)&cmd_flow_director_vlan_value,
11549                 (void *)&cmd_flow_director_flexbytes,
11550                 (void *)&cmd_flow_director_flexbytes_value,
11551                 (void *)&cmd_flow_director_drop,
11552                 (void *)&cmd_flow_director_pf_vf,
11553                 (void *)&cmd_flow_director_queue,
11554                 (void *)&cmd_flow_director_queue_id,
11555                 (void *)&cmd_flow_director_fd_id,
11556                 (void *)&cmd_flow_director_fd_id_value,
11557                 NULL,
11558         },
11559 };
11560
11561 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11562         .f = cmd_flow_director_filter_parsed,
11563         .data = NULL,
11564         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11565                 "director entry on NIC",
11566         .tokens = {
11567                 (void *)&cmd_flow_director_filter,
11568                 (void *)&cmd_flow_director_port_id,
11569                 (void *)&cmd_flow_director_mode,
11570                 (void *)&cmd_flow_director_mode_ip,
11571                 (void *)&cmd_flow_director_ops,
11572                 (void *)&cmd_flow_director_flow,
11573                 (void *)&cmd_flow_director_flow_type,
11574                 (void *)&cmd_flow_director_src,
11575                 (void *)&cmd_flow_director_ip_src,
11576                 (void *)&cmd_flow_director_port_src,
11577                 (void *)&cmd_flow_director_dst,
11578                 (void *)&cmd_flow_director_ip_dst,
11579                 (void *)&cmd_flow_director_port_dst,
11580                 (void *)&cmd_flow_director_verify_tag,
11581                 (void *)&cmd_flow_director_verify_tag_value,
11582                 (void *)&cmd_flow_director_tos,
11583                 (void *)&cmd_flow_director_tos_value,
11584                 (void *)&cmd_flow_director_ttl,
11585                 (void *)&cmd_flow_director_ttl_value,
11586                 (void *)&cmd_flow_director_vlan,
11587                 (void *)&cmd_flow_director_vlan_value,
11588                 (void *)&cmd_flow_director_flexbytes,
11589                 (void *)&cmd_flow_director_flexbytes_value,
11590                 (void *)&cmd_flow_director_drop,
11591                 (void *)&cmd_flow_director_pf_vf,
11592                 (void *)&cmd_flow_director_queue,
11593                 (void *)&cmd_flow_director_queue_id,
11594                 (void *)&cmd_flow_director_fd_id,
11595                 (void *)&cmd_flow_director_fd_id_value,
11596                 NULL,
11597         },
11598 };
11599
11600 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11601         .f = cmd_flow_director_filter_parsed,
11602         .data = NULL,
11603         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11604                 "director entry on NIC",
11605         .tokens = {
11606                 (void *)&cmd_flow_director_filter,
11607                 (void *)&cmd_flow_director_port_id,
11608                 (void *)&cmd_flow_director_mode,
11609                 (void *)&cmd_flow_director_mode_ip,
11610                 (void *)&cmd_flow_director_ops,
11611                 (void *)&cmd_flow_director_flow,
11612                 (void *)&cmd_flow_director_flow_type,
11613                 (void *)&cmd_flow_director_ether,
11614                 (void *)&cmd_flow_director_ether_type,
11615                 (void *)&cmd_flow_director_flexbytes,
11616                 (void *)&cmd_flow_director_flexbytes_value,
11617                 (void *)&cmd_flow_director_drop,
11618                 (void *)&cmd_flow_director_pf_vf,
11619                 (void *)&cmd_flow_director_queue,
11620                 (void *)&cmd_flow_director_queue_id,
11621                 (void *)&cmd_flow_director_fd_id,
11622                 (void *)&cmd_flow_director_fd_id_value,
11623                 NULL,
11624         },
11625 };
11626
11627 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11628         .f = cmd_flow_director_filter_parsed,
11629         .data = NULL,
11630         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11631                 "director entry on NIC",
11632         .tokens = {
11633                 (void *)&cmd_flow_director_filter,
11634                 (void *)&cmd_flow_director_port_id,
11635                 (void *)&cmd_flow_director_mode,
11636                 (void *)&cmd_flow_director_mode_mac_vlan,
11637                 (void *)&cmd_flow_director_ops,
11638                 (void *)&cmd_flow_director_mac,
11639                 (void *)&cmd_flow_director_mac_addr,
11640                 (void *)&cmd_flow_director_vlan,
11641                 (void *)&cmd_flow_director_vlan_value,
11642                 (void *)&cmd_flow_director_flexbytes,
11643                 (void *)&cmd_flow_director_flexbytes_value,
11644                 (void *)&cmd_flow_director_drop,
11645                 (void *)&cmd_flow_director_queue,
11646                 (void *)&cmd_flow_director_queue_id,
11647                 (void *)&cmd_flow_director_fd_id,
11648                 (void *)&cmd_flow_director_fd_id_value,
11649                 NULL,
11650         },
11651 };
11652
11653 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11654         .f = cmd_flow_director_filter_parsed,
11655         .data = NULL,
11656         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11657                 "director entry on NIC",
11658         .tokens = {
11659                 (void *)&cmd_flow_director_filter,
11660                 (void *)&cmd_flow_director_port_id,
11661                 (void *)&cmd_flow_director_mode,
11662                 (void *)&cmd_flow_director_mode_tunnel,
11663                 (void *)&cmd_flow_director_ops,
11664                 (void *)&cmd_flow_director_mac,
11665                 (void *)&cmd_flow_director_mac_addr,
11666                 (void *)&cmd_flow_director_vlan,
11667                 (void *)&cmd_flow_director_vlan_value,
11668                 (void *)&cmd_flow_director_tunnel,
11669                 (void *)&cmd_flow_director_tunnel_type,
11670                 (void *)&cmd_flow_director_tunnel_id,
11671                 (void *)&cmd_flow_director_tunnel_id_value,
11672                 (void *)&cmd_flow_director_flexbytes,
11673                 (void *)&cmd_flow_director_flexbytes_value,
11674                 (void *)&cmd_flow_director_drop,
11675                 (void *)&cmd_flow_director_queue,
11676                 (void *)&cmd_flow_director_queue_id,
11677                 (void *)&cmd_flow_director_fd_id,
11678                 (void *)&cmd_flow_director_fd_id_value,
11679                 NULL,
11680         },
11681 };
11682
11683 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11684         .f = cmd_flow_director_filter_parsed,
11685         .data = NULL,
11686         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11687                 "director entry on NIC",
11688         .tokens = {
11689                 (void *)&cmd_flow_director_filter,
11690                 (void *)&cmd_flow_director_port_id,
11691                 (void *)&cmd_flow_director_mode,
11692                 (void *)&cmd_flow_director_mode_raw,
11693                 (void *)&cmd_flow_director_ops,
11694                 (void *)&cmd_flow_director_flow,
11695                 (void *)&cmd_flow_director_flow_type,
11696                 (void *)&cmd_flow_director_drop,
11697                 (void *)&cmd_flow_director_queue,
11698                 (void *)&cmd_flow_director_queue_id,
11699                 (void *)&cmd_flow_director_fd_id,
11700                 (void *)&cmd_flow_director_fd_id_value,
11701                 (void *)&cmd_flow_director_packet,
11702                 (void *)&cmd_flow_director_filepath,
11703                 NULL,
11704         },
11705 };
11706
11707 struct cmd_flush_flow_director_result {
11708         cmdline_fixed_string_t flush_flow_director;
11709         portid_t port_id;
11710 };
11711
11712 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11713         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11714                                  flush_flow_director, "flush_flow_director");
11715 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11716         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11717                               port_id, UINT16);
11718
11719 static void
11720 cmd_flush_flow_director_parsed(void *parsed_result,
11721                           __rte_unused struct cmdline *cl,
11722                           __rte_unused void *data)
11723 {
11724         struct cmd_flow_director_result *res = parsed_result;
11725         int ret = 0;
11726
11727         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11728         if (ret < 0) {
11729                 printf("flow director is not supported on port %u.\n",
11730                         res->port_id);
11731                 return;
11732         }
11733
11734         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11735                         RTE_ETH_FILTER_FLUSH, NULL);
11736         if (ret < 0)
11737                 printf("flow director table flushing error: (%s)\n",
11738                         strerror(-ret));
11739 }
11740
11741 cmdline_parse_inst_t cmd_flush_flow_director = {
11742         .f = cmd_flush_flow_director_parsed,
11743         .data = NULL,
11744         .help_str = "flush_flow_director <port_id>: "
11745                 "Flush all flow director entries of a device on NIC",
11746         .tokens = {
11747                 (void *)&cmd_flush_flow_director_flush,
11748                 (void *)&cmd_flush_flow_director_port_id,
11749                 NULL,
11750         },
11751 };
11752
11753 /* *** deal with flow director mask *** */
11754 struct cmd_flow_director_mask_result {
11755         cmdline_fixed_string_t flow_director_mask;
11756         portid_t port_id;
11757         cmdline_fixed_string_t mode;
11758         cmdline_fixed_string_t mode_value;
11759         cmdline_fixed_string_t vlan;
11760         uint16_t vlan_mask;
11761         cmdline_fixed_string_t src_mask;
11762         cmdline_ipaddr_t ipv4_src;
11763         cmdline_ipaddr_t ipv6_src;
11764         uint16_t port_src;
11765         cmdline_fixed_string_t dst_mask;
11766         cmdline_ipaddr_t ipv4_dst;
11767         cmdline_ipaddr_t ipv6_dst;
11768         uint16_t port_dst;
11769         cmdline_fixed_string_t mac;
11770         uint8_t mac_addr_byte_mask;
11771         cmdline_fixed_string_t tunnel_id;
11772         uint32_t tunnel_id_mask;
11773         cmdline_fixed_string_t tunnel_type;
11774         uint8_t tunnel_type_mask;
11775 };
11776
11777 static void
11778 cmd_flow_director_mask_parsed(void *parsed_result,
11779                           __rte_unused struct cmdline *cl,
11780                           __rte_unused void *data)
11781 {
11782         struct cmd_flow_director_mask_result *res = parsed_result;
11783         struct rte_eth_fdir_masks *mask;
11784         struct rte_port *port;
11785
11786         port = &ports[res->port_id];
11787         /** Check if the port is not started **/
11788         if (port->port_status != RTE_PORT_STOPPED) {
11789                 printf("Please stop port %d first\n", res->port_id);
11790                 return;
11791         }
11792
11793         mask = &port->dev_conf.fdir_conf.mask;
11794
11795         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11796                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11797                         printf("Please set mode to MAC-VLAN.\n");
11798                         return;
11799                 }
11800
11801                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11802         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11803                 if (strcmp(res->mode_value, "Tunnel")) {
11804                         printf("Please set mode to Tunnel.\n");
11805                         return;
11806                 }
11807
11808                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11809                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11810                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11811                 mask->tunnel_type_mask = res->tunnel_type_mask;
11812         } else {
11813                 if (strcmp(res->mode_value, "IP")) {
11814                         printf("Please set mode to IP.\n");
11815                         return;
11816                 }
11817
11818                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11819                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11820                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11821                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11822                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11823                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11824                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11825         }
11826
11827         cmd_reconfig_device_queue(res->port_id, 1, 1);
11828 }
11829
11830 cmdline_parse_token_string_t cmd_flow_director_mask =
11831         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11832                                  flow_director_mask, "flow_director_mask");
11833 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11834         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11835                               port_id, UINT16);
11836 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11837         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11838                                  vlan, "vlan");
11839 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11840         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11841                               vlan_mask, UINT16);
11842 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11843         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11844                                  src_mask, "src_mask");
11845 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11846         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11847                                  ipv4_src);
11848 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11849         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11850                                  ipv6_src);
11851 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11852         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11853                               port_src, UINT16);
11854 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11855         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11856                                  dst_mask, "dst_mask");
11857 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11858         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11859                                  ipv4_dst);
11860 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11861         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11862                                  ipv6_dst);
11863 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11864         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11865                               port_dst, UINT16);
11866
11867 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11868         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11869                                  mode, "mode");
11870 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11871         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11872                                  mode_value, "IP");
11873 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11874         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11875                                  mode_value, "MAC-VLAN");
11876 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11877         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11878                                  mode_value, "Tunnel");
11879 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11880         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11881                                  mac, "mac");
11882 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11883         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11884                               mac_addr_byte_mask, UINT8);
11885 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11886         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11887                                  tunnel_type, "tunnel-type");
11888 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11889         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11890                               tunnel_type_mask, UINT8);
11891 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11892         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11893                                  tunnel_id, "tunnel-id");
11894 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11895         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11896                               tunnel_id_mask, UINT32);
11897
11898 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11899         .f = cmd_flow_director_mask_parsed,
11900         .data = NULL,
11901         .help_str = "flow_director_mask ... : "
11902                 "Set IP mode flow director's mask on NIC",
11903         .tokens = {
11904                 (void *)&cmd_flow_director_mask,
11905                 (void *)&cmd_flow_director_mask_port_id,
11906                 (void *)&cmd_flow_director_mask_mode,
11907                 (void *)&cmd_flow_director_mask_mode_ip,
11908                 (void *)&cmd_flow_director_mask_vlan,
11909                 (void *)&cmd_flow_director_mask_vlan_value,
11910                 (void *)&cmd_flow_director_mask_src,
11911                 (void *)&cmd_flow_director_mask_ipv4_src,
11912                 (void *)&cmd_flow_director_mask_ipv6_src,
11913                 (void *)&cmd_flow_director_mask_port_src,
11914                 (void *)&cmd_flow_director_mask_dst,
11915                 (void *)&cmd_flow_director_mask_ipv4_dst,
11916                 (void *)&cmd_flow_director_mask_ipv6_dst,
11917                 (void *)&cmd_flow_director_mask_port_dst,
11918                 NULL,
11919         },
11920 };
11921
11922 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11923         .f = cmd_flow_director_mask_parsed,
11924         .data = NULL,
11925         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11926                 "flow director's mask on NIC",
11927         .tokens = {
11928                 (void *)&cmd_flow_director_mask,
11929                 (void *)&cmd_flow_director_mask_port_id,
11930                 (void *)&cmd_flow_director_mask_mode,
11931                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11932                 (void *)&cmd_flow_director_mask_vlan,
11933                 (void *)&cmd_flow_director_mask_vlan_value,
11934                 NULL,
11935         },
11936 };
11937
11938 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11939         .f = cmd_flow_director_mask_parsed,
11940         .data = NULL,
11941         .help_str = "flow_director_mask ... : Set tunnel mode "
11942                 "flow director's mask on NIC",
11943         .tokens = {
11944                 (void *)&cmd_flow_director_mask,
11945                 (void *)&cmd_flow_director_mask_port_id,
11946                 (void *)&cmd_flow_director_mask_mode,
11947                 (void *)&cmd_flow_director_mask_mode_tunnel,
11948                 (void *)&cmd_flow_director_mask_vlan,
11949                 (void *)&cmd_flow_director_mask_vlan_value,
11950                 (void *)&cmd_flow_director_mask_mac,
11951                 (void *)&cmd_flow_director_mask_mac_value,
11952                 (void *)&cmd_flow_director_mask_tunnel_type,
11953                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11954                 (void *)&cmd_flow_director_mask_tunnel_id,
11955                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11956                 NULL,
11957         },
11958 };
11959
11960 /* *** deal with flow director mask on flexible payload *** */
11961 struct cmd_flow_director_flex_mask_result {
11962         cmdline_fixed_string_t flow_director_flexmask;
11963         portid_t port_id;
11964         cmdline_fixed_string_t flow;
11965         cmdline_fixed_string_t flow_type;
11966         cmdline_fixed_string_t mask;
11967 };
11968
11969 static void
11970 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11971                           __rte_unused struct cmdline *cl,
11972                           __rte_unused void *data)
11973 {
11974         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11975         struct rte_eth_fdir_info fdir_info;
11976         struct rte_eth_fdir_flex_mask flex_mask;
11977         struct rte_port *port;
11978         uint64_t flow_type_mask;
11979         uint16_t i;
11980         int ret;
11981
11982         port = &ports[res->port_id];
11983         /** Check if the port is not started **/
11984         if (port->port_status != RTE_PORT_STOPPED) {
11985                 printf("Please stop port %d first\n", res->port_id);
11986                 return;
11987         }
11988
11989         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11990         ret = parse_flexbytes(res->mask,
11991                         flex_mask.mask,
11992                         RTE_ETH_FDIR_MAX_FLEXLEN);
11993         if (ret < 0) {
11994                 printf("error: Cannot parse mask input.\n");
11995                 return;
11996         }
11997
11998         memset(&fdir_info, 0, sizeof(fdir_info));
11999         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12000                                 RTE_ETH_FILTER_INFO, &fdir_info);
12001         if (ret < 0) {
12002                 printf("Cannot get FDir filter info\n");
12003                 return;
12004         }
12005
12006         if (!strcmp(res->flow_type, "none")) {
12007                 /* means don't specify the flow type */
12008                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12009                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12010                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12011                                0, sizeof(struct rte_eth_fdir_flex_mask));
12012                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12013                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12014                                  &flex_mask,
12015                                  sizeof(struct rte_eth_fdir_flex_mask));
12016                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12017                 return;
12018         }
12019         flow_type_mask = fdir_info.flow_types_mask[0];
12020         if (!strcmp(res->flow_type, "all")) {
12021                 if (!flow_type_mask) {
12022                         printf("No flow type supported\n");
12023                         return;
12024                 }
12025                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12026                         if (flow_type_mask & (1ULL << i)) {
12027                                 flex_mask.flow_type = i;
12028                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12029                         }
12030                 }
12031                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12032                 return;
12033         }
12034         flex_mask.flow_type = str2flowtype(res->flow_type);
12035         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12036                 printf("Flow type %s not supported on port %d\n",
12037                                 res->flow_type, res->port_id);
12038                 return;
12039         }
12040         fdir_set_flex_mask(res->port_id, &flex_mask);
12041         cmd_reconfig_device_queue(res->port_id, 1, 1);
12042 }
12043
12044 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12045         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12046                                  flow_director_flexmask,
12047                                  "flow_director_flex_mask");
12048 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12049         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12050                               port_id, UINT16);
12051 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12052         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12053                                  flow, "flow");
12054 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12055         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12056                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12057                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12058 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12059         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12060                                  mask, NULL);
12061
12062 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12063         .f = cmd_flow_director_flex_mask_parsed,
12064         .data = NULL,
12065         .help_str = "flow_director_flex_mask ... : "
12066                 "Set flow director's flex mask on NIC",
12067         .tokens = {
12068                 (void *)&cmd_flow_director_flexmask,
12069                 (void *)&cmd_flow_director_flexmask_port_id,
12070                 (void *)&cmd_flow_director_flexmask_flow,
12071                 (void *)&cmd_flow_director_flexmask_flow_type,
12072                 (void *)&cmd_flow_director_flexmask_mask,
12073                 NULL,
12074         },
12075 };
12076
12077 /* *** deal with flow director flexible payload configuration *** */
12078 struct cmd_flow_director_flexpayload_result {
12079         cmdline_fixed_string_t flow_director_flexpayload;
12080         portid_t port_id;
12081         cmdline_fixed_string_t payload_layer;
12082         cmdline_fixed_string_t payload_cfg;
12083 };
12084
12085 static inline int
12086 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12087 {
12088         char s[256];
12089         const char *p, *p0 = q_arg;
12090         char *end;
12091         unsigned long int_fld;
12092         char *str_fld[max_num];
12093         int i;
12094         unsigned size;
12095         int ret = -1;
12096
12097         p = strchr(p0, '(');
12098         if (p == NULL)
12099                 return -1;
12100         ++p;
12101         p0 = strchr(p, ')');
12102         if (p0 == NULL)
12103                 return -1;
12104
12105         size = p0 - p;
12106         if (size >= sizeof(s))
12107                 return -1;
12108
12109         snprintf(s, sizeof(s), "%.*s", size, p);
12110         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12111         if (ret < 0 || ret > max_num)
12112                 return -1;
12113         for (i = 0; i < ret; i++) {
12114                 errno = 0;
12115                 int_fld = strtoul(str_fld[i], &end, 0);
12116                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12117                         return -1;
12118                 offsets[i] = (uint16_t)int_fld;
12119         }
12120         return ret;
12121 }
12122
12123 static void
12124 cmd_flow_director_flxpld_parsed(void *parsed_result,
12125                           __rte_unused struct cmdline *cl,
12126                           __rte_unused void *data)
12127 {
12128         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12129         struct rte_eth_flex_payload_cfg flex_cfg;
12130         struct rte_port *port;
12131         int ret = 0;
12132
12133         port = &ports[res->port_id];
12134         /** Check if the port is not started **/
12135         if (port->port_status != RTE_PORT_STOPPED) {
12136                 printf("Please stop port %d first\n", res->port_id);
12137                 return;
12138         }
12139
12140         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12141
12142         if (!strcmp(res->payload_layer, "raw"))
12143                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12144         else if (!strcmp(res->payload_layer, "l2"))
12145                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12146         else if (!strcmp(res->payload_layer, "l3"))
12147                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12148         else if (!strcmp(res->payload_layer, "l4"))
12149                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12150
12151         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12152                             RTE_ETH_FDIR_MAX_FLEXLEN);
12153         if (ret < 0) {
12154                 printf("error: Cannot parse flex payload input.\n");
12155                 return;
12156         }
12157
12158         fdir_set_flex_payload(res->port_id, &flex_cfg);
12159         cmd_reconfig_device_queue(res->port_id, 1, 1);
12160 }
12161
12162 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12163         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12164                                  flow_director_flexpayload,
12165                                  "flow_director_flex_payload");
12166 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12167         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12168                               port_id, UINT16);
12169 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12170         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12171                                  payload_layer, "raw#l2#l3#l4");
12172 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12173         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12174                                  payload_cfg, NULL);
12175
12176 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12177         .f = cmd_flow_director_flxpld_parsed,
12178         .data = NULL,
12179         .help_str = "flow_director_flexpayload ... : "
12180                 "Set flow director's flex payload on NIC",
12181         .tokens = {
12182                 (void *)&cmd_flow_director_flexpayload,
12183                 (void *)&cmd_flow_director_flexpayload_port_id,
12184                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12185                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12186                 NULL,
12187         },
12188 };
12189
12190 /* Generic flow interface command. */
12191 extern cmdline_parse_inst_t cmd_flow;
12192
12193 /* *** Classification Filters Control *** */
12194 /* *** Get symmetric hash enable per port *** */
12195 struct cmd_get_sym_hash_ena_per_port_result {
12196         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12197         portid_t port_id;
12198 };
12199
12200 static void
12201 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12202                                  __rte_unused struct cmdline *cl,
12203                                  __rte_unused void *data)
12204 {
12205         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12206         struct rte_eth_hash_filter_info info;
12207         int ret;
12208
12209         if (rte_eth_dev_filter_supported(res->port_id,
12210                                 RTE_ETH_FILTER_HASH) < 0) {
12211                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12212                                                         res->port_id);
12213                 return;
12214         }
12215
12216         memset(&info, 0, sizeof(info));
12217         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12218         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12219                                                 RTE_ETH_FILTER_GET, &info);
12220
12221         if (ret < 0) {
12222                 printf("Cannot get symmetric hash enable per port "
12223                                         "on port %u\n", res->port_id);
12224                 return;
12225         }
12226
12227         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12228                                 "enabled" : "disabled", res->port_id);
12229 }
12230
12231 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12232         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12233                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12234 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12235         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12236                 port_id, UINT16);
12237
12238 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12239         .f = cmd_get_sym_hash_per_port_parsed,
12240         .data = NULL,
12241         .help_str = "get_sym_hash_ena_per_port <port_id>",
12242         .tokens = {
12243                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12244                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12245                 NULL,
12246         },
12247 };
12248
12249 /* *** Set symmetric hash enable per port *** */
12250 struct cmd_set_sym_hash_ena_per_port_result {
12251         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12252         cmdline_fixed_string_t enable;
12253         portid_t port_id;
12254 };
12255
12256 static void
12257 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12258                                  __rte_unused struct cmdline *cl,
12259                                  __rte_unused void *data)
12260 {
12261         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12262         struct rte_eth_hash_filter_info info;
12263         int ret;
12264
12265         if (rte_eth_dev_filter_supported(res->port_id,
12266                                 RTE_ETH_FILTER_HASH) < 0) {
12267                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12268                                                         res->port_id);
12269                 return;
12270         }
12271
12272         memset(&info, 0, sizeof(info));
12273         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12274         if (!strcmp(res->enable, "enable"))
12275                 info.info.enable = 1;
12276         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12277                                         RTE_ETH_FILTER_SET, &info);
12278         if (ret < 0) {
12279                 printf("Cannot set symmetric hash enable per port on "
12280                                         "port %u\n", res->port_id);
12281                 return;
12282         }
12283         printf("Symmetric hash has been set to %s on port %u\n",
12284                                         res->enable, res->port_id);
12285 }
12286
12287 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12288         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12289                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12290 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12291         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12292                 port_id, UINT16);
12293 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12294         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12295                 enable, "enable#disable");
12296
12297 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12298         .f = cmd_set_sym_hash_per_port_parsed,
12299         .data = NULL,
12300         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12301         .tokens = {
12302                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12303                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12304                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12305                 NULL,
12306         },
12307 };
12308
12309 /* Get global config of hash function */
12310 struct cmd_get_hash_global_config_result {
12311         cmdline_fixed_string_t get_hash_global_config;
12312         portid_t port_id;
12313 };
12314
12315 static char *
12316 flowtype_to_str(uint16_t ftype)
12317 {
12318         uint16_t i;
12319         static struct {
12320                 char str[16];
12321                 uint16_t ftype;
12322         } ftype_table[] = {
12323                 {"ipv4", RTE_ETH_FLOW_IPV4},
12324                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12325                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12326                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12327                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12328                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12329                 {"ipv6", RTE_ETH_FLOW_IPV6},
12330                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12331                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12332                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12333                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12334                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12335                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12336                 {"port", RTE_ETH_FLOW_PORT},
12337                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12338                 {"geneve", RTE_ETH_FLOW_GENEVE},
12339                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12340                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12341         };
12342
12343         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12344                 if (ftype_table[i].ftype == ftype)
12345                         return ftype_table[i].str;
12346         }
12347
12348         return NULL;
12349 }
12350
12351 static void
12352 cmd_get_hash_global_config_parsed(void *parsed_result,
12353                                   __rte_unused struct cmdline *cl,
12354                                   __rte_unused void *data)
12355 {
12356         struct cmd_get_hash_global_config_result *res = parsed_result;
12357         struct rte_eth_hash_filter_info info;
12358         uint32_t idx, offset;
12359         uint16_t i;
12360         char *str;
12361         int ret;
12362
12363         if (rte_eth_dev_filter_supported(res->port_id,
12364                         RTE_ETH_FILTER_HASH) < 0) {
12365                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12366                                                         res->port_id);
12367                 return;
12368         }
12369
12370         memset(&info, 0, sizeof(info));
12371         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12372         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12373                                         RTE_ETH_FILTER_GET, &info);
12374         if (ret < 0) {
12375                 printf("Cannot get hash global configurations by port %d\n",
12376                                                         res->port_id);
12377                 return;
12378         }
12379
12380         switch (info.info.global_conf.hash_func) {
12381         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12382                 printf("Hash function is Toeplitz\n");
12383                 break;
12384         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12385                 printf("Hash function is Simple XOR\n");
12386                 break;
12387         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12388                 printf("Hash function is Symmetric Toeplitz\n");
12389                 break;
12390         default:
12391                 printf("Unknown hash function\n");
12392                 break;
12393         }
12394
12395         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12396                 idx = i / UINT64_BIT;
12397                 offset = i % UINT64_BIT;
12398                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12399                                                 (1ULL << offset)))
12400                         continue;
12401                 str = flowtype_to_str(i);
12402                 if (!str)
12403                         continue;
12404                 printf("Symmetric hash is %s globally for flow type %s "
12405                                                         "by port %d\n",
12406                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12407                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12408                                                         res->port_id);
12409         }
12410 }
12411
12412 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12413         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12414                 get_hash_global_config, "get_hash_global_config");
12415 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12416         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12417                 port_id, UINT16);
12418
12419 cmdline_parse_inst_t cmd_get_hash_global_config = {
12420         .f = cmd_get_hash_global_config_parsed,
12421         .data = NULL,
12422         .help_str = "get_hash_global_config <port_id>",
12423         .tokens = {
12424                 (void *)&cmd_get_hash_global_config_all,
12425                 (void *)&cmd_get_hash_global_config_port_id,
12426                 NULL,
12427         },
12428 };
12429
12430 /* Set global config of hash function */
12431 struct cmd_set_hash_global_config_result {
12432         cmdline_fixed_string_t set_hash_global_config;
12433         portid_t port_id;
12434         cmdline_fixed_string_t hash_func;
12435         cmdline_fixed_string_t flow_type;
12436         cmdline_fixed_string_t enable;
12437 };
12438
12439 static void
12440 cmd_set_hash_global_config_parsed(void *parsed_result,
12441                                   __rte_unused struct cmdline *cl,
12442                                   __rte_unused void *data)
12443 {
12444         struct cmd_set_hash_global_config_result *res = parsed_result;
12445         struct rte_eth_hash_filter_info info;
12446         uint32_t ftype, idx, offset;
12447         int ret;
12448
12449         if (rte_eth_dev_filter_supported(res->port_id,
12450                                 RTE_ETH_FILTER_HASH) < 0) {
12451                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12452                                                         res->port_id);
12453                 return;
12454         }
12455         memset(&info, 0, sizeof(info));
12456         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12457         if (!strcmp(res->hash_func, "toeplitz"))
12458                 info.info.global_conf.hash_func =
12459                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12460         else if (!strcmp(res->hash_func, "simple_xor"))
12461                 info.info.global_conf.hash_func =
12462                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12463         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12464                 info.info.global_conf.hash_func =
12465                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12466         else if (!strcmp(res->hash_func, "default"))
12467                 info.info.global_conf.hash_func =
12468                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12469
12470         ftype = str2flowtype(res->flow_type);
12471         idx = ftype / UINT64_BIT;
12472         offset = ftype % UINT64_BIT;
12473         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12474         if (!strcmp(res->enable, "enable"))
12475                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12476                                                 (1ULL << offset);
12477         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12478                                         RTE_ETH_FILTER_SET, &info);
12479         if (ret < 0)
12480                 printf("Cannot set global hash configurations by port %d\n",
12481                                                         res->port_id);
12482         else
12483                 printf("Global hash configurations have been set "
12484                         "successfully by port %d\n", res->port_id);
12485 }
12486
12487 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12488         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12489                 set_hash_global_config, "set_hash_global_config");
12490 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12491         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12492                 port_id, UINT16);
12493 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12494         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12495                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12496 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12497         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12498                 flow_type,
12499                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12500                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12501 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12502         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12503                 enable, "enable#disable");
12504
12505 cmdline_parse_inst_t cmd_set_hash_global_config = {
12506         .f = cmd_set_hash_global_config_parsed,
12507         .data = NULL,
12508         .help_str = "set_hash_global_config <port_id> "
12509                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12510                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12511                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12512                 "l2_payload enable|disable",
12513         .tokens = {
12514                 (void *)&cmd_set_hash_global_config_all,
12515                 (void *)&cmd_set_hash_global_config_port_id,
12516                 (void *)&cmd_set_hash_global_config_hash_func,
12517                 (void *)&cmd_set_hash_global_config_flow_type,
12518                 (void *)&cmd_set_hash_global_config_enable,
12519                 NULL,
12520         },
12521 };
12522
12523 /* Set hash input set */
12524 struct cmd_set_hash_input_set_result {
12525         cmdline_fixed_string_t set_hash_input_set;
12526         portid_t port_id;
12527         cmdline_fixed_string_t flow_type;
12528         cmdline_fixed_string_t inset_field;
12529         cmdline_fixed_string_t select;
12530 };
12531
12532 static enum rte_eth_input_set_field
12533 str2inset(char *string)
12534 {
12535         uint16_t i;
12536
12537         static const struct {
12538                 char str[32];
12539                 enum rte_eth_input_set_field inset;
12540         } inset_table[] = {
12541                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12542                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12543                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12544                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12545                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12546                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12547                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12548                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12549                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12550                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12551                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12552                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12553                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12554                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12555                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12556                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12557                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12558                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12559                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12560                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12561                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12562                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12563                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12564                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12565                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12566                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12567                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12568                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12569                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12570                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12571                 {"none", RTE_ETH_INPUT_SET_NONE},
12572         };
12573
12574         for (i = 0; i < RTE_DIM(inset_table); i++) {
12575                 if (!strcmp(string, inset_table[i].str))
12576                         return inset_table[i].inset;
12577         }
12578
12579         return RTE_ETH_INPUT_SET_UNKNOWN;
12580 }
12581
12582 static void
12583 cmd_set_hash_input_set_parsed(void *parsed_result,
12584                               __rte_unused struct cmdline *cl,
12585                               __rte_unused void *data)
12586 {
12587         struct cmd_set_hash_input_set_result *res = parsed_result;
12588         struct rte_eth_hash_filter_info info;
12589
12590         memset(&info, 0, sizeof(info));
12591         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12592         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12593         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12594         info.info.input_set_conf.inset_size = 1;
12595         if (!strcmp(res->select, "select"))
12596                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12597         else if (!strcmp(res->select, "add"))
12598                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12599         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12600                                 RTE_ETH_FILTER_SET, &info);
12601 }
12602
12603 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12604         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12605                 set_hash_input_set, "set_hash_input_set");
12606 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12607         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12608                 port_id, UINT16);
12609 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12610         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12611                 flow_type, NULL);
12612 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12613         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12614                 inset_field,
12615                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12616                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12617                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12618                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12619                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12620                 "fld-8th#none");
12621 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12622         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12623                 select, "select#add");
12624
12625 cmdline_parse_inst_t cmd_set_hash_input_set = {
12626         .f = cmd_set_hash_input_set_parsed,
12627         .data = NULL,
12628         .help_str = "set_hash_input_set <port_id> "
12629         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12630         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12631         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12632         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12633         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12634         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12635         "fld-7th|fld-8th|none select|add",
12636         .tokens = {
12637                 (void *)&cmd_set_hash_input_set_cmd,
12638                 (void *)&cmd_set_hash_input_set_port_id,
12639                 (void *)&cmd_set_hash_input_set_flow_type,
12640                 (void *)&cmd_set_hash_input_set_field,
12641                 (void *)&cmd_set_hash_input_set_select,
12642                 NULL,
12643         },
12644 };
12645
12646 /* Set flow director input set */
12647 struct cmd_set_fdir_input_set_result {
12648         cmdline_fixed_string_t set_fdir_input_set;
12649         portid_t port_id;
12650         cmdline_fixed_string_t flow_type;
12651         cmdline_fixed_string_t inset_field;
12652         cmdline_fixed_string_t select;
12653 };
12654
12655 static void
12656 cmd_set_fdir_input_set_parsed(void *parsed_result,
12657         __rte_unused struct cmdline *cl,
12658         __rte_unused void *data)
12659 {
12660         struct cmd_set_fdir_input_set_result *res = parsed_result;
12661         struct rte_eth_fdir_filter_info info;
12662
12663         memset(&info, 0, sizeof(info));
12664         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12665         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12666         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12667         info.info.input_set_conf.inset_size = 1;
12668         if (!strcmp(res->select, "select"))
12669                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12670         else if (!strcmp(res->select, "add"))
12671                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12672         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12673                 RTE_ETH_FILTER_SET, &info);
12674 }
12675
12676 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12677         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12678         set_fdir_input_set, "set_fdir_input_set");
12679 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12680         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12681         port_id, UINT16);
12682 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12683         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12684         flow_type,
12685         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12686         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12687 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12688         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12689         inset_field,
12690         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12691         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12692         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12693         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12694         "sctp-veri-tag#none");
12695 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12696         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12697         select, "select#add");
12698
12699 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12700         .f = cmd_set_fdir_input_set_parsed,
12701         .data = NULL,
12702         .help_str = "set_fdir_input_set <port_id> "
12703         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12704         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12705         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12706         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12707         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12708         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12709         "sctp-veri-tag|none select|add",
12710         .tokens = {
12711                 (void *)&cmd_set_fdir_input_set_cmd,
12712                 (void *)&cmd_set_fdir_input_set_port_id,
12713                 (void *)&cmd_set_fdir_input_set_flow_type,
12714                 (void *)&cmd_set_fdir_input_set_field,
12715                 (void *)&cmd_set_fdir_input_set_select,
12716                 NULL,
12717         },
12718 };
12719
12720 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12721 struct cmd_mcast_addr_result {
12722         cmdline_fixed_string_t mcast_addr_cmd;
12723         cmdline_fixed_string_t what;
12724         uint16_t port_num;
12725         struct rte_ether_addr mc_addr;
12726 };
12727
12728 static void cmd_mcast_addr_parsed(void *parsed_result,
12729                 __rte_unused struct cmdline *cl,
12730                 __rte_unused void *data)
12731 {
12732         struct cmd_mcast_addr_result *res = parsed_result;
12733
12734         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12735                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12736                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12737                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12738                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12739                 return;
12740         }
12741         if (strcmp(res->what, "add") == 0)
12742                 mcast_addr_add(res->port_num, &res->mc_addr);
12743         else
12744                 mcast_addr_remove(res->port_num, &res->mc_addr);
12745 }
12746
12747 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12748         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12749                                  mcast_addr_cmd, "mcast_addr");
12750 cmdline_parse_token_string_t cmd_mcast_addr_what =
12751         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12752                                  "add#remove");
12753 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12754         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12755 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12756         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12757
12758 cmdline_parse_inst_t cmd_mcast_addr = {
12759         .f = cmd_mcast_addr_parsed,
12760         .data = (void *)0,
12761         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12762                 "Add/Remove multicast MAC address on port_id",
12763         .tokens = {
12764                 (void *)&cmd_mcast_addr_cmd,
12765                 (void *)&cmd_mcast_addr_what,
12766                 (void *)&cmd_mcast_addr_portnum,
12767                 (void *)&cmd_mcast_addr_addr,
12768                 NULL,
12769         },
12770 };
12771
12772 /* l2 tunnel config
12773  * only support E-tag now.
12774  */
12775
12776 /* Ether type config */
12777 struct cmd_config_l2_tunnel_eth_type_result {
12778         cmdline_fixed_string_t port;
12779         cmdline_fixed_string_t config;
12780         cmdline_fixed_string_t all;
12781         portid_t id;
12782         cmdline_fixed_string_t l2_tunnel;
12783         cmdline_fixed_string_t l2_tunnel_type;
12784         cmdline_fixed_string_t eth_type;
12785         uint16_t eth_type_val;
12786 };
12787
12788 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_config_l2_tunnel_eth_type_result,
12791                  port, "port");
12792 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12793         TOKEN_STRING_INITIALIZER
12794                 (struct cmd_config_l2_tunnel_eth_type_result,
12795                  config, "config");
12796 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12797         TOKEN_STRING_INITIALIZER
12798                 (struct cmd_config_l2_tunnel_eth_type_result,
12799                  all, "all");
12800 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12801         TOKEN_NUM_INITIALIZER
12802                 (struct cmd_config_l2_tunnel_eth_type_result,
12803                  id, UINT16);
12804 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12805         TOKEN_STRING_INITIALIZER
12806                 (struct cmd_config_l2_tunnel_eth_type_result,
12807                  l2_tunnel, "l2-tunnel");
12808 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12809         TOKEN_STRING_INITIALIZER
12810                 (struct cmd_config_l2_tunnel_eth_type_result,
12811                  l2_tunnel_type, "E-tag");
12812 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12813         TOKEN_STRING_INITIALIZER
12814                 (struct cmd_config_l2_tunnel_eth_type_result,
12815                  eth_type, "ether-type");
12816 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12817         TOKEN_NUM_INITIALIZER
12818                 (struct cmd_config_l2_tunnel_eth_type_result,
12819                  eth_type_val, UINT16);
12820
12821 static enum rte_eth_tunnel_type
12822 str2fdir_l2_tunnel_type(char *string)
12823 {
12824         uint32_t i = 0;
12825
12826         static const struct {
12827                 char str[32];
12828                 enum rte_eth_tunnel_type type;
12829         } l2_tunnel_type_str[] = {
12830                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12831         };
12832
12833         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12834                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12835                         return l2_tunnel_type_str[i].type;
12836         }
12837         return RTE_TUNNEL_TYPE_NONE;
12838 }
12839
12840 /* ether type config for all ports */
12841 static void
12842 cmd_config_l2_tunnel_eth_type_all_parsed
12843         (void *parsed_result,
12844          __rte_unused struct cmdline *cl,
12845          __rte_unused void *data)
12846 {
12847         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12848         struct rte_eth_l2_tunnel_conf entry;
12849         portid_t pid;
12850
12851         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12852         entry.ether_type = res->eth_type_val;
12853
12854         RTE_ETH_FOREACH_DEV(pid) {
12855                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12856         }
12857 }
12858
12859 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
12860         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
12861         .data = NULL,
12862         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
12863         .tokens = {
12864                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12865                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12866                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
12867                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12868                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12869                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12870                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12871                 NULL,
12872         },
12873 };
12874
12875 /* ether type config for a specific port */
12876 static void
12877 cmd_config_l2_tunnel_eth_type_specific_parsed(
12878         void *parsed_result,
12879         __rte_unused struct cmdline *cl,
12880         __rte_unused void *data)
12881 {
12882         struct cmd_config_l2_tunnel_eth_type_result *res =
12883                  parsed_result;
12884         struct rte_eth_l2_tunnel_conf entry;
12885
12886         if (port_id_is_invalid(res->id, ENABLED_WARN))
12887                 return;
12888
12889         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12890         entry.ether_type = res->eth_type_val;
12891
12892         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
12893 }
12894
12895 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
12896         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
12897         .data = NULL,
12898         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
12899         .tokens = {
12900                 (void *)&cmd_config_l2_tunnel_eth_type_port,
12901                 (void *)&cmd_config_l2_tunnel_eth_type_config,
12902                 (void *)&cmd_config_l2_tunnel_eth_type_id,
12903                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
12904                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
12905                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
12906                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
12907                 NULL,
12908         },
12909 };
12910
12911 /* Enable/disable l2 tunnel */
12912 struct cmd_config_l2_tunnel_en_dis_result {
12913         cmdline_fixed_string_t port;
12914         cmdline_fixed_string_t config;
12915         cmdline_fixed_string_t all;
12916         portid_t id;
12917         cmdline_fixed_string_t l2_tunnel;
12918         cmdline_fixed_string_t l2_tunnel_type;
12919         cmdline_fixed_string_t en_dis;
12920 };
12921
12922 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
12923         TOKEN_STRING_INITIALIZER
12924                 (struct cmd_config_l2_tunnel_en_dis_result,
12925                  port, "port");
12926 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
12927         TOKEN_STRING_INITIALIZER
12928                 (struct cmd_config_l2_tunnel_en_dis_result,
12929                  config, "config");
12930 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
12931         TOKEN_STRING_INITIALIZER
12932                 (struct cmd_config_l2_tunnel_en_dis_result,
12933                  all, "all");
12934 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
12935         TOKEN_NUM_INITIALIZER
12936                 (struct cmd_config_l2_tunnel_en_dis_result,
12937                  id, UINT16);
12938 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
12939         TOKEN_STRING_INITIALIZER
12940                 (struct cmd_config_l2_tunnel_en_dis_result,
12941                  l2_tunnel, "l2-tunnel");
12942 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
12943         TOKEN_STRING_INITIALIZER
12944                 (struct cmd_config_l2_tunnel_en_dis_result,
12945                  l2_tunnel_type, "E-tag");
12946 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_config_l2_tunnel_en_dis_result,
12949                  en_dis, "enable#disable");
12950
12951 /* enable/disable l2 tunnel for all ports */
12952 static void
12953 cmd_config_l2_tunnel_en_dis_all_parsed(
12954         void *parsed_result,
12955         __rte_unused struct cmdline *cl,
12956         __rte_unused void *data)
12957 {
12958         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
12959         struct rte_eth_l2_tunnel_conf entry;
12960         portid_t pid;
12961         uint8_t en;
12962
12963         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12964
12965         if (!strcmp("enable", res->en_dis))
12966                 en = 1;
12967         else
12968                 en = 0;
12969
12970         RTE_ETH_FOREACH_DEV(pid) {
12971                 rte_eth_dev_l2_tunnel_offload_set(pid,
12972                                                   &entry,
12973                                                   ETH_L2_TUNNEL_ENABLE_MASK,
12974                                                   en);
12975         }
12976 }
12977
12978 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
12979         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
12980         .data = NULL,
12981         .help_str = "port config all l2-tunnel E-tag enable|disable",
12982         .tokens = {
12983                 (void *)&cmd_config_l2_tunnel_en_dis_port,
12984                 (void *)&cmd_config_l2_tunnel_en_dis_config,
12985                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
12986                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
12987                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
12988                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
12989                 NULL,
12990         },
12991 };
12992
12993 /* enable/disable l2 tunnel for a port */
12994 static void
12995 cmd_config_l2_tunnel_en_dis_specific_parsed(
12996         void *parsed_result,
12997         __rte_unused struct cmdline *cl,
12998         __rte_unused void *data)
12999 {
13000         struct cmd_config_l2_tunnel_en_dis_result *res =
13001                 parsed_result;
13002         struct rte_eth_l2_tunnel_conf entry;
13003
13004         if (port_id_is_invalid(res->id, ENABLED_WARN))
13005                 return;
13006
13007         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13008
13009         if (!strcmp("enable", res->en_dis))
13010                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13011                                                   &entry,
13012                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13013                                                   1);
13014         else
13015                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13016                                                   &entry,
13017                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13018                                                   0);
13019 }
13020
13021 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13022         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13023         .data = NULL,
13024         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13025         .tokens = {
13026                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13027                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13028                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13029                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13030                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13031                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13032                 NULL,
13033         },
13034 };
13035
13036 /* E-tag configuration */
13037
13038 /* Common result structure for all E-tag configuration */
13039 struct cmd_config_e_tag_result {
13040         cmdline_fixed_string_t e_tag;
13041         cmdline_fixed_string_t set;
13042         cmdline_fixed_string_t insertion;
13043         cmdline_fixed_string_t stripping;
13044         cmdline_fixed_string_t forwarding;
13045         cmdline_fixed_string_t filter;
13046         cmdline_fixed_string_t add;
13047         cmdline_fixed_string_t del;
13048         cmdline_fixed_string_t on;
13049         cmdline_fixed_string_t off;
13050         cmdline_fixed_string_t on_off;
13051         cmdline_fixed_string_t port_tag_id;
13052         uint32_t port_tag_id_val;
13053         cmdline_fixed_string_t e_tag_id;
13054         uint16_t e_tag_id_val;
13055         cmdline_fixed_string_t dst_pool;
13056         uint8_t dst_pool_val;
13057         cmdline_fixed_string_t port;
13058         portid_t port_id;
13059         cmdline_fixed_string_t vf;
13060         uint8_t vf_id;
13061 };
13062
13063 /* Common CLI fields for all E-tag configuration */
13064 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13065         TOKEN_STRING_INITIALIZER
13066                 (struct cmd_config_e_tag_result,
13067                  e_tag, "E-tag");
13068 cmdline_parse_token_string_t cmd_config_e_tag_set =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_config_e_tag_result,
13071                  set, "set");
13072 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13073         TOKEN_STRING_INITIALIZER
13074                 (struct cmd_config_e_tag_result,
13075                  insertion, "insertion");
13076 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13077         TOKEN_STRING_INITIALIZER
13078                 (struct cmd_config_e_tag_result,
13079                  stripping, "stripping");
13080 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13081         TOKEN_STRING_INITIALIZER
13082                 (struct cmd_config_e_tag_result,
13083                  forwarding, "forwarding");
13084 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_config_e_tag_result,
13087                  filter, "filter");
13088 cmdline_parse_token_string_t cmd_config_e_tag_add =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_config_e_tag_result,
13091                  add, "add");
13092 cmdline_parse_token_string_t cmd_config_e_tag_del =
13093         TOKEN_STRING_INITIALIZER
13094                 (struct cmd_config_e_tag_result,
13095                  del, "del");
13096 cmdline_parse_token_string_t cmd_config_e_tag_on =
13097         TOKEN_STRING_INITIALIZER
13098                 (struct cmd_config_e_tag_result,
13099                  on, "on");
13100 cmdline_parse_token_string_t cmd_config_e_tag_off =
13101         TOKEN_STRING_INITIALIZER
13102                 (struct cmd_config_e_tag_result,
13103                  off, "off");
13104 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13105         TOKEN_STRING_INITIALIZER
13106                 (struct cmd_config_e_tag_result,
13107                  on_off, "on#off");
13108 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13109         TOKEN_STRING_INITIALIZER
13110                 (struct cmd_config_e_tag_result,
13111                  port_tag_id, "port-tag-id");
13112 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13113         TOKEN_NUM_INITIALIZER
13114                 (struct cmd_config_e_tag_result,
13115                  port_tag_id_val, UINT32);
13116 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13117         TOKEN_STRING_INITIALIZER
13118                 (struct cmd_config_e_tag_result,
13119                  e_tag_id, "e-tag-id");
13120 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13121         TOKEN_NUM_INITIALIZER
13122                 (struct cmd_config_e_tag_result,
13123                  e_tag_id_val, UINT16);
13124 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13125         TOKEN_STRING_INITIALIZER
13126                 (struct cmd_config_e_tag_result,
13127                  dst_pool, "dst-pool");
13128 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13129         TOKEN_NUM_INITIALIZER
13130                 (struct cmd_config_e_tag_result,
13131                  dst_pool_val, UINT8);
13132 cmdline_parse_token_string_t cmd_config_e_tag_port =
13133         TOKEN_STRING_INITIALIZER
13134                 (struct cmd_config_e_tag_result,
13135                  port, "port");
13136 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13137         TOKEN_NUM_INITIALIZER
13138                 (struct cmd_config_e_tag_result,
13139                  port_id, UINT16);
13140 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13141         TOKEN_STRING_INITIALIZER
13142                 (struct cmd_config_e_tag_result,
13143                  vf, "vf");
13144 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13145         TOKEN_NUM_INITIALIZER
13146                 (struct cmd_config_e_tag_result,
13147                  vf_id, UINT8);
13148
13149 /* E-tag insertion configuration */
13150 static void
13151 cmd_config_e_tag_insertion_en_parsed(
13152         void *parsed_result,
13153         __rte_unused struct cmdline *cl,
13154         __rte_unused void *data)
13155 {
13156         struct cmd_config_e_tag_result *res =
13157                 parsed_result;
13158         struct rte_eth_l2_tunnel_conf entry;
13159
13160         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13161                 return;
13162
13163         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13164         entry.tunnel_id = res->port_tag_id_val;
13165         entry.vf_id = res->vf_id;
13166         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13167                                           &entry,
13168                                           ETH_L2_TUNNEL_INSERTION_MASK,
13169                                           1);
13170 }
13171
13172 static void
13173 cmd_config_e_tag_insertion_dis_parsed(
13174         void *parsed_result,
13175         __rte_unused struct cmdline *cl,
13176         __rte_unused void *data)
13177 {
13178         struct cmd_config_e_tag_result *res =
13179                 parsed_result;
13180         struct rte_eth_l2_tunnel_conf entry;
13181
13182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13183                 return;
13184
13185         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13186         entry.vf_id = res->vf_id;
13187
13188         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13189                                           &entry,
13190                                           ETH_L2_TUNNEL_INSERTION_MASK,
13191                                           0);
13192 }
13193
13194 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13195         .f = cmd_config_e_tag_insertion_en_parsed,
13196         .data = NULL,
13197         .help_str = "E-tag ... : E-tag insertion enable",
13198         .tokens = {
13199                 (void *)&cmd_config_e_tag_e_tag,
13200                 (void *)&cmd_config_e_tag_set,
13201                 (void *)&cmd_config_e_tag_insertion,
13202                 (void *)&cmd_config_e_tag_on,
13203                 (void *)&cmd_config_e_tag_port_tag_id,
13204                 (void *)&cmd_config_e_tag_port_tag_id_val,
13205                 (void *)&cmd_config_e_tag_port,
13206                 (void *)&cmd_config_e_tag_port_id,
13207                 (void *)&cmd_config_e_tag_vf,
13208                 (void *)&cmd_config_e_tag_vf_id,
13209                 NULL,
13210         },
13211 };
13212
13213 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13214         .f = cmd_config_e_tag_insertion_dis_parsed,
13215         .data = NULL,
13216         .help_str = "E-tag ... : E-tag insertion disable",
13217         .tokens = {
13218                 (void *)&cmd_config_e_tag_e_tag,
13219                 (void *)&cmd_config_e_tag_set,
13220                 (void *)&cmd_config_e_tag_insertion,
13221                 (void *)&cmd_config_e_tag_off,
13222                 (void *)&cmd_config_e_tag_port,
13223                 (void *)&cmd_config_e_tag_port_id,
13224                 (void *)&cmd_config_e_tag_vf,
13225                 (void *)&cmd_config_e_tag_vf_id,
13226                 NULL,
13227         },
13228 };
13229
13230 /* E-tag stripping configuration */
13231 static void
13232 cmd_config_e_tag_stripping_parsed(
13233         void *parsed_result,
13234         __rte_unused struct cmdline *cl,
13235         __rte_unused void *data)
13236 {
13237         struct cmd_config_e_tag_result *res =
13238                 parsed_result;
13239         struct rte_eth_l2_tunnel_conf entry;
13240
13241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13242                 return;
13243
13244         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13245
13246         if (!strcmp(res->on_off, "on"))
13247                 rte_eth_dev_l2_tunnel_offload_set
13248                         (res->port_id,
13249                          &entry,
13250                          ETH_L2_TUNNEL_STRIPPING_MASK,
13251                          1);
13252         else
13253                 rte_eth_dev_l2_tunnel_offload_set
13254                         (res->port_id,
13255                          &entry,
13256                          ETH_L2_TUNNEL_STRIPPING_MASK,
13257                          0);
13258 }
13259
13260 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13261         .f = cmd_config_e_tag_stripping_parsed,
13262         .data = NULL,
13263         .help_str = "E-tag ... : E-tag stripping enable/disable",
13264         .tokens = {
13265                 (void *)&cmd_config_e_tag_e_tag,
13266                 (void *)&cmd_config_e_tag_set,
13267                 (void *)&cmd_config_e_tag_stripping,
13268                 (void *)&cmd_config_e_tag_on_off,
13269                 (void *)&cmd_config_e_tag_port,
13270                 (void *)&cmd_config_e_tag_port_id,
13271                 NULL,
13272         },
13273 };
13274
13275 /* E-tag forwarding configuration */
13276 static void
13277 cmd_config_e_tag_forwarding_parsed(
13278         void *parsed_result,
13279         __rte_unused struct cmdline *cl,
13280         __rte_unused void *data)
13281 {
13282         struct cmd_config_e_tag_result *res = parsed_result;
13283         struct rte_eth_l2_tunnel_conf entry;
13284
13285         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13286                 return;
13287
13288         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13289
13290         if (!strcmp(res->on_off, "on"))
13291                 rte_eth_dev_l2_tunnel_offload_set
13292                         (res->port_id,
13293                          &entry,
13294                          ETH_L2_TUNNEL_FORWARDING_MASK,
13295                          1);
13296         else
13297                 rte_eth_dev_l2_tunnel_offload_set
13298                         (res->port_id,
13299                          &entry,
13300                          ETH_L2_TUNNEL_FORWARDING_MASK,
13301                          0);
13302 }
13303
13304 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13305         .f = cmd_config_e_tag_forwarding_parsed,
13306         .data = NULL,
13307         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13308         .tokens = {
13309                 (void *)&cmd_config_e_tag_e_tag,
13310                 (void *)&cmd_config_e_tag_set,
13311                 (void *)&cmd_config_e_tag_forwarding,
13312                 (void *)&cmd_config_e_tag_on_off,
13313                 (void *)&cmd_config_e_tag_port,
13314                 (void *)&cmd_config_e_tag_port_id,
13315                 NULL,
13316         },
13317 };
13318
13319 /* E-tag filter configuration */
13320 static void
13321 cmd_config_e_tag_filter_add_parsed(
13322         void *parsed_result,
13323         __rte_unused struct cmdline *cl,
13324         __rte_unused void *data)
13325 {
13326         struct cmd_config_e_tag_result *res = parsed_result;
13327         struct rte_eth_l2_tunnel_conf entry;
13328         int ret = 0;
13329
13330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13331                 return;
13332
13333         if (res->e_tag_id_val > 0x3fff) {
13334                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13335                 return;
13336         }
13337
13338         ret = rte_eth_dev_filter_supported(res->port_id,
13339                                            RTE_ETH_FILTER_L2_TUNNEL);
13340         if (ret < 0) {
13341                 printf("E-tag filter is not supported on port %u.\n",
13342                        res->port_id);
13343                 return;
13344         }
13345
13346         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13347         entry.tunnel_id = res->e_tag_id_val;
13348         entry.pool = res->dst_pool_val;
13349
13350         ret = rte_eth_dev_filter_ctrl(res->port_id,
13351                                       RTE_ETH_FILTER_L2_TUNNEL,
13352                                       RTE_ETH_FILTER_ADD,
13353                                       &entry);
13354         if (ret < 0)
13355                 printf("E-tag filter programming error: (%s)\n",
13356                        strerror(-ret));
13357 }
13358
13359 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13360         .f = cmd_config_e_tag_filter_add_parsed,
13361         .data = NULL,
13362         .help_str = "E-tag ... : E-tag filter add",
13363         .tokens = {
13364                 (void *)&cmd_config_e_tag_e_tag,
13365                 (void *)&cmd_config_e_tag_set,
13366                 (void *)&cmd_config_e_tag_filter,
13367                 (void *)&cmd_config_e_tag_add,
13368                 (void *)&cmd_config_e_tag_e_tag_id,
13369                 (void *)&cmd_config_e_tag_e_tag_id_val,
13370                 (void *)&cmd_config_e_tag_dst_pool,
13371                 (void *)&cmd_config_e_tag_dst_pool_val,
13372                 (void *)&cmd_config_e_tag_port,
13373                 (void *)&cmd_config_e_tag_port_id,
13374                 NULL,
13375         },
13376 };
13377
13378 static void
13379 cmd_config_e_tag_filter_del_parsed(
13380         void *parsed_result,
13381         __rte_unused struct cmdline *cl,
13382         __rte_unused void *data)
13383 {
13384         struct cmd_config_e_tag_result *res = parsed_result;
13385         struct rte_eth_l2_tunnel_conf entry;
13386         int ret = 0;
13387
13388         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13389                 return;
13390
13391         if (res->e_tag_id_val > 0x3fff) {
13392                 printf("e-tag-id must be less than 0x3fff.\n");
13393                 return;
13394         }
13395
13396         ret = rte_eth_dev_filter_supported(res->port_id,
13397                                            RTE_ETH_FILTER_L2_TUNNEL);
13398         if (ret < 0) {
13399                 printf("E-tag filter is not supported on port %u.\n",
13400                        res->port_id);
13401                 return;
13402         }
13403
13404         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13405         entry.tunnel_id = res->e_tag_id_val;
13406
13407         ret = rte_eth_dev_filter_ctrl(res->port_id,
13408                                       RTE_ETH_FILTER_L2_TUNNEL,
13409                                       RTE_ETH_FILTER_DELETE,
13410                                       &entry);
13411         if (ret < 0)
13412                 printf("E-tag filter programming error: (%s)\n",
13413                        strerror(-ret));
13414 }
13415
13416 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13417         .f = cmd_config_e_tag_filter_del_parsed,
13418         .data = NULL,
13419         .help_str = "E-tag ... : E-tag filter delete",
13420         .tokens = {
13421                 (void *)&cmd_config_e_tag_e_tag,
13422                 (void *)&cmd_config_e_tag_set,
13423                 (void *)&cmd_config_e_tag_filter,
13424                 (void *)&cmd_config_e_tag_del,
13425                 (void *)&cmd_config_e_tag_e_tag_id,
13426                 (void *)&cmd_config_e_tag_e_tag_id_val,
13427                 (void *)&cmd_config_e_tag_port,
13428                 (void *)&cmd_config_e_tag_port_id,
13429                 NULL,
13430         },
13431 };
13432
13433 /* vf vlan anti spoof configuration */
13434
13435 /* Common result structure for vf vlan anti spoof */
13436 struct cmd_vf_vlan_anti_spoof_result {
13437         cmdline_fixed_string_t set;
13438         cmdline_fixed_string_t vf;
13439         cmdline_fixed_string_t vlan;
13440         cmdline_fixed_string_t antispoof;
13441         portid_t port_id;
13442         uint32_t vf_id;
13443         cmdline_fixed_string_t on_off;
13444 };
13445
13446 /* Common CLI fields for vf vlan anti spoof enable disable */
13447 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13448         TOKEN_STRING_INITIALIZER
13449                 (struct cmd_vf_vlan_anti_spoof_result,
13450                  set, "set");
13451 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13452         TOKEN_STRING_INITIALIZER
13453                 (struct cmd_vf_vlan_anti_spoof_result,
13454                  vf, "vf");
13455 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_vf_vlan_anti_spoof_result,
13458                  vlan, "vlan");
13459 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_vf_vlan_anti_spoof_result,
13462                  antispoof, "antispoof");
13463 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13464         TOKEN_NUM_INITIALIZER
13465                 (struct cmd_vf_vlan_anti_spoof_result,
13466                  port_id, UINT16);
13467 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13468         TOKEN_NUM_INITIALIZER
13469                 (struct cmd_vf_vlan_anti_spoof_result,
13470                  vf_id, UINT32);
13471 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13472         TOKEN_STRING_INITIALIZER
13473                 (struct cmd_vf_vlan_anti_spoof_result,
13474                  on_off, "on#off");
13475
13476 static void
13477 cmd_set_vf_vlan_anti_spoof_parsed(
13478         void *parsed_result,
13479         __rte_unused struct cmdline *cl,
13480         __rte_unused void *data)
13481 {
13482         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13483         int ret = -ENOTSUP;
13484
13485         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13486
13487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13488                 return;
13489
13490 #ifdef RTE_LIBRTE_IXGBE_PMD
13491         if (ret == -ENOTSUP)
13492                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13493                                 res->vf_id, is_on);
13494 #endif
13495 #ifdef RTE_LIBRTE_I40E_PMD
13496         if (ret == -ENOTSUP)
13497                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13498                                 res->vf_id, is_on);
13499 #endif
13500 #ifdef RTE_LIBRTE_BNXT_PMD
13501         if (ret == -ENOTSUP)
13502                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13503                                 res->vf_id, is_on);
13504 #endif
13505
13506         switch (ret) {
13507         case 0:
13508                 break;
13509         case -EINVAL:
13510                 printf("invalid vf_id %d\n", res->vf_id);
13511                 break;
13512         case -ENODEV:
13513                 printf("invalid port_id %d\n", res->port_id);
13514                 break;
13515         case -ENOTSUP:
13516                 printf("function not implemented\n");
13517                 break;
13518         default:
13519                 printf("programming error: (%s)\n", strerror(-ret));
13520         }
13521 }
13522
13523 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13524         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13525         .data = NULL,
13526         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13527         .tokens = {
13528                 (void *)&cmd_vf_vlan_anti_spoof_set,
13529                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13530                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13531                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13532                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13533                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13534                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13535                 NULL,
13536         },
13537 };
13538
13539 /* vf mac anti spoof configuration */
13540
13541 /* Common result structure for vf mac anti spoof */
13542 struct cmd_vf_mac_anti_spoof_result {
13543         cmdline_fixed_string_t set;
13544         cmdline_fixed_string_t vf;
13545         cmdline_fixed_string_t mac;
13546         cmdline_fixed_string_t antispoof;
13547         portid_t port_id;
13548         uint32_t vf_id;
13549         cmdline_fixed_string_t on_off;
13550 };
13551
13552 /* Common CLI fields for vf mac anti spoof enable disable */
13553 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_vf_mac_anti_spoof_result,
13556                  set, "set");
13557 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_vf_mac_anti_spoof_result,
13560                  vf, "vf");
13561 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13562         TOKEN_STRING_INITIALIZER
13563                 (struct cmd_vf_mac_anti_spoof_result,
13564                  mac, "mac");
13565 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13566         TOKEN_STRING_INITIALIZER
13567                 (struct cmd_vf_mac_anti_spoof_result,
13568                  antispoof, "antispoof");
13569 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13570         TOKEN_NUM_INITIALIZER
13571                 (struct cmd_vf_mac_anti_spoof_result,
13572                  port_id, UINT16);
13573 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13574         TOKEN_NUM_INITIALIZER
13575                 (struct cmd_vf_mac_anti_spoof_result,
13576                  vf_id, UINT32);
13577 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13578         TOKEN_STRING_INITIALIZER
13579                 (struct cmd_vf_mac_anti_spoof_result,
13580                  on_off, "on#off");
13581
13582 static void
13583 cmd_set_vf_mac_anti_spoof_parsed(
13584         void *parsed_result,
13585         __rte_unused struct cmdline *cl,
13586         __rte_unused void *data)
13587 {
13588         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13589         int ret = -ENOTSUP;
13590
13591         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13592
13593         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13594                 return;
13595
13596 #ifdef RTE_LIBRTE_IXGBE_PMD
13597         if (ret == -ENOTSUP)
13598                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13599                         res->vf_id, is_on);
13600 #endif
13601 #ifdef RTE_LIBRTE_I40E_PMD
13602         if (ret == -ENOTSUP)
13603                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13604                         res->vf_id, is_on);
13605 #endif
13606 #ifdef RTE_LIBRTE_BNXT_PMD
13607         if (ret == -ENOTSUP)
13608                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13609                         res->vf_id, is_on);
13610 #endif
13611
13612         switch (ret) {
13613         case 0:
13614                 break;
13615         case -EINVAL:
13616                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13617                 break;
13618         case -ENODEV:
13619                 printf("invalid port_id %d\n", res->port_id);
13620                 break;
13621         case -ENOTSUP:
13622                 printf("function not implemented\n");
13623                 break;
13624         default:
13625                 printf("programming error: (%s)\n", strerror(-ret));
13626         }
13627 }
13628
13629 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13630         .f = cmd_set_vf_mac_anti_spoof_parsed,
13631         .data = NULL,
13632         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13633         .tokens = {
13634                 (void *)&cmd_vf_mac_anti_spoof_set,
13635                 (void *)&cmd_vf_mac_anti_spoof_vf,
13636                 (void *)&cmd_vf_mac_anti_spoof_mac,
13637                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13638                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13639                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13640                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13641                 NULL,
13642         },
13643 };
13644
13645 /* vf vlan strip queue configuration */
13646
13647 /* Common result structure for vf mac anti spoof */
13648 struct cmd_vf_vlan_stripq_result {
13649         cmdline_fixed_string_t set;
13650         cmdline_fixed_string_t vf;
13651         cmdline_fixed_string_t vlan;
13652         cmdline_fixed_string_t stripq;
13653         portid_t port_id;
13654         uint16_t vf_id;
13655         cmdline_fixed_string_t on_off;
13656 };
13657
13658 /* Common CLI fields for vf vlan strip enable disable */
13659 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13660         TOKEN_STRING_INITIALIZER
13661                 (struct cmd_vf_vlan_stripq_result,
13662                  set, "set");
13663 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13664         TOKEN_STRING_INITIALIZER
13665                 (struct cmd_vf_vlan_stripq_result,
13666                  vf, "vf");
13667 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13668         TOKEN_STRING_INITIALIZER
13669                 (struct cmd_vf_vlan_stripq_result,
13670                  vlan, "vlan");
13671 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13672         TOKEN_STRING_INITIALIZER
13673                 (struct cmd_vf_vlan_stripq_result,
13674                  stripq, "stripq");
13675 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13676         TOKEN_NUM_INITIALIZER
13677                 (struct cmd_vf_vlan_stripq_result,
13678                  port_id, UINT16);
13679 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13680         TOKEN_NUM_INITIALIZER
13681                 (struct cmd_vf_vlan_stripq_result,
13682                  vf_id, UINT16);
13683 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13684         TOKEN_STRING_INITIALIZER
13685                 (struct cmd_vf_vlan_stripq_result,
13686                  on_off, "on#off");
13687
13688 static void
13689 cmd_set_vf_vlan_stripq_parsed(
13690         void *parsed_result,
13691         __rte_unused struct cmdline *cl,
13692         __rte_unused void *data)
13693 {
13694         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13695         int ret = -ENOTSUP;
13696
13697         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13698
13699         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13700                 return;
13701
13702 #ifdef RTE_LIBRTE_IXGBE_PMD
13703         if (ret == -ENOTSUP)
13704                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13705                         res->vf_id, is_on);
13706 #endif
13707 #ifdef RTE_LIBRTE_I40E_PMD
13708         if (ret == -ENOTSUP)
13709                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13710                         res->vf_id, is_on);
13711 #endif
13712 #ifdef RTE_LIBRTE_BNXT_PMD
13713         if (ret == -ENOTSUP)
13714                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13715                         res->vf_id, is_on);
13716 #endif
13717
13718         switch (ret) {
13719         case 0:
13720                 break;
13721         case -EINVAL:
13722                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13723                 break;
13724         case -ENODEV:
13725                 printf("invalid port_id %d\n", res->port_id);
13726                 break;
13727         case -ENOTSUP:
13728                 printf("function not implemented\n");
13729                 break;
13730         default:
13731                 printf("programming error: (%s)\n", strerror(-ret));
13732         }
13733 }
13734
13735 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13736         .f = cmd_set_vf_vlan_stripq_parsed,
13737         .data = NULL,
13738         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13739         .tokens = {
13740                 (void *)&cmd_vf_vlan_stripq_set,
13741                 (void *)&cmd_vf_vlan_stripq_vf,
13742                 (void *)&cmd_vf_vlan_stripq_vlan,
13743                 (void *)&cmd_vf_vlan_stripq_stripq,
13744                 (void *)&cmd_vf_vlan_stripq_port_id,
13745                 (void *)&cmd_vf_vlan_stripq_vf_id,
13746                 (void *)&cmd_vf_vlan_stripq_on_off,
13747                 NULL,
13748         },
13749 };
13750
13751 /* vf vlan insert configuration */
13752
13753 /* Common result structure for vf vlan insert */
13754 struct cmd_vf_vlan_insert_result {
13755         cmdline_fixed_string_t set;
13756         cmdline_fixed_string_t vf;
13757         cmdline_fixed_string_t vlan;
13758         cmdline_fixed_string_t insert;
13759         portid_t port_id;
13760         uint16_t vf_id;
13761         uint16_t vlan_id;
13762 };
13763
13764 /* Common CLI fields for vf vlan insert enable disable */
13765 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13766         TOKEN_STRING_INITIALIZER
13767                 (struct cmd_vf_vlan_insert_result,
13768                  set, "set");
13769 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13770         TOKEN_STRING_INITIALIZER
13771                 (struct cmd_vf_vlan_insert_result,
13772                  vf, "vf");
13773 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13774         TOKEN_STRING_INITIALIZER
13775                 (struct cmd_vf_vlan_insert_result,
13776                  vlan, "vlan");
13777 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13778         TOKEN_STRING_INITIALIZER
13779                 (struct cmd_vf_vlan_insert_result,
13780                  insert, "insert");
13781 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13782         TOKEN_NUM_INITIALIZER
13783                 (struct cmd_vf_vlan_insert_result,
13784                  port_id, UINT16);
13785 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13786         TOKEN_NUM_INITIALIZER
13787                 (struct cmd_vf_vlan_insert_result,
13788                  vf_id, UINT16);
13789 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_vf_vlan_insert_result,
13792                  vlan_id, UINT16);
13793
13794 static void
13795 cmd_set_vf_vlan_insert_parsed(
13796         void *parsed_result,
13797         __rte_unused struct cmdline *cl,
13798         __rte_unused void *data)
13799 {
13800         struct cmd_vf_vlan_insert_result *res = parsed_result;
13801         int ret = -ENOTSUP;
13802
13803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13804                 return;
13805
13806 #ifdef RTE_LIBRTE_IXGBE_PMD
13807         if (ret == -ENOTSUP)
13808                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13809                         res->vlan_id);
13810 #endif
13811 #ifdef RTE_LIBRTE_I40E_PMD
13812         if (ret == -ENOTSUP)
13813                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13814                         res->vlan_id);
13815 #endif
13816 #ifdef RTE_LIBRTE_BNXT_PMD
13817         if (ret == -ENOTSUP)
13818                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13819                         res->vlan_id);
13820 #endif
13821
13822         switch (ret) {
13823         case 0:
13824                 break;
13825         case -EINVAL:
13826                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13827                 break;
13828         case -ENODEV:
13829                 printf("invalid port_id %d\n", res->port_id);
13830                 break;
13831         case -ENOTSUP:
13832                 printf("function not implemented\n");
13833                 break;
13834         default:
13835                 printf("programming error: (%s)\n", strerror(-ret));
13836         }
13837 }
13838
13839 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13840         .f = cmd_set_vf_vlan_insert_parsed,
13841         .data = NULL,
13842         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13843         .tokens = {
13844                 (void *)&cmd_vf_vlan_insert_set,
13845                 (void *)&cmd_vf_vlan_insert_vf,
13846                 (void *)&cmd_vf_vlan_insert_vlan,
13847                 (void *)&cmd_vf_vlan_insert_insert,
13848                 (void *)&cmd_vf_vlan_insert_port_id,
13849                 (void *)&cmd_vf_vlan_insert_vf_id,
13850                 (void *)&cmd_vf_vlan_insert_vlan_id,
13851                 NULL,
13852         },
13853 };
13854
13855 /* tx loopback configuration */
13856
13857 /* Common result structure for tx loopback */
13858 struct cmd_tx_loopback_result {
13859         cmdline_fixed_string_t set;
13860         cmdline_fixed_string_t tx;
13861         cmdline_fixed_string_t loopback;
13862         portid_t port_id;
13863         cmdline_fixed_string_t on_off;
13864 };
13865
13866 /* Common CLI fields for tx loopback enable disable */
13867 cmdline_parse_token_string_t cmd_tx_loopback_set =
13868         TOKEN_STRING_INITIALIZER
13869                 (struct cmd_tx_loopback_result,
13870                  set, "set");
13871 cmdline_parse_token_string_t cmd_tx_loopback_tx =
13872         TOKEN_STRING_INITIALIZER
13873                 (struct cmd_tx_loopback_result,
13874                  tx, "tx");
13875 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
13876         TOKEN_STRING_INITIALIZER
13877                 (struct cmd_tx_loopback_result,
13878                  loopback, "loopback");
13879 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
13880         TOKEN_NUM_INITIALIZER
13881                 (struct cmd_tx_loopback_result,
13882                  port_id, UINT16);
13883 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
13884         TOKEN_STRING_INITIALIZER
13885                 (struct cmd_tx_loopback_result,
13886                  on_off, "on#off");
13887
13888 static void
13889 cmd_set_tx_loopback_parsed(
13890         void *parsed_result,
13891         __rte_unused struct cmdline *cl,
13892         __rte_unused void *data)
13893 {
13894         struct cmd_tx_loopback_result *res = parsed_result;
13895         int ret = -ENOTSUP;
13896
13897         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13898
13899         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13900                 return;
13901
13902 #ifdef RTE_LIBRTE_IXGBE_PMD
13903         if (ret == -ENOTSUP)
13904                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
13905 #endif
13906 #ifdef RTE_LIBRTE_I40E_PMD
13907         if (ret == -ENOTSUP)
13908                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
13909 #endif
13910 #ifdef RTE_LIBRTE_BNXT_PMD
13911         if (ret == -ENOTSUP)
13912                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
13913 #endif
13914 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
13915         if (ret == -ENOTSUP)
13916                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
13917 #endif
13918
13919         switch (ret) {
13920         case 0:
13921                 break;
13922         case -EINVAL:
13923                 printf("invalid is_on %d\n", is_on);
13924                 break;
13925         case -ENODEV:
13926                 printf("invalid port_id %d\n", res->port_id);
13927                 break;
13928         case -ENOTSUP:
13929                 printf("function not implemented\n");
13930                 break;
13931         default:
13932                 printf("programming error: (%s)\n", strerror(-ret));
13933         }
13934 }
13935
13936 cmdline_parse_inst_t cmd_set_tx_loopback = {
13937         .f = cmd_set_tx_loopback_parsed,
13938         .data = NULL,
13939         .help_str = "set tx loopback <port_id> on|off",
13940         .tokens = {
13941                 (void *)&cmd_tx_loopback_set,
13942                 (void *)&cmd_tx_loopback_tx,
13943                 (void *)&cmd_tx_loopback_loopback,
13944                 (void *)&cmd_tx_loopback_port_id,
13945                 (void *)&cmd_tx_loopback_on_off,
13946                 NULL,
13947         },
13948 };
13949
13950 /* all queues drop enable configuration */
13951
13952 /* Common result structure for all queues drop enable */
13953 struct cmd_all_queues_drop_en_result {
13954         cmdline_fixed_string_t set;
13955         cmdline_fixed_string_t all;
13956         cmdline_fixed_string_t queues;
13957         cmdline_fixed_string_t drop;
13958         portid_t port_id;
13959         cmdline_fixed_string_t on_off;
13960 };
13961
13962 /* Common CLI fields for tx loopback enable disable */
13963 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
13964         TOKEN_STRING_INITIALIZER
13965                 (struct cmd_all_queues_drop_en_result,
13966                  set, "set");
13967 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
13968         TOKEN_STRING_INITIALIZER
13969                 (struct cmd_all_queues_drop_en_result,
13970                  all, "all");
13971 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
13972         TOKEN_STRING_INITIALIZER
13973                 (struct cmd_all_queues_drop_en_result,
13974                  queues, "queues");
13975 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
13976         TOKEN_STRING_INITIALIZER
13977                 (struct cmd_all_queues_drop_en_result,
13978                  drop, "drop");
13979 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
13980         TOKEN_NUM_INITIALIZER
13981                 (struct cmd_all_queues_drop_en_result,
13982                  port_id, UINT16);
13983 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
13984         TOKEN_STRING_INITIALIZER
13985                 (struct cmd_all_queues_drop_en_result,
13986                  on_off, "on#off");
13987
13988 static void
13989 cmd_set_all_queues_drop_en_parsed(
13990         void *parsed_result,
13991         __rte_unused struct cmdline *cl,
13992         __rte_unused void *data)
13993 {
13994         struct cmd_all_queues_drop_en_result *res = parsed_result;
13995         int ret = -ENOTSUP;
13996         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13997
13998         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13999                 return;
14000
14001 #ifdef RTE_LIBRTE_IXGBE_PMD
14002         if (ret == -ENOTSUP)
14003                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14004 #endif
14005 #ifdef RTE_LIBRTE_BNXT_PMD
14006         if (ret == -ENOTSUP)
14007                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14008 #endif
14009         switch (ret) {
14010         case 0:
14011                 break;
14012         case -EINVAL:
14013                 printf("invalid is_on %d\n", is_on);
14014                 break;
14015         case -ENODEV:
14016                 printf("invalid port_id %d\n", res->port_id);
14017                 break;
14018         case -ENOTSUP:
14019                 printf("function not implemented\n");
14020                 break;
14021         default:
14022                 printf("programming error: (%s)\n", strerror(-ret));
14023         }
14024 }
14025
14026 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14027         .f = cmd_set_all_queues_drop_en_parsed,
14028         .data = NULL,
14029         .help_str = "set all queues drop <port_id> on|off",
14030         .tokens = {
14031                 (void *)&cmd_all_queues_drop_en_set,
14032                 (void *)&cmd_all_queues_drop_en_all,
14033                 (void *)&cmd_all_queues_drop_en_queues,
14034                 (void *)&cmd_all_queues_drop_en_drop,
14035                 (void *)&cmd_all_queues_drop_en_port_id,
14036                 (void *)&cmd_all_queues_drop_en_on_off,
14037                 NULL,
14038         },
14039 };
14040
14041 /* vf split drop enable configuration */
14042
14043 /* Common result structure for vf split drop enable */
14044 struct cmd_vf_split_drop_en_result {
14045         cmdline_fixed_string_t set;
14046         cmdline_fixed_string_t vf;
14047         cmdline_fixed_string_t split;
14048         cmdline_fixed_string_t drop;
14049         portid_t port_id;
14050         uint16_t vf_id;
14051         cmdline_fixed_string_t on_off;
14052 };
14053
14054 /* Common CLI fields for vf split drop enable disable */
14055 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14056         TOKEN_STRING_INITIALIZER
14057                 (struct cmd_vf_split_drop_en_result,
14058                  set, "set");
14059 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14060         TOKEN_STRING_INITIALIZER
14061                 (struct cmd_vf_split_drop_en_result,
14062                  vf, "vf");
14063 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14064         TOKEN_STRING_INITIALIZER
14065                 (struct cmd_vf_split_drop_en_result,
14066                  split, "split");
14067 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14068         TOKEN_STRING_INITIALIZER
14069                 (struct cmd_vf_split_drop_en_result,
14070                  drop, "drop");
14071 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14072         TOKEN_NUM_INITIALIZER
14073                 (struct cmd_vf_split_drop_en_result,
14074                  port_id, UINT16);
14075 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14076         TOKEN_NUM_INITIALIZER
14077                 (struct cmd_vf_split_drop_en_result,
14078                  vf_id, UINT16);
14079 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14080         TOKEN_STRING_INITIALIZER
14081                 (struct cmd_vf_split_drop_en_result,
14082                  on_off, "on#off");
14083
14084 static void
14085 cmd_set_vf_split_drop_en_parsed(
14086         void *parsed_result,
14087         __rte_unused struct cmdline *cl,
14088         __rte_unused void *data)
14089 {
14090         struct cmd_vf_split_drop_en_result *res = parsed_result;
14091         int ret = -ENOTSUP;
14092         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14093
14094         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14095                 return;
14096
14097 #ifdef RTE_LIBRTE_IXGBE_PMD
14098         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14099                         is_on);
14100 #endif
14101         switch (ret) {
14102         case 0:
14103                 break;
14104         case -EINVAL:
14105                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14106                 break;
14107         case -ENODEV:
14108                 printf("invalid port_id %d\n", res->port_id);
14109                 break;
14110         case -ENOTSUP:
14111                 printf("not supported on port %d\n", res->port_id);
14112                 break;
14113         default:
14114                 printf("programming error: (%s)\n", strerror(-ret));
14115         }
14116 }
14117
14118 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14119         .f = cmd_set_vf_split_drop_en_parsed,
14120         .data = NULL,
14121         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14122         .tokens = {
14123                 (void *)&cmd_vf_split_drop_en_set,
14124                 (void *)&cmd_vf_split_drop_en_vf,
14125                 (void *)&cmd_vf_split_drop_en_split,
14126                 (void *)&cmd_vf_split_drop_en_drop,
14127                 (void *)&cmd_vf_split_drop_en_port_id,
14128                 (void *)&cmd_vf_split_drop_en_vf_id,
14129                 (void *)&cmd_vf_split_drop_en_on_off,
14130                 NULL,
14131         },
14132 };
14133
14134 /* vf mac address configuration */
14135
14136 /* Common result structure for vf mac address */
14137 struct cmd_set_vf_mac_addr_result {
14138         cmdline_fixed_string_t set;
14139         cmdline_fixed_string_t vf;
14140         cmdline_fixed_string_t mac;
14141         cmdline_fixed_string_t addr;
14142         portid_t port_id;
14143         uint16_t vf_id;
14144         struct rte_ether_addr mac_addr;
14145
14146 };
14147
14148 /* Common CLI fields for vf split drop enable disable */
14149 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14150         TOKEN_STRING_INITIALIZER
14151                 (struct cmd_set_vf_mac_addr_result,
14152                  set, "set");
14153 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14154         TOKEN_STRING_INITIALIZER
14155                 (struct cmd_set_vf_mac_addr_result,
14156                  vf, "vf");
14157 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14158         TOKEN_STRING_INITIALIZER
14159                 (struct cmd_set_vf_mac_addr_result,
14160                  mac, "mac");
14161 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14162         TOKEN_STRING_INITIALIZER
14163                 (struct cmd_set_vf_mac_addr_result,
14164                  addr, "addr");
14165 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14166         TOKEN_NUM_INITIALIZER
14167                 (struct cmd_set_vf_mac_addr_result,
14168                  port_id, UINT16);
14169 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14170         TOKEN_NUM_INITIALIZER
14171                 (struct cmd_set_vf_mac_addr_result,
14172                  vf_id, UINT16);
14173 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14174         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14175                  mac_addr);
14176
14177 static void
14178 cmd_set_vf_mac_addr_parsed(
14179         void *parsed_result,
14180         __rte_unused struct cmdline *cl,
14181         __rte_unused void *data)
14182 {
14183         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14184         int ret = -ENOTSUP;
14185
14186         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14187                 return;
14188
14189 #ifdef RTE_LIBRTE_IXGBE_PMD
14190         if (ret == -ENOTSUP)
14191                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14192                                 &res->mac_addr);
14193 #endif
14194 #ifdef RTE_LIBRTE_I40E_PMD
14195         if (ret == -ENOTSUP)
14196                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14197                                 &res->mac_addr);
14198 #endif
14199 #ifdef RTE_LIBRTE_BNXT_PMD
14200         if (ret == -ENOTSUP)
14201                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14202                                 &res->mac_addr);
14203 #endif
14204
14205         switch (ret) {
14206         case 0:
14207                 break;
14208         case -EINVAL:
14209                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14210                 break;
14211         case -ENODEV:
14212                 printf("invalid port_id %d\n", res->port_id);
14213                 break;
14214         case -ENOTSUP:
14215                 printf("function not implemented\n");
14216                 break;
14217         default:
14218                 printf("programming error: (%s)\n", strerror(-ret));
14219         }
14220 }
14221
14222 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14223         .f = cmd_set_vf_mac_addr_parsed,
14224         .data = NULL,
14225         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14226         .tokens = {
14227                 (void *)&cmd_set_vf_mac_addr_set,
14228                 (void *)&cmd_set_vf_mac_addr_vf,
14229                 (void *)&cmd_set_vf_mac_addr_mac,
14230                 (void *)&cmd_set_vf_mac_addr_addr,
14231                 (void *)&cmd_set_vf_mac_addr_port_id,
14232                 (void *)&cmd_set_vf_mac_addr_vf_id,
14233                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14234                 NULL,
14235         },
14236 };
14237
14238 /* MACsec configuration */
14239
14240 /* Common result structure for MACsec offload enable */
14241 struct cmd_macsec_offload_on_result {
14242         cmdline_fixed_string_t set;
14243         cmdline_fixed_string_t macsec;
14244         cmdline_fixed_string_t offload;
14245         portid_t port_id;
14246         cmdline_fixed_string_t on;
14247         cmdline_fixed_string_t encrypt;
14248         cmdline_fixed_string_t en_on_off;
14249         cmdline_fixed_string_t replay_protect;
14250         cmdline_fixed_string_t rp_on_off;
14251 };
14252
14253 /* Common CLI fields for MACsec offload disable */
14254 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14255         TOKEN_STRING_INITIALIZER
14256                 (struct cmd_macsec_offload_on_result,
14257                  set, "set");
14258 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14259         TOKEN_STRING_INITIALIZER
14260                 (struct cmd_macsec_offload_on_result,
14261                  macsec, "macsec");
14262 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14263         TOKEN_STRING_INITIALIZER
14264                 (struct cmd_macsec_offload_on_result,
14265                  offload, "offload");
14266 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14267         TOKEN_NUM_INITIALIZER
14268                 (struct cmd_macsec_offload_on_result,
14269                  port_id, UINT16);
14270 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14271         TOKEN_STRING_INITIALIZER
14272                 (struct cmd_macsec_offload_on_result,
14273                  on, "on");
14274 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14275         TOKEN_STRING_INITIALIZER
14276                 (struct cmd_macsec_offload_on_result,
14277                  encrypt, "encrypt");
14278 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14279         TOKEN_STRING_INITIALIZER
14280                 (struct cmd_macsec_offload_on_result,
14281                  en_on_off, "on#off");
14282 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14283         TOKEN_STRING_INITIALIZER
14284                 (struct cmd_macsec_offload_on_result,
14285                  replay_protect, "replay-protect");
14286 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14287         TOKEN_STRING_INITIALIZER
14288                 (struct cmd_macsec_offload_on_result,
14289                  rp_on_off, "on#off");
14290
14291 static void
14292 cmd_set_macsec_offload_on_parsed(
14293         void *parsed_result,
14294         __rte_unused struct cmdline *cl,
14295         __rte_unused void *data)
14296 {
14297         struct cmd_macsec_offload_on_result *res = parsed_result;
14298         int ret = -ENOTSUP;
14299         portid_t port_id = res->port_id;
14300         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14301         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14302         struct rte_eth_dev_info dev_info;
14303
14304         if (port_id_is_invalid(port_id, ENABLED_WARN))
14305                 return;
14306         if (!port_is_stopped(port_id)) {
14307                 printf("Please stop port %d first\n", port_id);
14308                 return;
14309         }
14310
14311         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14312         if (ret != 0)
14313                 return;
14314
14315         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14316 #ifdef RTE_LIBRTE_IXGBE_PMD
14317                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14318 #endif
14319         }
14320         RTE_SET_USED(en);
14321         RTE_SET_USED(rp);
14322
14323         switch (ret) {
14324         case 0:
14325                 ports[port_id].dev_conf.txmode.offloads |=
14326                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14327                 cmd_reconfig_device_queue(port_id, 1, 1);
14328                 break;
14329         case -ENODEV:
14330                 printf("invalid port_id %d\n", port_id);
14331                 break;
14332         case -ENOTSUP:
14333                 printf("not supported on port %d\n", port_id);
14334                 break;
14335         default:
14336                 printf("programming error: (%s)\n", strerror(-ret));
14337         }
14338 }
14339
14340 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14341         .f = cmd_set_macsec_offload_on_parsed,
14342         .data = NULL,
14343         .help_str = "set macsec offload <port_id> on "
14344                 "encrypt on|off replay-protect on|off",
14345         .tokens = {
14346                 (void *)&cmd_macsec_offload_on_set,
14347                 (void *)&cmd_macsec_offload_on_macsec,
14348                 (void *)&cmd_macsec_offload_on_offload,
14349                 (void *)&cmd_macsec_offload_on_port_id,
14350                 (void *)&cmd_macsec_offload_on_on,
14351                 (void *)&cmd_macsec_offload_on_encrypt,
14352                 (void *)&cmd_macsec_offload_on_en_on_off,
14353                 (void *)&cmd_macsec_offload_on_replay_protect,
14354                 (void *)&cmd_macsec_offload_on_rp_on_off,
14355                 NULL,
14356         },
14357 };
14358
14359 /* Common result structure for MACsec offload disable */
14360 struct cmd_macsec_offload_off_result {
14361         cmdline_fixed_string_t set;
14362         cmdline_fixed_string_t macsec;
14363         cmdline_fixed_string_t offload;
14364         portid_t port_id;
14365         cmdline_fixed_string_t off;
14366 };
14367
14368 /* Common CLI fields for MACsec offload disable */
14369 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14370         TOKEN_STRING_INITIALIZER
14371                 (struct cmd_macsec_offload_off_result,
14372                  set, "set");
14373 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14374         TOKEN_STRING_INITIALIZER
14375                 (struct cmd_macsec_offload_off_result,
14376                  macsec, "macsec");
14377 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14378         TOKEN_STRING_INITIALIZER
14379                 (struct cmd_macsec_offload_off_result,
14380                  offload, "offload");
14381 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14382         TOKEN_NUM_INITIALIZER
14383                 (struct cmd_macsec_offload_off_result,
14384                  port_id, UINT16);
14385 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14386         TOKEN_STRING_INITIALIZER
14387                 (struct cmd_macsec_offload_off_result,
14388                  off, "off");
14389
14390 static void
14391 cmd_set_macsec_offload_off_parsed(
14392         void *parsed_result,
14393         __rte_unused struct cmdline *cl,
14394         __rte_unused void *data)
14395 {
14396         struct cmd_macsec_offload_off_result *res = parsed_result;
14397         int ret = -ENOTSUP;
14398         struct rte_eth_dev_info dev_info;
14399         portid_t port_id = res->port_id;
14400
14401         if (port_id_is_invalid(port_id, ENABLED_WARN))
14402                 return;
14403         if (!port_is_stopped(port_id)) {
14404                 printf("Please stop port %d first\n", port_id);
14405                 return;
14406         }
14407
14408         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14409         if (ret != 0)
14410                 return;
14411
14412         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14413 #ifdef RTE_LIBRTE_IXGBE_PMD
14414                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14415 #endif
14416         }
14417         switch (ret) {
14418         case 0:
14419                 ports[port_id].dev_conf.txmode.offloads &=
14420                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14421                 cmd_reconfig_device_queue(port_id, 1, 1);
14422                 break;
14423         case -ENODEV:
14424                 printf("invalid port_id %d\n", port_id);
14425                 break;
14426         case -ENOTSUP:
14427                 printf("not supported on port %d\n", port_id);
14428                 break;
14429         default:
14430                 printf("programming error: (%s)\n", strerror(-ret));
14431         }
14432 }
14433
14434 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14435         .f = cmd_set_macsec_offload_off_parsed,
14436         .data = NULL,
14437         .help_str = "set macsec offload <port_id> off",
14438         .tokens = {
14439                 (void *)&cmd_macsec_offload_off_set,
14440                 (void *)&cmd_macsec_offload_off_macsec,
14441                 (void *)&cmd_macsec_offload_off_offload,
14442                 (void *)&cmd_macsec_offload_off_port_id,
14443                 (void *)&cmd_macsec_offload_off_off,
14444                 NULL,
14445         },
14446 };
14447
14448 /* Common result structure for MACsec secure connection configure */
14449 struct cmd_macsec_sc_result {
14450         cmdline_fixed_string_t set;
14451         cmdline_fixed_string_t macsec;
14452         cmdline_fixed_string_t sc;
14453         cmdline_fixed_string_t tx_rx;
14454         portid_t port_id;
14455         struct rte_ether_addr mac;
14456         uint16_t pi;
14457 };
14458
14459 /* Common CLI fields for MACsec secure connection configure */
14460 cmdline_parse_token_string_t cmd_macsec_sc_set =
14461         TOKEN_STRING_INITIALIZER
14462                 (struct cmd_macsec_sc_result,
14463                  set, "set");
14464 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14465         TOKEN_STRING_INITIALIZER
14466                 (struct cmd_macsec_sc_result,
14467                  macsec, "macsec");
14468 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14469         TOKEN_STRING_INITIALIZER
14470                 (struct cmd_macsec_sc_result,
14471                  sc, "sc");
14472 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14473         TOKEN_STRING_INITIALIZER
14474                 (struct cmd_macsec_sc_result,
14475                  tx_rx, "tx#rx");
14476 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14477         TOKEN_NUM_INITIALIZER
14478                 (struct cmd_macsec_sc_result,
14479                  port_id, UINT16);
14480 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14481         TOKEN_ETHERADDR_INITIALIZER
14482                 (struct cmd_macsec_sc_result,
14483                  mac);
14484 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14485         TOKEN_NUM_INITIALIZER
14486                 (struct cmd_macsec_sc_result,
14487                  pi, UINT16);
14488
14489 static void
14490 cmd_set_macsec_sc_parsed(
14491         void *parsed_result,
14492         __rte_unused struct cmdline *cl,
14493         __rte_unused void *data)
14494 {
14495         struct cmd_macsec_sc_result *res = parsed_result;
14496         int ret = -ENOTSUP;
14497         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14498
14499 #ifdef RTE_LIBRTE_IXGBE_PMD
14500         ret = is_tx ?
14501                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14502                                 res->mac.addr_bytes) :
14503                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14504                                 res->mac.addr_bytes, res->pi);
14505 #endif
14506         RTE_SET_USED(is_tx);
14507
14508         switch (ret) {
14509         case 0:
14510                 break;
14511         case -ENODEV:
14512                 printf("invalid port_id %d\n", res->port_id);
14513                 break;
14514         case -ENOTSUP:
14515                 printf("not supported on port %d\n", res->port_id);
14516                 break;
14517         default:
14518                 printf("programming error: (%s)\n", strerror(-ret));
14519         }
14520 }
14521
14522 cmdline_parse_inst_t cmd_set_macsec_sc = {
14523         .f = cmd_set_macsec_sc_parsed,
14524         .data = NULL,
14525         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14526         .tokens = {
14527                 (void *)&cmd_macsec_sc_set,
14528                 (void *)&cmd_macsec_sc_macsec,
14529                 (void *)&cmd_macsec_sc_sc,
14530                 (void *)&cmd_macsec_sc_tx_rx,
14531                 (void *)&cmd_macsec_sc_port_id,
14532                 (void *)&cmd_macsec_sc_mac,
14533                 (void *)&cmd_macsec_sc_pi,
14534                 NULL,
14535         },
14536 };
14537
14538 /* Common result structure for MACsec secure connection configure */
14539 struct cmd_macsec_sa_result {
14540         cmdline_fixed_string_t set;
14541         cmdline_fixed_string_t macsec;
14542         cmdline_fixed_string_t sa;
14543         cmdline_fixed_string_t tx_rx;
14544         portid_t port_id;
14545         uint8_t idx;
14546         uint8_t an;
14547         uint32_t pn;
14548         cmdline_fixed_string_t key;
14549 };
14550
14551 /* Common CLI fields for MACsec secure connection configure */
14552 cmdline_parse_token_string_t cmd_macsec_sa_set =
14553         TOKEN_STRING_INITIALIZER
14554                 (struct cmd_macsec_sa_result,
14555                  set, "set");
14556 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14557         TOKEN_STRING_INITIALIZER
14558                 (struct cmd_macsec_sa_result,
14559                  macsec, "macsec");
14560 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14561         TOKEN_STRING_INITIALIZER
14562                 (struct cmd_macsec_sa_result,
14563                  sa, "sa");
14564 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14565         TOKEN_STRING_INITIALIZER
14566                 (struct cmd_macsec_sa_result,
14567                  tx_rx, "tx#rx");
14568 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14569         TOKEN_NUM_INITIALIZER
14570                 (struct cmd_macsec_sa_result,
14571                  port_id, UINT16);
14572 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14573         TOKEN_NUM_INITIALIZER
14574                 (struct cmd_macsec_sa_result,
14575                  idx, UINT8);
14576 cmdline_parse_token_num_t cmd_macsec_sa_an =
14577         TOKEN_NUM_INITIALIZER
14578                 (struct cmd_macsec_sa_result,
14579                  an, UINT8);
14580 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14581         TOKEN_NUM_INITIALIZER
14582                 (struct cmd_macsec_sa_result,
14583                  pn, UINT32);
14584 cmdline_parse_token_string_t cmd_macsec_sa_key =
14585         TOKEN_STRING_INITIALIZER
14586                 (struct cmd_macsec_sa_result,
14587                  key, NULL);
14588
14589 static void
14590 cmd_set_macsec_sa_parsed(
14591         void *parsed_result,
14592         __rte_unused struct cmdline *cl,
14593         __rte_unused void *data)
14594 {
14595         struct cmd_macsec_sa_result *res = parsed_result;
14596         int ret = -ENOTSUP;
14597         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14598         uint8_t key[16] = { 0 };
14599         uint8_t xdgt0;
14600         uint8_t xdgt1;
14601         int key_len;
14602         int i;
14603
14604         key_len = strlen(res->key) / 2;
14605         if (key_len > 16)
14606                 key_len = 16;
14607
14608         for (i = 0; i < key_len; i++) {
14609                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14610                 if (xdgt0 == 0xFF)
14611                         return;
14612                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14613                 if (xdgt1 == 0xFF)
14614                         return;
14615                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14616         }
14617
14618 #ifdef RTE_LIBRTE_IXGBE_PMD
14619         ret = is_tx ?
14620                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14621                         res->idx, res->an, res->pn, key) :
14622                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14623                         res->idx, res->an, res->pn, key);
14624 #endif
14625         RTE_SET_USED(is_tx);
14626         RTE_SET_USED(key);
14627
14628         switch (ret) {
14629         case 0:
14630                 break;
14631         case -EINVAL:
14632                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14633                 break;
14634         case -ENODEV:
14635                 printf("invalid port_id %d\n", res->port_id);
14636                 break;
14637         case -ENOTSUP:
14638                 printf("not supported on port %d\n", res->port_id);
14639                 break;
14640         default:
14641                 printf("programming error: (%s)\n", strerror(-ret));
14642         }
14643 }
14644
14645 cmdline_parse_inst_t cmd_set_macsec_sa = {
14646         .f = cmd_set_macsec_sa_parsed,
14647         .data = NULL,
14648         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14649         .tokens = {
14650                 (void *)&cmd_macsec_sa_set,
14651                 (void *)&cmd_macsec_sa_macsec,
14652                 (void *)&cmd_macsec_sa_sa,
14653                 (void *)&cmd_macsec_sa_tx_rx,
14654                 (void *)&cmd_macsec_sa_port_id,
14655                 (void *)&cmd_macsec_sa_idx,
14656                 (void *)&cmd_macsec_sa_an,
14657                 (void *)&cmd_macsec_sa_pn,
14658                 (void *)&cmd_macsec_sa_key,
14659                 NULL,
14660         },
14661 };
14662
14663 /* VF unicast promiscuous mode configuration */
14664
14665 /* Common result structure for VF unicast promiscuous mode */
14666 struct cmd_vf_promisc_result {
14667         cmdline_fixed_string_t set;
14668         cmdline_fixed_string_t vf;
14669         cmdline_fixed_string_t promisc;
14670         portid_t port_id;
14671         uint32_t vf_id;
14672         cmdline_fixed_string_t on_off;
14673 };
14674
14675 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14676 cmdline_parse_token_string_t cmd_vf_promisc_set =
14677         TOKEN_STRING_INITIALIZER
14678                 (struct cmd_vf_promisc_result,
14679                  set, "set");
14680 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14681         TOKEN_STRING_INITIALIZER
14682                 (struct cmd_vf_promisc_result,
14683                  vf, "vf");
14684 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14685         TOKEN_STRING_INITIALIZER
14686                 (struct cmd_vf_promisc_result,
14687                  promisc, "promisc");
14688 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14689         TOKEN_NUM_INITIALIZER
14690                 (struct cmd_vf_promisc_result,
14691                  port_id, UINT16);
14692 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14693         TOKEN_NUM_INITIALIZER
14694                 (struct cmd_vf_promisc_result,
14695                  vf_id, UINT32);
14696 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14697         TOKEN_STRING_INITIALIZER
14698                 (struct cmd_vf_promisc_result,
14699                  on_off, "on#off");
14700
14701 static void
14702 cmd_set_vf_promisc_parsed(
14703         void *parsed_result,
14704         __rte_unused struct cmdline *cl,
14705         __rte_unused void *data)
14706 {
14707         struct cmd_vf_promisc_result *res = parsed_result;
14708         int ret = -ENOTSUP;
14709
14710         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14711
14712         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14713                 return;
14714
14715 #ifdef RTE_LIBRTE_I40E_PMD
14716         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14717                                                   res->vf_id, is_on);
14718 #endif
14719
14720         switch (ret) {
14721         case 0:
14722                 break;
14723         case -EINVAL:
14724                 printf("invalid vf_id %d\n", res->vf_id);
14725                 break;
14726         case -ENODEV:
14727                 printf("invalid port_id %d\n", res->port_id);
14728                 break;
14729         case -ENOTSUP:
14730                 printf("function not implemented\n");
14731                 break;
14732         default:
14733                 printf("programming error: (%s)\n", strerror(-ret));
14734         }
14735 }
14736
14737 cmdline_parse_inst_t cmd_set_vf_promisc = {
14738         .f = cmd_set_vf_promisc_parsed,
14739         .data = NULL,
14740         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14741                 "Set unicast promiscuous mode for a VF from the PF",
14742         .tokens = {
14743                 (void *)&cmd_vf_promisc_set,
14744                 (void *)&cmd_vf_promisc_vf,
14745                 (void *)&cmd_vf_promisc_promisc,
14746                 (void *)&cmd_vf_promisc_port_id,
14747                 (void *)&cmd_vf_promisc_vf_id,
14748                 (void *)&cmd_vf_promisc_on_off,
14749                 NULL,
14750         },
14751 };
14752
14753 /* VF multicast promiscuous mode configuration */
14754
14755 /* Common result structure for VF multicast promiscuous mode */
14756 struct cmd_vf_allmulti_result {
14757         cmdline_fixed_string_t set;
14758         cmdline_fixed_string_t vf;
14759         cmdline_fixed_string_t allmulti;
14760         portid_t port_id;
14761         uint32_t vf_id;
14762         cmdline_fixed_string_t on_off;
14763 };
14764
14765 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14766 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14767         TOKEN_STRING_INITIALIZER
14768                 (struct cmd_vf_allmulti_result,
14769                  set, "set");
14770 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14771         TOKEN_STRING_INITIALIZER
14772                 (struct cmd_vf_allmulti_result,
14773                  vf, "vf");
14774 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14775         TOKEN_STRING_INITIALIZER
14776                 (struct cmd_vf_allmulti_result,
14777                  allmulti, "allmulti");
14778 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14779         TOKEN_NUM_INITIALIZER
14780                 (struct cmd_vf_allmulti_result,
14781                  port_id, UINT16);
14782 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14783         TOKEN_NUM_INITIALIZER
14784                 (struct cmd_vf_allmulti_result,
14785                  vf_id, UINT32);
14786 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14787         TOKEN_STRING_INITIALIZER
14788                 (struct cmd_vf_allmulti_result,
14789                  on_off, "on#off");
14790
14791 static void
14792 cmd_set_vf_allmulti_parsed(
14793         void *parsed_result,
14794         __rte_unused struct cmdline *cl,
14795         __rte_unused void *data)
14796 {
14797         struct cmd_vf_allmulti_result *res = parsed_result;
14798         int ret = -ENOTSUP;
14799
14800         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14801
14802         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14803                 return;
14804
14805 #ifdef RTE_LIBRTE_I40E_PMD
14806         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14807                                                     res->vf_id, is_on);
14808 #endif
14809
14810         switch (ret) {
14811         case 0:
14812                 break;
14813         case -EINVAL:
14814                 printf("invalid vf_id %d\n", res->vf_id);
14815                 break;
14816         case -ENODEV:
14817                 printf("invalid port_id %d\n", res->port_id);
14818                 break;
14819         case -ENOTSUP:
14820                 printf("function not implemented\n");
14821                 break;
14822         default:
14823                 printf("programming error: (%s)\n", strerror(-ret));
14824         }
14825 }
14826
14827 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14828         .f = cmd_set_vf_allmulti_parsed,
14829         .data = NULL,
14830         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14831                 "Set multicast promiscuous mode for a VF from the PF",
14832         .tokens = {
14833                 (void *)&cmd_vf_allmulti_set,
14834                 (void *)&cmd_vf_allmulti_vf,
14835                 (void *)&cmd_vf_allmulti_allmulti,
14836                 (void *)&cmd_vf_allmulti_port_id,
14837                 (void *)&cmd_vf_allmulti_vf_id,
14838                 (void *)&cmd_vf_allmulti_on_off,
14839                 NULL,
14840         },
14841 };
14842
14843 /* vf broadcast mode configuration */
14844
14845 /* Common result structure for vf broadcast */
14846 struct cmd_set_vf_broadcast_result {
14847         cmdline_fixed_string_t set;
14848         cmdline_fixed_string_t vf;
14849         cmdline_fixed_string_t broadcast;
14850         portid_t port_id;
14851         uint16_t vf_id;
14852         cmdline_fixed_string_t on_off;
14853 };
14854
14855 /* Common CLI fields for vf broadcast enable disable */
14856 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14857         TOKEN_STRING_INITIALIZER
14858                 (struct cmd_set_vf_broadcast_result,
14859                  set, "set");
14860 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
14861         TOKEN_STRING_INITIALIZER
14862                 (struct cmd_set_vf_broadcast_result,
14863                  vf, "vf");
14864 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
14865         TOKEN_STRING_INITIALIZER
14866                 (struct cmd_set_vf_broadcast_result,
14867                  broadcast, "broadcast");
14868 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
14869         TOKEN_NUM_INITIALIZER
14870                 (struct cmd_set_vf_broadcast_result,
14871                  port_id, UINT16);
14872 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
14873         TOKEN_NUM_INITIALIZER
14874                 (struct cmd_set_vf_broadcast_result,
14875                  vf_id, UINT16);
14876 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
14877         TOKEN_STRING_INITIALIZER
14878                 (struct cmd_set_vf_broadcast_result,
14879                  on_off, "on#off");
14880
14881 static void
14882 cmd_set_vf_broadcast_parsed(
14883         void *parsed_result,
14884         __rte_unused struct cmdline *cl,
14885         __rte_unused void *data)
14886 {
14887         struct cmd_set_vf_broadcast_result *res = parsed_result;
14888         int ret = -ENOTSUP;
14889
14890         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14891
14892         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14893                 return;
14894
14895 #ifdef RTE_LIBRTE_I40E_PMD
14896         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
14897                                             res->vf_id, is_on);
14898 #endif
14899
14900         switch (ret) {
14901         case 0:
14902                 break;
14903         case -EINVAL:
14904                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14905                 break;
14906         case -ENODEV:
14907                 printf("invalid port_id %d\n", res->port_id);
14908                 break;
14909         case -ENOTSUP:
14910                 printf("function not implemented\n");
14911                 break;
14912         default:
14913                 printf("programming error: (%s)\n", strerror(-ret));
14914         }
14915 }
14916
14917 cmdline_parse_inst_t cmd_set_vf_broadcast = {
14918         .f = cmd_set_vf_broadcast_parsed,
14919         .data = NULL,
14920         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
14921         .tokens = {
14922                 (void *)&cmd_set_vf_broadcast_set,
14923                 (void *)&cmd_set_vf_broadcast_vf,
14924                 (void *)&cmd_set_vf_broadcast_broadcast,
14925                 (void *)&cmd_set_vf_broadcast_port_id,
14926                 (void *)&cmd_set_vf_broadcast_vf_id,
14927                 (void *)&cmd_set_vf_broadcast_on_off,
14928                 NULL,
14929         },
14930 };
14931
14932 /* vf vlan tag configuration */
14933
14934 /* Common result structure for vf vlan tag */
14935 struct cmd_set_vf_vlan_tag_result {
14936         cmdline_fixed_string_t set;
14937         cmdline_fixed_string_t vf;
14938         cmdline_fixed_string_t vlan;
14939         cmdline_fixed_string_t tag;
14940         portid_t port_id;
14941         uint16_t vf_id;
14942         cmdline_fixed_string_t on_off;
14943 };
14944
14945 /* Common CLI fields for vf vlan tag enable disable */
14946 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
14947         TOKEN_STRING_INITIALIZER
14948                 (struct cmd_set_vf_vlan_tag_result,
14949                  set, "set");
14950 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
14951         TOKEN_STRING_INITIALIZER
14952                 (struct cmd_set_vf_vlan_tag_result,
14953                  vf, "vf");
14954 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
14955         TOKEN_STRING_INITIALIZER
14956                 (struct cmd_set_vf_vlan_tag_result,
14957                  vlan, "vlan");
14958 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
14959         TOKEN_STRING_INITIALIZER
14960                 (struct cmd_set_vf_vlan_tag_result,
14961                  tag, "tag");
14962 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
14963         TOKEN_NUM_INITIALIZER
14964                 (struct cmd_set_vf_vlan_tag_result,
14965                  port_id, UINT16);
14966 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
14967         TOKEN_NUM_INITIALIZER
14968                 (struct cmd_set_vf_vlan_tag_result,
14969                  vf_id, UINT16);
14970 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
14971         TOKEN_STRING_INITIALIZER
14972                 (struct cmd_set_vf_vlan_tag_result,
14973                  on_off, "on#off");
14974
14975 static void
14976 cmd_set_vf_vlan_tag_parsed(
14977         void *parsed_result,
14978         __rte_unused struct cmdline *cl,
14979         __rte_unused void *data)
14980 {
14981         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
14982         int ret = -ENOTSUP;
14983
14984         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14985
14986         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14987                 return;
14988
14989 #ifdef RTE_LIBRTE_I40E_PMD
14990         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
14991                                            res->vf_id, is_on);
14992 #endif
14993
14994         switch (ret) {
14995         case 0:
14996                 break;
14997         case -EINVAL:
14998                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14999                 break;
15000         case -ENODEV:
15001                 printf("invalid port_id %d\n", res->port_id);
15002                 break;
15003         case -ENOTSUP:
15004                 printf("function not implemented\n");
15005                 break;
15006         default:
15007                 printf("programming error: (%s)\n", strerror(-ret));
15008         }
15009 }
15010
15011 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15012         .f = cmd_set_vf_vlan_tag_parsed,
15013         .data = NULL,
15014         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15015         .tokens = {
15016                 (void *)&cmd_set_vf_vlan_tag_set,
15017                 (void *)&cmd_set_vf_vlan_tag_vf,
15018                 (void *)&cmd_set_vf_vlan_tag_vlan,
15019                 (void *)&cmd_set_vf_vlan_tag_tag,
15020                 (void *)&cmd_set_vf_vlan_tag_port_id,
15021                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15022                 (void *)&cmd_set_vf_vlan_tag_on_off,
15023                 NULL,
15024         },
15025 };
15026
15027 /* Common definition of VF and TC TX bandwidth configuration */
15028 struct cmd_vf_tc_bw_result {
15029         cmdline_fixed_string_t set;
15030         cmdline_fixed_string_t vf;
15031         cmdline_fixed_string_t tc;
15032         cmdline_fixed_string_t tx;
15033         cmdline_fixed_string_t min_bw;
15034         cmdline_fixed_string_t max_bw;
15035         cmdline_fixed_string_t strict_link_prio;
15036         portid_t port_id;
15037         uint16_t vf_id;
15038         uint8_t tc_no;
15039         uint32_t bw;
15040         cmdline_fixed_string_t bw_list;
15041         uint8_t tc_map;
15042 };
15043
15044 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15045         TOKEN_STRING_INITIALIZER
15046                 (struct cmd_vf_tc_bw_result,
15047                  set, "set");
15048 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15049         TOKEN_STRING_INITIALIZER
15050                 (struct cmd_vf_tc_bw_result,
15051                  vf, "vf");
15052 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15053         TOKEN_STRING_INITIALIZER
15054                 (struct cmd_vf_tc_bw_result,
15055                  tc, "tc");
15056 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15057         TOKEN_STRING_INITIALIZER
15058                 (struct cmd_vf_tc_bw_result,
15059                  tx, "tx");
15060 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15061         TOKEN_STRING_INITIALIZER
15062                 (struct cmd_vf_tc_bw_result,
15063                  strict_link_prio, "strict-link-priority");
15064 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15065         TOKEN_STRING_INITIALIZER
15066                 (struct cmd_vf_tc_bw_result,
15067                  min_bw, "min-bandwidth");
15068 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15069         TOKEN_STRING_INITIALIZER
15070                 (struct cmd_vf_tc_bw_result,
15071                  max_bw, "max-bandwidth");
15072 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15073         TOKEN_NUM_INITIALIZER
15074                 (struct cmd_vf_tc_bw_result,
15075                  port_id, UINT16);
15076 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15077         TOKEN_NUM_INITIALIZER
15078                 (struct cmd_vf_tc_bw_result,
15079                  vf_id, UINT16);
15080 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15081         TOKEN_NUM_INITIALIZER
15082                 (struct cmd_vf_tc_bw_result,
15083                  tc_no, UINT8);
15084 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15085         TOKEN_NUM_INITIALIZER
15086                 (struct cmd_vf_tc_bw_result,
15087                  bw, UINT32);
15088 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15089         TOKEN_STRING_INITIALIZER
15090                 (struct cmd_vf_tc_bw_result,
15091                  bw_list, NULL);
15092 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15093         TOKEN_NUM_INITIALIZER
15094                 (struct cmd_vf_tc_bw_result,
15095                  tc_map, UINT8);
15096
15097 /* VF max bandwidth setting */
15098 static void
15099 cmd_vf_max_bw_parsed(
15100         void *parsed_result,
15101         __rte_unused struct cmdline *cl,
15102         __rte_unused void *data)
15103 {
15104         struct cmd_vf_tc_bw_result *res = parsed_result;
15105         int ret = -ENOTSUP;
15106
15107         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15108                 return;
15109
15110 #ifdef RTE_LIBRTE_I40E_PMD
15111         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15112                                          res->vf_id, res->bw);
15113 #endif
15114
15115         switch (ret) {
15116         case 0:
15117                 break;
15118         case -EINVAL:
15119                 printf("invalid vf_id %d or bandwidth %d\n",
15120                        res->vf_id, res->bw);
15121                 break;
15122         case -ENODEV:
15123                 printf("invalid port_id %d\n", res->port_id);
15124                 break;
15125         case -ENOTSUP:
15126                 printf("function not implemented\n");
15127                 break;
15128         default:
15129                 printf("programming error: (%s)\n", strerror(-ret));
15130         }
15131 }
15132
15133 cmdline_parse_inst_t cmd_vf_max_bw = {
15134         .f = cmd_vf_max_bw_parsed,
15135         .data = NULL,
15136         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15137         .tokens = {
15138                 (void *)&cmd_vf_tc_bw_set,
15139                 (void *)&cmd_vf_tc_bw_vf,
15140                 (void *)&cmd_vf_tc_bw_tx,
15141                 (void *)&cmd_vf_tc_bw_max_bw,
15142                 (void *)&cmd_vf_tc_bw_port_id,
15143                 (void *)&cmd_vf_tc_bw_vf_id,
15144                 (void *)&cmd_vf_tc_bw_bw,
15145                 NULL,
15146         },
15147 };
15148
15149 static int
15150 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15151                            uint8_t *tc_num,
15152                            char *str)
15153 {
15154         uint32_t size;
15155         const char *p, *p0 = str;
15156         char s[256];
15157         char *end;
15158         char *str_fld[16];
15159         uint16_t i;
15160         int ret;
15161
15162         p = strchr(p0, '(');
15163         if (p == NULL) {
15164                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15165                 return -1;
15166         }
15167         p++;
15168         p0 = strchr(p, ')');
15169         if (p0 == NULL) {
15170                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15171                 return -1;
15172         }
15173         size = p0 - p;
15174         if (size >= sizeof(s)) {
15175                 printf("The string size exceeds the internal buffer size\n");
15176                 return -1;
15177         }
15178         snprintf(s, sizeof(s), "%.*s", size, p);
15179         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15180         if (ret <= 0) {
15181                 printf("Failed to get the bandwidth list. ");
15182                 return -1;
15183         }
15184         *tc_num = ret;
15185         for (i = 0; i < ret; i++)
15186                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15187
15188         return 0;
15189 }
15190
15191 /* TC min bandwidth setting */
15192 static void
15193 cmd_vf_tc_min_bw_parsed(
15194         void *parsed_result,
15195         __rte_unused struct cmdline *cl,
15196         __rte_unused void *data)
15197 {
15198         struct cmd_vf_tc_bw_result *res = parsed_result;
15199         uint8_t tc_num;
15200         uint8_t bw[16];
15201         int ret = -ENOTSUP;
15202
15203         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15204                 return;
15205
15206         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15207         if (ret)
15208                 return;
15209
15210 #ifdef RTE_LIBRTE_I40E_PMD
15211         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15212                                               tc_num, bw);
15213 #endif
15214
15215         switch (ret) {
15216         case 0:
15217                 break;
15218         case -EINVAL:
15219                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15220                 break;
15221         case -ENODEV:
15222                 printf("invalid port_id %d\n", res->port_id);
15223                 break;
15224         case -ENOTSUP:
15225                 printf("function not implemented\n");
15226                 break;
15227         default:
15228                 printf("programming error: (%s)\n", strerror(-ret));
15229         }
15230 }
15231
15232 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15233         .f = cmd_vf_tc_min_bw_parsed,
15234         .data = NULL,
15235         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15236                     " <bw1, bw2, ...>",
15237         .tokens = {
15238                 (void *)&cmd_vf_tc_bw_set,
15239                 (void *)&cmd_vf_tc_bw_vf,
15240                 (void *)&cmd_vf_tc_bw_tc,
15241                 (void *)&cmd_vf_tc_bw_tx,
15242                 (void *)&cmd_vf_tc_bw_min_bw,
15243                 (void *)&cmd_vf_tc_bw_port_id,
15244                 (void *)&cmd_vf_tc_bw_vf_id,
15245                 (void *)&cmd_vf_tc_bw_bw_list,
15246                 NULL,
15247         },
15248 };
15249
15250 static void
15251 cmd_tc_min_bw_parsed(
15252         void *parsed_result,
15253         __rte_unused struct cmdline *cl,
15254         __rte_unused void *data)
15255 {
15256         struct cmd_vf_tc_bw_result *res = parsed_result;
15257         struct rte_port *port;
15258         uint8_t tc_num;
15259         uint8_t bw[16];
15260         int ret = -ENOTSUP;
15261
15262         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15263                 return;
15264
15265         port = &ports[res->port_id];
15266         /** Check if the port is not started **/
15267         if (port->port_status != RTE_PORT_STOPPED) {
15268                 printf("Please stop port %d first\n", res->port_id);
15269                 return;
15270         }
15271
15272         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15273         if (ret)
15274                 return;
15275
15276 #ifdef RTE_LIBRTE_IXGBE_PMD
15277         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15278 #endif
15279
15280         switch (ret) {
15281         case 0:
15282                 break;
15283         case -EINVAL:
15284                 printf("invalid bandwidth\n");
15285                 break;
15286         case -ENODEV:
15287                 printf("invalid port_id %d\n", res->port_id);
15288                 break;
15289         case -ENOTSUP:
15290                 printf("function not implemented\n");
15291                 break;
15292         default:
15293                 printf("programming error: (%s)\n", strerror(-ret));
15294         }
15295 }
15296
15297 cmdline_parse_inst_t cmd_tc_min_bw = {
15298         .f = cmd_tc_min_bw_parsed,
15299         .data = NULL,
15300         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15301         .tokens = {
15302                 (void *)&cmd_vf_tc_bw_set,
15303                 (void *)&cmd_vf_tc_bw_tc,
15304                 (void *)&cmd_vf_tc_bw_tx,
15305                 (void *)&cmd_vf_tc_bw_min_bw,
15306                 (void *)&cmd_vf_tc_bw_port_id,
15307                 (void *)&cmd_vf_tc_bw_bw_list,
15308                 NULL,
15309         },
15310 };
15311
15312 /* TC max bandwidth setting */
15313 static void
15314 cmd_vf_tc_max_bw_parsed(
15315         void *parsed_result,
15316         __rte_unused struct cmdline *cl,
15317         __rte_unused void *data)
15318 {
15319         struct cmd_vf_tc_bw_result *res = parsed_result;
15320         int ret = -ENOTSUP;
15321
15322         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15323                 return;
15324
15325 #ifdef RTE_LIBRTE_I40E_PMD
15326         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15327                                             res->tc_no, res->bw);
15328 #endif
15329
15330         switch (ret) {
15331         case 0:
15332                 break;
15333         case -EINVAL:
15334                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15335                        res->vf_id, res->tc_no, res->bw);
15336                 break;
15337         case -ENODEV:
15338                 printf("invalid port_id %d\n", res->port_id);
15339                 break;
15340         case -ENOTSUP:
15341                 printf("function not implemented\n");
15342                 break;
15343         default:
15344                 printf("programming error: (%s)\n", strerror(-ret));
15345         }
15346 }
15347
15348 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15349         .f = cmd_vf_tc_max_bw_parsed,
15350         .data = NULL,
15351         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15352                     " <bandwidth>",
15353         .tokens = {
15354                 (void *)&cmd_vf_tc_bw_set,
15355                 (void *)&cmd_vf_tc_bw_vf,
15356                 (void *)&cmd_vf_tc_bw_tc,
15357                 (void *)&cmd_vf_tc_bw_tx,
15358                 (void *)&cmd_vf_tc_bw_max_bw,
15359                 (void *)&cmd_vf_tc_bw_port_id,
15360                 (void *)&cmd_vf_tc_bw_vf_id,
15361                 (void *)&cmd_vf_tc_bw_tc_no,
15362                 (void *)&cmd_vf_tc_bw_bw,
15363                 NULL,
15364         },
15365 };
15366
15367 /** Set VXLAN encapsulation details */
15368 struct cmd_set_vxlan_result {
15369         cmdline_fixed_string_t set;
15370         cmdline_fixed_string_t vxlan;
15371         cmdline_fixed_string_t pos_token;
15372         cmdline_fixed_string_t ip_version;
15373         uint32_t vlan_present:1;
15374         uint32_t vni;
15375         uint16_t udp_src;
15376         uint16_t udp_dst;
15377         cmdline_ipaddr_t ip_src;
15378         cmdline_ipaddr_t ip_dst;
15379         uint16_t tci;
15380         uint8_t tos;
15381         uint8_t ttl;
15382         struct rte_ether_addr eth_src;
15383         struct rte_ether_addr eth_dst;
15384 };
15385
15386 cmdline_parse_token_string_t cmd_set_vxlan_set =
15387         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15388 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15389         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15390 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15391         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15392                                  "vxlan-tos-ttl");
15393 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15394         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15395                                  "vxlan-with-vlan");
15396 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15397         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15398                                  "ip-version");
15399 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15400         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15401                                  "ipv4#ipv6");
15402 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15403         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15404                                  "vni");
15405 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15406         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15407 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15408         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15409                                  "udp-src");
15410 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15411         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15412 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15413         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15414                                  "udp-dst");
15415 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15416         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15417 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15418         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15419                                  "ip-tos");
15420 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15421         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15422 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15423         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15424                                  "ip-ttl");
15425 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15426         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15427 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15428         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15429                                  "ip-src");
15430 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15431         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15432 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15433         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15434                                  "ip-dst");
15435 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15436         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15437 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15438         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15439                                  "vlan-tci");
15440 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15441         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15442 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15443         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15444                                  "eth-src");
15445 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15446         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15447 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15448         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15449                                  "eth-dst");
15450 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15451         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15452
15453 static void cmd_set_vxlan_parsed(void *parsed_result,
15454         __rte_unused struct cmdline *cl,
15455         __rte_unused void *data)
15456 {
15457         struct cmd_set_vxlan_result *res = parsed_result;
15458         union {
15459                 uint32_t vxlan_id;
15460                 uint8_t vni[4];
15461         } id = {
15462                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15463         };
15464
15465         vxlan_encap_conf.select_tos_ttl = 0;
15466         if (strcmp(res->vxlan, "vxlan") == 0)
15467                 vxlan_encap_conf.select_vlan = 0;
15468         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15469                 vxlan_encap_conf.select_vlan = 1;
15470         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15471                 vxlan_encap_conf.select_vlan = 0;
15472                 vxlan_encap_conf.select_tos_ttl = 1;
15473         }
15474         if (strcmp(res->ip_version, "ipv4") == 0)
15475                 vxlan_encap_conf.select_ipv4 = 1;
15476         else if (strcmp(res->ip_version, "ipv6") == 0)
15477                 vxlan_encap_conf.select_ipv4 = 0;
15478         else
15479                 return;
15480         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15481         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15482         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15483         vxlan_encap_conf.ip_tos = res->tos;
15484         vxlan_encap_conf.ip_ttl = res->ttl;
15485         if (vxlan_encap_conf.select_ipv4) {
15486                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15487                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15488         } else {
15489                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15490                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15491         }
15492         if (vxlan_encap_conf.select_vlan)
15493                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15494         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15495                    RTE_ETHER_ADDR_LEN);
15496         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15497                    RTE_ETHER_ADDR_LEN);
15498 }
15499
15500 cmdline_parse_inst_t cmd_set_vxlan = {
15501         .f = cmd_set_vxlan_parsed,
15502         .data = NULL,
15503         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15504                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15505                 " eth-src <eth-src> eth-dst <eth-dst>",
15506         .tokens = {
15507                 (void *)&cmd_set_vxlan_set,
15508                 (void *)&cmd_set_vxlan_vxlan,
15509                 (void *)&cmd_set_vxlan_ip_version,
15510                 (void *)&cmd_set_vxlan_ip_version_value,
15511                 (void *)&cmd_set_vxlan_vni,
15512                 (void *)&cmd_set_vxlan_vni_value,
15513                 (void *)&cmd_set_vxlan_udp_src,
15514                 (void *)&cmd_set_vxlan_udp_src_value,
15515                 (void *)&cmd_set_vxlan_udp_dst,
15516                 (void *)&cmd_set_vxlan_udp_dst_value,
15517                 (void *)&cmd_set_vxlan_ip_src,
15518                 (void *)&cmd_set_vxlan_ip_src_value,
15519                 (void *)&cmd_set_vxlan_ip_dst,
15520                 (void *)&cmd_set_vxlan_ip_dst_value,
15521                 (void *)&cmd_set_vxlan_eth_src,
15522                 (void *)&cmd_set_vxlan_eth_src_value,
15523                 (void *)&cmd_set_vxlan_eth_dst,
15524                 (void *)&cmd_set_vxlan_eth_dst_value,
15525                 NULL,
15526         },
15527 };
15528
15529 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15530         .f = cmd_set_vxlan_parsed,
15531         .data = NULL,
15532         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15533                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15534                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15535                 " eth-dst <eth-dst>",
15536         .tokens = {
15537                 (void *)&cmd_set_vxlan_set,
15538                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15539                 (void *)&cmd_set_vxlan_ip_version,
15540                 (void *)&cmd_set_vxlan_ip_version_value,
15541                 (void *)&cmd_set_vxlan_vni,
15542                 (void *)&cmd_set_vxlan_vni_value,
15543                 (void *)&cmd_set_vxlan_udp_src,
15544                 (void *)&cmd_set_vxlan_udp_src_value,
15545                 (void *)&cmd_set_vxlan_udp_dst,
15546                 (void *)&cmd_set_vxlan_udp_dst_value,
15547                 (void *)&cmd_set_vxlan_ip_tos,
15548                 (void *)&cmd_set_vxlan_ip_tos_value,
15549                 (void *)&cmd_set_vxlan_ip_ttl,
15550                 (void *)&cmd_set_vxlan_ip_ttl_value,
15551                 (void *)&cmd_set_vxlan_ip_src,
15552                 (void *)&cmd_set_vxlan_ip_src_value,
15553                 (void *)&cmd_set_vxlan_ip_dst,
15554                 (void *)&cmd_set_vxlan_ip_dst_value,
15555                 (void *)&cmd_set_vxlan_eth_src,
15556                 (void *)&cmd_set_vxlan_eth_src_value,
15557                 (void *)&cmd_set_vxlan_eth_dst,
15558                 (void *)&cmd_set_vxlan_eth_dst_value,
15559                 NULL,
15560         },
15561 };
15562
15563 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15564         .f = cmd_set_vxlan_parsed,
15565         .data = NULL,
15566         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15567                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15568                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15569                 " <eth-dst>",
15570         .tokens = {
15571                 (void *)&cmd_set_vxlan_set,
15572                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15573                 (void *)&cmd_set_vxlan_ip_version,
15574                 (void *)&cmd_set_vxlan_ip_version_value,
15575                 (void *)&cmd_set_vxlan_vni,
15576                 (void *)&cmd_set_vxlan_vni_value,
15577                 (void *)&cmd_set_vxlan_udp_src,
15578                 (void *)&cmd_set_vxlan_udp_src_value,
15579                 (void *)&cmd_set_vxlan_udp_dst,
15580                 (void *)&cmd_set_vxlan_udp_dst_value,
15581                 (void *)&cmd_set_vxlan_ip_src,
15582                 (void *)&cmd_set_vxlan_ip_src_value,
15583                 (void *)&cmd_set_vxlan_ip_dst,
15584                 (void *)&cmd_set_vxlan_ip_dst_value,
15585                 (void *)&cmd_set_vxlan_vlan,
15586                 (void *)&cmd_set_vxlan_vlan_value,
15587                 (void *)&cmd_set_vxlan_eth_src,
15588                 (void *)&cmd_set_vxlan_eth_src_value,
15589                 (void *)&cmd_set_vxlan_eth_dst,
15590                 (void *)&cmd_set_vxlan_eth_dst_value,
15591                 NULL,
15592         },
15593 };
15594
15595 /** Set NVGRE encapsulation details */
15596 struct cmd_set_nvgre_result {
15597         cmdline_fixed_string_t set;
15598         cmdline_fixed_string_t nvgre;
15599         cmdline_fixed_string_t pos_token;
15600         cmdline_fixed_string_t ip_version;
15601         uint32_t tni;
15602         cmdline_ipaddr_t ip_src;
15603         cmdline_ipaddr_t ip_dst;
15604         uint16_t tci;
15605         struct rte_ether_addr eth_src;
15606         struct rte_ether_addr eth_dst;
15607 };
15608
15609 cmdline_parse_token_string_t cmd_set_nvgre_set =
15610         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15611 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15612         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15613 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15614         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15615                                  "nvgre-with-vlan");
15616 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15617         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15618                                  "ip-version");
15619 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15620         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15621                                  "ipv4#ipv6");
15622 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15623         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15624                                  "tni");
15625 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15626         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15627 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15628         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15629                                  "ip-src");
15630 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15631         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15632 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15633         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15634                                  "ip-dst");
15635 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15636         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15637 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15638         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15639                                  "vlan-tci");
15640 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15641         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15642 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15643         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15644                                  "eth-src");
15645 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15646         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15647 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15648         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15649                                  "eth-dst");
15650 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15651         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15652
15653 static void cmd_set_nvgre_parsed(void *parsed_result,
15654         __rte_unused struct cmdline *cl,
15655         __rte_unused void *data)
15656 {
15657         struct cmd_set_nvgre_result *res = parsed_result;
15658         union {
15659                 uint32_t nvgre_tni;
15660                 uint8_t tni[4];
15661         } id = {
15662                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15663         };
15664
15665         if (strcmp(res->nvgre, "nvgre") == 0)
15666                 nvgre_encap_conf.select_vlan = 0;
15667         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15668                 nvgre_encap_conf.select_vlan = 1;
15669         if (strcmp(res->ip_version, "ipv4") == 0)
15670                 nvgre_encap_conf.select_ipv4 = 1;
15671         else if (strcmp(res->ip_version, "ipv6") == 0)
15672                 nvgre_encap_conf.select_ipv4 = 0;
15673         else
15674                 return;
15675         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15676         if (nvgre_encap_conf.select_ipv4) {
15677                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15678                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15679         } else {
15680                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15681                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15682         }
15683         if (nvgre_encap_conf.select_vlan)
15684                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15685         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15686                    RTE_ETHER_ADDR_LEN);
15687         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15688                    RTE_ETHER_ADDR_LEN);
15689 }
15690
15691 cmdline_parse_inst_t cmd_set_nvgre = {
15692         .f = cmd_set_nvgre_parsed,
15693         .data = NULL,
15694         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15695                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15696                 " eth-dst <eth-dst>",
15697         .tokens = {
15698                 (void *)&cmd_set_nvgre_set,
15699                 (void *)&cmd_set_nvgre_nvgre,
15700                 (void *)&cmd_set_nvgre_ip_version,
15701                 (void *)&cmd_set_nvgre_ip_version_value,
15702                 (void *)&cmd_set_nvgre_tni,
15703                 (void *)&cmd_set_nvgre_tni_value,
15704                 (void *)&cmd_set_nvgre_ip_src,
15705                 (void *)&cmd_set_nvgre_ip_src_value,
15706                 (void *)&cmd_set_nvgre_ip_dst,
15707                 (void *)&cmd_set_nvgre_ip_dst_value,
15708                 (void *)&cmd_set_nvgre_eth_src,
15709                 (void *)&cmd_set_nvgre_eth_src_value,
15710                 (void *)&cmd_set_nvgre_eth_dst,
15711                 (void *)&cmd_set_nvgre_eth_dst_value,
15712                 NULL,
15713         },
15714 };
15715
15716 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15717         .f = cmd_set_nvgre_parsed,
15718         .data = NULL,
15719         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15720                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15721                 " eth-src <eth-src> eth-dst <eth-dst>",
15722         .tokens = {
15723                 (void *)&cmd_set_nvgre_set,
15724                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15725                 (void *)&cmd_set_nvgre_ip_version,
15726                 (void *)&cmd_set_nvgre_ip_version_value,
15727                 (void *)&cmd_set_nvgre_tni,
15728                 (void *)&cmd_set_nvgre_tni_value,
15729                 (void *)&cmd_set_nvgre_ip_src,
15730                 (void *)&cmd_set_nvgre_ip_src_value,
15731                 (void *)&cmd_set_nvgre_ip_dst,
15732                 (void *)&cmd_set_nvgre_ip_dst_value,
15733                 (void *)&cmd_set_nvgre_vlan,
15734                 (void *)&cmd_set_nvgre_vlan_value,
15735                 (void *)&cmd_set_nvgre_eth_src,
15736                 (void *)&cmd_set_nvgre_eth_src_value,
15737                 (void *)&cmd_set_nvgre_eth_dst,
15738                 (void *)&cmd_set_nvgre_eth_dst_value,
15739                 NULL,
15740         },
15741 };
15742
15743 /** Set L2 encapsulation details */
15744 struct cmd_set_l2_encap_result {
15745         cmdline_fixed_string_t set;
15746         cmdline_fixed_string_t l2_encap;
15747         cmdline_fixed_string_t pos_token;
15748         cmdline_fixed_string_t ip_version;
15749         uint32_t vlan_present:1;
15750         uint16_t tci;
15751         struct rte_ether_addr eth_src;
15752         struct rte_ether_addr eth_dst;
15753 };
15754
15755 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15757 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15758         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15759 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15760         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15761                                  "l2_encap-with-vlan");
15762 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15763         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15764                                  "ip-version");
15765 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15766         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15767                                  "ipv4#ipv6");
15768 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15769         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15770                                  "vlan-tci");
15771 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15772         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15773 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15775                                  "eth-src");
15776 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15777         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15778 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15780                                  "eth-dst");
15781 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15782         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15783
15784 static void cmd_set_l2_encap_parsed(void *parsed_result,
15785         __rte_unused struct cmdline *cl,
15786         __rte_unused void *data)
15787 {
15788         struct cmd_set_l2_encap_result *res = parsed_result;
15789
15790         if (strcmp(res->l2_encap, "l2_encap") == 0)
15791                 l2_encap_conf.select_vlan = 0;
15792         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15793                 l2_encap_conf.select_vlan = 1;
15794         if (strcmp(res->ip_version, "ipv4") == 0)
15795                 l2_encap_conf.select_ipv4 = 1;
15796         else if (strcmp(res->ip_version, "ipv6") == 0)
15797                 l2_encap_conf.select_ipv4 = 0;
15798         else
15799                 return;
15800         if (l2_encap_conf.select_vlan)
15801                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15802         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15803                    RTE_ETHER_ADDR_LEN);
15804         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15805                    RTE_ETHER_ADDR_LEN);
15806 }
15807
15808 cmdline_parse_inst_t cmd_set_l2_encap = {
15809         .f = cmd_set_l2_encap_parsed,
15810         .data = NULL,
15811         .help_str = "set l2_encap ip-version ipv4|ipv6"
15812                 " eth-src <eth-src> eth-dst <eth-dst>",
15813         .tokens = {
15814                 (void *)&cmd_set_l2_encap_set,
15815                 (void *)&cmd_set_l2_encap_l2_encap,
15816                 (void *)&cmd_set_l2_encap_ip_version,
15817                 (void *)&cmd_set_l2_encap_ip_version_value,
15818                 (void *)&cmd_set_l2_encap_eth_src,
15819                 (void *)&cmd_set_l2_encap_eth_src_value,
15820                 (void *)&cmd_set_l2_encap_eth_dst,
15821                 (void *)&cmd_set_l2_encap_eth_dst_value,
15822                 NULL,
15823         },
15824 };
15825
15826 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15827         .f = cmd_set_l2_encap_parsed,
15828         .data = NULL,
15829         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15830                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15831         .tokens = {
15832                 (void *)&cmd_set_l2_encap_set,
15833                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15834                 (void *)&cmd_set_l2_encap_ip_version,
15835                 (void *)&cmd_set_l2_encap_ip_version_value,
15836                 (void *)&cmd_set_l2_encap_vlan,
15837                 (void *)&cmd_set_l2_encap_vlan_value,
15838                 (void *)&cmd_set_l2_encap_eth_src,
15839                 (void *)&cmd_set_l2_encap_eth_src_value,
15840                 (void *)&cmd_set_l2_encap_eth_dst,
15841                 (void *)&cmd_set_l2_encap_eth_dst_value,
15842                 NULL,
15843         },
15844 };
15845
15846 /** Set L2 decapsulation details */
15847 struct cmd_set_l2_decap_result {
15848         cmdline_fixed_string_t set;
15849         cmdline_fixed_string_t l2_decap;
15850         cmdline_fixed_string_t pos_token;
15851         uint32_t vlan_present:1;
15852 };
15853
15854 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15855         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15856 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15857         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15858                                  "l2_decap");
15859 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
15860         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
15861                                  "l2_decap-with-vlan");
15862
15863 static void cmd_set_l2_decap_parsed(void *parsed_result,
15864         __rte_unused struct cmdline *cl,
15865         __rte_unused void *data)
15866 {
15867         struct cmd_set_l2_decap_result *res = parsed_result;
15868
15869         if (strcmp(res->l2_decap, "l2_decap") == 0)
15870                 l2_decap_conf.select_vlan = 0;
15871         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
15872                 l2_decap_conf.select_vlan = 1;
15873 }
15874
15875 cmdline_parse_inst_t cmd_set_l2_decap = {
15876         .f = cmd_set_l2_decap_parsed,
15877         .data = NULL,
15878         .help_str = "set l2_decap",
15879         .tokens = {
15880                 (void *)&cmd_set_l2_decap_set,
15881                 (void *)&cmd_set_l2_decap_l2_decap,
15882                 NULL,
15883         },
15884 };
15885
15886 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
15887         .f = cmd_set_l2_decap_parsed,
15888         .data = NULL,
15889         .help_str = "set l2_decap-with-vlan",
15890         .tokens = {
15891                 (void *)&cmd_set_l2_decap_set,
15892                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
15893                 NULL,
15894         },
15895 };
15896
15897 /** Set MPLSoGRE encapsulation details */
15898 struct cmd_set_mplsogre_encap_result {
15899         cmdline_fixed_string_t set;
15900         cmdline_fixed_string_t mplsogre;
15901         cmdline_fixed_string_t pos_token;
15902         cmdline_fixed_string_t ip_version;
15903         uint32_t vlan_present:1;
15904         uint32_t label;
15905         cmdline_ipaddr_t ip_src;
15906         cmdline_ipaddr_t ip_dst;
15907         uint16_t tci;
15908         struct rte_ether_addr eth_src;
15909         struct rte_ether_addr eth_dst;
15910 };
15911
15912 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
15913         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
15914                                  "set");
15915 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
15916         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
15917                                  "mplsogre_encap");
15918 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
15919         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15920                                  mplsogre, "mplsogre_encap-with-vlan");
15921 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
15922         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15923                                  pos_token, "ip-version");
15924 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
15925         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15926                                  ip_version, "ipv4#ipv6");
15927 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
15928         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15929                                  pos_token, "label");
15930 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
15931         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
15932                               UINT32);
15933 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
15934         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15935                                  pos_token, "ip-src");
15936 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
15937         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
15938 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
15939         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15940                                  pos_token, "ip-dst");
15941 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
15942         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
15943 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
15944         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15945                                  pos_token, "vlan-tci");
15946 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
15947         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
15948                               UINT16);
15949 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
15950         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15951                                  pos_token, "eth-src");
15952 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
15953         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15954                                     eth_src);
15955 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
15956         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15957                                  pos_token, "eth-dst");
15958 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
15959         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
15960                                     eth_dst);
15961
15962 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
15963         __rte_unused struct cmdline *cl,
15964         __rte_unused void *data)
15965 {
15966         struct cmd_set_mplsogre_encap_result *res = parsed_result;
15967         union {
15968                 uint32_t mplsogre_label;
15969                 uint8_t label[4];
15970         } id = {
15971                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
15972         };
15973
15974         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
15975                 mplsogre_encap_conf.select_vlan = 0;
15976         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
15977                 mplsogre_encap_conf.select_vlan = 1;
15978         if (strcmp(res->ip_version, "ipv4") == 0)
15979                 mplsogre_encap_conf.select_ipv4 = 1;
15980         else if (strcmp(res->ip_version, "ipv6") == 0)
15981                 mplsogre_encap_conf.select_ipv4 = 0;
15982         else
15983                 return;
15984         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
15985         if (mplsogre_encap_conf.select_ipv4) {
15986                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
15987                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
15988         } else {
15989                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
15990                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
15991         }
15992         if (mplsogre_encap_conf.select_vlan)
15993                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15994         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
15995                    RTE_ETHER_ADDR_LEN);
15996         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15997                    RTE_ETHER_ADDR_LEN);
15998 }
15999
16000 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16001         .f = cmd_set_mplsogre_encap_parsed,
16002         .data = NULL,
16003         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16004                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16005                 " eth-dst <eth-dst>",
16006         .tokens = {
16007                 (void *)&cmd_set_mplsogre_encap_set,
16008                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16009                 (void *)&cmd_set_mplsogre_encap_ip_version,
16010                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16011                 (void *)&cmd_set_mplsogre_encap_label,
16012                 (void *)&cmd_set_mplsogre_encap_label_value,
16013                 (void *)&cmd_set_mplsogre_encap_ip_src,
16014                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16015                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16016                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16017                 (void *)&cmd_set_mplsogre_encap_eth_src,
16018                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16019                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16020                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16021                 NULL,
16022         },
16023 };
16024
16025 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16026         .f = cmd_set_mplsogre_encap_parsed,
16027         .data = NULL,
16028         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16029                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16030                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16031         .tokens = {
16032                 (void *)&cmd_set_mplsogre_encap_set,
16033                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16034                 (void *)&cmd_set_mplsogre_encap_ip_version,
16035                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16036                 (void *)&cmd_set_mplsogre_encap_label,
16037                 (void *)&cmd_set_mplsogre_encap_label_value,
16038                 (void *)&cmd_set_mplsogre_encap_ip_src,
16039                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16040                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16041                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16042                 (void *)&cmd_set_mplsogre_encap_vlan,
16043                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16044                 (void *)&cmd_set_mplsogre_encap_eth_src,
16045                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16046                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16047                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16048                 NULL,
16049         },
16050 };
16051
16052 /** Set MPLSoGRE decapsulation details */
16053 struct cmd_set_mplsogre_decap_result {
16054         cmdline_fixed_string_t set;
16055         cmdline_fixed_string_t mplsogre;
16056         cmdline_fixed_string_t pos_token;
16057         cmdline_fixed_string_t ip_version;
16058         uint32_t vlan_present:1;
16059 };
16060
16061 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16062         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16063                                  "set");
16064 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16065         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16066                                  "mplsogre_decap");
16067 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16068         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16069                                  mplsogre, "mplsogre_decap-with-vlan");
16070 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16071         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16072                                  pos_token, "ip-version");
16073 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16074         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16075                                  ip_version, "ipv4#ipv6");
16076
16077 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16078         __rte_unused struct cmdline *cl,
16079         __rte_unused void *data)
16080 {
16081         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16082
16083         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16084                 mplsogre_decap_conf.select_vlan = 0;
16085         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16086                 mplsogre_decap_conf.select_vlan = 1;
16087         if (strcmp(res->ip_version, "ipv4") == 0)
16088                 mplsogre_decap_conf.select_ipv4 = 1;
16089         else if (strcmp(res->ip_version, "ipv6") == 0)
16090                 mplsogre_decap_conf.select_ipv4 = 0;
16091 }
16092
16093 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16094         .f = cmd_set_mplsogre_decap_parsed,
16095         .data = NULL,
16096         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16097         .tokens = {
16098                 (void *)&cmd_set_mplsogre_decap_set,
16099                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16100                 (void *)&cmd_set_mplsogre_decap_ip_version,
16101                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16102                 NULL,
16103         },
16104 };
16105
16106 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16107         .f = cmd_set_mplsogre_decap_parsed,
16108         .data = NULL,
16109         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16110         .tokens = {
16111                 (void *)&cmd_set_mplsogre_decap_set,
16112                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16113                 (void *)&cmd_set_mplsogre_decap_ip_version,
16114                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16115                 NULL,
16116         },
16117 };
16118
16119 /** Set MPLSoUDP encapsulation details */
16120 struct cmd_set_mplsoudp_encap_result {
16121         cmdline_fixed_string_t set;
16122         cmdline_fixed_string_t mplsoudp;
16123         cmdline_fixed_string_t pos_token;
16124         cmdline_fixed_string_t ip_version;
16125         uint32_t vlan_present:1;
16126         uint32_t label;
16127         uint16_t udp_src;
16128         uint16_t udp_dst;
16129         cmdline_ipaddr_t ip_src;
16130         cmdline_ipaddr_t ip_dst;
16131         uint16_t tci;
16132         struct rte_ether_addr eth_src;
16133         struct rte_ether_addr eth_dst;
16134 };
16135
16136 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16137         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16138                                  "set");
16139 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16140         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16141                                  "mplsoudp_encap");
16142 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16143         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16144                                  mplsoudp, "mplsoudp_encap-with-vlan");
16145 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16146         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16147                                  pos_token, "ip-version");
16148 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16149         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16150                                  ip_version, "ipv4#ipv6");
16151 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16152         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16153                                  pos_token, "label");
16154 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16155         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16156                               UINT32);
16157 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16158         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16159                                  pos_token, "udp-src");
16160 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16161         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16162                               UINT16);
16163 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16164         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16165                                  pos_token, "udp-dst");
16166 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16167         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16168                               UINT16);
16169 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16170         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16171                                  pos_token, "ip-src");
16172 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16173         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16174 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16175         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16176                                  pos_token, "ip-dst");
16177 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16178         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16179 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16180         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16181                                  pos_token, "vlan-tci");
16182 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16183         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16184                               UINT16);
16185 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16186         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16187                                  pos_token, "eth-src");
16188 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16189         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16190                                     eth_src);
16191 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16193                                  pos_token, "eth-dst");
16194 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16195         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16196                                     eth_dst);
16197
16198 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16199         __rte_unused struct cmdline *cl,
16200         __rte_unused void *data)
16201 {
16202         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16203         union {
16204                 uint32_t mplsoudp_label;
16205                 uint8_t label[4];
16206         } id = {
16207                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16208         };
16209
16210         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16211                 mplsoudp_encap_conf.select_vlan = 0;
16212         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16213                 mplsoudp_encap_conf.select_vlan = 1;
16214         if (strcmp(res->ip_version, "ipv4") == 0)
16215                 mplsoudp_encap_conf.select_ipv4 = 1;
16216         else if (strcmp(res->ip_version, "ipv6") == 0)
16217                 mplsoudp_encap_conf.select_ipv4 = 0;
16218         else
16219                 return;
16220         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16221         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16222         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16223         if (mplsoudp_encap_conf.select_ipv4) {
16224                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16225                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16226         } else {
16227                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16228                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16229         }
16230         if (mplsoudp_encap_conf.select_vlan)
16231                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16232         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16233                    RTE_ETHER_ADDR_LEN);
16234         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16235                    RTE_ETHER_ADDR_LEN);
16236 }
16237
16238 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16239         .f = cmd_set_mplsoudp_encap_parsed,
16240         .data = NULL,
16241         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16242                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16243                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16244         .tokens = {
16245                 (void *)&cmd_set_mplsoudp_encap_set,
16246                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16247                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16248                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16249                 (void *)&cmd_set_mplsoudp_encap_label,
16250                 (void *)&cmd_set_mplsoudp_encap_label_value,
16251                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16252                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16253                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16254                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16255                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16256                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16257                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16258                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16259                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16260                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16261                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16262                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16263                 NULL,
16264         },
16265 };
16266
16267 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16268         .f = cmd_set_mplsoudp_encap_parsed,
16269         .data = NULL,
16270         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16271                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16272                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16273                 " eth-src <eth-src> eth-dst <eth-dst>",
16274         .tokens = {
16275                 (void *)&cmd_set_mplsoudp_encap_set,
16276                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16277                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16278                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16279                 (void *)&cmd_set_mplsoudp_encap_label,
16280                 (void *)&cmd_set_mplsoudp_encap_label_value,
16281                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16282                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16283                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16284                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16285                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16286                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16287                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16288                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16289                 (void *)&cmd_set_mplsoudp_encap_vlan,
16290                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16291                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16292                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16293                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16294                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16295                 NULL,
16296         },
16297 };
16298
16299 /** Set MPLSoUDP decapsulation details */
16300 struct cmd_set_mplsoudp_decap_result {
16301         cmdline_fixed_string_t set;
16302         cmdline_fixed_string_t mplsoudp;
16303         cmdline_fixed_string_t pos_token;
16304         cmdline_fixed_string_t ip_version;
16305         uint32_t vlan_present:1;
16306 };
16307
16308 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16309         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16310                                  "set");
16311 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16312         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16313                                  "mplsoudp_decap");
16314 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16315         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16316                                  mplsoudp, "mplsoudp_decap-with-vlan");
16317 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16318         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16319                                  pos_token, "ip-version");
16320 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16321         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16322                                  ip_version, "ipv4#ipv6");
16323
16324 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16325         __rte_unused struct cmdline *cl,
16326         __rte_unused void *data)
16327 {
16328         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16329
16330         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16331                 mplsoudp_decap_conf.select_vlan = 0;
16332         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16333                 mplsoudp_decap_conf.select_vlan = 1;
16334         if (strcmp(res->ip_version, "ipv4") == 0)
16335                 mplsoudp_decap_conf.select_ipv4 = 1;
16336         else if (strcmp(res->ip_version, "ipv6") == 0)
16337                 mplsoudp_decap_conf.select_ipv4 = 0;
16338 }
16339
16340 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16341         .f = cmd_set_mplsoudp_decap_parsed,
16342         .data = NULL,
16343         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16344         .tokens = {
16345                 (void *)&cmd_set_mplsoudp_decap_set,
16346                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16347                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16348                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16349                 NULL,
16350         },
16351 };
16352
16353 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16354         .f = cmd_set_mplsoudp_decap_parsed,
16355         .data = NULL,
16356         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16357         .tokens = {
16358                 (void *)&cmd_set_mplsoudp_decap_set,
16359                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16360                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16361                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16362                 NULL,
16363         },
16364 };
16365
16366 /* Strict link priority scheduling mode setting */
16367 static void
16368 cmd_strict_link_prio_parsed(
16369         void *parsed_result,
16370         __rte_unused struct cmdline *cl,
16371         __rte_unused void *data)
16372 {
16373         struct cmd_vf_tc_bw_result *res = parsed_result;
16374         int ret = -ENOTSUP;
16375
16376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16377                 return;
16378
16379 #ifdef RTE_LIBRTE_I40E_PMD
16380         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16381 #endif
16382
16383         switch (ret) {
16384         case 0:
16385                 break;
16386         case -EINVAL:
16387                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16388                 break;
16389         case -ENODEV:
16390                 printf("invalid port_id %d\n", res->port_id);
16391                 break;
16392         case -ENOTSUP:
16393                 printf("function not implemented\n");
16394                 break;
16395         default:
16396                 printf("programming error: (%s)\n", strerror(-ret));
16397         }
16398 }
16399
16400 cmdline_parse_inst_t cmd_strict_link_prio = {
16401         .f = cmd_strict_link_prio_parsed,
16402         .data = NULL,
16403         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16404         .tokens = {
16405                 (void *)&cmd_vf_tc_bw_set,
16406                 (void *)&cmd_vf_tc_bw_tx,
16407                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16408                 (void *)&cmd_vf_tc_bw_port_id,
16409                 (void *)&cmd_vf_tc_bw_tc_map,
16410                 NULL,
16411         },
16412 };
16413
16414 /* Load dynamic device personalization*/
16415 struct cmd_ddp_add_result {
16416         cmdline_fixed_string_t ddp;
16417         cmdline_fixed_string_t add;
16418         portid_t port_id;
16419         char filepath[];
16420 };
16421
16422 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16423         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16424 cmdline_parse_token_string_t cmd_ddp_add_add =
16425         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16426 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16427         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16428 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16429         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16430
16431 static void
16432 cmd_ddp_add_parsed(
16433         void *parsed_result,
16434         __rte_unused struct cmdline *cl,
16435         __rte_unused void *data)
16436 {
16437         struct cmd_ddp_add_result *res = parsed_result;
16438         uint8_t *buff;
16439         uint32_t size;
16440         char *filepath;
16441         char *file_fld[2];
16442         int file_num;
16443         int ret = -ENOTSUP;
16444
16445         if (!all_ports_stopped()) {
16446                 printf("Please stop all ports first\n");
16447                 return;
16448         }
16449
16450         filepath = strdup(res->filepath);
16451         if (filepath == NULL) {
16452                 printf("Failed to allocate memory\n");
16453                 return;
16454         }
16455         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16456
16457         buff = open_file(file_fld[0], &size);
16458         if (!buff) {
16459                 free((void *)filepath);
16460                 return;
16461         }
16462
16463 #ifdef RTE_LIBRTE_I40E_PMD
16464         if (ret == -ENOTSUP)
16465                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16466                                                buff, size,
16467                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16468 #endif
16469
16470         if (ret == -EEXIST)
16471                 printf("Profile has already existed.\n");
16472         else if (ret < 0)
16473                 printf("Failed to load profile.\n");
16474         else if (file_num == 2)
16475                 save_file(file_fld[1], buff, size);
16476
16477         close_file(buff);
16478         free((void *)filepath);
16479 }
16480
16481 cmdline_parse_inst_t cmd_ddp_add = {
16482         .f = cmd_ddp_add_parsed,
16483         .data = NULL,
16484         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16485         .tokens = {
16486                 (void *)&cmd_ddp_add_ddp,
16487                 (void *)&cmd_ddp_add_add,
16488                 (void *)&cmd_ddp_add_port_id,
16489                 (void *)&cmd_ddp_add_filepath,
16490                 NULL,
16491         },
16492 };
16493
16494 /* Delete dynamic device personalization*/
16495 struct cmd_ddp_del_result {
16496         cmdline_fixed_string_t ddp;
16497         cmdline_fixed_string_t del;
16498         portid_t port_id;
16499         char filepath[];
16500 };
16501
16502 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16503         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16504 cmdline_parse_token_string_t cmd_ddp_del_del =
16505         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16506 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16507         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16508 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16509         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16510
16511 static void
16512 cmd_ddp_del_parsed(
16513         void *parsed_result,
16514         __rte_unused struct cmdline *cl,
16515         __rte_unused void *data)
16516 {
16517         struct cmd_ddp_del_result *res = parsed_result;
16518         uint8_t *buff;
16519         uint32_t size;
16520         int ret = -ENOTSUP;
16521
16522         if (!all_ports_stopped()) {
16523                 printf("Please stop all ports first\n");
16524                 return;
16525         }
16526
16527         buff = open_file(res->filepath, &size);
16528         if (!buff)
16529                 return;
16530
16531 #ifdef RTE_LIBRTE_I40E_PMD
16532         if (ret == -ENOTSUP)
16533                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16534                                                buff, size,
16535                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16536 #endif
16537
16538         if (ret == -EACCES)
16539                 printf("Profile does not exist.\n");
16540         else if (ret < 0)
16541                 printf("Failed to delete profile.\n");
16542
16543         close_file(buff);
16544 }
16545
16546 cmdline_parse_inst_t cmd_ddp_del = {
16547         .f = cmd_ddp_del_parsed,
16548         .data = NULL,
16549         .help_str = "ddp del <port_id> <backup_profile_path>",
16550         .tokens = {
16551                 (void *)&cmd_ddp_del_ddp,
16552                 (void *)&cmd_ddp_del_del,
16553                 (void *)&cmd_ddp_del_port_id,
16554                 (void *)&cmd_ddp_del_filepath,
16555                 NULL,
16556         },
16557 };
16558
16559 /* Get dynamic device personalization profile info */
16560 struct cmd_ddp_info_result {
16561         cmdline_fixed_string_t ddp;
16562         cmdline_fixed_string_t get;
16563         cmdline_fixed_string_t info;
16564         char filepath[];
16565 };
16566
16567 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16568         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16569 cmdline_parse_token_string_t cmd_ddp_info_get =
16570         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16571 cmdline_parse_token_string_t cmd_ddp_info_info =
16572         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16573 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16574         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16575
16576 static void
16577 cmd_ddp_info_parsed(
16578         void *parsed_result,
16579         __rte_unused struct cmdline *cl,
16580         __rte_unused void *data)
16581 {
16582         struct cmd_ddp_info_result *res = parsed_result;
16583         uint8_t *pkg;
16584         uint32_t pkg_size;
16585         int ret = -ENOTSUP;
16586 #ifdef RTE_LIBRTE_I40E_PMD
16587         uint32_t i, j, n;
16588         uint8_t *buff;
16589         uint32_t buff_size = 0;
16590         struct rte_pmd_i40e_profile_info info;
16591         uint32_t dev_num = 0;
16592         struct rte_pmd_i40e_ddp_device_id *devs;
16593         uint32_t proto_num = 0;
16594         struct rte_pmd_i40e_proto_info *proto = NULL;
16595         uint32_t pctype_num = 0;
16596         struct rte_pmd_i40e_ptype_info *pctype;
16597         uint32_t ptype_num = 0;
16598         struct rte_pmd_i40e_ptype_info *ptype;
16599         uint8_t proto_id;
16600
16601 #endif
16602
16603         pkg = open_file(res->filepath, &pkg_size);
16604         if (!pkg)
16605                 return;
16606
16607 #ifdef RTE_LIBRTE_I40E_PMD
16608         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16609                                 (uint8_t *)&info, sizeof(info),
16610                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16611         if (!ret) {
16612                 printf("Global Track id:       0x%x\n", info.track_id);
16613                 printf("Global Version:        %d.%d.%d.%d\n",
16614                         info.version.major,
16615                         info.version.minor,
16616                         info.version.update,
16617                         info.version.draft);
16618                 printf("Global Package name:   %s\n\n", info.name);
16619         }
16620
16621         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16622                                 (uint8_t *)&info, sizeof(info),
16623                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16624         if (!ret) {
16625                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16626                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16627                         info.version.major,
16628                         info.version.minor,
16629                         info.version.update,
16630                         info.version.draft);
16631                 printf("i40e Profile name:     %s\n\n", info.name);
16632         }
16633
16634         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16635                                 (uint8_t *)&buff_size, sizeof(buff_size),
16636                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16637         if (!ret && buff_size) {
16638                 buff = (uint8_t *)malloc(buff_size);
16639                 if (buff) {
16640                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16641                                                 buff, buff_size,
16642                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16643                         if (!ret)
16644                                 printf("Package Notes:\n%s\n\n", buff);
16645                         free(buff);
16646                 }
16647         }
16648
16649         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16650                                 (uint8_t *)&dev_num, sizeof(dev_num),
16651                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16652         if (!ret && dev_num) {
16653                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16654                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16655                 if (devs) {
16656                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16657                                                 (uint8_t *)devs, buff_size,
16658                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16659                         if (!ret) {
16660                                 printf("List of supported devices:\n");
16661                                 for (i = 0; i < dev_num; i++) {
16662                                         printf("  %04X:%04X %04X:%04X\n",
16663                                                 devs[i].vendor_dev_id >> 16,
16664                                                 devs[i].vendor_dev_id & 0xFFFF,
16665                                                 devs[i].sub_vendor_dev_id >> 16,
16666                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16667                                 }
16668                                 printf("\n");
16669                         }
16670                         free(devs);
16671                 }
16672         }
16673
16674         /* get information about protocols and packet types */
16675         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16676                 (uint8_t *)&proto_num, sizeof(proto_num),
16677                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16678         if (ret || !proto_num)
16679                 goto no_print_return;
16680
16681         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16682         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16683         if (!proto)
16684                 goto no_print_return;
16685
16686         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16687                                         buff_size,
16688                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16689         if (!ret) {
16690                 printf("List of used protocols:\n");
16691                 for (i = 0; i < proto_num; i++)
16692                         printf("  %2u: %s\n", proto[i].proto_id,
16693                                proto[i].name);
16694                 printf("\n");
16695         }
16696         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16697                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16698                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16699         if (ret || !pctype_num)
16700                 goto no_print_pctypes;
16701
16702         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16703         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16704         if (!pctype)
16705                 goto no_print_pctypes;
16706
16707         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16708                                         buff_size,
16709                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16710         if (ret) {
16711                 free(pctype);
16712                 goto no_print_pctypes;
16713         }
16714
16715         printf("List of defined packet classification types:\n");
16716         for (i = 0; i < pctype_num; i++) {
16717                 printf("  %2u:", pctype[i].ptype_id);
16718                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16719                         proto_id = pctype[i].protocols[j];
16720                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16721                                 for (n = 0; n < proto_num; n++) {
16722                                         if (proto[n].proto_id == proto_id) {
16723                                                 printf(" %s", proto[n].name);
16724                                                 break;
16725                                         }
16726                                 }
16727                         }
16728                 }
16729                 printf("\n");
16730         }
16731         printf("\n");
16732         free(pctype);
16733
16734 no_print_pctypes:
16735
16736         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16737                                         sizeof(ptype_num),
16738                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16739         if (ret || !ptype_num)
16740                 goto no_print_return;
16741
16742         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16743         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16744         if (!ptype)
16745                 goto no_print_return;
16746
16747         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16748                                         buff_size,
16749                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16750         if (ret) {
16751                 free(ptype);
16752                 goto no_print_return;
16753         }
16754         printf("List of defined packet types:\n");
16755         for (i = 0; i < ptype_num; i++) {
16756                 printf("  %2u:", ptype[i].ptype_id);
16757                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16758                         proto_id = ptype[i].protocols[j];
16759                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16760                                 for (n = 0; n < proto_num; n++) {
16761                                         if (proto[n].proto_id == proto_id) {
16762                                                 printf(" %s", proto[n].name);
16763                                                 break;
16764                                         }
16765                                 }
16766                         }
16767                 }
16768                 printf("\n");
16769         }
16770         free(ptype);
16771         printf("\n");
16772
16773         ret = 0;
16774 no_print_return:
16775         if (proto)
16776                 free(proto);
16777 #endif
16778         if (ret == -ENOTSUP)
16779                 printf("Function not supported in PMD driver\n");
16780         close_file(pkg);
16781 }
16782
16783 cmdline_parse_inst_t cmd_ddp_get_info = {
16784         .f = cmd_ddp_info_parsed,
16785         .data = NULL,
16786         .help_str = "ddp get info <profile_path>",
16787         .tokens = {
16788                 (void *)&cmd_ddp_info_ddp,
16789                 (void *)&cmd_ddp_info_get,
16790                 (void *)&cmd_ddp_info_info,
16791                 (void *)&cmd_ddp_info_filepath,
16792                 NULL,
16793         },
16794 };
16795
16796 /* Get dynamic device personalization profile info list*/
16797 #define PROFILE_INFO_SIZE 48
16798 #define MAX_PROFILE_NUM 16
16799
16800 struct cmd_ddp_get_list_result {
16801         cmdline_fixed_string_t ddp;
16802         cmdline_fixed_string_t get;
16803         cmdline_fixed_string_t list;
16804         portid_t port_id;
16805 };
16806
16807 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16808         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16809 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16810         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16811 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16812         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16813 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16814         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16815
16816 static void
16817 cmd_ddp_get_list_parsed(
16818         __rte_unused void *parsed_result,
16819         __rte_unused struct cmdline *cl,
16820         __rte_unused void *data)
16821 {
16822 #ifdef RTE_LIBRTE_I40E_PMD
16823         struct cmd_ddp_get_list_result *res = parsed_result;
16824         struct rte_pmd_i40e_profile_list *p_list;
16825         struct rte_pmd_i40e_profile_info *p_info;
16826         uint32_t p_num;
16827         uint32_t size;
16828         uint32_t i;
16829 #endif
16830         int ret = -ENOTSUP;
16831
16832 #ifdef RTE_LIBRTE_I40E_PMD
16833         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16834         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16835         if (!p_list) {
16836                 printf("%s: Failed to malloc buffer\n", __func__);
16837                 return;
16838         }
16839
16840         if (ret == -ENOTSUP)
16841                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16842                                                 (uint8_t *)p_list, size);
16843
16844         if (!ret) {
16845                 p_num = p_list->p_count;
16846                 printf("Profile number is: %d\n\n", p_num);
16847
16848                 for (i = 0; i < p_num; i++) {
16849                         p_info = &p_list->p_info[i];
16850                         printf("Profile %d:\n", i);
16851                         printf("Track id:     0x%x\n", p_info->track_id);
16852                         printf("Version:      %d.%d.%d.%d\n",
16853                                p_info->version.major,
16854                                p_info->version.minor,
16855                                p_info->version.update,
16856                                p_info->version.draft);
16857                         printf("Profile name: %s\n\n", p_info->name);
16858                 }
16859         }
16860
16861         free(p_list);
16862 #endif
16863
16864         if (ret < 0)
16865                 printf("Failed to get ddp list\n");
16866 }
16867
16868 cmdline_parse_inst_t cmd_ddp_get_list = {
16869         .f = cmd_ddp_get_list_parsed,
16870         .data = NULL,
16871         .help_str = "ddp get list <port_id>",
16872         .tokens = {
16873                 (void *)&cmd_ddp_get_list_ddp,
16874                 (void *)&cmd_ddp_get_list_get,
16875                 (void *)&cmd_ddp_get_list_list,
16876                 (void *)&cmd_ddp_get_list_port_id,
16877                 NULL,
16878         },
16879 };
16880
16881 /* Configure input set */
16882 struct cmd_cfg_input_set_result {
16883         cmdline_fixed_string_t port;
16884         cmdline_fixed_string_t cfg;
16885         portid_t port_id;
16886         cmdline_fixed_string_t pctype;
16887         uint8_t pctype_id;
16888         cmdline_fixed_string_t inset_type;
16889         cmdline_fixed_string_t opt;
16890         cmdline_fixed_string_t field;
16891         uint8_t field_idx;
16892 };
16893
16894 static void
16895 cmd_cfg_input_set_parsed(
16896         __rte_unused void *parsed_result,
16897         __rte_unused struct cmdline *cl,
16898         __rte_unused void *data)
16899 {
16900 #ifdef RTE_LIBRTE_I40E_PMD
16901         struct cmd_cfg_input_set_result *res = parsed_result;
16902         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
16903         struct rte_pmd_i40e_inset inset;
16904 #endif
16905         int ret = -ENOTSUP;
16906
16907         if (!all_ports_stopped()) {
16908                 printf("Please stop all ports first\n");
16909                 return;
16910         }
16911
16912 #ifdef RTE_LIBRTE_I40E_PMD
16913         if (!strcmp(res->inset_type, "hash_inset"))
16914                 inset_type = INSET_HASH;
16915         else if (!strcmp(res->inset_type, "fdir_inset"))
16916                 inset_type = INSET_FDIR;
16917         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
16918                 inset_type = INSET_FDIR_FLX;
16919         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
16920                                      &inset, inset_type);
16921         if (ret) {
16922                 printf("Failed to get input set.\n");
16923                 return;
16924         }
16925
16926         if (!strcmp(res->opt, "get")) {
16927                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
16928                                                    res->field_idx);
16929                 if (ret)
16930                         printf("Field index %d is enabled.\n", res->field_idx);
16931                 else
16932                         printf("Field index %d is disabled.\n", res->field_idx);
16933                 return;
16934         } else if (!strcmp(res->opt, "set"))
16935                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
16936                                                    res->field_idx);
16937         else if (!strcmp(res->opt, "clear"))
16938                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
16939                                                      res->field_idx);
16940         if (ret) {
16941                 printf("Failed to configure input set field.\n");
16942                 return;
16943         }
16944
16945         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
16946                                      &inset, inset_type);
16947         if (ret) {
16948                 printf("Failed to set input set.\n");
16949                 return;
16950         }
16951 #endif
16952
16953         if (ret == -ENOTSUP)
16954                 printf("Function not supported\n");
16955 }
16956
16957 cmdline_parse_token_string_t cmd_cfg_input_set_port =
16958         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16959                                  port, "port");
16960 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
16961         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16962                                  cfg, "config");
16963 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
16964         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16965                               port_id, UINT16);
16966 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
16967         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16968                                  pctype, "pctype");
16969 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
16970         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16971                               pctype_id, UINT8);
16972 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
16973         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16974                                  inset_type,
16975                                  "hash_inset#fdir_inset#fdir_flx_inset");
16976 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
16977         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16978                                  opt, "get#set#clear");
16979 cmdline_parse_token_string_t cmd_cfg_input_set_field =
16980         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
16981                                  field, "field");
16982 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
16983         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
16984                               field_idx, UINT8);
16985
16986 cmdline_parse_inst_t cmd_cfg_input_set = {
16987         .f = cmd_cfg_input_set_parsed,
16988         .data = NULL,
16989         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
16990                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
16991         .tokens = {
16992                 (void *)&cmd_cfg_input_set_port,
16993                 (void *)&cmd_cfg_input_set_cfg,
16994                 (void *)&cmd_cfg_input_set_port_id,
16995                 (void *)&cmd_cfg_input_set_pctype,
16996                 (void *)&cmd_cfg_input_set_pctype_id,
16997                 (void *)&cmd_cfg_input_set_inset_type,
16998                 (void *)&cmd_cfg_input_set_opt,
16999                 (void *)&cmd_cfg_input_set_field,
17000                 (void *)&cmd_cfg_input_set_field_idx,
17001                 NULL,
17002         },
17003 };
17004
17005 /* Clear input set */
17006 struct cmd_clear_input_set_result {
17007         cmdline_fixed_string_t port;
17008         cmdline_fixed_string_t cfg;
17009         portid_t port_id;
17010         cmdline_fixed_string_t pctype;
17011         uint8_t pctype_id;
17012         cmdline_fixed_string_t inset_type;
17013         cmdline_fixed_string_t clear;
17014         cmdline_fixed_string_t all;
17015 };
17016
17017 static void
17018 cmd_clear_input_set_parsed(
17019         __rte_unused void *parsed_result,
17020         __rte_unused struct cmdline *cl,
17021         __rte_unused void *data)
17022 {
17023 #ifdef RTE_LIBRTE_I40E_PMD
17024         struct cmd_clear_input_set_result *res = parsed_result;
17025         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17026         struct rte_pmd_i40e_inset inset;
17027 #endif
17028         int ret = -ENOTSUP;
17029
17030         if (!all_ports_stopped()) {
17031                 printf("Please stop all ports first\n");
17032                 return;
17033         }
17034
17035 #ifdef RTE_LIBRTE_I40E_PMD
17036         if (!strcmp(res->inset_type, "hash_inset"))
17037                 inset_type = INSET_HASH;
17038         else if (!strcmp(res->inset_type, "fdir_inset"))
17039                 inset_type = INSET_FDIR;
17040         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17041                 inset_type = INSET_FDIR_FLX;
17042
17043         memset(&inset, 0, sizeof(inset));
17044
17045         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17046                                      &inset, inset_type);
17047         if (ret) {
17048                 printf("Failed to clear input set.\n");
17049                 return;
17050         }
17051
17052 #endif
17053
17054         if (ret == -ENOTSUP)
17055                 printf("Function not supported\n");
17056 }
17057
17058 cmdline_parse_token_string_t cmd_clear_input_set_port =
17059         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17060                                  port, "port");
17061 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17062         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17063                                  cfg, "config");
17064 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17065         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17066                               port_id, UINT16);
17067 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17068         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17069                                  pctype, "pctype");
17070 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17071         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17072                               pctype_id, UINT8);
17073 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17074         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17075                                  inset_type,
17076                                  "hash_inset#fdir_inset#fdir_flx_inset");
17077 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17078         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17079                                  clear, "clear");
17080 cmdline_parse_token_string_t cmd_clear_input_set_all =
17081         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17082                                  all, "all");
17083
17084 cmdline_parse_inst_t cmd_clear_input_set = {
17085         .f = cmd_clear_input_set_parsed,
17086         .data = NULL,
17087         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17088                     "fdir_inset|fdir_flx_inset clear all",
17089         .tokens = {
17090                 (void *)&cmd_clear_input_set_port,
17091                 (void *)&cmd_clear_input_set_cfg,
17092                 (void *)&cmd_clear_input_set_port_id,
17093                 (void *)&cmd_clear_input_set_pctype,
17094                 (void *)&cmd_clear_input_set_pctype_id,
17095                 (void *)&cmd_clear_input_set_inset_type,
17096                 (void *)&cmd_clear_input_set_clear,
17097                 (void *)&cmd_clear_input_set_all,
17098                 NULL,
17099         },
17100 };
17101
17102 /* show vf stats */
17103
17104 /* Common result structure for show vf stats */
17105 struct cmd_show_vf_stats_result {
17106         cmdline_fixed_string_t show;
17107         cmdline_fixed_string_t vf;
17108         cmdline_fixed_string_t stats;
17109         portid_t port_id;
17110         uint16_t vf_id;
17111 };
17112
17113 /* Common CLI fields show vf stats*/
17114 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17115         TOKEN_STRING_INITIALIZER
17116                 (struct cmd_show_vf_stats_result,
17117                  show, "show");
17118 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17119         TOKEN_STRING_INITIALIZER
17120                 (struct cmd_show_vf_stats_result,
17121                  vf, "vf");
17122 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17123         TOKEN_STRING_INITIALIZER
17124                 (struct cmd_show_vf_stats_result,
17125                  stats, "stats");
17126 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17127         TOKEN_NUM_INITIALIZER
17128                 (struct cmd_show_vf_stats_result,
17129                  port_id, UINT16);
17130 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17131         TOKEN_NUM_INITIALIZER
17132                 (struct cmd_show_vf_stats_result,
17133                  vf_id, UINT16);
17134
17135 static void
17136 cmd_show_vf_stats_parsed(
17137         void *parsed_result,
17138         __rte_unused struct cmdline *cl,
17139         __rte_unused void *data)
17140 {
17141         struct cmd_show_vf_stats_result *res = parsed_result;
17142         struct rte_eth_stats stats;
17143         int ret = -ENOTSUP;
17144         static const char *nic_stats_border = "########################";
17145
17146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17147                 return;
17148
17149         memset(&stats, 0, sizeof(stats));
17150
17151 #ifdef RTE_LIBRTE_I40E_PMD
17152         if (ret == -ENOTSUP)
17153                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17154                                                 res->vf_id,
17155                                                 &stats);
17156 #endif
17157 #ifdef RTE_LIBRTE_BNXT_PMD
17158         if (ret == -ENOTSUP)
17159                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17160                                                 res->vf_id,
17161                                                 &stats);
17162 #endif
17163
17164         switch (ret) {
17165         case 0:
17166                 break;
17167         case -EINVAL:
17168                 printf("invalid vf_id %d\n", res->vf_id);
17169                 break;
17170         case -ENODEV:
17171                 printf("invalid port_id %d\n", res->port_id);
17172                 break;
17173         case -ENOTSUP:
17174                 printf("function not implemented\n");
17175                 break;
17176         default:
17177                 printf("programming error: (%s)\n", strerror(-ret));
17178         }
17179
17180         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17181                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17182
17183         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17184                "%-"PRIu64"\n",
17185                stats.ipackets, stats.imissed, stats.ibytes);
17186         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17187         printf("  RX-nombuf:  %-10"PRIu64"\n",
17188                stats.rx_nombuf);
17189         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17190                "%-"PRIu64"\n",
17191                stats.opackets, stats.oerrors, stats.obytes);
17192
17193         printf("  %s############################%s\n",
17194                                nic_stats_border, nic_stats_border);
17195 }
17196
17197 cmdline_parse_inst_t cmd_show_vf_stats = {
17198         .f = cmd_show_vf_stats_parsed,
17199         .data = NULL,
17200         .help_str = "show vf stats <port_id> <vf_id>",
17201         .tokens = {
17202                 (void *)&cmd_show_vf_stats_show,
17203                 (void *)&cmd_show_vf_stats_vf,
17204                 (void *)&cmd_show_vf_stats_stats,
17205                 (void *)&cmd_show_vf_stats_port_id,
17206                 (void *)&cmd_show_vf_stats_vf_id,
17207                 NULL,
17208         },
17209 };
17210
17211 /* clear vf stats */
17212
17213 /* Common result structure for clear vf stats */
17214 struct cmd_clear_vf_stats_result {
17215         cmdline_fixed_string_t clear;
17216         cmdline_fixed_string_t vf;
17217         cmdline_fixed_string_t stats;
17218         portid_t port_id;
17219         uint16_t vf_id;
17220 };
17221
17222 /* Common CLI fields clear vf stats*/
17223 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17224         TOKEN_STRING_INITIALIZER
17225                 (struct cmd_clear_vf_stats_result,
17226                  clear, "clear");
17227 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17228         TOKEN_STRING_INITIALIZER
17229                 (struct cmd_clear_vf_stats_result,
17230                  vf, "vf");
17231 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17232         TOKEN_STRING_INITIALIZER
17233                 (struct cmd_clear_vf_stats_result,
17234                  stats, "stats");
17235 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17236         TOKEN_NUM_INITIALIZER
17237                 (struct cmd_clear_vf_stats_result,
17238                  port_id, UINT16);
17239 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17240         TOKEN_NUM_INITIALIZER
17241                 (struct cmd_clear_vf_stats_result,
17242                  vf_id, UINT16);
17243
17244 static void
17245 cmd_clear_vf_stats_parsed(
17246         void *parsed_result,
17247         __rte_unused struct cmdline *cl,
17248         __rte_unused void *data)
17249 {
17250         struct cmd_clear_vf_stats_result *res = parsed_result;
17251         int ret = -ENOTSUP;
17252
17253         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17254                 return;
17255
17256 #ifdef RTE_LIBRTE_I40E_PMD
17257         if (ret == -ENOTSUP)
17258                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17259                                                   res->vf_id);
17260 #endif
17261 #ifdef RTE_LIBRTE_BNXT_PMD
17262         if (ret == -ENOTSUP)
17263                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17264                                                   res->vf_id);
17265 #endif
17266
17267         switch (ret) {
17268         case 0:
17269                 break;
17270         case -EINVAL:
17271                 printf("invalid vf_id %d\n", res->vf_id);
17272                 break;
17273         case -ENODEV:
17274                 printf("invalid port_id %d\n", res->port_id);
17275                 break;
17276         case -ENOTSUP:
17277                 printf("function not implemented\n");
17278                 break;
17279         default:
17280                 printf("programming error: (%s)\n", strerror(-ret));
17281         }
17282 }
17283
17284 cmdline_parse_inst_t cmd_clear_vf_stats = {
17285         .f = cmd_clear_vf_stats_parsed,
17286         .data = NULL,
17287         .help_str = "clear vf stats <port_id> <vf_id>",
17288         .tokens = {
17289                 (void *)&cmd_clear_vf_stats_clear,
17290                 (void *)&cmd_clear_vf_stats_vf,
17291                 (void *)&cmd_clear_vf_stats_stats,
17292                 (void *)&cmd_clear_vf_stats_port_id,
17293                 (void *)&cmd_clear_vf_stats_vf_id,
17294                 NULL,
17295         },
17296 };
17297
17298 /* port config pctype mapping reset */
17299
17300 /* Common result structure for port config pctype mapping reset */
17301 struct cmd_pctype_mapping_reset_result {
17302         cmdline_fixed_string_t port;
17303         cmdline_fixed_string_t config;
17304         portid_t port_id;
17305         cmdline_fixed_string_t pctype;
17306         cmdline_fixed_string_t mapping;
17307         cmdline_fixed_string_t reset;
17308 };
17309
17310 /* Common CLI fields for port config pctype mapping reset*/
17311 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17312         TOKEN_STRING_INITIALIZER
17313                 (struct cmd_pctype_mapping_reset_result,
17314                  port, "port");
17315 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17316         TOKEN_STRING_INITIALIZER
17317                 (struct cmd_pctype_mapping_reset_result,
17318                  config, "config");
17319 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17320         TOKEN_NUM_INITIALIZER
17321                 (struct cmd_pctype_mapping_reset_result,
17322                  port_id, UINT16);
17323 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17324         TOKEN_STRING_INITIALIZER
17325                 (struct cmd_pctype_mapping_reset_result,
17326                  pctype, "pctype");
17327 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17328         TOKEN_STRING_INITIALIZER
17329                 (struct cmd_pctype_mapping_reset_result,
17330                  mapping, "mapping");
17331 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17332         TOKEN_STRING_INITIALIZER
17333                 (struct cmd_pctype_mapping_reset_result,
17334                  reset, "reset");
17335
17336 static void
17337 cmd_pctype_mapping_reset_parsed(
17338         void *parsed_result,
17339         __rte_unused struct cmdline *cl,
17340         __rte_unused void *data)
17341 {
17342         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17343         int ret = -ENOTSUP;
17344
17345         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17346                 return;
17347
17348 #ifdef RTE_LIBRTE_I40E_PMD
17349         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17350 #endif
17351
17352         switch (ret) {
17353         case 0:
17354                 break;
17355         case -ENODEV:
17356                 printf("invalid port_id %d\n", res->port_id);
17357                 break;
17358         case -ENOTSUP:
17359                 printf("function not implemented\n");
17360                 break;
17361         default:
17362                 printf("programming error: (%s)\n", strerror(-ret));
17363         }
17364 }
17365
17366 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17367         .f = cmd_pctype_mapping_reset_parsed,
17368         .data = NULL,
17369         .help_str = "port config <port_id> pctype mapping reset",
17370         .tokens = {
17371                 (void *)&cmd_pctype_mapping_reset_port,
17372                 (void *)&cmd_pctype_mapping_reset_config,
17373                 (void *)&cmd_pctype_mapping_reset_port_id,
17374                 (void *)&cmd_pctype_mapping_reset_pctype,
17375                 (void *)&cmd_pctype_mapping_reset_mapping,
17376                 (void *)&cmd_pctype_mapping_reset_reset,
17377                 NULL,
17378         },
17379 };
17380
17381 /* show port pctype mapping */
17382
17383 /* Common result structure for show port pctype mapping */
17384 struct cmd_pctype_mapping_get_result {
17385         cmdline_fixed_string_t show;
17386         cmdline_fixed_string_t port;
17387         portid_t port_id;
17388         cmdline_fixed_string_t pctype;
17389         cmdline_fixed_string_t mapping;
17390 };
17391
17392 /* Common CLI fields for pctype mapping get */
17393 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17394         TOKEN_STRING_INITIALIZER
17395                 (struct cmd_pctype_mapping_get_result,
17396                  show, "show");
17397 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17398         TOKEN_STRING_INITIALIZER
17399                 (struct cmd_pctype_mapping_get_result,
17400                  port, "port");
17401 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17402         TOKEN_NUM_INITIALIZER
17403                 (struct cmd_pctype_mapping_get_result,
17404                  port_id, UINT16);
17405 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17406         TOKEN_STRING_INITIALIZER
17407                 (struct cmd_pctype_mapping_get_result,
17408                  pctype, "pctype");
17409 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17410         TOKEN_STRING_INITIALIZER
17411                 (struct cmd_pctype_mapping_get_result,
17412                  mapping, "mapping");
17413
17414 static void
17415 cmd_pctype_mapping_get_parsed(
17416         void *parsed_result,
17417         __rte_unused struct cmdline *cl,
17418         __rte_unused void *data)
17419 {
17420         struct cmd_pctype_mapping_get_result *res = parsed_result;
17421         int ret = -ENOTSUP;
17422 #ifdef RTE_LIBRTE_I40E_PMD
17423         struct rte_pmd_i40e_flow_type_mapping
17424                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17425         int i, j, first_pctype;
17426 #endif
17427
17428         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17429                 return;
17430
17431 #ifdef RTE_LIBRTE_I40E_PMD
17432         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17433 #endif
17434
17435         switch (ret) {
17436         case 0:
17437                 break;
17438         case -ENODEV:
17439                 printf("invalid port_id %d\n", res->port_id);
17440                 return;
17441         case -ENOTSUP:
17442                 printf("function not implemented\n");
17443                 return;
17444         default:
17445                 printf("programming error: (%s)\n", strerror(-ret));
17446                 return;
17447         }
17448
17449 #ifdef RTE_LIBRTE_I40E_PMD
17450         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17451                 if (mapping[i].pctype != 0ULL) {
17452                         first_pctype = 1;
17453
17454                         printf("pctype: ");
17455                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17456                                 if (mapping[i].pctype & (1ULL << j)) {
17457                                         printf(first_pctype ?
17458                                                "%02d" : ",%02d", j);
17459                                         first_pctype = 0;
17460                                 }
17461                         }
17462                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17463                 }
17464         }
17465 #endif
17466 }
17467
17468 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17469         .f = cmd_pctype_mapping_get_parsed,
17470         .data = NULL,
17471         .help_str = "show port <port_id> pctype mapping",
17472         .tokens = {
17473                 (void *)&cmd_pctype_mapping_get_show,
17474                 (void *)&cmd_pctype_mapping_get_port,
17475                 (void *)&cmd_pctype_mapping_get_port_id,
17476                 (void *)&cmd_pctype_mapping_get_pctype,
17477                 (void *)&cmd_pctype_mapping_get_mapping,
17478                 NULL,
17479         },
17480 };
17481
17482 /* port config pctype mapping update */
17483
17484 /* Common result structure for port config pctype mapping update */
17485 struct cmd_pctype_mapping_update_result {
17486         cmdline_fixed_string_t port;
17487         cmdline_fixed_string_t config;
17488         portid_t port_id;
17489         cmdline_fixed_string_t pctype;
17490         cmdline_fixed_string_t mapping;
17491         cmdline_fixed_string_t update;
17492         cmdline_fixed_string_t pctype_list;
17493         uint16_t flow_type;
17494 };
17495
17496 /* Common CLI fields for pctype mapping update*/
17497 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17498         TOKEN_STRING_INITIALIZER
17499                 (struct cmd_pctype_mapping_update_result,
17500                  port, "port");
17501 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17502         TOKEN_STRING_INITIALIZER
17503                 (struct cmd_pctype_mapping_update_result,
17504                  config, "config");
17505 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17506         TOKEN_NUM_INITIALIZER
17507                 (struct cmd_pctype_mapping_update_result,
17508                  port_id, UINT16);
17509 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17510         TOKEN_STRING_INITIALIZER
17511                 (struct cmd_pctype_mapping_update_result,
17512                  pctype, "pctype");
17513 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17514         TOKEN_STRING_INITIALIZER
17515                 (struct cmd_pctype_mapping_update_result,
17516                  mapping, "mapping");
17517 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17518         TOKEN_STRING_INITIALIZER
17519                 (struct cmd_pctype_mapping_update_result,
17520                  update, "update");
17521 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17522         TOKEN_STRING_INITIALIZER
17523                 (struct cmd_pctype_mapping_update_result,
17524                  pctype_list, NULL);
17525 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17526         TOKEN_NUM_INITIALIZER
17527                 (struct cmd_pctype_mapping_update_result,
17528                  flow_type, UINT16);
17529
17530 static void
17531 cmd_pctype_mapping_update_parsed(
17532         void *parsed_result,
17533         __rte_unused struct cmdline *cl,
17534         __rte_unused void *data)
17535 {
17536         struct cmd_pctype_mapping_update_result *res = parsed_result;
17537         int ret = -ENOTSUP;
17538 #ifdef RTE_LIBRTE_I40E_PMD
17539         struct rte_pmd_i40e_flow_type_mapping mapping;
17540         unsigned int i;
17541         unsigned int nb_item;
17542         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17543 #endif
17544
17545         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17546                 return;
17547
17548 #ifdef RTE_LIBRTE_I40E_PMD
17549         nb_item = parse_item_list(res->pctype_list, "pctypes",
17550                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17551         mapping.flow_type = res->flow_type;
17552         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17553                 mapping.pctype |= (1ULL << pctype_list[i]);
17554         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17555                                                 &mapping,
17556                                                 1,
17557                                                 0);
17558 #endif
17559
17560         switch (ret) {
17561         case 0:
17562                 break;
17563         case -EINVAL:
17564                 printf("invalid pctype or flow type\n");
17565                 break;
17566         case -ENODEV:
17567                 printf("invalid port_id %d\n", res->port_id);
17568                 break;
17569         case -ENOTSUP:
17570                 printf("function not implemented\n");
17571                 break;
17572         default:
17573                 printf("programming error: (%s)\n", strerror(-ret));
17574         }
17575 }
17576
17577 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17578         .f = cmd_pctype_mapping_update_parsed,
17579         .data = NULL,
17580         .help_str = "port config <port_id> pctype mapping update"
17581         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17582         .tokens = {
17583                 (void *)&cmd_pctype_mapping_update_port,
17584                 (void *)&cmd_pctype_mapping_update_config,
17585                 (void *)&cmd_pctype_mapping_update_port_id,
17586                 (void *)&cmd_pctype_mapping_update_pctype,
17587                 (void *)&cmd_pctype_mapping_update_mapping,
17588                 (void *)&cmd_pctype_mapping_update_update,
17589                 (void *)&cmd_pctype_mapping_update_pc_type,
17590                 (void *)&cmd_pctype_mapping_update_flow_type,
17591                 NULL,
17592         },
17593 };
17594
17595 /* ptype mapping get */
17596
17597 /* Common result structure for ptype mapping get */
17598 struct cmd_ptype_mapping_get_result {
17599         cmdline_fixed_string_t ptype;
17600         cmdline_fixed_string_t mapping;
17601         cmdline_fixed_string_t get;
17602         portid_t port_id;
17603         uint8_t valid_only;
17604 };
17605
17606 /* Common CLI fields for ptype mapping get */
17607 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17608         TOKEN_STRING_INITIALIZER
17609                 (struct cmd_ptype_mapping_get_result,
17610                  ptype, "ptype");
17611 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17612         TOKEN_STRING_INITIALIZER
17613                 (struct cmd_ptype_mapping_get_result,
17614                  mapping, "mapping");
17615 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17616         TOKEN_STRING_INITIALIZER
17617                 (struct cmd_ptype_mapping_get_result,
17618                  get, "get");
17619 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17620         TOKEN_NUM_INITIALIZER
17621                 (struct cmd_ptype_mapping_get_result,
17622                  port_id, UINT16);
17623 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17624         TOKEN_NUM_INITIALIZER
17625                 (struct cmd_ptype_mapping_get_result,
17626                  valid_only, UINT8);
17627
17628 static void
17629 cmd_ptype_mapping_get_parsed(
17630         void *parsed_result,
17631         __rte_unused struct cmdline *cl,
17632         __rte_unused void *data)
17633 {
17634         struct cmd_ptype_mapping_get_result *res = parsed_result;
17635         int ret = -ENOTSUP;
17636 #ifdef RTE_LIBRTE_I40E_PMD
17637         int max_ptype_num = 256;
17638         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17639         uint16_t count;
17640         int i;
17641 #endif
17642
17643         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17644                 return;
17645
17646 #ifdef RTE_LIBRTE_I40E_PMD
17647         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17648                                         mapping,
17649                                         max_ptype_num,
17650                                         &count,
17651                                         res->valid_only);
17652 #endif
17653
17654         switch (ret) {
17655         case 0:
17656                 break;
17657         case -ENODEV:
17658                 printf("invalid port_id %d\n", res->port_id);
17659                 break;
17660         case -ENOTSUP:
17661                 printf("function not implemented\n");
17662                 break;
17663         default:
17664                 printf("programming error: (%s)\n", strerror(-ret));
17665         }
17666
17667 #ifdef RTE_LIBRTE_I40E_PMD
17668         if (!ret) {
17669                 for (i = 0; i < count; i++)
17670                         printf("%3d\t0x%08x\n",
17671                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17672         }
17673 #endif
17674 }
17675
17676 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17677         .f = cmd_ptype_mapping_get_parsed,
17678         .data = NULL,
17679         .help_str = "ptype mapping get <port_id> <valid_only>",
17680         .tokens = {
17681                 (void *)&cmd_ptype_mapping_get_ptype,
17682                 (void *)&cmd_ptype_mapping_get_mapping,
17683                 (void *)&cmd_ptype_mapping_get_get,
17684                 (void *)&cmd_ptype_mapping_get_port_id,
17685                 (void *)&cmd_ptype_mapping_get_valid_only,
17686                 NULL,
17687         },
17688 };
17689
17690 /* ptype mapping replace */
17691
17692 /* Common result structure for ptype mapping replace */
17693 struct cmd_ptype_mapping_replace_result {
17694         cmdline_fixed_string_t ptype;
17695         cmdline_fixed_string_t mapping;
17696         cmdline_fixed_string_t replace;
17697         portid_t port_id;
17698         uint32_t target;
17699         uint8_t mask;
17700         uint32_t pkt_type;
17701 };
17702
17703 /* Common CLI fields for ptype mapping replace */
17704 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17705         TOKEN_STRING_INITIALIZER
17706                 (struct cmd_ptype_mapping_replace_result,
17707                  ptype, "ptype");
17708 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17709         TOKEN_STRING_INITIALIZER
17710                 (struct cmd_ptype_mapping_replace_result,
17711                  mapping, "mapping");
17712 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17713         TOKEN_STRING_INITIALIZER
17714                 (struct cmd_ptype_mapping_replace_result,
17715                  replace, "replace");
17716 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17717         TOKEN_NUM_INITIALIZER
17718                 (struct cmd_ptype_mapping_replace_result,
17719                  port_id, UINT16);
17720 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17721         TOKEN_NUM_INITIALIZER
17722                 (struct cmd_ptype_mapping_replace_result,
17723                  target, UINT32);
17724 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17725         TOKEN_NUM_INITIALIZER
17726                 (struct cmd_ptype_mapping_replace_result,
17727                  mask, UINT8);
17728 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17729         TOKEN_NUM_INITIALIZER
17730                 (struct cmd_ptype_mapping_replace_result,
17731                  pkt_type, UINT32);
17732
17733 static void
17734 cmd_ptype_mapping_replace_parsed(
17735         void *parsed_result,
17736         __rte_unused struct cmdline *cl,
17737         __rte_unused void *data)
17738 {
17739         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17740         int ret = -ENOTSUP;
17741
17742         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17743                 return;
17744
17745 #ifdef RTE_LIBRTE_I40E_PMD
17746         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17747                                         res->target,
17748                                         res->mask,
17749                                         res->pkt_type);
17750 #endif
17751
17752         switch (ret) {
17753         case 0:
17754                 break;
17755         case -EINVAL:
17756                 printf("invalid ptype 0x%8x or 0x%8x\n",
17757                                 res->target, res->pkt_type);
17758                 break;
17759         case -ENODEV:
17760                 printf("invalid port_id %d\n", res->port_id);
17761                 break;
17762         case -ENOTSUP:
17763                 printf("function not implemented\n");
17764                 break;
17765         default:
17766                 printf("programming error: (%s)\n", strerror(-ret));
17767         }
17768 }
17769
17770 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17771         .f = cmd_ptype_mapping_replace_parsed,
17772         .data = NULL,
17773         .help_str =
17774                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17775         .tokens = {
17776                 (void *)&cmd_ptype_mapping_replace_ptype,
17777                 (void *)&cmd_ptype_mapping_replace_mapping,
17778                 (void *)&cmd_ptype_mapping_replace_replace,
17779                 (void *)&cmd_ptype_mapping_replace_port_id,
17780                 (void *)&cmd_ptype_mapping_replace_target,
17781                 (void *)&cmd_ptype_mapping_replace_mask,
17782                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17783                 NULL,
17784         },
17785 };
17786
17787 /* ptype mapping reset */
17788
17789 /* Common result structure for ptype mapping reset */
17790 struct cmd_ptype_mapping_reset_result {
17791         cmdline_fixed_string_t ptype;
17792         cmdline_fixed_string_t mapping;
17793         cmdline_fixed_string_t reset;
17794         portid_t port_id;
17795 };
17796
17797 /* Common CLI fields for ptype mapping reset*/
17798 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17799         TOKEN_STRING_INITIALIZER
17800                 (struct cmd_ptype_mapping_reset_result,
17801                  ptype, "ptype");
17802 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17803         TOKEN_STRING_INITIALIZER
17804                 (struct cmd_ptype_mapping_reset_result,
17805                  mapping, "mapping");
17806 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17807         TOKEN_STRING_INITIALIZER
17808                 (struct cmd_ptype_mapping_reset_result,
17809                  reset, "reset");
17810 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17811         TOKEN_NUM_INITIALIZER
17812                 (struct cmd_ptype_mapping_reset_result,
17813                  port_id, UINT16);
17814
17815 static void
17816 cmd_ptype_mapping_reset_parsed(
17817         void *parsed_result,
17818         __rte_unused struct cmdline *cl,
17819         __rte_unused void *data)
17820 {
17821         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17822         int ret = -ENOTSUP;
17823
17824         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17825                 return;
17826
17827 #ifdef RTE_LIBRTE_I40E_PMD
17828         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17829 #endif
17830
17831         switch (ret) {
17832         case 0:
17833                 break;
17834         case -ENODEV:
17835                 printf("invalid port_id %d\n", res->port_id);
17836                 break;
17837         case -ENOTSUP:
17838                 printf("function not implemented\n");
17839                 break;
17840         default:
17841                 printf("programming error: (%s)\n", strerror(-ret));
17842         }
17843 }
17844
17845 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17846         .f = cmd_ptype_mapping_reset_parsed,
17847         .data = NULL,
17848         .help_str = "ptype mapping reset <port_id>",
17849         .tokens = {
17850                 (void *)&cmd_ptype_mapping_reset_ptype,
17851                 (void *)&cmd_ptype_mapping_reset_mapping,
17852                 (void *)&cmd_ptype_mapping_reset_reset,
17853                 (void *)&cmd_ptype_mapping_reset_port_id,
17854                 NULL,
17855         },
17856 };
17857
17858 /* ptype mapping update */
17859
17860 /* Common result structure for ptype mapping update */
17861 struct cmd_ptype_mapping_update_result {
17862         cmdline_fixed_string_t ptype;
17863         cmdline_fixed_string_t mapping;
17864         cmdline_fixed_string_t reset;
17865         portid_t port_id;
17866         uint8_t hw_ptype;
17867         uint32_t sw_ptype;
17868 };
17869
17870 /* Common CLI fields for ptype mapping update*/
17871 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
17872         TOKEN_STRING_INITIALIZER
17873                 (struct cmd_ptype_mapping_update_result,
17874                  ptype, "ptype");
17875 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
17876         TOKEN_STRING_INITIALIZER
17877                 (struct cmd_ptype_mapping_update_result,
17878                  mapping, "mapping");
17879 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
17880         TOKEN_STRING_INITIALIZER
17881                 (struct cmd_ptype_mapping_update_result,
17882                  reset, "update");
17883 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
17884         TOKEN_NUM_INITIALIZER
17885                 (struct cmd_ptype_mapping_update_result,
17886                  port_id, UINT16);
17887 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
17888         TOKEN_NUM_INITIALIZER
17889                 (struct cmd_ptype_mapping_update_result,
17890                  hw_ptype, UINT8);
17891 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
17892         TOKEN_NUM_INITIALIZER
17893                 (struct cmd_ptype_mapping_update_result,
17894                  sw_ptype, UINT32);
17895
17896 static void
17897 cmd_ptype_mapping_update_parsed(
17898         void *parsed_result,
17899         __rte_unused struct cmdline *cl,
17900         __rte_unused void *data)
17901 {
17902         struct cmd_ptype_mapping_update_result *res = parsed_result;
17903         int ret = -ENOTSUP;
17904 #ifdef RTE_LIBRTE_I40E_PMD
17905         struct rte_pmd_i40e_ptype_mapping mapping;
17906 #endif
17907         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17908                 return;
17909
17910 #ifdef RTE_LIBRTE_I40E_PMD
17911         mapping.hw_ptype = res->hw_ptype;
17912         mapping.sw_ptype = res->sw_ptype;
17913         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
17914                                                 &mapping,
17915                                                 1,
17916                                                 0);
17917 #endif
17918
17919         switch (ret) {
17920         case 0:
17921                 break;
17922         case -EINVAL:
17923                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
17924                 break;
17925         case -ENODEV:
17926                 printf("invalid port_id %d\n", res->port_id);
17927                 break;
17928         case -ENOTSUP:
17929                 printf("function not implemented\n");
17930                 break;
17931         default:
17932                 printf("programming error: (%s)\n", strerror(-ret));
17933         }
17934 }
17935
17936 cmdline_parse_inst_t cmd_ptype_mapping_update = {
17937         .f = cmd_ptype_mapping_update_parsed,
17938         .data = NULL,
17939         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
17940         .tokens = {
17941                 (void *)&cmd_ptype_mapping_update_ptype,
17942                 (void *)&cmd_ptype_mapping_update_mapping,
17943                 (void *)&cmd_ptype_mapping_update_update,
17944                 (void *)&cmd_ptype_mapping_update_port_id,
17945                 (void *)&cmd_ptype_mapping_update_hw_ptype,
17946                 (void *)&cmd_ptype_mapping_update_sw_ptype,
17947                 NULL,
17948         },
17949 };
17950
17951 /* Common result structure for file commands */
17952 struct cmd_cmdfile_result {
17953         cmdline_fixed_string_t load;
17954         cmdline_fixed_string_t filename;
17955 };
17956
17957 /* Common CLI fields for file commands */
17958 cmdline_parse_token_string_t cmd_load_cmdfile =
17959         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
17960 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
17961         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
17962
17963 static void
17964 cmd_load_from_file_parsed(
17965         void *parsed_result,
17966         __rte_unused struct cmdline *cl,
17967         __rte_unused void *data)
17968 {
17969         struct cmd_cmdfile_result *res = parsed_result;
17970
17971         cmdline_read_from_file(res->filename);
17972 }
17973
17974 cmdline_parse_inst_t cmd_load_from_file = {
17975         .f = cmd_load_from_file_parsed,
17976         .data = NULL,
17977         .help_str = "load <filename>",
17978         .tokens = {
17979                 (void *)&cmd_load_cmdfile,
17980                 (void *)&cmd_load_cmdfile_filename,
17981                 NULL,
17982         },
17983 };
17984
17985 /* Get Rx offloads capabilities */
17986 struct cmd_rx_offload_get_capa_result {
17987         cmdline_fixed_string_t show;
17988         cmdline_fixed_string_t port;
17989         portid_t port_id;
17990         cmdline_fixed_string_t rx_offload;
17991         cmdline_fixed_string_t capabilities;
17992 };
17993
17994 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
17995         TOKEN_STRING_INITIALIZER
17996                 (struct cmd_rx_offload_get_capa_result,
17997                  show, "show");
17998 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
17999         TOKEN_STRING_INITIALIZER
18000                 (struct cmd_rx_offload_get_capa_result,
18001                  port, "port");
18002 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18003         TOKEN_NUM_INITIALIZER
18004                 (struct cmd_rx_offload_get_capa_result,
18005                  port_id, UINT16);
18006 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18007         TOKEN_STRING_INITIALIZER
18008                 (struct cmd_rx_offload_get_capa_result,
18009                  rx_offload, "rx_offload");
18010 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18011         TOKEN_STRING_INITIALIZER
18012                 (struct cmd_rx_offload_get_capa_result,
18013                  capabilities, "capabilities");
18014
18015 static void
18016 print_rx_offloads(uint64_t offloads)
18017 {
18018         uint64_t single_offload;
18019         int begin;
18020         int end;
18021         int bit;
18022
18023         if (offloads == 0)
18024                 return;
18025
18026         begin = __builtin_ctzll(offloads);
18027         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18028
18029         single_offload = 1ULL << begin;
18030         for (bit = begin; bit < end; bit++) {
18031                 if (offloads & single_offload)
18032                         printf(" %s",
18033                                rte_eth_dev_rx_offload_name(single_offload));
18034                 single_offload <<= 1;
18035         }
18036 }
18037
18038 static void
18039 cmd_rx_offload_get_capa_parsed(
18040         void *parsed_result,
18041         __rte_unused struct cmdline *cl,
18042         __rte_unused void *data)
18043 {
18044         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18045         struct rte_eth_dev_info dev_info;
18046         portid_t port_id = res->port_id;
18047         uint64_t queue_offloads;
18048         uint64_t port_offloads;
18049         int ret;
18050
18051         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18052         if (ret != 0)
18053                 return;
18054
18055         queue_offloads = dev_info.rx_queue_offload_capa;
18056         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18057
18058         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18059         printf("  Per Queue :");
18060         print_rx_offloads(queue_offloads);
18061
18062         printf("\n");
18063         printf("  Per Port  :");
18064         print_rx_offloads(port_offloads);
18065         printf("\n\n");
18066 }
18067
18068 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18069         .f = cmd_rx_offload_get_capa_parsed,
18070         .data = NULL,
18071         .help_str = "show port <port_id> rx_offload capabilities",
18072         .tokens = {
18073                 (void *)&cmd_rx_offload_get_capa_show,
18074                 (void *)&cmd_rx_offload_get_capa_port,
18075                 (void *)&cmd_rx_offload_get_capa_port_id,
18076                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18077                 (void *)&cmd_rx_offload_get_capa_capabilities,
18078                 NULL,
18079         }
18080 };
18081
18082 /* Get Rx offloads configuration */
18083 struct cmd_rx_offload_get_configuration_result {
18084         cmdline_fixed_string_t show;
18085         cmdline_fixed_string_t port;
18086         portid_t port_id;
18087         cmdline_fixed_string_t rx_offload;
18088         cmdline_fixed_string_t configuration;
18089 };
18090
18091 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18092         TOKEN_STRING_INITIALIZER
18093                 (struct cmd_rx_offload_get_configuration_result,
18094                  show, "show");
18095 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18096         TOKEN_STRING_INITIALIZER
18097                 (struct cmd_rx_offload_get_configuration_result,
18098                  port, "port");
18099 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18100         TOKEN_NUM_INITIALIZER
18101                 (struct cmd_rx_offload_get_configuration_result,
18102                  port_id, UINT16);
18103 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18104         TOKEN_STRING_INITIALIZER
18105                 (struct cmd_rx_offload_get_configuration_result,
18106                  rx_offload, "rx_offload");
18107 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18108         TOKEN_STRING_INITIALIZER
18109                 (struct cmd_rx_offload_get_configuration_result,
18110                  configuration, "configuration");
18111
18112 static void
18113 cmd_rx_offload_get_configuration_parsed(
18114         void *parsed_result,
18115         __rte_unused struct cmdline *cl,
18116         __rte_unused void *data)
18117 {
18118         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18119         struct rte_eth_dev_info dev_info;
18120         portid_t port_id = res->port_id;
18121         struct rte_port *port = &ports[port_id];
18122         uint64_t port_offloads;
18123         uint64_t queue_offloads;
18124         uint16_t nb_rx_queues;
18125         int q;
18126         int ret;
18127
18128         printf("Rx Offloading Configuration of port %d :\n", port_id);
18129
18130         port_offloads = port->dev_conf.rxmode.offloads;
18131         printf("  Port :");
18132         print_rx_offloads(port_offloads);
18133         printf("\n");
18134
18135         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18136         if (ret != 0)
18137                 return;
18138
18139         nb_rx_queues = dev_info.nb_rx_queues;
18140         for (q = 0; q < nb_rx_queues; q++) {
18141                 queue_offloads = port->rx_conf[q].offloads;
18142                 printf("  Queue[%2d] :", q);
18143                 print_rx_offloads(queue_offloads);
18144                 printf("\n");
18145         }
18146         printf("\n");
18147 }
18148
18149 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18150         .f = cmd_rx_offload_get_configuration_parsed,
18151         .data = NULL,
18152         .help_str = "show port <port_id> rx_offload configuration",
18153         .tokens = {
18154                 (void *)&cmd_rx_offload_get_configuration_show,
18155                 (void *)&cmd_rx_offload_get_configuration_port,
18156                 (void *)&cmd_rx_offload_get_configuration_port_id,
18157                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18158                 (void *)&cmd_rx_offload_get_configuration_configuration,
18159                 NULL,
18160         }
18161 };
18162
18163 /* Enable/Disable a per port offloading */
18164 struct cmd_config_per_port_rx_offload_result {
18165         cmdline_fixed_string_t port;
18166         cmdline_fixed_string_t config;
18167         portid_t port_id;
18168         cmdline_fixed_string_t rx_offload;
18169         cmdline_fixed_string_t offload;
18170         cmdline_fixed_string_t on_off;
18171 };
18172
18173 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18174         TOKEN_STRING_INITIALIZER
18175                 (struct cmd_config_per_port_rx_offload_result,
18176                  port, "port");
18177 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18178         TOKEN_STRING_INITIALIZER
18179                 (struct cmd_config_per_port_rx_offload_result,
18180                  config, "config");
18181 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18182         TOKEN_NUM_INITIALIZER
18183                 (struct cmd_config_per_port_rx_offload_result,
18184                  port_id, UINT16);
18185 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18186         TOKEN_STRING_INITIALIZER
18187                 (struct cmd_config_per_port_rx_offload_result,
18188                  rx_offload, "rx_offload");
18189 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18190         TOKEN_STRING_INITIALIZER
18191                 (struct cmd_config_per_port_rx_offload_result,
18192                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18193                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18194                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18195                            "scatter#timestamp#security#keep_crc#rss_hash");
18196 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18197         TOKEN_STRING_INITIALIZER
18198                 (struct cmd_config_per_port_rx_offload_result,
18199                  on_off, "on#off");
18200
18201 static uint64_t
18202 search_rx_offload(const char *name)
18203 {
18204         uint64_t single_offload;
18205         const char *single_name;
18206         int found = 0;
18207         unsigned int bit;
18208
18209         single_offload = 1;
18210         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18211                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18212                 if (!strcasecmp(single_name, name)) {
18213                         found = 1;
18214                         break;
18215                 }
18216                 single_offload <<= 1;
18217         }
18218
18219         if (found)
18220                 return single_offload;
18221
18222         return 0;
18223 }
18224
18225 static void
18226 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18227                                 __rte_unused struct cmdline *cl,
18228                                 __rte_unused void *data)
18229 {
18230         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18231         portid_t port_id = res->port_id;
18232         struct rte_eth_dev_info dev_info;
18233         struct rte_port *port = &ports[port_id];
18234         uint64_t single_offload;
18235         uint16_t nb_rx_queues;
18236         int q;
18237         int ret;
18238
18239         if (port->port_status != RTE_PORT_STOPPED) {
18240                 printf("Error: Can't config offload when Port %d "
18241                        "is not stopped\n", port_id);
18242                 return;
18243         }
18244
18245         single_offload = search_rx_offload(res->offload);
18246         if (single_offload == 0) {
18247                 printf("Unknown offload name: %s\n", res->offload);
18248                 return;
18249         }
18250
18251         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18252         if (ret != 0)
18253                 return;
18254
18255         nb_rx_queues = dev_info.nb_rx_queues;
18256         if (!strcmp(res->on_off, "on")) {
18257                 port->dev_conf.rxmode.offloads |= single_offload;
18258                 for (q = 0; q < nb_rx_queues; q++)
18259                         port->rx_conf[q].offloads |= single_offload;
18260         } else {
18261                 port->dev_conf.rxmode.offloads &= ~single_offload;
18262                 for (q = 0; q < nb_rx_queues; q++)
18263                         port->rx_conf[q].offloads &= ~single_offload;
18264         }
18265
18266         cmd_reconfig_device_queue(port_id, 1, 1);
18267 }
18268
18269 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18270         .f = cmd_config_per_port_rx_offload_parsed,
18271         .data = NULL,
18272         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18273                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18274                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18275                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18276                     "on|off",
18277         .tokens = {
18278                 (void *)&cmd_config_per_port_rx_offload_result_port,
18279                 (void *)&cmd_config_per_port_rx_offload_result_config,
18280                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18281                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18282                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18283                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18284                 NULL,
18285         }
18286 };
18287
18288 /* Enable/Disable a per queue offloading */
18289 struct cmd_config_per_queue_rx_offload_result {
18290         cmdline_fixed_string_t port;
18291         portid_t port_id;
18292         cmdline_fixed_string_t rxq;
18293         uint16_t queue_id;
18294         cmdline_fixed_string_t rx_offload;
18295         cmdline_fixed_string_t offload;
18296         cmdline_fixed_string_t on_off;
18297 };
18298
18299 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18300         TOKEN_STRING_INITIALIZER
18301                 (struct cmd_config_per_queue_rx_offload_result,
18302                  port, "port");
18303 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18304         TOKEN_NUM_INITIALIZER
18305                 (struct cmd_config_per_queue_rx_offload_result,
18306                  port_id, UINT16);
18307 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18308         TOKEN_STRING_INITIALIZER
18309                 (struct cmd_config_per_queue_rx_offload_result,
18310                  rxq, "rxq");
18311 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18312         TOKEN_NUM_INITIALIZER
18313                 (struct cmd_config_per_queue_rx_offload_result,
18314                  queue_id, UINT16);
18315 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18316         TOKEN_STRING_INITIALIZER
18317                 (struct cmd_config_per_queue_rx_offload_result,
18318                  rx_offload, "rx_offload");
18319 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18320         TOKEN_STRING_INITIALIZER
18321                 (struct cmd_config_per_queue_rx_offload_result,
18322                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18323                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18324                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18325                            "scatter#timestamp#security#keep_crc");
18326 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18327         TOKEN_STRING_INITIALIZER
18328                 (struct cmd_config_per_queue_rx_offload_result,
18329                  on_off, "on#off");
18330
18331 static void
18332 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18333                                 __rte_unused struct cmdline *cl,
18334                                 __rte_unused void *data)
18335 {
18336         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18337         struct rte_eth_dev_info dev_info;
18338         portid_t port_id = res->port_id;
18339         uint16_t queue_id = res->queue_id;
18340         struct rte_port *port = &ports[port_id];
18341         uint64_t single_offload;
18342         int ret;
18343
18344         if (port->port_status != RTE_PORT_STOPPED) {
18345                 printf("Error: Can't config offload when Port %d "
18346                        "is not stopped\n", port_id);
18347                 return;
18348         }
18349
18350         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18351         if (ret != 0)
18352                 return;
18353
18354         if (queue_id >= dev_info.nb_rx_queues) {
18355                 printf("Error: input queue_id should be 0 ... "
18356                        "%d\n", dev_info.nb_rx_queues - 1);
18357                 return;
18358         }
18359
18360         single_offload = search_rx_offload(res->offload);
18361         if (single_offload == 0) {
18362                 printf("Unknown offload name: %s\n", res->offload);
18363                 return;
18364         }
18365
18366         if (!strcmp(res->on_off, "on"))
18367                 port->rx_conf[queue_id].offloads |= single_offload;
18368         else
18369                 port->rx_conf[queue_id].offloads &= ~single_offload;
18370
18371         cmd_reconfig_device_queue(port_id, 1, 1);
18372 }
18373
18374 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18375         .f = cmd_config_per_queue_rx_offload_parsed,
18376         .data = NULL,
18377         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18378                     "vlan_strip|ipv4_cksum|"
18379                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18380                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18381                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18382                     "on|off",
18383         .tokens = {
18384                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18385                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18386                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18387                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18388                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18389                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18390                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18391                 NULL,
18392         }
18393 };
18394
18395 /* Get Tx offloads capabilities */
18396 struct cmd_tx_offload_get_capa_result {
18397         cmdline_fixed_string_t show;
18398         cmdline_fixed_string_t port;
18399         portid_t port_id;
18400         cmdline_fixed_string_t tx_offload;
18401         cmdline_fixed_string_t capabilities;
18402 };
18403
18404 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18405         TOKEN_STRING_INITIALIZER
18406                 (struct cmd_tx_offload_get_capa_result,
18407                  show, "show");
18408 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18409         TOKEN_STRING_INITIALIZER
18410                 (struct cmd_tx_offload_get_capa_result,
18411                  port, "port");
18412 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18413         TOKEN_NUM_INITIALIZER
18414                 (struct cmd_tx_offload_get_capa_result,
18415                  port_id, UINT16);
18416 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18417         TOKEN_STRING_INITIALIZER
18418                 (struct cmd_tx_offload_get_capa_result,
18419                  tx_offload, "tx_offload");
18420 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18421         TOKEN_STRING_INITIALIZER
18422                 (struct cmd_tx_offload_get_capa_result,
18423                  capabilities, "capabilities");
18424
18425 static void
18426 print_tx_offloads(uint64_t offloads)
18427 {
18428         uint64_t single_offload;
18429         int begin;
18430         int end;
18431         int bit;
18432
18433         if (offloads == 0)
18434                 return;
18435
18436         begin = __builtin_ctzll(offloads);
18437         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18438
18439         single_offload = 1ULL << begin;
18440         for (bit = begin; bit < end; bit++) {
18441                 if (offloads & single_offload)
18442                         printf(" %s",
18443                                rte_eth_dev_tx_offload_name(single_offload));
18444                 single_offload <<= 1;
18445         }
18446 }
18447
18448 static void
18449 cmd_tx_offload_get_capa_parsed(
18450         void *parsed_result,
18451         __rte_unused struct cmdline *cl,
18452         __rte_unused void *data)
18453 {
18454         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18455         struct rte_eth_dev_info dev_info;
18456         portid_t port_id = res->port_id;
18457         uint64_t queue_offloads;
18458         uint64_t port_offloads;
18459         int ret;
18460
18461         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18462         if (ret != 0)
18463                 return;
18464
18465         queue_offloads = dev_info.tx_queue_offload_capa;
18466         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18467
18468         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18469         printf("  Per Queue :");
18470         print_tx_offloads(queue_offloads);
18471
18472         printf("\n");
18473         printf("  Per Port  :");
18474         print_tx_offloads(port_offloads);
18475         printf("\n\n");
18476 }
18477
18478 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18479         .f = cmd_tx_offload_get_capa_parsed,
18480         .data = NULL,
18481         .help_str = "show port <port_id> tx_offload capabilities",
18482         .tokens = {
18483                 (void *)&cmd_tx_offload_get_capa_show,
18484                 (void *)&cmd_tx_offload_get_capa_port,
18485                 (void *)&cmd_tx_offload_get_capa_port_id,
18486                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18487                 (void *)&cmd_tx_offload_get_capa_capabilities,
18488                 NULL,
18489         }
18490 };
18491
18492 /* Get Tx offloads configuration */
18493 struct cmd_tx_offload_get_configuration_result {
18494         cmdline_fixed_string_t show;
18495         cmdline_fixed_string_t port;
18496         portid_t port_id;
18497         cmdline_fixed_string_t tx_offload;
18498         cmdline_fixed_string_t configuration;
18499 };
18500
18501 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18502         TOKEN_STRING_INITIALIZER
18503                 (struct cmd_tx_offload_get_configuration_result,
18504                  show, "show");
18505 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18506         TOKEN_STRING_INITIALIZER
18507                 (struct cmd_tx_offload_get_configuration_result,
18508                  port, "port");
18509 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18510         TOKEN_NUM_INITIALIZER
18511                 (struct cmd_tx_offload_get_configuration_result,
18512                  port_id, UINT16);
18513 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18514         TOKEN_STRING_INITIALIZER
18515                 (struct cmd_tx_offload_get_configuration_result,
18516                  tx_offload, "tx_offload");
18517 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18518         TOKEN_STRING_INITIALIZER
18519                 (struct cmd_tx_offload_get_configuration_result,
18520                  configuration, "configuration");
18521
18522 static void
18523 cmd_tx_offload_get_configuration_parsed(
18524         void *parsed_result,
18525         __rte_unused struct cmdline *cl,
18526         __rte_unused void *data)
18527 {
18528         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18529         struct rte_eth_dev_info dev_info;
18530         portid_t port_id = res->port_id;
18531         struct rte_port *port = &ports[port_id];
18532         uint64_t port_offloads;
18533         uint64_t queue_offloads;
18534         uint16_t nb_tx_queues;
18535         int q;
18536         int ret;
18537
18538         printf("Tx Offloading Configuration of port %d :\n", port_id);
18539
18540         port_offloads = port->dev_conf.txmode.offloads;
18541         printf("  Port :");
18542         print_tx_offloads(port_offloads);
18543         printf("\n");
18544
18545         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18546         if (ret != 0)
18547                 return;
18548
18549         nb_tx_queues = dev_info.nb_tx_queues;
18550         for (q = 0; q < nb_tx_queues; q++) {
18551                 queue_offloads = port->tx_conf[q].offloads;
18552                 printf("  Queue[%2d] :", q);
18553                 print_tx_offloads(queue_offloads);
18554                 printf("\n");
18555         }
18556         printf("\n");
18557 }
18558
18559 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18560         .f = cmd_tx_offload_get_configuration_parsed,
18561         .data = NULL,
18562         .help_str = "show port <port_id> tx_offload configuration",
18563         .tokens = {
18564                 (void *)&cmd_tx_offload_get_configuration_show,
18565                 (void *)&cmd_tx_offload_get_configuration_port,
18566                 (void *)&cmd_tx_offload_get_configuration_port_id,
18567                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18568                 (void *)&cmd_tx_offload_get_configuration_configuration,
18569                 NULL,
18570         }
18571 };
18572
18573 /* Enable/Disable a per port offloading */
18574 struct cmd_config_per_port_tx_offload_result {
18575         cmdline_fixed_string_t port;
18576         cmdline_fixed_string_t config;
18577         portid_t port_id;
18578         cmdline_fixed_string_t tx_offload;
18579         cmdline_fixed_string_t offload;
18580         cmdline_fixed_string_t on_off;
18581 };
18582
18583 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18584         TOKEN_STRING_INITIALIZER
18585                 (struct cmd_config_per_port_tx_offload_result,
18586                  port, "port");
18587 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18588         TOKEN_STRING_INITIALIZER
18589                 (struct cmd_config_per_port_tx_offload_result,
18590                  config, "config");
18591 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18592         TOKEN_NUM_INITIALIZER
18593                 (struct cmd_config_per_port_tx_offload_result,
18594                  port_id, UINT16);
18595 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18596         TOKEN_STRING_INITIALIZER
18597                 (struct cmd_config_per_port_tx_offload_result,
18598                  tx_offload, "tx_offload");
18599 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18600         TOKEN_STRING_INITIALIZER
18601                 (struct cmd_config_per_port_tx_offload_result,
18602                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18603                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18604                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18605                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18606                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18607 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18608         TOKEN_STRING_INITIALIZER
18609                 (struct cmd_config_per_port_tx_offload_result,
18610                  on_off, "on#off");
18611
18612 static uint64_t
18613 search_tx_offload(const char *name)
18614 {
18615         uint64_t single_offload;
18616         const char *single_name;
18617         int found = 0;
18618         unsigned int bit;
18619
18620         single_offload = 1;
18621         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18622                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18623                 if (single_name == NULL)
18624                         break;
18625                 if (!strcasecmp(single_name, name)) {
18626                         found = 1;
18627                         break;
18628                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18629                         break;
18630                 single_offload <<= 1;
18631         }
18632
18633         if (found)
18634                 return single_offload;
18635
18636         return 0;
18637 }
18638
18639 static void
18640 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18641                                 __rte_unused struct cmdline *cl,
18642                                 __rte_unused void *data)
18643 {
18644         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18645         portid_t port_id = res->port_id;
18646         struct rte_eth_dev_info dev_info;
18647         struct rte_port *port = &ports[port_id];
18648         uint64_t single_offload;
18649         uint16_t nb_tx_queues;
18650         int q;
18651         int ret;
18652
18653         if (port->port_status != RTE_PORT_STOPPED) {
18654                 printf("Error: Can't config offload when Port %d "
18655                        "is not stopped\n", port_id);
18656                 return;
18657         }
18658
18659         single_offload = search_tx_offload(res->offload);
18660         if (single_offload == 0) {
18661                 printf("Unknown offload name: %s\n", res->offload);
18662                 return;
18663         }
18664
18665         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18666         if (ret != 0)
18667                 return;
18668
18669         nb_tx_queues = dev_info.nb_tx_queues;
18670         if (!strcmp(res->on_off, "on")) {
18671                 port->dev_conf.txmode.offloads |= single_offload;
18672                 for (q = 0; q < nb_tx_queues; q++)
18673                         port->tx_conf[q].offloads |= single_offload;
18674         } else {
18675                 port->dev_conf.txmode.offloads &= ~single_offload;
18676                 for (q = 0; q < nb_tx_queues; q++)
18677                         port->tx_conf[q].offloads &= ~single_offload;
18678         }
18679
18680         cmd_reconfig_device_queue(port_id, 1, 1);
18681 }
18682
18683 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18684         .f = cmd_config_per_port_tx_offload_parsed,
18685         .data = NULL,
18686         .help_str = "port config <port_id> tx_offload "
18687                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18688                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18689                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18690                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18691                     "mt_lockfree|multi_segs|mbuf_fast_free|security on|off",
18692         .tokens = {
18693                 (void *)&cmd_config_per_port_tx_offload_result_port,
18694                 (void *)&cmd_config_per_port_tx_offload_result_config,
18695                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18696                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18697                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18698                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18699                 NULL,
18700         }
18701 };
18702
18703 /* Enable/Disable a per queue offloading */
18704 struct cmd_config_per_queue_tx_offload_result {
18705         cmdline_fixed_string_t port;
18706         portid_t port_id;
18707         cmdline_fixed_string_t txq;
18708         uint16_t queue_id;
18709         cmdline_fixed_string_t tx_offload;
18710         cmdline_fixed_string_t offload;
18711         cmdline_fixed_string_t on_off;
18712 };
18713
18714 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18715         TOKEN_STRING_INITIALIZER
18716                 (struct cmd_config_per_queue_tx_offload_result,
18717                  port, "port");
18718 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18719         TOKEN_NUM_INITIALIZER
18720                 (struct cmd_config_per_queue_tx_offload_result,
18721                  port_id, UINT16);
18722 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18723         TOKEN_STRING_INITIALIZER
18724                 (struct cmd_config_per_queue_tx_offload_result,
18725                  txq, "txq");
18726 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18727         TOKEN_NUM_INITIALIZER
18728                 (struct cmd_config_per_queue_tx_offload_result,
18729                  queue_id, UINT16);
18730 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18731         TOKEN_STRING_INITIALIZER
18732                 (struct cmd_config_per_queue_tx_offload_result,
18733                  tx_offload, "tx_offload");
18734 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18735         TOKEN_STRING_INITIALIZER
18736                 (struct cmd_config_per_queue_tx_offload_result,
18737                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18738                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18739                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18740                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18741                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18742 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18743         TOKEN_STRING_INITIALIZER
18744                 (struct cmd_config_per_queue_tx_offload_result,
18745                  on_off, "on#off");
18746
18747 static void
18748 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18749                                 __rte_unused struct cmdline *cl,
18750                                 __rte_unused void *data)
18751 {
18752         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18753         struct rte_eth_dev_info dev_info;
18754         portid_t port_id = res->port_id;
18755         uint16_t queue_id = res->queue_id;
18756         struct rte_port *port = &ports[port_id];
18757         uint64_t single_offload;
18758         int ret;
18759
18760         if (port->port_status != RTE_PORT_STOPPED) {
18761                 printf("Error: Can't config offload when Port %d "
18762                        "is not stopped\n", port_id);
18763                 return;
18764         }
18765
18766         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18767         if (ret != 0)
18768                 return;
18769
18770         if (queue_id >= dev_info.nb_tx_queues) {
18771                 printf("Error: input queue_id should be 0 ... "
18772                        "%d\n", dev_info.nb_tx_queues - 1);
18773                 return;
18774         }
18775
18776         single_offload = search_tx_offload(res->offload);
18777         if (single_offload == 0) {
18778                 printf("Unknown offload name: %s\n", res->offload);
18779                 return;
18780         }
18781
18782         if (!strcmp(res->on_off, "on"))
18783                 port->tx_conf[queue_id].offloads |= single_offload;
18784         else
18785                 port->tx_conf[queue_id].offloads &= ~single_offload;
18786
18787         cmd_reconfig_device_queue(port_id, 1, 1);
18788 }
18789
18790 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18791         .f = cmd_config_per_queue_tx_offload_parsed,
18792         .data = NULL,
18793         .help_str = "port <port_id> txq <queue_id> tx_offload "
18794                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18795                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18796                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18797                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18798                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18799                     "on|off",
18800         .tokens = {
18801                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18802                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18803                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18804                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18805                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18806                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18807                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18808                 NULL,
18809         }
18810 };
18811
18812 /* *** configure tx_metadata for specific port *** */
18813 struct cmd_config_tx_metadata_specific_result {
18814         cmdline_fixed_string_t port;
18815         cmdline_fixed_string_t keyword;
18816         uint16_t port_id;
18817         cmdline_fixed_string_t item;
18818         uint32_t value;
18819 };
18820
18821 static void
18822 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18823                                 __rte_unused struct cmdline *cl,
18824                                 __rte_unused void *data)
18825 {
18826         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18827
18828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18829                 return;
18830         ports[res->port_id].tx_metadata = res->value;
18831         /* Add/remove callback to insert valid metadata in every Tx packet. */
18832         if (ports[res->port_id].tx_metadata)
18833                 add_tx_md_callback(res->port_id);
18834         else
18835                 remove_tx_md_callback(res->port_id);
18836         rte_flow_dynf_metadata_register();
18837 }
18838
18839 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18840         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18841                         port, "port");
18842 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18843         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18844                         keyword, "config");
18845 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18846         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18847                         port_id, UINT16);
18848 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18849         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18850                         item, "tx_metadata");
18851 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18852         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18853                         value, UINT32);
18854
18855 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
18856         .f = cmd_config_tx_metadata_specific_parsed,
18857         .data = NULL,
18858         .help_str = "port config <port_id> tx_metadata <value>",
18859         .tokens = {
18860                 (void *)&cmd_config_tx_metadata_specific_port,
18861                 (void *)&cmd_config_tx_metadata_specific_keyword,
18862                 (void *)&cmd_config_tx_metadata_specific_id,
18863                 (void *)&cmd_config_tx_metadata_specific_item,
18864                 (void *)&cmd_config_tx_metadata_specific_value,
18865                 NULL,
18866         },
18867 };
18868
18869 /* *** set dynf *** */
18870 struct cmd_config_tx_dynf_specific_result {
18871         cmdline_fixed_string_t port;
18872         cmdline_fixed_string_t keyword;
18873         uint16_t port_id;
18874         cmdline_fixed_string_t item;
18875         cmdline_fixed_string_t name;
18876         cmdline_fixed_string_t value;
18877 };
18878
18879 static void
18880 cmd_config_dynf_specific_parsed(void *parsed_result,
18881                                 __rte_unused struct cmdline *cl,
18882                                 __rte_unused void *data)
18883 {
18884         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
18885         struct rte_mbuf_dynflag desc_flag;
18886         int flag;
18887         uint64_t old_port_flags;
18888
18889         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18890                 return;
18891         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
18892         if (flag <= 0) {
18893                 if (strlcpy(desc_flag.name, res->name,
18894                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
18895                         printf("Flag name too long\n");
18896                         return;
18897                 }
18898                 desc_flag.flags = 0;
18899                 flag = rte_mbuf_dynflag_register(&desc_flag);
18900                 if (flag < 0) {
18901                         printf("Can't register flag\n");
18902                         return;
18903                 }
18904                 strcpy(dynf_names[flag], desc_flag.name);
18905         }
18906         old_port_flags = ports[res->port_id].mbuf_dynf;
18907         if (!strcmp(res->value, "set")) {
18908                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
18909                 if (old_port_flags == 0)
18910                         add_tx_dynf_callback(res->port_id);
18911         } else {
18912                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
18913                 if (ports[res->port_id].mbuf_dynf == 0)
18914                         remove_tx_dynf_callback(res->port_id);
18915         }
18916 }
18917
18918 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
18919         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18920                         keyword, "port");
18921 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
18922         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18923                         keyword, "config");
18924 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
18925         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18926                         port_id, UINT16);
18927 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
18928         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18929                         item, "dynf");
18930 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
18931         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18932                         name, NULL);
18933 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
18934         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
18935                         value, "set#clear");
18936
18937 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
18938         .f = cmd_config_dynf_specific_parsed,
18939         .data = NULL,
18940         .help_str = "port config <port id> dynf <name> set|clear",
18941         .tokens = {
18942                 (void *)&cmd_config_tx_dynf_specific_port,
18943                 (void *)&cmd_config_tx_dynf_specific_keyword,
18944                 (void *)&cmd_config_tx_dynf_specific_port_id,
18945                 (void *)&cmd_config_tx_dynf_specific_item,
18946                 (void *)&cmd_config_tx_dynf_specific_name,
18947                 (void *)&cmd_config_tx_dynf_specific_value,
18948                 NULL,
18949         },
18950 };
18951
18952 /* *** display tx_metadata per port configuration *** */
18953 struct cmd_show_tx_metadata_result {
18954         cmdline_fixed_string_t cmd_show;
18955         cmdline_fixed_string_t cmd_port;
18956         cmdline_fixed_string_t cmd_keyword;
18957         portid_t cmd_pid;
18958 };
18959
18960 static void
18961 cmd_show_tx_metadata_parsed(void *parsed_result,
18962                 __rte_unused struct cmdline *cl,
18963                 __rte_unused void *data)
18964 {
18965         struct cmd_show_tx_metadata_result *res = parsed_result;
18966
18967         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18968                 printf("invalid port id %u\n", res->cmd_pid);
18969                 return;
18970         }
18971         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
18972                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
18973                        ports[res->cmd_pid].tx_metadata);
18974         }
18975 }
18976
18977 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
18978         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18979                         cmd_show, "show");
18980 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
18981         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18982                         cmd_port, "port");
18983 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
18984         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
18985                         cmd_pid, UINT16);
18986 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
18987         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
18988                         cmd_keyword, "tx_metadata");
18989
18990 cmdline_parse_inst_t cmd_show_tx_metadata = {
18991         .f = cmd_show_tx_metadata_parsed,
18992         .data = NULL,
18993         .help_str = "show port <port_id> tx_metadata",
18994         .tokens = {
18995                 (void *)&cmd_show_tx_metadata_show,
18996                 (void *)&cmd_show_tx_metadata_port,
18997                 (void *)&cmd_show_tx_metadata_pid,
18998                 (void *)&cmd_show_tx_metadata_keyword,
18999                 NULL,
19000         },
19001 };
19002
19003 /* show port supported ptypes */
19004
19005 /* Common result structure for show port ptypes */
19006 struct cmd_show_port_supported_ptypes_result {
19007         cmdline_fixed_string_t show;
19008         cmdline_fixed_string_t port;
19009         portid_t port_id;
19010         cmdline_fixed_string_t ptypes;
19011 };
19012
19013 /* Common CLI fields for show port ptypes */
19014 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19015         TOKEN_STRING_INITIALIZER
19016                 (struct cmd_show_port_supported_ptypes_result,
19017                  show, "show");
19018 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19019         TOKEN_STRING_INITIALIZER
19020                 (struct cmd_show_port_supported_ptypes_result,
19021                  port, "port");
19022 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19023         TOKEN_NUM_INITIALIZER
19024                 (struct cmd_show_port_supported_ptypes_result,
19025                  port_id, UINT16);
19026 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19027         TOKEN_STRING_INITIALIZER
19028                 (struct cmd_show_port_supported_ptypes_result,
19029                  ptypes, "ptypes");
19030
19031 static void
19032 cmd_show_port_supported_ptypes_parsed(
19033         void *parsed_result,
19034         __rte_unused struct cmdline *cl,
19035         __rte_unused void *data)
19036 {
19037 #define RSVD_PTYPE_MASK       0xf0000000
19038 #define MAX_PTYPES_PER_LAYER  16
19039 #define LTYPE_NAMESIZE        32
19040 #define PTYPE_NAMESIZE        256
19041         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19042         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19043         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19044         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19045         uint16_t port_id = res->port_id;
19046         int ret, i;
19047
19048         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19049         if (ret < 0)
19050                 return;
19051
19052         while (ptype_mask != RSVD_PTYPE_MASK) {
19053
19054                 switch (ptype_mask) {
19055                 case RTE_PTYPE_L2_MASK:
19056                         strlcpy(ltype, "L2", sizeof(ltype));
19057                         break;
19058                 case RTE_PTYPE_L3_MASK:
19059                         strlcpy(ltype, "L3", sizeof(ltype));
19060                         break;
19061                 case RTE_PTYPE_L4_MASK:
19062                         strlcpy(ltype, "L4", sizeof(ltype));
19063                         break;
19064                 case RTE_PTYPE_TUNNEL_MASK:
19065                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19066                         break;
19067                 case RTE_PTYPE_INNER_L2_MASK:
19068                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19069                         break;
19070                 case RTE_PTYPE_INNER_L3_MASK:
19071                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19072                         break;
19073                 case RTE_PTYPE_INNER_L4_MASK:
19074                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19075                         break;
19076                 default:
19077                         return;
19078                 }
19079
19080                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19081                                                        ptype_mask, ptypes,
19082                                                        MAX_PTYPES_PER_LAYER);
19083
19084                 if (ret > 0)
19085                         printf("Supported %s ptypes:\n", ltype);
19086                 else
19087                         printf("%s ptypes unsupported\n", ltype);
19088
19089                 for (i = 0; i < ret; ++i) {
19090                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19091                         printf("%s\n", buf);
19092                 }
19093
19094                 ptype_mask <<= 4;
19095         }
19096 }
19097
19098 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19099         .f = cmd_show_port_supported_ptypes_parsed,
19100         .data = NULL,
19101         .help_str = "show port <port_id> ptypes",
19102         .tokens = {
19103                 (void *)&cmd_show_port_supported_ptypes_show,
19104                 (void *)&cmd_show_port_supported_ptypes_port,
19105                 (void *)&cmd_show_port_supported_ptypes_port_id,
19106                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19107                 NULL,
19108         },
19109 };
19110
19111 /* *** display rx/tx descriptor status *** */
19112 struct cmd_show_rx_tx_desc_status_result {
19113         cmdline_fixed_string_t cmd_show;
19114         cmdline_fixed_string_t cmd_port;
19115         cmdline_fixed_string_t cmd_keyword;
19116         cmdline_fixed_string_t cmd_desc;
19117         cmdline_fixed_string_t cmd_status;
19118         portid_t cmd_pid;
19119         portid_t cmd_qid;
19120         portid_t cmd_did;
19121 };
19122
19123 static void
19124 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19125                 __rte_unused struct cmdline *cl,
19126                 __rte_unused void *data)
19127 {
19128         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19129         int rc;
19130
19131         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19132                 printf("invalid port id %u\n", res->cmd_pid);
19133                 return;
19134         }
19135
19136         if (!strcmp(res->cmd_keyword, "rxq")) {
19137                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19138                                              res->cmd_did);
19139                 if (rc < 0) {
19140                         printf("Invalid queueid = %d\n", res->cmd_qid);
19141                         return;
19142                 }
19143                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19144                         printf("Desc status = AVAILABLE\n");
19145                 else if (rc == RTE_ETH_RX_DESC_DONE)
19146                         printf("Desc status = DONE\n");
19147                 else
19148                         printf("Desc status = UNAVAILABLE\n");
19149         } else if (!strcmp(res->cmd_keyword, "txq")) {
19150                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19151                                              res->cmd_did);
19152                 if (rc < 0) {
19153                         printf("Invalid queueid = %d\n", res->cmd_qid);
19154                         return;
19155                 }
19156                 if (rc == RTE_ETH_TX_DESC_FULL)
19157                         printf("Desc status = FULL\n");
19158                 else if (rc == RTE_ETH_TX_DESC_DONE)
19159                         printf("Desc status = DONE\n");
19160                 else
19161                         printf("Desc status = UNAVAILABLE\n");
19162         }
19163 }
19164
19165 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19166         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19167                         cmd_show, "show");
19168 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19169         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19170                         cmd_port, "port");
19171 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19172         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19173                         cmd_pid, UINT16);
19174 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19175         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19176                         cmd_keyword, "rxq#txq");
19177 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19178         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19179                         cmd_qid, UINT16);
19180 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19181         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19182                         cmd_desc, "desc");
19183 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19184         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19185                         cmd_did, UINT16);
19186 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19187         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19188                         cmd_status, "status");
19189 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19190         .f = cmd_show_rx_tx_desc_status_parsed,
19191         .data = NULL,
19192         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19193                 "status",
19194         .tokens = {
19195                 (void *)&cmd_show_rx_tx_desc_status_show,
19196                 (void *)&cmd_show_rx_tx_desc_status_port,
19197                 (void *)&cmd_show_rx_tx_desc_status_pid,
19198                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19199                 (void *)&cmd_show_rx_tx_desc_status_qid,
19200                 (void *)&cmd_show_rx_tx_desc_status_desc,
19201                 (void *)&cmd_show_rx_tx_desc_status_did,
19202                 (void *)&cmd_show_rx_tx_desc_status_status,
19203                 NULL,
19204         },
19205 };
19206
19207 /* Common result structure for set port ptypes */
19208 struct cmd_set_port_ptypes_result {
19209         cmdline_fixed_string_t set;
19210         cmdline_fixed_string_t port;
19211         portid_t port_id;
19212         cmdline_fixed_string_t ptype_mask;
19213         uint32_t mask;
19214 };
19215
19216 /* Common CLI fields for set port ptypes */
19217 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19218         TOKEN_STRING_INITIALIZER
19219                 (struct cmd_set_port_ptypes_result,
19220                  set, "set");
19221 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19222         TOKEN_STRING_INITIALIZER
19223                 (struct cmd_set_port_ptypes_result,
19224                  port, "port");
19225 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19226         TOKEN_NUM_INITIALIZER
19227                 (struct cmd_set_port_ptypes_result,
19228                  port_id, UINT16);
19229 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19230         TOKEN_STRING_INITIALIZER
19231                 (struct cmd_set_port_ptypes_result,
19232                  ptype_mask, "ptype_mask");
19233 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19234         TOKEN_NUM_INITIALIZER
19235                 (struct cmd_set_port_ptypes_result,
19236                  mask, UINT32);
19237
19238 static void
19239 cmd_set_port_ptypes_parsed(
19240         void *parsed_result,
19241         __rte_unused struct cmdline *cl,
19242         __rte_unused void *data)
19243 {
19244         struct cmd_set_port_ptypes_result *res = parsed_result;
19245 #define PTYPE_NAMESIZE        256
19246         char ptype_name[PTYPE_NAMESIZE];
19247         uint16_t port_id = res->port_id;
19248         uint32_t ptype_mask = res->mask;
19249         int ret, i;
19250
19251         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19252                                                NULL, 0);
19253         if (ret <= 0) {
19254                 printf("Port %d doesn't support any ptypes.\n", port_id);
19255                 return;
19256         }
19257
19258         uint32_t ptypes[ret];
19259
19260         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19261         if (ret < 0) {
19262                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19263                 return;
19264         }
19265
19266         printf("Successfully set following ptypes for Port %d\n", port_id);
19267         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19268                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19269                 printf("%s\n", ptype_name);
19270         }
19271
19272         clear_ptypes = false;
19273 }
19274
19275 cmdline_parse_inst_t cmd_set_port_ptypes = {
19276         .f = cmd_set_port_ptypes_parsed,
19277         .data = NULL,
19278         .help_str = "set port <port_id> ptype_mask <mask>",
19279         .tokens = {
19280                 (void *)&cmd_set_port_ptypes_set,
19281                 (void *)&cmd_set_port_ptypes_port,
19282                 (void *)&cmd_set_port_ptypes_port_id,
19283                 (void *)&cmd_set_port_ptypes_mask_str,
19284                 (void *)&cmd_set_port_ptypes_mask_u32,
19285                 NULL,
19286         },
19287 };
19288
19289 /* *** display mac addresses added to a port *** */
19290 struct cmd_showport_macs_result {
19291         cmdline_fixed_string_t cmd_show;
19292         cmdline_fixed_string_t cmd_port;
19293         cmdline_fixed_string_t cmd_keyword;
19294         portid_t cmd_pid;
19295 };
19296
19297 static void
19298 cmd_showport_macs_parsed(void *parsed_result,
19299                 __rte_unused struct cmdline *cl,
19300                 __rte_unused void *data)
19301 {
19302         struct cmd_showport_macs_result *res = parsed_result;
19303
19304         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19305                 return;
19306
19307         if (!strcmp(res->cmd_keyword, "macs"))
19308                 show_macs(res->cmd_pid);
19309         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19310                 show_mcast_macs(res->cmd_pid);
19311 }
19312
19313 cmdline_parse_token_string_t cmd_showport_macs_show =
19314         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19315                         cmd_show, "show");
19316 cmdline_parse_token_string_t cmd_showport_macs_port =
19317         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19318                         cmd_port, "port");
19319 cmdline_parse_token_num_t cmd_showport_macs_pid =
19320         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19321                         cmd_pid, UINT16);
19322 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19323         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19324                         cmd_keyword, "macs#mcast_macs");
19325
19326 cmdline_parse_inst_t cmd_showport_macs = {
19327         .f = cmd_showport_macs_parsed,
19328         .data = NULL,
19329         .help_str = "show port <port_id> macs|mcast_macs",
19330         .tokens = {
19331                 (void *)&cmd_showport_macs_show,
19332                 (void *)&cmd_showport_macs_port,
19333                 (void *)&cmd_showport_macs_pid,
19334                 (void *)&cmd_showport_macs_keyword,
19335                 NULL,
19336         },
19337 };
19338
19339 /* ******************************************************************************** */
19340
19341 /* list of instructions */
19342 cmdline_parse_ctx_t main_ctx[] = {
19343         (cmdline_parse_inst_t *)&cmd_help_brief,
19344         (cmdline_parse_inst_t *)&cmd_help_long,
19345         (cmdline_parse_inst_t *)&cmd_quit,
19346         (cmdline_parse_inst_t *)&cmd_load_from_file,
19347         (cmdline_parse_inst_t *)&cmd_showport,
19348         (cmdline_parse_inst_t *)&cmd_showqueue,
19349         (cmdline_parse_inst_t *)&cmd_showportall,
19350         (cmdline_parse_inst_t *)&cmd_showdevice,
19351         (cmdline_parse_inst_t *)&cmd_showcfg,
19352         (cmdline_parse_inst_t *)&cmd_showfwdall,
19353         (cmdline_parse_inst_t *)&cmd_start,
19354         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19355         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19356         (cmdline_parse_inst_t *)&cmd_set_link_up,
19357         (cmdline_parse_inst_t *)&cmd_set_link_down,
19358         (cmdline_parse_inst_t *)&cmd_reset,
19359         (cmdline_parse_inst_t *)&cmd_set_numbers,
19360         (cmdline_parse_inst_t *)&cmd_set_log,
19361         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19362         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19363         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19364         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19365         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19366         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19367         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19368         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19369         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19370         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19371         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19372         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19373         (cmdline_parse_inst_t *)&cmd_set_link_check,
19374         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19375         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19376         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19377         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19378 #ifdef RTE_LIBRTE_PMD_BOND
19379         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19380         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19381         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19382         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19383         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19384         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19385         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19386         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19387         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19388         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19389         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19390 #endif
19391         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19392         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19393         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19394         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19395         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19396         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19397         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19398         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19399         (cmdline_parse_inst_t *)&cmd_csum_set,
19400         (cmdline_parse_inst_t *)&cmd_csum_show,
19401         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19402         (cmdline_parse_inst_t *)&cmd_tso_set,
19403         (cmdline_parse_inst_t *)&cmd_tso_show,
19404         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19405         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19406         (cmdline_parse_inst_t *)&cmd_gro_enable,
19407         (cmdline_parse_inst_t *)&cmd_gro_flush,
19408         (cmdline_parse_inst_t *)&cmd_gro_show,
19409         (cmdline_parse_inst_t *)&cmd_gso_enable,
19410         (cmdline_parse_inst_t *)&cmd_gso_size,
19411         (cmdline_parse_inst_t *)&cmd_gso_show,
19412         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19413         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19414         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19415         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19416         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19417         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19418         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19419         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19420         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19421         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19422         (cmdline_parse_inst_t *)&cmd_config_dcb,
19423         (cmdline_parse_inst_t *)&cmd_read_reg,
19424         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19425         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19426         (cmdline_parse_inst_t *)&cmd_write_reg,
19427         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19428         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19429         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19430         (cmdline_parse_inst_t *)&cmd_stop,
19431         (cmdline_parse_inst_t *)&cmd_mac_addr,
19432         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19433         (cmdline_parse_inst_t *)&cmd_set_qmap,
19434         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19435         (cmdline_parse_inst_t *)&cmd_operate_port,
19436         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19437         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19438         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19439         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19440         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19441         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19442         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19443         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19444         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19445         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19446         (cmdline_parse_inst_t *)&cmd_config_mtu,
19447         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19448         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19449         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19450         (cmdline_parse_inst_t *)&cmd_config_rss,
19451         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19452         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19453         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19454         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19455         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19456         (cmdline_parse_inst_t *)&cmd_showport_reta,
19457         (cmdline_parse_inst_t *)&cmd_showport_macs,
19458         (cmdline_parse_inst_t *)&cmd_config_burst,
19459         (cmdline_parse_inst_t *)&cmd_config_thresh,
19460         (cmdline_parse_inst_t *)&cmd_config_threshold,
19461         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19462         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19463         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19464         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19465         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19466         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19467         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19468         (cmdline_parse_inst_t *)&cmd_global_config,
19469         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19470         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19471         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19472         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19473         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19474         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19475         (cmdline_parse_inst_t *)&cmd_dump,
19476         (cmdline_parse_inst_t *)&cmd_dump_one,
19477         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19478         (cmdline_parse_inst_t *)&cmd_syn_filter,
19479         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19480         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19481         (cmdline_parse_inst_t *)&cmd_flex_filter,
19482         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19483         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19484         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19485         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19486         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19487         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19488         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19489         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19490         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19491         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19492         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19493         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19494         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19495         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19496         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19497         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19498         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19499         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19500         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19501         (cmdline_parse_inst_t *)&cmd_flow,
19502         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19503         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19504         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19505         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19506         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19507         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19508         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19509         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19510         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19511         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19512         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19513         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19514         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19515         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19516         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19517         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19518         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19519         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19520         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19521         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19522         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19523         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19524         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19525         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19526         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19527         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19528         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19529         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19530         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19531         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19532         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19533         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19534         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19535         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19536         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19537         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19538         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19539         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19540         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19541         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19542         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19543         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19544         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19545         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19546         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19547         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19548         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19549         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19550         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19551         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19552         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19553         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19554         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19555         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19556         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19557         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19558         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19559         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19560         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19561         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19562         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19563         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19564         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19565         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19566         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19567         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19568         (cmdline_parse_inst_t *)&cmd_ddp_add,
19569         (cmdline_parse_inst_t *)&cmd_ddp_del,
19570         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19571         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19572         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19573         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19574         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19575         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19576         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19577         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19578         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19579         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19580         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19581         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19582
19583         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19584         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19585         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19586         (cmdline_parse_inst_t *)&cmd_queue_region,
19587         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19588         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19589         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19590         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19591         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19592         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19593         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19594         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19595         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19596         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19597         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19598         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19599         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19600         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19601         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19602         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19603         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19604         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19605         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19606         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19607         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19608         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19609         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19610         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19611         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19612         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19613         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19614         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19615         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19616         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19617         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19618         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19619         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19620         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19621         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19622 #ifdef RTE_LIBRTE_BPF
19623         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19624         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19625 #endif
19626         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19627         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19628         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19629         (cmdline_parse_inst_t *)&cmd_set_raw,
19630         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19631         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19632         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19633         NULL,
19634 };
19635
19636 /* read cmdline commands from file */
19637 void
19638 cmdline_read_from_file(const char *filename)
19639 {
19640         struct cmdline *cl;
19641
19642         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19643         if (cl == NULL) {
19644                 printf("Failed to create file based cmdline context: %s\n",
19645                        filename);
19646                 return;
19647         }
19648
19649         cmdline_interact(cl);
19650         cmdline_quit(cl);
19651
19652         cmdline_free(cl);
19653
19654         printf("Read CLI commands from %s\n", filename);
19655 }
19656
19657 /* prompt function, called from main on MASTER lcore */
19658 void
19659 prompt(void)
19660 {
19661         /* initialize non-constant commands */
19662         cmd_set_fwd_mode_init();
19663         cmd_set_fwd_retry_mode_init();
19664
19665         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19666         if (testpmd_cl == NULL)
19667                 return;
19668         cmdline_interact(testpmd_cl);
19669         cmdline_stdin_exit(testpmd_cl);
19670 }
19671
19672 void
19673 prompt_exit(void)
19674 {
19675         if (testpmd_cl != NULL)
19676                 cmdline_quit(testpmd_cl);
19677 }
19678
19679 static void
19680 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19681 {
19682         if (id == (portid_t)RTE_PORT_ALL) {
19683                 portid_t pid;
19684
19685                 RTE_ETH_FOREACH_DEV(pid) {
19686                         /* check if need_reconfig has been set to 1 */
19687                         if (ports[pid].need_reconfig == 0)
19688                                 ports[pid].need_reconfig = dev;
19689                         /* check if need_reconfig_queues has been set to 1 */
19690                         if (ports[pid].need_reconfig_queues == 0)
19691                                 ports[pid].need_reconfig_queues = queue;
19692                 }
19693         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19694                 /* check if need_reconfig has been set to 1 */
19695                 if (ports[id].need_reconfig == 0)
19696                         ports[id].need_reconfig = dev;
19697                 /* check if need_reconfig_queues has been set to 1 */
19698                 if (ports[id].need_reconfig_queues == 0)
19699                         ports[id].need_reconfig_queues = queue;
19700         }
19701 }