net/axgbe: support IEEE 1588 PTP
[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) (packet_mode)\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 nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1234                         " (priority) (weight) (level_id) (shaper_profile_id)"
1235                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1236                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1237                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1238
1239                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1240                         " (priority) (weight) (level_id) (shaper_profile_id)"
1241                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1242                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1243                         "       Add port tm leaf node.\n\n"
1244
1245                         "del port tm node (port_id) (node_id)\n"
1246                         "       Delete port tm node.\n\n"
1247
1248                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1249                         " (priority) (weight)\n"
1250                         "       Set port tm node parent.\n\n"
1251
1252                         "suspend port tm node (port_id) (node_id)"
1253                         "       Suspend tm node.\n\n"
1254
1255                         "resume port tm node (port_id) (node_id)"
1256                         "       Resume tm node.\n\n"
1257
1258                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1259                         "       Commit tm hierarchy.\n\n"
1260
1261                         "set port tm mark ip_ecn (port) (green) (yellow)"
1262                         " (red)\n"
1263                         "    Enables/Disables the traffic management marking"
1264                         " for IP ECN (Explicit Congestion Notification)"
1265                         " packets on a given port\n\n"
1266
1267                         "set port tm mark ip_dscp (port) (green) (yellow)"
1268                         " (red)\n"
1269                         "    Enables/Disables the traffic management marking"
1270                         " on the port for IP dscp packets\n\n"
1271
1272                         "set port tm mark vlan_dei (port) (green) (yellow)"
1273                         " (red)\n"
1274                         "    Enables/Disables the traffic management marking"
1275                         " on the port for VLAN packets with DEI enabled\n\n"
1276                 );
1277         }
1278
1279         if (show_all || !strcmp(res->section, "devices")) {
1280                 cmdline_printf(
1281                         cl,
1282                         "\n"
1283                         "Device Operations:\n"
1284                         "--------------\n"
1285                         "device detach (identifier)\n"
1286                         "       Detach device by identifier.\n\n"
1287                 );
1288         }
1289
1290 }
1291
1292 cmdline_parse_token_string_t cmd_help_long_help =
1293         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1294
1295 cmdline_parse_token_string_t cmd_help_long_section =
1296         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1297                         "all#control#display#config#"
1298                         "ports#registers#filters#traffic_management#devices");
1299
1300 cmdline_parse_inst_t cmd_help_long = {
1301         .f = cmd_help_long_parsed,
1302         .data = NULL,
1303         .help_str = "help all|control|display|config|ports|register|"
1304                 "filters|traffic_management|devices: "
1305                 "Show help",
1306         .tokens = {
1307                 (void *)&cmd_help_long_help,
1308                 (void *)&cmd_help_long_section,
1309                 NULL,
1310         },
1311 };
1312
1313
1314 /* *** start/stop/close all ports *** */
1315 struct cmd_operate_port_result {
1316         cmdline_fixed_string_t keyword;
1317         cmdline_fixed_string_t name;
1318         cmdline_fixed_string_t value;
1319 };
1320
1321 static void cmd_operate_port_parsed(void *parsed_result,
1322                                 __rte_unused struct cmdline *cl,
1323                                 __rte_unused void *data)
1324 {
1325         struct cmd_operate_port_result *res = parsed_result;
1326
1327         if (!strcmp(res->name, "start"))
1328                 start_port(RTE_PORT_ALL);
1329         else if (!strcmp(res->name, "stop"))
1330                 stop_port(RTE_PORT_ALL);
1331         else if (!strcmp(res->name, "close"))
1332                 close_port(RTE_PORT_ALL);
1333         else if (!strcmp(res->name, "reset"))
1334                 reset_port(RTE_PORT_ALL);
1335         else
1336                 printf("Unknown parameter\n");
1337 }
1338
1339 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1340         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1341                                                                 "port");
1342 cmdline_parse_token_string_t cmd_operate_port_all_port =
1343         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1344                                                 "start#stop#close#reset");
1345 cmdline_parse_token_string_t cmd_operate_port_all_all =
1346         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1347
1348 cmdline_parse_inst_t cmd_operate_port = {
1349         .f = cmd_operate_port_parsed,
1350         .data = NULL,
1351         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1352         .tokens = {
1353                 (void *)&cmd_operate_port_all_cmd,
1354                 (void *)&cmd_operate_port_all_port,
1355                 (void *)&cmd_operate_port_all_all,
1356                 NULL,
1357         },
1358 };
1359
1360 /* *** start/stop/close specific port *** */
1361 struct cmd_operate_specific_port_result {
1362         cmdline_fixed_string_t keyword;
1363         cmdline_fixed_string_t name;
1364         uint8_t value;
1365 };
1366
1367 static void cmd_operate_specific_port_parsed(void *parsed_result,
1368                         __rte_unused struct cmdline *cl,
1369                                 __rte_unused void *data)
1370 {
1371         struct cmd_operate_specific_port_result *res = parsed_result;
1372
1373         if (!strcmp(res->name, "start"))
1374                 start_port(res->value);
1375         else if (!strcmp(res->name, "stop"))
1376                 stop_port(res->value);
1377         else if (!strcmp(res->name, "close"))
1378                 close_port(res->value);
1379         else if (!strcmp(res->name, "reset"))
1380                 reset_port(res->value);
1381         else
1382                 printf("Unknown parameter\n");
1383 }
1384
1385 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1386         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1387                                                         keyword, "port");
1388 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1389         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1390                                                 name, "start#stop#close#reset");
1391 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1392         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1393                                                         value, UINT8);
1394
1395 cmdline_parse_inst_t cmd_operate_specific_port = {
1396         .f = cmd_operate_specific_port_parsed,
1397         .data = NULL,
1398         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1399         .tokens = {
1400                 (void *)&cmd_operate_specific_port_cmd,
1401                 (void *)&cmd_operate_specific_port_port,
1402                 (void *)&cmd_operate_specific_port_id,
1403                 NULL,
1404         },
1405 };
1406
1407 /* *** enable port setup (after attach) via iterator or event *** */
1408 struct cmd_set_port_setup_on_result {
1409         cmdline_fixed_string_t set;
1410         cmdline_fixed_string_t port;
1411         cmdline_fixed_string_t setup;
1412         cmdline_fixed_string_t on;
1413         cmdline_fixed_string_t mode;
1414 };
1415
1416 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1417                                 __rte_unused struct cmdline *cl,
1418                                 __rte_unused void *data)
1419 {
1420         struct cmd_set_port_setup_on_result *res = parsed_result;
1421
1422         if (strcmp(res->mode, "event") == 0)
1423                 setup_on_probe_event = true;
1424         else if (strcmp(res->mode, "iterator") == 0)
1425                 setup_on_probe_event = false;
1426         else
1427                 printf("Unknown mode\n");
1428 }
1429
1430 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1431         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1432                         set, "set");
1433 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1434         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1435                         port, "port");
1436 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1437         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1438                         setup, "setup");
1439 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1440         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1441                         on, "on");
1442 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1443         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1444                         mode, "iterator#event");
1445
1446 cmdline_parse_inst_t cmd_set_port_setup_on = {
1447         .f = cmd_set_port_setup_on_parsed,
1448         .data = NULL,
1449         .help_str = "set port setup on iterator|event",
1450         .tokens = {
1451                 (void *)&cmd_set_port_setup_on_set,
1452                 (void *)&cmd_set_port_setup_on_port,
1453                 (void *)&cmd_set_port_setup_on_setup,
1454                 (void *)&cmd_set_port_setup_on_on,
1455                 (void *)&cmd_set_port_setup_on_mode,
1456                 NULL,
1457         },
1458 };
1459
1460 /* *** attach a specified port *** */
1461 struct cmd_operate_attach_port_result {
1462         cmdline_fixed_string_t port;
1463         cmdline_fixed_string_t keyword;
1464         cmdline_multi_string_t identifier;
1465 };
1466
1467 static void cmd_operate_attach_port_parsed(void *parsed_result,
1468                                 __rte_unused struct cmdline *cl,
1469                                 __rte_unused void *data)
1470 {
1471         struct cmd_operate_attach_port_result *res = parsed_result;
1472
1473         if (!strcmp(res->keyword, "attach"))
1474                 attach_port(res->identifier);
1475         else
1476                 printf("Unknown parameter\n");
1477 }
1478
1479 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1480         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1481                         port, "port");
1482 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1483         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1484                         keyword, "attach");
1485 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1486         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1487                         identifier, TOKEN_STRING_MULTI);
1488
1489 cmdline_parse_inst_t cmd_operate_attach_port = {
1490         .f = cmd_operate_attach_port_parsed,
1491         .data = NULL,
1492         .help_str = "port attach <identifier>: "
1493                 "(identifier: pci address or virtual dev name)",
1494         .tokens = {
1495                 (void *)&cmd_operate_attach_port_port,
1496                 (void *)&cmd_operate_attach_port_keyword,
1497                 (void *)&cmd_operate_attach_port_identifier,
1498                 NULL,
1499         },
1500 };
1501
1502 /* *** detach a specified port *** */
1503 struct cmd_operate_detach_port_result {
1504         cmdline_fixed_string_t port;
1505         cmdline_fixed_string_t keyword;
1506         portid_t port_id;
1507 };
1508
1509 static void cmd_operate_detach_port_parsed(void *parsed_result,
1510                                 __rte_unused struct cmdline *cl,
1511                                 __rte_unused void *data)
1512 {
1513         struct cmd_operate_detach_port_result *res = parsed_result;
1514
1515         if (!strcmp(res->keyword, "detach")) {
1516                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1517                 detach_port_device(res->port_id);
1518         } else {
1519                 printf("Unknown parameter\n");
1520         }
1521 }
1522
1523 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1524         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1525                         port, "port");
1526 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1527         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1528                         keyword, "detach");
1529 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1530         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1531                         port_id, UINT16);
1532
1533 cmdline_parse_inst_t cmd_operate_detach_port = {
1534         .f = cmd_operate_detach_port_parsed,
1535         .data = NULL,
1536         .help_str = "port detach <port_id>",
1537         .tokens = {
1538                 (void *)&cmd_operate_detach_port_port,
1539                 (void *)&cmd_operate_detach_port_keyword,
1540                 (void *)&cmd_operate_detach_port_port_id,
1541                 NULL,
1542         },
1543 };
1544
1545 /* *** detach device by identifier *** */
1546 struct cmd_operate_detach_device_result {
1547         cmdline_fixed_string_t device;
1548         cmdline_fixed_string_t keyword;
1549         cmdline_fixed_string_t identifier;
1550 };
1551
1552 static void cmd_operate_detach_device_parsed(void *parsed_result,
1553                                 __rte_unused struct cmdline *cl,
1554                                 __rte_unused void *data)
1555 {
1556         struct cmd_operate_detach_device_result *res = parsed_result;
1557
1558         if (!strcmp(res->keyword, "detach"))
1559                 detach_devargs(res->identifier);
1560         else
1561                 printf("Unknown parameter\n");
1562 }
1563
1564 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1565         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1566                         device, "device");
1567 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1568         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1569                         keyword, "detach");
1570 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1571         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1572                         identifier, NULL);
1573
1574 cmdline_parse_inst_t cmd_operate_detach_device = {
1575         .f = cmd_operate_detach_device_parsed,
1576         .data = NULL,
1577         .help_str = "device detach <identifier>:"
1578                 "(identifier: pci address or virtual dev name)",
1579         .tokens = {
1580                 (void *)&cmd_operate_detach_device_device,
1581                 (void *)&cmd_operate_detach_device_keyword,
1582                 (void *)&cmd_operate_detach_device_identifier,
1583                 NULL,
1584         },
1585 };
1586 /* *** configure speed for all ports *** */
1587 struct cmd_config_speed_all {
1588         cmdline_fixed_string_t port;
1589         cmdline_fixed_string_t keyword;
1590         cmdline_fixed_string_t all;
1591         cmdline_fixed_string_t item1;
1592         cmdline_fixed_string_t item2;
1593         cmdline_fixed_string_t value1;
1594         cmdline_fixed_string_t value2;
1595 };
1596
1597 static int
1598 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1599 {
1600
1601         int duplex;
1602
1603         if (!strcmp(duplexstr, "half")) {
1604                 duplex = ETH_LINK_HALF_DUPLEX;
1605         } else if (!strcmp(duplexstr, "full")) {
1606                 duplex = ETH_LINK_FULL_DUPLEX;
1607         } else if (!strcmp(duplexstr, "auto")) {
1608                 duplex = ETH_LINK_FULL_DUPLEX;
1609         } else {
1610                 printf("Unknown duplex parameter\n");
1611                 return -1;
1612         }
1613
1614         if (!strcmp(speedstr, "10")) {
1615                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1616                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1617         } else if (!strcmp(speedstr, "100")) {
1618                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1619                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1620         } else {
1621                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1622                         printf("Invalid speed/duplex parameters\n");
1623                         return -1;
1624                 }
1625                 if (!strcmp(speedstr, "1000")) {
1626                         *speed = ETH_LINK_SPEED_1G;
1627                 } else if (!strcmp(speedstr, "10000")) {
1628                         *speed = ETH_LINK_SPEED_10G;
1629                 } else if (!strcmp(speedstr, "25000")) {
1630                         *speed = ETH_LINK_SPEED_25G;
1631                 } else if (!strcmp(speedstr, "40000")) {
1632                         *speed = ETH_LINK_SPEED_40G;
1633                 } else if (!strcmp(speedstr, "50000")) {
1634                         *speed = ETH_LINK_SPEED_50G;
1635                 } else if (!strcmp(speedstr, "100000")) {
1636                         *speed = ETH_LINK_SPEED_100G;
1637                 } else if (!strcmp(speedstr, "200000")) {
1638                         *speed = ETH_LINK_SPEED_200G;
1639                 } else if (!strcmp(speedstr, "auto")) {
1640                         *speed = ETH_LINK_SPEED_AUTONEG;
1641                 } else {
1642                         printf("Unknown speed parameter\n");
1643                         return -1;
1644                 }
1645         }
1646
1647         return 0;
1648 }
1649
1650 static void
1651 cmd_config_speed_all_parsed(void *parsed_result,
1652                         __rte_unused struct cmdline *cl,
1653                         __rte_unused void *data)
1654 {
1655         struct cmd_config_speed_all *res = parsed_result;
1656         uint32_t link_speed;
1657         portid_t pid;
1658
1659         if (!all_ports_stopped()) {
1660                 printf("Please stop all ports first\n");
1661                 return;
1662         }
1663
1664         if (parse_and_check_speed_duplex(res->value1, res->value2,
1665                         &link_speed) < 0)
1666                 return;
1667
1668         RTE_ETH_FOREACH_DEV(pid) {
1669                 ports[pid].dev_conf.link_speeds = link_speed;
1670         }
1671
1672         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1673 }
1674
1675 cmdline_parse_token_string_t cmd_config_speed_all_port =
1676         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1677 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1678         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1679                                                         "config");
1680 cmdline_parse_token_string_t cmd_config_speed_all_all =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1682 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1683         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1684 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1685         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1686                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1687 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1688         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1689 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1690         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1691                                                 "half#full#auto");
1692
1693 cmdline_parse_inst_t cmd_config_speed_all = {
1694         .f = cmd_config_speed_all_parsed,
1695         .data = NULL,
1696         .help_str = "port config all speed "
1697                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1698                                                         "half|full|auto",
1699         .tokens = {
1700                 (void *)&cmd_config_speed_all_port,
1701                 (void *)&cmd_config_speed_all_keyword,
1702                 (void *)&cmd_config_speed_all_all,
1703                 (void *)&cmd_config_speed_all_item1,
1704                 (void *)&cmd_config_speed_all_value1,
1705                 (void *)&cmd_config_speed_all_item2,
1706                 (void *)&cmd_config_speed_all_value2,
1707                 NULL,
1708         },
1709 };
1710
1711 /* *** configure speed for specific port *** */
1712 struct cmd_config_speed_specific {
1713         cmdline_fixed_string_t port;
1714         cmdline_fixed_string_t keyword;
1715         portid_t id;
1716         cmdline_fixed_string_t item1;
1717         cmdline_fixed_string_t item2;
1718         cmdline_fixed_string_t value1;
1719         cmdline_fixed_string_t value2;
1720 };
1721
1722 static void
1723 cmd_config_speed_specific_parsed(void *parsed_result,
1724                                 __rte_unused struct cmdline *cl,
1725                                 __rte_unused void *data)
1726 {
1727         struct cmd_config_speed_specific *res = parsed_result;
1728         uint32_t link_speed;
1729
1730         if (!all_ports_stopped()) {
1731                 printf("Please stop all ports first\n");
1732                 return;
1733         }
1734
1735         if (port_id_is_invalid(res->id, ENABLED_WARN))
1736                 return;
1737
1738         if (parse_and_check_speed_duplex(res->value1, res->value2,
1739                         &link_speed) < 0)
1740                 return;
1741
1742         ports[res->id].dev_conf.link_speeds = link_speed;
1743
1744         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1745 }
1746
1747
1748 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1749         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1750                                                                 "port");
1751 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1752         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1753                                                                 "config");
1754 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1755         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1756 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1757         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1758                                                                 "speed");
1759 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1760         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1761                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1762 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1763         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1764                                                                 "duplex");
1765 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1766         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1767                                                         "half#full#auto");
1768
1769 cmdline_parse_inst_t cmd_config_speed_specific = {
1770         .f = cmd_config_speed_specific_parsed,
1771         .data = NULL,
1772         .help_str = "port config <port_id> speed "
1773                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1774                                                         "half|full|auto",
1775         .tokens = {
1776                 (void *)&cmd_config_speed_specific_port,
1777                 (void *)&cmd_config_speed_specific_keyword,
1778                 (void *)&cmd_config_speed_specific_id,
1779                 (void *)&cmd_config_speed_specific_item1,
1780                 (void *)&cmd_config_speed_specific_value1,
1781                 (void *)&cmd_config_speed_specific_item2,
1782                 (void *)&cmd_config_speed_specific_value2,
1783                 NULL,
1784         },
1785 };
1786
1787 /* *** configure loopback for all ports *** */
1788 struct cmd_config_loopback_all {
1789         cmdline_fixed_string_t port;
1790         cmdline_fixed_string_t keyword;
1791         cmdline_fixed_string_t all;
1792         cmdline_fixed_string_t item;
1793         uint32_t mode;
1794 };
1795
1796 static void
1797 cmd_config_loopback_all_parsed(void *parsed_result,
1798                         __rte_unused struct cmdline *cl,
1799                         __rte_unused void *data)
1800 {
1801         struct cmd_config_loopback_all *res = parsed_result;
1802         portid_t pid;
1803
1804         if (!all_ports_stopped()) {
1805                 printf("Please stop all ports first\n");
1806                 return;
1807         }
1808
1809         RTE_ETH_FOREACH_DEV(pid) {
1810                 ports[pid].dev_conf.lpbk_mode = res->mode;
1811         }
1812
1813         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1814 }
1815
1816 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1817         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1818 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1820                                                         "config");
1821 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1822         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1823 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1824         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1825                                                         "loopback");
1826 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1827         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1828
1829 cmdline_parse_inst_t cmd_config_loopback_all = {
1830         .f = cmd_config_loopback_all_parsed,
1831         .data = NULL,
1832         .help_str = "port config all loopback <mode>",
1833         .tokens = {
1834                 (void *)&cmd_config_loopback_all_port,
1835                 (void *)&cmd_config_loopback_all_keyword,
1836                 (void *)&cmd_config_loopback_all_all,
1837                 (void *)&cmd_config_loopback_all_item,
1838                 (void *)&cmd_config_loopback_all_mode,
1839                 NULL,
1840         },
1841 };
1842
1843 /* *** configure loopback for specific port *** */
1844 struct cmd_config_loopback_specific {
1845         cmdline_fixed_string_t port;
1846         cmdline_fixed_string_t keyword;
1847         uint16_t port_id;
1848         cmdline_fixed_string_t item;
1849         uint32_t mode;
1850 };
1851
1852 static void
1853 cmd_config_loopback_specific_parsed(void *parsed_result,
1854                                 __rte_unused struct cmdline *cl,
1855                                 __rte_unused void *data)
1856 {
1857         struct cmd_config_loopback_specific *res = parsed_result;
1858
1859         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1860                 return;
1861
1862         if (!port_is_stopped(res->port_id)) {
1863                 printf("Please stop port %u first\n", res->port_id);
1864                 return;
1865         }
1866
1867         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1868
1869         cmd_reconfig_device_queue(res->port_id, 1, 1);
1870 }
1871
1872
1873 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1874         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1875                                                                 "port");
1876 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1878                                                                 "config");
1879 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1880         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1881                                                                 UINT16);
1882 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1883         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1884                                                                 "loopback");
1885 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1886         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1887                               UINT32);
1888
1889 cmdline_parse_inst_t cmd_config_loopback_specific = {
1890         .f = cmd_config_loopback_specific_parsed,
1891         .data = NULL,
1892         .help_str = "port config <port_id> loopback <mode>",
1893         .tokens = {
1894                 (void *)&cmd_config_loopback_specific_port,
1895                 (void *)&cmd_config_loopback_specific_keyword,
1896                 (void *)&cmd_config_loopback_specific_id,
1897                 (void *)&cmd_config_loopback_specific_item,
1898                 (void *)&cmd_config_loopback_specific_mode,
1899                 NULL,
1900         },
1901 };
1902
1903 /* *** configure txq/rxq, txd/rxd *** */
1904 struct cmd_config_rx_tx {
1905         cmdline_fixed_string_t port;
1906         cmdline_fixed_string_t keyword;
1907         cmdline_fixed_string_t all;
1908         cmdline_fixed_string_t name;
1909         uint16_t value;
1910 };
1911
1912 static void
1913 cmd_config_rx_tx_parsed(void *parsed_result,
1914                         __rte_unused struct cmdline *cl,
1915                         __rte_unused void *data)
1916 {
1917         struct cmd_config_rx_tx *res = parsed_result;
1918
1919         if (!all_ports_stopped()) {
1920                 printf("Please stop all ports first\n");
1921                 return;
1922         }
1923         if (!strcmp(res->name, "rxq")) {
1924                 if (!res->value && !nb_txq) {
1925                         printf("Warning: Either rx or tx queues should be non zero\n");
1926                         return;
1927                 }
1928                 if (check_nb_rxq(res->value) != 0)
1929                         return;
1930                 nb_rxq = res->value;
1931         }
1932         else if (!strcmp(res->name, "txq")) {
1933                 if (!res->value && !nb_rxq) {
1934                         printf("Warning: Either rx or tx queues should be non zero\n");
1935                         return;
1936                 }
1937                 if (check_nb_txq(res->value) != 0)
1938                         return;
1939                 nb_txq = res->value;
1940         }
1941         else if (!strcmp(res->name, "rxd")) {
1942                 if (check_nb_rxd(res->value) != 0)
1943                         return;
1944                 nb_rxd = res->value;
1945         } else if (!strcmp(res->name, "txd")) {
1946                 if (check_nb_txd(res->value) != 0)
1947                         return;
1948
1949                 nb_txd = res->value;
1950         } else {
1951                 printf("Unknown parameter\n");
1952                 return;
1953         }
1954
1955         fwd_config_setup();
1956
1957         init_port_config();
1958
1959         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1960 }
1961
1962 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1963         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1964 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1965         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1966 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1967         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1968 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1969         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1970                                                 "rxq#txq#rxd#txd");
1971 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1972         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1973
1974 cmdline_parse_inst_t cmd_config_rx_tx = {
1975         .f = cmd_config_rx_tx_parsed,
1976         .data = NULL,
1977         .help_str = "port config all rxq|txq|rxd|txd <value>",
1978         .tokens = {
1979                 (void *)&cmd_config_rx_tx_port,
1980                 (void *)&cmd_config_rx_tx_keyword,
1981                 (void *)&cmd_config_rx_tx_all,
1982                 (void *)&cmd_config_rx_tx_name,
1983                 (void *)&cmd_config_rx_tx_value,
1984                 NULL,
1985         },
1986 };
1987
1988 /* *** config max packet length *** */
1989 struct cmd_config_max_pkt_len_result {
1990         cmdline_fixed_string_t port;
1991         cmdline_fixed_string_t keyword;
1992         cmdline_fixed_string_t all;
1993         cmdline_fixed_string_t name;
1994         uint32_t value;
1995 };
1996
1997 static void
1998 cmd_config_max_pkt_len_parsed(void *parsed_result,
1999                                 __rte_unused struct cmdline *cl,
2000                                 __rte_unused void *data)
2001 {
2002         struct cmd_config_max_pkt_len_result *res = parsed_result;
2003         portid_t pid;
2004
2005         if (!all_ports_stopped()) {
2006                 printf("Please stop all ports first\n");
2007                 return;
2008         }
2009
2010         RTE_ETH_FOREACH_DEV(pid) {
2011                 struct rte_port *port = &ports[pid];
2012                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2013
2014                 if (!strcmp(res->name, "max-pkt-len")) {
2015                         if (res->value < RTE_ETHER_MIN_LEN) {
2016                                 printf("max-pkt-len can not be less than %d\n",
2017                                                 RTE_ETHER_MIN_LEN);
2018                                 return;
2019                         }
2020                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2021                                 return;
2022
2023                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2024                         if (res->value > RTE_ETHER_MAX_LEN)
2025                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2026                         else
2027                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2028                         port->dev_conf.rxmode.offloads = rx_offloads;
2029                 } else {
2030                         printf("Unknown parameter\n");
2031                         return;
2032                 }
2033         }
2034
2035         init_port_config();
2036
2037         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2038 }
2039
2040 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2041         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2042                                                                 "port");
2043 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2044         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2045                                                                 "config");
2046 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2047         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2048                                                                 "all");
2049 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2050         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2051                                                                 "max-pkt-len");
2052 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2053         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2054                                                                 UINT32);
2055
2056 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2057         .f = cmd_config_max_pkt_len_parsed,
2058         .data = NULL,
2059         .help_str = "port config all max-pkt-len <value>",
2060         .tokens = {
2061                 (void *)&cmd_config_max_pkt_len_port,
2062                 (void *)&cmd_config_max_pkt_len_keyword,
2063                 (void *)&cmd_config_max_pkt_len_all,
2064                 (void *)&cmd_config_max_pkt_len_name,
2065                 (void *)&cmd_config_max_pkt_len_value,
2066                 NULL,
2067         },
2068 };
2069
2070 /* *** config max LRO aggregated packet size *** */
2071 struct cmd_config_max_lro_pkt_size_result {
2072         cmdline_fixed_string_t port;
2073         cmdline_fixed_string_t keyword;
2074         cmdline_fixed_string_t all;
2075         cmdline_fixed_string_t name;
2076         uint32_t value;
2077 };
2078
2079 static void
2080 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2081                                 __rte_unused struct cmdline *cl,
2082                                 __rte_unused void *data)
2083 {
2084         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2085         portid_t pid;
2086
2087         if (!all_ports_stopped()) {
2088                 printf("Please stop all ports first\n");
2089                 return;
2090         }
2091
2092         RTE_ETH_FOREACH_DEV(pid) {
2093                 struct rte_port *port = &ports[pid];
2094
2095                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2096                         if (res->value ==
2097                                         port->dev_conf.rxmode.max_lro_pkt_size)
2098                                 return;
2099
2100                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2101                 } else {
2102                         printf("Unknown parameter\n");
2103                         return;
2104                 }
2105         }
2106
2107         init_port_config();
2108
2109         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2110 }
2111
2112 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2113         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2114                                  port, "port");
2115 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2116         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2117                                  keyword, "config");
2118 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2119         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2120                                  all, "all");
2121 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2122         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2123                                  name, "max-lro-pkt-size");
2124 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2125         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2126                               value, UINT32);
2127
2128 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2129         .f = cmd_config_max_lro_pkt_size_parsed,
2130         .data = NULL,
2131         .help_str = "port config all max-lro-pkt-size <value>",
2132         .tokens = {
2133                 (void *)&cmd_config_max_lro_pkt_size_port,
2134                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2135                 (void *)&cmd_config_max_lro_pkt_size_all,
2136                 (void *)&cmd_config_max_lro_pkt_size_name,
2137                 (void *)&cmd_config_max_lro_pkt_size_value,
2138                 NULL,
2139         },
2140 };
2141
2142 /* *** configure port MTU *** */
2143 struct cmd_config_mtu_result {
2144         cmdline_fixed_string_t port;
2145         cmdline_fixed_string_t keyword;
2146         cmdline_fixed_string_t mtu;
2147         portid_t port_id;
2148         uint16_t value;
2149 };
2150
2151 static void
2152 cmd_config_mtu_parsed(void *parsed_result,
2153                       __rte_unused struct cmdline *cl,
2154                       __rte_unused void *data)
2155 {
2156         struct cmd_config_mtu_result *res = parsed_result;
2157
2158         if (res->value < RTE_ETHER_MIN_LEN) {
2159                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2160                 return;
2161         }
2162         port_mtu_set(res->port_id, res->value);
2163 }
2164
2165 cmdline_parse_token_string_t cmd_config_mtu_port =
2166         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2167                                  "port");
2168 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2169         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2170                                  "config");
2171 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2172         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2173                                  "mtu");
2174 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2175         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2176 cmdline_parse_token_num_t cmd_config_mtu_value =
2177         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2178
2179 cmdline_parse_inst_t cmd_config_mtu = {
2180         .f = cmd_config_mtu_parsed,
2181         .data = NULL,
2182         .help_str = "port config mtu <port_id> <value>",
2183         .tokens = {
2184                 (void *)&cmd_config_mtu_port,
2185                 (void *)&cmd_config_mtu_keyword,
2186                 (void *)&cmd_config_mtu_mtu,
2187                 (void *)&cmd_config_mtu_port_id,
2188                 (void *)&cmd_config_mtu_value,
2189                 NULL,
2190         },
2191 };
2192
2193 /* *** configure rx mode *** */
2194 struct cmd_config_rx_mode_flag {
2195         cmdline_fixed_string_t port;
2196         cmdline_fixed_string_t keyword;
2197         cmdline_fixed_string_t all;
2198         cmdline_fixed_string_t name;
2199         cmdline_fixed_string_t value;
2200 };
2201
2202 static void
2203 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2204                                 __rte_unused struct cmdline *cl,
2205                                 __rte_unused void *data)
2206 {
2207         struct cmd_config_rx_mode_flag *res = parsed_result;
2208
2209         if (!all_ports_stopped()) {
2210                 printf("Please stop all ports first\n");
2211                 return;
2212         }
2213
2214         if (!strcmp(res->name, "drop-en")) {
2215                 if (!strcmp(res->value, "on"))
2216                         rx_drop_en = 1;
2217                 else if (!strcmp(res->value, "off"))
2218                         rx_drop_en = 0;
2219                 else {
2220                         printf("Unknown parameter\n");
2221                         return;
2222                 }
2223         } else {
2224                 printf("Unknown parameter\n");
2225                 return;
2226         }
2227
2228         init_port_config();
2229
2230         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2231 }
2232
2233 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2234         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2235 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2236         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2237                                                                 "config");
2238 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2239         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2240 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2241         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2242                                         "drop-en");
2243 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2244         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2245                                                         "on#off");
2246
2247 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2248         .f = cmd_config_rx_mode_flag_parsed,
2249         .data = NULL,
2250         .help_str = "port config all drop-en on|off",
2251         .tokens = {
2252                 (void *)&cmd_config_rx_mode_flag_port,
2253                 (void *)&cmd_config_rx_mode_flag_keyword,
2254                 (void *)&cmd_config_rx_mode_flag_all,
2255                 (void *)&cmd_config_rx_mode_flag_name,
2256                 (void *)&cmd_config_rx_mode_flag_value,
2257                 NULL,
2258         },
2259 };
2260
2261 /* *** configure rss *** */
2262 struct cmd_config_rss {
2263         cmdline_fixed_string_t port;
2264         cmdline_fixed_string_t keyword;
2265         cmdline_fixed_string_t all;
2266         cmdline_fixed_string_t name;
2267         cmdline_fixed_string_t value;
2268 };
2269
2270 static void
2271 cmd_config_rss_parsed(void *parsed_result,
2272                         __rte_unused struct cmdline *cl,
2273                         __rte_unused void *data)
2274 {
2275         struct cmd_config_rss *res = parsed_result;
2276         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2277         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2278         int use_default = 0;
2279         int all_updated = 1;
2280         int diag;
2281         uint16_t i;
2282         int ret;
2283
2284         if (!strcmp(res->value, "all"))
2285                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2286                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2287                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2288                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2289         else if (!strcmp(res->value, "eth"))
2290                 rss_conf.rss_hf = ETH_RSS_ETH;
2291         else if (!strcmp(res->value, "vlan"))
2292                 rss_conf.rss_hf = ETH_RSS_VLAN;
2293         else if (!strcmp(res->value, "ip"))
2294                 rss_conf.rss_hf = ETH_RSS_IP;
2295         else if (!strcmp(res->value, "udp"))
2296                 rss_conf.rss_hf = ETH_RSS_UDP;
2297         else if (!strcmp(res->value, "tcp"))
2298                 rss_conf.rss_hf = ETH_RSS_TCP;
2299         else if (!strcmp(res->value, "sctp"))
2300                 rss_conf.rss_hf = ETH_RSS_SCTP;
2301         else if (!strcmp(res->value, "ether"))
2302                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2303         else if (!strcmp(res->value, "port"))
2304                 rss_conf.rss_hf = ETH_RSS_PORT;
2305         else if (!strcmp(res->value, "vxlan"))
2306                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2307         else if (!strcmp(res->value, "geneve"))
2308                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2309         else if (!strcmp(res->value, "nvgre"))
2310                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2311         else if (!strcmp(res->value, "l3-pre32"))
2312                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2313         else if (!strcmp(res->value, "l3-pre40"))
2314                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2315         else if (!strcmp(res->value, "l3-pre48"))
2316                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2317         else if (!strcmp(res->value, "l3-pre56"))
2318                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2319         else if (!strcmp(res->value, "l3-pre64"))
2320                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2321         else if (!strcmp(res->value, "l3-pre96"))
2322                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2323         else if (!strcmp(res->value, "l3-src-only"))
2324                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2325         else if (!strcmp(res->value, "l3-dst-only"))
2326                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2327         else if (!strcmp(res->value, "l4-src-only"))
2328                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2329         else if (!strcmp(res->value, "l4-dst-only"))
2330                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2331         else if (!strcmp(res->value, "l2-src-only"))
2332                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2333         else if (!strcmp(res->value, "l2-dst-only"))
2334                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2335         else if (!strcmp(res->value, "l2tpv3"))
2336                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2337         else if (!strcmp(res->value, "esp"))
2338                 rss_conf.rss_hf = ETH_RSS_ESP;
2339         else if (!strcmp(res->value, "ah"))
2340                 rss_conf.rss_hf = ETH_RSS_AH;
2341         else if (!strcmp(res->value, "pfcp"))
2342                 rss_conf.rss_hf = ETH_RSS_PFCP;
2343         else if (!strcmp(res->value, "pppoe"))
2344                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2345         else if (!strcmp(res->value, "gtpu"))
2346                 rss_conf.rss_hf = ETH_RSS_GTPU;
2347         else if (!strcmp(res->value, "none"))
2348                 rss_conf.rss_hf = 0;
2349         else if (!strcmp(res->value, "default"))
2350                 use_default = 1;
2351         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2352                                                 atoi(res->value) < 64)
2353                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2354         else {
2355                 printf("Unknown parameter\n");
2356                 return;
2357         }
2358         rss_conf.rss_key = NULL;
2359         /* Update global configuration for RSS types. */
2360         RTE_ETH_FOREACH_DEV(i) {
2361                 struct rte_eth_rss_conf local_rss_conf;
2362
2363                 ret = eth_dev_info_get_print_err(i, &dev_info);
2364                 if (ret != 0)
2365                         return;
2366
2367                 if (use_default)
2368                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2369
2370                 local_rss_conf = rss_conf;
2371                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2372                         dev_info.flow_type_rss_offloads;
2373                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2374                         printf("Port %u modified RSS hash function based on hardware support,"
2375                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2376                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2377                 }
2378                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2379                 if (diag < 0) {
2380                         all_updated = 0;
2381                         printf("Configuration of RSS hash at ethernet port %d "
2382                                 "failed with error (%d): %s.\n",
2383                                 i, -diag, strerror(-diag));
2384                 }
2385         }
2386         if (all_updated && !use_default) {
2387                 rss_hf = rss_conf.rss_hf;
2388                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2389         }
2390 }
2391
2392 cmdline_parse_token_string_t cmd_config_rss_port =
2393         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2394 cmdline_parse_token_string_t cmd_config_rss_keyword =
2395         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2396 cmdline_parse_token_string_t cmd_config_rss_all =
2397         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2398 cmdline_parse_token_string_t cmd_config_rss_name =
2399         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2400 cmdline_parse_token_string_t cmd_config_rss_value =
2401         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2402
2403 cmdline_parse_inst_t cmd_config_rss = {
2404         .f = cmd_config_rss_parsed,
2405         .data = NULL,
2406         .help_str = "port config all rss "
2407                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2408                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|<flowtype_id>",
2409         .tokens = {
2410                 (void *)&cmd_config_rss_port,
2411                 (void *)&cmd_config_rss_keyword,
2412                 (void *)&cmd_config_rss_all,
2413                 (void *)&cmd_config_rss_name,
2414                 (void *)&cmd_config_rss_value,
2415                 NULL,
2416         },
2417 };
2418
2419 /* *** configure rss hash key *** */
2420 struct cmd_config_rss_hash_key {
2421         cmdline_fixed_string_t port;
2422         cmdline_fixed_string_t config;
2423         portid_t port_id;
2424         cmdline_fixed_string_t rss_hash_key;
2425         cmdline_fixed_string_t rss_type;
2426         cmdline_fixed_string_t key;
2427 };
2428
2429 static uint8_t
2430 hexa_digit_to_value(char hexa_digit)
2431 {
2432         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2433                 return (uint8_t) (hexa_digit - '0');
2434         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2435                 return (uint8_t) ((hexa_digit - 'a') + 10);
2436         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2437                 return (uint8_t) ((hexa_digit - 'A') + 10);
2438         /* Invalid hexa digit */
2439         return 0xFF;
2440 }
2441
2442 static uint8_t
2443 parse_and_check_key_hexa_digit(char *key, int idx)
2444 {
2445         uint8_t hexa_v;
2446
2447         hexa_v = hexa_digit_to_value(key[idx]);
2448         if (hexa_v == 0xFF)
2449                 printf("invalid key: character %c at position %d is not a "
2450                        "valid hexa digit\n", key[idx], idx);
2451         return hexa_v;
2452 }
2453
2454 static void
2455 cmd_config_rss_hash_key_parsed(void *parsed_result,
2456                                __rte_unused struct cmdline *cl,
2457                                __rte_unused void *data)
2458 {
2459         struct cmd_config_rss_hash_key *res = parsed_result;
2460         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2461         uint8_t xdgt0;
2462         uint8_t xdgt1;
2463         int i;
2464         struct rte_eth_dev_info dev_info;
2465         uint8_t hash_key_size;
2466         uint32_t key_len;
2467         int ret;
2468
2469         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2470         if (ret != 0)
2471                 return;
2472
2473         if (dev_info.hash_key_size > 0 &&
2474                         dev_info.hash_key_size <= sizeof(hash_key))
2475                 hash_key_size = dev_info.hash_key_size;
2476         else {
2477                 printf("dev_info did not provide a valid hash key size\n");
2478                 return;
2479         }
2480         /* Check the length of the RSS hash key */
2481         key_len = strlen(res->key);
2482         if (key_len != (hash_key_size * 2)) {
2483                 printf("key length: %d invalid - key must be a string of %d"
2484                            " hexa-decimal numbers\n",
2485                            (int) key_len, hash_key_size * 2);
2486                 return;
2487         }
2488         /* Translate RSS hash key into binary representation */
2489         for (i = 0; i < hash_key_size; i++) {
2490                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2491                 if (xdgt0 == 0xFF)
2492                         return;
2493                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2494                 if (xdgt1 == 0xFF)
2495                         return;
2496                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2497         }
2498         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2499                         hash_key_size);
2500 }
2501
2502 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2503         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2504 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2505         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2506                                  "config");
2507 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2508         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2509 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2510         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2511                                  rss_hash_key, "rss-hash-key");
2512 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2513         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2514                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2515                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2516                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2517                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2518                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2519                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2520                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2521 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2522         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2523
2524 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2525         .f = cmd_config_rss_hash_key_parsed,
2526         .data = NULL,
2527         .help_str = "port config <port_id> rss-hash-key "
2528                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2529                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2530                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2531                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2532                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2533                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2534                 "<string of hex digits (variable length, NIC dependent)>",
2535         .tokens = {
2536                 (void *)&cmd_config_rss_hash_key_port,
2537                 (void *)&cmd_config_rss_hash_key_config,
2538                 (void *)&cmd_config_rss_hash_key_port_id,
2539                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2540                 (void *)&cmd_config_rss_hash_key_rss_type,
2541                 (void *)&cmd_config_rss_hash_key_value,
2542                 NULL,
2543         },
2544 };
2545
2546 /* *** configure port rxq/txq ring size *** */
2547 struct cmd_config_rxtx_ring_size {
2548         cmdline_fixed_string_t port;
2549         cmdline_fixed_string_t config;
2550         portid_t portid;
2551         cmdline_fixed_string_t rxtxq;
2552         uint16_t qid;
2553         cmdline_fixed_string_t rsize;
2554         uint16_t size;
2555 };
2556
2557 static void
2558 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2559                                  __rte_unused struct cmdline *cl,
2560                                  __rte_unused void *data)
2561 {
2562         struct cmd_config_rxtx_ring_size *res = parsed_result;
2563         struct rte_port *port;
2564         uint8_t isrx;
2565
2566         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2567                 return;
2568
2569         if (res->portid == (portid_t)RTE_PORT_ALL) {
2570                 printf("Invalid port id\n");
2571                 return;
2572         }
2573
2574         port = &ports[res->portid];
2575
2576         if (!strcmp(res->rxtxq, "rxq"))
2577                 isrx = 1;
2578         else if (!strcmp(res->rxtxq, "txq"))
2579                 isrx = 0;
2580         else {
2581                 printf("Unknown parameter\n");
2582                 return;
2583         }
2584
2585         if (isrx && rx_queue_id_is_invalid(res->qid))
2586                 return;
2587         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2588                 return;
2589
2590         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2591                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2592                        rx_free_thresh);
2593                 return;
2594         }
2595
2596         if (isrx)
2597                 port->nb_rx_desc[res->qid] = res->size;
2598         else
2599                 port->nb_tx_desc[res->qid] = res->size;
2600
2601         cmd_reconfig_device_queue(res->portid, 0, 1);
2602 }
2603
2604 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2605         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2606                                  port, "port");
2607 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2608         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2609                                  config, "config");
2610 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2611         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2612                                  portid, UINT16);
2613 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2614         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2615                                  rxtxq, "rxq#txq");
2616 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2617         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2618                               qid, UINT16);
2619 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2620         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2621                                  rsize, "ring_size");
2622 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2623         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2624                               size, UINT16);
2625
2626 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2627         .f = cmd_config_rxtx_ring_size_parsed,
2628         .data = NULL,
2629         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2630         .tokens = {
2631                 (void *)&cmd_config_rxtx_ring_size_port,
2632                 (void *)&cmd_config_rxtx_ring_size_config,
2633                 (void *)&cmd_config_rxtx_ring_size_portid,
2634                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2635                 (void *)&cmd_config_rxtx_ring_size_qid,
2636                 (void *)&cmd_config_rxtx_ring_size_rsize,
2637                 (void *)&cmd_config_rxtx_ring_size_size,
2638                 NULL,
2639         },
2640 };
2641
2642 /* *** configure port rxq/txq start/stop *** */
2643 struct cmd_config_rxtx_queue {
2644         cmdline_fixed_string_t port;
2645         portid_t portid;
2646         cmdline_fixed_string_t rxtxq;
2647         uint16_t qid;
2648         cmdline_fixed_string_t opname;
2649 };
2650
2651 static void
2652 cmd_config_rxtx_queue_parsed(void *parsed_result,
2653                         __rte_unused struct cmdline *cl,
2654                         __rte_unused void *data)
2655 {
2656         struct cmd_config_rxtx_queue *res = parsed_result;
2657         uint8_t isrx;
2658         uint8_t isstart;
2659         int ret = 0;
2660
2661         if (test_done == 0) {
2662                 printf("Please stop forwarding first\n");
2663                 return;
2664         }
2665
2666         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2667                 return;
2668
2669         if (port_is_started(res->portid) != 1) {
2670                 printf("Please start port %u first\n", res->portid);
2671                 return;
2672         }
2673
2674         if (!strcmp(res->rxtxq, "rxq"))
2675                 isrx = 1;
2676         else if (!strcmp(res->rxtxq, "txq"))
2677                 isrx = 0;
2678         else {
2679                 printf("Unknown parameter\n");
2680                 return;
2681         }
2682
2683         if (isrx && rx_queue_id_is_invalid(res->qid))
2684                 return;
2685         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2686                 return;
2687
2688         if (!strcmp(res->opname, "start"))
2689                 isstart = 1;
2690         else if (!strcmp(res->opname, "stop"))
2691                 isstart = 0;
2692         else {
2693                 printf("Unknown parameter\n");
2694                 return;
2695         }
2696
2697         if (isstart && isrx)
2698                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2699         else if (!isstart && isrx)
2700                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2701         else if (isstart && !isrx)
2702                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2703         else
2704                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2705
2706         if (ret == -ENOTSUP)
2707                 printf("Function not supported in PMD driver\n");
2708 }
2709
2710 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2711         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2712 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2713         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2714 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2715         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2716 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2717         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2718 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2719         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2720                                                 "start#stop");
2721
2722 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2723         .f = cmd_config_rxtx_queue_parsed,
2724         .data = NULL,
2725         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2726         .tokens = {
2727                 (void *)&cmd_config_rxtx_queue_port,
2728                 (void *)&cmd_config_rxtx_queue_portid,
2729                 (void *)&cmd_config_rxtx_queue_rxtxq,
2730                 (void *)&cmd_config_rxtx_queue_qid,
2731                 (void *)&cmd_config_rxtx_queue_opname,
2732                 NULL,
2733         },
2734 };
2735
2736 /* *** configure port rxq/txq deferred start on/off *** */
2737 struct cmd_config_deferred_start_rxtx_queue {
2738         cmdline_fixed_string_t port;
2739         portid_t port_id;
2740         cmdline_fixed_string_t rxtxq;
2741         uint16_t qid;
2742         cmdline_fixed_string_t opname;
2743         cmdline_fixed_string_t state;
2744 };
2745
2746 static void
2747 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2748                         __rte_unused struct cmdline *cl,
2749                         __rte_unused void *data)
2750 {
2751         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2752         struct rte_port *port;
2753         uint8_t isrx;
2754         uint8_t ison;
2755         uint8_t needreconfig = 0;
2756
2757         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2758                 return;
2759
2760         if (port_is_started(res->port_id) != 0) {
2761                 printf("Please stop port %u first\n", res->port_id);
2762                 return;
2763         }
2764
2765         port = &ports[res->port_id];
2766
2767         isrx = !strcmp(res->rxtxq, "rxq");
2768
2769         if (isrx && rx_queue_id_is_invalid(res->qid))
2770                 return;
2771         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2772                 return;
2773
2774         ison = !strcmp(res->state, "on");
2775
2776         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2777                 port->rx_conf[res->qid].rx_deferred_start = ison;
2778                 needreconfig = 1;
2779         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2780                 port->tx_conf[res->qid].tx_deferred_start = ison;
2781                 needreconfig = 1;
2782         }
2783
2784         if (needreconfig)
2785                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2786 }
2787
2788 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2789         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2790                                                 port, "port");
2791 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2792         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2793                                                 port_id, UINT16);
2794 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2795         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2796                                                 rxtxq, "rxq#txq");
2797 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2798         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2799                                                 qid, UINT16);
2800 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2801         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2802                                                 opname, "deferred_start");
2803 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2804         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2805                                                 state, "on#off");
2806
2807 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2808         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2809         .data = NULL,
2810         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2811         .tokens = {
2812                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2813                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2814                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2815                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2816                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2817                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2818                 NULL,
2819         },
2820 };
2821
2822 /* *** configure port rxq/txq setup *** */
2823 struct cmd_setup_rxtx_queue {
2824         cmdline_fixed_string_t port;
2825         portid_t portid;
2826         cmdline_fixed_string_t rxtxq;
2827         uint16_t qid;
2828         cmdline_fixed_string_t setup;
2829 };
2830
2831 /* Common CLI fields for queue setup */
2832 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2833         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2834 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2835         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2836 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2837         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2838 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2839         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2840 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2841         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2842
2843 static void
2844 cmd_setup_rxtx_queue_parsed(
2845         void *parsed_result,
2846         __rte_unused struct cmdline *cl,
2847         __rte_unused void *data)
2848 {
2849         struct cmd_setup_rxtx_queue *res = parsed_result;
2850         struct rte_port *port;
2851         struct rte_mempool *mp;
2852         unsigned int socket_id;
2853         uint8_t isrx = 0;
2854         int ret;
2855
2856         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2857                 return;
2858
2859         if (res->portid == (portid_t)RTE_PORT_ALL) {
2860                 printf("Invalid port id\n");
2861                 return;
2862         }
2863
2864         if (!strcmp(res->rxtxq, "rxq"))
2865                 isrx = 1;
2866         else if (!strcmp(res->rxtxq, "txq"))
2867                 isrx = 0;
2868         else {
2869                 printf("Unknown parameter\n");
2870                 return;
2871         }
2872
2873         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2874                 printf("Invalid rx queue\n");
2875                 return;
2876         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2877                 printf("Invalid tx queue\n");
2878                 return;
2879         }
2880
2881         port = &ports[res->portid];
2882         if (isrx) {
2883                 socket_id = rxring_numa[res->portid];
2884                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2885                         socket_id = port->socket_id;
2886
2887                 mp = mbuf_pool_find(socket_id);
2888                 if (mp == NULL) {
2889                         printf("Failed to setup RX queue: "
2890                                 "No mempool allocation"
2891                                 " on the socket %d\n",
2892                                 rxring_numa[res->portid]);
2893                         return;
2894                 }
2895                 ret = rte_eth_rx_queue_setup(res->portid,
2896                                              res->qid,
2897                                              port->nb_rx_desc[res->qid],
2898                                              socket_id,
2899                                              &port->rx_conf[res->qid],
2900                                              mp);
2901                 if (ret)
2902                         printf("Failed to setup RX queue\n");
2903         } else {
2904                 socket_id = txring_numa[res->portid];
2905                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2906                         socket_id = port->socket_id;
2907
2908                 ret = rte_eth_tx_queue_setup(res->portid,
2909                                              res->qid,
2910                                              port->nb_tx_desc[res->qid],
2911                                              socket_id,
2912                                              &port->tx_conf[res->qid]);
2913                 if (ret)
2914                         printf("Failed to setup TX queue\n");
2915         }
2916 }
2917
2918 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2919         .f = cmd_setup_rxtx_queue_parsed,
2920         .data = NULL,
2921         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2922         .tokens = {
2923                 (void *)&cmd_setup_rxtx_queue_port,
2924                 (void *)&cmd_setup_rxtx_queue_portid,
2925                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2926                 (void *)&cmd_setup_rxtx_queue_qid,
2927                 (void *)&cmd_setup_rxtx_queue_setup,
2928                 NULL,
2929         },
2930 };
2931
2932
2933 /* *** Configure RSS RETA *** */
2934 struct cmd_config_rss_reta {
2935         cmdline_fixed_string_t port;
2936         cmdline_fixed_string_t keyword;
2937         portid_t port_id;
2938         cmdline_fixed_string_t name;
2939         cmdline_fixed_string_t list_name;
2940         cmdline_fixed_string_t list_of_items;
2941 };
2942
2943 static int
2944 parse_reta_config(const char *str,
2945                   struct rte_eth_rss_reta_entry64 *reta_conf,
2946                   uint16_t nb_entries)
2947 {
2948         int i;
2949         unsigned size;
2950         uint16_t hash_index, idx, shift;
2951         uint16_t nb_queue;
2952         char s[256];
2953         const char *p, *p0 = str;
2954         char *end;
2955         enum fieldnames {
2956                 FLD_HASH_INDEX = 0,
2957                 FLD_QUEUE,
2958                 _NUM_FLD
2959         };
2960         unsigned long int_fld[_NUM_FLD];
2961         char *str_fld[_NUM_FLD];
2962
2963         while ((p = strchr(p0,'(')) != NULL) {
2964                 ++p;
2965                 if((p0 = strchr(p,')')) == NULL)
2966                         return -1;
2967
2968                 size = p0 - p;
2969                 if(size >= sizeof(s))
2970                         return -1;
2971
2972                 snprintf(s, sizeof(s), "%.*s", size, p);
2973                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2974                         return -1;
2975                 for (i = 0; i < _NUM_FLD; i++) {
2976                         errno = 0;
2977                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2978                         if (errno != 0 || end == str_fld[i] ||
2979                                         int_fld[i] > 65535)
2980                                 return -1;
2981                 }
2982
2983                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2984                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2985
2986                 if (hash_index >= nb_entries) {
2987                         printf("Invalid RETA hash index=%d\n", hash_index);
2988                         return -1;
2989                 }
2990
2991                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2992                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2993                 reta_conf[idx].mask |= (1ULL << shift);
2994                 reta_conf[idx].reta[shift] = nb_queue;
2995         }
2996
2997         return 0;
2998 }
2999
3000 static void
3001 cmd_set_rss_reta_parsed(void *parsed_result,
3002                         __rte_unused struct cmdline *cl,
3003                         __rte_unused void *data)
3004 {
3005         int ret;
3006         struct rte_eth_dev_info dev_info;
3007         struct rte_eth_rss_reta_entry64 reta_conf[8];
3008         struct cmd_config_rss_reta *res = parsed_result;
3009
3010         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3011         if (ret != 0)
3012                 return;
3013
3014         if (dev_info.reta_size == 0) {
3015                 printf("Redirection table size is 0 which is "
3016                                         "invalid for RSS\n");
3017                 return;
3018         } else
3019                 printf("The reta size of port %d is %u\n",
3020                         res->port_id, dev_info.reta_size);
3021         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3022                 printf("Currently do not support more than %u entries of "
3023                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3024                 return;
3025         }
3026
3027         memset(reta_conf, 0, sizeof(reta_conf));
3028         if (!strcmp(res->list_name, "reta")) {
3029                 if (parse_reta_config(res->list_of_items, reta_conf,
3030                                                 dev_info.reta_size)) {
3031                         printf("Invalid RSS Redirection Table "
3032                                         "config entered\n");
3033                         return;
3034                 }
3035                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3036                                 reta_conf, dev_info.reta_size);
3037                 if (ret != 0)
3038                         printf("Bad redirection table parameter, "
3039                                         "return code = %d \n", ret);
3040         }
3041 }
3042
3043 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3044         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3045 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3046         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3047 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3048         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3049 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3050         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3051 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3052         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3053 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3054         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3055                                  NULL);
3056 cmdline_parse_inst_t cmd_config_rss_reta = {
3057         .f = cmd_set_rss_reta_parsed,
3058         .data = NULL,
3059         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3060         .tokens = {
3061                 (void *)&cmd_config_rss_reta_port,
3062                 (void *)&cmd_config_rss_reta_keyword,
3063                 (void *)&cmd_config_rss_reta_port_id,
3064                 (void *)&cmd_config_rss_reta_name,
3065                 (void *)&cmd_config_rss_reta_list_name,
3066                 (void *)&cmd_config_rss_reta_list_of_items,
3067                 NULL,
3068         },
3069 };
3070
3071 /* *** SHOW PORT RETA INFO *** */
3072 struct cmd_showport_reta {
3073         cmdline_fixed_string_t show;
3074         cmdline_fixed_string_t port;
3075         portid_t port_id;
3076         cmdline_fixed_string_t rss;
3077         cmdline_fixed_string_t reta;
3078         uint16_t size;
3079         cmdline_fixed_string_t list_of_items;
3080 };
3081
3082 static int
3083 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3084                            uint16_t nb_entries,
3085                            char *str)
3086 {
3087         uint32_t size;
3088         const char *p, *p0 = str;
3089         char s[256];
3090         char *end;
3091         char *str_fld[8];
3092         uint16_t i;
3093         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3094                         RTE_RETA_GROUP_SIZE;
3095         int ret;
3096
3097         p = strchr(p0, '(');
3098         if (p == NULL)
3099                 return -1;
3100         p++;
3101         p0 = strchr(p, ')');
3102         if (p0 == NULL)
3103                 return -1;
3104         size = p0 - p;
3105         if (size >= sizeof(s)) {
3106                 printf("The string size exceeds the internal buffer size\n");
3107                 return -1;
3108         }
3109         snprintf(s, sizeof(s), "%.*s", size, p);
3110         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3111         if (ret <= 0 || ret != num) {
3112                 printf("The bits of masks do not match the number of "
3113                                         "reta entries: %u\n", num);
3114                 return -1;
3115         }
3116         for (i = 0; i < ret; i++)
3117                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3118
3119         return 0;
3120 }
3121
3122 static void
3123 cmd_showport_reta_parsed(void *parsed_result,
3124                          __rte_unused struct cmdline *cl,
3125                          __rte_unused void *data)
3126 {
3127         struct cmd_showport_reta *res = parsed_result;
3128         struct rte_eth_rss_reta_entry64 reta_conf[8];
3129         struct rte_eth_dev_info dev_info;
3130         uint16_t max_reta_size;
3131         int ret;
3132
3133         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3134         if (ret != 0)
3135                 return;
3136
3137         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3138         if (res->size == 0 || res->size > max_reta_size) {
3139                 printf("Invalid redirection table size: %u (1-%u)\n",
3140                         res->size, max_reta_size);
3141                 return;
3142         }
3143
3144         memset(reta_conf, 0, sizeof(reta_conf));
3145         if (showport_parse_reta_config(reta_conf, res->size,
3146                                 res->list_of_items) < 0) {
3147                 printf("Invalid string: %s for reta masks\n",
3148                                         res->list_of_items);
3149                 return;
3150         }
3151         port_rss_reta_info(res->port_id, reta_conf, res->size);
3152 }
3153
3154 cmdline_parse_token_string_t cmd_showport_reta_show =
3155         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3156 cmdline_parse_token_string_t cmd_showport_reta_port =
3157         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3158 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3159         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3160 cmdline_parse_token_string_t cmd_showport_reta_rss =
3161         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3162 cmdline_parse_token_string_t cmd_showport_reta_reta =
3163         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3164 cmdline_parse_token_num_t cmd_showport_reta_size =
3165         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3166 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3167         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3168                                         list_of_items, NULL);
3169
3170 cmdline_parse_inst_t cmd_showport_reta = {
3171         .f = cmd_showport_reta_parsed,
3172         .data = NULL,
3173         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3174         .tokens = {
3175                 (void *)&cmd_showport_reta_show,
3176                 (void *)&cmd_showport_reta_port,
3177                 (void *)&cmd_showport_reta_port_id,
3178                 (void *)&cmd_showport_reta_rss,
3179                 (void *)&cmd_showport_reta_reta,
3180                 (void *)&cmd_showport_reta_size,
3181                 (void *)&cmd_showport_reta_list_of_items,
3182                 NULL,
3183         },
3184 };
3185
3186 /* *** Show RSS hash configuration *** */
3187 struct cmd_showport_rss_hash {
3188         cmdline_fixed_string_t show;
3189         cmdline_fixed_string_t port;
3190         portid_t port_id;
3191         cmdline_fixed_string_t rss_hash;
3192         cmdline_fixed_string_t rss_type;
3193         cmdline_fixed_string_t key; /* optional argument */
3194 };
3195
3196 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3197                                 __rte_unused struct cmdline *cl,
3198                                 void *show_rss_key)
3199 {
3200         struct cmd_showport_rss_hash *res = parsed_result;
3201
3202         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3203 }
3204
3205 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3206         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3207 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3208         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3209 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3210         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3211 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3212         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3213                                  "rss-hash");
3214 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3215         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3216
3217 cmdline_parse_inst_t cmd_showport_rss_hash = {
3218         .f = cmd_showport_rss_hash_parsed,
3219         .data = NULL,
3220         .help_str = "show port <port_id> rss-hash",
3221         .tokens = {
3222                 (void *)&cmd_showport_rss_hash_show,
3223                 (void *)&cmd_showport_rss_hash_port,
3224                 (void *)&cmd_showport_rss_hash_port_id,
3225                 (void *)&cmd_showport_rss_hash_rss_hash,
3226                 NULL,
3227         },
3228 };
3229
3230 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3231         .f = cmd_showport_rss_hash_parsed,
3232         .data = (void *)1,
3233         .help_str = "show port <port_id> rss-hash key",
3234         .tokens = {
3235                 (void *)&cmd_showport_rss_hash_show,
3236                 (void *)&cmd_showport_rss_hash_port,
3237                 (void *)&cmd_showport_rss_hash_port_id,
3238                 (void *)&cmd_showport_rss_hash_rss_hash,
3239                 (void *)&cmd_showport_rss_hash_rss_key,
3240                 NULL,
3241         },
3242 };
3243
3244 /* *** Configure DCB *** */
3245 struct cmd_config_dcb {
3246         cmdline_fixed_string_t port;
3247         cmdline_fixed_string_t config;
3248         portid_t port_id;
3249         cmdline_fixed_string_t dcb;
3250         cmdline_fixed_string_t vt;
3251         cmdline_fixed_string_t vt_en;
3252         uint8_t num_tcs;
3253         cmdline_fixed_string_t pfc;
3254         cmdline_fixed_string_t pfc_en;
3255 };
3256
3257 static void
3258 cmd_config_dcb_parsed(void *parsed_result,
3259                         __rte_unused struct cmdline *cl,
3260                         __rte_unused void *data)
3261 {
3262         struct cmd_config_dcb *res = parsed_result;
3263         portid_t port_id = res->port_id;
3264         struct rte_port *port;
3265         uint8_t pfc_en;
3266         int ret;
3267
3268         port = &ports[port_id];
3269         /** Check if the port is not started **/
3270         if (port->port_status != RTE_PORT_STOPPED) {
3271                 printf("Please stop port %d first\n", port_id);
3272                 return;
3273         }
3274
3275         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3276                 printf("The invalid number of traffic class,"
3277                         " only 4 or 8 allowed.\n");
3278                 return;
3279         }
3280
3281         if (nb_fwd_lcores < res->num_tcs) {
3282                 printf("nb_cores shouldn't be less than number of TCs.\n");
3283                 return;
3284         }
3285         if (!strncmp(res->pfc_en, "on", 2))
3286                 pfc_en = 1;
3287         else
3288                 pfc_en = 0;
3289
3290         /* DCB in VT mode */
3291         if (!strncmp(res->vt_en, "on", 2))
3292                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3293                                 (enum rte_eth_nb_tcs)res->num_tcs,
3294                                 pfc_en);
3295         else
3296                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3297                                 (enum rte_eth_nb_tcs)res->num_tcs,
3298                                 pfc_en);
3299
3300
3301         if (ret != 0) {
3302                 printf("Cannot initialize network ports.\n");
3303                 return;
3304         }
3305
3306         cmd_reconfig_device_queue(port_id, 1, 1);
3307 }
3308
3309 cmdline_parse_token_string_t cmd_config_dcb_port =
3310         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3311 cmdline_parse_token_string_t cmd_config_dcb_config =
3312         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3313 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3314         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3315 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3316         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3317 cmdline_parse_token_string_t cmd_config_dcb_vt =
3318         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3319 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3320         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3321 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3322         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3323 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3324         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3325 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3326         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3327
3328 cmdline_parse_inst_t cmd_config_dcb = {
3329         .f = cmd_config_dcb_parsed,
3330         .data = NULL,
3331         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3332         .tokens = {
3333                 (void *)&cmd_config_dcb_port,
3334                 (void *)&cmd_config_dcb_config,
3335                 (void *)&cmd_config_dcb_port_id,
3336                 (void *)&cmd_config_dcb_dcb,
3337                 (void *)&cmd_config_dcb_vt,
3338                 (void *)&cmd_config_dcb_vt_en,
3339                 (void *)&cmd_config_dcb_num_tcs,
3340                 (void *)&cmd_config_dcb_pfc,
3341                 (void *)&cmd_config_dcb_pfc_en,
3342                 NULL,
3343         },
3344 };
3345
3346 /* *** configure number of packets per burst *** */
3347 struct cmd_config_burst {
3348         cmdline_fixed_string_t port;
3349         cmdline_fixed_string_t keyword;
3350         cmdline_fixed_string_t all;
3351         cmdline_fixed_string_t name;
3352         uint16_t value;
3353 };
3354
3355 static void
3356 cmd_config_burst_parsed(void *parsed_result,
3357                         __rte_unused struct cmdline *cl,
3358                         __rte_unused void *data)
3359 {
3360         struct cmd_config_burst *res = parsed_result;
3361         struct rte_eth_dev_info dev_info;
3362         uint16_t rec_nb_pkts;
3363         int ret;
3364
3365         if (!all_ports_stopped()) {
3366                 printf("Please stop all ports first\n");
3367                 return;
3368         }
3369
3370         if (!strcmp(res->name, "burst")) {
3371                 if (res->value == 0) {
3372                         /* If user gives a value of zero, query the PMD for
3373                          * its recommended Rx burst size. Testpmd uses a single
3374                          * size for all ports, so assume all ports are the same
3375                          * NIC model and use the values from Port 0.
3376                          */
3377                         ret = eth_dev_info_get_print_err(0, &dev_info);
3378                         if (ret != 0)
3379                                 return;
3380
3381                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3382
3383                         if (rec_nb_pkts == 0) {
3384                                 printf("PMD does not recommend a burst size.\n"
3385                                         "User provided value must be between"
3386                                         " 1 and %d\n", MAX_PKT_BURST);
3387                                 return;
3388                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3389                                 printf("PMD recommended burst size of %d"
3390                                         " exceeds maximum value of %d\n",
3391                                         rec_nb_pkts, MAX_PKT_BURST);
3392                                 return;
3393                         }
3394                         printf("Using PMD-provided burst value of %d\n",
3395                                 rec_nb_pkts);
3396                         nb_pkt_per_burst = rec_nb_pkts;
3397                 } else if (res->value > MAX_PKT_BURST) {
3398                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3399                         return;
3400                 } else
3401                         nb_pkt_per_burst = res->value;
3402         } else {
3403                 printf("Unknown parameter\n");
3404                 return;
3405         }
3406
3407         init_port_config();
3408
3409         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3410 }
3411
3412 cmdline_parse_token_string_t cmd_config_burst_port =
3413         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3414 cmdline_parse_token_string_t cmd_config_burst_keyword =
3415         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3416 cmdline_parse_token_string_t cmd_config_burst_all =
3417         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3418 cmdline_parse_token_string_t cmd_config_burst_name =
3419         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3420 cmdline_parse_token_num_t cmd_config_burst_value =
3421         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3422
3423 cmdline_parse_inst_t cmd_config_burst = {
3424         .f = cmd_config_burst_parsed,
3425         .data = NULL,
3426         .help_str = "port config all burst <value>",
3427         .tokens = {
3428                 (void *)&cmd_config_burst_port,
3429                 (void *)&cmd_config_burst_keyword,
3430                 (void *)&cmd_config_burst_all,
3431                 (void *)&cmd_config_burst_name,
3432                 (void *)&cmd_config_burst_value,
3433                 NULL,
3434         },
3435 };
3436
3437 /* *** configure rx/tx queues *** */
3438 struct cmd_config_thresh {
3439         cmdline_fixed_string_t port;
3440         cmdline_fixed_string_t keyword;
3441         cmdline_fixed_string_t all;
3442         cmdline_fixed_string_t name;
3443         uint8_t value;
3444 };
3445
3446 static void
3447 cmd_config_thresh_parsed(void *parsed_result,
3448                         __rte_unused struct cmdline *cl,
3449                         __rte_unused void *data)
3450 {
3451         struct cmd_config_thresh *res = parsed_result;
3452
3453         if (!all_ports_stopped()) {
3454                 printf("Please stop all ports first\n");
3455                 return;
3456         }
3457
3458         if (!strcmp(res->name, "txpt"))
3459                 tx_pthresh = res->value;
3460         else if(!strcmp(res->name, "txht"))
3461                 tx_hthresh = res->value;
3462         else if(!strcmp(res->name, "txwt"))
3463                 tx_wthresh = res->value;
3464         else if(!strcmp(res->name, "rxpt"))
3465                 rx_pthresh = res->value;
3466         else if(!strcmp(res->name, "rxht"))
3467                 rx_hthresh = res->value;
3468         else if(!strcmp(res->name, "rxwt"))
3469                 rx_wthresh = res->value;
3470         else {
3471                 printf("Unknown parameter\n");
3472                 return;
3473         }
3474
3475         init_port_config();
3476
3477         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3478 }
3479
3480 cmdline_parse_token_string_t cmd_config_thresh_port =
3481         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3482 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3483         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3484 cmdline_parse_token_string_t cmd_config_thresh_all =
3485         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3486 cmdline_parse_token_string_t cmd_config_thresh_name =
3487         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3488                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3489 cmdline_parse_token_num_t cmd_config_thresh_value =
3490         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3491
3492 cmdline_parse_inst_t cmd_config_thresh = {
3493         .f = cmd_config_thresh_parsed,
3494         .data = NULL,
3495         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3496         .tokens = {
3497                 (void *)&cmd_config_thresh_port,
3498                 (void *)&cmd_config_thresh_keyword,
3499                 (void *)&cmd_config_thresh_all,
3500                 (void *)&cmd_config_thresh_name,
3501                 (void *)&cmd_config_thresh_value,
3502                 NULL,
3503         },
3504 };
3505
3506 /* *** configure free/rs threshold *** */
3507 struct cmd_config_threshold {
3508         cmdline_fixed_string_t port;
3509         cmdline_fixed_string_t keyword;
3510         cmdline_fixed_string_t all;
3511         cmdline_fixed_string_t name;
3512         uint16_t value;
3513 };
3514
3515 static void
3516 cmd_config_threshold_parsed(void *parsed_result,
3517                         __rte_unused struct cmdline *cl,
3518                         __rte_unused void *data)
3519 {
3520         struct cmd_config_threshold *res = parsed_result;
3521
3522         if (!all_ports_stopped()) {
3523                 printf("Please stop all ports first\n");
3524                 return;
3525         }
3526
3527         if (!strcmp(res->name, "txfreet"))
3528                 tx_free_thresh = res->value;
3529         else if (!strcmp(res->name, "txrst"))
3530                 tx_rs_thresh = res->value;
3531         else if (!strcmp(res->name, "rxfreet"))
3532                 rx_free_thresh = res->value;
3533         else {
3534                 printf("Unknown parameter\n");
3535                 return;
3536         }
3537
3538         init_port_config();
3539
3540         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3541 }
3542
3543 cmdline_parse_token_string_t cmd_config_threshold_port =
3544         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3545 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3546         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3547                                                                 "config");
3548 cmdline_parse_token_string_t cmd_config_threshold_all =
3549         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3550 cmdline_parse_token_string_t cmd_config_threshold_name =
3551         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3552                                                 "txfreet#txrst#rxfreet");
3553 cmdline_parse_token_num_t cmd_config_threshold_value =
3554         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3555
3556 cmdline_parse_inst_t cmd_config_threshold = {
3557         .f = cmd_config_threshold_parsed,
3558         .data = NULL,
3559         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3560         .tokens = {
3561                 (void *)&cmd_config_threshold_port,
3562                 (void *)&cmd_config_threshold_keyword,
3563                 (void *)&cmd_config_threshold_all,
3564                 (void *)&cmd_config_threshold_name,
3565                 (void *)&cmd_config_threshold_value,
3566                 NULL,
3567         },
3568 };
3569
3570 /* *** stop *** */
3571 struct cmd_stop_result {
3572         cmdline_fixed_string_t stop;
3573 };
3574
3575 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3576                             __rte_unused struct cmdline *cl,
3577                             __rte_unused void *data)
3578 {
3579         stop_packet_forwarding();
3580 }
3581
3582 cmdline_parse_token_string_t cmd_stop_stop =
3583         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3584
3585 cmdline_parse_inst_t cmd_stop = {
3586         .f = cmd_stop_parsed,
3587         .data = NULL,
3588         .help_str = "stop: Stop packet forwarding",
3589         .tokens = {
3590                 (void *)&cmd_stop_stop,
3591                 NULL,
3592         },
3593 };
3594
3595 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3596
3597 unsigned int
3598 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3599                 unsigned int *parsed_items, int check_unique_values)
3600 {
3601         unsigned int nb_item;
3602         unsigned int value;
3603         unsigned int i;
3604         unsigned int j;
3605         int value_ok;
3606         char c;
3607
3608         /*
3609          * First parse all items in the list and store their value.
3610          */
3611         value = 0;
3612         nb_item = 0;
3613         value_ok = 0;
3614         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3615                 c = str[i];
3616                 if ((c >= '0') && (c <= '9')) {
3617                         value = (unsigned int) (value * 10 + (c - '0'));
3618                         value_ok = 1;
3619                         continue;
3620                 }
3621                 if (c != ',') {
3622                         printf("character %c is not a decimal digit\n", c);
3623                         return 0;
3624                 }
3625                 if (! value_ok) {
3626                         printf("No valid value before comma\n");
3627                         return 0;
3628                 }
3629                 if (nb_item < max_items) {
3630                         parsed_items[nb_item] = value;
3631                         value_ok = 0;
3632                         value = 0;
3633                 }
3634                 nb_item++;
3635         }
3636         if (nb_item >= max_items) {
3637                 printf("Number of %s = %u > %u (maximum items)\n",
3638                        item_name, nb_item + 1, max_items);
3639                 return 0;
3640         }
3641         parsed_items[nb_item++] = value;
3642         if (! check_unique_values)
3643                 return nb_item;
3644
3645         /*
3646          * Then, check that all values in the list are differents.
3647          * No optimization here...
3648          */
3649         for (i = 0; i < nb_item; i++) {
3650                 for (j = i + 1; j < nb_item; j++) {
3651                         if (parsed_items[j] == parsed_items[i]) {
3652                                 printf("duplicated %s %u at index %u and %u\n",
3653                                        item_name, parsed_items[i], i, j);
3654                                 return 0;
3655                         }
3656                 }
3657         }
3658         return nb_item;
3659 }
3660
3661 struct cmd_set_list_result {
3662         cmdline_fixed_string_t cmd_keyword;
3663         cmdline_fixed_string_t list_name;
3664         cmdline_fixed_string_t list_of_items;
3665 };
3666
3667 static void cmd_set_list_parsed(void *parsed_result,
3668                                 __rte_unused struct cmdline *cl,
3669                                 __rte_unused void *data)
3670 {
3671         struct cmd_set_list_result *res;
3672         union {
3673                 unsigned int lcorelist[RTE_MAX_LCORE];
3674                 unsigned int portlist[RTE_MAX_ETHPORTS];
3675         } parsed_items;
3676         unsigned int nb_item;
3677
3678         if (test_done == 0) {
3679                 printf("Please stop forwarding first\n");
3680                 return;
3681         }
3682
3683         res = parsed_result;
3684         if (!strcmp(res->list_name, "corelist")) {
3685                 nb_item = parse_item_list(res->list_of_items, "core",
3686                                           RTE_MAX_LCORE,
3687                                           parsed_items.lcorelist, 1);
3688                 if (nb_item > 0) {
3689                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3690                         fwd_config_setup();
3691                 }
3692                 return;
3693         }
3694         if (!strcmp(res->list_name, "portlist")) {
3695                 nb_item = parse_item_list(res->list_of_items, "port",
3696                                           RTE_MAX_ETHPORTS,
3697                                           parsed_items.portlist, 1);
3698                 if (nb_item > 0) {
3699                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3700                         fwd_config_setup();
3701                 }
3702         }
3703 }
3704
3705 cmdline_parse_token_string_t cmd_set_list_keyword =
3706         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3707                                  "set");
3708 cmdline_parse_token_string_t cmd_set_list_name =
3709         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3710                                  "corelist#portlist");
3711 cmdline_parse_token_string_t cmd_set_list_of_items =
3712         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3713                                  NULL);
3714
3715 cmdline_parse_inst_t cmd_set_fwd_list = {
3716         .f = cmd_set_list_parsed,
3717         .data = NULL,
3718         .help_str = "set corelist|portlist <list0[,list1]*>",
3719         .tokens = {
3720                 (void *)&cmd_set_list_keyword,
3721                 (void *)&cmd_set_list_name,
3722                 (void *)&cmd_set_list_of_items,
3723                 NULL,
3724         },
3725 };
3726
3727 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3728
3729 struct cmd_setmask_result {
3730         cmdline_fixed_string_t set;
3731         cmdline_fixed_string_t mask;
3732         uint64_t hexavalue;
3733 };
3734
3735 static void cmd_set_mask_parsed(void *parsed_result,
3736                                 __rte_unused struct cmdline *cl,
3737                                 __rte_unused void *data)
3738 {
3739         struct cmd_setmask_result *res = parsed_result;
3740
3741         if (test_done == 0) {
3742                 printf("Please stop forwarding first\n");
3743                 return;
3744         }
3745         if (!strcmp(res->mask, "coremask")) {
3746                 set_fwd_lcores_mask(res->hexavalue);
3747                 fwd_config_setup();
3748         } else if (!strcmp(res->mask, "portmask")) {
3749                 set_fwd_ports_mask(res->hexavalue);
3750                 fwd_config_setup();
3751         }
3752 }
3753
3754 cmdline_parse_token_string_t cmd_setmask_set =
3755         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3756 cmdline_parse_token_string_t cmd_setmask_mask =
3757         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3758                                  "coremask#portmask");
3759 cmdline_parse_token_num_t cmd_setmask_value =
3760         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3761
3762 cmdline_parse_inst_t cmd_set_fwd_mask = {
3763         .f = cmd_set_mask_parsed,
3764         .data = NULL,
3765         .help_str = "set coremask|portmask <hexadecimal value>",
3766         .tokens = {
3767                 (void *)&cmd_setmask_set,
3768                 (void *)&cmd_setmask_mask,
3769                 (void *)&cmd_setmask_value,
3770                 NULL,
3771         },
3772 };
3773
3774 /*
3775  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3776  */
3777 struct cmd_set_result {
3778         cmdline_fixed_string_t set;
3779         cmdline_fixed_string_t what;
3780         uint16_t value;
3781 };
3782
3783 static void cmd_set_parsed(void *parsed_result,
3784                            __rte_unused struct cmdline *cl,
3785                            __rte_unused void *data)
3786 {
3787         struct cmd_set_result *res = parsed_result;
3788         if (!strcmp(res->what, "nbport")) {
3789                 set_fwd_ports_number(res->value);
3790                 fwd_config_setup();
3791         } else if (!strcmp(res->what, "nbcore")) {
3792                 set_fwd_lcores_number(res->value);
3793                 fwd_config_setup();
3794         } else if (!strcmp(res->what, "burst"))
3795                 set_nb_pkt_per_burst(res->value);
3796         else if (!strcmp(res->what, "verbose"))
3797                 set_verbose_level(res->value);
3798 }
3799
3800 cmdline_parse_token_string_t cmd_set_set =
3801         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3802 cmdline_parse_token_string_t cmd_set_what =
3803         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3804                                  "nbport#nbcore#burst#verbose");
3805 cmdline_parse_token_num_t cmd_set_value =
3806         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3807
3808 cmdline_parse_inst_t cmd_set_numbers = {
3809         .f = cmd_set_parsed,
3810         .data = NULL,
3811         .help_str = "set nbport|nbcore|burst|verbose <value>",
3812         .tokens = {
3813                 (void *)&cmd_set_set,
3814                 (void *)&cmd_set_what,
3815                 (void *)&cmd_set_value,
3816                 NULL,
3817         },
3818 };
3819
3820 /* *** SET LOG LEVEL CONFIGURATION *** */
3821
3822 struct cmd_set_log_result {
3823         cmdline_fixed_string_t set;
3824         cmdline_fixed_string_t log;
3825         cmdline_fixed_string_t type;
3826         uint32_t level;
3827 };
3828
3829 static void
3830 cmd_set_log_parsed(void *parsed_result,
3831                    __rte_unused struct cmdline *cl,
3832                    __rte_unused void *data)
3833 {
3834         struct cmd_set_log_result *res;
3835         int ret;
3836
3837         res = parsed_result;
3838         if (!strcmp(res->type, "global"))
3839                 rte_log_set_global_level(res->level);
3840         else {
3841                 ret = rte_log_set_level_regexp(res->type, res->level);
3842                 if (ret < 0)
3843                         printf("Unable to set log level\n");
3844         }
3845 }
3846
3847 cmdline_parse_token_string_t cmd_set_log_set =
3848         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3849 cmdline_parse_token_string_t cmd_set_log_log =
3850         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3851 cmdline_parse_token_string_t cmd_set_log_type =
3852         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3853 cmdline_parse_token_num_t cmd_set_log_level =
3854         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3855
3856 cmdline_parse_inst_t cmd_set_log = {
3857         .f = cmd_set_log_parsed,
3858         .data = NULL,
3859         .help_str = "set log global|<type> <level>",
3860         .tokens = {
3861                 (void *)&cmd_set_log_set,
3862                 (void *)&cmd_set_log_log,
3863                 (void *)&cmd_set_log_type,
3864                 (void *)&cmd_set_log_level,
3865                 NULL,
3866         },
3867 };
3868
3869 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3870
3871 struct cmd_set_txpkts_result {
3872         cmdline_fixed_string_t cmd_keyword;
3873         cmdline_fixed_string_t txpkts;
3874         cmdline_fixed_string_t seg_lengths;
3875 };
3876
3877 static void
3878 cmd_set_txpkts_parsed(void *parsed_result,
3879                       __rte_unused struct cmdline *cl,
3880                       __rte_unused void *data)
3881 {
3882         struct cmd_set_txpkts_result *res;
3883         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3884         unsigned int nb_segs;
3885
3886         res = parsed_result;
3887         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3888                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3889         if (nb_segs > 0)
3890                 set_tx_pkt_segments(seg_lengths, nb_segs);
3891 }
3892
3893 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3894         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3895                                  cmd_keyword, "set");
3896 cmdline_parse_token_string_t cmd_set_txpkts_name =
3897         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3898                                  txpkts, "txpkts");
3899 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3900         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3901                                  seg_lengths, NULL);
3902
3903 cmdline_parse_inst_t cmd_set_txpkts = {
3904         .f = cmd_set_txpkts_parsed,
3905         .data = NULL,
3906         .help_str = "set txpkts <len0[,len1]*>",
3907         .tokens = {
3908                 (void *)&cmd_set_txpkts_keyword,
3909                 (void *)&cmd_set_txpkts_name,
3910                 (void *)&cmd_set_txpkts_lengths,
3911                 NULL,
3912         },
3913 };
3914
3915 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3916
3917 struct cmd_set_txsplit_result {
3918         cmdline_fixed_string_t cmd_keyword;
3919         cmdline_fixed_string_t txsplit;
3920         cmdline_fixed_string_t mode;
3921 };
3922
3923 static void
3924 cmd_set_txsplit_parsed(void *parsed_result,
3925                       __rte_unused struct cmdline *cl,
3926                       __rte_unused void *data)
3927 {
3928         struct cmd_set_txsplit_result *res;
3929
3930         res = parsed_result;
3931         set_tx_pkt_split(res->mode);
3932 }
3933
3934 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3936                                  cmd_keyword, "set");
3937 cmdline_parse_token_string_t cmd_set_txsplit_name =
3938         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3939                                  txsplit, "txsplit");
3940 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3941         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3942                                  mode, NULL);
3943
3944 cmdline_parse_inst_t cmd_set_txsplit = {
3945         .f = cmd_set_txsplit_parsed,
3946         .data = NULL,
3947         .help_str = "set txsplit on|off|rand",
3948         .tokens = {
3949                 (void *)&cmd_set_txsplit_keyword,
3950                 (void *)&cmd_set_txsplit_name,
3951                 (void *)&cmd_set_txsplit_mode,
3952                 NULL,
3953         },
3954 };
3955
3956 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3957
3958 struct cmd_set_txtimes_result {
3959         cmdline_fixed_string_t cmd_keyword;
3960         cmdline_fixed_string_t txtimes;
3961         cmdline_fixed_string_t tx_times;
3962 };
3963
3964 static void
3965 cmd_set_txtimes_parsed(void *parsed_result,
3966                        __rte_unused struct cmdline *cl,
3967                        __rte_unused void *data)
3968 {
3969         struct cmd_set_txtimes_result *res;
3970         unsigned int tx_times[2] = {0, 0};
3971         unsigned int n_times;
3972
3973         res = parsed_result;
3974         n_times = parse_item_list(res->tx_times, "tx times",
3975                                   2, tx_times, 0);
3976         if (n_times == 2)
3977                 set_tx_pkt_times(tx_times);
3978 }
3979
3980 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
3981         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3982                                  cmd_keyword, "set");
3983 cmdline_parse_token_string_t cmd_set_txtimes_name =
3984         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3985                                  txtimes, "txtimes");
3986 cmdline_parse_token_string_t cmd_set_txtimes_value =
3987         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
3988                                  tx_times, NULL);
3989
3990 cmdline_parse_inst_t cmd_set_txtimes = {
3991         .f = cmd_set_txtimes_parsed,
3992         .data = NULL,
3993         .help_str = "set txtimes <inter_burst>,<intra_burst>",
3994         .tokens = {
3995                 (void *)&cmd_set_txtimes_keyword,
3996                 (void *)&cmd_set_txtimes_name,
3997                 (void *)&cmd_set_txtimes_value,
3998                 NULL,
3999         },
4000 };
4001
4002 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4003 struct cmd_rx_vlan_filter_all_result {
4004         cmdline_fixed_string_t rx_vlan;
4005         cmdline_fixed_string_t what;
4006         cmdline_fixed_string_t all;
4007         portid_t port_id;
4008 };
4009
4010 static void
4011 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4012                               __rte_unused struct cmdline *cl,
4013                               __rte_unused void *data)
4014 {
4015         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4016
4017         if (!strcmp(res->what, "add"))
4018                 rx_vlan_all_filter_set(res->port_id, 1);
4019         else
4020                 rx_vlan_all_filter_set(res->port_id, 0);
4021 }
4022
4023 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4024         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4025                                  rx_vlan, "rx_vlan");
4026 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4027         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4028                                  what, "add#rm");
4029 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4030         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4031                                  all, "all");
4032 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4033         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4034                               port_id, UINT16);
4035
4036 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4037         .f = cmd_rx_vlan_filter_all_parsed,
4038         .data = NULL,
4039         .help_str = "rx_vlan add|rm all <port_id>: "
4040                 "Add/Remove all identifiers to/from the set of VLAN "
4041                 "identifiers filtered by a port",
4042         .tokens = {
4043                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4044                 (void *)&cmd_rx_vlan_filter_all_what,
4045                 (void *)&cmd_rx_vlan_filter_all_all,
4046                 (void *)&cmd_rx_vlan_filter_all_portid,
4047                 NULL,
4048         },
4049 };
4050
4051 /* *** VLAN OFFLOAD SET ON A PORT *** */
4052 struct cmd_vlan_offload_result {
4053         cmdline_fixed_string_t vlan;
4054         cmdline_fixed_string_t set;
4055         cmdline_fixed_string_t vlan_type;
4056         cmdline_fixed_string_t what;
4057         cmdline_fixed_string_t on;
4058         cmdline_fixed_string_t port_id;
4059 };
4060
4061 static void
4062 cmd_vlan_offload_parsed(void *parsed_result,
4063                           __rte_unused struct cmdline *cl,
4064                           __rte_unused void *data)
4065 {
4066         int on;
4067         struct cmd_vlan_offload_result *res = parsed_result;
4068         char *str;
4069         int i, len = 0;
4070         portid_t port_id = 0;
4071         unsigned int tmp;
4072
4073         str = res->port_id;
4074         len = strnlen(str, STR_TOKEN_SIZE);
4075         i = 0;
4076         /* Get port_id first */
4077         while(i < len){
4078                 if(str[i] == ',')
4079                         break;
4080
4081                 i++;
4082         }
4083         str[i]='\0';
4084         tmp = strtoul(str, NULL, 0);
4085         /* If port_id greater that what portid_t can represent, return */
4086         if(tmp >= RTE_MAX_ETHPORTS)
4087                 return;
4088         port_id = (portid_t)tmp;
4089
4090         if (!strcmp(res->on, "on"))
4091                 on = 1;
4092         else
4093                 on = 0;
4094
4095         if (!strcmp(res->what, "strip"))
4096                 rx_vlan_strip_set(port_id,  on);
4097         else if(!strcmp(res->what, "stripq")){
4098                 uint16_t queue_id = 0;
4099
4100                 /* No queue_id, return */
4101                 if(i + 1 >= len) {
4102                         printf("must specify (port,queue_id)\n");
4103                         return;
4104                 }
4105                 tmp = strtoul(str + i + 1, NULL, 0);
4106                 /* If queue_id greater that what 16-bits can represent, return */
4107                 if(tmp > 0xffff)
4108                         return;
4109
4110                 queue_id = (uint16_t)tmp;
4111                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4112         }
4113         else if (!strcmp(res->what, "filter"))
4114                 rx_vlan_filter_set(port_id, on);
4115         else if (!strcmp(res->what, "qinq_strip"))
4116                 rx_vlan_qinq_strip_set(port_id, on);
4117         else
4118                 vlan_extend_set(port_id, on);
4119
4120         return;
4121 }
4122
4123 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4124         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4125                                  vlan, "vlan");
4126 cmdline_parse_token_string_t cmd_vlan_offload_set =
4127         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4128                                  set, "set");
4129 cmdline_parse_token_string_t cmd_vlan_offload_what =
4130         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4131                                 what, "strip#filter#qinq_strip#extend#stripq");
4132 cmdline_parse_token_string_t cmd_vlan_offload_on =
4133         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4134                               on, "on#off");
4135 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4136         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4137                               port_id, NULL);
4138
4139 cmdline_parse_inst_t cmd_vlan_offload = {
4140         .f = cmd_vlan_offload_parsed,
4141         .data = NULL,
4142         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4143                 "<port_id[,queue_id]>: "
4144                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4145         .tokens = {
4146                 (void *)&cmd_vlan_offload_vlan,
4147                 (void *)&cmd_vlan_offload_set,
4148                 (void *)&cmd_vlan_offload_what,
4149                 (void *)&cmd_vlan_offload_on,
4150                 (void *)&cmd_vlan_offload_portid,
4151                 NULL,
4152         },
4153 };
4154
4155 /* *** VLAN TPID SET ON A PORT *** */
4156 struct cmd_vlan_tpid_result {
4157         cmdline_fixed_string_t vlan;
4158         cmdline_fixed_string_t set;
4159         cmdline_fixed_string_t vlan_type;
4160         cmdline_fixed_string_t what;
4161         uint16_t tp_id;
4162         portid_t port_id;
4163 };
4164
4165 static void
4166 cmd_vlan_tpid_parsed(void *parsed_result,
4167                           __rte_unused struct cmdline *cl,
4168                           __rte_unused void *data)
4169 {
4170         struct cmd_vlan_tpid_result *res = parsed_result;
4171         enum rte_vlan_type vlan_type;
4172
4173         if (!strcmp(res->vlan_type, "inner"))
4174                 vlan_type = ETH_VLAN_TYPE_INNER;
4175         else if (!strcmp(res->vlan_type, "outer"))
4176                 vlan_type = ETH_VLAN_TYPE_OUTER;
4177         else {
4178                 printf("Unknown vlan type\n");
4179                 return;
4180         }
4181         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4182 }
4183
4184 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4185         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4186                                  vlan, "vlan");
4187 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4188         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4189                                  set, "set");
4190 cmdline_parse_token_string_t cmd_vlan_type =
4191         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4192                                  vlan_type, "inner#outer");
4193 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4194         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4195                                  what, "tpid");
4196 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4197         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4198                               tp_id, UINT16);
4199 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4200         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4201                               port_id, UINT16);
4202
4203 cmdline_parse_inst_t cmd_vlan_tpid = {
4204         .f = cmd_vlan_tpid_parsed,
4205         .data = NULL,
4206         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4207                 "Set the VLAN Ether type",
4208         .tokens = {
4209                 (void *)&cmd_vlan_tpid_vlan,
4210                 (void *)&cmd_vlan_tpid_set,
4211                 (void *)&cmd_vlan_type,
4212                 (void *)&cmd_vlan_tpid_what,
4213                 (void *)&cmd_vlan_tpid_tpid,
4214                 (void *)&cmd_vlan_tpid_portid,
4215                 NULL,
4216         },
4217 };
4218
4219 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4220 struct cmd_rx_vlan_filter_result {
4221         cmdline_fixed_string_t rx_vlan;
4222         cmdline_fixed_string_t what;
4223         uint16_t vlan_id;
4224         portid_t port_id;
4225 };
4226
4227 static void
4228 cmd_rx_vlan_filter_parsed(void *parsed_result,
4229                           __rte_unused struct cmdline *cl,
4230                           __rte_unused void *data)
4231 {
4232         struct cmd_rx_vlan_filter_result *res = parsed_result;
4233
4234         if (!strcmp(res->what, "add"))
4235                 rx_vft_set(res->port_id, res->vlan_id, 1);
4236         else
4237                 rx_vft_set(res->port_id, res->vlan_id, 0);
4238 }
4239
4240 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4241         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4242                                  rx_vlan, "rx_vlan");
4243 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4244         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4245                                  what, "add#rm");
4246 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4247         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4248                               vlan_id, UINT16);
4249 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4250         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4251                               port_id, UINT16);
4252
4253 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4254         .f = cmd_rx_vlan_filter_parsed,
4255         .data = NULL,
4256         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4257                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4258                 "identifiers filtered by a port",
4259         .tokens = {
4260                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4261                 (void *)&cmd_rx_vlan_filter_what,
4262                 (void *)&cmd_rx_vlan_filter_vlanid,
4263                 (void *)&cmd_rx_vlan_filter_portid,
4264                 NULL,
4265         },
4266 };
4267
4268 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4269 struct cmd_tx_vlan_set_result {
4270         cmdline_fixed_string_t tx_vlan;
4271         cmdline_fixed_string_t set;
4272         portid_t port_id;
4273         uint16_t vlan_id;
4274 };
4275
4276 static void
4277 cmd_tx_vlan_set_parsed(void *parsed_result,
4278                        __rte_unused struct cmdline *cl,
4279                        __rte_unused void *data)
4280 {
4281         struct cmd_tx_vlan_set_result *res = parsed_result;
4282
4283         if (!port_is_stopped(res->port_id)) {
4284                 printf("Please stop port %d first\n", res->port_id);
4285                 return;
4286         }
4287
4288         tx_vlan_set(res->port_id, res->vlan_id);
4289
4290         cmd_reconfig_device_queue(res->port_id, 1, 1);
4291 }
4292
4293 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4294         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4295                                  tx_vlan, "tx_vlan");
4296 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4297         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4298                                  set, "set");
4299 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4300         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4301                               port_id, UINT16);
4302 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4303         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4304                               vlan_id, UINT16);
4305
4306 cmdline_parse_inst_t cmd_tx_vlan_set = {
4307         .f = cmd_tx_vlan_set_parsed,
4308         .data = NULL,
4309         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4310                 "Enable hardware insertion of a single VLAN header "
4311                 "with a given TAG Identifier in packets sent on a port",
4312         .tokens = {
4313                 (void *)&cmd_tx_vlan_set_tx_vlan,
4314                 (void *)&cmd_tx_vlan_set_set,
4315                 (void *)&cmd_tx_vlan_set_portid,
4316                 (void *)&cmd_tx_vlan_set_vlanid,
4317                 NULL,
4318         },
4319 };
4320
4321 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4322 struct cmd_tx_vlan_set_qinq_result {
4323         cmdline_fixed_string_t tx_vlan;
4324         cmdline_fixed_string_t set;
4325         portid_t port_id;
4326         uint16_t vlan_id;
4327         uint16_t vlan_id_outer;
4328 };
4329
4330 static void
4331 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4332                             __rte_unused struct cmdline *cl,
4333                             __rte_unused void *data)
4334 {
4335         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4336
4337         if (!port_is_stopped(res->port_id)) {
4338                 printf("Please stop port %d first\n", res->port_id);
4339                 return;
4340         }
4341
4342         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4343
4344         cmd_reconfig_device_queue(res->port_id, 1, 1);
4345 }
4346
4347 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4348         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4349                 tx_vlan, "tx_vlan");
4350 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4351         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4352                 set, "set");
4353 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4354         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4355                 port_id, UINT16);
4356 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4357         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4358                 vlan_id, UINT16);
4359 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4360         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4361                 vlan_id_outer, UINT16);
4362
4363 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4364         .f = cmd_tx_vlan_set_qinq_parsed,
4365         .data = NULL,
4366         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4367                 "Enable hardware insertion of double VLAN header "
4368                 "with given TAG Identifiers in packets sent on a port",
4369         .tokens = {
4370                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4371                 (void *)&cmd_tx_vlan_set_qinq_set,
4372                 (void *)&cmd_tx_vlan_set_qinq_portid,
4373                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4374                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4375                 NULL,
4376         },
4377 };
4378
4379 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4380 struct cmd_tx_vlan_set_pvid_result {
4381         cmdline_fixed_string_t tx_vlan;
4382         cmdline_fixed_string_t set;
4383         cmdline_fixed_string_t pvid;
4384         portid_t port_id;
4385         uint16_t vlan_id;
4386         cmdline_fixed_string_t mode;
4387 };
4388
4389 static void
4390 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4391                             __rte_unused struct cmdline *cl,
4392                             __rte_unused void *data)
4393 {
4394         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4395
4396         if (strcmp(res->mode, "on") == 0)
4397                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4398         else
4399                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4400 }
4401
4402 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4403         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4404                                  tx_vlan, "tx_vlan");
4405 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4406         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4407                                  set, "set");
4408 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4409         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4410                                  pvid, "pvid");
4411 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4412         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4413                              port_id, UINT16);
4414 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4415         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4416                               vlan_id, UINT16);
4417 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4418         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4419                                  mode, "on#off");
4420
4421 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4422         .f = cmd_tx_vlan_set_pvid_parsed,
4423         .data = NULL,
4424         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4425         .tokens = {
4426                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4427                 (void *)&cmd_tx_vlan_set_pvid_set,
4428                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4429                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4430                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4431                 (void *)&cmd_tx_vlan_set_pvid_mode,
4432                 NULL,
4433         },
4434 };
4435
4436 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4437 struct cmd_tx_vlan_reset_result {
4438         cmdline_fixed_string_t tx_vlan;
4439         cmdline_fixed_string_t reset;
4440         portid_t port_id;
4441 };
4442
4443 static void
4444 cmd_tx_vlan_reset_parsed(void *parsed_result,
4445                          __rte_unused struct cmdline *cl,
4446                          __rte_unused void *data)
4447 {
4448         struct cmd_tx_vlan_reset_result *res = parsed_result;
4449
4450         if (!port_is_stopped(res->port_id)) {
4451                 printf("Please stop port %d first\n", res->port_id);
4452                 return;
4453         }
4454
4455         tx_vlan_reset(res->port_id);
4456
4457         cmd_reconfig_device_queue(res->port_id, 1, 1);
4458 }
4459
4460 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4461         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4462                                  tx_vlan, "tx_vlan");
4463 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4464         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4465                                  reset, "reset");
4466 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4467         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4468                               port_id, UINT16);
4469
4470 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4471         .f = cmd_tx_vlan_reset_parsed,
4472         .data = NULL,
4473         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4474                 "VLAN header in packets sent on a port",
4475         .tokens = {
4476                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4477                 (void *)&cmd_tx_vlan_reset_reset,
4478                 (void *)&cmd_tx_vlan_reset_portid,
4479                 NULL,
4480         },
4481 };
4482
4483
4484 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4485 struct cmd_csum_result {
4486         cmdline_fixed_string_t csum;
4487         cmdline_fixed_string_t mode;
4488         cmdline_fixed_string_t proto;
4489         cmdline_fixed_string_t hwsw;
4490         portid_t port_id;
4491 };
4492
4493 static void
4494 csum_show(int port_id)
4495 {
4496         struct rte_eth_dev_info dev_info;
4497         uint64_t tx_offloads;
4498         int ret;
4499
4500         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4501         printf("Parse tunnel is %s\n",
4502                 (ports[port_id].parse_tunnel) ? "on" : "off");
4503         printf("IP checksum offload is %s\n",
4504                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4505         printf("UDP checksum offload is %s\n",
4506                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4507         printf("TCP checksum offload is %s\n",
4508                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4509         printf("SCTP checksum offload is %s\n",
4510                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4511         printf("Outer-Ip checksum offload is %s\n",
4512                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4513         printf("Outer-Udp checksum offload is %s\n",
4514                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4515
4516         /* display warnings if configuration is not supported by the NIC */
4517         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4518         if (ret != 0)
4519                 return;
4520
4521         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4522                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4523                 printf("Warning: hardware IP checksum enabled but not "
4524                         "supported by port %d\n", port_id);
4525         }
4526         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4527                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4528                 printf("Warning: hardware UDP checksum enabled but not "
4529                         "supported by port %d\n", port_id);
4530         }
4531         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4532                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4533                 printf("Warning: hardware TCP checksum enabled but not "
4534                         "supported by port %d\n", port_id);
4535         }
4536         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4537                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4538                 printf("Warning: hardware SCTP checksum enabled but not "
4539                         "supported by port %d\n", port_id);
4540         }
4541         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4542                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4543                 printf("Warning: hardware outer IP checksum enabled but not "
4544                         "supported by port %d\n", port_id);
4545         }
4546         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4547                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4548                         == 0) {
4549                 printf("Warning: hardware outer UDP checksum enabled but not "
4550                         "supported by port %d\n", port_id);
4551         }
4552 }
4553
4554 static void
4555 cmd_config_queue_tx_offloads(struct rte_port *port)
4556 {
4557         int k;
4558
4559         /* Apply queue tx offloads configuration */
4560         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4561                 port->tx_conf[k].offloads =
4562                         port->dev_conf.txmode.offloads;
4563 }
4564
4565 static void
4566 cmd_csum_parsed(void *parsed_result,
4567                        __rte_unused struct cmdline *cl,
4568                        __rte_unused void *data)
4569 {
4570         struct cmd_csum_result *res = parsed_result;
4571         int hw = 0;
4572         uint64_t csum_offloads = 0;
4573         struct rte_eth_dev_info dev_info;
4574         int ret;
4575
4576         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4577                 printf("invalid port %d\n", res->port_id);
4578                 return;
4579         }
4580         if (!port_is_stopped(res->port_id)) {
4581                 printf("Please stop port %d first\n", res->port_id);
4582                 return;
4583         }
4584
4585         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4586         if (ret != 0)
4587                 return;
4588
4589         if (!strcmp(res->mode, "set")) {
4590
4591                 if (!strcmp(res->hwsw, "hw"))
4592                         hw = 1;
4593
4594                 if (!strcmp(res->proto, "ip")) {
4595                         if (hw == 0 || (dev_info.tx_offload_capa &
4596                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4597                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4598                         } else {
4599                                 printf("IP checksum offload is not supported "
4600                                        "by port %u\n", res->port_id);
4601                         }
4602                 } else if (!strcmp(res->proto, "udp")) {
4603                         if (hw == 0 || (dev_info.tx_offload_capa &
4604                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4605                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4606                         } else {
4607                                 printf("UDP checksum offload is not supported "
4608                                        "by port %u\n", res->port_id);
4609                         }
4610                 } else if (!strcmp(res->proto, "tcp")) {
4611                         if (hw == 0 || (dev_info.tx_offload_capa &
4612                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4613                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4614                         } else {
4615                                 printf("TCP checksum offload is not supported "
4616                                        "by port %u\n", res->port_id);
4617                         }
4618                 } else if (!strcmp(res->proto, "sctp")) {
4619                         if (hw == 0 || (dev_info.tx_offload_capa &
4620                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4621                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4622                         } else {
4623                                 printf("SCTP checksum offload is not supported "
4624                                        "by port %u\n", res->port_id);
4625                         }
4626                 } else if (!strcmp(res->proto, "outer-ip")) {
4627                         if (hw == 0 || (dev_info.tx_offload_capa &
4628                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4629                                 csum_offloads |=
4630                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4631                         } else {
4632                                 printf("Outer IP checksum offload is not "
4633                                        "supported by port %u\n", res->port_id);
4634                         }
4635                 } else if (!strcmp(res->proto, "outer-udp")) {
4636                         if (hw == 0 || (dev_info.tx_offload_capa &
4637                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4638                                 csum_offloads |=
4639                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4640                         } else {
4641                                 printf("Outer UDP checksum offload is not "
4642                                        "supported by port %u\n", res->port_id);
4643                         }
4644                 }
4645
4646                 if (hw) {
4647                         ports[res->port_id].dev_conf.txmode.offloads |=
4648                                                         csum_offloads;
4649                 } else {
4650                         ports[res->port_id].dev_conf.txmode.offloads &=
4651                                                         (~csum_offloads);
4652                 }
4653                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4654         }
4655         csum_show(res->port_id);
4656
4657         cmd_reconfig_device_queue(res->port_id, 1, 1);
4658 }
4659
4660 cmdline_parse_token_string_t cmd_csum_csum =
4661         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4662                                 csum, "csum");
4663 cmdline_parse_token_string_t cmd_csum_mode =
4664         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4665                                 mode, "set");
4666 cmdline_parse_token_string_t cmd_csum_proto =
4667         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4668                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4669 cmdline_parse_token_string_t cmd_csum_hwsw =
4670         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4671                                 hwsw, "hw#sw");
4672 cmdline_parse_token_num_t cmd_csum_portid =
4673         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4674                                 port_id, UINT16);
4675
4676 cmdline_parse_inst_t cmd_csum_set = {
4677         .f = cmd_csum_parsed,
4678         .data = NULL,
4679         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4680                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4681                 "using csum forward engine",
4682         .tokens = {
4683                 (void *)&cmd_csum_csum,
4684                 (void *)&cmd_csum_mode,
4685                 (void *)&cmd_csum_proto,
4686                 (void *)&cmd_csum_hwsw,
4687                 (void *)&cmd_csum_portid,
4688                 NULL,
4689         },
4690 };
4691
4692 cmdline_parse_token_string_t cmd_csum_mode_show =
4693         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4694                                 mode, "show");
4695
4696 cmdline_parse_inst_t cmd_csum_show = {
4697         .f = cmd_csum_parsed,
4698         .data = NULL,
4699         .help_str = "csum show <port_id>: Show checksum offload configuration",
4700         .tokens = {
4701                 (void *)&cmd_csum_csum,
4702                 (void *)&cmd_csum_mode_show,
4703                 (void *)&cmd_csum_portid,
4704                 NULL,
4705         },
4706 };
4707
4708 /* Enable/disable tunnel parsing */
4709 struct cmd_csum_tunnel_result {
4710         cmdline_fixed_string_t csum;
4711         cmdline_fixed_string_t parse;
4712         cmdline_fixed_string_t onoff;
4713         portid_t port_id;
4714 };
4715
4716 static void
4717 cmd_csum_tunnel_parsed(void *parsed_result,
4718                        __rte_unused struct cmdline *cl,
4719                        __rte_unused void *data)
4720 {
4721         struct cmd_csum_tunnel_result *res = parsed_result;
4722
4723         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4724                 return;
4725
4726         if (!strcmp(res->onoff, "on"))
4727                 ports[res->port_id].parse_tunnel = 1;
4728         else
4729                 ports[res->port_id].parse_tunnel = 0;
4730
4731         csum_show(res->port_id);
4732 }
4733
4734 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4735         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4736                                 csum, "csum");
4737 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4738         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4739                                 parse, "parse-tunnel");
4740 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4741         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4742                                 onoff, "on#off");
4743 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4744         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4745                                 port_id, UINT16);
4746
4747 cmdline_parse_inst_t cmd_csum_tunnel = {
4748         .f = cmd_csum_tunnel_parsed,
4749         .data = NULL,
4750         .help_str = "csum parse-tunnel on|off <port_id>: "
4751                 "Enable/Disable parsing of tunnels for csum engine",
4752         .tokens = {
4753                 (void *)&cmd_csum_tunnel_csum,
4754                 (void *)&cmd_csum_tunnel_parse,
4755                 (void *)&cmd_csum_tunnel_onoff,
4756                 (void *)&cmd_csum_tunnel_portid,
4757                 NULL,
4758         },
4759 };
4760
4761 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4762 struct cmd_tso_set_result {
4763         cmdline_fixed_string_t tso;
4764         cmdline_fixed_string_t mode;
4765         uint16_t tso_segsz;
4766         portid_t port_id;
4767 };
4768
4769 static void
4770 cmd_tso_set_parsed(void *parsed_result,
4771                        __rte_unused struct cmdline *cl,
4772                        __rte_unused void *data)
4773 {
4774         struct cmd_tso_set_result *res = parsed_result;
4775         struct rte_eth_dev_info dev_info;
4776         int ret;
4777
4778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4779                 return;
4780         if (!port_is_stopped(res->port_id)) {
4781                 printf("Please stop port %d first\n", res->port_id);
4782                 return;
4783         }
4784
4785         if (!strcmp(res->mode, "set"))
4786                 ports[res->port_id].tso_segsz = res->tso_segsz;
4787
4788         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4789         if (ret != 0)
4790                 return;
4791
4792         if ((ports[res->port_id].tso_segsz != 0) &&
4793                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4794                 printf("Error: TSO is not supported by port %d\n",
4795                        res->port_id);
4796                 return;
4797         }
4798
4799         if (ports[res->port_id].tso_segsz == 0) {
4800                 ports[res->port_id].dev_conf.txmode.offloads &=
4801                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4802                 printf("TSO for non-tunneled packets is disabled\n");
4803         } else {
4804                 ports[res->port_id].dev_conf.txmode.offloads |=
4805                                                 DEV_TX_OFFLOAD_TCP_TSO;
4806                 printf("TSO segment size for non-tunneled packets is %d\n",
4807                         ports[res->port_id].tso_segsz);
4808         }
4809         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4810
4811         /* display warnings if configuration is not supported by the NIC */
4812         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4813         if (ret != 0)
4814                 return;
4815
4816         if ((ports[res->port_id].tso_segsz != 0) &&
4817                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4818                 printf("Warning: TSO enabled but not "
4819                         "supported by port %d\n", res->port_id);
4820         }
4821
4822         cmd_reconfig_device_queue(res->port_id, 1, 1);
4823 }
4824
4825 cmdline_parse_token_string_t cmd_tso_set_tso =
4826         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4827                                 tso, "tso");
4828 cmdline_parse_token_string_t cmd_tso_set_mode =
4829         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4830                                 mode, "set");
4831 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4832         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4833                                 tso_segsz, UINT16);
4834 cmdline_parse_token_num_t cmd_tso_set_portid =
4835         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4836                                 port_id, UINT16);
4837
4838 cmdline_parse_inst_t cmd_tso_set = {
4839         .f = cmd_tso_set_parsed,
4840         .data = NULL,
4841         .help_str = "tso set <tso_segsz> <port_id>: "
4842                 "Set TSO segment size of non-tunneled packets for csum engine "
4843                 "(0 to disable)",
4844         .tokens = {
4845                 (void *)&cmd_tso_set_tso,
4846                 (void *)&cmd_tso_set_mode,
4847                 (void *)&cmd_tso_set_tso_segsz,
4848                 (void *)&cmd_tso_set_portid,
4849                 NULL,
4850         },
4851 };
4852
4853 cmdline_parse_token_string_t cmd_tso_show_mode =
4854         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4855                                 mode, "show");
4856
4857
4858 cmdline_parse_inst_t cmd_tso_show = {
4859         .f = cmd_tso_set_parsed,
4860         .data = NULL,
4861         .help_str = "tso show <port_id>: "
4862                 "Show TSO segment size of non-tunneled packets for csum engine",
4863         .tokens = {
4864                 (void *)&cmd_tso_set_tso,
4865                 (void *)&cmd_tso_show_mode,
4866                 (void *)&cmd_tso_set_portid,
4867                 NULL,
4868         },
4869 };
4870
4871 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4872 struct cmd_tunnel_tso_set_result {
4873         cmdline_fixed_string_t tso;
4874         cmdline_fixed_string_t mode;
4875         uint16_t tso_segsz;
4876         portid_t port_id;
4877 };
4878
4879 static struct rte_eth_dev_info
4880 check_tunnel_tso_nic_support(portid_t port_id)
4881 {
4882         struct rte_eth_dev_info dev_info;
4883
4884         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4885                 return dev_info;
4886
4887         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4888                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4889                        "not enabled for port %d\n", port_id);
4890         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4891                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4892                        "not enabled for port %d\n", port_id);
4893         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4894                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4895                        "not enabled for port %d\n", port_id);
4896         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4897                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4898                        "not enabled for port %d\n", port_id);
4899         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4900                 printf("Warning: IP TUNNEL TSO not supported therefore "
4901                        "not enabled for port %d\n", port_id);
4902         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4903                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4904                        "not enabled for port %d\n", port_id);
4905         return dev_info;
4906 }
4907
4908 static void
4909 cmd_tunnel_tso_set_parsed(void *parsed_result,
4910                           __rte_unused struct cmdline *cl,
4911                           __rte_unused void *data)
4912 {
4913         struct cmd_tunnel_tso_set_result *res = parsed_result;
4914         struct rte_eth_dev_info dev_info;
4915
4916         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4917                 return;
4918         if (!port_is_stopped(res->port_id)) {
4919                 printf("Please stop port %d first\n", res->port_id);
4920                 return;
4921         }
4922
4923         if (!strcmp(res->mode, "set"))
4924                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4925
4926         dev_info = check_tunnel_tso_nic_support(res->port_id);
4927         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4928                 ports[res->port_id].dev_conf.txmode.offloads &=
4929                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4930                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4931                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4932                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4933                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4934                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4935                 printf("TSO for tunneled packets is disabled\n");
4936         } else {
4937                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4938                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4939                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4940                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4941                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4942                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4943
4944                 ports[res->port_id].dev_conf.txmode.offloads |=
4945                         (tso_offloads & dev_info.tx_offload_capa);
4946                 printf("TSO segment size for tunneled packets is %d\n",
4947                         ports[res->port_id].tunnel_tso_segsz);
4948
4949                 /* Below conditions are needed to make it work:
4950                  * (1) tunnel TSO is supported by the NIC;
4951                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
4952                  * are recognized;
4953                  * (3) for tunneled pkts with outer L3 of IPv4,
4954                  * "csum set outer-ip" must be set to hw, because after tso,
4955                  * total_len of outer IP header is changed, and the checksum
4956                  * of outer IP header calculated by sw should be wrong; that
4957                  * is not necessary for IPv6 tunneled pkts because there's no
4958                  * checksum in IP header anymore.
4959                  */
4960
4961                 if (!ports[res->port_id].parse_tunnel)
4962                         printf("Warning: csum parse_tunnel must be set "
4963                                 "so that tunneled packets are recognized\n");
4964                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
4965                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
4966                         printf("Warning: csum set outer-ip must be set to hw "
4967                                 "if outer L3 is IPv4; not necessary for IPv6\n");
4968         }
4969
4970         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4971         cmd_reconfig_device_queue(res->port_id, 1, 1);
4972 }
4973
4974 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
4975         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4976                                 tso, "tunnel_tso");
4977 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
4978         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4979                                 mode, "set");
4980 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
4981         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4982                                 tso_segsz, UINT16);
4983 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
4984         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
4985                                 port_id, UINT16);
4986
4987 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4988         .f = cmd_tunnel_tso_set_parsed,
4989         .data = NULL,
4990         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4991                 "Set TSO segment size of tunneled packets for csum engine "
4992                 "(0 to disable)",
4993         .tokens = {
4994                 (void *)&cmd_tunnel_tso_set_tso,
4995                 (void *)&cmd_tunnel_tso_set_mode,
4996                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4997                 (void *)&cmd_tunnel_tso_set_portid,
4998                 NULL,
4999         },
5000 };
5001
5002 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5003         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5004                                 mode, "show");
5005
5006
5007 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5008         .f = cmd_tunnel_tso_set_parsed,
5009         .data = NULL,
5010         .help_str = "tunnel_tso show <port_id> "
5011                 "Show TSO segment size of tunneled packets for csum engine",
5012         .tokens = {
5013                 (void *)&cmd_tunnel_tso_set_tso,
5014                 (void *)&cmd_tunnel_tso_show_mode,
5015                 (void *)&cmd_tunnel_tso_set_portid,
5016                 NULL,
5017         },
5018 };
5019
5020 /* *** SET GRO FOR A PORT *** */
5021 struct cmd_gro_enable_result {
5022         cmdline_fixed_string_t cmd_set;
5023         cmdline_fixed_string_t cmd_port;
5024         cmdline_fixed_string_t cmd_keyword;
5025         cmdline_fixed_string_t cmd_onoff;
5026         portid_t cmd_pid;
5027 };
5028
5029 static void
5030 cmd_gro_enable_parsed(void *parsed_result,
5031                 __rte_unused struct cmdline *cl,
5032                 __rte_unused void *data)
5033 {
5034         struct cmd_gro_enable_result *res;
5035
5036         res = parsed_result;
5037         if (!strcmp(res->cmd_keyword, "gro"))
5038                 setup_gro(res->cmd_onoff, res->cmd_pid);
5039 }
5040
5041 cmdline_parse_token_string_t cmd_gro_enable_set =
5042         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5043                         cmd_set, "set");
5044 cmdline_parse_token_string_t cmd_gro_enable_port =
5045         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5046                         cmd_keyword, "port");
5047 cmdline_parse_token_num_t cmd_gro_enable_pid =
5048         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5049                         cmd_pid, UINT16);
5050 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5051         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5052                         cmd_keyword, "gro");
5053 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5054         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5055                         cmd_onoff, "on#off");
5056
5057 cmdline_parse_inst_t cmd_gro_enable = {
5058         .f = cmd_gro_enable_parsed,
5059         .data = NULL,
5060         .help_str = "set port <port_id> gro on|off",
5061         .tokens = {
5062                 (void *)&cmd_gro_enable_set,
5063                 (void *)&cmd_gro_enable_port,
5064                 (void *)&cmd_gro_enable_pid,
5065                 (void *)&cmd_gro_enable_keyword,
5066                 (void *)&cmd_gro_enable_onoff,
5067                 NULL,
5068         },
5069 };
5070
5071 /* *** DISPLAY GRO CONFIGURATION *** */
5072 struct cmd_gro_show_result {
5073         cmdline_fixed_string_t cmd_show;
5074         cmdline_fixed_string_t cmd_port;
5075         cmdline_fixed_string_t cmd_keyword;
5076         portid_t cmd_pid;
5077 };
5078
5079 static void
5080 cmd_gro_show_parsed(void *parsed_result,
5081                 __rte_unused struct cmdline *cl,
5082                 __rte_unused void *data)
5083 {
5084         struct cmd_gro_show_result *res;
5085
5086         res = parsed_result;
5087         if (!strcmp(res->cmd_keyword, "gro"))
5088                 show_gro(res->cmd_pid);
5089 }
5090
5091 cmdline_parse_token_string_t cmd_gro_show_show =
5092         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5093                         cmd_show, "show");
5094 cmdline_parse_token_string_t cmd_gro_show_port =
5095         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5096                         cmd_port, "port");
5097 cmdline_parse_token_num_t cmd_gro_show_pid =
5098         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5099                         cmd_pid, UINT16);
5100 cmdline_parse_token_string_t cmd_gro_show_keyword =
5101         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5102                         cmd_keyword, "gro");
5103
5104 cmdline_parse_inst_t cmd_gro_show = {
5105         .f = cmd_gro_show_parsed,
5106         .data = NULL,
5107         .help_str = "show port <port_id> gro",
5108         .tokens = {
5109                 (void *)&cmd_gro_show_show,
5110                 (void *)&cmd_gro_show_port,
5111                 (void *)&cmd_gro_show_pid,
5112                 (void *)&cmd_gro_show_keyword,
5113                 NULL,
5114         },
5115 };
5116
5117 /* *** SET FLUSH CYCLES FOR GRO *** */
5118 struct cmd_gro_flush_result {
5119         cmdline_fixed_string_t cmd_set;
5120         cmdline_fixed_string_t cmd_keyword;
5121         cmdline_fixed_string_t cmd_flush;
5122         uint8_t cmd_cycles;
5123 };
5124
5125 static void
5126 cmd_gro_flush_parsed(void *parsed_result,
5127                 __rte_unused struct cmdline *cl,
5128                 __rte_unused void *data)
5129 {
5130         struct cmd_gro_flush_result *res;
5131
5132         res = parsed_result;
5133         if ((!strcmp(res->cmd_keyword, "gro")) &&
5134                         (!strcmp(res->cmd_flush, "flush")))
5135                 setup_gro_flush_cycles(res->cmd_cycles);
5136 }
5137
5138 cmdline_parse_token_string_t cmd_gro_flush_set =
5139         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5140                         cmd_set, "set");
5141 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5142         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5143                         cmd_keyword, "gro");
5144 cmdline_parse_token_string_t cmd_gro_flush_flush =
5145         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5146                         cmd_flush, "flush");
5147 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5148         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5149                         cmd_cycles, UINT8);
5150
5151 cmdline_parse_inst_t cmd_gro_flush = {
5152         .f = cmd_gro_flush_parsed,
5153         .data = NULL,
5154         .help_str = "set gro flush <cycles>",
5155         .tokens = {
5156                 (void *)&cmd_gro_flush_set,
5157                 (void *)&cmd_gro_flush_keyword,
5158                 (void *)&cmd_gro_flush_flush,
5159                 (void *)&cmd_gro_flush_cycles,
5160                 NULL,
5161         },
5162 };
5163
5164 /* *** ENABLE/DISABLE GSO *** */
5165 struct cmd_gso_enable_result {
5166         cmdline_fixed_string_t cmd_set;
5167         cmdline_fixed_string_t cmd_port;
5168         cmdline_fixed_string_t cmd_keyword;
5169         cmdline_fixed_string_t cmd_mode;
5170         portid_t cmd_pid;
5171 };
5172
5173 static void
5174 cmd_gso_enable_parsed(void *parsed_result,
5175                 __rte_unused struct cmdline *cl,
5176                 __rte_unused void *data)
5177 {
5178         struct cmd_gso_enable_result *res;
5179
5180         res = parsed_result;
5181         if (!strcmp(res->cmd_keyword, "gso"))
5182                 setup_gso(res->cmd_mode, res->cmd_pid);
5183 }
5184
5185 cmdline_parse_token_string_t cmd_gso_enable_set =
5186         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5187                         cmd_set, "set");
5188 cmdline_parse_token_string_t cmd_gso_enable_port =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5190                         cmd_port, "port");
5191 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5192         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5193                         cmd_keyword, "gso");
5194 cmdline_parse_token_string_t cmd_gso_enable_mode =
5195         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5196                         cmd_mode, "on#off");
5197 cmdline_parse_token_num_t cmd_gso_enable_pid =
5198         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5199                         cmd_pid, UINT16);
5200
5201 cmdline_parse_inst_t cmd_gso_enable = {
5202         .f = cmd_gso_enable_parsed,
5203         .data = NULL,
5204         .help_str = "set port <port_id> gso on|off",
5205         .tokens = {
5206                 (void *)&cmd_gso_enable_set,
5207                 (void *)&cmd_gso_enable_port,
5208                 (void *)&cmd_gso_enable_pid,
5209                 (void *)&cmd_gso_enable_keyword,
5210                 (void *)&cmd_gso_enable_mode,
5211                 NULL,
5212         },
5213 };
5214
5215 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5216 struct cmd_gso_size_result {
5217         cmdline_fixed_string_t cmd_set;
5218         cmdline_fixed_string_t cmd_keyword;
5219         cmdline_fixed_string_t cmd_segsz;
5220         uint16_t cmd_size;
5221 };
5222
5223 static void
5224 cmd_gso_size_parsed(void *parsed_result,
5225                        __rte_unused struct cmdline *cl,
5226                        __rte_unused void *data)
5227 {
5228         struct cmd_gso_size_result *res = parsed_result;
5229
5230         if (test_done == 0) {
5231                 printf("Before setting GSO segsz, please first"
5232                                 " stop forwarding\n");
5233                 return;
5234         }
5235
5236         if (!strcmp(res->cmd_keyword, "gso") &&
5237                         !strcmp(res->cmd_segsz, "segsz")) {
5238                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5239                         printf("gso_size should be larger than %zu."
5240                                         " Please input a legal value\n",
5241                                         RTE_GSO_SEG_SIZE_MIN);
5242                 else
5243                         gso_max_segment_size = res->cmd_size;
5244         }
5245 }
5246
5247 cmdline_parse_token_string_t cmd_gso_size_set =
5248         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5249                                 cmd_set, "set");
5250 cmdline_parse_token_string_t cmd_gso_size_keyword =
5251         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5252                                 cmd_keyword, "gso");
5253 cmdline_parse_token_string_t cmd_gso_size_segsz =
5254         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5255                                 cmd_segsz, "segsz");
5256 cmdline_parse_token_num_t cmd_gso_size_size =
5257         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5258                                 cmd_size, UINT16);
5259
5260 cmdline_parse_inst_t cmd_gso_size = {
5261         .f = cmd_gso_size_parsed,
5262         .data = NULL,
5263         .help_str = "set gso segsz <length>",
5264         .tokens = {
5265                 (void *)&cmd_gso_size_set,
5266                 (void *)&cmd_gso_size_keyword,
5267                 (void *)&cmd_gso_size_segsz,
5268                 (void *)&cmd_gso_size_size,
5269                 NULL,
5270         },
5271 };
5272
5273 /* *** SHOW GSO CONFIGURATION *** */
5274 struct cmd_gso_show_result {
5275         cmdline_fixed_string_t cmd_show;
5276         cmdline_fixed_string_t cmd_port;
5277         cmdline_fixed_string_t cmd_keyword;
5278         portid_t cmd_pid;
5279 };
5280
5281 static void
5282 cmd_gso_show_parsed(void *parsed_result,
5283                        __rte_unused struct cmdline *cl,
5284                        __rte_unused void *data)
5285 {
5286         struct cmd_gso_show_result *res = parsed_result;
5287
5288         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5289                 printf("invalid port id %u\n", res->cmd_pid);
5290                 return;
5291         }
5292         if (!strcmp(res->cmd_keyword, "gso")) {
5293                 if (gso_ports[res->cmd_pid].enable) {
5294                         printf("Max GSO'd packet size: %uB\n"
5295                                         "Supported GSO types: TCP/IPv4, "
5296                                         "UDP/IPv4, VxLAN with inner "
5297                                         "TCP/IPv4 packet, GRE with inner "
5298                                         "TCP/IPv4 packet\n",
5299                                         gso_max_segment_size);
5300                 } else
5301                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5302         }
5303 }
5304
5305 cmdline_parse_token_string_t cmd_gso_show_show =
5306 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5307                 cmd_show, "show");
5308 cmdline_parse_token_string_t cmd_gso_show_port =
5309 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5310                 cmd_port, "port");
5311 cmdline_parse_token_string_t cmd_gso_show_keyword =
5312         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5313                                 cmd_keyword, "gso");
5314 cmdline_parse_token_num_t cmd_gso_show_pid =
5315         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5316                                 cmd_pid, UINT16);
5317
5318 cmdline_parse_inst_t cmd_gso_show = {
5319         .f = cmd_gso_show_parsed,
5320         .data = NULL,
5321         .help_str = "show port <port_id> gso",
5322         .tokens = {
5323                 (void *)&cmd_gso_show_show,
5324                 (void *)&cmd_gso_show_port,
5325                 (void *)&cmd_gso_show_pid,
5326                 (void *)&cmd_gso_show_keyword,
5327                 NULL,
5328         },
5329 };
5330
5331 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5332 struct cmd_set_flush_rx {
5333         cmdline_fixed_string_t set;
5334         cmdline_fixed_string_t flush_rx;
5335         cmdline_fixed_string_t mode;
5336 };
5337
5338 static void
5339 cmd_set_flush_rx_parsed(void *parsed_result,
5340                 __rte_unused struct cmdline *cl,
5341                 __rte_unused void *data)
5342 {
5343         struct cmd_set_flush_rx *res = parsed_result;
5344         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5345 }
5346
5347 cmdline_parse_token_string_t cmd_setflushrx_set =
5348         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5349                         set, "set");
5350 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5351         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5352                         flush_rx, "flush_rx");
5353 cmdline_parse_token_string_t cmd_setflushrx_mode =
5354         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5355                         mode, "on#off");
5356
5357
5358 cmdline_parse_inst_t cmd_set_flush_rx = {
5359         .f = cmd_set_flush_rx_parsed,
5360         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5361         .data = NULL,
5362         .tokens = {
5363                 (void *)&cmd_setflushrx_set,
5364                 (void *)&cmd_setflushrx_flush_rx,
5365                 (void *)&cmd_setflushrx_mode,
5366                 NULL,
5367         },
5368 };
5369
5370 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5371 struct cmd_set_link_check {
5372         cmdline_fixed_string_t set;
5373         cmdline_fixed_string_t link_check;
5374         cmdline_fixed_string_t mode;
5375 };
5376
5377 static void
5378 cmd_set_link_check_parsed(void *parsed_result,
5379                 __rte_unused struct cmdline *cl,
5380                 __rte_unused void *data)
5381 {
5382         struct cmd_set_link_check *res = parsed_result;
5383         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5384 }
5385
5386 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5387         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5388                         set, "set");
5389 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5390         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5391                         link_check, "link_check");
5392 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5393         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5394                         mode, "on#off");
5395
5396
5397 cmdline_parse_inst_t cmd_set_link_check = {
5398         .f = cmd_set_link_check_parsed,
5399         .help_str = "set link_check on|off: Enable/Disable link status check "
5400                     "when starting/stopping a port",
5401         .data = NULL,
5402         .tokens = {
5403                 (void *)&cmd_setlinkcheck_set,
5404                 (void *)&cmd_setlinkcheck_link_check,
5405                 (void *)&cmd_setlinkcheck_mode,
5406                 NULL,
5407         },
5408 };
5409
5410 /* *** SET NIC BYPASS MODE *** */
5411 struct cmd_set_bypass_mode_result {
5412         cmdline_fixed_string_t set;
5413         cmdline_fixed_string_t bypass;
5414         cmdline_fixed_string_t mode;
5415         cmdline_fixed_string_t value;
5416         portid_t port_id;
5417 };
5418
5419 static void
5420 cmd_set_bypass_mode_parsed(void *parsed_result,
5421                 __rte_unused struct cmdline *cl,
5422                 __rte_unused void *data)
5423 {
5424         struct cmd_set_bypass_mode_result *res = parsed_result;
5425         portid_t port_id = res->port_id;
5426         int32_t rc = -EINVAL;
5427
5428 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5429         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5430
5431         if (!strcmp(res->value, "bypass"))
5432                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5433         else if (!strcmp(res->value, "isolate"))
5434                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5435         else
5436                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5437
5438         /* Set the bypass mode for the relevant port. */
5439         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5440 #endif
5441         if (rc != 0)
5442                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5443 }
5444
5445 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5447                         set, "set");
5448 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5450                         bypass, "bypass");
5451 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5452         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5453                         mode, "mode");
5454 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5455         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5456                         value, "normal#bypass#isolate");
5457 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5458         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5459                                 port_id, UINT16);
5460
5461 cmdline_parse_inst_t cmd_set_bypass_mode = {
5462         .f = cmd_set_bypass_mode_parsed,
5463         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5464                     "Set the NIC bypass mode for port_id",
5465         .data = NULL,
5466         .tokens = {
5467                 (void *)&cmd_setbypass_mode_set,
5468                 (void *)&cmd_setbypass_mode_bypass,
5469                 (void *)&cmd_setbypass_mode_mode,
5470                 (void *)&cmd_setbypass_mode_value,
5471                 (void *)&cmd_setbypass_mode_port,
5472                 NULL,
5473         },
5474 };
5475
5476 /* *** SET NIC BYPASS EVENT *** */
5477 struct cmd_set_bypass_event_result {
5478         cmdline_fixed_string_t set;
5479         cmdline_fixed_string_t bypass;
5480         cmdline_fixed_string_t event;
5481         cmdline_fixed_string_t event_value;
5482         cmdline_fixed_string_t mode;
5483         cmdline_fixed_string_t mode_value;
5484         portid_t port_id;
5485 };
5486
5487 static void
5488 cmd_set_bypass_event_parsed(void *parsed_result,
5489                 __rte_unused struct cmdline *cl,
5490                 __rte_unused void *data)
5491 {
5492         int32_t rc = -EINVAL;
5493         struct cmd_set_bypass_event_result *res = parsed_result;
5494         portid_t port_id = res->port_id;
5495
5496 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5497         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5498         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5499
5500         if (!strcmp(res->event_value, "timeout"))
5501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5502         else if (!strcmp(res->event_value, "os_on"))
5503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5504         else if (!strcmp(res->event_value, "os_off"))
5505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5506         else if (!strcmp(res->event_value, "power_on"))
5507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5508         else if (!strcmp(res->event_value, "power_off"))
5509                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5510         else
5511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5512
5513         if (!strcmp(res->mode_value, "bypass"))
5514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5515         else if (!strcmp(res->mode_value, "isolate"))
5516                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5517         else
5518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5519
5520         /* Set the watchdog timeout. */
5521         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5522
5523                 rc = -EINVAL;
5524                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5525                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5526                                                            bypass_timeout);
5527                 }
5528                 if (rc != 0) {
5529                         printf("Failed to set timeout value %u "
5530                         "for port %d, errto code: %d.\n",
5531                         bypass_timeout, port_id, rc);
5532                 }
5533         }
5534
5535         /* Set the bypass event to transition to bypass mode. */
5536         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5537                                               bypass_mode);
5538 #endif
5539
5540         if (rc != 0)
5541                 printf("\t Failed to set bypass event for port = %d.\n",
5542                        port_id);
5543 }
5544
5545 cmdline_parse_token_string_t cmd_setbypass_event_set =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5547                         set, "set");
5548 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5550                         bypass, "bypass");
5551 cmdline_parse_token_string_t cmd_setbypass_event_event =
5552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5553                         event, "event");
5554 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5556                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5557 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5559                         mode, "mode");
5560 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5561         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5562                         mode_value, "normal#bypass#isolate");
5563 cmdline_parse_token_num_t cmd_setbypass_event_port =
5564         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5565                                 port_id, UINT16);
5566
5567 cmdline_parse_inst_t cmd_set_bypass_event = {
5568         .f = cmd_set_bypass_event_parsed,
5569         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5570                 "power_off mode normal|bypass|isolate <port_id>: "
5571                 "Set the NIC bypass event mode for port_id",
5572         .data = NULL,
5573         .tokens = {
5574                 (void *)&cmd_setbypass_event_set,
5575                 (void *)&cmd_setbypass_event_bypass,
5576                 (void *)&cmd_setbypass_event_event,
5577                 (void *)&cmd_setbypass_event_event_value,
5578                 (void *)&cmd_setbypass_event_mode,
5579                 (void *)&cmd_setbypass_event_mode_value,
5580                 (void *)&cmd_setbypass_event_port,
5581                 NULL,
5582         },
5583 };
5584
5585
5586 /* *** SET NIC BYPASS TIMEOUT *** */
5587 struct cmd_set_bypass_timeout_result {
5588         cmdline_fixed_string_t set;
5589         cmdline_fixed_string_t bypass;
5590         cmdline_fixed_string_t timeout;
5591         cmdline_fixed_string_t value;
5592 };
5593
5594 static void
5595 cmd_set_bypass_timeout_parsed(void *parsed_result,
5596                 __rte_unused struct cmdline *cl,
5597                 __rte_unused void *data)
5598 {
5599         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5600
5601 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5602         if (!strcmp(res->value, "1.5"))
5603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5604         else if (!strcmp(res->value, "2"))
5605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5606         else if (!strcmp(res->value, "3"))
5607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5608         else if (!strcmp(res->value, "4"))
5609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5610         else if (!strcmp(res->value, "8"))
5611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5612         else if (!strcmp(res->value, "16"))
5613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5614         else if (!strcmp(res->value, "32"))
5615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5616         else
5617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5618 #endif
5619 }
5620
5621 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5622         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5623                         set, "set");
5624 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5626                         bypass, "bypass");
5627 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5628         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5629                         timeout, "timeout");
5630 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5631         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5632                         value, "0#1.5#2#3#4#8#16#32");
5633
5634 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5635         .f = cmd_set_bypass_timeout_parsed,
5636         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5637                 "Set the NIC bypass watchdog timeout in seconds",
5638         .data = NULL,
5639         .tokens = {
5640                 (void *)&cmd_setbypass_timeout_set,
5641                 (void *)&cmd_setbypass_timeout_bypass,
5642                 (void *)&cmd_setbypass_timeout_timeout,
5643                 (void *)&cmd_setbypass_timeout_value,
5644                 NULL,
5645         },
5646 };
5647
5648 /* *** SHOW NIC BYPASS MODE *** */
5649 struct cmd_show_bypass_config_result {
5650         cmdline_fixed_string_t show;
5651         cmdline_fixed_string_t bypass;
5652         cmdline_fixed_string_t config;
5653         portid_t port_id;
5654 };
5655
5656 static void
5657 cmd_show_bypass_config_parsed(void *parsed_result,
5658                 __rte_unused struct cmdline *cl,
5659                 __rte_unused void *data)
5660 {
5661         struct cmd_show_bypass_config_result *res = parsed_result;
5662         portid_t port_id = res->port_id;
5663         int rc = -EINVAL;
5664 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5665         uint32_t event_mode;
5666         uint32_t bypass_mode;
5667         uint32_t timeout = bypass_timeout;
5668         unsigned int i;
5669
5670         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5671                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5672         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5673                 {"UNKNOWN", "normal", "bypass", "isolate"};
5674         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5675                 "NONE",
5676                 "OS/board on",
5677                 "power supply on",
5678                 "OS/board off",
5679                 "power supply off",
5680                 "timeout"};
5681
5682         /* Display the bypass mode.*/
5683         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5684                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5685                 return;
5686         }
5687         else {
5688                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5689                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5690
5691                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5692         }
5693
5694         /* Display the bypass timeout.*/
5695         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5696                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5697
5698         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5699
5700         /* Display the bypass events and associated modes. */
5701         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5702
5703                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5704                         printf("\tFailed to get bypass mode for event = %s\n",
5705                                 events[i]);
5706                 } else {
5707                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5708                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5709
5710                         printf("\tbypass event: %-16s = %s\n", events[i],
5711                                 modes[event_mode]);
5712                 }
5713         }
5714 #endif
5715         if (rc != 0)
5716                 printf("\tFailed to get bypass configuration for port = %d\n",
5717                        port_id);
5718 }
5719
5720 cmdline_parse_token_string_t cmd_showbypass_config_show =
5721         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5722                         show, "show");
5723 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5724         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5725                         bypass, "bypass");
5726 cmdline_parse_token_string_t cmd_showbypass_config_config =
5727         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5728                         config, "config");
5729 cmdline_parse_token_num_t cmd_showbypass_config_port =
5730         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5731                                 port_id, UINT16);
5732
5733 cmdline_parse_inst_t cmd_show_bypass_config = {
5734         .f = cmd_show_bypass_config_parsed,
5735         .help_str = "show bypass config <port_id>: "
5736                     "Show the NIC bypass config for port_id",
5737         .data = NULL,
5738         .tokens = {
5739                 (void *)&cmd_showbypass_config_show,
5740                 (void *)&cmd_showbypass_config_bypass,
5741                 (void *)&cmd_showbypass_config_config,
5742                 (void *)&cmd_showbypass_config_port,
5743                 NULL,
5744         },
5745 };
5746
5747 #ifdef RTE_LIBRTE_PMD_BOND
5748 /* *** SET BONDING MODE *** */
5749 struct cmd_set_bonding_mode_result {
5750         cmdline_fixed_string_t set;
5751         cmdline_fixed_string_t bonding;
5752         cmdline_fixed_string_t mode;
5753         uint8_t value;
5754         portid_t port_id;
5755 };
5756
5757 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5758                 __rte_unused  struct cmdline *cl,
5759                 __rte_unused void *data)
5760 {
5761         struct cmd_set_bonding_mode_result *res = parsed_result;
5762         portid_t port_id = res->port_id;
5763
5764         /* Set the bonding mode for the relevant port. */
5765         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5766                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5767 }
5768
5769 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5770 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5771                 set, "set");
5772 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5773 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5774                 bonding, "bonding");
5775 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5776 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5777                 mode, "mode");
5778 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5779 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5780                 value, UINT8);
5781 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5782 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5783                 port_id, UINT16);
5784
5785 cmdline_parse_inst_t cmd_set_bonding_mode = {
5786                 .f = cmd_set_bonding_mode_parsed,
5787                 .help_str = "set bonding mode <mode_value> <port_id>: "
5788                         "Set the bonding mode for port_id",
5789                 .data = NULL,
5790                 .tokens = {
5791                                 (void *) &cmd_setbonding_mode_set,
5792                                 (void *) &cmd_setbonding_mode_bonding,
5793                                 (void *) &cmd_setbonding_mode_mode,
5794                                 (void *) &cmd_setbonding_mode_value,
5795                                 (void *) &cmd_setbonding_mode_port,
5796                                 NULL
5797                 }
5798 };
5799
5800 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5801 struct cmd_set_bonding_lacp_dedicated_queues_result {
5802         cmdline_fixed_string_t set;
5803         cmdline_fixed_string_t bonding;
5804         cmdline_fixed_string_t lacp;
5805         cmdline_fixed_string_t dedicated_queues;
5806         portid_t port_id;
5807         cmdline_fixed_string_t mode;
5808 };
5809
5810 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5811                 __rte_unused  struct cmdline *cl,
5812                 __rte_unused void *data)
5813 {
5814         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5815         portid_t port_id = res->port_id;
5816         struct rte_port *port;
5817
5818         port = &ports[port_id];
5819
5820         /** Check if the port is not started **/
5821         if (port->port_status != RTE_PORT_STOPPED) {
5822                 printf("Please stop port %d first\n", port_id);
5823                 return;
5824         }
5825
5826         if (!strcmp(res->mode, "enable")) {
5827                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5828                         printf("Dedicate queues for LACP control packets"
5829                                         " enabled\n");
5830                 else
5831                         printf("Enabling dedicate queues for LACP control "
5832                                         "packets on port %d failed\n", port_id);
5833         } else if (!strcmp(res->mode, "disable")) {
5834                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5835                         printf("Dedicated queues for LACP control packets "
5836                                         "disabled\n");
5837                 else
5838                         printf("Disabling dedicated queues for LACP control "
5839                                         "traffic on port %d failed\n", port_id);
5840         }
5841 }
5842
5843 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5844 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5845                 set, "set");
5846 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5847 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5848                 bonding, "bonding");
5849 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5850 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5851                 lacp, "lacp");
5852 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5853 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5854                 dedicated_queues, "dedicated_queues");
5855 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5856 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5857                 port_id, UINT16);
5858 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5859 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5860                 mode, "enable#disable");
5861
5862 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5863                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5864                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5865                         "enable|disable: "
5866                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5867                 .data = NULL,
5868                 .tokens = {
5869                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5870                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5871                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5872                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5873                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5874                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5875                         NULL
5876                 }
5877 };
5878
5879 /* *** SET BALANCE XMIT POLICY *** */
5880 struct cmd_set_bonding_balance_xmit_policy_result {
5881         cmdline_fixed_string_t set;
5882         cmdline_fixed_string_t bonding;
5883         cmdline_fixed_string_t balance_xmit_policy;
5884         portid_t port_id;
5885         cmdline_fixed_string_t policy;
5886 };
5887
5888 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5889                 __rte_unused  struct cmdline *cl,
5890                 __rte_unused void *data)
5891 {
5892         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5893         portid_t port_id = res->port_id;
5894         uint8_t policy;
5895
5896         if (!strcmp(res->policy, "l2")) {
5897                 policy = BALANCE_XMIT_POLICY_LAYER2;
5898         } else if (!strcmp(res->policy, "l23")) {
5899                 policy = BALANCE_XMIT_POLICY_LAYER23;
5900         } else if (!strcmp(res->policy, "l34")) {
5901                 policy = BALANCE_XMIT_POLICY_LAYER34;
5902         } else {
5903                 printf("\t Invalid xmit policy selection");
5904                 return;
5905         }
5906
5907         /* Set the bonding mode for the relevant port. */
5908         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5909                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5910                                 port_id);
5911         }
5912 }
5913
5914 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5915 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5916                 set, "set");
5917 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5918 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5919                 bonding, "bonding");
5920 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5921 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5922                 balance_xmit_policy, "balance_xmit_policy");
5923 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5924 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5925                 port_id, UINT16);
5926 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5928                 policy, "l2#l23#l34");
5929
5930 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5931                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5932                 .help_str = "set bonding balance_xmit_policy <port_id> "
5933                         "l2|l23|l34: "
5934                         "Set the bonding balance_xmit_policy for port_id",
5935                 .data = NULL,
5936                 .tokens = {
5937                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5938                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5939                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5940                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5941                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5942                                 NULL
5943                 }
5944 };
5945
5946 /* *** SHOW NIC BONDING CONFIGURATION *** */
5947 struct cmd_show_bonding_config_result {
5948         cmdline_fixed_string_t show;
5949         cmdline_fixed_string_t bonding;
5950         cmdline_fixed_string_t config;
5951         portid_t port_id;
5952 };
5953
5954 static void cmd_show_bonding_config_parsed(void *parsed_result,
5955                 __rte_unused  struct cmdline *cl,
5956                 __rte_unused void *data)
5957 {
5958         struct cmd_show_bonding_config_result *res = parsed_result;
5959         int bonding_mode, agg_mode;
5960         portid_t slaves[RTE_MAX_ETHPORTS];
5961         int num_slaves, num_active_slaves;
5962         int primary_id;
5963         int i;
5964         portid_t port_id = res->port_id;
5965
5966         /* Display the bonding mode.*/
5967         bonding_mode = rte_eth_bond_mode_get(port_id);
5968         if (bonding_mode < 0) {
5969                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
5970                 return;
5971         } else
5972                 printf("\tBonding mode: %d\n", bonding_mode);
5973
5974         if (bonding_mode == BONDING_MODE_BALANCE) {
5975                 int balance_xmit_policy;
5976
5977                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
5978                 if (balance_xmit_policy < 0) {
5979                         printf("\tFailed to get balance xmit policy for port = %d\n",
5980                                         port_id);
5981                         return;
5982                 } else {
5983                         printf("\tBalance Xmit Policy: ");
5984
5985                         switch (balance_xmit_policy) {
5986                         case BALANCE_XMIT_POLICY_LAYER2:
5987                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5988                                 break;
5989                         case BALANCE_XMIT_POLICY_LAYER23:
5990                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5991                                 break;
5992                         case BALANCE_XMIT_POLICY_LAYER34:
5993                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5994                                 break;
5995                         }
5996                         printf("\n");
5997                 }
5998         }
5999
6000         if (bonding_mode == BONDING_MODE_8023AD) {
6001                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6002                 printf("\tIEEE802.3AD Aggregator Mode: ");
6003                 switch (agg_mode) {
6004                 case AGG_BANDWIDTH:
6005                         printf("bandwidth");
6006                         break;
6007                 case AGG_STABLE:
6008                         printf("stable");
6009                         break;
6010                 case AGG_COUNT:
6011                         printf("count");
6012                         break;
6013                 }
6014                 printf("\n");
6015         }
6016
6017         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6018
6019         if (num_slaves < 0) {
6020                 printf("\tFailed to get slave list for port = %d\n", port_id);
6021                 return;
6022         }
6023         if (num_slaves > 0) {
6024                 printf("\tSlaves (%d): [", num_slaves);
6025                 for (i = 0; i < num_slaves - 1; i++)
6026                         printf("%d ", slaves[i]);
6027
6028                 printf("%d]\n", slaves[num_slaves - 1]);
6029         } else {
6030                 printf("\tSlaves: []\n");
6031
6032         }
6033
6034         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6035                         RTE_MAX_ETHPORTS);
6036
6037         if (num_active_slaves < 0) {
6038                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6039                 return;
6040         }
6041         if (num_active_slaves > 0) {
6042                 printf("\tActive Slaves (%d): [", num_active_slaves);
6043                 for (i = 0; i < num_active_slaves - 1; i++)
6044                         printf("%d ", slaves[i]);
6045
6046                 printf("%d]\n", slaves[num_active_slaves - 1]);
6047
6048         } else {
6049                 printf("\tActive Slaves: []\n");
6050
6051         }
6052
6053         primary_id = rte_eth_bond_primary_get(port_id);
6054         if (primary_id < 0) {
6055                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6056                 return;
6057         } else
6058                 printf("\tPrimary: [%d]\n", primary_id);
6059
6060 }
6061
6062 cmdline_parse_token_string_t cmd_showbonding_config_show =
6063 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6064                 show, "show");
6065 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6066 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6067                 bonding, "bonding");
6068 cmdline_parse_token_string_t cmd_showbonding_config_config =
6069 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6070                 config, "config");
6071 cmdline_parse_token_num_t cmd_showbonding_config_port =
6072 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6073                 port_id, UINT16);
6074
6075 cmdline_parse_inst_t cmd_show_bonding_config = {
6076                 .f = cmd_show_bonding_config_parsed,
6077                 .help_str = "show bonding config <port_id>: "
6078                         "Show the bonding config for port_id",
6079                 .data = NULL,
6080                 .tokens = {
6081                                 (void *)&cmd_showbonding_config_show,
6082                                 (void *)&cmd_showbonding_config_bonding,
6083                                 (void *)&cmd_showbonding_config_config,
6084                                 (void *)&cmd_showbonding_config_port,
6085                                 NULL
6086                 }
6087 };
6088
6089 /* *** SET BONDING PRIMARY *** */
6090 struct cmd_set_bonding_primary_result {
6091         cmdline_fixed_string_t set;
6092         cmdline_fixed_string_t bonding;
6093         cmdline_fixed_string_t primary;
6094         portid_t slave_id;
6095         portid_t port_id;
6096 };
6097
6098 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6099                 __rte_unused  struct cmdline *cl,
6100                 __rte_unused void *data)
6101 {
6102         struct cmd_set_bonding_primary_result *res = parsed_result;
6103         portid_t master_port_id = res->port_id;
6104         portid_t slave_port_id = res->slave_id;
6105
6106         /* Set the primary slave for a bonded device. */
6107         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6108                 printf("\t Failed to set primary slave for port = %d.\n",
6109                                 master_port_id);
6110                 return;
6111         }
6112         init_port_config();
6113 }
6114
6115 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6117                 set, "set");
6118 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6120                 bonding, "bonding");
6121 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6123                 primary, "primary");
6124 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6125 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6126                 slave_id, UINT16);
6127 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6128 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6129                 port_id, UINT16);
6130
6131 cmdline_parse_inst_t cmd_set_bonding_primary = {
6132                 .f = cmd_set_bonding_primary_parsed,
6133                 .help_str = "set bonding primary <slave_id> <port_id>: "
6134                         "Set the primary slave for port_id",
6135                 .data = NULL,
6136                 .tokens = {
6137                                 (void *)&cmd_setbonding_primary_set,
6138                                 (void *)&cmd_setbonding_primary_bonding,
6139                                 (void *)&cmd_setbonding_primary_primary,
6140                                 (void *)&cmd_setbonding_primary_slave,
6141                                 (void *)&cmd_setbonding_primary_port,
6142                                 NULL
6143                 }
6144 };
6145
6146 /* *** ADD SLAVE *** */
6147 struct cmd_add_bonding_slave_result {
6148         cmdline_fixed_string_t add;
6149         cmdline_fixed_string_t bonding;
6150         cmdline_fixed_string_t slave;
6151         portid_t slave_id;
6152         portid_t port_id;
6153 };
6154
6155 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6156                 __rte_unused  struct cmdline *cl,
6157                 __rte_unused void *data)
6158 {
6159         struct cmd_add_bonding_slave_result *res = parsed_result;
6160         portid_t master_port_id = res->port_id;
6161         portid_t slave_port_id = res->slave_id;
6162
6163         /* add the slave for a bonded device. */
6164         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6165                 printf("\t Failed to add slave %d to master port = %d.\n",
6166                                 slave_port_id, master_port_id);
6167                 return;
6168         }
6169         init_port_config();
6170         set_port_slave_flag(slave_port_id);
6171 }
6172
6173 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6174 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6175                 add, "add");
6176 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6177 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6178                 bonding, "bonding");
6179 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6180 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6181                 slave, "slave");
6182 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6183 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6184                 slave_id, UINT16);
6185 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6186 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6187                 port_id, UINT16);
6188
6189 cmdline_parse_inst_t cmd_add_bonding_slave = {
6190                 .f = cmd_add_bonding_slave_parsed,
6191                 .help_str = "add bonding slave <slave_id> <port_id>: "
6192                         "Add a slave device to a bonded device",
6193                 .data = NULL,
6194                 .tokens = {
6195                                 (void *)&cmd_addbonding_slave_add,
6196                                 (void *)&cmd_addbonding_slave_bonding,
6197                                 (void *)&cmd_addbonding_slave_slave,
6198                                 (void *)&cmd_addbonding_slave_slaveid,
6199                                 (void *)&cmd_addbonding_slave_port,
6200                                 NULL
6201                 }
6202 };
6203
6204 /* *** REMOVE SLAVE *** */
6205 struct cmd_remove_bonding_slave_result {
6206         cmdline_fixed_string_t remove;
6207         cmdline_fixed_string_t bonding;
6208         cmdline_fixed_string_t slave;
6209         portid_t slave_id;
6210         portid_t port_id;
6211 };
6212
6213 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6214                 __rte_unused  struct cmdline *cl,
6215                 __rte_unused void *data)
6216 {
6217         struct cmd_remove_bonding_slave_result *res = parsed_result;
6218         portid_t master_port_id = res->port_id;
6219         portid_t slave_port_id = res->slave_id;
6220
6221         /* remove the slave from a bonded device. */
6222         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6223                 printf("\t Failed to remove slave %d from master port = %d.\n",
6224                                 slave_port_id, master_port_id);
6225                 return;
6226         }
6227         init_port_config();
6228         clear_port_slave_flag(slave_port_id);
6229 }
6230
6231 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6232                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6233                                 remove, "remove");
6234 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6235                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6236                                 bonding, "bonding");
6237 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6238                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6239                                 slave, "slave");
6240 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6241                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6242                                 slave_id, UINT16);
6243 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6244                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6245                                 port_id, UINT16);
6246
6247 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6248                 .f = cmd_remove_bonding_slave_parsed,
6249                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6250                         "Remove a slave device from a bonded device",
6251                 .data = NULL,
6252                 .tokens = {
6253                                 (void *)&cmd_removebonding_slave_remove,
6254                                 (void *)&cmd_removebonding_slave_bonding,
6255                                 (void *)&cmd_removebonding_slave_slave,
6256                                 (void *)&cmd_removebonding_slave_slaveid,
6257                                 (void *)&cmd_removebonding_slave_port,
6258                                 NULL
6259                 }
6260 };
6261
6262 /* *** CREATE BONDED DEVICE *** */
6263 struct cmd_create_bonded_device_result {
6264         cmdline_fixed_string_t create;
6265         cmdline_fixed_string_t bonded;
6266         cmdline_fixed_string_t device;
6267         uint8_t mode;
6268         uint8_t socket;
6269 };
6270
6271 static int bond_dev_num = 0;
6272
6273 static void cmd_create_bonded_device_parsed(void *parsed_result,
6274                 __rte_unused  struct cmdline *cl,
6275                 __rte_unused void *data)
6276 {
6277         struct cmd_create_bonded_device_result *res = parsed_result;
6278         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6279         int port_id;
6280         int ret;
6281
6282         if (test_done == 0) {
6283                 printf("Please stop forwarding first\n");
6284                 return;
6285         }
6286
6287         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6288                         bond_dev_num++);
6289
6290         /* Create a new bonded device. */
6291         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6292         if (port_id < 0) {
6293                 printf("\t Failed to create bonded device.\n");
6294                 return;
6295         } else {
6296                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6297                                 port_id);
6298
6299                 /* Update number of ports */
6300                 nb_ports = rte_eth_dev_count_avail();
6301                 reconfig(port_id, res->socket);
6302                 ret = rte_eth_promiscuous_enable(port_id);
6303                 if (ret != 0)
6304                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6305                                 port_id, rte_strerror(-ret));
6306
6307                 ports[port_id].need_setup = 0;
6308                 ports[port_id].port_status = RTE_PORT_STOPPED;
6309         }
6310
6311 }
6312
6313 cmdline_parse_token_string_t cmd_createbonded_device_create =
6314                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6315                                 create, "create");
6316 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6317                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6318                                 bonded, "bonded");
6319 cmdline_parse_token_string_t cmd_createbonded_device_device =
6320                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6321                                 device, "device");
6322 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6323                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6324                                 mode, UINT8);
6325 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6326                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6327                                 socket, UINT8);
6328
6329 cmdline_parse_inst_t cmd_create_bonded_device = {
6330                 .f = cmd_create_bonded_device_parsed,
6331                 .help_str = "create bonded device <mode> <socket>: "
6332                         "Create a new bonded device with specific bonding mode and socket",
6333                 .data = NULL,
6334                 .tokens = {
6335                                 (void *)&cmd_createbonded_device_create,
6336                                 (void *)&cmd_createbonded_device_bonded,
6337                                 (void *)&cmd_createbonded_device_device,
6338                                 (void *)&cmd_createbonded_device_mode,
6339                                 (void *)&cmd_createbonded_device_socket,
6340                                 NULL
6341                 }
6342 };
6343
6344 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6345 struct cmd_set_bond_mac_addr_result {
6346         cmdline_fixed_string_t set;
6347         cmdline_fixed_string_t bonding;
6348         cmdline_fixed_string_t mac_addr;
6349         uint16_t port_num;
6350         struct rte_ether_addr address;
6351 };
6352
6353 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6354                 __rte_unused  struct cmdline *cl,
6355                 __rte_unused void *data)
6356 {
6357         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6358         int ret;
6359
6360         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6361                 return;
6362
6363         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6364
6365         /* check the return value and print it if is < 0 */
6366         if (ret < 0)
6367                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6368 }
6369
6370 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6371                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6372 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6373                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6374                                 "bonding");
6375 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6376                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6377                                 "mac_addr");
6378 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6379                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6380                                 port_num, UINT16);
6381 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6382                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6383
6384 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6385                 .f = cmd_set_bond_mac_addr_parsed,
6386                 .data = (void *) 0,
6387                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6388                 .tokens = {
6389                                 (void *)&cmd_set_bond_mac_addr_set,
6390                                 (void *)&cmd_set_bond_mac_addr_bonding,
6391                                 (void *)&cmd_set_bond_mac_addr_mac,
6392                                 (void *)&cmd_set_bond_mac_addr_portnum,
6393                                 (void *)&cmd_set_bond_mac_addr_addr,
6394                                 NULL
6395                 }
6396 };
6397
6398
6399 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6400 struct cmd_set_bond_mon_period_result {
6401         cmdline_fixed_string_t set;
6402         cmdline_fixed_string_t bonding;
6403         cmdline_fixed_string_t mon_period;
6404         uint16_t port_num;
6405         uint32_t period_ms;
6406 };
6407
6408 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6409                 __rte_unused  struct cmdline *cl,
6410                 __rte_unused void *data)
6411 {
6412         struct cmd_set_bond_mon_period_result *res = parsed_result;
6413         int ret;
6414
6415         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6416
6417         /* check the return value and print it if is < 0 */
6418         if (ret < 0)
6419                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6420 }
6421
6422 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6423                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6424                                 set, "set");
6425 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6426                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6427                                 bonding, "bonding");
6428 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6429                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6430                                 mon_period,     "mon_period");
6431 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6432                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6433                                 port_num, UINT16);
6434 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6435                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6436                                 period_ms, UINT32);
6437
6438 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6439                 .f = cmd_set_bond_mon_period_parsed,
6440                 .data = (void *) 0,
6441                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6442                 .tokens = {
6443                                 (void *)&cmd_set_bond_mon_period_set,
6444                                 (void *)&cmd_set_bond_mon_period_bonding,
6445                                 (void *)&cmd_set_bond_mon_period_mon_period,
6446                                 (void *)&cmd_set_bond_mon_period_portnum,
6447                                 (void *)&cmd_set_bond_mon_period_period_ms,
6448                                 NULL
6449                 }
6450 };
6451
6452
6453
6454 struct cmd_set_bonding_agg_mode_policy_result {
6455         cmdline_fixed_string_t set;
6456         cmdline_fixed_string_t bonding;
6457         cmdline_fixed_string_t agg_mode;
6458         uint16_t port_num;
6459         cmdline_fixed_string_t policy;
6460 };
6461
6462
6463 static void
6464 cmd_set_bonding_agg_mode(void *parsed_result,
6465                 __rte_unused struct cmdline *cl,
6466                 __rte_unused void *data)
6467 {
6468         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6469         uint8_t policy = AGG_BANDWIDTH;
6470
6471         if (!strcmp(res->policy, "bandwidth"))
6472                 policy = AGG_BANDWIDTH;
6473         else if (!strcmp(res->policy, "stable"))
6474                 policy = AGG_STABLE;
6475         else if (!strcmp(res->policy, "count"))
6476                 policy = AGG_COUNT;
6477
6478         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6479 }
6480
6481
6482 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6483         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6484                                 set, "set");
6485 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6486         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6487                                 bonding, "bonding");
6488
6489 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6490         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6491                                 agg_mode, "agg_mode");
6492
6493 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6494         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6495                                 port_num, UINT16);
6496
6497 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6498         TOKEN_STRING_INITIALIZER(
6499                         struct cmd_set_bonding_balance_xmit_policy_result,
6500                 policy, "stable#bandwidth#count");
6501
6502 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6503         .f = cmd_set_bonding_agg_mode,
6504         .data = (void *) 0,
6505         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6506         .tokens = {
6507                         (void *)&cmd_set_bonding_agg_mode_set,
6508                         (void *)&cmd_set_bonding_agg_mode_bonding,
6509                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6510                         (void *)&cmd_set_bonding_agg_mode_portnum,
6511                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6512                         NULL
6513                 }
6514 };
6515
6516
6517 #endif /* RTE_LIBRTE_PMD_BOND */
6518
6519 /* *** SET FORWARDING MODE *** */
6520 struct cmd_set_fwd_mode_result {
6521         cmdline_fixed_string_t set;
6522         cmdline_fixed_string_t fwd;
6523         cmdline_fixed_string_t mode;
6524 };
6525
6526 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6527                                     __rte_unused struct cmdline *cl,
6528                                     __rte_unused void *data)
6529 {
6530         struct cmd_set_fwd_mode_result *res = parsed_result;
6531
6532         retry_enabled = 0;
6533         set_pkt_forwarding_mode(res->mode);
6534 }
6535
6536 cmdline_parse_token_string_t cmd_setfwd_set =
6537         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6538 cmdline_parse_token_string_t cmd_setfwd_fwd =
6539         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6540 cmdline_parse_token_string_t cmd_setfwd_mode =
6541         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6542                 "" /* defined at init */);
6543
6544 cmdline_parse_inst_t cmd_set_fwd_mode = {
6545         .f = cmd_set_fwd_mode_parsed,
6546         .data = NULL,
6547         .help_str = NULL, /* defined at init */
6548         .tokens = {
6549                 (void *)&cmd_setfwd_set,
6550                 (void *)&cmd_setfwd_fwd,
6551                 (void *)&cmd_setfwd_mode,
6552                 NULL,
6553         },
6554 };
6555
6556 static void cmd_set_fwd_mode_init(void)
6557 {
6558         char *modes, *c;
6559         static char token[128];
6560         static char help[256];
6561         cmdline_parse_token_string_t *token_struct;
6562
6563         modes = list_pkt_forwarding_modes();
6564         snprintf(help, sizeof(help), "set fwd %s: "
6565                 "Set packet forwarding mode", modes);
6566         cmd_set_fwd_mode.help_str = help;
6567
6568         /* string token separator is # */
6569         for (c = token; *modes != '\0'; modes++)
6570                 if (*modes == '|')
6571                         *c++ = '#';
6572                 else
6573                         *c++ = *modes;
6574         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6575         token_struct->string_data.str = token;
6576 }
6577
6578 /* *** SET RETRY FORWARDING MODE *** */
6579 struct cmd_set_fwd_retry_mode_result {
6580         cmdline_fixed_string_t set;
6581         cmdline_fixed_string_t fwd;
6582         cmdline_fixed_string_t mode;
6583         cmdline_fixed_string_t retry;
6584 };
6585
6586 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6587                             __rte_unused struct cmdline *cl,
6588                             __rte_unused void *data)
6589 {
6590         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6591
6592         retry_enabled = 1;
6593         set_pkt_forwarding_mode(res->mode);
6594 }
6595
6596 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6597         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6598                         set, "set");
6599 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6600         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6601                         fwd, "fwd");
6602 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6603         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6604                         mode,
6605                 "" /* defined at init */);
6606 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6607         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6608                         retry, "retry");
6609
6610 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6611         .f = cmd_set_fwd_retry_mode_parsed,
6612         .data = NULL,
6613         .help_str = NULL, /* defined at init */
6614         .tokens = {
6615                 (void *)&cmd_setfwd_retry_set,
6616                 (void *)&cmd_setfwd_retry_fwd,
6617                 (void *)&cmd_setfwd_retry_mode,
6618                 (void *)&cmd_setfwd_retry_retry,
6619                 NULL,
6620         },
6621 };
6622
6623 static void cmd_set_fwd_retry_mode_init(void)
6624 {
6625         char *modes, *c;
6626         static char token[128];
6627         static char help[256];
6628         cmdline_parse_token_string_t *token_struct;
6629
6630         modes = list_pkt_forwarding_retry_modes();
6631         snprintf(help, sizeof(help), "set fwd %s retry: "
6632                 "Set packet forwarding mode with retry", modes);
6633         cmd_set_fwd_retry_mode.help_str = help;
6634
6635         /* string token separator is # */
6636         for (c = token; *modes != '\0'; modes++)
6637                 if (*modes == '|')
6638                         *c++ = '#';
6639                 else
6640                         *c++ = *modes;
6641         token_struct = (cmdline_parse_token_string_t *)
6642                 cmd_set_fwd_retry_mode.tokens[2];
6643         token_struct->string_data.str = token;
6644 }
6645
6646 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6647 struct cmd_set_burst_tx_retry_result {
6648         cmdline_fixed_string_t set;
6649         cmdline_fixed_string_t burst;
6650         cmdline_fixed_string_t tx;
6651         cmdline_fixed_string_t delay;
6652         uint32_t time;
6653         cmdline_fixed_string_t retry;
6654         uint32_t retry_num;
6655 };
6656
6657 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6658                                         __rte_unused struct cmdline *cl,
6659                                         __rte_unused void *data)
6660 {
6661         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6662
6663         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6664                 && !strcmp(res->tx, "tx")) {
6665                 if (!strcmp(res->delay, "delay"))
6666                         burst_tx_delay_time = res->time;
6667                 if (!strcmp(res->retry, "retry"))
6668                         burst_tx_retry_num = res->retry_num;
6669         }
6670
6671 }
6672
6673 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6674         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6675 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6676         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6677                                  "burst");
6678 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6679         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6680 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6682 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6683         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6684 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6685         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6686 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6687         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6688
6689 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6690         .f = cmd_set_burst_tx_retry_parsed,
6691         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6692         .tokens = {
6693                 (void *)&cmd_set_burst_tx_retry_set,
6694                 (void *)&cmd_set_burst_tx_retry_burst,
6695                 (void *)&cmd_set_burst_tx_retry_tx,
6696                 (void *)&cmd_set_burst_tx_retry_delay,
6697                 (void *)&cmd_set_burst_tx_retry_time,
6698                 (void *)&cmd_set_burst_tx_retry_retry,
6699                 (void *)&cmd_set_burst_tx_retry_retry_num,
6700                 NULL,
6701         },
6702 };
6703
6704 /* *** SET PROMISC MODE *** */
6705 struct cmd_set_promisc_mode_result {
6706         cmdline_fixed_string_t set;
6707         cmdline_fixed_string_t promisc;
6708         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6709         uint16_t port_num;               /* valid if "allports" argument == 0 */
6710         cmdline_fixed_string_t mode;
6711 };
6712
6713 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6714                                         __rte_unused struct cmdline *cl,
6715                                         void *allports)
6716 {
6717         struct cmd_set_promisc_mode_result *res = parsed_result;
6718         int enable;
6719         portid_t i;
6720
6721         if (!strcmp(res->mode, "on"))
6722                 enable = 1;
6723         else
6724                 enable = 0;
6725
6726         /* all ports */
6727         if (allports) {
6728                 RTE_ETH_FOREACH_DEV(i)
6729                         eth_set_promisc_mode(i, enable);
6730         } else {
6731                 eth_set_promisc_mode(res->port_num, enable);
6732         }
6733 }
6734
6735 cmdline_parse_token_string_t cmd_setpromisc_set =
6736         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6737 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6738         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6739                                  "promisc");
6740 cmdline_parse_token_string_t cmd_setpromisc_portall =
6741         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6742                                  "all");
6743 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6744         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6745                               UINT16);
6746 cmdline_parse_token_string_t cmd_setpromisc_mode =
6747         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6748                                  "on#off");
6749
6750 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6751         .f = cmd_set_promisc_mode_parsed,
6752         .data = (void *)1,
6753         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6754         .tokens = {
6755                 (void *)&cmd_setpromisc_set,
6756                 (void *)&cmd_setpromisc_promisc,
6757                 (void *)&cmd_setpromisc_portall,
6758                 (void *)&cmd_setpromisc_mode,
6759                 NULL,
6760         },
6761 };
6762
6763 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6764         .f = cmd_set_promisc_mode_parsed,
6765         .data = (void *)0,
6766         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6767         .tokens = {
6768                 (void *)&cmd_setpromisc_set,
6769                 (void *)&cmd_setpromisc_promisc,
6770                 (void *)&cmd_setpromisc_portnum,
6771                 (void *)&cmd_setpromisc_mode,
6772                 NULL,
6773         },
6774 };
6775
6776 /* *** SET ALLMULTI MODE *** */
6777 struct cmd_set_allmulti_mode_result {
6778         cmdline_fixed_string_t set;
6779         cmdline_fixed_string_t allmulti;
6780         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6781         uint16_t port_num;               /* valid if "allports" argument == 0 */
6782         cmdline_fixed_string_t mode;
6783 };
6784
6785 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6786                                         __rte_unused struct cmdline *cl,
6787                                         void *allports)
6788 {
6789         struct cmd_set_allmulti_mode_result *res = parsed_result;
6790         int enable;
6791         portid_t i;
6792
6793         if (!strcmp(res->mode, "on"))
6794                 enable = 1;
6795         else
6796                 enable = 0;
6797
6798         /* all ports */
6799         if (allports) {
6800                 RTE_ETH_FOREACH_DEV(i) {
6801                         eth_set_allmulticast_mode(i, enable);
6802                 }
6803         }
6804         else {
6805                 eth_set_allmulticast_mode(res->port_num, enable);
6806         }
6807 }
6808
6809 cmdline_parse_token_string_t cmd_setallmulti_set =
6810         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6811 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6812         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6813                                  "allmulti");
6814 cmdline_parse_token_string_t cmd_setallmulti_portall =
6815         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6816                                  "all");
6817 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6818         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6819                               UINT16);
6820 cmdline_parse_token_string_t cmd_setallmulti_mode =
6821         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6822                                  "on#off");
6823
6824 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6825         .f = cmd_set_allmulti_mode_parsed,
6826         .data = (void *)1,
6827         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6828         .tokens = {
6829                 (void *)&cmd_setallmulti_set,
6830                 (void *)&cmd_setallmulti_allmulti,
6831                 (void *)&cmd_setallmulti_portall,
6832                 (void *)&cmd_setallmulti_mode,
6833                 NULL,
6834         },
6835 };
6836
6837 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6838         .f = cmd_set_allmulti_mode_parsed,
6839         .data = (void *)0,
6840         .help_str = "set allmulti <port_id> on|off: "
6841                 "Set allmulti mode on port_id",
6842         .tokens = {
6843                 (void *)&cmd_setallmulti_set,
6844                 (void *)&cmd_setallmulti_allmulti,
6845                 (void *)&cmd_setallmulti_portnum,
6846                 (void *)&cmd_setallmulti_mode,
6847                 NULL,
6848         },
6849 };
6850
6851 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6852 struct cmd_link_flow_ctrl_set_result {
6853         cmdline_fixed_string_t set;
6854         cmdline_fixed_string_t flow_ctrl;
6855         cmdline_fixed_string_t rx;
6856         cmdline_fixed_string_t rx_lfc_mode;
6857         cmdline_fixed_string_t tx;
6858         cmdline_fixed_string_t tx_lfc_mode;
6859         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6860         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6861         cmdline_fixed_string_t autoneg_str;
6862         cmdline_fixed_string_t autoneg;
6863         cmdline_fixed_string_t hw_str;
6864         uint32_t high_water;
6865         cmdline_fixed_string_t lw_str;
6866         uint32_t low_water;
6867         cmdline_fixed_string_t pt_str;
6868         uint16_t pause_time;
6869         cmdline_fixed_string_t xon_str;
6870         uint16_t send_xon;
6871         portid_t port_id;
6872 };
6873
6874 cmdline_parse_token_string_t cmd_lfc_set_set =
6875         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6876                                 set, "set");
6877 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6878         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6879                                 flow_ctrl, "flow_ctrl");
6880 cmdline_parse_token_string_t cmd_lfc_set_rx =
6881         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6882                                 rx, "rx");
6883 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6884         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6885                                 rx_lfc_mode, "on#off");
6886 cmdline_parse_token_string_t cmd_lfc_set_tx =
6887         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6888                                 tx, "tx");
6889 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6890         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6891                                 tx_lfc_mode, "on#off");
6892 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6893         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6894                                 hw_str, "high_water");
6895 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6896         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6897                                 high_water, UINT32);
6898 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6899         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6900                                 lw_str, "low_water");
6901 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6902         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6903                                 low_water, UINT32);
6904 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6905         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6906                                 pt_str, "pause_time");
6907 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6908         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6909                                 pause_time, UINT16);
6910 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6911         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6912                                 xon_str, "send_xon");
6913 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6914         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6915                                 send_xon, UINT16);
6916 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6917         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6918                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6919 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6920         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6921                                 mac_ctrl_frame_fwd_mode, "on#off");
6922 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6923         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6924                                 autoneg_str, "autoneg");
6925 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6926         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6927                                 autoneg, "on#off");
6928 cmdline_parse_token_num_t cmd_lfc_set_portid =
6929         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6930                                 port_id, UINT16);
6931
6932 /* forward declaration */
6933 static void
6934 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6935                               void *data);
6936
6937 cmdline_parse_inst_t cmd_link_flow_control_set = {
6938         .f = cmd_link_flow_ctrl_set_parsed,
6939         .data = NULL,
6940         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6941                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6942                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6943         .tokens = {
6944                 (void *)&cmd_lfc_set_set,
6945                 (void *)&cmd_lfc_set_flow_ctrl,
6946                 (void *)&cmd_lfc_set_rx,
6947                 (void *)&cmd_lfc_set_rx_mode,
6948                 (void *)&cmd_lfc_set_tx,
6949                 (void *)&cmd_lfc_set_tx_mode,
6950                 (void *)&cmd_lfc_set_high_water,
6951                 (void *)&cmd_lfc_set_low_water,
6952                 (void *)&cmd_lfc_set_pause_time,
6953                 (void *)&cmd_lfc_set_send_xon,
6954                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6955                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6956                 (void *)&cmd_lfc_set_autoneg_str,
6957                 (void *)&cmd_lfc_set_autoneg,
6958                 (void *)&cmd_lfc_set_portid,
6959                 NULL,
6960         },
6961 };
6962
6963 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
6964         .f = cmd_link_flow_ctrl_set_parsed,
6965         .data = (void *)&cmd_link_flow_control_set_rx,
6966         .help_str = "set flow_ctrl rx on|off <port_id>: "
6967                 "Change rx flow control parameter",
6968         .tokens = {
6969                 (void *)&cmd_lfc_set_set,
6970                 (void *)&cmd_lfc_set_flow_ctrl,
6971                 (void *)&cmd_lfc_set_rx,
6972                 (void *)&cmd_lfc_set_rx_mode,
6973                 (void *)&cmd_lfc_set_portid,
6974                 NULL,
6975         },
6976 };
6977
6978 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6979         .f = cmd_link_flow_ctrl_set_parsed,
6980         .data = (void *)&cmd_link_flow_control_set_tx,
6981         .help_str = "set flow_ctrl tx on|off <port_id>: "
6982                 "Change tx flow control parameter",
6983         .tokens = {
6984                 (void *)&cmd_lfc_set_set,
6985                 (void *)&cmd_lfc_set_flow_ctrl,
6986                 (void *)&cmd_lfc_set_tx,
6987                 (void *)&cmd_lfc_set_tx_mode,
6988                 (void *)&cmd_lfc_set_portid,
6989                 NULL,
6990         },
6991 };
6992
6993 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6994         .f = cmd_link_flow_ctrl_set_parsed,
6995         .data = (void *)&cmd_link_flow_control_set_hw,
6996         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6997                 "Change high water flow control parameter",
6998         .tokens = {
6999                 (void *)&cmd_lfc_set_set,
7000                 (void *)&cmd_lfc_set_flow_ctrl,
7001                 (void *)&cmd_lfc_set_high_water_str,
7002                 (void *)&cmd_lfc_set_high_water,
7003                 (void *)&cmd_lfc_set_portid,
7004                 NULL,
7005         },
7006 };
7007
7008 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7009         .f = cmd_link_flow_ctrl_set_parsed,
7010         .data = (void *)&cmd_link_flow_control_set_lw,
7011         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7012                 "Change low water flow control parameter",
7013         .tokens = {
7014                 (void *)&cmd_lfc_set_set,
7015                 (void *)&cmd_lfc_set_flow_ctrl,
7016                 (void *)&cmd_lfc_set_low_water_str,
7017                 (void *)&cmd_lfc_set_low_water,
7018                 (void *)&cmd_lfc_set_portid,
7019                 NULL,
7020         },
7021 };
7022
7023 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7024         .f = cmd_link_flow_ctrl_set_parsed,
7025         .data = (void *)&cmd_link_flow_control_set_pt,
7026         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7027                 "Change pause time flow control parameter",
7028         .tokens = {
7029                 (void *)&cmd_lfc_set_set,
7030                 (void *)&cmd_lfc_set_flow_ctrl,
7031                 (void *)&cmd_lfc_set_pause_time_str,
7032                 (void *)&cmd_lfc_set_pause_time,
7033                 (void *)&cmd_lfc_set_portid,
7034                 NULL,
7035         },
7036 };
7037
7038 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7039         .f = cmd_link_flow_ctrl_set_parsed,
7040         .data = (void *)&cmd_link_flow_control_set_xon,
7041         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7042                 "Change send_xon flow control parameter",
7043         .tokens = {
7044                 (void *)&cmd_lfc_set_set,
7045                 (void *)&cmd_lfc_set_flow_ctrl,
7046                 (void *)&cmd_lfc_set_send_xon_str,
7047                 (void *)&cmd_lfc_set_send_xon,
7048                 (void *)&cmd_lfc_set_portid,
7049                 NULL,
7050         },
7051 };
7052
7053 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7054         .f = cmd_link_flow_ctrl_set_parsed,
7055         .data = (void *)&cmd_link_flow_control_set_macfwd,
7056         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7057                 "Change mac ctrl fwd flow control parameter",
7058         .tokens = {
7059                 (void *)&cmd_lfc_set_set,
7060                 (void *)&cmd_lfc_set_flow_ctrl,
7061                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7062                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7063                 (void *)&cmd_lfc_set_portid,
7064                 NULL,
7065         },
7066 };
7067
7068 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7069         .f = cmd_link_flow_ctrl_set_parsed,
7070         .data = (void *)&cmd_link_flow_control_set_autoneg,
7071         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7072                 "Change autoneg flow control parameter",
7073         .tokens = {
7074                 (void *)&cmd_lfc_set_set,
7075                 (void *)&cmd_lfc_set_flow_ctrl,
7076                 (void *)&cmd_lfc_set_autoneg_str,
7077                 (void *)&cmd_lfc_set_autoneg,
7078                 (void *)&cmd_lfc_set_portid,
7079                 NULL,
7080         },
7081 };
7082
7083 static void
7084 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7085                               __rte_unused struct cmdline *cl,
7086                               void *data)
7087 {
7088         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7089         cmdline_parse_inst_t *cmd = data;
7090         struct rte_eth_fc_conf fc_conf;
7091         int rx_fc_en = 0;
7092         int tx_fc_en = 0;
7093         int ret;
7094
7095         /*
7096          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7097          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7098          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7099          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7100          */
7101         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7102                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7103         };
7104
7105         /* Partial command line, retrieve current configuration */
7106         if (cmd) {
7107                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7108                 if (ret != 0) {
7109                         printf("cannot get current flow ctrl parameters, return"
7110                                "code = %d\n", ret);
7111                         return;
7112                 }
7113
7114                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7115                     (fc_conf.mode == RTE_FC_FULL))
7116                         rx_fc_en = 1;
7117                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7118                     (fc_conf.mode == RTE_FC_FULL))
7119                         tx_fc_en = 1;
7120         }
7121
7122         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7123                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7124
7125         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7126                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7127
7128         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7129
7130         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7131                 fc_conf.high_water = res->high_water;
7132
7133         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7134                 fc_conf.low_water = res->low_water;
7135
7136         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7137                 fc_conf.pause_time = res->pause_time;
7138
7139         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7140                 fc_conf.send_xon = res->send_xon;
7141
7142         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7143                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7144                         fc_conf.mac_ctrl_frame_fwd = 1;
7145                 else
7146                         fc_conf.mac_ctrl_frame_fwd = 0;
7147         }
7148
7149         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7150                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7151
7152         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7153         if (ret != 0)
7154                 printf("bad flow contrl parameter, return code = %d \n", ret);
7155 }
7156
7157 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7158 struct cmd_priority_flow_ctrl_set_result {
7159         cmdline_fixed_string_t set;
7160         cmdline_fixed_string_t pfc_ctrl;
7161         cmdline_fixed_string_t rx;
7162         cmdline_fixed_string_t rx_pfc_mode;
7163         cmdline_fixed_string_t tx;
7164         cmdline_fixed_string_t tx_pfc_mode;
7165         uint32_t high_water;
7166         uint32_t low_water;
7167         uint16_t pause_time;
7168         uint8_t  priority;
7169         portid_t port_id;
7170 };
7171
7172 static void
7173 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7174                        __rte_unused struct cmdline *cl,
7175                        __rte_unused void *data)
7176 {
7177         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7178         struct rte_eth_pfc_conf pfc_conf;
7179         int rx_fc_enable, tx_fc_enable;
7180         int ret;
7181
7182         /*
7183          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7184          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7185          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7186          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7187          */
7188         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7189                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7190         };
7191
7192         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7193         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7194         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7195         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7196         pfc_conf.fc.high_water = res->high_water;
7197         pfc_conf.fc.low_water  = res->low_water;
7198         pfc_conf.fc.pause_time = res->pause_time;
7199         pfc_conf.priority      = res->priority;
7200
7201         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7202         if (ret != 0)
7203                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7204 }
7205
7206 cmdline_parse_token_string_t cmd_pfc_set_set =
7207         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7208                                 set, "set");
7209 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7210         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7211                                 pfc_ctrl, "pfc_ctrl");
7212 cmdline_parse_token_string_t cmd_pfc_set_rx =
7213         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7214                                 rx, "rx");
7215 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7216         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7217                                 rx_pfc_mode, "on#off");
7218 cmdline_parse_token_string_t cmd_pfc_set_tx =
7219         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7220                                 tx, "tx");
7221 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7222         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7223                                 tx_pfc_mode, "on#off");
7224 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7225         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7226                                 high_water, UINT32);
7227 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7228         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7229                                 low_water, UINT32);
7230 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7231         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7232                                 pause_time, UINT16);
7233 cmdline_parse_token_num_t cmd_pfc_set_priority =
7234         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7235                                 priority, UINT8);
7236 cmdline_parse_token_num_t cmd_pfc_set_portid =
7237         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7238                                 port_id, UINT16);
7239
7240 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7241         .f = cmd_priority_flow_ctrl_set_parsed,
7242         .data = NULL,
7243         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7244                 "<pause_time> <priority> <port_id>: "
7245                 "Configure the Ethernet priority flow control",
7246         .tokens = {
7247                 (void *)&cmd_pfc_set_set,
7248                 (void *)&cmd_pfc_set_flow_ctrl,
7249                 (void *)&cmd_pfc_set_rx,
7250                 (void *)&cmd_pfc_set_rx_mode,
7251                 (void *)&cmd_pfc_set_tx,
7252                 (void *)&cmd_pfc_set_tx_mode,
7253                 (void *)&cmd_pfc_set_high_water,
7254                 (void *)&cmd_pfc_set_low_water,
7255                 (void *)&cmd_pfc_set_pause_time,
7256                 (void *)&cmd_pfc_set_priority,
7257                 (void *)&cmd_pfc_set_portid,
7258                 NULL,
7259         },
7260 };
7261
7262 /* *** RESET CONFIGURATION *** */
7263 struct cmd_reset_result {
7264         cmdline_fixed_string_t reset;
7265         cmdline_fixed_string_t def;
7266 };
7267
7268 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7269                              struct cmdline *cl,
7270                              __rte_unused void *data)
7271 {
7272         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7273         set_def_fwd_config();
7274 }
7275
7276 cmdline_parse_token_string_t cmd_reset_set =
7277         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7278 cmdline_parse_token_string_t cmd_reset_def =
7279         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7280                                  "default");
7281
7282 cmdline_parse_inst_t cmd_reset = {
7283         .f = cmd_reset_parsed,
7284         .data = NULL,
7285         .help_str = "set default: Reset default forwarding configuration",
7286         .tokens = {
7287                 (void *)&cmd_reset_set,
7288                 (void *)&cmd_reset_def,
7289                 NULL,
7290         },
7291 };
7292
7293 /* *** START FORWARDING *** */
7294 struct cmd_start_result {
7295         cmdline_fixed_string_t start;
7296 };
7297
7298 cmdline_parse_token_string_t cmd_start_start =
7299         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7300
7301 static void cmd_start_parsed(__rte_unused void *parsed_result,
7302                              __rte_unused struct cmdline *cl,
7303                              __rte_unused void *data)
7304 {
7305         start_packet_forwarding(0);
7306 }
7307
7308 cmdline_parse_inst_t cmd_start = {
7309         .f = cmd_start_parsed,
7310         .data = NULL,
7311         .help_str = "start: Start packet forwarding",
7312         .tokens = {
7313                 (void *)&cmd_start_start,
7314                 NULL,
7315         },
7316 };
7317
7318 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7319 struct cmd_start_tx_first_result {
7320         cmdline_fixed_string_t start;
7321         cmdline_fixed_string_t tx_first;
7322 };
7323
7324 static void
7325 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7326                           __rte_unused struct cmdline *cl,
7327                           __rte_unused void *data)
7328 {
7329         start_packet_forwarding(1);
7330 }
7331
7332 cmdline_parse_token_string_t cmd_start_tx_first_start =
7333         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7334                                  "start");
7335 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7336         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7337                                  tx_first, "tx_first");
7338
7339 cmdline_parse_inst_t cmd_start_tx_first = {
7340         .f = cmd_start_tx_first_parsed,
7341         .data = NULL,
7342         .help_str = "start tx_first: Start packet forwarding, "
7343                 "after sending 1 burst of packets",
7344         .tokens = {
7345                 (void *)&cmd_start_tx_first_start,
7346                 (void *)&cmd_start_tx_first_tx_first,
7347                 NULL,
7348         },
7349 };
7350
7351 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7352 struct cmd_start_tx_first_n_result {
7353         cmdline_fixed_string_t start;
7354         cmdline_fixed_string_t tx_first;
7355         uint32_t tx_num;
7356 };
7357
7358 static void
7359 cmd_start_tx_first_n_parsed(void *parsed_result,
7360                           __rte_unused struct cmdline *cl,
7361                           __rte_unused void *data)
7362 {
7363         struct cmd_start_tx_first_n_result *res = parsed_result;
7364
7365         start_packet_forwarding(res->tx_num);
7366 }
7367
7368 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7369         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7370                         start, "start");
7371 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7372         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7373                         tx_first, "tx_first");
7374 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7375         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7376                         tx_num, UINT32);
7377
7378 cmdline_parse_inst_t cmd_start_tx_first_n = {
7379         .f = cmd_start_tx_first_n_parsed,
7380         .data = NULL,
7381         .help_str = "start tx_first <num>: "
7382                 "packet forwarding, after sending <num> bursts of packets",
7383         .tokens = {
7384                 (void *)&cmd_start_tx_first_n_start,
7385                 (void *)&cmd_start_tx_first_n_tx_first,
7386                 (void *)&cmd_start_tx_first_n_tx_num,
7387                 NULL,
7388         },
7389 };
7390
7391 /* *** SET LINK UP *** */
7392 struct cmd_set_link_up_result {
7393         cmdline_fixed_string_t set;
7394         cmdline_fixed_string_t link_up;
7395         cmdline_fixed_string_t port;
7396         portid_t port_id;
7397 };
7398
7399 cmdline_parse_token_string_t cmd_set_link_up_set =
7400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7401 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7402         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7403                                 "link-up");
7404 cmdline_parse_token_string_t cmd_set_link_up_port =
7405         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7406 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7407         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7408
7409 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7410                              __rte_unused struct cmdline *cl,
7411                              __rte_unused void *data)
7412 {
7413         struct cmd_set_link_up_result *res = parsed_result;
7414         dev_set_link_up(res->port_id);
7415 }
7416
7417 cmdline_parse_inst_t cmd_set_link_up = {
7418         .f = cmd_set_link_up_parsed,
7419         .data = NULL,
7420         .help_str = "set link-up port <port id>",
7421         .tokens = {
7422                 (void *)&cmd_set_link_up_set,
7423                 (void *)&cmd_set_link_up_link_up,
7424                 (void *)&cmd_set_link_up_port,
7425                 (void *)&cmd_set_link_up_port_id,
7426                 NULL,
7427         },
7428 };
7429
7430 /* *** SET LINK DOWN *** */
7431 struct cmd_set_link_down_result {
7432         cmdline_fixed_string_t set;
7433         cmdline_fixed_string_t link_down;
7434         cmdline_fixed_string_t port;
7435         portid_t port_id;
7436 };
7437
7438 cmdline_parse_token_string_t cmd_set_link_down_set =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7440 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7441         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7442                                 "link-down");
7443 cmdline_parse_token_string_t cmd_set_link_down_port =
7444         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7445 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7446         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7447
7448 static void cmd_set_link_down_parsed(
7449                                 __rte_unused void *parsed_result,
7450                                 __rte_unused struct cmdline *cl,
7451                                 __rte_unused void *data)
7452 {
7453         struct cmd_set_link_down_result *res = parsed_result;
7454         dev_set_link_down(res->port_id);
7455 }
7456
7457 cmdline_parse_inst_t cmd_set_link_down = {
7458         .f = cmd_set_link_down_parsed,
7459         .data = NULL,
7460         .help_str = "set link-down port <port id>",
7461         .tokens = {
7462                 (void *)&cmd_set_link_down_set,
7463                 (void *)&cmd_set_link_down_link_down,
7464                 (void *)&cmd_set_link_down_port,
7465                 (void *)&cmd_set_link_down_port_id,
7466                 NULL,
7467         },
7468 };
7469
7470 /* *** SHOW CFG *** */
7471 struct cmd_showcfg_result {
7472         cmdline_fixed_string_t show;
7473         cmdline_fixed_string_t cfg;
7474         cmdline_fixed_string_t what;
7475 };
7476
7477 static void cmd_showcfg_parsed(void *parsed_result,
7478                                __rte_unused struct cmdline *cl,
7479                                __rte_unused void *data)
7480 {
7481         struct cmd_showcfg_result *res = parsed_result;
7482         if (!strcmp(res->what, "rxtx"))
7483                 rxtx_config_display();
7484         else if (!strcmp(res->what, "cores"))
7485                 fwd_lcores_config_display();
7486         else if (!strcmp(res->what, "fwd"))
7487                 pkt_fwd_config_display(&cur_fwd_config);
7488         else if (!strcmp(res->what, "txpkts"))
7489                 show_tx_pkt_segments();
7490         else if (!strcmp(res->what, "txtimes"))
7491                 show_tx_pkt_times();
7492 }
7493
7494 cmdline_parse_token_string_t cmd_showcfg_show =
7495         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7496 cmdline_parse_token_string_t cmd_showcfg_port =
7497         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7498 cmdline_parse_token_string_t cmd_showcfg_what =
7499         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7500                                  "rxtx#cores#fwd#txpkts#txtimes");
7501
7502 cmdline_parse_inst_t cmd_showcfg = {
7503         .f = cmd_showcfg_parsed,
7504         .data = NULL,
7505         .help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7506         .tokens = {
7507                 (void *)&cmd_showcfg_show,
7508                 (void *)&cmd_showcfg_port,
7509                 (void *)&cmd_showcfg_what,
7510                 NULL,
7511         },
7512 };
7513
7514 /* *** SHOW ALL PORT INFO *** */
7515 struct cmd_showportall_result {
7516         cmdline_fixed_string_t show;
7517         cmdline_fixed_string_t port;
7518         cmdline_fixed_string_t what;
7519         cmdline_fixed_string_t all;
7520 };
7521
7522 static void cmd_showportall_parsed(void *parsed_result,
7523                                 __rte_unused struct cmdline *cl,
7524                                 __rte_unused void *data)
7525 {
7526         portid_t i;
7527
7528         struct cmd_showportall_result *res = parsed_result;
7529         if (!strcmp(res->show, "clear")) {
7530                 if (!strcmp(res->what, "stats"))
7531                         RTE_ETH_FOREACH_DEV(i)
7532                                 nic_stats_clear(i);
7533                 else if (!strcmp(res->what, "xstats"))
7534                         RTE_ETH_FOREACH_DEV(i)
7535                                 nic_xstats_clear(i);
7536         } else if (!strcmp(res->what, "info"))
7537                 RTE_ETH_FOREACH_DEV(i)
7538                         port_infos_display(i);
7539         else if (!strcmp(res->what, "summary")) {
7540                 port_summary_header_display();
7541                 RTE_ETH_FOREACH_DEV(i)
7542                         port_summary_display(i);
7543         }
7544         else if (!strcmp(res->what, "stats"))
7545                 RTE_ETH_FOREACH_DEV(i)
7546                         nic_stats_display(i);
7547         else if (!strcmp(res->what, "xstats"))
7548                 RTE_ETH_FOREACH_DEV(i)
7549                         nic_xstats_display(i);
7550         else if (!strcmp(res->what, "fdir"))
7551                 RTE_ETH_FOREACH_DEV(i)
7552                         fdir_get_infos(i);
7553         else if (!strcmp(res->what, "stat_qmap"))
7554                 RTE_ETH_FOREACH_DEV(i)
7555                         nic_stats_mapping_display(i);
7556         else if (!strcmp(res->what, "dcb_tc"))
7557                 RTE_ETH_FOREACH_DEV(i)
7558                         port_dcb_info_display(i);
7559         else if (!strcmp(res->what, "cap"))
7560                 RTE_ETH_FOREACH_DEV(i)
7561                         port_offload_cap_display(i);
7562 }
7563
7564 cmdline_parse_token_string_t cmd_showportall_show =
7565         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7566                                  "show#clear");
7567 cmdline_parse_token_string_t cmd_showportall_port =
7568         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7569 cmdline_parse_token_string_t cmd_showportall_what =
7570         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7571                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7572 cmdline_parse_token_string_t cmd_showportall_all =
7573         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7574 cmdline_parse_inst_t cmd_showportall = {
7575         .f = cmd_showportall_parsed,
7576         .data = NULL,
7577         .help_str = "show|clear port "
7578                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7579         .tokens = {
7580                 (void *)&cmd_showportall_show,
7581                 (void *)&cmd_showportall_port,
7582                 (void *)&cmd_showportall_what,
7583                 (void *)&cmd_showportall_all,
7584                 NULL,
7585         },
7586 };
7587
7588 /* *** SHOW PORT INFO *** */
7589 struct cmd_showport_result {
7590         cmdline_fixed_string_t show;
7591         cmdline_fixed_string_t port;
7592         cmdline_fixed_string_t what;
7593         uint16_t portnum;
7594 };
7595
7596 static void cmd_showport_parsed(void *parsed_result,
7597                                 __rte_unused struct cmdline *cl,
7598                                 __rte_unused void *data)
7599 {
7600         struct cmd_showport_result *res = parsed_result;
7601         if (!strcmp(res->show, "clear")) {
7602                 if (!strcmp(res->what, "stats"))
7603                         nic_stats_clear(res->portnum);
7604                 else if (!strcmp(res->what, "xstats"))
7605                         nic_xstats_clear(res->portnum);
7606         } else if (!strcmp(res->what, "info"))
7607                 port_infos_display(res->portnum);
7608         else if (!strcmp(res->what, "summary")) {
7609                 port_summary_header_display();
7610                 port_summary_display(res->portnum);
7611         }
7612         else if (!strcmp(res->what, "stats"))
7613                 nic_stats_display(res->portnum);
7614         else if (!strcmp(res->what, "xstats"))
7615                 nic_xstats_display(res->portnum);
7616         else if (!strcmp(res->what, "fdir"))
7617                  fdir_get_infos(res->portnum);
7618         else if (!strcmp(res->what, "stat_qmap"))
7619                 nic_stats_mapping_display(res->portnum);
7620         else if (!strcmp(res->what, "dcb_tc"))
7621                 port_dcb_info_display(res->portnum);
7622         else if (!strcmp(res->what, "cap"))
7623                 port_offload_cap_display(res->portnum);
7624 }
7625
7626 cmdline_parse_token_string_t cmd_showport_show =
7627         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7628                                  "show#clear");
7629 cmdline_parse_token_string_t cmd_showport_port =
7630         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7631 cmdline_parse_token_string_t cmd_showport_what =
7632         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7633                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7634 cmdline_parse_token_num_t cmd_showport_portnum =
7635         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7636
7637 cmdline_parse_inst_t cmd_showport = {
7638         .f = cmd_showport_parsed,
7639         .data = NULL,
7640         .help_str = "show|clear port "
7641                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7642                 "<port_id>",
7643         .tokens = {
7644                 (void *)&cmd_showport_show,
7645                 (void *)&cmd_showport_port,
7646                 (void *)&cmd_showport_what,
7647                 (void *)&cmd_showport_portnum,
7648                 NULL,
7649         },
7650 };
7651
7652 /* *** SHOW DEVICE INFO *** */
7653 struct cmd_showdevice_result {
7654         cmdline_fixed_string_t show;
7655         cmdline_fixed_string_t device;
7656         cmdline_fixed_string_t what;
7657         cmdline_fixed_string_t identifier;
7658 };
7659
7660 static void cmd_showdevice_parsed(void *parsed_result,
7661                                 __rte_unused struct cmdline *cl,
7662                                 __rte_unused void *data)
7663 {
7664         struct cmd_showdevice_result *res = parsed_result;
7665         if (!strcmp(res->what, "info")) {
7666                 if (!strcmp(res->identifier, "all"))
7667                         device_infos_display(NULL);
7668                 else
7669                         device_infos_display(res->identifier);
7670         }
7671 }
7672
7673 cmdline_parse_token_string_t cmd_showdevice_show =
7674         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7675                                  "show");
7676 cmdline_parse_token_string_t cmd_showdevice_device =
7677         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7678 cmdline_parse_token_string_t cmd_showdevice_what =
7679         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7680                                  "info");
7681 cmdline_parse_token_string_t cmd_showdevice_identifier =
7682         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7683                         identifier, NULL);
7684
7685 cmdline_parse_inst_t cmd_showdevice = {
7686         .f = cmd_showdevice_parsed,
7687         .data = NULL,
7688         .help_str = "show device info <identifier>|all",
7689         .tokens = {
7690                 (void *)&cmd_showdevice_show,
7691                 (void *)&cmd_showdevice_device,
7692                 (void *)&cmd_showdevice_what,
7693                 (void *)&cmd_showdevice_identifier,
7694                 NULL,
7695         },
7696 };
7697 /* *** SHOW QUEUE INFO *** */
7698 struct cmd_showqueue_result {
7699         cmdline_fixed_string_t show;
7700         cmdline_fixed_string_t type;
7701         cmdline_fixed_string_t what;
7702         uint16_t portnum;
7703         uint16_t queuenum;
7704 };
7705
7706 static void
7707 cmd_showqueue_parsed(void *parsed_result,
7708         __rte_unused struct cmdline *cl,
7709         __rte_unused void *data)
7710 {
7711         struct cmd_showqueue_result *res = parsed_result;
7712
7713         if (!strcmp(res->type, "rxq"))
7714                 rx_queue_infos_display(res->portnum, res->queuenum);
7715         else if (!strcmp(res->type, "txq"))
7716                 tx_queue_infos_display(res->portnum, res->queuenum);
7717 }
7718
7719 cmdline_parse_token_string_t cmd_showqueue_show =
7720         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7721 cmdline_parse_token_string_t cmd_showqueue_type =
7722         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7723 cmdline_parse_token_string_t cmd_showqueue_what =
7724         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7725 cmdline_parse_token_num_t cmd_showqueue_portnum =
7726         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7727 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7728         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7729
7730 cmdline_parse_inst_t cmd_showqueue = {
7731         .f = cmd_showqueue_parsed,
7732         .data = NULL,
7733         .help_str = "show rxq|txq info <port_id> <queue_id>",
7734         .tokens = {
7735                 (void *)&cmd_showqueue_show,
7736                 (void *)&cmd_showqueue_type,
7737                 (void *)&cmd_showqueue_what,
7738                 (void *)&cmd_showqueue_portnum,
7739                 (void *)&cmd_showqueue_queuenum,
7740                 NULL,
7741         },
7742 };
7743
7744 /* show/clear fwd engine statistics */
7745 struct fwd_result {
7746         cmdline_fixed_string_t action;
7747         cmdline_fixed_string_t fwd;
7748         cmdline_fixed_string_t stats;
7749         cmdline_fixed_string_t all;
7750 };
7751
7752 cmdline_parse_token_string_t cmd_fwd_action =
7753         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7754 cmdline_parse_token_string_t cmd_fwd_fwd =
7755         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7756 cmdline_parse_token_string_t cmd_fwd_stats =
7757         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7758 cmdline_parse_token_string_t cmd_fwd_all =
7759         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7760
7761 static void
7762 cmd_showfwdall_parsed(void *parsed_result,
7763                       __rte_unused struct cmdline *cl,
7764                       __rte_unused void *data)
7765 {
7766         struct fwd_result *res = parsed_result;
7767
7768         if (!strcmp(res->action, "show"))
7769                 fwd_stats_display();
7770         else
7771                 fwd_stats_reset();
7772 }
7773
7774 static cmdline_parse_inst_t cmd_showfwdall = {
7775         .f = cmd_showfwdall_parsed,
7776         .data = NULL,
7777         .help_str = "show|clear fwd stats all",
7778         .tokens = {
7779                 (void *)&cmd_fwd_action,
7780                 (void *)&cmd_fwd_fwd,
7781                 (void *)&cmd_fwd_stats,
7782                 (void *)&cmd_fwd_all,
7783                 NULL,
7784         },
7785 };
7786
7787 /* *** READ PORT REGISTER *** */
7788 struct cmd_read_reg_result {
7789         cmdline_fixed_string_t read;
7790         cmdline_fixed_string_t reg;
7791         portid_t port_id;
7792         uint32_t reg_off;
7793 };
7794
7795 static void
7796 cmd_read_reg_parsed(void *parsed_result,
7797                     __rte_unused struct cmdline *cl,
7798                     __rte_unused void *data)
7799 {
7800         struct cmd_read_reg_result *res = parsed_result;
7801         port_reg_display(res->port_id, res->reg_off);
7802 }
7803
7804 cmdline_parse_token_string_t cmd_read_reg_read =
7805         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7806 cmdline_parse_token_string_t cmd_read_reg_reg =
7807         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7808 cmdline_parse_token_num_t cmd_read_reg_port_id =
7809         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7810 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7811         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7812
7813 cmdline_parse_inst_t cmd_read_reg = {
7814         .f = cmd_read_reg_parsed,
7815         .data = NULL,
7816         .help_str = "read reg <port_id> <reg_off>",
7817         .tokens = {
7818                 (void *)&cmd_read_reg_read,
7819                 (void *)&cmd_read_reg_reg,
7820                 (void *)&cmd_read_reg_port_id,
7821                 (void *)&cmd_read_reg_reg_off,
7822                 NULL,
7823         },
7824 };
7825
7826 /* *** READ PORT REGISTER BIT FIELD *** */
7827 struct cmd_read_reg_bit_field_result {
7828         cmdline_fixed_string_t read;
7829         cmdline_fixed_string_t regfield;
7830         portid_t port_id;
7831         uint32_t reg_off;
7832         uint8_t bit1_pos;
7833         uint8_t bit2_pos;
7834 };
7835
7836 static void
7837 cmd_read_reg_bit_field_parsed(void *parsed_result,
7838                               __rte_unused struct cmdline *cl,
7839                               __rte_unused void *data)
7840 {
7841         struct cmd_read_reg_bit_field_result *res = parsed_result;
7842         port_reg_bit_field_display(res->port_id, res->reg_off,
7843                                    res->bit1_pos, res->bit2_pos);
7844 }
7845
7846 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7847         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7848                                  "read");
7849 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7850         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7851                                  regfield, "regfield");
7852 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7853         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7854                               UINT16);
7855 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7856         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7857                               UINT32);
7858 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7859         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7860                               UINT8);
7861 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7862         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7863                               UINT8);
7864
7865 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7866         .f = cmd_read_reg_bit_field_parsed,
7867         .data = NULL,
7868         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7869         "Read register bit field between bit_x and bit_y included",
7870         .tokens = {
7871                 (void *)&cmd_read_reg_bit_field_read,
7872                 (void *)&cmd_read_reg_bit_field_regfield,
7873                 (void *)&cmd_read_reg_bit_field_port_id,
7874                 (void *)&cmd_read_reg_bit_field_reg_off,
7875                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7876                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7877                 NULL,
7878         },
7879 };
7880
7881 /* *** READ PORT REGISTER BIT *** */
7882 struct cmd_read_reg_bit_result {
7883         cmdline_fixed_string_t read;
7884         cmdline_fixed_string_t regbit;
7885         portid_t port_id;
7886         uint32_t reg_off;
7887         uint8_t bit_pos;
7888 };
7889
7890 static void
7891 cmd_read_reg_bit_parsed(void *parsed_result,
7892                         __rte_unused struct cmdline *cl,
7893                         __rte_unused void *data)
7894 {
7895         struct cmd_read_reg_bit_result *res = parsed_result;
7896         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7897 }
7898
7899 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7900         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7901 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7902         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7903                                  regbit, "regbit");
7904 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
7905         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
7906 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
7907         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
7908 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
7909         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
7910
7911 cmdline_parse_inst_t cmd_read_reg_bit = {
7912         .f = cmd_read_reg_bit_parsed,
7913         .data = NULL,
7914         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
7915         .tokens = {
7916                 (void *)&cmd_read_reg_bit_read,
7917                 (void *)&cmd_read_reg_bit_regbit,
7918                 (void *)&cmd_read_reg_bit_port_id,
7919                 (void *)&cmd_read_reg_bit_reg_off,
7920                 (void *)&cmd_read_reg_bit_bit_pos,
7921                 NULL,
7922         },
7923 };
7924
7925 /* *** WRITE PORT REGISTER *** */
7926 struct cmd_write_reg_result {
7927         cmdline_fixed_string_t write;
7928         cmdline_fixed_string_t reg;
7929         portid_t port_id;
7930         uint32_t reg_off;
7931         uint32_t value;
7932 };
7933
7934 static void
7935 cmd_write_reg_parsed(void *parsed_result,
7936                      __rte_unused struct cmdline *cl,
7937                      __rte_unused void *data)
7938 {
7939         struct cmd_write_reg_result *res = parsed_result;
7940         port_reg_set(res->port_id, res->reg_off, res->value);
7941 }
7942
7943 cmdline_parse_token_string_t cmd_write_reg_write =
7944         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
7945 cmdline_parse_token_string_t cmd_write_reg_reg =
7946         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
7947 cmdline_parse_token_num_t cmd_write_reg_port_id =
7948         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
7949 cmdline_parse_token_num_t cmd_write_reg_reg_off =
7950         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
7951 cmdline_parse_token_num_t cmd_write_reg_value =
7952         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
7953
7954 cmdline_parse_inst_t cmd_write_reg = {
7955         .f = cmd_write_reg_parsed,
7956         .data = NULL,
7957         .help_str = "write reg <port_id> <reg_off> <reg_value>",
7958         .tokens = {
7959                 (void *)&cmd_write_reg_write,
7960                 (void *)&cmd_write_reg_reg,
7961                 (void *)&cmd_write_reg_port_id,
7962                 (void *)&cmd_write_reg_reg_off,
7963                 (void *)&cmd_write_reg_value,
7964                 NULL,
7965         },
7966 };
7967
7968 /* *** WRITE PORT REGISTER BIT FIELD *** */
7969 struct cmd_write_reg_bit_field_result {
7970         cmdline_fixed_string_t write;
7971         cmdline_fixed_string_t regfield;
7972         portid_t port_id;
7973         uint32_t reg_off;
7974         uint8_t bit1_pos;
7975         uint8_t bit2_pos;
7976         uint32_t value;
7977 };
7978
7979 static void
7980 cmd_write_reg_bit_field_parsed(void *parsed_result,
7981                                __rte_unused struct cmdline *cl,
7982                                __rte_unused void *data)
7983 {
7984         struct cmd_write_reg_bit_field_result *res = parsed_result;
7985         port_reg_bit_field_set(res->port_id, res->reg_off,
7986                           res->bit1_pos, res->bit2_pos, res->value);
7987 }
7988
7989 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
7990         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
7991                                  "write");
7992 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
7993         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
7994                                  regfield, "regfield");
7995 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
7996         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
7997                               UINT16);
7998 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
7999         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8000                               UINT32);
8001 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8002         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8003                               UINT8);
8004 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8005         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8006                               UINT8);
8007 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8008         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8009                               UINT32);
8010
8011 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8012         .f = cmd_write_reg_bit_field_parsed,
8013         .data = NULL,
8014         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8015                 "<reg_value>: "
8016                 "Set register bit field between bit_x and bit_y included",
8017         .tokens = {
8018                 (void *)&cmd_write_reg_bit_field_write,
8019                 (void *)&cmd_write_reg_bit_field_regfield,
8020                 (void *)&cmd_write_reg_bit_field_port_id,
8021                 (void *)&cmd_write_reg_bit_field_reg_off,
8022                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8023                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8024                 (void *)&cmd_write_reg_bit_field_value,
8025                 NULL,
8026         },
8027 };
8028
8029 /* *** WRITE PORT REGISTER BIT *** */
8030 struct cmd_write_reg_bit_result {
8031         cmdline_fixed_string_t write;
8032         cmdline_fixed_string_t regbit;
8033         portid_t port_id;
8034         uint32_t reg_off;
8035         uint8_t bit_pos;
8036         uint8_t value;
8037 };
8038
8039 static void
8040 cmd_write_reg_bit_parsed(void *parsed_result,
8041                          __rte_unused struct cmdline *cl,
8042                          __rte_unused void *data)
8043 {
8044         struct cmd_write_reg_bit_result *res = parsed_result;
8045         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8046 }
8047
8048 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8049         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8050                                  "write");
8051 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8052         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8053                                  regbit, "regbit");
8054 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8055         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8056 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8057         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8058 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8059         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8060 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8061         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8062
8063 cmdline_parse_inst_t cmd_write_reg_bit = {
8064         .f = cmd_write_reg_bit_parsed,
8065         .data = NULL,
8066         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8067                 "0 <= bit_x <= 31",
8068         .tokens = {
8069                 (void *)&cmd_write_reg_bit_write,
8070                 (void *)&cmd_write_reg_bit_regbit,
8071                 (void *)&cmd_write_reg_bit_port_id,
8072                 (void *)&cmd_write_reg_bit_reg_off,
8073                 (void *)&cmd_write_reg_bit_bit_pos,
8074                 (void *)&cmd_write_reg_bit_value,
8075                 NULL,
8076         },
8077 };
8078
8079 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8080 struct cmd_read_rxd_txd_result {
8081         cmdline_fixed_string_t read;
8082         cmdline_fixed_string_t rxd_txd;
8083         portid_t port_id;
8084         uint16_t queue_id;
8085         uint16_t desc_id;
8086 };
8087
8088 static void
8089 cmd_read_rxd_txd_parsed(void *parsed_result,
8090                         __rte_unused struct cmdline *cl,
8091                         __rte_unused void *data)
8092 {
8093         struct cmd_read_rxd_txd_result *res = parsed_result;
8094
8095         if (!strcmp(res->rxd_txd, "rxd"))
8096                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8097         else if (!strcmp(res->rxd_txd, "txd"))
8098                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8099 }
8100
8101 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8102         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8103 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8104         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8105                                  "rxd#txd");
8106 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8107         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8108 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8109         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8110 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8111         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8112
8113 cmdline_parse_inst_t cmd_read_rxd_txd = {
8114         .f = cmd_read_rxd_txd_parsed,
8115         .data = NULL,
8116         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8117         .tokens = {
8118                 (void *)&cmd_read_rxd_txd_read,
8119                 (void *)&cmd_read_rxd_txd_rxd_txd,
8120                 (void *)&cmd_read_rxd_txd_port_id,
8121                 (void *)&cmd_read_rxd_txd_queue_id,
8122                 (void *)&cmd_read_rxd_txd_desc_id,
8123                 NULL,
8124         },
8125 };
8126
8127 /* *** QUIT *** */
8128 struct cmd_quit_result {
8129         cmdline_fixed_string_t quit;
8130 };
8131
8132 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8133                             struct cmdline *cl,
8134                             __rte_unused void *data)
8135 {
8136         cmdline_quit(cl);
8137 }
8138
8139 cmdline_parse_token_string_t cmd_quit_quit =
8140         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8141
8142 cmdline_parse_inst_t cmd_quit = {
8143         .f = cmd_quit_parsed,
8144         .data = NULL,
8145         .help_str = "quit: Exit application",
8146         .tokens = {
8147                 (void *)&cmd_quit_quit,
8148                 NULL,
8149         },
8150 };
8151
8152 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8153 struct cmd_mac_addr_result {
8154         cmdline_fixed_string_t mac_addr_cmd;
8155         cmdline_fixed_string_t what;
8156         uint16_t port_num;
8157         struct rte_ether_addr address;
8158 };
8159
8160 static void cmd_mac_addr_parsed(void *parsed_result,
8161                 __rte_unused struct cmdline *cl,
8162                 __rte_unused void *data)
8163 {
8164         struct cmd_mac_addr_result *res = parsed_result;
8165         int ret;
8166
8167         if (strcmp(res->what, "add") == 0)
8168                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8169         else if (strcmp(res->what, "set") == 0)
8170                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8171                                                        &res->address);
8172         else
8173                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8174
8175         /* check the return value and print it if is < 0 */
8176         if(ret < 0)
8177                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8178
8179 }
8180
8181 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8182         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8183                                 "mac_addr");
8184 cmdline_parse_token_string_t cmd_mac_addr_what =
8185         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8186                                 "add#remove#set");
8187 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8188                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8189                                         UINT16);
8190 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8191                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8192
8193 cmdline_parse_inst_t cmd_mac_addr = {
8194         .f = cmd_mac_addr_parsed,
8195         .data = (void *)0,
8196         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8197                         "Add/Remove/Set MAC address on port_id",
8198         .tokens = {
8199                 (void *)&cmd_mac_addr_cmd,
8200                 (void *)&cmd_mac_addr_what,
8201                 (void *)&cmd_mac_addr_portnum,
8202                 (void *)&cmd_mac_addr_addr,
8203                 NULL,
8204         },
8205 };
8206
8207 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8208 struct cmd_eth_peer_result {
8209         cmdline_fixed_string_t set;
8210         cmdline_fixed_string_t eth_peer;
8211         portid_t port_id;
8212         cmdline_fixed_string_t peer_addr;
8213 };
8214
8215 static void cmd_set_eth_peer_parsed(void *parsed_result,
8216                         __rte_unused struct cmdline *cl,
8217                         __rte_unused void *data)
8218 {
8219                 struct cmd_eth_peer_result *res = parsed_result;
8220
8221                 if (test_done == 0) {
8222                         printf("Please stop forwarding first\n");
8223                         return;
8224                 }
8225                 if (!strcmp(res->eth_peer, "eth-peer")) {
8226                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8227                         fwd_config_setup();
8228                 }
8229 }
8230 cmdline_parse_token_string_t cmd_eth_peer_set =
8231         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8232 cmdline_parse_token_string_t cmd_eth_peer =
8233         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8234 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8235         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8236 cmdline_parse_token_string_t cmd_eth_peer_addr =
8237         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8238
8239 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8240         .f = cmd_set_eth_peer_parsed,
8241         .data = NULL,
8242         .help_str = "set eth-peer <port_id> <peer_mac>",
8243         .tokens = {
8244                 (void *)&cmd_eth_peer_set,
8245                 (void *)&cmd_eth_peer,
8246                 (void *)&cmd_eth_peer_port_id,
8247                 (void *)&cmd_eth_peer_addr,
8248                 NULL,
8249         },
8250 };
8251
8252 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8253 struct cmd_set_qmap_result {
8254         cmdline_fixed_string_t set;
8255         cmdline_fixed_string_t qmap;
8256         cmdline_fixed_string_t what;
8257         portid_t port_id;
8258         uint16_t queue_id;
8259         uint8_t map_value;
8260 };
8261
8262 static void
8263 cmd_set_qmap_parsed(void *parsed_result,
8264                        __rte_unused struct cmdline *cl,
8265                        __rte_unused void *data)
8266 {
8267         struct cmd_set_qmap_result *res = parsed_result;
8268         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8269
8270         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8271 }
8272
8273 cmdline_parse_token_string_t cmd_setqmap_set =
8274         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8275                                  set, "set");
8276 cmdline_parse_token_string_t cmd_setqmap_qmap =
8277         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8278                                  qmap, "stat_qmap");
8279 cmdline_parse_token_string_t cmd_setqmap_what =
8280         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8281                                  what, "tx#rx");
8282 cmdline_parse_token_num_t cmd_setqmap_portid =
8283         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8284                               port_id, UINT16);
8285 cmdline_parse_token_num_t cmd_setqmap_queueid =
8286         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8287                               queue_id, UINT16);
8288 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8289         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8290                               map_value, UINT8);
8291
8292 cmdline_parse_inst_t cmd_set_qmap = {
8293         .f = cmd_set_qmap_parsed,
8294         .data = NULL,
8295         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8296                 "Set statistics mapping value on tx|rx queue_id of port_id",
8297         .tokens = {
8298                 (void *)&cmd_setqmap_set,
8299                 (void *)&cmd_setqmap_qmap,
8300                 (void *)&cmd_setqmap_what,
8301                 (void *)&cmd_setqmap_portid,
8302                 (void *)&cmd_setqmap_queueid,
8303                 (void *)&cmd_setqmap_mapvalue,
8304                 NULL,
8305         },
8306 };
8307
8308 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8309 struct cmd_set_xstats_hide_zero_result {
8310         cmdline_fixed_string_t keyword;
8311         cmdline_fixed_string_t name;
8312         cmdline_fixed_string_t on_off;
8313 };
8314
8315 static void
8316 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8317                         __rte_unused struct cmdline *cl,
8318                         __rte_unused void *data)
8319 {
8320         struct cmd_set_xstats_hide_zero_result *res;
8321         uint16_t on_off = 0;
8322
8323         res = parsed_result;
8324         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8325         set_xstats_hide_zero(on_off);
8326 }
8327
8328 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8329         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8330                                  keyword, "set");
8331 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8333                                  name, "xstats-hide-zero");
8334 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8335         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8336                                  on_off, "on#off");
8337
8338 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8339         .f = cmd_set_xstats_hide_zero_parsed,
8340         .data = NULL,
8341         .help_str = "set xstats-hide-zero on|off",
8342         .tokens = {
8343                 (void *)&cmd_set_xstats_hide_zero_keyword,
8344                 (void *)&cmd_set_xstats_hide_zero_name,
8345                 (void *)&cmd_set_xstats_hide_zero_on_off,
8346                 NULL,
8347         },
8348 };
8349
8350 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8351 struct cmd_set_record_core_cycles_result {
8352         cmdline_fixed_string_t keyword;
8353         cmdline_fixed_string_t name;
8354         cmdline_fixed_string_t on_off;
8355 };
8356
8357 static void
8358 cmd_set_record_core_cycles_parsed(void *parsed_result,
8359                         __rte_unused struct cmdline *cl,
8360                         __rte_unused void *data)
8361 {
8362         struct cmd_set_record_core_cycles_result *res;
8363         uint16_t on_off = 0;
8364
8365         res = parsed_result;
8366         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8367         set_record_core_cycles(on_off);
8368 }
8369
8370 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8371         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8372                                  keyword, "set");
8373 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8374         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8375                                  name, "record-core-cycles");
8376 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8377         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8378                                  on_off, "on#off");
8379
8380 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8381         .f = cmd_set_record_core_cycles_parsed,
8382         .data = NULL,
8383         .help_str = "set record-core-cycles on|off",
8384         .tokens = {
8385                 (void *)&cmd_set_record_core_cycles_keyword,
8386                 (void *)&cmd_set_record_core_cycles_name,
8387                 (void *)&cmd_set_record_core_cycles_on_off,
8388                 NULL,
8389         },
8390 };
8391
8392 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8393 struct cmd_set_record_burst_stats_result {
8394         cmdline_fixed_string_t keyword;
8395         cmdline_fixed_string_t name;
8396         cmdline_fixed_string_t on_off;
8397 };
8398
8399 static void
8400 cmd_set_record_burst_stats_parsed(void *parsed_result,
8401                         __rte_unused struct cmdline *cl,
8402                         __rte_unused void *data)
8403 {
8404         struct cmd_set_record_burst_stats_result *res;
8405         uint16_t on_off = 0;
8406
8407         res = parsed_result;
8408         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8409         set_record_burst_stats(on_off);
8410 }
8411
8412 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8413         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8414                                  keyword, "set");
8415 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8416         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8417                                  name, "record-burst-stats");
8418 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8419         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8420                                  on_off, "on#off");
8421
8422 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8423         .f = cmd_set_record_burst_stats_parsed,
8424         .data = NULL,
8425         .help_str = "set record-burst-stats on|off",
8426         .tokens = {
8427                 (void *)&cmd_set_record_burst_stats_keyword,
8428                 (void *)&cmd_set_record_burst_stats_name,
8429                 (void *)&cmd_set_record_burst_stats_on_off,
8430                 NULL,
8431         },
8432 };
8433
8434 /* *** CONFIGURE UNICAST HASH TABLE *** */
8435 struct cmd_set_uc_hash_table {
8436         cmdline_fixed_string_t set;
8437         cmdline_fixed_string_t port;
8438         portid_t port_id;
8439         cmdline_fixed_string_t what;
8440         struct rte_ether_addr address;
8441         cmdline_fixed_string_t mode;
8442 };
8443
8444 static void
8445 cmd_set_uc_hash_parsed(void *parsed_result,
8446                        __rte_unused struct cmdline *cl,
8447                        __rte_unused void *data)
8448 {
8449         int ret=0;
8450         struct cmd_set_uc_hash_table *res = parsed_result;
8451
8452         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8453
8454         if (strcmp(res->what, "uta") == 0)
8455                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8456                                                 &res->address,(uint8_t)is_on);
8457         if (ret < 0)
8458                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8459
8460 }
8461
8462 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8463         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8464                                  set, "set");
8465 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8466         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8467                                  port, "port");
8468 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8469         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8470                               port_id, UINT16);
8471 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8473                                  what, "uta");
8474 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8475         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8476                                 address);
8477 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8478         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8479                                  mode, "on#off");
8480
8481 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8482         .f = cmd_set_uc_hash_parsed,
8483         .data = NULL,
8484         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8485         .tokens = {
8486                 (void *)&cmd_set_uc_hash_set,
8487                 (void *)&cmd_set_uc_hash_port,
8488                 (void *)&cmd_set_uc_hash_portid,
8489                 (void *)&cmd_set_uc_hash_what,
8490                 (void *)&cmd_set_uc_hash_mac,
8491                 (void *)&cmd_set_uc_hash_mode,
8492                 NULL,
8493         },
8494 };
8495
8496 struct cmd_set_uc_all_hash_table {
8497         cmdline_fixed_string_t set;
8498         cmdline_fixed_string_t port;
8499         portid_t port_id;
8500         cmdline_fixed_string_t what;
8501         cmdline_fixed_string_t value;
8502         cmdline_fixed_string_t mode;
8503 };
8504
8505 static void
8506 cmd_set_uc_all_hash_parsed(void *parsed_result,
8507                        __rte_unused struct cmdline *cl,
8508                        __rte_unused void *data)
8509 {
8510         int ret=0;
8511         struct cmd_set_uc_all_hash_table *res = parsed_result;
8512
8513         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8514
8515         if ((strcmp(res->what, "uta") == 0) &&
8516                 (strcmp(res->value, "all") == 0))
8517                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8518         if (ret < 0)
8519                 printf("bad unicast hash table parameter,"
8520                         "return code = %d \n", ret);
8521 }
8522
8523 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8524         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8525                                  set, "set");
8526 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8527         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8528                                  port, "port");
8529 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8530         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8531                               port_id, UINT16);
8532 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8533         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8534                                  what, "uta");
8535 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8536         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8537                                 value,"all");
8538 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8539         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8540                                  mode, "on#off");
8541
8542 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8543         .f = cmd_set_uc_all_hash_parsed,
8544         .data = NULL,
8545         .help_str = "set port <port_id> uta all on|off",
8546         .tokens = {
8547                 (void *)&cmd_set_uc_all_hash_set,
8548                 (void *)&cmd_set_uc_all_hash_port,
8549                 (void *)&cmd_set_uc_all_hash_portid,
8550                 (void *)&cmd_set_uc_all_hash_what,
8551                 (void *)&cmd_set_uc_all_hash_value,
8552                 (void *)&cmd_set_uc_all_hash_mode,
8553                 NULL,
8554         },
8555 };
8556
8557 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8558 struct cmd_set_vf_macvlan_filter {
8559         cmdline_fixed_string_t set;
8560         cmdline_fixed_string_t port;
8561         portid_t port_id;
8562         cmdline_fixed_string_t vf;
8563         uint8_t vf_id;
8564         struct rte_ether_addr address;
8565         cmdline_fixed_string_t filter_type;
8566         cmdline_fixed_string_t mode;
8567 };
8568
8569 static void
8570 cmd_set_vf_macvlan_parsed(void *parsed_result,
8571                        __rte_unused struct cmdline *cl,
8572                        __rte_unused void *data)
8573 {
8574         int is_on, ret = 0;
8575         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8576         struct rte_eth_mac_filter filter;
8577
8578         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8579
8580         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8581
8582         /* set VF MAC filter */
8583         filter.is_vf = 1;
8584
8585         /* set VF ID */
8586         filter.dst_id = res->vf_id;
8587
8588         if (!strcmp(res->filter_type, "exact-mac"))
8589                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8590         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8591                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8592         else if (!strcmp(res->filter_type, "hashmac"))
8593                 filter.filter_type = RTE_MAC_HASH_MATCH;
8594         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8595                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8596
8597         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8598
8599         if (is_on)
8600                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8601                                         RTE_ETH_FILTER_MACVLAN,
8602                                         RTE_ETH_FILTER_ADD,
8603                                          &filter);
8604         else
8605                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8606                                         RTE_ETH_FILTER_MACVLAN,
8607                                         RTE_ETH_FILTER_DELETE,
8608                                         &filter);
8609
8610         if (ret < 0)
8611                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8612
8613 }
8614
8615 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8617                                  set, "set");
8618 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8620                                  port, "port");
8621 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8622         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8623                               port_id, UINT16);
8624 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8625         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8626                                  vf, "vf");
8627 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8628         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8629                                 vf_id, UINT8);
8630 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8631         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8632                                 address);
8633 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8635                                 filter_type, "exact-mac#exact-mac-vlan"
8636                                 "#hashmac#hashmac-vlan");
8637 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8638         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8639                                  mode, "on#off");
8640
8641 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8642         .f = cmd_set_vf_macvlan_parsed,
8643         .data = NULL,
8644         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8645                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8646                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8647                 "hash match rule: hash match of MAC and exact match of VLAN",
8648         .tokens = {
8649                 (void *)&cmd_set_vf_macvlan_set,
8650                 (void *)&cmd_set_vf_macvlan_port,
8651                 (void *)&cmd_set_vf_macvlan_portid,
8652                 (void *)&cmd_set_vf_macvlan_vf,
8653                 (void *)&cmd_set_vf_macvlan_vf_id,
8654                 (void *)&cmd_set_vf_macvlan_mac,
8655                 (void *)&cmd_set_vf_macvlan_filter_type,
8656                 (void *)&cmd_set_vf_macvlan_mode,
8657                 NULL,
8658         },
8659 };
8660
8661 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8662 struct cmd_set_vf_traffic {
8663         cmdline_fixed_string_t set;
8664         cmdline_fixed_string_t port;
8665         portid_t port_id;
8666         cmdline_fixed_string_t vf;
8667         uint8_t vf_id;
8668         cmdline_fixed_string_t what;
8669         cmdline_fixed_string_t mode;
8670 };
8671
8672 static void
8673 cmd_set_vf_traffic_parsed(void *parsed_result,
8674                        __rte_unused struct cmdline *cl,
8675                        __rte_unused void *data)
8676 {
8677         struct cmd_set_vf_traffic *res = parsed_result;
8678         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8679         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8680
8681         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8682 }
8683
8684 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8685         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8686                                  set, "set");
8687 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8688         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8689                                  port, "port");
8690 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8691         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8692                               port_id, UINT16);
8693 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8694         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8695                                  vf, "vf");
8696 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8697         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8698                               vf_id, UINT8);
8699 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8700         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8701                                  what, "tx#rx");
8702 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8703         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8704                                  mode, "on#off");
8705
8706 cmdline_parse_inst_t cmd_set_vf_traffic = {
8707         .f = cmd_set_vf_traffic_parsed,
8708         .data = NULL,
8709         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8710         .tokens = {
8711                 (void *)&cmd_setvf_traffic_set,
8712                 (void *)&cmd_setvf_traffic_port,
8713                 (void *)&cmd_setvf_traffic_portid,
8714                 (void *)&cmd_setvf_traffic_vf,
8715                 (void *)&cmd_setvf_traffic_vfid,
8716                 (void *)&cmd_setvf_traffic_what,
8717                 (void *)&cmd_setvf_traffic_mode,
8718                 NULL,
8719         },
8720 };
8721
8722 /* *** CONFIGURE VF RECEIVE MODE *** */
8723 struct cmd_set_vf_rxmode {
8724         cmdline_fixed_string_t set;
8725         cmdline_fixed_string_t port;
8726         portid_t port_id;
8727         cmdline_fixed_string_t vf;
8728         uint8_t vf_id;
8729         cmdline_fixed_string_t what;
8730         cmdline_fixed_string_t mode;
8731         cmdline_fixed_string_t on;
8732 };
8733
8734 static void
8735 cmd_set_vf_rxmode_parsed(void *parsed_result,
8736                        __rte_unused struct cmdline *cl,
8737                        __rte_unused void *data)
8738 {
8739         int ret = -ENOTSUP;
8740         uint16_t vf_rxmode = 0;
8741         struct cmd_set_vf_rxmode *res = parsed_result;
8742
8743         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8744         if (!strcmp(res->what,"rxmode")) {
8745                 if (!strcmp(res->mode, "AUPE"))
8746                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8747                 else if (!strcmp(res->mode, "ROPE"))
8748                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8749                 else if (!strcmp(res->mode, "BAM"))
8750                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8751                 else if (!strncmp(res->mode, "MPE",3))
8752                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8753         }
8754
8755         RTE_SET_USED(is_on);
8756
8757 #ifdef RTE_LIBRTE_IXGBE_PMD
8758         if (ret == -ENOTSUP)
8759                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8760                                                   vf_rxmode, (uint8_t)is_on);
8761 #endif
8762 #ifdef RTE_LIBRTE_BNXT_PMD
8763         if (ret == -ENOTSUP)
8764                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8765                                                  vf_rxmode, (uint8_t)is_on);
8766 #endif
8767         if (ret < 0)
8768                 printf("bad VF receive mode parameter, return code = %d \n",
8769                 ret);
8770 }
8771
8772 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8773         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8774                                  set, "set");
8775 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8776         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8777                                  port, "port");
8778 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8779         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8780                               port_id, UINT16);
8781 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8782         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8783                                  vf, "vf");
8784 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8785         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8786                               vf_id, UINT8);
8787 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8788         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8789                                  what, "rxmode");
8790 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8791         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8792                                  mode, "AUPE#ROPE#BAM#MPE");
8793 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8794         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8795                                  on, "on#off");
8796
8797 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8798         .f = cmd_set_vf_rxmode_parsed,
8799         .data = NULL,
8800         .help_str = "set port <port_id> vf <vf_id> rxmode "
8801                 "AUPE|ROPE|BAM|MPE on|off",
8802         .tokens = {
8803                 (void *)&cmd_set_vf_rxmode_set,
8804                 (void *)&cmd_set_vf_rxmode_port,
8805                 (void *)&cmd_set_vf_rxmode_portid,
8806                 (void *)&cmd_set_vf_rxmode_vf,
8807                 (void *)&cmd_set_vf_rxmode_vfid,
8808                 (void *)&cmd_set_vf_rxmode_what,
8809                 (void *)&cmd_set_vf_rxmode_mode,
8810                 (void *)&cmd_set_vf_rxmode_on,
8811                 NULL,
8812         },
8813 };
8814
8815 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8816 struct cmd_vf_mac_addr_result {
8817         cmdline_fixed_string_t mac_addr_cmd;
8818         cmdline_fixed_string_t what;
8819         cmdline_fixed_string_t port;
8820         uint16_t port_num;
8821         cmdline_fixed_string_t vf;
8822         uint8_t vf_num;
8823         struct rte_ether_addr address;
8824 };
8825
8826 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8827                 __rte_unused struct cmdline *cl,
8828                 __rte_unused void *data)
8829 {
8830         struct cmd_vf_mac_addr_result *res = parsed_result;
8831         int ret = -ENOTSUP;
8832
8833         if (strcmp(res->what, "add") != 0)
8834                 return;
8835
8836 #ifdef RTE_LIBRTE_I40E_PMD
8837         if (ret == -ENOTSUP)
8838                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8839                                                    &res->address);
8840 #endif
8841 #ifdef RTE_LIBRTE_BNXT_PMD
8842         if (ret == -ENOTSUP)
8843                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8844                                                 res->vf_num);
8845 #endif
8846
8847         if(ret < 0)
8848                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8849
8850 }
8851
8852 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8853         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8854                                 mac_addr_cmd,"mac_addr");
8855 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8856         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8857                                 what,"add");
8858 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8859         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8860                                 port,"port");
8861 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8862         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8863                                 port_num, UINT16);
8864 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8865         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8866                                 vf,"vf");
8867 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8868         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8869                                 vf_num, UINT8);
8870 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8871         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8872                                 address);
8873
8874 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8875         .f = cmd_vf_mac_addr_parsed,
8876         .data = (void *)0,
8877         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8878                 "Add MAC address filtering for a VF on port_id",
8879         .tokens = {
8880                 (void *)&cmd_vf_mac_addr_cmd,
8881                 (void *)&cmd_vf_mac_addr_what,
8882                 (void *)&cmd_vf_mac_addr_port,
8883                 (void *)&cmd_vf_mac_addr_portnum,
8884                 (void *)&cmd_vf_mac_addr_vf,
8885                 (void *)&cmd_vf_mac_addr_vfnum,
8886                 (void *)&cmd_vf_mac_addr_addr,
8887                 NULL,
8888         },
8889 };
8890
8891 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8892 struct cmd_vf_rx_vlan_filter {
8893         cmdline_fixed_string_t rx_vlan;
8894         cmdline_fixed_string_t what;
8895         uint16_t vlan_id;
8896         cmdline_fixed_string_t port;
8897         portid_t port_id;
8898         cmdline_fixed_string_t vf;
8899         uint64_t vf_mask;
8900 };
8901
8902 static void
8903 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8904                           __rte_unused struct cmdline *cl,
8905                           __rte_unused void *data)
8906 {
8907         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8908         int ret = -ENOTSUP;
8909
8910         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8911
8912 #ifdef RTE_LIBRTE_IXGBE_PMD
8913         if (ret == -ENOTSUP)
8914                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8915                                 res->vlan_id, res->vf_mask, is_add);
8916 #endif
8917 #ifdef RTE_LIBRTE_I40E_PMD
8918         if (ret == -ENOTSUP)
8919                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8920                                 res->vlan_id, res->vf_mask, is_add);
8921 #endif
8922 #ifdef RTE_LIBRTE_BNXT_PMD
8923         if (ret == -ENOTSUP)
8924                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8925                                 res->vlan_id, res->vf_mask, is_add);
8926 #endif
8927
8928         switch (ret) {
8929         case 0:
8930                 break;
8931         case -EINVAL:
8932                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8933                                 res->vlan_id, res->vf_mask);
8934                 break;
8935         case -ENODEV:
8936                 printf("invalid port_id %d\n", res->port_id);
8937                 break;
8938         case -ENOTSUP:
8939                 printf("function not implemented or supported\n");
8940                 break;
8941         default:
8942                 printf("programming error: (%s)\n", strerror(-ret));
8943         }
8944 }
8945
8946 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8947         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8948                                  rx_vlan, "rx_vlan");
8949 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8950         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8951                                  what, "add#rm");
8952 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8953         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8954                               vlan_id, UINT16);
8955 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8956         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8957                                  port, "port");
8958 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8959         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8960                               port_id, UINT16);
8961 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8962         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8963                                  vf, "vf");
8964 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8965         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8966                               vf_mask, UINT64);
8967
8968 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8969         .f = cmd_vf_rx_vlan_filter_parsed,
8970         .data = NULL,
8971         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
8972                 "(vf_mask = hexadecimal VF mask)",
8973         .tokens = {
8974                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
8975                 (void *)&cmd_vf_rx_vlan_filter_what,
8976                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
8977                 (void *)&cmd_vf_rx_vlan_filter_port,
8978                 (void *)&cmd_vf_rx_vlan_filter_portid,
8979                 (void *)&cmd_vf_rx_vlan_filter_vf,
8980                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
8981                 NULL,
8982         },
8983 };
8984
8985 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
8986 struct cmd_queue_rate_limit_result {
8987         cmdline_fixed_string_t set;
8988         cmdline_fixed_string_t port;
8989         uint16_t port_num;
8990         cmdline_fixed_string_t queue;
8991         uint8_t queue_num;
8992         cmdline_fixed_string_t rate;
8993         uint16_t rate_num;
8994 };
8995
8996 static void cmd_queue_rate_limit_parsed(void *parsed_result,
8997                 __rte_unused struct cmdline *cl,
8998                 __rte_unused void *data)
8999 {
9000         struct cmd_queue_rate_limit_result *res = parsed_result;
9001         int ret = 0;
9002
9003         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9004                 && (strcmp(res->queue, "queue") == 0)
9005                 && (strcmp(res->rate, "rate") == 0))
9006                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9007                                         res->rate_num);
9008         if (ret < 0)
9009                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9010
9011 }
9012
9013 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9014         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9015                                 set, "set");
9016 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9017         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9018                                 port, "port");
9019 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9020         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9021                                 port_num, UINT16);
9022 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9023         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9024                                 queue, "queue");
9025 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9026         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9027                                 queue_num, UINT8);
9028 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9029         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9030                                 rate, "rate");
9031 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9032         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9033                                 rate_num, UINT16);
9034
9035 cmdline_parse_inst_t cmd_queue_rate_limit = {
9036         .f = cmd_queue_rate_limit_parsed,
9037         .data = (void *)0,
9038         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9039                 "Set rate limit for a queue on port_id",
9040         .tokens = {
9041                 (void *)&cmd_queue_rate_limit_set,
9042                 (void *)&cmd_queue_rate_limit_port,
9043                 (void *)&cmd_queue_rate_limit_portnum,
9044                 (void *)&cmd_queue_rate_limit_queue,
9045                 (void *)&cmd_queue_rate_limit_queuenum,
9046                 (void *)&cmd_queue_rate_limit_rate,
9047                 (void *)&cmd_queue_rate_limit_ratenum,
9048                 NULL,
9049         },
9050 };
9051
9052 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9053 struct cmd_vf_rate_limit_result {
9054         cmdline_fixed_string_t set;
9055         cmdline_fixed_string_t port;
9056         uint16_t port_num;
9057         cmdline_fixed_string_t vf;
9058         uint8_t vf_num;
9059         cmdline_fixed_string_t rate;
9060         uint16_t rate_num;
9061         cmdline_fixed_string_t q_msk;
9062         uint64_t q_msk_val;
9063 };
9064
9065 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9066                 __rte_unused struct cmdline *cl,
9067                 __rte_unused void *data)
9068 {
9069         struct cmd_vf_rate_limit_result *res = parsed_result;
9070         int ret = 0;
9071
9072         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9073                 && (strcmp(res->vf, "vf") == 0)
9074                 && (strcmp(res->rate, "rate") == 0)
9075                 && (strcmp(res->q_msk, "queue_mask") == 0))
9076                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9077                                         res->rate_num, res->q_msk_val);
9078         if (ret < 0)
9079                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9080
9081 }
9082
9083 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9084         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9085                                 set, "set");
9086 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9087         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9088                                 port, "port");
9089 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9090         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9091                                 port_num, UINT16);
9092 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9093         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9094                                 vf, "vf");
9095 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9096         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9097                                 vf_num, UINT8);
9098 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9099         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9100                                 rate, "rate");
9101 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9102         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9103                                 rate_num, UINT16);
9104 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9105         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9106                                 q_msk, "queue_mask");
9107 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9108         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9109                                 q_msk_val, UINT64);
9110
9111 cmdline_parse_inst_t cmd_vf_rate_limit = {
9112         .f = cmd_vf_rate_limit_parsed,
9113         .data = (void *)0,
9114         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9115                 "queue_mask <queue_mask_value>: "
9116                 "Set rate limit for queues of VF on port_id",
9117         .tokens = {
9118                 (void *)&cmd_vf_rate_limit_set,
9119                 (void *)&cmd_vf_rate_limit_port,
9120                 (void *)&cmd_vf_rate_limit_portnum,
9121                 (void *)&cmd_vf_rate_limit_vf,
9122                 (void *)&cmd_vf_rate_limit_vfnum,
9123                 (void *)&cmd_vf_rate_limit_rate,
9124                 (void *)&cmd_vf_rate_limit_ratenum,
9125                 (void *)&cmd_vf_rate_limit_q_msk,
9126                 (void *)&cmd_vf_rate_limit_q_msk_val,
9127                 NULL,
9128         },
9129 };
9130
9131 /* *** ADD TUNNEL FILTER OF A PORT *** */
9132 struct cmd_tunnel_filter_result {
9133         cmdline_fixed_string_t cmd;
9134         cmdline_fixed_string_t what;
9135         portid_t port_id;
9136         struct rte_ether_addr outer_mac;
9137         struct rte_ether_addr inner_mac;
9138         cmdline_ipaddr_t ip_value;
9139         uint16_t inner_vlan;
9140         cmdline_fixed_string_t tunnel_type;
9141         cmdline_fixed_string_t filter_type;
9142         uint32_t tenant_id;
9143         uint16_t queue_num;
9144 };
9145
9146 static void
9147 cmd_tunnel_filter_parsed(void *parsed_result,
9148                           __rte_unused struct cmdline *cl,
9149                           __rte_unused void *data)
9150 {
9151         struct cmd_tunnel_filter_result *res = parsed_result;
9152         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9153         int ret = 0;
9154
9155         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9156
9157         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9158         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9159         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9160
9161         if (res->ip_value.family == AF_INET) {
9162                 tunnel_filter_conf.ip_addr.ipv4_addr =
9163                         res->ip_value.addr.ipv4.s_addr;
9164                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9165         } else {
9166                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9167                         &(res->ip_value.addr.ipv6),
9168                         sizeof(struct in6_addr));
9169                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9170         }
9171
9172         if (!strcmp(res->filter_type, "imac-ivlan"))
9173                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9174         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9175                 tunnel_filter_conf.filter_type =
9176                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9177         else if (!strcmp(res->filter_type, "imac-tenid"))
9178                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9179         else if (!strcmp(res->filter_type, "imac"))
9180                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9181         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9182                 tunnel_filter_conf.filter_type =
9183                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9184         else if (!strcmp(res->filter_type, "oip"))
9185                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9186         else if (!strcmp(res->filter_type, "iip"))
9187                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9188         else {
9189                 printf("The filter type is not supported");
9190                 return;
9191         }
9192
9193         if (!strcmp(res->tunnel_type, "vxlan"))
9194                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9195         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9196                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9197         else if (!strcmp(res->tunnel_type, "nvgre"))
9198                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9199         else if (!strcmp(res->tunnel_type, "ipingre"))
9200                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9201         else {
9202                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9203                 return;
9204         }
9205
9206         tunnel_filter_conf.tenant_id = res->tenant_id;
9207         tunnel_filter_conf.queue_id = res->queue_num;
9208         if (!strcmp(res->what, "add"))
9209                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9210                                         RTE_ETH_FILTER_TUNNEL,
9211                                         RTE_ETH_FILTER_ADD,
9212                                         &tunnel_filter_conf);
9213         else
9214                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9215                                         RTE_ETH_FILTER_TUNNEL,
9216                                         RTE_ETH_FILTER_DELETE,
9217                                         &tunnel_filter_conf);
9218         if (ret < 0)
9219                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9220                                 strerror(-ret));
9221
9222 }
9223 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9224         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9225         cmd, "tunnel_filter");
9226 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9227         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9228         what, "add#rm");
9229 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9230         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9231         port_id, UINT16);
9232 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9233         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9234         outer_mac);
9235 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9236         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9237         inner_mac);
9238 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9239         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9240         inner_vlan, UINT16);
9241 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9242         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9243         ip_value);
9244 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9245         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9246         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9247
9248 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9249         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9250         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9251                 "imac#omac-imac-tenid");
9252 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9253         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9254         tenant_id, UINT32);
9255 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9256         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9257         queue_num, UINT16);
9258
9259 cmdline_parse_inst_t cmd_tunnel_filter = {
9260         .f = cmd_tunnel_filter_parsed,
9261         .data = (void *)0,
9262         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9263                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9264                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9265                 "<queue_id>: Add/Rm tunnel filter of a port",
9266         .tokens = {
9267                 (void *)&cmd_tunnel_filter_cmd,
9268                 (void *)&cmd_tunnel_filter_what,
9269                 (void *)&cmd_tunnel_filter_port_id,
9270                 (void *)&cmd_tunnel_filter_outer_mac,
9271                 (void *)&cmd_tunnel_filter_inner_mac,
9272                 (void *)&cmd_tunnel_filter_ip_value,
9273                 (void *)&cmd_tunnel_filter_innner_vlan,
9274                 (void *)&cmd_tunnel_filter_tunnel_type,
9275                 (void *)&cmd_tunnel_filter_filter_type,
9276                 (void *)&cmd_tunnel_filter_tenant_id,
9277                 (void *)&cmd_tunnel_filter_queue_num,
9278                 NULL,
9279         },
9280 };
9281
9282 /* *** CONFIGURE TUNNEL UDP PORT *** */
9283 struct cmd_tunnel_udp_config {
9284         cmdline_fixed_string_t cmd;
9285         cmdline_fixed_string_t what;
9286         uint16_t udp_port;
9287         portid_t port_id;
9288 };
9289
9290 static void
9291 cmd_tunnel_udp_config_parsed(void *parsed_result,
9292                           __rte_unused struct cmdline *cl,
9293                           __rte_unused void *data)
9294 {
9295         struct cmd_tunnel_udp_config *res = parsed_result;
9296         struct rte_eth_udp_tunnel tunnel_udp;
9297         int ret;
9298
9299         tunnel_udp.udp_port = res->udp_port;
9300
9301         if (!strcmp(res->cmd, "rx_vxlan_port"))
9302                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9303
9304         if (!strcmp(res->what, "add"))
9305                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9306                                                       &tunnel_udp);
9307         else
9308                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9309                                                          &tunnel_udp);
9310
9311         if (ret < 0)
9312                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9313 }
9314
9315 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9316         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9317                                 cmd, "rx_vxlan_port");
9318 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9319         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9320                                 what, "add#rm");
9321 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9322         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9323                                 udp_port, UINT16);
9324 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9325         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9326                                 port_id, UINT16);
9327
9328 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9329         .f = cmd_tunnel_udp_config_parsed,
9330         .data = (void *)0,
9331         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9332                 "Add/Remove a tunneling UDP port filter",
9333         .tokens = {
9334                 (void *)&cmd_tunnel_udp_config_cmd,
9335                 (void *)&cmd_tunnel_udp_config_what,
9336                 (void *)&cmd_tunnel_udp_config_udp_port,
9337                 (void *)&cmd_tunnel_udp_config_port_id,
9338                 NULL,
9339         },
9340 };
9341
9342 struct cmd_config_tunnel_udp_port {
9343         cmdline_fixed_string_t port;
9344         cmdline_fixed_string_t config;
9345         portid_t port_id;
9346         cmdline_fixed_string_t udp_tunnel_port;
9347         cmdline_fixed_string_t action;
9348         cmdline_fixed_string_t tunnel_type;
9349         uint16_t udp_port;
9350 };
9351
9352 static void
9353 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9354                                __rte_unused struct cmdline *cl,
9355                                __rte_unused void *data)
9356 {
9357         struct cmd_config_tunnel_udp_port *res = parsed_result;
9358         struct rte_eth_udp_tunnel tunnel_udp;
9359         int ret = 0;
9360
9361         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9362                 return;
9363
9364         tunnel_udp.udp_port = res->udp_port;
9365
9366         if (!strcmp(res->tunnel_type, "vxlan")) {
9367                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9368         } else if (!strcmp(res->tunnel_type, "geneve")) {
9369                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9370         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9371                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9372         } else {
9373                 printf("Invalid tunnel type\n");
9374                 return;
9375         }
9376
9377         if (!strcmp(res->action, "add"))
9378                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9379                                                       &tunnel_udp);
9380         else
9381                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9382                                                          &tunnel_udp);
9383
9384         if (ret < 0)
9385                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9386 }
9387
9388 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9389         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9390                                  "port");
9391 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9392         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9393                                  "config");
9394 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9395         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9396                               UINT16);
9397 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9398         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9399                                  udp_tunnel_port,
9400                                  "udp_tunnel_port");
9401 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9402         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9403                                  "add#rm");
9404 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9405         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9406                                  "vxlan#geneve#vxlan-gpe");
9407 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9408         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9409                               UINT16);
9410
9411 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9412         .f = cmd_cfg_tunnel_udp_port_parsed,
9413         .data = NULL,
9414         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9415         .tokens = {
9416                 (void *)&cmd_config_tunnel_udp_port_port,
9417                 (void *)&cmd_config_tunnel_udp_port_config,
9418                 (void *)&cmd_config_tunnel_udp_port_port_id,
9419                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9420                 (void *)&cmd_config_tunnel_udp_port_action,
9421                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9422                 (void *)&cmd_config_tunnel_udp_port_value,
9423                 NULL,
9424         },
9425 };
9426
9427 /* *** GLOBAL CONFIG *** */
9428 struct cmd_global_config_result {
9429         cmdline_fixed_string_t cmd;
9430         portid_t port_id;
9431         cmdline_fixed_string_t cfg_type;
9432         uint8_t len;
9433 };
9434
9435 static void
9436 cmd_global_config_parsed(void *parsed_result,
9437                          __rte_unused struct cmdline *cl,
9438                          __rte_unused void *data)
9439 {
9440         struct cmd_global_config_result *res = parsed_result;
9441         struct rte_eth_global_cfg conf;
9442         int ret;
9443
9444         memset(&conf, 0, sizeof(conf));
9445         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9446         conf.cfg.gre_key_len = res->len;
9447         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9448                                       RTE_ETH_FILTER_SET, &conf);
9449 #ifdef RTE_LIBRTE_I40E_PMD
9450         if (ret == -ENOTSUP)
9451                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9452 #endif
9453         if (ret != 0)
9454                 printf("Global config error\n");
9455 }
9456
9457 cmdline_parse_token_string_t cmd_global_config_cmd =
9458         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9459                 "global_config");
9460 cmdline_parse_token_num_t cmd_global_config_port_id =
9461         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9462                                UINT16);
9463 cmdline_parse_token_string_t cmd_global_config_type =
9464         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9465                 cfg_type, "gre-key-len");
9466 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9467         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9468                 len, UINT8);
9469
9470 cmdline_parse_inst_t cmd_global_config = {
9471         .f = cmd_global_config_parsed,
9472         .data = (void *)NULL,
9473         .help_str = "global_config <port_id> gre-key-len <key_len>",
9474         .tokens = {
9475                 (void *)&cmd_global_config_cmd,
9476                 (void *)&cmd_global_config_port_id,
9477                 (void *)&cmd_global_config_type,
9478                 (void *)&cmd_global_config_gre_key_len,
9479                 NULL,
9480         },
9481 };
9482
9483 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9484 struct cmd_set_mirror_mask_result {
9485         cmdline_fixed_string_t set;
9486         cmdline_fixed_string_t port;
9487         portid_t port_id;
9488         cmdline_fixed_string_t mirror;
9489         uint8_t rule_id;
9490         cmdline_fixed_string_t what;
9491         cmdline_fixed_string_t value;
9492         cmdline_fixed_string_t dstpool;
9493         uint8_t dstpool_id;
9494         cmdline_fixed_string_t on;
9495 };
9496
9497 cmdline_parse_token_string_t cmd_mirror_mask_set =
9498         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9499                                 set, "set");
9500 cmdline_parse_token_string_t cmd_mirror_mask_port =
9501         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9502                                 port, "port");
9503 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9504         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9505                                 port_id, UINT16);
9506 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9507         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9508                                 mirror, "mirror-rule");
9509 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9510         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9511                                 rule_id, UINT8);
9512 cmdline_parse_token_string_t cmd_mirror_mask_what =
9513         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9514                                 what, "pool-mirror-up#pool-mirror-down"
9515                                       "#vlan-mirror");
9516 cmdline_parse_token_string_t cmd_mirror_mask_value =
9517         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9518                                 value, NULL);
9519 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9520         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9521                                 dstpool, "dst-pool");
9522 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9523         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9524                                 dstpool_id, UINT8);
9525 cmdline_parse_token_string_t cmd_mirror_mask_on =
9526         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9527                                 on, "on#off");
9528
9529 static void
9530 cmd_set_mirror_mask_parsed(void *parsed_result,
9531                        __rte_unused struct cmdline *cl,
9532                        __rte_unused void *data)
9533 {
9534         int ret,nb_item,i;
9535         struct cmd_set_mirror_mask_result *res = parsed_result;
9536         struct rte_eth_mirror_conf mr_conf;
9537
9538         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9539
9540         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9541
9542         mr_conf.dst_pool = res->dstpool_id;
9543
9544         if (!strcmp(res->what, "pool-mirror-up")) {
9545                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9546                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9547         } else if (!strcmp(res->what, "pool-mirror-down")) {
9548                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9549                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9550         } else if (!strcmp(res->what, "vlan-mirror")) {
9551                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9552                 nb_item = parse_item_list(res->value, "vlan",
9553                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9554                 if (nb_item <= 0)
9555                         return;
9556
9557                 for (i = 0; i < nb_item; i++) {
9558                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9559                                 printf("Invalid vlan_id: must be < 4096\n");
9560                                 return;
9561                         }
9562
9563                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9564                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9565                 }
9566         }
9567
9568         if (!strcmp(res->on, "on"))
9569                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9570                                                 res->rule_id, 1);
9571         else
9572                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9573                                                 res->rule_id, 0);
9574         if (ret < 0)
9575                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9576 }
9577
9578 cmdline_parse_inst_t cmd_set_mirror_mask = {
9579                 .f = cmd_set_mirror_mask_parsed,
9580                 .data = NULL,
9581                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9582                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9583                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9584                 .tokens = {
9585                         (void *)&cmd_mirror_mask_set,
9586                         (void *)&cmd_mirror_mask_port,
9587                         (void *)&cmd_mirror_mask_portid,
9588                         (void *)&cmd_mirror_mask_mirror,
9589                         (void *)&cmd_mirror_mask_ruleid,
9590                         (void *)&cmd_mirror_mask_what,
9591                         (void *)&cmd_mirror_mask_value,
9592                         (void *)&cmd_mirror_mask_dstpool,
9593                         (void *)&cmd_mirror_mask_poolid,
9594                         (void *)&cmd_mirror_mask_on,
9595                         NULL,
9596                 },
9597 };
9598
9599 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9600 struct cmd_set_mirror_link_result {
9601         cmdline_fixed_string_t set;
9602         cmdline_fixed_string_t port;
9603         portid_t port_id;
9604         cmdline_fixed_string_t mirror;
9605         uint8_t rule_id;
9606         cmdline_fixed_string_t what;
9607         cmdline_fixed_string_t dstpool;
9608         uint8_t dstpool_id;
9609         cmdline_fixed_string_t on;
9610 };
9611
9612 cmdline_parse_token_string_t cmd_mirror_link_set =
9613         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9614                                  set, "set");
9615 cmdline_parse_token_string_t cmd_mirror_link_port =
9616         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9617                                 port, "port");
9618 cmdline_parse_token_num_t cmd_mirror_link_portid =
9619         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9620                                 port_id, UINT16);
9621 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9622         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9623                                 mirror, "mirror-rule");
9624 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9625         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9626                             rule_id, UINT8);
9627 cmdline_parse_token_string_t cmd_mirror_link_what =
9628         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9629                                 what, "uplink-mirror#downlink-mirror");
9630 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9631         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9632                                 dstpool, "dst-pool");
9633 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9634         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9635                                 dstpool_id, UINT8);
9636 cmdline_parse_token_string_t cmd_mirror_link_on =
9637         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9638                                 on, "on#off");
9639
9640 static void
9641 cmd_set_mirror_link_parsed(void *parsed_result,
9642                        __rte_unused struct cmdline *cl,
9643                        __rte_unused void *data)
9644 {
9645         int ret;
9646         struct cmd_set_mirror_link_result *res = parsed_result;
9647         struct rte_eth_mirror_conf mr_conf;
9648
9649         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9650         if (!strcmp(res->what, "uplink-mirror"))
9651                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9652         else
9653                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9654
9655         mr_conf.dst_pool = res->dstpool_id;
9656
9657         if (!strcmp(res->on, "on"))
9658                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9659                                                 res->rule_id, 1);
9660         else
9661                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9662                                                 res->rule_id, 0);
9663
9664         /* check the return value and print it if is < 0 */
9665         if (ret < 0)
9666                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9667
9668 }
9669
9670 cmdline_parse_inst_t cmd_set_mirror_link = {
9671                 .f = cmd_set_mirror_link_parsed,
9672                 .data = NULL,
9673                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9674                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9675                 .tokens = {
9676                         (void *)&cmd_mirror_link_set,
9677                         (void *)&cmd_mirror_link_port,
9678                         (void *)&cmd_mirror_link_portid,
9679                         (void *)&cmd_mirror_link_mirror,
9680                         (void *)&cmd_mirror_link_ruleid,
9681                         (void *)&cmd_mirror_link_what,
9682                         (void *)&cmd_mirror_link_dstpool,
9683                         (void *)&cmd_mirror_link_poolid,
9684                         (void *)&cmd_mirror_link_on,
9685                         NULL,
9686                 },
9687 };
9688
9689 /* *** RESET VM MIRROR RULE *** */
9690 struct cmd_rm_mirror_rule_result {
9691         cmdline_fixed_string_t reset;
9692         cmdline_fixed_string_t port;
9693         portid_t port_id;
9694         cmdline_fixed_string_t mirror;
9695         uint8_t rule_id;
9696 };
9697
9698 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9699         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9700                                  reset, "reset");
9701 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9702         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9703                                 port, "port");
9704 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9705         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9706                                 port_id, UINT16);
9707 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9708         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9709                                 mirror, "mirror-rule");
9710 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9711         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9712                                 rule_id, UINT8);
9713
9714 static void
9715 cmd_reset_mirror_rule_parsed(void *parsed_result,
9716                        __rte_unused struct cmdline *cl,
9717                        __rte_unused void *data)
9718 {
9719         int ret;
9720         struct cmd_set_mirror_link_result *res = parsed_result;
9721         /* check rule_id */
9722         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9723         if(ret < 0)
9724                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9725 }
9726
9727 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9728                 .f = cmd_reset_mirror_rule_parsed,
9729                 .data = NULL,
9730                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9731                 .tokens = {
9732                         (void *)&cmd_rm_mirror_rule_reset,
9733                         (void *)&cmd_rm_mirror_rule_port,
9734                         (void *)&cmd_rm_mirror_rule_portid,
9735                         (void *)&cmd_rm_mirror_rule_mirror,
9736                         (void *)&cmd_rm_mirror_rule_ruleid,
9737                         NULL,
9738                 },
9739 };
9740
9741 /* ******************************************************************************** */
9742
9743 struct cmd_dump_result {
9744         cmdline_fixed_string_t dump;
9745 };
9746
9747 static void
9748 dump_struct_sizes(void)
9749 {
9750 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9751         DUMP_SIZE(struct rte_mbuf);
9752         DUMP_SIZE(struct rte_mempool);
9753         DUMP_SIZE(struct rte_ring);
9754 #undef DUMP_SIZE
9755 }
9756
9757
9758 /* Dump the socket memory statistics on console */
9759 static void
9760 dump_socket_mem(FILE *f)
9761 {
9762         struct rte_malloc_socket_stats socket_stats;
9763         unsigned int i;
9764         size_t total = 0;
9765         size_t alloc = 0;
9766         size_t free = 0;
9767         unsigned int n_alloc = 0;
9768         unsigned int n_free = 0;
9769         static size_t last_allocs;
9770         static size_t last_total;
9771
9772
9773         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9774                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9775                     !socket_stats.heap_totalsz_bytes)
9776                         continue;
9777                 total += socket_stats.heap_totalsz_bytes;
9778                 alloc += socket_stats.heap_allocsz_bytes;
9779                 free += socket_stats.heap_freesz_bytes;
9780                 n_alloc += socket_stats.alloc_count;
9781                 n_free += socket_stats.free_count;
9782                 fprintf(f,
9783                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9784                         i,
9785                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9786                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9787                         (double)socket_stats.heap_allocsz_bytes * 100 /
9788                         (double)socket_stats.heap_totalsz_bytes,
9789                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9790                         socket_stats.alloc_count,
9791                         socket_stats.free_count);
9792         }
9793         fprintf(f,
9794                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9795                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9796                 (double)alloc * 100 / (double)total,
9797                 (double)free / (1024 * 1024),
9798                 n_alloc, n_free);
9799         if (last_allocs)
9800                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9801                         ((double)total - (double)last_total) / (1024 * 1024),
9802                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9803         last_allocs = alloc;
9804         last_total = total;
9805 }
9806
9807 static void cmd_dump_parsed(void *parsed_result,
9808                             __rte_unused struct cmdline *cl,
9809                             __rte_unused void *data)
9810 {
9811         struct cmd_dump_result *res = parsed_result;
9812
9813         if (!strcmp(res->dump, "dump_physmem"))
9814                 rte_dump_physmem_layout(stdout);
9815         else if (!strcmp(res->dump, "dump_socket_mem"))
9816                 dump_socket_mem(stdout);
9817         else if (!strcmp(res->dump, "dump_memzone"))
9818                 rte_memzone_dump(stdout);
9819         else if (!strcmp(res->dump, "dump_struct_sizes"))
9820                 dump_struct_sizes();
9821         else if (!strcmp(res->dump, "dump_ring"))
9822                 rte_ring_list_dump(stdout);
9823         else if (!strcmp(res->dump, "dump_mempool"))
9824                 rte_mempool_list_dump(stdout);
9825         else if (!strcmp(res->dump, "dump_devargs"))
9826                 rte_devargs_dump(stdout);
9827         else if (!strcmp(res->dump, "dump_log_types"))
9828                 rte_log_dump(stdout);
9829 }
9830
9831 cmdline_parse_token_string_t cmd_dump_dump =
9832         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9833                 "dump_physmem#"
9834                 "dump_memzone#"
9835                 "dump_socket_mem#"
9836                 "dump_struct_sizes#"
9837                 "dump_ring#"
9838                 "dump_mempool#"
9839                 "dump_devargs#"
9840                 "dump_log_types");
9841
9842 cmdline_parse_inst_t cmd_dump = {
9843         .f = cmd_dump_parsed,  /* function to call */
9844         .data = NULL,      /* 2nd arg of func */
9845         .help_str = "Dump status",
9846         .tokens = {        /* token list, NULL terminated */
9847                 (void *)&cmd_dump_dump,
9848                 NULL,
9849         },
9850 };
9851
9852 /* ******************************************************************************** */
9853
9854 struct cmd_dump_one_result {
9855         cmdline_fixed_string_t dump;
9856         cmdline_fixed_string_t name;
9857 };
9858
9859 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9860                                 __rte_unused void *data)
9861 {
9862         struct cmd_dump_one_result *res = parsed_result;
9863
9864         if (!strcmp(res->dump, "dump_ring")) {
9865                 struct rte_ring *r;
9866                 r = rte_ring_lookup(res->name);
9867                 if (r == NULL) {
9868                         cmdline_printf(cl, "Cannot find ring\n");
9869                         return;
9870                 }
9871                 rte_ring_dump(stdout, r);
9872         } else if (!strcmp(res->dump, "dump_mempool")) {
9873                 struct rte_mempool *mp;
9874                 mp = rte_mempool_lookup(res->name);
9875                 if (mp == NULL) {
9876                         cmdline_printf(cl, "Cannot find mempool\n");
9877                         return;
9878                 }
9879                 rte_mempool_dump(stdout, mp);
9880         }
9881 }
9882
9883 cmdline_parse_token_string_t cmd_dump_one_dump =
9884         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9885                                  "dump_ring#dump_mempool");
9886
9887 cmdline_parse_token_string_t cmd_dump_one_name =
9888         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9889
9890 cmdline_parse_inst_t cmd_dump_one = {
9891         .f = cmd_dump_one_parsed,  /* function to call */
9892         .data = NULL,      /* 2nd arg of func */
9893         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9894         .tokens = {        /* token list, NULL terminated */
9895                 (void *)&cmd_dump_one_dump,
9896                 (void *)&cmd_dump_one_name,
9897                 NULL,
9898         },
9899 };
9900
9901 /* *** Add/Del syn filter *** */
9902 struct cmd_syn_filter_result {
9903         cmdline_fixed_string_t filter;
9904         portid_t port_id;
9905         cmdline_fixed_string_t ops;
9906         cmdline_fixed_string_t priority;
9907         cmdline_fixed_string_t high;
9908         cmdline_fixed_string_t queue;
9909         uint16_t queue_id;
9910 };
9911
9912 static void
9913 cmd_syn_filter_parsed(void *parsed_result,
9914                         __rte_unused struct cmdline *cl,
9915                         __rte_unused void *data)
9916 {
9917         struct cmd_syn_filter_result *res = parsed_result;
9918         struct rte_eth_syn_filter syn_filter;
9919         int ret = 0;
9920
9921         ret = rte_eth_dev_filter_supported(res->port_id,
9922                                         RTE_ETH_FILTER_SYN);
9923         if (ret < 0) {
9924                 printf("syn filter is not supported on port %u.\n",
9925                                 res->port_id);
9926                 return;
9927         }
9928
9929         memset(&syn_filter, 0, sizeof(syn_filter));
9930
9931         if (!strcmp(res->ops, "add")) {
9932                 if (!strcmp(res->high, "high"))
9933                         syn_filter.hig_pri = 1;
9934                 else
9935                         syn_filter.hig_pri = 0;
9936
9937                 syn_filter.queue = res->queue_id;
9938                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9939                                                 RTE_ETH_FILTER_SYN,
9940                                                 RTE_ETH_FILTER_ADD,
9941                                                 &syn_filter);
9942         } else
9943                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9944                                                 RTE_ETH_FILTER_SYN,
9945                                                 RTE_ETH_FILTER_DELETE,
9946                                                 &syn_filter);
9947
9948         if (ret < 0)
9949                 printf("syn filter programming error: (%s)\n",
9950                                 strerror(-ret));
9951 }
9952
9953 cmdline_parse_token_string_t cmd_syn_filter_filter =
9954         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9955         filter, "syn_filter");
9956 cmdline_parse_token_num_t cmd_syn_filter_port_id =
9957         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9958         port_id, UINT16);
9959 cmdline_parse_token_string_t cmd_syn_filter_ops =
9960         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9961         ops, "add#del");
9962 cmdline_parse_token_string_t cmd_syn_filter_priority =
9963         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9964                                 priority, "priority");
9965 cmdline_parse_token_string_t cmd_syn_filter_high =
9966         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9967                                 high, "high#low");
9968 cmdline_parse_token_string_t cmd_syn_filter_queue =
9969         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
9970                                 queue, "queue");
9971 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
9972         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
9973                                 queue_id, UINT16);
9974
9975 cmdline_parse_inst_t cmd_syn_filter = {
9976         .f = cmd_syn_filter_parsed,
9977         .data = NULL,
9978         .help_str = "syn_filter <port_id> add|del priority high|low queue "
9979                 "<queue_id>: Add/Delete syn filter",
9980         .tokens = {
9981                 (void *)&cmd_syn_filter_filter,
9982                 (void *)&cmd_syn_filter_port_id,
9983                 (void *)&cmd_syn_filter_ops,
9984                 (void *)&cmd_syn_filter_priority,
9985                 (void *)&cmd_syn_filter_high,
9986                 (void *)&cmd_syn_filter_queue,
9987                 (void *)&cmd_syn_filter_queue_id,
9988                 NULL,
9989         },
9990 };
9991
9992 /* *** queue region set *** */
9993 struct cmd_queue_region_result {
9994         cmdline_fixed_string_t set;
9995         cmdline_fixed_string_t port;
9996         portid_t port_id;
9997         cmdline_fixed_string_t cmd;
9998         cmdline_fixed_string_t region;
9999         uint8_t  region_id;
10000         cmdline_fixed_string_t queue_start_index;
10001         uint8_t  queue_id;
10002         cmdline_fixed_string_t queue_num;
10003         uint8_t  queue_num_value;
10004 };
10005
10006 static void
10007 cmd_queue_region_parsed(void *parsed_result,
10008                         __rte_unused struct cmdline *cl,
10009                         __rte_unused void *data)
10010 {
10011         struct cmd_queue_region_result *res = parsed_result;
10012         int ret = -ENOTSUP;
10013 #ifdef RTE_LIBRTE_I40E_PMD
10014         struct rte_pmd_i40e_queue_region_conf region_conf;
10015         enum rte_pmd_i40e_queue_region_op op_type;
10016 #endif
10017
10018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10019                 return;
10020
10021 #ifdef RTE_LIBRTE_I40E_PMD
10022         memset(&region_conf, 0, sizeof(region_conf));
10023         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10024         region_conf.region_id = res->region_id;
10025         region_conf.queue_num = res->queue_num_value;
10026         region_conf.queue_start_index = res->queue_id;
10027
10028         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10029                                 op_type, &region_conf);
10030 #endif
10031
10032         switch (ret) {
10033         case 0:
10034                 break;
10035         case -ENOTSUP:
10036                 printf("function not implemented or supported\n");
10037                 break;
10038         default:
10039                 printf("queue region config error: (%s)\n", strerror(-ret));
10040         }
10041 }
10042
10043 cmdline_parse_token_string_t cmd_queue_region_set =
10044 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10045                 set, "set");
10046 cmdline_parse_token_string_t cmd_queue_region_port =
10047         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10048 cmdline_parse_token_num_t cmd_queue_region_port_id =
10049         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10050                                 port_id, UINT16);
10051 cmdline_parse_token_string_t cmd_queue_region_cmd =
10052         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10053                                  cmd, "queue-region");
10054 cmdline_parse_token_string_t cmd_queue_region_id =
10055         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10056                                 region, "region_id");
10057 cmdline_parse_token_num_t cmd_queue_region_index =
10058         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10059                                 region_id, UINT8);
10060 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10061         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10062                                 queue_start_index, "queue_start_index");
10063 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10064         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10065                                 queue_id, UINT8);
10066 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10067         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10068                                 queue_num, "queue_num");
10069 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10070         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10071                                 queue_num_value, UINT8);
10072
10073 cmdline_parse_inst_t cmd_queue_region = {
10074         .f = cmd_queue_region_parsed,
10075         .data = NULL,
10076         .help_str = "set port <port_id> queue-region region_id <value> "
10077                 "queue_start_index <value> queue_num <value>: Set a queue region",
10078         .tokens = {
10079                 (void *)&cmd_queue_region_set,
10080                 (void *)&cmd_queue_region_port,
10081                 (void *)&cmd_queue_region_port_id,
10082                 (void *)&cmd_queue_region_cmd,
10083                 (void *)&cmd_queue_region_id,
10084                 (void *)&cmd_queue_region_index,
10085                 (void *)&cmd_queue_region_queue_start_index,
10086                 (void *)&cmd_queue_region_queue_id,
10087                 (void *)&cmd_queue_region_queue_num,
10088                 (void *)&cmd_queue_region_queue_num_value,
10089                 NULL,
10090         },
10091 };
10092
10093 /* *** queue region and flowtype set *** */
10094 struct cmd_region_flowtype_result {
10095         cmdline_fixed_string_t set;
10096         cmdline_fixed_string_t port;
10097         portid_t port_id;
10098         cmdline_fixed_string_t cmd;
10099         cmdline_fixed_string_t region;
10100         uint8_t  region_id;
10101         cmdline_fixed_string_t flowtype;
10102         uint8_t  flowtype_id;
10103 };
10104
10105 static void
10106 cmd_region_flowtype_parsed(void *parsed_result,
10107                         __rte_unused struct cmdline *cl,
10108                         __rte_unused void *data)
10109 {
10110         struct cmd_region_flowtype_result *res = parsed_result;
10111         int ret = -ENOTSUP;
10112 #ifdef RTE_LIBRTE_I40E_PMD
10113         struct rte_pmd_i40e_queue_region_conf region_conf;
10114         enum rte_pmd_i40e_queue_region_op op_type;
10115 #endif
10116
10117         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10118                 return;
10119
10120 #ifdef RTE_LIBRTE_I40E_PMD
10121         memset(&region_conf, 0, sizeof(region_conf));
10122
10123         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10124         region_conf.region_id = res->region_id;
10125         region_conf.hw_flowtype = res->flowtype_id;
10126
10127         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10128                         op_type, &region_conf);
10129 #endif
10130
10131         switch (ret) {
10132         case 0:
10133                 break;
10134         case -ENOTSUP:
10135                 printf("function not implemented or supported\n");
10136                 break;
10137         default:
10138                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10139         }
10140 }
10141
10142 cmdline_parse_token_string_t cmd_region_flowtype_set =
10143 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10144                                 set, "set");
10145 cmdline_parse_token_string_t cmd_region_flowtype_port =
10146         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10147                                 port, "port");
10148 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10149         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10150                                 port_id, UINT16);
10151 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10152         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10153                                 cmd, "queue-region");
10154 cmdline_parse_token_string_t cmd_region_flowtype_index =
10155         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10156                                 region, "region_id");
10157 cmdline_parse_token_num_t cmd_region_flowtype_id =
10158         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10159                                 region_id, UINT8);
10160 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10161         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10162                                 flowtype, "flowtype");
10163 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10164         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10165                                 flowtype_id, UINT8);
10166 cmdline_parse_inst_t cmd_region_flowtype = {
10167         .f = cmd_region_flowtype_parsed,
10168         .data = NULL,
10169         .help_str = "set port <port_id> queue-region region_id <value> "
10170                 "flowtype <value>: Set a flowtype region index",
10171         .tokens = {
10172                 (void *)&cmd_region_flowtype_set,
10173                 (void *)&cmd_region_flowtype_port,
10174                 (void *)&cmd_region_flowtype_port_index,
10175                 (void *)&cmd_region_flowtype_cmd,
10176                 (void *)&cmd_region_flowtype_index,
10177                 (void *)&cmd_region_flowtype_id,
10178                 (void *)&cmd_region_flowtype_flow_index,
10179                 (void *)&cmd_region_flowtype_flow_id,
10180                 NULL,
10181         },
10182 };
10183
10184 /* *** User Priority (UP) to queue region (region_id) set *** */
10185 struct cmd_user_priority_region_result {
10186         cmdline_fixed_string_t set;
10187         cmdline_fixed_string_t port;
10188         portid_t port_id;
10189         cmdline_fixed_string_t cmd;
10190         cmdline_fixed_string_t user_priority;
10191         uint8_t  user_priority_id;
10192         cmdline_fixed_string_t region;
10193         uint8_t  region_id;
10194 };
10195
10196 static void
10197 cmd_user_priority_region_parsed(void *parsed_result,
10198                         __rte_unused struct cmdline *cl,
10199                         __rte_unused void *data)
10200 {
10201         struct cmd_user_priority_region_result *res = parsed_result;
10202         int ret = -ENOTSUP;
10203 #ifdef RTE_LIBRTE_I40E_PMD
10204         struct rte_pmd_i40e_queue_region_conf region_conf;
10205         enum rte_pmd_i40e_queue_region_op op_type;
10206 #endif
10207
10208         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10209                 return;
10210
10211 #ifdef RTE_LIBRTE_I40E_PMD
10212         memset(&region_conf, 0, sizeof(region_conf));
10213         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10214         region_conf.user_priority = res->user_priority_id;
10215         region_conf.region_id = res->region_id;
10216
10217         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10218                                 op_type, &region_conf);
10219 #endif
10220
10221         switch (ret) {
10222         case 0:
10223                 break;
10224         case -ENOTSUP:
10225                 printf("function not implemented or supported\n");
10226                 break;
10227         default:
10228                 printf("user_priority region config error: (%s)\n",
10229                                 strerror(-ret));
10230         }
10231 }
10232
10233 cmdline_parse_token_string_t cmd_user_priority_region_set =
10234         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10235                                 set, "set");
10236 cmdline_parse_token_string_t cmd_user_priority_region_port =
10237         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10238                                 port, "port");
10239 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10240         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10241                                 port_id, UINT16);
10242 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10243         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10244                                 cmd, "queue-region");
10245 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10246         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10247                                 user_priority, "UP");
10248 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10249         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10250                                 user_priority_id, UINT8);
10251 cmdline_parse_token_string_t cmd_user_priority_region_region =
10252         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10253                                 region, "region_id");
10254 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10255         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10256                                 region_id, UINT8);
10257
10258 cmdline_parse_inst_t cmd_user_priority_region = {
10259         .f = cmd_user_priority_region_parsed,
10260         .data = NULL,
10261         .help_str = "set port <port_id> queue-region UP <value> "
10262                 "region_id <value>: Set the mapping of User Priority (UP) "
10263                 "to queue region (region_id) ",
10264         .tokens = {
10265                 (void *)&cmd_user_priority_region_set,
10266                 (void *)&cmd_user_priority_region_port,
10267                 (void *)&cmd_user_priority_region_port_index,
10268                 (void *)&cmd_user_priority_region_cmd,
10269                 (void *)&cmd_user_priority_region_UP,
10270                 (void *)&cmd_user_priority_region_UP_id,
10271                 (void *)&cmd_user_priority_region_region,
10272                 (void *)&cmd_user_priority_region_region_id,
10273                 NULL,
10274         },
10275 };
10276
10277 /* *** flush all queue region related configuration *** */
10278 struct cmd_flush_queue_region_result {
10279         cmdline_fixed_string_t set;
10280         cmdline_fixed_string_t port;
10281         portid_t port_id;
10282         cmdline_fixed_string_t cmd;
10283         cmdline_fixed_string_t flush;
10284         cmdline_fixed_string_t what;
10285 };
10286
10287 static void
10288 cmd_flush_queue_region_parsed(void *parsed_result,
10289                         __rte_unused struct cmdline *cl,
10290                         __rte_unused void *data)
10291 {
10292         struct cmd_flush_queue_region_result *res = parsed_result;
10293         int ret = -ENOTSUP;
10294 #ifdef RTE_LIBRTE_I40E_PMD
10295         struct rte_pmd_i40e_queue_region_conf region_conf;
10296         enum rte_pmd_i40e_queue_region_op op_type;
10297 #endif
10298
10299         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10300                 return;
10301
10302 #ifdef RTE_LIBRTE_I40E_PMD
10303         memset(&region_conf, 0, sizeof(region_conf));
10304
10305         if (strcmp(res->what, "on") == 0)
10306                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10307         else
10308                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10309
10310         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10311                                 op_type, &region_conf);
10312 #endif
10313
10314         switch (ret) {
10315         case 0:
10316                 break;
10317         case -ENOTSUP:
10318                 printf("function not implemented or supported\n");
10319                 break;
10320         default:
10321                 printf("queue region config flush error: (%s)\n",
10322                                 strerror(-ret));
10323         }
10324 }
10325
10326 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10327         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10328                                 set, "set");
10329 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10330         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10331                                 port, "port");
10332 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10333         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10334                                 port_id, UINT16);
10335 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10336         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10337                                 cmd, "queue-region");
10338 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10339         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10340                                 flush, "flush");
10341 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10342         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10343                                 what, "on#off");
10344
10345 cmdline_parse_inst_t cmd_flush_queue_region = {
10346         .f = cmd_flush_queue_region_parsed,
10347         .data = NULL,
10348         .help_str = "set port <port_id> queue-region flush on|off"
10349                 ": flush all queue region related configuration",
10350         .tokens = {
10351                 (void *)&cmd_flush_queue_region_set,
10352                 (void *)&cmd_flush_queue_region_port,
10353                 (void *)&cmd_flush_queue_region_port_index,
10354                 (void *)&cmd_flush_queue_region_cmd,
10355                 (void *)&cmd_flush_queue_region_flush,
10356                 (void *)&cmd_flush_queue_region_what,
10357                 NULL,
10358         },
10359 };
10360
10361 /* *** get all queue region related configuration info *** */
10362 struct cmd_show_queue_region_info {
10363         cmdline_fixed_string_t show;
10364         cmdline_fixed_string_t port;
10365         portid_t port_id;
10366         cmdline_fixed_string_t cmd;
10367 };
10368
10369 static void
10370 cmd_show_queue_region_info_parsed(void *parsed_result,
10371                         __rte_unused struct cmdline *cl,
10372                         __rte_unused void *data)
10373 {
10374         struct cmd_show_queue_region_info *res = parsed_result;
10375         int ret = -ENOTSUP;
10376 #ifdef RTE_LIBRTE_I40E_PMD
10377         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10378         enum rte_pmd_i40e_queue_region_op op_type;
10379 #endif
10380
10381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10382                 return;
10383
10384 #ifdef RTE_LIBRTE_I40E_PMD
10385         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10386
10387         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10388
10389         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10390                                         op_type, &rte_pmd_regions);
10391
10392         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10393 #endif
10394
10395         switch (ret) {
10396         case 0:
10397                 break;
10398         case -ENOTSUP:
10399                 printf("function not implemented or supported\n");
10400                 break;
10401         default:
10402                 printf("queue region config info show error: (%s)\n",
10403                                 strerror(-ret));
10404         }
10405 }
10406
10407 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10408 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10409                                 show, "show");
10410 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10411         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10412                                 port, "port");
10413 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10414         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10415                                 port_id, UINT16);
10416 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10417         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10418                                 cmd, "queue-region");
10419
10420 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10421         .f = cmd_show_queue_region_info_parsed,
10422         .data = NULL,
10423         .help_str = "show port <port_id> queue-region"
10424                 ": show all queue region related configuration info",
10425         .tokens = {
10426                 (void *)&cmd_show_queue_region_info_get,
10427                 (void *)&cmd_show_queue_region_info_port,
10428                 (void *)&cmd_show_queue_region_info_port_index,
10429                 (void *)&cmd_show_queue_region_info_cmd,
10430                 NULL,
10431         },
10432 };
10433
10434 /* *** ADD/REMOVE A 2tuple FILTER *** */
10435 struct cmd_2tuple_filter_result {
10436         cmdline_fixed_string_t filter;
10437         portid_t port_id;
10438         cmdline_fixed_string_t ops;
10439         cmdline_fixed_string_t dst_port;
10440         uint16_t dst_port_value;
10441         cmdline_fixed_string_t protocol;
10442         uint8_t protocol_value;
10443         cmdline_fixed_string_t mask;
10444         uint8_t  mask_value;
10445         cmdline_fixed_string_t tcp_flags;
10446         uint8_t tcp_flags_value;
10447         cmdline_fixed_string_t priority;
10448         uint8_t  priority_value;
10449         cmdline_fixed_string_t queue;
10450         uint16_t  queue_id;
10451 };
10452
10453 static void
10454 cmd_2tuple_filter_parsed(void *parsed_result,
10455                         __rte_unused struct cmdline *cl,
10456                         __rte_unused void *data)
10457 {
10458         struct rte_eth_ntuple_filter filter;
10459         struct cmd_2tuple_filter_result *res = parsed_result;
10460         int ret = 0;
10461
10462         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10463         if (ret < 0) {
10464                 printf("ntuple filter is not supported on port %u.\n",
10465                         res->port_id);
10466                 return;
10467         }
10468
10469         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10470
10471         filter.flags = RTE_2TUPLE_FLAGS;
10472         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10473         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10474         filter.proto = res->protocol_value;
10475         filter.priority = res->priority_value;
10476         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10477                 printf("nonzero tcp_flags is only meaningful"
10478                         " when protocol is TCP.\n");
10479                 return;
10480         }
10481         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10482                 printf("invalid TCP flags.\n");
10483                 return;
10484         }
10485
10486         if (res->tcp_flags_value != 0) {
10487                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10488                 filter.tcp_flags = res->tcp_flags_value;
10489         }
10490
10491         /* need convert to big endian. */
10492         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10493         filter.queue = res->queue_id;
10494
10495         if (!strcmp(res->ops, "add"))
10496                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10497                                 RTE_ETH_FILTER_NTUPLE,
10498                                 RTE_ETH_FILTER_ADD,
10499                                 &filter);
10500         else
10501                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10502                                 RTE_ETH_FILTER_NTUPLE,
10503                                 RTE_ETH_FILTER_DELETE,
10504                                 &filter);
10505         if (ret < 0)
10506                 printf("2tuple filter programming error: (%s)\n",
10507                         strerror(-ret));
10508
10509 }
10510
10511 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10512         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10513                                  filter, "2tuple_filter");
10514 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10515         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10516                                 port_id, UINT16);
10517 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10518         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10519                                  ops, "add#del");
10520 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10521         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10522                                 dst_port, "dst_port");
10523 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10524         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10525                                 dst_port_value, UINT16);
10526 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10527         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10528                                 protocol, "protocol");
10529 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10530         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10531                                 protocol_value, UINT8);
10532 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10533         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10534                                 mask, "mask");
10535 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10536         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10537                                 mask_value, INT8);
10538 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10539         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10540                                 tcp_flags, "tcp_flags");
10541 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10542         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10543                                 tcp_flags_value, UINT8);
10544 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10545         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10546                                 priority, "priority");
10547 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10548         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10549                                 priority_value, UINT8);
10550 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10551         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10552                                 queue, "queue");
10553 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10554         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10555                                 queue_id, UINT16);
10556
10557 cmdline_parse_inst_t cmd_2tuple_filter = {
10558         .f = cmd_2tuple_filter_parsed,
10559         .data = NULL,
10560         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10561                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10562                 "<queue_id>: Add a 2tuple filter",
10563         .tokens = {
10564                 (void *)&cmd_2tuple_filter_filter,
10565                 (void *)&cmd_2tuple_filter_port_id,
10566                 (void *)&cmd_2tuple_filter_ops,
10567                 (void *)&cmd_2tuple_filter_dst_port,
10568                 (void *)&cmd_2tuple_filter_dst_port_value,
10569                 (void *)&cmd_2tuple_filter_protocol,
10570                 (void *)&cmd_2tuple_filter_protocol_value,
10571                 (void *)&cmd_2tuple_filter_mask,
10572                 (void *)&cmd_2tuple_filter_mask_value,
10573                 (void *)&cmd_2tuple_filter_tcp_flags,
10574                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10575                 (void *)&cmd_2tuple_filter_priority,
10576                 (void *)&cmd_2tuple_filter_priority_value,
10577                 (void *)&cmd_2tuple_filter_queue,
10578                 (void *)&cmd_2tuple_filter_queue_id,
10579                 NULL,
10580         },
10581 };
10582
10583 /* *** ADD/REMOVE A 5tuple FILTER *** */
10584 struct cmd_5tuple_filter_result {
10585         cmdline_fixed_string_t filter;
10586         portid_t port_id;
10587         cmdline_fixed_string_t ops;
10588         cmdline_fixed_string_t dst_ip;
10589         cmdline_ipaddr_t dst_ip_value;
10590         cmdline_fixed_string_t src_ip;
10591         cmdline_ipaddr_t src_ip_value;
10592         cmdline_fixed_string_t dst_port;
10593         uint16_t dst_port_value;
10594         cmdline_fixed_string_t src_port;
10595         uint16_t src_port_value;
10596         cmdline_fixed_string_t protocol;
10597         uint8_t protocol_value;
10598         cmdline_fixed_string_t mask;
10599         uint8_t  mask_value;
10600         cmdline_fixed_string_t tcp_flags;
10601         uint8_t tcp_flags_value;
10602         cmdline_fixed_string_t priority;
10603         uint8_t  priority_value;
10604         cmdline_fixed_string_t queue;
10605         uint16_t  queue_id;
10606 };
10607
10608 static void
10609 cmd_5tuple_filter_parsed(void *parsed_result,
10610                         __rte_unused struct cmdline *cl,
10611                         __rte_unused void *data)
10612 {
10613         struct rte_eth_ntuple_filter filter;
10614         struct cmd_5tuple_filter_result *res = parsed_result;
10615         int ret = 0;
10616
10617         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10618         if (ret < 0) {
10619                 printf("ntuple filter is not supported on port %u.\n",
10620                         res->port_id);
10621                 return;
10622         }
10623
10624         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10625
10626         filter.flags = RTE_5TUPLE_FLAGS;
10627         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10628         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10629         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10630         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10631         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10632         filter.proto = res->protocol_value;
10633         filter.priority = res->priority_value;
10634         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10635                 printf("nonzero tcp_flags is only meaningful"
10636                         " when protocol is TCP.\n");
10637                 return;
10638         }
10639         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10640                 printf("invalid TCP flags.\n");
10641                 return;
10642         }
10643
10644         if (res->tcp_flags_value != 0) {
10645                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10646                 filter.tcp_flags = res->tcp_flags_value;
10647         }
10648
10649         if (res->dst_ip_value.family == AF_INET)
10650                 /* no need to convert, already big endian. */
10651                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10652         else {
10653                 if (filter.dst_ip_mask == 0) {
10654                         printf("can not support ipv6 involved compare.\n");
10655                         return;
10656                 }
10657                 filter.dst_ip = 0;
10658         }
10659
10660         if (res->src_ip_value.family == AF_INET)
10661                 /* no need to convert, already big endian. */
10662                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10663         else {
10664                 if (filter.src_ip_mask == 0) {
10665                         printf("can not support ipv6 involved compare.\n");
10666                         return;
10667                 }
10668                 filter.src_ip = 0;
10669         }
10670         /* need convert to big endian. */
10671         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10672         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10673         filter.queue = res->queue_id;
10674
10675         if (!strcmp(res->ops, "add"))
10676                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10677                                 RTE_ETH_FILTER_NTUPLE,
10678                                 RTE_ETH_FILTER_ADD,
10679                                 &filter);
10680         else
10681                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10682                                 RTE_ETH_FILTER_NTUPLE,
10683                                 RTE_ETH_FILTER_DELETE,
10684                                 &filter);
10685         if (ret < 0)
10686                 printf("5tuple filter programming error: (%s)\n",
10687                         strerror(-ret));
10688 }
10689
10690 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10691         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10692                                  filter, "5tuple_filter");
10693 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10694         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10695                                 port_id, UINT16);
10696 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10697         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10698                                  ops, "add#del");
10699 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10700         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10701                                 dst_ip, "dst_ip");
10702 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10703         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10704                                 dst_ip_value);
10705 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10706         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10707                                 src_ip, "src_ip");
10708 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10709         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10710                                 src_ip_value);
10711 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10712         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10713                                 dst_port, "dst_port");
10714 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10715         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10716                                 dst_port_value, UINT16);
10717 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10718         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10719                                 src_port, "src_port");
10720 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10721         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10722                                 src_port_value, UINT16);
10723 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10724         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10725                                 protocol, "protocol");
10726 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10727         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10728                                 protocol_value, UINT8);
10729 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10730         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10731                                 mask, "mask");
10732 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10733         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10734                                 mask_value, INT8);
10735 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10736         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10737                                 tcp_flags, "tcp_flags");
10738 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10739         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10740                                 tcp_flags_value, UINT8);
10741 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10742         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10743                                 priority, "priority");
10744 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10745         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10746                                 priority_value, UINT8);
10747 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10748         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10749                                 queue, "queue");
10750 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10751         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10752                                 queue_id, UINT16);
10753
10754 cmdline_parse_inst_t cmd_5tuple_filter = {
10755         .f = cmd_5tuple_filter_parsed,
10756         .data = NULL,
10757         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10758                 "src_ip <value> dst_port <value> src_port <value> "
10759                 "protocol <value>  mask <value> tcp_flags <value> "
10760                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10761         .tokens = {
10762                 (void *)&cmd_5tuple_filter_filter,
10763                 (void *)&cmd_5tuple_filter_port_id,
10764                 (void *)&cmd_5tuple_filter_ops,
10765                 (void *)&cmd_5tuple_filter_dst_ip,
10766                 (void *)&cmd_5tuple_filter_dst_ip_value,
10767                 (void *)&cmd_5tuple_filter_src_ip,
10768                 (void *)&cmd_5tuple_filter_src_ip_value,
10769                 (void *)&cmd_5tuple_filter_dst_port,
10770                 (void *)&cmd_5tuple_filter_dst_port_value,
10771                 (void *)&cmd_5tuple_filter_src_port,
10772                 (void *)&cmd_5tuple_filter_src_port_value,
10773                 (void *)&cmd_5tuple_filter_protocol,
10774                 (void *)&cmd_5tuple_filter_protocol_value,
10775                 (void *)&cmd_5tuple_filter_mask,
10776                 (void *)&cmd_5tuple_filter_mask_value,
10777                 (void *)&cmd_5tuple_filter_tcp_flags,
10778                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10779                 (void *)&cmd_5tuple_filter_priority,
10780                 (void *)&cmd_5tuple_filter_priority_value,
10781                 (void *)&cmd_5tuple_filter_queue,
10782                 (void *)&cmd_5tuple_filter_queue_id,
10783                 NULL,
10784         },
10785 };
10786
10787 /* *** ADD/REMOVE A flex FILTER *** */
10788 struct cmd_flex_filter_result {
10789         cmdline_fixed_string_t filter;
10790         cmdline_fixed_string_t ops;
10791         portid_t port_id;
10792         cmdline_fixed_string_t len;
10793         uint8_t len_value;
10794         cmdline_fixed_string_t bytes;
10795         cmdline_fixed_string_t bytes_value;
10796         cmdline_fixed_string_t mask;
10797         cmdline_fixed_string_t mask_value;
10798         cmdline_fixed_string_t priority;
10799         uint8_t priority_value;
10800         cmdline_fixed_string_t queue;
10801         uint16_t queue_id;
10802 };
10803
10804 static int xdigit2val(unsigned char c)
10805 {
10806         int val;
10807         if (isdigit(c))
10808                 val = c - '0';
10809         else if (isupper(c))
10810                 val = c - 'A' + 10;
10811         else
10812                 val = c - 'a' + 10;
10813         return val;
10814 }
10815
10816 static void
10817 cmd_flex_filter_parsed(void *parsed_result,
10818                           __rte_unused struct cmdline *cl,
10819                           __rte_unused void *data)
10820 {
10821         int ret = 0;
10822         struct rte_eth_flex_filter filter;
10823         struct cmd_flex_filter_result *res = parsed_result;
10824         char *bytes_ptr, *mask_ptr;
10825         uint16_t len, i, j = 0;
10826         char c;
10827         int val;
10828         uint8_t byte = 0;
10829
10830         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10831                 printf("the len exceed the max length 128\n");
10832                 return;
10833         }
10834         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10835         filter.len = res->len_value;
10836         filter.priority = res->priority_value;
10837         filter.queue = res->queue_id;
10838         bytes_ptr = res->bytes_value;
10839         mask_ptr = res->mask_value;
10840
10841          /* translate bytes string to array. */
10842         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10843                 (bytes_ptr[1] == 'X')))
10844                 bytes_ptr += 2;
10845         len = strnlen(bytes_ptr, res->len_value * 2);
10846         if (len == 0 || (len % 8 != 0)) {
10847                 printf("please check len and bytes input\n");
10848                 return;
10849         }
10850         for (i = 0; i < len; i++) {
10851                 c = bytes_ptr[i];
10852                 if (isxdigit(c) == 0) {
10853                         /* invalid characters. */
10854                         printf("invalid input\n");
10855                         return;
10856                 }
10857                 val = xdigit2val(c);
10858                 if (i % 2) {
10859                         byte |= val;
10860                         filter.bytes[j] = byte;
10861                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10862                         j++;
10863                         byte = 0;
10864                 } else
10865                         byte |= val << 4;
10866         }
10867         printf("\n");
10868          /* translate mask string to uint8_t array. */
10869         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10870                 (mask_ptr[1] == 'X')))
10871                 mask_ptr += 2;
10872         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10873         if (len == 0) {
10874                 printf("invalid input\n");
10875                 return;
10876         }
10877         j = 0;
10878         byte = 0;
10879         for (i = 0; i < len; i++) {
10880                 c = mask_ptr[i];
10881                 if (isxdigit(c) == 0) {
10882                         /* invalid characters. */
10883                         printf("invalid input\n");
10884                         return;
10885                 }
10886                 val = xdigit2val(c);
10887                 if (i % 2) {
10888                         byte |= val;
10889                         filter.mask[j] = byte;
10890                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10891                         j++;
10892                         byte = 0;
10893                 } else
10894                         byte |= val << 4;
10895         }
10896         printf("\n");
10897
10898         if (!strcmp(res->ops, "add"))
10899                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10900                                 RTE_ETH_FILTER_FLEXIBLE,
10901                                 RTE_ETH_FILTER_ADD,
10902                                 &filter);
10903         else
10904                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10905                                 RTE_ETH_FILTER_FLEXIBLE,
10906                                 RTE_ETH_FILTER_DELETE,
10907                                 &filter);
10908
10909         if (ret < 0)
10910                 printf("flex filter setting error: (%s)\n", strerror(-ret));
10911 }
10912
10913 cmdline_parse_token_string_t cmd_flex_filter_filter =
10914         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10915                                 filter, "flex_filter");
10916 cmdline_parse_token_num_t cmd_flex_filter_port_id =
10917         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10918                                 port_id, UINT16);
10919 cmdline_parse_token_string_t cmd_flex_filter_ops =
10920         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10921                                 ops, "add#del");
10922 cmdline_parse_token_string_t cmd_flex_filter_len =
10923         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10924                                 len, "len");
10925 cmdline_parse_token_num_t cmd_flex_filter_len_value =
10926         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10927                                 len_value, UINT8);
10928 cmdline_parse_token_string_t cmd_flex_filter_bytes =
10929         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10930                                 bytes, "bytes");
10931 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
10932         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10933                                 bytes_value, NULL);
10934 cmdline_parse_token_string_t cmd_flex_filter_mask =
10935         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10936                                 mask, "mask");
10937 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
10938         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10939                                 mask_value, NULL);
10940 cmdline_parse_token_string_t cmd_flex_filter_priority =
10941         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10942                                 priority, "priority");
10943 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
10944         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10945                                 priority_value, UINT8);
10946 cmdline_parse_token_string_t cmd_flex_filter_queue =
10947         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
10948                                 queue, "queue");
10949 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
10950         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
10951                                 queue_id, UINT16);
10952 cmdline_parse_inst_t cmd_flex_filter = {
10953         .f = cmd_flex_filter_parsed,
10954         .data = NULL,
10955         .help_str = "flex_filter <port_id> add|del len <value> bytes "
10956                 "<value> mask <value> priority <value> queue <queue_id>: "
10957                 "Add/Del a flex filter",
10958         .tokens = {
10959                 (void *)&cmd_flex_filter_filter,
10960                 (void *)&cmd_flex_filter_port_id,
10961                 (void *)&cmd_flex_filter_ops,
10962                 (void *)&cmd_flex_filter_len,
10963                 (void *)&cmd_flex_filter_len_value,
10964                 (void *)&cmd_flex_filter_bytes,
10965                 (void *)&cmd_flex_filter_bytes_value,
10966                 (void *)&cmd_flex_filter_mask,
10967                 (void *)&cmd_flex_filter_mask_value,
10968                 (void *)&cmd_flex_filter_priority,
10969                 (void *)&cmd_flex_filter_priority_value,
10970                 (void *)&cmd_flex_filter_queue,
10971                 (void *)&cmd_flex_filter_queue_id,
10972                 NULL,
10973         },
10974 };
10975
10976 /* *** Filters Control *** */
10977
10978 /* *** deal with ethertype filter *** */
10979 struct cmd_ethertype_filter_result {
10980         cmdline_fixed_string_t filter;
10981         portid_t port_id;
10982         cmdline_fixed_string_t ops;
10983         cmdline_fixed_string_t mac;
10984         struct rte_ether_addr mac_addr;
10985         cmdline_fixed_string_t ethertype;
10986         uint16_t ethertype_value;
10987         cmdline_fixed_string_t drop;
10988         cmdline_fixed_string_t queue;
10989         uint16_t  queue_id;
10990 };
10991
10992 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
10993         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
10994                                  filter, "ethertype_filter");
10995 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
10996         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
10997                               port_id, UINT16);
10998 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
10999         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11000                                  ops, "add#del");
11001 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11002         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11003                                  mac, "mac_addr#mac_ignr");
11004 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11005         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11006                                      mac_addr);
11007 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11008         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11009                                  ethertype, "ethertype");
11010 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11011         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11012                               ethertype_value, UINT16);
11013 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11014         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11015                                  drop, "drop#fwd");
11016 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11017         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11018                                  queue, "queue");
11019 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11020         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11021                               queue_id, UINT16);
11022
11023 static void
11024 cmd_ethertype_filter_parsed(void *parsed_result,
11025                           __rte_unused struct cmdline *cl,
11026                           __rte_unused void *data)
11027 {
11028         struct cmd_ethertype_filter_result *res = parsed_result;
11029         struct rte_eth_ethertype_filter filter;
11030         int ret = 0;
11031
11032         ret = rte_eth_dev_filter_supported(res->port_id,
11033                         RTE_ETH_FILTER_ETHERTYPE);
11034         if (ret < 0) {
11035                 printf("ethertype filter is not supported on port %u.\n",
11036                         res->port_id);
11037                 return;
11038         }
11039
11040         memset(&filter, 0, sizeof(filter));
11041         if (!strcmp(res->mac, "mac_addr")) {
11042                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11043                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11044                         sizeof(struct rte_ether_addr));
11045         }
11046         if (!strcmp(res->drop, "drop"))
11047                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11048         filter.ether_type = res->ethertype_value;
11049         filter.queue = res->queue_id;
11050
11051         if (!strcmp(res->ops, "add"))
11052                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11053                                 RTE_ETH_FILTER_ETHERTYPE,
11054                                 RTE_ETH_FILTER_ADD,
11055                                 &filter);
11056         else
11057                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11058                                 RTE_ETH_FILTER_ETHERTYPE,
11059                                 RTE_ETH_FILTER_DELETE,
11060                                 &filter);
11061         if (ret < 0)
11062                 printf("ethertype filter programming error: (%s)\n",
11063                         strerror(-ret));
11064 }
11065
11066 cmdline_parse_inst_t cmd_ethertype_filter = {
11067         .f = cmd_ethertype_filter_parsed,
11068         .data = NULL,
11069         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11070                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11071                 "Add or delete an ethertype filter entry",
11072         .tokens = {
11073                 (void *)&cmd_ethertype_filter_filter,
11074                 (void *)&cmd_ethertype_filter_port_id,
11075                 (void *)&cmd_ethertype_filter_ops,
11076                 (void *)&cmd_ethertype_filter_mac,
11077                 (void *)&cmd_ethertype_filter_mac_addr,
11078                 (void *)&cmd_ethertype_filter_ethertype,
11079                 (void *)&cmd_ethertype_filter_ethertype_value,
11080                 (void *)&cmd_ethertype_filter_drop,
11081                 (void *)&cmd_ethertype_filter_queue,
11082                 (void *)&cmd_ethertype_filter_queue_id,
11083                 NULL,
11084         },
11085 };
11086
11087 /* *** deal with flow director filter *** */
11088 struct cmd_flow_director_result {
11089         cmdline_fixed_string_t flow_director_filter;
11090         portid_t port_id;
11091         cmdline_fixed_string_t mode;
11092         cmdline_fixed_string_t mode_value;
11093         cmdline_fixed_string_t ops;
11094         cmdline_fixed_string_t flow;
11095         cmdline_fixed_string_t flow_type;
11096         cmdline_fixed_string_t ether;
11097         uint16_t ether_type;
11098         cmdline_fixed_string_t src;
11099         cmdline_ipaddr_t ip_src;
11100         uint16_t port_src;
11101         cmdline_fixed_string_t dst;
11102         cmdline_ipaddr_t ip_dst;
11103         uint16_t port_dst;
11104         cmdline_fixed_string_t verify_tag;
11105         uint32_t verify_tag_value;
11106         cmdline_fixed_string_t tos;
11107         uint8_t tos_value;
11108         cmdline_fixed_string_t proto;
11109         uint8_t proto_value;
11110         cmdline_fixed_string_t ttl;
11111         uint8_t ttl_value;
11112         cmdline_fixed_string_t vlan;
11113         uint16_t vlan_value;
11114         cmdline_fixed_string_t flexbytes;
11115         cmdline_fixed_string_t flexbytes_value;
11116         cmdline_fixed_string_t pf_vf;
11117         cmdline_fixed_string_t drop;
11118         cmdline_fixed_string_t queue;
11119         uint16_t  queue_id;
11120         cmdline_fixed_string_t fd_id;
11121         uint32_t  fd_id_value;
11122         cmdline_fixed_string_t mac;
11123         struct rte_ether_addr mac_addr;
11124         cmdline_fixed_string_t tunnel;
11125         cmdline_fixed_string_t tunnel_type;
11126         cmdline_fixed_string_t tunnel_id;
11127         uint32_t tunnel_id_value;
11128         cmdline_fixed_string_t packet;
11129         char filepath[];
11130 };
11131
11132 static inline int
11133 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11134 {
11135         char s[256];
11136         const char *p, *p0 = q_arg;
11137         char *end;
11138         unsigned long int_fld;
11139         char *str_fld[max_num];
11140         int i;
11141         unsigned size;
11142         int ret = -1;
11143
11144         p = strchr(p0, '(');
11145         if (p == NULL)
11146                 return -1;
11147         ++p;
11148         p0 = strchr(p, ')');
11149         if (p0 == NULL)
11150                 return -1;
11151
11152         size = p0 - p;
11153         if (size >= sizeof(s))
11154                 return -1;
11155
11156         snprintf(s, sizeof(s), "%.*s", size, p);
11157         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11158         if (ret < 0 || ret > max_num)
11159                 return -1;
11160         for (i = 0; i < ret; i++) {
11161                 errno = 0;
11162                 int_fld = strtoul(str_fld[i], &end, 0);
11163                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11164                         return -1;
11165                 flexbytes[i] = (uint8_t)int_fld;
11166         }
11167         return ret;
11168 }
11169
11170 static uint16_t
11171 str2flowtype(char *string)
11172 {
11173         uint8_t i = 0;
11174         static const struct {
11175                 char str[32];
11176                 uint16_t type;
11177         } flowtype_str[] = {
11178                 {"raw", RTE_ETH_FLOW_RAW},
11179                 {"ipv4", RTE_ETH_FLOW_IPV4},
11180                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11181                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11182                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11183                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11184                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11185                 {"ipv6", RTE_ETH_FLOW_IPV6},
11186                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11187                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11188                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11189                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11190                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11191                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11192         };
11193
11194         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11195                 if (!strcmp(flowtype_str[i].str, string))
11196                         return flowtype_str[i].type;
11197         }
11198
11199         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11200                 return (uint16_t)atoi(string);
11201
11202         return RTE_ETH_FLOW_UNKNOWN;
11203 }
11204
11205 static enum rte_eth_fdir_tunnel_type
11206 str2fdir_tunneltype(char *string)
11207 {
11208         uint8_t i = 0;
11209
11210         static const struct {
11211                 char str[32];
11212                 enum rte_eth_fdir_tunnel_type type;
11213         } tunneltype_str[] = {
11214                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11215                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11216         };
11217
11218         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11219                 if (!strcmp(tunneltype_str[i].str, string))
11220                         return tunneltype_str[i].type;
11221         }
11222         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11223 }
11224
11225 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11226 do { \
11227         if ((ip_addr).family == AF_INET) \
11228                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11229         else { \
11230                 printf("invalid parameter.\n"); \
11231                 return; \
11232         } \
11233 } while (0)
11234
11235 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11236 do { \
11237         if ((ip_addr).family == AF_INET6) \
11238                 rte_memcpy(&(ip), \
11239                                  &((ip_addr).addr.ipv6), \
11240                                  sizeof(struct in6_addr)); \
11241         else { \
11242                 printf("invalid parameter.\n"); \
11243                 return; \
11244         } \
11245 } while (0)
11246
11247 static void
11248 cmd_flow_director_filter_parsed(void *parsed_result,
11249                           __rte_unused struct cmdline *cl,
11250                           __rte_unused void *data)
11251 {
11252         struct cmd_flow_director_result *res = parsed_result;
11253         struct rte_eth_fdir_filter entry;
11254         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11255         char *end;
11256         unsigned long vf_id;
11257         int ret = 0;
11258
11259         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11260         if (ret < 0) {
11261                 printf("flow director is not supported on port %u.\n",
11262                         res->port_id);
11263                 return;
11264         }
11265         memset(flexbytes, 0, sizeof(flexbytes));
11266         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11267
11268         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11269                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11270                         printf("Please set mode to MAC-VLAN.\n");
11271                         return;
11272                 }
11273         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11274                 if (strcmp(res->mode_value, "Tunnel")) {
11275                         printf("Please set mode to Tunnel.\n");
11276                         return;
11277                 }
11278         } else {
11279                 if (!strcmp(res->mode_value, "raw")) {
11280 #ifdef RTE_LIBRTE_I40E_PMD
11281                         struct rte_pmd_i40e_flow_type_mapping
11282                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11283                         struct rte_pmd_i40e_pkt_template_conf conf;
11284                         uint16_t flow_type = str2flowtype(res->flow_type);
11285                         uint16_t i, port = res->port_id;
11286                         uint8_t add;
11287
11288                         memset(&conf, 0, sizeof(conf));
11289
11290                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11291                                 printf("Invalid flow type specified.\n");
11292                                 return;
11293                         }
11294                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11295                                                                  mapping);
11296                         if (ret)
11297                                 return;
11298                         if (mapping[flow_type].pctype == 0ULL) {
11299                                 printf("Invalid flow type specified.\n");
11300                                 return;
11301                         }
11302                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11303                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11304                                         conf.input.pctype = i;
11305                                         break;
11306                                 }
11307                         }
11308
11309                         conf.input.packet = open_file(res->filepath,
11310                                                 &conf.input.length);
11311                         if (!conf.input.packet)
11312                                 return;
11313                         if (!strcmp(res->drop, "drop"))
11314                                 conf.action.behavior =
11315                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11316                         else
11317                                 conf.action.behavior =
11318                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11319                         conf.action.report_status =
11320                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11321                         conf.action.rx_queue = res->queue_id;
11322                         conf.soft_id = res->fd_id_value;
11323                         add  = strcmp(res->ops, "del") ? 1 : 0;
11324                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11325                                                                         &conf,
11326                                                                         add);
11327                         if (ret < 0)
11328                                 printf("flow director config error: (%s)\n",
11329                                        strerror(-ret));
11330                         close_file(conf.input.packet);
11331 #endif
11332                         return;
11333                 } else if (strcmp(res->mode_value, "IP")) {
11334                         printf("Please set mode to IP or raw.\n");
11335                         return;
11336                 }
11337                 entry.input.flow_type = str2flowtype(res->flow_type);
11338         }
11339
11340         ret = parse_flexbytes(res->flexbytes_value,
11341                                         flexbytes,
11342                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11343         if (ret < 0) {
11344                 printf("error: Cannot parse flexbytes input.\n");
11345                 return;
11346         }
11347
11348         switch (entry.input.flow_type) {
11349         case RTE_ETH_FLOW_FRAG_IPV4:
11350         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11351                 entry.input.flow.ip4_flow.proto = res->proto_value;
11352                 /* fall-through */
11353         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11354         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11355                 IPV4_ADDR_TO_UINT(res->ip_dst,
11356                         entry.input.flow.ip4_flow.dst_ip);
11357                 IPV4_ADDR_TO_UINT(res->ip_src,
11358                         entry.input.flow.ip4_flow.src_ip);
11359                 entry.input.flow.ip4_flow.tos = res->tos_value;
11360                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11361                 /* need convert to big endian. */
11362                 entry.input.flow.udp4_flow.dst_port =
11363                                 rte_cpu_to_be_16(res->port_dst);
11364                 entry.input.flow.udp4_flow.src_port =
11365                                 rte_cpu_to_be_16(res->port_src);
11366                 break;
11367         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11368                 IPV4_ADDR_TO_UINT(res->ip_dst,
11369                         entry.input.flow.sctp4_flow.ip.dst_ip);
11370                 IPV4_ADDR_TO_UINT(res->ip_src,
11371                         entry.input.flow.sctp4_flow.ip.src_ip);
11372                 entry.input.flow.ip4_flow.tos = res->tos_value;
11373                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11374                 /* need convert to big endian. */
11375                 entry.input.flow.sctp4_flow.dst_port =
11376                                 rte_cpu_to_be_16(res->port_dst);
11377                 entry.input.flow.sctp4_flow.src_port =
11378                                 rte_cpu_to_be_16(res->port_src);
11379                 entry.input.flow.sctp4_flow.verify_tag =
11380                                 rte_cpu_to_be_32(res->verify_tag_value);
11381                 break;
11382         case RTE_ETH_FLOW_FRAG_IPV6:
11383         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11384                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11385                 /* fall-through */
11386         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11387         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11388                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11389                         entry.input.flow.ipv6_flow.dst_ip);
11390                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11391                         entry.input.flow.ipv6_flow.src_ip);
11392                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11393                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11394                 /* need convert to big endian. */
11395                 entry.input.flow.udp6_flow.dst_port =
11396                                 rte_cpu_to_be_16(res->port_dst);
11397                 entry.input.flow.udp6_flow.src_port =
11398                                 rte_cpu_to_be_16(res->port_src);
11399                 break;
11400         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11401                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11402                         entry.input.flow.sctp6_flow.ip.dst_ip);
11403                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11404                         entry.input.flow.sctp6_flow.ip.src_ip);
11405                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11406                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11407                 /* need convert to big endian. */
11408                 entry.input.flow.sctp6_flow.dst_port =
11409                                 rte_cpu_to_be_16(res->port_dst);
11410                 entry.input.flow.sctp6_flow.src_port =
11411                                 rte_cpu_to_be_16(res->port_src);
11412                 entry.input.flow.sctp6_flow.verify_tag =
11413                                 rte_cpu_to_be_32(res->verify_tag_value);
11414                 break;
11415         case RTE_ETH_FLOW_L2_PAYLOAD:
11416                 entry.input.flow.l2_flow.ether_type =
11417                         rte_cpu_to_be_16(res->ether_type);
11418                 break;
11419         default:
11420                 break;
11421         }
11422
11423         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11424                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11425                                  &res->mac_addr,
11426                                  sizeof(struct rte_ether_addr));
11427
11428         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11429                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11430                                  &res->mac_addr,
11431                                  sizeof(struct rte_ether_addr));
11432                 entry.input.flow.tunnel_flow.tunnel_type =
11433                         str2fdir_tunneltype(res->tunnel_type);
11434                 entry.input.flow.tunnel_flow.tunnel_id =
11435                         rte_cpu_to_be_32(res->tunnel_id_value);
11436         }
11437
11438         rte_memcpy(entry.input.flow_ext.flexbytes,
11439                    flexbytes,
11440                    RTE_ETH_FDIR_MAX_FLEXLEN);
11441
11442         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11443
11444         entry.action.flex_off = 0;  /*use 0 by default */
11445         if (!strcmp(res->drop, "drop"))
11446                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11447         else
11448                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11449
11450         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11451             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11452                 if (!strcmp(res->pf_vf, "pf"))
11453                         entry.input.flow_ext.is_vf = 0;
11454                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11455                         struct rte_eth_dev_info dev_info;
11456
11457                         ret = eth_dev_info_get_print_err(res->port_id,
11458                                                 &dev_info);
11459                         if (ret != 0)
11460                                 return;
11461
11462                         errno = 0;
11463                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11464                         if (errno != 0 || *end != '\0' ||
11465                             vf_id >= dev_info.max_vfs) {
11466                                 printf("invalid parameter %s.\n", res->pf_vf);
11467                                 return;
11468                         }
11469                         entry.input.flow_ext.is_vf = 1;
11470                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11471                 } else {
11472                         printf("invalid parameter %s.\n", res->pf_vf);
11473                         return;
11474                 }
11475         }
11476
11477         /* set to report FD ID by default */
11478         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11479         entry.action.rx_queue = res->queue_id;
11480         entry.soft_id = res->fd_id_value;
11481         if (!strcmp(res->ops, "add"))
11482                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11483                                              RTE_ETH_FILTER_ADD, &entry);
11484         else if (!strcmp(res->ops, "del"))
11485                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11486                                              RTE_ETH_FILTER_DELETE, &entry);
11487         else
11488                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11489                                              RTE_ETH_FILTER_UPDATE, &entry);
11490         if (ret < 0)
11491                 printf("flow director programming error: (%s)\n",
11492                         strerror(-ret));
11493 }
11494
11495 cmdline_parse_token_string_t cmd_flow_director_filter =
11496         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11497                                  flow_director_filter, "flow_director_filter");
11498 cmdline_parse_token_num_t cmd_flow_director_port_id =
11499         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11500                               port_id, UINT16);
11501 cmdline_parse_token_string_t cmd_flow_director_ops =
11502         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11503                                  ops, "add#del#update");
11504 cmdline_parse_token_string_t cmd_flow_director_flow =
11505         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11506                                  flow, "flow");
11507 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11508         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11509                 flow_type, NULL);
11510 cmdline_parse_token_string_t cmd_flow_director_ether =
11511         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11512                                  ether, "ether");
11513 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11514         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11515                               ether_type, UINT16);
11516 cmdline_parse_token_string_t cmd_flow_director_src =
11517         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11518                                  src, "src");
11519 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11520         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11521                                  ip_src);
11522 cmdline_parse_token_num_t cmd_flow_director_port_src =
11523         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11524                               port_src, UINT16);
11525 cmdline_parse_token_string_t cmd_flow_director_dst =
11526         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11527                                  dst, "dst");
11528 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11529         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11530                                  ip_dst);
11531 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11532         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11533                               port_dst, UINT16);
11534 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11535         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11536                                   verify_tag, "verify_tag");
11537 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11538         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11539                               verify_tag_value, UINT32);
11540 cmdline_parse_token_string_t cmd_flow_director_tos =
11541         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11542                                  tos, "tos");
11543 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11544         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11545                               tos_value, UINT8);
11546 cmdline_parse_token_string_t cmd_flow_director_proto =
11547         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11548                                  proto, "proto");
11549 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11550         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11551                               proto_value, UINT8);
11552 cmdline_parse_token_string_t cmd_flow_director_ttl =
11553         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11554                                  ttl, "ttl");
11555 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11556         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11557                               ttl_value, UINT8);
11558 cmdline_parse_token_string_t cmd_flow_director_vlan =
11559         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11560                                  vlan, "vlan");
11561 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11562         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11563                               vlan_value, UINT16);
11564 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11565         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11566                                  flexbytes, "flexbytes");
11567 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11568         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11569                               flexbytes_value, NULL);
11570 cmdline_parse_token_string_t cmd_flow_director_drop =
11571         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11572                                  drop, "drop#fwd");
11573 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11574         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11575                               pf_vf, NULL);
11576 cmdline_parse_token_string_t cmd_flow_director_queue =
11577         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11578                                  queue, "queue");
11579 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11580         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11581                               queue_id, UINT16);
11582 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11583         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11584                                  fd_id, "fd_id");
11585 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11586         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11587                               fd_id_value, UINT32);
11588
11589 cmdline_parse_token_string_t cmd_flow_director_mode =
11590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11591                                  mode, "mode");
11592 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11593         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11594                                  mode_value, "IP");
11595 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11597                                  mode_value, "MAC-VLAN");
11598 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11599         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11600                                  mode_value, "Tunnel");
11601 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11603                                  mode_value, "raw");
11604 cmdline_parse_token_string_t cmd_flow_director_mac =
11605         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11606                                  mac, "mac");
11607 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11608         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11609                                     mac_addr);
11610 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11611         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11612                                  tunnel, "tunnel");
11613 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11614         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11615                                  tunnel_type, "NVGRE#VxLAN");
11616 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11617         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11618                                  tunnel_id, "tunnel-id");
11619 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11620         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11621                               tunnel_id_value, UINT32);
11622 cmdline_parse_token_string_t cmd_flow_director_packet =
11623         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11624                                  packet, "packet");
11625 cmdline_parse_token_string_t cmd_flow_director_filepath =
11626         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11627                                  filepath, NULL);
11628
11629 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11630         .f = cmd_flow_director_filter_parsed,
11631         .data = NULL,
11632         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11633                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11634                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11635                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11636                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11637                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11638                 "fd_id <fd_id_value>: "
11639                 "Add or delete an ip flow director entry on NIC",
11640         .tokens = {
11641                 (void *)&cmd_flow_director_filter,
11642                 (void *)&cmd_flow_director_port_id,
11643                 (void *)&cmd_flow_director_mode,
11644                 (void *)&cmd_flow_director_mode_ip,
11645                 (void *)&cmd_flow_director_ops,
11646                 (void *)&cmd_flow_director_flow,
11647                 (void *)&cmd_flow_director_flow_type,
11648                 (void *)&cmd_flow_director_src,
11649                 (void *)&cmd_flow_director_ip_src,
11650                 (void *)&cmd_flow_director_dst,
11651                 (void *)&cmd_flow_director_ip_dst,
11652                 (void *)&cmd_flow_director_tos,
11653                 (void *)&cmd_flow_director_tos_value,
11654                 (void *)&cmd_flow_director_proto,
11655                 (void *)&cmd_flow_director_proto_value,
11656                 (void *)&cmd_flow_director_ttl,
11657                 (void *)&cmd_flow_director_ttl_value,
11658                 (void *)&cmd_flow_director_vlan,
11659                 (void *)&cmd_flow_director_vlan_value,
11660                 (void *)&cmd_flow_director_flexbytes,
11661                 (void *)&cmd_flow_director_flexbytes_value,
11662                 (void *)&cmd_flow_director_drop,
11663                 (void *)&cmd_flow_director_pf_vf,
11664                 (void *)&cmd_flow_director_queue,
11665                 (void *)&cmd_flow_director_queue_id,
11666                 (void *)&cmd_flow_director_fd_id,
11667                 (void *)&cmd_flow_director_fd_id_value,
11668                 NULL,
11669         },
11670 };
11671
11672 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11673         .f = cmd_flow_director_filter_parsed,
11674         .data = NULL,
11675         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11676                 "director entry on NIC",
11677         .tokens = {
11678                 (void *)&cmd_flow_director_filter,
11679                 (void *)&cmd_flow_director_port_id,
11680                 (void *)&cmd_flow_director_mode,
11681                 (void *)&cmd_flow_director_mode_ip,
11682                 (void *)&cmd_flow_director_ops,
11683                 (void *)&cmd_flow_director_flow,
11684                 (void *)&cmd_flow_director_flow_type,
11685                 (void *)&cmd_flow_director_src,
11686                 (void *)&cmd_flow_director_ip_src,
11687                 (void *)&cmd_flow_director_port_src,
11688                 (void *)&cmd_flow_director_dst,
11689                 (void *)&cmd_flow_director_ip_dst,
11690                 (void *)&cmd_flow_director_port_dst,
11691                 (void *)&cmd_flow_director_tos,
11692                 (void *)&cmd_flow_director_tos_value,
11693                 (void *)&cmd_flow_director_ttl,
11694                 (void *)&cmd_flow_director_ttl_value,
11695                 (void *)&cmd_flow_director_vlan,
11696                 (void *)&cmd_flow_director_vlan_value,
11697                 (void *)&cmd_flow_director_flexbytes,
11698                 (void *)&cmd_flow_director_flexbytes_value,
11699                 (void *)&cmd_flow_director_drop,
11700                 (void *)&cmd_flow_director_pf_vf,
11701                 (void *)&cmd_flow_director_queue,
11702                 (void *)&cmd_flow_director_queue_id,
11703                 (void *)&cmd_flow_director_fd_id,
11704                 (void *)&cmd_flow_director_fd_id_value,
11705                 NULL,
11706         },
11707 };
11708
11709 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11710         .f = cmd_flow_director_filter_parsed,
11711         .data = NULL,
11712         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11713                 "director entry on NIC",
11714         .tokens = {
11715                 (void *)&cmd_flow_director_filter,
11716                 (void *)&cmd_flow_director_port_id,
11717                 (void *)&cmd_flow_director_mode,
11718                 (void *)&cmd_flow_director_mode_ip,
11719                 (void *)&cmd_flow_director_ops,
11720                 (void *)&cmd_flow_director_flow,
11721                 (void *)&cmd_flow_director_flow_type,
11722                 (void *)&cmd_flow_director_src,
11723                 (void *)&cmd_flow_director_ip_src,
11724                 (void *)&cmd_flow_director_port_src,
11725                 (void *)&cmd_flow_director_dst,
11726                 (void *)&cmd_flow_director_ip_dst,
11727                 (void *)&cmd_flow_director_port_dst,
11728                 (void *)&cmd_flow_director_verify_tag,
11729                 (void *)&cmd_flow_director_verify_tag_value,
11730                 (void *)&cmd_flow_director_tos,
11731                 (void *)&cmd_flow_director_tos_value,
11732                 (void *)&cmd_flow_director_ttl,
11733                 (void *)&cmd_flow_director_ttl_value,
11734                 (void *)&cmd_flow_director_vlan,
11735                 (void *)&cmd_flow_director_vlan_value,
11736                 (void *)&cmd_flow_director_flexbytes,
11737                 (void *)&cmd_flow_director_flexbytes_value,
11738                 (void *)&cmd_flow_director_drop,
11739                 (void *)&cmd_flow_director_pf_vf,
11740                 (void *)&cmd_flow_director_queue,
11741                 (void *)&cmd_flow_director_queue_id,
11742                 (void *)&cmd_flow_director_fd_id,
11743                 (void *)&cmd_flow_director_fd_id_value,
11744                 NULL,
11745         },
11746 };
11747
11748 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11749         .f = cmd_flow_director_filter_parsed,
11750         .data = NULL,
11751         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11752                 "director entry on NIC",
11753         .tokens = {
11754                 (void *)&cmd_flow_director_filter,
11755                 (void *)&cmd_flow_director_port_id,
11756                 (void *)&cmd_flow_director_mode,
11757                 (void *)&cmd_flow_director_mode_ip,
11758                 (void *)&cmd_flow_director_ops,
11759                 (void *)&cmd_flow_director_flow,
11760                 (void *)&cmd_flow_director_flow_type,
11761                 (void *)&cmd_flow_director_ether,
11762                 (void *)&cmd_flow_director_ether_type,
11763                 (void *)&cmd_flow_director_flexbytes,
11764                 (void *)&cmd_flow_director_flexbytes_value,
11765                 (void *)&cmd_flow_director_drop,
11766                 (void *)&cmd_flow_director_pf_vf,
11767                 (void *)&cmd_flow_director_queue,
11768                 (void *)&cmd_flow_director_queue_id,
11769                 (void *)&cmd_flow_director_fd_id,
11770                 (void *)&cmd_flow_director_fd_id_value,
11771                 NULL,
11772         },
11773 };
11774
11775 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11776         .f = cmd_flow_director_filter_parsed,
11777         .data = NULL,
11778         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11779                 "director entry on NIC",
11780         .tokens = {
11781                 (void *)&cmd_flow_director_filter,
11782                 (void *)&cmd_flow_director_port_id,
11783                 (void *)&cmd_flow_director_mode,
11784                 (void *)&cmd_flow_director_mode_mac_vlan,
11785                 (void *)&cmd_flow_director_ops,
11786                 (void *)&cmd_flow_director_mac,
11787                 (void *)&cmd_flow_director_mac_addr,
11788                 (void *)&cmd_flow_director_vlan,
11789                 (void *)&cmd_flow_director_vlan_value,
11790                 (void *)&cmd_flow_director_flexbytes,
11791                 (void *)&cmd_flow_director_flexbytes_value,
11792                 (void *)&cmd_flow_director_drop,
11793                 (void *)&cmd_flow_director_queue,
11794                 (void *)&cmd_flow_director_queue_id,
11795                 (void *)&cmd_flow_director_fd_id,
11796                 (void *)&cmd_flow_director_fd_id_value,
11797                 NULL,
11798         },
11799 };
11800
11801 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11802         .f = cmd_flow_director_filter_parsed,
11803         .data = NULL,
11804         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11805                 "director entry on NIC",
11806         .tokens = {
11807                 (void *)&cmd_flow_director_filter,
11808                 (void *)&cmd_flow_director_port_id,
11809                 (void *)&cmd_flow_director_mode,
11810                 (void *)&cmd_flow_director_mode_tunnel,
11811                 (void *)&cmd_flow_director_ops,
11812                 (void *)&cmd_flow_director_mac,
11813                 (void *)&cmd_flow_director_mac_addr,
11814                 (void *)&cmd_flow_director_vlan,
11815                 (void *)&cmd_flow_director_vlan_value,
11816                 (void *)&cmd_flow_director_tunnel,
11817                 (void *)&cmd_flow_director_tunnel_type,
11818                 (void *)&cmd_flow_director_tunnel_id,
11819                 (void *)&cmd_flow_director_tunnel_id_value,
11820                 (void *)&cmd_flow_director_flexbytes,
11821                 (void *)&cmd_flow_director_flexbytes_value,
11822                 (void *)&cmd_flow_director_drop,
11823                 (void *)&cmd_flow_director_queue,
11824                 (void *)&cmd_flow_director_queue_id,
11825                 (void *)&cmd_flow_director_fd_id,
11826                 (void *)&cmd_flow_director_fd_id_value,
11827                 NULL,
11828         },
11829 };
11830
11831 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11832         .f = cmd_flow_director_filter_parsed,
11833         .data = NULL,
11834         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11835                 "director entry on NIC",
11836         .tokens = {
11837                 (void *)&cmd_flow_director_filter,
11838                 (void *)&cmd_flow_director_port_id,
11839                 (void *)&cmd_flow_director_mode,
11840                 (void *)&cmd_flow_director_mode_raw,
11841                 (void *)&cmd_flow_director_ops,
11842                 (void *)&cmd_flow_director_flow,
11843                 (void *)&cmd_flow_director_flow_type,
11844                 (void *)&cmd_flow_director_drop,
11845                 (void *)&cmd_flow_director_queue,
11846                 (void *)&cmd_flow_director_queue_id,
11847                 (void *)&cmd_flow_director_fd_id,
11848                 (void *)&cmd_flow_director_fd_id_value,
11849                 (void *)&cmd_flow_director_packet,
11850                 (void *)&cmd_flow_director_filepath,
11851                 NULL,
11852         },
11853 };
11854
11855 struct cmd_flush_flow_director_result {
11856         cmdline_fixed_string_t flush_flow_director;
11857         portid_t port_id;
11858 };
11859
11860 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11861         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11862                                  flush_flow_director, "flush_flow_director");
11863 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11864         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11865                               port_id, UINT16);
11866
11867 static void
11868 cmd_flush_flow_director_parsed(void *parsed_result,
11869                           __rte_unused struct cmdline *cl,
11870                           __rte_unused void *data)
11871 {
11872         struct cmd_flow_director_result *res = parsed_result;
11873         int ret = 0;
11874
11875         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11876         if (ret < 0) {
11877                 printf("flow director is not supported on port %u.\n",
11878                         res->port_id);
11879                 return;
11880         }
11881
11882         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11883                         RTE_ETH_FILTER_FLUSH, NULL);
11884         if (ret < 0)
11885                 printf("flow director table flushing error: (%s)\n",
11886                         strerror(-ret));
11887 }
11888
11889 cmdline_parse_inst_t cmd_flush_flow_director = {
11890         .f = cmd_flush_flow_director_parsed,
11891         .data = NULL,
11892         .help_str = "flush_flow_director <port_id>: "
11893                 "Flush all flow director entries of a device on NIC",
11894         .tokens = {
11895                 (void *)&cmd_flush_flow_director_flush,
11896                 (void *)&cmd_flush_flow_director_port_id,
11897                 NULL,
11898         },
11899 };
11900
11901 /* *** deal with flow director mask *** */
11902 struct cmd_flow_director_mask_result {
11903         cmdline_fixed_string_t flow_director_mask;
11904         portid_t port_id;
11905         cmdline_fixed_string_t mode;
11906         cmdline_fixed_string_t mode_value;
11907         cmdline_fixed_string_t vlan;
11908         uint16_t vlan_mask;
11909         cmdline_fixed_string_t src_mask;
11910         cmdline_ipaddr_t ipv4_src;
11911         cmdline_ipaddr_t ipv6_src;
11912         uint16_t port_src;
11913         cmdline_fixed_string_t dst_mask;
11914         cmdline_ipaddr_t ipv4_dst;
11915         cmdline_ipaddr_t ipv6_dst;
11916         uint16_t port_dst;
11917         cmdline_fixed_string_t mac;
11918         uint8_t mac_addr_byte_mask;
11919         cmdline_fixed_string_t tunnel_id;
11920         uint32_t tunnel_id_mask;
11921         cmdline_fixed_string_t tunnel_type;
11922         uint8_t tunnel_type_mask;
11923 };
11924
11925 static void
11926 cmd_flow_director_mask_parsed(void *parsed_result,
11927                           __rte_unused struct cmdline *cl,
11928                           __rte_unused void *data)
11929 {
11930         struct cmd_flow_director_mask_result *res = parsed_result;
11931         struct rte_eth_fdir_masks *mask;
11932         struct rte_port *port;
11933
11934         port = &ports[res->port_id];
11935         /** Check if the port is not started **/
11936         if (port->port_status != RTE_PORT_STOPPED) {
11937                 printf("Please stop port %d first\n", res->port_id);
11938                 return;
11939         }
11940
11941         mask = &port->dev_conf.fdir_conf.mask;
11942
11943         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11944                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11945                         printf("Please set mode to MAC-VLAN.\n");
11946                         return;
11947                 }
11948
11949                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11950         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11951                 if (strcmp(res->mode_value, "Tunnel")) {
11952                         printf("Please set mode to Tunnel.\n");
11953                         return;
11954                 }
11955
11956                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11957                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11958                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11959                 mask->tunnel_type_mask = res->tunnel_type_mask;
11960         } else {
11961                 if (strcmp(res->mode_value, "IP")) {
11962                         printf("Please set mode to IP.\n");
11963                         return;
11964                 }
11965
11966                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11967                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11968                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11969                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11970                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11971                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11972                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11973         }
11974
11975         cmd_reconfig_device_queue(res->port_id, 1, 1);
11976 }
11977
11978 cmdline_parse_token_string_t cmd_flow_director_mask =
11979         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11980                                  flow_director_mask, "flow_director_mask");
11981 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11982         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11983                               port_id, UINT16);
11984 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11985         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11986                                  vlan, "vlan");
11987 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11988         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11989                               vlan_mask, UINT16);
11990 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11991         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11992                                  src_mask, "src_mask");
11993 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11994         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11995                                  ipv4_src);
11996 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11997         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11998                                  ipv6_src);
11999 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12000         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12001                               port_src, UINT16);
12002 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12003         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12004                                  dst_mask, "dst_mask");
12005 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12006         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12007                                  ipv4_dst);
12008 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12009         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12010                                  ipv6_dst);
12011 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12012         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12013                               port_dst, UINT16);
12014
12015 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12016         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12017                                  mode, "mode");
12018 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12019         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12020                                  mode_value, "IP");
12021 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12022         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12023                                  mode_value, "MAC-VLAN");
12024 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12025         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12026                                  mode_value, "Tunnel");
12027 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12028         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12029                                  mac, "mac");
12030 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12031         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12032                               mac_addr_byte_mask, UINT8);
12033 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12034         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12035                                  tunnel_type, "tunnel-type");
12036 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12037         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12038                               tunnel_type_mask, UINT8);
12039 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12040         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12041                                  tunnel_id, "tunnel-id");
12042 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12043         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12044                               tunnel_id_mask, UINT32);
12045
12046 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12047         .f = cmd_flow_director_mask_parsed,
12048         .data = NULL,
12049         .help_str = "flow_director_mask ... : "
12050                 "Set IP mode flow director's mask on NIC",
12051         .tokens = {
12052                 (void *)&cmd_flow_director_mask,
12053                 (void *)&cmd_flow_director_mask_port_id,
12054                 (void *)&cmd_flow_director_mask_mode,
12055                 (void *)&cmd_flow_director_mask_mode_ip,
12056                 (void *)&cmd_flow_director_mask_vlan,
12057                 (void *)&cmd_flow_director_mask_vlan_value,
12058                 (void *)&cmd_flow_director_mask_src,
12059                 (void *)&cmd_flow_director_mask_ipv4_src,
12060                 (void *)&cmd_flow_director_mask_ipv6_src,
12061                 (void *)&cmd_flow_director_mask_port_src,
12062                 (void *)&cmd_flow_director_mask_dst,
12063                 (void *)&cmd_flow_director_mask_ipv4_dst,
12064                 (void *)&cmd_flow_director_mask_ipv6_dst,
12065                 (void *)&cmd_flow_director_mask_port_dst,
12066                 NULL,
12067         },
12068 };
12069
12070 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12071         .f = cmd_flow_director_mask_parsed,
12072         .data = NULL,
12073         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12074                 "flow director's mask on NIC",
12075         .tokens = {
12076                 (void *)&cmd_flow_director_mask,
12077                 (void *)&cmd_flow_director_mask_port_id,
12078                 (void *)&cmd_flow_director_mask_mode,
12079                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12080                 (void *)&cmd_flow_director_mask_vlan,
12081                 (void *)&cmd_flow_director_mask_vlan_value,
12082                 NULL,
12083         },
12084 };
12085
12086 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12087         .f = cmd_flow_director_mask_parsed,
12088         .data = NULL,
12089         .help_str = "flow_director_mask ... : Set tunnel mode "
12090                 "flow director's mask on NIC",
12091         .tokens = {
12092                 (void *)&cmd_flow_director_mask,
12093                 (void *)&cmd_flow_director_mask_port_id,
12094                 (void *)&cmd_flow_director_mask_mode,
12095                 (void *)&cmd_flow_director_mask_mode_tunnel,
12096                 (void *)&cmd_flow_director_mask_vlan,
12097                 (void *)&cmd_flow_director_mask_vlan_value,
12098                 (void *)&cmd_flow_director_mask_mac,
12099                 (void *)&cmd_flow_director_mask_mac_value,
12100                 (void *)&cmd_flow_director_mask_tunnel_type,
12101                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12102                 (void *)&cmd_flow_director_mask_tunnel_id,
12103                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12104                 NULL,
12105         },
12106 };
12107
12108 /* *** deal with flow director mask on flexible payload *** */
12109 struct cmd_flow_director_flex_mask_result {
12110         cmdline_fixed_string_t flow_director_flexmask;
12111         portid_t port_id;
12112         cmdline_fixed_string_t flow;
12113         cmdline_fixed_string_t flow_type;
12114         cmdline_fixed_string_t mask;
12115 };
12116
12117 static void
12118 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12119                           __rte_unused struct cmdline *cl,
12120                           __rte_unused void *data)
12121 {
12122         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12123         struct rte_eth_fdir_info fdir_info;
12124         struct rte_eth_fdir_flex_mask flex_mask;
12125         struct rte_port *port;
12126         uint64_t flow_type_mask;
12127         uint16_t i;
12128         int ret;
12129
12130         port = &ports[res->port_id];
12131         /** Check if the port is not started **/
12132         if (port->port_status != RTE_PORT_STOPPED) {
12133                 printf("Please stop port %d first\n", res->port_id);
12134                 return;
12135         }
12136
12137         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12138         ret = parse_flexbytes(res->mask,
12139                         flex_mask.mask,
12140                         RTE_ETH_FDIR_MAX_FLEXLEN);
12141         if (ret < 0) {
12142                 printf("error: Cannot parse mask input.\n");
12143                 return;
12144         }
12145
12146         memset(&fdir_info, 0, sizeof(fdir_info));
12147         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12148                                 RTE_ETH_FILTER_INFO, &fdir_info);
12149         if (ret < 0) {
12150                 printf("Cannot get FDir filter info\n");
12151                 return;
12152         }
12153
12154         if (!strcmp(res->flow_type, "none")) {
12155                 /* means don't specify the flow type */
12156                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12157                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12158                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12159                                0, sizeof(struct rte_eth_fdir_flex_mask));
12160                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12161                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12162                                  &flex_mask,
12163                                  sizeof(struct rte_eth_fdir_flex_mask));
12164                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12165                 return;
12166         }
12167         flow_type_mask = fdir_info.flow_types_mask[0];
12168         if (!strcmp(res->flow_type, "all")) {
12169                 if (!flow_type_mask) {
12170                         printf("No flow type supported\n");
12171                         return;
12172                 }
12173                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12174                         if (flow_type_mask & (1ULL << i)) {
12175                                 flex_mask.flow_type = i;
12176                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12177                         }
12178                 }
12179                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12180                 return;
12181         }
12182         flex_mask.flow_type = str2flowtype(res->flow_type);
12183         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12184                 printf("Flow type %s not supported on port %d\n",
12185                                 res->flow_type, res->port_id);
12186                 return;
12187         }
12188         fdir_set_flex_mask(res->port_id, &flex_mask);
12189         cmd_reconfig_device_queue(res->port_id, 1, 1);
12190 }
12191
12192 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12194                                  flow_director_flexmask,
12195                                  "flow_director_flex_mask");
12196 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12197         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12198                               port_id, UINT16);
12199 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12200         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12201                                  flow, "flow");
12202 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12203         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12204                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12205                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12206 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12207         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12208                                  mask, NULL);
12209
12210 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12211         .f = cmd_flow_director_flex_mask_parsed,
12212         .data = NULL,
12213         .help_str = "flow_director_flex_mask ... : "
12214                 "Set flow director's flex mask on NIC",
12215         .tokens = {
12216                 (void *)&cmd_flow_director_flexmask,
12217                 (void *)&cmd_flow_director_flexmask_port_id,
12218                 (void *)&cmd_flow_director_flexmask_flow,
12219                 (void *)&cmd_flow_director_flexmask_flow_type,
12220                 (void *)&cmd_flow_director_flexmask_mask,
12221                 NULL,
12222         },
12223 };
12224
12225 /* *** deal with flow director flexible payload configuration *** */
12226 struct cmd_flow_director_flexpayload_result {
12227         cmdline_fixed_string_t flow_director_flexpayload;
12228         portid_t port_id;
12229         cmdline_fixed_string_t payload_layer;
12230         cmdline_fixed_string_t payload_cfg;
12231 };
12232
12233 static inline int
12234 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12235 {
12236         char s[256];
12237         const char *p, *p0 = q_arg;
12238         char *end;
12239         unsigned long int_fld;
12240         char *str_fld[max_num];
12241         int i;
12242         unsigned size;
12243         int ret = -1;
12244
12245         p = strchr(p0, '(');
12246         if (p == NULL)
12247                 return -1;
12248         ++p;
12249         p0 = strchr(p, ')');
12250         if (p0 == NULL)
12251                 return -1;
12252
12253         size = p0 - p;
12254         if (size >= sizeof(s))
12255                 return -1;
12256
12257         snprintf(s, sizeof(s), "%.*s", size, p);
12258         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12259         if (ret < 0 || ret > max_num)
12260                 return -1;
12261         for (i = 0; i < ret; i++) {
12262                 errno = 0;
12263                 int_fld = strtoul(str_fld[i], &end, 0);
12264                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12265                         return -1;
12266                 offsets[i] = (uint16_t)int_fld;
12267         }
12268         return ret;
12269 }
12270
12271 static void
12272 cmd_flow_director_flxpld_parsed(void *parsed_result,
12273                           __rte_unused struct cmdline *cl,
12274                           __rte_unused void *data)
12275 {
12276         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12277         struct rte_eth_flex_payload_cfg flex_cfg;
12278         struct rte_port *port;
12279         int ret = 0;
12280
12281         port = &ports[res->port_id];
12282         /** Check if the port is not started **/
12283         if (port->port_status != RTE_PORT_STOPPED) {
12284                 printf("Please stop port %d first\n", res->port_id);
12285                 return;
12286         }
12287
12288         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12289
12290         if (!strcmp(res->payload_layer, "raw"))
12291                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12292         else if (!strcmp(res->payload_layer, "l2"))
12293                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12294         else if (!strcmp(res->payload_layer, "l3"))
12295                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12296         else if (!strcmp(res->payload_layer, "l4"))
12297                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12298
12299         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12300                             RTE_ETH_FDIR_MAX_FLEXLEN);
12301         if (ret < 0) {
12302                 printf("error: Cannot parse flex payload input.\n");
12303                 return;
12304         }
12305
12306         fdir_set_flex_payload(res->port_id, &flex_cfg);
12307         cmd_reconfig_device_queue(res->port_id, 1, 1);
12308 }
12309
12310 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12311         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12312                                  flow_director_flexpayload,
12313                                  "flow_director_flex_payload");
12314 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12315         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12316                               port_id, UINT16);
12317 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12318         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12319                                  payload_layer, "raw#l2#l3#l4");
12320 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12321         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12322                                  payload_cfg, NULL);
12323
12324 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12325         .f = cmd_flow_director_flxpld_parsed,
12326         .data = NULL,
12327         .help_str = "flow_director_flexpayload ... : "
12328                 "Set flow director's flex payload on NIC",
12329         .tokens = {
12330                 (void *)&cmd_flow_director_flexpayload,
12331                 (void *)&cmd_flow_director_flexpayload_port_id,
12332                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12333                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12334                 NULL,
12335         },
12336 };
12337
12338 /* Generic flow interface command. */
12339 extern cmdline_parse_inst_t cmd_flow;
12340
12341 /* *** Classification Filters Control *** */
12342 /* *** Get symmetric hash enable per port *** */
12343 struct cmd_get_sym_hash_ena_per_port_result {
12344         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12345         portid_t port_id;
12346 };
12347
12348 static void
12349 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12350                                  __rte_unused struct cmdline *cl,
12351                                  __rte_unused void *data)
12352 {
12353         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12354         struct rte_eth_hash_filter_info info;
12355         int ret;
12356
12357         if (rte_eth_dev_filter_supported(res->port_id,
12358                                 RTE_ETH_FILTER_HASH) < 0) {
12359                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12360                                                         res->port_id);
12361                 return;
12362         }
12363
12364         memset(&info, 0, sizeof(info));
12365         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12366         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12367                                                 RTE_ETH_FILTER_GET, &info);
12368
12369         if (ret < 0) {
12370                 printf("Cannot get symmetric hash enable per port "
12371                                         "on port %u\n", res->port_id);
12372                 return;
12373         }
12374
12375         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12376                                 "enabled" : "disabled", res->port_id);
12377 }
12378
12379 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12380         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12381                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12382 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12383         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12384                 port_id, UINT16);
12385
12386 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12387         .f = cmd_get_sym_hash_per_port_parsed,
12388         .data = NULL,
12389         .help_str = "get_sym_hash_ena_per_port <port_id>",
12390         .tokens = {
12391                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12392                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12393                 NULL,
12394         },
12395 };
12396
12397 /* *** Set symmetric hash enable per port *** */
12398 struct cmd_set_sym_hash_ena_per_port_result {
12399         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12400         cmdline_fixed_string_t enable;
12401         portid_t port_id;
12402 };
12403
12404 static void
12405 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12406                                  __rte_unused struct cmdline *cl,
12407                                  __rte_unused void *data)
12408 {
12409         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12410         struct rte_eth_hash_filter_info info;
12411         int ret;
12412
12413         if (rte_eth_dev_filter_supported(res->port_id,
12414                                 RTE_ETH_FILTER_HASH) < 0) {
12415                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12416                                                         res->port_id);
12417                 return;
12418         }
12419
12420         memset(&info, 0, sizeof(info));
12421         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12422         if (!strcmp(res->enable, "enable"))
12423                 info.info.enable = 1;
12424         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12425                                         RTE_ETH_FILTER_SET, &info);
12426         if (ret < 0) {
12427                 printf("Cannot set symmetric hash enable per port on "
12428                                         "port %u\n", res->port_id);
12429                 return;
12430         }
12431         printf("Symmetric hash has been set to %s on port %u\n",
12432                                         res->enable, res->port_id);
12433 }
12434
12435 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12436         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12437                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12438 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12439         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12440                 port_id, UINT16);
12441 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12442         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12443                 enable, "enable#disable");
12444
12445 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12446         .f = cmd_set_sym_hash_per_port_parsed,
12447         .data = NULL,
12448         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12449         .tokens = {
12450                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12451                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12452                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12453                 NULL,
12454         },
12455 };
12456
12457 /* Get global config of hash function */
12458 struct cmd_get_hash_global_config_result {
12459         cmdline_fixed_string_t get_hash_global_config;
12460         portid_t port_id;
12461 };
12462
12463 static char *
12464 flowtype_to_str(uint16_t ftype)
12465 {
12466         uint16_t i;
12467         static struct {
12468                 char str[16];
12469                 uint16_t ftype;
12470         } ftype_table[] = {
12471                 {"ipv4", RTE_ETH_FLOW_IPV4},
12472                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12473                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12474                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12475                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12476                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12477                 {"ipv6", RTE_ETH_FLOW_IPV6},
12478                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12479                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12480                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12481                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12482                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12483                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12484                 {"port", RTE_ETH_FLOW_PORT},
12485                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12486                 {"geneve", RTE_ETH_FLOW_GENEVE},
12487                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12488                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12489         };
12490
12491         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12492                 if (ftype_table[i].ftype == ftype)
12493                         return ftype_table[i].str;
12494         }
12495
12496         return NULL;
12497 }
12498
12499 static void
12500 cmd_get_hash_global_config_parsed(void *parsed_result,
12501                                   __rte_unused struct cmdline *cl,
12502                                   __rte_unused void *data)
12503 {
12504         struct cmd_get_hash_global_config_result *res = parsed_result;
12505         struct rte_eth_hash_filter_info info;
12506         uint32_t idx, offset;
12507         uint16_t i;
12508         char *str;
12509         int ret;
12510
12511         if (rte_eth_dev_filter_supported(res->port_id,
12512                         RTE_ETH_FILTER_HASH) < 0) {
12513                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12514                                                         res->port_id);
12515                 return;
12516         }
12517
12518         memset(&info, 0, sizeof(info));
12519         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12520         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12521                                         RTE_ETH_FILTER_GET, &info);
12522         if (ret < 0) {
12523                 printf("Cannot get hash global configurations by port %d\n",
12524                                                         res->port_id);
12525                 return;
12526         }
12527
12528         switch (info.info.global_conf.hash_func) {
12529         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12530                 printf("Hash function is Toeplitz\n");
12531                 break;
12532         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12533                 printf("Hash function is Simple XOR\n");
12534                 break;
12535         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12536                 printf("Hash function is Symmetric Toeplitz\n");
12537                 break;
12538         default:
12539                 printf("Unknown hash function\n");
12540                 break;
12541         }
12542
12543         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12544                 idx = i / UINT64_BIT;
12545                 offset = i % UINT64_BIT;
12546                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12547                                                 (1ULL << offset)))
12548                         continue;
12549                 str = flowtype_to_str(i);
12550                 if (!str)
12551                         continue;
12552                 printf("Symmetric hash is %s globally for flow type %s "
12553                                                         "by port %d\n",
12554                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12555                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12556                                                         res->port_id);
12557         }
12558 }
12559
12560 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12561         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12562                 get_hash_global_config, "get_hash_global_config");
12563 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12564         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12565                 port_id, UINT16);
12566
12567 cmdline_parse_inst_t cmd_get_hash_global_config = {
12568         .f = cmd_get_hash_global_config_parsed,
12569         .data = NULL,
12570         .help_str = "get_hash_global_config <port_id>",
12571         .tokens = {
12572                 (void *)&cmd_get_hash_global_config_all,
12573                 (void *)&cmd_get_hash_global_config_port_id,
12574                 NULL,
12575         },
12576 };
12577
12578 /* Set global config of hash function */
12579 struct cmd_set_hash_global_config_result {
12580         cmdline_fixed_string_t set_hash_global_config;
12581         portid_t port_id;
12582         cmdline_fixed_string_t hash_func;
12583         cmdline_fixed_string_t flow_type;
12584         cmdline_fixed_string_t enable;
12585 };
12586
12587 static void
12588 cmd_set_hash_global_config_parsed(void *parsed_result,
12589                                   __rte_unused struct cmdline *cl,
12590                                   __rte_unused void *data)
12591 {
12592         struct cmd_set_hash_global_config_result *res = parsed_result;
12593         struct rte_eth_hash_filter_info info;
12594         uint32_t ftype, idx, offset;
12595         int ret;
12596
12597         if (rte_eth_dev_filter_supported(res->port_id,
12598                                 RTE_ETH_FILTER_HASH) < 0) {
12599                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12600                                                         res->port_id);
12601                 return;
12602         }
12603         memset(&info, 0, sizeof(info));
12604         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12605         if (!strcmp(res->hash_func, "toeplitz"))
12606                 info.info.global_conf.hash_func =
12607                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12608         else if (!strcmp(res->hash_func, "simple_xor"))
12609                 info.info.global_conf.hash_func =
12610                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12611         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12612                 info.info.global_conf.hash_func =
12613                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12614         else if (!strcmp(res->hash_func, "default"))
12615                 info.info.global_conf.hash_func =
12616                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12617
12618         ftype = str2flowtype(res->flow_type);
12619         idx = ftype / UINT64_BIT;
12620         offset = ftype % UINT64_BIT;
12621         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12622         if (!strcmp(res->enable, "enable"))
12623                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12624                                                 (1ULL << offset);
12625         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12626                                         RTE_ETH_FILTER_SET, &info);
12627         if (ret < 0)
12628                 printf("Cannot set global hash configurations by port %d\n",
12629                                                         res->port_id);
12630         else
12631                 printf("Global hash configurations have been set "
12632                         "successfully by port %d\n", res->port_id);
12633 }
12634
12635 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12636         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12637                 set_hash_global_config, "set_hash_global_config");
12638 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12639         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12640                 port_id, UINT16);
12641 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12642         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12643                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12644 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12645         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12646                 flow_type,
12647                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12648                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12649 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12650         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12651                 enable, "enable#disable");
12652
12653 cmdline_parse_inst_t cmd_set_hash_global_config = {
12654         .f = cmd_set_hash_global_config_parsed,
12655         .data = NULL,
12656         .help_str = "set_hash_global_config <port_id> "
12657                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12658                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12659                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12660                 "l2_payload enable|disable",
12661         .tokens = {
12662                 (void *)&cmd_set_hash_global_config_all,
12663                 (void *)&cmd_set_hash_global_config_port_id,
12664                 (void *)&cmd_set_hash_global_config_hash_func,
12665                 (void *)&cmd_set_hash_global_config_flow_type,
12666                 (void *)&cmd_set_hash_global_config_enable,
12667                 NULL,
12668         },
12669 };
12670
12671 /* Set hash input set */
12672 struct cmd_set_hash_input_set_result {
12673         cmdline_fixed_string_t set_hash_input_set;
12674         portid_t port_id;
12675         cmdline_fixed_string_t flow_type;
12676         cmdline_fixed_string_t inset_field;
12677         cmdline_fixed_string_t select;
12678 };
12679
12680 static enum rte_eth_input_set_field
12681 str2inset(char *string)
12682 {
12683         uint16_t i;
12684
12685         static const struct {
12686                 char str[32];
12687                 enum rte_eth_input_set_field inset;
12688         } inset_table[] = {
12689                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12690                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12691                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12692                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12693                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12694                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12695                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12696                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12697                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12698                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12699                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12700                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12701                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12702                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12703                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12704                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12705                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12706                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12707                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12708                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12709                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12710                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12711                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12712                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12713                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12714                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12715                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12716                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12717                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12718                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12719                 {"none", RTE_ETH_INPUT_SET_NONE},
12720         };
12721
12722         for (i = 0; i < RTE_DIM(inset_table); i++) {
12723                 if (!strcmp(string, inset_table[i].str))
12724                         return inset_table[i].inset;
12725         }
12726
12727         return RTE_ETH_INPUT_SET_UNKNOWN;
12728 }
12729
12730 static void
12731 cmd_set_hash_input_set_parsed(void *parsed_result,
12732                               __rte_unused struct cmdline *cl,
12733                               __rte_unused void *data)
12734 {
12735         struct cmd_set_hash_input_set_result *res = parsed_result;
12736         struct rte_eth_hash_filter_info info;
12737
12738         memset(&info, 0, sizeof(info));
12739         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12740         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12741         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12742         info.info.input_set_conf.inset_size = 1;
12743         if (!strcmp(res->select, "select"))
12744                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12745         else if (!strcmp(res->select, "add"))
12746                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12747         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12748                                 RTE_ETH_FILTER_SET, &info);
12749 }
12750
12751 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12752         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12753                 set_hash_input_set, "set_hash_input_set");
12754 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12755         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12756                 port_id, UINT16);
12757 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12758         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12759                 flow_type, NULL);
12760 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12761         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12762                 inset_field,
12763                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12764                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12765                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12766                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12767                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12768                 "fld-8th#none");
12769 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12770         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12771                 select, "select#add");
12772
12773 cmdline_parse_inst_t cmd_set_hash_input_set = {
12774         .f = cmd_set_hash_input_set_parsed,
12775         .data = NULL,
12776         .help_str = "set_hash_input_set <port_id> "
12777         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12778         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12779         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12780         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12781         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12782         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12783         "fld-7th|fld-8th|none select|add",
12784         .tokens = {
12785                 (void *)&cmd_set_hash_input_set_cmd,
12786                 (void *)&cmd_set_hash_input_set_port_id,
12787                 (void *)&cmd_set_hash_input_set_flow_type,
12788                 (void *)&cmd_set_hash_input_set_field,
12789                 (void *)&cmd_set_hash_input_set_select,
12790                 NULL,
12791         },
12792 };
12793
12794 /* Set flow director input set */
12795 struct cmd_set_fdir_input_set_result {
12796         cmdline_fixed_string_t set_fdir_input_set;
12797         portid_t port_id;
12798         cmdline_fixed_string_t flow_type;
12799         cmdline_fixed_string_t inset_field;
12800         cmdline_fixed_string_t select;
12801 };
12802
12803 static void
12804 cmd_set_fdir_input_set_parsed(void *parsed_result,
12805         __rte_unused struct cmdline *cl,
12806         __rte_unused void *data)
12807 {
12808         struct cmd_set_fdir_input_set_result *res = parsed_result;
12809         struct rte_eth_fdir_filter_info info;
12810
12811         memset(&info, 0, sizeof(info));
12812         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12813         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12814         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12815         info.info.input_set_conf.inset_size = 1;
12816         if (!strcmp(res->select, "select"))
12817                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12818         else if (!strcmp(res->select, "add"))
12819                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12820         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12821                 RTE_ETH_FILTER_SET, &info);
12822 }
12823
12824 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12825         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12826         set_fdir_input_set, "set_fdir_input_set");
12827 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12828         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12829         port_id, UINT16);
12830 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12831         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12832         flow_type,
12833         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12834         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12835 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12836         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12837         inset_field,
12838         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12839         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12840         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12841         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12842         "sctp-veri-tag#none");
12843 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12844         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12845         select, "select#add");
12846
12847 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12848         .f = cmd_set_fdir_input_set_parsed,
12849         .data = NULL,
12850         .help_str = "set_fdir_input_set <port_id> "
12851         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12852         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12853         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12854         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12855         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12856         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12857         "sctp-veri-tag|none select|add",
12858         .tokens = {
12859                 (void *)&cmd_set_fdir_input_set_cmd,
12860                 (void *)&cmd_set_fdir_input_set_port_id,
12861                 (void *)&cmd_set_fdir_input_set_flow_type,
12862                 (void *)&cmd_set_fdir_input_set_field,
12863                 (void *)&cmd_set_fdir_input_set_select,
12864                 NULL,
12865         },
12866 };
12867
12868 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12869 struct cmd_mcast_addr_result {
12870         cmdline_fixed_string_t mcast_addr_cmd;
12871         cmdline_fixed_string_t what;
12872         uint16_t port_num;
12873         struct rte_ether_addr mc_addr;
12874 };
12875
12876 static void cmd_mcast_addr_parsed(void *parsed_result,
12877                 __rte_unused struct cmdline *cl,
12878                 __rte_unused void *data)
12879 {
12880         struct cmd_mcast_addr_result *res = parsed_result;
12881
12882         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12883                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12884                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12885                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12886                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12887                 return;
12888         }
12889         if (strcmp(res->what, "add") == 0)
12890                 mcast_addr_add(res->port_num, &res->mc_addr);
12891         else
12892                 mcast_addr_remove(res->port_num, &res->mc_addr);
12893 }
12894
12895 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12896         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12897                                  mcast_addr_cmd, "mcast_addr");
12898 cmdline_parse_token_string_t cmd_mcast_addr_what =
12899         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12900                                  "add#remove");
12901 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12902         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12903 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12904         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
12905
12906 cmdline_parse_inst_t cmd_mcast_addr = {
12907         .f = cmd_mcast_addr_parsed,
12908         .data = (void *)0,
12909         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
12910                 "Add/Remove multicast MAC address on port_id",
12911         .tokens = {
12912                 (void *)&cmd_mcast_addr_cmd,
12913                 (void *)&cmd_mcast_addr_what,
12914                 (void *)&cmd_mcast_addr_portnum,
12915                 (void *)&cmd_mcast_addr_addr,
12916                 NULL,
12917         },
12918 };
12919
12920 /* l2 tunnel config
12921  * only support E-tag now.
12922  */
12923
12924 /* Ether type config */
12925 struct cmd_config_l2_tunnel_eth_type_result {
12926         cmdline_fixed_string_t port;
12927         cmdline_fixed_string_t config;
12928         cmdline_fixed_string_t all;
12929         portid_t id;
12930         cmdline_fixed_string_t l2_tunnel;
12931         cmdline_fixed_string_t l2_tunnel_type;
12932         cmdline_fixed_string_t eth_type;
12933         uint16_t eth_type_val;
12934 };
12935
12936 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
12937         TOKEN_STRING_INITIALIZER
12938                 (struct cmd_config_l2_tunnel_eth_type_result,
12939                  port, "port");
12940 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
12941         TOKEN_STRING_INITIALIZER
12942                 (struct cmd_config_l2_tunnel_eth_type_result,
12943                  config, "config");
12944 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
12945         TOKEN_STRING_INITIALIZER
12946                 (struct cmd_config_l2_tunnel_eth_type_result,
12947                  all, "all");
12948 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
12949         TOKEN_NUM_INITIALIZER
12950                 (struct cmd_config_l2_tunnel_eth_type_result,
12951                  id, UINT16);
12952 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
12953         TOKEN_STRING_INITIALIZER
12954                 (struct cmd_config_l2_tunnel_eth_type_result,
12955                  l2_tunnel, "l2-tunnel");
12956 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
12957         TOKEN_STRING_INITIALIZER
12958                 (struct cmd_config_l2_tunnel_eth_type_result,
12959                  l2_tunnel_type, "E-tag");
12960 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
12961         TOKEN_STRING_INITIALIZER
12962                 (struct cmd_config_l2_tunnel_eth_type_result,
12963                  eth_type, "ether-type");
12964 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
12965         TOKEN_NUM_INITIALIZER
12966                 (struct cmd_config_l2_tunnel_eth_type_result,
12967                  eth_type_val, UINT16);
12968
12969 static enum rte_eth_tunnel_type
12970 str2fdir_l2_tunnel_type(char *string)
12971 {
12972         uint32_t i = 0;
12973
12974         static const struct {
12975                 char str[32];
12976                 enum rte_eth_tunnel_type type;
12977         } l2_tunnel_type_str[] = {
12978                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
12979         };
12980
12981         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
12982                 if (!strcmp(l2_tunnel_type_str[i].str, string))
12983                         return l2_tunnel_type_str[i].type;
12984         }
12985         return RTE_TUNNEL_TYPE_NONE;
12986 }
12987
12988 /* ether type config for all ports */
12989 static void
12990 cmd_config_l2_tunnel_eth_type_all_parsed
12991         (void *parsed_result,
12992          __rte_unused struct cmdline *cl,
12993          __rte_unused void *data)
12994 {
12995         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
12996         struct rte_eth_l2_tunnel_conf entry;
12997         portid_t pid;
12998
12999         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13000         entry.ether_type = res->eth_type_val;
13001
13002         RTE_ETH_FOREACH_DEV(pid) {
13003                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13004         }
13005 }
13006
13007 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13008         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13009         .data = NULL,
13010         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13011         .tokens = {
13012                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13013                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13014                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13015                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13016                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13017                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13018                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13019                 NULL,
13020         },
13021 };
13022
13023 /* ether type config for a specific port */
13024 static void
13025 cmd_config_l2_tunnel_eth_type_specific_parsed(
13026         void *parsed_result,
13027         __rte_unused struct cmdline *cl,
13028         __rte_unused void *data)
13029 {
13030         struct cmd_config_l2_tunnel_eth_type_result *res =
13031                  parsed_result;
13032         struct rte_eth_l2_tunnel_conf entry;
13033
13034         if (port_id_is_invalid(res->id, ENABLED_WARN))
13035                 return;
13036
13037         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13038         entry.ether_type = res->eth_type_val;
13039
13040         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13041 }
13042
13043 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13044         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13045         .data = NULL,
13046         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13047         .tokens = {
13048                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13049                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13050                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13051                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13052                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13053                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13054                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13055                 NULL,
13056         },
13057 };
13058
13059 /* Enable/disable l2 tunnel */
13060 struct cmd_config_l2_tunnel_en_dis_result {
13061         cmdline_fixed_string_t port;
13062         cmdline_fixed_string_t config;
13063         cmdline_fixed_string_t all;
13064         portid_t id;
13065         cmdline_fixed_string_t l2_tunnel;
13066         cmdline_fixed_string_t l2_tunnel_type;
13067         cmdline_fixed_string_t en_dis;
13068 };
13069
13070 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13071         TOKEN_STRING_INITIALIZER
13072                 (struct cmd_config_l2_tunnel_en_dis_result,
13073                  port, "port");
13074 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13075         TOKEN_STRING_INITIALIZER
13076                 (struct cmd_config_l2_tunnel_en_dis_result,
13077                  config, "config");
13078 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_config_l2_tunnel_en_dis_result,
13081                  all, "all");
13082 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13083         TOKEN_NUM_INITIALIZER
13084                 (struct cmd_config_l2_tunnel_en_dis_result,
13085                  id, UINT16);
13086 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13087         TOKEN_STRING_INITIALIZER
13088                 (struct cmd_config_l2_tunnel_en_dis_result,
13089                  l2_tunnel, "l2-tunnel");
13090 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13091         TOKEN_STRING_INITIALIZER
13092                 (struct cmd_config_l2_tunnel_en_dis_result,
13093                  l2_tunnel_type, "E-tag");
13094 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_config_l2_tunnel_en_dis_result,
13097                  en_dis, "enable#disable");
13098
13099 /* enable/disable l2 tunnel for all ports */
13100 static void
13101 cmd_config_l2_tunnel_en_dis_all_parsed(
13102         void *parsed_result,
13103         __rte_unused struct cmdline *cl,
13104         __rte_unused void *data)
13105 {
13106         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13107         struct rte_eth_l2_tunnel_conf entry;
13108         portid_t pid;
13109         uint8_t en;
13110
13111         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13112
13113         if (!strcmp("enable", res->en_dis))
13114                 en = 1;
13115         else
13116                 en = 0;
13117
13118         RTE_ETH_FOREACH_DEV(pid) {
13119                 rte_eth_dev_l2_tunnel_offload_set(pid,
13120                                                   &entry,
13121                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13122                                                   en);
13123         }
13124 }
13125
13126 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13127         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13128         .data = NULL,
13129         .help_str = "port config all l2-tunnel E-tag enable|disable",
13130         .tokens = {
13131                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13132                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13133                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13134                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13135                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13136                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13137                 NULL,
13138         },
13139 };
13140
13141 /* enable/disable l2 tunnel for a port */
13142 static void
13143 cmd_config_l2_tunnel_en_dis_specific_parsed(
13144         void *parsed_result,
13145         __rte_unused struct cmdline *cl,
13146         __rte_unused void *data)
13147 {
13148         struct cmd_config_l2_tunnel_en_dis_result *res =
13149                 parsed_result;
13150         struct rte_eth_l2_tunnel_conf entry;
13151
13152         if (port_id_is_invalid(res->id, ENABLED_WARN))
13153                 return;
13154
13155         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13156
13157         if (!strcmp("enable", res->en_dis))
13158                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13159                                                   &entry,
13160                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13161                                                   1);
13162         else
13163                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13164                                                   &entry,
13165                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13166                                                   0);
13167 }
13168
13169 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13170         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13171         .data = NULL,
13172         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13173         .tokens = {
13174                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13175                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13176                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13177                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13178                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13179                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13180                 NULL,
13181         },
13182 };
13183
13184 /* E-tag configuration */
13185
13186 /* Common result structure for all E-tag configuration */
13187 struct cmd_config_e_tag_result {
13188         cmdline_fixed_string_t e_tag;
13189         cmdline_fixed_string_t set;
13190         cmdline_fixed_string_t insertion;
13191         cmdline_fixed_string_t stripping;
13192         cmdline_fixed_string_t forwarding;
13193         cmdline_fixed_string_t filter;
13194         cmdline_fixed_string_t add;
13195         cmdline_fixed_string_t del;
13196         cmdline_fixed_string_t on;
13197         cmdline_fixed_string_t off;
13198         cmdline_fixed_string_t on_off;
13199         cmdline_fixed_string_t port_tag_id;
13200         uint32_t port_tag_id_val;
13201         cmdline_fixed_string_t e_tag_id;
13202         uint16_t e_tag_id_val;
13203         cmdline_fixed_string_t dst_pool;
13204         uint8_t dst_pool_val;
13205         cmdline_fixed_string_t port;
13206         portid_t port_id;
13207         cmdline_fixed_string_t vf;
13208         uint8_t vf_id;
13209 };
13210
13211 /* Common CLI fields for all E-tag configuration */
13212 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13213         TOKEN_STRING_INITIALIZER
13214                 (struct cmd_config_e_tag_result,
13215                  e_tag, "E-tag");
13216 cmdline_parse_token_string_t cmd_config_e_tag_set =
13217         TOKEN_STRING_INITIALIZER
13218                 (struct cmd_config_e_tag_result,
13219                  set, "set");
13220 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13221         TOKEN_STRING_INITIALIZER
13222                 (struct cmd_config_e_tag_result,
13223                  insertion, "insertion");
13224 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13225         TOKEN_STRING_INITIALIZER
13226                 (struct cmd_config_e_tag_result,
13227                  stripping, "stripping");
13228 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13229         TOKEN_STRING_INITIALIZER
13230                 (struct cmd_config_e_tag_result,
13231                  forwarding, "forwarding");
13232 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13233         TOKEN_STRING_INITIALIZER
13234                 (struct cmd_config_e_tag_result,
13235                  filter, "filter");
13236 cmdline_parse_token_string_t cmd_config_e_tag_add =
13237         TOKEN_STRING_INITIALIZER
13238                 (struct cmd_config_e_tag_result,
13239                  add, "add");
13240 cmdline_parse_token_string_t cmd_config_e_tag_del =
13241         TOKEN_STRING_INITIALIZER
13242                 (struct cmd_config_e_tag_result,
13243                  del, "del");
13244 cmdline_parse_token_string_t cmd_config_e_tag_on =
13245         TOKEN_STRING_INITIALIZER
13246                 (struct cmd_config_e_tag_result,
13247                  on, "on");
13248 cmdline_parse_token_string_t cmd_config_e_tag_off =
13249         TOKEN_STRING_INITIALIZER
13250                 (struct cmd_config_e_tag_result,
13251                  off, "off");
13252 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13253         TOKEN_STRING_INITIALIZER
13254                 (struct cmd_config_e_tag_result,
13255                  on_off, "on#off");
13256 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13257         TOKEN_STRING_INITIALIZER
13258                 (struct cmd_config_e_tag_result,
13259                  port_tag_id, "port-tag-id");
13260 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13261         TOKEN_NUM_INITIALIZER
13262                 (struct cmd_config_e_tag_result,
13263                  port_tag_id_val, UINT32);
13264 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13265         TOKEN_STRING_INITIALIZER
13266                 (struct cmd_config_e_tag_result,
13267                  e_tag_id, "e-tag-id");
13268 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13269         TOKEN_NUM_INITIALIZER
13270                 (struct cmd_config_e_tag_result,
13271                  e_tag_id_val, UINT16);
13272 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13273         TOKEN_STRING_INITIALIZER
13274                 (struct cmd_config_e_tag_result,
13275                  dst_pool, "dst-pool");
13276 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13277         TOKEN_NUM_INITIALIZER
13278                 (struct cmd_config_e_tag_result,
13279                  dst_pool_val, UINT8);
13280 cmdline_parse_token_string_t cmd_config_e_tag_port =
13281         TOKEN_STRING_INITIALIZER
13282                 (struct cmd_config_e_tag_result,
13283                  port, "port");
13284 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13285         TOKEN_NUM_INITIALIZER
13286                 (struct cmd_config_e_tag_result,
13287                  port_id, UINT16);
13288 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13289         TOKEN_STRING_INITIALIZER
13290                 (struct cmd_config_e_tag_result,
13291                  vf, "vf");
13292 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13293         TOKEN_NUM_INITIALIZER
13294                 (struct cmd_config_e_tag_result,
13295                  vf_id, UINT8);
13296
13297 /* E-tag insertion configuration */
13298 static void
13299 cmd_config_e_tag_insertion_en_parsed(
13300         void *parsed_result,
13301         __rte_unused struct cmdline *cl,
13302         __rte_unused void *data)
13303 {
13304         struct cmd_config_e_tag_result *res =
13305                 parsed_result;
13306         struct rte_eth_l2_tunnel_conf entry;
13307
13308         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13309                 return;
13310
13311         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13312         entry.tunnel_id = res->port_tag_id_val;
13313         entry.vf_id = res->vf_id;
13314         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13315                                           &entry,
13316                                           ETH_L2_TUNNEL_INSERTION_MASK,
13317                                           1);
13318 }
13319
13320 static void
13321 cmd_config_e_tag_insertion_dis_parsed(
13322         void *parsed_result,
13323         __rte_unused struct cmdline *cl,
13324         __rte_unused void *data)
13325 {
13326         struct cmd_config_e_tag_result *res =
13327                 parsed_result;
13328         struct rte_eth_l2_tunnel_conf entry;
13329
13330         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13331                 return;
13332
13333         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13334         entry.vf_id = res->vf_id;
13335
13336         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13337                                           &entry,
13338                                           ETH_L2_TUNNEL_INSERTION_MASK,
13339                                           0);
13340 }
13341
13342 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13343         .f = cmd_config_e_tag_insertion_en_parsed,
13344         .data = NULL,
13345         .help_str = "E-tag ... : E-tag insertion enable",
13346         .tokens = {
13347                 (void *)&cmd_config_e_tag_e_tag,
13348                 (void *)&cmd_config_e_tag_set,
13349                 (void *)&cmd_config_e_tag_insertion,
13350                 (void *)&cmd_config_e_tag_on,
13351                 (void *)&cmd_config_e_tag_port_tag_id,
13352                 (void *)&cmd_config_e_tag_port_tag_id_val,
13353                 (void *)&cmd_config_e_tag_port,
13354                 (void *)&cmd_config_e_tag_port_id,
13355                 (void *)&cmd_config_e_tag_vf,
13356                 (void *)&cmd_config_e_tag_vf_id,
13357                 NULL,
13358         },
13359 };
13360
13361 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13362         .f = cmd_config_e_tag_insertion_dis_parsed,
13363         .data = NULL,
13364         .help_str = "E-tag ... : E-tag insertion disable",
13365         .tokens = {
13366                 (void *)&cmd_config_e_tag_e_tag,
13367                 (void *)&cmd_config_e_tag_set,
13368                 (void *)&cmd_config_e_tag_insertion,
13369                 (void *)&cmd_config_e_tag_off,
13370                 (void *)&cmd_config_e_tag_port,
13371                 (void *)&cmd_config_e_tag_port_id,
13372                 (void *)&cmd_config_e_tag_vf,
13373                 (void *)&cmd_config_e_tag_vf_id,
13374                 NULL,
13375         },
13376 };
13377
13378 /* E-tag stripping configuration */
13379 static void
13380 cmd_config_e_tag_stripping_parsed(
13381         void *parsed_result,
13382         __rte_unused struct cmdline *cl,
13383         __rte_unused void *data)
13384 {
13385         struct cmd_config_e_tag_result *res =
13386                 parsed_result;
13387         struct rte_eth_l2_tunnel_conf entry;
13388
13389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13390                 return;
13391
13392         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13393
13394         if (!strcmp(res->on_off, "on"))
13395                 rte_eth_dev_l2_tunnel_offload_set
13396                         (res->port_id,
13397                          &entry,
13398                          ETH_L2_TUNNEL_STRIPPING_MASK,
13399                          1);
13400         else
13401                 rte_eth_dev_l2_tunnel_offload_set
13402                         (res->port_id,
13403                          &entry,
13404                          ETH_L2_TUNNEL_STRIPPING_MASK,
13405                          0);
13406 }
13407
13408 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13409         .f = cmd_config_e_tag_stripping_parsed,
13410         .data = NULL,
13411         .help_str = "E-tag ... : E-tag stripping enable/disable",
13412         .tokens = {
13413                 (void *)&cmd_config_e_tag_e_tag,
13414                 (void *)&cmd_config_e_tag_set,
13415                 (void *)&cmd_config_e_tag_stripping,
13416                 (void *)&cmd_config_e_tag_on_off,
13417                 (void *)&cmd_config_e_tag_port,
13418                 (void *)&cmd_config_e_tag_port_id,
13419                 NULL,
13420         },
13421 };
13422
13423 /* E-tag forwarding configuration */
13424 static void
13425 cmd_config_e_tag_forwarding_parsed(
13426         void *parsed_result,
13427         __rte_unused struct cmdline *cl,
13428         __rte_unused void *data)
13429 {
13430         struct cmd_config_e_tag_result *res = parsed_result;
13431         struct rte_eth_l2_tunnel_conf entry;
13432
13433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13434                 return;
13435
13436         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13437
13438         if (!strcmp(res->on_off, "on"))
13439                 rte_eth_dev_l2_tunnel_offload_set
13440                         (res->port_id,
13441                          &entry,
13442                          ETH_L2_TUNNEL_FORWARDING_MASK,
13443                          1);
13444         else
13445                 rte_eth_dev_l2_tunnel_offload_set
13446                         (res->port_id,
13447                          &entry,
13448                          ETH_L2_TUNNEL_FORWARDING_MASK,
13449                          0);
13450 }
13451
13452 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13453         .f = cmd_config_e_tag_forwarding_parsed,
13454         .data = NULL,
13455         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13456         .tokens = {
13457                 (void *)&cmd_config_e_tag_e_tag,
13458                 (void *)&cmd_config_e_tag_set,
13459                 (void *)&cmd_config_e_tag_forwarding,
13460                 (void *)&cmd_config_e_tag_on_off,
13461                 (void *)&cmd_config_e_tag_port,
13462                 (void *)&cmd_config_e_tag_port_id,
13463                 NULL,
13464         },
13465 };
13466
13467 /* E-tag filter configuration */
13468 static void
13469 cmd_config_e_tag_filter_add_parsed(
13470         void *parsed_result,
13471         __rte_unused struct cmdline *cl,
13472         __rte_unused void *data)
13473 {
13474         struct cmd_config_e_tag_result *res = parsed_result;
13475         struct rte_eth_l2_tunnel_conf entry;
13476         int ret = 0;
13477
13478         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13479                 return;
13480
13481         if (res->e_tag_id_val > 0x3fff) {
13482                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13483                 return;
13484         }
13485
13486         ret = rte_eth_dev_filter_supported(res->port_id,
13487                                            RTE_ETH_FILTER_L2_TUNNEL);
13488         if (ret < 0) {
13489                 printf("E-tag filter is not supported on port %u.\n",
13490                        res->port_id);
13491                 return;
13492         }
13493
13494         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13495         entry.tunnel_id = res->e_tag_id_val;
13496         entry.pool = res->dst_pool_val;
13497
13498         ret = rte_eth_dev_filter_ctrl(res->port_id,
13499                                       RTE_ETH_FILTER_L2_TUNNEL,
13500                                       RTE_ETH_FILTER_ADD,
13501                                       &entry);
13502         if (ret < 0)
13503                 printf("E-tag filter programming error: (%s)\n",
13504                        strerror(-ret));
13505 }
13506
13507 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13508         .f = cmd_config_e_tag_filter_add_parsed,
13509         .data = NULL,
13510         .help_str = "E-tag ... : E-tag filter add",
13511         .tokens = {
13512                 (void *)&cmd_config_e_tag_e_tag,
13513                 (void *)&cmd_config_e_tag_set,
13514                 (void *)&cmd_config_e_tag_filter,
13515                 (void *)&cmd_config_e_tag_add,
13516                 (void *)&cmd_config_e_tag_e_tag_id,
13517                 (void *)&cmd_config_e_tag_e_tag_id_val,
13518                 (void *)&cmd_config_e_tag_dst_pool,
13519                 (void *)&cmd_config_e_tag_dst_pool_val,
13520                 (void *)&cmd_config_e_tag_port,
13521                 (void *)&cmd_config_e_tag_port_id,
13522                 NULL,
13523         },
13524 };
13525
13526 static void
13527 cmd_config_e_tag_filter_del_parsed(
13528         void *parsed_result,
13529         __rte_unused struct cmdline *cl,
13530         __rte_unused void *data)
13531 {
13532         struct cmd_config_e_tag_result *res = parsed_result;
13533         struct rte_eth_l2_tunnel_conf entry;
13534         int ret = 0;
13535
13536         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13537                 return;
13538
13539         if (res->e_tag_id_val > 0x3fff) {
13540                 printf("e-tag-id must be less than 0x3fff.\n");
13541                 return;
13542         }
13543
13544         ret = rte_eth_dev_filter_supported(res->port_id,
13545                                            RTE_ETH_FILTER_L2_TUNNEL);
13546         if (ret < 0) {
13547                 printf("E-tag filter is not supported on port %u.\n",
13548                        res->port_id);
13549                 return;
13550         }
13551
13552         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13553         entry.tunnel_id = res->e_tag_id_val;
13554
13555         ret = rte_eth_dev_filter_ctrl(res->port_id,
13556                                       RTE_ETH_FILTER_L2_TUNNEL,
13557                                       RTE_ETH_FILTER_DELETE,
13558                                       &entry);
13559         if (ret < 0)
13560                 printf("E-tag filter programming error: (%s)\n",
13561                        strerror(-ret));
13562 }
13563
13564 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13565         .f = cmd_config_e_tag_filter_del_parsed,
13566         .data = NULL,
13567         .help_str = "E-tag ... : E-tag filter delete",
13568         .tokens = {
13569                 (void *)&cmd_config_e_tag_e_tag,
13570                 (void *)&cmd_config_e_tag_set,
13571                 (void *)&cmd_config_e_tag_filter,
13572                 (void *)&cmd_config_e_tag_del,
13573                 (void *)&cmd_config_e_tag_e_tag_id,
13574                 (void *)&cmd_config_e_tag_e_tag_id_val,
13575                 (void *)&cmd_config_e_tag_port,
13576                 (void *)&cmd_config_e_tag_port_id,
13577                 NULL,
13578         },
13579 };
13580
13581 /* vf vlan anti spoof configuration */
13582
13583 /* Common result structure for vf vlan anti spoof */
13584 struct cmd_vf_vlan_anti_spoof_result {
13585         cmdline_fixed_string_t set;
13586         cmdline_fixed_string_t vf;
13587         cmdline_fixed_string_t vlan;
13588         cmdline_fixed_string_t antispoof;
13589         portid_t port_id;
13590         uint32_t vf_id;
13591         cmdline_fixed_string_t on_off;
13592 };
13593
13594 /* Common CLI fields for vf vlan anti spoof enable disable */
13595 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13596         TOKEN_STRING_INITIALIZER
13597                 (struct cmd_vf_vlan_anti_spoof_result,
13598                  set, "set");
13599 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13600         TOKEN_STRING_INITIALIZER
13601                 (struct cmd_vf_vlan_anti_spoof_result,
13602                  vf, "vf");
13603 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13604         TOKEN_STRING_INITIALIZER
13605                 (struct cmd_vf_vlan_anti_spoof_result,
13606                  vlan, "vlan");
13607 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13608         TOKEN_STRING_INITIALIZER
13609                 (struct cmd_vf_vlan_anti_spoof_result,
13610                  antispoof, "antispoof");
13611 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13612         TOKEN_NUM_INITIALIZER
13613                 (struct cmd_vf_vlan_anti_spoof_result,
13614                  port_id, UINT16);
13615 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13616         TOKEN_NUM_INITIALIZER
13617                 (struct cmd_vf_vlan_anti_spoof_result,
13618                  vf_id, UINT32);
13619 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13620         TOKEN_STRING_INITIALIZER
13621                 (struct cmd_vf_vlan_anti_spoof_result,
13622                  on_off, "on#off");
13623
13624 static void
13625 cmd_set_vf_vlan_anti_spoof_parsed(
13626         void *parsed_result,
13627         __rte_unused struct cmdline *cl,
13628         __rte_unused void *data)
13629 {
13630         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13631         int ret = -ENOTSUP;
13632
13633         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13634
13635         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13636                 return;
13637
13638 #ifdef RTE_LIBRTE_IXGBE_PMD
13639         if (ret == -ENOTSUP)
13640                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13641                                 res->vf_id, is_on);
13642 #endif
13643 #ifdef RTE_LIBRTE_I40E_PMD
13644         if (ret == -ENOTSUP)
13645                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13646                                 res->vf_id, is_on);
13647 #endif
13648 #ifdef RTE_LIBRTE_BNXT_PMD
13649         if (ret == -ENOTSUP)
13650                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13651                                 res->vf_id, is_on);
13652 #endif
13653
13654         switch (ret) {
13655         case 0:
13656                 break;
13657         case -EINVAL:
13658                 printf("invalid vf_id %d\n", res->vf_id);
13659                 break;
13660         case -ENODEV:
13661                 printf("invalid port_id %d\n", res->port_id);
13662                 break;
13663         case -ENOTSUP:
13664                 printf("function not implemented\n");
13665                 break;
13666         default:
13667                 printf("programming error: (%s)\n", strerror(-ret));
13668         }
13669 }
13670
13671 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13672         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13673         .data = NULL,
13674         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13675         .tokens = {
13676                 (void *)&cmd_vf_vlan_anti_spoof_set,
13677                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13678                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13679                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13680                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13681                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13682                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13683                 NULL,
13684         },
13685 };
13686
13687 /* vf mac anti spoof configuration */
13688
13689 /* Common result structure for vf mac anti spoof */
13690 struct cmd_vf_mac_anti_spoof_result {
13691         cmdline_fixed_string_t set;
13692         cmdline_fixed_string_t vf;
13693         cmdline_fixed_string_t mac;
13694         cmdline_fixed_string_t antispoof;
13695         portid_t port_id;
13696         uint32_t vf_id;
13697         cmdline_fixed_string_t on_off;
13698 };
13699
13700 /* Common CLI fields for vf mac anti spoof enable disable */
13701 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13702         TOKEN_STRING_INITIALIZER
13703                 (struct cmd_vf_mac_anti_spoof_result,
13704                  set, "set");
13705 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13706         TOKEN_STRING_INITIALIZER
13707                 (struct cmd_vf_mac_anti_spoof_result,
13708                  vf, "vf");
13709 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13710         TOKEN_STRING_INITIALIZER
13711                 (struct cmd_vf_mac_anti_spoof_result,
13712                  mac, "mac");
13713 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13714         TOKEN_STRING_INITIALIZER
13715                 (struct cmd_vf_mac_anti_spoof_result,
13716                  antispoof, "antispoof");
13717 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13718         TOKEN_NUM_INITIALIZER
13719                 (struct cmd_vf_mac_anti_spoof_result,
13720                  port_id, UINT16);
13721 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13722         TOKEN_NUM_INITIALIZER
13723                 (struct cmd_vf_mac_anti_spoof_result,
13724                  vf_id, UINT32);
13725 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13726         TOKEN_STRING_INITIALIZER
13727                 (struct cmd_vf_mac_anti_spoof_result,
13728                  on_off, "on#off");
13729
13730 static void
13731 cmd_set_vf_mac_anti_spoof_parsed(
13732         void *parsed_result,
13733         __rte_unused struct cmdline *cl,
13734         __rte_unused void *data)
13735 {
13736         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13737         int ret = -ENOTSUP;
13738
13739         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13740
13741         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13742                 return;
13743
13744 #ifdef RTE_LIBRTE_IXGBE_PMD
13745         if (ret == -ENOTSUP)
13746                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13747                         res->vf_id, is_on);
13748 #endif
13749 #ifdef RTE_LIBRTE_I40E_PMD
13750         if (ret == -ENOTSUP)
13751                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13752                         res->vf_id, is_on);
13753 #endif
13754 #ifdef RTE_LIBRTE_BNXT_PMD
13755         if (ret == -ENOTSUP)
13756                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13757                         res->vf_id, is_on);
13758 #endif
13759
13760         switch (ret) {
13761         case 0:
13762                 break;
13763         case -EINVAL:
13764                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13765                 break;
13766         case -ENODEV:
13767                 printf("invalid port_id %d\n", res->port_id);
13768                 break;
13769         case -ENOTSUP:
13770                 printf("function not implemented\n");
13771                 break;
13772         default:
13773                 printf("programming error: (%s)\n", strerror(-ret));
13774         }
13775 }
13776
13777 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13778         .f = cmd_set_vf_mac_anti_spoof_parsed,
13779         .data = NULL,
13780         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13781         .tokens = {
13782                 (void *)&cmd_vf_mac_anti_spoof_set,
13783                 (void *)&cmd_vf_mac_anti_spoof_vf,
13784                 (void *)&cmd_vf_mac_anti_spoof_mac,
13785                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13786                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13787                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13788                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13789                 NULL,
13790         },
13791 };
13792
13793 /* vf vlan strip queue configuration */
13794
13795 /* Common result structure for vf mac anti spoof */
13796 struct cmd_vf_vlan_stripq_result {
13797         cmdline_fixed_string_t set;
13798         cmdline_fixed_string_t vf;
13799         cmdline_fixed_string_t vlan;
13800         cmdline_fixed_string_t stripq;
13801         portid_t port_id;
13802         uint16_t vf_id;
13803         cmdline_fixed_string_t on_off;
13804 };
13805
13806 /* Common CLI fields for vf vlan strip enable disable */
13807 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13808         TOKEN_STRING_INITIALIZER
13809                 (struct cmd_vf_vlan_stripq_result,
13810                  set, "set");
13811 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13812         TOKEN_STRING_INITIALIZER
13813                 (struct cmd_vf_vlan_stripq_result,
13814                  vf, "vf");
13815 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13816         TOKEN_STRING_INITIALIZER
13817                 (struct cmd_vf_vlan_stripq_result,
13818                  vlan, "vlan");
13819 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13820         TOKEN_STRING_INITIALIZER
13821                 (struct cmd_vf_vlan_stripq_result,
13822                  stripq, "stripq");
13823 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13824         TOKEN_NUM_INITIALIZER
13825                 (struct cmd_vf_vlan_stripq_result,
13826                  port_id, UINT16);
13827 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13828         TOKEN_NUM_INITIALIZER
13829                 (struct cmd_vf_vlan_stripq_result,
13830                  vf_id, UINT16);
13831 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13832         TOKEN_STRING_INITIALIZER
13833                 (struct cmd_vf_vlan_stripq_result,
13834                  on_off, "on#off");
13835
13836 static void
13837 cmd_set_vf_vlan_stripq_parsed(
13838         void *parsed_result,
13839         __rte_unused struct cmdline *cl,
13840         __rte_unused void *data)
13841 {
13842         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13843         int ret = -ENOTSUP;
13844
13845         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13846
13847         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13848                 return;
13849
13850 #ifdef RTE_LIBRTE_IXGBE_PMD
13851         if (ret == -ENOTSUP)
13852                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13853                         res->vf_id, is_on);
13854 #endif
13855 #ifdef RTE_LIBRTE_I40E_PMD
13856         if (ret == -ENOTSUP)
13857                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13858                         res->vf_id, is_on);
13859 #endif
13860 #ifdef RTE_LIBRTE_BNXT_PMD
13861         if (ret == -ENOTSUP)
13862                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13863                         res->vf_id, is_on);
13864 #endif
13865
13866         switch (ret) {
13867         case 0:
13868                 break;
13869         case -EINVAL:
13870                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13871                 break;
13872         case -ENODEV:
13873                 printf("invalid port_id %d\n", res->port_id);
13874                 break;
13875         case -ENOTSUP:
13876                 printf("function not implemented\n");
13877                 break;
13878         default:
13879                 printf("programming error: (%s)\n", strerror(-ret));
13880         }
13881 }
13882
13883 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13884         .f = cmd_set_vf_vlan_stripq_parsed,
13885         .data = NULL,
13886         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13887         .tokens = {
13888                 (void *)&cmd_vf_vlan_stripq_set,
13889                 (void *)&cmd_vf_vlan_stripq_vf,
13890                 (void *)&cmd_vf_vlan_stripq_vlan,
13891                 (void *)&cmd_vf_vlan_stripq_stripq,
13892                 (void *)&cmd_vf_vlan_stripq_port_id,
13893                 (void *)&cmd_vf_vlan_stripq_vf_id,
13894                 (void *)&cmd_vf_vlan_stripq_on_off,
13895                 NULL,
13896         },
13897 };
13898
13899 /* vf vlan insert configuration */
13900
13901 /* Common result structure for vf vlan insert */
13902 struct cmd_vf_vlan_insert_result {
13903         cmdline_fixed_string_t set;
13904         cmdline_fixed_string_t vf;
13905         cmdline_fixed_string_t vlan;
13906         cmdline_fixed_string_t insert;
13907         portid_t port_id;
13908         uint16_t vf_id;
13909         uint16_t vlan_id;
13910 };
13911
13912 /* Common CLI fields for vf vlan insert enable disable */
13913 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
13914         TOKEN_STRING_INITIALIZER
13915                 (struct cmd_vf_vlan_insert_result,
13916                  set, "set");
13917 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
13918         TOKEN_STRING_INITIALIZER
13919                 (struct cmd_vf_vlan_insert_result,
13920                  vf, "vf");
13921 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
13922         TOKEN_STRING_INITIALIZER
13923                 (struct cmd_vf_vlan_insert_result,
13924                  vlan, "vlan");
13925 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
13926         TOKEN_STRING_INITIALIZER
13927                 (struct cmd_vf_vlan_insert_result,
13928                  insert, "insert");
13929 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
13930         TOKEN_NUM_INITIALIZER
13931                 (struct cmd_vf_vlan_insert_result,
13932                  port_id, UINT16);
13933 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
13934         TOKEN_NUM_INITIALIZER
13935                 (struct cmd_vf_vlan_insert_result,
13936                  vf_id, UINT16);
13937 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
13938         TOKEN_NUM_INITIALIZER
13939                 (struct cmd_vf_vlan_insert_result,
13940                  vlan_id, UINT16);
13941
13942 static void
13943 cmd_set_vf_vlan_insert_parsed(
13944         void *parsed_result,
13945         __rte_unused struct cmdline *cl,
13946         __rte_unused void *data)
13947 {
13948         struct cmd_vf_vlan_insert_result *res = parsed_result;
13949         int ret = -ENOTSUP;
13950
13951         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13952                 return;
13953
13954 #ifdef RTE_LIBRTE_IXGBE_PMD
13955         if (ret == -ENOTSUP)
13956                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
13957                         res->vlan_id);
13958 #endif
13959 #ifdef RTE_LIBRTE_I40E_PMD
13960         if (ret == -ENOTSUP)
13961                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
13962                         res->vlan_id);
13963 #endif
13964 #ifdef RTE_LIBRTE_BNXT_PMD
13965         if (ret == -ENOTSUP)
13966                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
13967                         res->vlan_id);
13968 #endif
13969
13970         switch (ret) {
13971         case 0:
13972                 break;
13973         case -EINVAL:
13974                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
13975                 break;
13976         case -ENODEV:
13977                 printf("invalid port_id %d\n", res->port_id);
13978                 break;
13979         case -ENOTSUP:
13980                 printf("function not implemented\n");
13981                 break;
13982         default:
13983                 printf("programming error: (%s)\n", strerror(-ret));
13984         }
13985 }
13986
13987 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
13988         .f = cmd_set_vf_vlan_insert_parsed,
13989         .data = NULL,
13990         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
13991         .tokens = {
13992                 (void *)&cmd_vf_vlan_insert_set,
13993                 (void *)&cmd_vf_vlan_insert_vf,
13994                 (void *)&cmd_vf_vlan_insert_vlan,
13995                 (void *)&cmd_vf_vlan_insert_insert,
13996                 (void *)&cmd_vf_vlan_insert_port_id,
13997                 (void *)&cmd_vf_vlan_insert_vf_id,
13998                 (void *)&cmd_vf_vlan_insert_vlan_id,
13999                 NULL,
14000         },
14001 };
14002
14003 /* tx loopback configuration */
14004
14005 /* Common result structure for tx loopback */
14006 struct cmd_tx_loopback_result {
14007         cmdline_fixed_string_t set;
14008         cmdline_fixed_string_t tx;
14009         cmdline_fixed_string_t loopback;
14010         portid_t port_id;
14011         cmdline_fixed_string_t on_off;
14012 };
14013
14014 /* Common CLI fields for tx loopback enable disable */
14015 cmdline_parse_token_string_t cmd_tx_loopback_set =
14016         TOKEN_STRING_INITIALIZER
14017                 (struct cmd_tx_loopback_result,
14018                  set, "set");
14019 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14020         TOKEN_STRING_INITIALIZER
14021                 (struct cmd_tx_loopback_result,
14022                  tx, "tx");
14023 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14024         TOKEN_STRING_INITIALIZER
14025                 (struct cmd_tx_loopback_result,
14026                  loopback, "loopback");
14027 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14028         TOKEN_NUM_INITIALIZER
14029                 (struct cmd_tx_loopback_result,
14030                  port_id, UINT16);
14031 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14032         TOKEN_STRING_INITIALIZER
14033                 (struct cmd_tx_loopback_result,
14034                  on_off, "on#off");
14035
14036 static void
14037 cmd_set_tx_loopback_parsed(
14038         void *parsed_result,
14039         __rte_unused struct cmdline *cl,
14040         __rte_unused void *data)
14041 {
14042         struct cmd_tx_loopback_result *res = parsed_result;
14043         int ret = -ENOTSUP;
14044
14045         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14046
14047         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14048                 return;
14049
14050 #ifdef RTE_LIBRTE_IXGBE_PMD
14051         if (ret == -ENOTSUP)
14052                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14053 #endif
14054 #ifdef RTE_LIBRTE_I40E_PMD
14055         if (ret == -ENOTSUP)
14056                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14057 #endif
14058 #ifdef RTE_LIBRTE_BNXT_PMD
14059         if (ret == -ENOTSUP)
14060                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14061 #endif
14062 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14063         if (ret == -ENOTSUP)
14064                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14065 #endif
14066
14067         switch (ret) {
14068         case 0:
14069                 break;
14070         case -EINVAL:
14071                 printf("invalid is_on %d\n", is_on);
14072                 break;
14073         case -ENODEV:
14074                 printf("invalid port_id %d\n", res->port_id);
14075                 break;
14076         case -ENOTSUP:
14077                 printf("function not implemented\n");
14078                 break;
14079         default:
14080                 printf("programming error: (%s)\n", strerror(-ret));
14081         }
14082 }
14083
14084 cmdline_parse_inst_t cmd_set_tx_loopback = {
14085         .f = cmd_set_tx_loopback_parsed,
14086         .data = NULL,
14087         .help_str = "set tx loopback <port_id> on|off",
14088         .tokens = {
14089                 (void *)&cmd_tx_loopback_set,
14090                 (void *)&cmd_tx_loopback_tx,
14091                 (void *)&cmd_tx_loopback_loopback,
14092                 (void *)&cmd_tx_loopback_port_id,
14093                 (void *)&cmd_tx_loopback_on_off,
14094                 NULL,
14095         },
14096 };
14097
14098 /* all queues drop enable configuration */
14099
14100 /* Common result structure for all queues drop enable */
14101 struct cmd_all_queues_drop_en_result {
14102         cmdline_fixed_string_t set;
14103         cmdline_fixed_string_t all;
14104         cmdline_fixed_string_t queues;
14105         cmdline_fixed_string_t drop;
14106         portid_t port_id;
14107         cmdline_fixed_string_t on_off;
14108 };
14109
14110 /* Common CLI fields for tx loopback enable disable */
14111 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14112         TOKEN_STRING_INITIALIZER
14113                 (struct cmd_all_queues_drop_en_result,
14114                  set, "set");
14115 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14116         TOKEN_STRING_INITIALIZER
14117                 (struct cmd_all_queues_drop_en_result,
14118                  all, "all");
14119 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14120         TOKEN_STRING_INITIALIZER
14121                 (struct cmd_all_queues_drop_en_result,
14122                  queues, "queues");
14123 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14124         TOKEN_STRING_INITIALIZER
14125                 (struct cmd_all_queues_drop_en_result,
14126                  drop, "drop");
14127 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14128         TOKEN_NUM_INITIALIZER
14129                 (struct cmd_all_queues_drop_en_result,
14130                  port_id, UINT16);
14131 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14132         TOKEN_STRING_INITIALIZER
14133                 (struct cmd_all_queues_drop_en_result,
14134                  on_off, "on#off");
14135
14136 static void
14137 cmd_set_all_queues_drop_en_parsed(
14138         void *parsed_result,
14139         __rte_unused struct cmdline *cl,
14140         __rte_unused void *data)
14141 {
14142         struct cmd_all_queues_drop_en_result *res = parsed_result;
14143         int ret = -ENOTSUP;
14144         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14145
14146         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14147                 return;
14148
14149 #ifdef RTE_LIBRTE_IXGBE_PMD
14150         if (ret == -ENOTSUP)
14151                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14152 #endif
14153 #ifdef RTE_LIBRTE_BNXT_PMD
14154         if (ret == -ENOTSUP)
14155                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14156 #endif
14157         switch (ret) {
14158         case 0:
14159                 break;
14160         case -EINVAL:
14161                 printf("invalid is_on %d\n", is_on);
14162                 break;
14163         case -ENODEV:
14164                 printf("invalid port_id %d\n", res->port_id);
14165                 break;
14166         case -ENOTSUP:
14167                 printf("function not implemented\n");
14168                 break;
14169         default:
14170                 printf("programming error: (%s)\n", strerror(-ret));
14171         }
14172 }
14173
14174 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14175         .f = cmd_set_all_queues_drop_en_parsed,
14176         .data = NULL,
14177         .help_str = "set all queues drop <port_id> on|off",
14178         .tokens = {
14179                 (void *)&cmd_all_queues_drop_en_set,
14180                 (void *)&cmd_all_queues_drop_en_all,
14181                 (void *)&cmd_all_queues_drop_en_queues,
14182                 (void *)&cmd_all_queues_drop_en_drop,
14183                 (void *)&cmd_all_queues_drop_en_port_id,
14184                 (void *)&cmd_all_queues_drop_en_on_off,
14185                 NULL,
14186         },
14187 };
14188
14189 /* vf split drop enable configuration */
14190
14191 /* Common result structure for vf split drop enable */
14192 struct cmd_vf_split_drop_en_result {
14193         cmdline_fixed_string_t set;
14194         cmdline_fixed_string_t vf;
14195         cmdline_fixed_string_t split;
14196         cmdline_fixed_string_t drop;
14197         portid_t port_id;
14198         uint16_t vf_id;
14199         cmdline_fixed_string_t on_off;
14200 };
14201
14202 /* Common CLI fields for vf split drop enable disable */
14203 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14204         TOKEN_STRING_INITIALIZER
14205                 (struct cmd_vf_split_drop_en_result,
14206                  set, "set");
14207 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14208         TOKEN_STRING_INITIALIZER
14209                 (struct cmd_vf_split_drop_en_result,
14210                  vf, "vf");
14211 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14212         TOKEN_STRING_INITIALIZER
14213                 (struct cmd_vf_split_drop_en_result,
14214                  split, "split");
14215 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14216         TOKEN_STRING_INITIALIZER
14217                 (struct cmd_vf_split_drop_en_result,
14218                  drop, "drop");
14219 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14220         TOKEN_NUM_INITIALIZER
14221                 (struct cmd_vf_split_drop_en_result,
14222                  port_id, UINT16);
14223 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14224         TOKEN_NUM_INITIALIZER
14225                 (struct cmd_vf_split_drop_en_result,
14226                  vf_id, UINT16);
14227 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14228         TOKEN_STRING_INITIALIZER
14229                 (struct cmd_vf_split_drop_en_result,
14230                  on_off, "on#off");
14231
14232 static void
14233 cmd_set_vf_split_drop_en_parsed(
14234         void *parsed_result,
14235         __rte_unused struct cmdline *cl,
14236         __rte_unused void *data)
14237 {
14238         struct cmd_vf_split_drop_en_result *res = parsed_result;
14239         int ret = -ENOTSUP;
14240         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14241
14242         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14243                 return;
14244
14245 #ifdef RTE_LIBRTE_IXGBE_PMD
14246         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14247                         is_on);
14248 #endif
14249         switch (ret) {
14250         case 0:
14251                 break;
14252         case -EINVAL:
14253                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14254                 break;
14255         case -ENODEV:
14256                 printf("invalid port_id %d\n", res->port_id);
14257                 break;
14258         case -ENOTSUP:
14259                 printf("not supported on port %d\n", res->port_id);
14260                 break;
14261         default:
14262                 printf("programming error: (%s)\n", strerror(-ret));
14263         }
14264 }
14265
14266 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14267         .f = cmd_set_vf_split_drop_en_parsed,
14268         .data = NULL,
14269         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14270         .tokens = {
14271                 (void *)&cmd_vf_split_drop_en_set,
14272                 (void *)&cmd_vf_split_drop_en_vf,
14273                 (void *)&cmd_vf_split_drop_en_split,
14274                 (void *)&cmd_vf_split_drop_en_drop,
14275                 (void *)&cmd_vf_split_drop_en_port_id,
14276                 (void *)&cmd_vf_split_drop_en_vf_id,
14277                 (void *)&cmd_vf_split_drop_en_on_off,
14278                 NULL,
14279         },
14280 };
14281
14282 /* vf mac address configuration */
14283
14284 /* Common result structure for vf mac address */
14285 struct cmd_set_vf_mac_addr_result {
14286         cmdline_fixed_string_t set;
14287         cmdline_fixed_string_t vf;
14288         cmdline_fixed_string_t mac;
14289         cmdline_fixed_string_t addr;
14290         portid_t port_id;
14291         uint16_t vf_id;
14292         struct rte_ether_addr mac_addr;
14293
14294 };
14295
14296 /* Common CLI fields for vf split drop enable disable */
14297 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14298         TOKEN_STRING_INITIALIZER
14299                 (struct cmd_set_vf_mac_addr_result,
14300                  set, "set");
14301 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14302         TOKEN_STRING_INITIALIZER
14303                 (struct cmd_set_vf_mac_addr_result,
14304                  vf, "vf");
14305 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14306         TOKEN_STRING_INITIALIZER
14307                 (struct cmd_set_vf_mac_addr_result,
14308                  mac, "mac");
14309 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14310         TOKEN_STRING_INITIALIZER
14311                 (struct cmd_set_vf_mac_addr_result,
14312                  addr, "addr");
14313 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14314         TOKEN_NUM_INITIALIZER
14315                 (struct cmd_set_vf_mac_addr_result,
14316                  port_id, UINT16);
14317 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14318         TOKEN_NUM_INITIALIZER
14319                 (struct cmd_set_vf_mac_addr_result,
14320                  vf_id, UINT16);
14321 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14322         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14323                  mac_addr);
14324
14325 static void
14326 cmd_set_vf_mac_addr_parsed(
14327         void *parsed_result,
14328         __rte_unused struct cmdline *cl,
14329         __rte_unused void *data)
14330 {
14331         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14332         int ret = -ENOTSUP;
14333
14334         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14335                 return;
14336
14337 #ifdef RTE_LIBRTE_IXGBE_PMD
14338         if (ret == -ENOTSUP)
14339                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14340                                 &res->mac_addr);
14341 #endif
14342 #ifdef RTE_LIBRTE_I40E_PMD
14343         if (ret == -ENOTSUP)
14344                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14345                                 &res->mac_addr);
14346 #endif
14347 #ifdef RTE_LIBRTE_BNXT_PMD
14348         if (ret == -ENOTSUP)
14349                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14350                                 &res->mac_addr);
14351 #endif
14352
14353         switch (ret) {
14354         case 0:
14355                 break;
14356         case -EINVAL:
14357                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14358                 break;
14359         case -ENODEV:
14360                 printf("invalid port_id %d\n", res->port_id);
14361                 break;
14362         case -ENOTSUP:
14363                 printf("function not implemented\n");
14364                 break;
14365         default:
14366                 printf("programming error: (%s)\n", strerror(-ret));
14367         }
14368 }
14369
14370 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14371         .f = cmd_set_vf_mac_addr_parsed,
14372         .data = NULL,
14373         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14374         .tokens = {
14375                 (void *)&cmd_set_vf_mac_addr_set,
14376                 (void *)&cmd_set_vf_mac_addr_vf,
14377                 (void *)&cmd_set_vf_mac_addr_mac,
14378                 (void *)&cmd_set_vf_mac_addr_addr,
14379                 (void *)&cmd_set_vf_mac_addr_port_id,
14380                 (void *)&cmd_set_vf_mac_addr_vf_id,
14381                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14382                 NULL,
14383         },
14384 };
14385
14386 /* MACsec configuration */
14387
14388 /* Common result structure for MACsec offload enable */
14389 struct cmd_macsec_offload_on_result {
14390         cmdline_fixed_string_t set;
14391         cmdline_fixed_string_t macsec;
14392         cmdline_fixed_string_t offload;
14393         portid_t port_id;
14394         cmdline_fixed_string_t on;
14395         cmdline_fixed_string_t encrypt;
14396         cmdline_fixed_string_t en_on_off;
14397         cmdline_fixed_string_t replay_protect;
14398         cmdline_fixed_string_t rp_on_off;
14399 };
14400
14401 /* Common CLI fields for MACsec offload disable */
14402 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14403         TOKEN_STRING_INITIALIZER
14404                 (struct cmd_macsec_offload_on_result,
14405                  set, "set");
14406 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14407         TOKEN_STRING_INITIALIZER
14408                 (struct cmd_macsec_offload_on_result,
14409                  macsec, "macsec");
14410 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14411         TOKEN_STRING_INITIALIZER
14412                 (struct cmd_macsec_offload_on_result,
14413                  offload, "offload");
14414 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14415         TOKEN_NUM_INITIALIZER
14416                 (struct cmd_macsec_offload_on_result,
14417                  port_id, UINT16);
14418 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14419         TOKEN_STRING_INITIALIZER
14420                 (struct cmd_macsec_offload_on_result,
14421                  on, "on");
14422 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14423         TOKEN_STRING_INITIALIZER
14424                 (struct cmd_macsec_offload_on_result,
14425                  encrypt, "encrypt");
14426 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14427         TOKEN_STRING_INITIALIZER
14428                 (struct cmd_macsec_offload_on_result,
14429                  en_on_off, "on#off");
14430 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14431         TOKEN_STRING_INITIALIZER
14432                 (struct cmd_macsec_offload_on_result,
14433                  replay_protect, "replay-protect");
14434 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14435         TOKEN_STRING_INITIALIZER
14436                 (struct cmd_macsec_offload_on_result,
14437                  rp_on_off, "on#off");
14438
14439 static void
14440 cmd_set_macsec_offload_on_parsed(
14441         void *parsed_result,
14442         __rte_unused struct cmdline *cl,
14443         __rte_unused void *data)
14444 {
14445         struct cmd_macsec_offload_on_result *res = parsed_result;
14446         int ret = -ENOTSUP;
14447         portid_t port_id = res->port_id;
14448         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14449         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14450         struct rte_eth_dev_info dev_info;
14451
14452         if (port_id_is_invalid(port_id, ENABLED_WARN))
14453                 return;
14454         if (!port_is_stopped(port_id)) {
14455                 printf("Please stop port %d first\n", port_id);
14456                 return;
14457         }
14458
14459         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14460         if (ret != 0)
14461                 return;
14462
14463         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14464 #ifdef RTE_LIBRTE_IXGBE_PMD
14465                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14466 #endif
14467         }
14468         RTE_SET_USED(en);
14469         RTE_SET_USED(rp);
14470
14471         switch (ret) {
14472         case 0:
14473                 ports[port_id].dev_conf.txmode.offloads |=
14474                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14475                 cmd_reconfig_device_queue(port_id, 1, 1);
14476                 break;
14477         case -ENODEV:
14478                 printf("invalid port_id %d\n", port_id);
14479                 break;
14480         case -ENOTSUP:
14481                 printf("not supported on port %d\n", port_id);
14482                 break;
14483         default:
14484                 printf("programming error: (%s)\n", strerror(-ret));
14485         }
14486 }
14487
14488 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14489         .f = cmd_set_macsec_offload_on_parsed,
14490         .data = NULL,
14491         .help_str = "set macsec offload <port_id> on "
14492                 "encrypt on|off replay-protect on|off",
14493         .tokens = {
14494                 (void *)&cmd_macsec_offload_on_set,
14495                 (void *)&cmd_macsec_offload_on_macsec,
14496                 (void *)&cmd_macsec_offload_on_offload,
14497                 (void *)&cmd_macsec_offload_on_port_id,
14498                 (void *)&cmd_macsec_offload_on_on,
14499                 (void *)&cmd_macsec_offload_on_encrypt,
14500                 (void *)&cmd_macsec_offload_on_en_on_off,
14501                 (void *)&cmd_macsec_offload_on_replay_protect,
14502                 (void *)&cmd_macsec_offload_on_rp_on_off,
14503                 NULL,
14504         },
14505 };
14506
14507 /* Common result structure for MACsec offload disable */
14508 struct cmd_macsec_offload_off_result {
14509         cmdline_fixed_string_t set;
14510         cmdline_fixed_string_t macsec;
14511         cmdline_fixed_string_t offload;
14512         portid_t port_id;
14513         cmdline_fixed_string_t off;
14514 };
14515
14516 /* Common CLI fields for MACsec offload disable */
14517 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14518         TOKEN_STRING_INITIALIZER
14519                 (struct cmd_macsec_offload_off_result,
14520                  set, "set");
14521 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14522         TOKEN_STRING_INITIALIZER
14523                 (struct cmd_macsec_offload_off_result,
14524                  macsec, "macsec");
14525 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14526         TOKEN_STRING_INITIALIZER
14527                 (struct cmd_macsec_offload_off_result,
14528                  offload, "offload");
14529 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14530         TOKEN_NUM_INITIALIZER
14531                 (struct cmd_macsec_offload_off_result,
14532                  port_id, UINT16);
14533 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14534         TOKEN_STRING_INITIALIZER
14535                 (struct cmd_macsec_offload_off_result,
14536                  off, "off");
14537
14538 static void
14539 cmd_set_macsec_offload_off_parsed(
14540         void *parsed_result,
14541         __rte_unused struct cmdline *cl,
14542         __rte_unused void *data)
14543 {
14544         struct cmd_macsec_offload_off_result *res = parsed_result;
14545         int ret = -ENOTSUP;
14546         struct rte_eth_dev_info dev_info;
14547         portid_t port_id = res->port_id;
14548
14549         if (port_id_is_invalid(port_id, ENABLED_WARN))
14550                 return;
14551         if (!port_is_stopped(port_id)) {
14552                 printf("Please stop port %d first\n", port_id);
14553                 return;
14554         }
14555
14556         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14557         if (ret != 0)
14558                 return;
14559
14560         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14561 #ifdef RTE_LIBRTE_IXGBE_PMD
14562                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14563 #endif
14564         }
14565         switch (ret) {
14566         case 0:
14567                 ports[port_id].dev_conf.txmode.offloads &=
14568                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14569                 cmd_reconfig_device_queue(port_id, 1, 1);
14570                 break;
14571         case -ENODEV:
14572                 printf("invalid port_id %d\n", port_id);
14573                 break;
14574         case -ENOTSUP:
14575                 printf("not supported on port %d\n", port_id);
14576                 break;
14577         default:
14578                 printf("programming error: (%s)\n", strerror(-ret));
14579         }
14580 }
14581
14582 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14583         .f = cmd_set_macsec_offload_off_parsed,
14584         .data = NULL,
14585         .help_str = "set macsec offload <port_id> off",
14586         .tokens = {
14587                 (void *)&cmd_macsec_offload_off_set,
14588                 (void *)&cmd_macsec_offload_off_macsec,
14589                 (void *)&cmd_macsec_offload_off_offload,
14590                 (void *)&cmd_macsec_offload_off_port_id,
14591                 (void *)&cmd_macsec_offload_off_off,
14592                 NULL,
14593         },
14594 };
14595
14596 /* Common result structure for MACsec secure connection configure */
14597 struct cmd_macsec_sc_result {
14598         cmdline_fixed_string_t set;
14599         cmdline_fixed_string_t macsec;
14600         cmdline_fixed_string_t sc;
14601         cmdline_fixed_string_t tx_rx;
14602         portid_t port_id;
14603         struct rte_ether_addr mac;
14604         uint16_t pi;
14605 };
14606
14607 /* Common CLI fields for MACsec secure connection configure */
14608 cmdline_parse_token_string_t cmd_macsec_sc_set =
14609         TOKEN_STRING_INITIALIZER
14610                 (struct cmd_macsec_sc_result,
14611                  set, "set");
14612 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14613         TOKEN_STRING_INITIALIZER
14614                 (struct cmd_macsec_sc_result,
14615                  macsec, "macsec");
14616 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14617         TOKEN_STRING_INITIALIZER
14618                 (struct cmd_macsec_sc_result,
14619                  sc, "sc");
14620 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14621         TOKEN_STRING_INITIALIZER
14622                 (struct cmd_macsec_sc_result,
14623                  tx_rx, "tx#rx");
14624 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14625         TOKEN_NUM_INITIALIZER
14626                 (struct cmd_macsec_sc_result,
14627                  port_id, UINT16);
14628 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14629         TOKEN_ETHERADDR_INITIALIZER
14630                 (struct cmd_macsec_sc_result,
14631                  mac);
14632 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14633         TOKEN_NUM_INITIALIZER
14634                 (struct cmd_macsec_sc_result,
14635                  pi, UINT16);
14636
14637 static void
14638 cmd_set_macsec_sc_parsed(
14639         void *parsed_result,
14640         __rte_unused struct cmdline *cl,
14641         __rte_unused void *data)
14642 {
14643         struct cmd_macsec_sc_result *res = parsed_result;
14644         int ret = -ENOTSUP;
14645         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14646
14647 #ifdef RTE_LIBRTE_IXGBE_PMD
14648         ret = is_tx ?
14649                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14650                                 res->mac.addr_bytes) :
14651                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14652                                 res->mac.addr_bytes, res->pi);
14653 #endif
14654         RTE_SET_USED(is_tx);
14655
14656         switch (ret) {
14657         case 0:
14658                 break;
14659         case -ENODEV:
14660                 printf("invalid port_id %d\n", res->port_id);
14661                 break;
14662         case -ENOTSUP:
14663                 printf("not supported on port %d\n", res->port_id);
14664                 break;
14665         default:
14666                 printf("programming error: (%s)\n", strerror(-ret));
14667         }
14668 }
14669
14670 cmdline_parse_inst_t cmd_set_macsec_sc = {
14671         .f = cmd_set_macsec_sc_parsed,
14672         .data = NULL,
14673         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14674         .tokens = {
14675                 (void *)&cmd_macsec_sc_set,
14676                 (void *)&cmd_macsec_sc_macsec,
14677                 (void *)&cmd_macsec_sc_sc,
14678                 (void *)&cmd_macsec_sc_tx_rx,
14679                 (void *)&cmd_macsec_sc_port_id,
14680                 (void *)&cmd_macsec_sc_mac,
14681                 (void *)&cmd_macsec_sc_pi,
14682                 NULL,
14683         },
14684 };
14685
14686 /* Common result structure for MACsec secure connection configure */
14687 struct cmd_macsec_sa_result {
14688         cmdline_fixed_string_t set;
14689         cmdline_fixed_string_t macsec;
14690         cmdline_fixed_string_t sa;
14691         cmdline_fixed_string_t tx_rx;
14692         portid_t port_id;
14693         uint8_t idx;
14694         uint8_t an;
14695         uint32_t pn;
14696         cmdline_fixed_string_t key;
14697 };
14698
14699 /* Common CLI fields for MACsec secure connection configure */
14700 cmdline_parse_token_string_t cmd_macsec_sa_set =
14701         TOKEN_STRING_INITIALIZER
14702                 (struct cmd_macsec_sa_result,
14703                  set, "set");
14704 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14705         TOKEN_STRING_INITIALIZER
14706                 (struct cmd_macsec_sa_result,
14707                  macsec, "macsec");
14708 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14709         TOKEN_STRING_INITIALIZER
14710                 (struct cmd_macsec_sa_result,
14711                  sa, "sa");
14712 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14713         TOKEN_STRING_INITIALIZER
14714                 (struct cmd_macsec_sa_result,
14715                  tx_rx, "tx#rx");
14716 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14717         TOKEN_NUM_INITIALIZER
14718                 (struct cmd_macsec_sa_result,
14719                  port_id, UINT16);
14720 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14721         TOKEN_NUM_INITIALIZER
14722                 (struct cmd_macsec_sa_result,
14723                  idx, UINT8);
14724 cmdline_parse_token_num_t cmd_macsec_sa_an =
14725         TOKEN_NUM_INITIALIZER
14726                 (struct cmd_macsec_sa_result,
14727                  an, UINT8);
14728 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14729         TOKEN_NUM_INITIALIZER
14730                 (struct cmd_macsec_sa_result,
14731                  pn, UINT32);
14732 cmdline_parse_token_string_t cmd_macsec_sa_key =
14733         TOKEN_STRING_INITIALIZER
14734                 (struct cmd_macsec_sa_result,
14735                  key, NULL);
14736
14737 static void
14738 cmd_set_macsec_sa_parsed(
14739         void *parsed_result,
14740         __rte_unused struct cmdline *cl,
14741         __rte_unused void *data)
14742 {
14743         struct cmd_macsec_sa_result *res = parsed_result;
14744         int ret = -ENOTSUP;
14745         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14746         uint8_t key[16] = { 0 };
14747         uint8_t xdgt0;
14748         uint8_t xdgt1;
14749         int key_len;
14750         int i;
14751
14752         key_len = strlen(res->key) / 2;
14753         if (key_len > 16)
14754                 key_len = 16;
14755
14756         for (i = 0; i < key_len; i++) {
14757                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14758                 if (xdgt0 == 0xFF)
14759                         return;
14760                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14761                 if (xdgt1 == 0xFF)
14762                         return;
14763                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14764         }
14765
14766 #ifdef RTE_LIBRTE_IXGBE_PMD
14767         ret = is_tx ?
14768                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14769                         res->idx, res->an, res->pn, key) :
14770                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14771                         res->idx, res->an, res->pn, key);
14772 #endif
14773         RTE_SET_USED(is_tx);
14774         RTE_SET_USED(key);
14775
14776         switch (ret) {
14777         case 0:
14778                 break;
14779         case -EINVAL:
14780                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14781                 break;
14782         case -ENODEV:
14783                 printf("invalid port_id %d\n", res->port_id);
14784                 break;
14785         case -ENOTSUP:
14786                 printf("not supported on port %d\n", res->port_id);
14787                 break;
14788         default:
14789                 printf("programming error: (%s)\n", strerror(-ret));
14790         }
14791 }
14792
14793 cmdline_parse_inst_t cmd_set_macsec_sa = {
14794         .f = cmd_set_macsec_sa_parsed,
14795         .data = NULL,
14796         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14797         .tokens = {
14798                 (void *)&cmd_macsec_sa_set,
14799                 (void *)&cmd_macsec_sa_macsec,
14800                 (void *)&cmd_macsec_sa_sa,
14801                 (void *)&cmd_macsec_sa_tx_rx,
14802                 (void *)&cmd_macsec_sa_port_id,
14803                 (void *)&cmd_macsec_sa_idx,
14804                 (void *)&cmd_macsec_sa_an,
14805                 (void *)&cmd_macsec_sa_pn,
14806                 (void *)&cmd_macsec_sa_key,
14807                 NULL,
14808         },
14809 };
14810
14811 /* VF unicast promiscuous mode configuration */
14812
14813 /* Common result structure for VF unicast promiscuous mode */
14814 struct cmd_vf_promisc_result {
14815         cmdline_fixed_string_t set;
14816         cmdline_fixed_string_t vf;
14817         cmdline_fixed_string_t promisc;
14818         portid_t port_id;
14819         uint32_t vf_id;
14820         cmdline_fixed_string_t on_off;
14821 };
14822
14823 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14824 cmdline_parse_token_string_t cmd_vf_promisc_set =
14825         TOKEN_STRING_INITIALIZER
14826                 (struct cmd_vf_promisc_result,
14827                  set, "set");
14828 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14829         TOKEN_STRING_INITIALIZER
14830                 (struct cmd_vf_promisc_result,
14831                  vf, "vf");
14832 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14833         TOKEN_STRING_INITIALIZER
14834                 (struct cmd_vf_promisc_result,
14835                  promisc, "promisc");
14836 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14837         TOKEN_NUM_INITIALIZER
14838                 (struct cmd_vf_promisc_result,
14839                  port_id, UINT16);
14840 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14841         TOKEN_NUM_INITIALIZER
14842                 (struct cmd_vf_promisc_result,
14843                  vf_id, UINT32);
14844 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14845         TOKEN_STRING_INITIALIZER
14846                 (struct cmd_vf_promisc_result,
14847                  on_off, "on#off");
14848
14849 static void
14850 cmd_set_vf_promisc_parsed(
14851         void *parsed_result,
14852         __rte_unused struct cmdline *cl,
14853         __rte_unused void *data)
14854 {
14855         struct cmd_vf_promisc_result *res = parsed_result;
14856         int ret = -ENOTSUP;
14857
14858         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14859
14860         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14861                 return;
14862
14863 #ifdef RTE_LIBRTE_I40E_PMD
14864         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14865                                                   res->vf_id, is_on);
14866 #endif
14867
14868         switch (ret) {
14869         case 0:
14870                 break;
14871         case -EINVAL:
14872                 printf("invalid vf_id %d\n", res->vf_id);
14873                 break;
14874         case -ENODEV:
14875                 printf("invalid port_id %d\n", res->port_id);
14876                 break;
14877         case -ENOTSUP:
14878                 printf("function not implemented\n");
14879                 break;
14880         default:
14881                 printf("programming error: (%s)\n", strerror(-ret));
14882         }
14883 }
14884
14885 cmdline_parse_inst_t cmd_set_vf_promisc = {
14886         .f = cmd_set_vf_promisc_parsed,
14887         .data = NULL,
14888         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14889                 "Set unicast promiscuous mode for a VF from the PF",
14890         .tokens = {
14891                 (void *)&cmd_vf_promisc_set,
14892                 (void *)&cmd_vf_promisc_vf,
14893                 (void *)&cmd_vf_promisc_promisc,
14894                 (void *)&cmd_vf_promisc_port_id,
14895                 (void *)&cmd_vf_promisc_vf_id,
14896                 (void *)&cmd_vf_promisc_on_off,
14897                 NULL,
14898         },
14899 };
14900
14901 /* VF multicast promiscuous mode configuration */
14902
14903 /* Common result structure for VF multicast promiscuous mode */
14904 struct cmd_vf_allmulti_result {
14905         cmdline_fixed_string_t set;
14906         cmdline_fixed_string_t vf;
14907         cmdline_fixed_string_t allmulti;
14908         portid_t port_id;
14909         uint32_t vf_id;
14910         cmdline_fixed_string_t on_off;
14911 };
14912
14913 /* Common CLI fields for VF multicast promiscuous mode enable disable */
14914 cmdline_parse_token_string_t cmd_vf_allmulti_set =
14915         TOKEN_STRING_INITIALIZER
14916                 (struct cmd_vf_allmulti_result,
14917                  set, "set");
14918 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
14919         TOKEN_STRING_INITIALIZER
14920                 (struct cmd_vf_allmulti_result,
14921                  vf, "vf");
14922 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
14923         TOKEN_STRING_INITIALIZER
14924                 (struct cmd_vf_allmulti_result,
14925                  allmulti, "allmulti");
14926 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
14927         TOKEN_NUM_INITIALIZER
14928                 (struct cmd_vf_allmulti_result,
14929                  port_id, UINT16);
14930 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
14931         TOKEN_NUM_INITIALIZER
14932                 (struct cmd_vf_allmulti_result,
14933                  vf_id, UINT32);
14934 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
14935         TOKEN_STRING_INITIALIZER
14936                 (struct cmd_vf_allmulti_result,
14937                  on_off, "on#off");
14938
14939 static void
14940 cmd_set_vf_allmulti_parsed(
14941         void *parsed_result,
14942         __rte_unused struct cmdline *cl,
14943         __rte_unused void *data)
14944 {
14945         struct cmd_vf_allmulti_result *res = parsed_result;
14946         int ret = -ENOTSUP;
14947
14948         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14949
14950         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14951                 return;
14952
14953 #ifdef RTE_LIBRTE_I40E_PMD
14954         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
14955                                                     res->vf_id, is_on);
14956 #endif
14957
14958         switch (ret) {
14959         case 0:
14960                 break;
14961         case -EINVAL:
14962                 printf("invalid vf_id %d\n", res->vf_id);
14963                 break;
14964         case -ENODEV:
14965                 printf("invalid port_id %d\n", res->port_id);
14966                 break;
14967         case -ENOTSUP:
14968                 printf("function not implemented\n");
14969                 break;
14970         default:
14971                 printf("programming error: (%s)\n", strerror(-ret));
14972         }
14973 }
14974
14975 cmdline_parse_inst_t cmd_set_vf_allmulti = {
14976         .f = cmd_set_vf_allmulti_parsed,
14977         .data = NULL,
14978         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
14979                 "Set multicast promiscuous mode for a VF from the PF",
14980         .tokens = {
14981                 (void *)&cmd_vf_allmulti_set,
14982                 (void *)&cmd_vf_allmulti_vf,
14983                 (void *)&cmd_vf_allmulti_allmulti,
14984                 (void *)&cmd_vf_allmulti_port_id,
14985                 (void *)&cmd_vf_allmulti_vf_id,
14986                 (void *)&cmd_vf_allmulti_on_off,
14987                 NULL,
14988         },
14989 };
14990
14991 /* vf broadcast mode configuration */
14992
14993 /* Common result structure for vf broadcast */
14994 struct cmd_set_vf_broadcast_result {
14995         cmdline_fixed_string_t set;
14996         cmdline_fixed_string_t vf;
14997         cmdline_fixed_string_t broadcast;
14998         portid_t port_id;
14999         uint16_t vf_id;
15000         cmdline_fixed_string_t on_off;
15001 };
15002
15003 /* Common CLI fields for vf broadcast enable disable */
15004 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15005         TOKEN_STRING_INITIALIZER
15006                 (struct cmd_set_vf_broadcast_result,
15007                  set, "set");
15008 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15009         TOKEN_STRING_INITIALIZER
15010                 (struct cmd_set_vf_broadcast_result,
15011                  vf, "vf");
15012 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15013         TOKEN_STRING_INITIALIZER
15014                 (struct cmd_set_vf_broadcast_result,
15015                  broadcast, "broadcast");
15016 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15017         TOKEN_NUM_INITIALIZER
15018                 (struct cmd_set_vf_broadcast_result,
15019                  port_id, UINT16);
15020 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15021         TOKEN_NUM_INITIALIZER
15022                 (struct cmd_set_vf_broadcast_result,
15023                  vf_id, UINT16);
15024 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15025         TOKEN_STRING_INITIALIZER
15026                 (struct cmd_set_vf_broadcast_result,
15027                  on_off, "on#off");
15028
15029 static void
15030 cmd_set_vf_broadcast_parsed(
15031         void *parsed_result,
15032         __rte_unused struct cmdline *cl,
15033         __rte_unused void *data)
15034 {
15035         struct cmd_set_vf_broadcast_result *res = parsed_result;
15036         int ret = -ENOTSUP;
15037
15038         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15039
15040         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15041                 return;
15042
15043 #ifdef RTE_LIBRTE_I40E_PMD
15044         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15045                                             res->vf_id, is_on);
15046 #endif
15047
15048         switch (ret) {
15049         case 0:
15050                 break;
15051         case -EINVAL:
15052                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15053                 break;
15054         case -ENODEV:
15055                 printf("invalid port_id %d\n", res->port_id);
15056                 break;
15057         case -ENOTSUP:
15058                 printf("function not implemented\n");
15059                 break;
15060         default:
15061                 printf("programming error: (%s)\n", strerror(-ret));
15062         }
15063 }
15064
15065 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15066         .f = cmd_set_vf_broadcast_parsed,
15067         .data = NULL,
15068         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15069         .tokens = {
15070                 (void *)&cmd_set_vf_broadcast_set,
15071                 (void *)&cmd_set_vf_broadcast_vf,
15072                 (void *)&cmd_set_vf_broadcast_broadcast,
15073                 (void *)&cmd_set_vf_broadcast_port_id,
15074                 (void *)&cmd_set_vf_broadcast_vf_id,
15075                 (void *)&cmd_set_vf_broadcast_on_off,
15076                 NULL,
15077         },
15078 };
15079
15080 /* vf vlan tag configuration */
15081
15082 /* Common result structure for vf vlan tag */
15083 struct cmd_set_vf_vlan_tag_result {
15084         cmdline_fixed_string_t set;
15085         cmdline_fixed_string_t vf;
15086         cmdline_fixed_string_t vlan;
15087         cmdline_fixed_string_t tag;
15088         portid_t port_id;
15089         uint16_t vf_id;
15090         cmdline_fixed_string_t on_off;
15091 };
15092
15093 /* Common CLI fields for vf vlan tag enable disable */
15094 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15095         TOKEN_STRING_INITIALIZER
15096                 (struct cmd_set_vf_vlan_tag_result,
15097                  set, "set");
15098 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15099         TOKEN_STRING_INITIALIZER
15100                 (struct cmd_set_vf_vlan_tag_result,
15101                  vf, "vf");
15102 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15103         TOKEN_STRING_INITIALIZER
15104                 (struct cmd_set_vf_vlan_tag_result,
15105                  vlan, "vlan");
15106 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15107         TOKEN_STRING_INITIALIZER
15108                 (struct cmd_set_vf_vlan_tag_result,
15109                  tag, "tag");
15110 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15111         TOKEN_NUM_INITIALIZER
15112                 (struct cmd_set_vf_vlan_tag_result,
15113                  port_id, UINT16);
15114 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15115         TOKEN_NUM_INITIALIZER
15116                 (struct cmd_set_vf_vlan_tag_result,
15117                  vf_id, UINT16);
15118 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15119         TOKEN_STRING_INITIALIZER
15120                 (struct cmd_set_vf_vlan_tag_result,
15121                  on_off, "on#off");
15122
15123 static void
15124 cmd_set_vf_vlan_tag_parsed(
15125         void *parsed_result,
15126         __rte_unused struct cmdline *cl,
15127         __rte_unused void *data)
15128 {
15129         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15130         int ret = -ENOTSUP;
15131
15132         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15133
15134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15135                 return;
15136
15137 #ifdef RTE_LIBRTE_I40E_PMD
15138         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15139                                            res->vf_id, is_on);
15140 #endif
15141
15142         switch (ret) {
15143         case 0:
15144                 break;
15145         case -EINVAL:
15146                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15147                 break;
15148         case -ENODEV:
15149                 printf("invalid port_id %d\n", res->port_id);
15150                 break;
15151         case -ENOTSUP:
15152                 printf("function not implemented\n");
15153                 break;
15154         default:
15155                 printf("programming error: (%s)\n", strerror(-ret));
15156         }
15157 }
15158
15159 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15160         .f = cmd_set_vf_vlan_tag_parsed,
15161         .data = NULL,
15162         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15163         .tokens = {
15164                 (void *)&cmd_set_vf_vlan_tag_set,
15165                 (void *)&cmd_set_vf_vlan_tag_vf,
15166                 (void *)&cmd_set_vf_vlan_tag_vlan,
15167                 (void *)&cmd_set_vf_vlan_tag_tag,
15168                 (void *)&cmd_set_vf_vlan_tag_port_id,
15169                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15170                 (void *)&cmd_set_vf_vlan_tag_on_off,
15171                 NULL,
15172         },
15173 };
15174
15175 /* Common definition of VF and TC TX bandwidth configuration */
15176 struct cmd_vf_tc_bw_result {
15177         cmdline_fixed_string_t set;
15178         cmdline_fixed_string_t vf;
15179         cmdline_fixed_string_t tc;
15180         cmdline_fixed_string_t tx;
15181         cmdline_fixed_string_t min_bw;
15182         cmdline_fixed_string_t max_bw;
15183         cmdline_fixed_string_t strict_link_prio;
15184         portid_t port_id;
15185         uint16_t vf_id;
15186         uint8_t tc_no;
15187         uint32_t bw;
15188         cmdline_fixed_string_t bw_list;
15189         uint8_t tc_map;
15190 };
15191
15192 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15193         TOKEN_STRING_INITIALIZER
15194                 (struct cmd_vf_tc_bw_result,
15195                  set, "set");
15196 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15197         TOKEN_STRING_INITIALIZER
15198                 (struct cmd_vf_tc_bw_result,
15199                  vf, "vf");
15200 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15201         TOKEN_STRING_INITIALIZER
15202                 (struct cmd_vf_tc_bw_result,
15203                  tc, "tc");
15204 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15205         TOKEN_STRING_INITIALIZER
15206                 (struct cmd_vf_tc_bw_result,
15207                  tx, "tx");
15208 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15209         TOKEN_STRING_INITIALIZER
15210                 (struct cmd_vf_tc_bw_result,
15211                  strict_link_prio, "strict-link-priority");
15212 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15213         TOKEN_STRING_INITIALIZER
15214                 (struct cmd_vf_tc_bw_result,
15215                  min_bw, "min-bandwidth");
15216 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15217         TOKEN_STRING_INITIALIZER
15218                 (struct cmd_vf_tc_bw_result,
15219                  max_bw, "max-bandwidth");
15220 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15221         TOKEN_NUM_INITIALIZER
15222                 (struct cmd_vf_tc_bw_result,
15223                  port_id, UINT16);
15224 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15225         TOKEN_NUM_INITIALIZER
15226                 (struct cmd_vf_tc_bw_result,
15227                  vf_id, UINT16);
15228 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15229         TOKEN_NUM_INITIALIZER
15230                 (struct cmd_vf_tc_bw_result,
15231                  tc_no, UINT8);
15232 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15233         TOKEN_NUM_INITIALIZER
15234                 (struct cmd_vf_tc_bw_result,
15235                  bw, UINT32);
15236 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15237         TOKEN_STRING_INITIALIZER
15238                 (struct cmd_vf_tc_bw_result,
15239                  bw_list, NULL);
15240 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15241         TOKEN_NUM_INITIALIZER
15242                 (struct cmd_vf_tc_bw_result,
15243                  tc_map, UINT8);
15244
15245 /* VF max bandwidth setting */
15246 static void
15247 cmd_vf_max_bw_parsed(
15248         void *parsed_result,
15249         __rte_unused struct cmdline *cl,
15250         __rte_unused void *data)
15251 {
15252         struct cmd_vf_tc_bw_result *res = parsed_result;
15253         int ret = -ENOTSUP;
15254
15255         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15256                 return;
15257
15258 #ifdef RTE_LIBRTE_I40E_PMD
15259         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15260                                          res->vf_id, res->bw);
15261 #endif
15262
15263         switch (ret) {
15264         case 0:
15265                 break;
15266         case -EINVAL:
15267                 printf("invalid vf_id %d or bandwidth %d\n",
15268                        res->vf_id, res->bw);
15269                 break;
15270         case -ENODEV:
15271                 printf("invalid port_id %d\n", res->port_id);
15272                 break;
15273         case -ENOTSUP:
15274                 printf("function not implemented\n");
15275                 break;
15276         default:
15277                 printf("programming error: (%s)\n", strerror(-ret));
15278         }
15279 }
15280
15281 cmdline_parse_inst_t cmd_vf_max_bw = {
15282         .f = cmd_vf_max_bw_parsed,
15283         .data = NULL,
15284         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15285         .tokens = {
15286                 (void *)&cmd_vf_tc_bw_set,
15287                 (void *)&cmd_vf_tc_bw_vf,
15288                 (void *)&cmd_vf_tc_bw_tx,
15289                 (void *)&cmd_vf_tc_bw_max_bw,
15290                 (void *)&cmd_vf_tc_bw_port_id,
15291                 (void *)&cmd_vf_tc_bw_vf_id,
15292                 (void *)&cmd_vf_tc_bw_bw,
15293                 NULL,
15294         },
15295 };
15296
15297 static int
15298 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15299                            uint8_t *tc_num,
15300                            char *str)
15301 {
15302         uint32_t size;
15303         const char *p, *p0 = str;
15304         char s[256];
15305         char *end;
15306         char *str_fld[16];
15307         uint16_t i;
15308         int ret;
15309
15310         p = strchr(p0, '(');
15311         if (p == NULL) {
15312                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15313                 return -1;
15314         }
15315         p++;
15316         p0 = strchr(p, ')');
15317         if (p0 == NULL) {
15318                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15319                 return -1;
15320         }
15321         size = p0 - p;
15322         if (size >= sizeof(s)) {
15323                 printf("The string size exceeds the internal buffer size\n");
15324                 return -1;
15325         }
15326         snprintf(s, sizeof(s), "%.*s", size, p);
15327         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15328         if (ret <= 0) {
15329                 printf("Failed to get the bandwidth list. ");
15330                 return -1;
15331         }
15332         *tc_num = ret;
15333         for (i = 0; i < ret; i++)
15334                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15335
15336         return 0;
15337 }
15338
15339 /* TC min bandwidth setting */
15340 static void
15341 cmd_vf_tc_min_bw_parsed(
15342         void *parsed_result,
15343         __rte_unused struct cmdline *cl,
15344         __rte_unused void *data)
15345 {
15346         struct cmd_vf_tc_bw_result *res = parsed_result;
15347         uint8_t tc_num;
15348         uint8_t bw[16];
15349         int ret = -ENOTSUP;
15350
15351         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15352                 return;
15353
15354         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15355         if (ret)
15356                 return;
15357
15358 #ifdef RTE_LIBRTE_I40E_PMD
15359         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15360                                               tc_num, bw);
15361 #endif
15362
15363         switch (ret) {
15364         case 0:
15365                 break;
15366         case -EINVAL:
15367                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15368                 break;
15369         case -ENODEV:
15370                 printf("invalid port_id %d\n", res->port_id);
15371                 break;
15372         case -ENOTSUP:
15373                 printf("function not implemented\n");
15374                 break;
15375         default:
15376                 printf("programming error: (%s)\n", strerror(-ret));
15377         }
15378 }
15379
15380 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15381         .f = cmd_vf_tc_min_bw_parsed,
15382         .data = NULL,
15383         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15384                     " <bw1, bw2, ...>",
15385         .tokens = {
15386                 (void *)&cmd_vf_tc_bw_set,
15387                 (void *)&cmd_vf_tc_bw_vf,
15388                 (void *)&cmd_vf_tc_bw_tc,
15389                 (void *)&cmd_vf_tc_bw_tx,
15390                 (void *)&cmd_vf_tc_bw_min_bw,
15391                 (void *)&cmd_vf_tc_bw_port_id,
15392                 (void *)&cmd_vf_tc_bw_vf_id,
15393                 (void *)&cmd_vf_tc_bw_bw_list,
15394                 NULL,
15395         },
15396 };
15397
15398 static void
15399 cmd_tc_min_bw_parsed(
15400         void *parsed_result,
15401         __rte_unused struct cmdline *cl,
15402         __rte_unused void *data)
15403 {
15404         struct cmd_vf_tc_bw_result *res = parsed_result;
15405         struct rte_port *port;
15406         uint8_t tc_num;
15407         uint8_t bw[16];
15408         int ret = -ENOTSUP;
15409
15410         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15411                 return;
15412
15413         port = &ports[res->port_id];
15414         /** Check if the port is not started **/
15415         if (port->port_status != RTE_PORT_STOPPED) {
15416                 printf("Please stop port %d first\n", res->port_id);
15417                 return;
15418         }
15419
15420         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15421         if (ret)
15422                 return;
15423
15424 #ifdef RTE_LIBRTE_IXGBE_PMD
15425         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15426 #endif
15427
15428         switch (ret) {
15429         case 0:
15430                 break;
15431         case -EINVAL:
15432                 printf("invalid bandwidth\n");
15433                 break;
15434         case -ENODEV:
15435                 printf("invalid port_id %d\n", res->port_id);
15436                 break;
15437         case -ENOTSUP:
15438                 printf("function not implemented\n");
15439                 break;
15440         default:
15441                 printf("programming error: (%s)\n", strerror(-ret));
15442         }
15443 }
15444
15445 cmdline_parse_inst_t cmd_tc_min_bw = {
15446         .f = cmd_tc_min_bw_parsed,
15447         .data = NULL,
15448         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15449         .tokens = {
15450                 (void *)&cmd_vf_tc_bw_set,
15451                 (void *)&cmd_vf_tc_bw_tc,
15452                 (void *)&cmd_vf_tc_bw_tx,
15453                 (void *)&cmd_vf_tc_bw_min_bw,
15454                 (void *)&cmd_vf_tc_bw_port_id,
15455                 (void *)&cmd_vf_tc_bw_bw_list,
15456                 NULL,
15457         },
15458 };
15459
15460 /* TC max bandwidth setting */
15461 static void
15462 cmd_vf_tc_max_bw_parsed(
15463         void *parsed_result,
15464         __rte_unused struct cmdline *cl,
15465         __rte_unused void *data)
15466 {
15467         struct cmd_vf_tc_bw_result *res = parsed_result;
15468         int ret = -ENOTSUP;
15469
15470         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15471                 return;
15472
15473 #ifdef RTE_LIBRTE_I40E_PMD
15474         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15475                                             res->tc_no, res->bw);
15476 #endif
15477
15478         switch (ret) {
15479         case 0:
15480                 break;
15481         case -EINVAL:
15482                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15483                        res->vf_id, res->tc_no, res->bw);
15484                 break;
15485         case -ENODEV:
15486                 printf("invalid port_id %d\n", res->port_id);
15487                 break;
15488         case -ENOTSUP:
15489                 printf("function not implemented\n");
15490                 break;
15491         default:
15492                 printf("programming error: (%s)\n", strerror(-ret));
15493         }
15494 }
15495
15496 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15497         .f = cmd_vf_tc_max_bw_parsed,
15498         .data = NULL,
15499         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15500                     " <bandwidth>",
15501         .tokens = {
15502                 (void *)&cmd_vf_tc_bw_set,
15503                 (void *)&cmd_vf_tc_bw_vf,
15504                 (void *)&cmd_vf_tc_bw_tc,
15505                 (void *)&cmd_vf_tc_bw_tx,
15506                 (void *)&cmd_vf_tc_bw_max_bw,
15507                 (void *)&cmd_vf_tc_bw_port_id,
15508                 (void *)&cmd_vf_tc_bw_vf_id,
15509                 (void *)&cmd_vf_tc_bw_tc_no,
15510                 (void *)&cmd_vf_tc_bw_bw,
15511                 NULL,
15512         },
15513 };
15514
15515 /** Set VXLAN encapsulation details */
15516 struct cmd_set_vxlan_result {
15517         cmdline_fixed_string_t set;
15518         cmdline_fixed_string_t vxlan;
15519         cmdline_fixed_string_t pos_token;
15520         cmdline_fixed_string_t ip_version;
15521         uint32_t vlan_present:1;
15522         uint32_t vni;
15523         uint16_t udp_src;
15524         uint16_t udp_dst;
15525         cmdline_ipaddr_t ip_src;
15526         cmdline_ipaddr_t ip_dst;
15527         uint16_t tci;
15528         uint8_t tos;
15529         uint8_t ttl;
15530         struct rte_ether_addr eth_src;
15531         struct rte_ether_addr eth_dst;
15532 };
15533
15534 cmdline_parse_token_string_t cmd_set_vxlan_set =
15535         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15536 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15537         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15538 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15539         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15540                                  "vxlan-tos-ttl");
15541 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15542         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15543                                  "vxlan-with-vlan");
15544 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15545         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15546                                  "ip-version");
15547 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15548         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15549                                  "ipv4#ipv6");
15550 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15551         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15552                                  "vni");
15553 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15554         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15555 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15556         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15557                                  "udp-src");
15558 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15559         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15560 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15561         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15562                                  "udp-dst");
15563 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15564         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15565 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15566         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15567                                  "ip-tos");
15568 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15569         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15570 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15571         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15572                                  "ip-ttl");
15573 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15574         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15575 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15576         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15577                                  "ip-src");
15578 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15579         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15580 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15581         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15582                                  "ip-dst");
15583 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15584         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15585 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15586         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15587                                  "vlan-tci");
15588 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15589         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15590 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15591         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15592                                  "eth-src");
15593 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15594         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15595 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15596         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15597                                  "eth-dst");
15598 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15599         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15600
15601 static void cmd_set_vxlan_parsed(void *parsed_result,
15602         __rte_unused struct cmdline *cl,
15603         __rte_unused void *data)
15604 {
15605         struct cmd_set_vxlan_result *res = parsed_result;
15606         union {
15607                 uint32_t vxlan_id;
15608                 uint8_t vni[4];
15609         } id = {
15610                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15611         };
15612
15613         vxlan_encap_conf.select_tos_ttl = 0;
15614         if (strcmp(res->vxlan, "vxlan") == 0)
15615                 vxlan_encap_conf.select_vlan = 0;
15616         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15617                 vxlan_encap_conf.select_vlan = 1;
15618         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15619                 vxlan_encap_conf.select_vlan = 0;
15620                 vxlan_encap_conf.select_tos_ttl = 1;
15621         }
15622         if (strcmp(res->ip_version, "ipv4") == 0)
15623                 vxlan_encap_conf.select_ipv4 = 1;
15624         else if (strcmp(res->ip_version, "ipv6") == 0)
15625                 vxlan_encap_conf.select_ipv4 = 0;
15626         else
15627                 return;
15628         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15629         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15630         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15631         vxlan_encap_conf.ip_tos = res->tos;
15632         vxlan_encap_conf.ip_ttl = res->ttl;
15633         if (vxlan_encap_conf.select_ipv4) {
15634                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15635                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15636         } else {
15637                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15638                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15639         }
15640         if (vxlan_encap_conf.select_vlan)
15641                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15642         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15643                    RTE_ETHER_ADDR_LEN);
15644         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15645                    RTE_ETHER_ADDR_LEN);
15646 }
15647
15648 cmdline_parse_inst_t cmd_set_vxlan = {
15649         .f = cmd_set_vxlan_parsed,
15650         .data = NULL,
15651         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15652                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15653                 " eth-src <eth-src> eth-dst <eth-dst>",
15654         .tokens = {
15655                 (void *)&cmd_set_vxlan_set,
15656                 (void *)&cmd_set_vxlan_vxlan,
15657                 (void *)&cmd_set_vxlan_ip_version,
15658                 (void *)&cmd_set_vxlan_ip_version_value,
15659                 (void *)&cmd_set_vxlan_vni,
15660                 (void *)&cmd_set_vxlan_vni_value,
15661                 (void *)&cmd_set_vxlan_udp_src,
15662                 (void *)&cmd_set_vxlan_udp_src_value,
15663                 (void *)&cmd_set_vxlan_udp_dst,
15664                 (void *)&cmd_set_vxlan_udp_dst_value,
15665                 (void *)&cmd_set_vxlan_ip_src,
15666                 (void *)&cmd_set_vxlan_ip_src_value,
15667                 (void *)&cmd_set_vxlan_ip_dst,
15668                 (void *)&cmd_set_vxlan_ip_dst_value,
15669                 (void *)&cmd_set_vxlan_eth_src,
15670                 (void *)&cmd_set_vxlan_eth_src_value,
15671                 (void *)&cmd_set_vxlan_eth_dst,
15672                 (void *)&cmd_set_vxlan_eth_dst_value,
15673                 NULL,
15674         },
15675 };
15676
15677 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15678         .f = cmd_set_vxlan_parsed,
15679         .data = NULL,
15680         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15681                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15682                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15683                 " eth-dst <eth-dst>",
15684         .tokens = {
15685                 (void *)&cmd_set_vxlan_set,
15686                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15687                 (void *)&cmd_set_vxlan_ip_version,
15688                 (void *)&cmd_set_vxlan_ip_version_value,
15689                 (void *)&cmd_set_vxlan_vni,
15690                 (void *)&cmd_set_vxlan_vni_value,
15691                 (void *)&cmd_set_vxlan_udp_src,
15692                 (void *)&cmd_set_vxlan_udp_src_value,
15693                 (void *)&cmd_set_vxlan_udp_dst,
15694                 (void *)&cmd_set_vxlan_udp_dst_value,
15695                 (void *)&cmd_set_vxlan_ip_tos,
15696                 (void *)&cmd_set_vxlan_ip_tos_value,
15697                 (void *)&cmd_set_vxlan_ip_ttl,
15698                 (void *)&cmd_set_vxlan_ip_ttl_value,
15699                 (void *)&cmd_set_vxlan_ip_src,
15700                 (void *)&cmd_set_vxlan_ip_src_value,
15701                 (void *)&cmd_set_vxlan_ip_dst,
15702                 (void *)&cmd_set_vxlan_ip_dst_value,
15703                 (void *)&cmd_set_vxlan_eth_src,
15704                 (void *)&cmd_set_vxlan_eth_src_value,
15705                 (void *)&cmd_set_vxlan_eth_dst,
15706                 (void *)&cmd_set_vxlan_eth_dst_value,
15707                 NULL,
15708         },
15709 };
15710
15711 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15712         .f = cmd_set_vxlan_parsed,
15713         .data = NULL,
15714         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15715                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15716                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15717                 " <eth-dst>",
15718         .tokens = {
15719                 (void *)&cmd_set_vxlan_set,
15720                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15721                 (void *)&cmd_set_vxlan_ip_version,
15722                 (void *)&cmd_set_vxlan_ip_version_value,
15723                 (void *)&cmd_set_vxlan_vni,
15724                 (void *)&cmd_set_vxlan_vni_value,
15725                 (void *)&cmd_set_vxlan_udp_src,
15726                 (void *)&cmd_set_vxlan_udp_src_value,
15727                 (void *)&cmd_set_vxlan_udp_dst,
15728                 (void *)&cmd_set_vxlan_udp_dst_value,
15729                 (void *)&cmd_set_vxlan_ip_src,
15730                 (void *)&cmd_set_vxlan_ip_src_value,
15731                 (void *)&cmd_set_vxlan_ip_dst,
15732                 (void *)&cmd_set_vxlan_ip_dst_value,
15733                 (void *)&cmd_set_vxlan_vlan,
15734                 (void *)&cmd_set_vxlan_vlan_value,
15735                 (void *)&cmd_set_vxlan_eth_src,
15736                 (void *)&cmd_set_vxlan_eth_src_value,
15737                 (void *)&cmd_set_vxlan_eth_dst,
15738                 (void *)&cmd_set_vxlan_eth_dst_value,
15739                 NULL,
15740         },
15741 };
15742
15743 /** Set NVGRE encapsulation details */
15744 struct cmd_set_nvgre_result {
15745         cmdline_fixed_string_t set;
15746         cmdline_fixed_string_t nvgre;
15747         cmdline_fixed_string_t pos_token;
15748         cmdline_fixed_string_t ip_version;
15749         uint32_t tni;
15750         cmdline_ipaddr_t ip_src;
15751         cmdline_ipaddr_t ip_dst;
15752         uint16_t tci;
15753         struct rte_ether_addr eth_src;
15754         struct rte_ether_addr eth_dst;
15755 };
15756
15757 cmdline_parse_token_string_t cmd_set_nvgre_set =
15758         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15759 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15760         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15761 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15762         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15763                                  "nvgre-with-vlan");
15764 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15765         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15766                                  "ip-version");
15767 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15768         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15769                                  "ipv4#ipv6");
15770 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15771         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15772                                  "tni");
15773 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15774         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15775 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15776         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15777                                  "ip-src");
15778 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15779         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15780 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15781         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15782                                  "ip-dst");
15783 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15784         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15785 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15786         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15787                                  "vlan-tci");
15788 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15789         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15790 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15791         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15792                                  "eth-src");
15793 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15794         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15795 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15796         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15797                                  "eth-dst");
15798 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15799         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15800
15801 static void cmd_set_nvgre_parsed(void *parsed_result,
15802         __rte_unused struct cmdline *cl,
15803         __rte_unused void *data)
15804 {
15805         struct cmd_set_nvgre_result *res = parsed_result;
15806         union {
15807                 uint32_t nvgre_tni;
15808                 uint8_t tni[4];
15809         } id = {
15810                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15811         };
15812
15813         if (strcmp(res->nvgre, "nvgre") == 0)
15814                 nvgre_encap_conf.select_vlan = 0;
15815         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15816                 nvgre_encap_conf.select_vlan = 1;
15817         if (strcmp(res->ip_version, "ipv4") == 0)
15818                 nvgre_encap_conf.select_ipv4 = 1;
15819         else if (strcmp(res->ip_version, "ipv6") == 0)
15820                 nvgre_encap_conf.select_ipv4 = 0;
15821         else
15822                 return;
15823         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15824         if (nvgre_encap_conf.select_ipv4) {
15825                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15826                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15827         } else {
15828                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15829                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15830         }
15831         if (nvgre_encap_conf.select_vlan)
15832                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15833         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15834                    RTE_ETHER_ADDR_LEN);
15835         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15836                    RTE_ETHER_ADDR_LEN);
15837 }
15838
15839 cmdline_parse_inst_t cmd_set_nvgre = {
15840         .f = cmd_set_nvgre_parsed,
15841         .data = NULL,
15842         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15843                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15844                 " eth-dst <eth-dst>",
15845         .tokens = {
15846                 (void *)&cmd_set_nvgre_set,
15847                 (void *)&cmd_set_nvgre_nvgre,
15848                 (void *)&cmd_set_nvgre_ip_version,
15849                 (void *)&cmd_set_nvgre_ip_version_value,
15850                 (void *)&cmd_set_nvgre_tni,
15851                 (void *)&cmd_set_nvgre_tni_value,
15852                 (void *)&cmd_set_nvgre_ip_src,
15853                 (void *)&cmd_set_nvgre_ip_src_value,
15854                 (void *)&cmd_set_nvgre_ip_dst,
15855                 (void *)&cmd_set_nvgre_ip_dst_value,
15856                 (void *)&cmd_set_nvgre_eth_src,
15857                 (void *)&cmd_set_nvgre_eth_src_value,
15858                 (void *)&cmd_set_nvgre_eth_dst,
15859                 (void *)&cmd_set_nvgre_eth_dst_value,
15860                 NULL,
15861         },
15862 };
15863
15864 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15865         .f = cmd_set_nvgre_parsed,
15866         .data = NULL,
15867         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15868                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15869                 " eth-src <eth-src> eth-dst <eth-dst>",
15870         .tokens = {
15871                 (void *)&cmd_set_nvgre_set,
15872                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15873                 (void *)&cmd_set_nvgre_ip_version,
15874                 (void *)&cmd_set_nvgre_ip_version_value,
15875                 (void *)&cmd_set_nvgre_tni,
15876                 (void *)&cmd_set_nvgre_tni_value,
15877                 (void *)&cmd_set_nvgre_ip_src,
15878                 (void *)&cmd_set_nvgre_ip_src_value,
15879                 (void *)&cmd_set_nvgre_ip_dst,
15880                 (void *)&cmd_set_nvgre_ip_dst_value,
15881                 (void *)&cmd_set_nvgre_vlan,
15882                 (void *)&cmd_set_nvgre_vlan_value,
15883                 (void *)&cmd_set_nvgre_eth_src,
15884                 (void *)&cmd_set_nvgre_eth_src_value,
15885                 (void *)&cmd_set_nvgre_eth_dst,
15886                 (void *)&cmd_set_nvgre_eth_dst_value,
15887                 NULL,
15888         },
15889 };
15890
15891 /** Set L2 encapsulation details */
15892 struct cmd_set_l2_encap_result {
15893         cmdline_fixed_string_t set;
15894         cmdline_fixed_string_t l2_encap;
15895         cmdline_fixed_string_t pos_token;
15896         cmdline_fixed_string_t ip_version;
15897         uint32_t vlan_present:1;
15898         uint16_t tci;
15899         struct rte_ether_addr eth_src;
15900         struct rte_ether_addr eth_dst;
15901 };
15902
15903 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15904         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
15905 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
15906         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
15907 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
15908         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
15909                                  "l2_encap-with-vlan");
15910 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
15911         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15912                                  "ip-version");
15913 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
15914         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
15915                                  "ipv4#ipv6");
15916 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
15917         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15918                                  "vlan-tci");
15919 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
15920         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
15921 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
15922         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15923                                  "eth-src");
15924 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
15925         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
15926 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
15927         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
15928                                  "eth-dst");
15929 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
15930         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
15931
15932 static void cmd_set_l2_encap_parsed(void *parsed_result,
15933         __rte_unused struct cmdline *cl,
15934         __rte_unused void *data)
15935 {
15936         struct cmd_set_l2_encap_result *res = parsed_result;
15937
15938         if (strcmp(res->l2_encap, "l2_encap") == 0)
15939                 l2_encap_conf.select_vlan = 0;
15940         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
15941                 l2_encap_conf.select_vlan = 1;
15942         if (strcmp(res->ip_version, "ipv4") == 0)
15943                 l2_encap_conf.select_ipv4 = 1;
15944         else if (strcmp(res->ip_version, "ipv6") == 0)
15945                 l2_encap_conf.select_ipv4 = 0;
15946         else
15947                 return;
15948         if (l2_encap_conf.select_vlan)
15949                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15950         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
15951                    RTE_ETHER_ADDR_LEN);
15952         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15953                    RTE_ETHER_ADDR_LEN);
15954 }
15955
15956 cmdline_parse_inst_t cmd_set_l2_encap = {
15957         .f = cmd_set_l2_encap_parsed,
15958         .data = NULL,
15959         .help_str = "set l2_encap ip-version ipv4|ipv6"
15960                 " eth-src <eth-src> eth-dst <eth-dst>",
15961         .tokens = {
15962                 (void *)&cmd_set_l2_encap_set,
15963                 (void *)&cmd_set_l2_encap_l2_encap,
15964                 (void *)&cmd_set_l2_encap_ip_version,
15965                 (void *)&cmd_set_l2_encap_ip_version_value,
15966                 (void *)&cmd_set_l2_encap_eth_src,
15967                 (void *)&cmd_set_l2_encap_eth_src_value,
15968                 (void *)&cmd_set_l2_encap_eth_dst,
15969                 (void *)&cmd_set_l2_encap_eth_dst_value,
15970                 NULL,
15971         },
15972 };
15973
15974 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
15975         .f = cmd_set_l2_encap_parsed,
15976         .data = NULL,
15977         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
15978                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
15979         .tokens = {
15980                 (void *)&cmd_set_l2_encap_set,
15981                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
15982                 (void *)&cmd_set_l2_encap_ip_version,
15983                 (void *)&cmd_set_l2_encap_ip_version_value,
15984                 (void *)&cmd_set_l2_encap_vlan,
15985                 (void *)&cmd_set_l2_encap_vlan_value,
15986                 (void *)&cmd_set_l2_encap_eth_src,
15987                 (void *)&cmd_set_l2_encap_eth_src_value,
15988                 (void *)&cmd_set_l2_encap_eth_dst,
15989                 (void *)&cmd_set_l2_encap_eth_dst_value,
15990                 NULL,
15991         },
15992 };
15993
15994 /** Set L2 decapsulation details */
15995 struct cmd_set_l2_decap_result {
15996         cmdline_fixed_string_t set;
15997         cmdline_fixed_string_t l2_decap;
15998         cmdline_fixed_string_t pos_token;
15999         uint32_t vlan_present:1;
16000 };
16001
16002 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16003         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16004 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16005         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16006                                  "l2_decap");
16007 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16008         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16009                                  "l2_decap-with-vlan");
16010
16011 static void cmd_set_l2_decap_parsed(void *parsed_result,
16012         __rte_unused struct cmdline *cl,
16013         __rte_unused void *data)
16014 {
16015         struct cmd_set_l2_decap_result *res = parsed_result;
16016
16017         if (strcmp(res->l2_decap, "l2_decap") == 0)
16018                 l2_decap_conf.select_vlan = 0;
16019         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16020                 l2_decap_conf.select_vlan = 1;
16021 }
16022
16023 cmdline_parse_inst_t cmd_set_l2_decap = {
16024         .f = cmd_set_l2_decap_parsed,
16025         .data = NULL,
16026         .help_str = "set l2_decap",
16027         .tokens = {
16028                 (void *)&cmd_set_l2_decap_set,
16029                 (void *)&cmd_set_l2_decap_l2_decap,
16030                 NULL,
16031         },
16032 };
16033
16034 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16035         .f = cmd_set_l2_decap_parsed,
16036         .data = NULL,
16037         .help_str = "set l2_decap-with-vlan",
16038         .tokens = {
16039                 (void *)&cmd_set_l2_decap_set,
16040                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16041                 NULL,
16042         },
16043 };
16044
16045 /** Set MPLSoGRE encapsulation details */
16046 struct cmd_set_mplsogre_encap_result {
16047         cmdline_fixed_string_t set;
16048         cmdline_fixed_string_t mplsogre;
16049         cmdline_fixed_string_t pos_token;
16050         cmdline_fixed_string_t ip_version;
16051         uint32_t vlan_present:1;
16052         uint32_t label;
16053         cmdline_ipaddr_t ip_src;
16054         cmdline_ipaddr_t ip_dst;
16055         uint16_t tci;
16056         struct rte_ether_addr eth_src;
16057         struct rte_ether_addr eth_dst;
16058 };
16059
16060 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16061         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16062                                  "set");
16063 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16064         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16065                                  "mplsogre_encap");
16066 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16067         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16068                                  mplsogre, "mplsogre_encap-with-vlan");
16069 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16070         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16071                                  pos_token, "ip-version");
16072 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16073         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16074                                  ip_version, "ipv4#ipv6");
16075 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16076         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16077                                  pos_token, "label");
16078 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16079         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16080                               UINT32);
16081 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16082         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16083                                  pos_token, "ip-src");
16084 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16085         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16086 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16087         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16088                                  pos_token, "ip-dst");
16089 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16090         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16091 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16092         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16093                                  pos_token, "vlan-tci");
16094 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16095         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16096                               UINT16);
16097 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16098         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16099                                  pos_token, "eth-src");
16100 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16101         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16102                                     eth_src);
16103 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16104         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16105                                  pos_token, "eth-dst");
16106 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16107         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16108                                     eth_dst);
16109
16110 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16111         __rte_unused struct cmdline *cl,
16112         __rte_unused void *data)
16113 {
16114         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16115         union {
16116                 uint32_t mplsogre_label;
16117                 uint8_t label[4];
16118         } id = {
16119                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16120         };
16121
16122         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16123                 mplsogre_encap_conf.select_vlan = 0;
16124         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16125                 mplsogre_encap_conf.select_vlan = 1;
16126         if (strcmp(res->ip_version, "ipv4") == 0)
16127                 mplsogre_encap_conf.select_ipv4 = 1;
16128         else if (strcmp(res->ip_version, "ipv6") == 0)
16129                 mplsogre_encap_conf.select_ipv4 = 0;
16130         else
16131                 return;
16132         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16133         if (mplsogre_encap_conf.select_ipv4) {
16134                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16135                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16136         } else {
16137                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16138                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16139         }
16140         if (mplsogre_encap_conf.select_vlan)
16141                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16142         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16143                    RTE_ETHER_ADDR_LEN);
16144         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16145                    RTE_ETHER_ADDR_LEN);
16146 }
16147
16148 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16149         .f = cmd_set_mplsogre_encap_parsed,
16150         .data = NULL,
16151         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16152                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16153                 " eth-dst <eth-dst>",
16154         .tokens = {
16155                 (void *)&cmd_set_mplsogre_encap_set,
16156                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16157                 (void *)&cmd_set_mplsogre_encap_ip_version,
16158                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16159                 (void *)&cmd_set_mplsogre_encap_label,
16160                 (void *)&cmd_set_mplsogre_encap_label_value,
16161                 (void *)&cmd_set_mplsogre_encap_ip_src,
16162                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16163                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16164                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16165                 (void *)&cmd_set_mplsogre_encap_eth_src,
16166                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16167                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16168                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16169                 NULL,
16170         },
16171 };
16172
16173 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16174         .f = cmd_set_mplsogre_encap_parsed,
16175         .data = NULL,
16176         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16177                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16178                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16179         .tokens = {
16180                 (void *)&cmd_set_mplsogre_encap_set,
16181                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16182                 (void *)&cmd_set_mplsogre_encap_ip_version,
16183                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16184                 (void *)&cmd_set_mplsogre_encap_label,
16185                 (void *)&cmd_set_mplsogre_encap_label_value,
16186                 (void *)&cmd_set_mplsogre_encap_ip_src,
16187                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16188                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16189                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16190                 (void *)&cmd_set_mplsogre_encap_vlan,
16191                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16192                 (void *)&cmd_set_mplsogre_encap_eth_src,
16193                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16194                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16195                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16196                 NULL,
16197         },
16198 };
16199
16200 /** Set MPLSoGRE decapsulation details */
16201 struct cmd_set_mplsogre_decap_result {
16202         cmdline_fixed_string_t set;
16203         cmdline_fixed_string_t mplsogre;
16204         cmdline_fixed_string_t pos_token;
16205         cmdline_fixed_string_t ip_version;
16206         uint32_t vlan_present:1;
16207 };
16208
16209 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16211                                  "set");
16212 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16213         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16214                                  "mplsogre_decap");
16215 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16217                                  mplsogre, "mplsogre_decap-with-vlan");
16218 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16219         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16220                                  pos_token, "ip-version");
16221 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16222         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16223                                  ip_version, "ipv4#ipv6");
16224
16225 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16226         __rte_unused struct cmdline *cl,
16227         __rte_unused void *data)
16228 {
16229         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16230
16231         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16232                 mplsogre_decap_conf.select_vlan = 0;
16233         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16234                 mplsogre_decap_conf.select_vlan = 1;
16235         if (strcmp(res->ip_version, "ipv4") == 0)
16236                 mplsogre_decap_conf.select_ipv4 = 1;
16237         else if (strcmp(res->ip_version, "ipv6") == 0)
16238                 mplsogre_decap_conf.select_ipv4 = 0;
16239 }
16240
16241 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16242         .f = cmd_set_mplsogre_decap_parsed,
16243         .data = NULL,
16244         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16245         .tokens = {
16246                 (void *)&cmd_set_mplsogre_decap_set,
16247                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16248                 (void *)&cmd_set_mplsogre_decap_ip_version,
16249                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16250                 NULL,
16251         },
16252 };
16253
16254 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16255         .f = cmd_set_mplsogre_decap_parsed,
16256         .data = NULL,
16257         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16258         .tokens = {
16259                 (void *)&cmd_set_mplsogre_decap_set,
16260                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16261                 (void *)&cmd_set_mplsogre_decap_ip_version,
16262                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16263                 NULL,
16264         },
16265 };
16266
16267 /** Set MPLSoUDP encapsulation details */
16268 struct cmd_set_mplsoudp_encap_result {
16269         cmdline_fixed_string_t set;
16270         cmdline_fixed_string_t mplsoudp;
16271         cmdline_fixed_string_t pos_token;
16272         cmdline_fixed_string_t ip_version;
16273         uint32_t vlan_present:1;
16274         uint32_t label;
16275         uint16_t udp_src;
16276         uint16_t udp_dst;
16277         cmdline_ipaddr_t ip_src;
16278         cmdline_ipaddr_t ip_dst;
16279         uint16_t tci;
16280         struct rte_ether_addr eth_src;
16281         struct rte_ether_addr eth_dst;
16282 };
16283
16284 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16285         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16286                                  "set");
16287 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16288         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16289                                  "mplsoudp_encap");
16290 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16291         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16292                                  mplsoudp, "mplsoudp_encap-with-vlan");
16293 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16294         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16295                                  pos_token, "ip-version");
16296 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16297         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16298                                  ip_version, "ipv4#ipv6");
16299 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16300         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16301                                  pos_token, "label");
16302 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16303         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16304                               UINT32);
16305 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16306         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16307                                  pos_token, "udp-src");
16308 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16309         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16310                               UINT16);
16311 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16312         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16313                                  pos_token, "udp-dst");
16314 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16315         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16316                               UINT16);
16317 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16318         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16319                                  pos_token, "ip-src");
16320 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16321         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16322 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16323         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16324                                  pos_token, "ip-dst");
16325 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16326         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16327 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16328         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16329                                  pos_token, "vlan-tci");
16330 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16331         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16332                               UINT16);
16333 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16334         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16335                                  pos_token, "eth-src");
16336 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16337         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16338                                     eth_src);
16339 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16340         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16341                                  pos_token, "eth-dst");
16342 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16343         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16344                                     eth_dst);
16345
16346 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16347         __rte_unused struct cmdline *cl,
16348         __rte_unused void *data)
16349 {
16350         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16351         union {
16352                 uint32_t mplsoudp_label;
16353                 uint8_t label[4];
16354         } id = {
16355                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16356         };
16357
16358         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16359                 mplsoudp_encap_conf.select_vlan = 0;
16360         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16361                 mplsoudp_encap_conf.select_vlan = 1;
16362         if (strcmp(res->ip_version, "ipv4") == 0)
16363                 mplsoudp_encap_conf.select_ipv4 = 1;
16364         else if (strcmp(res->ip_version, "ipv6") == 0)
16365                 mplsoudp_encap_conf.select_ipv4 = 0;
16366         else
16367                 return;
16368         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16369         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16370         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16371         if (mplsoudp_encap_conf.select_ipv4) {
16372                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16373                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16374         } else {
16375                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16376                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16377         }
16378         if (mplsoudp_encap_conf.select_vlan)
16379                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16380         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16381                    RTE_ETHER_ADDR_LEN);
16382         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16383                    RTE_ETHER_ADDR_LEN);
16384 }
16385
16386 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16387         .f = cmd_set_mplsoudp_encap_parsed,
16388         .data = NULL,
16389         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16390                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16391                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16392         .tokens = {
16393                 (void *)&cmd_set_mplsoudp_encap_set,
16394                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16395                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16396                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16397                 (void *)&cmd_set_mplsoudp_encap_label,
16398                 (void *)&cmd_set_mplsoudp_encap_label_value,
16399                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16400                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16401                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16402                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16403                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16404                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16405                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16406                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16407                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16408                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16409                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16410                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16411                 NULL,
16412         },
16413 };
16414
16415 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16416         .f = cmd_set_mplsoudp_encap_parsed,
16417         .data = NULL,
16418         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16419                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16420                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16421                 " eth-src <eth-src> eth-dst <eth-dst>",
16422         .tokens = {
16423                 (void *)&cmd_set_mplsoudp_encap_set,
16424                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16425                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16426                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16427                 (void *)&cmd_set_mplsoudp_encap_label,
16428                 (void *)&cmd_set_mplsoudp_encap_label_value,
16429                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16430                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16431                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16432                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16433                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16434                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16435                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16436                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16437                 (void *)&cmd_set_mplsoudp_encap_vlan,
16438                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16439                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16440                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16441                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16442                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16443                 NULL,
16444         },
16445 };
16446
16447 /** Set MPLSoUDP decapsulation details */
16448 struct cmd_set_mplsoudp_decap_result {
16449         cmdline_fixed_string_t set;
16450         cmdline_fixed_string_t mplsoudp;
16451         cmdline_fixed_string_t pos_token;
16452         cmdline_fixed_string_t ip_version;
16453         uint32_t vlan_present:1;
16454 };
16455
16456 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16457         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16458                                  "set");
16459 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16460         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16461                                  "mplsoudp_decap");
16462 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16463         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16464                                  mplsoudp, "mplsoudp_decap-with-vlan");
16465 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16466         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16467                                  pos_token, "ip-version");
16468 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16469         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16470                                  ip_version, "ipv4#ipv6");
16471
16472 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16473         __rte_unused struct cmdline *cl,
16474         __rte_unused void *data)
16475 {
16476         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16477
16478         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16479                 mplsoudp_decap_conf.select_vlan = 0;
16480         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16481                 mplsoudp_decap_conf.select_vlan = 1;
16482         if (strcmp(res->ip_version, "ipv4") == 0)
16483                 mplsoudp_decap_conf.select_ipv4 = 1;
16484         else if (strcmp(res->ip_version, "ipv6") == 0)
16485                 mplsoudp_decap_conf.select_ipv4 = 0;
16486 }
16487
16488 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16489         .f = cmd_set_mplsoudp_decap_parsed,
16490         .data = NULL,
16491         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16492         .tokens = {
16493                 (void *)&cmd_set_mplsoudp_decap_set,
16494                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16495                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16496                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16497                 NULL,
16498         },
16499 };
16500
16501 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16502         .f = cmd_set_mplsoudp_decap_parsed,
16503         .data = NULL,
16504         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16505         .tokens = {
16506                 (void *)&cmd_set_mplsoudp_decap_set,
16507                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16508                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16509                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16510                 NULL,
16511         },
16512 };
16513
16514 /* Strict link priority scheduling mode setting */
16515 static void
16516 cmd_strict_link_prio_parsed(
16517         void *parsed_result,
16518         __rte_unused struct cmdline *cl,
16519         __rte_unused void *data)
16520 {
16521         struct cmd_vf_tc_bw_result *res = parsed_result;
16522         int ret = -ENOTSUP;
16523
16524         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16525                 return;
16526
16527 #ifdef RTE_LIBRTE_I40E_PMD
16528         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16529 #endif
16530
16531         switch (ret) {
16532         case 0:
16533                 break;
16534         case -EINVAL:
16535                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16536                 break;
16537         case -ENODEV:
16538                 printf("invalid port_id %d\n", res->port_id);
16539                 break;
16540         case -ENOTSUP:
16541                 printf("function not implemented\n");
16542                 break;
16543         default:
16544                 printf("programming error: (%s)\n", strerror(-ret));
16545         }
16546 }
16547
16548 cmdline_parse_inst_t cmd_strict_link_prio = {
16549         .f = cmd_strict_link_prio_parsed,
16550         .data = NULL,
16551         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16552         .tokens = {
16553                 (void *)&cmd_vf_tc_bw_set,
16554                 (void *)&cmd_vf_tc_bw_tx,
16555                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16556                 (void *)&cmd_vf_tc_bw_port_id,
16557                 (void *)&cmd_vf_tc_bw_tc_map,
16558                 NULL,
16559         },
16560 };
16561
16562 /* Load dynamic device personalization*/
16563 struct cmd_ddp_add_result {
16564         cmdline_fixed_string_t ddp;
16565         cmdline_fixed_string_t add;
16566         portid_t port_id;
16567         char filepath[];
16568 };
16569
16570 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16571         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16572 cmdline_parse_token_string_t cmd_ddp_add_add =
16573         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16574 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16575         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16576 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16577         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16578
16579 static void
16580 cmd_ddp_add_parsed(
16581         void *parsed_result,
16582         __rte_unused struct cmdline *cl,
16583         __rte_unused void *data)
16584 {
16585         struct cmd_ddp_add_result *res = parsed_result;
16586         uint8_t *buff;
16587         uint32_t size;
16588         char *filepath;
16589         char *file_fld[2];
16590         int file_num;
16591         int ret = -ENOTSUP;
16592
16593         if (!all_ports_stopped()) {
16594                 printf("Please stop all ports first\n");
16595                 return;
16596         }
16597
16598         filepath = strdup(res->filepath);
16599         if (filepath == NULL) {
16600                 printf("Failed to allocate memory\n");
16601                 return;
16602         }
16603         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16604
16605         buff = open_file(file_fld[0], &size);
16606         if (!buff) {
16607                 free((void *)filepath);
16608                 return;
16609         }
16610
16611 #ifdef RTE_LIBRTE_I40E_PMD
16612         if (ret == -ENOTSUP)
16613                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16614                                                buff, size,
16615                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16616 #endif
16617
16618         if (ret == -EEXIST)
16619                 printf("Profile has already existed.\n");
16620         else if (ret < 0)
16621                 printf("Failed to load profile.\n");
16622         else if (file_num == 2)
16623                 save_file(file_fld[1], buff, size);
16624
16625         close_file(buff);
16626         free((void *)filepath);
16627 }
16628
16629 cmdline_parse_inst_t cmd_ddp_add = {
16630         .f = cmd_ddp_add_parsed,
16631         .data = NULL,
16632         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16633         .tokens = {
16634                 (void *)&cmd_ddp_add_ddp,
16635                 (void *)&cmd_ddp_add_add,
16636                 (void *)&cmd_ddp_add_port_id,
16637                 (void *)&cmd_ddp_add_filepath,
16638                 NULL,
16639         },
16640 };
16641
16642 /* Delete dynamic device personalization*/
16643 struct cmd_ddp_del_result {
16644         cmdline_fixed_string_t ddp;
16645         cmdline_fixed_string_t del;
16646         portid_t port_id;
16647         char filepath[];
16648 };
16649
16650 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16651         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16652 cmdline_parse_token_string_t cmd_ddp_del_del =
16653         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16654 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16655         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16656 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16657         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16658
16659 static void
16660 cmd_ddp_del_parsed(
16661         void *parsed_result,
16662         __rte_unused struct cmdline *cl,
16663         __rte_unused void *data)
16664 {
16665         struct cmd_ddp_del_result *res = parsed_result;
16666         uint8_t *buff;
16667         uint32_t size;
16668         int ret = -ENOTSUP;
16669
16670         if (!all_ports_stopped()) {
16671                 printf("Please stop all ports first\n");
16672                 return;
16673         }
16674
16675         buff = open_file(res->filepath, &size);
16676         if (!buff)
16677                 return;
16678
16679 #ifdef RTE_LIBRTE_I40E_PMD
16680         if (ret == -ENOTSUP)
16681                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16682                                                buff, size,
16683                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16684 #endif
16685
16686         if (ret == -EACCES)
16687                 printf("Profile does not exist.\n");
16688         else if (ret < 0)
16689                 printf("Failed to delete profile.\n");
16690
16691         close_file(buff);
16692 }
16693
16694 cmdline_parse_inst_t cmd_ddp_del = {
16695         .f = cmd_ddp_del_parsed,
16696         .data = NULL,
16697         .help_str = "ddp del <port_id> <backup_profile_path>",
16698         .tokens = {
16699                 (void *)&cmd_ddp_del_ddp,
16700                 (void *)&cmd_ddp_del_del,
16701                 (void *)&cmd_ddp_del_port_id,
16702                 (void *)&cmd_ddp_del_filepath,
16703                 NULL,
16704         },
16705 };
16706
16707 /* Get dynamic device personalization profile info */
16708 struct cmd_ddp_info_result {
16709         cmdline_fixed_string_t ddp;
16710         cmdline_fixed_string_t get;
16711         cmdline_fixed_string_t info;
16712         char filepath[];
16713 };
16714
16715 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16716         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16717 cmdline_parse_token_string_t cmd_ddp_info_get =
16718         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16719 cmdline_parse_token_string_t cmd_ddp_info_info =
16720         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16721 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16722         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16723
16724 static void
16725 cmd_ddp_info_parsed(
16726         void *parsed_result,
16727         __rte_unused struct cmdline *cl,
16728         __rte_unused void *data)
16729 {
16730         struct cmd_ddp_info_result *res = parsed_result;
16731         uint8_t *pkg;
16732         uint32_t pkg_size;
16733         int ret = -ENOTSUP;
16734 #ifdef RTE_LIBRTE_I40E_PMD
16735         uint32_t i, j, n;
16736         uint8_t *buff;
16737         uint32_t buff_size = 0;
16738         struct rte_pmd_i40e_profile_info info;
16739         uint32_t dev_num = 0;
16740         struct rte_pmd_i40e_ddp_device_id *devs;
16741         uint32_t proto_num = 0;
16742         struct rte_pmd_i40e_proto_info *proto = NULL;
16743         uint32_t pctype_num = 0;
16744         struct rte_pmd_i40e_ptype_info *pctype;
16745         uint32_t ptype_num = 0;
16746         struct rte_pmd_i40e_ptype_info *ptype;
16747         uint8_t proto_id;
16748
16749 #endif
16750
16751         pkg = open_file(res->filepath, &pkg_size);
16752         if (!pkg)
16753                 return;
16754
16755 #ifdef RTE_LIBRTE_I40E_PMD
16756         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16757                                 (uint8_t *)&info, sizeof(info),
16758                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16759         if (!ret) {
16760                 printf("Global Track id:       0x%x\n", info.track_id);
16761                 printf("Global Version:        %d.%d.%d.%d\n",
16762                         info.version.major,
16763                         info.version.minor,
16764                         info.version.update,
16765                         info.version.draft);
16766                 printf("Global Package name:   %s\n\n", info.name);
16767         }
16768
16769         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16770                                 (uint8_t *)&info, sizeof(info),
16771                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16772         if (!ret) {
16773                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16774                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16775                         info.version.major,
16776                         info.version.minor,
16777                         info.version.update,
16778                         info.version.draft);
16779                 printf("i40e Profile name:     %s\n\n", info.name);
16780         }
16781
16782         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16783                                 (uint8_t *)&buff_size, sizeof(buff_size),
16784                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16785         if (!ret && buff_size) {
16786                 buff = (uint8_t *)malloc(buff_size);
16787                 if (buff) {
16788                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16789                                                 buff, buff_size,
16790                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16791                         if (!ret)
16792                                 printf("Package Notes:\n%s\n\n", buff);
16793                         free(buff);
16794                 }
16795         }
16796
16797         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16798                                 (uint8_t *)&dev_num, sizeof(dev_num),
16799                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16800         if (!ret && dev_num) {
16801                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16802                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16803                 if (devs) {
16804                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16805                                                 (uint8_t *)devs, buff_size,
16806                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16807                         if (!ret) {
16808                                 printf("List of supported devices:\n");
16809                                 for (i = 0; i < dev_num; i++) {
16810                                         printf("  %04X:%04X %04X:%04X\n",
16811                                                 devs[i].vendor_dev_id >> 16,
16812                                                 devs[i].vendor_dev_id & 0xFFFF,
16813                                                 devs[i].sub_vendor_dev_id >> 16,
16814                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16815                                 }
16816                                 printf("\n");
16817                         }
16818                         free(devs);
16819                 }
16820         }
16821
16822         /* get information about protocols and packet types */
16823         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16824                 (uint8_t *)&proto_num, sizeof(proto_num),
16825                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16826         if (ret || !proto_num)
16827                 goto no_print_return;
16828
16829         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16830         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16831         if (!proto)
16832                 goto no_print_return;
16833
16834         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16835                                         buff_size,
16836                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16837         if (!ret) {
16838                 printf("List of used protocols:\n");
16839                 for (i = 0; i < proto_num; i++)
16840                         printf("  %2u: %s\n", proto[i].proto_id,
16841                                proto[i].name);
16842                 printf("\n");
16843         }
16844         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16845                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16846                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16847         if (ret || !pctype_num)
16848                 goto no_print_pctypes;
16849
16850         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16851         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16852         if (!pctype)
16853                 goto no_print_pctypes;
16854
16855         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16856                                         buff_size,
16857                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16858         if (ret) {
16859                 free(pctype);
16860                 goto no_print_pctypes;
16861         }
16862
16863         printf("List of defined packet classification types:\n");
16864         for (i = 0; i < pctype_num; i++) {
16865                 printf("  %2u:", pctype[i].ptype_id);
16866                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16867                         proto_id = pctype[i].protocols[j];
16868                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16869                                 for (n = 0; n < proto_num; n++) {
16870                                         if (proto[n].proto_id == proto_id) {
16871                                                 printf(" %s", proto[n].name);
16872                                                 break;
16873                                         }
16874                                 }
16875                         }
16876                 }
16877                 printf("\n");
16878         }
16879         printf("\n");
16880         free(pctype);
16881
16882 no_print_pctypes:
16883
16884         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16885                                         sizeof(ptype_num),
16886                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16887         if (ret || !ptype_num)
16888                 goto no_print_return;
16889
16890         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16891         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16892         if (!ptype)
16893                 goto no_print_return;
16894
16895         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16896                                         buff_size,
16897                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16898         if (ret) {
16899                 free(ptype);
16900                 goto no_print_return;
16901         }
16902         printf("List of defined packet types:\n");
16903         for (i = 0; i < ptype_num; i++) {
16904                 printf("  %2u:", ptype[i].ptype_id);
16905                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16906                         proto_id = ptype[i].protocols[j];
16907                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16908                                 for (n = 0; n < proto_num; n++) {
16909                                         if (proto[n].proto_id == proto_id) {
16910                                                 printf(" %s", proto[n].name);
16911                                                 break;
16912                                         }
16913                                 }
16914                         }
16915                 }
16916                 printf("\n");
16917         }
16918         free(ptype);
16919         printf("\n");
16920
16921         ret = 0;
16922 no_print_return:
16923         if (proto)
16924                 free(proto);
16925 #endif
16926         if (ret == -ENOTSUP)
16927                 printf("Function not supported in PMD driver\n");
16928         close_file(pkg);
16929 }
16930
16931 cmdline_parse_inst_t cmd_ddp_get_info = {
16932         .f = cmd_ddp_info_parsed,
16933         .data = NULL,
16934         .help_str = "ddp get info <profile_path>",
16935         .tokens = {
16936                 (void *)&cmd_ddp_info_ddp,
16937                 (void *)&cmd_ddp_info_get,
16938                 (void *)&cmd_ddp_info_info,
16939                 (void *)&cmd_ddp_info_filepath,
16940                 NULL,
16941         },
16942 };
16943
16944 /* Get dynamic device personalization profile info list*/
16945 #define PROFILE_INFO_SIZE 48
16946 #define MAX_PROFILE_NUM 16
16947
16948 struct cmd_ddp_get_list_result {
16949         cmdline_fixed_string_t ddp;
16950         cmdline_fixed_string_t get;
16951         cmdline_fixed_string_t list;
16952         portid_t port_id;
16953 };
16954
16955 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
16956         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
16957 cmdline_parse_token_string_t cmd_ddp_get_list_get =
16958         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
16959 cmdline_parse_token_string_t cmd_ddp_get_list_list =
16960         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
16961 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
16962         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
16963
16964 static void
16965 cmd_ddp_get_list_parsed(
16966         __rte_unused void *parsed_result,
16967         __rte_unused struct cmdline *cl,
16968         __rte_unused void *data)
16969 {
16970 #ifdef RTE_LIBRTE_I40E_PMD
16971         struct cmd_ddp_get_list_result *res = parsed_result;
16972         struct rte_pmd_i40e_profile_list *p_list;
16973         struct rte_pmd_i40e_profile_info *p_info;
16974         uint32_t p_num;
16975         uint32_t size;
16976         uint32_t i;
16977 #endif
16978         int ret = -ENOTSUP;
16979
16980 #ifdef RTE_LIBRTE_I40E_PMD
16981         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
16982         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
16983         if (!p_list) {
16984                 printf("%s: Failed to malloc buffer\n", __func__);
16985                 return;
16986         }
16987
16988         if (ret == -ENOTSUP)
16989                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
16990                                                 (uint8_t *)p_list, size);
16991
16992         if (!ret) {
16993                 p_num = p_list->p_count;
16994                 printf("Profile number is: %d\n\n", p_num);
16995
16996                 for (i = 0; i < p_num; i++) {
16997                         p_info = &p_list->p_info[i];
16998                         printf("Profile %d:\n", i);
16999                         printf("Track id:     0x%x\n", p_info->track_id);
17000                         printf("Version:      %d.%d.%d.%d\n",
17001                                p_info->version.major,
17002                                p_info->version.minor,
17003                                p_info->version.update,
17004                                p_info->version.draft);
17005                         printf("Profile name: %s\n\n", p_info->name);
17006                 }
17007         }
17008
17009         free(p_list);
17010 #endif
17011
17012         if (ret < 0)
17013                 printf("Failed to get ddp list\n");
17014 }
17015
17016 cmdline_parse_inst_t cmd_ddp_get_list = {
17017         .f = cmd_ddp_get_list_parsed,
17018         .data = NULL,
17019         .help_str = "ddp get list <port_id>",
17020         .tokens = {
17021                 (void *)&cmd_ddp_get_list_ddp,
17022                 (void *)&cmd_ddp_get_list_get,
17023                 (void *)&cmd_ddp_get_list_list,
17024                 (void *)&cmd_ddp_get_list_port_id,
17025                 NULL,
17026         },
17027 };
17028
17029 /* Configure input set */
17030 struct cmd_cfg_input_set_result {
17031         cmdline_fixed_string_t port;
17032         cmdline_fixed_string_t cfg;
17033         portid_t port_id;
17034         cmdline_fixed_string_t pctype;
17035         uint8_t pctype_id;
17036         cmdline_fixed_string_t inset_type;
17037         cmdline_fixed_string_t opt;
17038         cmdline_fixed_string_t field;
17039         uint8_t field_idx;
17040 };
17041
17042 static void
17043 cmd_cfg_input_set_parsed(
17044         __rte_unused void *parsed_result,
17045         __rte_unused struct cmdline *cl,
17046         __rte_unused void *data)
17047 {
17048 #ifdef RTE_LIBRTE_I40E_PMD
17049         struct cmd_cfg_input_set_result *res = parsed_result;
17050         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17051         struct rte_pmd_i40e_inset inset;
17052 #endif
17053         int ret = -ENOTSUP;
17054
17055         if (!all_ports_stopped()) {
17056                 printf("Please stop all ports first\n");
17057                 return;
17058         }
17059
17060 #ifdef RTE_LIBRTE_I40E_PMD
17061         if (!strcmp(res->inset_type, "hash_inset"))
17062                 inset_type = INSET_HASH;
17063         else if (!strcmp(res->inset_type, "fdir_inset"))
17064                 inset_type = INSET_FDIR;
17065         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17066                 inset_type = INSET_FDIR_FLX;
17067         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17068                                      &inset, inset_type);
17069         if (ret) {
17070                 printf("Failed to get input set.\n");
17071                 return;
17072         }
17073
17074         if (!strcmp(res->opt, "get")) {
17075                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17076                                                    res->field_idx);
17077                 if (ret)
17078                         printf("Field index %d is enabled.\n", res->field_idx);
17079                 else
17080                         printf("Field index %d is disabled.\n", res->field_idx);
17081                 return;
17082         } else if (!strcmp(res->opt, "set"))
17083                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17084                                                    res->field_idx);
17085         else if (!strcmp(res->opt, "clear"))
17086                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17087                                                      res->field_idx);
17088         if (ret) {
17089                 printf("Failed to configure input set field.\n");
17090                 return;
17091         }
17092
17093         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17094                                      &inset, inset_type);
17095         if (ret) {
17096                 printf("Failed to set input set.\n");
17097                 return;
17098         }
17099 #endif
17100
17101         if (ret == -ENOTSUP)
17102                 printf("Function not supported\n");
17103 }
17104
17105 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17106         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17107                                  port, "port");
17108 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17109         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17110                                  cfg, "config");
17111 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17112         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17113                               port_id, UINT16);
17114 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17115         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17116                                  pctype, "pctype");
17117 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17118         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17119                               pctype_id, UINT8);
17120 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17121         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17122                                  inset_type,
17123                                  "hash_inset#fdir_inset#fdir_flx_inset");
17124 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17125         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17126                                  opt, "get#set#clear");
17127 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17128         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17129                                  field, "field");
17130 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17131         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17132                               field_idx, UINT8);
17133
17134 cmdline_parse_inst_t cmd_cfg_input_set = {
17135         .f = cmd_cfg_input_set_parsed,
17136         .data = NULL,
17137         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17138                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17139         .tokens = {
17140                 (void *)&cmd_cfg_input_set_port,
17141                 (void *)&cmd_cfg_input_set_cfg,
17142                 (void *)&cmd_cfg_input_set_port_id,
17143                 (void *)&cmd_cfg_input_set_pctype,
17144                 (void *)&cmd_cfg_input_set_pctype_id,
17145                 (void *)&cmd_cfg_input_set_inset_type,
17146                 (void *)&cmd_cfg_input_set_opt,
17147                 (void *)&cmd_cfg_input_set_field,
17148                 (void *)&cmd_cfg_input_set_field_idx,
17149                 NULL,
17150         },
17151 };
17152
17153 /* Clear input set */
17154 struct cmd_clear_input_set_result {
17155         cmdline_fixed_string_t port;
17156         cmdline_fixed_string_t cfg;
17157         portid_t port_id;
17158         cmdline_fixed_string_t pctype;
17159         uint8_t pctype_id;
17160         cmdline_fixed_string_t inset_type;
17161         cmdline_fixed_string_t clear;
17162         cmdline_fixed_string_t all;
17163 };
17164
17165 static void
17166 cmd_clear_input_set_parsed(
17167         __rte_unused void *parsed_result,
17168         __rte_unused struct cmdline *cl,
17169         __rte_unused void *data)
17170 {
17171 #ifdef RTE_LIBRTE_I40E_PMD
17172         struct cmd_clear_input_set_result *res = parsed_result;
17173         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17174         struct rte_pmd_i40e_inset inset;
17175 #endif
17176         int ret = -ENOTSUP;
17177
17178         if (!all_ports_stopped()) {
17179                 printf("Please stop all ports first\n");
17180                 return;
17181         }
17182
17183 #ifdef RTE_LIBRTE_I40E_PMD
17184         if (!strcmp(res->inset_type, "hash_inset"))
17185                 inset_type = INSET_HASH;
17186         else if (!strcmp(res->inset_type, "fdir_inset"))
17187                 inset_type = INSET_FDIR;
17188         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17189                 inset_type = INSET_FDIR_FLX;
17190
17191         memset(&inset, 0, sizeof(inset));
17192
17193         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17194                                      &inset, inset_type);
17195         if (ret) {
17196                 printf("Failed to clear input set.\n");
17197                 return;
17198         }
17199
17200 #endif
17201
17202         if (ret == -ENOTSUP)
17203                 printf("Function not supported\n");
17204 }
17205
17206 cmdline_parse_token_string_t cmd_clear_input_set_port =
17207         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17208                                  port, "port");
17209 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17210         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17211                                  cfg, "config");
17212 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17213         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17214                               port_id, UINT16);
17215 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17216         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17217                                  pctype, "pctype");
17218 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17219         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17220                               pctype_id, UINT8);
17221 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17222         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17223                                  inset_type,
17224                                  "hash_inset#fdir_inset#fdir_flx_inset");
17225 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17226         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17227                                  clear, "clear");
17228 cmdline_parse_token_string_t cmd_clear_input_set_all =
17229         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17230                                  all, "all");
17231
17232 cmdline_parse_inst_t cmd_clear_input_set = {
17233         .f = cmd_clear_input_set_parsed,
17234         .data = NULL,
17235         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17236                     "fdir_inset|fdir_flx_inset clear all",
17237         .tokens = {
17238                 (void *)&cmd_clear_input_set_port,
17239                 (void *)&cmd_clear_input_set_cfg,
17240                 (void *)&cmd_clear_input_set_port_id,
17241                 (void *)&cmd_clear_input_set_pctype,
17242                 (void *)&cmd_clear_input_set_pctype_id,
17243                 (void *)&cmd_clear_input_set_inset_type,
17244                 (void *)&cmd_clear_input_set_clear,
17245                 (void *)&cmd_clear_input_set_all,
17246                 NULL,
17247         },
17248 };
17249
17250 /* show vf stats */
17251
17252 /* Common result structure for show vf stats */
17253 struct cmd_show_vf_stats_result {
17254         cmdline_fixed_string_t show;
17255         cmdline_fixed_string_t vf;
17256         cmdline_fixed_string_t stats;
17257         portid_t port_id;
17258         uint16_t vf_id;
17259 };
17260
17261 /* Common CLI fields show vf stats*/
17262 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17263         TOKEN_STRING_INITIALIZER
17264                 (struct cmd_show_vf_stats_result,
17265                  show, "show");
17266 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17267         TOKEN_STRING_INITIALIZER
17268                 (struct cmd_show_vf_stats_result,
17269                  vf, "vf");
17270 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17271         TOKEN_STRING_INITIALIZER
17272                 (struct cmd_show_vf_stats_result,
17273                  stats, "stats");
17274 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17275         TOKEN_NUM_INITIALIZER
17276                 (struct cmd_show_vf_stats_result,
17277                  port_id, UINT16);
17278 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17279         TOKEN_NUM_INITIALIZER
17280                 (struct cmd_show_vf_stats_result,
17281                  vf_id, UINT16);
17282
17283 static void
17284 cmd_show_vf_stats_parsed(
17285         void *parsed_result,
17286         __rte_unused struct cmdline *cl,
17287         __rte_unused void *data)
17288 {
17289         struct cmd_show_vf_stats_result *res = parsed_result;
17290         struct rte_eth_stats stats;
17291         int ret = -ENOTSUP;
17292         static const char *nic_stats_border = "########################";
17293
17294         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17295                 return;
17296
17297         memset(&stats, 0, sizeof(stats));
17298
17299 #ifdef RTE_LIBRTE_I40E_PMD
17300         if (ret == -ENOTSUP)
17301                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17302                                                 res->vf_id,
17303                                                 &stats);
17304 #endif
17305 #ifdef RTE_LIBRTE_BNXT_PMD
17306         if (ret == -ENOTSUP)
17307                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17308                                                 res->vf_id,
17309                                                 &stats);
17310 #endif
17311
17312         switch (ret) {
17313         case 0:
17314                 break;
17315         case -EINVAL:
17316                 printf("invalid vf_id %d\n", res->vf_id);
17317                 break;
17318         case -ENODEV:
17319                 printf("invalid port_id %d\n", res->port_id);
17320                 break;
17321         case -ENOTSUP:
17322                 printf("function not implemented\n");
17323                 break;
17324         default:
17325                 printf("programming error: (%s)\n", strerror(-ret));
17326         }
17327
17328         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17329                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17330
17331         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17332                "%-"PRIu64"\n",
17333                stats.ipackets, stats.imissed, stats.ibytes);
17334         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17335         printf("  RX-nombuf:  %-10"PRIu64"\n",
17336                stats.rx_nombuf);
17337         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17338                "%-"PRIu64"\n",
17339                stats.opackets, stats.oerrors, stats.obytes);
17340
17341         printf("  %s############################%s\n",
17342                                nic_stats_border, nic_stats_border);
17343 }
17344
17345 cmdline_parse_inst_t cmd_show_vf_stats = {
17346         .f = cmd_show_vf_stats_parsed,
17347         .data = NULL,
17348         .help_str = "show vf stats <port_id> <vf_id>",
17349         .tokens = {
17350                 (void *)&cmd_show_vf_stats_show,
17351                 (void *)&cmd_show_vf_stats_vf,
17352                 (void *)&cmd_show_vf_stats_stats,
17353                 (void *)&cmd_show_vf_stats_port_id,
17354                 (void *)&cmd_show_vf_stats_vf_id,
17355                 NULL,
17356         },
17357 };
17358
17359 /* clear vf stats */
17360
17361 /* Common result structure for clear vf stats */
17362 struct cmd_clear_vf_stats_result {
17363         cmdline_fixed_string_t clear;
17364         cmdline_fixed_string_t vf;
17365         cmdline_fixed_string_t stats;
17366         portid_t port_id;
17367         uint16_t vf_id;
17368 };
17369
17370 /* Common CLI fields clear vf stats*/
17371 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17372         TOKEN_STRING_INITIALIZER
17373                 (struct cmd_clear_vf_stats_result,
17374                  clear, "clear");
17375 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17376         TOKEN_STRING_INITIALIZER
17377                 (struct cmd_clear_vf_stats_result,
17378                  vf, "vf");
17379 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17380         TOKEN_STRING_INITIALIZER
17381                 (struct cmd_clear_vf_stats_result,
17382                  stats, "stats");
17383 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17384         TOKEN_NUM_INITIALIZER
17385                 (struct cmd_clear_vf_stats_result,
17386                  port_id, UINT16);
17387 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17388         TOKEN_NUM_INITIALIZER
17389                 (struct cmd_clear_vf_stats_result,
17390                  vf_id, UINT16);
17391
17392 static void
17393 cmd_clear_vf_stats_parsed(
17394         void *parsed_result,
17395         __rte_unused struct cmdline *cl,
17396         __rte_unused void *data)
17397 {
17398         struct cmd_clear_vf_stats_result *res = parsed_result;
17399         int ret = -ENOTSUP;
17400
17401         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17402                 return;
17403
17404 #ifdef RTE_LIBRTE_I40E_PMD
17405         if (ret == -ENOTSUP)
17406                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17407                                                   res->vf_id);
17408 #endif
17409 #ifdef RTE_LIBRTE_BNXT_PMD
17410         if (ret == -ENOTSUP)
17411                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17412                                                   res->vf_id);
17413 #endif
17414
17415         switch (ret) {
17416         case 0:
17417                 break;
17418         case -EINVAL:
17419                 printf("invalid vf_id %d\n", res->vf_id);
17420                 break;
17421         case -ENODEV:
17422                 printf("invalid port_id %d\n", res->port_id);
17423                 break;
17424         case -ENOTSUP:
17425                 printf("function not implemented\n");
17426                 break;
17427         default:
17428                 printf("programming error: (%s)\n", strerror(-ret));
17429         }
17430 }
17431
17432 cmdline_parse_inst_t cmd_clear_vf_stats = {
17433         .f = cmd_clear_vf_stats_parsed,
17434         .data = NULL,
17435         .help_str = "clear vf stats <port_id> <vf_id>",
17436         .tokens = {
17437                 (void *)&cmd_clear_vf_stats_clear,
17438                 (void *)&cmd_clear_vf_stats_vf,
17439                 (void *)&cmd_clear_vf_stats_stats,
17440                 (void *)&cmd_clear_vf_stats_port_id,
17441                 (void *)&cmd_clear_vf_stats_vf_id,
17442                 NULL,
17443         },
17444 };
17445
17446 /* port config pctype mapping reset */
17447
17448 /* Common result structure for port config pctype mapping reset */
17449 struct cmd_pctype_mapping_reset_result {
17450         cmdline_fixed_string_t port;
17451         cmdline_fixed_string_t config;
17452         portid_t port_id;
17453         cmdline_fixed_string_t pctype;
17454         cmdline_fixed_string_t mapping;
17455         cmdline_fixed_string_t reset;
17456 };
17457
17458 /* Common CLI fields for port config pctype mapping reset*/
17459 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17460         TOKEN_STRING_INITIALIZER
17461                 (struct cmd_pctype_mapping_reset_result,
17462                  port, "port");
17463 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17464         TOKEN_STRING_INITIALIZER
17465                 (struct cmd_pctype_mapping_reset_result,
17466                  config, "config");
17467 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17468         TOKEN_NUM_INITIALIZER
17469                 (struct cmd_pctype_mapping_reset_result,
17470                  port_id, UINT16);
17471 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17472         TOKEN_STRING_INITIALIZER
17473                 (struct cmd_pctype_mapping_reset_result,
17474                  pctype, "pctype");
17475 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17476         TOKEN_STRING_INITIALIZER
17477                 (struct cmd_pctype_mapping_reset_result,
17478                  mapping, "mapping");
17479 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17480         TOKEN_STRING_INITIALIZER
17481                 (struct cmd_pctype_mapping_reset_result,
17482                  reset, "reset");
17483
17484 static void
17485 cmd_pctype_mapping_reset_parsed(
17486         void *parsed_result,
17487         __rte_unused struct cmdline *cl,
17488         __rte_unused void *data)
17489 {
17490         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17491         int ret = -ENOTSUP;
17492
17493         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17494                 return;
17495
17496 #ifdef RTE_LIBRTE_I40E_PMD
17497         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17498 #endif
17499
17500         switch (ret) {
17501         case 0:
17502                 break;
17503         case -ENODEV:
17504                 printf("invalid port_id %d\n", res->port_id);
17505                 break;
17506         case -ENOTSUP:
17507                 printf("function not implemented\n");
17508                 break;
17509         default:
17510                 printf("programming error: (%s)\n", strerror(-ret));
17511         }
17512 }
17513
17514 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17515         .f = cmd_pctype_mapping_reset_parsed,
17516         .data = NULL,
17517         .help_str = "port config <port_id> pctype mapping reset",
17518         .tokens = {
17519                 (void *)&cmd_pctype_mapping_reset_port,
17520                 (void *)&cmd_pctype_mapping_reset_config,
17521                 (void *)&cmd_pctype_mapping_reset_port_id,
17522                 (void *)&cmd_pctype_mapping_reset_pctype,
17523                 (void *)&cmd_pctype_mapping_reset_mapping,
17524                 (void *)&cmd_pctype_mapping_reset_reset,
17525                 NULL,
17526         },
17527 };
17528
17529 /* show port pctype mapping */
17530
17531 /* Common result structure for show port pctype mapping */
17532 struct cmd_pctype_mapping_get_result {
17533         cmdline_fixed_string_t show;
17534         cmdline_fixed_string_t port;
17535         portid_t port_id;
17536         cmdline_fixed_string_t pctype;
17537         cmdline_fixed_string_t mapping;
17538 };
17539
17540 /* Common CLI fields for pctype mapping get */
17541 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17542         TOKEN_STRING_INITIALIZER
17543                 (struct cmd_pctype_mapping_get_result,
17544                  show, "show");
17545 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17546         TOKEN_STRING_INITIALIZER
17547                 (struct cmd_pctype_mapping_get_result,
17548                  port, "port");
17549 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17550         TOKEN_NUM_INITIALIZER
17551                 (struct cmd_pctype_mapping_get_result,
17552                  port_id, UINT16);
17553 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17554         TOKEN_STRING_INITIALIZER
17555                 (struct cmd_pctype_mapping_get_result,
17556                  pctype, "pctype");
17557 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17558         TOKEN_STRING_INITIALIZER
17559                 (struct cmd_pctype_mapping_get_result,
17560                  mapping, "mapping");
17561
17562 static void
17563 cmd_pctype_mapping_get_parsed(
17564         void *parsed_result,
17565         __rte_unused struct cmdline *cl,
17566         __rte_unused void *data)
17567 {
17568         struct cmd_pctype_mapping_get_result *res = parsed_result;
17569         int ret = -ENOTSUP;
17570 #ifdef RTE_LIBRTE_I40E_PMD
17571         struct rte_pmd_i40e_flow_type_mapping
17572                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17573         int i, j, first_pctype;
17574 #endif
17575
17576         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17577                 return;
17578
17579 #ifdef RTE_LIBRTE_I40E_PMD
17580         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17581 #endif
17582
17583         switch (ret) {
17584         case 0:
17585                 break;
17586         case -ENODEV:
17587                 printf("invalid port_id %d\n", res->port_id);
17588                 return;
17589         case -ENOTSUP:
17590                 printf("function not implemented\n");
17591                 return;
17592         default:
17593                 printf("programming error: (%s)\n", strerror(-ret));
17594                 return;
17595         }
17596
17597 #ifdef RTE_LIBRTE_I40E_PMD
17598         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17599                 if (mapping[i].pctype != 0ULL) {
17600                         first_pctype = 1;
17601
17602                         printf("pctype: ");
17603                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17604                                 if (mapping[i].pctype & (1ULL << j)) {
17605                                         printf(first_pctype ?
17606                                                "%02d" : ",%02d", j);
17607                                         first_pctype = 0;
17608                                 }
17609                         }
17610                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17611                 }
17612         }
17613 #endif
17614 }
17615
17616 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17617         .f = cmd_pctype_mapping_get_parsed,
17618         .data = NULL,
17619         .help_str = "show port <port_id> pctype mapping",
17620         .tokens = {
17621                 (void *)&cmd_pctype_mapping_get_show,
17622                 (void *)&cmd_pctype_mapping_get_port,
17623                 (void *)&cmd_pctype_mapping_get_port_id,
17624                 (void *)&cmd_pctype_mapping_get_pctype,
17625                 (void *)&cmd_pctype_mapping_get_mapping,
17626                 NULL,
17627         },
17628 };
17629
17630 /* port config pctype mapping update */
17631
17632 /* Common result structure for port config pctype mapping update */
17633 struct cmd_pctype_mapping_update_result {
17634         cmdline_fixed_string_t port;
17635         cmdline_fixed_string_t config;
17636         portid_t port_id;
17637         cmdline_fixed_string_t pctype;
17638         cmdline_fixed_string_t mapping;
17639         cmdline_fixed_string_t update;
17640         cmdline_fixed_string_t pctype_list;
17641         uint16_t flow_type;
17642 };
17643
17644 /* Common CLI fields for pctype mapping update*/
17645 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17646         TOKEN_STRING_INITIALIZER
17647                 (struct cmd_pctype_mapping_update_result,
17648                  port, "port");
17649 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17650         TOKEN_STRING_INITIALIZER
17651                 (struct cmd_pctype_mapping_update_result,
17652                  config, "config");
17653 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17654         TOKEN_NUM_INITIALIZER
17655                 (struct cmd_pctype_mapping_update_result,
17656                  port_id, UINT16);
17657 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17658         TOKEN_STRING_INITIALIZER
17659                 (struct cmd_pctype_mapping_update_result,
17660                  pctype, "pctype");
17661 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17662         TOKEN_STRING_INITIALIZER
17663                 (struct cmd_pctype_mapping_update_result,
17664                  mapping, "mapping");
17665 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17666         TOKEN_STRING_INITIALIZER
17667                 (struct cmd_pctype_mapping_update_result,
17668                  update, "update");
17669 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17670         TOKEN_STRING_INITIALIZER
17671                 (struct cmd_pctype_mapping_update_result,
17672                  pctype_list, NULL);
17673 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17674         TOKEN_NUM_INITIALIZER
17675                 (struct cmd_pctype_mapping_update_result,
17676                  flow_type, UINT16);
17677
17678 static void
17679 cmd_pctype_mapping_update_parsed(
17680         void *parsed_result,
17681         __rte_unused struct cmdline *cl,
17682         __rte_unused void *data)
17683 {
17684         struct cmd_pctype_mapping_update_result *res = parsed_result;
17685         int ret = -ENOTSUP;
17686 #ifdef RTE_LIBRTE_I40E_PMD
17687         struct rte_pmd_i40e_flow_type_mapping mapping;
17688         unsigned int i;
17689         unsigned int nb_item;
17690         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17691 #endif
17692
17693         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17694                 return;
17695
17696 #ifdef RTE_LIBRTE_I40E_PMD
17697         nb_item = parse_item_list(res->pctype_list, "pctypes",
17698                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17699         mapping.flow_type = res->flow_type;
17700         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17701                 mapping.pctype |= (1ULL << pctype_list[i]);
17702         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17703                                                 &mapping,
17704                                                 1,
17705                                                 0);
17706 #endif
17707
17708         switch (ret) {
17709         case 0:
17710                 break;
17711         case -EINVAL:
17712                 printf("invalid pctype or flow type\n");
17713                 break;
17714         case -ENODEV:
17715                 printf("invalid port_id %d\n", res->port_id);
17716                 break;
17717         case -ENOTSUP:
17718                 printf("function not implemented\n");
17719                 break;
17720         default:
17721                 printf("programming error: (%s)\n", strerror(-ret));
17722         }
17723 }
17724
17725 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17726         .f = cmd_pctype_mapping_update_parsed,
17727         .data = NULL,
17728         .help_str = "port config <port_id> pctype mapping update"
17729         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17730         .tokens = {
17731                 (void *)&cmd_pctype_mapping_update_port,
17732                 (void *)&cmd_pctype_mapping_update_config,
17733                 (void *)&cmd_pctype_mapping_update_port_id,
17734                 (void *)&cmd_pctype_mapping_update_pctype,
17735                 (void *)&cmd_pctype_mapping_update_mapping,
17736                 (void *)&cmd_pctype_mapping_update_update,
17737                 (void *)&cmd_pctype_mapping_update_pc_type,
17738                 (void *)&cmd_pctype_mapping_update_flow_type,
17739                 NULL,
17740         },
17741 };
17742
17743 /* ptype mapping get */
17744
17745 /* Common result structure for ptype mapping get */
17746 struct cmd_ptype_mapping_get_result {
17747         cmdline_fixed_string_t ptype;
17748         cmdline_fixed_string_t mapping;
17749         cmdline_fixed_string_t get;
17750         portid_t port_id;
17751         uint8_t valid_only;
17752 };
17753
17754 /* Common CLI fields for ptype mapping get */
17755 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17756         TOKEN_STRING_INITIALIZER
17757                 (struct cmd_ptype_mapping_get_result,
17758                  ptype, "ptype");
17759 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17760         TOKEN_STRING_INITIALIZER
17761                 (struct cmd_ptype_mapping_get_result,
17762                  mapping, "mapping");
17763 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17764         TOKEN_STRING_INITIALIZER
17765                 (struct cmd_ptype_mapping_get_result,
17766                  get, "get");
17767 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17768         TOKEN_NUM_INITIALIZER
17769                 (struct cmd_ptype_mapping_get_result,
17770                  port_id, UINT16);
17771 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17772         TOKEN_NUM_INITIALIZER
17773                 (struct cmd_ptype_mapping_get_result,
17774                  valid_only, UINT8);
17775
17776 static void
17777 cmd_ptype_mapping_get_parsed(
17778         void *parsed_result,
17779         __rte_unused struct cmdline *cl,
17780         __rte_unused void *data)
17781 {
17782         struct cmd_ptype_mapping_get_result *res = parsed_result;
17783         int ret = -ENOTSUP;
17784 #ifdef RTE_LIBRTE_I40E_PMD
17785         int max_ptype_num = 256;
17786         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17787         uint16_t count;
17788         int i;
17789 #endif
17790
17791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17792                 return;
17793
17794 #ifdef RTE_LIBRTE_I40E_PMD
17795         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17796                                         mapping,
17797                                         max_ptype_num,
17798                                         &count,
17799                                         res->valid_only);
17800 #endif
17801
17802         switch (ret) {
17803         case 0:
17804                 break;
17805         case -ENODEV:
17806                 printf("invalid port_id %d\n", res->port_id);
17807                 break;
17808         case -ENOTSUP:
17809                 printf("function not implemented\n");
17810                 break;
17811         default:
17812                 printf("programming error: (%s)\n", strerror(-ret));
17813         }
17814
17815 #ifdef RTE_LIBRTE_I40E_PMD
17816         if (!ret) {
17817                 for (i = 0; i < count; i++)
17818                         printf("%3d\t0x%08x\n",
17819                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17820         }
17821 #endif
17822 }
17823
17824 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17825         .f = cmd_ptype_mapping_get_parsed,
17826         .data = NULL,
17827         .help_str = "ptype mapping get <port_id> <valid_only>",
17828         .tokens = {
17829                 (void *)&cmd_ptype_mapping_get_ptype,
17830                 (void *)&cmd_ptype_mapping_get_mapping,
17831                 (void *)&cmd_ptype_mapping_get_get,
17832                 (void *)&cmd_ptype_mapping_get_port_id,
17833                 (void *)&cmd_ptype_mapping_get_valid_only,
17834                 NULL,
17835         },
17836 };
17837
17838 /* ptype mapping replace */
17839
17840 /* Common result structure for ptype mapping replace */
17841 struct cmd_ptype_mapping_replace_result {
17842         cmdline_fixed_string_t ptype;
17843         cmdline_fixed_string_t mapping;
17844         cmdline_fixed_string_t replace;
17845         portid_t port_id;
17846         uint32_t target;
17847         uint8_t mask;
17848         uint32_t pkt_type;
17849 };
17850
17851 /* Common CLI fields for ptype mapping replace */
17852 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17853         TOKEN_STRING_INITIALIZER
17854                 (struct cmd_ptype_mapping_replace_result,
17855                  ptype, "ptype");
17856 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17857         TOKEN_STRING_INITIALIZER
17858                 (struct cmd_ptype_mapping_replace_result,
17859                  mapping, "mapping");
17860 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17861         TOKEN_STRING_INITIALIZER
17862                 (struct cmd_ptype_mapping_replace_result,
17863                  replace, "replace");
17864 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17865         TOKEN_NUM_INITIALIZER
17866                 (struct cmd_ptype_mapping_replace_result,
17867                  port_id, UINT16);
17868 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17869         TOKEN_NUM_INITIALIZER
17870                 (struct cmd_ptype_mapping_replace_result,
17871                  target, UINT32);
17872 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17873         TOKEN_NUM_INITIALIZER
17874                 (struct cmd_ptype_mapping_replace_result,
17875                  mask, UINT8);
17876 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17877         TOKEN_NUM_INITIALIZER
17878                 (struct cmd_ptype_mapping_replace_result,
17879                  pkt_type, UINT32);
17880
17881 static void
17882 cmd_ptype_mapping_replace_parsed(
17883         void *parsed_result,
17884         __rte_unused struct cmdline *cl,
17885         __rte_unused void *data)
17886 {
17887         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17888         int ret = -ENOTSUP;
17889
17890         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17891                 return;
17892
17893 #ifdef RTE_LIBRTE_I40E_PMD
17894         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17895                                         res->target,
17896                                         res->mask,
17897                                         res->pkt_type);
17898 #endif
17899
17900         switch (ret) {
17901         case 0:
17902                 break;
17903         case -EINVAL:
17904                 printf("invalid ptype 0x%8x or 0x%8x\n",
17905                                 res->target, res->pkt_type);
17906                 break;
17907         case -ENODEV:
17908                 printf("invalid port_id %d\n", res->port_id);
17909                 break;
17910         case -ENOTSUP:
17911                 printf("function not implemented\n");
17912                 break;
17913         default:
17914                 printf("programming error: (%s)\n", strerror(-ret));
17915         }
17916 }
17917
17918 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
17919         .f = cmd_ptype_mapping_replace_parsed,
17920         .data = NULL,
17921         .help_str =
17922                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
17923         .tokens = {
17924                 (void *)&cmd_ptype_mapping_replace_ptype,
17925                 (void *)&cmd_ptype_mapping_replace_mapping,
17926                 (void *)&cmd_ptype_mapping_replace_replace,
17927                 (void *)&cmd_ptype_mapping_replace_port_id,
17928                 (void *)&cmd_ptype_mapping_replace_target,
17929                 (void *)&cmd_ptype_mapping_replace_mask,
17930                 (void *)&cmd_ptype_mapping_replace_pkt_type,
17931                 NULL,
17932         },
17933 };
17934
17935 /* ptype mapping reset */
17936
17937 /* Common result structure for ptype mapping reset */
17938 struct cmd_ptype_mapping_reset_result {
17939         cmdline_fixed_string_t ptype;
17940         cmdline_fixed_string_t mapping;
17941         cmdline_fixed_string_t reset;
17942         portid_t port_id;
17943 };
17944
17945 /* Common CLI fields for ptype mapping reset*/
17946 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
17947         TOKEN_STRING_INITIALIZER
17948                 (struct cmd_ptype_mapping_reset_result,
17949                  ptype, "ptype");
17950 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
17951         TOKEN_STRING_INITIALIZER
17952                 (struct cmd_ptype_mapping_reset_result,
17953                  mapping, "mapping");
17954 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
17955         TOKEN_STRING_INITIALIZER
17956                 (struct cmd_ptype_mapping_reset_result,
17957                  reset, "reset");
17958 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
17959         TOKEN_NUM_INITIALIZER
17960                 (struct cmd_ptype_mapping_reset_result,
17961                  port_id, UINT16);
17962
17963 static void
17964 cmd_ptype_mapping_reset_parsed(
17965         void *parsed_result,
17966         __rte_unused struct cmdline *cl,
17967         __rte_unused void *data)
17968 {
17969         struct cmd_ptype_mapping_reset_result *res = parsed_result;
17970         int ret = -ENOTSUP;
17971
17972         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17973                 return;
17974
17975 #ifdef RTE_LIBRTE_I40E_PMD
17976         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
17977 #endif
17978
17979         switch (ret) {
17980         case 0:
17981                 break;
17982         case -ENODEV:
17983                 printf("invalid port_id %d\n", res->port_id);
17984                 break;
17985         case -ENOTSUP:
17986                 printf("function not implemented\n");
17987                 break;
17988         default:
17989                 printf("programming error: (%s)\n", strerror(-ret));
17990         }
17991 }
17992
17993 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
17994         .f = cmd_ptype_mapping_reset_parsed,
17995         .data = NULL,
17996         .help_str = "ptype mapping reset <port_id>",
17997         .tokens = {
17998                 (void *)&cmd_ptype_mapping_reset_ptype,
17999                 (void *)&cmd_ptype_mapping_reset_mapping,
18000                 (void *)&cmd_ptype_mapping_reset_reset,
18001                 (void *)&cmd_ptype_mapping_reset_port_id,
18002                 NULL,
18003         },
18004 };
18005
18006 /* ptype mapping update */
18007
18008 /* Common result structure for ptype mapping update */
18009 struct cmd_ptype_mapping_update_result {
18010         cmdline_fixed_string_t ptype;
18011         cmdline_fixed_string_t mapping;
18012         cmdline_fixed_string_t reset;
18013         portid_t port_id;
18014         uint8_t hw_ptype;
18015         uint32_t sw_ptype;
18016 };
18017
18018 /* Common CLI fields for ptype mapping update*/
18019 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18020         TOKEN_STRING_INITIALIZER
18021                 (struct cmd_ptype_mapping_update_result,
18022                  ptype, "ptype");
18023 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18024         TOKEN_STRING_INITIALIZER
18025                 (struct cmd_ptype_mapping_update_result,
18026                  mapping, "mapping");
18027 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18028         TOKEN_STRING_INITIALIZER
18029                 (struct cmd_ptype_mapping_update_result,
18030                  reset, "update");
18031 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18032         TOKEN_NUM_INITIALIZER
18033                 (struct cmd_ptype_mapping_update_result,
18034                  port_id, UINT16);
18035 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18036         TOKEN_NUM_INITIALIZER
18037                 (struct cmd_ptype_mapping_update_result,
18038                  hw_ptype, UINT8);
18039 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18040         TOKEN_NUM_INITIALIZER
18041                 (struct cmd_ptype_mapping_update_result,
18042                  sw_ptype, UINT32);
18043
18044 static void
18045 cmd_ptype_mapping_update_parsed(
18046         void *parsed_result,
18047         __rte_unused struct cmdline *cl,
18048         __rte_unused void *data)
18049 {
18050         struct cmd_ptype_mapping_update_result *res = parsed_result;
18051         int ret = -ENOTSUP;
18052 #ifdef RTE_LIBRTE_I40E_PMD
18053         struct rte_pmd_i40e_ptype_mapping mapping;
18054 #endif
18055         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18056                 return;
18057
18058 #ifdef RTE_LIBRTE_I40E_PMD
18059         mapping.hw_ptype = res->hw_ptype;
18060         mapping.sw_ptype = res->sw_ptype;
18061         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18062                                                 &mapping,
18063                                                 1,
18064                                                 0);
18065 #endif
18066
18067         switch (ret) {
18068         case 0:
18069                 break;
18070         case -EINVAL:
18071                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18072                 break;
18073         case -ENODEV:
18074                 printf("invalid port_id %d\n", res->port_id);
18075                 break;
18076         case -ENOTSUP:
18077                 printf("function not implemented\n");
18078                 break;
18079         default:
18080                 printf("programming error: (%s)\n", strerror(-ret));
18081         }
18082 }
18083
18084 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18085         .f = cmd_ptype_mapping_update_parsed,
18086         .data = NULL,
18087         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18088         .tokens = {
18089                 (void *)&cmd_ptype_mapping_update_ptype,
18090                 (void *)&cmd_ptype_mapping_update_mapping,
18091                 (void *)&cmd_ptype_mapping_update_update,
18092                 (void *)&cmd_ptype_mapping_update_port_id,
18093                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18094                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18095                 NULL,
18096         },
18097 };
18098
18099 /* Common result structure for file commands */
18100 struct cmd_cmdfile_result {
18101         cmdline_fixed_string_t load;
18102         cmdline_fixed_string_t filename;
18103 };
18104
18105 /* Common CLI fields for file commands */
18106 cmdline_parse_token_string_t cmd_load_cmdfile =
18107         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18108 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18109         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18110
18111 static void
18112 cmd_load_from_file_parsed(
18113         void *parsed_result,
18114         __rte_unused struct cmdline *cl,
18115         __rte_unused void *data)
18116 {
18117         struct cmd_cmdfile_result *res = parsed_result;
18118
18119         cmdline_read_from_file(res->filename);
18120 }
18121
18122 cmdline_parse_inst_t cmd_load_from_file = {
18123         .f = cmd_load_from_file_parsed,
18124         .data = NULL,
18125         .help_str = "load <filename>",
18126         .tokens = {
18127                 (void *)&cmd_load_cmdfile,
18128                 (void *)&cmd_load_cmdfile_filename,
18129                 NULL,
18130         },
18131 };
18132
18133 /* Get Rx offloads capabilities */
18134 struct cmd_rx_offload_get_capa_result {
18135         cmdline_fixed_string_t show;
18136         cmdline_fixed_string_t port;
18137         portid_t port_id;
18138         cmdline_fixed_string_t rx_offload;
18139         cmdline_fixed_string_t capabilities;
18140 };
18141
18142 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18143         TOKEN_STRING_INITIALIZER
18144                 (struct cmd_rx_offload_get_capa_result,
18145                  show, "show");
18146 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18147         TOKEN_STRING_INITIALIZER
18148                 (struct cmd_rx_offload_get_capa_result,
18149                  port, "port");
18150 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18151         TOKEN_NUM_INITIALIZER
18152                 (struct cmd_rx_offload_get_capa_result,
18153                  port_id, UINT16);
18154 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18155         TOKEN_STRING_INITIALIZER
18156                 (struct cmd_rx_offload_get_capa_result,
18157                  rx_offload, "rx_offload");
18158 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18159         TOKEN_STRING_INITIALIZER
18160                 (struct cmd_rx_offload_get_capa_result,
18161                  capabilities, "capabilities");
18162
18163 static void
18164 print_rx_offloads(uint64_t offloads)
18165 {
18166         uint64_t single_offload;
18167         int begin;
18168         int end;
18169         int bit;
18170
18171         if (offloads == 0)
18172                 return;
18173
18174         begin = __builtin_ctzll(offloads);
18175         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18176
18177         single_offload = 1ULL << begin;
18178         for (bit = begin; bit < end; bit++) {
18179                 if (offloads & single_offload)
18180                         printf(" %s",
18181                                rte_eth_dev_rx_offload_name(single_offload));
18182                 single_offload <<= 1;
18183         }
18184 }
18185
18186 static void
18187 cmd_rx_offload_get_capa_parsed(
18188         void *parsed_result,
18189         __rte_unused struct cmdline *cl,
18190         __rte_unused void *data)
18191 {
18192         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18193         struct rte_eth_dev_info dev_info;
18194         portid_t port_id = res->port_id;
18195         uint64_t queue_offloads;
18196         uint64_t port_offloads;
18197         int ret;
18198
18199         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18200         if (ret != 0)
18201                 return;
18202
18203         queue_offloads = dev_info.rx_queue_offload_capa;
18204         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18205
18206         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18207         printf("  Per Queue :");
18208         print_rx_offloads(queue_offloads);
18209
18210         printf("\n");
18211         printf("  Per Port  :");
18212         print_rx_offloads(port_offloads);
18213         printf("\n\n");
18214 }
18215
18216 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18217         .f = cmd_rx_offload_get_capa_parsed,
18218         .data = NULL,
18219         .help_str = "show port <port_id> rx_offload capabilities",
18220         .tokens = {
18221                 (void *)&cmd_rx_offload_get_capa_show,
18222                 (void *)&cmd_rx_offload_get_capa_port,
18223                 (void *)&cmd_rx_offload_get_capa_port_id,
18224                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18225                 (void *)&cmd_rx_offload_get_capa_capabilities,
18226                 NULL,
18227         }
18228 };
18229
18230 /* Get Rx offloads configuration */
18231 struct cmd_rx_offload_get_configuration_result {
18232         cmdline_fixed_string_t show;
18233         cmdline_fixed_string_t port;
18234         portid_t port_id;
18235         cmdline_fixed_string_t rx_offload;
18236         cmdline_fixed_string_t configuration;
18237 };
18238
18239 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18240         TOKEN_STRING_INITIALIZER
18241                 (struct cmd_rx_offload_get_configuration_result,
18242                  show, "show");
18243 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18244         TOKEN_STRING_INITIALIZER
18245                 (struct cmd_rx_offload_get_configuration_result,
18246                  port, "port");
18247 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18248         TOKEN_NUM_INITIALIZER
18249                 (struct cmd_rx_offload_get_configuration_result,
18250                  port_id, UINT16);
18251 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18252         TOKEN_STRING_INITIALIZER
18253                 (struct cmd_rx_offload_get_configuration_result,
18254                  rx_offload, "rx_offload");
18255 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18256         TOKEN_STRING_INITIALIZER
18257                 (struct cmd_rx_offload_get_configuration_result,
18258                  configuration, "configuration");
18259
18260 static void
18261 cmd_rx_offload_get_configuration_parsed(
18262         void *parsed_result,
18263         __rte_unused struct cmdline *cl,
18264         __rte_unused void *data)
18265 {
18266         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18267         struct rte_eth_dev_info dev_info;
18268         portid_t port_id = res->port_id;
18269         struct rte_port *port = &ports[port_id];
18270         uint64_t port_offloads;
18271         uint64_t queue_offloads;
18272         uint16_t nb_rx_queues;
18273         int q;
18274         int ret;
18275
18276         printf("Rx Offloading Configuration of port %d :\n", port_id);
18277
18278         port_offloads = port->dev_conf.rxmode.offloads;
18279         printf("  Port :");
18280         print_rx_offloads(port_offloads);
18281         printf("\n");
18282
18283         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18284         if (ret != 0)
18285                 return;
18286
18287         nb_rx_queues = dev_info.nb_rx_queues;
18288         for (q = 0; q < nb_rx_queues; q++) {
18289                 queue_offloads = port->rx_conf[q].offloads;
18290                 printf("  Queue[%2d] :", q);
18291                 print_rx_offloads(queue_offloads);
18292                 printf("\n");
18293         }
18294         printf("\n");
18295 }
18296
18297 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18298         .f = cmd_rx_offload_get_configuration_parsed,
18299         .data = NULL,
18300         .help_str = "show port <port_id> rx_offload configuration",
18301         .tokens = {
18302                 (void *)&cmd_rx_offload_get_configuration_show,
18303                 (void *)&cmd_rx_offload_get_configuration_port,
18304                 (void *)&cmd_rx_offload_get_configuration_port_id,
18305                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18306                 (void *)&cmd_rx_offload_get_configuration_configuration,
18307                 NULL,
18308         }
18309 };
18310
18311 /* Enable/Disable a per port offloading */
18312 struct cmd_config_per_port_rx_offload_result {
18313         cmdline_fixed_string_t port;
18314         cmdline_fixed_string_t config;
18315         portid_t port_id;
18316         cmdline_fixed_string_t rx_offload;
18317         cmdline_fixed_string_t offload;
18318         cmdline_fixed_string_t on_off;
18319 };
18320
18321 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18322         TOKEN_STRING_INITIALIZER
18323                 (struct cmd_config_per_port_rx_offload_result,
18324                  port, "port");
18325 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18326         TOKEN_STRING_INITIALIZER
18327                 (struct cmd_config_per_port_rx_offload_result,
18328                  config, "config");
18329 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18330         TOKEN_NUM_INITIALIZER
18331                 (struct cmd_config_per_port_rx_offload_result,
18332                  port_id, UINT16);
18333 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18334         TOKEN_STRING_INITIALIZER
18335                 (struct cmd_config_per_port_rx_offload_result,
18336                  rx_offload, "rx_offload");
18337 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18338         TOKEN_STRING_INITIALIZER
18339                 (struct cmd_config_per_port_rx_offload_result,
18340                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18341                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18342                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18343                            "scatter#timestamp#security#keep_crc#rss_hash");
18344 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18345         TOKEN_STRING_INITIALIZER
18346                 (struct cmd_config_per_port_rx_offload_result,
18347                  on_off, "on#off");
18348
18349 static uint64_t
18350 search_rx_offload(const char *name)
18351 {
18352         uint64_t single_offload;
18353         const char *single_name;
18354         int found = 0;
18355         unsigned int bit;
18356
18357         single_offload = 1;
18358         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18359                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18360                 if (!strcasecmp(single_name, name)) {
18361                         found = 1;
18362                         break;
18363                 }
18364                 single_offload <<= 1;
18365         }
18366
18367         if (found)
18368                 return single_offload;
18369
18370         return 0;
18371 }
18372
18373 static void
18374 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18375                                 __rte_unused struct cmdline *cl,
18376                                 __rte_unused void *data)
18377 {
18378         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18379         portid_t port_id = res->port_id;
18380         struct rte_eth_dev_info dev_info;
18381         struct rte_port *port = &ports[port_id];
18382         uint64_t single_offload;
18383         uint16_t nb_rx_queues;
18384         int q;
18385         int ret;
18386
18387         if (port->port_status != RTE_PORT_STOPPED) {
18388                 printf("Error: Can't config offload when Port %d "
18389                        "is not stopped\n", port_id);
18390                 return;
18391         }
18392
18393         single_offload = search_rx_offload(res->offload);
18394         if (single_offload == 0) {
18395                 printf("Unknown offload name: %s\n", res->offload);
18396                 return;
18397         }
18398
18399         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18400         if (ret != 0)
18401                 return;
18402
18403         nb_rx_queues = dev_info.nb_rx_queues;
18404         if (!strcmp(res->on_off, "on")) {
18405                 port->dev_conf.rxmode.offloads |= single_offload;
18406                 for (q = 0; q < nb_rx_queues; q++)
18407                         port->rx_conf[q].offloads |= single_offload;
18408         } else {
18409                 port->dev_conf.rxmode.offloads &= ~single_offload;
18410                 for (q = 0; q < nb_rx_queues; q++)
18411                         port->rx_conf[q].offloads &= ~single_offload;
18412         }
18413
18414         cmd_reconfig_device_queue(port_id, 1, 1);
18415 }
18416
18417 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18418         .f = cmd_config_per_port_rx_offload_parsed,
18419         .data = NULL,
18420         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18421                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18422                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18423                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18424                     "on|off",
18425         .tokens = {
18426                 (void *)&cmd_config_per_port_rx_offload_result_port,
18427                 (void *)&cmd_config_per_port_rx_offload_result_config,
18428                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18429                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18430                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18431                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18432                 NULL,
18433         }
18434 };
18435
18436 /* Enable/Disable a per queue offloading */
18437 struct cmd_config_per_queue_rx_offload_result {
18438         cmdline_fixed_string_t port;
18439         portid_t port_id;
18440         cmdline_fixed_string_t rxq;
18441         uint16_t queue_id;
18442         cmdline_fixed_string_t rx_offload;
18443         cmdline_fixed_string_t offload;
18444         cmdline_fixed_string_t on_off;
18445 };
18446
18447 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18448         TOKEN_STRING_INITIALIZER
18449                 (struct cmd_config_per_queue_rx_offload_result,
18450                  port, "port");
18451 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18452         TOKEN_NUM_INITIALIZER
18453                 (struct cmd_config_per_queue_rx_offload_result,
18454                  port_id, UINT16);
18455 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18456         TOKEN_STRING_INITIALIZER
18457                 (struct cmd_config_per_queue_rx_offload_result,
18458                  rxq, "rxq");
18459 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18460         TOKEN_NUM_INITIALIZER
18461                 (struct cmd_config_per_queue_rx_offload_result,
18462                  queue_id, UINT16);
18463 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18464         TOKEN_STRING_INITIALIZER
18465                 (struct cmd_config_per_queue_rx_offload_result,
18466                  rx_offload, "rx_offload");
18467 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18468         TOKEN_STRING_INITIALIZER
18469                 (struct cmd_config_per_queue_rx_offload_result,
18470                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18471                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18472                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18473                            "scatter#timestamp#security#keep_crc");
18474 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18475         TOKEN_STRING_INITIALIZER
18476                 (struct cmd_config_per_queue_rx_offload_result,
18477                  on_off, "on#off");
18478
18479 static void
18480 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18481                                 __rte_unused struct cmdline *cl,
18482                                 __rte_unused void *data)
18483 {
18484         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18485         struct rte_eth_dev_info dev_info;
18486         portid_t port_id = res->port_id;
18487         uint16_t queue_id = res->queue_id;
18488         struct rte_port *port = &ports[port_id];
18489         uint64_t single_offload;
18490         int ret;
18491
18492         if (port->port_status != RTE_PORT_STOPPED) {
18493                 printf("Error: Can't config offload when Port %d "
18494                        "is not stopped\n", port_id);
18495                 return;
18496         }
18497
18498         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18499         if (ret != 0)
18500                 return;
18501
18502         if (queue_id >= dev_info.nb_rx_queues) {
18503                 printf("Error: input queue_id should be 0 ... "
18504                        "%d\n", dev_info.nb_rx_queues - 1);
18505                 return;
18506         }
18507
18508         single_offload = search_rx_offload(res->offload);
18509         if (single_offload == 0) {
18510                 printf("Unknown offload name: %s\n", res->offload);
18511                 return;
18512         }
18513
18514         if (!strcmp(res->on_off, "on"))
18515                 port->rx_conf[queue_id].offloads |= single_offload;
18516         else
18517                 port->rx_conf[queue_id].offloads &= ~single_offload;
18518
18519         cmd_reconfig_device_queue(port_id, 1, 1);
18520 }
18521
18522 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18523         .f = cmd_config_per_queue_rx_offload_parsed,
18524         .data = NULL,
18525         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18526                     "vlan_strip|ipv4_cksum|"
18527                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18528                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18529                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18530                     "on|off",
18531         .tokens = {
18532                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18533                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18534                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18535                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18536                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18537                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18538                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18539                 NULL,
18540         }
18541 };
18542
18543 /* Get Tx offloads capabilities */
18544 struct cmd_tx_offload_get_capa_result {
18545         cmdline_fixed_string_t show;
18546         cmdline_fixed_string_t port;
18547         portid_t port_id;
18548         cmdline_fixed_string_t tx_offload;
18549         cmdline_fixed_string_t capabilities;
18550 };
18551
18552 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18553         TOKEN_STRING_INITIALIZER
18554                 (struct cmd_tx_offload_get_capa_result,
18555                  show, "show");
18556 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18557         TOKEN_STRING_INITIALIZER
18558                 (struct cmd_tx_offload_get_capa_result,
18559                  port, "port");
18560 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18561         TOKEN_NUM_INITIALIZER
18562                 (struct cmd_tx_offload_get_capa_result,
18563                  port_id, UINT16);
18564 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18565         TOKEN_STRING_INITIALIZER
18566                 (struct cmd_tx_offload_get_capa_result,
18567                  tx_offload, "tx_offload");
18568 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18569         TOKEN_STRING_INITIALIZER
18570                 (struct cmd_tx_offload_get_capa_result,
18571                  capabilities, "capabilities");
18572
18573 static void
18574 print_tx_offloads(uint64_t offloads)
18575 {
18576         uint64_t single_offload;
18577         int begin;
18578         int end;
18579         int bit;
18580
18581         if (offloads == 0)
18582                 return;
18583
18584         begin = __builtin_ctzll(offloads);
18585         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18586
18587         single_offload = 1ULL << begin;
18588         for (bit = begin; bit < end; bit++) {
18589                 if (offloads & single_offload)
18590                         printf(" %s",
18591                                rte_eth_dev_tx_offload_name(single_offload));
18592                 single_offload <<= 1;
18593         }
18594 }
18595
18596 static void
18597 cmd_tx_offload_get_capa_parsed(
18598         void *parsed_result,
18599         __rte_unused struct cmdline *cl,
18600         __rte_unused void *data)
18601 {
18602         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18603         struct rte_eth_dev_info dev_info;
18604         portid_t port_id = res->port_id;
18605         uint64_t queue_offloads;
18606         uint64_t port_offloads;
18607         int ret;
18608
18609         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18610         if (ret != 0)
18611                 return;
18612
18613         queue_offloads = dev_info.tx_queue_offload_capa;
18614         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18615
18616         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18617         printf("  Per Queue :");
18618         print_tx_offloads(queue_offloads);
18619
18620         printf("\n");
18621         printf("  Per Port  :");
18622         print_tx_offloads(port_offloads);
18623         printf("\n\n");
18624 }
18625
18626 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18627         .f = cmd_tx_offload_get_capa_parsed,
18628         .data = NULL,
18629         .help_str = "show port <port_id> tx_offload capabilities",
18630         .tokens = {
18631                 (void *)&cmd_tx_offload_get_capa_show,
18632                 (void *)&cmd_tx_offload_get_capa_port,
18633                 (void *)&cmd_tx_offload_get_capa_port_id,
18634                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18635                 (void *)&cmd_tx_offload_get_capa_capabilities,
18636                 NULL,
18637         }
18638 };
18639
18640 /* Get Tx offloads configuration */
18641 struct cmd_tx_offload_get_configuration_result {
18642         cmdline_fixed_string_t show;
18643         cmdline_fixed_string_t port;
18644         portid_t port_id;
18645         cmdline_fixed_string_t tx_offload;
18646         cmdline_fixed_string_t configuration;
18647 };
18648
18649 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18650         TOKEN_STRING_INITIALIZER
18651                 (struct cmd_tx_offload_get_configuration_result,
18652                  show, "show");
18653 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18654         TOKEN_STRING_INITIALIZER
18655                 (struct cmd_tx_offload_get_configuration_result,
18656                  port, "port");
18657 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18658         TOKEN_NUM_INITIALIZER
18659                 (struct cmd_tx_offload_get_configuration_result,
18660                  port_id, UINT16);
18661 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18662         TOKEN_STRING_INITIALIZER
18663                 (struct cmd_tx_offload_get_configuration_result,
18664                  tx_offload, "tx_offload");
18665 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18666         TOKEN_STRING_INITIALIZER
18667                 (struct cmd_tx_offload_get_configuration_result,
18668                  configuration, "configuration");
18669
18670 static void
18671 cmd_tx_offload_get_configuration_parsed(
18672         void *parsed_result,
18673         __rte_unused struct cmdline *cl,
18674         __rte_unused void *data)
18675 {
18676         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18677         struct rte_eth_dev_info dev_info;
18678         portid_t port_id = res->port_id;
18679         struct rte_port *port = &ports[port_id];
18680         uint64_t port_offloads;
18681         uint64_t queue_offloads;
18682         uint16_t nb_tx_queues;
18683         int q;
18684         int ret;
18685
18686         printf("Tx Offloading Configuration of port %d :\n", port_id);
18687
18688         port_offloads = port->dev_conf.txmode.offloads;
18689         printf("  Port :");
18690         print_tx_offloads(port_offloads);
18691         printf("\n");
18692
18693         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18694         if (ret != 0)
18695                 return;
18696
18697         nb_tx_queues = dev_info.nb_tx_queues;
18698         for (q = 0; q < nb_tx_queues; q++) {
18699                 queue_offloads = port->tx_conf[q].offloads;
18700                 printf("  Queue[%2d] :", q);
18701                 print_tx_offloads(queue_offloads);
18702                 printf("\n");
18703         }
18704         printf("\n");
18705 }
18706
18707 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18708         .f = cmd_tx_offload_get_configuration_parsed,
18709         .data = NULL,
18710         .help_str = "show port <port_id> tx_offload configuration",
18711         .tokens = {
18712                 (void *)&cmd_tx_offload_get_configuration_show,
18713                 (void *)&cmd_tx_offload_get_configuration_port,
18714                 (void *)&cmd_tx_offload_get_configuration_port_id,
18715                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18716                 (void *)&cmd_tx_offload_get_configuration_configuration,
18717                 NULL,
18718         }
18719 };
18720
18721 /* Enable/Disable a per port offloading */
18722 struct cmd_config_per_port_tx_offload_result {
18723         cmdline_fixed_string_t port;
18724         cmdline_fixed_string_t config;
18725         portid_t port_id;
18726         cmdline_fixed_string_t tx_offload;
18727         cmdline_fixed_string_t offload;
18728         cmdline_fixed_string_t on_off;
18729 };
18730
18731 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18732         TOKEN_STRING_INITIALIZER
18733                 (struct cmd_config_per_port_tx_offload_result,
18734                  port, "port");
18735 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18736         TOKEN_STRING_INITIALIZER
18737                 (struct cmd_config_per_port_tx_offload_result,
18738                  config, "config");
18739 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18740         TOKEN_NUM_INITIALIZER
18741                 (struct cmd_config_per_port_tx_offload_result,
18742                  port_id, UINT16);
18743 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18744         TOKEN_STRING_INITIALIZER
18745                 (struct cmd_config_per_port_tx_offload_result,
18746                  tx_offload, "tx_offload");
18747 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18748         TOKEN_STRING_INITIALIZER
18749                 (struct cmd_config_per_port_tx_offload_result,
18750                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18751                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18752                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18753                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18754                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18755                           "send_on_timestamp");
18756 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18757         TOKEN_STRING_INITIALIZER
18758                 (struct cmd_config_per_port_tx_offload_result,
18759                  on_off, "on#off");
18760
18761 static uint64_t
18762 search_tx_offload(const char *name)
18763 {
18764         uint64_t single_offload;
18765         const char *single_name;
18766         int found = 0;
18767         unsigned int bit;
18768
18769         single_offload = 1;
18770         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18771                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18772                 if (single_name == NULL)
18773                         break;
18774                 if (!strcasecmp(single_name, name)) {
18775                         found = 1;
18776                         break;
18777                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18778                         break;
18779                 single_offload <<= 1;
18780         }
18781
18782         if (found)
18783                 return single_offload;
18784
18785         return 0;
18786 }
18787
18788 static void
18789 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18790                                 __rte_unused struct cmdline *cl,
18791                                 __rte_unused void *data)
18792 {
18793         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18794         portid_t port_id = res->port_id;
18795         struct rte_eth_dev_info dev_info;
18796         struct rte_port *port = &ports[port_id];
18797         uint64_t single_offload;
18798         uint16_t nb_tx_queues;
18799         int q;
18800         int ret;
18801
18802         if (port->port_status != RTE_PORT_STOPPED) {
18803                 printf("Error: Can't config offload when Port %d "
18804                        "is not stopped\n", port_id);
18805                 return;
18806         }
18807
18808         single_offload = search_tx_offload(res->offload);
18809         if (single_offload == 0) {
18810                 printf("Unknown offload name: %s\n", res->offload);
18811                 return;
18812         }
18813
18814         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18815         if (ret != 0)
18816                 return;
18817
18818         nb_tx_queues = dev_info.nb_tx_queues;
18819         if (!strcmp(res->on_off, "on")) {
18820                 port->dev_conf.txmode.offloads |= single_offload;
18821                 for (q = 0; q < nb_tx_queues; q++)
18822                         port->tx_conf[q].offloads |= single_offload;
18823         } else {
18824                 port->dev_conf.txmode.offloads &= ~single_offload;
18825                 for (q = 0; q < nb_tx_queues; q++)
18826                         port->tx_conf[q].offloads &= ~single_offload;
18827         }
18828
18829         cmd_reconfig_device_queue(port_id, 1, 1);
18830 }
18831
18832 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18833         .f = cmd_config_per_port_tx_offload_parsed,
18834         .data = NULL,
18835         .help_str = "port config <port_id> tx_offload "
18836                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18837                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18838                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18839                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18840                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18841                     "send_on_timestamp on|off",
18842         .tokens = {
18843                 (void *)&cmd_config_per_port_tx_offload_result_port,
18844                 (void *)&cmd_config_per_port_tx_offload_result_config,
18845                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18846                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18847                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18848                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18849                 NULL,
18850         }
18851 };
18852
18853 /* Enable/Disable a per queue offloading */
18854 struct cmd_config_per_queue_tx_offload_result {
18855         cmdline_fixed_string_t port;
18856         portid_t port_id;
18857         cmdline_fixed_string_t txq;
18858         uint16_t queue_id;
18859         cmdline_fixed_string_t tx_offload;
18860         cmdline_fixed_string_t offload;
18861         cmdline_fixed_string_t on_off;
18862 };
18863
18864 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18865         TOKEN_STRING_INITIALIZER
18866                 (struct cmd_config_per_queue_tx_offload_result,
18867                  port, "port");
18868 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18869         TOKEN_NUM_INITIALIZER
18870                 (struct cmd_config_per_queue_tx_offload_result,
18871                  port_id, UINT16);
18872 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18873         TOKEN_STRING_INITIALIZER
18874                 (struct cmd_config_per_queue_tx_offload_result,
18875                  txq, "txq");
18876 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18877         TOKEN_NUM_INITIALIZER
18878                 (struct cmd_config_per_queue_tx_offload_result,
18879                  queue_id, UINT16);
18880 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18881         TOKEN_STRING_INITIALIZER
18882                 (struct cmd_config_per_queue_tx_offload_result,
18883                  tx_offload, "tx_offload");
18884 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18885         TOKEN_STRING_INITIALIZER
18886                 (struct cmd_config_per_queue_tx_offload_result,
18887                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18888                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18889                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18890                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18891                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18892 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18893         TOKEN_STRING_INITIALIZER
18894                 (struct cmd_config_per_queue_tx_offload_result,
18895                  on_off, "on#off");
18896
18897 static void
18898 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18899                                 __rte_unused struct cmdline *cl,
18900                                 __rte_unused void *data)
18901 {
18902         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18903         struct rte_eth_dev_info dev_info;
18904         portid_t port_id = res->port_id;
18905         uint16_t queue_id = res->queue_id;
18906         struct rte_port *port = &ports[port_id];
18907         uint64_t single_offload;
18908         int ret;
18909
18910         if (port->port_status != RTE_PORT_STOPPED) {
18911                 printf("Error: Can't config offload when Port %d "
18912                        "is not stopped\n", port_id);
18913                 return;
18914         }
18915
18916         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18917         if (ret != 0)
18918                 return;
18919
18920         if (queue_id >= dev_info.nb_tx_queues) {
18921                 printf("Error: input queue_id should be 0 ... "
18922                        "%d\n", dev_info.nb_tx_queues - 1);
18923                 return;
18924         }
18925
18926         single_offload = search_tx_offload(res->offload);
18927         if (single_offload == 0) {
18928                 printf("Unknown offload name: %s\n", res->offload);
18929                 return;
18930         }
18931
18932         if (!strcmp(res->on_off, "on"))
18933                 port->tx_conf[queue_id].offloads |= single_offload;
18934         else
18935                 port->tx_conf[queue_id].offloads &= ~single_offload;
18936
18937         cmd_reconfig_device_queue(port_id, 1, 1);
18938 }
18939
18940 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
18941         .f = cmd_config_per_queue_tx_offload_parsed,
18942         .data = NULL,
18943         .help_str = "port <port_id> txq <queue_id> tx_offload "
18944                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18945                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18946                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18947                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18948                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
18949                     "on|off",
18950         .tokens = {
18951                 (void *)&cmd_config_per_queue_tx_offload_result_port,
18952                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
18953                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
18954                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
18955                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
18956                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
18957                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
18958                 NULL,
18959         }
18960 };
18961
18962 /* *** configure tx_metadata for specific port *** */
18963 struct cmd_config_tx_metadata_specific_result {
18964         cmdline_fixed_string_t port;
18965         cmdline_fixed_string_t keyword;
18966         uint16_t port_id;
18967         cmdline_fixed_string_t item;
18968         uint32_t value;
18969 };
18970
18971 static void
18972 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
18973                                 __rte_unused struct cmdline *cl,
18974                                 __rte_unused void *data)
18975 {
18976         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
18977
18978         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18979                 return;
18980         ports[res->port_id].tx_metadata = res->value;
18981         /* Add/remove callback to insert valid metadata in every Tx packet. */
18982         if (ports[res->port_id].tx_metadata)
18983                 add_tx_md_callback(res->port_id);
18984         else
18985                 remove_tx_md_callback(res->port_id);
18986         rte_flow_dynf_metadata_register();
18987 }
18988
18989 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
18990         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18991                         port, "port");
18992 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
18993         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18994                         keyword, "config");
18995 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
18996         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
18997                         port_id, UINT16);
18998 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
18999         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19000                         item, "tx_metadata");
19001 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19002         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19003                         value, UINT32);
19004
19005 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19006         .f = cmd_config_tx_metadata_specific_parsed,
19007         .data = NULL,
19008         .help_str = "port config <port_id> tx_metadata <value>",
19009         .tokens = {
19010                 (void *)&cmd_config_tx_metadata_specific_port,
19011                 (void *)&cmd_config_tx_metadata_specific_keyword,
19012                 (void *)&cmd_config_tx_metadata_specific_id,
19013                 (void *)&cmd_config_tx_metadata_specific_item,
19014                 (void *)&cmd_config_tx_metadata_specific_value,
19015                 NULL,
19016         },
19017 };
19018
19019 /* *** set dynf *** */
19020 struct cmd_config_tx_dynf_specific_result {
19021         cmdline_fixed_string_t port;
19022         cmdline_fixed_string_t keyword;
19023         uint16_t port_id;
19024         cmdline_fixed_string_t item;
19025         cmdline_fixed_string_t name;
19026         cmdline_fixed_string_t value;
19027 };
19028
19029 static void
19030 cmd_config_dynf_specific_parsed(void *parsed_result,
19031                                 __rte_unused struct cmdline *cl,
19032                                 __rte_unused void *data)
19033 {
19034         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19035         struct rte_mbuf_dynflag desc_flag;
19036         int flag;
19037         uint64_t old_port_flags;
19038
19039         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19040                 return;
19041         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19042         if (flag <= 0) {
19043                 if (strlcpy(desc_flag.name, res->name,
19044                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19045                         printf("Flag name too long\n");
19046                         return;
19047                 }
19048                 desc_flag.flags = 0;
19049                 flag = rte_mbuf_dynflag_register(&desc_flag);
19050                 if (flag < 0) {
19051                         printf("Can't register flag\n");
19052                         return;
19053                 }
19054                 strcpy(dynf_names[flag], desc_flag.name);
19055         }
19056         old_port_flags = ports[res->port_id].mbuf_dynf;
19057         if (!strcmp(res->value, "set")) {
19058                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19059                 if (old_port_flags == 0)
19060                         add_tx_dynf_callback(res->port_id);
19061         } else {
19062                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19063                 if (ports[res->port_id].mbuf_dynf == 0)
19064                         remove_tx_dynf_callback(res->port_id);
19065         }
19066 }
19067
19068 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19069         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19070                         keyword, "port");
19071 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19072         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19073                         keyword, "config");
19074 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19075         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19076                         port_id, UINT16);
19077 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19078         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19079                         item, "dynf");
19080 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19081         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19082                         name, NULL);
19083 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19084         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19085                         value, "set#clear");
19086
19087 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19088         .f = cmd_config_dynf_specific_parsed,
19089         .data = NULL,
19090         .help_str = "port config <port id> dynf <name> set|clear",
19091         .tokens = {
19092                 (void *)&cmd_config_tx_dynf_specific_port,
19093                 (void *)&cmd_config_tx_dynf_specific_keyword,
19094                 (void *)&cmd_config_tx_dynf_specific_port_id,
19095                 (void *)&cmd_config_tx_dynf_specific_item,
19096                 (void *)&cmd_config_tx_dynf_specific_name,
19097                 (void *)&cmd_config_tx_dynf_specific_value,
19098                 NULL,
19099         },
19100 };
19101
19102 /* *** display tx_metadata per port configuration *** */
19103 struct cmd_show_tx_metadata_result {
19104         cmdline_fixed_string_t cmd_show;
19105         cmdline_fixed_string_t cmd_port;
19106         cmdline_fixed_string_t cmd_keyword;
19107         portid_t cmd_pid;
19108 };
19109
19110 static void
19111 cmd_show_tx_metadata_parsed(void *parsed_result,
19112                 __rte_unused struct cmdline *cl,
19113                 __rte_unused void *data)
19114 {
19115         struct cmd_show_tx_metadata_result *res = parsed_result;
19116
19117         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19118                 printf("invalid port id %u\n", res->cmd_pid);
19119                 return;
19120         }
19121         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19122                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19123                        ports[res->cmd_pid].tx_metadata);
19124         }
19125 }
19126
19127 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19128         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19129                         cmd_show, "show");
19130 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19131         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19132                         cmd_port, "port");
19133 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19134         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19135                         cmd_pid, UINT16);
19136 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19137         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19138                         cmd_keyword, "tx_metadata");
19139
19140 cmdline_parse_inst_t cmd_show_tx_metadata = {
19141         .f = cmd_show_tx_metadata_parsed,
19142         .data = NULL,
19143         .help_str = "show port <port_id> tx_metadata",
19144         .tokens = {
19145                 (void *)&cmd_show_tx_metadata_show,
19146                 (void *)&cmd_show_tx_metadata_port,
19147                 (void *)&cmd_show_tx_metadata_pid,
19148                 (void *)&cmd_show_tx_metadata_keyword,
19149                 NULL,
19150         },
19151 };
19152
19153 /* show port supported ptypes */
19154
19155 /* Common result structure for show port ptypes */
19156 struct cmd_show_port_supported_ptypes_result {
19157         cmdline_fixed_string_t show;
19158         cmdline_fixed_string_t port;
19159         portid_t port_id;
19160         cmdline_fixed_string_t ptypes;
19161 };
19162
19163 /* Common CLI fields for show port ptypes */
19164 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19165         TOKEN_STRING_INITIALIZER
19166                 (struct cmd_show_port_supported_ptypes_result,
19167                  show, "show");
19168 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19169         TOKEN_STRING_INITIALIZER
19170                 (struct cmd_show_port_supported_ptypes_result,
19171                  port, "port");
19172 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19173         TOKEN_NUM_INITIALIZER
19174                 (struct cmd_show_port_supported_ptypes_result,
19175                  port_id, UINT16);
19176 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19177         TOKEN_STRING_INITIALIZER
19178                 (struct cmd_show_port_supported_ptypes_result,
19179                  ptypes, "ptypes");
19180
19181 static void
19182 cmd_show_port_supported_ptypes_parsed(
19183         void *parsed_result,
19184         __rte_unused struct cmdline *cl,
19185         __rte_unused void *data)
19186 {
19187 #define RSVD_PTYPE_MASK       0xf0000000
19188 #define MAX_PTYPES_PER_LAYER  16
19189 #define LTYPE_NAMESIZE        32
19190 #define PTYPE_NAMESIZE        256
19191         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19192         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19193         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19194         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19195         uint16_t port_id = res->port_id;
19196         int ret, i;
19197
19198         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19199         if (ret < 0)
19200                 return;
19201
19202         while (ptype_mask != RSVD_PTYPE_MASK) {
19203
19204                 switch (ptype_mask) {
19205                 case RTE_PTYPE_L2_MASK:
19206                         strlcpy(ltype, "L2", sizeof(ltype));
19207                         break;
19208                 case RTE_PTYPE_L3_MASK:
19209                         strlcpy(ltype, "L3", sizeof(ltype));
19210                         break;
19211                 case RTE_PTYPE_L4_MASK:
19212                         strlcpy(ltype, "L4", sizeof(ltype));
19213                         break;
19214                 case RTE_PTYPE_TUNNEL_MASK:
19215                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19216                         break;
19217                 case RTE_PTYPE_INNER_L2_MASK:
19218                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19219                         break;
19220                 case RTE_PTYPE_INNER_L3_MASK:
19221                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19222                         break;
19223                 case RTE_PTYPE_INNER_L4_MASK:
19224                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19225                         break;
19226                 default:
19227                         return;
19228                 }
19229
19230                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19231                                                        ptype_mask, ptypes,
19232                                                        MAX_PTYPES_PER_LAYER);
19233
19234                 if (ret > 0)
19235                         printf("Supported %s ptypes:\n", ltype);
19236                 else
19237                         printf("%s ptypes unsupported\n", ltype);
19238
19239                 for (i = 0; i < ret; ++i) {
19240                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19241                         printf("%s\n", buf);
19242                 }
19243
19244                 ptype_mask <<= 4;
19245         }
19246 }
19247
19248 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19249         .f = cmd_show_port_supported_ptypes_parsed,
19250         .data = NULL,
19251         .help_str = "show port <port_id> ptypes",
19252         .tokens = {
19253                 (void *)&cmd_show_port_supported_ptypes_show,
19254                 (void *)&cmd_show_port_supported_ptypes_port,
19255                 (void *)&cmd_show_port_supported_ptypes_port_id,
19256                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19257                 NULL,
19258         },
19259 };
19260
19261 /* *** display rx/tx descriptor status *** */
19262 struct cmd_show_rx_tx_desc_status_result {
19263         cmdline_fixed_string_t cmd_show;
19264         cmdline_fixed_string_t cmd_port;
19265         cmdline_fixed_string_t cmd_keyword;
19266         cmdline_fixed_string_t cmd_desc;
19267         cmdline_fixed_string_t cmd_status;
19268         portid_t cmd_pid;
19269         portid_t cmd_qid;
19270         portid_t cmd_did;
19271 };
19272
19273 static void
19274 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19275                 __rte_unused struct cmdline *cl,
19276                 __rte_unused void *data)
19277 {
19278         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19279         int rc;
19280
19281         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19282                 printf("invalid port id %u\n", res->cmd_pid);
19283                 return;
19284         }
19285
19286         if (!strcmp(res->cmd_keyword, "rxq")) {
19287                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19288                                              res->cmd_did);
19289                 if (rc < 0) {
19290                         printf("Invalid queueid = %d\n", res->cmd_qid);
19291                         return;
19292                 }
19293                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19294                         printf("Desc status = AVAILABLE\n");
19295                 else if (rc == RTE_ETH_RX_DESC_DONE)
19296                         printf("Desc status = DONE\n");
19297                 else
19298                         printf("Desc status = UNAVAILABLE\n");
19299         } else if (!strcmp(res->cmd_keyword, "txq")) {
19300                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19301                                              res->cmd_did);
19302                 if (rc < 0) {
19303                         printf("Invalid queueid = %d\n", res->cmd_qid);
19304                         return;
19305                 }
19306                 if (rc == RTE_ETH_TX_DESC_FULL)
19307                         printf("Desc status = FULL\n");
19308                 else if (rc == RTE_ETH_TX_DESC_DONE)
19309                         printf("Desc status = DONE\n");
19310                 else
19311                         printf("Desc status = UNAVAILABLE\n");
19312         }
19313 }
19314
19315 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19316         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19317                         cmd_show, "show");
19318 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19319         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19320                         cmd_port, "port");
19321 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19322         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19323                         cmd_pid, UINT16);
19324 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19325         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19326                         cmd_keyword, "rxq#txq");
19327 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19328         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19329                         cmd_qid, UINT16);
19330 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19331         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19332                         cmd_desc, "desc");
19333 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19334         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19335                         cmd_did, UINT16);
19336 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19337         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19338                         cmd_status, "status");
19339 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19340         .f = cmd_show_rx_tx_desc_status_parsed,
19341         .data = NULL,
19342         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19343                 "status",
19344         .tokens = {
19345                 (void *)&cmd_show_rx_tx_desc_status_show,
19346                 (void *)&cmd_show_rx_tx_desc_status_port,
19347                 (void *)&cmd_show_rx_tx_desc_status_pid,
19348                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19349                 (void *)&cmd_show_rx_tx_desc_status_qid,
19350                 (void *)&cmd_show_rx_tx_desc_status_desc,
19351                 (void *)&cmd_show_rx_tx_desc_status_did,
19352                 (void *)&cmd_show_rx_tx_desc_status_status,
19353                 NULL,
19354         },
19355 };
19356
19357 /* Common result structure for set port ptypes */
19358 struct cmd_set_port_ptypes_result {
19359         cmdline_fixed_string_t set;
19360         cmdline_fixed_string_t port;
19361         portid_t port_id;
19362         cmdline_fixed_string_t ptype_mask;
19363         uint32_t mask;
19364 };
19365
19366 /* Common CLI fields for set port ptypes */
19367 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19368         TOKEN_STRING_INITIALIZER
19369                 (struct cmd_set_port_ptypes_result,
19370                  set, "set");
19371 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19372         TOKEN_STRING_INITIALIZER
19373                 (struct cmd_set_port_ptypes_result,
19374                  port, "port");
19375 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19376         TOKEN_NUM_INITIALIZER
19377                 (struct cmd_set_port_ptypes_result,
19378                  port_id, UINT16);
19379 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19380         TOKEN_STRING_INITIALIZER
19381                 (struct cmd_set_port_ptypes_result,
19382                  ptype_mask, "ptype_mask");
19383 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19384         TOKEN_NUM_INITIALIZER
19385                 (struct cmd_set_port_ptypes_result,
19386                  mask, UINT32);
19387
19388 static void
19389 cmd_set_port_ptypes_parsed(
19390         void *parsed_result,
19391         __rte_unused struct cmdline *cl,
19392         __rte_unused void *data)
19393 {
19394         struct cmd_set_port_ptypes_result *res = parsed_result;
19395 #define PTYPE_NAMESIZE        256
19396         char ptype_name[PTYPE_NAMESIZE];
19397         uint16_t port_id = res->port_id;
19398         uint32_t ptype_mask = res->mask;
19399         int ret, i;
19400
19401         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19402                                                NULL, 0);
19403         if (ret <= 0) {
19404                 printf("Port %d doesn't support any ptypes.\n", port_id);
19405                 return;
19406         }
19407
19408         uint32_t ptypes[ret];
19409
19410         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19411         if (ret < 0) {
19412                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19413                 return;
19414         }
19415
19416         printf("Successfully set following ptypes for Port %d\n", port_id);
19417         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19418                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19419                 printf("%s\n", ptype_name);
19420         }
19421
19422         clear_ptypes = false;
19423 }
19424
19425 cmdline_parse_inst_t cmd_set_port_ptypes = {
19426         .f = cmd_set_port_ptypes_parsed,
19427         .data = NULL,
19428         .help_str = "set port <port_id> ptype_mask <mask>",
19429         .tokens = {
19430                 (void *)&cmd_set_port_ptypes_set,
19431                 (void *)&cmd_set_port_ptypes_port,
19432                 (void *)&cmd_set_port_ptypes_port_id,
19433                 (void *)&cmd_set_port_ptypes_mask_str,
19434                 (void *)&cmd_set_port_ptypes_mask_u32,
19435                 NULL,
19436         },
19437 };
19438
19439 /* *** display mac addresses added to a port *** */
19440 struct cmd_showport_macs_result {
19441         cmdline_fixed_string_t cmd_show;
19442         cmdline_fixed_string_t cmd_port;
19443         cmdline_fixed_string_t cmd_keyword;
19444         portid_t cmd_pid;
19445 };
19446
19447 static void
19448 cmd_showport_macs_parsed(void *parsed_result,
19449                 __rte_unused struct cmdline *cl,
19450                 __rte_unused void *data)
19451 {
19452         struct cmd_showport_macs_result *res = parsed_result;
19453
19454         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19455                 return;
19456
19457         if (!strcmp(res->cmd_keyword, "macs"))
19458                 show_macs(res->cmd_pid);
19459         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19460                 show_mcast_macs(res->cmd_pid);
19461 }
19462
19463 cmdline_parse_token_string_t cmd_showport_macs_show =
19464         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19465                         cmd_show, "show");
19466 cmdline_parse_token_string_t cmd_showport_macs_port =
19467         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19468                         cmd_port, "port");
19469 cmdline_parse_token_num_t cmd_showport_macs_pid =
19470         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19471                         cmd_pid, UINT16);
19472 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19473         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19474                         cmd_keyword, "macs#mcast_macs");
19475
19476 cmdline_parse_inst_t cmd_showport_macs = {
19477         .f = cmd_showport_macs_parsed,
19478         .data = NULL,
19479         .help_str = "show port <port_id> macs|mcast_macs",
19480         .tokens = {
19481                 (void *)&cmd_showport_macs_show,
19482                 (void *)&cmd_showport_macs_port,
19483                 (void *)&cmd_showport_macs_pid,
19484                 (void *)&cmd_showport_macs_keyword,
19485                 NULL,
19486         },
19487 };
19488
19489 /* ******************************************************************************** */
19490
19491 /* list of instructions */
19492 cmdline_parse_ctx_t main_ctx[] = {
19493         (cmdline_parse_inst_t *)&cmd_help_brief,
19494         (cmdline_parse_inst_t *)&cmd_help_long,
19495         (cmdline_parse_inst_t *)&cmd_quit,
19496         (cmdline_parse_inst_t *)&cmd_load_from_file,
19497         (cmdline_parse_inst_t *)&cmd_showport,
19498         (cmdline_parse_inst_t *)&cmd_showqueue,
19499         (cmdline_parse_inst_t *)&cmd_showportall,
19500         (cmdline_parse_inst_t *)&cmd_showdevice,
19501         (cmdline_parse_inst_t *)&cmd_showcfg,
19502         (cmdline_parse_inst_t *)&cmd_showfwdall,
19503         (cmdline_parse_inst_t *)&cmd_start,
19504         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19505         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19506         (cmdline_parse_inst_t *)&cmd_set_link_up,
19507         (cmdline_parse_inst_t *)&cmd_set_link_down,
19508         (cmdline_parse_inst_t *)&cmd_reset,
19509         (cmdline_parse_inst_t *)&cmd_set_numbers,
19510         (cmdline_parse_inst_t *)&cmd_set_log,
19511         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19512         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19513         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19514         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19515         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19516         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19517         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19518         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19519         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19520         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19521         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19522         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19523         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19524         (cmdline_parse_inst_t *)&cmd_set_link_check,
19525         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19526         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19527         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19528         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19529 #ifdef RTE_LIBRTE_PMD_BOND
19530         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19531         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19532         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19533         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19534         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19535         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19536         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19537         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19538         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19539         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19540         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19541 #endif
19542         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19543         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19544         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19545         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19546         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19547         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19548         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19549         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19550         (cmdline_parse_inst_t *)&cmd_csum_set,
19551         (cmdline_parse_inst_t *)&cmd_csum_show,
19552         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19553         (cmdline_parse_inst_t *)&cmd_tso_set,
19554         (cmdline_parse_inst_t *)&cmd_tso_show,
19555         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19556         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19557         (cmdline_parse_inst_t *)&cmd_gro_enable,
19558         (cmdline_parse_inst_t *)&cmd_gro_flush,
19559         (cmdline_parse_inst_t *)&cmd_gro_show,
19560         (cmdline_parse_inst_t *)&cmd_gso_enable,
19561         (cmdline_parse_inst_t *)&cmd_gso_size,
19562         (cmdline_parse_inst_t *)&cmd_gso_show,
19563         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19564         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19565         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19566         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19567         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19568         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19569         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19570         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19571         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19572         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19573         (cmdline_parse_inst_t *)&cmd_config_dcb,
19574         (cmdline_parse_inst_t *)&cmd_read_reg,
19575         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19576         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19577         (cmdline_parse_inst_t *)&cmd_write_reg,
19578         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19579         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19580         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19581         (cmdline_parse_inst_t *)&cmd_stop,
19582         (cmdline_parse_inst_t *)&cmd_mac_addr,
19583         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19584         (cmdline_parse_inst_t *)&cmd_set_qmap,
19585         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19586         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19587         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19588         (cmdline_parse_inst_t *)&cmd_operate_port,
19589         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19590         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19591         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19592         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19593         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19594         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19595         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19596         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19597         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19598         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19599         (cmdline_parse_inst_t *)&cmd_config_mtu,
19600         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19601         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19602         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19603         (cmdline_parse_inst_t *)&cmd_config_rss,
19604         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19605         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19606         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19607         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19608         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19609         (cmdline_parse_inst_t *)&cmd_showport_reta,
19610         (cmdline_parse_inst_t *)&cmd_showport_macs,
19611         (cmdline_parse_inst_t *)&cmd_config_burst,
19612         (cmdline_parse_inst_t *)&cmd_config_thresh,
19613         (cmdline_parse_inst_t *)&cmd_config_threshold,
19614         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19615         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19616         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19617         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19618         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19619         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19620         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19621         (cmdline_parse_inst_t *)&cmd_global_config,
19622         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19623         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19624         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19625         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19626         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19627         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19628         (cmdline_parse_inst_t *)&cmd_dump,
19629         (cmdline_parse_inst_t *)&cmd_dump_one,
19630         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19631         (cmdline_parse_inst_t *)&cmd_syn_filter,
19632         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19633         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19634         (cmdline_parse_inst_t *)&cmd_flex_filter,
19635         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19636         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19637         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19638         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19639         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19640         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19641         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19642         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19643         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19644         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19645         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19646         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19647         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19648         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19649         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19650         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19651         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19652         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19653         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19654         (cmdline_parse_inst_t *)&cmd_flow,
19655         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19656         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19657         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19658         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19659         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19660         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19661         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19662         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19663         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19664         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19665         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19666         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19667         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19668         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19669         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19670         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19671         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19672         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19673         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19674         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19675         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19676         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19677         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19678         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19679         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19680         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19681         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19682         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19683         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
19684         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
19685         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
19686         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
19687         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
19688         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
19689         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
19690         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
19691         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
19692         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
19693         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
19694         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
19695         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
19696         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
19697         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
19698         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
19699         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
19700         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
19701         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
19702         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
19703         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
19704         (cmdline_parse_inst_t *)&cmd_set_vxlan,
19705         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
19706         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
19707         (cmdline_parse_inst_t *)&cmd_set_nvgre,
19708         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
19709         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
19710         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
19711         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
19712         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
19713         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
19714         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
19715         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
19716         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
19717         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
19718         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
19719         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
19720         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
19721         (cmdline_parse_inst_t *)&cmd_ddp_add,
19722         (cmdline_parse_inst_t *)&cmd_ddp_del,
19723         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
19724         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
19725         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
19726         (cmdline_parse_inst_t *)&cmd_clear_input_set,
19727         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
19728         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
19729         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
19730         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
19731         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
19732         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
19733         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
19734         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
19735
19736         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
19737         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
19738         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
19739         (cmdline_parse_inst_t *)&cmd_queue_region,
19740         (cmdline_parse_inst_t *)&cmd_region_flowtype,
19741         (cmdline_parse_inst_t *)&cmd_user_priority_region,
19742         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
19743         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
19744         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
19745         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
19746         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
19747         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
19748         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
19749         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
19750         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
19751         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
19752         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
19753         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
19754         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
19755         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
19756         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
19757         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
19758         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
19759         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
19760         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
19761         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
19762         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
19763         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
19764         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
19765         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
19766         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
19767         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
19768         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
19769         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
19770         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
19771         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
19772         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
19773         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
19774         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
19775         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
19776 #ifdef RTE_LIBRTE_BPF
19777         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
19778         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
19779 #endif
19780         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
19781         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
19782         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
19783         (cmdline_parse_inst_t *)&cmd_set_raw,
19784         (cmdline_parse_inst_t *)&cmd_show_set_raw,
19785         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
19786         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
19787         NULL,
19788 };
19789
19790 /* read cmdline commands from file */
19791 void
19792 cmdline_read_from_file(const char *filename)
19793 {
19794         struct cmdline *cl;
19795
19796         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
19797         if (cl == NULL) {
19798                 printf("Failed to create file based cmdline context: %s\n",
19799                        filename);
19800                 return;
19801         }
19802
19803         cmdline_interact(cl);
19804         cmdline_quit(cl);
19805
19806         cmdline_free(cl);
19807
19808         printf("Read CLI commands from %s\n", filename);
19809 }
19810
19811 /* prompt function, called from main on MASTER lcore */
19812 void
19813 prompt(void)
19814 {
19815         /* initialize non-constant commands */
19816         cmd_set_fwd_mode_init();
19817         cmd_set_fwd_retry_mode_init();
19818
19819         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
19820         if (testpmd_cl == NULL)
19821                 return;
19822         cmdline_interact(testpmd_cl);
19823         cmdline_stdin_exit(testpmd_cl);
19824 }
19825
19826 void
19827 prompt_exit(void)
19828 {
19829         if (testpmd_cl != NULL)
19830                 cmdline_quit(testpmd_cl);
19831 }
19832
19833 static void
19834 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
19835 {
19836         if (id == (portid_t)RTE_PORT_ALL) {
19837                 portid_t pid;
19838
19839                 RTE_ETH_FOREACH_DEV(pid) {
19840                         /* check if need_reconfig has been set to 1 */
19841                         if (ports[pid].need_reconfig == 0)
19842                                 ports[pid].need_reconfig = dev;
19843                         /* check if need_reconfig_queues has been set to 1 */
19844                         if (ports[pid].need_reconfig_queues == 0)
19845                                 ports[pid].need_reconfig_queues = queue;
19846                 }
19847         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
19848                 /* check if need_reconfig has been set to 1 */
19849                 if (ports[id].need_reconfig == 0)
19850                         ports[id].need_reconfig = dev;
19851                 /* check if need_reconfig_queues has been set to 1 */
19852                 if (ports[id].need_reconfig_queues == 0)
19853                         ports[id].need_reconfig_queues = queue;
19854         }
19855 }