app/testpmd: add record-burst-stats runtime config
[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 txtimes (x, y)\n"
298                         "    Set the scheduling on timestamps"
299                         " timings for the TXONLY mode\n\n"
300
301                         "set corelist (x[,y]*)\n"
302                         "    Set the list of forwarding cores.\n\n"
303
304                         "set portlist (x[,y]*)\n"
305                         "    Set the list of forwarding ports.\n\n"
306
307                         "set port setup on (iterator|event)\n"
308                         "    Select how attached port is retrieved for setup.\n\n"
309
310                         "set tx loopback (port_id) (on|off)\n"
311                         "    Enable or disable tx loopback.\n\n"
312
313                         "set all queues drop (port_id) (on|off)\n"
314                         "    Set drop enable bit for all queues.\n\n"
315
316                         "set vf split drop (port_id) (vf_id) (on|off)\n"
317                         "    Set split drop enable bit for a VF from the PF.\n\n"
318
319                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
320                         "    Set MAC antispoof for a VF from the PF.\n\n"
321
322                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
323                         "    Enable MACsec offload.\n\n"
324
325                         "set macsec offload (port_id) off\n"
326                         "    Disable MACsec offload.\n\n"
327
328                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
329                         "    Configure MACsec secure connection (SC).\n\n"
330
331                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
332                         "    Configure MACsec secure association (SA).\n\n"
333
334                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
335                         "    Set VF broadcast for a VF from the PF.\n\n"
336
337                         "vlan set stripq (on|off) (port_id,queue_id)\n"
338                         "    Set the VLAN strip for a queue on a port.\n\n"
339
340                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
341                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
342
343                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
344                         "    Set VLAN insert for a VF from the PF.\n\n"
345
346                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
347                         "    Set VLAN antispoof for a VF from the PF.\n\n"
348
349                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
350                         "    Set VLAN tag for a VF from the PF.\n\n"
351
352                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
353                         "    Set a VF's max bandwidth(Mbps).\n\n"
354
355                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
356                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
357
358                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
359                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
360
361                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
362                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
363
364                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
365                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
366
367                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
368                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
369
370                         "vlan set (inner|outer) tpid (value) (port_id)\n"
371                         "    Set the VLAN TPID for Packet Filtering on"
372                         " a port\n\n"
373
374                         "rx_vlan add (vlan_id|all) (port_id)\n"
375                         "    Add a vlan_id, or all identifiers, to the set"
376                         " of VLAN identifiers filtered by port_id.\n\n"
377
378                         "rx_vlan rm (vlan_id|all) (port_id)\n"
379                         "    Remove a vlan_id, or all identifiers, from the set"
380                         " of VLAN identifiers filtered by port_id.\n\n"
381
382                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
383                         "    Add a vlan_id, to the set of VLAN identifiers"
384                         "filtered for VF(s) from port_id.\n\n"
385
386                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
387                         "    Remove a vlan_id, to the set of VLAN identifiers"
388                         "filtered for VF(s) from port_id.\n\n"
389
390                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
391                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
392                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
393                         "   add a tunnel filter of a port.\n\n"
394
395                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   remove a tunnel filter of a port.\n\n"
399
400                         "rx_vxlan_port add (udp_port) (port_id)\n"
401                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
402
403                         "rx_vxlan_port rm (udp_port) (port_id)\n"
404                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
405
406                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
407                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
408                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
409
410                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
411                         "    Set port based TX VLAN insertion.\n\n"
412
413                         "tx_vlan reset (port_id)\n"
414                         "    Disable hardware insertion of a VLAN header in"
415                         " packets sent on a port.\n\n"
416
417                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
418                         "    Select hardware or software calculation of the"
419                         " checksum when transmitting a packet using the"
420                         " csum forward engine.\n"
421                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
422                         "    outer-ip concerns the outer IP layer in"
423                         "    outer-udp concerns the outer UDP layer in"
424                         " case the packet is recognized as a tunnel packet by"
425                         " the forward engine (vxlan, gre and ipip are supported)\n"
426                         "    Please check the NIC datasheet for HW limits.\n\n"
427
428                         "csum parse-tunnel (on|off) (tx_port_id)\n"
429                         "    If disabled, treat tunnel packets as non-tunneled"
430                         " packets (treat inner headers as payload). The port\n"
431                         "    argument is the port used for TX in csum forward"
432                         " engine.\n\n"
433
434                         "csum show (port_id)\n"
435                         "    Display tx checksum offload configuration\n\n"
436
437                         "tso set (segsize) (portid)\n"
438                         "    Enable TCP Segmentation Offload in csum forward"
439                         " engine.\n"
440                         "    Please check the NIC datasheet for HW limits.\n\n"
441
442                         "tso show (portid)"
443                         "    Display the status of TCP Segmentation Offload.\n\n"
444
445                         "set port (port_id) gro on|off\n"
446                         "    Enable or disable Generic Receive Offload in"
447                         " csum forwarding engine.\n\n"
448
449                         "show port (port_id) gro\n"
450                         "    Display GRO configuration.\n\n"
451
452                         "set gro flush (cycles)\n"
453                         "    Set the cycle to flush GROed packets from"
454                         " reassembly tables.\n\n"
455
456                         "set port (port_id) gso (on|off)"
457                         "    Enable or disable Generic Segmentation Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "set gso segsz (length)\n"
461                         "    Set max packet length for output GSO segments,"
462                         " including packet header and payload.\n\n"
463
464                         "show port (port_id) gso\n"
465                         "    Show GSO configuration.\n\n"
466
467                         "set fwd (%s)\n"
468                         "    Set packet forwarding mode.\n\n"
469
470                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
471                         "    Add a MAC address on port_id.\n\n"
472
473                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
474                         "    Remove a MAC address from port_id.\n\n"
475
476                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
477                         "    Set the default MAC address for port_id.\n\n"
478
479                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
480                         "    Add a MAC address for a VF on the port.\n\n"
481
482                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
483                         "    Set the MAC address for a VF from the PF.\n\n"
484
485                         "set eth-peer (port_id) (peer_addr)\n"
486                         "    set the peer address for certain port.\n\n"
487
488                         "set port (port_id) uta (mac_address|all) (on|off)\n"
489                         "    Add/Remove a or all unicast hash filter(s)"
490                         "from port X.\n\n"
491
492                         "set promisc (port_id|all) (on|off)\n"
493                         "    Set the promiscuous mode on port_id, or all.\n\n"
494
495                         "set allmulti (port_id|all) (on|off)\n"
496                         "    Set the allmulti mode on port_id, or all.\n\n"
497
498                         "set vf promisc (port_id) (vf_id) (on|off)\n"
499                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
500
501                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
502                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
503
504                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
505                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
506                         " (on|off) autoneg (on|off) (port_id)\n"
507                         "set flow_ctrl rx (on|off) (portid)\n"
508                         "set flow_ctrl tx (on|off) (portid)\n"
509                         "set flow_ctrl high_water (high_water) (portid)\n"
510                         "set flow_ctrl low_water (low_water) (portid)\n"
511                         "set flow_ctrl pause_time (pause_time) (portid)\n"
512                         "set flow_ctrl send_xon (send_xon) (portid)\n"
513                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
514                         "set flow_ctrl autoneg (on|off) (port_id)\n"
515                         "    Set the link flow control parameter on a port.\n\n"
516
517                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
518                         " (low_water) (pause_time) (priority) (port_id)\n"
519                         "    Set the priority flow control parameter on a"
520                         " port.\n\n"
521
522                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
523                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
524                         " queue on port.\n"
525                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
526                         " on port 0 to mapping 5.\n\n"
527
528                         "set xstats-hide-zero on|off\n"
529                         "    Set the option to hide the zero values"
530                         " for xstats display.\n"
531
532                         "set record-core-cycles on|off\n"
533                         "    Set the option to enable measurement of CPU cycles.\n"
534
535                         "set record-burst-stats on|off\n"
536                         "    Set the option to enable display of RX and TX bursts.\n"
537
538                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
539                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
540
541                         "set port (port_id) vf (vf_id) (mac_addr)"
542                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
543                         "   Add/Remove unicast or multicast MAC addr filter"
544                         " for a VF.\n\n"
545
546                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
547                         "|MPE) (on|off)\n"
548                         "    AUPE:accepts untagged VLAN;"
549                         "ROPE:accept unicast hash\n\n"
550                         "    BAM:accepts broadcast packets;"
551                         "MPE:accepts all multicast packets\n\n"
552                         "    Enable/Disable a VF receive mode of a port\n\n"
553
554                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
555                         "    Set rate limit for a queue of a port\n\n"
556
557                         "set port (port_id) vf (vf_id) rate (rate_num) "
558                         "queue_mask (queue_mask_value)\n"
559                         "    Set rate limit for queues in VF of a port\n\n"
560
561                         "set port (port_id) mirror-rule (rule_id)"
562                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
563                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
564                         "   Set pool or vlan type mirror rule on a port.\n"
565                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
566                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
567                         " to pool 0.\n\n"
568
569                         "set port (port_id) mirror-rule (rule_id)"
570                         " (uplink-mirror|downlink-mirror) dst-pool"
571                         " (pool_id) (on|off)\n"
572                         "   Set uplink or downlink type mirror rule on a port.\n"
573                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
574                         " 0 on' enable mirror income traffic to pool 0.\n\n"
575
576                         "reset port (port_id) mirror-rule (rule_id)\n"
577                         "   Reset a mirror rule.\n\n"
578
579                         "set flush_rx (on|off)\n"
580                         "   Flush (default) or don't flush RX streams before"
581                         " forwarding. Mainly used with PCAP drivers.\n\n"
582
583                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the bypass mode for the lowest port on bypass enabled"
585                         " NIC.\n\n"
586
587                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
588                         "mode (normal|bypass|isolate) (port_id)\n"
589                         "   Set the event required to initiate specified bypass mode for"
590                         " the lowest port on a bypass enabled NIC where:\n"
591                         "       timeout   = enable bypass after watchdog timeout.\n"
592                         "       os_on     = enable bypass when OS/board is powered on.\n"
593                         "       os_off    = enable bypass when OS/board is powered off.\n"
594                         "       power_on  = enable bypass when power supply is turned on.\n"
595                         "       power_off = enable bypass when power supply is turned off."
596                         "\n\n"
597
598                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
599                         "   Set the bypass watchdog timeout to 'n' seconds"
600                         " where 0 = instant.\n\n"
601
602                         "show bypass config (port_id)\n"
603                         "   Show the bypass configuration for a bypass enabled NIC"
604                         " using the lowest port on the NIC.\n\n"
605
606 #ifdef RTE_LIBRTE_PMD_BOND
607                         "create bonded device (mode) (socket)\n"
608                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
609
610                         "add bonding slave (slave_id) (port_id)\n"
611                         "       Add a slave device to a bonded device.\n\n"
612
613                         "remove bonding slave (slave_id) (port_id)\n"
614                         "       Remove a slave device from a bonded device.\n\n"
615
616                         "set bonding mode (value) (port_id)\n"
617                         "       Set the bonding mode on a bonded device.\n\n"
618
619                         "set bonding primary (slave_id) (port_id)\n"
620                         "       Set the primary slave for a bonded device.\n\n"
621
622                         "show bonding config (port_id)\n"
623                         "       Show the bonding config for port_id.\n\n"
624
625                         "set bonding mac_addr (port_id) (address)\n"
626                         "       Set the MAC address of a bonded device.\n\n"
627
628                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
629                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
630
631                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
632                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
633
634                         "set bonding mon_period (port_id) (value)\n"
635                         "       Set the bonding link status monitoring polling period in ms.\n\n"
636
637                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
638                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
639
640 #endif
641                         "set link-up port (port_id)\n"
642                         "       Set link up for a port.\n\n"
643
644                         "set link-down port (port_id)\n"
645                         "       Set link down for a port.\n\n"
646
647                         "E-tag set insertion on port-tag-id (value)"
648                         " port (port_id) vf (vf_id)\n"
649                         "    Enable E-tag insertion for a VF on a port\n\n"
650
651                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
652                         "    Disable E-tag insertion for a VF on a port\n\n"
653
654                         "E-tag set stripping (on|off) port (port_id)\n"
655                         "    Enable/disable E-tag stripping on a port\n\n"
656
657                         "E-tag set forwarding (on|off) port (port_id)\n"
658                         "    Enable/disable E-tag based forwarding"
659                         " on a port\n\n"
660
661                         "E-tag set filter add e-tag-id (value) dst-pool"
662                         " (pool_id) port (port_id)\n"
663                         "    Add an E-tag forwarding filter on a port\n\n"
664
665                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
666                         "    Delete an E-tag forwarding filter on a port\n\n"
667
668                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (backup_profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) ptype_mask (ptype_mask)\n"
687                         "    set packet types classification for a specific port\n\n"
688
689                         "set port (port_id) queue-region region_id (value) "
690                         "queue_start_index (value) queue_num (value)\n"
691                         "    Set a queue region on a port\n\n"
692
693                         "set port (port_id) queue-region region_id (value) "
694                         "flowtype (value)\n"
695                         "    Set a flowtype region index on a port\n\n"
696
697                         "set port (port_id) queue-region UP (value) region_id (value)\n"
698                         "    Set the mapping of User Priority to "
699                         "queue region on a port\n\n"
700
701                         "set port (port_id) queue-region flush (on|off)\n"
702                         "    flush all queue region related configuration\n\n"
703
704                         "show port meter cap (port_id)\n"
705                         "    Show port meter capability information\n\n"
706
707                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
708                         "    meter profile add - srtcm rfc 2697\n\n"
709
710                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
711                         "    meter profile add - trtcm rfc 2698\n\n"
712
713                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
714                         "    meter profile add - trtcm rfc 4115\n\n"
715
716                         "del port meter profile (port_id) (profile_id)\n"
717                         "    meter profile delete\n\n"
718
719                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
720                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
721                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
722                         "(dscp_tbl_entry63)]\n"
723                         "    meter create\n\n"
724
725                         "enable port meter (port_id) (mtr_id)\n"
726                         "    meter enable\n\n"
727
728                         "disable port meter (port_id) (mtr_id)\n"
729                         "    meter disable\n\n"
730
731                         "del port meter (port_id) (mtr_id)\n"
732                         "    meter delete\n\n"
733
734                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
735                         "    meter update meter profile\n\n"
736
737                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
738                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
739                         "    update meter dscp table entries\n\n"
740
741                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
742                         "(action0) [(action1) (action2)]\n"
743                         "    meter update policer action\n\n"
744
745                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
746                         "    meter update stats\n\n"
747
748                         "show port (port_id) queue-region\n"
749                         "    show all queue region related configuration info\n\n"
750
751                         , list_pkt_forwarding_modes()
752                 );
753         }
754
755         if (show_all || !strcmp(res->section, "ports")) {
756
757                 cmdline_printf(
758                         cl,
759                         "\n"
760                         "Port Operations:\n"
761                         "----------------\n\n"
762
763                         "port start (port_id|all)\n"
764                         "    Start all ports or port_id.\n\n"
765
766                         "port stop (port_id|all)\n"
767                         "    Stop all ports or port_id.\n\n"
768
769                         "port close (port_id|all)\n"
770                         "    Close all ports or port_id.\n\n"
771
772                         "port reset (port_id|all)\n"
773                         "    Reset all ports or port_id.\n\n"
774
775                         "port attach (ident)\n"
776                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
777
778                         "port detach (port_id)\n"
779                         "    Detach physical or virtual dev by port_id\n\n"
780
781                         "port config (port_id|all)"
782                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
783                         " duplex (half|full|auto)\n"
784                         "    Set speed and duplex for all ports or port_id\n\n"
785
786                         "port config (port_id|all) loopback (mode)\n"
787                         "    Set loopback mode for all ports or port_id\n\n"
788
789                         "port config all (rxq|txq|rxd|txd) (value)\n"
790                         "    Set number for rxq/txq/rxd/txd.\n\n"
791
792                         "port config all max-pkt-len (value)\n"
793                         "    Set the max packet length.\n\n"
794
795                         "port config all max-lro-pkt-size (value)\n"
796                         "    Set the max LRO aggregated packet size.\n\n"
797
798                         "port config all drop-en (on|off)\n"
799                         "    Enable or disable packet drop on all RX queues of all ports when no "
800                         "receive buffers available.\n\n"
801
802                         "port config all rss (all|default|ip|tcp|udp|sctp|"
803                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|<flowtype_id>)\n"
804                         "    Set the RSS mode.\n\n"
805
806                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
807                         "    Set the RSS redirection table.\n\n"
808
809                         "port config (port_id) dcb vt (on|off) (traffic_class)"
810                         " pfc (on|off)\n"
811                         "    Set the DCB mode.\n\n"
812
813                         "port config all burst (value)\n"
814                         "    Set the number of packets per burst.\n\n"
815
816                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
817                         " (value)\n"
818                         "    Set the ring prefetch/host/writeback threshold"
819                         " for tx/rx queue.\n\n"
820
821                         "port config all (txfreet|txrst|rxfreet) (value)\n"
822                         "    Set free threshold for rx/tx, or set"
823                         " tx rs bit threshold.\n\n"
824                         "port config mtu X value\n"
825                         "    Set the MTU of port X to a given value\n\n"
826
827                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
828                         "    Set a rx/tx queue's ring size configuration, the new"
829                         " value will take effect after command that (re-)start the port"
830                         " or command that setup the specific queue\n\n"
831
832                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
833                         "    Start/stop a rx/tx queue of port X. Only take effect"
834                         " when port X is started\n\n"
835
836                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
837                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
838                         " take effect when port X is stopped.\n\n"
839
840                         "port (port_id) (rxq|txq) (queue_id) setup\n"
841                         "    Setup a rx/tx queue of port X.\n\n"
842
843                         "port config (port_id|all) l2-tunnel E-tag ether-type"
844                         " (value)\n"
845                         "    Set the value of E-tag ether-type.\n\n"
846
847                         "port config (port_id|all) l2-tunnel E-tag"
848                         " (enable|disable)\n"
849                         "    Enable/disable the E-tag support.\n\n"
850
851                         "port config (port_id) pctype mapping reset\n"
852                         "    Reset flow type to pctype mapping on a port\n\n"
853
854                         "port config (port_id) pctype mapping update"
855                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
856                         "    Update a flow type to pctype mapping item on a port\n\n"
857
858                         "port config (port_id) pctype (pctype_id) hash_inset|"
859                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
860                         " (field_idx)\n"
861                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
862
863                         "port config (port_id) pctype (pctype_id) hash_inset|"
864                         "fdir_inset|fdir_flx_inset clear all"
865                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
866
867                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
868                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
869
870                         "port config <port_id> rx_offload vlan_strip|"
871                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
872                         "outer_ipv4_cksum|macsec_strip|header_split|"
873                         "vlan_filter|vlan_extend|jumbo_frame|"
874                         "scatter|timestamp|security|keep_crc on|off\n"
875                         "     Enable or disable a per port Rx offloading"
876                         " on all Rx queues of a port\n\n"
877
878                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
879                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
880                         "outer_ipv4_cksum|macsec_strip|header_split|"
881                         "vlan_filter|vlan_extend|jumbo_frame|"
882                         "scatter|timestamp|security|keep_crc on|off\n"
883                         "    Enable or disable a per queue Rx offloading"
884                         " only on a specific Rx queue\n\n"
885
886                         "port config (port_id) tx_offload vlan_insert|"
887                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
888                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
889                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
890                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
891                         "security on|off\n"
892                         "    Enable or disable a per port Tx offloading"
893                         " on all Tx queues of a port\n\n"
894
895                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
896                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
897                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
898                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
899                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
900                         " on|off\n"
901                         "    Enable or disable a per queue Tx offloading"
902                         " only on a specific Tx queue\n\n"
903
904                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
905                         "    Load an eBPF program as a callback"
906                         " for particular RX/TX queue\n\n"
907
908                         "bpf-unload rx|tx (port) (queue)\n"
909                         "    Unload previously loaded eBPF program"
910                         " for particular RX/TX queue\n\n"
911
912                         "port config (port_id) tx_metadata (value)\n"
913                         "    Set Tx metadata value per port. Testpmd will add this value"
914                         " to any Tx packet sent from this port\n\n"
915
916                         "port config (port_id) dynf (name) set|clear\n"
917                         "    Register a dynf and Set/clear this flag on Tx. "
918                         "Testpmd will set this value to any Tx packet "
919                         "sent from this port\n\n"
920                 );
921         }
922
923         if (show_all || !strcmp(res->section, "registers")) {
924
925                 cmdline_printf(
926                         cl,
927                         "\n"
928                         "Registers:\n"
929                         "----------\n\n"
930
931                         "read reg (port_id) (address)\n"
932                         "    Display value of a port register.\n\n"
933
934                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
935                         "    Display a port register bit field.\n\n"
936
937                         "read regbit (port_id) (address) (bit_x)\n"
938                         "    Display a single port register bit.\n\n"
939
940                         "write reg (port_id) (address) (value)\n"
941                         "    Set value of a port register.\n\n"
942
943                         "write regfield (port_id) (address) (bit_x) (bit_y)"
944                         " (value)\n"
945                         "    Set bit field of a port register.\n\n"
946
947                         "write regbit (port_id) (address) (bit_x) (value)\n"
948                         "    Set single bit value of a port register.\n\n"
949                 );
950         }
951         if (show_all || !strcmp(res->section, "filters")) {
952
953                 cmdline_printf(
954                         cl,
955                         "\n"
956                         "filters:\n"
957                         "--------\n\n"
958
959                         "ethertype_filter (port_id) (add|del)"
960                         " (mac_addr|mac_ignr) (mac_address) ethertype"
961                         " (ether_type) (drop|fwd) queue (queue_id)\n"
962                         "    Add/Del an ethertype filter.\n\n"
963
964                         "2tuple_filter (port_id) (add|del)"
965                         " dst_port (dst_port_value) protocol (protocol_value)"
966                         " mask (mask_value) tcp_flags (tcp_flags_value)"
967                         " priority (prio_value) queue (queue_id)\n"
968                         "    Add/Del a 2tuple filter.\n\n"
969
970                         "5tuple_filter (port_id) (add|del)"
971                         " dst_ip (dst_address) src_ip (src_address)"
972                         " dst_port (dst_port_value) src_port (src_port_value)"
973                         " protocol (protocol_value)"
974                         " mask (mask_value) tcp_flags (tcp_flags_value)"
975                         " priority (prio_value) queue (queue_id)\n"
976                         "    Add/Del a 5tuple filter.\n\n"
977
978                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
979                         "    Add/Del syn filter.\n\n"
980
981                         "flex_filter (port_id) (add|del) len (len_value)"
982                         " bytes (bytes_value) mask (mask_value)"
983                         " priority (prio_value) queue (queue_id)\n"
984                         "    Add/Del a flex filter.\n\n"
985
986                         "flow_director_filter (port_id) mode IP (add|del|update)"
987                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
988                         " src (src_ip_address) dst (dst_ip_address)"
989                         " tos (tos_value) proto (proto_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 IP type flow director filter.\n\n"
994
995                         "flow_director_filter (port_id) mode IP (add|del|update)"
996                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
997                         " src (src_ip_address) (src_port)"
998                         " dst (dst_ip_address) (dst_port)"
999                         " tos (tos_value) ttl (ttl_value)"
1000                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1001                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1002                         " fd_id (fd_id_value)\n"
1003                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode IP (add|del|update)"
1006                         " flow (ipv4-sctp|ipv6-sctp)"
1007                         " src (src_ip_address) (src_port)"
1008                         " dst (dst_ip_address) (dst_port)"
1009                         " tag (verification_tag) "
1010                         " tos (tos_value) ttl (ttl_value)"
1011                         " vlan (vlan_value)"
1012                         " flexbytes (flexbytes_value) (drop|fwd)"
1013                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1014                         "    Add/Del a SCTP type flow director filter.\n\n"
1015
1016                         "flow_director_filter (port_id) mode IP (add|del|update)"
1017                         " flow l2_payload ether (ethertype)"
1018                         " flexbytes (flexbytes_value) (drop|fwd)"
1019                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1020                         "    Add/Del a l2 payload type flow director filter.\n\n"
1021
1022                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1023                         " mac (mac_address) vlan (vlan_value)"
1024                         " flexbytes (flexbytes_value) (drop|fwd)"
1025                         " queue (queue_id) fd_id (fd_id_value)\n"
1026                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1027
1028                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1029                         " mac (mac_address) vlan (vlan_value)"
1030                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1031                         " flexbytes (flexbytes_value) (drop|fwd)"
1032                         " queue (queue_id) fd_id (fd_id_value)\n"
1033                         "    Add/Del a Tunnel flow director filter.\n\n"
1034
1035                         "flow_director_filter (port_id) mode raw (add|del|update)"
1036                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1037                         " fd_id (fd_id_value) packet (packet file name)\n"
1038                         "    Add/Del a raw type flow director filter.\n\n"
1039
1040                         "flush_flow_director (port_id)\n"
1041                         "    Flush all flow director entries of a device.\n\n"
1042
1043                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1044                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1045                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1046                         "    Set flow director IP mask.\n\n"
1047
1048                         "flow_director_mask (port_id) mode MAC-VLAN"
1049                         " vlan (vlan_value)\n"
1050                         "    Set flow director MAC-VLAN mask.\n\n"
1051
1052                         "flow_director_mask (port_id) mode Tunnel"
1053                         " vlan (vlan_value) mac (mac_value)"
1054                         " tunnel-type (tunnel_type_value)"
1055                         " tunnel-id (tunnel_id_value)\n"
1056                         "    Set flow director Tunnel mask.\n\n"
1057
1058                         "flow_director_flex_mask (port_id)"
1059                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1060                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1061                         " (mask)\n"
1062                         "    Configure mask of flex payload.\n\n"
1063
1064                         "flow_director_flex_payload (port_id)"
1065                         " (raw|l2|l3|l4) (config)\n"
1066                         "    Configure flex payload selection.\n\n"
1067
1068                         "get_sym_hash_ena_per_port (port_id)\n"
1069                         "    get symmetric hash enable configuration per port.\n\n"
1070
1071                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1072                         "    set symmetric hash enable configuration per port"
1073                         " to enable or disable.\n\n"
1074
1075                         "get_hash_global_config (port_id)\n"
1076                         "    Get the global configurations of hash filters.\n\n"
1077
1078                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1079                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1080                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1081                         " (enable|disable)\n"
1082                         "    Set the global configurations of hash filters.\n\n"
1083
1084                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1085                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1086                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1087                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1088                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1089                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1090                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1091                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1092                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1093                         "fld-8th|none) (select|add)\n"
1094                         "    Set the input set for hash.\n\n"
1095
1096                         "set_fdir_input_set (port_id) "
1097                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1098                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1099                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1100                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1101                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1102                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1103                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1104                         " (select|add)\n"
1105                         "    Set the input set for FDir.\n\n"
1106
1107                         "flow validate {port_id}"
1108                         " [group {group_id}] [priority {level}]"
1109                         " [ingress] [egress]"
1110                         " pattern {item} [/ {item} [...]] / end"
1111                         " actions {action} [/ {action} [...]] / end\n"
1112                         "    Check whether a flow rule can be created.\n\n"
1113
1114                         "flow create {port_id}"
1115                         " [group {group_id}] [priority {level}]"
1116                         " [ingress] [egress]"
1117                         " pattern {item} [/ {item} [...]] / end"
1118                         " actions {action} [/ {action} [...]] / end\n"
1119                         "    Create a flow rule.\n\n"
1120
1121                         "flow destroy {port_id} rule {rule_id} [...]\n"
1122                         "    Destroy specific flow rules.\n\n"
1123
1124                         "flow flush {port_id}\n"
1125                         "    Destroy all flow rules.\n\n"
1126
1127                         "flow query {port_id} {rule_id} {action}\n"
1128                         "    Query an existing flow rule.\n\n"
1129
1130                         "flow list {port_id} [group {group_id}] [...]\n"
1131                         "    List existing flow rules sorted by priority,"
1132                         " filtered by group identifiers.\n\n"
1133
1134                         "flow isolate {port_id} {boolean}\n"
1135                         "    Restrict ingress traffic to the defined"
1136                         " flow rules\n\n"
1137
1138                         "flow aged {port_id} [destroy]\n"
1139                         "    List and destroy aged flows"
1140                         " flow rules\n\n"
1141
1142                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1143                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1144                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1145                         "       Configure the VXLAN encapsulation for flows.\n\n"
1146
1147                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1148                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1149                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1150                         " eth-dst (eth-dst)\n"
1151                         "       Configure the VXLAN encapsulation for flows.\n\n"
1152
1153                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1154                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1155                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1156                         " eth-dst (eth-dst)\n"
1157                         "       Configure the VXLAN encapsulation for flows.\n\n"
1158
1159                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1160                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1161                         " (eth-dst)\n"
1162                         "       Configure the NVGRE encapsulation for flows.\n\n"
1163
1164                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1165                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1166                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1167                         "       Configure the NVGRE encapsulation for flows.\n\n"
1168
1169                         "set raw_encap {flow items}\n"
1170                         "       Configure the encapsulation with raw data.\n\n"
1171
1172                         "set raw_decap {flow items}\n"
1173                         "       Configure the decapsulation with raw data.\n\n"
1174
1175                 );
1176         }
1177
1178         if (show_all || !strcmp(res->section, "traffic_management")) {
1179                 cmdline_printf(
1180                         cl,
1181                         "\n"
1182                         "Traffic Management:\n"
1183                         "--------------\n"
1184                         "show port tm cap (port_id)\n"
1185                         "       Display the port TM capability.\n\n"
1186
1187                         "show port tm level cap (port_id) (level_id)\n"
1188                         "       Display the port TM hierarchical level capability.\n\n"
1189
1190                         "show port tm node cap (port_id) (node_id)\n"
1191                         "       Display the port TM node capability.\n\n"
1192
1193                         "show port tm node type (port_id) (node_id)\n"
1194                         "       Display the port TM node type.\n\n"
1195
1196                         "show port tm node stats (port_id) (node_id) (clear)\n"
1197                         "       Display the port TM node stats.\n\n"
1198
1199                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1200                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1201                         " (packet_length_adjust)\n"
1202                         "       Add port tm node private shaper profile.\n\n"
1203
1204                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1205                         "       Delete port tm node private shaper profile.\n\n"
1206
1207                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1208                         " (shaper_profile_id)\n"
1209                         "       Add/update port tm node shared shaper.\n\n"
1210
1211                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1212                         "       Delete port tm node shared shaper.\n\n"
1213
1214                         "set port tm node shaper profile (port_id) (node_id)"
1215                         " (shaper_profile_id)\n"
1216                         "       Set port tm node shaper profile.\n\n"
1217
1218                         "add port tm node wred profile (port_id) (wred_profile_id)"
1219                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1220                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1221                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1222                         "       Add port tm node wred profile.\n\n"
1223
1224                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1225                         "       Delete port tm node wred profile.\n\n"
1226
1227                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1228                         " (priority) (weight) (level_id) (shaper_profile_id)"
1229                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1230                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1231                         "       Add port tm nonleaf node.\n\n"
1232
1233                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1234                         " (priority) (weight) (level_id) (shaper_profile_id)"
1235                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1236                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1237                         "       Add port tm leaf node.\n\n"
1238
1239                         "del port tm node (port_id) (node_id)\n"
1240                         "       Delete port tm node.\n\n"
1241
1242                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1243                         " (priority) (weight)\n"
1244                         "       Set port tm node parent.\n\n"
1245
1246                         "suspend port tm node (port_id) (node_id)"
1247                         "       Suspend tm node.\n\n"
1248
1249                         "resume port tm node (port_id) (node_id)"
1250                         "       Resume tm node.\n\n"
1251
1252                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1253                         "       Commit tm hierarchy.\n\n"
1254
1255                         "set port tm mark ip_ecn (port) (green) (yellow)"
1256                         " (red)\n"
1257                         "    Enables/Disables the traffic management marking"
1258                         " for IP ECN (Explicit Congestion Notification)"
1259                         " packets on a given port\n\n"
1260
1261                         "set port tm mark ip_dscp (port) (green) (yellow)"
1262                         " (red)\n"
1263                         "    Enables/Disables the traffic management marking"
1264                         " on the port for IP dscp packets\n\n"
1265
1266                         "set port tm mark vlan_dei (port) (green) (yellow)"
1267                         " (red)\n"
1268                         "    Enables/Disables the traffic management marking"
1269                         " on the port for VLAN packets with DEI enabled\n\n"
1270                 );
1271         }
1272
1273         if (show_all || !strcmp(res->section, "devices")) {
1274                 cmdline_printf(
1275                         cl,
1276                         "\n"
1277                         "Device Operations:\n"
1278                         "--------------\n"
1279                         "device detach (identifier)\n"
1280                         "       Detach device by identifier.\n\n"
1281                 );
1282         }
1283
1284 }
1285
1286 cmdline_parse_token_string_t cmd_help_long_help =
1287         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1288
1289 cmdline_parse_token_string_t cmd_help_long_section =
1290         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1291                         "all#control#display#config#"
1292                         "ports#registers#filters#traffic_management#devices");
1293
1294 cmdline_parse_inst_t cmd_help_long = {
1295         .f = cmd_help_long_parsed,
1296         .data = NULL,
1297         .help_str = "help all|control|display|config|ports|register|"
1298                 "filters|traffic_management|devices: "
1299                 "Show help",
1300         .tokens = {
1301                 (void *)&cmd_help_long_help,
1302                 (void *)&cmd_help_long_section,
1303                 NULL,
1304         },
1305 };
1306
1307
1308 /* *** start/stop/close all ports *** */
1309 struct cmd_operate_port_result {
1310         cmdline_fixed_string_t keyword;
1311         cmdline_fixed_string_t name;
1312         cmdline_fixed_string_t value;
1313 };
1314
1315 static void cmd_operate_port_parsed(void *parsed_result,
1316                                 __rte_unused struct cmdline *cl,
1317                                 __rte_unused void *data)
1318 {
1319         struct cmd_operate_port_result *res = parsed_result;
1320
1321         if (!strcmp(res->name, "start"))
1322                 start_port(RTE_PORT_ALL);
1323         else if (!strcmp(res->name, "stop"))
1324                 stop_port(RTE_PORT_ALL);
1325         else if (!strcmp(res->name, "close"))
1326                 close_port(RTE_PORT_ALL);
1327         else if (!strcmp(res->name, "reset"))
1328                 reset_port(RTE_PORT_ALL);
1329         else
1330                 printf("Unknown parameter\n");
1331 }
1332
1333 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1334         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1335                                                                 "port");
1336 cmdline_parse_token_string_t cmd_operate_port_all_port =
1337         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1338                                                 "start#stop#close#reset");
1339 cmdline_parse_token_string_t cmd_operate_port_all_all =
1340         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1341
1342 cmdline_parse_inst_t cmd_operate_port = {
1343         .f = cmd_operate_port_parsed,
1344         .data = NULL,
1345         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1346         .tokens = {
1347                 (void *)&cmd_operate_port_all_cmd,
1348                 (void *)&cmd_operate_port_all_port,
1349                 (void *)&cmd_operate_port_all_all,
1350                 NULL,
1351         },
1352 };
1353
1354 /* *** start/stop/close specific port *** */
1355 struct cmd_operate_specific_port_result {
1356         cmdline_fixed_string_t keyword;
1357         cmdline_fixed_string_t name;
1358         uint8_t value;
1359 };
1360
1361 static void cmd_operate_specific_port_parsed(void *parsed_result,
1362                         __rte_unused struct cmdline *cl,
1363                                 __rte_unused void *data)
1364 {
1365         struct cmd_operate_specific_port_result *res = parsed_result;
1366
1367         if (!strcmp(res->name, "start"))
1368                 start_port(res->value);
1369         else if (!strcmp(res->name, "stop"))
1370                 stop_port(res->value);
1371         else if (!strcmp(res->name, "close"))
1372                 close_port(res->value);
1373         else if (!strcmp(res->name, "reset"))
1374                 reset_port(res->value);
1375         else
1376                 printf("Unknown parameter\n");
1377 }
1378
1379 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1380         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1381                                                         keyword, "port");
1382 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1383         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1384                                                 name, "start#stop#close#reset");
1385 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1386         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1387                                                         value, UINT8);
1388
1389 cmdline_parse_inst_t cmd_operate_specific_port = {
1390         .f = cmd_operate_specific_port_parsed,
1391         .data = NULL,
1392         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1393         .tokens = {
1394                 (void *)&cmd_operate_specific_port_cmd,
1395                 (void *)&cmd_operate_specific_port_port,
1396                 (void *)&cmd_operate_specific_port_id,
1397                 NULL,
1398         },
1399 };
1400
1401 /* *** enable port setup (after attach) via iterator or event *** */
1402 struct cmd_set_port_setup_on_result {
1403         cmdline_fixed_string_t set;
1404         cmdline_fixed_string_t port;
1405         cmdline_fixed_string_t setup;
1406         cmdline_fixed_string_t on;
1407         cmdline_fixed_string_t mode;
1408 };
1409
1410 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1411                                 __rte_unused struct cmdline *cl,
1412                                 __rte_unused void *data)
1413 {
1414         struct cmd_set_port_setup_on_result *res = parsed_result;
1415
1416         if (strcmp(res->mode, "event") == 0)
1417                 setup_on_probe_event = true;
1418         else if (strcmp(res->mode, "iterator") == 0)
1419                 setup_on_probe_event = false;
1420         else
1421                 printf("Unknown mode\n");
1422 }
1423
1424 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1425         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1426                         set, "set");
1427 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1428         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1429                         port, "port");
1430 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1431         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1432                         setup, "setup");
1433 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1434         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1435                         on, "on");
1436 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1437         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1438                         mode, "iterator#event");
1439
1440 cmdline_parse_inst_t cmd_set_port_setup_on = {
1441         .f = cmd_set_port_setup_on_parsed,
1442         .data = NULL,
1443         .help_str = "set port setup on iterator|event",
1444         .tokens = {
1445                 (void *)&cmd_set_port_setup_on_set,
1446                 (void *)&cmd_set_port_setup_on_port,
1447                 (void *)&cmd_set_port_setup_on_setup,
1448                 (void *)&cmd_set_port_setup_on_on,
1449                 (void *)&cmd_set_port_setup_on_mode,
1450                 NULL,
1451         },
1452 };
1453
1454 /* *** attach a specified port *** */
1455 struct cmd_operate_attach_port_result {
1456         cmdline_fixed_string_t port;
1457         cmdline_fixed_string_t keyword;
1458         cmdline_multi_string_t identifier;
1459 };
1460
1461 static void cmd_operate_attach_port_parsed(void *parsed_result,
1462                                 __rte_unused struct cmdline *cl,
1463                                 __rte_unused void *data)
1464 {
1465         struct cmd_operate_attach_port_result *res = parsed_result;
1466
1467         if (!strcmp(res->keyword, "attach"))
1468                 attach_port(res->identifier);
1469         else
1470                 printf("Unknown parameter\n");
1471 }
1472
1473 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1474         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1475                         port, "port");
1476 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1477         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1478                         keyword, "attach");
1479 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1480         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1481                         identifier, TOKEN_STRING_MULTI);
1482
1483 cmdline_parse_inst_t cmd_operate_attach_port = {
1484         .f = cmd_operate_attach_port_parsed,
1485         .data = NULL,
1486         .help_str = "port attach <identifier>: "
1487                 "(identifier: pci address or virtual dev name)",
1488         .tokens = {
1489                 (void *)&cmd_operate_attach_port_port,
1490                 (void *)&cmd_operate_attach_port_keyword,
1491                 (void *)&cmd_operate_attach_port_identifier,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** detach a specified port *** */
1497 struct cmd_operate_detach_port_result {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         portid_t port_id;
1501 };
1502
1503 static void cmd_operate_detach_port_parsed(void *parsed_result,
1504                                 __rte_unused struct cmdline *cl,
1505                                 __rte_unused void *data)
1506 {
1507         struct cmd_operate_detach_port_result *res = parsed_result;
1508
1509         if (!strcmp(res->keyword, "detach")) {
1510                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1511                 detach_port_device(res->port_id);
1512         } else {
1513                 printf("Unknown parameter\n");
1514         }
1515 }
1516
1517 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1518         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1519                         port, "port");
1520 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1521         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1522                         keyword, "detach");
1523 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1524         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1525                         port_id, UINT16);
1526
1527 cmdline_parse_inst_t cmd_operate_detach_port = {
1528         .f = cmd_operate_detach_port_parsed,
1529         .data = NULL,
1530         .help_str = "port detach <port_id>",
1531         .tokens = {
1532                 (void *)&cmd_operate_detach_port_port,
1533                 (void *)&cmd_operate_detach_port_keyword,
1534                 (void *)&cmd_operate_detach_port_port_id,
1535                 NULL,
1536         },
1537 };
1538
1539 /* *** detach device by identifier *** */
1540 struct cmd_operate_detach_device_result {
1541         cmdline_fixed_string_t device;
1542         cmdline_fixed_string_t keyword;
1543         cmdline_fixed_string_t identifier;
1544 };
1545
1546 static void cmd_operate_detach_device_parsed(void *parsed_result,
1547                                 __rte_unused struct cmdline *cl,
1548                                 __rte_unused void *data)
1549 {
1550         struct cmd_operate_detach_device_result *res = parsed_result;
1551
1552         if (!strcmp(res->keyword, "detach"))
1553                 detach_devargs(res->identifier);
1554         else
1555                 printf("Unknown parameter\n");
1556 }
1557
1558 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1559         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1560                         device, "device");
1561 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1562         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1563                         keyword, "detach");
1564 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1565         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1566                         identifier, NULL);
1567
1568 cmdline_parse_inst_t cmd_operate_detach_device = {
1569         .f = cmd_operate_detach_device_parsed,
1570         .data = NULL,
1571         .help_str = "device detach <identifier>:"
1572                 "(identifier: pci address or virtual dev name)",
1573         .tokens = {
1574                 (void *)&cmd_operate_detach_device_device,
1575                 (void *)&cmd_operate_detach_device_keyword,
1576                 (void *)&cmd_operate_detach_device_identifier,
1577                 NULL,
1578         },
1579 };
1580 /* *** configure speed for all ports *** */
1581 struct cmd_config_speed_all {
1582         cmdline_fixed_string_t port;
1583         cmdline_fixed_string_t keyword;
1584         cmdline_fixed_string_t all;
1585         cmdline_fixed_string_t item1;
1586         cmdline_fixed_string_t item2;
1587         cmdline_fixed_string_t value1;
1588         cmdline_fixed_string_t value2;
1589 };
1590
1591 static int
1592 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1593 {
1594
1595         int duplex;
1596
1597         if (!strcmp(duplexstr, "half")) {
1598                 duplex = ETH_LINK_HALF_DUPLEX;
1599         } else if (!strcmp(duplexstr, "full")) {
1600                 duplex = ETH_LINK_FULL_DUPLEX;
1601         } else if (!strcmp(duplexstr, "auto")) {
1602                 duplex = ETH_LINK_FULL_DUPLEX;
1603         } else {
1604                 printf("Unknown duplex parameter\n");
1605                 return -1;
1606         }
1607
1608         if (!strcmp(speedstr, "10")) {
1609                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1610                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1611         } else if (!strcmp(speedstr, "100")) {
1612                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1613                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1614         } else {
1615                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1616                         printf("Invalid speed/duplex parameters\n");
1617                         return -1;
1618                 }
1619                 if (!strcmp(speedstr, "1000")) {
1620                         *speed = ETH_LINK_SPEED_1G;
1621                 } else if (!strcmp(speedstr, "10000")) {
1622                         *speed = ETH_LINK_SPEED_10G;
1623                 } else if (!strcmp(speedstr, "25000")) {
1624                         *speed = ETH_LINK_SPEED_25G;
1625                 } else if (!strcmp(speedstr, "40000")) {
1626                         *speed = ETH_LINK_SPEED_40G;
1627                 } else if (!strcmp(speedstr, "50000")) {
1628                         *speed = ETH_LINK_SPEED_50G;
1629                 } else if (!strcmp(speedstr, "100000")) {
1630                         *speed = ETH_LINK_SPEED_100G;
1631                 } else if (!strcmp(speedstr, "200000")) {
1632                         *speed = ETH_LINK_SPEED_200G;
1633                 } else if (!strcmp(speedstr, "auto")) {
1634                         *speed = ETH_LINK_SPEED_AUTONEG;
1635                 } else {
1636                         printf("Unknown speed parameter\n");
1637                         return -1;
1638                 }
1639         }
1640
1641         return 0;
1642 }
1643
1644 static void
1645 cmd_config_speed_all_parsed(void *parsed_result,
1646                         __rte_unused struct cmdline *cl,
1647                         __rte_unused void *data)
1648 {
1649         struct cmd_config_speed_all *res = parsed_result;
1650         uint32_t link_speed;
1651         portid_t pid;
1652
1653         if (!all_ports_stopped()) {
1654                 printf("Please stop all ports first\n");
1655                 return;
1656         }
1657
1658         if (parse_and_check_speed_duplex(res->value1, res->value2,
1659                         &link_speed) < 0)
1660                 return;
1661
1662         RTE_ETH_FOREACH_DEV(pid) {
1663                 ports[pid].dev_conf.link_speeds = link_speed;
1664         }
1665
1666         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1667 }
1668
1669 cmdline_parse_token_string_t cmd_config_speed_all_port =
1670         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1671 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1672         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1673                                                         "config");
1674 cmdline_parse_token_string_t cmd_config_speed_all_all =
1675         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1676 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1677         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1678 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1679         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1680                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1681 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1682         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1683 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1685                                                 "half#full#auto");
1686
1687 cmdline_parse_inst_t cmd_config_speed_all = {
1688         .f = cmd_config_speed_all_parsed,
1689         .data = NULL,
1690         .help_str = "port config all speed "
1691                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1692                                                         "half|full|auto",
1693         .tokens = {
1694                 (void *)&cmd_config_speed_all_port,
1695                 (void *)&cmd_config_speed_all_keyword,
1696                 (void *)&cmd_config_speed_all_all,
1697                 (void *)&cmd_config_speed_all_item1,
1698                 (void *)&cmd_config_speed_all_value1,
1699                 (void *)&cmd_config_speed_all_item2,
1700                 (void *)&cmd_config_speed_all_value2,
1701                 NULL,
1702         },
1703 };
1704
1705 /* *** configure speed for specific port *** */
1706 struct cmd_config_speed_specific {
1707         cmdline_fixed_string_t port;
1708         cmdline_fixed_string_t keyword;
1709         portid_t id;
1710         cmdline_fixed_string_t item1;
1711         cmdline_fixed_string_t item2;
1712         cmdline_fixed_string_t value1;
1713         cmdline_fixed_string_t value2;
1714 };
1715
1716 static void
1717 cmd_config_speed_specific_parsed(void *parsed_result,
1718                                 __rte_unused struct cmdline *cl,
1719                                 __rte_unused void *data)
1720 {
1721         struct cmd_config_speed_specific *res = parsed_result;
1722         uint32_t link_speed;
1723
1724         if (!all_ports_stopped()) {
1725                 printf("Please stop all ports first\n");
1726                 return;
1727         }
1728
1729         if (port_id_is_invalid(res->id, ENABLED_WARN))
1730                 return;
1731
1732         if (parse_and_check_speed_duplex(res->value1, res->value2,
1733                         &link_speed) < 0)
1734                 return;
1735
1736         ports[res->id].dev_conf.link_speeds = link_speed;
1737
1738         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1739 }
1740
1741
1742 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1743         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1744                                                                 "port");
1745 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1746         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1747                                                                 "config");
1748 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1749         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1750 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1751         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1752                                                                 "speed");
1753 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1754         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1755                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1756 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1757         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1758                                                                 "duplex");
1759 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1761                                                         "half#full#auto");
1762
1763 cmdline_parse_inst_t cmd_config_speed_specific = {
1764         .f = cmd_config_speed_specific_parsed,
1765         .data = NULL,
1766         .help_str = "port config <port_id> speed "
1767                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1768                                                         "half|full|auto",
1769         .tokens = {
1770                 (void *)&cmd_config_speed_specific_port,
1771                 (void *)&cmd_config_speed_specific_keyword,
1772                 (void *)&cmd_config_speed_specific_id,
1773                 (void *)&cmd_config_speed_specific_item1,
1774                 (void *)&cmd_config_speed_specific_value1,
1775                 (void *)&cmd_config_speed_specific_item2,
1776                 (void *)&cmd_config_speed_specific_value2,
1777                 NULL,
1778         },
1779 };
1780
1781 /* *** configure loopback for all ports *** */
1782 struct cmd_config_loopback_all {
1783         cmdline_fixed_string_t port;
1784         cmdline_fixed_string_t keyword;
1785         cmdline_fixed_string_t all;
1786         cmdline_fixed_string_t item;
1787         uint32_t mode;
1788 };
1789
1790 static void
1791 cmd_config_loopback_all_parsed(void *parsed_result,
1792                         __rte_unused struct cmdline *cl,
1793                         __rte_unused void *data)
1794 {
1795         struct cmd_config_loopback_all *res = parsed_result;
1796         portid_t pid;
1797
1798         if (!all_ports_stopped()) {
1799                 printf("Please stop all ports first\n");
1800                 return;
1801         }
1802
1803         RTE_ETH_FOREACH_DEV(pid) {
1804                 ports[pid].dev_conf.lpbk_mode = res->mode;
1805         }
1806
1807         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1808 }
1809
1810 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1811         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1812 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1813         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1814                                                         "config");
1815 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1816         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1817 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1818         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1819                                                         "loopback");
1820 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1821         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1822
1823 cmdline_parse_inst_t cmd_config_loopback_all = {
1824         .f = cmd_config_loopback_all_parsed,
1825         .data = NULL,
1826         .help_str = "port config all loopback <mode>",
1827         .tokens = {
1828                 (void *)&cmd_config_loopback_all_port,
1829                 (void *)&cmd_config_loopback_all_keyword,
1830                 (void *)&cmd_config_loopback_all_all,
1831                 (void *)&cmd_config_loopback_all_item,
1832                 (void *)&cmd_config_loopback_all_mode,
1833                 NULL,
1834         },
1835 };
1836
1837 /* *** configure loopback for specific port *** */
1838 struct cmd_config_loopback_specific {
1839         cmdline_fixed_string_t port;
1840         cmdline_fixed_string_t keyword;
1841         uint16_t port_id;
1842         cmdline_fixed_string_t item;
1843         uint32_t mode;
1844 };
1845
1846 static void
1847 cmd_config_loopback_specific_parsed(void *parsed_result,
1848                                 __rte_unused struct cmdline *cl,
1849                                 __rte_unused void *data)
1850 {
1851         struct cmd_config_loopback_specific *res = parsed_result;
1852
1853         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1854                 return;
1855
1856         if (!port_is_stopped(res->port_id)) {
1857                 printf("Please stop port %u first\n", res->port_id);
1858                 return;
1859         }
1860
1861         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1862
1863         cmd_reconfig_device_queue(res->port_id, 1, 1);
1864 }
1865
1866
1867 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1868         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1869                                                                 "port");
1870 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1871         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1872                                                                 "config");
1873 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1874         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1875                                                                 UINT16);
1876 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1878                                                                 "loopback");
1879 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1880         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1881                               UINT32);
1882
1883 cmdline_parse_inst_t cmd_config_loopback_specific = {
1884         .f = cmd_config_loopback_specific_parsed,
1885         .data = NULL,
1886         .help_str = "port config <port_id> loopback <mode>",
1887         .tokens = {
1888                 (void *)&cmd_config_loopback_specific_port,
1889                 (void *)&cmd_config_loopback_specific_keyword,
1890                 (void *)&cmd_config_loopback_specific_id,
1891                 (void *)&cmd_config_loopback_specific_item,
1892                 (void *)&cmd_config_loopback_specific_mode,
1893                 NULL,
1894         },
1895 };
1896
1897 /* *** configure txq/rxq, txd/rxd *** */
1898 struct cmd_config_rx_tx {
1899         cmdline_fixed_string_t port;
1900         cmdline_fixed_string_t keyword;
1901         cmdline_fixed_string_t all;
1902         cmdline_fixed_string_t name;
1903         uint16_t value;
1904 };
1905
1906 static void
1907 cmd_config_rx_tx_parsed(void *parsed_result,
1908                         __rte_unused struct cmdline *cl,
1909                         __rte_unused void *data)
1910 {
1911         struct cmd_config_rx_tx *res = parsed_result;
1912
1913         if (!all_ports_stopped()) {
1914                 printf("Please stop all ports first\n");
1915                 return;
1916         }
1917         if (!strcmp(res->name, "rxq")) {
1918                 if (!res->value && !nb_txq) {
1919                         printf("Warning: Either rx or tx queues should be non zero\n");
1920                         return;
1921                 }
1922                 if (check_nb_rxq(res->value) != 0)
1923                         return;
1924                 nb_rxq = res->value;
1925         }
1926         else if (!strcmp(res->name, "txq")) {
1927                 if (!res->value && !nb_rxq) {
1928                         printf("Warning: Either rx or tx queues should be non zero\n");
1929                         return;
1930                 }
1931                 if (check_nb_txq(res->value) != 0)
1932                         return;
1933                 nb_txq = res->value;
1934         }
1935         else if (!strcmp(res->name, "rxd")) {
1936                 if (check_nb_rxd(res->value) != 0)
1937                         return;
1938                 nb_rxd = res->value;
1939         } else if (!strcmp(res->name, "txd")) {
1940                 if (check_nb_txd(res->value) != 0)
1941                         return;
1942
1943                 nb_txd = res->value;
1944         } else {
1945                 printf("Unknown parameter\n");
1946                 return;
1947         }
1948
1949         fwd_config_setup();
1950
1951         init_port_config();
1952
1953         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1954 }
1955
1956 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1957         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1958 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1959         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1960 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1961         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1962 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1964                                                 "rxq#txq#rxd#txd");
1965 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1966         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1967
1968 cmdline_parse_inst_t cmd_config_rx_tx = {
1969         .f = cmd_config_rx_tx_parsed,
1970         .data = NULL,
1971         .help_str = "port config all rxq|txq|rxd|txd <value>",
1972         .tokens = {
1973                 (void *)&cmd_config_rx_tx_port,
1974                 (void *)&cmd_config_rx_tx_keyword,
1975                 (void *)&cmd_config_rx_tx_all,
1976                 (void *)&cmd_config_rx_tx_name,
1977                 (void *)&cmd_config_rx_tx_value,
1978                 NULL,
1979         },
1980 };
1981
1982 /* *** config max packet length *** */
1983 struct cmd_config_max_pkt_len_result {
1984         cmdline_fixed_string_t port;
1985         cmdline_fixed_string_t keyword;
1986         cmdline_fixed_string_t all;
1987         cmdline_fixed_string_t name;
1988         uint32_t value;
1989 };
1990
1991 static void
1992 cmd_config_max_pkt_len_parsed(void *parsed_result,
1993                                 __rte_unused struct cmdline *cl,
1994                                 __rte_unused void *data)
1995 {
1996         struct cmd_config_max_pkt_len_result *res = parsed_result;
1997         portid_t pid;
1998
1999         if (!all_ports_stopped()) {
2000                 printf("Please stop all ports first\n");
2001                 return;
2002         }
2003
2004         RTE_ETH_FOREACH_DEV(pid) {
2005                 struct rte_port *port = &ports[pid];
2006                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2007
2008                 if (!strcmp(res->name, "max-pkt-len")) {
2009                         if (res->value < RTE_ETHER_MIN_LEN) {
2010                                 printf("max-pkt-len can not be less than %d\n",
2011                                                 RTE_ETHER_MIN_LEN);
2012                                 return;
2013                         }
2014                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2015                                 return;
2016
2017                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2018                         if (res->value > RTE_ETHER_MAX_LEN)
2019                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2020                         else
2021                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2022                         port->dev_conf.rxmode.offloads = rx_offloads;
2023                 } else {
2024                         printf("Unknown parameter\n");
2025                         return;
2026                 }
2027         }
2028
2029         init_port_config();
2030
2031         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2032 }
2033
2034 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2035         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2036                                                                 "port");
2037 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2038         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2039                                                                 "config");
2040 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2041         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2042                                                                 "all");
2043 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2044         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2045                                                                 "max-pkt-len");
2046 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2047         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2048                                                                 UINT32);
2049
2050 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2051         .f = cmd_config_max_pkt_len_parsed,
2052         .data = NULL,
2053         .help_str = "port config all max-pkt-len <value>",
2054         .tokens = {
2055                 (void *)&cmd_config_max_pkt_len_port,
2056                 (void *)&cmd_config_max_pkt_len_keyword,
2057                 (void *)&cmd_config_max_pkt_len_all,
2058                 (void *)&cmd_config_max_pkt_len_name,
2059                 (void *)&cmd_config_max_pkt_len_value,
2060                 NULL,
2061         },
2062 };
2063
2064 /* *** config max LRO aggregated packet size *** */
2065 struct cmd_config_max_lro_pkt_size_result {
2066         cmdline_fixed_string_t port;
2067         cmdline_fixed_string_t keyword;
2068         cmdline_fixed_string_t all;
2069         cmdline_fixed_string_t name;
2070         uint32_t value;
2071 };
2072
2073 static void
2074 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2075                                 __rte_unused struct cmdline *cl,
2076                                 __rte_unused void *data)
2077 {
2078         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2079         portid_t pid;
2080
2081         if (!all_ports_stopped()) {
2082                 printf("Please stop all ports first\n");
2083                 return;
2084         }
2085
2086         RTE_ETH_FOREACH_DEV(pid) {
2087                 struct rte_port *port = &ports[pid];
2088
2089                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2090                         if (res->value ==
2091                                         port->dev_conf.rxmode.max_lro_pkt_size)
2092                                 return;
2093
2094                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2095                 } else {
2096                         printf("Unknown parameter\n");
2097                         return;
2098                 }
2099         }
2100
2101         init_port_config();
2102
2103         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2104 }
2105
2106 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2107         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2108                                  port, "port");
2109 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2110         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2111                                  keyword, "config");
2112 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114                                  all, "all");
2115 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2116         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2117                                  name, "max-lro-pkt-size");
2118 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2119         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2120                               value, UINT32);
2121
2122 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2123         .f = cmd_config_max_lro_pkt_size_parsed,
2124         .data = NULL,
2125         .help_str = "port config all max-lro-pkt-size <value>",
2126         .tokens = {
2127                 (void *)&cmd_config_max_lro_pkt_size_port,
2128                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2129                 (void *)&cmd_config_max_lro_pkt_size_all,
2130                 (void *)&cmd_config_max_lro_pkt_size_name,
2131                 (void *)&cmd_config_max_lro_pkt_size_value,
2132                 NULL,
2133         },
2134 };
2135
2136 /* *** configure port MTU *** */
2137 struct cmd_config_mtu_result {
2138         cmdline_fixed_string_t port;
2139         cmdline_fixed_string_t keyword;
2140         cmdline_fixed_string_t mtu;
2141         portid_t port_id;
2142         uint16_t value;
2143 };
2144
2145 static void
2146 cmd_config_mtu_parsed(void *parsed_result,
2147                       __rte_unused struct cmdline *cl,
2148                       __rte_unused void *data)
2149 {
2150         struct cmd_config_mtu_result *res = parsed_result;
2151
2152         if (res->value < RTE_ETHER_MIN_LEN) {
2153                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2154                 return;
2155         }
2156         port_mtu_set(res->port_id, res->value);
2157 }
2158
2159 cmdline_parse_token_string_t cmd_config_mtu_port =
2160         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2161                                  "port");
2162 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2163         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2164                                  "config");
2165 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2166         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2167                                  "mtu");
2168 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2169         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2170 cmdline_parse_token_num_t cmd_config_mtu_value =
2171         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2172
2173 cmdline_parse_inst_t cmd_config_mtu = {
2174         .f = cmd_config_mtu_parsed,
2175         .data = NULL,
2176         .help_str = "port config mtu <port_id> <value>",
2177         .tokens = {
2178                 (void *)&cmd_config_mtu_port,
2179                 (void *)&cmd_config_mtu_keyword,
2180                 (void *)&cmd_config_mtu_mtu,
2181                 (void *)&cmd_config_mtu_port_id,
2182                 (void *)&cmd_config_mtu_value,
2183                 NULL,
2184         },
2185 };
2186
2187 /* *** configure rx mode *** */
2188 struct cmd_config_rx_mode_flag {
2189         cmdline_fixed_string_t port;
2190         cmdline_fixed_string_t keyword;
2191         cmdline_fixed_string_t all;
2192         cmdline_fixed_string_t name;
2193         cmdline_fixed_string_t value;
2194 };
2195
2196 static void
2197 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2198                                 __rte_unused struct cmdline *cl,
2199                                 __rte_unused void *data)
2200 {
2201         struct cmd_config_rx_mode_flag *res = parsed_result;
2202
2203         if (!all_ports_stopped()) {
2204                 printf("Please stop all ports first\n");
2205                 return;
2206         }
2207
2208         if (!strcmp(res->name, "drop-en")) {
2209                 if (!strcmp(res->value, "on"))
2210                         rx_drop_en = 1;
2211                 else if (!strcmp(res->value, "off"))
2212                         rx_drop_en = 0;
2213                 else {
2214                         printf("Unknown parameter\n");
2215                         return;
2216                 }
2217         } else {
2218                 printf("Unknown parameter\n");
2219                 return;
2220         }
2221
2222         init_port_config();
2223
2224         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2225 }
2226
2227 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2228         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2229 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2230         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2231                                                                 "config");
2232 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2233         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2234 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2235         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2236                                         "drop-en");
2237 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2238         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2239                                                         "on#off");
2240
2241 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2242         .f = cmd_config_rx_mode_flag_parsed,
2243         .data = NULL,
2244         .help_str = "port config all drop-en on|off",
2245         .tokens = {
2246                 (void *)&cmd_config_rx_mode_flag_port,
2247                 (void *)&cmd_config_rx_mode_flag_keyword,
2248                 (void *)&cmd_config_rx_mode_flag_all,
2249                 (void *)&cmd_config_rx_mode_flag_name,
2250                 (void *)&cmd_config_rx_mode_flag_value,
2251                 NULL,
2252         },
2253 };
2254
2255 /* *** configure rss *** */
2256 struct cmd_config_rss {
2257         cmdline_fixed_string_t port;
2258         cmdline_fixed_string_t keyword;
2259         cmdline_fixed_string_t all;
2260         cmdline_fixed_string_t name;
2261         cmdline_fixed_string_t value;
2262 };
2263
2264 static void
2265 cmd_config_rss_parsed(void *parsed_result,
2266                         __rte_unused struct cmdline *cl,
2267                         __rte_unused void *data)
2268 {
2269         struct cmd_config_rss *res = parsed_result;
2270         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2271         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2272         int use_default = 0;
2273         int all_updated = 1;
2274         int diag;
2275         uint16_t i;
2276         int ret;
2277
2278         if (!strcmp(res->value, "all"))
2279                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2280                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2281                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2282                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2283         else if (!strcmp(res->value, "eth"))
2284                 rss_conf.rss_hf = ETH_RSS_ETH;
2285         else if (!strcmp(res->value, "vlan"))
2286                 rss_conf.rss_hf = ETH_RSS_VLAN;
2287         else if (!strcmp(res->value, "ip"))
2288                 rss_conf.rss_hf = ETH_RSS_IP;
2289         else if (!strcmp(res->value, "udp"))
2290                 rss_conf.rss_hf = ETH_RSS_UDP;
2291         else if (!strcmp(res->value, "tcp"))
2292                 rss_conf.rss_hf = ETH_RSS_TCP;
2293         else if (!strcmp(res->value, "sctp"))
2294                 rss_conf.rss_hf = ETH_RSS_SCTP;
2295         else if (!strcmp(res->value, "ether"))
2296                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2297         else if (!strcmp(res->value, "port"))
2298                 rss_conf.rss_hf = ETH_RSS_PORT;
2299         else if (!strcmp(res->value, "vxlan"))
2300                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2301         else if (!strcmp(res->value, "geneve"))
2302                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2303         else if (!strcmp(res->value, "nvgre"))
2304                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2305         else if (!strcmp(res->value, "l3-pre32"))
2306                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2307         else if (!strcmp(res->value, "l3-pre40"))
2308                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2309         else if (!strcmp(res->value, "l3-pre48"))
2310                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2311         else if (!strcmp(res->value, "l3-pre56"))
2312                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2313         else if (!strcmp(res->value, "l3-pre64"))
2314                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2315         else if (!strcmp(res->value, "l3-pre96"))
2316                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2317         else if (!strcmp(res->value, "l3-src-only"))
2318                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2319         else if (!strcmp(res->value, "l3-dst-only"))
2320                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2321         else if (!strcmp(res->value, "l4-src-only"))
2322                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2323         else if (!strcmp(res->value, "l4-dst-only"))
2324                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2325         else if (!strcmp(res->value, "l2-src-only"))
2326                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2327         else if (!strcmp(res->value, "l2-dst-only"))
2328                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2329         else if (!strcmp(res->value, "l2tpv3"))
2330                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2331         else if (!strcmp(res->value, "esp"))
2332                 rss_conf.rss_hf = ETH_RSS_ESP;
2333         else if (!strcmp(res->value, "ah"))
2334                 rss_conf.rss_hf = ETH_RSS_AH;
2335         else if (!strcmp(res->value, "pfcp"))
2336                 rss_conf.rss_hf = ETH_RSS_PFCP;
2337         else if (!strcmp(res->value, "pppoe"))
2338                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2339         else if (!strcmp(res->value, "gtpu"))
2340                 rss_conf.rss_hf = ETH_RSS_GTPU;
2341         else if (!strcmp(res->value, "none"))
2342                 rss_conf.rss_hf = 0;
2343         else if (!strcmp(res->value, "default"))
2344                 use_default = 1;
2345         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2346                                                 atoi(res->value) < 64)
2347                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2348         else {
2349                 printf("Unknown parameter\n");
2350                 return;
2351         }
2352         rss_conf.rss_key = NULL;
2353         /* Update global configuration for RSS types. */
2354         RTE_ETH_FOREACH_DEV(i) {
2355                 struct rte_eth_rss_conf local_rss_conf;
2356
2357                 ret = eth_dev_info_get_print_err(i, &dev_info);
2358                 if (ret != 0)
2359                         return;
2360
2361                 if (use_default)
2362                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2363
2364                 local_rss_conf = rss_conf;
2365                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2366                         dev_info.flow_type_rss_offloads;
2367                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2368                         printf("Port %u modified RSS hash function based on hardware support,"
2369                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2370                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2371                 }
2372                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2373                 if (diag < 0) {
2374                         all_updated = 0;
2375                         printf("Configuration of RSS hash at ethernet port %d "
2376                                 "failed with error (%d): %s.\n",
2377                                 i, -diag, strerror(-diag));
2378                 }
2379         }
2380         if (all_updated && !use_default) {
2381                 rss_hf = rss_conf.rss_hf;
2382                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2383         }
2384 }
2385
2386 cmdline_parse_token_string_t cmd_config_rss_port =
2387         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2388 cmdline_parse_token_string_t cmd_config_rss_keyword =
2389         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2390 cmdline_parse_token_string_t cmd_config_rss_all =
2391         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2392 cmdline_parse_token_string_t cmd_config_rss_name =
2393         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2394 cmdline_parse_token_string_t cmd_config_rss_value =
2395         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2396
2397 cmdline_parse_inst_t cmd_config_rss = {
2398         .f = cmd_config_rss_parsed,
2399         .data = NULL,
2400         .help_str = "port config all rss "
2401                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2402                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2403         .tokens = {
2404                 (void *)&cmd_config_rss_port,
2405                 (void *)&cmd_config_rss_keyword,
2406                 (void *)&cmd_config_rss_all,
2407                 (void *)&cmd_config_rss_name,
2408                 (void *)&cmd_config_rss_value,
2409                 NULL,
2410         },
2411 };
2412
2413 /* *** configure rss hash key *** */
2414 struct cmd_config_rss_hash_key {
2415         cmdline_fixed_string_t port;
2416         cmdline_fixed_string_t config;
2417         portid_t port_id;
2418         cmdline_fixed_string_t rss_hash_key;
2419         cmdline_fixed_string_t rss_type;
2420         cmdline_fixed_string_t key;
2421 };
2422
2423 static uint8_t
2424 hexa_digit_to_value(char hexa_digit)
2425 {
2426         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2427                 return (uint8_t) (hexa_digit - '0');
2428         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2429                 return (uint8_t) ((hexa_digit - 'a') + 10);
2430         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2431                 return (uint8_t) ((hexa_digit - 'A') + 10);
2432         /* Invalid hexa digit */
2433         return 0xFF;
2434 }
2435
2436 static uint8_t
2437 parse_and_check_key_hexa_digit(char *key, int idx)
2438 {
2439         uint8_t hexa_v;
2440
2441         hexa_v = hexa_digit_to_value(key[idx]);
2442         if (hexa_v == 0xFF)
2443                 printf("invalid key: character %c at position %d is not a "
2444                        "valid hexa digit\n", key[idx], idx);
2445         return hexa_v;
2446 }
2447
2448 static void
2449 cmd_config_rss_hash_key_parsed(void *parsed_result,
2450                                __rte_unused struct cmdline *cl,
2451                                __rte_unused void *data)
2452 {
2453         struct cmd_config_rss_hash_key *res = parsed_result;
2454         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2455         uint8_t xdgt0;
2456         uint8_t xdgt1;
2457         int i;
2458         struct rte_eth_dev_info dev_info;
2459         uint8_t hash_key_size;
2460         uint32_t key_len;
2461         int ret;
2462
2463         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2464         if (ret != 0)
2465                 return;
2466
2467         if (dev_info.hash_key_size > 0 &&
2468                         dev_info.hash_key_size <= sizeof(hash_key))
2469                 hash_key_size = dev_info.hash_key_size;
2470         else {
2471                 printf("dev_info did not provide a valid hash key size\n");
2472                 return;
2473         }
2474         /* Check the length of the RSS hash key */
2475         key_len = strlen(res->key);
2476         if (key_len != (hash_key_size * 2)) {
2477                 printf("key length: %d invalid - key must be a string of %d"
2478                            " hexa-decimal numbers\n",
2479                            (int) key_len, hash_key_size * 2);
2480                 return;
2481         }
2482         /* Translate RSS hash key into binary representation */
2483         for (i = 0; i < hash_key_size; i++) {
2484                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2485                 if (xdgt0 == 0xFF)
2486                         return;
2487                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2488                 if (xdgt1 == 0xFF)
2489                         return;
2490                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2491         }
2492         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2493                         hash_key_size);
2494 }
2495
2496 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2497         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2498 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2499         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2500                                  "config");
2501 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2502         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2503 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2504         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2505                                  rss_hash_key, "rss-hash-key");
2506 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2507         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2508                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2509                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2510                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2511                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2512                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2513                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2514                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2515 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2516         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2517
2518 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2519         .f = cmd_config_rss_hash_key_parsed,
2520         .data = NULL,
2521         .help_str = "port config <port_id> rss-hash-key "
2522                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2523                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2524                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2525                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2526                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2527                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2528                 "<string of hex digits (variable length, NIC dependent)>",
2529         .tokens = {
2530                 (void *)&cmd_config_rss_hash_key_port,
2531                 (void *)&cmd_config_rss_hash_key_config,
2532                 (void *)&cmd_config_rss_hash_key_port_id,
2533                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2534                 (void *)&cmd_config_rss_hash_key_rss_type,
2535                 (void *)&cmd_config_rss_hash_key_value,
2536                 NULL,
2537         },
2538 };
2539
2540 /* *** configure port rxq/txq ring size *** */
2541 struct cmd_config_rxtx_ring_size {
2542         cmdline_fixed_string_t port;
2543         cmdline_fixed_string_t config;
2544         portid_t portid;
2545         cmdline_fixed_string_t rxtxq;
2546         uint16_t qid;
2547         cmdline_fixed_string_t rsize;
2548         uint16_t size;
2549 };
2550
2551 static void
2552 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2553                                  __rte_unused struct cmdline *cl,
2554                                  __rte_unused void *data)
2555 {
2556         struct cmd_config_rxtx_ring_size *res = parsed_result;
2557         struct rte_port *port;
2558         uint8_t isrx;
2559
2560         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2561                 return;
2562
2563         if (res->portid == (portid_t)RTE_PORT_ALL) {
2564                 printf("Invalid port id\n");
2565                 return;
2566         }
2567
2568         port = &ports[res->portid];
2569
2570         if (!strcmp(res->rxtxq, "rxq"))
2571                 isrx = 1;
2572         else if (!strcmp(res->rxtxq, "txq"))
2573                 isrx = 0;
2574         else {
2575                 printf("Unknown parameter\n");
2576                 return;
2577         }
2578
2579         if (isrx && rx_queue_id_is_invalid(res->qid))
2580                 return;
2581         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2582                 return;
2583
2584         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2585                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2586                        rx_free_thresh);
2587                 return;
2588         }
2589
2590         if (isrx)
2591                 port->nb_rx_desc[res->qid] = res->size;
2592         else
2593                 port->nb_tx_desc[res->qid] = res->size;
2594
2595         cmd_reconfig_device_queue(res->portid, 0, 1);
2596 }
2597
2598 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2599         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2600                                  port, "port");
2601 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2603                                  config, "config");
2604 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2605         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606                                  portid, UINT16);
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609                                  rxtxq, "rxq#txq");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                               qid, UINT16);
2613 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2614         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615                                  rsize, "ring_size");
2616 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2617         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618                               size, UINT16);
2619
2620 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2621         .f = cmd_config_rxtx_ring_size_parsed,
2622         .data = NULL,
2623         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2624         .tokens = {
2625                 (void *)&cmd_config_rxtx_ring_size_port,
2626                 (void *)&cmd_config_rxtx_ring_size_config,
2627                 (void *)&cmd_config_rxtx_ring_size_portid,
2628                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2629                 (void *)&cmd_config_rxtx_ring_size_qid,
2630                 (void *)&cmd_config_rxtx_ring_size_rsize,
2631                 (void *)&cmd_config_rxtx_ring_size_size,
2632                 NULL,
2633         },
2634 };
2635
2636 /* *** configure port rxq/txq start/stop *** */
2637 struct cmd_config_rxtx_queue {
2638         cmdline_fixed_string_t port;
2639         portid_t portid;
2640         cmdline_fixed_string_t rxtxq;
2641         uint16_t qid;
2642         cmdline_fixed_string_t opname;
2643 };
2644
2645 static void
2646 cmd_config_rxtx_queue_parsed(void *parsed_result,
2647                         __rte_unused struct cmdline *cl,
2648                         __rte_unused void *data)
2649 {
2650         struct cmd_config_rxtx_queue *res = parsed_result;
2651         uint8_t isrx;
2652         uint8_t isstart;
2653         int ret = 0;
2654
2655         if (test_done == 0) {
2656                 printf("Please stop forwarding first\n");
2657                 return;
2658         }
2659
2660         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2661                 return;
2662
2663         if (port_is_started(res->portid) != 1) {
2664                 printf("Please start port %u first\n", res->portid);
2665                 return;
2666         }
2667
2668         if (!strcmp(res->rxtxq, "rxq"))
2669                 isrx = 1;
2670         else if (!strcmp(res->rxtxq, "txq"))
2671                 isrx = 0;
2672         else {
2673                 printf("Unknown parameter\n");
2674                 return;
2675         }
2676
2677         if (isrx && rx_queue_id_is_invalid(res->qid))
2678                 return;
2679         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2680                 return;
2681
2682         if (!strcmp(res->opname, "start"))
2683                 isstart = 1;
2684         else if (!strcmp(res->opname, "stop"))
2685                 isstart = 0;
2686         else {
2687                 printf("Unknown parameter\n");
2688                 return;
2689         }
2690
2691         if (isstart && isrx)
2692                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2693         else if (!isstart && isrx)
2694                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2695         else if (isstart && !isrx)
2696                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2697         else
2698                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2699
2700         if (ret == -ENOTSUP)
2701                 printf("Function not supported in PMD driver\n");
2702 }
2703
2704 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2705         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2706 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2707         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2708 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2709         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2710 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2711         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2712 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2713         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2714                                                 "start#stop");
2715
2716 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2717         .f = cmd_config_rxtx_queue_parsed,
2718         .data = NULL,
2719         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2720         .tokens = {
2721                 (void *)&cmd_config_rxtx_queue_port,
2722                 (void *)&cmd_config_rxtx_queue_portid,
2723                 (void *)&cmd_config_rxtx_queue_rxtxq,
2724                 (void *)&cmd_config_rxtx_queue_qid,
2725                 (void *)&cmd_config_rxtx_queue_opname,
2726                 NULL,
2727         },
2728 };
2729
2730 /* *** configure port rxq/txq deferred start on/off *** */
2731 struct cmd_config_deferred_start_rxtx_queue {
2732         cmdline_fixed_string_t port;
2733         portid_t port_id;
2734         cmdline_fixed_string_t rxtxq;
2735         uint16_t qid;
2736         cmdline_fixed_string_t opname;
2737         cmdline_fixed_string_t state;
2738 };
2739
2740 static void
2741 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2742                         __rte_unused struct cmdline *cl,
2743                         __rte_unused void *data)
2744 {
2745         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2746         struct rte_port *port;
2747         uint8_t isrx;
2748         uint8_t ison;
2749         uint8_t needreconfig = 0;
2750
2751         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2752                 return;
2753
2754         if (port_is_started(res->port_id) != 0) {
2755                 printf("Please stop port %u first\n", res->port_id);
2756                 return;
2757         }
2758
2759         port = &ports[res->port_id];
2760
2761         isrx = !strcmp(res->rxtxq, "rxq");
2762
2763         if (isrx && rx_queue_id_is_invalid(res->qid))
2764                 return;
2765         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2766                 return;
2767
2768         ison = !strcmp(res->state, "on");
2769
2770         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2771                 port->rx_conf[res->qid].rx_deferred_start = ison;
2772                 needreconfig = 1;
2773         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2774                 port->tx_conf[res->qid].tx_deferred_start = ison;
2775                 needreconfig = 1;
2776         }
2777
2778         if (needreconfig)
2779                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2780 }
2781
2782 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2783         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2784                                                 port, "port");
2785 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2786         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2787                                                 port_id, UINT16);
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790                                                 rxtxq, "rxq#txq");
2791 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2792         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793                                                 qid, UINT16);
2794 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2795         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796                                                 opname, "deferred_start");
2797 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2798         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                 state, "on#off");
2800
2801 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2802         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2803         .data = NULL,
2804         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2805         .tokens = {
2806                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2807                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2808                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2809                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2810                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2811                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2812                 NULL,
2813         },
2814 };
2815
2816 /* *** configure port rxq/txq setup *** */
2817 struct cmd_setup_rxtx_queue {
2818         cmdline_fixed_string_t port;
2819         portid_t portid;
2820         cmdline_fixed_string_t rxtxq;
2821         uint16_t qid;
2822         cmdline_fixed_string_t setup;
2823 };
2824
2825 /* Common CLI fields for queue setup */
2826 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2827         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2828 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2829         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2830 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2831         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2832 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2833         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2834 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2835         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2836
2837 static void
2838 cmd_setup_rxtx_queue_parsed(
2839         void *parsed_result,
2840         __rte_unused struct cmdline *cl,
2841         __rte_unused void *data)
2842 {
2843         struct cmd_setup_rxtx_queue *res = parsed_result;
2844         struct rte_port *port;
2845         struct rte_mempool *mp;
2846         unsigned int socket_id;
2847         uint8_t isrx = 0;
2848         int ret;
2849
2850         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2851                 return;
2852
2853         if (res->portid == (portid_t)RTE_PORT_ALL) {
2854                 printf("Invalid port id\n");
2855                 return;
2856         }
2857
2858         if (!strcmp(res->rxtxq, "rxq"))
2859                 isrx = 1;
2860         else if (!strcmp(res->rxtxq, "txq"))
2861                 isrx = 0;
2862         else {
2863                 printf("Unknown parameter\n");
2864                 return;
2865         }
2866
2867         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2868                 printf("Invalid rx queue\n");
2869                 return;
2870         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2871                 printf("Invalid tx queue\n");
2872                 return;
2873         }
2874
2875         port = &ports[res->portid];
2876         if (isrx) {
2877                 socket_id = rxring_numa[res->portid];
2878                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2879                         socket_id = port->socket_id;
2880
2881                 mp = mbuf_pool_find(socket_id);
2882                 if (mp == NULL) {
2883                         printf("Failed to setup RX queue: "
2884                                 "No mempool allocation"
2885                                 " on the socket %d\n",
2886                                 rxring_numa[res->portid]);
2887                         return;
2888                 }
2889                 ret = rte_eth_rx_queue_setup(res->portid,
2890                                              res->qid,
2891                                              port->nb_rx_desc[res->qid],
2892                                              socket_id,
2893                                              &port->rx_conf[res->qid],
2894                                              mp);
2895                 if (ret)
2896                         printf("Failed to setup RX queue\n");
2897         } else {
2898                 socket_id = txring_numa[res->portid];
2899                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2900                         socket_id = port->socket_id;
2901
2902                 ret = rte_eth_tx_queue_setup(res->portid,
2903                                              res->qid,
2904                                              port->nb_tx_desc[res->qid],
2905                                              socket_id,
2906                                              &port->tx_conf[res->qid]);
2907                 if (ret)
2908                         printf("Failed to setup TX queue\n");
2909         }
2910 }
2911
2912 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2913         .f = cmd_setup_rxtx_queue_parsed,
2914         .data = NULL,
2915         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2916         .tokens = {
2917                 (void *)&cmd_setup_rxtx_queue_port,
2918                 (void *)&cmd_setup_rxtx_queue_portid,
2919                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2920                 (void *)&cmd_setup_rxtx_queue_qid,
2921                 (void *)&cmd_setup_rxtx_queue_setup,
2922                 NULL,
2923         },
2924 };
2925
2926
2927 /* *** Configure RSS RETA *** */
2928 struct cmd_config_rss_reta {
2929         cmdline_fixed_string_t port;
2930         cmdline_fixed_string_t keyword;
2931         portid_t port_id;
2932         cmdline_fixed_string_t name;
2933         cmdline_fixed_string_t list_name;
2934         cmdline_fixed_string_t list_of_items;
2935 };
2936
2937 static int
2938 parse_reta_config(const char *str,
2939                   struct rte_eth_rss_reta_entry64 *reta_conf,
2940                   uint16_t nb_entries)
2941 {
2942         int i;
2943         unsigned size;
2944         uint16_t hash_index, idx, shift;
2945         uint16_t nb_queue;
2946         char s[256];
2947         const char *p, *p0 = str;
2948         char *end;
2949         enum fieldnames {
2950                 FLD_HASH_INDEX = 0,
2951                 FLD_QUEUE,
2952                 _NUM_FLD
2953         };
2954         unsigned long int_fld[_NUM_FLD];
2955         char *str_fld[_NUM_FLD];
2956
2957         while ((p = strchr(p0,'(')) != NULL) {
2958                 ++p;
2959                 if((p0 = strchr(p,')')) == NULL)
2960                         return -1;
2961
2962                 size = p0 - p;
2963                 if(size >= sizeof(s))
2964                         return -1;
2965
2966                 snprintf(s, sizeof(s), "%.*s", size, p);
2967                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2968                         return -1;
2969                 for (i = 0; i < _NUM_FLD; i++) {
2970                         errno = 0;
2971                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2972                         if (errno != 0 || end == str_fld[i] ||
2973                                         int_fld[i] > 65535)
2974                                 return -1;
2975                 }
2976
2977                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2978                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2979
2980                 if (hash_index >= nb_entries) {
2981                         printf("Invalid RETA hash index=%d\n", hash_index);
2982                         return -1;
2983                 }
2984
2985                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2986                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2987                 reta_conf[idx].mask |= (1ULL << shift);
2988                 reta_conf[idx].reta[shift] = nb_queue;
2989         }
2990
2991         return 0;
2992 }
2993
2994 static void
2995 cmd_set_rss_reta_parsed(void *parsed_result,
2996                         __rte_unused struct cmdline *cl,
2997                         __rte_unused void *data)
2998 {
2999         int ret;
3000         struct rte_eth_dev_info dev_info;
3001         struct rte_eth_rss_reta_entry64 reta_conf[8];
3002         struct cmd_config_rss_reta *res = parsed_result;
3003
3004         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3005         if (ret != 0)
3006                 return;
3007
3008         if (dev_info.reta_size == 0) {
3009                 printf("Redirection table size is 0 which is "
3010                                         "invalid for RSS\n");
3011                 return;
3012         } else
3013                 printf("The reta size of port %d is %u\n",
3014                         res->port_id, dev_info.reta_size);
3015         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3016                 printf("Currently do not support more than %u entries of "
3017                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3018                 return;
3019         }
3020
3021         memset(reta_conf, 0, sizeof(reta_conf));
3022         if (!strcmp(res->list_name, "reta")) {
3023                 if (parse_reta_config(res->list_of_items, reta_conf,
3024                                                 dev_info.reta_size)) {
3025                         printf("Invalid RSS Redirection Table "
3026                                         "config entered\n");
3027                         return;
3028                 }
3029                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3030                                 reta_conf, dev_info.reta_size);
3031                 if (ret != 0)
3032                         printf("Bad redirection table parameter, "
3033                                         "return code = %d \n", ret);
3034         }
3035 }
3036
3037 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3038         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3039 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3040         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3041 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3042         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3043 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3044         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3045 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3047 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3048         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3049                                  NULL);
3050 cmdline_parse_inst_t cmd_config_rss_reta = {
3051         .f = cmd_set_rss_reta_parsed,
3052         .data = NULL,
3053         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3054         .tokens = {
3055                 (void *)&cmd_config_rss_reta_port,
3056                 (void *)&cmd_config_rss_reta_keyword,
3057                 (void *)&cmd_config_rss_reta_port_id,
3058                 (void *)&cmd_config_rss_reta_name,
3059                 (void *)&cmd_config_rss_reta_list_name,
3060                 (void *)&cmd_config_rss_reta_list_of_items,
3061                 NULL,
3062         },
3063 };
3064
3065 /* *** SHOW PORT RETA INFO *** */
3066 struct cmd_showport_reta {
3067         cmdline_fixed_string_t show;
3068         cmdline_fixed_string_t port;
3069         portid_t port_id;
3070         cmdline_fixed_string_t rss;
3071         cmdline_fixed_string_t reta;
3072         uint16_t size;
3073         cmdline_fixed_string_t list_of_items;
3074 };
3075
3076 static int
3077 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3078                            uint16_t nb_entries,
3079                            char *str)
3080 {
3081         uint32_t size;
3082         const char *p, *p0 = str;
3083         char s[256];
3084         char *end;
3085         char *str_fld[8];
3086         uint16_t i;
3087         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3088                         RTE_RETA_GROUP_SIZE;
3089         int ret;
3090
3091         p = strchr(p0, '(');
3092         if (p == NULL)
3093                 return -1;
3094         p++;
3095         p0 = strchr(p, ')');
3096         if (p0 == NULL)
3097                 return -1;
3098         size = p0 - p;
3099         if (size >= sizeof(s)) {
3100                 printf("The string size exceeds the internal buffer size\n");
3101                 return -1;
3102         }
3103         snprintf(s, sizeof(s), "%.*s", size, p);
3104         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3105         if (ret <= 0 || ret != num) {
3106                 printf("The bits of masks do not match the number of "
3107                                         "reta entries: %u\n", num);
3108                 return -1;
3109         }
3110         for (i = 0; i < ret; i++)
3111                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3112
3113         return 0;
3114 }
3115
3116 static void
3117 cmd_showport_reta_parsed(void *parsed_result,
3118                          __rte_unused struct cmdline *cl,
3119                          __rte_unused void *data)
3120 {
3121         struct cmd_showport_reta *res = parsed_result;
3122         struct rte_eth_rss_reta_entry64 reta_conf[8];
3123         struct rte_eth_dev_info dev_info;
3124         uint16_t max_reta_size;
3125         int ret;
3126
3127         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3128         if (ret != 0)
3129                 return;
3130
3131         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3132         if (res->size == 0 || res->size > max_reta_size) {
3133                 printf("Invalid redirection table size: %u (1-%u)\n",
3134                         res->size, max_reta_size);
3135                 return;
3136         }
3137
3138         memset(reta_conf, 0, sizeof(reta_conf));
3139         if (showport_parse_reta_config(reta_conf, res->size,
3140                                 res->list_of_items) < 0) {
3141                 printf("Invalid string: %s for reta masks\n",
3142                                         res->list_of_items);
3143                 return;
3144         }
3145         port_rss_reta_info(res->port_id, reta_conf, res->size);
3146 }
3147
3148 cmdline_parse_token_string_t cmd_showport_reta_show =
3149         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3150 cmdline_parse_token_string_t cmd_showport_reta_port =
3151         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3152 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3153         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3154 cmdline_parse_token_string_t cmd_showport_reta_rss =
3155         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3156 cmdline_parse_token_string_t cmd_showport_reta_reta =
3157         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3158 cmdline_parse_token_num_t cmd_showport_reta_size =
3159         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3160 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3161         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3162                                         list_of_items, NULL);
3163
3164 cmdline_parse_inst_t cmd_showport_reta = {
3165         .f = cmd_showport_reta_parsed,
3166         .data = NULL,
3167         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3168         .tokens = {
3169                 (void *)&cmd_showport_reta_show,
3170                 (void *)&cmd_showport_reta_port,
3171                 (void *)&cmd_showport_reta_port_id,
3172                 (void *)&cmd_showport_reta_rss,
3173                 (void *)&cmd_showport_reta_reta,
3174                 (void *)&cmd_showport_reta_size,
3175                 (void *)&cmd_showport_reta_list_of_items,
3176                 NULL,
3177         },
3178 };
3179
3180 /* *** Show RSS hash configuration *** */
3181 struct cmd_showport_rss_hash {
3182         cmdline_fixed_string_t show;
3183         cmdline_fixed_string_t port;
3184         portid_t port_id;
3185         cmdline_fixed_string_t rss_hash;
3186         cmdline_fixed_string_t rss_type;
3187         cmdline_fixed_string_t key; /* optional argument */
3188 };
3189
3190 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3191                                 __rte_unused struct cmdline *cl,
3192                                 void *show_rss_key)
3193 {
3194         struct cmd_showport_rss_hash *res = parsed_result;
3195
3196         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3197 }
3198
3199 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3200         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3201 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3202         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3203 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3204         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3205 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3206         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3207                                  "rss-hash");
3208 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3209         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3210
3211 cmdline_parse_inst_t cmd_showport_rss_hash = {
3212         .f = cmd_showport_rss_hash_parsed,
3213         .data = NULL,
3214         .help_str = "show port <port_id> rss-hash",
3215         .tokens = {
3216                 (void *)&cmd_showport_rss_hash_show,
3217                 (void *)&cmd_showport_rss_hash_port,
3218                 (void *)&cmd_showport_rss_hash_port_id,
3219                 (void *)&cmd_showport_rss_hash_rss_hash,
3220                 NULL,
3221         },
3222 };
3223
3224 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3225         .f = cmd_showport_rss_hash_parsed,
3226         .data = (void *)1,
3227         .help_str = "show port <port_id> rss-hash key",
3228         .tokens = {
3229                 (void *)&cmd_showport_rss_hash_show,
3230                 (void *)&cmd_showport_rss_hash_port,
3231                 (void *)&cmd_showport_rss_hash_port_id,
3232                 (void *)&cmd_showport_rss_hash_rss_hash,
3233                 (void *)&cmd_showport_rss_hash_rss_key,
3234                 NULL,
3235         },
3236 };
3237
3238 /* *** Configure DCB *** */
3239 struct cmd_config_dcb {
3240         cmdline_fixed_string_t port;
3241         cmdline_fixed_string_t config;
3242         portid_t port_id;
3243         cmdline_fixed_string_t dcb;
3244         cmdline_fixed_string_t vt;
3245         cmdline_fixed_string_t vt_en;
3246         uint8_t num_tcs;
3247         cmdline_fixed_string_t pfc;
3248         cmdline_fixed_string_t pfc_en;
3249 };
3250
3251 static void
3252 cmd_config_dcb_parsed(void *parsed_result,
3253                         __rte_unused struct cmdline *cl,
3254                         __rte_unused void *data)
3255 {
3256         struct cmd_config_dcb *res = parsed_result;
3257         portid_t port_id = res->port_id;
3258         struct rte_port *port;
3259         uint8_t pfc_en;
3260         int ret;
3261
3262         port = &ports[port_id];
3263         /** Check if the port is not started **/
3264         if (port->port_status != RTE_PORT_STOPPED) {
3265                 printf("Please stop port %d first\n", port_id);
3266                 return;
3267         }
3268
3269         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3270                 printf("The invalid number of traffic class,"
3271                         " only 4 or 8 allowed.\n");
3272                 return;
3273         }
3274
3275         if (nb_fwd_lcores < res->num_tcs) {
3276                 printf("nb_cores shouldn't be less than number of TCs.\n");
3277                 return;
3278         }
3279         if (!strncmp(res->pfc_en, "on", 2))
3280                 pfc_en = 1;
3281         else
3282                 pfc_en = 0;
3283
3284         /* DCB in VT mode */
3285         if (!strncmp(res->vt_en, "on", 2))
3286                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3287                                 (enum rte_eth_nb_tcs)res->num_tcs,
3288                                 pfc_en);
3289         else
3290                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3291                                 (enum rte_eth_nb_tcs)res->num_tcs,
3292                                 pfc_en);
3293
3294
3295         if (ret != 0) {
3296                 printf("Cannot initialize network ports.\n");
3297                 return;
3298         }
3299
3300         cmd_reconfig_device_queue(port_id, 1, 1);
3301 }
3302
3303 cmdline_parse_token_string_t cmd_config_dcb_port =
3304         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3305 cmdline_parse_token_string_t cmd_config_dcb_config =
3306         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3307 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3308         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3309 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3310         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3311 cmdline_parse_token_string_t cmd_config_dcb_vt =
3312         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3313 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3314         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3315 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3316         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3317 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3319 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3321
3322 cmdline_parse_inst_t cmd_config_dcb = {
3323         .f = cmd_config_dcb_parsed,
3324         .data = NULL,
3325         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3326         .tokens = {
3327                 (void *)&cmd_config_dcb_port,
3328                 (void *)&cmd_config_dcb_config,
3329                 (void *)&cmd_config_dcb_port_id,
3330                 (void *)&cmd_config_dcb_dcb,
3331                 (void *)&cmd_config_dcb_vt,
3332                 (void *)&cmd_config_dcb_vt_en,
3333                 (void *)&cmd_config_dcb_num_tcs,
3334                 (void *)&cmd_config_dcb_pfc,
3335                 (void *)&cmd_config_dcb_pfc_en,
3336                 NULL,
3337         },
3338 };
3339
3340 /* *** configure number of packets per burst *** */
3341 struct cmd_config_burst {
3342         cmdline_fixed_string_t port;
3343         cmdline_fixed_string_t keyword;
3344         cmdline_fixed_string_t all;
3345         cmdline_fixed_string_t name;
3346         uint16_t value;
3347 };
3348
3349 static void
3350 cmd_config_burst_parsed(void *parsed_result,
3351                         __rte_unused struct cmdline *cl,
3352                         __rte_unused void *data)
3353 {
3354         struct cmd_config_burst *res = parsed_result;
3355         struct rte_eth_dev_info dev_info;
3356         uint16_t rec_nb_pkts;
3357         int ret;
3358
3359         if (!all_ports_stopped()) {
3360                 printf("Please stop all ports first\n");
3361                 return;
3362         }
3363
3364         if (!strcmp(res->name, "burst")) {
3365                 if (res->value == 0) {
3366                         /* If user gives a value of zero, query the PMD for
3367                          * its recommended Rx burst size. Testpmd uses a single
3368                          * size for all ports, so assume all ports are the same
3369                          * NIC model and use the values from Port 0.
3370                          */
3371                         ret = eth_dev_info_get_print_err(0, &dev_info);
3372                         if (ret != 0)
3373                                 return;
3374
3375                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3376
3377                         if (rec_nb_pkts == 0) {
3378                                 printf("PMD does not recommend a burst size.\n"
3379                                         "User provided value must be between"
3380                                         " 1 and %d\n", MAX_PKT_BURST);
3381                                 return;
3382                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3383                                 printf("PMD recommended burst size of %d"
3384                                         " exceeds maximum value of %d\n",
3385                                         rec_nb_pkts, MAX_PKT_BURST);
3386                                 return;
3387                         }
3388                         printf("Using PMD-provided burst value of %d\n",
3389                                 rec_nb_pkts);
3390                         nb_pkt_per_burst = rec_nb_pkts;
3391                 } else if (res->value > MAX_PKT_BURST) {
3392                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3393                         return;
3394                 } else
3395                         nb_pkt_per_burst = res->value;
3396         } else {
3397                 printf("Unknown parameter\n");
3398                 return;
3399         }
3400
3401         init_port_config();
3402
3403         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3404 }
3405
3406 cmdline_parse_token_string_t cmd_config_burst_port =
3407         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3408 cmdline_parse_token_string_t cmd_config_burst_keyword =
3409         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3410 cmdline_parse_token_string_t cmd_config_burst_all =
3411         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3412 cmdline_parse_token_string_t cmd_config_burst_name =
3413         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3414 cmdline_parse_token_num_t cmd_config_burst_value =
3415         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3416
3417 cmdline_parse_inst_t cmd_config_burst = {
3418         .f = cmd_config_burst_parsed,
3419         .data = NULL,
3420         .help_str = "port config all burst <value>",
3421         .tokens = {
3422                 (void *)&cmd_config_burst_port,
3423                 (void *)&cmd_config_burst_keyword,
3424                 (void *)&cmd_config_burst_all,
3425                 (void *)&cmd_config_burst_name,
3426                 (void *)&cmd_config_burst_value,
3427                 NULL,
3428         },
3429 };
3430
3431 /* *** configure rx/tx queues *** */
3432 struct cmd_config_thresh {
3433         cmdline_fixed_string_t port;
3434         cmdline_fixed_string_t keyword;
3435         cmdline_fixed_string_t all;
3436         cmdline_fixed_string_t name;
3437         uint8_t value;
3438 };
3439
3440 static void
3441 cmd_config_thresh_parsed(void *parsed_result,
3442                         __rte_unused struct cmdline *cl,
3443                         __rte_unused void *data)
3444 {
3445         struct cmd_config_thresh *res = parsed_result;
3446
3447         if (!all_ports_stopped()) {
3448                 printf("Please stop all ports first\n");
3449                 return;
3450         }
3451
3452         if (!strcmp(res->name, "txpt"))
3453                 tx_pthresh = res->value;
3454         else if(!strcmp(res->name, "txht"))
3455                 tx_hthresh = res->value;
3456         else if(!strcmp(res->name, "txwt"))
3457                 tx_wthresh = res->value;
3458         else if(!strcmp(res->name, "rxpt"))
3459                 rx_pthresh = res->value;
3460         else if(!strcmp(res->name, "rxht"))
3461                 rx_hthresh = res->value;
3462         else if(!strcmp(res->name, "rxwt"))
3463                 rx_wthresh = res->value;
3464         else {
3465                 printf("Unknown parameter\n");
3466                 return;
3467         }
3468
3469         init_port_config();
3470
3471         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3472 }
3473
3474 cmdline_parse_token_string_t cmd_config_thresh_port =
3475         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3476 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3477         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3478 cmdline_parse_token_string_t cmd_config_thresh_all =
3479         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3480 cmdline_parse_token_string_t cmd_config_thresh_name =
3481         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3482                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3483 cmdline_parse_token_num_t cmd_config_thresh_value =
3484         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3485
3486 cmdline_parse_inst_t cmd_config_thresh = {
3487         .f = cmd_config_thresh_parsed,
3488         .data = NULL,
3489         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3490         .tokens = {
3491                 (void *)&cmd_config_thresh_port,
3492                 (void *)&cmd_config_thresh_keyword,
3493                 (void *)&cmd_config_thresh_all,
3494                 (void *)&cmd_config_thresh_name,
3495                 (void *)&cmd_config_thresh_value,
3496                 NULL,
3497         },
3498 };
3499
3500 /* *** configure free/rs threshold *** */
3501 struct cmd_config_threshold {
3502         cmdline_fixed_string_t port;
3503         cmdline_fixed_string_t keyword;
3504         cmdline_fixed_string_t all;
3505         cmdline_fixed_string_t name;
3506         uint16_t value;
3507 };
3508
3509 static void
3510 cmd_config_threshold_parsed(void *parsed_result,
3511                         __rte_unused struct cmdline *cl,
3512                         __rte_unused void *data)
3513 {
3514         struct cmd_config_threshold *res = parsed_result;
3515
3516         if (!all_ports_stopped()) {
3517                 printf("Please stop all ports first\n");
3518                 return;
3519         }
3520
3521         if (!strcmp(res->name, "txfreet"))
3522                 tx_free_thresh = res->value;
3523         else if (!strcmp(res->name, "txrst"))
3524                 tx_rs_thresh = res->value;
3525         else if (!strcmp(res->name, "rxfreet"))
3526                 rx_free_thresh = res->value;
3527         else {
3528                 printf("Unknown parameter\n");
3529                 return;
3530         }
3531
3532         init_port_config();
3533
3534         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3535 }
3536
3537 cmdline_parse_token_string_t cmd_config_threshold_port =
3538         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3539 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3540         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3541                                                                 "config");
3542 cmdline_parse_token_string_t cmd_config_threshold_all =
3543         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3544 cmdline_parse_token_string_t cmd_config_threshold_name =
3545         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3546                                                 "txfreet#txrst#rxfreet");
3547 cmdline_parse_token_num_t cmd_config_threshold_value =
3548         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3549
3550 cmdline_parse_inst_t cmd_config_threshold = {
3551         .f = cmd_config_threshold_parsed,
3552         .data = NULL,
3553         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3554         .tokens = {
3555                 (void *)&cmd_config_threshold_port,
3556                 (void *)&cmd_config_threshold_keyword,
3557                 (void *)&cmd_config_threshold_all,
3558                 (void *)&cmd_config_threshold_name,
3559                 (void *)&cmd_config_threshold_value,
3560                 NULL,
3561         },
3562 };
3563
3564 /* *** stop *** */
3565 struct cmd_stop_result {
3566         cmdline_fixed_string_t stop;
3567 };
3568
3569 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3570                             __rte_unused struct cmdline *cl,
3571                             __rte_unused void *data)
3572 {
3573         stop_packet_forwarding();
3574 }
3575
3576 cmdline_parse_token_string_t cmd_stop_stop =
3577         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3578
3579 cmdline_parse_inst_t cmd_stop = {
3580         .f = cmd_stop_parsed,
3581         .data = NULL,
3582         .help_str = "stop: Stop packet forwarding",
3583         .tokens = {
3584                 (void *)&cmd_stop_stop,
3585                 NULL,
3586         },
3587 };
3588
3589 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3590
3591 unsigned int
3592 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3593                 unsigned int *parsed_items, int check_unique_values)
3594 {
3595         unsigned int nb_item;
3596         unsigned int value;
3597         unsigned int i;
3598         unsigned int j;
3599         int value_ok;
3600         char c;
3601
3602         /*
3603          * First parse all items in the list and store their value.
3604          */
3605         value = 0;
3606         nb_item = 0;
3607         value_ok = 0;
3608         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3609                 c = str[i];
3610                 if ((c >= '0') && (c <= '9')) {
3611                         value = (unsigned int) (value * 10 + (c - '0'));
3612                         value_ok = 1;
3613                         continue;
3614                 }
3615                 if (c != ',') {
3616                         printf("character %c is not a decimal digit\n", c);
3617                         return 0;
3618                 }
3619                 if (! value_ok) {
3620                         printf("No valid value before comma\n");
3621                         return 0;
3622                 }
3623                 if (nb_item < max_items) {
3624                         parsed_items[nb_item] = value;
3625                         value_ok = 0;
3626                         value = 0;
3627                 }
3628                 nb_item++;
3629         }
3630         if (nb_item >= max_items) {
3631                 printf("Number of %s = %u > %u (maximum items)\n",
3632                        item_name, nb_item + 1, max_items);
3633                 return 0;
3634         }
3635         parsed_items[nb_item++] = value;
3636         if (! check_unique_values)
3637                 return nb_item;
3638
3639         /*
3640          * Then, check that all values in the list are differents.
3641          * No optimization here...
3642          */
3643         for (i = 0; i < nb_item; i++) {
3644                 for (j = i + 1; j < nb_item; j++) {
3645                         if (parsed_items[j] == parsed_items[i]) {
3646                                 printf("duplicated %s %u at index %u and %u\n",
3647                                        item_name, parsed_items[i], i, j);
3648                                 return 0;
3649                         }
3650                 }
3651         }
3652         return nb_item;
3653 }
3654
3655 struct cmd_set_list_result {
3656         cmdline_fixed_string_t cmd_keyword;
3657         cmdline_fixed_string_t list_name;
3658         cmdline_fixed_string_t list_of_items;
3659 };
3660
3661 static void cmd_set_list_parsed(void *parsed_result,
3662                                 __rte_unused struct cmdline *cl,
3663                                 __rte_unused void *data)
3664 {
3665         struct cmd_set_list_result *res;
3666         union {
3667                 unsigned int lcorelist[RTE_MAX_LCORE];
3668                 unsigned int portlist[RTE_MAX_ETHPORTS];
3669         } parsed_items;
3670         unsigned int nb_item;
3671
3672         if (test_done == 0) {
3673                 printf("Please stop forwarding first\n");
3674                 return;
3675         }
3676
3677         res = parsed_result;
3678         if (!strcmp(res->list_name, "corelist")) {
3679                 nb_item = parse_item_list(res->list_of_items, "core",
3680                                           RTE_MAX_LCORE,
3681                                           parsed_items.lcorelist, 1);
3682                 if (nb_item > 0) {
3683                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3684                         fwd_config_setup();
3685                 }
3686                 return;
3687         }
3688         if (!strcmp(res->list_name, "portlist")) {
3689                 nb_item = parse_item_list(res->list_of_items, "port",
3690                                           RTE_MAX_ETHPORTS,
3691                                           parsed_items.portlist, 1);
3692                 if (nb_item > 0) {
3693                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3694                         fwd_config_setup();
3695                 }
3696         }
3697 }
3698
3699 cmdline_parse_token_string_t cmd_set_list_keyword =
3700         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3701                                  "set");
3702 cmdline_parse_token_string_t cmd_set_list_name =
3703         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3704                                  "corelist#portlist");
3705 cmdline_parse_token_string_t cmd_set_list_of_items =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3707                                  NULL);
3708
3709 cmdline_parse_inst_t cmd_set_fwd_list = {
3710         .f = cmd_set_list_parsed,
3711         .data = NULL,
3712         .help_str = "set corelist|portlist <list0[,list1]*>",
3713         .tokens = {
3714                 (void *)&cmd_set_list_keyword,
3715                 (void *)&cmd_set_list_name,
3716                 (void *)&cmd_set_list_of_items,
3717                 NULL,
3718         },
3719 };
3720
3721 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3722
3723 struct cmd_setmask_result {
3724         cmdline_fixed_string_t set;
3725         cmdline_fixed_string_t mask;
3726         uint64_t hexavalue;
3727 };
3728
3729 static void cmd_set_mask_parsed(void *parsed_result,
3730                                 __rte_unused struct cmdline *cl,
3731                                 __rte_unused void *data)
3732 {
3733         struct cmd_setmask_result *res = parsed_result;
3734
3735         if (test_done == 0) {
3736                 printf("Please stop forwarding first\n");
3737                 return;
3738         }
3739         if (!strcmp(res->mask, "coremask")) {
3740                 set_fwd_lcores_mask(res->hexavalue);
3741                 fwd_config_setup();
3742         } else if (!strcmp(res->mask, "portmask")) {
3743                 set_fwd_ports_mask(res->hexavalue);
3744                 fwd_config_setup();
3745         }
3746 }
3747
3748 cmdline_parse_token_string_t cmd_setmask_set =
3749         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3750 cmdline_parse_token_string_t cmd_setmask_mask =
3751         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3752                                  "coremask#portmask");
3753 cmdline_parse_token_num_t cmd_setmask_value =
3754         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3755
3756 cmdline_parse_inst_t cmd_set_fwd_mask = {
3757         .f = cmd_set_mask_parsed,
3758         .data = NULL,
3759         .help_str = "set coremask|portmask <hexadecimal value>",
3760         .tokens = {
3761                 (void *)&cmd_setmask_set,
3762                 (void *)&cmd_setmask_mask,
3763                 (void *)&cmd_setmask_value,
3764                 NULL,
3765         },
3766 };
3767
3768 /*
3769  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3770  */
3771 struct cmd_set_result {
3772         cmdline_fixed_string_t set;
3773         cmdline_fixed_string_t what;
3774         uint16_t value;
3775 };
3776
3777 static void cmd_set_parsed(void *parsed_result,
3778                            __rte_unused struct cmdline *cl,
3779                            __rte_unused void *data)
3780 {
3781         struct cmd_set_result *res = parsed_result;
3782         if (!strcmp(res->what, "nbport")) {
3783                 set_fwd_ports_number(res->value);
3784                 fwd_config_setup();
3785         } else if (!strcmp(res->what, "nbcore")) {
3786                 set_fwd_lcores_number(res->value);
3787                 fwd_config_setup();
3788         } else if (!strcmp(res->what, "burst"))
3789                 set_nb_pkt_per_burst(res->value);
3790         else if (!strcmp(res->what, "verbose"))
3791                 set_verbose_level(res->value);
3792 }
3793
3794 cmdline_parse_token_string_t cmd_set_set =
3795         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3796 cmdline_parse_token_string_t cmd_set_what =
3797         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3798                                  "nbport#nbcore#burst#verbose");
3799 cmdline_parse_token_num_t cmd_set_value =
3800         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3801
3802 cmdline_parse_inst_t cmd_set_numbers = {
3803         .f = cmd_set_parsed,
3804         .data = NULL,
3805         .help_str = "set nbport|nbcore|burst|verbose <value>",
3806         .tokens = {
3807                 (void *)&cmd_set_set,
3808                 (void *)&cmd_set_what,
3809                 (void *)&cmd_set_value,
3810                 NULL,
3811         },
3812 };
3813
3814 /* *** SET LOG LEVEL CONFIGURATION *** */
3815
3816 struct cmd_set_log_result {
3817         cmdline_fixed_string_t set;
3818         cmdline_fixed_string_t log;
3819         cmdline_fixed_string_t type;
3820         uint32_t level;
3821 };
3822
3823 static void
3824 cmd_set_log_parsed(void *parsed_result,
3825                    __rte_unused struct cmdline *cl,
3826                    __rte_unused void *data)
3827 {
3828         struct cmd_set_log_result *res;
3829         int ret;
3830
3831         res = parsed_result;
3832         if (!strcmp(res->type, "global"))
3833                 rte_log_set_global_level(res->level);
3834         else {
3835                 ret = rte_log_set_level_regexp(res->type, res->level);
3836                 if (ret < 0)
3837                         printf("Unable to set log level\n");
3838         }
3839 }
3840
3841 cmdline_parse_token_string_t cmd_set_log_set =
3842         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3843 cmdline_parse_token_string_t cmd_set_log_log =
3844         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3845 cmdline_parse_token_string_t cmd_set_log_type =
3846         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3847 cmdline_parse_token_num_t cmd_set_log_level =
3848         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3849
3850 cmdline_parse_inst_t cmd_set_log = {
3851         .f = cmd_set_log_parsed,
3852         .data = NULL,
3853         .help_str = "set log global|<type> <level>",
3854         .tokens = {
3855                 (void *)&cmd_set_log_set,
3856                 (void *)&cmd_set_log_log,
3857                 (void *)&cmd_set_log_type,
3858                 (void *)&cmd_set_log_level,
3859                 NULL,
3860         },
3861 };
3862
3863 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3864
3865 struct cmd_set_txpkts_result {
3866         cmdline_fixed_string_t cmd_keyword;
3867         cmdline_fixed_string_t txpkts;
3868         cmdline_fixed_string_t seg_lengths;
3869 };
3870
3871 static void
3872 cmd_set_txpkts_parsed(void *parsed_result,
3873                       __rte_unused struct cmdline *cl,
3874                       __rte_unused void *data)
3875 {
3876         struct cmd_set_txpkts_result *res;
3877         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3878         unsigned int nb_segs;
3879
3880         res = parsed_result;
3881         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3882                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3883         if (nb_segs > 0)
3884                 set_tx_pkt_segments(seg_lengths, nb_segs);
3885 }
3886
3887 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3888         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3889                                  cmd_keyword, "set");
3890 cmdline_parse_token_string_t cmd_set_txpkts_name =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3892                                  txpkts, "txpkts");
3893 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3894         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3895                                  seg_lengths, NULL);
3896
3897 cmdline_parse_inst_t cmd_set_txpkts = {
3898         .f = cmd_set_txpkts_parsed,
3899         .data = NULL,
3900         .help_str = "set txpkts <len0[,len1]*>",
3901         .tokens = {
3902                 (void *)&cmd_set_txpkts_keyword,
3903                 (void *)&cmd_set_txpkts_name,
3904                 (void *)&cmd_set_txpkts_lengths,
3905                 NULL,
3906         },
3907 };
3908
3909 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3910
3911 struct cmd_set_txsplit_result {
3912         cmdline_fixed_string_t cmd_keyword;
3913         cmdline_fixed_string_t txsplit;
3914         cmdline_fixed_string_t mode;
3915 };
3916
3917 static void
3918 cmd_set_txsplit_parsed(void *parsed_result,
3919                       __rte_unused struct cmdline *cl,
3920                       __rte_unused void *data)
3921 {
3922         struct cmd_set_txsplit_result *res;
3923
3924         res = parsed_result;
3925         set_tx_pkt_split(res->mode);
3926 }
3927
3928 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3929         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3930                                  cmd_keyword, "set");
3931 cmdline_parse_token_string_t cmd_set_txsplit_name =
3932         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3933                                  txsplit, "txsplit");
3934 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3936                                  mode, NULL);
3937
3938 cmdline_parse_inst_t cmd_set_txsplit = {
3939         .f = cmd_set_txsplit_parsed,
3940         .data = NULL,
3941         .help_str = "set txsplit on|off|rand",
3942         .tokens = {
3943                 (void *)&cmd_set_txsplit_keyword,
3944                 (void *)&cmd_set_txsplit_name,
3945                 (void *)&cmd_set_txsplit_mode,
3946                 NULL,
3947         },
3948 };
3949
3950 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3951
3952 struct cmd_set_txtimes_result {
3953         cmdline_fixed_string_t cmd_keyword;
3954         cmdline_fixed_string_t txtimes;
3955         cmdline_fixed_string_t tx_times;
3956 };
3957
3958 static void
3959 cmd_set_txtimes_parsed(void *parsed_result,
3960                        __rte_unused struct cmdline *cl,
3961                        __rte_unused void *data)
3962 {
3963         struct cmd_set_txtimes_result *res;
3964         unsigned int tx_times[2] = {0, 0};
3965         unsigned int n_times;
3966
3967         res = parsed_result;
3968         n_times = parse_item_list(res->tx_times, "tx times",
3969                                   2, tx_times, 0);
3970         if (n_times == 2)
3971                 set_tx_pkt_times(tx_times);
3972 }
3973
3974 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3975         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3976                                  cmd_keyword, "set");
3977 cmdline_parse_token_string_t cmd_set_txtimes_name =
3978         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3979                                  txtimes, "txtimes");
3980 cmdline_parse_token_string_t cmd_set_txtimes_value =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3982                                  tx_times, NULL);
3983
3984 cmdline_parse_inst_t cmd_set_txtimes = {
3985         .f = cmd_set_txtimes_parsed,
3986         .data = NULL,
3987         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3988         .tokens = {
3989                 (void *)&cmd_set_txtimes_keyword,
3990                 (void *)&cmd_set_txtimes_name,
3991                 (void *)&cmd_set_txtimes_value,
3992                 NULL,
3993         },
3994 };
3995
3996 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3997 struct cmd_rx_vlan_filter_all_result {
3998         cmdline_fixed_string_t rx_vlan;
3999         cmdline_fixed_string_t what;
4000         cmdline_fixed_string_t all;
4001         portid_t port_id;
4002 };
4003
4004 static void
4005 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4006                               __rte_unused struct cmdline *cl,
4007                               __rte_unused void *data)
4008 {
4009         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4010
4011         if (!strcmp(res->what, "add"))
4012                 rx_vlan_all_filter_set(res->port_id, 1);
4013         else
4014                 rx_vlan_all_filter_set(res->port_id, 0);
4015 }
4016
4017 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4018         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4019                                  rx_vlan, "rx_vlan");
4020 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4021         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4022                                  what, "add#rm");
4023 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4024         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4025                                  all, "all");
4026 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4027         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4028                               port_id, UINT16);
4029
4030 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4031         .f = cmd_rx_vlan_filter_all_parsed,
4032         .data = NULL,
4033         .help_str = "rx_vlan add|rm all <port_id>: "
4034                 "Add/Remove all identifiers to/from the set of VLAN "
4035                 "identifiers filtered by a port",
4036         .tokens = {
4037                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4038                 (void *)&cmd_rx_vlan_filter_all_what,
4039                 (void *)&cmd_rx_vlan_filter_all_all,
4040                 (void *)&cmd_rx_vlan_filter_all_portid,
4041                 NULL,
4042         },
4043 };
4044
4045 /* *** VLAN OFFLOAD SET ON A PORT *** */
4046 struct cmd_vlan_offload_result {
4047         cmdline_fixed_string_t vlan;
4048         cmdline_fixed_string_t set;
4049         cmdline_fixed_string_t vlan_type;
4050         cmdline_fixed_string_t what;
4051         cmdline_fixed_string_t on;
4052         cmdline_fixed_string_t port_id;
4053 };
4054
4055 static void
4056 cmd_vlan_offload_parsed(void *parsed_result,
4057                           __rte_unused struct cmdline *cl,
4058                           __rte_unused void *data)
4059 {
4060         int on;
4061         struct cmd_vlan_offload_result *res = parsed_result;
4062         char *str;
4063         int i, len = 0;
4064         portid_t port_id = 0;
4065         unsigned int tmp;
4066
4067         str = res->port_id;
4068         len = strnlen(str, STR_TOKEN_SIZE);
4069         i = 0;
4070         /* Get port_id first */
4071         while(i < len){
4072                 if(str[i] == ',')
4073                         break;
4074
4075                 i++;
4076         }
4077         str[i]='\0';
4078         tmp = strtoul(str, NULL, 0);
4079         /* If port_id greater that what portid_t can represent, return */
4080         if(tmp >= RTE_MAX_ETHPORTS)
4081                 return;
4082         port_id = (portid_t)tmp;
4083
4084         if (!strcmp(res->on, "on"))
4085                 on = 1;
4086         else
4087                 on = 0;
4088
4089         if (!strcmp(res->what, "strip"))
4090                 rx_vlan_strip_set(port_id,  on);
4091         else if(!strcmp(res->what, "stripq")){
4092                 uint16_t queue_id = 0;
4093
4094                 /* No queue_id, return */
4095                 if(i + 1 >= len) {
4096                         printf("must specify (port,queue_id)\n");
4097                         return;
4098                 }
4099                 tmp = strtoul(str + i + 1, NULL, 0);
4100                 /* If queue_id greater that what 16-bits can represent, return */
4101                 if(tmp > 0xffff)
4102                         return;
4103
4104                 queue_id = (uint16_t)tmp;
4105                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4106         }
4107         else if (!strcmp(res->what, "filter"))
4108                 rx_vlan_filter_set(port_id, on);
4109         else if (!strcmp(res->what, "qinq_strip"))
4110                 rx_vlan_qinq_strip_set(port_id, on);
4111         else
4112                 vlan_extend_set(port_id, on);
4113
4114         return;
4115 }
4116
4117 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4118         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4119                                  vlan, "vlan");
4120 cmdline_parse_token_string_t cmd_vlan_offload_set =
4121         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4122                                  set, "set");
4123 cmdline_parse_token_string_t cmd_vlan_offload_what =
4124         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4125                                 what, "strip#filter#qinq_strip#extend#stripq");
4126 cmdline_parse_token_string_t cmd_vlan_offload_on =
4127         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4128                               on, "on#off");
4129 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4130         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4131                               port_id, NULL);
4132
4133 cmdline_parse_inst_t cmd_vlan_offload = {
4134         .f = cmd_vlan_offload_parsed,
4135         .data = NULL,
4136         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4137                 "<port_id[,queue_id]>: "
4138                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4139         .tokens = {
4140                 (void *)&cmd_vlan_offload_vlan,
4141                 (void *)&cmd_vlan_offload_set,
4142                 (void *)&cmd_vlan_offload_what,
4143                 (void *)&cmd_vlan_offload_on,
4144                 (void *)&cmd_vlan_offload_portid,
4145                 NULL,
4146         },
4147 };
4148
4149 /* *** VLAN TPID SET ON A PORT *** */
4150 struct cmd_vlan_tpid_result {
4151         cmdline_fixed_string_t vlan;
4152         cmdline_fixed_string_t set;
4153         cmdline_fixed_string_t vlan_type;
4154         cmdline_fixed_string_t what;
4155         uint16_t tp_id;
4156         portid_t port_id;
4157 };
4158
4159 static void
4160 cmd_vlan_tpid_parsed(void *parsed_result,
4161                           __rte_unused struct cmdline *cl,
4162                           __rte_unused void *data)
4163 {
4164         struct cmd_vlan_tpid_result *res = parsed_result;
4165         enum rte_vlan_type vlan_type;
4166
4167         if (!strcmp(res->vlan_type, "inner"))
4168                 vlan_type = ETH_VLAN_TYPE_INNER;
4169         else if (!strcmp(res->vlan_type, "outer"))
4170                 vlan_type = ETH_VLAN_TYPE_OUTER;
4171         else {
4172                 printf("Unknown vlan type\n");
4173                 return;
4174         }
4175         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4176 }
4177
4178 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4179         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4180                                  vlan, "vlan");
4181 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4182         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4183                                  set, "set");
4184 cmdline_parse_token_string_t cmd_vlan_type =
4185         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4186                                  vlan_type, "inner#outer");
4187 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4188         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4189                                  what, "tpid");
4190 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4191         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4192                               tp_id, UINT16);
4193 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4194         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4195                               port_id, UINT16);
4196
4197 cmdline_parse_inst_t cmd_vlan_tpid = {
4198         .f = cmd_vlan_tpid_parsed,
4199         .data = NULL,
4200         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4201                 "Set the VLAN Ether type",
4202         .tokens = {
4203                 (void *)&cmd_vlan_tpid_vlan,
4204                 (void *)&cmd_vlan_tpid_set,
4205                 (void *)&cmd_vlan_type,
4206                 (void *)&cmd_vlan_tpid_what,
4207                 (void *)&cmd_vlan_tpid_tpid,
4208                 (void *)&cmd_vlan_tpid_portid,
4209                 NULL,
4210         },
4211 };
4212
4213 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4214 struct cmd_rx_vlan_filter_result {
4215         cmdline_fixed_string_t rx_vlan;
4216         cmdline_fixed_string_t what;
4217         uint16_t vlan_id;
4218         portid_t port_id;
4219 };
4220
4221 static void
4222 cmd_rx_vlan_filter_parsed(void *parsed_result,
4223                           __rte_unused struct cmdline *cl,
4224                           __rte_unused void *data)
4225 {
4226         struct cmd_rx_vlan_filter_result *res = parsed_result;
4227
4228         if (!strcmp(res->what, "add"))
4229                 rx_vft_set(res->port_id, res->vlan_id, 1);
4230         else
4231                 rx_vft_set(res->port_id, res->vlan_id, 0);
4232 }
4233
4234 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4235         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4236                                  rx_vlan, "rx_vlan");
4237 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4238         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4239                                  what, "add#rm");
4240 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4241         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4242                               vlan_id, UINT16);
4243 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4244         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4245                               port_id, UINT16);
4246
4247 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4248         .f = cmd_rx_vlan_filter_parsed,
4249         .data = NULL,
4250         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4251                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4252                 "identifiers filtered by a port",
4253         .tokens = {
4254                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4255                 (void *)&cmd_rx_vlan_filter_what,
4256                 (void *)&cmd_rx_vlan_filter_vlanid,
4257                 (void *)&cmd_rx_vlan_filter_portid,
4258                 NULL,
4259         },
4260 };
4261
4262 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4263 struct cmd_tx_vlan_set_result {
4264         cmdline_fixed_string_t tx_vlan;
4265         cmdline_fixed_string_t set;
4266         portid_t port_id;
4267         uint16_t vlan_id;
4268 };
4269
4270 static void
4271 cmd_tx_vlan_set_parsed(void *parsed_result,
4272                        __rte_unused struct cmdline *cl,
4273                        __rte_unused void *data)
4274 {
4275         struct cmd_tx_vlan_set_result *res = parsed_result;
4276
4277         if (!port_is_stopped(res->port_id)) {
4278                 printf("Please stop port %d first\n", res->port_id);
4279                 return;
4280         }
4281
4282         tx_vlan_set(res->port_id, res->vlan_id);
4283
4284         cmd_reconfig_device_queue(res->port_id, 1, 1);
4285 }
4286
4287 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4288         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4289                                  tx_vlan, "tx_vlan");
4290 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4291         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4292                                  set, "set");
4293 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4294         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4295                               port_id, UINT16);
4296 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4297         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4298                               vlan_id, UINT16);
4299
4300 cmdline_parse_inst_t cmd_tx_vlan_set = {
4301         .f = cmd_tx_vlan_set_parsed,
4302         .data = NULL,
4303         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4304                 "Enable hardware insertion of a single VLAN header "
4305                 "with a given TAG Identifier in packets sent on a port",
4306         .tokens = {
4307                 (void *)&cmd_tx_vlan_set_tx_vlan,
4308                 (void *)&cmd_tx_vlan_set_set,
4309                 (void *)&cmd_tx_vlan_set_portid,
4310                 (void *)&cmd_tx_vlan_set_vlanid,
4311                 NULL,
4312         },
4313 };
4314
4315 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4316 struct cmd_tx_vlan_set_qinq_result {
4317         cmdline_fixed_string_t tx_vlan;
4318         cmdline_fixed_string_t set;
4319         portid_t port_id;
4320         uint16_t vlan_id;
4321         uint16_t vlan_id_outer;
4322 };
4323
4324 static void
4325 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4326                             __rte_unused struct cmdline *cl,
4327                             __rte_unused void *data)
4328 {
4329         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4330
4331         if (!port_is_stopped(res->port_id)) {
4332                 printf("Please stop port %d first\n", res->port_id);
4333                 return;
4334         }
4335
4336         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4337
4338         cmd_reconfig_device_queue(res->port_id, 1, 1);
4339 }
4340
4341 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4342         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4343                 tx_vlan, "tx_vlan");
4344 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4345         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4346                 set, "set");
4347 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4348         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4349                 port_id, UINT16);
4350 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4351         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4352                 vlan_id, UINT16);
4353 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4354         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4355                 vlan_id_outer, UINT16);
4356
4357 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4358         .f = cmd_tx_vlan_set_qinq_parsed,
4359         .data = NULL,
4360         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4361                 "Enable hardware insertion of double VLAN header "
4362                 "with given TAG Identifiers in packets sent on a port",
4363         .tokens = {
4364                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4365                 (void *)&cmd_tx_vlan_set_qinq_set,
4366                 (void *)&cmd_tx_vlan_set_qinq_portid,
4367                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4368                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4369                 NULL,
4370         },
4371 };
4372
4373 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4374 struct cmd_tx_vlan_set_pvid_result {
4375         cmdline_fixed_string_t tx_vlan;
4376         cmdline_fixed_string_t set;
4377         cmdline_fixed_string_t pvid;
4378         portid_t port_id;
4379         uint16_t vlan_id;
4380         cmdline_fixed_string_t mode;
4381 };
4382
4383 static void
4384 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4385                             __rte_unused struct cmdline *cl,
4386                             __rte_unused void *data)
4387 {
4388         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4389
4390         if (strcmp(res->mode, "on") == 0)
4391                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4392         else
4393                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4394 }
4395
4396 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4397         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4398                                  tx_vlan, "tx_vlan");
4399 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4400         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4401                                  set, "set");
4402 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4403         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4404                                  pvid, "pvid");
4405 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4406         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4407                              port_id, UINT16);
4408 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4409         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4410                               vlan_id, UINT16);
4411 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4412         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4413                                  mode, "on#off");
4414
4415 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4416         .f = cmd_tx_vlan_set_pvid_parsed,
4417         .data = NULL,
4418         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4419         .tokens = {
4420                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4421                 (void *)&cmd_tx_vlan_set_pvid_set,
4422                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4423                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4424                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4425                 (void *)&cmd_tx_vlan_set_pvid_mode,
4426                 NULL,
4427         },
4428 };
4429
4430 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4431 struct cmd_tx_vlan_reset_result {
4432         cmdline_fixed_string_t tx_vlan;
4433         cmdline_fixed_string_t reset;
4434         portid_t port_id;
4435 };
4436
4437 static void
4438 cmd_tx_vlan_reset_parsed(void *parsed_result,
4439                          __rte_unused struct cmdline *cl,
4440                          __rte_unused void *data)
4441 {
4442         struct cmd_tx_vlan_reset_result *res = parsed_result;
4443
4444         if (!port_is_stopped(res->port_id)) {
4445                 printf("Please stop port %d first\n", res->port_id);
4446                 return;
4447         }
4448
4449         tx_vlan_reset(res->port_id);
4450
4451         cmd_reconfig_device_queue(res->port_id, 1, 1);
4452 }
4453
4454 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4455         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4456                                  tx_vlan, "tx_vlan");
4457 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4458         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4459                                  reset, "reset");
4460 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4461         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4462                               port_id, UINT16);
4463
4464 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4465         .f = cmd_tx_vlan_reset_parsed,
4466         .data = NULL,
4467         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4468                 "VLAN header in packets sent on a port",
4469         .tokens = {
4470                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4471                 (void *)&cmd_tx_vlan_reset_reset,
4472                 (void *)&cmd_tx_vlan_reset_portid,
4473                 NULL,
4474         },
4475 };
4476
4477
4478 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4479 struct cmd_csum_result {
4480         cmdline_fixed_string_t csum;
4481         cmdline_fixed_string_t mode;
4482         cmdline_fixed_string_t proto;
4483         cmdline_fixed_string_t hwsw;
4484         portid_t port_id;
4485 };
4486
4487 static void
4488 csum_show(int port_id)
4489 {
4490         struct rte_eth_dev_info dev_info;
4491         uint64_t tx_offloads;
4492         int ret;
4493
4494         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4495         printf("Parse tunnel is %s\n",
4496                 (ports[port_id].parse_tunnel) ? "on" : "off");
4497         printf("IP checksum offload is %s\n",
4498                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4499         printf("UDP checksum offload is %s\n",
4500                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4501         printf("TCP checksum offload is %s\n",
4502                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4503         printf("SCTP checksum offload is %s\n",
4504                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4505         printf("Outer-Ip checksum offload is %s\n",
4506                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4507         printf("Outer-Udp checksum offload is %s\n",
4508                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4509
4510         /* display warnings if configuration is not supported by the NIC */
4511         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4512         if (ret != 0)
4513                 return;
4514
4515         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4516                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4517                 printf("Warning: hardware IP checksum enabled but not "
4518                         "supported by port %d\n", port_id);
4519         }
4520         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4521                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4522                 printf("Warning: hardware UDP checksum enabled but not "
4523                         "supported by port %d\n", port_id);
4524         }
4525         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4526                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4527                 printf("Warning: hardware TCP checksum enabled but not "
4528                         "supported by port %d\n", port_id);
4529         }
4530         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4531                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4532                 printf("Warning: hardware SCTP checksum enabled but not "
4533                         "supported by port %d\n", port_id);
4534         }
4535         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4536                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4537                 printf("Warning: hardware outer IP checksum enabled but not "
4538                         "supported by port %d\n", port_id);
4539         }
4540         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4541                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4542                         == 0) {
4543                 printf("Warning: hardware outer UDP checksum enabled but not "
4544                         "supported by port %d\n", port_id);
4545         }
4546 }
4547
4548 static void
4549 cmd_config_queue_tx_offloads(struct rte_port *port)
4550 {
4551         int k;
4552
4553         /* Apply queue tx offloads configuration */
4554         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4555                 port->tx_conf[k].offloads =
4556                         port->dev_conf.txmode.offloads;
4557 }
4558
4559 static void
4560 cmd_csum_parsed(void *parsed_result,
4561                        __rte_unused struct cmdline *cl,
4562                        __rte_unused void *data)
4563 {
4564         struct cmd_csum_result *res = parsed_result;
4565         int hw = 0;
4566         uint64_t csum_offloads = 0;
4567         struct rte_eth_dev_info dev_info;
4568         int ret;
4569
4570         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4571                 printf("invalid port %d\n", res->port_id);
4572                 return;
4573         }
4574         if (!port_is_stopped(res->port_id)) {
4575                 printf("Please stop port %d first\n", res->port_id);
4576                 return;
4577         }
4578
4579         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4580         if (ret != 0)
4581                 return;
4582
4583         if (!strcmp(res->mode, "set")) {
4584
4585                 if (!strcmp(res->hwsw, "hw"))
4586                         hw = 1;
4587
4588                 if (!strcmp(res->proto, "ip")) {
4589                         if (hw == 0 || (dev_info.tx_offload_capa &
4590                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4591                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4592                         } else {
4593                                 printf("IP checksum offload is not supported "
4594                                        "by port %u\n", res->port_id);
4595                         }
4596                 } else if (!strcmp(res->proto, "udp")) {
4597                         if (hw == 0 || (dev_info.tx_offload_capa &
4598                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4599                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4600                         } else {
4601                                 printf("UDP checksum offload is not supported "
4602                                        "by port %u\n", res->port_id);
4603                         }
4604                 } else if (!strcmp(res->proto, "tcp")) {
4605                         if (hw == 0 || (dev_info.tx_offload_capa &
4606                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4607                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4608                         } else {
4609                                 printf("TCP checksum offload is not supported "
4610                                        "by port %u\n", res->port_id);
4611                         }
4612                 } else if (!strcmp(res->proto, "sctp")) {
4613                         if (hw == 0 || (dev_info.tx_offload_capa &
4614                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4615                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4616                         } else {
4617                                 printf("SCTP checksum offload is not supported "
4618                                        "by port %u\n", res->port_id);
4619                         }
4620                 } else if (!strcmp(res->proto, "outer-ip")) {
4621                         if (hw == 0 || (dev_info.tx_offload_capa &
4622                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4623                                 csum_offloads |=
4624                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4625                         } else {
4626                                 printf("Outer IP checksum offload is not "
4627                                        "supported by port %u\n", res->port_id);
4628                         }
4629                 } else if (!strcmp(res->proto, "outer-udp")) {
4630                         if (hw == 0 || (dev_info.tx_offload_capa &
4631                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4632                                 csum_offloads |=
4633                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4634                         } else {
4635                                 printf("Outer UDP checksum offload is not "
4636                                        "supported by port %u\n", res->port_id);
4637                         }
4638                 }
4639
4640                 if (hw) {
4641                         ports[res->port_id].dev_conf.txmode.offloads |=
4642                                                         csum_offloads;
4643                 } else {
4644                         ports[res->port_id].dev_conf.txmode.offloads &=
4645                                                         (~csum_offloads);
4646                 }
4647                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4648         }
4649         csum_show(res->port_id);
4650
4651         cmd_reconfig_device_queue(res->port_id, 1, 1);
4652 }
4653
4654 cmdline_parse_token_string_t cmd_csum_csum =
4655         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4656                                 csum, "csum");
4657 cmdline_parse_token_string_t cmd_csum_mode =
4658         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4659                                 mode, "set");
4660 cmdline_parse_token_string_t cmd_csum_proto =
4661         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4662                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4663 cmdline_parse_token_string_t cmd_csum_hwsw =
4664         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4665                                 hwsw, "hw#sw");
4666 cmdline_parse_token_num_t cmd_csum_portid =
4667         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4668                                 port_id, UINT16);
4669
4670 cmdline_parse_inst_t cmd_csum_set = {
4671         .f = cmd_csum_parsed,
4672         .data = NULL,
4673         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4674                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4675                 "using csum forward engine",
4676         .tokens = {
4677                 (void *)&cmd_csum_csum,
4678                 (void *)&cmd_csum_mode,
4679                 (void *)&cmd_csum_proto,
4680                 (void *)&cmd_csum_hwsw,
4681                 (void *)&cmd_csum_portid,
4682                 NULL,
4683         },
4684 };
4685
4686 cmdline_parse_token_string_t cmd_csum_mode_show =
4687         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4688                                 mode, "show");
4689
4690 cmdline_parse_inst_t cmd_csum_show = {
4691         .f = cmd_csum_parsed,
4692         .data = NULL,
4693         .help_str = "csum show <port_id>: Show checksum offload configuration",
4694         .tokens = {
4695                 (void *)&cmd_csum_csum,
4696                 (void *)&cmd_csum_mode_show,
4697                 (void *)&cmd_csum_portid,
4698                 NULL,
4699         },
4700 };
4701
4702 /* Enable/disable tunnel parsing */
4703 struct cmd_csum_tunnel_result {
4704         cmdline_fixed_string_t csum;
4705         cmdline_fixed_string_t parse;
4706         cmdline_fixed_string_t onoff;
4707         portid_t port_id;
4708 };
4709
4710 static void
4711 cmd_csum_tunnel_parsed(void *parsed_result,
4712                        __rte_unused struct cmdline *cl,
4713                        __rte_unused void *data)
4714 {
4715         struct cmd_csum_tunnel_result *res = parsed_result;
4716
4717         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4718                 return;
4719
4720         if (!strcmp(res->onoff, "on"))
4721                 ports[res->port_id].parse_tunnel = 1;
4722         else
4723                 ports[res->port_id].parse_tunnel = 0;
4724
4725         csum_show(res->port_id);
4726 }
4727
4728 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4729         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4730                                 csum, "csum");
4731 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4732         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4733                                 parse, "parse-tunnel");
4734 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4735         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4736                                 onoff, "on#off");
4737 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4738         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4739                                 port_id, UINT16);
4740
4741 cmdline_parse_inst_t cmd_csum_tunnel = {
4742         .f = cmd_csum_tunnel_parsed,
4743         .data = NULL,
4744         .help_str = "csum parse-tunnel on|off <port_id>: "
4745                 "Enable/Disable parsing of tunnels for csum engine",
4746         .tokens = {
4747                 (void *)&cmd_csum_tunnel_csum,
4748                 (void *)&cmd_csum_tunnel_parse,
4749                 (void *)&cmd_csum_tunnel_onoff,
4750                 (void *)&cmd_csum_tunnel_portid,
4751                 NULL,
4752         },
4753 };
4754
4755 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4756 struct cmd_tso_set_result {
4757         cmdline_fixed_string_t tso;
4758         cmdline_fixed_string_t mode;
4759         uint16_t tso_segsz;
4760         portid_t port_id;
4761 };
4762
4763 static void
4764 cmd_tso_set_parsed(void *parsed_result,
4765                        __rte_unused struct cmdline *cl,
4766                        __rte_unused void *data)
4767 {
4768         struct cmd_tso_set_result *res = parsed_result;
4769         struct rte_eth_dev_info dev_info;
4770         int ret;
4771
4772         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4773                 return;
4774         if (!port_is_stopped(res->port_id)) {
4775                 printf("Please stop port %d first\n", res->port_id);
4776                 return;
4777         }
4778
4779         if (!strcmp(res->mode, "set"))
4780                 ports[res->port_id].tso_segsz = res->tso_segsz;
4781
4782         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4783         if (ret != 0)
4784                 return;
4785
4786         if ((ports[res->port_id].tso_segsz != 0) &&
4787                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4788                 printf("Error: TSO is not supported by port %d\n",
4789                        res->port_id);
4790                 return;
4791         }
4792
4793         if (ports[res->port_id].tso_segsz == 0) {
4794                 ports[res->port_id].dev_conf.txmode.offloads &=
4795                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4796                 printf("TSO for non-tunneled packets is disabled\n");
4797         } else {
4798                 ports[res->port_id].dev_conf.txmode.offloads |=
4799                                                 DEV_TX_OFFLOAD_TCP_TSO;
4800                 printf("TSO segment size for non-tunneled packets is %d\n",
4801                         ports[res->port_id].tso_segsz);
4802         }
4803         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4804
4805         /* display warnings if configuration is not supported by the NIC */
4806         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4807         if (ret != 0)
4808                 return;
4809
4810         if ((ports[res->port_id].tso_segsz != 0) &&
4811                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4812                 printf("Warning: TSO enabled but not "
4813                         "supported by port %d\n", res->port_id);
4814         }
4815
4816         cmd_reconfig_device_queue(res->port_id, 1, 1);
4817 }
4818
4819 cmdline_parse_token_string_t cmd_tso_set_tso =
4820         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4821                                 tso, "tso");
4822 cmdline_parse_token_string_t cmd_tso_set_mode =
4823         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4824                                 mode, "set");
4825 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4826         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4827                                 tso_segsz, UINT16);
4828 cmdline_parse_token_num_t cmd_tso_set_portid =
4829         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4830                                 port_id, UINT16);
4831
4832 cmdline_parse_inst_t cmd_tso_set = {
4833         .f = cmd_tso_set_parsed,
4834         .data = NULL,
4835         .help_str = "tso set <tso_segsz> <port_id>: "
4836                 "Set TSO segment size of non-tunneled packets for csum engine "
4837                 "(0 to disable)",
4838         .tokens = {
4839                 (void *)&cmd_tso_set_tso,
4840                 (void *)&cmd_tso_set_mode,
4841                 (void *)&cmd_tso_set_tso_segsz,
4842                 (void *)&cmd_tso_set_portid,
4843                 NULL,
4844         },
4845 };
4846
4847 cmdline_parse_token_string_t cmd_tso_show_mode =
4848         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4849                                 mode, "show");
4850
4851
4852 cmdline_parse_inst_t cmd_tso_show = {
4853         .f = cmd_tso_set_parsed,
4854         .data = NULL,
4855         .help_str = "tso show <port_id>: "
4856                 "Show TSO segment size of non-tunneled packets for csum engine",
4857         .tokens = {
4858                 (void *)&cmd_tso_set_tso,
4859                 (void *)&cmd_tso_show_mode,
4860                 (void *)&cmd_tso_set_portid,
4861                 NULL,
4862         },
4863 };
4864
4865 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4866 struct cmd_tunnel_tso_set_result {
4867         cmdline_fixed_string_t tso;
4868         cmdline_fixed_string_t mode;
4869         uint16_t tso_segsz;
4870         portid_t port_id;
4871 };
4872
4873 static struct rte_eth_dev_info
4874 check_tunnel_tso_nic_support(portid_t port_id)
4875 {
4876         struct rte_eth_dev_info dev_info;
4877
4878         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4879                 return dev_info;
4880
4881         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4882                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4883                        "not enabled for port %d\n", port_id);
4884         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4885                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4886                        "not enabled for port %d\n", port_id);
4887         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4888                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4889                        "not enabled for port %d\n", port_id);
4890         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4891                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4892                        "not enabled for port %d\n", port_id);
4893         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4894                 printf("Warning: IP TUNNEL TSO not supported therefore "
4895                        "not enabled for port %d\n", port_id);
4896         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4897                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4898                        "not enabled for port %d\n", port_id);
4899         return dev_info;
4900 }
4901
4902 static void
4903 cmd_tunnel_tso_set_parsed(void *parsed_result,
4904                           __rte_unused struct cmdline *cl,
4905                           __rte_unused void *data)
4906 {
4907         struct cmd_tunnel_tso_set_result *res = parsed_result;
4908         struct rte_eth_dev_info dev_info;
4909
4910         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4911                 return;
4912         if (!port_is_stopped(res->port_id)) {
4913                 printf("Please stop port %d first\n", res->port_id);
4914                 return;
4915         }
4916
4917         if (!strcmp(res->mode, "set"))
4918                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4919
4920         dev_info = check_tunnel_tso_nic_support(res->port_id);
4921         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4922                 ports[res->port_id].dev_conf.txmode.offloads &=
4923                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4924                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4925                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4926                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4927                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4928                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4929                 printf("TSO for tunneled packets is disabled\n");
4930         } else {
4931                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4932                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4933                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4934                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4935                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4936                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4937
4938                 ports[res->port_id].dev_conf.txmode.offloads |=
4939                         (tso_offloads & dev_info.tx_offload_capa);
4940                 printf("TSO segment size for tunneled packets is %d\n",
4941                         ports[res->port_id].tunnel_tso_segsz);
4942
4943                 /* Below conditions are needed to make it work:
4944                  * (1) tunnel TSO is supported by the NIC;
4945                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4946                  * are recognized;
4947                  * (3) for tunneled pkts with outer L3 of IPv4,
4948                  * "csum set outer-ip" must be set to hw, because after tso,
4949                  * total_len of outer IP header is changed, and the checksum
4950                  * of outer IP header calculated by sw should be wrong; that
4951                  * is not necessary for IPv6 tunneled pkts because there's no
4952                  * checksum in IP header anymore.
4953                  */
4954
4955                 if (!ports[res->port_id].parse_tunnel)
4956                         printf("Warning: csum parse_tunnel must be set "
4957                                 "so that tunneled packets are recognized\n");
4958                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4959                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4960                         printf("Warning: csum set outer-ip must be set to hw "
4961                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4962         }
4963
4964         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4965         cmd_reconfig_device_queue(res->port_id, 1, 1);
4966 }
4967
4968 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4969         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4970                                 tso, "tunnel_tso");
4971 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4972         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4973                                 mode, "set");
4974 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4975         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4976                                 tso_segsz, UINT16);
4977 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4978         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4979                                 port_id, UINT16);
4980
4981 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4982         .f = cmd_tunnel_tso_set_parsed,
4983         .data = NULL,
4984         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4985                 "Set TSO segment size of tunneled packets for csum engine "
4986                 "(0 to disable)",
4987         .tokens = {
4988                 (void *)&cmd_tunnel_tso_set_tso,
4989                 (void *)&cmd_tunnel_tso_set_mode,
4990                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4991                 (void *)&cmd_tunnel_tso_set_portid,
4992                 NULL,
4993         },
4994 };
4995
4996 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4997         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4998                                 mode, "show");
4999
5000
5001 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5002         .f = cmd_tunnel_tso_set_parsed,
5003         .data = NULL,
5004         .help_str = "tunnel_tso show <port_id> "
5005                 "Show TSO segment size of tunneled packets for csum engine",
5006         .tokens = {
5007                 (void *)&cmd_tunnel_tso_set_tso,
5008                 (void *)&cmd_tunnel_tso_show_mode,
5009                 (void *)&cmd_tunnel_tso_set_portid,
5010                 NULL,
5011         },
5012 };
5013
5014 /* *** SET GRO FOR A PORT *** */
5015 struct cmd_gro_enable_result {
5016         cmdline_fixed_string_t cmd_set;
5017         cmdline_fixed_string_t cmd_port;
5018         cmdline_fixed_string_t cmd_keyword;
5019         cmdline_fixed_string_t cmd_onoff;
5020         portid_t cmd_pid;
5021 };
5022
5023 static void
5024 cmd_gro_enable_parsed(void *parsed_result,
5025                 __rte_unused struct cmdline *cl,
5026                 __rte_unused void *data)
5027 {
5028         struct cmd_gro_enable_result *res;
5029
5030         res = parsed_result;
5031         if (!strcmp(res->cmd_keyword, "gro"))
5032                 setup_gro(res->cmd_onoff, res->cmd_pid);
5033 }
5034
5035 cmdline_parse_token_string_t cmd_gro_enable_set =
5036         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5037                         cmd_set, "set");
5038 cmdline_parse_token_string_t cmd_gro_enable_port =
5039         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5040                         cmd_keyword, "port");
5041 cmdline_parse_token_num_t cmd_gro_enable_pid =
5042         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5043                         cmd_pid, UINT16);
5044 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5045         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5046                         cmd_keyword, "gro");
5047 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5048         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5049                         cmd_onoff, "on#off");
5050
5051 cmdline_parse_inst_t cmd_gro_enable = {
5052         .f = cmd_gro_enable_parsed,
5053         .data = NULL,
5054         .help_str = "set port <port_id> gro on|off",
5055         .tokens = {
5056                 (void *)&cmd_gro_enable_set,
5057                 (void *)&cmd_gro_enable_port,
5058                 (void *)&cmd_gro_enable_pid,
5059                 (void *)&cmd_gro_enable_keyword,
5060                 (void *)&cmd_gro_enable_onoff,
5061                 NULL,
5062         },
5063 };
5064
5065 /* *** DISPLAY GRO CONFIGURATION *** */
5066 struct cmd_gro_show_result {
5067         cmdline_fixed_string_t cmd_show;
5068         cmdline_fixed_string_t cmd_port;
5069         cmdline_fixed_string_t cmd_keyword;
5070         portid_t cmd_pid;
5071 };
5072
5073 static void
5074 cmd_gro_show_parsed(void *parsed_result,
5075                 __rte_unused struct cmdline *cl,
5076                 __rte_unused void *data)
5077 {
5078         struct cmd_gro_show_result *res;
5079
5080         res = parsed_result;
5081         if (!strcmp(res->cmd_keyword, "gro"))
5082                 show_gro(res->cmd_pid);
5083 }
5084
5085 cmdline_parse_token_string_t cmd_gro_show_show =
5086         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5087                         cmd_show, "show");
5088 cmdline_parse_token_string_t cmd_gro_show_port =
5089         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5090                         cmd_port, "port");
5091 cmdline_parse_token_num_t cmd_gro_show_pid =
5092         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5093                         cmd_pid, UINT16);
5094 cmdline_parse_token_string_t cmd_gro_show_keyword =
5095         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5096                         cmd_keyword, "gro");
5097
5098 cmdline_parse_inst_t cmd_gro_show = {
5099         .f = cmd_gro_show_parsed,
5100         .data = NULL,
5101         .help_str = "show port <port_id> gro",
5102         .tokens = {
5103                 (void *)&cmd_gro_show_show,
5104                 (void *)&cmd_gro_show_port,
5105                 (void *)&cmd_gro_show_pid,
5106                 (void *)&cmd_gro_show_keyword,
5107                 NULL,
5108         },
5109 };
5110
5111 /* *** SET FLUSH CYCLES FOR GRO *** */
5112 struct cmd_gro_flush_result {
5113         cmdline_fixed_string_t cmd_set;
5114         cmdline_fixed_string_t cmd_keyword;
5115         cmdline_fixed_string_t cmd_flush;
5116         uint8_t cmd_cycles;
5117 };
5118
5119 static void
5120 cmd_gro_flush_parsed(void *parsed_result,
5121                 __rte_unused struct cmdline *cl,
5122                 __rte_unused void *data)
5123 {
5124         struct cmd_gro_flush_result *res;
5125
5126         res = parsed_result;
5127         if ((!strcmp(res->cmd_keyword, "gro")) &&
5128                         (!strcmp(res->cmd_flush, "flush")))
5129                 setup_gro_flush_cycles(res->cmd_cycles);
5130 }
5131
5132 cmdline_parse_token_string_t cmd_gro_flush_set =
5133         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5134                         cmd_set, "set");
5135 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5136         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5137                         cmd_keyword, "gro");
5138 cmdline_parse_token_string_t cmd_gro_flush_flush =
5139         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5140                         cmd_flush, "flush");
5141 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5142         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5143                         cmd_cycles, UINT8);
5144
5145 cmdline_parse_inst_t cmd_gro_flush = {
5146         .f = cmd_gro_flush_parsed,
5147         .data = NULL,
5148         .help_str = "set gro flush <cycles>",
5149         .tokens = {
5150                 (void *)&cmd_gro_flush_set,
5151                 (void *)&cmd_gro_flush_keyword,
5152                 (void *)&cmd_gro_flush_flush,
5153                 (void *)&cmd_gro_flush_cycles,
5154                 NULL,
5155         },
5156 };
5157
5158 /* *** ENABLE/DISABLE GSO *** */
5159 struct cmd_gso_enable_result {
5160         cmdline_fixed_string_t cmd_set;
5161         cmdline_fixed_string_t cmd_port;
5162         cmdline_fixed_string_t cmd_keyword;
5163         cmdline_fixed_string_t cmd_mode;
5164         portid_t cmd_pid;
5165 };
5166
5167 static void
5168 cmd_gso_enable_parsed(void *parsed_result,
5169                 __rte_unused struct cmdline *cl,
5170                 __rte_unused void *data)
5171 {
5172         struct cmd_gso_enable_result *res;
5173
5174         res = parsed_result;
5175         if (!strcmp(res->cmd_keyword, "gso"))
5176                 setup_gso(res->cmd_mode, res->cmd_pid);
5177 }
5178
5179 cmdline_parse_token_string_t cmd_gso_enable_set =
5180         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5181                         cmd_set, "set");
5182 cmdline_parse_token_string_t cmd_gso_enable_port =
5183         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5184                         cmd_port, "port");
5185 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5186         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5187                         cmd_keyword, "gso");
5188 cmdline_parse_token_string_t cmd_gso_enable_mode =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5190                         cmd_mode, "on#off");
5191 cmdline_parse_token_num_t cmd_gso_enable_pid =
5192         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5193                         cmd_pid, UINT16);
5194
5195 cmdline_parse_inst_t cmd_gso_enable = {
5196         .f = cmd_gso_enable_parsed,
5197         .data = NULL,
5198         .help_str = "set port <port_id> gso on|off",
5199         .tokens = {
5200                 (void *)&cmd_gso_enable_set,
5201                 (void *)&cmd_gso_enable_port,
5202                 (void *)&cmd_gso_enable_pid,
5203                 (void *)&cmd_gso_enable_keyword,
5204                 (void *)&cmd_gso_enable_mode,
5205                 NULL,
5206         },
5207 };
5208
5209 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5210 struct cmd_gso_size_result {
5211         cmdline_fixed_string_t cmd_set;
5212         cmdline_fixed_string_t cmd_keyword;
5213         cmdline_fixed_string_t cmd_segsz;
5214         uint16_t cmd_size;
5215 };
5216
5217 static void
5218 cmd_gso_size_parsed(void *parsed_result,
5219                        __rte_unused struct cmdline *cl,
5220                        __rte_unused void *data)
5221 {
5222         struct cmd_gso_size_result *res = parsed_result;
5223
5224         if (test_done == 0) {
5225                 printf("Before setting GSO segsz, please first"
5226                                 " stop forwarding\n");
5227                 return;
5228         }
5229
5230         if (!strcmp(res->cmd_keyword, "gso") &&
5231                         !strcmp(res->cmd_segsz, "segsz")) {
5232                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5233                         printf("gso_size should be larger than %zu."
5234                                         " Please input a legal value\n",
5235                                         RTE_GSO_SEG_SIZE_MIN);
5236                 else
5237                         gso_max_segment_size = res->cmd_size;
5238         }
5239 }
5240
5241 cmdline_parse_token_string_t cmd_gso_size_set =
5242         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5243                                 cmd_set, "set");
5244 cmdline_parse_token_string_t cmd_gso_size_keyword =
5245         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5246                                 cmd_keyword, "gso");
5247 cmdline_parse_token_string_t cmd_gso_size_segsz =
5248         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5249                                 cmd_segsz, "segsz");
5250 cmdline_parse_token_num_t cmd_gso_size_size =
5251         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5252                                 cmd_size, UINT16);
5253
5254 cmdline_parse_inst_t cmd_gso_size = {
5255         .f = cmd_gso_size_parsed,
5256         .data = NULL,
5257         .help_str = "set gso segsz <length>",
5258         .tokens = {
5259                 (void *)&cmd_gso_size_set,
5260                 (void *)&cmd_gso_size_keyword,
5261                 (void *)&cmd_gso_size_segsz,
5262                 (void *)&cmd_gso_size_size,
5263                 NULL,
5264         },
5265 };
5266
5267 /* *** SHOW GSO CONFIGURATION *** */
5268 struct cmd_gso_show_result {
5269         cmdline_fixed_string_t cmd_show;
5270         cmdline_fixed_string_t cmd_port;
5271         cmdline_fixed_string_t cmd_keyword;
5272         portid_t cmd_pid;
5273 };
5274
5275 static void
5276 cmd_gso_show_parsed(void *parsed_result,
5277                        __rte_unused struct cmdline *cl,
5278                        __rte_unused void *data)
5279 {
5280         struct cmd_gso_show_result *res = parsed_result;
5281
5282         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5283                 printf("invalid port id %u\n", res->cmd_pid);
5284                 return;
5285         }
5286         if (!strcmp(res->cmd_keyword, "gso")) {
5287                 if (gso_ports[res->cmd_pid].enable) {
5288                         printf("Max GSO'd packet size: %uB\n"
5289                                         "Supported GSO types: TCP/IPv4, "
5290                                         "UDP/IPv4, VxLAN with inner "
5291                                         "TCP/IPv4 packet, GRE with inner "
5292                                         "TCP/IPv4 packet\n",
5293                                         gso_max_segment_size);
5294                 } else
5295                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5296         }
5297 }
5298
5299 cmdline_parse_token_string_t cmd_gso_show_show =
5300 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5301                 cmd_show, "show");
5302 cmdline_parse_token_string_t cmd_gso_show_port =
5303 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5304                 cmd_port, "port");
5305 cmdline_parse_token_string_t cmd_gso_show_keyword =
5306         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5307                                 cmd_keyword, "gso");
5308 cmdline_parse_token_num_t cmd_gso_show_pid =
5309         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5310                                 cmd_pid, UINT16);
5311
5312 cmdline_parse_inst_t cmd_gso_show = {
5313         .f = cmd_gso_show_parsed,
5314         .data = NULL,
5315         .help_str = "show port <port_id> gso",
5316         .tokens = {
5317                 (void *)&cmd_gso_show_show,
5318                 (void *)&cmd_gso_show_port,
5319                 (void *)&cmd_gso_show_pid,
5320                 (void *)&cmd_gso_show_keyword,
5321                 NULL,
5322         },
5323 };
5324
5325 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5326 struct cmd_set_flush_rx {
5327         cmdline_fixed_string_t set;
5328         cmdline_fixed_string_t flush_rx;
5329         cmdline_fixed_string_t mode;
5330 };
5331
5332 static void
5333 cmd_set_flush_rx_parsed(void *parsed_result,
5334                 __rte_unused struct cmdline *cl,
5335                 __rte_unused void *data)
5336 {
5337         struct cmd_set_flush_rx *res = parsed_result;
5338         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5339 }
5340
5341 cmdline_parse_token_string_t cmd_setflushrx_set =
5342         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5343                         set, "set");
5344 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5345         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5346                         flush_rx, "flush_rx");
5347 cmdline_parse_token_string_t cmd_setflushrx_mode =
5348         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5349                         mode, "on#off");
5350
5351
5352 cmdline_parse_inst_t cmd_set_flush_rx = {
5353         .f = cmd_set_flush_rx_parsed,
5354         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5355         .data = NULL,
5356         .tokens = {
5357                 (void *)&cmd_setflushrx_set,
5358                 (void *)&cmd_setflushrx_flush_rx,
5359                 (void *)&cmd_setflushrx_mode,
5360                 NULL,
5361         },
5362 };
5363
5364 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5365 struct cmd_set_link_check {
5366         cmdline_fixed_string_t set;
5367         cmdline_fixed_string_t link_check;
5368         cmdline_fixed_string_t mode;
5369 };
5370
5371 static void
5372 cmd_set_link_check_parsed(void *parsed_result,
5373                 __rte_unused struct cmdline *cl,
5374                 __rte_unused void *data)
5375 {
5376         struct cmd_set_link_check *res = parsed_result;
5377         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5378 }
5379
5380 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5381         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5382                         set, "set");
5383 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5384         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5385                         link_check, "link_check");
5386 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5387         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5388                         mode, "on#off");
5389
5390
5391 cmdline_parse_inst_t cmd_set_link_check = {
5392         .f = cmd_set_link_check_parsed,
5393         .help_str = "set link_check on|off: Enable/Disable link status check "
5394                     "when starting/stopping a port",
5395         .data = NULL,
5396         .tokens = {
5397                 (void *)&cmd_setlinkcheck_set,
5398                 (void *)&cmd_setlinkcheck_link_check,
5399                 (void *)&cmd_setlinkcheck_mode,
5400                 NULL,
5401         },
5402 };
5403
5404 /* *** SET NIC BYPASS MODE *** */
5405 struct cmd_set_bypass_mode_result {
5406         cmdline_fixed_string_t set;
5407         cmdline_fixed_string_t bypass;
5408         cmdline_fixed_string_t mode;
5409         cmdline_fixed_string_t value;
5410         portid_t port_id;
5411 };
5412
5413 static void
5414 cmd_set_bypass_mode_parsed(void *parsed_result,
5415                 __rte_unused struct cmdline *cl,
5416                 __rte_unused void *data)
5417 {
5418         struct cmd_set_bypass_mode_result *res = parsed_result;
5419         portid_t port_id = res->port_id;
5420         int32_t rc = -EINVAL;
5421
5422 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5423         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5424
5425         if (!strcmp(res->value, "bypass"))
5426                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5427         else if (!strcmp(res->value, "isolate"))
5428                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5429         else
5430                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5431
5432         /* Set the bypass mode for the relevant port. */
5433         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5434 #endif
5435         if (rc != 0)
5436                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5437 }
5438
5439 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5441                         set, "set");
5442 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5444                         bypass, "bypass");
5445 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5447                         mode, "mode");
5448 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5450                         value, "normal#bypass#isolate");
5451 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5452         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5453                                 port_id, UINT16);
5454
5455 cmdline_parse_inst_t cmd_set_bypass_mode = {
5456         .f = cmd_set_bypass_mode_parsed,
5457         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5458                     "Set the NIC bypass mode for port_id",
5459         .data = NULL,
5460         .tokens = {
5461                 (void *)&cmd_setbypass_mode_set,
5462                 (void *)&cmd_setbypass_mode_bypass,
5463                 (void *)&cmd_setbypass_mode_mode,
5464                 (void *)&cmd_setbypass_mode_value,
5465                 (void *)&cmd_setbypass_mode_port,
5466                 NULL,
5467         },
5468 };
5469
5470 /* *** SET NIC BYPASS EVENT *** */
5471 struct cmd_set_bypass_event_result {
5472         cmdline_fixed_string_t set;
5473         cmdline_fixed_string_t bypass;
5474         cmdline_fixed_string_t event;
5475         cmdline_fixed_string_t event_value;
5476         cmdline_fixed_string_t mode;
5477         cmdline_fixed_string_t mode_value;
5478         portid_t port_id;
5479 };
5480
5481 static void
5482 cmd_set_bypass_event_parsed(void *parsed_result,
5483                 __rte_unused struct cmdline *cl,
5484                 __rte_unused void *data)
5485 {
5486         int32_t rc = -EINVAL;
5487         struct cmd_set_bypass_event_result *res = parsed_result;
5488         portid_t port_id = res->port_id;
5489
5490 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5491         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5492         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5493
5494         if (!strcmp(res->event_value, "timeout"))
5495                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5496         else if (!strcmp(res->event_value, "os_on"))
5497                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5498         else if (!strcmp(res->event_value, "os_off"))
5499                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5500         else if (!strcmp(res->event_value, "power_on"))
5501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5502         else if (!strcmp(res->event_value, "power_off"))
5503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5504         else
5505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5506
5507         if (!strcmp(res->mode_value, "bypass"))
5508                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5509         else if (!strcmp(res->mode_value, "isolate"))
5510                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5511         else
5512                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5513
5514         /* Set the watchdog timeout. */
5515         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5516
5517                 rc = -EINVAL;
5518                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5519                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5520                                                            bypass_timeout);
5521                 }
5522                 if (rc != 0) {
5523                         printf("Failed to set timeout value %u "
5524                         "for port %d, errto code: %d.\n",
5525                         bypass_timeout, port_id, rc);
5526                 }
5527         }
5528
5529         /* Set the bypass event to transition to bypass mode. */
5530         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5531                                               bypass_mode);
5532 #endif
5533
5534         if (rc != 0)
5535                 printf("\t Failed to set bypass event for port = %d.\n",
5536                        port_id);
5537 }
5538
5539 cmdline_parse_token_string_t cmd_setbypass_event_set =
5540         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5541                         set, "set");
5542 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5543         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5544                         bypass, "bypass");
5545 cmdline_parse_token_string_t cmd_setbypass_event_event =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5547                         event, "event");
5548 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5550                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5551 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5553                         mode, "mode");
5554 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5556                         mode_value, "normal#bypass#isolate");
5557 cmdline_parse_token_num_t cmd_setbypass_event_port =
5558         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5559                                 port_id, UINT16);
5560
5561 cmdline_parse_inst_t cmd_set_bypass_event = {
5562         .f = cmd_set_bypass_event_parsed,
5563         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5564                 "power_off mode normal|bypass|isolate <port_id>: "
5565                 "Set the NIC bypass event mode for port_id",
5566         .data = NULL,
5567         .tokens = {
5568                 (void *)&cmd_setbypass_event_set,
5569                 (void *)&cmd_setbypass_event_bypass,
5570                 (void *)&cmd_setbypass_event_event,
5571                 (void *)&cmd_setbypass_event_event_value,
5572                 (void *)&cmd_setbypass_event_mode,
5573                 (void *)&cmd_setbypass_event_mode_value,
5574                 (void *)&cmd_setbypass_event_port,
5575                 NULL,
5576         },
5577 };
5578
5579
5580 /* *** SET NIC BYPASS TIMEOUT *** */
5581 struct cmd_set_bypass_timeout_result {
5582         cmdline_fixed_string_t set;
5583         cmdline_fixed_string_t bypass;
5584         cmdline_fixed_string_t timeout;
5585         cmdline_fixed_string_t value;
5586 };
5587
5588 static void
5589 cmd_set_bypass_timeout_parsed(void *parsed_result,
5590                 __rte_unused struct cmdline *cl,
5591                 __rte_unused void *data)
5592 {
5593         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5594
5595 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5596         if (!strcmp(res->value, "1.5"))
5597                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5598         else if (!strcmp(res->value, "2"))
5599                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5600         else if (!strcmp(res->value, "3"))
5601                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5602         else if (!strcmp(res->value, "4"))
5603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5604         else if (!strcmp(res->value, "8"))
5605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5606         else if (!strcmp(res->value, "16"))
5607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5608         else if (!strcmp(res->value, "32"))
5609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5610         else
5611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5612 #endif
5613 }
5614
5615 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5616         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5617                         set, "set");
5618 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5619         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5620                         bypass, "bypass");
5621 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5623                         timeout, "timeout");
5624 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5626                         value, "0#1.5#2#3#4#8#16#32");
5627
5628 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5629         .f = cmd_set_bypass_timeout_parsed,
5630         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5631                 "Set the NIC bypass watchdog timeout in seconds",
5632         .data = NULL,
5633         .tokens = {
5634                 (void *)&cmd_setbypass_timeout_set,
5635                 (void *)&cmd_setbypass_timeout_bypass,
5636                 (void *)&cmd_setbypass_timeout_timeout,
5637                 (void *)&cmd_setbypass_timeout_value,
5638                 NULL,
5639         },
5640 };
5641
5642 /* *** SHOW NIC BYPASS MODE *** */
5643 struct cmd_show_bypass_config_result {
5644         cmdline_fixed_string_t show;
5645         cmdline_fixed_string_t bypass;
5646         cmdline_fixed_string_t config;
5647         portid_t port_id;
5648 };
5649
5650 static void
5651 cmd_show_bypass_config_parsed(void *parsed_result,
5652                 __rte_unused struct cmdline *cl,
5653                 __rte_unused void *data)
5654 {
5655         struct cmd_show_bypass_config_result *res = parsed_result;
5656         portid_t port_id = res->port_id;
5657         int rc = -EINVAL;
5658 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5659         uint32_t event_mode;
5660         uint32_t bypass_mode;
5661         uint32_t timeout = bypass_timeout;
5662         unsigned int i;
5663
5664         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5665                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5666         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5667                 {"UNKNOWN", "normal", "bypass", "isolate"};
5668         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5669                 "NONE",
5670                 "OS/board on",
5671                 "power supply on",
5672                 "OS/board off",
5673                 "power supply off",
5674                 "timeout"};
5675
5676         /* Display the bypass mode.*/
5677         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5678                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5679                 return;
5680         }
5681         else {
5682                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5683                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5684
5685                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5686         }
5687
5688         /* Display the bypass timeout.*/
5689         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5690                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5691
5692         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5693
5694         /* Display the bypass events and associated modes. */
5695         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5696
5697                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5698                         printf("\tFailed to get bypass mode for event = %s\n",
5699                                 events[i]);
5700                 } else {
5701                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5702                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5703
5704                         printf("\tbypass event: %-16s = %s\n", events[i],
5705                                 modes[event_mode]);
5706                 }
5707         }
5708 #endif
5709         if (rc != 0)
5710                 printf("\tFailed to get bypass configuration for port = %d\n",
5711                        port_id);
5712 }
5713
5714 cmdline_parse_token_string_t cmd_showbypass_config_show =
5715         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5716                         show, "show");
5717 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5718         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5719                         bypass, "bypass");
5720 cmdline_parse_token_string_t cmd_showbypass_config_config =
5721         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5722                         config, "config");
5723 cmdline_parse_token_num_t cmd_showbypass_config_port =
5724         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5725                                 port_id, UINT16);
5726
5727 cmdline_parse_inst_t cmd_show_bypass_config = {
5728         .f = cmd_show_bypass_config_parsed,
5729         .help_str = "show bypass config <port_id>: "
5730                     "Show the NIC bypass config for port_id",
5731         .data = NULL,
5732         .tokens = {
5733                 (void *)&cmd_showbypass_config_show,
5734                 (void *)&cmd_showbypass_config_bypass,
5735                 (void *)&cmd_showbypass_config_config,
5736                 (void *)&cmd_showbypass_config_port,
5737                 NULL,
5738         },
5739 };
5740
5741 #ifdef RTE_LIBRTE_PMD_BOND
5742 /* *** SET BONDING MODE *** */
5743 struct cmd_set_bonding_mode_result {
5744         cmdline_fixed_string_t set;
5745         cmdline_fixed_string_t bonding;
5746         cmdline_fixed_string_t mode;
5747         uint8_t value;
5748         portid_t port_id;
5749 };
5750
5751 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5752                 __rte_unused  struct cmdline *cl,
5753                 __rte_unused void *data)
5754 {
5755         struct cmd_set_bonding_mode_result *res = parsed_result;
5756         portid_t port_id = res->port_id;
5757
5758         /* Set the bonding mode for the relevant port. */
5759         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5760                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5761 }
5762
5763 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5764 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5765                 set, "set");
5766 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5767 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5768                 bonding, "bonding");
5769 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5771                 mode, "mode");
5772 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5773 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5774                 value, UINT8);
5775 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5776 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5777                 port_id, UINT16);
5778
5779 cmdline_parse_inst_t cmd_set_bonding_mode = {
5780                 .f = cmd_set_bonding_mode_parsed,
5781                 .help_str = "set bonding mode <mode_value> <port_id>: "
5782                         "Set the bonding mode for port_id",
5783                 .data = NULL,
5784                 .tokens = {
5785                                 (void *) &cmd_setbonding_mode_set,
5786                                 (void *) &cmd_setbonding_mode_bonding,
5787                                 (void *) &cmd_setbonding_mode_mode,
5788                                 (void *) &cmd_setbonding_mode_value,
5789                                 (void *) &cmd_setbonding_mode_port,
5790                                 NULL
5791                 }
5792 };
5793
5794 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5795 struct cmd_set_bonding_lacp_dedicated_queues_result {
5796         cmdline_fixed_string_t set;
5797         cmdline_fixed_string_t bonding;
5798         cmdline_fixed_string_t lacp;
5799         cmdline_fixed_string_t dedicated_queues;
5800         portid_t port_id;
5801         cmdline_fixed_string_t mode;
5802 };
5803
5804 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5805                 __rte_unused  struct cmdline *cl,
5806                 __rte_unused void *data)
5807 {
5808         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5809         portid_t port_id = res->port_id;
5810         struct rte_port *port;
5811
5812         port = &ports[port_id];
5813
5814         /** Check if the port is not started **/
5815         if (port->port_status != RTE_PORT_STOPPED) {
5816                 printf("Please stop port %d first\n", port_id);
5817                 return;
5818         }
5819
5820         if (!strcmp(res->mode, "enable")) {
5821                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5822                         printf("Dedicate queues for LACP control packets"
5823                                         " enabled\n");
5824                 else
5825                         printf("Enabling dedicate queues for LACP control "
5826                                         "packets on port %d failed\n", port_id);
5827         } else if (!strcmp(res->mode, "disable")) {
5828                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5829                         printf("Dedicated queues for LACP control packets "
5830                                         "disabled\n");
5831                 else
5832                         printf("Disabling dedicated queues for LACP control "
5833                                         "traffic on port %d failed\n", port_id);
5834         }
5835 }
5836
5837 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5838 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5839                 set, "set");
5840 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5841 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5842                 bonding, "bonding");
5843 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5844 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5845                 lacp, "lacp");
5846 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5848                 dedicated_queues, "dedicated_queues");
5849 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5850 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5851                 port_id, UINT16);
5852 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5854                 mode, "enable#disable");
5855
5856 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5857                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5858                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5859                         "enable|disable: "
5860                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5861                 .data = NULL,
5862                 .tokens = {
5863                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5864                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5865                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5866                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5867                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5868                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5869                         NULL
5870                 }
5871 };
5872
5873 /* *** SET BALANCE XMIT POLICY *** */
5874 struct cmd_set_bonding_balance_xmit_policy_result {
5875         cmdline_fixed_string_t set;
5876         cmdline_fixed_string_t bonding;
5877         cmdline_fixed_string_t balance_xmit_policy;
5878         portid_t port_id;
5879         cmdline_fixed_string_t policy;
5880 };
5881
5882 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5883                 __rte_unused  struct cmdline *cl,
5884                 __rte_unused void *data)
5885 {
5886         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5887         portid_t port_id = res->port_id;
5888         uint8_t policy;
5889
5890         if (!strcmp(res->policy, "l2")) {
5891                 policy = BALANCE_XMIT_POLICY_LAYER2;
5892         } else if (!strcmp(res->policy, "l23")) {
5893                 policy = BALANCE_XMIT_POLICY_LAYER23;
5894         } else if (!strcmp(res->policy, "l34")) {
5895                 policy = BALANCE_XMIT_POLICY_LAYER34;
5896         } else {
5897                 printf("\t Invalid xmit policy selection");
5898                 return;
5899         }
5900
5901         /* Set the bonding mode for the relevant port. */
5902         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5903                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5904                                 port_id);
5905         }
5906 }
5907
5908 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5910                 set, "set");
5911 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5912 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5913                 bonding, "bonding");
5914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5916                 balance_xmit_policy, "balance_xmit_policy");
5917 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5918 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5919                 port_id, UINT16);
5920 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5922                 policy, "l2#l23#l34");
5923
5924 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5925                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5926                 .help_str = "set bonding balance_xmit_policy <port_id> "
5927                         "l2|l23|l34: "
5928                         "Set the bonding balance_xmit_policy for port_id",
5929                 .data = NULL,
5930                 .tokens = {
5931                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5932                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5933                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5934                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5935                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5936                                 NULL
5937                 }
5938 };
5939
5940 /* *** SHOW NIC BONDING CONFIGURATION *** */
5941 struct cmd_show_bonding_config_result {
5942         cmdline_fixed_string_t show;
5943         cmdline_fixed_string_t bonding;
5944         cmdline_fixed_string_t config;
5945         portid_t port_id;
5946 };
5947
5948 static void cmd_show_bonding_config_parsed(void *parsed_result,
5949                 __rte_unused  struct cmdline *cl,
5950                 __rte_unused void *data)
5951 {
5952         struct cmd_show_bonding_config_result *res = parsed_result;
5953         int bonding_mode, agg_mode;
5954         portid_t slaves[RTE_MAX_ETHPORTS];
5955         int num_slaves, num_active_slaves;
5956         int primary_id;
5957         int i;
5958         portid_t port_id = res->port_id;
5959
5960         /* Display the bonding mode.*/
5961         bonding_mode = rte_eth_bond_mode_get(port_id);
5962         if (bonding_mode < 0) {
5963                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5964                 return;
5965         } else
5966                 printf("\tBonding mode: %d\n", bonding_mode);
5967
5968         if (bonding_mode == BONDING_MODE_BALANCE) {
5969                 int balance_xmit_policy;
5970
5971                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5972                 if (balance_xmit_policy < 0) {
5973                         printf("\tFailed to get balance xmit policy for port = %d\n",
5974                                         port_id);
5975                         return;
5976                 } else {
5977                         printf("\tBalance Xmit Policy: ");
5978
5979                         switch (balance_xmit_policy) {
5980                         case BALANCE_XMIT_POLICY_LAYER2:
5981                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5982                                 break;
5983                         case BALANCE_XMIT_POLICY_LAYER23:
5984                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5985                                 break;
5986                         case BALANCE_XMIT_POLICY_LAYER34:
5987                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5988                                 break;
5989                         }
5990                         printf("\n");
5991                 }
5992         }
5993
5994         if (bonding_mode == BONDING_MODE_8023AD) {
5995                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5996                 printf("\tIEEE802.3AD Aggregator Mode: ");
5997                 switch (agg_mode) {
5998                 case AGG_BANDWIDTH:
5999                         printf("bandwidth");
6000                         break;
6001                 case AGG_STABLE:
6002                         printf("stable");
6003                         break;
6004                 case AGG_COUNT:
6005                         printf("count");
6006                         break;
6007                 }
6008                 printf("\n");
6009         }
6010
6011         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6012
6013         if (num_slaves < 0) {
6014                 printf("\tFailed to get slave list for port = %d\n", port_id);
6015                 return;
6016         }
6017         if (num_slaves > 0) {
6018                 printf("\tSlaves (%d): [", num_slaves);
6019                 for (i = 0; i < num_slaves - 1; i++)
6020                         printf("%d ", slaves[i]);
6021
6022                 printf("%d]\n", slaves[num_slaves - 1]);
6023         } else {
6024                 printf("\tSlaves: []\n");
6025
6026         }
6027
6028         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6029                         RTE_MAX_ETHPORTS);
6030
6031         if (num_active_slaves < 0) {
6032                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6033                 return;
6034         }
6035         if (num_active_slaves > 0) {
6036                 printf("\tActive Slaves (%d): [", num_active_slaves);
6037                 for (i = 0; i < num_active_slaves - 1; i++)
6038                         printf("%d ", slaves[i]);
6039
6040                 printf("%d]\n", slaves[num_active_slaves - 1]);
6041
6042         } else {
6043                 printf("\tActive Slaves: []\n");
6044
6045         }
6046
6047         primary_id = rte_eth_bond_primary_get(port_id);
6048         if (primary_id < 0) {
6049                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6050                 return;
6051         } else
6052                 printf("\tPrimary: [%d]\n", primary_id);
6053
6054 }
6055
6056 cmdline_parse_token_string_t cmd_showbonding_config_show =
6057 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6058                 show, "show");
6059 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6060 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6061                 bonding, "bonding");
6062 cmdline_parse_token_string_t cmd_showbonding_config_config =
6063 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6064                 config, "config");
6065 cmdline_parse_token_num_t cmd_showbonding_config_port =
6066 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6067                 port_id, UINT16);
6068
6069 cmdline_parse_inst_t cmd_show_bonding_config = {
6070                 .f = cmd_show_bonding_config_parsed,
6071                 .help_str = "show bonding config <port_id>: "
6072                         "Show the bonding config for port_id",
6073                 .data = NULL,
6074                 .tokens = {
6075                                 (void *)&cmd_showbonding_config_show,
6076                                 (void *)&cmd_showbonding_config_bonding,
6077                                 (void *)&cmd_showbonding_config_config,
6078                                 (void *)&cmd_showbonding_config_port,
6079                                 NULL
6080                 }
6081 };
6082
6083 /* *** SET BONDING PRIMARY *** */
6084 struct cmd_set_bonding_primary_result {
6085         cmdline_fixed_string_t set;
6086         cmdline_fixed_string_t bonding;
6087         cmdline_fixed_string_t primary;
6088         portid_t slave_id;
6089         portid_t port_id;
6090 };
6091
6092 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6093                 __rte_unused  struct cmdline *cl,
6094                 __rte_unused void *data)
6095 {
6096         struct cmd_set_bonding_primary_result *res = parsed_result;
6097         portid_t master_port_id = res->port_id;
6098         portid_t slave_port_id = res->slave_id;
6099
6100         /* Set the primary slave for a bonded device. */
6101         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6102                 printf("\t Failed to set primary slave for port = %d.\n",
6103                                 master_port_id);
6104                 return;
6105         }
6106         init_port_config();
6107 }
6108
6109 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6110 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6111                 set, "set");
6112 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6113 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6114                 bonding, "bonding");
6115 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6117                 primary, "primary");
6118 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6119 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6120                 slave_id, UINT16);
6121 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6122 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6123                 port_id, UINT16);
6124
6125 cmdline_parse_inst_t cmd_set_bonding_primary = {
6126                 .f = cmd_set_bonding_primary_parsed,
6127                 .help_str = "set bonding primary <slave_id> <port_id>: "
6128                         "Set the primary slave for port_id",
6129                 .data = NULL,
6130                 .tokens = {
6131                                 (void *)&cmd_setbonding_primary_set,
6132                                 (void *)&cmd_setbonding_primary_bonding,
6133                                 (void *)&cmd_setbonding_primary_primary,
6134                                 (void *)&cmd_setbonding_primary_slave,
6135                                 (void *)&cmd_setbonding_primary_port,
6136                                 NULL
6137                 }
6138 };
6139
6140 /* *** ADD SLAVE *** */
6141 struct cmd_add_bonding_slave_result {
6142         cmdline_fixed_string_t add;
6143         cmdline_fixed_string_t bonding;
6144         cmdline_fixed_string_t slave;
6145         portid_t slave_id;
6146         portid_t port_id;
6147 };
6148
6149 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6150                 __rte_unused  struct cmdline *cl,
6151                 __rte_unused void *data)
6152 {
6153         struct cmd_add_bonding_slave_result *res = parsed_result;
6154         portid_t master_port_id = res->port_id;
6155         portid_t slave_port_id = res->slave_id;
6156
6157         /* add the slave for a bonded device. */
6158         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6159                 printf("\t Failed to add slave %d to master port = %d.\n",
6160                                 slave_port_id, master_port_id);
6161                 return;
6162         }
6163         init_port_config();
6164         set_port_slave_flag(slave_port_id);
6165 }
6166
6167 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6168 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6169                 add, "add");
6170 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6171 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6172                 bonding, "bonding");
6173 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6174 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6175                 slave, "slave");
6176 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6177 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6178                 slave_id, UINT16);
6179 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6180 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6181                 port_id, UINT16);
6182
6183 cmdline_parse_inst_t cmd_add_bonding_slave = {
6184                 .f = cmd_add_bonding_slave_parsed,
6185                 .help_str = "add bonding slave <slave_id> <port_id>: "
6186                         "Add a slave device to a bonded device",
6187                 .data = NULL,
6188                 .tokens = {
6189                                 (void *)&cmd_addbonding_slave_add,
6190                                 (void *)&cmd_addbonding_slave_bonding,
6191                                 (void *)&cmd_addbonding_slave_slave,
6192                                 (void *)&cmd_addbonding_slave_slaveid,
6193                                 (void *)&cmd_addbonding_slave_port,
6194                                 NULL
6195                 }
6196 };
6197
6198 /* *** REMOVE SLAVE *** */
6199 struct cmd_remove_bonding_slave_result {
6200         cmdline_fixed_string_t remove;
6201         cmdline_fixed_string_t bonding;
6202         cmdline_fixed_string_t slave;
6203         portid_t slave_id;
6204         portid_t port_id;
6205 };
6206
6207 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6208                 __rte_unused  struct cmdline *cl,
6209                 __rte_unused void *data)
6210 {
6211         struct cmd_remove_bonding_slave_result *res = parsed_result;
6212         portid_t master_port_id = res->port_id;
6213         portid_t slave_port_id = res->slave_id;
6214
6215         /* remove the slave from a bonded device. */
6216         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6217                 printf("\t Failed to remove slave %d from master port = %d.\n",
6218                                 slave_port_id, master_port_id);
6219                 return;
6220         }
6221         init_port_config();
6222         clear_port_slave_flag(slave_port_id);
6223 }
6224
6225 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6226                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6227                                 remove, "remove");
6228 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6229                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6230                                 bonding, "bonding");
6231 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6232                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6233                                 slave, "slave");
6234 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6235                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6236                                 slave_id, UINT16);
6237 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6238                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6239                                 port_id, UINT16);
6240
6241 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6242                 .f = cmd_remove_bonding_slave_parsed,
6243                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6244                         "Remove a slave device from a bonded device",
6245                 .data = NULL,
6246                 .tokens = {
6247                                 (void *)&cmd_removebonding_slave_remove,
6248                                 (void *)&cmd_removebonding_slave_bonding,
6249                                 (void *)&cmd_removebonding_slave_slave,
6250                                 (void *)&cmd_removebonding_slave_slaveid,
6251                                 (void *)&cmd_removebonding_slave_port,
6252                                 NULL
6253                 }
6254 };
6255
6256 /* *** CREATE BONDED DEVICE *** */
6257 struct cmd_create_bonded_device_result {
6258         cmdline_fixed_string_t create;
6259         cmdline_fixed_string_t bonded;
6260         cmdline_fixed_string_t device;
6261         uint8_t mode;
6262         uint8_t socket;
6263 };
6264
6265 static int bond_dev_num = 0;
6266
6267 static void cmd_create_bonded_device_parsed(void *parsed_result,
6268                 __rte_unused  struct cmdline *cl,
6269                 __rte_unused void *data)
6270 {
6271         struct cmd_create_bonded_device_result *res = parsed_result;
6272         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6273         int port_id;
6274         int ret;
6275
6276         if (test_done == 0) {
6277                 printf("Please stop forwarding first\n");
6278                 return;
6279         }
6280
6281         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6282                         bond_dev_num++);
6283
6284         /* Create a new bonded device. */
6285         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6286         if (port_id < 0) {
6287                 printf("\t Failed to create bonded device.\n");
6288                 return;
6289         } else {
6290                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6291                                 port_id);
6292
6293                 /* Update number of ports */
6294                 nb_ports = rte_eth_dev_count_avail();
6295                 reconfig(port_id, res->socket);
6296                 ret = rte_eth_promiscuous_enable(port_id);
6297                 if (ret != 0)
6298                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6299                                 port_id, rte_strerror(-ret));
6300
6301                 ports[port_id].need_setup = 0;
6302                 ports[port_id].port_status = RTE_PORT_STOPPED;
6303         }
6304
6305 }
6306
6307 cmdline_parse_token_string_t cmd_createbonded_device_create =
6308                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6309                                 create, "create");
6310 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6311                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6312                                 bonded, "bonded");
6313 cmdline_parse_token_string_t cmd_createbonded_device_device =
6314                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6315                                 device, "device");
6316 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6317                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6318                                 mode, UINT8);
6319 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6320                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6321                                 socket, UINT8);
6322
6323 cmdline_parse_inst_t cmd_create_bonded_device = {
6324                 .f = cmd_create_bonded_device_parsed,
6325                 .help_str = "create bonded device <mode> <socket>: "
6326                         "Create a new bonded device with specific bonding mode and socket",
6327                 .data = NULL,
6328                 .tokens = {
6329                                 (void *)&cmd_createbonded_device_create,
6330                                 (void *)&cmd_createbonded_device_bonded,
6331                                 (void *)&cmd_createbonded_device_device,
6332                                 (void *)&cmd_createbonded_device_mode,
6333                                 (void *)&cmd_createbonded_device_socket,
6334                                 NULL
6335                 }
6336 };
6337
6338 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6339 struct cmd_set_bond_mac_addr_result {
6340         cmdline_fixed_string_t set;
6341         cmdline_fixed_string_t bonding;
6342         cmdline_fixed_string_t mac_addr;
6343         uint16_t port_num;
6344         struct rte_ether_addr address;
6345 };
6346
6347 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6348                 __rte_unused  struct cmdline *cl,
6349                 __rte_unused void *data)
6350 {
6351         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6352         int ret;
6353
6354         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6355                 return;
6356
6357         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6358
6359         /* check the return value and print it if is < 0 */
6360         if (ret < 0)
6361                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6362 }
6363
6364 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6365                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6366 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6367                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6368                                 "bonding");
6369 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6370                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6371                                 "mac_addr");
6372 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6373                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6374                                 port_num, UINT16);
6375 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6376                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6377
6378 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6379                 .f = cmd_set_bond_mac_addr_parsed,
6380                 .data = (void *) 0,
6381                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6382                 .tokens = {
6383                                 (void *)&cmd_set_bond_mac_addr_set,
6384                                 (void *)&cmd_set_bond_mac_addr_bonding,
6385                                 (void *)&cmd_set_bond_mac_addr_mac,
6386                                 (void *)&cmd_set_bond_mac_addr_portnum,
6387                                 (void *)&cmd_set_bond_mac_addr_addr,
6388                                 NULL
6389                 }
6390 };
6391
6392
6393 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6394 struct cmd_set_bond_mon_period_result {
6395         cmdline_fixed_string_t set;
6396         cmdline_fixed_string_t bonding;
6397         cmdline_fixed_string_t mon_period;
6398         uint16_t port_num;
6399         uint32_t period_ms;
6400 };
6401
6402 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6403                 __rte_unused  struct cmdline *cl,
6404                 __rte_unused void *data)
6405 {
6406         struct cmd_set_bond_mon_period_result *res = parsed_result;
6407         int ret;
6408
6409         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6410
6411         /* check the return value and print it if is < 0 */
6412         if (ret < 0)
6413                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6414 }
6415
6416 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6417                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6418                                 set, "set");
6419 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6420                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6421                                 bonding, "bonding");
6422 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6423                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6424                                 mon_period,     "mon_period");
6425 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6426                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6427                                 port_num, UINT16);
6428 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6429                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6430                                 period_ms, UINT32);
6431
6432 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6433                 .f = cmd_set_bond_mon_period_parsed,
6434                 .data = (void *) 0,
6435                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6436                 .tokens = {
6437                                 (void *)&cmd_set_bond_mon_period_set,
6438                                 (void *)&cmd_set_bond_mon_period_bonding,
6439                                 (void *)&cmd_set_bond_mon_period_mon_period,
6440                                 (void *)&cmd_set_bond_mon_period_portnum,
6441                                 (void *)&cmd_set_bond_mon_period_period_ms,
6442                                 NULL
6443                 }
6444 };
6445
6446
6447
6448 struct cmd_set_bonding_agg_mode_policy_result {
6449         cmdline_fixed_string_t set;
6450         cmdline_fixed_string_t bonding;
6451         cmdline_fixed_string_t agg_mode;
6452         uint16_t port_num;
6453         cmdline_fixed_string_t policy;
6454 };
6455
6456
6457 static void
6458 cmd_set_bonding_agg_mode(void *parsed_result,
6459                 __rte_unused struct cmdline *cl,
6460                 __rte_unused void *data)
6461 {
6462         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6463         uint8_t policy = AGG_BANDWIDTH;
6464
6465         if (!strcmp(res->policy, "bandwidth"))
6466                 policy = AGG_BANDWIDTH;
6467         else if (!strcmp(res->policy, "stable"))
6468                 policy = AGG_STABLE;
6469         else if (!strcmp(res->policy, "count"))
6470                 policy = AGG_COUNT;
6471
6472         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6473 }
6474
6475
6476 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6477         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6478                                 set, "set");
6479 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6480         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6481                                 bonding, "bonding");
6482
6483 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6484         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6485                                 agg_mode, "agg_mode");
6486
6487 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6488         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6489                                 port_num, UINT16);
6490
6491 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6492         TOKEN_STRING_INITIALIZER(
6493                         struct cmd_set_bonding_balance_xmit_policy_result,
6494                 policy, "stable#bandwidth#count");
6495
6496 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6497         .f = cmd_set_bonding_agg_mode,
6498         .data = (void *) 0,
6499         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6500         .tokens = {
6501                         (void *)&cmd_set_bonding_agg_mode_set,
6502                         (void *)&cmd_set_bonding_agg_mode_bonding,
6503                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6504                         (void *)&cmd_set_bonding_agg_mode_portnum,
6505                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6506                         NULL
6507                 }
6508 };
6509
6510
6511 #endif /* RTE_LIBRTE_PMD_BOND */
6512
6513 /* *** SET FORWARDING MODE *** */
6514 struct cmd_set_fwd_mode_result {
6515         cmdline_fixed_string_t set;
6516         cmdline_fixed_string_t fwd;
6517         cmdline_fixed_string_t mode;
6518 };
6519
6520 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6521                                     __rte_unused struct cmdline *cl,
6522                                     __rte_unused void *data)
6523 {
6524         struct cmd_set_fwd_mode_result *res = parsed_result;
6525
6526         retry_enabled = 0;
6527         set_pkt_forwarding_mode(res->mode);
6528 }
6529
6530 cmdline_parse_token_string_t cmd_setfwd_set =
6531         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6532 cmdline_parse_token_string_t cmd_setfwd_fwd =
6533         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6534 cmdline_parse_token_string_t cmd_setfwd_mode =
6535         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6536                 "" /* defined at init */);
6537
6538 cmdline_parse_inst_t cmd_set_fwd_mode = {
6539         .f = cmd_set_fwd_mode_parsed,
6540         .data = NULL,
6541         .help_str = NULL, /* defined at init */
6542         .tokens = {
6543                 (void *)&cmd_setfwd_set,
6544                 (void *)&cmd_setfwd_fwd,
6545                 (void *)&cmd_setfwd_mode,
6546                 NULL,
6547         },
6548 };
6549
6550 static void cmd_set_fwd_mode_init(void)
6551 {
6552         char *modes, *c;
6553         static char token[128];
6554         static char help[256];
6555         cmdline_parse_token_string_t *token_struct;
6556
6557         modes = list_pkt_forwarding_modes();
6558         snprintf(help, sizeof(help), "set fwd %s: "
6559                 "Set packet forwarding mode", modes);
6560         cmd_set_fwd_mode.help_str = help;
6561
6562         /* string token separator is # */
6563         for (c = token; *modes != '\0'; modes++)
6564                 if (*modes == '|')
6565                         *c++ = '#';
6566                 else
6567                         *c++ = *modes;
6568         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6569         token_struct->string_data.str = token;
6570 }
6571
6572 /* *** SET RETRY FORWARDING MODE *** */
6573 struct cmd_set_fwd_retry_mode_result {
6574         cmdline_fixed_string_t set;
6575         cmdline_fixed_string_t fwd;
6576         cmdline_fixed_string_t mode;
6577         cmdline_fixed_string_t retry;
6578 };
6579
6580 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6581                             __rte_unused struct cmdline *cl,
6582                             __rte_unused void *data)
6583 {
6584         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6585
6586         retry_enabled = 1;
6587         set_pkt_forwarding_mode(res->mode);
6588 }
6589
6590 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6591         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6592                         set, "set");
6593 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6594         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6595                         fwd, "fwd");
6596 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6597         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6598                         mode,
6599                 "" /* defined at init */);
6600 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6601         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6602                         retry, "retry");
6603
6604 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6605         .f = cmd_set_fwd_retry_mode_parsed,
6606         .data = NULL,
6607         .help_str = NULL, /* defined at init */
6608         .tokens = {
6609                 (void *)&cmd_setfwd_retry_set,
6610                 (void *)&cmd_setfwd_retry_fwd,
6611                 (void *)&cmd_setfwd_retry_mode,
6612                 (void *)&cmd_setfwd_retry_retry,
6613                 NULL,
6614         },
6615 };
6616
6617 static void cmd_set_fwd_retry_mode_init(void)
6618 {
6619         char *modes, *c;
6620         static char token[128];
6621         static char help[256];
6622         cmdline_parse_token_string_t *token_struct;
6623
6624         modes = list_pkt_forwarding_retry_modes();
6625         snprintf(help, sizeof(help), "set fwd %s retry: "
6626                 "Set packet forwarding mode with retry", modes);
6627         cmd_set_fwd_retry_mode.help_str = help;
6628
6629         /* string token separator is # */
6630         for (c = token; *modes != '\0'; modes++)
6631                 if (*modes == '|')
6632                         *c++ = '#';
6633                 else
6634                         *c++ = *modes;
6635         token_struct = (cmdline_parse_token_string_t *)
6636                 cmd_set_fwd_retry_mode.tokens[2];
6637         token_struct->string_data.str = token;
6638 }
6639
6640 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6641 struct cmd_set_burst_tx_retry_result {
6642         cmdline_fixed_string_t set;
6643         cmdline_fixed_string_t burst;
6644         cmdline_fixed_string_t tx;
6645         cmdline_fixed_string_t delay;
6646         uint32_t time;
6647         cmdline_fixed_string_t retry;
6648         uint32_t retry_num;
6649 };
6650
6651 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6652                                         __rte_unused struct cmdline *cl,
6653                                         __rte_unused void *data)
6654 {
6655         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6656
6657         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6658                 && !strcmp(res->tx, "tx")) {
6659                 if (!strcmp(res->delay, "delay"))
6660                         burst_tx_delay_time = res->time;
6661                 if (!strcmp(res->retry, "retry"))
6662                         burst_tx_retry_num = res->retry_num;
6663         }
6664
6665 }
6666
6667 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6668         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6669 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6670         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6671                                  "burst");
6672 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6673         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6674 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6675         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6676 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6677         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6678 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6679         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6680 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6681         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6682
6683 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6684         .f = cmd_set_burst_tx_retry_parsed,
6685         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6686         .tokens = {
6687                 (void *)&cmd_set_burst_tx_retry_set,
6688                 (void *)&cmd_set_burst_tx_retry_burst,
6689                 (void *)&cmd_set_burst_tx_retry_tx,
6690                 (void *)&cmd_set_burst_tx_retry_delay,
6691                 (void *)&cmd_set_burst_tx_retry_time,
6692                 (void *)&cmd_set_burst_tx_retry_retry,
6693                 (void *)&cmd_set_burst_tx_retry_retry_num,
6694                 NULL,
6695         },
6696 };
6697
6698 /* *** SET PROMISC MODE *** */
6699 struct cmd_set_promisc_mode_result {
6700         cmdline_fixed_string_t set;
6701         cmdline_fixed_string_t promisc;
6702         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6703         uint16_t port_num;               /* valid if "allports" argument == 0 */
6704         cmdline_fixed_string_t mode;
6705 };
6706
6707 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6708                                         __rte_unused struct cmdline *cl,
6709                                         void *allports)
6710 {
6711         struct cmd_set_promisc_mode_result *res = parsed_result;
6712         int enable;
6713         portid_t i;
6714
6715         if (!strcmp(res->mode, "on"))
6716                 enable = 1;
6717         else
6718                 enable = 0;
6719
6720         /* all ports */
6721         if (allports) {
6722                 RTE_ETH_FOREACH_DEV(i)
6723                         eth_set_promisc_mode(i, enable);
6724         } else {
6725                 eth_set_promisc_mode(res->port_num, enable);
6726         }
6727 }
6728
6729 cmdline_parse_token_string_t cmd_setpromisc_set =
6730         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6731 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6732         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6733                                  "promisc");
6734 cmdline_parse_token_string_t cmd_setpromisc_portall =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6736                                  "all");
6737 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6738         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6739                               UINT16);
6740 cmdline_parse_token_string_t cmd_setpromisc_mode =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6742                                  "on#off");
6743
6744 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6745         .f = cmd_set_promisc_mode_parsed,
6746         .data = (void *)1,
6747         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6748         .tokens = {
6749                 (void *)&cmd_setpromisc_set,
6750                 (void *)&cmd_setpromisc_promisc,
6751                 (void *)&cmd_setpromisc_portall,
6752                 (void *)&cmd_setpromisc_mode,
6753                 NULL,
6754         },
6755 };
6756
6757 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6758         .f = cmd_set_promisc_mode_parsed,
6759         .data = (void *)0,
6760         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6761         .tokens = {
6762                 (void *)&cmd_setpromisc_set,
6763                 (void *)&cmd_setpromisc_promisc,
6764                 (void *)&cmd_setpromisc_portnum,
6765                 (void *)&cmd_setpromisc_mode,
6766                 NULL,
6767         },
6768 };
6769
6770 /* *** SET ALLMULTI MODE *** */
6771 struct cmd_set_allmulti_mode_result {
6772         cmdline_fixed_string_t set;
6773         cmdline_fixed_string_t allmulti;
6774         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6775         uint16_t port_num;               /* valid if "allports" argument == 0 */
6776         cmdline_fixed_string_t mode;
6777 };
6778
6779 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6780                                         __rte_unused struct cmdline *cl,
6781                                         void *allports)
6782 {
6783         struct cmd_set_allmulti_mode_result *res = parsed_result;
6784         int enable;
6785         portid_t i;
6786
6787         if (!strcmp(res->mode, "on"))
6788                 enable = 1;
6789         else
6790                 enable = 0;
6791
6792         /* all ports */
6793         if (allports) {
6794                 RTE_ETH_FOREACH_DEV(i) {
6795                         eth_set_allmulticast_mode(i, enable);
6796                 }
6797         }
6798         else {
6799                 eth_set_allmulticast_mode(res->port_num, enable);
6800         }
6801 }
6802
6803 cmdline_parse_token_string_t cmd_setallmulti_set =
6804         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6805 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6806         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6807                                  "allmulti");
6808 cmdline_parse_token_string_t cmd_setallmulti_portall =
6809         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6810                                  "all");
6811 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6812         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6813                               UINT16);
6814 cmdline_parse_token_string_t cmd_setallmulti_mode =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6816                                  "on#off");
6817
6818 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6819         .f = cmd_set_allmulti_mode_parsed,
6820         .data = (void *)1,
6821         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6822         .tokens = {
6823                 (void *)&cmd_setallmulti_set,
6824                 (void *)&cmd_setallmulti_allmulti,
6825                 (void *)&cmd_setallmulti_portall,
6826                 (void *)&cmd_setallmulti_mode,
6827                 NULL,
6828         },
6829 };
6830
6831 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6832         .f = cmd_set_allmulti_mode_parsed,
6833         .data = (void *)0,
6834         .help_str = "set allmulti <port_id> on|off: "
6835                 "Set allmulti mode on port_id",
6836         .tokens = {
6837                 (void *)&cmd_setallmulti_set,
6838                 (void *)&cmd_setallmulti_allmulti,
6839                 (void *)&cmd_setallmulti_portnum,
6840                 (void *)&cmd_setallmulti_mode,
6841                 NULL,
6842         },
6843 };
6844
6845 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6846 struct cmd_link_flow_ctrl_set_result {
6847         cmdline_fixed_string_t set;
6848         cmdline_fixed_string_t flow_ctrl;
6849         cmdline_fixed_string_t rx;
6850         cmdline_fixed_string_t rx_lfc_mode;
6851         cmdline_fixed_string_t tx;
6852         cmdline_fixed_string_t tx_lfc_mode;
6853         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6854         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6855         cmdline_fixed_string_t autoneg_str;
6856         cmdline_fixed_string_t autoneg;
6857         cmdline_fixed_string_t hw_str;
6858         uint32_t high_water;
6859         cmdline_fixed_string_t lw_str;
6860         uint32_t low_water;
6861         cmdline_fixed_string_t pt_str;
6862         uint16_t pause_time;
6863         cmdline_fixed_string_t xon_str;
6864         uint16_t send_xon;
6865         portid_t port_id;
6866 };
6867
6868 cmdline_parse_token_string_t cmd_lfc_set_set =
6869         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6870                                 set, "set");
6871 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6872         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6873                                 flow_ctrl, "flow_ctrl");
6874 cmdline_parse_token_string_t cmd_lfc_set_rx =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 rx, "rx");
6877 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 rx_lfc_mode, "on#off");
6880 cmdline_parse_token_string_t cmd_lfc_set_tx =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 tx, "tx");
6883 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 tx_lfc_mode, "on#off");
6886 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 hw_str, "high_water");
6889 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6890         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 high_water, UINT32);
6892 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 lw_str, "low_water");
6895 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6896         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 low_water, UINT32);
6898 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 pt_str, "pause_time");
6901 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 pause_time, UINT16);
6904 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 xon_str, "send_xon");
6907 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 send_xon, UINT16);
6910 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6913 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6914         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 mac_ctrl_frame_fwd_mode, "on#off");
6916 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 autoneg_str, "autoneg");
6919 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 autoneg, "on#off");
6922 cmdline_parse_token_num_t cmd_lfc_set_portid =
6923         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 port_id, UINT16);
6925
6926 /* forward declaration */
6927 static void
6928 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6929                               void *data);
6930
6931 cmdline_parse_inst_t cmd_link_flow_control_set = {
6932         .f = cmd_link_flow_ctrl_set_parsed,
6933         .data = NULL,
6934         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6935                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6936                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6937         .tokens = {
6938                 (void *)&cmd_lfc_set_set,
6939                 (void *)&cmd_lfc_set_flow_ctrl,
6940                 (void *)&cmd_lfc_set_rx,
6941                 (void *)&cmd_lfc_set_rx_mode,
6942                 (void *)&cmd_lfc_set_tx,
6943                 (void *)&cmd_lfc_set_tx_mode,
6944                 (void *)&cmd_lfc_set_high_water,
6945                 (void *)&cmd_lfc_set_low_water,
6946                 (void *)&cmd_lfc_set_pause_time,
6947                 (void *)&cmd_lfc_set_send_xon,
6948                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6949                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6950                 (void *)&cmd_lfc_set_autoneg_str,
6951                 (void *)&cmd_lfc_set_autoneg,
6952                 (void *)&cmd_lfc_set_portid,
6953                 NULL,
6954         },
6955 };
6956
6957 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6958         .f = cmd_link_flow_ctrl_set_parsed,
6959         .data = (void *)&cmd_link_flow_control_set_rx,
6960         .help_str = "set flow_ctrl rx on|off <port_id>: "
6961                 "Change rx flow control parameter",
6962         .tokens = {
6963                 (void *)&cmd_lfc_set_set,
6964                 (void *)&cmd_lfc_set_flow_ctrl,
6965                 (void *)&cmd_lfc_set_rx,
6966                 (void *)&cmd_lfc_set_rx_mode,
6967                 (void *)&cmd_lfc_set_portid,
6968                 NULL,
6969         },
6970 };
6971
6972 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6973         .f = cmd_link_flow_ctrl_set_parsed,
6974         .data = (void *)&cmd_link_flow_control_set_tx,
6975         .help_str = "set flow_ctrl tx on|off <port_id>: "
6976                 "Change tx flow control parameter",
6977         .tokens = {
6978                 (void *)&cmd_lfc_set_set,
6979                 (void *)&cmd_lfc_set_flow_ctrl,
6980                 (void *)&cmd_lfc_set_tx,
6981                 (void *)&cmd_lfc_set_tx_mode,
6982                 (void *)&cmd_lfc_set_portid,
6983                 NULL,
6984         },
6985 };
6986
6987 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6988         .f = cmd_link_flow_ctrl_set_parsed,
6989         .data = (void *)&cmd_link_flow_control_set_hw,
6990         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6991                 "Change high water flow control parameter",
6992         .tokens = {
6993                 (void *)&cmd_lfc_set_set,
6994                 (void *)&cmd_lfc_set_flow_ctrl,
6995                 (void *)&cmd_lfc_set_high_water_str,
6996                 (void *)&cmd_lfc_set_high_water,
6997                 (void *)&cmd_lfc_set_portid,
6998                 NULL,
6999         },
7000 };
7001
7002 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7003         .f = cmd_link_flow_ctrl_set_parsed,
7004         .data = (void *)&cmd_link_flow_control_set_lw,
7005         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7006                 "Change low water flow control parameter",
7007         .tokens = {
7008                 (void *)&cmd_lfc_set_set,
7009                 (void *)&cmd_lfc_set_flow_ctrl,
7010                 (void *)&cmd_lfc_set_low_water_str,
7011                 (void *)&cmd_lfc_set_low_water,
7012                 (void *)&cmd_lfc_set_portid,
7013                 NULL,
7014         },
7015 };
7016
7017 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7018         .f = cmd_link_flow_ctrl_set_parsed,
7019         .data = (void *)&cmd_link_flow_control_set_pt,
7020         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7021                 "Change pause time flow control parameter",
7022         .tokens = {
7023                 (void *)&cmd_lfc_set_set,
7024                 (void *)&cmd_lfc_set_flow_ctrl,
7025                 (void *)&cmd_lfc_set_pause_time_str,
7026                 (void *)&cmd_lfc_set_pause_time,
7027                 (void *)&cmd_lfc_set_portid,
7028                 NULL,
7029         },
7030 };
7031
7032 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7033         .f = cmd_link_flow_ctrl_set_parsed,
7034         .data = (void *)&cmd_link_flow_control_set_xon,
7035         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7036                 "Change send_xon flow control parameter",
7037         .tokens = {
7038                 (void *)&cmd_lfc_set_set,
7039                 (void *)&cmd_lfc_set_flow_ctrl,
7040                 (void *)&cmd_lfc_set_send_xon_str,
7041                 (void *)&cmd_lfc_set_send_xon,
7042                 (void *)&cmd_lfc_set_portid,
7043                 NULL,
7044         },
7045 };
7046
7047 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7048         .f = cmd_link_flow_ctrl_set_parsed,
7049         .data = (void *)&cmd_link_flow_control_set_macfwd,
7050         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7051                 "Change mac ctrl fwd flow control parameter",
7052         .tokens = {
7053                 (void *)&cmd_lfc_set_set,
7054                 (void *)&cmd_lfc_set_flow_ctrl,
7055                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7056                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7057                 (void *)&cmd_lfc_set_portid,
7058                 NULL,
7059         },
7060 };
7061
7062 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7063         .f = cmd_link_flow_ctrl_set_parsed,
7064         .data = (void *)&cmd_link_flow_control_set_autoneg,
7065         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7066                 "Change autoneg flow control parameter",
7067         .tokens = {
7068                 (void *)&cmd_lfc_set_set,
7069                 (void *)&cmd_lfc_set_flow_ctrl,
7070                 (void *)&cmd_lfc_set_autoneg_str,
7071                 (void *)&cmd_lfc_set_autoneg,
7072                 (void *)&cmd_lfc_set_portid,
7073                 NULL,
7074         },
7075 };
7076
7077 static void
7078 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7079                               __rte_unused struct cmdline *cl,
7080                               void *data)
7081 {
7082         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7083         cmdline_parse_inst_t *cmd = data;
7084         struct rte_eth_fc_conf fc_conf;
7085         int rx_fc_en = 0;
7086         int tx_fc_en = 0;
7087         int ret;
7088
7089         /*
7090          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7091          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7092          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7093          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7094          */
7095         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7096                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7097         };
7098
7099         /* Partial command line, retrieve current configuration */
7100         if (cmd) {
7101                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7102                 if (ret != 0) {
7103                         printf("cannot get current flow ctrl parameters, return"
7104                                "code = %d\n", ret);
7105                         return;
7106                 }
7107
7108                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7109                     (fc_conf.mode == RTE_FC_FULL))
7110                         rx_fc_en = 1;
7111                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7112                     (fc_conf.mode == RTE_FC_FULL))
7113                         tx_fc_en = 1;
7114         }
7115
7116         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7117                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7118
7119         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7120                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7121
7122         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7123
7124         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7125                 fc_conf.high_water = res->high_water;
7126
7127         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7128                 fc_conf.low_water = res->low_water;
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7131                 fc_conf.pause_time = res->pause_time;
7132
7133         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7134                 fc_conf.send_xon = res->send_xon;
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7137                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7138                         fc_conf.mac_ctrl_frame_fwd = 1;
7139                 else
7140                         fc_conf.mac_ctrl_frame_fwd = 0;
7141         }
7142
7143         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7144                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7145
7146         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7147         if (ret != 0)
7148                 printf("bad flow contrl parameter, return code = %d \n", ret);
7149 }
7150
7151 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7152 struct cmd_priority_flow_ctrl_set_result {
7153         cmdline_fixed_string_t set;
7154         cmdline_fixed_string_t pfc_ctrl;
7155         cmdline_fixed_string_t rx;
7156         cmdline_fixed_string_t rx_pfc_mode;
7157         cmdline_fixed_string_t tx;
7158         cmdline_fixed_string_t tx_pfc_mode;
7159         uint32_t high_water;
7160         uint32_t low_water;
7161         uint16_t pause_time;
7162         uint8_t  priority;
7163         portid_t port_id;
7164 };
7165
7166 static void
7167 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7168                        __rte_unused struct cmdline *cl,
7169                        __rte_unused void *data)
7170 {
7171         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7172         struct rte_eth_pfc_conf pfc_conf;
7173         int rx_fc_enable, tx_fc_enable;
7174         int ret;
7175
7176         /*
7177          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7178          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7179          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7180          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7181          */
7182         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7183                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7184         };
7185
7186         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7187         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7188         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7189         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7190         pfc_conf.fc.high_water = res->high_water;
7191         pfc_conf.fc.low_water  = res->low_water;
7192         pfc_conf.fc.pause_time = res->pause_time;
7193         pfc_conf.priority      = res->priority;
7194
7195         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7196         if (ret != 0)
7197                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7198 }
7199
7200 cmdline_parse_token_string_t cmd_pfc_set_set =
7201         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7202                                 set, "set");
7203 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7204         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7205                                 pfc_ctrl, "pfc_ctrl");
7206 cmdline_parse_token_string_t cmd_pfc_set_rx =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 rx, "rx");
7209 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 rx_pfc_mode, "on#off");
7212 cmdline_parse_token_string_t cmd_pfc_set_tx =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 tx, "tx");
7215 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 tx_pfc_mode, "on#off");
7218 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7219         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 high_water, UINT32);
7221 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7222         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 low_water, UINT32);
7224 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 pause_time, UINT16);
7227 cmdline_parse_token_num_t cmd_pfc_set_priority =
7228         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 priority, UINT8);
7230 cmdline_parse_token_num_t cmd_pfc_set_portid =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 port_id, UINT16);
7233
7234 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7235         .f = cmd_priority_flow_ctrl_set_parsed,
7236         .data = NULL,
7237         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7238                 "<pause_time> <priority> <port_id>: "
7239                 "Configure the Ethernet priority flow control",
7240         .tokens = {
7241                 (void *)&cmd_pfc_set_set,
7242                 (void *)&cmd_pfc_set_flow_ctrl,
7243                 (void *)&cmd_pfc_set_rx,
7244                 (void *)&cmd_pfc_set_rx_mode,
7245                 (void *)&cmd_pfc_set_tx,
7246                 (void *)&cmd_pfc_set_tx_mode,
7247                 (void *)&cmd_pfc_set_high_water,
7248                 (void *)&cmd_pfc_set_low_water,
7249                 (void *)&cmd_pfc_set_pause_time,
7250                 (void *)&cmd_pfc_set_priority,
7251                 (void *)&cmd_pfc_set_portid,
7252                 NULL,
7253         },
7254 };
7255
7256 /* *** RESET CONFIGURATION *** */
7257 struct cmd_reset_result {
7258         cmdline_fixed_string_t reset;
7259         cmdline_fixed_string_t def;
7260 };
7261
7262 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7263                              struct cmdline *cl,
7264                              __rte_unused void *data)
7265 {
7266         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7267         set_def_fwd_config();
7268 }
7269
7270 cmdline_parse_token_string_t cmd_reset_set =
7271         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7272 cmdline_parse_token_string_t cmd_reset_def =
7273         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7274                                  "default");
7275
7276 cmdline_parse_inst_t cmd_reset = {
7277         .f = cmd_reset_parsed,
7278         .data = NULL,
7279         .help_str = "set default: Reset default forwarding configuration",
7280         .tokens = {
7281                 (void *)&cmd_reset_set,
7282                 (void *)&cmd_reset_def,
7283                 NULL,
7284         },
7285 };
7286
7287 /* *** START FORWARDING *** */
7288 struct cmd_start_result {
7289         cmdline_fixed_string_t start;
7290 };
7291
7292 cmdline_parse_token_string_t cmd_start_start =
7293         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7294
7295 static void cmd_start_parsed(__rte_unused void *parsed_result,
7296                              __rte_unused struct cmdline *cl,
7297                              __rte_unused void *data)
7298 {
7299         start_packet_forwarding(0);
7300 }
7301
7302 cmdline_parse_inst_t cmd_start = {
7303         .f = cmd_start_parsed,
7304         .data = NULL,
7305         .help_str = "start: Start packet forwarding",
7306         .tokens = {
7307                 (void *)&cmd_start_start,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7313 struct cmd_start_tx_first_result {
7314         cmdline_fixed_string_t start;
7315         cmdline_fixed_string_t tx_first;
7316 };
7317
7318 static void
7319 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7320                           __rte_unused struct cmdline *cl,
7321                           __rte_unused void *data)
7322 {
7323         start_packet_forwarding(1);
7324 }
7325
7326 cmdline_parse_token_string_t cmd_start_tx_first_start =
7327         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7328                                  "start");
7329 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7330         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7331                                  tx_first, "tx_first");
7332
7333 cmdline_parse_inst_t cmd_start_tx_first = {
7334         .f = cmd_start_tx_first_parsed,
7335         .data = NULL,
7336         .help_str = "start tx_first: Start packet forwarding, "
7337                 "after sending 1 burst of packets",
7338         .tokens = {
7339                 (void *)&cmd_start_tx_first_start,
7340                 (void *)&cmd_start_tx_first_tx_first,
7341                 NULL,
7342         },
7343 };
7344
7345 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7346 struct cmd_start_tx_first_n_result {
7347         cmdline_fixed_string_t start;
7348         cmdline_fixed_string_t tx_first;
7349         uint32_t tx_num;
7350 };
7351
7352 static void
7353 cmd_start_tx_first_n_parsed(void *parsed_result,
7354                           __rte_unused struct cmdline *cl,
7355                           __rte_unused void *data)
7356 {
7357         struct cmd_start_tx_first_n_result *res = parsed_result;
7358
7359         start_packet_forwarding(res->tx_num);
7360 }
7361
7362 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7363         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7364                         start, "start");
7365 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7366         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7367                         tx_first, "tx_first");
7368 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7369         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7370                         tx_num, UINT32);
7371
7372 cmdline_parse_inst_t cmd_start_tx_first_n = {
7373         .f = cmd_start_tx_first_n_parsed,
7374         .data = NULL,
7375         .help_str = "start tx_first <num>: "
7376                 "packet forwarding, after sending <num> bursts of packets",
7377         .tokens = {
7378                 (void *)&cmd_start_tx_first_n_start,
7379                 (void *)&cmd_start_tx_first_n_tx_first,
7380                 (void *)&cmd_start_tx_first_n_tx_num,
7381                 NULL,
7382         },
7383 };
7384
7385 /* *** SET LINK UP *** */
7386 struct cmd_set_link_up_result {
7387         cmdline_fixed_string_t set;
7388         cmdline_fixed_string_t link_up;
7389         cmdline_fixed_string_t port;
7390         portid_t port_id;
7391 };
7392
7393 cmdline_parse_token_string_t cmd_set_link_up_set =
7394         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7395 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7396         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7397                                 "link-up");
7398 cmdline_parse_token_string_t cmd_set_link_up_port =
7399         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7400 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7401         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7402
7403 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7404                              __rte_unused struct cmdline *cl,
7405                              __rte_unused void *data)
7406 {
7407         struct cmd_set_link_up_result *res = parsed_result;
7408         dev_set_link_up(res->port_id);
7409 }
7410
7411 cmdline_parse_inst_t cmd_set_link_up = {
7412         .f = cmd_set_link_up_parsed,
7413         .data = NULL,
7414         .help_str = "set link-up port <port id>",
7415         .tokens = {
7416                 (void *)&cmd_set_link_up_set,
7417                 (void *)&cmd_set_link_up_link_up,
7418                 (void *)&cmd_set_link_up_port,
7419                 (void *)&cmd_set_link_up_port_id,
7420                 NULL,
7421         },
7422 };
7423
7424 /* *** SET LINK DOWN *** */
7425 struct cmd_set_link_down_result {
7426         cmdline_fixed_string_t set;
7427         cmdline_fixed_string_t link_down;
7428         cmdline_fixed_string_t port;
7429         portid_t port_id;
7430 };
7431
7432 cmdline_parse_token_string_t cmd_set_link_down_set =
7433         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7434 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7435         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7436                                 "link-down");
7437 cmdline_parse_token_string_t cmd_set_link_down_port =
7438         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7439 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7440         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7441
7442 static void cmd_set_link_down_parsed(
7443                                 __rte_unused void *parsed_result,
7444                                 __rte_unused struct cmdline *cl,
7445                                 __rte_unused void *data)
7446 {
7447         struct cmd_set_link_down_result *res = parsed_result;
7448         dev_set_link_down(res->port_id);
7449 }
7450
7451 cmdline_parse_inst_t cmd_set_link_down = {
7452         .f = cmd_set_link_down_parsed,
7453         .data = NULL,
7454         .help_str = "set link-down port <port id>",
7455         .tokens = {
7456                 (void *)&cmd_set_link_down_set,
7457                 (void *)&cmd_set_link_down_link_down,
7458                 (void *)&cmd_set_link_down_port,
7459                 (void *)&cmd_set_link_down_port_id,
7460                 NULL,
7461         },
7462 };
7463
7464 /* *** SHOW CFG *** */
7465 struct cmd_showcfg_result {
7466         cmdline_fixed_string_t show;
7467         cmdline_fixed_string_t cfg;
7468         cmdline_fixed_string_t what;
7469 };
7470
7471 static void cmd_showcfg_parsed(void *parsed_result,
7472                                __rte_unused struct cmdline *cl,
7473                                __rte_unused void *data)
7474 {
7475         struct cmd_showcfg_result *res = parsed_result;
7476         if (!strcmp(res->what, "rxtx"))
7477                 rxtx_config_display();
7478         else if (!strcmp(res->what, "cores"))
7479                 fwd_lcores_config_display();
7480         else if (!strcmp(res->what, "fwd"))
7481                 pkt_fwd_config_display(&cur_fwd_config);
7482         else if (!strcmp(res->what, "txpkts"))
7483                 show_tx_pkt_segments();
7484         else if (!strcmp(res->what, "txtimes"))
7485                 show_tx_pkt_times();
7486 }
7487
7488 cmdline_parse_token_string_t cmd_showcfg_show =
7489         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7490 cmdline_parse_token_string_t cmd_showcfg_port =
7491         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7492 cmdline_parse_token_string_t cmd_showcfg_what =
7493         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7494                                  "rxtx#cores#fwd#txpkts#txtimes");
7495
7496 cmdline_parse_inst_t cmd_showcfg = {
7497         .f = cmd_showcfg_parsed,
7498         .data = NULL,
7499         .help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7500         .tokens = {
7501                 (void *)&cmd_showcfg_show,
7502                 (void *)&cmd_showcfg_port,
7503                 (void *)&cmd_showcfg_what,
7504                 NULL,
7505         },
7506 };
7507
7508 /* *** SHOW ALL PORT INFO *** */
7509 struct cmd_showportall_result {
7510         cmdline_fixed_string_t show;
7511         cmdline_fixed_string_t port;
7512         cmdline_fixed_string_t what;
7513         cmdline_fixed_string_t all;
7514 };
7515
7516 static void cmd_showportall_parsed(void *parsed_result,
7517                                 __rte_unused struct cmdline *cl,
7518                                 __rte_unused void *data)
7519 {
7520         portid_t i;
7521
7522         struct cmd_showportall_result *res = parsed_result;
7523         if (!strcmp(res->show, "clear")) {
7524                 if (!strcmp(res->what, "stats"))
7525                         RTE_ETH_FOREACH_DEV(i)
7526                                 nic_stats_clear(i);
7527                 else if (!strcmp(res->what, "xstats"))
7528                         RTE_ETH_FOREACH_DEV(i)
7529                                 nic_xstats_clear(i);
7530         } else if (!strcmp(res->what, "info"))
7531                 RTE_ETH_FOREACH_DEV(i)
7532                         port_infos_display(i);
7533         else if (!strcmp(res->what, "summary")) {
7534                 port_summary_header_display();
7535                 RTE_ETH_FOREACH_DEV(i)
7536                         port_summary_display(i);
7537         }
7538         else if (!strcmp(res->what, "stats"))
7539                 RTE_ETH_FOREACH_DEV(i)
7540                         nic_stats_display(i);
7541         else if (!strcmp(res->what, "xstats"))
7542                 RTE_ETH_FOREACH_DEV(i)
7543                         nic_xstats_display(i);
7544         else if (!strcmp(res->what, "fdir"))
7545                 RTE_ETH_FOREACH_DEV(i)
7546                         fdir_get_infos(i);
7547         else if (!strcmp(res->what, "stat_qmap"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_stats_mapping_display(i);
7550         else if (!strcmp(res->what, "dcb_tc"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         port_dcb_info_display(i);
7553         else if (!strcmp(res->what, "cap"))
7554                 RTE_ETH_FOREACH_DEV(i)
7555                         port_offload_cap_display(i);
7556 }
7557
7558 cmdline_parse_token_string_t cmd_showportall_show =
7559         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7560                                  "show#clear");
7561 cmdline_parse_token_string_t cmd_showportall_port =
7562         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7563 cmdline_parse_token_string_t cmd_showportall_what =
7564         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7565                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7566 cmdline_parse_token_string_t cmd_showportall_all =
7567         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7568 cmdline_parse_inst_t cmd_showportall = {
7569         .f = cmd_showportall_parsed,
7570         .data = NULL,
7571         .help_str = "show|clear port "
7572                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7573         .tokens = {
7574                 (void *)&cmd_showportall_show,
7575                 (void *)&cmd_showportall_port,
7576                 (void *)&cmd_showportall_what,
7577                 (void *)&cmd_showportall_all,
7578                 NULL,
7579         },
7580 };
7581
7582 /* *** SHOW PORT INFO *** */
7583 struct cmd_showport_result {
7584         cmdline_fixed_string_t show;
7585         cmdline_fixed_string_t port;
7586         cmdline_fixed_string_t what;
7587         uint16_t portnum;
7588 };
7589
7590 static void cmd_showport_parsed(void *parsed_result,
7591                                 __rte_unused struct cmdline *cl,
7592                                 __rte_unused void *data)
7593 {
7594         struct cmd_showport_result *res = parsed_result;
7595         if (!strcmp(res->show, "clear")) {
7596                 if (!strcmp(res->what, "stats"))
7597                         nic_stats_clear(res->portnum);
7598                 else if (!strcmp(res->what, "xstats"))
7599                         nic_xstats_clear(res->portnum);
7600         } else if (!strcmp(res->what, "info"))
7601                 port_infos_display(res->portnum);
7602         else if (!strcmp(res->what, "summary")) {
7603                 port_summary_header_display();
7604                 port_summary_display(res->portnum);
7605         }
7606         else if (!strcmp(res->what, "stats"))
7607                 nic_stats_display(res->portnum);
7608         else if (!strcmp(res->what, "xstats"))
7609                 nic_xstats_display(res->portnum);
7610         else if (!strcmp(res->what, "fdir"))
7611                  fdir_get_infos(res->portnum);
7612         else if (!strcmp(res->what, "stat_qmap"))
7613                 nic_stats_mapping_display(res->portnum);
7614         else if (!strcmp(res->what, "dcb_tc"))
7615                 port_dcb_info_display(res->portnum);
7616         else if (!strcmp(res->what, "cap"))
7617                 port_offload_cap_display(res->portnum);
7618 }
7619
7620 cmdline_parse_token_string_t cmd_showport_show =
7621         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7622                                  "show#clear");
7623 cmdline_parse_token_string_t cmd_showport_port =
7624         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7625 cmdline_parse_token_string_t cmd_showport_what =
7626         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7627                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7628 cmdline_parse_token_num_t cmd_showport_portnum =
7629         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7630
7631 cmdline_parse_inst_t cmd_showport = {
7632         .f = cmd_showport_parsed,
7633         .data = NULL,
7634         .help_str = "show|clear port "
7635                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7636                 "<port_id>",
7637         .tokens = {
7638                 (void *)&cmd_showport_show,
7639                 (void *)&cmd_showport_port,
7640                 (void *)&cmd_showport_what,
7641                 (void *)&cmd_showport_portnum,
7642                 NULL,
7643         },
7644 };
7645
7646 /* *** SHOW DEVICE INFO *** */
7647 struct cmd_showdevice_result {
7648         cmdline_fixed_string_t show;
7649         cmdline_fixed_string_t device;
7650         cmdline_fixed_string_t what;
7651         cmdline_fixed_string_t identifier;
7652 };
7653
7654 static void cmd_showdevice_parsed(void *parsed_result,
7655                                 __rte_unused struct cmdline *cl,
7656                                 __rte_unused void *data)
7657 {
7658         struct cmd_showdevice_result *res = parsed_result;
7659         if (!strcmp(res->what, "info")) {
7660                 if (!strcmp(res->identifier, "all"))
7661                         device_infos_display(NULL);
7662                 else
7663                         device_infos_display(res->identifier);
7664         }
7665 }
7666
7667 cmdline_parse_token_string_t cmd_showdevice_show =
7668         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7669                                  "show");
7670 cmdline_parse_token_string_t cmd_showdevice_device =
7671         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7672 cmdline_parse_token_string_t cmd_showdevice_what =
7673         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7674                                  "info");
7675 cmdline_parse_token_string_t cmd_showdevice_identifier =
7676         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7677                         identifier, NULL);
7678
7679 cmdline_parse_inst_t cmd_showdevice = {
7680         .f = cmd_showdevice_parsed,
7681         .data = NULL,
7682         .help_str = "show device info <identifier>|all",
7683         .tokens = {
7684                 (void *)&cmd_showdevice_show,
7685                 (void *)&cmd_showdevice_device,
7686                 (void *)&cmd_showdevice_what,
7687                 (void *)&cmd_showdevice_identifier,
7688                 NULL,
7689         },
7690 };
7691 /* *** SHOW QUEUE INFO *** */
7692 struct cmd_showqueue_result {
7693         cmdline_fixed_string_t show;
7694         cmdline_fixed_string_t type;
7695         cmdline_fixed_string_t what;
7696         uint16_t portnum;
7697         uint16_t queuenum;
7698 };
7699
7700 static void
7701 cmd_showqueue_parsed(void *parsed_result,
7702         __rte_unused struct cmdline *cl,
7703         __rte_unused void *data)
7704 {
7705         struct cmd_showqueue_result *res = parsed_result;
7706
7707         if (!strcmp(res->type, "rxq"))
7708                 rx_queue_infos_display(res->portnum, res->queuenum);
7709         else if (!strcmp(res->type, "txq"))
7710                 tx_queue_infos_display(res->portnum, res->queuenum);
7711 }
7712
7713 cmdline_parse_token_string_t cmd_showqueue_show =
7714         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7715 cmdline_parse_token_string_t cmd_showqueue_type =
7716         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7717 cmdline_parse_token_string_t cmd_showqueue_what =
7718         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7719 cmdline_parse_token_num_t cmd_showqueue_portnum =
7720         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7721 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7722         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7723
7724 cmdline_parse_inst_t cmd_showqueue = {
7725         .f = cmd_showqueue_parsed,
7726         .data = NULL,
7727         .help_str = "show rxq|txq info <port_id> <queue_id>",
7728         .tokens = {
7729                 (void *)&cmd_showqueue_show,
7730                 (void *)&cmd_showqueue_type,
7731                 (void *)&cmd_showqueue_what,
7732                 (void *)&cmd_showqueue_portnum,
7733                 (void *)&cmd_showqueue_queuenum,
7734                 NULL,
7735         },
7736 };
7737
7738 /* show/clear fwd engine statistics */
7739 struct fwd_result {
7740         cmdline_fixed_string_t action;
7741         cmdline_fixed_string_t fwd;
7742         cmdline_fixed_string_t stats;
7743         cmdline_fixed_string_t all;
7744 };
7745
7746 cmdline_parse_token_string_t cmd_fwd_action =
7747         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7748 cmdline_parse_token_string_t cmd_fwd_fwd =
7749         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7750 cmdline_parse_token_string_t cmd_fwd_stats =
7751         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7752 cmdline_parse_token_string_t cmd_fwd_all =
7753         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7754
7755 static void
7756 cmd_showfwdall_parsed(void *parsed_result,
7757                       __rte_unused struct cmdline *cl,
7758                       __rte_unused void *data)
7759 {
7760         struct fwd_result *res = parsed_result;
7761
7762         if (!strcmp(res->action, "show"))
7763                 fwd_stats_display();
7764         else
7765                 fwd_stats_reset();
7766 }
7767
7768 static cmdline_parse_inst_t cmd_showfwdall = {
7769         .f = cmd_showfwdall_parsed,
7770         .data = NULL,
7771         .help_str = "show|clear fwd stats all",
7772         .tokens = {
7773                 (void *)&cmd_fwd_action,
7774                 (void *)&cmd_fwd_fwd,
7775                 (void *)&cmd_fwd_stats,
7776                 (void *)&cmd_fwd_all,
7777                 NULL,
7778         },
7779 };
7780
7781 /* *** READ PORT REGISTER *** */
7782 struct cmd_read_reg_result {
7783         cmdline_fixed_string_t read;
7784         cmdline_fixed_string_t reg;
7785         portid_t port_id;
7786         uint32_t reg_off;
7787 };
7788
7789 static void
7790 cmd_read_reg_parsed(void *parsed_result,
7791                     __rte_unused struct cmdline *cl,
7792                     __rte_unused void *data)
7793 {
7794         struct cmd_read_reg_result *res = parsed_result;
7795         port_reg_display(res->port_id, res->reg_off);
7796 }
7797
7798 cmdline_parse_token_string_t cmd_read_reg_read =
7799         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7800 cmdline_parse_token_string_t cmd_read_reg_reg =
7801         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7802 cmdline_parse_token_num_t cmd_read_reg_port_id =
7803         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7804 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7805         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7806
7807 cmdline_parse_inst_t cmd_read_reg = {
7808         .f = cmd_read_reg_parsed,
7809         .data = NULL,
7810         .help_str = "read reg <port_id> <reg_off>",
7811         .tokens = {
7812                 (void *)&cmd_read_reg_read,
7813                 (void *)&cmd_read_reg_reg,
7814                 (void *)&cmd_read_reg_port_id,
7815                 (void *)&cmd_read_reg_reg_off,
7816                 NULL,
7817         },
7818 };
7819
7820 /* *** READ PORT REGISTER BIT FIELD *** */
7821 struct cmd_read_reg_bit_field_result {
7822         cmdline_fixed_string_t read;
7823         cmdline_fixed_string_t regfield;
7824         portid_t port_id;
7825         uint32_t reg_off;
7826         uint8_t bit1_pos;
7827         uint8_t bit2_pos;
7828 };
7829
7830 static void
7831 cmd_read_reg_bit_field_parsed(void *parsed_result,
7832                               __rte_unused struct cmdline *cl,
7833                               __rte_unused void *data)
7834 {
7835         struct cmd_read_reg_bit_field_result *res = parsed_result;
7836         port_reg_bit_field_display(res->port_id, res->reg_off,
7837                                    res->bit1_pos, res->bit2_pos);
7838 }
7839
7840 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7841         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7842                                  "read");
7843 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7844         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7845                                  regfield, "regfield");
7846 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7847         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7848                               UINT16);
7849 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7850         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7851                               UINT32);
7852 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7853         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7854                               UINT8);
7855 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7856         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7857                               UINT8);
7858
7859 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7860         .f = cmd_read_reg_bit_field_parsed,
7861         .data = NULL,
7862         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7863         "Read register bit field between bit_x and bit_y included",
7864         .tokens = {
7865                 (void *)&cmd_read_reg_bit_field_read,
7866                 (void *)&cmd_read_reg_bit_field_regfield,
7867                 (void *)&cmd_read_reg_bit_field_port_id,
7868                 (void *)&cmd_read_reg_bit_field_reg_off,
7869                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7870                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7871                 NULL,
7872         },
7873 };
7874
7875 /* *** READ PORT REGISTER BIT *** */
7876 struct cmd_read_reg_bit_result {
7877         cmdline_fixed_string_t read;
7878         cmdline_fixed_string_t regbit;
7879         portid_t port_id;
7880         uint32_t reg_off;
7881         uint8_t bit_pos;
7882 };
7883
7884 static void
7885 cmd_read_reg_bit_parsed(void *parsed_result,
7886                         __rte_unused struct cmdline *cl,
7887                         __rte_unused void *data)
7888 {
7889         struct cmd_read_reg_bit_result *res = parsed_result;
7890         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7891 }
7892
7893 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7894         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7895 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7896         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7897                                  regbit, "regbit");
7898 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7899         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7900 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7901         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7902 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7903         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7904
7905 cmdline_parse_inst_t cmd_read_reg_bit = {
7906         .f = cmd_read_reg_bit_parsed,
7907         .data = NULL,
7908         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7909         .tokens = {
7910                 (void *)&cmd_read_reg_bit_read,
7911                 (void *)&cmd_read_reg_bit_regbit,
7912                 (void *)&cmd_read_reg_bit_port_id,
7913                 (void *)&cmd_read_reg_bit_reg_off,
7914                 (void *)&cmd_read_reg_bit_bit_pos,
7915                 NULL,
7916         },
7917 };
7918
7919 /* *** WRITE PORT REGISTER *** */
7920 struct cmd_write_reg_result {
7921         cmdline_fixed_string_t write;
7922         cmdline_fixed_string_t reg;
7923         portid_t port_id;
7924         uint32_t reg_off;
7925         uint32_t value;
7926 };
7927
7928 static void
7929 cmd_write_reg_parsed(void *parsed_result,
7930                      __rte_unused struct cmdline *cl,
7931                      __rte_unused void *data)
7932 {
7933         struct cmd_write_reg_result *res = parsed_result;
7934         port_reg_set(res->port_id, res->reg_off, res->value);
7935 }
7936
7937 cmdline_parse_token_string_t cmd_write_reg_write =
7938         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7939 cmdline_parse_token_string_t cmd_write_reg_reg =
7940         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7941 cmdline_parse_token_num_t cmd_write_reg_port_id =
7942         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7943 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7944         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7945 cmdline_parse_token_num_t cmd_write_reg_value =
7946         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7947
7948 cmdline_parse_inst_t cmd_write_reg = {
7949         .f = cmd_write_reg_parsed,
7950         .data = NULL,
7951         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7952         .tokens = {
7953                 (void *)&cmd_write_reg_write,
7954                 (void *)&cmd_write_reg_reg,
7955                 (void *)&cmd_write_reg_port_id,
7956                 (void *)&cmd_write_reg_reg_off,
7957                 (void *)&cmd_write_reg_value,
7958                 NULL,
7959         },
7960 };
7961
7962 /* *** WRITE PORT REGISTER BIT FIELD *** */
7963 struct cmd_write_reg_bit_field_result {
7964         cmdline_fixed_string_t write;
7965         cmdline_fixed_string_t regfield;
7966         portid_t port_id;
7967         uint32_t reg_off;
7968         uint8_t bit1_pos;
7969         uint8_t bit2_pos;
7970         uint32_t value;
7971 };
7972
7973 static void
7974 cmd_write_reg_bit_field_parsed(void *parsed_result,
7975                                __rte_unused struct cmdline *cl,
7976                                __rte_unused void *data)
7977 {
7978         struct cmd_write_reg_bit_field_result *res = parsed_result;
7979         port_reg_bit_field_set(res->port_id, res->reg_off,
7980                           res->bit1_pos, res->bit2_pos, res->value);
7981 }
7982
7983 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7984         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7985                                  "write");
7986 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7987         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7988                                  regfield, "regfield");
7989 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7990         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7991                               UINT16);
7992 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
7994                               UINT32);
7995 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
7996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
7997                               UINT8);
7998 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
7999         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8000                               UINT8);
8001 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8002         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8003                               UINT32);
8004
8005 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8006         .f = cmd_write_reg_bit_field_parsed,
8007         .data = NULL,
8008         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8009                 "<reg_value>: "
8010                 "Set register bit field between bit_x and bit_y included",
8011         .tokens = {
8012                 (void *)&cmd_write_reg_bit_field_write,
8013                 (void *)&cmd_write_reg_bit_field_regfield,
8014                 (void *)&cmd_write_reg_bit_field_port_id,
8015                 (void *)&cmd_write_reg_bit_field_reg_off,
8016                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8017                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8018                 (void *)&cmd_write_reg_bit_field_value,
8019                 NULL,
8020         },
8021 };
8022
8023 /* *** WRITE PORT REGISTER BIT *** */
8024 struct cmd_write_reg_bit_result {
8025         cmdline_fixed_string_t write;
8026         cmdline_fixed_string_t regbit;
8027         portid_t port_id;
8028         uint32_t reg_off;
8029         uint8_t bit_pos;
8030         uint8_t value;
8031 };
8032
8033 static void
8034 cmd_write_reg_bit_parsed(void *parsed_result,
8035                          __rte_unused struct cmdline *cl,
8036                          __rte_unused void *data)
8037 {
8038         struct cmd_write_reg_bit_result *res = parsed_result;
8039         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8040 }
8041
8042 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8043         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8044                                  "write");
8045 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8046         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8047                                  regbit, "regbit");
8048 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8049         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8050 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8051         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8052 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8053         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8054 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8056
8057 cmdline_parse_inst_t cmd_write_reg_bit = {
8058         .f = cmd_write_reg_bit_parsed,
8059         .data = NULL,
8060         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8061                 "0 <= bit_x <= 31",
8062         .tokens = {
8063                 (void *)&cmd_write_reg_bit_write,
8064                 (void *)&cmd_write_reg_bit_regbit,
8065                 (void *)&cmd_write_reg_bit_port_id,
8066                 (void *)&cmd_write_reg_bit_reg_off,
8067                 (void *)&cmd_write_reg_bit_bit_pos,
8068                 (void *)&cmd_write_reg_bit_value,
8069                 NULL,
8070         },
8071 };
8072
8073 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8074 struct cmd_read_rxd_txd_result {
8075         cmdline_fixed_string_t read;
8076         cmdline_fixed_string_t rxd_txd;
8077         portid_t port_id;
8078         uint16_t queue_id;
8079         uint16_t desc_id;
8080 };
8081
8082 static void
8083 cmd_read_rxd_txd_parsed(void *parsed_result,
8084                         __rte_unused struct cmdline *cl,
8085                         __rte_unused void *data)
8086 {
8087         struct cmd_read_rxd_txd_result *res = parsed_result;
8088
8089         if (!strcmp(res->rxd_txd, "rxd"))
8090                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8091         else if (!strcmp(res->rxd_txd, "txd"))
8092                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8093 }
8094
8095 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8096         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8097 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8098         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8099                                  "rxd#txd");
8100 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8101         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8102 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8103         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8104 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8105         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8106
8107 cmdline_parse_inst_t cmd_read_rxd_txd = {
8108         .f = cmd_read_rxd_txd_parsed,
8109         .data = NULL,
8110         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8111         .tokens = {
8112                 (void *)&cmd_read_rxd_txd_read,
8113                 (void *)&cmd_read_rxd_txd_rxd_txd,
8114                 (void *)&cmd_read_rxd_txd_port_id,
8115                 (void *)&cmd_read_rxd_txd_queue_id,
8116                 (void *)&cmd_read_rxd_txd_desc_id,
8117                 NULL,
8118         },
8119 };
8120
8121 /* *** QUIT *** */
8122 struct cmd_quit_result {
8123         cmdline_fixed_string_t quit;
8124 };
8125
8126 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8127                             struct cmdline *cl,
8128                             __rte_unused void *data)
8129 {
8130         cmdline_quit(cl);
8131 }
8132
8133 cmdline_parse_token_string_t cmd_quit_quit =
8134         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8135
8136 cmdline_parse_inst_t cmd_quit = {
8137         .f = cmd_quit_parsed,
8138         .data = NULL,
8139         .help_str = "quit: Exit application",
8140         .tokens = {
8141                 (void *)&cmd_quit_quit,
8142                 NULL,
8143         },
8144 };
8145
8146 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8147 struct cmd_mac_addr_result {
8148         cmdline_fixed_string_t mac_addr_cmd;
8149         cmdline_fixed_string_t what;
8150         uint16_t port_num;
8151         struct rte_ether_addr address;
8152 };
8153
8154 static void cmd_mac_addr_parsed(void *parsed_result,
8155                 __rte_unused struct cmdline *cl,
8156                 __rte_unused void *data)
8157 {
8158         struct cmd_mac_addr_result *res = parsed_result;
8159         int ret;
8160
8161         if (strcmp(res->what, "add") == 0)
8162                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8163         else if (strcmp(res->what, "set") == 0)
8164                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8165                                                        &res->address);
8166         else
8167                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8168
8169         /* check the return value and print it if is < 0 */
8170         if(ret < 0)
8171                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8172
8173 }
8174
8175 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8176         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8177                                 "mac_addr");
8178 cmdline_parse_token_string_t cmd_mac_addr_what =
8179         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8180                                 "add#remove#set");
8181 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8182                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8183                                         UINT16);
8184 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8185                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8186
8187 cmdline_parse_inst_t cmd_mac_addr = {
8188         .f = cmd_mac_addr_parsed,
8189         .data = (void *)0,
8190         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8191                         "Add/Remove/Set MAC address on port_id",
8192         .tokens = {
8193                 (void *)&cmd_mac_addr_cmd,
8194                 (void *)&cmd_mac_addr_what,
8195                 (void *)&cmd_mac_addr_portnum,
8196                 (void *)&cmd_mac_addr_addr,
8197                 NULL,
8198         },
8199 };
8200
8201 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8202 struct cmd_eth_peer_result {
8203         cmdline_fixed_string_t set;
8204         cmdline_fixed_string_t eth_peer;
8205         portid_t port_id;
8206         cmdline_fixed_string_t peer_addr;
8207 };
8208
8209 static void cmd_set_eth_peer_parsed(void *parsed_result,
8210                         __rte_unused struct cmdline *cl,
8211                         __rte_unused void *data)
8212 {
8213                 struct cmd_eth_peer_result *res = parsed_result;
8214
8215                 if (test_done == 0) {
8216                         printf("Please stop forwarding first\n");
8217                         return;
8218                 }
8219                 if (!strcmp(res->eth_peer, "eth-peer")) {
8220                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8221                         fwd_config_setup();
8222                 }
8223 }
8224 cmdline_parse_token_string_t cmd_eth_peer_set =
8225         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8226 cmdline_parse_token_string_t cmd_eth_peer =
8227         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8228 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8229         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8230 cmdline_parse_token_string_t cmd_eth_peer_addr =
8231         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8232
8233 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8234         .f = cmd_set_eth_peer_parsed,
8235         .data = NULL,
8236         .help_str = "set eth-peer <port_id> <peer_mac>",
8237         .tokens = {
8238                 (void *)&cmd_eth_peer_set,
8239                 (void *)&cmd_eth_peer,
8240                 (void *)&cmd_eth_peer_port_id,
8241                 (void *)&cmd_eth_peer_addr,
8242                 NULL,
8243         },
8244 };
8245
8246 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8247 struct cmd_set_qmap_result {
8248         cmdline_fixed_string_t set;
8249         cmdline_fixed_string_t qmap;
8250         cmdline_fixed_string_t what;
8251         portid_t port_id;
8252         uint16_t queue_id;
8253         uint8_t map_value;
8254 };
8255
8256 static void
8257 cmd_set_qmap_parsed(void *parsed_result,
8258                        __rte_unused struct cmdline *cl,
8259                        __rte_unused void *data)
8260 {
8261         struct cmd_set_qmap_result *res = parsed_result;
8262         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8263
8264         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8265 }
8266
8267 cmdline_parse_token_string_t cmd_setqmap_set =
8268         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8269                                  set, "set");
8270 cmdline_parse_token_string_t cmd_setqmap_qmap =
8271         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8272                                  qmap, "stat_qmap");
8273 cmdline_parse_token_string_t cmd_setqmap_what =
8274         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8275                                  what, "tx#rx");
8276 cmdline_parse_token_num_t cmd_setqmap_portid =
8277         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8278                               port_id, UINT16);
8279 cmdline_parse_token_num_t cmd_setqmap_queueid =
8280         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8281                               queue_id, UINT16);
8282 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8283         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8284                               map_value, UINT8);
8285
8286 cmdline_parse_inst_t cmd_set_qmap = {
8287         .f = cmd_set_qmap_parsed,
8288         .data = NULL,
8289         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8290                 "Set statistics mapping value on tx|rx queue_id of port_id",
8291         .tokens = {
8292                 (void *)&cmd_setqmap_set,
8293                 (void *)&cmd_setqmap_qmap,
8294                 (void *)&cmd_setqmap_what,
8295                 (void *)&cmd_setqmap_portid,
8296                 (void *)&cmd_setqmap_queueid,
8297                 (void *)&cmd_setqmap_mapvalue,
8298                 NULL,
8299         },
8300 };
8301
8302 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8303 struct cmd_set_xstats_hide_zero_result {
8304         cmdline_fixed_string_t keyword;
8305         cmdline_fixed_string_t name;
8306         cmdline_fixed_string_t on_off;
8307 };
8308
8309 static void
8310 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8311                         __rte_unused struct cmdline *cl,
8312                         __rte_unused void *data)
8313 {
8314         struct cmd_set_xstats_hide_zero_result *res;
8315         uint16_t on_off = 0;
8316
8317         res = parsed_result;
8318         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8319         set_xstats_hide_zero(on_off);
8320 }
8321
8322 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8324                                  keyword, "set");
8325 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8326         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8327                                  name, "xstats-hide-zero");
8328 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8329         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8330                                  on_off, "on#off");
8331
8332 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8333         .f = cmd_set_xstats_hide_zero_parsed,
8334         .data = NULL,
8335         .help_str = "set xstats-hide-zero on|off",
8336         .tokens = {
8337                 (void *)&cmd_set_xstats_hide_zero_keyword,
8338                 (void *)&cmd_set_xstats_hide_zero_name,
8339                 (void *)&cmd_set_xstats_hide_zero_on_off,
8340                 NULL,
8341         },
8342 };
8343
8344 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8345 struct cmd_set_record_core_cycles_result {
8346         cmdline_fixed_string_t keyword;
8347         cmdline_fixed_string_t name;
8348         cmdline_fixed_string_t on_off;
8349 };
8350
8351 static void
8352 cmd_set_record_core_cycles_parsed(void *parsed_result,
8353                         __rte_unused struct cmdline *cl,
8354                         __rte_unused void *data)
8355 {
8356         struct cmd_set_record_core_cycles_result *res;
8357         uint16_t on_off = 0;
8358
8359         res = parsed_result;
8360         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8361         set_record_core_cycles(on_off);
8362 }
8363
8364 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8365         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8366                                  keyword, "set");
8367 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8368         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8369                                  name, "record-core-cycles");
8370 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8371         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8372                                  on_off, "on#off");
8373
8374 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8375         .f = cmd_set_record_core_cycles_parsed,
8376         .data = NULL,
8377         .help_str = "set record-core-cycles on|off",
8378         .tokens = {
8379                 (void *)&cmd_set_record_core_cycles_keyword,
8380                 (void *)&cmd_set_record_core_cycles_name,
8381                 (void *)&cmd_set_record_core_cycles_on_off,
8382                 NULL,
8383         },
8384 };
8385
8386 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8387 struct cmd_set_record_burst_stats_result {
8388         cmdline_fixed_string_t keyword;
8389         cmdline_fixed_string_t name;
8390         cmdline_fixed_string_t on_off;
8391 };
8392
8393 static void
8394 cmd_set_record_burst_stats_parsed(void *parsed_result,
8395                         __rte_unused struct cmdline *cl,
8396                         __rte_unused void *data)
8397 {
8398         struct cmd_set_record_burst_stats_result *res;
8399         uint16_t on_off = 0;
8400
8401         res = parsed_result;
8402         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8403         set_record_burst_stats(on_off);
8404 }
8405
8406 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8407         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8408                                  keyword, "set");
8409 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8410         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8411                                  name, "record-burst-stats");
8412 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8413         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8414                                  on_off, "on#off");
8415
8416 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8417         .f = cmd_set_record_burst_stats_parsed,
8418         .data = NULL,
8419         .help_str = "set record-burst-stats on|off",
8420         .tokens = {
8421                 (void *)&cmd_set_record_burst_stats_keyword,
8422                 (void *)&cmd_set_record_burst_stats_name,
8423                 (void *)&cmd_set_record_burst_stats_on_off,
8424                 NULL,
8425         },
8426 };
8427
8428 /* *** CONFIGURE UNICAST HASH TABLE *** */
8429 struct cmd_set_uc_hash_table {
8430         cmdline_fixed_string_t set;
8431         cmdline_fixed_string_t port;
8432         portid_t port_id;
8433         cmdline_fixed_string_t what;
8434         struct rte_ether_addr address;
8435         cmdline_fixed_string_t mode;
8436 };
8437
8438 static void
8439 cmd_set_uc_hash_parsed(void *parsed_result,
8440                        __rte_unused struct cmdline *cl,
8441                        __rte_unused void *data)
8442 {
8443         int ret=0;
8444         struct cmd_set_uc_hash_table *res = parsed_result;
8445
8446         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8447
8448         if (strcmp(res->what, "uta") == 0)
8449                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8450                                                 &res->address,(uint8_t)is_on);
8451         if (ret < 0)
8452                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8453
8454 }
8455
8456 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8457         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8458                                  set, "set");
8459 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8460         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8461                                  port, "port");
8462 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8463         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8464                               port_id, UINT16);
8465 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8466         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8467                                  what, "uta");
8468 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8469         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8470                                 address);
8471 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8473                                  mode, "on#off");
8474
8475 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8476         .f = cmd_set_uc_hash_parsed,
8477         .data = NULL,
8478         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8479         .tokens = {
8480                 (void *)&cmd_set_uc_hash_set,
8481                 (void *)&cmd_set_uc_hash_port,
8482                 (void *)&cmd_set_uc_hash_portid,
8483                 (void *)&cmd_set_uc_hash_what,
8484                 (void *)&cmd_set_uc_hash_mac,
8485                 (void *)&cmd_set_uc_hash_mode,
8486                 NULL,
8487         },
8488 };
8489
8490 struct cmd_set_uc_all_hash_table {
8491         cmdline_fixed_string_t set;
8492         cmdline_fixed_string_t port;
8493         portid_t port_id;
8494         cmdline_fixed_string_t what;
8495         cmdline_fixed_string_t value;
8496         cmdline_fixed_string_t mode;
8497 };
8498
8499 static void
8500 cmd_set_uc_all_hash_parsed(void *parsed_result,
8501                        __rte_unused struct cmdline *cl,
8502                        __rte_unused void *data)
8503 {
8504         int ret=0;
8505         struct cmd_set_uc_all_hash_table *res = parsed_result;
8506
8507         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8508
8509         if ((strcmp(res->what, "uta") == 0) &&
8510                 (strcmp(res->value, "all") == 0))
8511                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8512         if (ret < 0)
8513                 printf("bad unicast hash table parameter,"
8514                         "return code = %d \n", ret);
8515 }
8516
8517 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8518         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8519                                  set, "set");
8520 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8521         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8522                                  port, "port");
8523 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8524         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8525                               port_id, UINT16);
8526 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8527         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8528                                  what, "uta");
8529 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8530         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8531                                 value,"all");
8532 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8534                                  mode, "on#off");
8535
8536 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8537         .f = cmd_set_uc_all_hash_parsed,
8538         .data = NULL,
8539         .help_str = "set port <port_id> uta all on|off",
8540         .tokens = {
8541                 (void *)&cmd_set_uc_all_hash_set,
8542                 (void *)&cmd_set_uc_all_hash_port,
8543                 (void *)&cmd_set_uc_all_hash_portid,
8544                 (void *)&cmd_set_uc_all_hash_what,
8545                 (void *)&cmd_set_uc_all_hash_value,
8546                 (void *)&cmd_set_uc_all_hash_mode,
8547                 NULL,
8548         },
8549 };
8550
8551 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8552 struct cmd_set_vf_macvlan_filter {
8553         cmdline_fixed_string_t set;
8554         cmdline_fixed_string_t port;
8555         portid_t port_id;
8556         cmdline_fixed_string_t vf;
8557         uint8_t vf_id;
8558         struct rte_ether_addr address;
8559         cmdline_fixed_string_t filter_type;
8560         cmdline_fixed_string_t mode;
8561 };
8562
8563 static void
8564 cmd_set_vf_macvlan_parsed(void *parsed_result,
8565                        __rte_unused struct cmdline *cl,
8566                        __rte_unused void *data)
8567 {
8568         int is_on, ret = 0;
8569         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8570         struct rte_eth_mac_filter filter;
8571
8572         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8573
8574         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8575
8576         /* set VF MAC filter */
8577         filter.is_vf = 1;
8578
8579         /* set VF ID */
8580         filter.dst_id = res->vf_id;
8581
8582         if (!strcmp(res->filter_type, "exact-mac"))
8583                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8584         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8585                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8586         else if (!strcmp(res->filter_type, "hashmac"))
8587                 filter.filter_type = RTE_MAC_HASH_MATCH;
8588         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8589                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8590
8591         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8592
8593         if (is_on)
8594                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8595                                         RTE_ETH_FILTER_MACVLAN,
8596                                         RTE_ETH_FILTER_ADD,
8597                                          &filter);
8598         else
8599                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8600                                         RTE_ETH_FILTER_MACVLAN,
8601                                         RTE_ETH_FILTER_DELETE,
8602                                         &filter);
8603
8604         if (ret < 0)
8605                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8606
8607 }
8608
8609 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8610         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8611                                  set, "set");
8612 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8613         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8614                                  port, "port");
8615 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8616         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8617                               port_id, UINT16);
8618 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8620                                  vf, "vf");
8621 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8622         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8623                                 vf_id, UINT8);
8624 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8625         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8626                                 address);
8627 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8628         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8629                                 filter_type, "exact-mac#exact-mac-vlan"
8630                                 "#hashmac#hashmac-vlan");
8631 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8632         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8633                                  mode, "on#off");
8634
8635 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8636         .f = cmd_set_vf_macvlan_parsed,
8637         .data = NULL,
8638         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8639                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8640                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8641                 "hash match rule: hash match of MAC and exact match of VLAN",
8642         .tokens = {
8643                 (void *)&cmd_set_vf_macvlan_set,
8644                 (void *)&cmd_set_vf_macvlan_port,
8645                 (void *)&cmd_set_vf_macvlan_portid,
8646                 (void *)&cmd_set_vf_macvlan_vf,
8647                 (void *)&cmd_set_vf_macvlan_vf_id,
8648                 (void *)&cmd_set_vf_macvlan_mac,
8649                 (void *)&cmd_set_vf_macvlan_filter_type,
8650                 (void *)&cmd_set_vf_macvlan_mode,
8651                 NULL,
8652         },
8653 };
8654
8655 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8656 struct cmd_set_vf_traffic {
8657         cmdline_fixed_string_t set;
8658         cmdline_fixed_string_t port;
8659         portid_t port_id;
8660         cmdline_fixed_string_t vf;
8661         uint8_t vf_id;
8662         cmdline_fixed_string_t what;
8663         cmdline_fixed_string_t mode;
8664 };
8665
8666 static void
8667 cmd_set_vf_traffic_parsed(void *parsed_result,
8668                        __rte_unused struct cmdline *cl,
8669                        __rte_unused void *data)
8670 {
8671         struct cmd_set_vf_traffic *res = parsed_result;
8672         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8673         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8674
8675         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8676 }
8677
8678 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8679         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8680                                  set, "set");
8681 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8682         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8683                                  port, "port");
8684 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8685         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8686                               port_id, UINT16);
8687 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8688         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8689                                  vf, "vf");
8690 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8691         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8692                               vf_id, UINT8);
8693 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8694         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8695                                  what, "tx#rx");
8696 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8697         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8698                                  mode, "on#off");
8699
8700 cmdline_parse_inst_t cmd_set_vf_traffic = {
8701         .f = cmd_set_vf_traffic_parsed,
8702         .data = NULL,
8703         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8704         .tokens = {
8705                 (void *)&cmd_setvf_traffic_set,
8706                 (void *)&cmd_setvf_traffic_port,
8707                 (void *)&cmd_setvf_traffic_portid,
8708                 (void *)&cmd_setvf_traffic_vf,
8709                 (void *)&cmd_setvf_traffic_vfid,
8710                 (void *)&cmd_setvf_traffic_what,
8711                 (void *)&cmd_setvf_traffic_mode,
8712                 NULL,
8713         },
8714 };
8715
8716 /* *** CONFIGURE VF RECEIVE MODE *** */
8717 struct cmd_set_vf_rxmode {
8718         cmdline_fixed_string_t set;
8719         cmdline_fixed_string_t port;
8720         portid_t port_id;
8721         cmdline_fixed_string_t vf;
8722         uint8_t vf_id;
8723         cmdline_fixed_string_t what;
8724         cmdline_fixed_string_t mode;
8725         cmdline_fixed_string_t on;
8726 };
8727
8728 static void
8729 cmd_set_vf_rxmode_parsed(void *parsed_result,
8730                        __rte_unused struct cmdline *cl,
8731                        __rte_unused void *data)
8732 {
8733         int ret = -ENOTSUP;
8734         uint16_t vf_rxmode = 0;
8735         struct cmd_set_vf_rxmode *res = parsed_result;
8736
8737         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8738         if (!strcmp(res->what,"rxmode")) {
8739                 if (!strcmp(res->mode, "AUPE"))
8740                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8741                 else if (!strcmp(res->mode, "ROPE"))
8742                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8743                 else if (!strcmp(res->mode, "BAM"))
8744                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8745                 else if (!strncmp(res->mode, "MPE",3))
8746                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8747         }
8748
8749         RTE_SET_USED(is_on);
8750
8751 #ifdef RTE_LIBRTE_IXGBE_PMD
8752         if (ret == -ENOTSUP)
8753                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8754                                                   vf_rxmode, (uint8_t)is_on);
8755 #endif
8756 #ifdef RTE_LIBRTE_BNXT_PMD
8757         if (ret == -ENOTSUP)
8758                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8759                                                  vf_rxmode, (uint8_t)is_on);
8760 #endif
8761         if (ret < 0)
8762                 printf("bad VF receive mode parameter, return code = %d \n",
8763                 ret);
8764 }
8765
8766 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8767         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8768                                  set, "set");
8769 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8770         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8771                                  port, "port");
8772 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8773         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8774                               port_id, UINT16);
8775 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8777                                  vf, "vf");
8778 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8779         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8780                               vf_id, UINT8);
8781 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8782         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8783                                  what, "rxmode");
8784 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8785         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8786                                  mode, "AUPE#ROPE#BAM#MPE");
8787 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8788         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8789                                  on, "on#off");
8790
8791 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8792         .f = cmd_set_vf_rxmode_parsed,
8793         .data = NULL,
8794         .help_str = "set port <port_id> vf <vf_id> rxmode "
8795                 "AUPE|ROPE|BAM|MPE on|off",
8796         .tokens = {
8797                 (void *)&cmd_set_vf_rxmode_set,
8798                 (void *)&cmd_set_vf_rxmode_port,
8799                 (void *)&cmd_set_vf_rxmode_portid,
8800                 (void *)&cmd_set_vf_rxmode_vf,
8801                 (void *)&cmd_set_vf_rxmode_vfid,
8802                 (void *)&cmd_set_vf_rxmode_what,
8803                 (void *)&cmd_set_vf_rxmode_mode,
8804                 (void *)&cmd_set_vf_rxmode_on,
8805                 NULL,
8806         },
8807 };
8808
8809 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8810 struct cmd_vf_mac_addr_result {
8811         cmdline_fixed_string_t mac_addr_cmd;
8812         cmdline_fixed_string_t what;
8813         cmdline_fixed_string_t port;
8814         uint16_t port_num;
8815         cmdline_fixed_string_t vf;
8816         uint8_t vf_num;
8817         struct rte_ether_addr address;
8818 };
8819
8820 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8821                 __rte_unused struct cmdline *cl,
8822                 __rte_unused void *data)
8823 {
8824         struct cmd_vf_mac_addr_result *res = parsed_result;
8825         int ret = -ENOTSUP;
8826
8827         if (strcmp(res->what, "add") != 0)
8828                 return;
8829
8830 #ifdef RTE_LIBRTE_I40E_PMD
8831         if (ret == -ENOTSUP)
8832                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8833                                                    &res->address);
8834 #endif
8835 #ifdef RTE_LIBRTE_BNXT_PMD
8836         if (ret == -ENOTSUP)
8837                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8838                                                 res->vf_num);
8839 #endif
8840
8841         if(ret < 0)
8842                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8843
8844 }
8845
8846 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8847         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8848                                 mac_addr_cmd,"mac_addr");
8849 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8850         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8851                                 what,"add");
8852 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8853         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8854                                 port,"port");
8855 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8856         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8857                                 port_num, UINT16);
8858 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8859         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8860                                 vf,"vf");
8861 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8862         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8863                                 vf_num, UINT8);
8864 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8865         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8866                                 address);
8867
8868 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8869         .f = cmd_vf_mac_addr_parsed,
8870         .data = (void *)0,
8871         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8872                 "Add MAC address filtering for a VF on port_id",
8873         .tokens = {
8874                 (void *)&cmd_vf_mac_addr_cmd,
8875                 (void *)&cmd_vf_mac_addr_what,
8876                 (void *)&cmd_vf_mac_addr_port,
8877                 (void *)&cmd_vf_mac_addr_portnum,
8878                 (void *)&cmd_vf_mac_addr_vf,
8879                 (void *)&cmd_vf_mac_addr_vfnum,
8880                 (void *)&cmd_vf_mac_addr_addr,
8881                 NULL,
8882         },
8883 };
8884
8885 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8886 struct cmd_vf_rx_vlan_filter {
8887         cmdline_fixed_string_t rx_vlan;
8888         cmdline_fixed_string_t what;
8889         uint16_t vlan_id;
8890         cmdline_fixed_string_t port;
8891         portid_t port_id;
8892         cmdline_fixed_string_t vf;
8893         uint64_t vf_mask;
8894 };
8895
8896 static void
8897 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8898                           __rte_unused struct cmdline *cl,
8899                           __rte_unused void *data)
8900 {
8901         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8902         int ret = -ENOTSUP;
8903
8904         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8905
8906 #ifdef RTE_LIBRTE_IXGBE_PMD
8907         if (ret == -ENOTSUP)
8908                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8909                                 res->vlan_id, res->vf_mask, is_add);
8910 #endif
8911 #ifdef RTE_LIBRTE_I40E_PMD
8912         if (ret == -ENOTSUP)
8913                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8914                                 res->vlan_id, res->vf_mask, is_add);
8915 #endif
8916 #ifdef RTE_LIBRTE_BNXT_PMD
8917         if (ret == -ENOTSUP)
8918                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8919                                 res->vlan_id, res->vf_mask, is_add);
8920 #endif
8921
8922         switch (ret) {
8923         case 0:
8924                 break;
8925         case -EINVAL:
8926                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8927                                 res->vlan_id, res->vf_mask);
8928                 break;
8929         case -ENODEV:
8930                 printf("invalid port_id %d\n", res->port_id);
8931                 break;
8932         case -ENOTSUP:
8933                 printf("function not implemented or supported\n");
8934                 break;
8935         default:
8936                 printf("programming error: (%s)\n", strerror(-ret));
8937         }
8938 }
8939
8940 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8941         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8942                                  rx_vlan, "rx_vlan");
8943 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8944         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8945                                  what, "add#rm");
8946 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8947         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8948                               vlan_id, UINT16);
8949 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8950         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8951                                  port, "port");
8952 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8953         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8954                               port_id, UINT16);
8955 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8956         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8957                                  vf, "vf");
8958 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8959         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8960                               vf_mask, UINT64);
8961
8962 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8963         .f = cmd_vf_rx_vlan_filter_parsed,
8964         .data = NULL,
8965         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8966                 "(vf_mask = hexadecimal VF mask)",
8967         .tokens = {
8968                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8969                 (void *)&cmd_vf_rx_vlan_filter_what,
8970                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8971                 (void *)&cmd_vf_rx_vlan_filter_port,
8972                 (void *)&cmd_vf_rx_vlan_filter_portid,
8973                 (void *)&cmd_vf_rx_vlan_filter_vf,
8974                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8975                 NULL,
8976         },
8977 };
8978
8979 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8980 struct cmd_queue_rate_limit_result {
8981         cmdline_fixed_string_t set;
8982         cmdline_fixed_string_t port;
8983         uint16_t port_num;
8984         cmdline_fixed_string_t queue;
8985         uint8_t queue_num;
8986         cmdline_fixed_string_t rate;
8987         uint16_t rate_num;
8988 };
8989
8990 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8991                 __rte_unused struct cmdline *cl,
8992                 __rte_unused void *data)
8993 {
8994         struct cmd_queue_rate_limit_result *res = parsed_result;
8995         int ret = 0;
8996
8997         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
8998                 && (strcmp(res->queue, "queue") == 0)
8999                 && (strcmp(res->rate, "rate") == 0))
9000                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9001                                         res->rate_num);
9002         if (ret < 0)
9003                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9004
9005 }
9006
9007 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9008         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9009                                 set, "set");
9010 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9011         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9012                                 port, "port");
9013 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9014         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9015                                 port_num, UINT16);
9016 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9017         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9018                                 queue, "queue");
9019 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9020         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9021                                 queue_num, UINT8);
9022 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9023         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9024                                 rate, "rate");
9025 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9026         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9027                                 rate_num, UINT16);
9028
9029 cmdline_parse_inst_t cmd_queue_rate_limit = {
9030         .f = cmd_queue_rate_limit_parsed,
9031         .data = (void *)0,
9032         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9033                 "Set rate limit for a queue on port_id",
9034         .tokens = {
9035                 (void *)&cmd_queue_rate_limit_set,
9036                 (void *)&cmd_queue_rate_limit_port,
9037                 (void *)&cmd_queue_rate_limit_portnum,
9038                 (void *)&cmd_queue_rate_limit_queue,
9039                 (void *)&cmd_queue_rate_limit_queuenum,
9040                 (void *)&cmd_queue_rate_limit_rate,
9041                 (void *)&cmd_queue_rate_limit_ratenum,
9042                 NULL,
9043         },
9044 };
9045
9046 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9047 struct cmd_vf_rate_limit_result {
9048         cmdline_fixed_string_t set;
9049         cmdline_fixed_string_t port;
9050         uint16_t port_num;
9051         cmdline_fixed_string_t vf;
9052         uint8_t vf_num;
9053         cmdline_fixed_string_t rate;
9054         uint16_t rate_num;
9055         cmdline_fixed_string_t q_msk;
9056         uint64_t q_msk_val;
9057 };
9058
9059 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9060                 __rte_unused struct cmdline *cl,
9061                 __rte_unused void *data)
9062 {
9063         struct cmd_vf_rate_limit_result *res = parsed_result;
9064         int ret = 0;
9065
9066         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9067                 && (strcmp(res->vf, "vf") == 0)
9068                 && (strcmp(res->rate, "rate") == 0)
9069                 && (strcmp(res->q_msk, "queue_mask") == 0))
9070                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9071                                         res->rate_num, res->q_msk_val);
9072         if (ret < 0)
9073                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9074
9075 }
9076
9077 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9078         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9079                                 set, "set");
9080 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9081         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9082                                 port, "port");
9083 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9084         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9085                                 port_num, UINT16);
9086 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9087         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9088                                 vf, "vf");
9089 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9090         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9091                                 vf_num, UINT8);
9092 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9093         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9094                                 rate, "rate");
9095 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9096         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9097                                 rate_num, UINT16);
9098 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9099         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9100                                 q_msk, "queue_mask");
9101 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9102         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9103                                 q_msk_val, UINT64);
9104
9105 cmdline_parse_inst_t cmd_vf_rate_limit = {
9106         .f = cmd_vf_rate_limit_parsed,
9107         .data = (void *)0,
9108         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9109                 "queue_mask <queue_mask_value>: "
9110                 "Set rate limit for queues of VF on port_id",
9111         .tokens = {
9112                 (void *)&cmd_vf_rate_limit_set,
9113                 (void *)&cmd_vf_rate_limit_port,
9114                 (void *)&cmd_vf_rate_limit_portnum,
9115                 (void *)&cmd_vf_rate_limit_vf,
9116                 (void *)&cmd_vf_rate_limit_vfnum,
9117                 (void *)&cmd_vf_rate_limit_rate,
9118                 (void *)&cmd_vf_rate_limit_ratenum,
9119                 (void *)&cmd_vf_rate_limit_q_msk,
9120                 (void *)&cmd_vf_rate_limit_q_msk_val,
9121                 NULL,
9122         },
9123 };
9124
9125 /* *** ADD TUNNEL FILTER OF A PORT *** */
9126 struct cmd_tunnel_filter_result {
9127         cmdline_fixed_string_t cmd;
9128         cmdline_fixed_string_t what;
9129         portid_t port_id;
9130         struct rte_ether_addr outer_mac;
9131         struct rte_ether_addr inner_mac;
9132         cmdline_ipaddr_t ip_value;
9133         uint16_t inner_vlan;
9134         cmdline_fixed_string_t tunnel_type;
9135         cmdline_fixed_string_t filter_type;
9136         uint32_t tenant_id;
9137         uint16_t queue_num;
9138 };
9139
9140 static void
9141 cmd_tunnel_filter_parsed(void *parsed_result,
9142                           __rte_unused struct cmdline *cl,
9143                           __rte_unused void *data)
9144 {
9145         struct cmd_tunnel_filter_result *res = parsed_result;
9146         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9147         int ret = 0;
9148
9149         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9150
9151         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9152         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9153         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9154
9155         if (res->ip_value.family == AF_INET) {
9156                 tunnel_filter_conf.ip_addr.ipv4_addr =
9157                         res->ip_value.addr.ipv4.s_addr;
9158                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9159         } else {
9160                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9161                         &(res->ip_value.addr.ipv6),
9162                         sizeof(struct in6_addr));
9163                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9164         }
9165
9166         if (!strcmp(res->filter_type, "imac-ivlan"))
9167                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9168         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9169                 tunnel_filter_conf.filter_type =
9170                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9171         else if (!strcmp(res->filter_type, "imac-tenid"))
9172                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9173         else if (!strcmp(res->filter_type, "imac"))
9174                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9175         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9176                 tunnel_filter_conf.filter_type =
9177                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9178         else if (!strcmp(res->filter_type, "oip"))
9179                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9180         else if (!strcmp(res->filter_type, "iip"))
9181                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9182         else {
9183                 printf("The filter type is not supported");
9184                 return;
9185         }
9186
9187         if (!strcmp(res->tunnel_type, "vxlan"))
9188                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9189         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9190                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9191         else if (!strcmp(res->tunnel_type, "nvgre"))
9192                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9193         else if (!strcmp(res->tunnel_type, "ipingre"))
9194                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9195         else {
9196                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9197                 return;
9198         }
9199
9200         tunnel_filter_conf.tenant_id = res->tenant_id;
9201         tunnel_filter_conf.queue_id = res->queue_num;
9202         if (!strcmp(res->what, "add"))
9203                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9204                                         RTE_ETH_FILTER_TUNNEL,
9205                                         RTE_ETH_FILTER_ADD,
9206                                         &tunnel_filter_conf);
9207         else
9208                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9209                                         RTE_ETH_FILTER_TUNNEL,
9210                                         RTE_ETH_FILTER_DELETE,
9211                                         &tunnel_filter_conf);
9212         if (ret < 0)
9213                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9214                                 strerror(-ret));
9215
9216 }
9217 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9218         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9219         cmd, "tunnel_filter");
9220 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9221         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9222         what, "add#rm");
9223 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9224         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9225         port_id, UINT16);
9226 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9227         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9228         outer_mac);
9229 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9230         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9231         inner_mac);
9232 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9233         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9234         inner_vlan, UINT16);
9235 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9236         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9237         ip_value);
9238 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9239         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9240         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9241
9242 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9243         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9244         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9245                 "imac#omac-imac-tenid");
9246 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9247         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9248         tenant_id, UINT32);
9249 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9250         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9251         queue_num, UINT16);
9252
9253 cmdline_parse_inst_t cmd_tunnel_filter = {
9254         .f = cmd_tunnel_filter_parsed,
9255         .data = (void *)0,
9256         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9257                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9258                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9259                 "<queue_id>: Add/Rm tunnel filter of a port",
9260         .tokens = {
9261                 (void *)&cmd_tunnel_filter_cmd,
9262                 (void *)&cmd_tunnel_filter_what,
9263                 (void *)&cmd_tunnel_filter_port_id,
9264                 (void *)&cmd_tunnel_filter_outer_mac,
9265                 (void *)&cmd_tunnel_filter_inner_mac,
9266                 (void *)&cmd_tunnel_filter_ip_value,
9267                 (void *)&cmd_tunnel_filter_innner_vlan,
9268                 (void *)&cmd_tunnel_filter_tunnel_type,
9269                 (void *)&cmd_tunnel_filter_filter_type,
9270                 (void *)&cmd_tunnel_filter_tenant_id,
9271                 (void *)&cmd_tunnel_filter_queue_num,
9272                 NULL,
9273         },
9274 };
9275
9276 /* *** CONFIGURE TUNNEL UDP PORT *** */
9277 struct cmd_tunnel_udp_config {
9278         cmdline_fixed_string_t cmd;
9279         cmdline_fixed_string_t what;
9280         uint16_t udp_port;
9281         portid_t port_id;
9282 };
9283
9284 static void
9285 cmd_tunnel_udp_config_parsed(void *parsed_result,
9286                           __rte_unused struct cmdline *cl,
9287                           __rte_unused void *data)
9288 {
9289         struct cmd_tunnel_udp_config *res = parsed_result;
9290         struct rte_eth_udp_tunnel tunnel_udp;
9291         int ret;
9292
9293         tunnel_udp.udp_port = res->udp_port;
9294
9295         if (!strcmp(res->cmd, "rx_vxlan_port"))
9296                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9297
9298         if (!strcmp(res->what, "add"))
9299                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9300                                                       &tunnel_udp);
9301         else
9302                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9303                                                          &tunnel_udp);
9304
9305         if (ret < 0)
9306                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9307 }
9308
9309 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9310         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9311                                 cmd, "rx_vxlan_port");
9312 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9313         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9314                                 what, "add#rm");
9315 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9316         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9317                                 udp_port, UINT16);
9318 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9319         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9320                                 port_id, UINT16);
9321
9322 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9323         .f = cmd_tunnel_udp_config_parsed,
9324         .data = (void *)0,
9325         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9326                 "Add/Remove a tunneling UDP port filter",
9327         .tokens = {
9328                 (void *)&cmd_tunnel_udp_config_cmd,
9329                 (void *)&cmd_tunnel_udp_config_what,
9330                 (void *)&cmd_tunnel_udp_config_udp_port,
9331                 (void *)&cmd_tunnel_udp_config_port_id,
9332                 NULL,
9333         },
9334 };
9335
9336 struct cmd_config_tunnel_udp_port {
9337         cmdline_fixed_string_t port;
9338         cmdline_fixed_string_t config;
9339         portid_t port_id;
9340         cmdline_fixed_string_t udp_tunnel_port;
9341         cmdline_fixed_string_t action;
9342         cmdline_fixed_string_t tunnel_type;
9343         uint16_t udp_port;
9344 };
9345
9346 static void
9347 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9348                                __rte_unused struct cmdline *cl,
9349                                __rte_unused void *data)
9350 {
9351         struct cmd_config_tunnel_udp_port *res = parsed_result;
9352         struct rte_eth_udp_tunnel tunnel_udp;
9353         int ret = 0;
9354
9355         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9356                 return;
9357
9358         tunnel_udp.udp_port = res->udp_port;
9359
9360         if (!strcmp(res->tunnel_type, "vxlan")) {
9361                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9362         } else if (!strcmp(res->tunnel_type, "geneve")) {
9363                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9364         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9365                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9366         } else {
9367                 printf("Invalid tunnel type\n");
9368                 return;
9369         }
9370
9371         if (!strcmp(res->action, "add"))
9372                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9373                                                       &tunnel_udp);
9374         else
9375                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9376                                                          &tunnel_udp);
9377
9378         if (ret < 0)
9379                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9380 }
9381
9382 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9383         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9384                                  "port");
9385 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9386         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9387                                  "config");
9388 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9389         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9390                               UINT16);
9391 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9392         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9393                                  udp_tunnel_port,
9394                                  "udp_tunnel_port");
9395 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9396         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9397                                  "add#rm");
9398 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9399         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9400                                  "vxlan#geneve#vxlan-gpe");
9401 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9402         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9403                               UINT16);
9404
9405 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9406         .f = cmd_cfg_tunnel_udp_port_parsed,
9407         .data = NULL,
9408         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9409         .tokens = {
9410                 (void *)&cmd_config_tunnel_udp_port_port,
9411                 (void *)&cmd_config_tunnel_udp_port_config,
9412                 (void *)&cmd_config_tunnel_udp_port_port_id,
9413                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9414                 (void *)&cmd_config_tunnel_udp_port_action,
9415                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9416                 (void *)&cmd_config_tunnel_udp_port_value,
9417                 NULL,
9418         },
9419 };
9420
9421 /* *** GLOBAL CONFIG *** */
9422 struct cmd_global_config_result {
9423         cmdline_fixed_string_t cmd;
9424         portid_t port_id;
9425         cmdline_fixed_string_t cfg_type;
9426         uint8_t len;
9427 };
9428
9429 static void
9430 cmd_global_config_parsed(void *parsed_result,
9431                          __rte_unused struct cmdline *cl,
9432                          __rte_unused void *data)
9433 {
9434         struct cmd_global_config_result *res = parsed_result;
9435         struct rte_eth_global_cfg conf;
9436         int ret;
9437
9438         memset(&conf, 0, sizeof(conf));
9439         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9440         conf.cfg.gre_key_len = res->len;
9441         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9442                                       RTE_ETH_FILTER_SET, &conf);
9443 #ifdef RTE_LIBRTE_I40E_PMD
9444         if (ret == -ENOTSUP)
9445                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9446 #endif
9447         if (ret != 0)
9448                 printf("Global config error\n");
9449 }
9450
9451 cmdline_parse_token_string_t cmd_global_config_cmd =
9452         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9453                 "global_config");
9454 cmdline_parse_token_num_t cmd_global_config_port_id =
9455         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9456                                UINT16);
9457 cmdline_parse_token_string_t cmd_global_config_type =
9458         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9459                 cfg_type, "gre-key-len");
9460 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9461         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9462                 len, UINT8);
9463
9464 cmdline_parse_inst_t cmd_global_config = {
9465         .f = cmd_global_config_parsed,
9466         .data = (void *)NULL,
9467         .help_str = "global_config <port_id> gre-key-len <key_len>",
9468         .tokens = {
9469                 (void *)&cmd_global_config_cmd,
9470                 (void *)&cmd_global_config_port_id,
9471                 (void *)&cmd_global_config_type,
9472                 (void *)&cmd_global_config_gre_key_len,
9473                 NULL,
9474         },
9475 };
9476
9477 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9478 struct cmd_set_mirror_mask_result {
9479         cmdline_fixed_string_t set;
9480         cmdline_fixed_string_t port;
9481         portid_t port_id;
9482         cmdline_fixed_string_t mirror;
9483         uint8_t rule_id;
9484         cmdline_fixed_string_t what;
9485         cmdline_fixed_string_t value;
9486         cmdline_fixed_string_t dstpool;
9487         uint8_t dstpool_id;
9488         cmdline_fixed_string_t on;
9489 };
9490
9491 cmdline_parse_token_string_t cmd_mirror_mask_set =
9492         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9493                                 set, "set");
9494 cmdline_parse_token_string_t cmd_mirror_mask_port =
9495         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9496                                 port, "port");
9497 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9498         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9499                                 port_id, UINT16);
9500 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9501         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9502                                 mirror, "mirror-rule");
9503 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9504         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9505                                 rule_id, UINT8);
9506 cmdline_parse_token_string_t cmd_mirror_mask_what =
9507         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9508                                 what, "pool-mirror-up#pool-mirror-down"
9509                                       "#vlan-mirror");
9510 cmdline_parse_token_string_t cmd_mirror_mask_value =
9511         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9512                                 value, NULL);
9513 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9514         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9515                                 dstpool, "dst-pool");
9516 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9517         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9518                                 dstpool_id, UINT8);
9519 cmdline_parse_token_string_t cmd_mirror_mask_on =
9520         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9521                                 on, "on#off");
9522
9523 static void
9524 cmd_set_mirror_mask_parsed(void *parsed_result,
9525                        __rte_unused struct cmdline *cl,
9526                        __rte_unused void *data)
9527 {
9528         int ret,nb_item,i;
9529         struct cmd_set_mirror_mask_result *res = parsed_result;
9530         struct rte_eth_mirror_conf mr_conf;
9531
9532         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9533
9534         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9535
9536         mr_conf.dst_pool = res->dstpool_id;
9537
9538         if (!strcmp(res->what, "pool-mirror-up")) {
9539                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9540                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9541         } else if (!strcmp(res->what, "pool-mirror-down")) {
9542                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9543                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9544         } else if (!strcmp(res->what, "vlan-mirror")) {
9545                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9546                 nb_item = parse_item_list(res->value, "vlan",
9547                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9548                 if (nb_item <= 0)
9549                         return;
9550
9551                 for (i = 0; i < nb_item; i++) {
9552                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9553                                 printf("Invalid vlan_id: must be < 4096\n");
9554                                 return;
9555                         }
9556
9557                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9558                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9559                 }
9560         }
9561
9562         if (!strcmp(res->on, "on"))
9563                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9564                                                 res->rule_id, 1);
9565         else
9566                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9567                                                 res->rule_id, 0);
9568         if (ret < 0)
9569                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9570 }
9571
9572 cmdline_parse_inst_t cmd_set_mirror_mask = {
9573                 .f = cmd_set_mirror_mask_parsed,
9574                 .data = NULL,
9575                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9576                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9577                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9578                 .tokens = {
9579                         (void *)&cmd_mirror_mask_set,
9580                         (void *)&cmd_mirror_mask_port,
9581                         (void *)&cmd_mirror_mask_portid,
9582                         (void *)&cmd_mirror_mask_mirror,
9583                         (void *)&cmd_mirror_mask_ruleid,
9584                         (void *)&cmd_mirror_mask_what,
9585                         (void *)&cmd_mirror_mask_value,
9586                         (void *)&cmd_mirror_mask_dstpool,
9587                         (void *)&cmd_mirror_mask_poolid,
9588                         (void *)&cmd_mirror_mask_on,
9589                         NULL,
9590                 },
9591 };
9592
9593 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9594 struct cmd_set_mirror_link_result {
9595         cmdline_fixed_string_t set;
9596         cmdline_fixed_string_t port;
9597         portid_t port_id;
9598         cmdline_fixed_string_t mirror;
9599         uint8_t rule_id;
9600         cmdline_fixed_string_t what;
9601         cmdline_fixed_string_t dstpool;
9602         uint8_t dstpool_id;
9603         cmdline_fixed_string_t on;
9604 };
9605
9606 cmdline_parse_token_string_t cmd_mirror_link_set =
9607         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9608                                  set, "set");
9609 cmdline_parse_token_string_t cmd_mirror_link_port =
9610         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9611                                 port, "port");
9612 cmdline_parse_token_num_t cmd_mirror_link_portid =
9613         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9614                                 port_id, UINT16);
9615 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9616         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9617                                 mirror, "mirror-rule");
9618 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9619         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9620                             rule_id, UINT8);
9621 cmdline_parse_token_string_t cmd_mirror_link_what =
9622         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9623                                 what, "uplink-mirror#downlink-mirror");
9624 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9625         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9626                                 dstpool, "dst-pool");
9627 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9628         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9629                                 dstpool_id, UINT8);
9630 cmdline_parse_token_string_t cmd_mirror_link_on =
9631         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9632                                 on, "on#off");
9633
9634 static void
9635 cmd_set_mirror_link_parsed(void *parsed_result,
9636                        __rte_unused struct cmdline *cl,
9637                        __rte_unused void *data)
9638 {
9639         int ret;
9640         struct cmd_set_mirror_link_result *res = parsed_result;
9641         struct rte_eth_mirror_conf mr_conf;
9642
9643         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9644         if (!strcmp(res->what, "uplink-mirror"))
9645                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9646         else
9647                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9648
9649         mr_conf.dst_pool = res->dstpool_id;
9650
9651         if (!strcmp(res->on, "on"))
9652                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9653                                                 res->rule_id, 1);
9654         else
9655                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9656                                                 res->rule_id, 0);
9657
9658         /* check the return value and print it if is < 0 */
9659         if (ret < 0)
9660                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9661
9662 }
9663
9664 cmdline_parse_inst_t cmd_set_mirror_link = {
9665                 .f = cmd_set_mirror_link_parsed,
9666                 .data = NULL,
9667                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9668                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9669                 .tokens = {
9670                         (void *)&cmd_mirror_link_set,
9671                         (void *)&cmd_mirror_link_port,
9672                         (void *)&cmd_mirror_link_portid,
9673                         (void *)&cmd_mirror_link_mirror,
9674                         (void *)&cmd_mirror_link_ruleid,
9675                         (void *)&cmd_mirror_link_what,
9676                         (void *)&cmd_mirror_link_dstpool,
9677                         (void *)&cmd_mirror_link_poolid,
9678                         (void *)&cmd_mirror_link_on,
9679                         NULL,
9680                 },
9681 };
9682
9683 /* *** RESET VM MIRROR RULE *** */
9684 struct cmd_rm_mirror_rule_result {
9685         cmdline_fixed_string_t reset;
9686         cmdline_fixed_string_t port;
9687         portid_t port_id;
9688         cmdline_fixed_string_t mirror;
9689         uint8_t rule_id;
9690 };
9691
9692 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9693         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9694                                  reset, "reset");
9695 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9696         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9697                                 port, "port");
9698 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9699         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9700                                 port_id, UINT16);
9701 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9702         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9703                                 mirror, "mirror-rule");
9704 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9705         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9706                                 rule_id, UINT8);
9707
9708 static void
9709 cmd_reset_mirror_rule_parsed(void *parsed_result,
9710                        __rte_unused struct cmdline *cl,
9711                        __rte_unused void *data)
9712 {
9713         int ret;
9714         struct cmd_set_mirror_link_result *res = parsed_result;
9715         /* check rule_id */
9716         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9717         if(ret < 0)
9718                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9719 }
9720
9721 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9722                 .f = cmd_reset_mirror_rule_parsed,
9723                 .data = NULL,
9724                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9725                 .tokens = {
9726                         (void *)&cmd_rm_mirror_rule_reset,
9727                         (void *)&cmd_rm_mirror_rule_port,
9728                         (void *)&cmd_rm_mirror_rule_portid,
9729                         (void *)&cmd_rm_mirror_rule_mirror,
9730                         (void *)&cmd_rm_mirror_rule_ruleid,
9731                         NULL,
9732                 },
9733 };
9734
9735 /* ******************************************************************************** */
9736
9737 struct cmd_dump_result {
9738         cmdline_fixed_string_t dump;
9739 };
9740
9741 static void
9742 dump_struct_sizes(void)
9743 {
9744 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9745         DUMP_SIZE(struct rte_mbuf);
9746         DUMP_SIZE(struct rte_mempool);
9747         DUMP_SIZE(struct rte_ring);
9748 #undef DUMP_SIZE
9749 }
9750
9751
9752 /* Dump the socket memory statistics on console */
9753 static void
9754 dump_socket_mem(FILE *f)
9755 {
9756         struct rte_malloc_socket_stats socket_stats;
9757         unsigned int i;
9758         size_t total = 0;
9759         size_t alloc = 0;
9760         size_t free = 0;
9761         unsigned int n_alloc = 0;
9762         unsigned int n_free = 0;
9763         static size_t last_allocs;
9764         static size_t last_total;
9765
9766
9767         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9768                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9769                     !socket_stats.heap_totalsz_bytes)
9770                         continue;
9771                 total += socket_stats.heap_totalsz_bytes;
9772                 alloc += socket_stats.heap_allocsz_bytes;
9773                 free += socket_stats.heap_freesz_bytes;
9774                 n_alloc += socket_stats.alloc_count;
9775                 n_free += socket_stats.free_count;
9776                 fprintf(f,
9777                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9778                         i,
9779                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9780                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9781                         (double)socket_stats.heap_allocsz_bytes * 100 /
9782                         (double)socket_stats.heap_totalsz_bytes,
9783                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9784                         socket_stats.alloc_count,
9785                         socket_stats.free_count);
9786         }
9787         fprintf(f,
9788                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9789                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9790                 (double)alloc * 100 / (double)total,
9791                 (double)free / (1024 * 1024),
9792                 n_alloc, n_free);
9793         if (last_allocs)
9794                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9795                         ((double)total - (double)last_total) / (1024 * 1024),
9796                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9797         last_allocs = alloc;
9798         last_total = total;
9799 }
9800
9801 static void cmd_dump_parsed(void *parsed_result,
9802                             __rte_unused struct cmdline *cl,
9803                             __rte_unused void *data)
9804 {
9805         struct cmd_dump_result *res = parsed_result;
9806
9807         if (!strcmp(res->dump, "dump_physmem"))
9808                 rte_dump_physmem_layout(stdout);
9809         else if (!strcmp(res->dump, "dump_socket_mem"))
9810                 dump_socket_mem(stdout);
9811         else if (!strcmp(res->dump, "dump_memzone"))
9812                 rte_memzone_dump(stdout);
9813         else if (!strcmp(res->dump, "dump_struct_sizes"))
9814                 dump_struct_sizes();
9815         else if (!strcmp(res->dump, "dump_ring"))
9816                 rte_ring_list_dump(stdout);
9817         else if (!strcmp(res->dump, "dump_mempool"))
9818                 rte_mempool_list_dump(stdout);
9819         else if (!strcmp(res->dump, "dump_devargs"))
9820                 rte_devargs_dump(stdout);
9821         else if (!strcmp(res->dump, "dump_log_types"))
9822                 rte_log_dump(stdout);
9823 }
9824
9825 cmdline_parse_token_string_t cmd_dump_dump =
9826         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9827                 "dump_physmem#"
9828                 "dump_memzone#"
9829                 "dump_socket_mem#"
9830                 "dump_struct_sizes#"
9831                 "dump_ring#"
9832                 "dump_mempool#"
9833                 "dump_devargs#"
9834                 "dump_log_types");
9835
9836 cmdline_parse_inst_t cmd_dump = {
9837         .f = cmd_dump_parsed,  /* function to call */
9838         .data = NULL,      /* 2nd arg of func */
9839         .help_str = "Dump status",
9840         .tokens = {        /* token list, NULL terminated */
9841                 (void *)&cmd_dump_dump,
9842                 NULL,
9843         },
9844 };
9845
9846 /* ******************************************************************************** */
9847
9848 struct cmd_dump_one_result {
9849         cmdline_fixed_string_t dump;
9850         cmdline_fixed_string_t name;
9851 };
9852
9853 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9854                                 __rte_unused void *data)
9855 {
9856         struct cmd_dump_one_result *res = parsed_result;
9857
9858         if (!strcmp(res->dump, "dump_ring")) {
9859                 struct rte_ring *r;
9860                 r = rte_ring_lookup(res->name);
9861                 if (r == NULL) {
9862                         cmdline_printf(cl, "Cannot find ring\n");
9863                         return;
9864                 }
9865                 rte_ring_dump(stdout, r);
9866         } else if (!strcmp(res->dump, "dump_mempool")) {
9867                 struct rte_mempool *mp;
9868                 mp = rte_mempool_lookup(res->name);
9869                 if (mp == NULL) {
9870                         cmdline_printf(cl, "Cannot find mempool\n");
9871                         return;
9872                 }
9873                 rte_mempool_dump(stdout, mp);
9874         }
9875 }
9876
9877 cmdline_parse_token_string_t cmd_dump_one_dump =
9878         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9879                                  "dump_ring#dump_mempool");
9880
9881 cmdline_parse_token_string_t cmd_dump_one_name =
9882         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9883
9884 cmdline_parse_inst_t cmd_dump_one = {
9885         .f = cmd_dump_one_parsed,  /* function to call */
9886         .data = NULL,      /* 2nd arg of func */
9887         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9888         .tokens = {        /* token list, NULL terminated */
9889                 (void *)&cmd_dump_one_dump,
9890                 (void *)&cmd_dump_one_name,
9891                 NULL,
9892         },
9893 };
9894
9895 /* *** Add/Del syn filter *** */
9896 struct cmd_syn_filter_result {
9897         cmdline_fixed_string_t filter;
9898         portid_t port_id;
9899         cmdline_fixed_string_t ops;
9900         cmdline_fixed_string_t priority;
9901         cmdline_fixed_string_t high;
9902         cmdline_fixed_string_t queue;
9903         uint16_t queue_id;
9904 };
9905
9906 static void
9907 cmd_syn_filter_parsed(void *parsed_result,
9908                         __rte_unused struct cmdline *cl,
9909                         __rte_unused void *data)
9910 {
9911         struct cmd_syn_filter_result *res = parsed_result;
9912         struct rte_eth_syn_filter syn_filter;
9913         int ret = 0;
9914
9915         ret = rte_eth_dev_filter_supported(res->port_id,
9916                                         RTE_ETH_FILTER_SYN);
9917         if (ret < 0) {
9918                 printf("syn filter is not supported on port %u.\n",
9919                                 res->port_id);
9920                 return;
9921         }
9922
9923         memset(&syn_filter, 0, sizeof(syn_filter));
9924
9925         if (!strcmp(res->ops, "add")) {
9926                 if (!strcmp(res->high, "high"))
9927                         syn_filter.hig_pri = 1;
9928                 else
9929                         syn_filter.hig_pri = 0;
9930
9931                 syn_filter.queue = res->queue_id;
9932                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9933                                                 RTE_ETH_FILTER_SYN,
9934                                                 RTE_ETH_FILTER_ADD,
9935                                                 &syn_filter);
9936         } else
9937                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9938                                                 RTE_ETH_FILTER_SYN,
9939                                                 RTE_ETH_FILTER_DELETE,
9940                                                 &syn_filter);
9941
9942         if (ret < 0)
9943                 printf("syn filter programming error: (%s)\n",
9944                                 strerror(-ret));
9945 }
9946
9947 cmdline_parse_token_string_t cmd_syn_filter_filter =
9948         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9949         filter, "syn_filter");
9950 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9951         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9952         port_id, UINT16);
9953 cmdline_parse_token_string_t cmd_syn_filter_ops =
9954         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9955         ops, "add#del");
9956 cmdline_parse_token_string_t cmd_syn_filter_priority =
9957         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9958                                 priority, "priority");
9959 cmdline_parse_token_string_t cmd_syn_filter_high =
9960         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9961                                 high, "high#low");
9962 cmdline_parse_token_string_t cmd_syn_filter_queue =
9963         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9964                                 queue, "queue");
9965 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9966         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9967                                 queue_id, UINT16);
9968
9969 cmdline_parse_inst_t cmd_syn_filter = {
9970         .f = cmd_syn_filter_parsed,
9971         .data = NULL,
9972         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9973                 "<queue_id>: Add/Delete syn filter",
9974         .tokens = {
9975                 (void *)&cmd_syn_filter_filter,
9976                 (void *)&cmd_syn_filter_port_id,
9977                 (void *)&cmd_syn_filter_ops,
9978                 (void *)&cmd_syn_filter_priority,
9979                 (void *)&cmd_syn_filter_high,
9980                 (void *)&cmd_syn_filter_queue,
9981                 (void *)&cmd_syn_filter_queue_id,
9982                 NULL,
9983         },
9984 };
9985
9986 /* *** queue region set *** */
9987 struct cmd_queue_region_result {
9988         cmdline_fixed_string_t set;
9989         cmdline_fixed_string_t port;
9990         portid_t port_id;
9991         cmdline_fixed_string_t cmd;
9992         cmdline_fixed_string_t region;
9993         uint8_t  region_id;
9994         cmdline_fixed_string_t queue_start_index;
9995         uint8_t  queue_id;
9996         cmdline_fixed_string_t queue_num;
9997         uint8_t  queue_num_value;
9998 };
9999
10000 static void
10001 cmd_queue_region_parsed(void *parsed_result,
10002                         __rte_unused struct cmdline *cl,
10003                         __rte_unused void *data)
10004 {
10005         struct cmd_queue_region_result *res = parsed_result;
10006         int ret = -ENOTSUP;
10007 #ifdef RTE_LIBRTE_I40E_PMD
10008         struct rte_pmd_i40e_queue_region_conf region_conf;
10009         enum rte_pmd_i40e_queue_region_op op_type;
10010 #endif
10011
10012         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10013                 return;
10014
10015 #ifdef RTE_LIBRTE_I40E_PMD
10016         memset(&region_conf, 0, sizeof(region_conf));
10017         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10018         region_conf.region_id = res->region_id;
10019         region_conf.queue_num = res->queue_num_value;
10020         region_conf.queue_start_index = res->queue_id;
10021
10022         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10023                                 op_type, &region_conf);
10024 #endif
10025
10026         switch (ret) {
10027         case 0:
10028                 break;
10029         case -ENOTSUP:
10030                 printf("function not implemented or supported\n");
10031                 break;
10032         default:
10033                 printf("queue region config error: (%s)\n", strerror(-ret));
10034         }
10035 }
10036
10037 cmdline_parse_token_string_t cmd_queue_region_set =
10038 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10039                 set, "set");
10040 cmdline_parse_token_string_t cmd_queue_region_port =
10041         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10042 cmdline_parse_token_num_t cmd_queue_region_port_id =
10043         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10044                                 port_id, UINT16);
10045 cmdline_parse_token_string_t cmd_queue_region_cmd =
10046         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10047                                  cmd, "queue-region");
10048 cmdline_parse_token_string_t cmd_queue_region_id =
10049         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10050                                 region, "region_id");
10051 cmdline_parse_token_num_t cmd_queue_region_index =
10052         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10053                                 region_id, UINT8);
10054 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10055         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10056                                 queue_start_index, "queue_start_index");
10057 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10058         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10059                                 queue_id, UINT8);
10060 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10061         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10062                                 queue_num, "queue_num");
10063 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10064         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10065                                 queue_num_value, UINT8);
10066
10067 cmdline_parse_inst_t cmd_queue_region = {
10068         .f = cmd_queue_region_parsed,
10069         .data = NULL,
10070         .help_str = "set port <port_id> queue-region region_id <value> "
10071                 "queue_start_index <value> queue_num <value>: Set a queue region",
10072         .tokens = {
10073                 (void *)&cmd_queue_region_set,
10074                 (void *)&cmd_queue_region_port,
10075                 (void *)&cmd_queue_region_port_id,
10076                 (void *)&cmd_queue_region_cmd,
10077                 (void *)&cmd_queue_region_id,
10078                 (void *)&cmd_queue_region_index,
10079                 (void *)&cmd_queue_region_queue_start_index,
10080                 (void *)&cmd_queue_region_queue_id,
10081                 (void *)&cmd_queue_region_queue_num,
10082                 (void *)&cmd_queue_region_queue_num_value,
10083                 NULL,
10084         },
10085 };
10086
10087 /* *** queue region and flowtype set *** */
10088 struct cmd_region_flowtype_result {
10089         cmdline_fixed_string_t set;
10090         cmdline_fixed_string_t port;
10091         portid_t port_id;
10092         cmdline_fixed_string_t cmd;
10093         cmdline_fixed_string_t region;
10094         uint8_t  region_id;
10095         cmdline_fixed_string_t flowtype;
10096         uint8_t  flowtype_id;
10097 };
10098
10099 static void
10100 cmd_region_flowtype_parsed(void *parsed_result,
10101                         __rte_unused struct cmdline *cl,
10102                         __rte_unused void *data)
10103 {
10104         struct cmd_region_flowtype_result *res = parsed_result;
10105         int ret = -ENOTSUP;
10106 #ifdef RTE_LIBRTE_I40E_PMD
10107         struct rte_pmd_i40e_queue_region_conf region_conf;
10108         enum rte_pmd_i40e_queue_region_op op_type;
10109 #endif
10110
10111         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10112                 return;
10113
10114 #ifdef RTE_LIBRTE_I40E_PMD
10115         memset(&region_conf, 0, sizeof(region_conf));
10116
10117         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10118         region_conf.region_id = res->region_id;
10119         region_conf.hw_flowtype = res->flowtype_id;
10120
10121         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10122                         op_type, &region_conf);
10123 #endif
10124
10125         switch (ret) {
10126         case 0:
10127                 break;
10128         case -ENOTSUP:
10129                 printf("function not implemented or supported\n");
10130                 break;
10131         default:
10132                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10133         }
10134 }
10135
10136 cmdline_parse_token_string_t cmd_region_flowtype_set =
10137 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10138                                 set, "set");
10139 cmdline_parse_token_string_t cmd_region_flowtype_port =
10140         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10141                                 port, "port");
10142 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10143         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10144                                 port_id, UINT16);
10145 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10146         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10147                                 cmd, "queue-region");
10148 cmdline_parse_token_string_t cmd_region_flowtype_index =
10149         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10150                                 region, "region_id");
10151 cmdline_parse_token_num_t cmd_region_flowtype_id =
10152         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10153                                 region_id, UINT8);
10154 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10155         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10156                                 flowtype, "flowtype");
10157 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10158         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10159                                 flowtype_id, UINT8);
10160 cmdline_parse_inst_t cmd_region_flowtype = {
10161         .f = cmd_region_flowtype_parsed,
10162         .data = NULL,
10163         .help_str = "set port <port_id> queue-region region_id <value> "
10164                 "flowtype <value>: Set a flowtype region index",
10165         .tokens = {
10166                 (void *)&cmd_region_flowtype_set,
10167                 (void *)&cmd_region_flowtype_port,
10168                 (void *)&cmd_region_flowtype_port_index,
10169                 (void *)&cmd_region_flowtype_cmd,
10170                 (void *)&cmd_region_flowtype_index,
10171                 (void *)&cmd_region_flowtype_id,
10172                 (void *)&cmd_region_flowtype_flow_index,
10173                 (void *)&cmd_region_flowtype_flow_id,
10174                 NULL,
10175         },
10176 };
10177
10178 /* *** User Priority (UP) to queue region (region_id) set *** */
10179 struct cmd_user_priority_region_result {
10180         cmdline_fixed_string_t set;
10181         cmdline_fixed_string_t port;
10182         portid_t port_id;
10183         cmdline_fixed_string_t cmd;
10184         cmdline_fixed_string_t user_priority;
10185         uint8_t  user_priority_id;
10186         cmdline_fixed_string_t region;
10187         uint8_t  region_id;
10188 };
10189
10190 static void
10191 cmd_user_priority_region_parsed(void *parsed_result,
10192                         __rte_unused struct cmdline *cl,
10193                         __rte_unused void *data)
10194 {
10195         struct cmd_user_priority_region_result *res = parsed_result;
10196         int ret = -ENOTSUP;
10197 #ifdef RTE_LIBRTE_I40E_PMD
10198         struct rte_pmd_i40e_queue_region_conf region_conf;
10199         enum rte_pmd_i40e_queue_region_op op_type;
10200 #endif
10201
10202         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10203                 return;
10204
10205 #ifdef RTE_LIBRTE_I40E_PMD
10206         memset(&region_conf, 0, sizeof(region_conf));
10207         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10208         region_conf.user_priority = res->user_priority_id;
10209         region_conf.region_id = res->region_id;
10210
10211         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10212                                 op_type, &region_conf);
10213 #endif
10214
10215         switch (ret) {
10216         case 0:
10217                 break;
10218         case -ENOTSUP:
10219                 printf("function not implemented or supported\n");
10220                 break;
10221         default:
10222                 printf("user_priority region config error: (%s)\n",
10223                                 strerror(-ret));
10224         }
10225 }
10226
10227 cmdline_parse_token_string_t cmd_user_priority_region_set =
10228         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10229                                 set, "set");
10230 cmdline_parse_token_string_t cmd_user_priority_region_port =
10231         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10232                                 port, "port");
10233 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10234         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10235                                 port_id, UINT16);
10236 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10237         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10238                                 cmd, "queue-region");
10239 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10240         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10241                                 user_priority, "UP");
10242 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10243         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10244                                 user_priority_id, UINT8);
10245 cmdline_parse_token_string_t cmd_user_priority_region_region =
10246         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10247                                 region, "region_id");
10248 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10249         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10250                                 region_id, UINT8);
10251
10252 cmdline_parse_inst_t cmd_user_priority_region = {
10253         .f = cmd_user_priority_region_parsed,
10254         .data = NULL,
10255         .help_str = "set port <port_id> queue-region UP <value> "
10256                 "region_id <value>: Set the mapping of User Priority (UP) "
10257                 "to queue region (region_id) ",
10258         .tokens = {
10259                 (void *)&cmd_user_priority_region_set,
10260                 (void *)&cmd_user_priority_region_port,
10261                 (void *)&cmd_user_priority_region_port_index,
10262                 (void *)&cmd_user_priority_region_cmd,
10263                 (void *)&cmd_user_priority_region_UP,
10264                 (void *)&cmd_user_priority_region_UP_id,
10265                 (void *)&cmd_user_priority_region_region,
10266                 (void *)&cmd_user_priority_region_region_id,
10267                 NULL,
10268         },
10269 };
10270
10271 /* *** flush all queue region related configuration *** */
10272 struct cmd_flush_queue_region_result {
10273         cmdline_fixed_string_t set;
10274         cmdline_fixed_string_t port;
10275         portid_t port_id;
10276         cmdline_fixed_string_t cmd;
10277         cmdline_fixed_string_t flush;
10278         cmdline_fixed_string_t what;
10279 };
10280
10281 static void
10282 cmd_flush_queue_region_parsed(void *parsed_result,
10283                         __rte_unused struct cmdline *cl,
10284                         __rte_unused void *data)
10285 {
10286         struct cmd_flush_queue_region_result *res = parsed_result;
10287         int ret = -ENOTSUP;
10288 #ifdef RTE_LIBRTE_I40E_PMD
10289         struct rte_pmd_i40e_queue_region_conf region_conf;
10290         enum rte_pmd_i40e_queue_region_op op_type;
10291 #endif
10292
10293         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10294                 return;
10295
10296 #ifdef RTE_LIBRTE_I40E_PMD
10297         memset(&region_conf, 0, sizeof(region_conf));
10298
10299         if (strcmp(res->what, "on") == 0)
10300                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10301         else
10302                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10303
10304         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10305                                 op_type, &region_conf);
10306 #endif
10307
10308         switch (ret) {
10309         case 0:
10310                 break;
10311         case -ENOTSUP:
10312                 printf("function not implemented or supported\n");
10313                 break;
10314         default:
10315                 printf("queue region config flush error: (%s)\n",
10316                                 strerror(-ret));
10317         }
10318 }
10319
10320 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10321         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10322                                 set, "set");
10323 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10324         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10325                                 port, "port");
10326 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10327         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10328                                 port_id, UINT16);
10329 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10330         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10331                                 cmd, "queue-region");
10332 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10333         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10334                                 flush, "flush");
10335 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10336         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10337                                 what, "on#off");
10338
10339 cmdline_parse_inst_t cmd_flush_queue_region = {
10340         .f = cmd_flush_queue_region_parsed,
10341         .data = NULL,
10342         .help_str = "set port <port_id> queue-region flush on|off"
10343                 ": flush all queue region related configuration",
10344         .tokens = {
10345                 (void *)&cmd_flush_queue_region_set,
10346                 (void *)&cmd_flush_queue_region_port,
10347                 (void *)&cmd_flush_queue_region_port_index,
10348                 (void *)&cmd_flush_queue_region_cmd,
10349                 (void *)&cmd_flush_queue_region_flush,
10350                 (void *)&cmd_flush_queue_region_what,
10351                 NULL,
10352         },
10353 };
10354
10355 /* *** get all queue region related configuration info *** */
10356 struct cmd_show_queue_region_info {
10357         cmdline_fixed_string_t show;
10358         cmdline_fixed_string_t port;
10359         portid_t port_id;
10360         cmdline_fixed_string_t cmd;
10361 };
10362
10363 static void
10364 cmd_show_queue_region_info_parsed(void *parsed_result,
10365                         __rte_unused struct cmdline *cl,
10366                         __rte_unused void *data)
10367 {
10368         struct cmd_show_queue_region_info *res = parsed_result;
10369         int ret = -ENOTSUP;
10370 #ifdef RTE_LIBRTE_I40E_PMD
10371         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10372         enum rte_pmd_i40e_queue_region_op op_type;
10373 #endif
10374
10375         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10376                 return;
10377
10378 #ifdef RTE_LIBRTE_I40E_PMD
10379         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10380
10381         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10382
10383         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10384                                         op_type, &rte_pmd_regions);
10385
10386         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10387 #endif
10388
10389         switch (ret) {
10390         case 0:
10391                 break;
10392         case -ENOTSUP:
10393                 printf("function not implemented or supported\n");
10394                 break;
10395         default:
10396                 printf("queue region config info show error: (%s)\n",
10397                                 strerror(-ret));
10398         }
10399 }
10400
10401 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10402 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10403                                 show, "show");
10404 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10405         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10406                                 port, "port");
10407 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10408         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10409                                 port_id, UINT16);
10410 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10411         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10412                                 cmd, "queue-region");
10413
10414 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10415         .f = cmd_show_queue_region_info_parsed,
10416         .data = NULL,
10417         .help_str = "show port <port_id> queue-region"
10418                 ": show all queue region related configuration info",
10419         .tokens = {
10420                 (void *)&cmd_show_queue_region_info_get,
10421                 (void *)&cmd_show_queue_region_info_port,
10422                 (void *)&cmd_show_queue_region_info_port_index,
10423                 (void *)&cmd_show_queue_region_info_cmd,
10424                 NULL,
10425         },
10426 };
10427
10428 /* *** ADD/REMOVE A 2tuple FILTER *** */
10429 struct cmd_2tuple_filter_result {
10430         cmdline_fixed_string_t filter;
10431         portid_t port_id;
10432         cmdline_fixed_string_t ops;
10433         cmdline_fixed_string_t dst_port;
10434         uint16_t dst_port_value;
10435         cmdline_fixed_string_t protocol;
10436         uint8_t protocol_value;
10437         cmdline_fixed_string_t mask;
10438         uint8_t  mask_value;
10439         cmdline_fixed_string_t tcp_flags;
10440         uint8_t tcp_flags_value;
10441         cmdline_fixed_string_t priority;
10442         uint8_t  priority_value;
10443         cmdline_fixed_string_t queue;
10444         uint16_t  queue_id;
10445 };
10446
10447 static void
10448 cmd_2tuple_filter_parsed(void *parsed_result,
10449                         __rte_unused struct cmdline *cl,
10450                         __rte_unused void *data)
10451 {
10452         struct rte_eth_ntuple_filter filter;
10453         struct cmd_2tuple_filter_result *res = parsed_result;
10454         int ret = 0;
10455
10456         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10457         if (ret < 0) {
10458                 printf("ntuple filter is not supported on port %u.\n",
10459                         res->port_id);
10460                 return;
10461         }
10462
10463         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10464
10465         filter.flags = RTE_2TUPLE_FLAGS;
10466         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10467         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10468         filter.proto = res->protocol_value;
10469         filter.priority = res->priority_value;
10470         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10471                 printf("nonzero tcp_flags is only meaningful"
10472                         " when protocol is TCP.\n");
10473                 return;
10474         }
10475         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10476                 printf("invalid TCP flags.\n");
10477                 return;
10478         }
10479
10480         if (res->tcp_flags_value != 0) {
10481                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10482                 filter.tcp_flags = res->tcp_flags_value;
10483         }
10484
10485         /* need convert to big endian. */
10486         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10487         filter.queue = res->queue_id;
10488
10489         if (!strcmp(res->ops, "add"))
10490                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10491                                 RTE_ETH_FILTER_NTUPLE,
10492                                 RTE_ETH_FILTER_ADD,
10493                                 &filter);
10494         else
10495                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10496                                 RTE_ETH_FILTER_NTUPLE,
10497                                 RTE_ETH_FILTER_DELETE,
10498                                 &filter);
10499         if (ret < 0)
10500                 printf("2tuple filter programming error: (%s)\n",
10501                         strerror(-ret));
10502
10503 }
10504
10505 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10506         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10507                                  filter, "2tuple_filter");
10508 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10509         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10510                                 port_id, UINT16);
10511 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10512         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10513                                  ops, "add#del");
10514 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10515         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10516                                 dst_port, "dst_port");
10517 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10518         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10519                                 dst_port_value, UINT16);
10520 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10521         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10522                                 protocol, "protocol");
10523 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10524         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10525                                 protocol_value, UINT8);
10526 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10527         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10528                                 mask, "mask");
10529 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10530         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10531                                 mask_value, INT8);
10532 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10533         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10534                                 tcp_flags, "tcp_flags");
10535 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10536         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10537                                 tcp_flags_value, UINT8);
10538 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10539         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10540                                 priority, "priority");
10541 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10542         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10543                                 priority_value, UINT8);
10544 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10545         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10546                                 queue, "queue");
10547 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10548         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10549                                 queue_id, UINT16);
10550
10551 cmdline_parse_inst_t cmd_2tuple_filter = {
10552         .f = cmd_2tuple_filter_parsed,
10553         .data = NULL,
10554         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10555                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10556                 "<queue_id>: Add a 2tuple filter",
10557         .tokens = {
10558                 (void *)&cmd_2tuple_filter_filter,
10559                 (void *)&cmd_2tuple_filter_port_id,
10560                 (void *)&cmd_2tuple_filter_ops,
10561                 (void *)&cmd_2tuple_filter_dst_port,
10562                 (void *)&cmd_2tuple_filter_dst_port_value,
10563                 (void *)&cmd_2tuple_filter_protocol,
10564                 (void *)&cmd_2tuple_filter_protocol_value,
10565                 (void *)&cmd_2tuple_filter_mask,
10566                 (void *)&cmd_2tuple_filter_mask_value,
10567                 (void *)&cmd_2tuple_filter_tcp_flags,
10568                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10569                 (void *)&cmd_2tuple_filter_priority,
10570                 (void *)&cmd_2tuple_filter_priority_value,
10571                 (void *)&cmd_2tuple_filter_queue,
10572                 (void *)&cmd_2tuple_filter_queue_id,
10573                 NULL,
10574         },
10575 };
10576
10577 /* *** ADD/REMOVE A 5tuple FILTER *** */
10578 struct cmd_5tuple_filter_result {
10579         cmdline_fixed_string_t filter;
10580         portid_t port_id;
10581         cmdline_fixed_string_t ops;
10582         cmdline_fixed_string_t dst_ip;
10583         cmdline_ipaddr_t dst_ip_value;
10584         cmdline_fixed_string_t src_ip;
10585         cmdline_ipaddr_t src_ip_value;
10586         cmdline_fixed_string_t dst_port;
10587         uint16_t dst_port_value;
10588         cmdline_fixed_string_t src_port;
10589         uint16_t src_port_value;
10590         cmdline_fixed_string_t protocol;
10591         uint8_t protocol_value;
10592         cmdline_fixed_string_t mask;
10593         uint8_t  mask_value;
10594         cmdline_fixed_string_t tcp_flags;
10595         uint8_t tcp_flags_value;
10596         cmdline_fixed_string_t priority;
10597         uint8_t  priority_value;
10598         cmdline_fixed_string_t queue;
10599         uint16_t  queue_id;
10600 };
10601
10602 static void
10603 cmd_5tuple_filter_parsed(void *parsed_result,
10604                         __rte_unused struct cmdline *cl,
10605                         __rte_unused void *data)
10606 {
10607         struct rte_eth_ntuple_filter filter;
10608         struct cmd_5tuple_filter_result *res = parsed_result;
10609         int ret = 0;
10610
10611         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10612         if (ret < 0) {
10613                 printf("ntuple filter is not supported on port %u.\n",
10614                         res->port_id);
10615                 return;
10616         }
10617
10618         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10619
10620         filter.flags = RTE_5TUPLE_FLAGS;
10621         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10622         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10623         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10624         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10625         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10626         filter.proto = res->protocol_value;
10627         filter.priority = res->priority_value;
10628         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10629                 printf("nonzero tcp_flags is only meaningful"
10630                         " when protocol is TCP.\n");
10631                 return;
10632         }
10633         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10634                 printf("invalid TCP flags.\n");
10635                 return;
10636         }
10637
10638         if (res->tcp_flags_value != 0) {
10639                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10640                 filter.tcp_flags = res->tcp_flags_value;
10641         }
10642
10643         if (res->dst_ip_value.family == AF_INET)
10644                 /* no need to convert, already big endian. */
10645                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10646         else {
10647                 if (filter.dst_ip_mask == 0) {
10648                         printf("can not support ipv6 involved compare.\n");
10649                         return;
10650                 }
10651                 filter.dst_ip = 0;
10652         }
10653
10654         if (res->src_ip_value.family == AF_INET)
10655                 /* no need to convert, already big endian. */
10656                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10657         else {
10658                 if (filter.src_ip_mask == 0) {
10659                         printf("can not support ipv6 involved compare.\n");
10660                         return;
10661                 }
10662                 filter.src_ip = 0;
10663         }
10664         /* need convert to big endian. */
10665         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10666         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10667         filter.queue = res->queue_id;
10668
10669         if (!strcmp(res->ops, "add"))
10670                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10671                                 RTE_ETH_FILTER_NTUPLE,
10672                                 RTE_ETH_FILTER_ADD,
10673                                 &filter);
10674         else
10675                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10676                                 RTE_ETH_FILTER_NTUPLE,
10677                                 RTE_ETH_FILTER_DELETE,
10678                                 &filter);
10679         if (ret < 0)
10680                 printf("5tuple filter programming error: (%s)\n",
10681                         strerror(-ret));
10682 }
10683
10684 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10685         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10686                                  filter, "5tuple_filter");
10687 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10688         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10689                                 port_id, UINT16);
10690 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10691         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10692                                  ops, "add#del");
10693 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10694         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10695                                 dst_ip, "dst_ip");
10696 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10697         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10698                                 dst_ip_value);
10699 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10700         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10701                                 src_ip, "src_ip");
10702 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10703         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10704                                 src_ip_value);
10705 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10706         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10707                                 dst_port, "dst_port");
10708 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10709         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10710                                 dst_port_value, UINT16);
10711 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10712         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10713                                 src_port, "src_port");
10714 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10715         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10716                                 src_port_value, UINT16);
10717 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10718         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10719                                 protocol, "protocol");
10720 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10721         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10722                                 protocol_value, UINT8);
10723 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10724         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10725                                 mask, "mask");
10726 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10727         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10728                                 mask_value, INT8);
10729 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10730         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10731                                 tcp_flags, "tcp_flags");
10732 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10733         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10734                                 tcp_flags_value, UINT8);
10735 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10736         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10737                                 priority, "priority");
10738 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10739         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10740                                 priority_value, UINT8);
10741 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10742         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10743                                 queue, "queue");
10744 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10745         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10746                                 queue_id, UINT16);
10747
10748 cmdline_parse_inst_t cmd_5tuple_filter = {
10749         .f = cmd_5tuple_filter_parsed,
10750         .data = NULL,
10751         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10752                 "src_ip <value> dst_port <value> src_port <value> "
10753                 "protocol <value>  mask <value> tcp_flags <value> "
10754                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10755         .tokens = {
10756                 (void *)&cmd_5tuple_filter_filter,
10757                 (void *)&cmd_5tuple_filter_port_id,
10758                 (void *)&cmd_5tuple_filter_ops,
10759                 (void *)&cmd_5tuple_filter_dst_ip,
10760                 (void *)&cmd_5tuple_filter_dst_ip_value,
10761                 (void *)&cmd_5tuple_filter_src_ip,
10762                 (void *)&cmd_5tuple_filter_src_ip_value,
10763                 (void *)&cmd_5tuple_filter_dst_port,
10764                 (void *)&cmd_5tuple_filter_dst_port_value,
10765                 (void *)&cmd_5tuple_filter_src_port,
10766                 (void *)&cmd_5tuple_filter_src_port_value,
10767                 (void *)&cmd_5tuple_filter_protocol,
10768                 (void *)&cmd_5tuple_filter_protocol_value,
10769                 (void *)&cmd_5tuple_filter_mask,
10770                 (void *)&cmd_5tuple_filter_mask_value,
10771                 (void *)&cmd_5tuple_filter_tcp_flags,
10772                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10773                 (void *)&cmd_5tuple_filter_priority,
10774                 (void *)&cmd_5tuple_filter_priority_value,
10775                 (void *)&cmd_5tuple_filter_queue,
10776                 (void *)&cmd_5tuple_filter_queue_id,
10777                 NULL,
10778         },
10779 };
10780
10781 /* *** ADD/REMOVE A flex FILTER *** */
10782 struct cmd_flex_filter_result {
10783         cmdline_fixed_string_t filter;
10784         cmdline_fixed_string_t ops;
10785         portid_t port_id;
10786         cmdline_fixed_string_t len;
10787         uint8_t len_value;
10788         cmdline_fixed_string_t bytes;
10789         cmdline_fixed_string_t bytes_value;
10790         cmdline_fixed_string_t mask;
10791         cmdline_fixed_string_t mask_value;
10792         cmdline_fixed_string_t priority;
10793         uint8_t priority_value;
10794         cmdline_fixed_string_t queue;
10795         uint16_t queue_id;
10796 };
10797
10798 static int xdigit2val(unsigned char c)
10799 {
10800         int val;
10801         if (isdigit(c))
10802                 val = c - '0';
10803         else if (isupper(c))
10804                 val = c - 'A' + 10;
10805         else
10806                 val = c - 'a' + 10;
10807         return val;
10808 }
10809
10810 static void
10811 cmd_flex_filter_parsed(void *parsed_result,
10812                           __rte_unused struct cmdline *cl,
10813                           __rte_unused void *data)
10814 {
10815         int ret = 0;
10816         struct rte_eth_flex_filter filter;
10817         struct cmd_flex_filter_result *res = parsed_result;
10818         char *bytes_ptr, *mask_ptr;
10819         uint16_t len, i, j = 0;
10820         char c;
10821         int val;
10822         uint8_t byte = 0;
10823
10824         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10825                 printf("the len exceed the max length 128\n");
10826                 return;
10827         }
10828         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10829         filter.len = res->len_value;
10830         filter.priority = res->priority_value;
10831         filter.queue = res->queue_id;
10832         bytes_ptr = res->bytes_value;
10833         mask_ptr = res->mask_value;
10834
10835          /* translate bytes string to array. */
10836         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10837                 (bytes_ptr[1] == 'X')))
10838                 bytes_ptr += 2;
10839         len = strnlen(bytes_ptr, res->len_value * 2);
10840         if (len == 0 || (len % 8 != 0)) {
10841                 printf("please check len and bytes input\n");
10842                 return;
10843         }
10844         for (i = 0; i < len; i++) {
10845                 c = bytes_ptr[i];
10846                 if (isxdigit(c) == 0) {
10847                         /* invalid characters. */
10848                         printf("invalid input\n");
10849                         return;
10850                 }
10851                 val = xdigit2val(c);
10852                 if (i % 2) {
10853                         byte |= val;
10854                         filter.bytes[j] = byte;
10855                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10856                         j++;
10857                         byte = 0;
10858                 } else
10859                         byte |= val << 4;
10860         }
10861         printf("\n");
10862          /* translate mask string to uint8_t array. */
10863         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10864                 (mask_ptr[1] == 'X')))
10865                 mask_ptr += 2;
10866         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10867         if (len == 0) {
10868                 printf("invalid input\n");
10869                 return;
10870         }
10871         j = 0;
10872         byte = 0;
10873         for (i = 0; i < len; i++) {
10874                 c = mask_ptr[i];
10875                 if (isxdigit(c) == 0) {
10876                         /* invalid characters. */
10877                         printf("invalid input\n");
10878                         return;
10879                 }
10880                 val = xdigit2val(c);
10881                 if (i % 2) {
10882                         byte |= val;
10883                         filter.mask[j] = byte;
10884                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10885                         j++;
10886                         byte = 0;
10887                 } else
10888                         byte |= val << 4;
10889         }
10890         printf("\n");
10891
10892         if (!strcmp(res->ops, "add"))
10893                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10894                                 RTE_ETH_FILTER_FLEXIBLE,
10895                                 RTE_ETH_FILTER_ADD,
10896                                 &filter);
10897         else
10898                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10899                                 RTE_ETH_FILTER_FLEXIBLE,
10900                                 RTE_ETH_FILTER_DELETE,
10901                                 &filter);
10902
10903         if (ret < 0)
10904                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10905 }
10906
10907 cmdline_parse_token_string_t cmd_flex_filter_filter =
10908         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10909                                 filter, "flex_filter");
10910 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10911         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10912                                 port_id, UINT16);
10913 cmdline_parse_token_string_t cmd_flex_filter_ops =
10914         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10915                                 ops, "add#del");
10916 cmdline_parse_token_string_t cmd_flex_filter_len =
10917         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10918                                 len, "len");
10919 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10920         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10921                                 len_value, UINT8);
10922 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10923         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10924                                 bytes, "bytes");
10925 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10926         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10927                                 bytes_value, NULL);
10928 cmdline_parse_token_string_t cmd_flex_filter_mask =
10929         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10930                                 mask, "mask");
10931 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10932         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10933                                 mask_value, NULL);
10934 cmdline_parse_token_string_t cmd_flex_filter_priority =
10935         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10936                                 priority, "priority");
10937 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10938         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10939                                 priority_value, UINT8);
10940 cmdline_parse_token_string_t cmd_flex_filter_queue =
10941         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10942                                 queue, "queue");
10943 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10944         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10945                                 queue_id, UINT16);
10946 cmdline_parse_inst_t cmd_flex_filter = {
10947         .f = cmd_flex_filter_parsed,
10948         .data = NULL,
10949         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10950                 "<value> mask <value> priority <value> queue <queue_id>: "
10951                 "Add/Del a flex filter",
10952         .tokens = {
10953                 (void *)&cmd_flex_filter_filter,
10954                 (void *)&cmd_flex_filter_port_id,
10955                 (void *)&cmd_flex_filter_ops,
10956                 (void *)&cmd_flex_filter_len,
10957                 (void *)&cmd_flex_filter_len_value,
10958                 (void *)&cmd_flex_filter_bytes,
10959                 (void *)&cmd_flex_filter_bytes_value,
10960                 (void *)&cmd_flex_filter_mask,
10961                 (void *)&cmd_flex_filter_mask_value,
10962                 (void *)&cmd_flex_filter_priority,
10963                 (void *)&cmd_flex_filter_priority_value,
10964                 (void *)&cmd_flex_filter_queue,
10965                 (void *)&cmd_flex_filter_queue_id,
10966                 NULL,
10967         },
10968 };
10969
10970 /* *** Filters Control *** */
10971
10972 /* *** deal with ethertype filter *** */
10973 struct cmd_ethertype_filter_result {
10974         cmdline_fixed_string_t filter;
10975         portid_t port_id;
10976         cmdline_fixed_string_t ops;
10977         cmdline_fixed_string_t mac;
10978         struct rte_ether_addr mac_addr;
10979         cmdline_fixed_string_t ethertype;
10980         uint16_t ethertype_value;
10981         cmdline_fixed_string_t drop;
10982         cmdline_fixed_string_t queue;
10983         uint16_t  queue_id;
10984 };
10985
10986 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10987         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10988                                  filter, "ethertype_filter");
10989 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10990         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10991                               port_id, UINT16);
10992 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10993         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10994                                  ops, "add#del");
10995 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
10996         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10997                                  mac, "mac_addr#mac_ignr");
10998 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
10999         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11000                                      mac_addr);
11001 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11002         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11003                                  ethertype, "ethertype");
11004 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11005         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11006                               ethertype_value, UINT16);
11007 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11008         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11009                                  drop, "drop#fwd");
11010 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11011         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11012                                  queue, "queue");
11013 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11014         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11015                               queue_id, UINT16);
11016
11017 static void
11018 cmd_ethertype_filter_parsed(void *parsed_result,
11019                           __rte_unused struct cmdline *cl,
11020                           __rte_unused void *data)
11021 {
11022         struct cmd_ethertype_filter_result *res = parsed_result;
11023         struct rte_eth_ethertype_filter filter;
11024         int ret = 0;
11025
11026         ret = rte_eth_dev_filter_supported(res->port_id,
11027                         RTE_ETH_FILTER_ETHERTYPE);
11028         if (ret < 0) {
11029                 printf("ethertype filter is not supported on port %u.\n",
11030                         res->port_id);
11031                 return;
11032         }
11033
11034         memset(&filter, 0, sizeof(filter));
11035         if (!strcmp(res->mac, "mac_addr")) {
11036                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11037                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11038                         sizeof(struct rte_ether_addr));
11039         }
11040         if (!strcmp(res->drop, "drop"))
11041                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11042         filter.ether_type = res->ethertype_value;
11043         filter.queue = res->queue_id;
11044
11045         if (!strcmp(res->ops, "add"))
11046                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11047                                 RTE_ETH_FILTER_ETHERTYPE,
11048                                 RTE_ETH_FILTER_ADD,
11049                                 &filter);
11050         else
11051                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11052                                 RTE_ETH_FILTER_ETHERTYPE,
11053                                 RTE_ETH_FILTER_DELETE,
11054                                 &filter);
11055         if (ret < 0)
11056                 printf("ethertype filter programming error: (%s)\n",
11057                         strerror(-ret));
11058 }
11059
11060 cmdline_parse_inst_t cmd_ethertype_filter = {
11061         .f = cmd_ethertype_filter_parsed,
11062         .data = NULL,
11063         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11064                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11065                 "Add or delete an ethertype filter entry",
11066         .tokens = {
11067                 (void *)&cmd_ethertype_filter_filter,
11068                 (void *)&cmd_ethertype_filter_port_id,
11069                 (void *)&cmd_ethertype_filter_ops,
11070                 (void *)&cmd_ethertype_filter_mac,
11071                 (void *)&cmd_ethertype_filter_mac_addr,
11072                 (void *)&cmd_ethertype_filter_ethertype,
11073                 (void *)&cmd_ethertype_filter_ethertype_value,
11074                 (void *)&cmd_ethertype_filter_drop,
11075                 (void *)&cmd_ethertype_filter_queue,
11076                 (void *)&cmd_ethertype_filter_queue_id,
11077                 NULL,
11078         },
11079 };
11080
11081 /* *** deal with flow director filter *** */
11082 struct cmd_flow_director_result {
11083         cmdline_fixed_string_t flow_director_filter;
11084         portid_t port_id;
11085         cmdline_fixed_string_t mode;
11086         cmdline_fixed_string_t mode_value;
11087         cmdline_fixed_string_t ops;
11088         cmdline_fixed_string_t flow;
11089         cmdline_fixed_string_t flow_type;
11090         cmdline_fixed_string_t ether;
11091         uint16_t ether_type;
11092         cmdline_fixed_string_t src;
11093         cmdline_ipaddr_t ip_src;
11094         uint16_t port_src;
11095         cmdline_fixed_string_t dst;
11096         cmdline_ipaddr_t ip_dst;
11097         uint16_t port_dst;
11098         cmdline_fixed_string_t verify_tag;
11099         uint32_t verify_tag_value;
11100         cmdline_fixed_string_t tos;
11101         uint8_t tos_value;
11102         cmdline_fixed_string_t proto;
11103         uint8_t proto_value;
11104         cmdline_fixed_string_t ttl;
11105         uint8_t ttl_value;
11106         cmdline_fixed_string_t vlan;
11107         uint16_t vlan_value;
11108         cmdline_fixed_string_t flexbytes;
11109         cmdline_fixed_string_t flexbytes_value;
11110         cmdline_fixed_string_t pf_vf;
11111         cmdline_fixed_string_t drop;
11112         cmdline_fixed_string_t queue;
11113         uint16_t  queue_id;
11114         cmdline_fixed_string_t fd_id;
11115         uint32_t  fd_id_value;
11116         cmdline_fixed_string_t mac;
11117         struct rte_ether_addr mac_addr;
11118         cmdline_fixed_string_t tunnel;
11119         cmdline_fixed_string_t tunnel_type;
11120         cmdline_fixed_string_t tunnel_id;
11121         uint32_t tunnel_id_value;
11122         cmdline_fixed_string_t packet;
11123         char filepath[];
11124 };
11125
11126 static inline int
11127 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11128 {
11129         char s[256];
11130         const char *p, *p0 = q_arg;
11131         char *end;
11132         unsigned long int_fld;
11133         char *str_fld[max_num];
11134         int i;
11135         unsigned size;
11136         int ret = -1;
11137
11138         p = strchr(p0, '(');
11139         if (p == NULL)
11140                 return -1;
11141         ++p;
11142         p0 = strchr(p, ')');
11143         if (p0 == NULL)
11144                 return -1;
11145
11146         size = p0 - p;
11147         if (size >= sizeof(s))
11148                 return -1;
11149
11150         snprintf(s, sizeof(s), "%.*s", size, p);
11151         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11152         if (ret < 0 || ret > max_num)
11153                 return -1;
11154         for (i = 0; i < ret; i++) {
11155                 errno = 0;
11156                 int_fld = strtoul(str_fld[i], &end, 0);
11157                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11158                         return -1;
11159                 flexbytes[i] = (uint8_t)int_fld;
11160         }
11161         return ret;
11162 }
11163
11164 static uint16_t
11165 str2flowtype(char *string)
11166 {
11167         uint8_t i = 0;
11168         static const struct {
11169                 char str[32];
11170                 uint16_t type;
11171         } flowtype_str[] = {
11172                 {"raw", RTE_ETH_FLOW_RAW},
11173                 {"ipv4", RTE_ETH_FLOW_IPV4},
11174                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11175                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11176                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11177                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11178                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11179                 {"ipv6", RTE_ETH_FLOW_IPV6},
11180                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11181                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11182                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11183                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11184                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11185                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11186         };
11187
11188         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11189                 if (!strcmp(flowtype_str[i].str, string))
11190                         return flowtype_str[i].type;
11191         }
11192
11193         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11194                 return (uint16_t)atoi(string);
11195
11196         return RTE_ETH_FLOW_UNKNOWN;
11197 }
11198
11199 static enum rte_eth_fdir_tunnel_type
11200 str2fdir_tunneltype(char *string)
11201 {
11202         uint8_t i = 0;
11203
11204         static const struct {
11205                 char str[32];
11206                 enum rte_eth_fdir_tunnel_type type;
11207         } tunneltype_str[] = {
11208                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11209                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11210         };
11211
11212         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11213                 if (!strcmp(tunneltype_str[i].str, string))
11214                         return tunneltype_str[i].type;
11215         }
11216         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11217 }
11218
11219 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11220 do { \
11221         if ((ip_addr).family == AF_INET) \
11222                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11223         else { \
11224                 printf("invalid parameter.\n"); \
11225                 return; \
11226         } \
11227 } while (0)
11228
11229 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11230 do { \
11231         if ((ip_addr).family == AF_INET6) \
11232                 rte_memcpy(&(ip), \
11233                                  &((ip_addr).addr.ipv6), \
11234                                  sizeof(struct in6_addr)); \
11235         else { \
11236                 printf("invalid parameter.\n"); \
11237                 return; \
11238         } \
11239 } while (0)
11240
11241 static void
11242 cmd_flow_director_filter_parsed(void *parsed_result,
11243                           __rte_unused struct cmdline *cl,
11244                           __rte_unused void *data)
11245 {
11246         struct cmd_flow_director_result *res = parsed_result;
11247         struct rte_eth_fdir_filter entry;
11248         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11249         char *end;
11250         unsigned long vf_id;
11251         int ret = 0;
11252
11253         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11254         if (ret < 0) {
11255                 printf("flow director is not supported on port %u.\n",
11256                         res->port_id);
11257                 return;
11258         }
11259         memset(flexbytes, 0, sizeof(flexbytes));
11260         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11261
11262         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11263                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11264                         printf("Please set mode to MAC-VLAN.\n");
11265                         return;
11266                 }
11267         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11268                 if (strcmp(res->mode_value, "Tunnel")) {
11269                         printf("Please set mode to Tunnel.\n");
11270                         return;
11271                 }
11272         } else {
11273                 if (!strcmp(res->mode_value, "raw")) {
11274 #ifdef RTE_LIBRTE_I40E_PMD
11275                         struct rte_pmd_i40e_flow_type_mapping
11276                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11277                         struct rte_pmd_i40e_pkt_template_conf conf;
11278                         uint16_t flow_type = str2flowtype(res->flow_type);
11279                         uint16_t i, port = res->port_id;
11280                         uint8_t add;
11281
11282                         memset(&conf, 0, sizeof(conf));
11283
11284                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11285                                 printf("Invalid flow type specified.\n");
11286                                 return;
11287                         }
11288                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11289                                                                  mapping);
11290                         if (ret)
11291                                 return;
11292                         if (mapping[flow_type].pctype == 0ULL) {
11293                                 printf("Invalid flow type specified.\n");
11294                                 return;
11295                         }
11296                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11297                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11298                                         conf.input.pctype = i;
11299                                         break;
11300                                 }
11301                         }
11302
11303                         conf.input.packet = open_file(res->filepath,
11304                                                 &conf.input.length);
11305                         if (!conf.input.packet)
11306                                 return;
11307                         if (!strcmp(res->drop, "drop"))
11308                                 conf.action.behavior =
11309                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11310                         else
11311                                 conf.action.behavior =
11312                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11313                         conf.action.report_status =
11314                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11315                         conf.action.rx_queue = res->queue_id;
11316                         conf.soft_id = res->fd_id_value;
11317                         add  = strcmp(res->ops, "del") ? 1 : 0;
11318                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11319                                                                         &conf,
11320                                                                         add);
11321                         if (ret < 0)
11322                                 printf("flow director config error: (%s)\n",
11323                                        strerror(-ret));
11324                         close_file(conf.input.packet);
11325 #endif
11326                         return;
11327                 } else if (strcmp(res->mode_value, "IP")) {
11328                         printf("Please set mode to IP or raw.\n");
11329                         return;
11330                 }
11331                 entry.input.flow_type = str2flowtype(res->flow_type);
11332         }
11333
11334         ret = parse_flexbytes(res->flexbytes_value,
11335                                         flexbytes,
11336                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11337         if (ret < 0) {
11338                 printf("error: Cannot parse flexbytes input.\n");
11339                 return;
11340         }
11341
11342         switch (entry.input.flow_type) {
11343         case RTE_ETH_FLOW_FRAG_IPV4:
11344         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11345                 entry.input.flow.ip4_flow.proto = res->proto_value;
11346                 /* fall-through */
11347         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11348         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11349                 IPV4_ADDR_TO_UINT(res->ip_dst,
11350                         entry.input.flow.ip4_flow.dst_ip);
11351                 IPV4_ADDR_TO_UINT(res->ip_src,
11352                         entry.input.flow.ip4_flow.src_ip);
11353                 entry.input.flow.ip4_flow.tos = res->tos_value;
11354                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11355                 /* need convert to big endian. */
11356                 entry.input.flow.udp4_flow.dst_port =
11357                                 rte_cpu_to_be_16(res->port_dst);
11358                 entry.input.flow.udp4_flow.src_port =
11359                                 rte_cpu_to_be_16(res->port_src);
11360                 break;
11361         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11362                 IPV4_ADDR_TO_UINT(res->ip_dst,
11363                         entry.input.flow.sctp4_flow.ip.dst_ip);
11364                 IPV4_ADDR_TO_UINT(res->ip_src,
11365                         entry.input.flow.sctp4_flow.ip.src_ip);
11366                 entry.input.flow.ip4_flow.tos = res->tos_value;
11367                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11368                 /* need convert to big endian. */
11369                 entry.input.flow.sctp4_flow.dst_port =
11370                                 rte_cpu_to_be_16(res->port_dst);
11371                 entry.input.flow.sctp4_flow.src_port =
11372                                 rte_cpu_to_be_16(res->port_src);
11373                 entry.input.flow.sctp4_flow.verify_tag =
11374                                 rte_cpu_to_be_32(res->verify_tag_value);
11375                 break;
11376         case RTE_ETH_FLOW_FRAG_IPV6:
11377         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11378                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11379                 /* fall-through */
11380         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11381         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11382                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11383                         entry.input.flow.ipv6_flow.dst_ip);
11384                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11385                         entry.input.flow.ipv6_flow.src_ip);
11386                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11387                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11388                 /* need convert to big endian. */
11389                 entry.input.flow.udp6_flow.dst_port =
11390                                 rte_cpu_to_be_16(res->port_dst);
11391                 entry.input.flow.udp6_flow.src_port =
11392                                 rte_cpu_to_be_16(res->port_src);
11393                 break;
11394         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11395                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11396                         entry.input.flow.sctp6_flow.ip.dst_ip);
11397                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11398                         entry.input.flow.sctp6_flow.ip.src_ip);
11399                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11400                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11401                 /* need convert to big endian. */
11402                 entry.input.flow.sctp6_flow.dst_port =
11403                                 rte_cpu_to_be_16(res->port_dst);
11404                 entry.input.flow.sctp6_flow.src_port =
11405                                 rte_cpu_to_be_16(res->port_src);
11406                 entry.input.flow.sctp6_flow.verify_tag =
11407                                 rte_cpu_to_be_32(res->verify_tag_value);
11408                 break;
11409         case RTE_ETH_FLOW_L2_PAYLOAD:
11410                 entry.input.flow.l2_flow.ether_type =
11411                         rte_cpu_to_be_16(res->ether_type);
11412                 break;
11413         default:
11414                 break;
11415         }
11416
11417         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11418                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11419                                  &res->mac_addr,
11420                                  sizeof(struct rte_ether_addr));
11421
11422         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11423                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11424                                  &res->mac_addr,
11425                                  sizeof(struct rte_ether_addr));
11426                 entry.input.flow.tunnel_flow.tunnel_type =
11427                         str2fdir_tunneltype(res->tunnel_type);
11428                 entry.input.flow.tunnel_flow.tunnel_id =
11429                         rte_cpu_to_be_32(res->tunnel_id_value);
11430         }
11431
11432         rte_memcpy(entry.input.flow_ext.flexbytes,
11433                    flexbytes,
11434                    RTE_ETH_FDIR_MAX_FLEXLEN);
11435
11436         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11437
11438         entry.action.flex_off = 0;  /*use 0 by default */
11439         if (!strcmp(res->drop, "drop"))
11440                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11441         else
11442                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11443
11444         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11445             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11446                 if (!strcmp(res->pf_vf, "pf"))
11447                         entry.input.flow_ext.is_vf = 0;
11448                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11449                         struct rte_eth_dev_info dev_info;
11450
11451                         ret = eth_dev_info_get_print_err(res->port_id,
11452                                                 &dev_info);
11453                         if (ret != 0)
11454                                 return;
11455
11456                         errno = 0;
11457                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11458                         if (errno != 0 || *end != '\0' ||
11459                             vf_id >= dev_info.max_vfs) {
11460                                 printf("invalid parameter %s.\n", res->pf_vf);
11461                                 return;
11462                         }
11463                         entry.input.flow_ext.is_vf = 1;
11464                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11465                 } else {
11466                         printf("invalid parameter %s.\n", res->pf_vf);
11467                         return;
11468                 }
11469         }
11470
11471         /* set to report FD ID by default */
11472         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11473         entry.action.rx_queue = res->queue_id;
11474         entry.soft_id = res->fd_id_value;
11475         if (!strcmp(res->ops, "add"))
11476                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11477                                              RTE_ETH_FILTER_ADD, &entry);
11478         else if (!strcmp(res->ops, "del"))
11479                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11480                                              RTE_ETH_FILTER_DELETE, &entry);
11481         else
11482                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11483                                              RTE_ETH_FILTER_UPDATE, &entry);
11484         if (ret < 0)
11485                 printf("flow director programming error: (%s)\n",
11486                         strerror(-ret));
11487 }
11488
11489 cmdline_parse_token_string_t cmd_flow_director_filter =
11490         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11491                                  flow_director_filter, "flow_director_filter");
11492 cmdline_parse_token_num_t cmd_flow_director_port_id =
11493         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11494                               port_id, UINT16);
11495 cmdline_parse_token_string_t cmd_flow_director_ops =
11496         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11497                                  ops, "add#del#update");
11498 cmdline_parse_token_string_t cmd_flow_director_flow =
11499         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11500                                  flow, "flow");
11501 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11502         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11503                 flow_type, NULL);
11504 cmdline_parse_token_string_t cmd_flow_director_ether =
11505         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11506                                  ether, "ether");
11507 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11508         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11509                               ether_type, UINT16);
11510 cmdline_parse_token_string_t cmd_flow_director_src =
11511         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11512                                  src, "src");
11513 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11514         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11515                                  ip_src);
11516 cmdline_parse_token_num_t cmd_flow_director_port_src =
11517         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11518                               port_src, UINT16);
11519 cmdline_parse_token_string_t cmd_flow_director_dst =
11520         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11521                                  dst, "dst");
11522 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11523         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11524                                  ip_dst);
11525 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11526         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11527                               port_dst, UINT16);
11528 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11529         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11530                                   verify_tag, "verify_tag");
11531 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11532         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11533                               verify_tag_value, UINT32);
11534 cmdline_parse_token_string_t cmd_flow_director_tos =
11535         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11536                                  tos, "tos");
11537 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11538         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11539                               tos_value, UINT8);
11540 cmdline_parse_token_string_t cmd_flow_director_proto =
11541         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11542                                  proto, "proto");
11543 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11544         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11545                               proto_value, UINT8);
11546 cmdline_parse_token_string_t cmd_flow_director_ttl =
11547         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11548                                  ttl, "ttl");
11549 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11550         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11551                               ttl_value, UINT8);
11552 cmdline_parse_token_string_t cmd_flow_director_vlan =
11553         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11554                                  vlan, "vlan");
11555 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11556         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11557                               vlan_value, UINT16);
11558 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11559         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11560                                  flexbytes, "flexbytes");
11561 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11562         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11563                               flexbytes_value, NULL);
11564 cmdline_parse_token_string_t cmd_flow_director_drop =
11565         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11566                                  drop, "drop#fwd");
11567 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11568         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11569                               pf_vf, NULL);
11570 cmdline_parse_token_string_t cmd_flow_director_queue =
11571         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11572                                  queue, "queue");
11573 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11574         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11575                               queue_id, UINT16);
11576 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11578                                  fd_id, "fd_id");
11579 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11580         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11581                               fd_id_value, UINT32);
11582
11583 cmdline_parse_token_string_t cmd_flow_director_mode =
11584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11585                                  mode, "mode");
11586 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11587         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11588                                  mode_value, "IP");
11589 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11591                                  mode_value, "MAC-VLAN");
11592 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11593         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11594                                  mode_value, "Tunnel");
11595 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11597                                  mode_value, "raw");
11598 cmdline_parse_token_string_t cmd_flow_director_mac =
11599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11600                                  mac, "mac");
11601 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11602         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11603                                     mac_addr);
11604 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11606                                  tunnel, "tunnel");
11607 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11608         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11609                                  tunnel_type, "NVGRE#VxLAN");
11610 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11611         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11612                                  tunnel_id, "tunnel-id");
11613 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11614         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11615                               tunnel_id_value, UINT32);
11616 cmdline_parse_token_string_t cmd_flow_director_packet =
11617         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11618                                  packet, "packet");
11619 cmdline_parse_token_string_t cmd_flow_director_filepath =
11620         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11621                                  filepath, NULL);
11622
11623 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11624         .f = cmd_flow_director_filter_parsed,
11625         .data = NULL,
11626         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11627                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11628                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11629                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11630                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11631                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11632                 "fd_id <fd_id_value>: "
11633                 "Add or delete an ip flow director entry on NIC",
11634         .tokens = {
11635                 (void *)&cmd_flow_director_filter,
11636                 (void *)&cmd_flow_director_port_id,
11637                 (void *)&cmd_flow_director_mode,
11638                 (void *)&cmd_flow_director_mode_ip,
11639                 (void *)&cmd_flow_director_ops,
11640                 (void *)&cmd_flow_director_flow,
11641                 (void *)&cmd_flow_director_flow_type,
11642                 (void *)&cmd_flow_director_src,
11643                 (void *)&cmd_flow_director_ip_src,
11644                 (void *)&cmd_flow_director_dst,
11645                 (void *)&cmd_flow_director_ip_dst,
11646                 (void *)&cmd_flow_director_tos,
11647                 (void *)&cmd_flow_director_tos_value,
11648                 (void *)&cmd_flow_director_proto,
11649                 (void *)&cmd_flow_director_proto_value,
11650                 (void *)&cmd_flow_director_ttl,
11651                 (void *)&cmd_flow_director_ttl_value,
11652                 (void *)&cmd_flow_director_vlan,
11653                 (void *)&cmd_flow_director_vlan_value,
11654                 (void *)&cmd_flow_director_flexbytes,
11655                 (void *)&cmd_flow_director_flexbytes_value,
11656                 (void *)&cmd_flow_director_drop,
11657                 (void *)&cmd_flow_director_pf_vf,
11658                 (void *)&cmd_flow_director_queue,
11659                 (void *)&cmd_flow_director_queue_id,
11660                 (void *)&cmd_flow_director_fd_id,
11661                 (void *)&cmd_flow_director_fd_id_value,
11662                 NULL,
11663         },
11664 };
11665
11666 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11667         .f = cmd_flow_director_filter_parsed,
11668         .data = NULL,
11669         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11670                 "director entry on NIC",
11671         .tokens = {
11672                 (void *)&cmd_flow_director_filter,
11673                 (void *)&cmd_flow_director_port_id,
11674                 (void *)&cmd_flow_director_mode,
11675                 (void *)&cmd_flow_director_mode_ip,
11676                 (void *)&cmd_flow_director_ops,
11677                 (void *)&cmd_flow_director_flow,
11678                 (void *)&cmd_flow_director_flow_type,
11679                 (void *)&cmd_flow_director_src,
11680                 (void *)&cmd_flow_director_ip_src,
11681                 (void *)&cmd_flow_director_port_src,
11682                 (void *)&cmd_flow_director_dst,
11683                 (void *)&cmd_flow_director_ip_dst,
11684                 (void *)&cmd_flow_director_port_dst,
11685                 (void *)&cmd_flow_director_tos,
11686                 (void *)&cmd_flow_director_tos_value,
11687                 (void *)&cmd_flow_director_ttl,
11688                 (void *)&cmd_flow_director_ttl_value,
11689                 (void *)&cmd_flow_director_vlan,
11690                 (void *)&cmd_flow_director_vlan_value,
11691                 (void *)&cmd_flow_director_flexbytes,
11692                 (void *)&cmd_flow_director_flexbytes_value,
11693                 (void *)&cmd_flow_director_drop,
11694                 (void *)&cmd_flow_director_pf_vf,
11695                 (void *)&cmd_flow_director_queue,
11696                 (void *)&cmd_flow_director_queue_id,
11697                 (void *)&cmd_flow_director_fd_id,
11698                 (void *)&cmd_flow_director_fd_id_value,
11699                 NULL,
11700         },
11701 };
11702
11703 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11704         .f = cmd_flow_director_filter_parsed,
11705         .data = NULL,
11706         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11707                 "director entry on NIC",
11708         .tokens = {
11709                 (void *)&cmd_flow_director_filter,
11710                 (void *)&cmd_flow_director_port_id,
11711                 (void *)&cmd_flow_director_mode,
11712                 (void *)&cmd_flow_director_mode_ip,
11713                 (void *)&cmd_flow_director_ops,
11714                 (void *)&cmd_flow_director_flow,
11715                 (void *)&cmd_flow_director_flow_type,
11716                 (void *)&cmd_flow_director_src,
11717                 (void *)&cmd_flow_director_ip_src,
11718                 (void *)&cmd_flow_director_port_src,
11719                 (void *)&cmd_flow_director_dst,
11720                 (void *)&cmd_flow_director_ip_dst,
11721                 (void *)&cmd_flow_director_port_dst,
11722                 (void *)&cmd_flow_director_verify_tag,
11723                 (void *)&cmd_flow_director_verify_tag_value,
11724                 (void *)&cmd_flow_director_tos,
11725                 (void *)&cmd_flow_director_tos_value,
11726                 (void *)&cmd_flow_director_ttl,
11727                 (void *)&cmd_flow_director_ttl_value,
11728                 (void *)&cmd_flow_director_vlan,
11729                 (void *)&cmd_flow_director_vlan_value,
11730                 (void *)&cmd_flow_director_flexbytes,
11731                 (void *)&cmd_flow_director_flexbytes_value,
11732                 (void *)&cmd_flow_director_drop,
11733                 (void *)&cmd_flow_director_pf_vf,
11734                 (void *)&cmd_flow_director_queue,
11735                 (void *)&cmd_flow_director_queue_id,
11736                 (void *)&cmd_flow_director_fd_id,
11737                 (void *)&cmd_flow_director_fd_id_value,
11738                 NULL,
11739         },
11740 };
11741
11742 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11743         .f = cmd_flow_director_filter_parsed,
11744         .data = NULL,
11745         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11746                 "director entry on NIC",
11747         .tokens = {
11748                 (void *)&cmd_flow_director_filter,
11749                 (void *)&cmd_flow_director_port_id,
11750                 (void *)&cmd_flow_director_mode,
11751                 (void *)&cmd_flow_director_mode_ip,
11752                 (void *)&cmd_flow_director_ops,
11753                 (void *)&cmd_flow_director_flow,
11754                 (void *)&cmd_flow_director_flow_type,
11755                 (void *)&cmd_flow_director_ether,
11756                 (void *)&cmd_flow_director_ether_type,
11757                 (void *)&cmd_flow_director_flexbytes,
11758                 (void *)&cmd_flow_director_flexbytes_value,
11759                 (void *)&cmd_flow_director_drop,
11760                 (void *)&cmd_flow_director_pf_vf,
11761                 (void *)&cmd_flow_director_queue,
11762                 (void *)&cmd_flow_director_queue_id,
11763                 (void *)&cmd_flow_director_fd_id,
11764                 (void *)&cmd_flow_director_fd_id_value,
11765                 NULL,
11766         },
11767 };
11768
11769 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11770         .f = cmd_flow_director_filter_parsed,
11771         .data = NULL,
11772         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11773                 "director entry on NIC",
11774         .tokens = {
11775                 (void *)&cmd_flow_director_filter,
11776                 (void *)&cmd_flow_director_port_id,
11777                 (void *)&cmd_flow_director_mode,
11778                 (void *)&cmd_flow_director_mode_mac_vlan,
11779                 (void *)&cmd_flow_director_ops,
11780                 (void *)&cmd_flow_director_mac,
11781                 (void *)&cmd_flow_director_mac_addr,
11782                 (void *)&cmd_flow_director_vlan,
11783                 (void *)&cmd_flow_director_vlan_value,
11784                 (void *)&cmd_flow_director_flexbytes,
11785                 (void *)&cmd_flow_director_flexbytes_value,
11786                 (void *)&cmd_flow_director_drop,
11787                 (void *)&cmd_flow_director_queue,
11788                 (void *)&cmd_flow_director_queue_id,
11789                 (void *)&cmd_flow_director_fd_id,
11790                 (void *)&cmd_flow_director_fd_id_value,
11791                 NULL,
11792         },
11793 };
11794
11795 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11796         .f = cmd_flow_director_filter_parsed,
11797         .data = NULL,
11798         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11799                 "director entry on NIC",
11800         .tokens = {
11801                 (void *)&cmd_flow_director_filter,
11802                 (void *)&cmd_flow_director_port_id,
11803                 (void *)&cmd_flow_director_mode,
11804                 (void *)&cmd_flow_director_mode_tunnel,
11805                 (void *)&cmd_flow_director_ops,
11806                 (void *)&cmd_flow_director_mac,
11807                 (void *)&cmd_flow_director_mac_addr,
11808                 (void *)&cmd_flow_director_vlan,
11809                 (void *)&cmd_flow_director_vlan_value,
11810                 (void *)&cmd_flow_director_tunnel,
11811                 (void *)&cmd_flow_director_tunnel_type,
11812                 (void *)&cmd_flow_director_tunnel_id,
11813                 (void *)&cmd_flow_director_tunnel_id_value,
11814                 (void *)&cmd_flow_director_flexbytes,
11815                 (void *)&cmd_flow_director_flexbytes_value,
11816                 (void *)&cmd_flow_director_drop,
11817                 (void *)&cmd_flow_director_queue,
11818                 (void *)&cmd_flow_director_queue_id,
11819                 (void *)&cmd_flow_director_fd_id,
11820                 (void *)&cmd_flow_director_fd_id_value,
11821                 NULL,
11822         },
11823 };
11824
11825 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11826         .f = cmd_flow_director_filter_parsed,
11827         .data = NULL,
11828         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11829                 "director entry on NIC",
11830         .tokens = {
11831                 (void *)&cmd_flow_director_filter,
11832                 (void *)&cmd_flow_director_port_id,
11833                 (void *)&cmd_flow_director_mode,
11834                 (void *)&cmd_flow_director_mode_raw,
11835                 (void *)&cmd_flow_director_ops,
11836                 (void *)&cmd_flow_director_flow,
11837                 (void *)&cmd_flow_director_flow_type,
11838                 (void *)&cmd_flow_director_drop,
11839                 (void *)&cmd_flow_director_queue,
11840                 (void *)&cmd_flow_director_queue_id,
11841                 (void *)&cmd_flow_director_fd_id,
11842                 (void *)&cmd_flow_director_fd_id_value,
11843                 (void *)&cmd_flow_director_packet,
11844                 (void *)&cmd_flow_director_filepath,
11845                 NULL,
11846         },
11847 };
11848
11849 struct cmd_flush_flow_director_result {
11850         cmdline_fixed_string_t flush_flow_director;
11851         portid_t port_id;
11852 };
11853
11854 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11855         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11856                                  flush_flow_director, "flush_flow_director");
11857 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11858         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11859                               port_id, UINT16);
11860
11861 static void
11862 cmd_flush_flow_director_parsed(void *parsed_result,
11863                           __rte_unused struct cmdline *cl,
11864                           __rte_unused void *data)
11865 {
11866         struct cmd_flow_director_result *res = parsed_result;
11867         int ret = 0;
11868
11869         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11870         if (ret < 0) {
11871                 printf("flow director is not supported on port %u.\n",
11872                         res->port_id);
11873                 return;
11874         }
11875
11876         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11877                         RTE_ETH_FILTER_FLUSH, NULL);
11878         if (ret < 0)
11879                 printf("flow director table flushing error: (%s)\n",
11880                         strerror(-ret));
11881 }
11882
11883 cmdline_parse_inst_t cmd_flush_flow_director = {
11884         .f = cmd_flush_flow_director_parsed,
11885         .data = NULL,
11886         .help_str = "flush_flow_director <port_id>: "
11887                 "Flush all flow director entries of a device on NIC",
11888         .tokens = {
11889                 (void *)&cmd_flush_flow_director_flush,
11890                 (void *)&cmd_flush_flow_director_port_id,
11891                 NULL,
11892         },
11893 };
11894
11895 /* *** deal with flow director mask *** */
11896 struct cmd_flow_director_mask_result {
11897         cmdline_fixed_string_t flow_director_mask;
11898         portid_t port_id;
11899         cmdline_fixed_string_t mode;
11900         cmdline_fixed_string_t mode_value;
11901         cmdline_fixed_string_t vlan;
11902         uint16_t vlan_mask;
11903         cmdline_fixed_string_t src_mask;
11904         cmdline_ipaddr_t ipv4_src;
11905         cmdline_ipaddr_t ipv6_src;
11906         uint16_t port_src;
11907         cmdline_fixed_string_t dst_mask;
11908         cmdline_ipaddr_t ipv4_dst;
11909         cmdline_ipaddr_t ipv6_dst;
11910         uint16_t port_dst;
11911         cmdline_fixed_string_t mac;
11912         uint8_t mac_addr_byte_mask;
11913         cmdline_fixed_string_t tunnel_id;
11914         uint32_t tunnel_id_mask;
11915         cmdline_fixed_string_t tunnel_type;
11916         uint8_t tunnel_type_mask;
11917 };
11918
11919 static void
11920 cmd_flow_director_mask_parsed(void *parsed_result,
11921                           __rte_unused struct cmdline *cl,
11922                           __rte_unused void *data)
11923 {
11924         struct cmd_flow_director_mask_result *res = parsed_result;
11925         struct rte_eth_fdir_masks *mask;
11926         struct rte_port *port;
11927
11928         port = &ports[res->port_id];
11929         /** Check if the port is not started **/
11930         if (port->port_status != RTE_PORT_STOPPED) {
11931                 printf("Please stop port %d first\n", res->port_id);
11932                 return;
11933         }
11934
11935         mask = &port->dev_conf.fdir_conf.mask;
11936
11937         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11938                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11939                         printf("Please set mode to MAC-VLAN.\n");
11940                         return;
11941                 }
11942
11943                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11944         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11945                 if (strcmp(res->mode_value, "Tunnel")) {
11946                         printf("Please set mode to Tunnel.\n");
11947                         return;
11948                 }
11949
11950                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11951                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11952                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11953                 mask->tunnel_type_mask = res->tunnel_type_mask;
11954         } else {
11955                 if (strcmp(res->mode_value, "IP")) {
11956                         printf("Please set mode to IP.\n");
11957                         return;
11958                 }
11959
11960                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11961                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11962                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11963                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11964                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11965                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11966                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11967         }
11968
11969         cmd_reconfig_device_queue(res->port_id, 1, 1);
11970 }
11971
11972 cmdline_parse_token_string_t cmd_flow_director_mask =
11973         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11974                                  flow_director_mask, "flow_director_mask");
11975 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11976         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11977                               port_id, UINT16);
11978 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11979         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11980                                  vlan, "vlan");
11981 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11982         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11983                               vlan_mask, UINT16);
11984 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11985         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11986                                  src_mask, "src_mask");
11987 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11988         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11989                                  ipv4_src);
11990 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11991         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11992                                  ipv6_src);
11993 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11994         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11995                               port_src, UINT16);
11996 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11997         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11998                                  dst_mask, "dst_mask");
11999 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12000         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12001                                  ipv4_dst);
12002 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12003         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12004                                  ipv6_dst);
12005 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12006         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12007                               port_dst, UINT16);
12008
12009 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12010         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12011                                  mode, "mode");
12012 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12013         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12014                                  mode_value, "IP");
12015 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12016         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12017                                  mode_value, "MAC-VLAN");
12018 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12019         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12020                                  mode_value, "Tunnel");
12021 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12022         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12023                                  mac, "mac");
12024 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12025         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12026                               mac_addr_byte_mask, UINT8);
12027 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12028         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12029                                  tunnel_type, "tunnel-type");
12030 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12031         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12032                               tunnel_type_mask, UINT8);
12033 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12034         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12035                                  tunnel_id, "tunnel-id");
12036 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12037         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12038                               tunnel_id_mask, UINT32);
12039
12040 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12041         .f = cmd_flow_director_mask_parsed,
12042         .data = NULL,
12043         .help_str = "flow_director_mask ... : "
12044                 "Set IP mode flow director's mask on NIC",
12045         .tokens = {
12046                 (void *)&cmd_flow_director_mask,
12047                 (void *)&cmd_flow_director_mask_port_id,
12048                 (void *)&cmd_flow_director_mask_mode,
12049                 (void *)&cmd_flow_director_mask_mode_ip,
12050                 (void *)&cmd_flow_director_mask_vlan,
12051                 (void *)&cmd_flow_director_mask_vlan_value,
12052                 (void *)&cmd_flow_director_mask_src,
12053                 (void *)&cmd_flow_director_mask_ipv4_src,
12054                 (void *)&cmd_flow_director_mask_ipv6_src,
12055                 (void *)&cmd_flow_director_mask_port_src,
12056                 (void *)&cmd_flow_director_mask_dst,
12057                 (void *)&cmd_flow_director_mask_ipv4_dst,
12058                 (void *)&cmd_flow_director_mask_ipv6_dst,
12059                 (void *)&cmd_flow_director_mask_port_dst,
12060                 NULL,
12061         },
12062 };
12063
12064 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12065         .f = cmd_flow_director_mask_parsed,
12066         .data = NULL,
12067         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12068                 "flow director's mask on NIC",
12069         .tokens = {
12070                 (void *)&cmd_flow_director_mask,
12071                 (void *)&cmd_flow_director_mask_port_id,
12072                 (void *)&cmd_flow_director_mask_mode,
12073                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12074                 (void *)&cmd_flow_director_mask_vlan,
12075                 (void *)&cmd_flow_director_mask_vlan_value,
12076                 NULL,
12077         },
12078 };
12079
12080 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12081         .f = cmd_flow_director_mask_parsed,
12082         .data = NULL,
12083         .help_str = "flow_director_mask ... : Set tunnel mode "
12084                 "flow director's mask on NIC",
12085         .tokens = {
12086                 (void *)&cmd_flow_director_mask,
12087                 (void *)&cmd_flow_director_mask_port_id,
12088                 (void *)&cmd_flow_director_mask_mode,
12089                 (void *)&cmd_flow_director_mask_mode_tunnel,
12090                 (void *)&cmd_flow_director_mask_vlan,
12091                 (void *)&cmd_flow_director_mask_vlan_value,
12092                 (void *)&cmd_flow_director_mask_mac,
12093                 (void *)&cmd_flow_director_mask_mac_value,
12094                 (void *)&cmd_flow_director_mask_tunnel_type,
12095                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12096                 (void *)&cmd_flow_director_mask_tunnel_id,
12097                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12098                 NULL,
12099         },
12100 };
12101
12102 /* *** deal with flow director mask on flexible payload *** */
12103 struct cmd_flow_director_flex_mask_result {
12104         cmdline_fixed_string_t flow_director_flexmask;
12105         portid_t port_id;
12106         cmdline_fixed_string_t flow;
12107         cmdline_fixed_string_t flow_type;
12108         cmdline_fixed_string_t mask;
12109 };
12110
12111 static void
12112 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12113                           __rte_unused struct cmdline *cl,
12114                           __rte_unused void *data)
12115 {
12116         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12117         struct rte_eth_fdir_info fdir_info;
12118         struct rte_eth_fdir_flex_mask flex_mask;
12119         struct rte_port *port;
12120         uint64_t flow_type_mask;
12121         uint16_t i;
12122         int ret;
12123
12124         port = &ports[res->port_id];
12125         /** Check if the port is not started **/
12126         if (port->port_status != RTE_PORT_STOPPED) {
12127                 printf("Please stop port %d first\n", res->port_id);
12128                 return;
12129         }
12130
12131         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12132         ret = parse_flexbytes(res->mask,
12133                         flex_mask.mask,
12134                         RTE_ETH_FDIR_MAX_FLEXLEN);
12135         if (ret < 0) {
12136                 printf("error: Cannot parse mask input.\n");
12137                 return;
12138         }
12139
12140         memset(&fdir_info, 0, sizeof(fdir_info));
12141         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12142                                 RTE_ETH_FILTER_INFO, &fdir_info);
12143         if (ret < 0) {
12144                 printf("Cannot get FDir filter info\n");
12145                 return;
12146         }
12147
12148         if (!strcmp(res->flow_type, "none")) {
12149                 /* means don't specify the flow type */
12150                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12151                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12152                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12153                                0, sizeof(struct rte_eth_fdir_flex_mask));
12154                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12155                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12156                                  &flex_mask,
12157                                  sizeof(struct rte_eth_fdir_flex_mask));
12158                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12159                 return;
12160         }
12161         flow_type_mask = fdir_info.flow_types_mask[0];
12162         if (!strcmp(res->flow_type, "all")) {
12163                 if (!flow_type_mask) {
12164                         printf("No flow type supported\n");
12165                         return;
12166                 }
12167                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12168                         if (flow_type_mask & (1ULL << i)) {
12169                                 flex_mask.flow_type = i;
12170                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12171                         }
12172                 }
12173                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12174                 return;
12175         }
12176         flex_mask.flow_type = str2flowtype(res->flow_type);
12177         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12178                 printf("Flow type %s not supported on port %d\n",
12179                                 res->flow_type, res->port_id);
12180                 return;
12181         }
12182         fdir_set_flex_mask(res->port_id, &flex_mask);
12183         cmd_reconfig_device_queue(res->port_id, 1, 1);
12184 }
12185
12186 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12187         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12188                                  flow_director_flexmask,
12189                                  "flow_director_flex_mask");
12190 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12191         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12192                               port_id, UINT16);
12193 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12194         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12195                                  flow, "flow");
12196 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12197         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12198                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12199                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12200 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12202                                  mask, NULL);
12203
12204 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12205         .f = cmd_flow_director_flex_mask_parsed,
12206         .data = NULL,
12207         .help_str = "flow_director_flex_mask ... : "
12208                 "Set flow director's flex mask on NIC",
12209         .tokens = {
12210                 (void *)&cmd_flow_director_flexmask,
12211                 (void *)&cmd_flow_director_flexmask_port_id,
12212                 (void *)&cmd_flow_director_flexmask_flow,
12213                 (void *)&cmd_flow_director_flexmask_flow_type,
12214                 (void *)&cmd_flow_director_flexmask_mask,
12215                 NULL,
12216         },
12217 };
12218
12219 /* *** deal with flow director flexible payload configuration *** */
12220 struct cmd_flow_director_flexpayload_result {
12221         cmdline_fixed_string_t flow_director_flexpayload;
12222         portid_t port_id;
12223         cmdline_fixed_string_t payload_layer;
12224         cmdline_fixed_string_t payload_cfg;
12225 };
12226
12227 static inline int
12228 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12229 {
12230         char s[256];
12231         const char *p, *p0 = q_arg;
12232         char *end;
12233         unsigned long int_fld;
12234         char *str_fld[max_num];
12235         int i;
12236         unsigned size;
12237         int ret = -1;
12238
12239         p = strchr(p0, '(');
12240         if (p == NULL)
12241                 return -1;
12242         ++p;
12243         p0 = strchr(p, ')');
12244         if (p0 == NULL)
12245                 return -1;
12246
12247         size = p0 - p;
12248         if (size >= sizeof(s))
12249                 return -1;
12250
12251         snprintf(s, sizeof(s), "%.*s", size, p);
12252         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12253         if (ret < 0 || ret > max_num)
12254                 return -1;
12255         for (i = 0; i < ret; i++) {
12256                 errno = 0;
12257                 int_fld = strtoul(str_fld[i], &end, 0);
12258                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12259                         return -1;
12260                 offsets[i] = (uint16_t)int_fld;
12261         }
12262         return ret;
12263 }
12264
12265 static void
12266 cmd_flow_director_flxpld_parsed(void *parsed_result,
12267                           __rte_unused struct cmdline *cl,
12268                           __rte_unused void *data)
12269 {
12270         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12271         struct rte_eth_flex_payload_cfg flex_cfg;
12272         struct rte_port *port;
12273         int ret = 0;
12274
12275         port = &ports[res->port_id];
12276         /** Check if the port is not started **/
12277         if (port->port_status != RTE_PORT_STOPPED) {
12278                 printf("Please stop port %d first\n", res->port_id);
12279                 return;
12280         }
12281
12282         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12283
12284         if (!strcmp(res->payload_layer, "raw"))
12285                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12286         else if (!strcmp(res->payload_layer, "l2"))
12287                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12288         else if (!strcmp(res->payload_layer, "l3"))
12289                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12290         else if (!strcmp(res->payload_layer, "l4"))
12291                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12292
12293         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12294                             RTE_ETH_FDIR_MAX_FLEXLEN);
12295         if (ret < 0) {
12296                 printf("error: Cannot parse flex payload input.\n");
12297                 return;
12298         }
12299
12300         fdir_set_flex_payload(res->port_id, &flex_cfg);
12301         cmd_reconfig_device_queue(res->port_id, 1, 1);
12302 }
12303
12304 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12305         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12306                                  flow_director_flexpayload,
12307                                  "flow_director_flex_payload");
12308 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12309         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12310                               port_id, UINT16);
12311 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12312         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12313                                  payload_layer, "raw#l2#l3#l4");
12314 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12315         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12316                                  payload_cfg, NULL);
12317
12318 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12319         .f = cmd_flow_director_flxpld_parsed,
12320         .data = NULL,
12321         .help_str = "flow_director_flexpayload ... : "
12322                 "Set flow director's flex payload on NIC",
12323         .tokens = {
12324                 (void *)&cmd_flow_director_flexpayload,
12325                 (void *)&cmd_flow_director_flexpayload_port_id,
12326                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12327                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12328                 NULL,
12329         },
12330 };
12331
12332 /* Generic flow interface command. */
12333 extern cmdline_parse_inst_t cmd_flow;
12334
12335 /* *** Classification Filters Control *** */
12336 /* *** Get symmetric hash enable per port *** */
12337 struct cmd_get_sym_hash_ena_per_port_result {
12338         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12339         portid_t port_id;
12340 };
12341
12342 static void
12343 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12344                                  __rte_unused struct cmdline *cl,
12345                                  __rte_unused void *data)
12346 {
12347         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12348         struct rte_eth_hash_filter_info info;
12349         int ret;
12350
12351         if (rte_eth_dev_filter_supported(res->port_id,
12352                                 RTE_ETH_FILTER_HASH) < 0) {
12353                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12354                                                         res->port_id);
12355                 return;
12356         }
12357
12358         memset(&info, 0, sizeof(info));
12359         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12360         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12361                                                 RTE_ETH_FILTER_GET, &info);
12362
12363         if (ret < 0) {
12364                 printf("Cannot get symmetric hash enable per port "
12365                                         "on port %u\n", res->port_id);
12366                 return;
12367         }
12368
12369         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12370                                 "enabled" : "disabled", res->port_id);
12371 }
12372
12373 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12374         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12375                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12376 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12377         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12378                 port_id, UINT16);
12379
12380 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12381         .f = cmd_get_sym_hash_per_port_parsed,
12382         .data = NULL,
12383         .help_str = "get_sym_hash_ena_per_port <port_id>",
12384         .tokens = {
12385                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12386                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12387                 NULL,
12388         },
12389 };
12390
12391 /* *** Set symmetric hash enable per port *** */
12392 struct cmd_set_sym_hash_ena_per_port_result {
12393         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12394         cmdline_fixed_string_t enable;
12395         portid_t port_id;
12396 };
12397
12398 static void
12399 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12400                                  __rte_unused struct cmdline *cl,
12401                                  __rte_unused void *data)
12402 {
12403         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12404         struct rte_eth_hash_filter_info info;
12405         int ret;
12406
12407         if (rte_eth_dev_filter_supported(res->port_id,
12408                                 RTE_ETH_FILTER_HASH) < 0) {
12409                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12410                                                         res->port_id);
12411                 return;
12412         }
12413
12414         memset(&info, 0, sizeof(info));
12415         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12416         if (!strcmp(res->enable, "enable"))
12417                 info.info.enable = 1;
12418         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12419                                         RTE_ETH_FILTER_SET, &info);
12420         if (ret < 0) {
12421                 printf("Cannot set symmetric hash enable per port on "
12422                                         "port %u\n", res->port_id);
12423                 return;
12424         }
12425         printf("Symmetric hash has been set to %s on port %u\n",
12426                                         res->enable, res->port_id);
12427 }
12428
12429 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12430         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12431                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12432 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12433         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12434                 port_id, UINT16);
12435 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12436         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12437                 enable, "enable#disable");
12438
12439 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12440         .f = cmd_set_sym_hash_per_port_parsed,
12441         .data = NULL,
12442         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12443         .tokens = {
12444                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12445                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12446                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12447                 NULL,
12448         },
12449 };
12450
12451 /* Get global config of hash function */
12452 struct cmd_get_hash_global_config_result {
12453         cmdline_fixed_string_t get_hash_global_config;
12454         portid_t port_id;
12455 };
12456
12457 static char *
12458 flowtype_to_str(uint16_t ftype)
12459 {
12460         uint16_t i;
12461         static struct {
12462                 char str[16];
12463                 uint16_t ftype;
12464         } ftype_table[] = {
12465                 {"ipv4", RTE_ETH_FLOW_IPV4},
12466                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12467                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12468                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12469                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12470                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12471                 {"ipv6", RTE_ETH_FLOW_IPV6},
12472                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12473                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12474                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12475                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12476                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12477                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12478                 {"port", RTE_ETH_FLOW_PORT},
12479                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12480                 {"geneve", RTE_ETH_FLOW_GENEVE},
12481                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12482                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12483         };
12484
12485         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12486                 if (ftype_table[i].ftype == ftype)
12487                         return ftype_table[i].str;
12488         }
12489
12490         return NULL;
12491 }
12492
12493 static void
12494 cmd_get_hash_global_config_parsed(void *parsed_result,
12495                                   __rte_unused struct cmdline *cl,
12496                                   __rte_unused void *data)
12497 {
12498         struct cmd_get_hash_global_config_result *res = parsed_result;
12499         struct rte_eth_hash_filter_info info;
12500         uint32_t idx, offset;
12501         uint16_t i;
12502         char *str;
12503         int ret;
12504
12505         if (rte_eth_dev_filter_supported(res->port_id,
12506                         RTE_ETH_FILTER_HASH) < 0) {
12507                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12508                                                         res->port_id);
12509                 return;
12510         }
12511
12512         memset(&info, 0, sizeof(info));
12513         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12514         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12515                                         RTE_ETH_FILTER_GET, &info);
12516         if (ret < 0) {
12517                 printf("Cannot get hash global configurations by port %d\n",
12518                                                         res->port_id);
12519                 return;
12520         }
12521
12522         switch (info.info.global_conf.hash_func) {
12523         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12524                 printf("Hash function is Toeplitz\n");
12525                 break;
12526         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12527                 printf("Hash function is Simple XOR\n");
12528                 break;
12529         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12530                 printf("Hash function is Symmetric Toeplitz\n");
12531                 break;
12532         default:
12533                 printf("Unknown hash function\n");
12534                 break;
12535         }
12536
12537         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12538                 idx = i / UINT64_BIT;
12539                 offset = i % UINT64_BIT;
12540                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12541                                                 (1ULL << offset)))
12542                         continue;
12543                 str = flowtype_to_str(i);
12544                 if (!str)
12545                         continue;
12546                 printf("Symmetric hash is %s globally for flow type %s "
12547                                                         "by port %d\n",
12548                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12549                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12550                                                         res->port_id);
12551         }
12552 }
12553
12554 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12555         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12556                 get_hash_global_config, "get_hash_global_config");
12557 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12558         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12559                 port_id, UINT16);
12560
12561 cmdline_parse_inst_t cmd_get_hash_global_config = {
12562         .f = cmd_get_hash_global_config_parsed,
12563         .data = NULL,
12564         .help_str = "get_hash_global_config <port_id>",
12565         .tokens = {
12566                 (void *)&cmd_get_hash_global_config_all,
12567                 (void *)&cmd_get_hash_global_config_port_id,
12568                 NULL,
12569         },
12570 };
12571
12572 /* Set global config of hash function */
12573 struct cmd_set_hash_global_config_result {
12574         cmdline_fixed_string_t set_hash_global_config;
12575         portid_t port_id;
12576         cmdline_fixed_string_t hash_func;
12577         cmdline_fixed_string_t flow_type;
12578         cmdline_fixed_string_t enable;
12579 };
12580
12581 static void
12582 cmd_set_hash_global_config_parsed(void *parsed_result,
12583                                   __rte_unused struct cmdline *cl,
12584                                   __rte_unused void *data)
12585 {
12586         struct cmd_set_hash_global_config_result *res = parsed_result;
12587         struct rte_eth_hash_filter_info info;
12588         uint32_t ftype, idx, offset;
12589         int ret;
12590
12591         if (rte_eth_dev_filter_supported(res->port_id,
12592                                 RTE_ETH_FILTER_HASH) < 0) {
12593                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12594                                                         res->port_id);
12595                 return;
12596         }
12597         memset(&info, 0, sizeof(info));
12598         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12599         if (!strcmp(res->hash_func, "toeplitz"))
12600                 info.info.global_conf.hash_func =
12601                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12602         else if (!strcmp(res->hash_func, "simple_xor"))
12603                 info.info.global_conf.hash_func =
12604                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12605         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12606                 info.info.global_conf.hash_func =
12607                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12608         else if (!strcmp(res->hash_func, "default"))
12609                 info.info.global_conf.hash_func =
12610                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12611
12612         ftype = str2flowtype(res->flow_type);
12613         idx = ftype / UINT64_BIT;
12614         offset = ftype % UINT64_BIT;
12615         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12616         if (!strcmp(res->enable, "enable"))
12617                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12618                                                 (1ULL << offset);
12619         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12620                                         RTE_ETH_FILTER_SET, &info);
12621         if (ret < 0)
12622                 printf("Cannot set global hash configurations by port %d\n",
12623                                                         res->port_id);
12624         else
12625                 printf("Global hash configurations have been set "
12626                         "successfully by port %d\n", res->port_id);
12627 }
12628
12629 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12630         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12631                 set_hash_global_config, "set_hash_global_config");
12632 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12633         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12634                 port_id, UINT16);
12635 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12636         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12637                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12638 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12639         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12640                 flow_type,
12641                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12642                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12643 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12644         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12645                 enable, "enable#disable");
12646
12647 cmdline_parse_inst_t cmd_set_hash_global_config = {
12648         .f = cmd_set_hash_global_config_parsed,
12649         .data = NULL,
12650         .help_str = "set_hash_global_config <port_id> "
12651                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12652                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12653                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12654                 "l2_payload enable|disable",
12655         .tokens = {
12656                 (void *)&cmd_set_hash_global_config_all,
12657                 (void *)&cmd_set_hash_global_config_port_id,
12658                 (void *)&cmd_set_hash_global_config_hash_func,
12659                 (void *)&cmd_set_hash_global_config_flow_type,
12660                 (void *)&cmd_set_hash_global_config_enable,
12661                 NULL,
12662         },
12663 };
12664
12665 /* Set hash input set */
12666 struct cmd_set_hash_input_set_result {
12667         cmdline_fixed_string_t set_hash_input_set;
12668         portid_t port_id;
12669         cmdline_fixed_string_t flow_type;
12670         cmdline_fixed_string_t inset_field;
12671         cmdline_fixed_string_t select;
12672 };
12673
12674 static enum rte_eth_input_set_field
12675 str2inset(char *string)
12676 {
12677         uint16_t i;
12678
12679         static const struct {
12680                 char str[32];
12681                 enum rte_eth_input_set_field inset;
12682         } inset_table[] = {
12683                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12684                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12685                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12686                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12687                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12688                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12689                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12690                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12691                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12692                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12693                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12694                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12695                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12696                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12697                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12698                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12699                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12700                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12701                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12702                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12703                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12704                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12705                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12706                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12707                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12708                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12709                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12710                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12711                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12712                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12713                 {"none", RTE_ETH_INPUT_SET_NONE},
12714         };
12715
12716         for (i = 0; i < RTE_DIM(inset_table); i++) {
12717                 if (!strcmp(string, inset_table[i].str))
12718                         return inset_table[i].inset;
12719         }
12720
12721         return RTE_ETH_INPUT_SET_UNKNOWN;
12722 }
12723
12724 static void
12725 cmd_set_hash_input_set_parsed(void *parsed_result,
12726                               __rte_unused struct cmdline *cl,
12727                               __rte_unused void *data)
12728 {
12729         struct cmd_set_hash_input_set_result *res = parsed_result;
12730         struct rte_eth_hash_filter_info info;
12731
12732         memset(&info, 0, sizeof(info));
12733         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12734         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12735         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12736         info.info.input_set_conf.inset_size = 1;
12737         if (!strcmp(res->select, "select"))
12738                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12739         else if (!strcmp(res->select, "add"))
12740                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12741         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12742                                 RTE_ETH_FILTER_SET, &info);
12743 }
12744
12745 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12746         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12747                 set_hash_input_set, "set_hash_input_set");
12748 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12749         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12750                 port_id, UINT16);
12751 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12752         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12753                 flow_type, NULL);
12754 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12755         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12756                 inset_field,
12757                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12758                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12759                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12760                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12761                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12762                 "fld-8th#none");
12763 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12764         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12765                 select, "select#add");
12766
12767 cmdline_parse_inst_t cmd_set_hash_input_set = {
12768         .f = cmd_set_hash_input_set_parsed,
12769         .data = NULL,
12770         .help_str = "set_hash_input_set <port_id> "
12771         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12772         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12773         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12774         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12775         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12776         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12777         "fld-7th|fld-8th|none select|add",
12778         .tokens = {
12779                 (void *)&cmd_set_hash_input_set_cmd,
12780                 (void *)&cmd_set_hash_input_set_port_id,
12781                 (void *)&cmd_set_hash_input_set_flow_type,
12782                 (void *)&cmd_set_hash_input_set_field,
12783                 (void *)&cmd_set_hash_input_set_select,
12784                 NULL,
12785         },
12786 };
12787
12788 /* Set flow director input set */
12789 struct cmd_set_fdir_input_set_result {
12790         cmdline_fixed_string_t set_fdir_input_set;
12791         portid_t port_id;
12792         cmdline_fixed_string_t flow_type;
12793         cmdline_fixed_string_t inset_field;
12794         cmdline_fixed_string_t select;
12795 };
12796
12797 static void
12798 cmd_set_fdir_input_set_parsed(void *parsed_result,
12799         __rte_unused struct cmdline *cl,
12800         __rte_unused void *data)
12801 {
12802         struct cmd_set_fdir_input_set_result *res = parsed_result;
12803         struct rte_eth_fdir_filter_info info;
12804
12805         memset(&info, 0, sizeof(info));
12806         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12807         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12808         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12809         info.info.input_set_conf.inset_size = 1;
12810         if (!strcmp(res->select, "select"))
12811                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12812         else if (!strcmp(res->select, "add"))
12813                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12814         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12815                 RTE_ETH_FILTER_SET, &info);
12816 }
12817
12818 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12819         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12820         set_fdir_input_set, "set_fdir_input_set");
12821 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12822         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12823         port_id, UINT16);
12824 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12825         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12826         flow_type,
12827         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12828         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12829 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12830         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12831         inset_field,
12832         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12833         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12834         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12835         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12836         "sctp-veri-tag#none");
12837 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12838         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12839         select, "select#add");
12840
12841 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12842         .f = cmd_set_fdir_input_set_parsed,
12843         .data = NULL,
12844         .help_str = "set_fdir_input_set <port_id> "
12845         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12846         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12847         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12848         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12849         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12850         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12851         "sctp-veri-tag|none select|add",
12852         .tokens = {
12853                 (void *)&cmd_set_fdir_input_set_cmd,
12854                 (void *)&cmd_set_fdir_input_set_port_id,
12855                 (void *)&cmd_set_fdir_input_set_flow_type,
12856                 (void *)&cmd_set_fdir_input_set_field,
12857                 (void *)&cmd_set_fdir_input_set_select,
12858                 NULL,
12859         },
12860 };
12861
12862 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12863 struct cmd_mcast_addr_result {
12864         cmdline_fixed_string_t mcast_addr_cmd;
12865         cmdline_fixed_string_t what;
12866         uint16_t port_num;
12867         struct rte_ether_addr mc_addr;
12868 };
12869
12870 static void cmd_mcast_addr_parsed(void *parsed_result,
12871                 __rte_unused struct cmdline *cl,
12872                 __rte_unused void *data)
12873 {
12874         struct cmd_mcast_addr_result *res = parsed_result;
12875
12876         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12877                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12878                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12879                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12880                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12881                 return;
12882         }
12883         if (strcmp(res->what, "add") == 0)
12884                 mcast_addr_add(res->port_num, &res->mc_addr);
12885         else
12886                 mcast_addr_remove(res->port_num, &res->mc_addr);
12887 }
12888
12889 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12890         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12891                                  mcast_addr_cmd, "mcast_addr");
12892 cmdline_parse_token_string_t cmd_mcast_addr_what =
12893         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12894                                  "add#remove");
12895 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12896         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12897 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12898         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12899
12900 cmdline_parse_inst_t cmd_mcast_addr = {
12901         .f = cmd_mcast_addr_parsed,
12902         .data = (void *)0,
12903         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12904                 "Add/Remove multicast MAC address on port_id",
12905         .tokens = {
12906                 (void *)&cmd_mcast_addr_cmd,
12907                 (void *)&cmd_mcast_addr_what,
12908                 (void *)&cmd_mcast_addr_portnum,
12909                 (void *)&cmd_mcast_addr_addr,
12910                 NULL,
12911         },
12912 };
12913
12914 /* l2 tunnel config
12915  * only support E-tag now.
12916  */
12917
12918 /* Ether type config */
12919 struct cmd_config_l2_tunnel_eth_type_result {
12920         cmdline_fixed_string_t port;
12921         cmdline_fixed_string_t config;
12922         cmdline_fixed_string_t all;
12923         portid_t id;
12924         cmdline_fixed_string_t l2_tunnel;
12925         cmdline_fixed_string_t l2_tunnel_type;
12926         cmdline_fixed_string_t eth_type;
12927         uint16_t eth_type_val;
12928 };
12929
12930 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12931         TOKEN_STRING_INITIALIZER
12932                 (struct cmd_config_l2_tunnel_eth_type_result,
12933                  port, "port");
12934 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12935         TOKEN_STRING_INITIALIZER
12936                 (struct cmd_config_l2_tunnel_eth_type_result,
12937                  config, "config");
12938 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12939         TOKEN_STRING_INITIALIZER
12940                 (struct cmd_config_l2_tunnel_eth_type_result,
12941                  all, "all");
12942 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12943         TOKEN_NUM_INITIALIZER
12944                 (struct cmd_config_l2_tunnel_eth_type_result,
12945                  id, UINT16);
12946 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_config_l2_tunnel_eth_type_result,
12949                  l2_tunnel, "l2-tunnel");
12950 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12951         TOKEN_STRING_INITIALIZER
12952                 (struct cmd_config_l2_tunnel_eth_type_result,
12953                  l2_tunnel_type, "E-tag");
12954 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12955         TOKEN_STRING_INITIALIZER
12956                 (struct cmd_config_l2_tunnel_eth_type_result,
12957                  eth_type, "ether-type");
12958 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12959         TOKEN_NUM_INITIALIZER
12960                 (struct cmd_config_l2_tunnel_eth_type_result,
12961                  eth_type_val, UINT16);
12962
12963 static enum rte_eth_tunnel_type
12964 str2fdir_l2_tunnel_type(char *string)
12965 {
12966         uint32_t i = 0;
12967
12968         static const struct {
12969                 char str[32];
12970                 enum rte_eth_tunnel_type type;
12971         } l2_tunnel_type_str[] = {
12972                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12973         };
12974
12975         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12976                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12977                         return l2_tunnel_type_str[i].type;
12978         }
12979         return RTE_TUNNEL_TYPE_NONE;
12980 }
12981
12982 /* ether type config for all ports */
12983 static void
12984 cmd_config_l2_tunnel_eth_type_all_parsed
12985         (void *parsed_result,
12986          __rte_unused struct cmdline *cl,
12987          __rte_unused void *data)
12988 {
12989         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12990         struct rte_eth_l2_tunnel_conf entry;
12991         portid_t pid;
12992
12993         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
12994         entry.ether_type = res->eth_type_val;
12995
12996         RTE_ETH_FOREACH_DEV(pid) {
12997                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
12998         }
12999 }
13000
13001 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13002         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13003         .data = NULL,
13004         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13005         .tokens = {
13006                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13007                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13008                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13009                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13010                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13011                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13012                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13013                 NULL,
13014         },
13015 };
13016
13017 /* ether type config for a specific port */
13018 static void
13019 cmd_config_l2_tunnel_eth_type_specific_parsed(
13020         void *parsed_result,
13021         __rte_unused struct cmdline *cl,
13022         __rte_unused void *data)
13023 {
13024         struct cmd_config_l2_tunnel_eth_type_result *res =
13025                  parsed_result;
13026         struct rte_eth_l2_tunnel_conf entry;
13027
13028         if (port_id_is_invalid(res->id, ENABLED_WARN))
13029                 return;
13030
13031         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13032         entry.ether_type = res->eth_type_val;
13033
13034         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13035 }
13036
13037 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13038         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13039         .data = NULL,
13040         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13041         .tokens = {
13042                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13043                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13044                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13045                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13046                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13047                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13048                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13049                 NULL,
13050         },
13051 };
13052
13053 /* Enable/disable l2 tunnel */
13054 struct cmd_config_l2_tunnel_en_dis_result {
13055         cmdline_fixed_string_t port;
13056         cmdline_fixed_string_t config;
13057         cmdline_fixed_string_t all;
13058         portid_t id;
13059         cmdline_fixed_string_t l2_tunnel;
13060         cmdline_fixed_string_t l2_tunnel_type;
13061         cmdline_fixed_string_t en_dis;
13062 };
13063
13064 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13065         TOKEN_STRING_INITIALIZER
13066                 (struct cmd_config_l2_tunnel_en_dis_result,
13067                  port, "port");
13068 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13069         TOKEN_STRING_INITIALIZER
13070                 (struct cmd_config_l2_tunnel_en_dis_result,
13071                  config, "config");
13072 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13073         TOKEN_STRING_INITIALIZER
13074                 (struct cmd_config_l2_tunnel_en_dis_result,
13075                  all, "all");
13076 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13077         TOKEN_NUM_INITIALIZER
13078                 (struct cmd_config_l2_tunnel_en_dis_result,
13079                  id, UINT16);
13080 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13081         TOKEN_STRING_INITIALIZER
13082                 (struct cmd_config_l2_tunnel_en_dis_result,
13083                  l2_tunnel, "l2-tunnel");
13084 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13085         TOKEN_STRING_INITIALIZER
13086                 (struct cmd_config_l2_tunnel_en_dis_result,
13087                  l2_tunnel_type, "E-tag");
13088 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13089         TOKEN_STRING_INITIALIZER
13090                 (struct cmd_config_l2_tunnel_en_dis_result,
13091                  en_dis, "enable#disable");
13092
13093 /* enable/disable l2 tunnel for all ports */
13094 static void
13095 cmd_config_l2_tunnel_en_dis_all_parsed(
13096         void *parsed_result,
13097         __rte_unused struct cmdline *cl,
13098         __rte_unused void *data)
13099 {
13100         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13101         struct rte_eth_l2_tunnel_conf entry;
13102         portid_t pid;
13103         uint8_t en;
13104
13105         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13106
13107         if (!strcmp("enable", res->en_dis))
13108                 en = 1;
13109         else
13110                 en = 0;
13111
13112         RTE_ETH_FOREACH_DEV(pid) {
13113                 rte_eth_dev_l2_tunnel_offload_set(pid,
13114                                                   &entry,
13115                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13116                                                   en);
13117         }
13118 }
13119
13120 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13121         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13122         .data = NULL,
13123         .help_str = "port config all l2-tunnel E-tag enable|disable",
13124         .tokens = {
13125                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13126                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13127                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13128                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13129                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13130                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13131                 NULL,
13132         },
13133 };
13134
13135 /* enable/disable l2 tunnel for a port */
13136 static void
13137 cmd_config_l2_tunnel_en_dis_specific_parsed(
13138         void *parsed_result,
13139         __rte_unused struct cmdline *cl,
13140         __rte_unused void *data)
13141 {
13142         struct cmd_config_l2_tunnel_en_dis_result *res =
13143                 parsed_result;
13144         struct rte_eth_l2_tunnel_conf entry;
13145
13146         if (port_id_is_invalid(res->id, ENABLED_WARN))
13147                 return;
13148
13149         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13150
13151         if (!strcmp("enable", res->en_dis))
13152                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13153                                                   &entry,
13154                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13155                                                   1);
13156         else
13157                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13158                                                   &entry,
13159                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13160                                                   0);
13161 }
13162
13163 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13164         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13165         .data = NULL,
13166         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13167         .tokens = {
13168                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13169                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13170                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13171                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13172                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13173                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13174                 NULL,
13175         },
13176 };
13177
13178 /* E-tag configuration */
13179
13180 /* Common result structure for all E-tag configuration */
13181 struct cmd_config_e_tag_result {
13182         cmdline_fixed_string_t e_tag;
13183         cmdline_fixed_string_t set;
13184         cmdline_fixed_string_t insertion;
13185         cmdline_fixed_string_t stripping;
13186         cmdline_fixed_string_t forwarding;
13187         cmdline_fixed_string_t filter;
13188         cmdline_fixed_string_t add;
13189         cmdline_fixed_string_t del;
13190         cmdline_fixed_string_t on;
13191         cmdline_fixed_string_t off;
13192         cmdline_fixed_string_t on_off;
13193         cmdline_fixed_string_t port_tag_id;
13194         uint32_t port_tag_id_val;
13195         cmdline_fixed_string_t e_tag_id;
13196         uint16_t e_tag_id_val;
13197         cmdline_fixed_string_t dst_pool;
13198         uint8_t dst_pool_val;
13199         cmdline_fixed_string_t port;
13200         portid_t port_id;
13201         cmdline_fixed_string_t vf;
13202         uint8_t vf_id;
13203 };
13204
13205 /* Common CLI fields for all E-tag configuration */
13206 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13207         TOKEN_STRING_INITIALIZER
13208                 (struct cmd_config_e_tag_result,
13209                  e_tag, "E-tag");
13210 cmdline_parse_token_string_t cmd_config_e_tag_set =
13211         TOKEN_STRING_INITIALIZER
13212                 (struct cmd_config_e_tag_result,
13213                  set, "set");
13214 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13215         TOKEN_STRING_INITIALIZER
13216                 (struct cmd_config_e_tag_result,
13217                  insertion, "insertion");
13218 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13219         TOKEN_STRING_INITIALIZER
13220                 (struct cmd_config_e_tag_result,
13221                  stripping, "stripping");
13222 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13223         TOKEN_STRING_INITIALIZER
13224                 (struct cmd_config_e_tag_result,
13225                  forwarding, "forwarding");
13226 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13227         TOKEN_STRING_INITIALIZER
13228                 (struct cmd_config_e_tag_result,
13229                  filter, "filter");
13230 cmdline_parse_token_string_t cmd_config_e_tag_add =
13231         TOKEN_STRING_INITIALIZER
13232                 (struct cmd_config_e_tag_result,
13233                  add, "add");
13234 cmdline_parse_token_string_t cmd_config_e_tag_del =
13235         TOKEN_STRING_INITIALIZER
13236                 (struct cmd_config_e_tag_result,
13237                  del, "del");
13238 cmdline_parse_token_string_t cmd_config_e_tag_on =
13239         TOKEN_STRING_INITIALIZER
13240                 (struct cmd_config_e_tag_result,
13241                  on, "on");
13242 cmdline_parse_token_string_t cmd_config_e_tag_off =
13243         TOKEN_STRING_INITIALIZER
13244                 (struct cmd_config_e_tag_result,
13245                  off, "off");
13246 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13247         TOKEN_STRING_INITIALIZER
13248                 (struct cmd_config_e_tag_result,
13249                  on_off, "on#off");
13250 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13251         TOKEN_STRING_INITIALIZER
13252                 (struct cmd_config_e_tag_result,
13253                  port_tag_id, "port-tag-id");
13254 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13255         TOKEN_NUM_INITIALIZER
13256                 (struct cmd_config_e_tag_result,
13257                  port_tag_id_val, UINT32);
13258 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13259         TOKEN_STRING_INITIALIZER
13260                 (struct cmd_config_e_tag_result,
13261                  e_tag_id, "e-tag-id");
13262 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13263         TOKEN_NUM_INITIALIZER
13264                 (struct cmd_config_e_tag_result,
13265                  e_tag_id_val, UINT16);
13266 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13267         TOKEN_STRING_INITIALIZER
13268                 (struct cmd_config_e_tag_result,
13269                  dst_pool, "dst-pool");
13270 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13271         TOKEN_NUM_INITIALIZER
13272                 (struct cmd_config_e_tag_result,
13273                  dst_pool_val, UINT8);
13274 cmdline_parse_token_string_t cmd_config_e_tag_port =
13275         TOKEN_STRING_INITIALIZER
13276                 (struct cmd_config_e_tag_result,
13277                  port, "port");
13278 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13279         TOKEN_NUM_INITIALIZER
13280                 (struct cmd_config_e_tag_result,
13281                  port_id, UINT16);
13282 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13283         TOKEN_STRING_INITIALIZER
13284                 (struct cmd_config_e_tag_result,
13285                  vf, "vf");
13286 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13287         TOKEN_NUM_INITIALIZER
13288                 (struct cmd_config_e_tag_result,
13289                  vf_id, UINT8);
13290
13291 /* E-tag insertion configuration */
13292 static void
13293 cmd_config_e_tag_insertion_en_parsed(
13294         void *parsed_result,
13295         __rte_unused struct cmdline *cl,
13296         __rte_unused void *data)
13297 {
13298         struct cmd_config_e_tag_result *res =
13299                 parsed_result;
13300         struct rte_eth_l2_tunnel_conf entry;
13301
13302         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13303                 return;
13304
13305         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13306         entry.tunnel_id = res->port_tag_id_val;
13307         entry.vf_id = res->vf_id;
13308         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13309                                           &entry,
13310                                           ETH_L2_TUNNEL_INSERTION_MASK,
13311                                           1);
13312 }
13313
13314 static void
13315 cmd_config_e_tag_insertion_dis_parsed(
13316         void *parsed_result,
13317         __rte_unused struct cmdline *cl,
13318         __rte_unused void *data)
13319 {
13320         struct cmd_config_e_tag_result *res =
13321                 parsed_result;
13322         struct rte_eth_l2_tunnel_conf entry;
13323
13324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13325                 return;
13326
13327         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13328         entry.vf_id = res->vf_id;
13329
13330         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13331                                           &entry,
13332                                           ETH_L2_TUNNEL_INSERTION_MASK,
13333                                           0);
13334 }
13335
13336 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13337         .f = cmd_config_e_tag_insertion_en_parsed,
13338         .data = NULL,
13339         .help_str = "E-tag ... : E-tag insertion enable",
13340         .tokens = {
13341                 (void *)&cmd_config_e_tag_e_tag,
13342                 (void *)&cmd_config_e_tag_set,
13343                 (void *)&cmd_config_e_tag_insertion,
13344                 (void *)&cmd_config_e_tag_on,
13345                 (void *)&cmd_config_e_tag_port_tag_id,
13346                 (void *)&cmd_config_e_tag_port_tag_id_val,
13347                 (void *)&cmd_config_e_tag_port,
13348                 (void *)&cmd_config_e_tag_port_id,
13349                 (void *)&cmd_config_e_tag_vf,
13350                 (void *)&cmd_config_e_tag_vf_id,
13351                 NULL,
13352         },
13353 };
13354
13355 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13356         .f = cmd_config_e_tag_insertion_dis_parsed,
13357         .data = NULL,
13358         .help_str = "E-tag ... : E-tag insertion disable",
13359         .tokens = {
13360                 (void *)&cmd_config_e_tag_e_tag,
13361                 (void *)&cmd_config_e_tag_set,
13362                 (void *)&cmd_config_e_tag_insertion,
13363                 (void *)&cmd_config_e_tag_off,
13364                 (void *)&cmd_config_e_tag_port,
13365                 (void *)&cmd_config_e_tag_port_id,
13366                 (void *)&cmd_config_e_tag_vf,
13367                 (void *)&cmd_config_e_tag_vf_id,
13368                 NULL,
13369         },
13370 };
13371
13372 /* E-tag stripping configuration */
13373 static void
13374 cmd_config_e_tag_stripping_parsed(
13375         void *parsed_result,
13376         __rte_unused struct cmdline *cl,
13377         __rte_unused void *data)
13378 {
13379         struct cmd_config_e_tag_result *res =
13380                 parsed_result;
13381         struct rte_eth_l2_tunnel_conf entry;
13382
13383         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13384                 return;
13385
13386         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13387
13388         if (!strcmp(res->on_off, "on"))
13389                 rte_eth_dev_l2_tunnel_offload_set
13390                         (res->port_id,
13391                          &entry,
13392                          ETH_L2_TUNNEL_STRIPPING_MASK,
13393                          1);
13394         else
13395                 rte_eth_dev_l2_tunnel_offload_set
13396                         (res->port_id,
13397                          &entry,
13398                          ETH_L2_TUNNEL_STRIPPING_MASK,
13399                          0);
13400 }
13401
13402 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13403         .f = cmd_config_e_tag_stripping_parsed,
13404         .data = NULL,
13405         .help_str = "E-tag ... : E-tag stripping enable/disable",
13406         .tokens = {
13407                 (void *)&cmd_config_e_tag_e_tag,
13408                 (void *)&cmd_config_e_tag_set,
13409                 (void *)&cmd_config_e_tag_stripping,
13410                 (void *)&cmd_config_e_tag_on_off,
13411                 (void *)&cmd_config_e_tag_port,
13412                 (void *)&cmd_config_e_tag_port_id,
13413                 NULL,
13414         },
13415 };
13416
13417 /* E-tag forwarding configuration */
13418 static void
13419 cmd_config_e_tag_forwarding_parsed(
13420         void *parsed_result,
13421         __rte_unused struct cmdline *cl,
13422         __rte_unused void *data)
13423 {
13424         struct cmd_config_e_tag_result *res = parsed_result;
13425         struct rte_eth_l2_tunnel_conf entry;
13426
13427         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13428                 return;
13429
13430         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13431
13432         if (!strcmp(res->on_off, "on"))
13433                 rte_eth_dev_l2_tunnel_offload_set
13434                         (res->port_id,
13435                          &entry,
13436                          ETH_L2_TUNNEL_FORWARDING_MASK,
13437                          1);
13438         else
13439                 rte_eth_dev_l2_tunnel_offload_set
13440                         (res->port_id,
13441                          &entry,
13442                          ETH_L2_TUNNEL_FORWARDING_MASK,
13443                          0);
13444 }
13445
13446 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13447         .f = cmd_config_e_tag_forwarding_parsed,
13448         .data = NULL,
13449         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13450         .tokens = {
13451                 (void *)&cmd_config_e_tag_e_tag,
13452                 (void *)&cmd_config_e_tag_set,
13453                 (void *)&cmd_config_e_tag_forwarding,
13454                 (void *)&cmd_config_e_tag_on_off,
13455                 (void *)&cmd_config_e_tag_port,
13456                 (void *)&cmd_config_e_tag_port_id,
13457                 NULL,
13458         },
13459 };
13460
13461 /* E-tag filter configuration */
13462 static void
13463 cmd_config_e_tag_filter_add_parsed(
13464         void *parsed_result,
13465         __rte_unused struct cmdline *cl,
13466         __rte_unused void *data)
13467 {
13468         struct cmd_config_e_tag_result *res = parsed_result;
13469         struct rte_eth_l2_tunnel_conf entry;
13470         int ret = 0;
13471
13472         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13473                 return;
13474
13475         if (res->e_tag_id_val > 0x3fff) {
13476                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13477                 return;
13478         }
13479
13480         ret = rte_eth_dev_filter_supported(res->port_id,
13481                                            RTE_ETH_FILTER_L2_TUNNEL);
13482         if (ret < 0) {
13483                 printf("E-tag filter is not supported on port %u.\n",
13484                        res->port_id);
13485                 return;
13486         }
13487
13488         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13489         entry.tunnel_id = res->e_tag_id_val;
13490         entry.pool = res->dst_pool_val;
13491
13492         ret = rte_eth_dev_filter_ctrl(res->port_id,
13493                                       RTE_ETH_FILTER_L2_TUNNEL,
13494                                       RTE_ETH_FILTER_ADD,
13495                                       &entry);
13496         if (ret < 0)
13497                 printf("E-tag filter programming error: (%s)\n",
13498                        strerror(-ret));
13499 }
13500
13501 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13502         .f = cmd_config_e_tag_filter_add_parsed,
13503         .data = NULL,
13504         .help_str = "E-tag ... : E-tag filter add",
13505         .tokens = {
13506                 (void *)&cmd_config_e_tag_e_tag,
13507                 (void *)&cmd_config_e_tag_set,
13508                 (void *)&cmd_config_e_tag_filter,
13509                 (void *)&cmd_config_e_tag_add,
13510                 (void *)&cmd_config_e_tag_e_tag_id,
13511                 (void *)&cmd_config_e_tag_e_tag_id_val,
13512                 (void *)&cmd_config_e_tag_dst_pool,
13513                 (void *)&cmd_config_e_tag_dst_pool_val,
13514                 (void *)&cmd_config_e_tag_port,
13515                 (void *)&cmd_config_e_tag_port_id,
13516                 NULL,
13517         },
13518 };
13519
13520 static void
13521 cmd_config_e_tag_filter_del_parsed(
13522         void *parsed_result,
13523         __rte_unused struct cmdline *cl,
13524         __rte_unused void *data)
13525 {
13526         struct cmd_config_e_tag_result *res = parsed_result;
13527         struct rte_eth_l2_tunnel_conf entry;
13528         int ret = 0;
13529
13530         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13531                 return;
13532
13533         if (res->e_tag_id_val > 0x3fff) {
13534                 printf("e-tag-id must be less than 0x3fff.\n");
13535                 return;
13536         }
13537
13538         ret = rte_eth_dev_filter_supported(res->port_id,
13539                                            RTE_ETH_FILTER_L2_TUNNEL);
13540         if (ret < 0) {
13541                 printf("E-tag filter is not supported on port %u.\n",
13542                        res->port_id);
13543                 return;
13544         }
13545
13546         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13547         entry.tunnel_id = res->e_tag_id_val;
13548
13549         ret = rte_eth_dev_filter_ctrl(res->port_id,
13550                                       RTE_ETH_FILTER_L2_TUNNEL,
13551                                       RTE_ETH_FILTER_DELETE,
13552                                       &entry);
13553         if (ret < 0)
13554                 printf("E-tag filter programming error: (%s)\n",
13555                        strerror(-ret));
13556 }
13557
13558 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13559         .f = cmd_config_e_tag_filter_del_parsed,
13560         .data = NULL,
13561         .help_str = "E-tag ... : E-tag filter delete",
13562         .tokens = {
13563                 (void *)&cmd_config_e_tag_e_tag,
13564                 (void *)&cmd_config_e_tag_set,
13565                 (void *)&cmd_config_e_tag_filter,
13566                 (void *)&cmd_config_e_tag_del,
13567                 (void *)&cmd_config_e_tag_e_tag_id,
13568                 (void *)&cmd_config_e_tag_e_tag_id_val,
13569                 (void *)&cmd_config_e_tag_port,
13570                 (void *)&cmd_config_e_tag_port_id,
13571                 NULL,
13572         },
13573 };
13574
13575 /* vf vlan anti spoof configuration */
13576
13577 /* Common result structure for vf vlan anti spoof */
13578 struct cmd_vf_vlan_anti_spoof_result {
13579         cmdline_fixed_string_t set;
13580         cmdline_fixed_string_t vf;
13581         cmdline_fixed_string_t vlan;
13582         cmdline_fixed_string_t antispoof;
13583         portid_t port_id;
13584         uint32_t vf_id;
13585         cmdline_fixed_string_t on_off;
13586 };
13587
13588 /* Common CLI fields for vf vlan anti spoof enable disable */
13589 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13590         TOKEN_STRING_INITIALIZER
13591                 (struct cmd_vf_vlan_anti_spoof_result,
13592                  set, "set");
13593 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13594         TOKEN_STRING_INITIALIZER
13595                 (struct cmd_vf_vlan_anti_spoof_result,
13596                  vf, "vf");
13597 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13598         TOKEN_STRING_INITIALIZER
13599                 (struct cmd_vf_vlan_anti_spoof_result,
13600                  vlan, "vlan");
13601 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13602         TOKEN_STRING_INITIALIZER
13603                 (struct cmd_vf_vlan_anti_spoof_result,
13604                  antispoof, "antispoof");
13605 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13606         TOKEN_NUM_INITIALIZER
13607                 (struct cmd_vf_vlan_anti_spoof_result,
13608                  port_id, UINT16);
13609 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13610         TOKEN_NUM_INITIALIZER
13611                 (struct cmd_vf_vlan_anti_spoof_result,
13612                  vf_id, UINT32);
13613 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13614         TOKEN_STRING_INITIALIZER
13615                 (struct cmd_vf_vlan_anti_spoof_result,
13616                  on_off, "on#off");
13617
13618 static void
13619 cmd_set_vf_vlan_anti_spoof_parsed(
13620         void *parsed_result,
13621         __rte_unused struct cmdline *cl,
13622         __rte_unused void *data)
13623 {
13624         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13625         int ret = -ENOTSUP;
13626
13627         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13628
13629         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13630                 return;
13631
13632 #ifdef RTE_LIBRTE_IXGBE_PMD
13633         if (ret == -ENOTSUP)
13634                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13635                                 res->vf_id, is_on);
13636 #endif
13637 #ifdef RTE_LIBRTE_I40E_PMD
13638         if (ret == -ENOTSUP)
13639                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13640                                 res->vf_id, is_on);
13641 #endif
13642 #ifdef RTE_LIBRTE_BNXT_PMD
13643         if (ret == -ENOTSUP)
13644                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13645                                 res->vf_id, is_on);
13646 #endif
13647
13648         switch (ret) {
13649         case 0:
13650                 break;
13651         case -EINVAL:
13652                 printf("invalid vf_id %d\n", res->vf_id);
13653                 break;
13654         case -ENODEV:
13655                 printf("invalid port_id %d\n", res->port_id);
13656                 break;
13657         case -ENOTSUP:
13658                 printf("function not implemented\n");
13659                 break;
13660         default:
13661                 printf("programming error: (%s)\n", strerror(-ret));
13662         }
13663 }
13664
13665 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13666         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13667         .data = NULL,
13668         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13669         .tokens = {
13670                 (void *)&cmd_vf_vlan_anti_spoof_set,
13671                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13672                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13673                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13674                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13675                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13676                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13677                 NULL,
13678         },
13679 };
13680
13681 /* vf mac anti spoof configuration */
13682
13683 /* Common result structure for vf mac anti spoof */
13684 struct cmd_vf_mac_anti_spoof_result {
13685         cmdline_fixed_string_t set;
13686         cmdline_fixed_string_t vf;
13687         cmdline_fixed_string_t mac;
13688         cmdline_fixed_string_t antispoof;
13689         portid_t port_id;
13690         uint32_t vf_id;
13691         cmdline_fixed_string_t on_off;
13692 };
13693
13694 /* Common CLI fields for vf mac anti spoof enable disable */
13695 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13696         TOKEN_STRING_INITIALIZER
13697                 (struct cmd_vf_mac_anti_spoof_result,
13698                  set, "set");
13699 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13700         TOKEN_STRING_INITIALIZER
13701                 (struct cmd_vf_mac_anti_spoof_result,
13702                  vf, "vf");
13703 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13704         TOKEN_STRING_INITIALIZER
13705                 (struct cmd_vf_mac_anti_spoof_result,
13706                  mac, "mac");
13707 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13708         TOKEN_STRING_INITIALIZER
13709                 (struct cmd_vf_mac_anti_spoof_result,
13710                  antispoof, "antispoof");
13711 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13712         TOKEN_NUM_INITIALIZER
13713                 (struct cmd_vf_mac_anti_spoof_result,
13714                  port_id, UINT16);
13715 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13716         TOKEN_NUM_INITIALIZER
13717                 (struct cmd_vf_mac_anti_spoof_result,
13718                  vf_id, UINT32);
13719 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13720         TOKEN_STRING_INITIALIZER
13721                 (struct cmd_vf_mac_anti_spoof_result,
13722                  on_off, "on#off");
13723
13724 static void
13725 cmd_set_vf_mac_anti_spoof_parsed(
13726         void *parsed_result,
13727         __rte_unused struct cmdline *cl,
13728         __rte_unused void *data)
13729 {
13730         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13731         int ret = -ENOTSUP;
13732
13733         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13734
13735         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13736                 return;
13737
13738 #ifdef RTE_LIBRTE_IXGBE_PMD
13739         if (ret == -ENOTSUP)
13740                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13741                         res->vf_id, is_on);
13742 #endif
13743 #ifdef RTE_LIBRTE_I40E_PMD
13744         if (ret == -ENOTSUP)
13745                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13746                         res->vf_id, is_on);
13747 #endif
13748 #ifdef RTE_LIBRTE_BNXT_PMD
13749         if (ret == -ENOTSUP)
13750                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13751                         res->vf_id, is_on);
13752 #endif
13753
13754         switch (ret) {
13755         case 0:
13756                 break;
13757         case -EINVAL:
13758                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13759                 break;
13760         case -ENODEV:
13761                 printf("invalid port_id %d\n", res->port_id);
13762                 break;
13763         case -ENOTSUP:
13764                 printf("function not implemented\n");
13765                 break;
13766         default:
13767                 printf("programming error: (%s)\n", strerror(-ret));
13768         }
13769 }
13770
13771 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13772         .f = cmd_set_vf_mac_anti_spoof_parsed,
13773         .data = NULL,
13774         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13775         .tokens = {
13776                 (void *)&cmd_vf_mac_anti_spoof_set,
13777                 (void *)&cmd_vf_mac_anti_spoof_vf,
13778                 (void *)&cmd_vf_mac_anti_spoof_mac,
13779                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13780                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13781                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13782                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13783                 NULL,
13784         },
13785 };
13786
13787 /* vf vlan strip queue configuration */
13788
13789 /* Common result structure for vf mac anti spoof */
13790 struct cmd_vf_vlan_stripq_result {
13791         cmdline_fixed_string_t set;
13792         cmdline_fixed_string_t vf;
13793         cmdline_fixed_string_t vlan;
13794         cmdline_fixed_string_t stripq;
13795         portid_t port_id;
13796         uint16_t vf_id;
13797         cmdline_fixed_string_t on_off;
13798 };
13799
13800 /* Common CLI fields for vf vlan strip enable disable */
13801 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13802         TOKEN_STRING_INITIALIZER
13803                 (struct cmd_vf_vlan_stripq_result,
13804                  set, "set");
13805 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13806         TOKEN_STRING_INITIALIZER
13807                 (struct cmd_vf_vlan_stripq_result,
13808                  vf, "vf");
13809 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13810         TOKEN_STRING_INITIALIZER
13811                 (struct cmd_vf_vlan_stripq_result,
13812                  vlan, "vlan");
13813 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13814         TOKEN_STRING_INITIALIZER
13815                 (struct cmd_vf_vlan_stripq_result,
13816                  stripq, "stripq");
13817 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13818         TOKEN_NUM_INITIALIZER
13819                 (struct cmd_vf_vlan_stripq_result,
13820                  port_id, UINT16);
13821 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13822         TOKEN_NUM_INITIALIZER
13823                 (struct cmd_vf_vlan_stripq_result,
13824                  vf_id, UINT16);
13825 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13826         TOKEN_STRING_INITIALIZER
13827                 (struct cmd_vf_vlan_stripq_result,
13828                  on_off, "on#off");
13829
13830 static void
13831 cmd_set_vf_vlan_stripq_parsed(
13832         void *parsed_result,
13833         __rte_unused struct cmdline *cl,
13834         __rte_unused void *data)
13835 {
13836         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13837         int ret = -ENOTSUP;
13838
13839         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13840
13841         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13842                 return;
13843
13844 #ifdef RTE_LIBRTE_IXGBE_PMD
13845         if (ret == -ENOTSUP)
13846                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13847                         res->vf_id, is_on);
13848 #endif
13849 #ifdef RTE_LIBRTE_I40E_PMD
13850         if (ret == -ENOTSUP)
13851                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13852                         res->vf_id, is_on);
13853 #endif
13854 #ifdef RTE_LIBRTE_BNXT_PMD
13855         if (ret == -ENOTSUP)
13856                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13857                         res->vf_id, is_on);
13858 #endif
13859
13860         switch (ret) {
13861         case 0:
13862                 break;
13863         case -EINVAL:
13864                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13865                 break;
13866         case -ENODEV:
13867                 printf("invalid port_id %d\n", res->port_id);
13868                 break;
13869         case -ENOTSUP:
13870                 printf("function not implemented\n");
13871                 break;
13872         default:
13873                 printf("programming error: (%s)\n", strerror(-ret));
13874         }
13875 }
13876
13877 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13878         .f = cmd_set_vf_vlan_stripq_parsed,
13879         .data = NULL,
13880         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13881         .tokens = {
13882                 (void *)&cmd_vf_vlan_stripq_set,
13883                 (void *)&cmd_vf_vlan_stripq_vf,
13884                 (void *)&cmd_vf_vlan_stripq_vlan,
13885                 (void *)&cmd_vf_vlan_stripq_stripq,
13886                 (void *)&cmd_vf_vlan_stripq_port_id,
13887                 (void *)&cmd_vf_vlan_stripq_vf_id,
13888                 (void *)&cmd_vf_vlan_stripq_on_off,
13889                 NULL,
13890         },
13891 };
13892
13893 /* vf vlan insert configuration */
13894
13895 /* Common result structure for vf vlan insert */
13896 struct cmd_vf_vlan_insert_result {
13897         cmdline_fixed_string_t set;
13898         cmdline_fixed_string_t vf;
13899         cmdline_fixed_string_t vlan;
13900         cmdline_fixed_string_t insert;
13901         portid_t port_id;
13902         uint16_t vf_id;
13903         uint16_t vlan_id;
13904 };
13905
13906 /* Common CLI fields for vf vlan insert enable disable */
13907 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13908         TOKEN_STRING_INITIALIZER
13909                 (struct cmd_vf_vlan_insert_result,
13910                  set, "set");
13911 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13912         TOKEN_STRING_INITIALIZER
13913                 (struct cmd_vf_vlan_insert_result,
13914                  vf, "vf");
13915 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13916         TOKEN_STRING_INITIALIZER
13917                 (struct cmd_vf_vlan_insert_result,
13918                  vlan, "vlan");
13919 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13920         TOKEN_STRING_INITIALIZER
13921                 (struct cmd_vf_vlan_insert_result,
13922                  insert, "insert");
13923 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13924         TOKEN_NUM_INITIALIZER
13925                 (struct cmd_vf_vlan_insert_result,
13926                  port_id, UINT16);
13927 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13928         TOKEN_NUM_INITIALIZER
13929                 (struct cmd_vf_vlan_insert_result,
13930                  vf_id, UINT16);
13931 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13932         TOKEN_NUM_INITIALIZER
13933                 (struct cmd_vf_vlan_insert_result,
13934                  vlan_id, UINT16);
13935
13936 static void
13937 cmd_set_vf_vlan_insert_parsed(
13938         void *parsed_result,
13939         __rte_unused struct cmdline *cl,
13940         __rte_unused void *data)
13941 {
13942         struct cmd_vf_vlan_insert_result *res = parsed_result;
13943         int ret = -ENOTSUP;
13944
13945         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13946                 return;
13947
13948 #ifdef RTE_LIBRTE_IXGBE_PMD
13949         if (ret == -ENOTSUP)
13950                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13951                         res->vlan_id);
13952 #endif
13953 #ifdef RTE_LIBRTE_I40E_PMD
13954         if (ret == -ENOTSUP)
13955                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13956                         res->vlan_id);
13957 #endif
13958 #ifdef RTE_LIBRTE_BNXT_PMD
13959         if (ret == -ENOTSUP)
13960                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13961                         res->vlan_id);
13962 #endif
13963
13964         switch (ret) {
13965         case 0:
13966                 break;
13967         case -EINVAL:
13968                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13969                 break;
13970         case -ENODEV:
13971                 printf("invalid port_id %d\n", res->port_id);
13972                 break;
13973         case -ENOTSUP:
13974                 printf("function not implemented\n");
13975                 break;
13976         default:
13977                 printf("programming error: (%s)\n", strerror(-ret));
13978         }
13979 }
13980
13981 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13982         .f = cmd_set_vf_vlan_insert_parsed,
13983         .data = NULL,
13984         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13985         .tokens = {
13986                 (void *)&cmd_vf_vlan_insert_set,
13987                 (void *)&cmd_vf_vlan_insert_vf,
13988                 (void *)&cmd_vf_vlan_insert_vlan,
13989                 (void *)&cmd_vf_vlan_insert_insert,
13990                 (void *)&cmd_vf_vlan_insert_port_id,
13991                 (void *)&cmd_vf_vlan_insert_vf_id,
13992                 (void *)&cmd_vf_vlan_insert_vlan_id,
13993                 NULL,
13994         },
13995 };
13996
13997 /* tx loopback configuration */
13998
13999 /* Common result structure for tx loopback */
14000 struct cmd_tx_loopback_result {
14001         cmdline_fixed_string_t set;
14002         cmdline_fixed_string_t tx;
14003         cmdline_fixed_string_t loopback;
14004         portid_t port_id;
14005         cmdline_fixed_string_t on_off;
14006 };
14007
14008 /* Common CLI fields for tx loopback enable disable */
14009 cmdline_parse_token_string_t cmd_tx_loopback_set =
14010         TOKEN_STRING_INITIALIZER
14011                 (struct cmd_tx_loopback_result,
14012                  set, "set");
14013 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14014         TOKEN_STRING_INITIALIZER
14015                 (struct cmd_tx_loopback_result,
14016                  tx, "tx");
14017 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14018         TOKEN_STRING_INITIALIZER
14019                 (struct cmd_tx_loopback_result,
14020                  loopback, "loopback");
14021 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14022         TOKEN_NUM_INITIALIZER
14023                 (struct cmd_tx_loopback_result,
14024                  port_id, UINT16);
14025 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14026         TOKEN_STRING_INITIALIZER
14027                 (struct cmd_tx_loopback_result,
14028                  on_off, "on#off");
14029
14030 static void
14031 cmd_set_tx_loopback_parsed(
14032         void *parsed_result,
14033         __rte_unused struct cmdline *cl,
14034         __rte_unused void *data)
14035 {
14036         struct cmd_tx_loopback_result *res = parsed_result;
14037         int ret = -ENOTSUP;
14038
14039         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14040
14041         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14042                 return;
14043
14044 #ifdef RTE_LIBRTE_IXGBE_PMD
14045         if (ret == -ENOTSUP)
14046                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14047 #endif
14048 #ifdef RTE_LIBRTE_I40E_PMD
14049         if (ret == -ENOTSUP)
14050                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14051 #endif
14052 #ifdef RTE_LIBRTE_BNXT_PMD
14053         if (ret == -ENOTSUP)
14054                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14055 #endif
14056 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14057         if (ret == -ENOTSUP)
14058                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14059 #endif
14060
14061         switch (ret) {
14062         case 0:
14063                 break;
14064         case -EINVAL:
14065                 printf("invalid is_on %d\n", is_on);
14066                 break;
14067         case -ENODEV:
14068                 printf("invalid port_id %d\n", res->port_id);
14069                 break;
14070         case -ENOTSUP:
14071                 printf("function not implemented\n");
14072                 break;
14073         default:
14074                 printf("programming error: (%s)\n", strerror(-ret));
14075         }
14076 }
14077
14078 cmdline_parse_inst_t cmd_set_tx_loopback = {
14079         .f = cmd_set_tx_loopback_parsed,
14080         .data = NULL,
14081         .help_str = "set tx loopback <port_id> on|off",
14082         .tokens = {
14083                 (void *)&cmd_tx_loopback_set,
14084                 (void *)&cmd_tx_loopback_tx,
14085                 (void *)&cmd_tx_loopback_loopback,
14086                 (void *)&cmd_tx_loopback_port_id,
14087                 (void *)&cmd_tx_loopback_on_off,
14088                 NULL,
14089         },
14090 };
14091
14092 /* all queues drop enable configuration */
14093
14094 /* Common result structure for all queues drop enable */
14095 struct cmd_all_queues_drop_en_result {
14096         cmdline_fixed_string_t set;
14097         cmdline_fixed_string_t all;
14098         cmdline_fixed_string_t queues;
14099         cmdline_fixed_string_t drop;
14100         portid_t port_id;
14101         cmdline_fixed_string_t on_off;
14102 };
14103
14104 /* Common CLI fields for tx loopback enable disable */
14105 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14106         TOKEN_STRING_INITIALIZER
14107                 (struct cmd_all_queues_drop_en_result,
14108                  set, "set");
14109 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14110         TOKEN_STRING_INITIALIZER
14111                 (struct cmd_all_queues_drop_en_result,
14112                  all, "all");
14113 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14114         TOKEN_STRING_INITIALIZER
14115                 (struct cmd_all_queues_drop_en_result,
14116                  queues, "queues");
14117 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14118         TOKEN_STRING_INITIALIZER
14119                 (struct cmd_all_queues_drop_en_result,
14120                  drop, "drop");
14121 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14122         TOKEN_NUM_INITIALIZER
14123                 (struct cmd_all_queues_drop_en_result,
14124                  port_id, UINT16);
14125 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14126         TOKEN_STRING_INITIALIZER
14127                 (struct cmd_all_queues_drop_en_result,
14128                  on_off, "on#off");
14129
14130 static void
14131 cmd_set_all_queues_drop_en_parsed(
14132         void *parsed_result,
14133         __rte_unused struct cmdline *cl,
14134         __rte_unused void *data)
14135 {
14136         struct cmd_all_queues_drop_en_result *res = parsed_result;
14137         int ret = -ENOTSUP;
14138         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14139
14140         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14141                 return;
14142
14143 #ifdef RTE_LIBRTE_IXGBE_PMD
14144         if (ret == -ENOTSUP)
14145                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14146 #endif
14147 #ifdef RTE_LIBRTE_BNXT_PMD
14148         if (ret == -ENOTSUP)
14149                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14150 #endif
14151         switch (ret) {
14152         case 0:
14153                 break;
14154         case -EINVAL:
14155                 printf("invalid is_on %d\n", is_on);
14156                 break;
14157         case -ENODEV:
14158                 printf("invalid port_id %d\n", res->port_id);
14159                 break;
14160         case -ENOTSUP:
14161                 printf("function not implemented\n");
14162                 break;
14163         default:
14164                 printf("programming error: (%s)\n", strerror(-ret));
14165         }
14166 }
14167
14168 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14169         .f = cmd_set_all_queues_drop_en_parsed,
14170         .data = NULL,
14171         .help_str = "set all queues drop <port_id> on|off",
14172         .tokens = {
14173                 (void *)&cmd_all_queues_drop_en_set,
14174                 (void *)&cmd_all_queues_drop_en_all,
14175                 (void *)&cmd_all_queues_drop_en_queues,
14176                 (void *)&cmd_all_queues_drop_en_drop,
14177                 (void *)&cmd_all_queues_drop_en_port_id,
14178                 (void *)&cmd_all_queues_drop_en_on_off,
14179                 NULL,
14180         },
14181 };
14182
14183 /* vf split drop enable configuration */
14184
14185 /* Common result structure for vf split drop enable */
14186 struct cmd_vf_split_drop_en_result {
14187         cmdline_fixed_string_t set;
14188         cmdline_fixed_string_t vf;
14189         cmdline_fixed_string_t split;
14190         cmdline_fixed_string_t drop;
14191         portid_t port_id;
14192         uint16_t vf_id;
14193         cmdline_fixed_string_t on_off;
14194 };
14195
14196 /* Common CLI fields for vf split drop enable disable */
14197 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14198         TOKEN_STRING_INITIALIZER
14199                 (struct cmd_vf_split_drop_en_result,
14200                  set, "set");
14201 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14202         TOKEN_STRING_INITIALIZER
14203                 (struct cmd_vf_split_drop_en_result,
14204                  vf, "vf");
14205 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14206         TOKEN_STRING_INITIALIZER
14207                 (struct cmd_vf_split_drop_en_result,
14208                  split, "split");
14209 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14210         TOKEN_STRING_INITIALIZER
14211                 (struct cmd_vf_split_drop_en_result,
14212                  drop, "drop");
14213 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14214         TOKEN_NUM_INITIALIZER
14215                 (struct cmd_vf_split_drop_en_result,
14216                  port_id, UINT16);
14217 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14218         TOKEN_NUM_INITIALIZER
14219                 (struct cmd_vf_split_drop_en_result,
14220                  vf_id, UINT16);
14221 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14222         TOKEN_STRING_INITIALIZER
14223                 (struct cmd_vf_split_drop_en_result,
14224                  on_off, "on#off");
14225
14226 static void
14227 cmd_set_vf_split_drop_en_parsed(
14228         void *parsed_result,
14229         __rte_unused struct cmdline *cl,
14230         __rte_unused void *data)
14231 {
14232         struct cmd_vf_split_drop_en_result *res = parsed_result;
14233         int ret = -ENOTSUP;
14234         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14235
14236         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14237                 return;
14238
14239 #ifdef RTE_LIBRTE_IXGBE_PMD
14240         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14241                         is_on);
14242 #endif
14243         switch (ret) {
14244         case 0:
14245                 break;
14246         case -EINVAL:
14247                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14248                 break;
14249         case -ENODEV:
14250                 printf("invalid port_id %d\n", res->port_id);
14251                 break;
14252         case -ENOTSUP:
14253                 printf("not supported on port %d\n", res->port_id);
14254                 break;
14255         default:
14256                 printf("programming error: (%s)\n", strerror(-ret));
14257         }
14258 }
14259
14260 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14261         .f = cmd_set_vf_split_drop_en_parsed,
14262         .data = NULL,
14263         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14264         .tokens = {
14265                 (void *)&cmd_vf_split_drop_en_set,
14266                 (void *)&cmd_vf_split_drop_en_vf,
14267                 (void *)&cmd_vf_split_drop_en_split,
14268                 (void *)&cmd_vf_split_drop_en_drop,
14269                 (void *)&cmd_vf_split_drop_en_port_id,
14270                 (void *)&cmd_vf_split_drop_en_vf_id,
14271                 (void *)&cmd_vf_split_drop_en_on_off,
14272                 NULL,
14273         },
14274 };
14275
14276 /* vf mac address configuration */
14277
14278 /* Common result structure for vf mac address */
14279 struct cmd_set_vf_mac_addr_result {
14280         cmdline_fixed_string_t set;
14281         cmdline_fixed_string_t vf;
14282         cmdline_fixed_string_t mac;
14283         cmdline_fixed_string_t addr;
14284         portid_t port_id;
14285         uint16_t vf_id;
14286         struct rte_ether_addr mac_addr;
14287
14288 };
14289
14290 /* Common CLI fields for vf split drop enable disable */
14291 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14292         TOKEN_STRING_INITIALIZER
14293                 (struct cmd_set_vf_mac_addr_result,
14294                  set, "set");
14295 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14296         TOKEN_STRING_INITIALIZER
14297                 (struct cmd_set_vf_mac_addr_result,
14298                  vf, "vf");
14299 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14300         TOKEN_STRING_INITIALIZER
14301                 (struct cmd_set_vf_mac_addr_result,
14302                  mac, "mac");
14303 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14304         TOKEN_STRING_INITIALIZER
14305                 (struct cmd_set_vf_mac_addr_result,
14306                  addr, "addr");
14307 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14308         TOKEN_NUM_INITIALIZER
14309                 (struct cmd_set_vf_mac_addr_result,
14310                  port_id, UINT16);
14311 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14312         TOKEN_NUM_INITIALIZER
14313                 (struct cmd_set_vf_mac_addr_result,
14314                  vf_id, UINT16);
14315 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14316         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14317                  mac_addr);
14318
14319 static void
14320 cmd_set_vf_mac_addr_parsed(
14321         void *parsed_result,
14322         __rte_unused struct cmdline *cl,
14323         __rte_unused void *data)
14324 {
14325         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14326         int ret = -ENOTSUP;
14327
14328         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14329                 return;
14330
14331 #ifdef RTE_LIBRTE_IXGBE_PMD
14332         if (ret == -ENOTSUP)
14333                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14334                                 &res->mac_addr);
14335 #endif
14336 #ifdef RTE_LIBRTE_I40E_PMD
14337         if (ret == -ENOTSUP)
14338                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14339                                 &res->mac_addr);
14340 #endif
14341 #ifdef RTE_LIBRTE_BNXT_PMD
14342         if (ret == -ENOTSUP)
14343                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14344                                 &res->mac_addr);
14345 #endif
14346
14347         switch (ret) {
14348         case 0:
14349                 break;
14350         case -EINVAL:
14351                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14352                 break;
14353         case -ENODEV:
14354                 printf("invalid port_id %d\n", res->port_id);
14355                 break;
14356         case -ENOTSUP:
14357                 printf("function not implemented\n");
14358                 break;
14359         default:
14360                 printf("programming error: (%s)\n", strerror(-ret));
14361         }
14362 }
14363
14364 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14365         .f = cmd_set_vf_mac_addr_parsed,
14366         .data = NULL,
14367         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14368         .tokens = {
14369                 (void *)&cmd_set_vf_mac_addr_set,
14370                 (void *)&cmd_set_vf_mac_addr_vf,
14371                 (void *)&cmd_set_vf_mac_addr_mac,
14372                 (void *)&cmd_set_vf_mac_addr_addr,
14373                 (void *)&cmd_set_vf_mac_addr_port_id,
14374                 (void *)&cmd_set_vf_mac_addr_vf_id,
14375                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14376                 NULL,
14377         },
14378 };
14379
14380 /* MACsec configuration */
14381
14382 /* Common result structure for MACsec offload enable */
14383 struct cmd_macsec_offload_on_result {
14384         cmdline_fixed_string_t set;
14385         cmdline_fixed_string_t macsec;
14386         cmdline_fixed_string_t offload;
14387         portid_t port_id;
14388         cmdline_fixed_string_t on;
14389         cmdline_fixed_string_t encrypt;
14390         cmdline_fixed_string_t en_on_off;
14391         cmdline_fixed_string_t replay_protect;
14392         cmdline_fixed_string_t rp_on_off;
14393 };
14394
14395 /* Common CLI fields for MACsec offload disable */
14396 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14397         TOKEN_STRING_INITIALIZER
14398                 (struct cmd_macsec_offload_on_result,
14399                  set, "set");
14400 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14401         TOKEN_STRING_INITIALIZER
14402                 (struct cmd_macsec_offload_on_result,
14403                  macsec, "macsec");
14404 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14405         TOKEN_STRING_INITIALIZER
14406                 (struct cmd_macsec_offload_on_result,
14407                  offload, "offload");
14408 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14409         TOKEN_NUM_INITIALIZER
14410                 (struct cmd_macsec_offload_on_result,
14411                  port_id, UINT16);
14412 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14413         TOKEN_STRING_INITIALIZER
14414                 (struct cmd_macsec_offload_on_result,
14415                  on, "on");
14416 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14417         TOKEN_STRING_INITIALIZER
14418                 (struct cmd_macsec_offload_on_result,
14419                  encrypt, "encrypt");
14420 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14421         TOKEN_STRING_INITIALIZER
14422                 (struct cmd_macsec_offload_on_result,
14423                  en_on_off, "on#off");
14424 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14425         TOKEN_STRING_INITIALIZER
14426                 (struct cmd_macsec_offload_on_result,
14427                  replay_protect, "replay-protect");
14428 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14429         TOKEN_STRING_INITIALIZER
14430                 (struct cmd_macsec_offload_on_result,
14431                  rp_on_off, "on#off");
14432
14433 static void
14434 cmd_set_macsec_offload_on_parsed(
14435         void *parsed_result,
14436         __rte_unused struct cmdline *cl,
14437         __rte_unused void *data)
14438 {
14439         struct cmd_macsec_offload_on_result *res = parsed_result;
14440         int ret = -ENOTSUP;
14441         portid_t port_id = res->port_id;
14442         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14443         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14444         struct rte_eth_dev_info dev_info;
14445
14446         if (port_id_is_invalid(port_id, ENABLED_WARN))
14447                 return;
14448         if (!port_is_stopped(port_id)) {
14449                 printf("Please stop port %d first\n", port_id);
14450                 return;
14451         }
14452
14453         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14454         if (ret != 0)
14455                 return;
14456
14457         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14458 #ifdef RTE_LIBRTE_IXGBE_PMD
14459                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14460 #endif
14461         }
14462         RTE_SET_USED(en);
14463         RTE_SET_USED(rp);
14464
14465         switch (ret) {
14466         case 0:
14467                 ports[port_id].dev_conf.txmode.offloads |=
14468                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14469                 cmd_reconfig_device_queue(port_id, 1, 1);
14470                 break;
14471         case -ENODEV:
14472                 printf("invalid port_id %d\n", port_id);
14473                 break;
14474         case -ENOTSUP:
14475                 printf("not supported on port %d\n", port_id);
14476                 break;
14477         default:
14478                 printf("programming error: (%s)\n", strerror(-ret));
14479         }
14480 }
14481
14482 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14483         .f = cmd_set_macsec_offload_on_parsed,
14484         .data = NULL,
14485         .help_str = "set macsec offload <port_id> on "
14486                 "encrypt on|off replay-protect on|off",
14487         .tokens = {
14488                 (void *)&cmd_macsec_offload_on_set,
14489                 (void *)&cmd_macsec_offload_on_macsec,
14490                 (void *)&cmd_macsec_offload_on_offload,
14491                 (void *)&cmd_macsec_offload_on_port_id,
14492                 (void *)&cmd_macsec_offload_on_on,
14493                 (void *)&cmd_macsec_offload_on_encrypt,
14494                 (void *)&cmd_macsec_offload_on_en_on_off,
14495                 (void *)&cmd_macsec_offload_on_replay_protect,
14496                 (void *)&cmd_macsec_offload_on_rp_on_off,
14497                 NULL,
14498         },
14499 };
14500
14501 /* Common result structure for MACsec offload disable */
14502 struct cmd_macsec_offload_off_result {
14503         cmdline_fixed_string_t set;
14504         cmdline_fixed_string_t macsec;
14505         cmdline_fixed_string_t offload;
14506         portid_t port_id;
14507         cmdline_fixed_string_t off;
14508 };
14509
14510 /* Common CLI fields for MACsec offload disable */
14511 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14512         TOKEN_STRING_INITIALIZER
14513                 (struct cmd_macsec_offload_off_result,
14514                  set, "set");
14515 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14516         TOKEN_STRING_INITIALIZER
14517                 (struct cmd_macsec_offload_off_result,
14518                  macsec, "macsec");
14519 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14520         TOKEN_STRING_INITIALIZER
14521                 (struct cmd_macsec_offload_off_result,
14522                  offload, "offload");
14523 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14524         TOKEN_NUM_INITIALIZER
14525                 (struct cmd_macsec_offload_off_result,
14526                  port_id, UINT16);
14527 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14528         TOKEN_STRING_INITIALIZER
14529                 (struct cmd_macsec_offload_off_result,
14530                  off, "off");
14531
14532 static void
14533 cmd_set_macsec_offload_off_parsed(
14534         void *parsed_result,
14535         __rte_unused struct cmdline *cl,
14536         __rte_unused void *data)
14537 {
14538         struct cmd_macsec_offload_off_result *res = parsed_result;
14539         int ret = -ENOTSUP;
14540         struct rte_eth_dev_info dev_info;
14541         portid_t port_id = res->port_id;
14542
14543         if (port_id_is_invalid(port_id, ENABLED_WARN))
14544                 return;
14545         if (!port_is_stopped(port_id)) {
14546                 printf("Please stop port %d first\n", port_id);
14547                 return;
14548         }
14549
14550         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14551         if (ret != 0)
14552                 return;
14553
14554         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14555 #ifdef RTE_LIBRTE_IXGBE_PMD
14556                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14557 #endif
14558         }
14559         switch (ret) {
14560         case 0:
14561                 ports[port_id].dev_conf.txmode.offloads &=
14562                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14563                 cmd_reconfig_device_queue(port_id, 1, 1);
14564                 break;
14565         case -ENODEV:
14566                 printf("invalid port_id %d\n", port_id);
14567                 break;
14568         case -ENOTSUP:
14569                 printf("not supported on port %d\n", port_id);
14570                 break;
14571         default:
14572                 printf("programming error: (%s)\n", strerror(-ret));
14573         }
14574 }
14575
14576 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14577         .f = cmd_set_macsec_offload_off_parsed,
14578         .data = NULL,
14579         .help_str = "set macsec offload <port_id> off",
14580         .tokens = {
14581                 (void *)&cmd_macsec_offload_off_set,
14582                 (void *)&cmd_macsec_offload_off_macsec,
14583                 (void *)&cmd_macsec_offload_off_offload,
14584                 (void *)&cmd_macsec_offload_off_port_id,
14585                 (void *)&cmd_macsec_offload_off_off,
14586                 NULL,
14587         },
14588 };
14589
14590 /* Common result structure for MACsec secure connection configure */
14591 struct cmd_macsec_sc_result {
14592         cmdline_fixed_string_t set;
14593         cmdline_fixed_string_t macsec;
14594         cmdline_fixed_string_t sc;
14595         cmdline_fixed_string_t tx_rx;
14596         portid_t port_id;
14597         struct rte_ether_addr mac;
14598         uint16_t pi;
14599 };
14600
14601 /* Common CLI fields for MACsec secure connection configure */
14602 cmdline_parse_token_string_t cmd_macsec_sc_set =
14603         TOKEN_STRING_INITIALIZER
14604                 (struct cmd_macsec_sc_result,
14605                  set, "set");
14606 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14607         TOKEN_STRING_INITIALIZER
14608                 (struct cmd_macsec_sc_result,
14609                  macsec, "macsec");
14610 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14611         TOKEN_STRING_INITIALIZER
14612                 (struct cmd_macsec_sc_result,
14613                  sc, "sc");
14614 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14615         TOKEN_STRING_INITIALIZER
14616                 (struct cmd_macsec_sc_result,
14617                  tx_rx, "tx#rx");
14618 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14619         TOKEN_NUM_INITIALIZER
14620                 (struct cmd_macsec_sc_result,
14621                  port_id, UINT16);
14622 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14623         TOKEN_ETHERADDR_INITIALIZER
14624                 (struct cmd_macsec_sc_result,
14625                  mac);
14626 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14627         TOKEN_NUM_INITIALIZER
14628                 (struct cmd_macsec_sc_result,
14629                  pi, UINT16);
14630
14631 static void
14632 cmd_set_macsec_sc_parsed(
14633         void *parsed_result,
14634         __rte_unused struct cmdline *cl,
14635         __rte_unused void *data)
14636 {
14637         struct cmd_macsec_sc_result *res = parsed_result;
14638         int ret = -ENOTSUP;
14639         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14640
14641 #ifdef RTE_LIBRTE_IXGBE_PMD
14642         ret = is_tx ?
14643                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14644                                 res->mac.addr_bytes) :
14645                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14646                                 res->mac.addr_bytes, res->pi);
14647 #endif
14648         RTE_SET_USED(is_tx);
14649
14650         switch (ret) {
14651         case 0:
14652                 break;
14653         case -ENODEV:
14654                 printf("invalid port_id %d\n", res->port_id);
14655                 break;
14656         case -ENOTSUP:
14657                 printf("not supported on port %d\n", res->port_id);
14658                 break;
14659         default:
14660                 printf("programming error: (%s)\n", strerror(-ret));
14661         }
14662 }
14663
14664 cmdline_parse_inst_t cmd_set_macsec_sc = {
14665         .f = cmd_set_macsec_sc_parsed,
14666         .data = NULL,
14667         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14668         .tokens = {
14669                 (void *)&cmd_macsec_sc_set,
14670                 (void *)&cmd_macsec_sc_macsec,
14671                 (void *)&cmd_macsec_sc_sc,
14672                 (void *)&cmd_macsec_sc_tx_rx,
14673                 (void *)&cmd_macsec_sc_port_id,
14674                 (void *)&cmd_macsec_sc_mac,
14675                 (void *)&cmd_macsec_sc_pi,
14676                 NULL,
14677         },
14678 };
14679
14680 /* Common result structure for MACsec secure connection configure */
14681 struct cmd_macsec_sa_result {
14682         cmdline_fixed_string_t set;
14683         cmdline_fixed_string_t macsec;
14684         cmdline_fixed_string_t sa;
14685         cmdline_fixed_string_t tx_rx;
14686         portid_t port_id;
14687         uint8_t idx;
14688         uint8_t an;
14689         uint32_t pn;
14690         cmdline_fixed_string_t key;
14691 };
14692
14693 /* Common CLI fields for MACsec secure connection configure */
14694 cmdline_parse_token_string_t cmd_macsec_sa_set =
14695         TOKEN_STRING_INITIALIZER
14696                 (struct cmd_macsec_sa_result,
14697                  set, "set");
14698 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14699         TOKEN_STRING_INITIALIZER
14700                 (struct cmd_macsec_sa_result,
14701                  macsec, "macsec");
14702 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14703         TOKEN_STRING_INITIALIZER
14704                 (struct cmd_macsec_sa_result,
14705                  sa, "sa");
14706 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14707         TOKEN_STRING_INITIALIZER
14708                 (struct cmd_macsec_sa_result,
14709                  tx_rx, "tx#rx");
14710 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14711         TOKEN_NUM_INITIALIZER
14712                 (struct cmd_macsec_sa_result,
14713                  port_id, UINT16);
14714 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14715         TOKEN_NUM_INITIALIZER
14716                 (struct cmd_macsec_sa_result,
14717                  idx, UINT8);
14718 cmdline_parse_token_num_t cmd_macsec_sa_an =
14719         TOKEN_NUM_INITIALIZER
14720                 (struct cmd_macsec_sa_result,
14721                  an, UINT8);
14722 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14723         TOKEN_NUM_INITIALIZER
14724                 (struct cmd_macsec_sa_result,
14725                  pn, UINT32);
14726 cmdline_parse_token_string_t cmd_macsec_sa_key =
14727         TOKEN_STRING_INITIALIZER
14728                 (struct cmd_macsec_sa_result,
14729                  key, NULL);
14730
14731 static void
14732 cmd_set_macsec_sa_parsed(
14733         void *parsed_result,
14734         __rte_unused struct cmdline *cl,
14735         __rte_unused void *data)
14736 {
14737         struct cmd_macsec_sa_result *res = parsed_result;
14738         int ret = -ENOTSUP;
14739         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14740         uint8_t key[16] = { 0 };
14741         uint8_t xdgt0;
14742         uint8_t xdgt1;
14743         int key_len;
14744         int i;
14745
14746         key_len = strlen(res->key) / 2;
14747         if (key_len > 16)
14748                 key_len = 16;
14749
14750         for (i = 0; i < key_len; i++) {
14751                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14752                 if (xdgt0 == 0xFF)
14753                         return;
14754                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14755                 if (xdgt1 == 0xFF)
14756                         return;
14757                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14758         }
14759
14760 #ifdef RTE_LIBRTE_IXGBE_PMD
14761         ret = is_tx ?
14762                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14763                         res->idx, res->an, res->pn, key) :
14764                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14765                         res->idx, res->an, res->pn, key);
14766 #endif
14767         RTE_SET_USED(is_tx);
14768         RTE_SET_USED(key);
14769
14770         switch (ret) {
14771         case 0:
14772                 break;
14773         case -EINVAL:
14774                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14775                 break;
14776         case -ENODEV:
14777                 printf("invalid port_id %d\n", res->port_id);
14778                 break;
14779         case -ENOTSUP:
14780                 printf("not supported on port %d\n", res->port_id);
14781                 break;
14782         default:
14783                 printf("programming error: (%s)\n", strerror(-ret));
14784         }
14785 }
14786
14787 cmdline_parse_inst_t cmd_set_macsec_sa = {
14788         .f = cmd_set_macsec_sa_parsed,
14789         .data = NULL,
14790         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14791         .tokens = {
14792                 (void *)&cmd_macsec_sa_set,
14793                 (void *)&cmd_macsec_sa_macsec,
14794                 (void *)&cmd_macsec_sa_sa,
14795                 (void *)&cmd_macsec_sa_tx_rx,
14796                 (void *)&cmd_macsec_sa_port_id,
14797                 (void *)&cmd_macsec_sa_idx,
14798                 (void *)&cmd_macsec_sa_an,
14799                 (void *)&cmd_macsec_sa_pn,
14800                 (void *)&cmd_macsec_sa_key,
14801                 NULL,
14802         },
14803 };
14804
14805 /* VF unicast promiscuous mode configuration */
14806
14807 /* Common result structure for VF unicast promiscuous mode */
14808 struct cmd_vf_promisc_result {
14809         cmdline_fixed_string_t set;
14810         cmdline_fixed_string_t vf;
14811         cmdline_fixed_string_t promisc;
14812         portid_t port_id;
14813         uint32_t vf_id;
14814         cmdline_fixed_string_t on_off;
14815 };
14816
14817 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14818 cmdline_parse_token_string_t cmd_vf_promisc_set =
14819         TOKEN_STRING_INITIALIZER
14820                 (struct cmd_vf_promisc_result,
14821                  set, "set");
14822 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14823         TOKEN_STRING_INITIALIZER
14824                 (struct cmd_vf_promisc_result,
14825                  vf, "vf");
14826 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14827         TOKEN_STRING_INITIALIZER
14828                 (struct cmd_vf_promisc_result,
14829                  promisc, "promisc");
14830 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14831         TOKEN_NUM_INITIALIZER
14832                 (struct cmd_vf_promisc_result,
14833                  port_id, UINT16);
14834 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14835         TOKEN_NUM_INITIALIZER
14836                 (struct cmd_vf_promisc_result,
14837                  vf_id, UINT32);
14838 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14839         TOKEN_STRING_INITIALIZER
14840                 (struct cmd_vf_promisc_result,
14841                  on_off, "on#off");
14842
14843 static void
14844 cmd_set_vf_promisc_parsed(
14845         void *parsed_result,
14846         __rte_unused struct cmdline *cl,
14847         __rte_unused void *data)
14848 {
14849         struct cmd_vf_promisc_result *res = parsed_result;
14850         int ret = -ENOTSUP;
14851
14852         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14853
14854         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14855                 return;
14856
14857 #ifdef RTE_LIBRTE_I40E_PMD
14858         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14859                                                   res->vf_id, is_on);
14860 #endif
14861
14862         switch (ret) {
14863         case 0:
14864                 break;
14865         case -EINVAL:
14866                 printf("invalid vf_id %d\n", res->vf_id);
14867                 break;
14868         case -ENODEV:
14869                 printf("invalid port_id %d\n", res->port_id);
14870                 break;
14871         case -ENOTSUP:
14872                 printf("function not implemented\n");
14873                 break;
14874         default:
14875                 printf("programming error: (%s)\n", strerror(-ret));
14876         }
14877 }
14878
14879 cmdline_parse_inst_t cmd_set_vf_promisc = {
14880         .f = cmd_set_vf_promisc_parsed,
14881         .data = NULL,
14882         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14883                 "Set unicast promiscuous mode for a VF from the PF",
14884         .tokens = {
14885                 (void *)&cmd_vf_promisc_set,
14886                 (void *)&cmd_vf_promisc_vf,
14887                 (void *)&cmd_vf_promisc_promisc,
14888                 (void *)&cmd_vf_promisc_port_id,
14889                 (void *)&cmd_vf_promisc_vf_id,
14890                 (void *)&cmd_vf_promisc_on_off,
14891                 NULL,
14892         },
14893 };
14894
14895 /* VF multicast promiscuous mode configuration */
14896
14897 /* Common result structure for VF multicast promiscuous mode */
14898 struct cmd_vf_allmulti_result {
14899         cmdline_fixed_string_t set;
14900         cmdline_fixed_string_t vf;
14901         cmdline_fixed_string_t allmulti;
14902         portid_t port_id;
14903         uint32_t vf_id;
14904         cmdline_fixed_string_t on_off;
14905 };
14906
14907 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14908 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14909         TOKEN_STRING_INITIALIZER
14910                 (struct cmd_vf_allmulti_result,
14911                  set, "set");
14912 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14913         TOKEN_STRING_INITIALIZER
14914                 (struct cmd_vf_allmulti_result,
14915                  vf, "vf");
14916 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14917         TOKEN_STRING_INITIALIZER
14918                 (struct cmd_vf_allmulti_result,
14919                  allmulti, "allmulti");
14920 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14921         TOKEN_NUM_INITIALIZER
14922                 (struct cmd_vf_allmulti_result,
14923                  port_id, UINT16);
14924 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14925         TOKEN_NUM_INITIALIZER
14926                 (struct cmd_vf_allmulti_result,
14927                  vf_id, UINT32);
14928 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14929         TOKEN_STRING_INITIALIZER
14930                 (struct cmd_vf_allmulti_result,
14931                  on_off, "on#off");
14932
14933 static void
14934 cmd_set_vf_allmulti_parsed(
14935         void *parsed_result,
14936         __rte_unused struct cmdline *cl,
14937         __rte_unused void *data)
14938 {
14939         struct cmd_vf_allmulti_result *res = parsed_result;
14940         int ret = -ENOTSUP;
14941
14942         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14943
14944         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14945                 return;
14946
14947 #ifdef RTE_LIBRTE_I40E_PMD
14948         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14949                                                     res->vf_id, is_on);
14950 #endif
14951
14952         switch (ret) {
14953         case 0:
14954                 break;
14955         case -EINVAL:
14956                 printf("invalid vf_id %d\n", res->vf_id);
14957                 break;
14958         case -ENODEV:
14959                 printf("invalid port_id %d\n", res->port_id);
14960                 break;
14961         case -ENOTSUP:
14962                 printf("function not implemented\n");
14963                 break;
14964         default:
14965                 printf("programming error: (%s)\n", strerror(-ret));
14966         }
14967 }
14968
14969 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14970         .f = cmd_set_vf_allmulti_parsed,
14971         .data = NULL,
14972         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14973                 "Set multicast promiscuous mode for a VF from the PF",
14974         .tokens = {
14975                 (void *)&cmd_vf_allmulti_set,
14976                 (void *)&cmd_vf_allmulti_vf,
14977                 (void *)&cmd_vf_allmulti_allmulti,
14978                 (void *)&cmd_vf_allmulti_port_id,
14979                 (void *)&cmd_vf_allmulti_vf_id,
14980                 (void *)&cmd_vf_allmulti_on_off,
14981                 NULL,
14982         },
14983 };
14984
14985 /* vf broadcast mode configuration */
14986
14987 /* Common result structure for vf broadcast */
14988 struct cmd_set_vf_broadcast_result {
14989         cmdline_fixed_string_t set;
14990         cmdline_fixed_string_t vf;
14991         cmdline_fixed_string_t broadcast;
14992         portid_t port_id;
14993         uint16_t vf_id;
14994         cmdline_fixed_string_t on_off;
14995 };
14996
14997 /* Common CLI fields for vf broadcast enable disable */
14998 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
14999         TOKEN_STRING_INITIALIZER
15000                 (struct cmd_set_vf_broadcast_result,
15001                  set, "set");
15002 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15003         TOKEN_STRING_INITIALIZER
15004                 (struct cmd_set_vf_broadcast_result,
15005                  vf, "vf");
15006 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15007         TOKEN_STRING_INITIALIZER
15008                 (struct cmd_set_vf_broadcast_result,
15009                  broadcast, "broadcast");
15010 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15011         TOKEN_NUM_INITIALIZER
15012                 (struct cmd_set_vf_broadcast_result,
15013                  port_id, UINT16);
15014 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15015         TOKEN_NUM_INITIALIZER
15016                 (struct cmd_set_vf_broadcast_result,
15017                  vf_id, UINT16);
15018 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15019         TOKEN_STRING_INITIALIZER
15020                 (struct cmd_set_vf_broadcast_result,
15021                  on_off, "on#off");
15022
15023 static void
15024 cmd_set_vf_broadcast_parsed(
15025         void *parsed_result,
15026         __rte_unused struct cmdline *cl,
15027         __rte_unused void *data)
15028 {
15029         struct cmd_set_vf_broadcast_result *res = parsed_result;
15030         int ret = -ENOTSUP;
15031
15032         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15033
15034         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15035                 return;
15036
15037 #ifdef RTE_LIBRTE_I40E_PMD
15038         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15039                                             res->vf_id, is_on);
15040 #endif
15041
15042         switch (ret) {
15043         case 0:
15044                 break;
15045         case -EINVAL:
15046                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15047                 break;
15048         case -ENODEV:
15049                 printf("invalid port_id %d\n", res->port_id);
15050                 break;
15051         case -ENOTSUP:
15052                 printf("function not implemented\n");
15053                 break;
15054         default:
15055                 printf("programming error: (%s)\n", strerror(-ret));
15056         }
15057 }
15058
15059 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15060         .f = cmd_set_vf_broadcast_parsed,
15061         .data = NULL,
15062         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15063         .tokens = {
15064                 (void *)&cmd_set_vf_broadcast_set,
15065                 (void *)&cmd_set_vf_broadcast_vf,
15066                 (void *)&cmd_set_vf_broadcast_broadcast,
15067                 (void *)&cmd_set_vf_broadcast_port_id,
15068                 (void *)&cmd_set_vf_broadcast_vf_id,
15069                 (void *)&cmd_set_vf_broadcast_on_off,
15070                 NULL,
15071         },
15072 };
15073
15074 /* vf vlan tag configuration */
15075
15076 /* Common result structure for vf vlan tag */
15077 struct cmd_set_vf_vlan_tag_result {
15078         cmdline_fixed_string_t set;
15079         cmdline_fixed_string_t vf;
15080         cmdline_fixed_string_t vlan;
15081         cmdline_fixed_string_t tag;
15082         portid_t port_id;
15083         uint16_t vf_id;
15084         cmdline_fixed_string_t on_off;
15085 };
15086
15087 /* Common CLI fields for vf vlan tag enable disable */
15088 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15089         TOKEN_STRING_INITIALIZER
15090                 (struct cmd_set_vf_vlan_tag_result,
15091                  set, "set");
15092 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15093         TOKEN_STRING_INITIALIZER
15094                 (struct cmd_set_vf_vlan_tag_result,
15095                  vf, "vf");
15096 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15097         TOKEN_STRING_INITIALIZER
15098                 (struct cmd_set_vf_vlan_tag_result,
15099                  vlan, "vlan");
15100 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15101         TOKEN_STRING_INITIALIZER
15102                 (struct cmd_set_vf_vlan_tag_result,
15103                  tag, "tag");
15104 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15105         TOKEN_NUM_INITIALIZER
15106                 (struct cmd_set_vf_vlan_tag_result,
15107                  port_id, UINT16);
15108 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15109         TOKEN_NUM_INITIALIZER
15110                 (struct cmd_set_vf_vlan_tag_result,
15111                  vf_id, UINT16);
15112 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15113         TOKEN_STRING_INITIALIZER
15114                 (struct cmd_set_vf_vlan_tag_result,
15115                  on_off, "on#off");
15116
15117 static void
15118 cmd_set_vf_vlan_tag_parsed(
15119         void *parsed_result,
15120         __rte_unused struct cmdline *cl,
15121         __rte_unused void *data)
15122 {
15123         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15124         int ret = -ENOTSUP;
15125
15126         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15127
15128         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15129                 return;
15130
15131 #ifdef RTE_LIBRTE_I40E_PMD
15132         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15133                                            res->vf_id, is_on);
15134 #endif
15135
15136         switch (ret) {
15137         case 0:
15138                 break;
15139         case -EINVAL:
15140                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15141                 break;
15142         case -ENODEV:
15143                 printf("invalid port_id %d\n", res->port_id);
15144                 break;
15145         case -ENOTSUP:
15146                 printf("function not implemented\n");
15147                 break;
15148         default:
15149                 printf("programming error: (%s)\n", strerror(-ret));
15150         }
15151 }
15152
15153 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15154         .f = cmd_set_vf_vlan_tag_parsed,
15155         .data = NULL,
15156         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15157         .tokens = {
15158                 (void *)&cmd_set_vf_vlan_tag_set,
15159                 (void *)&cmd_set_vf_vlan_tag_vf,
15160                 (void *)&cmd_set_vf_vlan_tag_vlan,
15161                 (void *)&cmd_set_vf_vlan_tag_tag,
15162                 (void *)&cmd_set_vf_vlan_tag_port_id,
15163                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15164                 (void *)&cmd_set_vf_vlan_tag_on_off,
15165                 NULL,
15166         },
15167 };
15168
15169 /* Common definition of VF and TC TX bandwidth configuration */
15170 struct cmd_vf_tc_bw_result {
15171         cmdline_fixed_string_t set;
15172         cmdline_fixed_string_t vf;
15173         cmdline_fixed_string_t tc;
15174         cmdline_fixed_string_t tx;
15175         cmdline_fixed_string_t min_bw;
15176         cmdline_fixed_string_t max_bw;
15177         cmdline_fixed_string_t strict_link_prio;
15178         portid_t port_id;
15179         uint16_t vf_id;
15180         uint8_t tc_no;
15181         uint32_t bw;
15182         cmdline_fixed_string_t bw_list;
15183         uint8_t tc_map;
15184 };
15185
15186 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15187         TOKEN_STRING_INITIALIZER
15188                 (struct cmd_vf_tc_bw_result,
15189                  set, "set");
15190 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15191         TOKEN_STRING_INITIALIZER
15192                 (struct cmd_vf_tc_bw_result,
15193                  vf, "vf");
15194 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15195         TOKEN_STRING_INITIALIZER
15196                 (struct cmd_vf_tc_bw_result,
15197                  tc, "tc");
15198 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15199         TOKEN_STRING_INITIALIZER
15200                 (struct cmd_vf_tc_bw_result,
15201                  tx, "tx");
15202 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15203         TOKEN_STRING_INITIALIZER
15204                 (struct cmd_vf_tc_bw_result,
15205                  strict_link_prio, "strict-link-priority");
15206 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15207         TOKEN_STRING_INITIALIZER
15208                 (struct cmd_vf_tc_bw_result,
15209                  min_bw, "min-bandwidth");
15210 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15211         TOKEN_STRING_INITIALIZER
15212                 (struct cmd_vf_tc_bw_result,
15213                  max_bw, "max-bandwidth");
15214 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15215         TOKEN_NUM_INITIALIZER
15216                 (struct cmd_vf_tc_bw_result,
15217                  port_id, UINT16);
15218 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15219         TOKEN_NUM_INITIALIZER
15220                 (struct cmd_vf_tc_bw_result,
15221                  vf_id, UINT16);
15222 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15223         TOKEN_NUM_INITIALIZER
15224                 (struct cmd_vf_tc_bw_result,
15225                  tc_no, UINT8);
15226 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15227         TOKEN_NUM_INITIALIZER
15228                 (struct cmd_vf_tc_bw_result,
15229                  bw, UINT32);
15230 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15231         TOKEN_STRING_INITIALIZER
15232                 (struct cmd_vf_tc_bw_result,
15233                  bw_list, NULL);
15234 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15235         TOKEN_NUM_INITIALIZER
15236                 (struct cmd_vf_tc_bw_result,
15237                  tc_map, UINT8);
15238
15239 /* VF max bandwidth setting */
15240 static void
15241 cmd_vf_max_bw_parsed(
15242         void *parsed_result,
15243         __rte_unused struct cmdline *cl,
15244         __rte_unused void *data)
15245 {
15246         struct cmd_vf_tc_bw_result *res = parsed_result;
15247         int ret = -ENOTSUP;
15248
15249         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15250                 return;
15251
15252 #ifdef RTE_LIBRTE_I40E_PMD
15253         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15254                                          res->vf_id, res->bw);
15255 #endif
15256
15257         switch (ret) {
15258         case 0:
15259                 break;
15260         case -EINVAL:
15261                 printf("invalid vf_id %d or bandwidth %d\n",
15262                        res->vf_id, res->bw);
15263                 break;
15264         case -ENODEV:
15265                 printf("invalid port_id %d\n", res->port_id);
15266                 break;
15267         case -ENOTSUP:
15268                 printf("function not implemented\n");
15269                 break;
15270         default:
15271                 printf("programming error: (%s)\n", strerror(-ret));
15272         }
15273 }
15274
15275 cmdline_parse_inst_t cmd_vf_max_bw = {
15276         .f = cmd_vf_max_bw_parsed,
15277         .data = NULL,
15278         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15279         .tokens = {
15280                 (void *)&cmd_vf_tc_bw_set,
15281                 (void *)&cmd_vf_tc_bw_vf,
15282                 (void *)&cmd_vf_tc_bw_tx,
15283                 (void *)&cmd_vf_tc_bw_max_bw,
15284                 (void *)&cmd_vf_tc_bw_port_id,
15285                 (void *)&cmd_vf_tc_bw_vf_id,
15286                 (void *)&cmd_vf_tc_bw_bw,
15287                 NULL,
15288         },
15289 };
15290
15291 static int
15292 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15293                            uint8_t *tc_num,
15294                            char *str)
15295 {
15296         uint32_t size;
15297         const char *p, *p0 = str;
15298         char s[256];
15299         char *end;
15300         char *str_fld[16];
15301         uint16_t i;
15302         int ret;
15303
15304         p = strchr(p0, '(');
15305         if (p == NULL) {
15306                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15307                 return -1;
15308         }
15309         p++;
15310         p0 = strchr(p, ')');
15311         if (p0 == NULL) {
15312                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15313                 return -1;
15314         }
15315         size = p0 - p;
15316         if (size >= sizeof(s)) {
15317                 printf("The string size exceeds the internal buffer size\n");
15318                 return -1;
15319         }
15320         snprintf(s, sizeof(s), "%.*s", size, p);
15321         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15322         if (ret <= 0) {
15323                 printf("Failed to get the bandwidth list. ");
15324                 return -1;
15325         }
15326         *tc_num = ret;
15327         for (i = 0; i < ret; i++)
15328                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15329
15330         return 0;
15331 }
15332
15333 /* TC min bandwidth setting */
15334 static void
15335 cmd_vf_tc_min_bw_parsed(
15336         void *parsed_result,
15337         __rte_unused struct cmdline *cl,
15338         __rte_unused void *data)
15339 {
15340         struct cmd_vf_tc_bw_result *res = parsed_result;
15341         uint8_t tc_num;
15342         uint8_t bw[16];
15343         int ret = -ENOTSUP;
15344
15345         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15346                 return;
15347
15348         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15349         if (ret)
15350                 return;
15351
15352 #ifdef RTE_LIBRTE_I40E_PMD
15353         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15354                                               tc_num, bw);
15355 #endif
15356
15357         switch (ret) {
15358         case 0:
15359                 break;
15360         case -EINVAL:
15361                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15362                 break;
15363         case -ENODEV:
15364                 printf("invalid port_id %d\n", res->port_id);
15365                 break;
15366         case -ENOTSUP:
15367                 printf("function not implemented\n");
15368                 break;
15369         default:
15370                 printf("programming error: (%s)\n", strerror(-ret));
15371         }
15372 }
15373
15374 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15375         .f = cmd_vf_tc_min_bw_parsed,
15376         .data = NULL,
15377         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15378                     " <bw1, bw2, ...>",
15379         .tokens = {
15380                 (void *)&cmd_vf_tc_bw_set,
15381                 (void *)&cmd_vf_tc_bw_vf,
15382                 (void *)&cmd_vf_tc_bw_tc,
15383                 (void *)&cmd_vf_tc_bw_tx,
15384                 (void *)&cmd_vf_tc_bw_min_bw,
15385                 (void *)&cmd_vf_tc_bw_port_id,
15386                 (void *)&cmd_vf_tc_bw_vf_id,
15387                 (void *)&cmd_vf_tc_bw_bw_list,
15388                 NULL,
15389         },
15390 };
15391
15392 static void
15393 cmd_tc_min_bw_parsed(
15394         void *parsed_result,
15395         __rte_unused struct cmdline *cl,
15396         __rte_unused void *data)
15397 {
15398         struct cmd_vf_tc_bw_result *res = parsed_result;
15399         struct rte_port *port;
15400         uint8_t tc_num;
15401         uint8_t bw[16];
15402         int ret = -ENOTSUP;
15403
15404         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15405                 return;
15406
15407         port = &ports[res->port_id];
15408         /** Check if the port is not started **/
15409         if (port->port_status != RTE_PORT_STOPPED) {
15410                 printf("Please stop port %d first\n", res->port_id);
15411                 return;
15412         }
15413
15414         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15415         if (ret)
15416                 return;
15417
15418 #ifdef RTE_LIBRTE_IXGBE_PMD
15419         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15420 #endif
15421
15422         switch (ret) {
15423         case 0:
15424                 break;
15425         case -EINVAL:
15426                 printf("invalid bandwidth\n");
15427                 break;
15428         case -ENODEV:
15429                 printf("invalid port_id %d\n", res->port_id);
15430                 break;
15431         case -ENOTSUP:
15432                 printf("function not implemented\n");
15433                 break;
15434         default:
15435                 printf("programming error: (%s)\n", strerror(-ret));
15436         }
15437 }
15438
15439 cmdline_parse_inst_t cmd_tc_min_bw = {
15440         .f = cmd_tc_min_bw_parsed,
15441         .data = NULL,
15442         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15443         .tokens = {
15444                 (void *)&cmd_vf_tc_bw_set,
15445                 (void *)&cmd_vf_tc_bw_tc,
15446                 (void *)&cmd_vf_tc_bw_tx,
15447                 (void *)&cmd_vf_tc_bw_min_bw,
15448                 (void *)&cmd_vf_tc_bw_port_id,
15449                 (void *)&cmd_vf_tc_bw_bw_list,
15450                 NULL,
15451         },
15452 };
15453
15454 /* TC max bandwidth setting */
15455 static void
15456 cmd_vf_tc_max_bw_parsed(
15457         void *parsed_result,
15458         __rte_unused struct cmdline *cl,
15459         __rte_unused void *data)
15460 {
15461         struct cmd_vf_tc_bw_result *res = parsed_result;
15462         int ret = -ENOTSUP;
15463
15464         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15465                 return;
15466
15467 #ifdef RTE_LIBRTE_I40E_PMD
15468         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15469                                             res->tc_no, res->bw);
15470 #endif
15471
15472         switch (ret) {
15473         case 0:
15474                 break;
15475         case -EINVAL:
15476                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15477                        res->vf_id, res->tc_no, res->bw);
15478                 break;
15479         case -ENODEV:
15480                 printf("invalid port_id %d\n", res->port_id);
15481                 break;
15482         case -ENOTSUP:
15483                 printf("function not implemented\n");
15484                 break;
15485         default:
15486                 printf("programming error: (%s)\n", strerror(-ret));
15487         }
15488 }
15489
15490 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15491         .f = cmd_vf_tc_max_bw_parsed,
15492         .data = NULL,
15493         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15494                     " <bandwidth>",
15495         .tokens = {
15496                 (void *)&cmd_vf_tc_bw_set,
15497                 (void *)&cmd_vf_tc_bw_vf,
15498                 (void *)&cmd_vf_tc_bw_tc,
15499                 (void *)&cmd_vf_tc_bw_tx,
15500                 (void *)&cmd_vf_tc_bw_max_bw,
15501                 (void *)&cmd_vf_tc_bw_port_id,
15502                 (void *)&cmd_vf_tc_bw_vf_id,
15503                 (void *)&cmd_vf_tc_bw_tc_no,
15504                 (void *)&cmd_vf_tc_bw_bw,
15505                 NULL,
15506         },
15507 };
15508
15509 /** Set VXLAN encapsulation details */
15510 struct cmd_set_vxlan_result {
15511         cmdline_fixed_string_t set;
15512         cmdline_fixed_string_t vxlan;
15513         cmdline_fixed_string_t pos_token;
15514         cmdline_fixed_string_t ip_version;
15515         uint32_t vlan_present:1;
15516         uint32_t vni;
15517         uint16_t udp_src;
15518         uint16_t udp_dst;
15519         cmdline_ipaddr_t ip_src;
15520         cmdline_ipaddr_t ip_dst;
15521         uint16_t tci;
15522         uint8_t tos;
15523         uint8_t ttl;
15524         struct rte_ether_addr eth_src;
15525         struct rte_ether_addr eth_dst;
15526 };
15527
15528 cmdline_parse_token_string_t cmd_set_vxlan_set =
15529         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15530 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15531         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15532 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15533         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15534                                  "vxlan-tos-ttl");
15535 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15536         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15537                                  "vxlan-with-vlan");
15538 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15539         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15540                                  "ip-version");
15541 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15542         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15543                                  "ipv4#ipv6");
15544 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15545         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15546                                  "vni");
15547 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15548         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15549 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15550         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15551                                  "udp-src");
15552 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15553         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15554 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15555         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15556                                  "udp-dst");
15557 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15558         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15559 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15560         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15561                                  "ip-tos");
15562 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15563         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15564 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15565         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15566                                  "ip-ttl");
15567 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15568         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15569 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15570         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15571                                  "ip-src");
15572 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15573         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15574 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15575         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15576                                  "ip-dst");
15577 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15578         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15579 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15580         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15581                                  "vlan-tci");
15582 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15583         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15584 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15585         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15586                                  "eth-src");
15587 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15588         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15589 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15590         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15591                                  "eth-dst");
15592 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15593         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15594
15595 static void cmd_set_vxlan_parsed(void *parsed_result,
15596         __rte_unused struct cmdline *cl,
15597         __rte_unused void *data)
15598 {
15599         struct cmd_set_vxlan_result *res = parsed_result;
15600         union {
15601                 uint32_t vxlan_id;
15602                 uint8_t vni[4];
15603         } id = {
15604                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15605         };
15606
15607         vxlan_encap_conf.select_tos_ttl = 0;
15608         if (strcmp(res->vxlan, "vxlan") == 0)
15609                 vxlan_encap_conf.select_vlan = 0;
15610         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15611                 vxlan_encap_conf.select_vlan = 1;
15612         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15613                 vxlan_encap_conf.select_vlan = 0;
15614                 vxlan_encap_conf.select_tos_ttl = 1;
15615         }
15616         if (strcmp(res->ip_version, "ipv4") == 0)
15617                 vxlan_encap_conf.select_ipv4 = 1;
15618         else if (strcmp(res->ip_version, "ipv6") == 0)
15619                 vxlan_encap_conf.select_ipv4 = 0;
15620         else
15621                 return;
15622         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15623         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15624         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15625         vxlan_encap_conf.ip_tos = res->tos;
15626         vxlan_encap_conf.ip_ttl = res->ttl;
15627         if (vxlan_encap_conf.select_ipv4) {
15628                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15629                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15630         } else {
15631                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15632                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15633         }
15634         if (vxlan_encap_conf.select_vlan)
15635                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15636         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15637                    RTE_ETHER_ADDR_LEN);
15638         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15639                    RTE_ETHER_ADDR_LEN);
15640 }
15641
15642 cmdline_parse_inst_t cmd_set_vxlan = {
15643         .f = cmd_set_vxlan_parsed,
15644         .data = NULL,
15645         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15646                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15647                 " eth-src <eth-src> eth-dst <eth-dst>",
15648         .tokens = {
15649                 (void *)&cmd_set_vxlan_set,
15650                 (void *)&cmd_set_vxlan_vxlan,
15651                 (void *)&cmd_set_vxlan_ip_version,
15652                 (void *)&cmd_set_vxlan_ip_version_value,
15653                 (void *)&cmd_set_vxlan_vni,
15654                 (void *)&cmd_set_vxlan_vni_value,
15655                 (void *)&cmd_set_vxlan_udp_src,
15656                 (void *)&cmd_set_vxlan_udp_src_value,
15657                 (void *)&cmd_set_vxlan_udp_dst,
15658                 (void *)&cmd_set_vxlan_udp_dst_value,
15659                 (void *)&cmd_set_vxlan_ip_src,
15660                 (void *)&cmd_set_vxlan_ip_src_value,
15661                 (void *)&cmd_set_vxlan_ip_dst,
15662                 (void *)&cmd_set_vxlan_ip_dst_value,
15663                 (void *)&cmd_set_vxlan_eth_src,
15664                 (void *)&cmd_set_vxlan_eth_src_value,
15665                 (void *)&cmd_set_vxlan_eth_dst,
15666                 (void *)&cmd_set_vxlan_eth_dst_value,
15667                 NULL,
15668         },
15669 };
15670
15671 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15672         .f = cmd_set_vxlan_parsed,
15673         .data = NULL,
15674         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15675                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15676                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15677                 " eth-dst <eth-dst>",
15678         .tokens = {
15679                 (void *)&cmd_set_vxlan_set,
15680                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15681                 (void *)&cmd_set_vxlan_ip_version,
15682                 (void *)&cmd_set_vxlan_ip_version_value,
15683                 (void *)&cmd_set_vxlan_vni,
15684                 (void *)&cmd_set_vxlan_vni_value,
15685                 (void *)&cmd_set_vxlan_udp_src,
15686                 (void *)&cmd_set_vxlan_udp_src_value,
15687                 (void *)&cmd_set_vxlan_udp_dst,
15688                 (void *)&cmd_set_vxlan_udp_dst_value,
15689                 (void *)&cmd_set_vxlan_ip_tos,
15690                 (void *)&cmd_set_vxlan_ip_tos_value,
15691                 (void *)&cmd_set_vxlan_ip_ttl,
15692                 (void *)&cmd_set_vxlan_ip_ttl_value,
15693                 (void *)&cmd_set_vxlan_ip_src,
15694                 (void *)&cmd_set_vxlan_ip_src_value,
15695                 (void *)&cmd_set_vxlan_ip_dst,
15696                 (void *)&cmd_set_vxlan_ip_dst_value,
15697                 (void *)&cmd_set_vxlan_eth_src,
15698                 (void *)&cmd_set_vxlan_eth_src_value,
15699                 (void *)&cmd_set_vxlan_eth_dst,
15700                 (void *)&cmd_set_vxlan_eth_dst_value,
15701                 NULL,
15702         },
15703 };
15704
15705 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15706         .f = cmd_set_vxlan_parsed,
15707         .data = NULL,
15708         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15709                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15710                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15711                 " <eth-dst>",
15712         .tokens = {
15713                 (void *)&cmd_set_vxlan_set,
15714                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15715                 (void *)&cmd_set_vxlan_ip_version,
15716                 (void *)&cmd_set_vxlan_ip_version_value,
15717                 (void *)&cmd_set_vxlan_vni,
15718                 (void *)&cmd_set_vxlan_vni_value,
15719                 (void *)&cmd_set_vxlan_udp_src,
15720                 (void *)&cmd_set_vxlan_udp_src_value,
15721                 (void *)&cmd_set_vxlan_udp_dst,
15722                 (void *)&cmd_set_vxlan_udp_dst_value,
15723                 (void *)&cmd_set_vxlan_ip_src,
15724                 (void *)&cmd_set_vxlan_ip_src_value,
15725                 (void *)&cmd_set_vxlan_ip_dst,
15726                 (void *)&cmd_set_vxlan_ip_dst_value,
15727                 (void *)&cmd_set_vxlan_vlan,
15728                 (void *)&cmd_set_vxlan_vlan_value,
15729                 (void *)&cmd_set_vxlan_eth_src,
15730                 (void *)&cmd_set_vxlan_eth_src_value,
15731                 (void *)&cmd_set_vxlan_eth_dst,
15732                 (void *)&cmd_set_vxlan_eth_dst_value,
15733                 NULL,
15734         },
15735 };
15736
15737 /** Set NVGRE encapsulation details */
15738 struct cmd_set_nvgre_result {
15739         cmdline_fixed_string_t set;
15740         cmdline_fixed_string_t nvgre;
15741         cmdline_fixed_string_t pos_token;
15742         cmdline_fixed_string_t ip_version;
15743         uint32_t tni;
15744         cmdline_ipaddr_t ip_src;
15745         cmdline_ipaddr_t ip_dst;
15746         uint16_t tci;
15747         struct rte_ether_addr eth_src;
15748         struct rte_ether_addr eth_dst;
15749 };
15750
15751 cmdline_parse_token_string_t cmd_set_nvgre_set =
15752         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15753 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15755 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15756         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15757                                  "nvgre-with-vlan");
15758 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15759         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15760                                  "ip-version");
15761 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15762         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15763                                  "ipv4#ipv6");
15764 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15765         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15766                                  "tni");
15767 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15768         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15769 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15770         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15771                                  "ip-src");
15772 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15773         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15774 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15775         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15776                                  "ip-dst");
15777 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15778         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15779 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15780         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15781                                  "vlan-tci");
15782 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15783         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15784 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15785         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15786                                  "eth-src");
15787 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15788         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15789 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15790         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15791                                  "eth-dst");
15792 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15793         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15794
15795 static void cmd_set_nvgre_parsed(void *parsed_result,
15796         __rte_unused struct cmdline *cl,
15797         __rte_unused void *data)
15798 {
15799         struct cmd_set_nvgre_result *res = parsed_result;
15800         union {
15801                 uint32_t nvgre_tni;
15802                 uint8_t tni[4];
15803         } id = {
15804                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15805         };
15806
15807         if (strcmp(res->nvgre, "nvgre") == 0)
15808                 nvgre_encap_conf.select_vlan = 0;
15809         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15810                 nvgre_encap_conf.select_vlan = 1;
15811         if (strcmp(res->ip_version, "ipv4") == 0)
15812                 nvgre_encap_conf.select_ipv4 = 1;
15813         else if (strcmp(res->ip_version, "ipv6") == 0)
15814                 nvgre_encap_conf.select_ipv4 = 0;
15815         else
15816                 return;
15817         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15818         if (nvgre_encap_conf.select_ipv4) {
15819                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15820                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15821         } else {
15822                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15823                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15824         }
15825         if (nvgre_encap_conf.select_vlan)
15826                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15827         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15828                    RTE_ETHER_ADDR_LEN);
15829         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15830                    RTE_ETHER_ADDR_LEN);
15831 }
15832
15833 cmdline_parse_inst_t cmd_set_nvgre = {
15834         .f = cmd_set_nvgre_parsed,
15835         .data = NULL,
15836         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15837                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15838                 " eth-dst <eth-dst>",
15839         .tokens = {
15840                 (void *)&cmd_set_nvgre_set,
15841                 (void *)&cmd_set_nvgre_nvgre,
15842                 (void *)&cmd_set_nvgre_ip_version,
15843                 (void *)&cmd_set_nvgre_ip_version_value,
15844                 (void *)&cmd_set_nvgre_tni,
15845                 (void *)&cmd_set_nvgre_tni_value,
15846                 (void *)&cmd_set_nvgre_ip_src,
15847                 (void *)&cmd_set_nvgre_ip_src_value,
15848                 (void *)&cmd_set_nvgre_ip_dst,
15849                 (void *)&cmd_set_nvgre_ip_dst_value,
15850                 (void *)&cmd_set_nvgre_eth_src,
15851                 (void *)&cmd_set_nvgre_eth_src_value,
15852                 (void *)&cmd_set_nvgre_eth_dst,
15853                 (void *)&cmd_set_nvgre_eth_dst_value,
15854                 NULL,
15855         },
15856 };
15857
15858 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15859         .f = cmd_set_nvgre_parsed,
15860         .data = NULL,
15861         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15862                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15863                 " eth-src <eth-src> eth-dst <eth-dst>",
15864         .tokens = {
15865                 (void *)&cmd_set_nvgre_set,
15866                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15867                 (void *)&cmd_set_nvgre_ip_version,
15868                 (void *)&cmd_set_nvgre_ip_version_value,
15869                 (void *)&cmd_set_nvgre_tni,
15870                 (void *)&cmd_set_nvgre_tni_value,
15871                 (void *)&cmd_set_nvgre_ip_src,
15872                 (void *)&cmd_set_nvgre_ip_src_value,
15873                 (void *)&cmd_set_nvgre_ip_dst,
15874                 (void *)&cmd_set_nvgre_ip_dst_value,
15875                 (void *)&cmd_set_nvgre_vlan,
15876                 (void *)&cmd_set_nvgre_vlan_value,
15877                 (void *)&cmd_set_nvgre_eth_src,
15878                 (void *)&cmd_set_nvgre_eth_src_value,
15879                 (void *)&cmd_set_nvgre_eth_dst,
15880                 (void *)&cmd_set_nvgre_eth_dst_value,
15881                 NULL,
15882         },
15883 };
15884
15885 /** Set L2 encapsulation details */
15886 struct cmd_set_l2_encap_result {
15887         cmdline_fixed_string_t set;
15888         cmdline_fixed_string_t l2_encap;
15889         cmdline_fixed_string_t pos_token;
15890         cmdline_fixed_string_t ip_version;
15891         uint32_t vlan_present:1;
15892         uint16_t tci;
15893         struct rte_ether_addr eth_src;
15894         struct rte_ether_addr eth_dst;
15895 };
15896
15897 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15898         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15899 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15900         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15901 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15902         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15903                                  "l2_encap-with-vlan");
15904 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15905         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15906                                  "ip-version");
15907 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15909                                  "ipv4#ipv6");
15910 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15911         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15912                                  "vlan-tci");
15913 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15914         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15915 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15916         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15917                                  "eth-src");
15918 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15919         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15920 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15921         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15922                                  "eth-dst");
15923 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15924         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15925
15926 static void cmd_set_l2_encap_parsed(void *parsed_result,
15927         __rte_unused struct cmdline *cl,
15928         __rte_unused void *data)
15929 {
15930         struct cmd_set_l2_encap_result *res = parsed_result;
15931
15932         if (strcmp(res->l2_encap, "l2_encap") == 0)
15933                 l2_encap_conf.select_vlan = 0;
15934         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15935                 l2_encap_conf.select_vlan = 1;
15936         if (strcmp(res->ip_version, "ipv4") == 0)
15937                 l2_encap_conf.select_ipv4 = 1;
15938         else if (strcmp(res->ip_version, "ipv6") == 0)
15939                 l2_encap_conf.select_ipv4 = 0;
15940         else
15941                 return;
15942         if (l2_encap_conf.select_vlan)
15943                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15944         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15945                    RTE_ETHER_ADDR_LEN);
15946         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15947                    RTE_ETHER_ADDR_LEN);
15948 }
15949
15950 cmdline_parse_inst_t cmd_set_l2_encap = {
15951         .f = cmd_set_l2_encap_parsed,
15952         .data = NULL,
15953         .help_str = "set l2_encap ip-version ipv4|ipv6"
15954                 " eth-src <eth-src> eth-dst <eth-dst>",
15955         .tokens = {
15956                 (void *)&cmd_set_l2_encap_set,
15957                 (void *)&cmd_set_l2_encap_l2_encap,
15958                 (void *)&cmd_set_l2_encap_ip_version,
15959                 (void *)&cmd_set_l2_encap_ip_version_value,
15960                 (void *)&cmd_set_l2_encap_eth_src,
15961                 (void *)&cmd_set_l2_encap_eth_src_value,
15962                 (void *)&cmd_set_l2_encap_eth_dst,
15963                 (void *)&cmd_set_l2_encap_eth_dst_value,
15964                 NULL,
15965         },
15966 };
15967
15968 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15969         .f = cmd_set_l2_encap_parsed,
15970         .data = NULL,
15971         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15972                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15973         .tokens = {
15974                 (void *)&cmd_set_l2_encap_set,
15975                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15976                 (void *)&cmd_set_l2_encap_ip_version,
15977                 (void *)&cmd_set_l2_encap_ip_version_value,
15978                 (void *)&cmd_set_l2_encap_vlan,
15979                 (void *)&cmd_set_l2_encap_vlan_value,
15980                 (void *)&cmd_set_l2_encap_eth_src,
15981                 (void *)&cmd_set_l2_encap_eth_src_value,
15982                 (void *)&cmd_set_l2_encap_eth_dst,
15983                 (void *)&cmd_set_l2_encap_eth_dst_value,
15984                 NULL,
15985         },
15986 };
15987
15988 /** Set L2 decapsulation details */
15989 struct cmd_set_l2_decap_result {
15990         cmdline_fixed_string_t set;
15991         cmdline_fixed_string_t l2_decap;
15992         cmdline_fixed_string_t pos_token;
15993         uint32_t vlan_present:1;
15994 };
15995
15996 cmdline_parse_token_string_t cmd_set_l2_decap_set =
15997         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
15998 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16000                                  "l2_decap");
16001 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16002         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16003                                  "l2_decap-with-vlan");
16004
16005 static void cmd_set_l2_decap_parsed(void *parsed_result,
16006         __rte_unused struct cmdline *cl,
16007         __rte_unused void *data)
16008 {
16009         struct cmd_set_l2_decap_result *res = parsed_result;
16010
16011         if (strcmp(res->l2_decap, "l2_decap") == 0)
16012                 l2_decap_conf.select_vlan = 0;
16013         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16014                 l2_decap_conf.select_vlan = 1;
16015 }
16016
16017 cmdline_parse_inst_t cmd_set_l2_decap = {
16018         .f = cmd_set_l2_decap_parsed,
16019         .data = NULL,
16020         .help_str = "set l2_decap",
16021         .tokens = {
16022                 (void *)&cmd_set_l2_decap_set,
16023                 (void *)&cmd_set_l2_decap_l2_decap,
16024                 NULL,
16025         },
16026 };
16027
16028 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16029         .f = cmd_set_l2_decap_parsed,
16030         .data = NULL,
16031         .help_str = "set l2_decap-with-vlan",
16032         .tokens = {
16033                 (void *)&cmd_set_l2_decap_set,
16034                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16035                 NULL,
16036         },
16037 };
16038
16039 /** Set MPLSoGRE encapsulation details */
16040 struct cmd_set_mplsogre_encap_result {
16041         cmdline_fixed_string_t set;
16042         cmdline_fixed_string_t mplsogre;
16043         cmdline_fixed_string_t pos_token;
16044         cmdline_fixed_string_t ip_version;
16045         uint32_t vlan_present:1;
16046         uint32_t label;
16047         cmdline_ipaddr_t ip_src;
16048         cmdline_ipaddr_t ip_dst;
16049         uint16_t tci;
16050         struct rte_ether_addr eth_src;
16051         struct rte_ether_addr eth_dst;
16052 };
16053
16054 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16056                                  "set");
16057 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16058         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16059                                  "mplsogre_encap");
16060 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16061         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16062                                  mplsogre, "mplsogre_encap-with-vlan");
16063 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16064         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16065                                  pos_token, "ip-version");
16066 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16067         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16068                                  ip_version, "ipv4#ipv6");
16069 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16070         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16071                                  pos_token, "label");
16072 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16073         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16074                               UINT32);
16075 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16076         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16077                                  pos_token, "ip-src");
16078 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16079         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16080 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16081         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16082                                  pos_token, "ip-dst");
16083 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16084         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16085 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16086         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16087                                  pos_token, "vlan-tci");
16088 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16089         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16090                               UINT16);
16091 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16092         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16093                                  pos_token, "eth-src");
16094 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16095         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16096                                     eth_src);
16097 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16098         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16099                                  pos_token, "eth-dst");
16100 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16101         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16102                                     eth_dst);
16103
16104 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16105         __rte_unused struct cmdline *cl,
16106         __rte_unused void *data)
16107 {
16108         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16109         union {
16110                 uint32_t mplsogre_label;
16111                 uint8_t label[4];
16112         } id = {
16113                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16114         };
16115
16116         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16117                 mplsogre_encap_conf.select_vlan = 0;
16118         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16119                 mplsogre_encap_conf.select_vlan = 1;
16120         if (strcmp(res->ip_version, "ipv4") == 0)
16121                 mplsogre_encap_conf.select_ipv4 = 1;
16122         else if (strcmp(res->ip_version, "ipv6") == 0)
16123                 mplsogre_encap_conf.select_ipv4 = 0;
16124         else
16125                 return;
16126         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16127         if (mplsogre_encap_conf.select_ipv4) {
16128                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16129                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16130         } else {
16131                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16132                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16133         }
16134         if (mplsogre_encap_conf.select_vlan)
16135                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16136         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16137                    RTE_ETHER_ADDR_LEN);
16138         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16139                    RTE_ETHER_ADDR_LEN);
16140 }
16141
16142 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16143         .f = cmd_set_mplsogre_encap_parsed,
16144         .data = NULL,
16145         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16146                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16147                 " eth-dst <eth-dst>",
16148         .tokens = {
16149                 (void *)&cmd_set_mplsogre_encap_set,
16150                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16151                 (void *)&cmd_set_mplsogre_encap_ip_version,
16152                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16153                 (void *)&cmd_set_mplsogre_encap_label,
16154                 (void *)&cmd_set_mplsogre_encap_label_value,
16155                 (void *)&cmd_set_mplsogre_encap_ip_src,
16156                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16157                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16158                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16159                 (void *)&cmd_set_mplsogre_encap_eth_src,
16160                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16161                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16162                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16163                 NULL,
16164         },
16165 };
16166
16167 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16168         .f = cmd_set_mplsogre_encap_parsed,
16169         .data = NULL,
16170         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16171                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16172                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16173         .tokens = {
16174                 (void *)&cmd_set_mplsogre_encap_set,
16175                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16176                 (void *)&cmd_set_mplsogre_encap_ip_version,
16177                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16178                 (void *)&cmd_set_mplsogre_encap_label,
16179                 (void *)&cmd_set_mplsogre_encap_label_value,
16180                 (void *)&cmd_set_mplsogre_encap_ip_src,
16181                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16182                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16183                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16184                 (void *)&cmd_set_mplsogre_encap_vlan,
16185                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16186                 (void *)&cmd_set_mplsogre_encap_eth_src,
16187                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16188                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16189                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16190                 NULL,
16191         },
16192 };
16193
16194 /** Set MPLSoGRE decapsulation details */
16195 struct cmd_set_mplsogre_decap_result {
16196         cmdline_fixed_string_t set;
16197         cmdline_fixed_string_t mplsogre;
16198         cmdline_fixed_string_t pos_token;
16199         cmdline_fixed_string_t ip_version;
16200         uint32_t vlan_present:1;
16201 };
16202
16203 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16205                                  "set");
16206 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16207         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16208                                  "mplsogre_decap");
16209 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16211                                  mplsogre, "mplsogre_decap-with-vlan");
16212 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16213         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16214                                  pos_token, "ip-version");
16215 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16217                                  ip_version, "ipv4#ipv6");
16218
16219 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16220         __rte_unused struct cmdline *cl,
16221         __rte_unused void *data)
16222 {
16223         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16224
16225         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16226                 mplsogre_decap_conf.select_vlan = 0;
16227         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16228                 mplsogre_decap_conf.select_vlan = 1;
16229         if (strcmp(res->ip_version, "ipv4") == 0)
16230                 mplsogre_decap_conf.select_ipv4 = 1;
16231         else if (strcmp(res->ip_version, "ipv6") == 0)
16232                 mplsogre_decap_conf.select_ipv4 = 0;
16233 }
16234
16235 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16236         .f = cmd_set_mplsogre_decap_parsed,
16237         .data = NULL,
16238         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16239         .tokens = {
16240                 (void *)&cmd_set_mplsogre_decap_set,
16241                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16242                 (void *)&cmd_set_mplsogre_decap_ip_version,
16243                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16244                 NULL,
16245         },
16246 };
16247
16248 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16249         .f = cmd_set_mplsogre_decap_parsed,
16250         .data = NULL,
16251         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16252         .tokens = {
16253                 (void *)&cmd_set_mplsogre_decap_set,
16254                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16255                 (void *)&cmd_set_mplsogre_decap_ip_version,
16256                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16257                 NULL,
16258         },
16259 };
16260
16261 /** Set MPLSoUDP encapsulation details */
16262 struct cmd_set_mplsoudp_encap_result {
16263         cmdline_fixed_string_t set;
16264         cmdline_fixed_string_t mplsoudp;
16265         cmdline_fixed_string_t pos_token;
16266         cmdline_fixed_string_t ip_version;
16267         uint32_t vlan_present:1;
16268         uint32_t label;
16269         uint16_t udp_src;
16270         uint16_t udp_dst;
16271         cmdline_ipaddr_t ip_src;
16272         cmdline_ipaddr_t ip_dst;
16273         uint16_t tci;
16274         struct rte_ether_addr eth_src;
16275         struct rte_ether_addr eth_dst;
16276 };
16277
16278 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16279         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16280                                  "set");
16281 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16282         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16283                                  "mplsoudp_encap");
16284 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16285         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16286                                  mplsoudp, "mplsoudp_encap-with-vlan");
16287 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16288         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16289                                  pos_token, "ip-version");
16290 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16291         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16292                                  ip_version, "ipv4#ipv6");
16293 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16294         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16295                                  pos_token, "label");
16296 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16297         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16298                               UINT32);
16299 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16300         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16301                                  pos_token, "udp-src");
16302 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16303         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16304                               UINT16);
16305 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16306         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16307                                  pos_token, "udp-dst");
16308 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16309         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16310                               UINT16);
16311 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16312         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16313                                  pos_token, "ip-src");
16314 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16315         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16316 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16317         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16318                                  pos_token, "ip-dst");
16319 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16320         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16321 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16322         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16323                                  pos_token, "vlan-tci");
16324 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16325         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16326                               UINT16);
16327 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16328         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16329                                  pos_token, "eth-src");
16330 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16331         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16332                                     eth_src);
16333 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16334         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16335                                  pos_token, "eth-dst");
16336 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16337         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16338                                     eth_dst);
16339
16340 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16341         __rte_unused struct cmdline *cl,
16342         __rte_unused void *data)
16343 {
16344         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16345         union {
16346                 uint32_t mplsoudp_label;
16347                 uint8_t label[4];
16348         } id = {
16349                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16350         };
16351
16352         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16353                 mplsoudp_encap_conf.select_vlan = 0;
16354         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16355                 mplsoudp_encap_conf.select_vlan = 1;
16356         if (strcmp(res->ip_version, "ipv4") == 0)
16357                 mplsoudp_encap_conf.select_ipv4 = 1;
16358         else if (strcmp(res->ip_version, "ipv6") == 0)
16359                 mplsoudp_encap_conf.select_ipv4 = 0;
16360         else
16361                 return;
16362         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16363         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16364         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16365         if (mplsoudp_encap_conf.select_ipv4) {
16366                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16367                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16368         } else {
16369                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16370                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16371         }
16372         if (mplsoudp_encap_conf.select_vlan)
16373                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16374         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16375                    RTE_ETHER_ADDR_LEN);
16376         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16377                    RTE_ETHER_ADDR_LEN);
16378 }
16379
16380 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16381         .f = cmd_set_mplsoudp_encap_parsed,
16382         .data = NULL,
16383         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16384                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16385                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16386         .tokens = {
16387                 (void *)&cmd_set_mplsoudp_encap_set,
16388                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16389                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16390                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16391                 (void *)&cmd_set_mplsoudp_encap_label,
16392                 (void *)&cmd_set_mplsoudp_encap_label_value,
16393                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16394                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16395                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16396                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16397                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16398                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16399                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16400                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16401                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16402                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16403                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16404                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16405                 NULL,
16406         },
16407 };
16408
16409 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16410         .f = cmd_set_mplsoudp_encap_parsed,
16411         .data = NULL,
16412         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16413                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16414                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16415                 " eth-src <eth-src> eth-dst <eth-dst>",
16416         .tokens = {
16417                 (void *)&cmd_set_mplsoudp_encap_set,
16418                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16419                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16420                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16421                 (void *)&cmd_set_mplsoudp_encap_label,
16422                 (void *)&cmd_set_mplsoudp_encap_label_value,
16423                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16424                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16425                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16426                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16427                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16428                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16429                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16430                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16431                 (void *)&cmd_set_mplsoudp_encap_vlan,
16432                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16433                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16434                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16435                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16436                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16437                 NULL,
16438         },
16439 };
16440
16441 /** Set MPLSoUDP decapsulation details */
16442 struct cmd_set_mplsoudp_decap_result {
16443         cmdline_fixed_string_t set;
16444         cmdline_fixed_string_t mplsoudp;
16445         cmdline_fixed_string_t pos_token;
16446         cmdline_fixed_string_t ip_version;
16447         uint32_t vlan_present:1;
16448 };
16449
16450 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16451         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16452                                  "set");
16453 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16454         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16455                                  "mplsoudp_decap");
16456 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16457         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16458                                  mplsoudp, "mplsoudp_decap-with-vlan");
16459 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16460         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16461                                  pos_token, "ip-version");
16462 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16463         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16464                                  ip_version, "ipv4#ipv6");
16465
16466 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16467         __rte_unused struct cmdline *cl,
16468         __rte_unused void *data)
16469 {
16470         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16471
16472         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16473                 mplsoudp_decap_conf.select_vlan = 0;
16474         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16475                 mplsoudp_decap_conf.select_vlan = 1;
16476         if (strcmp(res->ip_version, "ipv4") == 0)
16477                 mplsoudp_decap_conf.select_ipv4 = 1;
16478         else if (strcmp(res->ip_version, "ipv6") == 0)
16479                 mplsoudp_decap_conf.select_ipv4 = 0;
16480 }
16481
16482 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16483         .f = cmd_set_mplsoudp_decap_parsed,
16484         .data = NULL,
16485         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16486         .tokens = {
16487                 (void *)&cmd_set_mplsoudp_decap_set,
16488                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16489                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16490                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16491                 NULL,
16492         },
16493 };
16494
16495 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16496         .f = cmd_set_mplsoudp_decap_parsed,
16497         .data = NULL,
16498         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16499         .tokens = {
16500                 (void *)&cmd_set_mplsoudp_decap_set,
16501                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16502                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16503                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16504                 NULL,
16505         },
16506 };
16507
16508 /* Strict link priority scheduling mode setting */
16509 static void
16510 cmd_strict_link_prio_parsed(
16511         void *parsed_result,
16512         __rte_unused struct cmdline *cl,
16513         __rte_unused void *data)
16514 {
16515         struct cmd_vf_tc_bw_result *res = parsed_result;
16516         int ret = -ENOTSUP;
16517
16518         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16519                 return;
16520
16521 #ifdef RTE_LIBRTE_I40E_PMD
16522         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16523 #endif
16524
16525         switch (ret) {
16526         case 0:
16527                 break;
16528         case -EINVAL:
16529                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16530                 break;
16531         case -ENODEV:
16532                 printf("invalid port_id %d\n", res->port_id);
16533                 break;
16534         case -ENOTSUP:
16535                 printf("function not implemented\n");
16536                 break;
16537         default:
16538                 printf("programming error: (%s)\n", strerror(-ret));
16539         }
16540 }
16541
16542 cmdline_parse_inst_t cmd_strict_link_prio = {
16543         .f = cmd_strict_link_prio_parsed,
16544         .data = NULL,
16545         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16546         .tokens = {
16547                 (void *)&cmd_vf_tc_bw_set,
16548                 (void *)&cmd_vf_tc_bw_tx,
16549                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16550                 (void *)&cmd_vf_tc_bw_port_id,
16551                 (void *)&cmd_vf_tc_bw_tc_map,
16552                 NULL,
16553         },
16554 };
16555
16556 /* Load dynamic device personalization*/
16557 struct cmd_ddp_add_result {
16558         cmdline_fixed_string_t ddp;
16559         cmdline_fixed_string_t add;
16560         portid_t port_id;
16561         char filepath[];
16562 };
16563
16564 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16565         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16566 cmdline_parse_token_string_t cmd_ddp_add_add =
16567         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16568 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16569         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16570 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16571         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16572
16573 static void
16574 cmd_ddp_add_parsed(
16575         void *parsed_result,
16576         __rte_unused struct cmdline *cl,
16577         __rte_unused void *data)
16578 {
16579         struct cmd_ddp_add_result *res = parsed_result;
16580         uint8_t *buff;
16581         uint32_t size;
16582         char *filepath;
16583         char *file_fld[2];
16584         int file_num;
16585         int ret = -ENOTSUP;
16586
16587         if (!all_ports_stopped()) {
16588                 printf("Please stop all ports first\n");
16589                 return;
16590         }
16591
16592         filepath = strdup(res->filepath);
16593         if (filepath == NULL) {
16594                 printf("Failed to allocate memory\n");
16595                 return;
16596         }
16597         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16598
16599         buff = open_file(file_fld[0], &size);
16600         if (!buff) {
16601                 free((void *)filepath);
16602                 return;
16603         }
16604
16605 #ifdef RTE_LIBRTE_I40E_PMD
16606         if (ret == -ENOTSUP)
16607                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16608                                                buff, size,
16609                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16610 #endif
16611
16612         if (ret == -EEXIST)
16613                 printf("Profile has already existed.\n");
16614         else if (ret < 0)
16615                 printf("Failed to load profile.\n");
16616         else if (file_num == 2)
16617                 save_file(file_fld[1], buff, size);
16618
16619         close_file(buff);
16620         free((void *)filepath);
16621 }
16622
16623 cmdline_parse_inst_t cmd_ddp_add = {
16624         .f = cmd_ddp_add_parsed,
16625         .data = NULL,
16626         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16627         .tokens = {
16628                 (void *)&cmd_ddp_add_ddp,
16629                 (void *)&cmd_ddp_add_add,
16630                 (void *)&cmd_ddp_add_port_id,
16631                 (void *)&cmd_ddp_add_filepath,
16632                 NULL,
16633         },
16634 };
16635
16636 /* Delete dynamic device personalization*/
16637 struct cmd_ddp_del_result {
16638         cmdline_fixed_string_t ddp;
16639         cmdline_fixed_string_t del;
16640         portid_t port_id;
16641         char filepath[];
16642 };
16643
16644 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16645         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16646 cmdline_parse_token_string_t cmd_ddp_del_del =
16647         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16648 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16649         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16650 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16651         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16652
16653 static void
16654 cmd_ddp_del_parsed(
16655         void *parsed_result,
16656         __rte_unused struct cmdline *cl,
16657         __rte_unused void *data)
16658 {
16659         struct cmd_ddp_del_result *res = parsed_result;
16660         uint8_t *buff;
16661         uint32_t size;
16662         int ret = -ENOTSUP;
16663
16664         if (!all_ports_stopped()) {
16665                 printf("Please stop all ports first\n");
16666                 return;
16667         }
16668
16669         buff = open_file(res->filepath, &size);
16670         if (!buff)
16671                 return;
16672
16673 #ifdef RTE_LIBRTE_I40E_PMD
16674         if (ret == -ENOTSUP)
16675                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16676                                                buff, size,
16677                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16678 #endif
16679
16680         if (ret == -EACCES)
16681                 printf("Profile does not exist.\n");
16682         else if (ret < 0)
16683                 printf("Failed to delete profile.\n");
16684
16685         close_file(buff);
16686 }
16687
16688 cmdline_parse_inst_t cmd_ddp_del = {
16689         .f = cmd_ddp_del_parsed,
16690         .data = NULL,
16691         .help_str = "ddp del <port_id> <backup_profile_path>",
16692         .tokens = {
16693                 (void *)&cmd_ddp_del_ddp,
16694                 (void *)&cmd_ddp_del_del,
16695                 (void *)&cmd_ddp_del_port_id,
16696                 (void *)&cmd_ddp_del_filepath,
16697                 NULL,
16698         },
16699 };
16700
16701 /* Get dynamic device personalization profile info */
16702 struct cmd_ddp_info_result {
16703         cmdline_fixed_string_t ddp;
16704         cmdline_fixed_string_t get;
16705         cmdline_fixed_string_t info;
16706         char filepath[];
16707 };
16708
16709 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16710         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16711 cmdline_parse_token_string_t cmd_ddp_info_get =
16712         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16713 cmdline_parse_token_string_t cmd_ddp_info_info =
16714         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16715 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16716         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16717
16718 static void
16719 cmd_ddp_info_parsed(
16720         void *parsed_result,
16721         __rte_unused struct cmdline *cl,
16722         __rte_unused void *data)
16723 {
16724         struct cmd_ddp_info_result *res = parsed_result;
16725         uint8_t *pkg;
16726         uint32_t pkg_size;
16727         int ret = -ENOTSUP;
16728 #ifdef RTE_LIBRTE_I40E_PMD
16729         uint32_t i, j, n;
16730         uint8_t *buff;
16731         uint32_t buff_size = 0;
16732         struct rte_pmd_i40e_profile_info info;
16733         uint32_t dev_num = 0;
16734         struct rte_pmd_i40e_ddp_device_id *devs;
16735         uint32_t proto_num = 0;
16736         struct rte_pmd_i40e_proto_info *proto = NULL;
16737         uint32_t pctype_num = 0;
16738         struct rte_pmd_i40e_ptype_info *pctype;
16739         uint32_t ptype_num = 0;
16740         struct rte_pmd_i40e_ptype_info *ptype;
16741         uint8_t proto_id;
16742
16743 #endif
16744
16745         pkg = open_file(res->filepath, &pkg_size);
16746         if (!pkg)
16747                 return;
16748
16749 #ifdef RTE_LIBRTE_I40E_PMD
16750         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16751                                 (uint8_t *)&info, sizeof(info),
16752                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16753         if (!ret) {
16754                 printf("Global Track id:       0x%x\n", info.track_id);
16755                 printf("Global Version:        %d.%d.%d.%d\n",
16756                         info.version.major,
16757                         info.version.minor,
16758                         info.version.update,
16759                         info.version.draft);
16760                 printf("Global Package name:   %s\n\n", info.name);
16761         }
16762
16763         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16764                                 (uint8_t *)&info, sizeof(info),
16765                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16766         if (!ret) {
16767                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16768                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16769                         info.version.major,
16770                         info.version.minor,
16771                         info.version.update,
16772                         info.version.draft);
16773                 printf("i40e Profile name:     %s\n\n", info.name);
16774         }
16775
16776         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16777                                 (uint8_t *)&buff_size, sizeof(buff_size),
16778                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16779         if (!ret && buff_size) {
16780                 buff = (uint8_t *)malloc(buff_size);
16781                 if (buff) {
16782                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16783                                                 buff, buff_size,
16784                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16785                         if (!ret)
16786                                 printf("Package Notes:\n%s\n\n", buff);
16787                         free(buff);
16788                 }
16789         }
16790
16791         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16792                                 (uint8_t *)&dev_num, sizeof(dev_num),
16793                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16794         if (!ret && dev_num) {
16795                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16796                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16797                 if (devs) {
16798                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16799                                                 (uint8_t *)devs, buff_size,
16800                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16801                         if (!ret) {
16802                                 printf("List of supported devices:\n");
16803                                 for (i = 0; i < dev_num; i++) {
16804                                         printf("  %04X:%04X %04X:%04X\n",
16805                                                 devs[i].vendor_dev_id >> 16,
16806                                                 devs[i].vendor_dev_id & 0xFFFF,
16807                                                 devs[i].sub_vendor_dev_id >> 16,
16808                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16809                                 }
16810                                 printf("\n");
16811                         }
16812                         free(devs);
16813                 }
16814         }
16815
16816         /* get information about protocols and packet types */
16817         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16818                 (uint8_t *)&proto_num, sizeof(proto_num),
16819                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16820         if (ret || !proto_num)
16821                 goto no_print_return;
16822
16823         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16824         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16825         if (!proto)
16826                 goto no_print_return;
16827
16828         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16829                                         buff_size,
16830                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16831         if (!ret) {
16832                 printf("List of used protocols:\n");
16833                 for (i = 0; i < proto_num; i++)
16834                         printf("  %2u: %s\n", proto[i].proto_id,
16835                                proto[i].name);
16836                 printf("\n");
16837         }
16838         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16839                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16840                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16841         if (ret || !pctype_num)
16842                 goto no_print_pctypes;
16843
16844         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16845         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16846         if (!pctype)
16847                 goto no_print_pctypes;
16848
16849         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16850                                         buff_size,
16851                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16852         if (ret) {
16853                 free(pctype);
16854                 goto no_print_pctypes;
16855         }
16856
16857         printf("List of defined packet classification types:\n");
16858         for (i = 0; i < pctype_num; i++) {
16859                 printf("  %2u:", pctype[i].ptype_id);
16860                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16861                         proto_id = pctype[i].protocols[j];
16862                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16863                                 for (n = 0; n < proto_num; n++) {
16864                                         if (proto[n].proto_id == proto_id) {
16865                                                 printf(" %s", proto[n].name);
16866                                                 break;
16867                                         }
16868                                 }
16869                         }
16870                 }
16871                 printf("\n");
16872         }
16873         printf("\n");
16874         free(pctype);
16875
16876 no_print_pctypes:
16877
16878         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16879                                         sizeof(ptype_num),
16880                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16881         if (ret || !ptype_num)
16882                 goto no_print_return;
16883
16884         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16885         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16886         if (!ptype)
16887                 goto no_print_return;
16888
16889         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16890                                         buff_size,
16891                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16892         if (ret) {
16893                 free(ptype);
16894                 goto no_print_return;
16895         }
16896         printf("List of defined packet types:\n");
16897         for (i = 0; i < ptype_num; i++) {
16898                 printf("  %2u:", ptype[i].ptype_id);
16899                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16900                         proto_id = ptype[i].protocols[j];
16901                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16902                                 for (n = 0; n < proto_num; n++) {
16903                                         if (proto[n].proto_id == proto_id) {
16904                                                 printf(" %s", proto[n].name);
16905                                                 break;
16906                                         }
16907                                 }
16908                         }
16909                 }
16910                 printf("\n");
16911         }
16912         free(ptype);
16913         printf("\n");
16914
16915         ret = 0;
16916 no_print_return:
16917         if (proto)
16918                 free(proto);
16919 #endif
16920         if (ret == -ENOTSUP)
16921                 printf("Function not supported in PMD driver\n");
16922         close_file(pkg);
16923 }
16924
16925 cmdline_parse_inst_t cmd_ddp_get_info = {
16926         .f = cmd_ddp_info_parsed,
16927         .data = NULL,
16928         .help_str = "ddp get info <profile_path>",
16929         .tokens = {
16930                 (void *)&cmd_ddp_info_ddp,
16931                 (void *)&cmd_ddp_info_get,
16932                 (void *)&cmd_ddp_info_info,
16933                 (void *)&cmd_ddp_info_filepath,
16934                 NULL,
16935         },
16936 };
16937
16938 /* Get dynamic device personalization profile info list*/
16939 #define PROFILE_INFO_SIZE 48
16940 #define MAX_PROFILE_NUM 16
16941
16942 struct cmd_ddp_get_list_result {
16943         cmdline_fixed_string_t ddp;
16944         cmdline_fixed_string_t get;
16945         cmdline_fixed_string_t list;
16946         portid_t port_id;
16947 };
16948
16949 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16950         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16951 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16952         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16953 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16954         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16955 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16956         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16957
16958 static void
16959 cmd_ddp_get_list_parsed(
16960         __rte_unused void *parsed_result,
16961         __rte_unused struct cmdline *cl,
16962         __rte_unused void *data)
16963 {
16964 #ifdef RTE_LIBRTE_I40E_PMD
16965         struct cmd_ddp_get_list_result *res = parsed_result;
16966         struct rte_pmd_i40e_profile_list *p_list;
16967         struct rte_pmd_i40e_profile_info *p_info;
16968         uint32_t p_num;
16969         uint32_t size;
16970         uint32_t i;
16971 #endif
16972         int ret = -ENOTSUP;
16973
16974 #ifdef RTE_LIBRTE_I40E_PMD
16975         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16976         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16977         if (!p_list) {
16978                 printf("%s: Failed to malloc buffer\n", __func__);
16979                 return;
16980         }
16981
16982         if (ret == -ENOTSUP)
16983                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16984                                                 (uint8_t *)p_list, size);
16985
16986         if (!ret) {
16987                 p_num = p_list->p_count;
16988                 printf("Profile number is: %d\n\n", p_num);
16989
16990                 for (i = 0; i < p_num; i++) {
16991                         p_info = &p_list->p_info[i];
16992                         printf("Profile %d:\n", i);
16993                         printf("Track id:     0x%x\n", p_info->track_id);
16994                         printf("Version:      %d.%d.%d.%d\n",
16995                                p_info->version.major,
16996                                p_info->version.minor,
16997                                p_info->version.update,
16998                                p_info->version.draft);
16999                         printf("Profile name: %s\n\n", p_info->name);
17000                 }
17001         }
17002
17003         free(p_list);
17004 #endif
17005
17006         if (ret < 0)
17007                 printf("Failed to get ddp list\n");
17008 }
17009
17010 cmdline_parse_inst_t cmd_ddp_get_list = {
17011         .f = cmd_ddp_get_list_parsed,
17012         .data = NULL,
17013         .help_str = "ddp get list <port_id>",
17014         .tokens = {
17015                 (void *)&cmd_ddp_get_list_ddp,
17016                 (void *)&cmd_ddp_get_list_get,
17017                 (void *)&cmd_ddp_get_list_list,
17018                 (void *)&cmd_ddp_get_list_port_id,
17019                 NULL,
17020         },
17021 };
17022
17023 /* Configure input set */
17024 struct cmd_cfg_input_set_result {
17025         cmdline_fixed_string_t port;
17026         cmdline_fixed_string_t cfg;
17027         portid_t port_id;
17028         cmdline_fixed_string_t pctype;
17029         uint8_t pctype_id;
17030         cmdline_fixed_string_t inset_type;
17031         cmdline_fixed_string_t opt;
17032         cmdline_fixed_string_t field;
17033         uint8_t field_idx;
17034 };
17035
17036 static void
17037 cmd_cfg_input_set_parsed(
17038         __rte_unused void *parsed_result,
17039         __rte_unused struct cmdline *cl,
17040         __rte_unused void *data)
17041 {
17042 #ifdef RTE_LIBRTE_I40E_PMD
17043         struct cmd_cfg_input_set_result *res = parsed_result;
17044         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17045         struct rte_pmd_i40e_inset inset;
17046 #endif
17047         int ret = -ENOTSUP;
17048
17049         if (!all_ports_stopped()) {
17050                 printf("Please stop all ports first\n");
17051                 return;
17052         }
17053
17054 #ifdef RTE_LIBRTE_I40E_PMD
17055         if (!strcmp(res->inset_type, "hash_inset"))
17056                 inset_type = INSET_HASH;
17057         else if (!strcmp(res->inset_type, "fdir_inset"))
17058                 inset_type = INSET_FDIR;
17059         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17060                 inset_type = INSET_FDIR_FLX;
17061         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17062                                      &inset, inset_type);
17063         if (ret) {
17064                 printf("Failed to get input set.\n");
17065                 return;
17066         }
17067
17068         if (!strcmp(res->opt, "get")) {
17069                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17070                                                    res->field_idx);
17071                 if (ret)
17072                         printf("Field index %d is enabled.\n", res->field_idx);
17073                 else
17074                         printf("Field index %d is disabled.\n", res->field_idx);
17075                 return;
17076         } else if (!strcmp(res->opt, "set"))
17077                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17078                                                    res->field_idx);
17079         else if (!strcmp(res->opt, "clear"))
17080                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17081                                                      res->field_idx);
17082         if (ret) {
17083                 printf("Failed to configure input set field.\n");
17084                 return;
17085         }
17086
17087         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17088                                      &inset, inset_type);
17089         if (ret) {
17090                 printf("Failed to set input set.\n");
17091                 return;
17092         }
17093 #endif
17094
17095         if (ret == -ENOTSUP)
17096                 printf("Function not supported\n");
17097 }
17098
17099 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17100         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17101                                  port, "port");
17102 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17103         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17104                                  cfg, "config");
17105 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17106         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17107                               port_id, UINT16);
17108 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17109         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17110                                  pctype, "pctype");
17111 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17112         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17113                               pctype_id, UINT8);
17114 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17115         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17116                                  inset_type,
17117                                  "hash_inset#fdir_inset#fdir_flx_inset");
17118 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17119         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17120                                  opt, "get#set#clear");
17121 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17122         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17123                                  field, "field");
17124 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17125         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17126                               field_idx, UINT8);
17127
17128 cmdline_parse_inst_t cmd_cfg_input_set = {
17129         .f = cmd_cfg_input_set_parsed,
17130         .data = NULL,
17131         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17132                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17133         .tokens = {
17134                 (void *)&cmd_cfg_input_set_port,
17135                 (void *)&cmd_cfg_input_set_cfg,
17136                 (void *)&cmd_cfg_input_set_port_id,
17137                 (void *)&cmd_cfg_input_set_pctype,
17138                 (void *)&cmd_cfg_input_set_pctype_id,
17139                 (void *)&cmd_cfg_input_set_inset_type,
17140                 (void *)&cmd_cfg_input_set_opt,
17141                 (void *)&cmd_cfg_input_set_field,
17142                 (void *)&cmd_cfg_input_set_field_idx,
17143                 NULL,
17144         },
17145 };
17146
17147 /* Clear input set */
17148 struct cmd_clear_input_set_result {
17149         cmdline_fixed_string_t port;
17150         cmdline_fixed_string_t cfg;
17151         portid_t port_id;
17152         cmdline_fixed_string_t pctype;
17153         uint8_t pctype_id;
17154         cmdline_fixed_string_t inset_type;
17155         cmdline_fixed_string_t clear;
17156         cmdline_fixed_string_t all;
17157 };
17158
17159 static void
17160 cmd_clear_input_set_parsed(
17161         __rte_unused void *parsed_result,
17162         __rte_unused struct cmdline *cl,
17163         __rte_unused void *data)
17164 {
17165 #ifdef RTE_LIBRTE_I40E_PMD
17166         struct cmd_clear_input_set_result *res = parsed_result;
17167         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17168         struct rte_pmd_i40e_inset inset;
17169 #endif
17170         int ret = -ENOTSUP;
17171
17172         if (!all_ports_stopped()) {
17173                 printf("Please stop all ports first\n");
17174                 return;
17175         }
17176
17177 #ifdef RTE_LIBRTE_I40E_PMD
17178         if (!strcmp(res->inset_type, "hash_inset"))
17179                 inset_type = INSET_HASH;
17180         else if (!strcmp(res->inset_type, "fdir_inset"))
17181                 inset_type = INSET_FDIR;
17182         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17183                 inset_type = INSET_FDIR_FLX;
17184
17185         memset(&inset, 0, sizeof(inset));
17186
17187         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17188                                      &inset, inset_type);
17189         if (ret) {
17190                 printf("Failed to clear input set.\n");
17191                 return;
17192         }
17193
17194 #endif
17195
17196         if (ret == -ENOTSUP)
17197                 printf("Function not supported\n");
17198 }
17199
17200 cmdline_parse_token_string_t cmd_clear_input_set_port =
17201         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17202                                  port, "port");
17203 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17204         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17205                                  cfg, "config");
17206 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17207         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17208                               port_id, UINT16);
17209 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17210         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17211                                  pctype, "pctype");
17212 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17213         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17214                               pctype_id, UINT8);
17215 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17216         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17217                                  inset_type,
17218                                  "hash_inset#fdir_inset#fdir_flx_inset");
17219 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17220         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17221                                  clear, "clear");
17222 cmdline_parse_token_string_t cmd_clear_input_set_all =
17223         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17224                                  all, "all");
17225
17226 cmdline_parse_inst_t cmd_clear_input_set = {
17227         .f = cmd_clear_input_set_parsed,
17228         .data = NULL,
17229         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17230                     "fdir_inset|fdir_flx_inset clear all",
17231         .tokens = {
17232                 (void *)&cmd_clear_input_set_port,
17233                 (void *)&cmd_clear_input_set_cfg,
17234                 (void *)&cmd_clear_input_set_port_id,
17235                 (void *)&cmd_clear_input_set_pctype,
17236                 (void *)&cmd_clear_input_set_pctype_id,
17237                 (void *)&cmd_clear_input_set_inset_type,
17238                 (void *)&cmd_clear_input_set_clear,
17239                 (void *)&cmd_clear_input_set_all,
17240                 NULL,
17241         },
17242 };
17243
17244 /* show vf stats */
17245
17246 /* Common result structure for show vf stats */
17247 struct cmd_show_vf_stats_result {
17248         cmdline_fixed_string_t show;
17249         cmdline_fixed_string_t vf;
17250         cmdline_fixed_string_t stats;
17251         portid_t port_id;
17252         uint16_t vf_id;
17253 };
17254
17255 /* Common CLI fields show vf stats*/
17256 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17257         TOKEN_STRING_INITIALIZER
17258                 (struct cmd_show_vf_stats_result,
17259                  show, "show");
17260 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17261         TOKEN_STRING_INITIALIZER
17262                 (struct cmd_show_vf_stats_result,
17263                  vf, "vf");
17264 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17265         TOKEN_STRING_INITIALIZER
17266                 (struct cmd_show_vf_stats_result,
17267                  stats, "stats");
17268 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17269         TOKEN_NUM_INITIALIZER
17270                 (struct cmd_show_vf_stats_result,
17271                  port_id, UINT16);
17272 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17273         TOKEN_NUM_INITIALIZER
17274                 (struct cmd_show_vf_stats_result,
17275                  vf_id, UINT16);
17276
17277 static void
17278 cmd_show_vf_stats_parsed(
17279         void *parsed_result,
17280         __rte_unused struct cmdline *cl,
17281         __rte_unused void *data)
17282 {
17283         struct cmd_show_vf_stats_result *res = parsed_result;
17284         struct rte_eth_stats stats;
17285         int ret = -ENOTSUP;
17286         static const char *nic_stats_border = "########################";
17287
17288         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17289                 return;
17290
17291         memset(&stats, 0, sizeof(stats));
17292
17293 #ifdef RTE_LIBRTE_I40E_PMD
17294         if (ret == -ENOTSUP)
17295                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17296                                                 res->vf_id,
17297                                                 &stats);
17298 #endif
17299 #ifdef RTE_LIBRTE_BNXT_PMD
17300         if (ret == -ENOTSUP)
17301                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17302                                                 res->vf_id,
17303                                                 &stats);
17304 #endif
17305
17306         switch (ret) {
17307         case 0:
17308                 break;
17309         case -EINVAL:
17310                 printf("invalid vf_id %d\n", res->vf_id);
17311                 break;
17312         case -ENODEV:
17313                 printf("invalid port_id %d\n", res->port_id);
17314                 break;
17315         case -ENOTSUP:
17316                 printf("function not implemented\n");
17317                 break;
17318         default:
17319                 printf("programming error: (%s)\n", strerror(-ret));
17320         }
17321
17322         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17323                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17324
17325         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17326                "%-"PRIu64"\n",
17327                stats.ipackets, stats.imissed, stats.ibytes);
17328         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17329         printf("  RX-nombuf:  %-10"PRIu64"\n",
17330                stats.rx_nombuf);
17331         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17332                "%-"PRIu64"\n",
17333                stats.opackets, stats.oerrors, stats.obytes);
17334
17335         printf("  %s############################%s\n",
17336                                nic_stats_border, nic_stats_border);
17337 }
17338
17339 cmdline_parse_inst_t cmd_show_vf_stats = {
17340         .f = cmd_show_vf_stats_parsed,
17341         .data = NULL,
17342         .help_str = "show vf stats <port_id> <vf_id>",
17343         .tokens = {
17344                 (void *)&cmd_show_vf_stats_show,
17345                 (void *)&cmd_show_vf_stats_vf,
17346                 (void *)&cmd_show_vf_stats_stats,
17347                 (void *)&cmd_show_vf_stats_port_id,
17348                 (void *)&cmd_show_vf_stats_vf_id,
17349                 NULL,
17350         },
17351 };
17352
17353 /* clear vf stats */
17354
17355 /* Common result structure for clear vf stats */
17356 struct cmd_clear_vf_stats_result {
17357         cmdline_fixed_string_t clear;
17358         cmdline_fixed_string_t vf;
17359         cmdline_fixed_string_t stats;
17360         portid_t port_id;
17361         uint16_t vf_id;
17362 };
17363
17364 /* Common CLI fields clear vf stats*/
17365 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17366         TOKEN_STRING_INITIALIZER
17367                 (struct cmd_clear_vf_stats_result,
17368                  clear, "clear");
17369 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17370         TOKEN_STRING_INITIALIZER
17371                 (struct cmd_clear_vf_stats_result,
17372                  vf, "vf");
17373 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17374         TOKEN_STRING_INITIALIZER
17375                 (struct cmd_clear_vf_stats_result,
17376                  stats, "stats");
17377 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17378         TOKEN_NUM_INITIALIZER
17379                 (struct cmd_clear_vf_stats_result,
17380                  port_id, UINT16);
17381 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17382         TOKEN_NUM_INITIALIZER
17383                 (struct cmd_clear_vf_stats_result,
17384                  vf_id, UINT16);
17385
17386 static void
17387 cmd_clear_vf_stats_parsed(
17388         void *parsed_result,
17389         __rte_unused struct cmdline *cl,
17390         __rte_unused void *data)
17391 {
17392         struct cmd_clear_vf_stats_result *res = parsed_result;
17393         int ret = -ENOTSUP;
17394
17395         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17396                 return;
17397
17398 #ifdef RTE_LIBRTE_I40E_PMD
17399         if (ret == -ENOTSUP)
17400                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17401                                                   res->vf_id);
17402 #endif
17403 #ifdef RTE_LIBRTE_BNXT_PMD
17404         if (ret == -ENOTSUP)
17405                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17406                                                   res->vf_id);
17407 #endif
17408
17409         switch (ret) {
17410         case 0:
17411                 break;
17412         case -EINVAL:
17413                 printf("invalid vf_id %d\n", res->vf_id);
17414                 break;
17415         case -ENODEV:
17416                 printf("invalid port_id %d\n", res->port_id);
17417                 break;
17418         case -ENOTSUP:
17419                 printf("function not implemented\n");
17420                 break;
17421         default:
17422                 printf("programming error: (%s)\n", strerror(-ret));
17423         }
17424 }
17425
17426 cmdline_parse_inst_t cmd_clear_vf_stats = {
17427         .f = cmd_clear_vf_stats_parsed,
17428         .data = NULL,
17429         .help_str = "clear vf stats <port_id> <vf_id>",
17430         .tokens = {
17431                 (void *)&cmd_clear_vf_stats_clear,
17432                 (void *)&cmd_clear_vf_stats_vf,
17433                 (void *)&cmd_clear_vf_stats_stats,
17434                 (void *)&cmd_clear_vf_stats_port_id,
17435                 (void *)&cmd_clear_vf_stats_vf_id,
17436                 NULL,
17437         },
17438 };
17439
17440 /* port config pctype mapping reset */
17441
17442 /* Common result structure for port config pctype mapping reset */
17443 struct cmd_pctype_mapping_reset_result {
17444         cmdline_fixed_string_t port;
17445         cmdline_fixed_string_t config;
17446         portid_t port_id;
17447         cmdline_fixed_string_t pctype;
17448         cmdline_fixed_string_t mapping;
17449         cmdline_fixed_string_t reset;
17450 };
17451
17452 /* Common CLI fields for port config pctype mapping reset*/
17453 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17454         TOKEN_STRING_INITIALIZER
17455                 (struct cmd_pctype_mapping_reset_result,
17456                  port, "port");
17457 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17458         TOKEN_STRING_INITIALIZER
17459                 (struct cmd_pctype_mapping_reset_result,
17460                  config, "config");
17461 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17462         TOKEN_NUM_INITIALIZER
17463                 (struct cmd_pctype_mapping_reset_result,
17464                  port_id, UINT16);
17465 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17466         TOKEN_STRING_INITIALIZER
17467                 (struct cmd_pctype_mapping_reset_result,
17468                  pctype, "pctype");
17469 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17470         TOKEN_STRING_INITIALIZER
17471                 (struct cmd_pctype_mapping_reset_result,
17472                  mapping, "mapping");
17473 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17474         TOKEN_STRING_INITIALIZER
17475                 (struct cmd_pctype_mapping_reset_result,
17476                  reset, "reset");
17477
17478 static void
17479 cmd_pctype_mapping_reset_parsed(
17480         void *parsed_result,
17481         __rte_unused struct cmdline *cl,
17482         __rte_unused void *data)
17483 {
17484         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17485         int ret = -ENOTSUP;
17486
17487         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17488                 return;
17489
17490 #ifdef RTE_LIBRTE_I40E_PMD
17491         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17492 #endif
17493
17494         switch (ret) {
17495         case 0:
17496                 break;
17497         case -ENODEV:
17498                 printf("invalid port_id %d\n", res->port_id);
17499                 break;
17500         case -ENOTSUP:
17501                 printf("function not implemented\n");
17502                 break;
17503         default:
17504                 printf("programming error: (%s)\n", strerror(-ret));
17505         }
17506 }
17507
17508 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17509         .f = cmd_pctype_mapping_reset_parsed,
17510         .data = NULL,
17511         .help_str = "port config <port_id> pctype mapping reset",
17512         .tokens = {
17513                 (void *)&cmd_pctype_mapping_reset_port,
17514                 (void *)&cmd_pctype_mapping_reset_config,
17515                 (void *)&cmd_pctype_mapping_reset_port_id,
17516                 (void *)&cmd_pctype_mapping_reset_pctype,
17517                 (void *)&cmd_pctype_mapping_reset_mapping,
17518                 (void *)&cmd_pctype_mapping_reset_reset,
17519                 NULL,
17520         },
17521 };
17522
17523 /* show port pctype mapping */
17524
17525 /* Common result structure for show port pctype mapping */
17526 struct cmd_pctype_mapping_get_result {
17527         cmdline_fixed_string_t show;
17528         cmdline_fixed_string_t port;
17529         portid_t port_id;
17530         cmdline_fixed_string_t pctype;
17531         cmdline_fixed_string_t mapping;
17532 };
17533
17534 /* Common CLI fields for pctype mapping get */
17535 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17536         TOKEN_STRING_INITIALIZER
17537                 (struct cmd_pctype_mapping_get_result,
17538                  show, "show");
17539 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17540         TOKEN_STRING_INITIALIZER
17541                 (struct cmd_pctype_mapping_get_result,
17542                  port, "port");
17543 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17544         TOKEN_NUM_INITIALIZER
17545                 (struct cmd_pctype_mapping_get_result,
17546                  port_id, UINT16);
17547 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17548         TOKEN_STRING_INITIALIZER
17549                 (struct cmd_pctype_mapping_get_result,
17550                  pctype, "pctype");
17551 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17552         TOKEN_STRING_INITIALIZER
17553                 (struct cmd_pctype_mapping_get_result,
17554                  mapping, "mapping");
17555
17556 static void
17557 cmd_pctype_mapping_get_parsed(
17558         void *parsed_result,
17559         __rte_unused struct cmdline *cl,
17560         __rte_unused void *data)
17561 {
17562         struct cmd_pctype_mapping_get_result *res = parsed_result;
17563         int ret = -ENOTSUP;
17564 #ifdef RTE_LIBRTE_I40E_PMD
17565         struct rte_pmd_i40e_flow_type_mapping
17566                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17567         int i, j, first_pctype;
17568 #endif
17569
17570         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17571                 return;
17572
17573 #ifdef RTE_LIBRTE_I40E_PMD
17574         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17575 #endif
17576
17577         switch (ret) {
17578         case 0:
17579                 break;
17580         case -ENODEV:
17581                 printf("invalid port_id %d\n", res->port_id);
17582                 return;
17583         case -ENOTSUP:
17584                 printf("function not implemented\n");
17585                 return;
17586         default:
17587                 printf("programming error: (%s)\n", strerror(-ret));
17588                 return;
17589         }
17590
17591 #ifdef RTE_LIBRTE_I40E_PMD
17592         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17593                 if (mapping[i].pctype != 0ULL) {
17594                         first_pctype = 1;
17595
17596                         printf("pctype: ");
17597                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17598                                 if (mapping[i].pctype & (1ULL << j)) {
17599                                         printf(first_pctype ?
17600                                                "%02d" : ",%02d", j);
17601                                         first_pctype = 0;
17602                                 }
17603                         }
17604                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17605                 }
17606         }
17607 #endif
17608 }
17609
17610 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17611         .f = cmd_pctype_mapping_get_parsed,
17612         .data = NULL,
17613         .help_str = "show port <port_id> pctype mapping",
17614         .tokens = {
17615                 (void *)&cmd_pctype_mapping_get_show,
17616                 (void *)&cmd_pctype_mapping_get_port,
17617                 (void *)&cmd_pctype_mapping_get_port_id,
17618                 (void *)&cmd_pctype_mapping_get_pctype,
17619                 (void *)&cmd_pctype_mapping_get_mapping,
17620                 NULL,
17621         },
17622 };
17623
17624 /* port config pctype mapping update */
17625
17626 /* Common result structure for port config pctype mapping update */
17627 struct cmd_pctype_mapping_update_result {
17628         cmdline_fixed_string_t port;
17629         cmdline_fixed_string_t config;
17630         portid_t port_id;
17631         cmdline_fixed_string_t pctype;
17632         cmdline_fixed_string_t mapping;
17633         cmdline_fixed_string_t update;
17634         cmdline_fixed_string_t pctype_list;
17635         uint16_t flow_type;
17636 };
17637
17638 /* Common CLI fields for pctype mapping update*/
17639 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17640         TOKEN_STRING_INITIALIZER
17641                 (struct cmd_pctype_mapping_update_result,
17642                  port, "port");
17643 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17644         TOKEN_STRING_INITIALIZER
17645                 (struct cmd_pctype_mapping_update_result,
17646                  config, "config");
17647 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17648         TOKEN_NUM_INITIALIZER
17649                 (struct cmd_pctype_mapping_update_result,
17650                  port_id, UINT16);
17651 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17652         TOKEN_STRING_INITIALIZER
17653                 (struct cmd_pctype_mapping_update_result,
17654                  pctype, "pctype");
17655 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17656         TOKEN_STRING_INITIALIZER
17657                 (struct cmd_pctype_mapping_update_result,
17658                  mapping, "mapping");
17659 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17660         TOKEN_STRING_INITIALIZER
17661                 (struct cmd_pctype_mapping_update_result,
17662                  update, "update");
17663 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17664         TOKEN_STRING_INITIALIZER
17665                 (struct cmd_pctype_mapping_update_result,
17666                  pctype_list, NULL);
17667 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17668         TOKEN_NUM_INITIALIZER
17669                 (struct cmd_pctype_mapping_update_result,
17670                  flow_type, UINT16);
17671
17672 static void
17673 cmd_pctype_mapping_update_parsed(
17674         void *parsed_result,
17675         __rte_unused struct cmdline *cl,
17676         __rte_unused void *data)
17677 {
17678         struct cmd_pctype_mapping_update_result *res = parsed_result;
17679         int ret = -ENOTSUP;
17680 #ifdef RTE_LIBRTE_I40E_PMD
17681         struct rte_pmd_i40e_flow_type_mapping mapping;
17682         unsigned int i;
17683         unsigned int nb_item;
17684         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17685 #endif
17686
17687         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17688                 return;
17689
17690 #ifdef RTE_LIBRTE_I40E_PMD
17691         nb_item = parse_item_list(res->pctype_list, "pctypes",
17692                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17693         mapping.flow_type = res->flow_type;
17694         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17695                 mapping.pctype |= (1ULL << pctype_list[i]);
17696         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17697                                                 &mapping,
17698                                                 1,
17699                                                 0);
17700 #endif
17701
17702         switch (ret) {
17703         case 0:
17704                 break;
17705         case -EINVAL:
17706                 printf("invalid pctype or flow type\n");
17707                 break;
17708         case -ENODEV:
17709                 printf("invalid port_id %d\n", res->port_id);
17710                 break;
17711         case -ENOTSUP:
17712                 printf("function not implemented\n");
17713                 break;
17714         default:
17715                 printf("programming error: (%s)\n", strerror(-ret));
17716         }
17717 }
17718
17719 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17720         .f = cmd_pctype_mapping_update_parsed,
17721         .data = NULL,
17722         .help_str = "port config <port_id> pctype mapping update"
17723         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17724         .tokens = {
17725                 (void *)&cmd_pctype_mapping_update_port,
17726                 (void *)&cmd_pctype_mapping_update_config,
17727                 (void *)&cmd_pctype_mapping_update_port_id,
17728                 (void *)&cmd_pctype_mapping_update_pctype,
17729                 (void *)&cmd_pctype_mapping_update_mapping,
17730                 (void *)&cmd_pctype_mapping_update_update,
17731                 (void *)&cmd_pctype_mapping_update_pc_type,
17732                 (void *)&cmd_pctype_mapping_update_flow_type,
17733                 NULL,
17734         },
17735 };
17736
17737 /* ptype mapping get */
17738
17739 /* Common result structure for ptype mapping get */
17740 struct cmd_ptype_mapping_get_result {
17741         cmdline_fixed_string_t ptype;
17742         cmdline_fixed_string_t mapping;
17743         cmdline_fixed_string_t get;
17744         portid_t port_id;
17745         uint8_t valid_only;
17746 };
17747
17748 /* Common CLI fields for ptype mapping get */
17749 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17750         TOKEN_STRING_INITIALIZER
17751                 (struct cmd_ptype_mapping_get_result,
17752                  ptype, "ptype");
17753 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17754         TOKEN_STRING_INITIALIZER
17755                 (struct cmd_ptype_mapping_get_result,
17756                  mapping, "mapping");
17757 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17758         TOKEN_STRING_INITIALIZER
17759                 (struct cmd_ptype_mapping_get_result,
17760                  get, "get");
17761 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17762         TOKEN_NUM_INITIALIZER
17763                 (struct cmd_ptype_mapping_get_result,
17764                  port_id, UINT16);
17765 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17766         TOKEN_NUM_INITIALIZER
17767                 (struct cmd_ptype_mapping_get_result,
17768                  valid_only, UINT8);
17769
17770 static void
17771 cmd_ptype_mapping_get_parsed(
17772         void *parsed_result,
17773         __rte_unused struct cmdline *cl,
17774         __rte_unused void *data)
17775 {
17776         struct cmd_ptype_mapping_get_result *res = parsed_result;
17777         int ret = -ENOTSUP;
17778 #ifdef RTE_LIBRTE_I40E_PMD
17779         int max_ptype_num = 256;
17780         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17781         uint16_t count;
17782         int i;
17783 #endif
17784
17785         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17786                 return;
17787
17788 #ifdef RTE_LIBRTE_I40E_PMD
17789         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17790                                         mapping,
17791                                         max_ptype_num,
17792                                         &count,
17793                                         res->valid_only);
17794 #endif
17795
17796         switch (ret) {
17797         case 0:
17798                 break;
17799         case -ENODEV:
17800                 printf("invalid port_id %d\n", res->port_id);
17801                 break;
17802         case -ENOTSUP:
17803                 printf("function not implemented\n");
17804                 break;
17805         default:
17806                 printf("programming error: (%s)\n", strerror(-ret));
17807         }
17808
17809 #ifdef RTE_LIBRTE_I40E_PMD
17810         if (!ret) {
17811                 for (i = 0; i < count; i++)
17812                         printf("%3d\t0x%08x\n",
17813                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17814         }
17815 #endif
17816 }
17817
17818 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17819         .f = cmd_ptype_mapping_get_parsed,
17820         .data = NULL,
17821         .help_str = "ptype mapping get <port_id> <valid_only>",
17822         .tokens = {
17823                 (void *)&cmd_ptype_mapping_get_ptype,
17824                 (void *)&cmd_ptype_mapping_get_mapping,
17825                 (void *)&cmd_ptype_mapping_get_get,
17826                 (void *)&cmd_ptype_mapping_get_port_id,
17827                 (void *)&cmd_ptype_mapping_get_valid_only,
17828                 NULL,
17829         },
17830 };
17831
17832 /* ptype mapping replace */
17833
17834 /* Common result structure for ptype mapping replace */
17835 struct cmd_ptype_mapping_replace_result {
17836         cmdline_fixed_string_t ptype;
17837         cmdline_fixed_string_t mapping;
17838         cmdline_fixed_string_t replace;
17839         portid_t port_id;
17840         uint32_t target;
17841         uint8_t mask;
17842         uint32_t pkt_type;
17843 };
17844
17845 /* Common CLI fields for ptype mapping replace */
17846 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17847         TOKEN_STRING_INITIALIZER
17848                 (struct cmd_ptype_mapping_replace_result,
17849                  ptype, "ptype");
17850 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17851         TOKEN_STRING_INITIALIZER
17852                 (struct cmd_ptype_mapping_replace_result,
17853                  mapping, "mapping");
17854 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17855         TOKEN_STRING_INITIALIZER
17856                 (struct cmd_ptype_mapping_replace_result,
17857                  replace, "replace");
17858 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17859         TOKEN_NUM_INITIALIZER
17860                 (struct cmd_ptype_mapping_replace_result,
17861                  port_id, UINT16);
17862 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17863         TOKEN_NUM_INITIALIZER
17864                 (struct cmd_ptype_mapping_replace_result,
17865                  target, UINT32);
17866 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17867         TOKEN_NUM_INITIALIZER
17868                 (struct cmd_ptype_mapping_replace_result,
17869                  mask, UINT8);
17870 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17871         TOKEN_NUM_INITIALIZER
17872                 (struct cmd_ptype_mapping_replace_result,
17873                  pkt_type, UINT32);
17874
17875 static void
17876 cmd_ptype_mapping_replace_parsed(
17877         void *parsed_result,
17878         __rte_unused struct cmdline *cl,
17879         __rte_unused void *data)
17880 {
17881         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17882         int ret = -ENOTSUP;
17883
17884         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17885                 return;
17886
17887 #ifdef RTE_LIBRTE_I40E_PMD
17888         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17889                                         res->target,
17890                                         res->mask,
17891                                         res->pkt_type);
17892 #endif
17893
17894         switch (ret) {
17895         case 0:
17896                 break;
17897         case -EINVAL:
17898                 printf("invalid ptype 0x%8x or 0x%8x\n",
17899                                 res->target, res->pkt_type);
17900                 break;
17901         case -ENODEV:
17902                 printf("invalid port_id %d\n", res->port_id);
17903                 break;
17904         case -ENOTSUP:
17905                 printf("function not implemented\n");
17906                 break;
17907         default:
17908                 printf("programming error: (%s)\n", strerror(-ret));
17909         }
17910 }
17911
17912 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17913         .f = cmd_ptype_mapping_replace_parsed,
17914         .data = NULL,
17915         .help_str =
17916                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17917         .tokens = {
17918                 (void *)&cmd_ptype_mapping_replace_ptype,
17919                 (void *)&cmd_ptype_mapping_replace_mapping,
17920                 (void *)&cmd_ptype_mapping_replace_replace,
17921                 (void *)&cmd_ptype_mapping_replace_port_id,
17922                 (void *)&cmd_ptype_mapping_replace_target,
17923                 (void *)&cmd_ptype_mapping_replace_mask,
17924                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17925                 NULL,
17926         },
17927 };
17928
17929 /* ptype mapping reset */
17930
17931 /* Common result structure for ptype mapping reset */
17932 struct cmd_ptype_mapping_reset_result {
17933         cmdline_fixed_string_t ptype;
17934         cmdline_fixed_string_t mapping;
17935         cmdline_fixed_string_t reset;
17936         portid_t port_id;
17937 };
17938
17939 /* Common CLI fields for ptype mapping reset*/
17940 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17941         TOKEN_STRING_INITIALIZER
17942                 (struct cmd_ptype_mapping_reset_result,
17943                  ptype, "ptype");
17944 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17945         TOKEN_STRING_INITIALIZER
17946                 (struct cmd_ptype_mapping_reset_result,
17947                  mapping, "mapping");
17948 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17949         TOKEN_STRING_INITIALIZER
17950                 (struct cmd_ptype_mapping_reset_result,
17951                  reset, "reset");
17952 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17953         TOKEN_NUM_INITIALIZER
17954                 (struct cmd_ptype_mapping_reset_result,
17955                  port_id, UINT16);
17956
17957 static void
17958 cmd_ptype_mapping_reset_parsed(
17959         void *parsed_result,
17960         __rte_unused struct cmdline *cl,
17961         __rte_unused void *data)
17962 {
17963         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17964         int ret = -ENOTSUP;
17965
17966         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17967                 return;
17968
17969 #ifdef RTE_LIBRTE_I40E_PMD
17970         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17971 #endif
17972
17973         switch (ret) {
17974         case 0:
17975                 break;
17976         case -ENODEV:
17977                 printf("invalid port_id %d\n", res->port_id);
17978                 break;
17979         case -ENOTSUP:
17980                 printf("function not implemented\n");
17981                 break;
17982         default:
17983                 printf("programming error: (%s)\n", strerror(-ret));
17984         }
17985 }
17986
17987 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17988         .f = cmd_ptype_mapping_reset_parsed,
17989         .data = NULL,
17990         .help_str = "ptype mapping reset <port_id>",
17991         .tokens = {
17992                 (void *)&cmd_ptype_mapping_reset_ptype,
17993                 (void *)&cmd_ptype_mapping_reset_mapping,
17994                 (void *)&cmd_ptype_mapping_reset_reset,
17995                 (void *)&cmd_ptype_mapping_reset_port_id,
17996                 NULL,
17997         },
17998 };
17999
18000 /* ptype mapping update */
18001
18002 /* Common result structure for ptype mapping update */
18003 struct cmd_ptype_mapping_update_result {
18004         cmdline_fixed_string_t ptype;
18005         cmdline_fixed_string_t mapping;
18006         cmdline_fixed_string_t reset;
18007         portid_t port_id;
18008         uint8_t hw_ptype;
18009         uint32_t sw_ptype;
18010 };
18011
18012 /* Common CLI fields for ptype mapping update*/
18013 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18014         TOKEN_STRING_INITIALIZER
18015                 (struct cmd_ptype_mapping_update_result,
18016                  ptype, "ptype");
18017 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18018         TOKEN_STRING_INITIALIZER
18019                 (struct cmd_ptype_mapping_update_result,
18020                  mapping, "mapping");
18021 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18022         TOKEN_STRING_INITIALIZER
18023                 (struct cmd_ptype_mapping_update_result,
18024                  reset, "update");
18025 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18026         TOKEN_NUM_INITIALIZER
18027                 (struct cmd_ptype_mapping_update_result,
18028                  port_id, UINT16);
18029 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18030         TOKEN_NUM_INITIALIZER
18031                 (struct cmd_ptype_mapping_update_result,
18032                  hw_ptype, UINT8);
18033 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18034         TOKEN_NUM_INITIALIZER
18035                 (struct cmd_ptype_mapping_update_result,
18036                  sw_ptype, UINT32);
18037
18038 static void
18039 cmd_ptype_mapping_update_parsed(
18040         void *parsed_result,
18041         __rte_unused struct cmdline *cl,
18042         __rte_unused void *data)
18043 {
18044         struct cmd_ptype_mapping_update_result *res = parsed_result;
18045         int ret = -ENOTSUP;
18046 #ifdef RTE_LIBRTE_I40E_PMD
18047         struct rte_pmd_i40e_ptype_mapping mapping;
18048 #endif
18049         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18050                 return;
18051
18052 #ifdef RTE_LIBRTE_I40E_PMD
18053         mapping.hw_ptype = res->hw_ptype;
18054         mapping.sw_ptype = res->sw_ptype;
18055         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18056                                                 &mapping,
18057                                                 1,
18058                                                 0);
18059 #endif
18060
18061         switch (ret) {
18062         case 0:
18063                 break;
18064         case -EINVAL:
18065                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18066                 break;
18067         case -ENODEV:
18068                 printf("invalid port_id %d\n", res->port_id);
18069                 break;
18070         case -ENOTSUP:
18071                 printf("function not implemented\n");
18072                 break;
18073         default:
18074                 printf("programming error: (%s)\n", strerror(-ret));
18075         }
18076 }
18077
18078 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18079         .f = cmd_ptype_mapping_update_parsed,
18080         .data = NULL,
18081         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18082         .tokens = {
18083                 (void *)&cmd_ptype_mapping_update_ptype,
18084                 (void *)&cmd_ptype_mapping_update_mapping,
18085                 (void *)&cmd_ptype_mapping_update_update,
18086                 (void *)&cmd_ptype_mapping_update_port_id,
18087                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18088                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18089                 NULL,
18090         },
18091 };
18092
18093 /* Common result structure for file commands */
18094 struct cmd_cmdfile_result {
18095         cmdline_fixed_string_t load;
18096         cmdline_fixed_string_t filename;
18097 };
18098
18099 /* Common CLI fields for file commands */
18100 cmdline_parse_token_string_t cmd_load_cmdfile =
18101         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18102 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18103         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18104
18105 static void
18106 cmd_load_from_file_parsed(
18107         void *parsed_result,
18108         __rte_unused struct cmdline *cl,
18109         __rte_unused void *data)
18110 {
18111         struct cmd_cmdfile_result *res = parsed_result;
18112
18113         cmdline_read_from_file(res->filename);
18114 }
18115
18116 cmdline_parse_inst_t cmd_load_from_file = {
18117         .f = cmd_load_from_file_parsed,
18118         .data = NULL,
18119         .help_str = "load <filename>",
18120         .tokens = {
18121                 (void *)&cmd_load_cmdfile,
18122                 (void *)&cmd_load_cmdfile_filename,
18123                 NULL,
18124         },
18125 };
18126
18127 /* Get Rx offloads capabilities */
18128 struct cmd_rx_offload_get_capa_result {
18129         cmdline_fixed_string_t show;
18130         cmdline_fixed_string_t port;
18131         portid_t port_id;
18132         cmdline_fixed_string_t rx_offload;
18133         cmdline_fixed_string_t capabilities;
18134 };
18135
18136 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18137         TOKEN_STRING_INITIALIZER
18138                 (struct cmd_rx_offload_get_capa_result,
18139                  show, "show");
18140 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18141         TOKEN_STRING_INITIALIZER
18142                 (struct cmd_rx_offload_get_capa_result,
18143                  port, "port");
18144 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18145         TOKEN_NUM_INITIALIZER
18146                 (struct cmd_rx_offload_get_capa_result,
18147                  port_id, UINT16);
18148 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18149         TOKEN_STRING_INITIALIZER
18150                 (struct cmd_rx_offload_get_capa_result,
18151                  rx_offload, "rx_offload");
18152 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18153         TOKEN_STRING_INITIALIZER
18154                 (struct cmd_rx_offload_get_capa_result,
18155                  capabilities, "capabilities");
18156
18157 static void
18158 print_rx_offloads(uint64_t offloads)
18159 {
18160         uint64_t single_offload;
18161         int begin;
18162         int end;
18163         int bit;
18164
18165         if (offloads == 0)
18166                 return;
18167
18168         begin = __builtin_ctzll(offloads);
18169         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18170
18171         single_offload = 1ULL << begin;
18172         for (bit = begin; bit < end; bit++) {
18173                 if (offloads & single_offload)
18174                         printf(" %s",
18175                                rte_eth_dev_rx_offload_name(single_offload));
18176                 single_offload <<= 1;
18177         }
18178 }
18179
18180 static void
18181 cmd_rx_offload_get_capa_parsed(
18182         void *parsed_result,
18183         __rte_unused struct cmdline *cl,
18184         __rte_unused void *data)
18185 {
18186         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18187         struct rte_eth_dev_info dev_info;
18188         portid_t port_id = res->port_id;
18189         uint64_t queue_offloads;
18190         uint64_t port_offloads;
18191         int ret;
18192
18193         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18194         if (ret != 0)
18195                 return;
18196
18197         queue_offloads = dev_info.rx_queue_offload_capa;
18198         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18199
18200         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18201         printf("  Per Queue :");
18202         print_rx_offloads(queue_offloads);
18203
18204         printf("\n");
18205         printf("  Per Port  :");
18206         print_rx_offloads(port_offloads);
18207         printf("\n\n");
18208 }
18209
18210 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18211         .f = cmd_rx_offload_get_capa_parsed,
18212         .data = NULL,
18213         .help_str = "show port <port_id> rx_offload capabilities",
18214         .tokens = {
18215                 (void *)&cmd_rx_offload_get_capa_show,
18216                 (void *)&cmd_rx_offload_get_capa_port,
18217                 (void *)&cmd_rx_offload_get_capa_port_id,
18218                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18219                 (void *)&cmd_rx_offload_get_capa_capabilities,
18220                 NULL,
18221         }
18222 };
18223
18224 /* Get Rx offloads configuration */
18225 struct cmd_rx_offload_get_configuration_result {
18226         cmdline_fixed_string_t show;
18227         cmdline_fixed_string_t port;
18228         portid_t port_id;
18229         cmdline_fixed_string_t rx_offload;
18230         cmdline_fixed_string_t configuration;
18231 };
18232
18233 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18234         TOKEN_STRING_INITIALIZER
18235                 (struct cmd_rx_offload_get_configuration_result,
18236                  show, "show");
18237 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18238         TOKEN_STRING_INITIALIZER
18239                 (struct cmd_rx_offload_get_configuration_result,
18240                  port, "port");
18241 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18242         TOKEN_NUM_INITIALIZER
18243                 (struct cmd_rx_offload_get_configuration_result,
18244                  port_id, UINT16);
18245 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18246         TOKEN_STRING_INITIALIZER
18247                 (struct cmd_rx_offload_get_configuration_result,
18248                  rx_offload, "rx_offload");
18249 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18250         TOKEN_STRING_INITIALIZER
18251                 (struct cmd_rx_offload_get_configuration_result,
18252                  configuration, "configuration");
18253
18254 static void
18255 cmd_rx_offload_get_configuration_parsed(
18256         void *parsed_result,
18257         __rte_unused struct cmdline *cl,
18258         __rte_unused void *data)
18259 {
18260         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18261         struct rte_eth_dev_info dev_info;
18262         portid_t port_id = res->port_id;
18263         struct rte_port *port = &ports[port_id];
18264         uint64_t port_offloads;
18265         uint64_t queue_offloads;
18266         uint16_t nb_rx_queues;
18267         int q;
18268         int ret;
18269
18270         printf("Rx Offloading Configuration of port %d :\n", port_id);
18271
18272         port_offloads = port->dev_conf.rxmode.offloads;
18273         printf("  Port :");
18274         print_rx_offloads(port_offloads);
18275         printf("\n");
18276
18277         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18278         if (ret != 0)
18279                 return;
18280
18281         nb_rx_queues = dev_info.nb_rx_queues;
18282         for (q = 0; q < nb_rx_queues; q++) {
18283                 queue_offloads = port->rx_conf[q].offloads;
18284                 printf("  Queue[%2d] :", q);
18285                 print_rx_offloads(queue_offloads);
18286                 printf("\n");
18287         }
18288         printf("\n");
18289 }
18290
18291 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18292         .f = cmd_rx_offload_get_configuration_parsed,
18293         .data = NULL,
18294         .help_str = "show port <port_id> rx_offload configuration",
18295         .tokens = {
18296                 (void *)&cmd_rx_offload_get_configuration_show,
18297                 (void *)&cmd_rx_offload_get_configuration_port,
18298                 (void *)&cmd_rx_offload_get_configuration_port_id,
18299                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18300                 (void *)&cmd_rx_offload_get_configuration_configuration,
18301                 NULL,
18302         }
18303 };
18304
18305 /* Enable/Disable a per port offloading */
18306 struct cmd_config_per_port_rx_offload_result {
18307         cmdline_fixed_string_t port;
18308         cmdline_fixed_string_t config;
18309         portid_t port_id;
18310         cmdline_fixed_string_t rx_offload;
18311         cmdline_fixed_string_t offload;
18312         cmdline_fixed_string_t on_off;
18313 };
18314
18315 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18316         TOKEN_STRING_INITIALIZER
18317                 (struct cmd_config_per_port_rx_offload_result,
18318                  port, "port");
18319 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18320         TOKEN_STRING_INITIALIZER
18321                 (struct cmd_config_per_port_rx_offload_result,
18322                  config, "config");
18323 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18324         TOKEN_NUM_INITIALIZER
18325                 (struct cmd_config_per_port_rx_offload_result,
18326                  port_id, UINT16);
18327 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18328         TOKEN_STRING_INITIALIZER
18329                 (struct cmd_config_per_port_rx_offload_result,
18330                  rx_offload, "rx_offload");
18331 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18332         TOKEN_STRING_INITIALIZER
18333                 (struct cmd_config_per_port_rx_offload_result,
18334                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18335                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18336                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18337                            "scatter#timestamp#security#keep_crc#rss_hash");
18338 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18339         TOKEN_STRING_INITIALIZER
18340                 (struct cmd_config_per_port_rx_offload_result,
18341                  on_off, "on#off");
18342
18343 static uint64_t
18344 search_rx_offload(const char *name)
18345 {
18346         uint64_t single_offload;
18347         const char *single_name;
18348         int found = 0;
18349         unsigned int bit;
18350
18351         single_offload = 1;
18352         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18353                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18354                 if (!strcasecmp(single_name, name)) {
18355                         found = 1;
18356                         break;
18357                 }
18358                 single_offload <<= 1;
18359         }
18360
18361         if (found)
18362                 return single_offload;
18363
18364         return 0;
18365 }
18366
18367 static void
18368 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18369                                 __rte_unused struct cmdline *cl,
18370                                 __rte_unused void *data)
18371 {
18372         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18373         portid_t port_id = res->port_id;
18374         struct rte_eth_dev_info dev_info;
18375         struct rte_port *port = &ports[port_id];
18376         uint64_t single_offload;
18377         uint16_t nb_rx_queues;
18378         int q;
18379         int ret;
18380
18381         if (port->port_status != RTE_PORT_STOPPED) {
18382                 printf("Error: Can't config offload when Port %d "
18383                        "is not stopped\n", port_id);
18384                 return;
18385         }
18386
18387         single_offload = search_rx_offload(res->offload);
18388         if (single_offload == 0) {
18389                 printf("Unknown offload name: %s\n", res->offload);
18390                 return;
18391         }
18392
18393         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18394         if (ret != 0)
18395                 return;
18396
18397         nb_rx_queues = dev_info.nb_rx_queues;
18398         if (!strcmp(res->on_off, "on")) {
18399                 port->dev_conf.rxmode.offloads |= single_offload;
18400                 for (q = 0; q < nb_rx_queues; q++)
18401                         port->rx_conf[q].offloads |= single_offload;
18402         } else {
18403                 port->dev_conf.rxmode.offloads &= ~single_offload;
18404                 for (q = 0; q < nb_rx_queues; q++)
18405                         port->rx_conf[q].offloads &= ~single_offload;
18406         }
18407
18408         cmd_reconfig_device_queue(port_id, 1, 1);
18409 }
18410
18411 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18412         .f = cmd_config_per_port_rx_offload_parsed,
18413         .data = NULL,
18414         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18415                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18416                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18417                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18418                     "on|off",
18419         .tokens = {
18420                 (void *)&cmd_config_per_port_rx_offload_result_port,
18421                 (void *)&cmd_config_per_port_rx_offload_result_config,
18422                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18423                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18424                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18425                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18426                 NULL,
18427         }
18428 };
18429
18430 /* Enable/Disable a per queue offloading */
18431 struct cmd_config_per_queue_rx_offload_result {
18432         cmdline_fixed_string_t port;
18433         portid_t port_id;
18434         cmdline_fixed_string_t rxq;
18435         uint16_t queue_id;
18436         cmdline_fixed_string_t rx_offload;
18437         cmdline_fixed_string_t offload;
18438         cmdline_fixed_string_t on_off;
18439 };
18440
18441 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18442         TOKEN_STRING_INITIALIZER
18443                 (struct cmd_config_per_queue_rx_offload_result,
18444                  port, "port");
18445 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18446         TOKEN_NUM_INITIALIZER
18447                 (struct cmd_config_per_queue_rx_offload_result,
18448                  port_id, UINT16);
18449 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18450         TOKEN_STRING_INITIALIZER
18451                 (struct cmd_config_per_queue_rx_offload_result,
18452                  rxq, "rxq");
18453 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18454         TOKEN_NUM_INITIALIZER
18455                 (struct cmd_config_per_queue_rx_offload_result,
18456                  queue_id, UINT16);
18457 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18458         TOKEN_STRING_INITIALIZER
18459                 (struct cmd_config_per_queue_rx_offload_result,
18460                  rx_offload, "rx_offload");
18461 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18462         TOKEN_STRING_INITIALIZER
18463                 (struct cmd_config_per_queue_rx_offload_result,
18464                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18465                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18466                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18467                            "scatter#timestamp#security#keep_crc");
18468 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18469         TOKEN_STRING_INITIALIZER
18470                 (struct cmd_config_per_queue_rx_offload_result,
18471                  on_off, "on#off");
18472
18473 static void
18474 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18475                                 __rte_unused struct cmdline *cl,
18476                                 __rte_unused void *data)
18477 {
18478         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18479         struct rte_eth_dev_info dev_info;
18480         portid_t port_id = res->port_id;
18481         uint16_t queue_id = res->queue_id;
18482         struct rte_port *port = &ports[port_id];
18483         uint64_t single_offload;
18484         int ret;
18485
18486         if (port->port_status != RTE_PORT_STOPPED) {
18487                 printf("Error: Can't config offload when Port %d "
18488                        "is not stopped\n", port_id);
18489                 return;
18490         }
18491
18492         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18493         if (ret != 0)
18494                 return;
18495
18496         if (queue_id >= dev_info.nb_rx_queues) {
18497                 printf("Error: input queue_id should be 0 ... "
18498                        "%d\n", dev_info.nb_rx_queues - 1);
18499                 return;
18500         }
18501
18502         single_offload = search_rx_offload(res->offload);
18503         if (single_offload == 0) {
18504                 printf("Unknown offload name: %s\n", res->offload);
18505                 return;
18506         }
18507
18508         if (!strcmp(res->on_off, "on"))
18509                 port->rx_conf[queue_id].offloads |= single_offload;
18510         else
18511                 port->rx_conf[queue_id].offloads &= ~single_offload;
18512
18513         cmd_reconfig_device_queue(port_id, 1, 1);
18514 }
18515
18516 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18517         .f = cmd_config_per_queue_rx_offload_parsed,
18518         .data = NULL,
18519         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18520                     "vlan_strip|ipv4_cksum|"
18521                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18522                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18523                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18524                     "on|off",
18525         .tokens = {
18526                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18527                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18528                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18529                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18530                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18531                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18532                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18533                 NULL,
18534         }
18535 };
18536
18537 /* Get Tx offloads capabilities */
18538 struct cmd_tx_offload_get_capa_result {
18539         cmdline_fixed_string_t show;
18540         cmdline_fixed_string_t port;
18541         portid_t port_id;
18542         cmdline_fixed_string_t tx_offload;
18543         cmdline_fixed_string_t capabilities;
18544 };
18545
18546 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18547         TOKEN_STRING_INITIALIZER
18548                 (struct cmd_tx_offload_get_capa_result,
18549                  show, "show");
18550 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18551         TOKEN_STRING_INITIALIZER
18552                 (struct cmd_tx_offload_get_capa_result,
18553                  port, "port");
18554 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18555         TOKEN_NUM_INITIALIZER
18556                 (struct cmd_tx_offload_get_capa_result,
18557                  port_id, UINT16);
18558 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18559         TOKEN_STRING_INITIALIZER
18560                 (struct cmd_tx_offload_get_capa_result,
18561                  tx_offload, "tx_offload");
18562 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_tx_offload_get_capa_result,
18565                  capabilities, "capabilities");
18566
18567 static void
18568 print_tx_offloads(uint64_t offloads)
18569 {
18570         uint64_t single_offload;
18571         int begin;
18572         int end;
18573         int bit;
18574
18575         if (offloads == 0)
18576                 return;
18577
18578         begin = __builtin_ctzll(offloads);
18579         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18580
18581         single_offload = 1ULL << begin;
18582         for (bit = begin; bit < end; bit++) {
18583                 if (offloads & single_offload)
18584                         printf(" %s",
18585                                rte_eth_dev_tx_offload_name(single_offload));
18586                 single_offload <<= 1;
18587         }
18588 }
18589
18590 static void
18591 cmd_tx_offload_get_capa_parsed(
18592         void *parsed_result,
18593         __rte_unused struct cmdline *cl,
18594         __rte_unused void *data)
18595 {
18596         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18597         struct rte_eth_dev_info dev_info;
18598         portid_t port_id = res->port_id;
18599         uint64_t queue_offloads;
18600         uint64_t port_offloads;
18601         int ret;
18602
18603         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18604         if (ret != 0)
18605                 return;
18606
18607         queue_offloads = dev_info.tx_queue_offload_capa;
18608         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18609
18610         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18611         printf("  Per Queue :");
18612         print_tx_offloads(queue_offloads);
18613
18614         printf("\n");
18615         printf("  Per Port  :");
18616         print_tx_offloads(port_offloads);
18617         printf("\n\n");
18618 }
18619
18620 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18621         .f = cmd_tx_offload_get_capa_parsed,
18622         .data = NULL,
18623         .help_str = "show port <port_id> tx_offload capabilities",
18624         .tokens = {
18625                 (void *)&cmd_tx_offload_get_capa_show,
18626                 (void *)&cmd_tx_offload_get_capa_port,
18627                 (void *)&cmd_tx_offload_get_capa_port_id,
18628                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18629                 (void *)&cmd_tx_offload_get_capa_capabilities,
18630                 NULL,
18631         }
18632 };
18633
18634 /* Get Tx offloads configuration */
18635 struct cmd_tx_offload_get_configuration_result {
18636         cmdline_fixed_string_t show;
18637         cmdline_fixed_string_t port;
18638         portid_t port_id;
18639         cmdline_fixed_string_t tx_offload;
18640         cmdline_fixed_string_t configuration;
18641 };
18642
18643 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18644         TOKEN_STRING_INITIALIZER
18645                 (struct cmd_tx_offload_get_configuration_result,
18646                  show, "show");
18647 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18648         TOKEN_STRING_INITIALIZER
18649                 (struct cmd_tx_offload_get_configuration_result,
18650                  port, "port");
18651 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18652         TOKEN_NUM_INITIALIZER
18653                 (struct cmd_tx_offload_get_configuration_result,
18654                  port_id, UINT16);
18655 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18656         TOKEN_STRING_INITIALIZER
18657                 (struct cmd_tx_offload_get_configuration_result,
18658                  tx_offload, "tx_offload");
18659 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18660         TOKEN_STRING_INITIALIZER
18661                 (struct cmd_tx_offload_get_configuration_result,
18662                  configuration, "configuration");
18663
18664 static void
18665 cmd_tx_offload_get_configuration_parsed(
18666         void *parsed_result,
18667         __rte_unused struct cmdline *cl,
18668         __rte_unused void *data)
18669 {
18670         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18671         struct rte_eth_dev_info dev_info;
18672         portid_t port_id = res->port_id;
18673         struct rte_port *port = &ports[port_id];
18674         uint64_t port_offloads;
18675         uint64_t queue_offloads;
18676         uint16_t nb_tx_queues;
18677         int q;
18678         int ret;
18679
18680         printf("Tx Offloading Configuration of port %d :\n", port_id);
18681
18682         port_offloads = port->dev_conf.txmode.offloads;
18683         printf("  Port :");
18684         print_tx_offloads(port_offloads);
18685         printf("\n");
18686
18687         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18688         if (ret != 0)
18689                 return;
18690
18691         nb_tx_queues = dev_info.nb_tx_queues;
18692         for (q = 0; q < nb_tx_queues; q++) {
18693                 queue_offloads = port->tx_conf[q].offloads;
18694                 printf("  Queue[%2d] :", q);
18695                 print_tx_offloads(queue_offloads);
18696                 printf("\n");
18697         }
18698         printf("\n");
18699 }
18700
18701 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18702         .f = cmd_tx_offload_get_configuration_parsed,
18703         .data = NULL,
18704         .help_str = "show port <port_id> tx_offload configuration",
18705         .tokens = {
18706                 (void *)&cmd_tx_offload_get_configuration_show,
18707                 (void *)&cmd_tx_offload_get_configuration_port,
18708                 (void *)&cmd_tx_offload_get_configuration_port_id,
18709                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18710                 (void *)&cmd_tx_offload_get_configuration_configuration,
18711                 NULL,
18712         }
18713 };
18714
18715 /* Enable/Disable a per port offloading */
18716 struct cmd_config_per_port_tx_offload_result {
18717         cmdline_fixed_string_t port;
18718         cmdline_fixed_string_t config;
18719         portid_t port_id;
18720         cmdline_fixed_string_t tx_offload;
18721         cmdline_fixed_string_t offload;
18722         cmdline_fixed_string_t on_off;
18723 };
18724
18725 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18726         TOKEN_STRING_INITIALIZER
18727                 (struct cmd_config_per_port_tx_offload_result,
18728                  port, "port");
18729 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18730         TOKEN_STRING_INITIALIZER
18731                 (struct cmd_config_per_port_tx_offload_result,
18732                  config, "config");
18733 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18734         TOKEN_NUM_INITIALIZER
18735                 (struct cmd_config_per_port_tx_offload_result,
18736                  port_id, UINT16);
18737 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18738         TOKEN_STRING_INITIALIZER
18739                 (struct cmd_config_per_port_tx_offload_result,
18740                  tx_offload, "tx_offload");
18741 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18742         TOKEN_STRING_INITIALIZER
18743                 (struct cmd_config_per_port_tx_offload_result,
18744                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18745                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18746                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18747                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18748                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18749                           "send_on_timestamp");
18750 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18751         TOKEN_STRING_INITIALIZER
18752                 (struct cmd_config_per_port_tx_offload_result,
18753                  on_off, "on#off");
18754
18755 static uint64_t
18756 search_tx_offload(const char *name)
18757 {
18758         uint64_t single_offload;
18759         const char *single_name;
18760         int found = 0;
18761         unsigned int bit;
18762
18763         single_offload = 1;
18764         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18765                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18766                 if (single_name == NULL)
18767                         break;
18768                 if (!strcasecmp(single_name, name)) {
18769                         found = 1;
18770                         break;
18771                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18772                         break;
18773                 single_offload <<= 1;
18774         }
18775
18776         if (found)
18777                 return single_offload;
18778
18779         return 0;
18780 }
18781
18782 static void
18783 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18784                                 __rte_unused struct cmdline *cl,
18785                                 __rte_unused void *data)
18786 {
18787         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18788         portid_t port_id = res->port_id;
18789         struct rte_eth_dev_info dev_info;
18790         struct rte_port *port = &ports[port_id];
18791         uint64_t single_offload;
18792         uint16_t nb_tx_queues;
18793         int q;
18794         int ret;
18795
18796         if (port->port_status != RTE_PORT_STOPPED) {
18797                 printf("Error: Can't config offload when Port %d "
18798                        "is not stopped\n", port_id);
18799                 return;
18800         }
18801
18802         single_offload = search_tx_offload(res->offload);
18803         if (single_offload == 0) {
18804                 printf("Unknown offload name: %s\n", res->offload);
18805                 return;
18806         }
18807
18808         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18809         if (ret != 0)
18810                 return;
18811
18812         nb_tx_queues = dev_info.nb_tx_queues;
18813         if (!strcmp(res->on_off, "on")) {
18814                 port->dev_conf.txmode.offloads |= single_offload;
18815                 for (q = 0; q < nb_tx_queues; q++)
18816                         port->tx_conf[q].offloads |= single_offload;
18817         } else {
18818                 port->dev_conf.txmode.offloads &= ~single_offload;
18819                 for (q = 0; q < nb_tx_queues; q++)
18820                         port->tx_conf[q].offloads &= ~single_offload;
18821         }
18822
18823         cmd_reconfig_device_queue(port_id, 1, 1);
18824 }
18825
18826 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18827         .f = cmd_config_per_port_tx_offload_parsed,
18828         .data = NULL,
18829         .help_str = "port config <port_id> tx_offload "
18830                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18831                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18832                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18833                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18834                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18835                     "send_on_timestamp on|off",
18836         .tokens = {
18837                 (void *)&cmd_config_per_port_tx_offload_result_port,
18838                 (void *)&cmd_config_per_port_tx_offload_result_config,
18839                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18840                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18841                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18842                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18843                 NULL,
18844         }
18845 };
18846
18847 /* Enable/Disable a per queue offloading */
18848 struct cmd_config_per_queue_tx_offload_result {
18849         cmdline_fixed_string_t port;
18850         portid_t port_id;
18851         cmdline_fixed_string_t txq;
18852         uint16_t queue_id;
18853         cmdline_fixed_string_t tx_offload;
18854         cmdline_fixed_string_t offload;
18855         cmdline_fixed_string_t on_off;
18856 };
18857
18858 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18859         TOKEN_STRING_INITIALIZER
18860                 (struct cmd_config_per_queue_tx_offload_result,
18861                  port, "port");
18862 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18863         TOKEN_NUM_INITIALIZER
18864                 (struct cmd_config_per_queue_tx_offload_result,
18865                  port_id, UINT16);
18866 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18867         TOKEN_STRING_INITIALIZER
18868                 (struct cmd_config_per_queue_tx_offload_result,
18869                  txq, "txq");
18870 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18871         TOKEN_NUM_INITIALIZER
18872                 (struct cmd_config_per_queue_tx_offload_result,
18873                  queue_id, UINT16);
18874 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18875         TOKEN_STRING_INITIALIZER
18876                 (struct cmd_config_per_queue_tx_offload_result,
18877                  tx_offload, "tx_offload");
18878 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18879         TOKEN_STRING_INITIALIZER
18880                 (struct cmd_config_per_queue_tx_offload_result,
18881                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18882                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18883                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18884                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18885                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18886 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18887         TOKEN_STRING_INITIALIZER
18888                 (struct cmd_config_per_queue_tx_offload_result,
18889                  on_off, "on#off");
18890
18891 static void
18892 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18893                                 __rte_unused struct cmdline *cl,
18894                                 __rte_unused void *data)
18895 {
18896         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18897         struct rte_eth_dev_info dev_info;
18898         portid_t port_id = res->port_id;
18899         uint16_t queue_id = res->queue_id;
18900         struct rte_port *port = &ports[port_id];
18901         uint64_t single_offload;
18902         int ret;
18903
18904         if (port->port_status != RTE_PORT_STOPPED) {
18905                 printf("Error: Can't config offload when Port %d "
18906                        "is not stopped\n", port_id);
18907                 return;
18908         }
18909
18910         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18911         if (ret != 0)
18912                 return;
18913
18914         if (queue_id >= dev_info.nb_tx_queues) {
18915                 printf("Error: input queue_id should be 0 ... "
18916                        "%d\n", dev_info.nb_tx_queues - 1);
18917                 return;
18918         }
18919
18920         single_offload = search_tx_offload(res->offload);
18921         if (single_offload == 0) {
18922                 printf("Unknown offload name: %s\n", res->offload);
18923                 return;
18924         }
18925
18926         if (!strcmp(res->on_off, "on"))
18927                 port->tx_conf[queue_id].offloads |= single_offload;
18928         else
18929                 port->tx_conf[queue_id].offloads &= ~single_offload;
18930
18931         cmd_reconfig_device_queue(port_id, 1, 1);
18932 }
18933
18934 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18935         .f = cmd_config_per_queue_tx_offload_parsed,
18936         .data = NULL,
18937         .help_str = "port <port_id> txq <queue_id> tx_offload "
18938                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18939                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18940                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18941                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18942                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18943                     "on|off",
18944         .tokens = {
18945                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18946                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18947                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18948                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18949                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18950                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18951                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18952                 NULL,
18953         }
18954 };
18955
18956 /* *** configure tx_metadata for specific port *** */
18957 struct cmd_config_tx_metadata_specific_result {
18958         cmdline_fixed_string_t port;
18959         cmdline_fixed_string_t keyword;
18960         uint16_t port_id;
18961         cmdline_fixed_string_t item;
18962         uint32_t value;
18963 };
18964
18965 static void
18966 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18967                                 __rte_unused struct cmdline *cl,
18968                                 __rte_unused void *data)
18969 {
18970         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18971
18972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18973                 return;
18974         ports[res->port_id].tx_metadata = res->value;
18975         /* Add/remove callback to insert valid metadata in every Tx packet. */
18976         if (ports[res->port_id].tx_metadata)
18977                 add_tx_md_callback(res->port_id);
18978         else
18979                 remove_tx_md_callback(res->port_id);
18980         rte_flow_dynf_metadata_register();
18981 }
18982
18983 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18984         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18985                         port, "port");
18986 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18987         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18988                         keyword, "config");
18989 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18990         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18991                         port_id, UINT16);
18992 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18993         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18994                         item, "tx_metadata");
18995 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
18996         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18997                         value, UINT32);
18998
18999 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19000         .f = cmd_config_tx_metadata_specific_parsed,
19001         .data = NULL,
19002         .help_str = "port config <port_id> tx_metadata <value>",
19003         .tokens = {
19004                 (void *)&cmd_config_tx_metadata_specific_port,
19005                 (void *)&cmd_config_tx_metadata_specific_keyword,
19006                 (void *)&cmd_config_tx_metadata_specific_id,
19007                 (void *)&cmd_config_tx_metadata_specific_item,
19008                 (void *)&cmd_config_tx_metadata_specific_value,
19009                 NULL,
19010         },
19011 };
19012
19013 /* *** set dynf *** */
19014 struct cmd_config_tx_dynf_specific_result {
19015         cmdline_fixed_string_t port;
19016         cmdline_fixed_string_t keyword;
19017         uint16_t port_id;
19018         cmdline_fixed_string_t item;
19019         cmdline_fixed_string_t name;
19020         cmdline_fixed_string_t value;
19021 };
19022
19023 static void
19024 cmd_config_dynf_specific_parsed(void *parsed_result,
19025                                 __rte_unused struct cmdline *cl,
19026                                 __rte_unused void *data)
19027 {
19028         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19029         struct rte_mbuf_dynflag desc_flag;
19030         int flag;
19031         uint64_t old_port_flags;
19032
19033         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19034                 return;
19035         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19036         if (flag <= 0) {
19037                 if (strlcpy(desc_flag.name, res->name,
19038                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19039                         printf("Flag name too long\n");
19040                         return;
19041                 }
19042                 desc_flag.flags = 0;
19043                 flag = rte_mbuf_dynflag_register(&desc_flag);
19044                 if (flag < 0) {
19045                         printf("Can't register flag\n");
19046                         return;
19047                 }
19048                 strcpy(dynf_names[flag], desc_flag.name);
19049         }
19050         old_port_flags = ports[res->port_id].mbuf_dynf;
19051         if (!strcmp(res->value, "set")) {
19052                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19053                 if (old_port_flags == 0)
19054                         add_tx_dynf_callback(res->port_id);
19055         } else {
19056                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19057                 if (ports[res->port_id].mbuf_dynf == 0)
19058                         remove_tx_dynf_callback(res->port_id);
19059         }
19060 }
19061
19062 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19063         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19064                         keyword, "port");
19065 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19066         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19067                         keyword, "config");
19068 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19069         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19070                         port_id, UINT16);
19071 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19072         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19073                         item, "dynf");
19074 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19075         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19076                         name, NULL);
19077 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19078         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19079                         value, "set#clear");
19080
19081 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19082         .f = cmd_config_dynf_specific_parsed,
19083         .data = NULL,
19084         .help_str = "port config <port id> dynf <name> set|clear",
19085         .tokens = {
19086                 (void *)&cmd_config_tx_dynf_specific_port,
19087                 (void *)&cmd_config_tx_dynf_specific_keyword,
19088                 (void *)&cmd_config_tx_dynf_specific_port_id,
19089                 (void *)&cmd_config_tx_dynf_specific_item,
19090                 (void *)&cmd_config_tx_dynf_specific_name,
19091                 (void *)&cmd_config_tx_dynf_specific_value,
19092                 NULL,
19093         },
19094 };
19095
19096 /* *** display tx_metadata per port configuration *** */
19097 struct cmd_show_tx_metadata_result {
19098         cmdline_fixed_string_t cmd_show;
19099         cmdline_fixed_string_t cmd_port;
19100         cmdline_fixed_string_t cmd_keyword;
19101         portid_t cmd_pid;
19102 };
19103
19104 static void
19105 cmd_show_tx_metadata_parsed(void *parsed_result,
19106                 __rte_unused struct cmdline *cl,
19107                 __rte_unused void *data)
19108 {
19109         struct cmd_show_tx_metadata_result *res = parsed_result;
19110
19111         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19112                 printf("invalid port id %u\n", res->cmd_pid);
19113                 return;
19114         }
19115         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19116                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19117                        ports[res->cmd_pid].tx_metadata);
19118         }
19119 }
19120
19121 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19122         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19123                         cmd_show, "show");
19124 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19125         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19126                         cmd_port, "port");
19127 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19128         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19129                         cmd_pid, UINT16);
19130 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19131         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19132                         cmd_keyword, "tx_metadata");
19133
19134 cmdline_parse_inst_t cmd_show_tx_metadata = {
19135         .f = cmd_show_tx_metadata_parsed,
19136         .data = NULL,
19137         .help_str = "show port <port_id> tx_metadata",
19138         .tokens = {
19139                 (void *)&cmd_show_tx_metadata_show,
19140                 (void *)&cmd_show_tx_metadata_port,
19141                 (void *)&cmd_show_tx_metadata_pid,
19142                 (void *)&cmd_show_tx_metadata_keyword,
19143                 NULL,
19144         },
19145 };
19146
19147 /* show port supported ptypes */
19148
19149 /* Common result structure for show port ptypes */
19150 struct cmd_show_port_supported_ptypes_result {
19151         cmdline_fixed_string_t show;
19152         cmdline_fixed_string_t port;
19153         portid_t port_id;
19154         cmdline_fixed_string_t ptypes;
19155 };
19156
19157 /* Common CLI fields for show port ptypes */
19158 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19159         TOKEN_STRING_INITIALIZER
19160                 (struct cmd_show_port_supported_ptypes_result,
19161                  show, "show");
19162 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19163         TOKEN_STRING_INITIALIZER
19164                 (struct cmd_show_port_supported_ptypes_result,
19165                  port, "port");
19166 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19167         TOKEN_NUM_INITIALIZER
19168                 (struct cmd_show_port_supported_ptypes_result,
19169                  port_id, UINT16);
19170 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19171         TOKEN_STRING_INITIALIZER
19172                 (struct cmd_show_port_supported_ptypes_result,
19173                  ptypes, "ptypes");
19174
19175 static void
19176 cmd_show_port_supported_ptypes_parsed(
19177         void *parsed_result,
19178         __rte_unused struct cmdline *cl,
19179         __rte_unused void *data)
19180 {
19181 #define RSVD_PTYPE_MASK       0xf0000000
19182 #define MAX_PTYPES_PER_LAYER  16
19183 #define LTYPE_NAMESIZE        32
19184 #define PTYPE_NAMESIZE        256
19185         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19186         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19187         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19188         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19189         uint16_t port_id = res->port_id;
19190         int ret, i;
19191
19192         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19193         if (ret < 0)
19194                 return;
19195
19196         while (ptype_mask != RSVD_PTYPE_MASK) {
19197
19198                 switch (ptype_mask) {
19199                 case RTE_PTYPE_L2_MASK:
19200                         strlcpy(ltype, "L2", sizeof(ltype));
19201                         break;
19202                 case RTE_PTYPE_L3_MASK:
19203                         strlcpy(ltype, "L3", sizeof(ltype));
19204                         break;
19205                 case RTE_PTYPE_L4_MASK:
19206                         strlcpy(ltype, "L4", sizeof(ltype));
19207                         break;
19208                 case RTE_PTYPE_TUNNEL_MASK:
19209                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19210                         break;
19211                 case RTE_PTYPE_INNER_L2_MASK:
19212                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19213                         break;
19214                 case RTE_PTYPE_INNER_L3_MASK:
19215                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19216                         break;
19217                 case RTE_PTYPE_INNER_L4_MASK:
19218                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19219                         break;
19220                 default:
19221                         return;
19222                 }
19223
19224                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19225                                                        ptype_mask, ptypes,
19226                                                        MAX_PTYPES_PER_LAYER);
19227
19228                 if (ret > 0)
19229                         printf("Supported %s ptypes:\n", ltype);
19230                 else
19231                         printf("%s ptypes unsupported\n", ltype);
19232
19233                 for (i = 0; i < ret; ++i) {
19234                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19235                         printf("%s\n", buf);
19236                 }
19237
19238                 ptype_mask <<= 4;
19239         }
19240 }
19241
19242 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19243         .f = cmd_show_port_supported_ptypes_parsed,
19244         .data = NULL,
19245         .help_str = "show port <port_id> ptypes",
19246         .tokens = {
19247                 (void *)&cmd_show_port_supported_ptypes_show,
19248                 (void *)&cmd_show_port_supported_ptypes_port,
19249                 (void *)&cmd_show_port_supported_ptypes_port_id,
19250                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19251                 NULL,
19252         },
19253 };
19254
19255 /* *** display rx/tx descriptor status *** */
19256 struct cmd_show_rx_tx_desc_status_result {
19257         cmdline_fixed_string_t cmd_show;
19258         cmdline_fixed_string_t cmd_port;
19259         cmdline_fixed_string_t cmd_keyword;
19260         cmdline_fixed_string_t cmd_desc;
19261         cmdline_fixed_string_t cmd_status;
19262         portid_t cmd_pid;
19263         portid_t cmd_qid;
19264         portid_t cmd_did;
19265 };
19266
19267 static void
19268 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19269                 __rte_unused struct cmdline *cl,
19270                 __rte_unused void *data)
19271 {
19272         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19273         int rc;
19274
19275         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19276                 printf("invalid port id %u\n", res->cmd_pid);
19277                 return;
19278         }
19279
19280         if (!strcmp(res->cmd_keyword, "rxq")) {
19281                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19282                                              res->cmd_did);
19283                 if (rc < 0) {
19284                         printf("Invalid queueid = %d\n", res->cmd_qid);
19285                         return;
19286                 }
19287                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19288                         printf("Desc status = AVAILABLE\n");
19289                 else if (rc == RTE_ETH_RX_DESC_DONE)
19290                         printf("Desc status = DONE\n");
19291                 else
19292                         printf("Desc status = UNAVAILABLE\n");
19293         } else if (!strcmp(res->cmd_keyword, "txq")) {
19294                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19295                                              res->cmd_did);
19296                 if (rc < 0) {
19297                         printf("Invalid queueid = %d\n", res->cmd_qid);
19298                         return;
19299                 }
19300                 if (rc == RTE_ETH_TX_DESC_FULL)
19301                         printf("Desc status = FULL\n");
19302                 else if (rc == RTE_ETH_TX_DESC_DONE)
19303                         printf("Desc status = DONE\n");
19304                 else
19305                         printf("Desc status = UNAVAILABLE\n");
19306         }
19307 }
19308
19309 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19310         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19311                         cmd_show, "show");
19312 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19313         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19314                         cmd_port, "port");
19315 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19316         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19317                         cmd_pid, UINT16);
19318 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19319         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19320                         cmd_keyword, "rxq#txq");
19321 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19322         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19323                         cmd_qid, UINT16);
19324 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19325         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19326                         cmd_desc, "desc");
19327 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19328         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19329                         cmd_did, UINT16);
19330 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19331         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19332                         cmd_status, "status");
19333 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19334         .f = cmd_show_rx_tx_desc_status_parsed,
19335         .data = NULL,
19336         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19337                 "status",
19338         .tokens = {
19339                 (void *)&cmd_show_rx_tx_desc_status_show,
19340                 (void *)&cmd_show_rx_tx_desc_status_port,
19341                 (void *)&cmd_show_rx_tx_desc_status_pid,
19342                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19343                 (void *)&cmd_show_rx_tx_desc_status_qid,
19344                 (void *)&cmd_show_rx_tx_desc_status_desc,
19345                 (void *)&cmd_show_rx_tx_desc_status_did,
19346                 (void *)&cmd_show_rx_tx_desc_status_status,
19347                 NULL,
19348         },
19349 };
19350
19351 /* Common result structure for set port ptypes */
19352 struct cmd_set_port_ptypes_result {
19353         cmdline_fixed_string_t set;
19354         cmdline_fixed_string_t port;
19355         portid_t port_id;
19356         cmdline_fixed_string_t ptype_mask;
19357         uint32_t mask;
19358 };
19359
19360 /* Common CLI fields for set port ptypes */
19361 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19362         TOKEN_STRING_INITIALIZER
19363                 (struct cmd_set_port_ptypes_result,
19364                  set, "set");
19365 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19366         TOKEN_STRING_INITIALIZER
19367                 (struct cmd_set_port_ptypes_result,
19368                  port, "port");
19369 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19370         TOKEN_NUM_INITIALIZER
19371                 (struct cmd_set_port_ptypes_result,
19372                  port_id, UINT16);
19373 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19374         TOKEN_STRING_INITIALIZER
19375                 (struct cmd_set_port_ptypes_result,
19376                  ptype_mask, "ptype_mask");
19377 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19378         TOKEN_NUM_INITIALIZER
19379                 (struct cmd_set_port_ptypes_result,
19380                  mask, UINT32);
19381
19382 static void
19383 cmd_set_port_ptypes_parsed(
19384         void *parsed_result,
19385         __rte_unused struct cmdline *cl,
19386         __rte_unused void *data)
19387 {
19388         struct cmd_set_port_ptypes_result *res = parsed_result;
19389 #define PTYPE_NAMESIZE        256
19390         char ptype_name[PTYPE_NAMESIZE];
19391         uint16_t port_id = res->port_id;
19392         uint32_t ptype_mask = res->mask;
19393         int ret, i;
19394
19395         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19396                                                NULL, 0);
19397         if (ret <= 0) {
19398                 printf("Port %d doesn't support any ptypes.\n", port_id);
19399                 return;
19400         }
19401
19402         uint32_t ptypes[ret];
19403
19404         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19405         if (ret < 0) {
19406                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19407                 return;
19408         }
19409
19410         printf("Successfully set following ptypes for Port %d\n", port_id);
19411         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19412                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19413                 printf("%s\n", ptype_name);
19414         }
19415
19416         clear_ptypes = false;
19417 }
19418
19419 cmdline_parse_inst_t cmd_set_port_ptypes = {
19420         .f = cmd_set_port_ptypes_parsed,
19421         .data = NULL,
19422         .help_str = "set port <port_id> ptype_mask <mask>",
19423         .tokens = {
19424                 (void *)&cmd_set_port_ptypes_set,
19425                 (void *)&cmd_set_port_ptypes_port,
19426                 (void *)&cmd_set_port_ptypes_port_id,
19427                 (void *)&cmd_set_port_ptypes_mask_str,
19428                 (void *)&cmd_set_port_ptypes_mask_u32,
19429                 NULL,
19430         },
19431 };
19432
19433 /* *** display mac addresses added to a port *** */
19434 struct cmd_showport_macs_result {
19435         cmdline_fixed_string_t cmd_show;
19436         cmdline_fixed_string_t cmd_port;
19437         cmdline_fixed_string_t cmd_keyword;
19438         portid_t cmd_pid;
19439 };
19440
19441 static void
19442 cmd_showport_macs_parsed(void *parsed_result,
19443                 __rte_unused struct cmdline *cl,
19444                 __rte_unused void *data)
19445 {
19446         struct cmd_showport_macs_result *res = parsed_result;
19447
19448         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19449                 return;
19450
19451         if (!strcmp(res->cmd_keyword, "macs"))
19452                 show_macs(res->cmd_pid);
19453         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19454                 show_mcast_macs(res->cmd_pid);
19455 }
19456
19457 cmdline_parse_token_string_t cmd_showport_macs_show =
19458         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19459                         cmd_show, "show");
19460 cmdline_parse_token_string_t cmd_showport_macs_port =
19461         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19462                         cmd_port, "port");
19463 cmdline_parse_token_num_t cmd_showport_macs_pid =
19464         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19465                         cmd_pid, UINT16);
19466 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19467         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19468                         cmd_keyword, "macs#mcast_macs");
19469
19470 cmdline_parse_inst_t cmd_showport_macs = {
19471         .f = cmd_showport_macs_parsed,
19472         .data = NULL,
19473         .help_str = "show port <port_id> macs|mcast_macs",
19474         .tokens = {
19475                 (void *)&cmd_showport_macs_show,
19476                 (void *)&cmd_showport_macs_port,
19477                 (void *)&cmd_showport_macs_pid,
19478                 (void *)&cmd_showport_macs_keyword,
19479                 NULL,
19480         },
19481 };
19482
19483 /* ******************************************************************************** */
19484
19485 /* list of instructions */
19486 cmdline_parse_ctx_t main_ctx[] = {
19487         (cmdline_parse_inst_t *)&cmd_help_brief,
19488         (cmdline_parse_inst_t *)&cmd_help_long,
19489         (cmdline_parse_inst_t *)&cmd_quit,
19490         (cmdline_parse_inst_t *)&cmd_load_from_file,
19491         (cmdline_parse_inst_t *)&cmd_showport,
19492         (cmdline_parse_inst_t *)&cmd_showqueue,
19493         (cmdline_parse_inst_t *)&cmd_showportall,
19494         (cmdline_parse_inst_t *)&cmd_showdevice,
19495         (cmdline_parse_inst_t *)&cmd_showcfg,
19496         (cmdline_parse_inst_t *)&cmd_showfwdall,
19497         (cmdline_parse_inst_t *)&cmd_start,
19498         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19499         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19500         (cmdline_parse_inst_t *)&cmd_set_link_up,
19501         (cmdline_parse_inst_t *)&cmd_set_link_down,
19502         (cmdline_parse_inst_t *)&cmd_reset,
19503         (cmdline_parse_inst_t *)&cmd_set_numbers,
19504         (cmdline_parse_inst_t *)&cmd_set_log,
19505         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19506         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19507         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19508         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19509         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19510         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19511         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19512         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19513         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19514         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19515         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19516         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19517         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19518         (cmdline_parse_inst_t *)&cmd_set_link_check,
19519         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19520         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19521         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19522         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19523 #ifdef RTE_LIBRTE_PMD_BOND
19524         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19525         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19526         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19527         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19528         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19529         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19530         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19531         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19532         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19533         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19534         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19535 #endif
19536         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19537         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19538         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19539         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19540         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19541         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19542         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19543         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19544         (cmdline_parse_inst_t *)&cmd_csum_set,
19545         (cmdline_parse_inst_t *)&cmd_csum_show,
19546         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19547         (cmdline_parse_inst_t *)&cmd_tso_set,
19548         (cmdline_parse_inst_t *)&cmd_tso_show,
19549         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19550         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19551         (cmdline_parse_inst_t *)&cmd_gro_enable,
19552         (cmdline_parse_inst_t *)&cmd_gro_flush,
19553         (cmdline_parse_inst_t *)&cmd_gro_show,
19554         (cmdline_parse_inst_t *)&cmd_gso_enable,
19555         (cmdline_parse_inst_t *)&cmd_gso_size,
19556         (cmdline_parse_inst_t *)&cmd_gso_show,
19557         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19558         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19559         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19560         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19561         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19562         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19566         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19567         (cmdline_parse_inst_t *)&cmd_config_dcb,
19568         (cmdline_parse_inst_t *)&cmd_read_reg,
19569         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19570         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19571         (cmdline_parse_inst_t *)&cmd_write_reg,
19572         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19573         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19574         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19575         (cmdline_parse_inst_t *)&cmd_stop,
19576         (cmdline_parse_inst_t *)&cmd_mac_addr,
19577         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19578         (cmdline_parse_inst_t *)&cmd_set_qmap,
19579         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19580         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19581         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19582         (cmdline_parse_inst_t *)&cmd_operate_port,
19583         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19584         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19585         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19586         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19587         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19588         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19589         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19590         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19591         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19592         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19593         (cmdline_parse_inst_t *)&cmd_config_mtu,
19594         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19595         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19596         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19597         (cmdline_parse_inst_t *)&cmd_config_rss,
19598         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19599         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19600         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19601         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19602         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19603         (cmdline_parse_inst_t *)&cmd_showport_reta,
19604         (cmdline_parse_inst_t *)&cmd_showport_macs,
19605         (cmdline_parse_inst_t *)&cmd_config_burst,
19606         (cmdline_parse_inst_t *)&cmd_config_thresh,
19607         (cmdline_parse_inst_t *)&cmd_config_threshold,
19608         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19609         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19610         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19611         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19612         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19613         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19614         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19615         (cmdline_parse_inst_t *)&cmd_global_config,
19616         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19617         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19618         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19619         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19620         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19621         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19622         (cmdline_parse_inst_t *)&cmd_dump,
19623         (cmdline_parse_inst_t *)&cmd_dump_one,
19624         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19625         (cmdline_parse_inst_t *)&cmd_syn_filter,
19626         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19627         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19628         (cmdline_parse_inst_t *)&cmd_flex_filter,
19629         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19630         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19631         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19632         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19633         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19634         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19635         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19636         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19637         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19638         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19639         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19640         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19641         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19642         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19643         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19644         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19645         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19646         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19647         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19648         (cmdline_parse_inst_t *)&cmd_flow,
19649         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19650         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19651         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19652         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19653         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19654         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19655         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19656         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19657         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19658         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19659         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19660         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19661         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19662         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19663         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19664         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19665         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19666         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19667         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19668         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19669         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19670         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19671         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19672         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19673         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19674         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19675         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19676         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19677         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19678         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19679         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19680         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19681         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19682         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19683         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19684         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19685         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19686         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19687         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19688         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19689         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19690         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19691         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19692         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19693         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19694         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19695         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19696         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19697         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19698         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19699         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19700         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19701         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19702         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19703         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19704         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19705         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19706         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19707         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19708         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19709         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19710         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19711         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19712         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19713         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19714         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19715         (cmdline_parse_inst_t *)&cmd_ddp_add,
19716         (cmdline_parse_inst_t *)&cmd_ddp_del,
19717         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19718         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19719         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19720         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19721         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19722         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19723         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19724         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19725         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19726         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19727         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19728         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19729
19730         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19731         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19732         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19733         (cmdline_parse_inst_t *)&cmd_queue_region,
19734         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19735         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19736         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19737         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19738         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19739         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19740         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19741         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19742         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19743         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19744         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19745         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19746         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19747         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19748         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19749         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19750         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19751         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19752         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19753         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19754         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19755         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19756         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19757         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19758         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19759         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19760         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19761         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19762         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19763         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19764         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19765         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19766         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19767         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19768         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19769 #ifdef RTE_LIBRTE_BPF
19770         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19771         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19772 #endif
19773         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19774         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19775         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19776         (cmdline_parse_inst_t *)&cmd_set_raw,
19777         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19778         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19779         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19780         NULL,
19781 };
19782
19783 /* read cmdline commands from file */
19784 void
19785 cmdline_read_from_file(const char *filename)
19786 {
19787         struct cmdline *cl;
19788
19789         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19790         if (cl == NULL) {
19791                 printf("Failed to create file based cmdline context: %s\n",
19792                        filename);
19793                 return;
19794         }
19795
19796         cmdline_interact(cl);
19797         cmdline_quit(cl);
19798
19799         cmdline_free(cl);
19800
19801         printf("Read CLI commands from %s\n", filename);
19802 }
19803
19804 /* prompt function, called from main on MASTER lcore */
19805 void
19806 prompt(void)
19807 {
19808         /* initialize non-constant commands */
19809         cmd_set_fwd_mode_init();
19810         cmd_set_fwd_retry_mode_init();
19811
19812         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19813         if (testpmd_cl == NULL)
19814                 return;
19815         cmdline_interact(testpmd_cl);
19816         cmdline_stdin_exit(testpmd_cl);
19817 }
19818
19819 void
19820 prompt_exit(void)
19821 {
19822         if (testpmd_cl != NULL)
19823                 cmdline_quit(testpmd_cl);
19824 }
19825
19826 static void
19827 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19828 {
19829         if (id == (portid_t)RTE_PORT_ALL) {
19830                 portid_t pid;
19831
19832                 RTE_ETH_FOREACH_DEV(pid) {
19833                         /* check if need_reconfig has been set to 1 */
19834                         if (ports[pid].need_reconfig == 0)
19835                                 ports[pid].need_reconfig = dev;
19836                         /* check if need_reconfig_queues has been set to 1 */
19837                         if (ports[pid].need_reconfig_queues == 0)
19838                                 ports[pid].need_reconfig_queues = queue;
19839                 }
19840         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19841                 /* check if need_reconfig has been set to 1 */
19842                 if (ports[id].need_reconfig == 0)
19843                         ports[id].need_reconfig = dev;
19844                 /* check if need_reconfig_queues has been set to 1 */
19845                 if (ports[id].need_reconfig_queues == 0)
19846                         ports[id].need_reconfig_queues = queue;
19847         }
19848 }