app/testpmd: add multiple pools per core creation
[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 port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set txpkts (x[,y]*)\n"
298                         "    Set the length of each segment of TXONLY"
299                         " and optionally CSUM packets.\n\n"
300
301                         "set txsplit (off|on|rand)\n"
302                         "    Set the split policy for the TX packets."
303                         " Right now only applicable for CSUM and TXONLY"
304                         " modes\n\n"
305
306                         "set txtimes (x, y)\n"
307                         "    Set the scheduling on timestamps"
308                         " timings for the TXONLY mode\n\n"
309
310                         "set corelist (x[,y]*)\n"
311                         "    Set the list of forwarding cores.\n\n"
312
313                         "set portlist (x[,y]*)\n"
314                         "    Set the list of forwarding ports.\n\n"
315
316                         "set port setup on (iterator|event)\n"
317                         "    Select how attached port is retrieved for setup.\n\n"
318
319                         "set tx loopback (port_id) (on|off)\n"
320                         "    Enable or disable tx loopback.\n\n"
321
322                         "set all queues drop (port_id) (on|off)\n"
323                         "    Set drop enable bit for all queues.\n\n"
324
325                         "set vf split drop (port_id) (vf_id) (on|off)\n"
326                         "    Set split drop enable bit for a VF from the PF.\n\n"
327
328                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
329                         "    Set MAC antispoof for a VF from the PF.\n\n"
330
331                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
332                         "    Enable MACsec offload.\n\n"
333
334                         "set macsec offload (port_id) off\n"
335                         "    Disable MACsec offload.\n\n"
336
337                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
338                         "    Configure MACsec secure connection (SC).\n\n"
339
340                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
341                         "    Configure MACsec secure association (SA).\n\n"
342
343                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
344                         "    Set VF broadcast for a VF from the PF.\n\n"
345
346                         "vlan set stripq (on|off) (port_id,queue_id)\n"
347                         "    Set the VLAN strip for a queue on a port.\n\n"
348
349                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
350                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
351
352                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
353                         "    Set VLAN insert for a VF from the PF.\n\n"
354
355                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
356                         "    Set VLAN antispoof for a VF from the PF.\n\n"
357
358                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
359                         "    Set VLAN tag for a VF from the PF.\n\n"
360
361                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
362                         "    Set a VF's max bandwidth(Mbps).\n\n"
363
364                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
365                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
366
367                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
368                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
369
370                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
371                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
372
373                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
374                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
375
376                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
377                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
378
379                         "vlan set (inner|outer) tpid (value) (port_id)\n"
380                         "    Set the VLAN TPID for Packet Filtering on"
381                         " a port\n\n"
382
383                         "rx_vlan add (vlan_id|all) (port_id)\n"
384                         "    Add a vlan_id, or all identifiers, to the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan rm (vlan_id|all) (port_id)\n"
388                         "    Remove a vlan_id, or all identifiers, from the set"
389                         " of VLAN identifiers filtered by port_id.\n\n"
390
391                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Add a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
396                         "    Remove a vlan_id, to the set of VLAN identifiers"
397                         "filtered for VF(s) from port_id.\n\n"
398
399                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
400                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
401                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
402                         "   add a tunnel filter of a port.\n\n"
403
404                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
405                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
406                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
407                         "   remove a tunnel filter of a port.\n\n"
408
409                         "rx_vxlan_port add (udp_port) (port_id)\n"
410                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
411
412                         "rx_vxlan_port rm (udp_port) (port_id)\n"
413                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
414
415                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
416                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
417                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
418
419                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
420                         "    Set port based TX VLAN insertion.\n\n"
421
422                         "tx_vlan reset (port_id)\n"
423                         "    Disable hardware insertion of a VLAN header in"
424                         " packets sent on a port.\n\n"
425
426                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
427                         "    Select hardware or software calculation of the"
428                         " checksum when transmitting a packet using the"
429                         " csum forward engine.\n"
430                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
431                         "    outer-ip concerns the outer IP layer in"
432                         "    outer-udp concerns the outer UDP layer in"
433                         " case the packet is recognized as a tunnel packet by"
434                         " the forward engine (vxlan, gre and ipip are supported)\n"
435                         "    Please check the NIC datasheet for HW limits.\n\n"
436
437                         "csum parse-tunnel (on|off) (tx_port_id)\n"
438                         "    If disabled, treat tunnel packets as non-tunneled"
439                         " packets (treat inner headers as payload). The port\n"
440                         "    argument is the port used for TX in csum forward"
441                         " engine.\n\n"
442
443                         "csum show (port_id)\n"
444                         "    Display tx checksum offload configuration\n\n"
445
446                         "tso set (segsize) (portid)\n"
447                         "    Enable TCP Segmentation Offload in csum forward"
448                         " engine.\n"
449                         "    Please check the NIC datasheet for HW limits.\n\n"
450
451                         "tso show (portid)"
452                         "    Display the status of TCP Segmentation Offload.\n\n"
453
454                         "set port (port_id) gro on|off\n"
455                         "    Enable or disable Generic Receive Offload in"
456                         " csum forwarding engine.\n\n"
457
458                         "show port (port_id) gro\n"
459                         "    Display GRO configuration.\n\n"
460
461                         "set gro flush (cycles)\n"
462                         "    Set the cycle to flush GROed packets from"
463                         " reassembly tables.\n\n"
464
465                         "set port (port_id) gso (on|off)"
466                         "    Enable or disable Generic Segmentation Offload in"
467                         " csum forwarding engine.\n\n"
468
469                         "set gso segsz (length)\n"
470                         "    Set max packet length for output GSO segments,"
471                         " including packet header and payload.\n\n"
472
473                         "show port (port_id) gso\n"
474                         "    Show GSO configuration.\n\n"
475
476                         "set fwd (%s)\n"
477                         "    Set packet forwarding mode.\n\n"
478
479                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
480                         "    Add a MAC address on port_id.\n\n"
481
482                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
483                         "    Remove a MAC address from port_id.\n\n"
484
485                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
486                         "    Set the default MAC address for port_id.\n\n"
487
488                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
489                         "    Add a MAC address for a VF on the port.\n\n"
490
491                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Set the MAC address for a VF from the PF.\n\n"
493
494                         "set eth-peer (port_id) (peer_addr)\n"
495                         "    set the peer address for certain port.\n\n"
496
497                         "set port (port_id) uta (mac_address|all) (on|off)\n"
498                         "    Add/Remove a or all unicast hash filter(s)"
499                         "from port X.\n\n"
500
501                         "set promisc (port_id|all) (on|off)\n"
502                         "    Set the promiscuous mode on port_id, or all.\n\n"
503
504                         "set allmulti (port_id|all) (on|off)\n"
505                         "    Set the allmulti mode on port_id, or all.\n\n"
506
507                         "set vf promisc (port_id) (vf_id) (on|off)\n"
508                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
509
510                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
511                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
512
513                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
514                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
515                         " (on|off) autoneg (on|off) (port_id)\n"
516                         "set flow_ctrl rx (on|off) (portid)\n"
517                         "set flow_ctrl tx (on|off) (portid)\n"
518                         "set flow_ctrl high_water (high_water) (portid)\n"
519                         "set flow_ctrl low_water (low_water) (portid)\n"
520                         "set flow_ctrl pause_time (pause_time) (portid)\n"
521                         "set flow_ctrl send_xon (send_xon) (portid)\n"
522                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
523                         "set flow_ctrl autoneg (on|off) (port_id)\n"
524                         "    Set the link flow control parameter on a port.\n\n"
525
526                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
527                         " (low_water) (pause_time) (priority) (port_id)\n"
528                         "    Set the priority flow control parameter on a"
529                         " port.\n\n"
530
531                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
532                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
533                         " queue on port.\n"
534                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
535                         " on port 0 to mapping 5.\n\n"
536
537                         "set xstats-hide-zero on|off\n"
538                         "    Set the option to hide the zero values"
539                         " for xstats display.\n"
540
541                         "set record-core-cycles on|off\n"
542                         "    Set the option to enable measurement of CPU cycles.\n"
543
544                         "set record-burst-stats on|off\n"
545                         "    Set the option to enable display of RX and TX bursts.\n"
546
547                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
548                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
549
550                         "set port (port_id) vf (vf_id) (mac_addr)"
551                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
552                         "   Add/Remove unicast or multicast MAC addr filter"
553                         " for a VF.\n\n"
554
555                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
556                         "|MPE) (on|off)\n"
557                         "    AUPE:accepts untagged VLAN;"
558                         "ROPE:accept unicast hash\n\n"
559                         "    BAM:accepts broadcast packets;"
560                         "MPE:accepts all multicast packets\n\n"
561                         "    Enable/Disable a VF receive mode of a port\n\n"
562
563                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
564                         "    Set rate limit for a queue of a port\n\n"
565
566                         "set port (port_id) vf (vf_id) rate (rate_num) "
567                         "queue_mask (queue_mask_value)\n"
568                         "    Set rate limit for queues in VF of a port\n\n"
569
570                         "set port (port_id) mirror-rule (rule_id)"
571                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
572                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
573                         "   Set pool or vlan type mirror rule on a port.\n"
574                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
575                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
576                         " to pool 0.\n\n"
577
578                         "set port (port_id) mirror-rule (rule_id)"
579                         " (uplink-mirror|downlink-mirror) dst-pool"
580                         " (pool_id) (on|off)\n"
581                         "   Set uplink or downlink type mirror rule on a port.\n"
582                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
583                         " 0 on' enable mirror income traffic to pool 0.\n\n"
584
585                         "reset port (port_id) mirror-rule (rule_id)\n"
586                         "   Reset a mirror rule.\n\n"
587
588                         "set flush_rx (on|off)\n"
589                         "   Flush (default) or don't flush RX streams before"
590                         " forwarding. Mainly used with PCAP drivers.\n\n"
591
592                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
593                         "   Set the bypass mode for the lowest port on bypass enabled"
594                         " NIC.\n\n"
595
596                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
597                         "mode (normal|bypass|isolate) (port_id)\n"
598                         "   Set the event required to initiate specified bypass mode for"
599                         " the lowest port on a bypass enabled NIC where:\n"
600                         "       timeout   = enable bypass after watchdog timeout.\n"
601                         "       os_on     = enable bypass when OS/board is powered on.\n"
602                         "       os_off    = enable bypass when OS/board is powered off.\n"
603                         "       power_on  = enable bypass when power supply is turned on.\n"
604                         "       power_off = enable bypass when power supply is turned off."
605                         "\n\n"
606
607                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
608                         "   Set the bypass watchdog timeout to 'n' seconds"
609                         " where 0 = instant.\n\n"
610
611                         "show bypass config (port_id)\n"
612                         "   Show the bypass configuration for a bypass enabled NIC"
613                         " using the lowest port on the NIC.\n\n"
614
615 #ifdef RTE_LIBRTE_PMD_BOND
616                         "create bonded device (mode) (socket)\n"
617                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
618
619                         "add bonding slave (slave_id) (port_id)\n"
620                         "       Add a slave device to a bonded device.\n\n"
621
622                         "remove bonding slave (slave_id) (port_id)\n"
623                         "       Remove a slave device from a bonded device.\n\n"
624
625                         "set bonding mode (value) (port_id)\n"
626                         "       Set the bonding mode on a bonded device.\n\n"
627
628                         "set bonding primary (slave_id) (port_id)\n"
629                         "       Set the primary slave for a bonded device.\n\n"
630
631                         "show bonding config (port_id)\n"
632                         "       Show the bonding config for port_id.\n\n"
633
634                         "set bonding mac_addr (port_id) (address)\n"
635                         "       Set the MAC address of a bonded device.\n\n"
636
637                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
638                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
639
640                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
641                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
642
643                         "set bonding mon_period (port_id) (value)\n"
644                         "       Set the bonding link status monitoring polling period in ms.\n\n"
645
646                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
647                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
648
649 #endif
650                         "set link-up port (port_id)\n"
651                         "       Set link up for a port.\n\n"
652
653                         "set link-down port (port_id)\n"
654                         "       Set link down for a port.\n\n"
655
656                         "E-tag set insertion on port-tag-id (value)"
657                         " port (port_id) vf (vf_id)\n"
658                         "    Enable E-tag insertion for a VF on a port\n\n"
659
660                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
661                         "    Disable E-tag insertion for a VF on a port\n\n"
662
663                         "E-tag set stripping (on|off) port (port_id)\n"
664                         "    Enable/disable E-tag stripping on a port\n\n"
665
666                         "E-tag set forwarding (on|off) port (port_id)\n"
667                         "    Enable/disable E-tag based forwarding"
668                         " on a port\n\n"
669
670                         "E-tag set filter add e-tag-id (value) dst-pool"
671                         " (pool_id) port (port_id)\n"
672                         "    Add an E-tag forwarding filter on a port\n\n"
673
674                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
675                         "    Delete an E-tag forwarding filter on a port\n\n"
676
677                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
678                         "    Load a profile package on a port\n\n"
679
680                         "ddp del (port_id) (backup_profile_path)\n"
681                         "    Delete a profile package from a port\n\n"
682
683                         "ptype mapping get (port_id) (valid_only)\n"
684                         "    Get ptype mapping on a port\n\n"
685
686                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
687                         "    Replace target with the pkt_type in ptype mapping\n\n"
688
689                         "ptype mapping reset (port_id)\n"
690                         "    Reset ptype mapping on a port\n\n"
691
692                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
693                         "    Update a ptype mapping item on a port\n\n"
694
695                         "set port (port_id) ptype_mask (ptype_mask)\n"
696                         "    set packet types classification for a specific port\n\n"
697
698                         "set port (port_id) queue-region region_id (value) "
699                         "queue_start_index (value) queue_num (value)\n"
700                         "    Set a queue region on a port\n\n"
701
702                         "set port (port_id) queue-region region_id (value) "
703                         "flowtype (value)\n"
704                         "    Set a flowtype region index on a port\n\n"
705
706                         "set port (port_id) queue-region UP (value) region_id (value)\n"
707                         "    Set the mapping of User Priority to "
708                         "queue region on a port\n\n"
709
710                         "set port (port_id) queue-region flush (on|off)\n"
711                         "    flush all queue region related configuration\n\n"
712
713                         "show port meter cap (port_id)\n"
714                         "    Show port meter capability information\n\n"
715
716                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
717                         "    meter profile add - srtcm rfc 2697\n\n"
718
719                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
720                         "    meter profile add - trtcm rfc 2698\n\n"
721
722                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
723                         "    meter profile add - trtcm rfc 4115\n\n"
724
725                         "del port meter profile (port_id) (profile_id)\n"
726                         "    meter profile delete\n\n"
727
728                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
729                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
730                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
731                         "(dscp_tbl_entry63)]\n"
732                         "    meter create\n\n"
733
734                         "enable port meter (port_id) (mtr_id)\n"
735                         "    meter enable\n\n"
736
737                         "disable port meter (port_id) (mtr_id)\n"
738                         "    meter disable\n\n"
739
740                         "del port meter (port_id) (mtr_id)\n"
741                         "    meter delete\n\n"
742
743                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
744                         "    meter update meter profile\n\n"
745
746                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
747                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
748                         "    update meter dscp table entries\n\n"
749
750                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
751                         "(action0) [(action1) (action2)]\n"
752                         "    meter update policer action\n\n"
753
754                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
755                         "    meter update stats\n\n"
756
757                         "show port (port_id) queue-region\n"
758                         "    show all queue region related configuration info\n\n"
759
760                         "set port (port_id) fec_mode auto|off|rs|baser\n"
761                         "    set fec mode for a specific port\n\n"
762
763                         , list_pkt_forwarding_modes()
764                 );
765         }
766
767         if (show_all || !strcmp(res->section, "ports")) {
768
769                 cmdline_printf(
770                         cl,
771                         "\n"
772                         "Port Operations:\n"
773                         "----------------\n\n"
774
775                         "port start (port_id|all)\n"
776                         "    Start all ports or port_id.\n\n"
777
778                         "port stop (port_id|all)\n"
779                         "    Stop all ports or port_id.\n\n"
780
781                         "port close (port_id|all)\n"
782                         "    Close all ports or port_id.\n\n"
783
784                         "port reset (port_id|all)\n"
785                         "    Reset all ports or port_id.\n\n"
786
787                         "port attach (ident)\n"
788                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
789
790                         "port detach (port_id)\n"
791                         "    Detach physical or virtual dev by port_id\n\n"
792
793                         "port config (port_id|all)"
794                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
795                         " duplex (half|full|auto)\n"
796                         "    Set speed and duplex for all ports or port_id\n\n"
797
798                         "port config (port_id|all) loopback (mode)\n"
799                         "    Set loopback mode for all ports or port_id\n\n"
800
801                         "port config all (rxq|txq|rxd|txd) (value)\n"
802                         "    Set number for rxq/txq/rxd/txd.\n\n"
803
804                         "port config all max-pkt-len (value)\n"
805                         "    Set the max packet length.\n\n"
806
807                         "port config all max-lro-pkt-size (value)\n"
808                         "    Set the max LRO aggregated packet size.\n\n"
809
810                         "port config all drop-en (on|off)\n"
811                         "    Enable or disable packet drop on all RX queues of all ports when no "
812                         "receive buffers available.\n\n"
813
814                         "port config all rss (all|default|ip|tcp|udp|sctp|"
815                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
816                         "level-outer|level-inner|<flowtype_id>)\n"
817                         "    Set the RSS mode.\n\n"
818
819                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
820                         "    Set the RSS redirection table.\n\n"
821
822                         "port config (port_id) dcb vt (on|off) (traffic_class)"
823                         " pfc (on|off)\n"
824                         "    Set the DCB mode.\n\n"
825
826                         "port config all burst (value)\n"
827                         "    Set the number of packets per burst.\n\n"
828
829                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
830                         " (value)\n"
831                         "    Set the ring prefetch/host/writeback threshold"
832                         " for tx/rx queue.\n\n"
833
834                         "port config all (txfreet|txrst|rxfreet) (value)\n"
835                         "    Set free threshold for rx/tx, or set"
836                         " tx rs bit threshold.\n\n"
837                         "port config mtu X value\n"
838                         "    Set the MTU of port X to a given value\n\n"
839
840                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
841                         "    Set a rx/tx queue's ring size configuration, the new"
842                         " value will take effect after command that (re-)start the port"
843                         " or command that setup the specific queue\n\n"
844
845                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
846                         "    Start/stop a rx/tx queue of port X. Only take effect"
847                         " when port X is started\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
850                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
851                         " take effect when port X is stopped.\n\n"
852
853                         "port (port_id) (rxq|txq) (queue_id) setup\n"
854                         "    Setup a rx/tx queue of port X.\n\n"
855
856                         "port config (port_id|all) l2-tunnel E-tag ether-type"
857                         " (value)\n"
858                         "    Set the value of E-tag ether-type.\n\n"
859
860                         "port config (port_id|all) l2-tunnel E-tag"
861                         " (enable|disable)\n"
862                         "    Enable/disable the E-tag support.\n\n"
863
864                         "port config (port_id) pctype mapping reset\n"
865                         "    Reset flow type to pctype mapping on a port\n\n"
866
867                         "port config (port_id) pctype mapping update"
868                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
869                         "    Update a flow type to pctype mapping item on a port\n\n"
870
871                         "port config (port_id) pctype (pctype_id) hash_inset|"
872                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
873                         " (field_idx)\n"
874                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
875
876                         "port config (port_id) pctype (pctype_id) hash_inset|"
877                         "fdir_inset|fdir_flx_inset clear all"
878                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
879
880                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
881                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
882
883                         "port config <port_id> rx_offload vlan_strip|"
884                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
885                         "outer_ipv4_cksum|macsec_strip|header_split|"
886                         "vlan_filter|vlan_extend|jumbo_frame|"
887                         "scatter|timestamp|security|keep_crc on|off\n"
888                         "     Enable or disable a per port Rx offloading"
889                         " on all Rx queues of a port\n\n"
890
891                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
892                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
893                         "outer_ipv4_cksum|macsec_strip|header_split|"
894                         "vlan_filter|vlan_extend|jumbo_frame|"
895                         "scatter|timestamp|security|keep_crc on|off\n"
896                         "    Enable or disable a per queue Rx offloading"
897                         " only on a specific Rx queue\n\n"
898
899                         "port config (port_id) tx_offload vlan_insert|"
900                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
901                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
902                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
903                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
904                         "security on|off\n"
905                         "    Enable or disable a per port Tx offloading"
906                         " on all Tx queues of a port\n\n"
907
908                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
909                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
910                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
911                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
912                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
913                         " on|off\n"
914                         "    Enable or disable a per queue Tx offloading"
915                         " only on a specific Tx queue\n\n"
916
917                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
918                         "    Load an eBPF program as a callback"
919                         " for particular RX/TX queue\n\n"
920
921                         "bpf-unload rx|tx (port) (queue)\n"
922                         "    Unload previously loaded eBPF program"
923                         " for particular RX/TX queue\n\n"
924
925                         "port config (port_id) tx_metadata (value)\n"
926                         "    Set Tx metadata value per port. Testpmd will add this value"
927                         " to any Tx packet sent from this port\n\n"
928
929                         "port config (port_id) dynf (name) set|clear\n"
930                         "    Register a dynf and Set/clear this flag on Tx. "
931                         "Testpmd will set this value to any Tx packet "
932                         "sent from this port\n\n"
933                 );
934         }
935
936         if (show_all || !strcmp(res->section, "registers")) {
937
938                 cmdline_printf(
939                         cl,
940                         "\n"
941                         "Registers:\n"
942                         "----------\n\n"
943
944                         "read reg (port_id) (address)\n"
945                         "    Display value of a port register.\n\n"
946
947                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
948                         "    Display a port register bit field.\n\n"
949
950                         "read regbit (port_id) (address) (bit_x)\n"
951                         "    Display a single port register bit.\n\n"
952
953                         "write reg (port_id) (address) (value)\n"
954                         "    Set value of a port register.\n\n"
955
956                         "write regfield (port_id) (address) (bit_x) (bit_y)"
957                         " (value)\n"
958                         "    Set bit field of a port register.\n\n"
959
960                         "write regbit (port_id) (address) (bit_x) (value)\n"
961                         "    Set single bit value of a port register.\n\n"
962                 );
963         }
964         if (show_all || !strcmp(res->section, "filters")) {
965
966                 cmdline_printf(
967                         cl,
968                         "\n"
969                         "filters:\n"
970                         "--------\n\n"
971
972                         "ethertype_filter (port_id) (add|del)"
973                         " (mac_addr|mac_ignr) (mac_address) ethertype"
974                         " (ether_type) (drop|fwd) queue (queue_id)\n"
975                         "    Add/Del an ethertype filter.\n\n"
976
977                         "2tuple_filter (port_id) (add|del)"
978                         " dst_port (dst_port_value) protocol (protocol_value)"
979                         " mask (mask_value) tcp_flags (tcp_flags_value)"
980                         " priority (prio_value) queue (queue_id)\n"
981                         "    Add/Del a 2tuple filter.\n\n"
982
983                         "5tuple_filter (port_id) (add|del)"
984                         " dst_ip (dst_address) src_ip (src_address)"
985                         " dst_port (dst_port_value) src_port (src_port_value)"
986                         " protocol (protocol_value)"
987                         " mask (mask_value) tcp_flags (tcp_flags_value)"
988                         " priority (prio_value) queue (queue_id)\n"
989                         "    Add/Del a 5tuple filter.\n\n"
990
991                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
992                         "    Add/Del syn filter.\n\n"
993
994                         "flex_filter (port_id) (add|del) len (len_value)"
995                         " bytes (bytes_value) mask (mask_value)"
996                         " priority (prio_value) queue (queue_id)\n"
997                         "    Add/Del a flex filter.\n\n"
998
999                         "flow_director_filter (port_id) mode IP (add|del|update)"
1000                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1001                         " src (src_ip_address) dst (dst_ip_address)"
1002                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1003                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1004                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1005                         " fd_id (fd_id_value)\n"
1006                         "    Add/Del an IP type flow director filter.\n\n"
1007
1008                         "flow_director_filter (port_id) mode IP (add|del|update)"
1009                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1010                         " src (src_ip_address) (src_port)"
1011                         " dst (dst_ip_address) (dst_port)"
1012                         " tos (tos_value) ttl (ttl_value)"
1013                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1014                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1015                         " fd_id (fd_id_value)\n"
1016                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode IP (add|del|update)"
1019                         " flow (ipv4-sctp|ipv6-sctp)"
1020                         " src (src_ip_address) (src_port)"
1021                         " dst (dst_ip_address) (dst_port)"
1022                         " tag (verification_tag) "
1023                         " tos (tos_value) ttl (ttl_value)"
1024                         " vlan (vlan_value)"
1025                         " flexbytes (flexbytes_value) (drop|fwd)"
1026                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1027                         "    Add/Del a SCTP type flow director filter.\n\n"
1028
1029                         "flow_director_filter (port_id) mode IP (add|del|update)"
1030                         " flow l2_payload ether (ethertype)"
1031                         " flexbytes (flexbytes_value) (drop|fwd)"
1032                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1033                         "    Add/Del a l2 payload type flow director filter.\n\n"
1034
1035                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1036                         " mac (mac_address) vlan (vlan_value)"
1037                         " flexbytes (flexbytes_value) (drop|fwd)"
1038                         " queue (queue_id) fd_id (fd_id_value)\n"
1039                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1040
1041                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1042                         " mac (mac_address) vlan (vlan_value)"
1043                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1044                         " flexbytes (flexbytes_value) (drop|fwd)"
1045                         " queue (queue_id) fd_id (fd_id_value)\n"
1046                         "    Add/Del a Tunnel flow director filter.\n\n"
1047
1048                         "flow_director_filter (port_id) mode raw (add|del|update)"
1049                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1050                         " fd_id (fd_id_value) packet (packet file name)\n"
1051                         "    Add/Del a raw type flow director filter.\n\n"
1052
1053                         "flush_flow_director (port_id)\n"
1054                         "    Flush all flow director entries of a device.\n\n"
1055
1056                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1057                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1058                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1059                         "    Set flow director IP mask.\n\n"
1060
1061                         "flow_director_mask (port_id) mode MAC-VLAN"
1062                         " vlan (vlan_value)\n"
1063                         "    Set flow director MAC-VLAN mask.\n\n"
1064
1065                         "flow_director_mask (port_id) mode Tunnel"
1066                         " vlan (vlan_value) mac (mac_value)"
1067                         " tunnel-type (tunnel_type_value)"
1068                         " tunnel-id (tunnel_id_value)\n"
1069                         "    Set flow director Tunnel mask.\n\n"
1070
1071                         "flow_director_flex_mask (port_id)"
1072                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1073                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1074                         " (mask)\n"
1075                         "    Configure mask of flex payload.\n\n"
1076
1077                         "flow_director_flex_payload (port_id)"
1078                         " (raw|l2|l3|l4) (config)\n"
1079                         "    Configure flex payload selection.\n\n"
1080
1081                         "get_sym_hash_ena_per_port (port_id)\n"
1082                         "    get symmetric hash enable configuration per port.\n\n"
1083
1084                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1085                         "    set symmetric hash enable configuration per port"
1086                         " to enable or disable.\n\n"
1087
1088                         "get_hash_global_config (port_id)\n"
1089                         "    Get the global configurations of hash filters.\n\n"
1090
1091                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1092                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1093                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1094                         " (enable|disable)\n"
1095                         "    Set the global configurations of hash filters.\n\n"
1096
1097                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1098                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1099                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1100                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1101                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1102                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1103                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1104                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1105                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1106                         "fld-8th|none) (select|add)\n"
1107                         "    Set the input set for hash.\n\n"
1108
1109                         "set_fdir_input_set (port_id) "
1110                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1111                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1112                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1113                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1114                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1115                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1116                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1117                         " (select|add)\n"
1118                         "    Set the input set for FDir.\n\n"
1119
1120                         "flow validate {port_id}"
1121                         " [group {group_id}] [priority {level}]"
1122                         " [ingress] [egress]"
1123                         " pattern {item} [/ {item} [...]] / end"
1124                         " actions {action} [/ {action} [...]] / end\n"
1125                         "    Check whether a flow rule can be created.\n\n"
1126
1127                         "flow create {port_id}"
1128                         " [group {group_id}] [priority {level}]"
1129                         " [ingress] [egress]"
1130                         " pattern {item} [/ {item} [...]] / end"
1131                         " actions {action} [/ {action} [...]] / end\n"
1132                         "    Create a flow rule.\n\n"
1133
1134                         "flow destroy {port_id} rule {rule_id} [...]\n"
1135                         "    Destroy specific flow rules.\n\n"
1136
1137                         "flow flush {port_id}\n"
1138                         "    Destroy all flow rules.\n\n"
1139
1140                         "flow query {port_id} {rule_id} {action}\n"
1141                         "    Query an existing flow rule.\n\n"
1142
1143                         "flow list {port_id} [group {group_id}] [...]\n"
1144                         "    List existing flow rules sorted by priority,"
1145                         " filtered by group identifiers.\n\n"
1146
1147                         "flow isolate {port_id} {boolean}\n"
1148                         "    Restrict ingress traffic to the defined"
1149                         " flow rules\n\n"
1150
1151                         "flow aged {port_id} [destroy]\n"
1152                         "    List and destroy aged flows"
1153                         " flow rules\n\n"
1154
1155                         "flow shared_action {port_id} create"
1156                         " [action_id {shared_action_id}]"
1157                         " [ingress] [egress]"
1158                         " action {action} / end\n"
1159                         "    Create shared action.\n\n"
1160
1161                         "flow shared_action {port_id} update"
1162                         " {shared_action_id} action {action} / end\n"
1163                         "    Update shared action.\n\n"
1164
1165                         "flow shared_action {port_id} destroy"
1166                         " action_id {shared_action_id} [...]\n"
1167                         "    Destroy specific shared actions.\n\n"
1168
1169                         "flow shared_action {port_id} query"
1170                         " {shared_action_id}\n"
1171                         "    Query an existing shared action.\n\n"
1172
1173                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1174                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1175                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1176                         "       Configure the VXLAN encapsulation for flows.\n\n"
1177
1178                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1179                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1180                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1181                         " eth-dst (eth-dst)\n"
1182                         "       Configure the VXLAN encapsulation for flows.\n\n"
1183
1184                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1185                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1186                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1187                         " eth-dst (eth-dst)\n"
1188                         "       Configure the VXLAN encapsulation for flows.\n\n"
1189
1190                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1191                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1192                         " (eth-dst)\n"
1193                         "       Configure the NVGRE encapsulation for flows.\n\n"
1194
1195                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1196                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1197                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1198                         "       Configure the NVGRE encapsulation for flows.\n\n"
1199
1200                         "set raw_encap {flow items}\n"
1201                         "       Configure the encapsulation with raw data.\n\n"
1202
1203                         "set raw_decap {flow items}\n"
1204                         "       Configure the decapsulation with raw data.\n\n"
1205
1206                 );
1207         }
1208
1209         if (show_all || !strcmp(res->section, "traffic_management")) {
1210                 cmdline_printf(
1211                         cl,
1212                         "\n"
1213                         "Traffic Management:\n"
1214                         "--------------\n"
1215                         "show port tm cap (port_id)\n"
1216                         "       Display the port TM capability.\n\n"
1217
1218                         "show port tm level cap (port_id) (level_id)\n"
1219                         "       Display the port TM hierarchical level capability.\n\n"
1220
1221                         "show port tm node cap (port_id) (node_id)\n"
1222                         "       Display the port TM node capability.\n\n"
1223
1224                         "show port tm node type (port_id) (node_id)\n"
1225                         "       Display the port TM node type.\n\n"
1226
1227                         "show port tm node stats (port_id) (node_id) (clear)\n"
1228                         "       Display the port TM node stats.\n\n"
1229
1230                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1231                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1232                         " (packet_length_adjust) (packet_mode)\n"
1233                         "       Add port tm node private shaper profile.\n\n"
1234
1235                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1236                         "       Delete port tm node private shaper profile.\n\n"
1237
1238                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1239                         " (shaper_profile_id)\n"
1240                         "       Add/update port tm node shared shaper.\n\n"
1241
1242                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1243                         "       Delete port tm node shared shaper.\n\n"
1244
1245                         "set port tm node shaper profile (port_id) (node_id)"
1246                         " (shaper_profile_id)\n"
1247                         "       Set port tm node shaper profile.\n\n"
1248
1249                         "add port tm node wred profile (port_id) (wred_profile_id)"
1250                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1251                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1252                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1253                         "       Add port tm node wred profile.\n\n"
1254
1255                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1256                         "       Delete port tm node wred profile.\n\n"
1257
1258                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1259                         " (priority) (weight) (level_id) (shaper_profile_id)"
1260                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1261                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1262                         "       Add port tm nonleaf node.\n\n"
1263
1264                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1265                         " (priority) (weight) (level_id) (shaper_profile_id)"
1266                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1267                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1268                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1269
1270                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1271                         " (priority) (weight) (level_id) (shaper_profile_id)"
1272                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1273                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1274                         "       Add port tm leaf node.\n\n"
1275
1276                         "del port tm node (port_id) (node_id)\n"
1277                         "       Delete port tm node.\n\n"
1278
1279                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1280                         " (priority) (weight)\n"
1281                         "       Set port tm node parent.\n\n"
1282
1283                         "suspend port tm node (port_id) (node_id)"
1284                         "       Suspend tm node.\n\n"
1285
1286                         "resume port tm node (port_id) (node_id)"
1287                         "       Resume tm node.\n\n"
1288
1289                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1290                         "       Commit tm hierarchy.\n\n"
1291
1292                         "set port tm mark ip_ecn (port) (green) (yellow)"
1293                         " (red)\n"
1294                         "    Enables/Disables the traffic management marking"
1295                         " for IP ECN (Explicit Congestion Notification)"
1296                         " packets on a given port\n\n"
1297
1298                         "set port tm mark ip_dscp (port) (green) (yellow)"
1299                         " (red)\n"
1300                         "    Enables/Disables the traffic management marking"
1301                         " on the port for IP dscp packets\n\n"
1302
1303                         "set port tm mark vlan_dei (port) (green) (yellow)"
1304                         " (red)\n"
1305                         "    Enables/Disables the traffic management marking"
1306                         " on the port for VLAN packets with DEI enabled\n\n"
1307                 );
1308         }
1309
1310         if (show_all || !strcmp(res->section, "devices")) {
1311                 cmdline_printf(
1312                         cl,
1313                         "\n"
1314                         "Device Operations:\n"
1315                         "--------------\n"
1316                         "device detach (identifier)\n"
1317                         "       Detach device by identifier.\n\n"
1318                 );
1319         }
1320
1321 }
1322
1323 cmdline_parse_token_string_t cmd_help_long_help =
1324         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1325
1326 cmdline_parse_token_string_t cmd_help_long_section =
1327         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1328                         "all#control#display#config#"
1329                         "ports#registers#filters#traffic_management#devices");
1330
1331 cmdline_parse_inst_t cmd_help_long = {
1332         .f = cmd_help_long_parsed,
1333         .data = NULL,
1334         .help_str = "help all|control|display|config|ports|register|"
1335                 "filters|traffic_management|devices: "
1336                 "Show help",
1337         .tokens = {
1338                 (void *)&cmd_help_long_help,
1339                 (void *)&cmd_help_long_section,
1340                 NULL,
1341         },
1342 };
1343
1344
1345 /* *** start/stop/close all ports *** */
1346 struct cmd_operate_port_result {
1347         cmdline_fixed_string_t keyword;
1348         cmdline_fixed_string_t name;
1349         cmdline_fixed_string_t value;
1350 };
1351
1352 static void cmd_operate_port_parsed(void *parsed_result,
1353                                 __rte_unused struct cmdline *cl,
1354                                 __rte_unused void *data)
1355 {
1356         struct cmd_operate_port_result *res = parsed_result;
1357
1358         if (!strcmp(res->name, "start"))
1359                 start_port(RTE_PORT_ALL);
1360         else if (!strcmp(res->name, "stop"))
1361                 stop_port(RTE_PORT_ALL);
1362         else if (!strcmp(res->name, "close"))
1363                 close_port(RTE_PORT_ALL);
1364         else if (!strcmp(res->name, "reset"))
1365                 reset_port(RTE_PORT_ALL);
1366         else
1367                 printf("Unknown parameter\n");
1368 }
1369
1370 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1371         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1372                                                                 "port");
1373 cmdline_parse_token_string_t cmd_operate_port_all_port =
1374         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1375                                                 "start#stop#close#reset");
1376 cmdline_parse_token_string_t cmd_operate_port_all_all =
1377         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1378
1379 cmdline_parse_inst_t cmd_operate_port = {
1380         .f = cmd_operate_port_parsed,
1381         .data = NULL,
1382         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1383         .tokens = {
1384                 (void *)&cmd_operate_port_all_cmd,
1385                 (void *)&cmd_operate_port_all_port,
1386                 (void *)&cmd_operate_port_all_all,
1387                 NULL,
1388         },
1389 };
1390
1391 /* *** start/stop/close specific port *** */
1392 struct cmd_operate_specific_port_result {
1393         cmdline_fixed_string_t keyword;
1394         cmdline_fixed_string_t name;
1395         uint8_t value;
1396 };
1397
1398 static void cmd_operate_specific_port_parsed(void *parsed_result,
1399                         __rte_unused struct cmdline *cl,
1400                                 __rte_unused void *data)
1401 {
1402         struct cmd_operate_specific_port_result *res = parsed_result;
1403
1404         if (!strcmp(res->name, "start"))
1405                 start_port(res->value);
1406         else if (!strcmp(res->name, "stop"))
1407                 stop_port(res->value);
1408         else if (!strcmp(res->name, "close"))
1409                 close_port(res->value);
1410         else if (!strcmp(res->name, "reset"))
1411                 reset_port(res->value);
1412         else
1413                 printf("Unknown parameter\n");
1414 }
1415
1416 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1417         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1418                                                         keyword, "port");
1419 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1420         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1421                                                 name, "start#stop#close#reset");
1422 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1423         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1424                                                         value, UINT8);
1425
1426 cmdline_parse_inst_t cmd_operate_specific_port = {
1427         .f = cmd_operate_specific_port_parsed,
1428         .data = NULL,
1429         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1430         .tokens = {
1431                 (void *)&cmd_operate_specific_port_cmd,
1432                 (void *)&cmd_operate_specific_port_port,
1433                 (void *)&cmd_operate_specific_port_id,
1434                 NULL,
1435         },
1436 };
1437
1438 /* *** enable port setup (after attach) via iterator or event *** */
1439 struct cmd_set_port_setup_on_result {
1440         cmdline_fixed_string_t set;
1441         cmdline_fixed_string_t port;
1442         cmdline_fixed_string_t setup;
1443         cmdline_fixed_string_t on;
1444         cmdline_fixed_string_t mode;
1445 };
1446
1447 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1448                                 __rte_unused struct cmdline *cl,
1449                                 __rte_unused void *data)
1450 {
1451         struct cmd_set_port_setup_on_result *res = parsed_result;
1452
1453         if (strcmp(res->mode, "event") == 0)
1454                 setup_on_probe_event = true;
1455         else if (strcmp(res->mode, "iterator") == 0)
1456                 setup_on_probe_event = false;
1457         else
1458                 printf("Unknown mode\n");
1459 }
1460
1461 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1462         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1463                         set, "set");
1464 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1465         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1466                         port, "port");
1467 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1468         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1469                         setup, "setup");
1470 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1471         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1472                         on, "on");
1473 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1474         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1475                         mode, "iterator#event");
1476
1477 cmdline_parse_inst_t cmd_set_port_setup_on = {
1478         .f = cmd_set_port_setup_on_parsed,
1479         .data = NULL,
1480         .help_str = "set port setup on iterator|event",
1481         .tokens = {
1482                 (void *)&cmd_set_port_setup_on_set,
1483                 (void *)&cmd_set_port_setup_on_port,
1484                 (void *)&cmd_set_port_setup_on_setup,
1485                 (void *)&cmd_set_port_setup_on_on,
1486                 (void *)&cmd_set_port_setup_on_mode,
1487                 NULL,
1488         },
1489 };
1490
1491 /* *** attach a specified port *** */
1492 struct cmd_operate_attach_port_result {
1493         cmdline_fixed_string_t port;
1494         cmdline_fixed_string_t keyword;
1495         cmdline_multi_string_t identifier;
1496 };
1497
1498 static void cmd_operate_attach_port_parsed(void *parsed_result,
1499                                 __rte_unused struct cmdline *cl,
1500                                 __rte_unused void *data)
1501 {
1502         struct cmd_operate_attach_port_result *res = parsed_result;
1503
1504         if (!strcmp(res->keyword, "attach"))
1505                 attach_port(res->identifier);
1506         else
1507                 printf("Unknown parameter\n");
1508 }
1509
1510 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1511         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1512                         port, "port");
1513 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1514         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1515                         keyword, "attach");
1516 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1517         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1518                         identifier, TOKEN_STRING_MULTI);
1519
1520 cmdline_parse_inst_t cmd_operate_attach_port = {
1521         .f = cmd_operate_attach_port_parsed,
1522         .data = NULL,
1523         .help_str = "port attach <identifier>: "
1524                 "(identifier: pci address or virtual dev name)",
1525         .tokens = {
1526                 (void *)&cmd_operate_attach_port_port,
1527                 (void *)&cmd_operate_attach_port_keyword,
1528                 (void *)&cmd_operate_attach_port_identifier,
1529                 NULL,
1530         },
1531 };
1532
1533 /* *** detach a specified port *** */
1534 struct cmd_operate_detach_port_result {
1535         cmdline_fixed_string_t port;
1536         cmdline_fixed_string_t keyword;
1537         portid_t port_id;
1538 };
1539
1540 static void cmd_operate_detach_port_parsed(void *parsed_result,
1541                                 __rte_unused struct cmdline *cl,
1542                                 __rte_unused void *data)
1543 {
1544         struct cmd_operate_detach_port_result *res = parsed_result;
1545
1546         if (!strcmp(res->keyword, "detach")) {
1547                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1548                 detach_port_device(res->port_id);
1549         } else {
1550                 printf("Unknown parameter\n");
1551         }
1552 }
1553
1554 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1555         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1556                         port, "port");
1557 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1558         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1559                         keyword, "detach");
1560 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1561         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1562                         port_id, UINT16);
1563
1564 cmdline_parse_inst_t cmd_operate_detach_port = {
1565         .f = cmd_operate_detach_port_parsed,
1566         .data = NULL,
1567         .help_str = "port detach <port_id>",
1568         .tokens = {
1569                 (void *)&cmd_operate_detach_port_port,
1570                 (void *)&cmd_operate_detach_port_keyword,
1571                 (void *)&cmd_operate_detach_port_port_id,
1572                 NULL,
1573         },
1574 };
1575
1576 /* *** detach device by identifier *** */
1577 struct cmd_operate_detach_device_result {
1578         cmdline_fixed_string_t device;
1579         cmdline_fixed_string_t keyword;
1580         cmdline_fixed_string_t identifier;
1581 };
1582
1583 static void cmd_operate_detach_device_parsed(void *parsed_result,
1584                                 __rte_unused struct cmdline *cl,
1585                                 __rte_unused void *data)
1586 {
1587         struct cmd_operate_detach_device_result *res = parsed_result;
1588
1589         if (!strcmp(res->keyword, "detach"))
1590                 detach_devargs(res->identifier);
1591         else
1592                 printf("Unknown parameter\n");
1593 }
1594
1595 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1596         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1597                         device, "device");
1598 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1599         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1600                         keyword, "detach");
1601 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1602         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1603                         identifier, NULL);
1604
1605 cmdline_parse_inst_t cmd_operate_detach_device = {
1606         .f = cmd_operate_detach_device_parsed,
1607         .data = NULL,
1608         .help_str = "device detach <identifier>:"
1609                 "(identifier: pci address or virtual dev name)",
1610         .tokens = {
1611                 (void *)&cmd_operate_detach_device_device,
1612                 (void *)&cmd_operate_detach_device_keyword,
1613                 (void *)&cmd_operate_detach_device_identifier,
1614                 NULL,
1615         },
1616 };
1617 /* *** configure speed for all ports *** */
1618 struct cmd_config_speed_all {
1619         cmdline_fixed_string_t port;
1620         cmdline_fixed_string_t keyword;
1621         cmdline_fixed_string_t all;
1622         cmdline_fixed_string_t item1;
1623         cmdline_fixed_string_t item2;
1624         cmdline_fixed_string_t value1;
1625         cmdline_fixed_string_t value2;
1626 };
1627
1628 static int
1629 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1630 {
1631
1632         int duplex;
1633
1634         if (!strcmp(duplexstr, "half")) {
1635                 duplex = ETH_LINK_HALF_DUPLEX;
1636         } else if (!strcmp(duplexstr, "full")) {
1637                 duplex = ETH_LINK_FULL_DUPLEX;
1638         } else if (!strcmp(duplexstr, "auto")) {
1639                 duplex = ETH_LINK_FULL_DUPLEX;
1640         } else {
1641                 printf("Unknown duplex parameter\n");
1642                 return -1;
1643         }
1644
1645         if (!strcmp(speedstr, "10")) {
1646                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1647                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1648         } else if (!strcmp(speedstr, "100")) {
1649                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1650                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1651         } else {
1652                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1653                         printf("Invalid speed/duplex parameters\n");
1654                         return -1;
1655                 }
1656                 if (!strcmp(speedstr, "1000")) {
1657                         *speed = ETH_LINK_SPEED_1G;
1658                 } else if (!strcmp(speedstr, "10000")) {
1659                         *speed = ETH_LINK_SPEED_10G;
1660                 } else if (!strcmp(speedstr, "25000")) {
1661                         *speed = ETH_LINK_SPEED_25G;
1662                 } else if (!strcmp(speedstr, "40000")) {
1663                         *speed = ETH_LINK_SPEED_40G;
1664                 } else if (!strcmp(speedstr, "50000")) {
1665                         *speed = ETH_LINK_SPEED_50G;
1666                 } else if (!strcmp(speedstr, "100000")) {
1667                         *speed = ETH_LINK_SPEED_100G;
1668                 } else if (!strcmp(speedstr, "200000")) {
1669                         *speed = ETH_LINK_SPEED_200G;
1670                 } else if (!strcmp(speedstr, "auto")) {
1671                         *speed = ETH_LINK_SPEED_AUTONEG;
1672                 } else {
1673                         printf("Unknown speed parameter\n");
1674                         return -1;
1675                 }
1676         }
1677
1678         return 0;
1679 }
1680
1681 static void
1682 cmd_config_speed_all_parsed(void *parsed_result,
1683                         __rte_unused struct cmdline *cl,
1684                         __rte_unused void *data)
1685 {
1686         struct cmd_config_speed_all *res = parsed_result;
1687         uint32_t link_speed;
1688         portid_t pid;
1689
1690         if (!all_ports_stopped()) {
1691                 printf("Please stop all ports first\n");
1692                 return;
1693         }
1694
1695         if (parse_and_check_speed_duplex(res->value1, res->value2,
1696                         &link_speed) < 0)
1697                 return;
1698
1699         RTE_ETH_FOREACH_DEV(pid) {
1700                 ports[pid].dev_conf.link_speeds = link_speed;
1701         }
1702
1703         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1704 }
1705
1706 cmdline_parse_token_string_t cmd_config_speed_all_port =
1707         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1708 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1709         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1710                                                         "config");
1711 cmdline_parse_token_string_t cmd_config_speed_all_all =
1712         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1713 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1714         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1715 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1716         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1717                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1718 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1720 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1722                                                 "half#full#auto");
1723
1724 cmdline_parse_inst_t cmd_config_speed_all = {
1725         .f = cmd_config_speed_all_parsed,
1726         .data = NULL,
1727         .help_str = "port config all speed "
1728                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1729                                                         "half|full|auto",
1730         .tokens = {
1731                 (void *)&cmd_config_speed_all_port,
1732                 (void *)&cmd_config_speed_all_keyword,
1733                 (void *)&cmd_config_speed_all_all,
1734                 (void *)&cmd_config_speed_all_item1,
1735                 (void *)&cmd_config_speed_all_value1,
1736                 (void *)&cmd_config_speed_all_item2,
1737                 (void *)&cmd_config_speed_all_value2,
1738                 NULL,
1739         },
1740 };
1741
1742 /* *** configure speed for specific port *** */
1743 struct cmd_config_speed_specific {
1744         cmdline_fixed_string_t port;
1745         cmdline_fixed_string_t keyword;
1746         portid_t id;
1747         cmdline_fixed_string_t item1;
1748         cmdline_fixed_string_t item2;
1749         cmdline_fixed_string_t value1;
1750         cmdline_fixed_string_t value2;
1751 };
1752
1753 static void
1754 cmd_config_speed_specific_parsed(void *parsed_result,
1755                                 __rte_unused struct cmdline *cl,
1756                                 __rte_unused void *data)
1757 {
1758         struct cmd_config_speed_specific *res = parsed_result;
1759         uint32_t link_speed;
1760
1761         if (!all_ports_stopped()) {
1762                 printf("Please stop all ports first\n");
1763                 return;
1764         }
1765
1766         if (port_id_is_invalid(res->id, ENABLED_WARN))
1767                 return;
1768
1769         if (parse_and_check_speed_duplex(res->value1, res->value2,
1770                         &link_speed) < 0)
1771                 return;
1772
1773         ports[res->id].dev_conf.link_speeds = link_speed;
1774
1775         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1776 }
1777
1778
1779 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1780         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1781                                                                 "port");
1782 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1783         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1784                                                                 "config");
1785 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1786         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1787 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1788         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1789                                                                 "speed");
1790 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1791         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1792                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1793 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1795                                                                 "duplex");
1796 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1798                                                         "half#full#auto");
1799
1800 cmdline_parse_inst_t cmd_config_speed_specific = {
1801         .f = cmd_config_speed_specific_parsed,
1802         .data = NULL,
1803         .help_str = "port config <port_id> speed "
1804                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1805                                                         "half|full|auto",
1806         .tokens = {
1807                 (void *)&cmd_config_speed_specific_port,
1808                 (void *)&cmd_config_speed_specific_keyword,
1809                 (void *)&cmd_config_speed_specific_id,
1810                 (void *)&cmd_config_speed_specific_item1,
1811                 (void *)&cmd_config_speed_specific_value1,
1812                 (void *)&cmd_config_speed_specific_item2,
1813                 (void *)&cmd_config_speed_specific_value2,
1814                 NULL,
1815         },
1816 };
1817
1818 /* *** configure loopback for all ports *** */
1819 struct cmd_config_loopback_all {
1820         cmdline_fixed_string_t port;
1821         cmdline_fixed_string_t keyword;
1822         cmdline_fixed_string_t all;
1823         cmdline_fixed_string_t item;
1824         uint32_t mode;
1825 };
1826
1827 static void
1828 cmd_config_loopback_all_parsed(void *parsed_result,
1829                         __rte_unused struct cmdline *cl,
1830                         __rte_unused void *data)
1831 {
1832         struct cmd_config_loopback_all *res = parsed_result;
1833         portid_t pid;
1834
1835         if (!all_ports_stopped()) {
1836                 printf("Please stop all ports first\n");
1837                 return;
1838         }
1839
1840         RTE_ETH_FOREACH_DEV(pid) {
1841                 ports[pid].dev_conf.lpbk_mode = res->mode;
1842         }
1843
1844         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1845 }
1846
1847 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1848         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1849 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1851                                                         "config");
1852 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1853         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1854 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1855         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1856                                                         "loopback");
1857 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1858         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1859
1860 cmdline_parse_inst_t cmd_config_loopback_all = {
1861         .f = cmd_config_loopback_all_parsed,
1862         .data = NULL,
1863         .help_str = "port config all loopback <mode>",
1864         .tokens = {
1865                 (void *)&cmd_config_loopback_all_port,
1866                 (void *)&cmd_config_loopback_all_keyword,
1867                 (void *)&cmd_config_loopback_all_all,
1868                 (void *)&cmd_config_loopback_all_item,
1869                 (void *)&cmd_config_loopback_all_mode,
1870                 NULL,
1871         },
1872 };
1873
1874 /* *** configure loopback for specific port *** */
1875 struct cmd_config_loopback_specific {
1876         cmdline_fixed_string_t port;
1877         cmdline_fixed_string_t keyword;
1878         uint16_t port_id;
1879         cmdline_fixed_string_t item;
1880         uint32_t mode;
1881 };
1882
1883 static void
1884 cmd_config_loopback_specific_parsed(void *parsed_result,
1885                                 __rte_unused struct cmdline *cl,
1886                                 __rte_unused void *data)
1887 {
1888         struct cmd_config_loopback_specific *res = parsed_result;
1889
1890         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1891                 return;
1892
1893         if (!port_is_stopped(res->port_id)) {
1894                 printf("Please stop port %u first\n", res->port_id);
1895                 return;
1896         }
1897
1898         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1899
1900         cmd_reconfig_device_queue(res->port_id, 1, 1);
1901 }
1902
1903
1904 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1905         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1906                                                                 "port");
1907 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1908         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1909                                                                 "config");
1910 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1911         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1912                                                                 UINT16);
1913 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1914         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1915                                                                 "loopback");
1916 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1917         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1918                               UINT32);
1919
1920 cmdline_parse_inst_t cmd_config_loopback_specific = {
1921         .f = cmd_config_loopback_specific_parsed,
1922         .data = NULL,
1923         .help_str = "port config <port_id> loopback <mode>",
1924         .tokens = {
1925                 (void *)&cmd_config_loopback_specific_port,
1926                 (void *)&cmd_config_loopback_specific_keyword,
1927                 (void *)&cmd_config_loopback_specific_id,
1928                 (void *)&cmd_config_loopback_specific_item,
1929                 (void *)&cmd_config_loopback_specific_mode,
1930                 NULL,
1931         },
1932 };
1933
1934 /* *** configure txq/rxq, txd/rxd *** */
1935 struct cmd_config_rx_tx {
1936         cmdline_fixed_string_t port;
1937         cmdline_fixed_string_t keyword;
1938         cmdline_fixed_string_t all;
1939         cmdline_fixed_string_t name;
1940         uint16_t value;
1941 };
1942
1943 static void
1944 cmd_config_rx_tx_parsed(void *parsed_result,
1945                         __rte_unused struct cmdline *cl,
1946                         __rte_unused void *data)
1947 {
1948         struct cmd_config_rx_tx *res = parsed_result;
1949
1950         if (!all_ports_stopped()) {
1951                 printf("Please stop all ports first\n");
1952                 return;
1953         }
1954         if (!strcmp(res->name, "rxq")) {
1955                 if (!res->value && !nb_txq) {
1956                         printf("Warning: Either rx or tx queues should be non zero\n");
1957                         return;
1958                 }
1959                 if (check_nb_rxq(res->value) != 0)
1960                         return;
1961                 nb_rxq = res->value;
1962         }
1963         else if (!strcmp(res->name, "txq")) {
1964                 if (!res->value && !nb_rxq) {
1965                         printf("Warning: Either rx or tx queues should be non zero\n");
1966                         return;
1967                 }
1968                 if (check_nb_txq(res->value) != 0)
1969                         return;
1970                 nb_txq = res->value;
1971         }
1972         else if (!strcmp(res->name, "rxd")) {
1973                 if (check_nb_rxd(res->value) != 0)
1974                         return;
1975                 nb_rxd = res->value;
1976         } else if (!strcmp(res->name, "txd")) {
1977                 if (check_nb_txd(res->value) != 0)
1978                         return;
1979
1980                 nb_txd = res->value;
1981         } else {
1982                 printf("Unknown parameter\n");
1983                 return;
1984         }
1985
1986         fwd_config_setup();
1987
1988         init_port_config();
1989
1990         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1991 }
1992
1993 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1994         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1995 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1996         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1997 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1998         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1999 cmdline_parse_token_string_t cmd_config_rx_tx_name =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
2001                                                 "rxq#txq#rxd#txd");
2002 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2003         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2004
2005 cmdline_parse_inst_t cmd_config_rx_tx = {
2006         .f = cmd_config_rx_tx_parsed,
2007         .data = NULL,
2008         .help_str = "port config all rxq|txq|rxd|txd <value>",
2009         .tokens = {
2010                 (void *)&cmd_config_rx_tx_port,
2011                 (void *)&cmd_config_rx_tx_keyword,
2012                 (void *)&cmd_config_rx_tx_all,
2013                 (void *)&cmd_config_rx_tx_name,
2014                 (void *)&cmd_config_rx_tx_value,
2015                 NULL,
2016         },
2017 };
2018
2019 /* *** config max packet length *** */
2020 struct cmd_config_max_pkt_len_result {
2021         cmdline_fixed_string_t port;
2022         cmdline_fixed_string_t keyword;
2023         cmdline_fixed_string_t all;
2024         cmdline_fixed_string_t name;
2025         uint32_t value;
2026 };
2027
2028 static void
2029 cmd_config_max_pkt_len_parsed(void *parsed_result,
2030                                 __rte_unused struct cmdline *cl,
2031                                 __rte_unused void *data)
2032 {
2033         struct cmd_config_max_pkt_len_result *res = parsed_result;
2034         portid_t pid;
2035
2036         if (!all_ports_stopped()) {
2037                 printf("Please stop all ports first\n");
2038                 return;
2039         }
2040
2041         RTE_ETH_FOREACH_DEV(pid) {
2042                 struct rte_port *port = &ports[pid];
2043                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2044
2045                 if (!strcmp(res->name, "max-pkt-len")) {
2046                         if (res->value < RTE_ETHER_MIN_LEN) {
2047                                 printf("max-pkt-len can not be less than %d\n",
2048                                                 RTE_ETHER_MIN_LEN);
2049                                 return;
2050                         }
2051                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2052                                 return;
2053
2054                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2055                         if (res->value > RTE_ETHER_MAX_LEN)
2056                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2057                         else
2058                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2059                         port->dev_conf.rxmode.offloads = rx_offloads;
2060                 } else {
2061                         printf("Unknown parameter\n");
2062                         return;
2063                 }
2064         }
2065
2066         init_port_config();
2067
2068         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2069 }
2070
2071 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2072         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2073                                                                 "port");
2074 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2075         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2076                                                                 "config");
2077 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2079                                                                 "all");
2080 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2081         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2082                                                                 "max-pkt-len");
2083 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2084         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2085                                                                 UINT32);
2086
2087 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2088         .f = cmd_config_max_pkt_len_parsed,
2089         .data = NULL,
2090         .help_str = "port config all max-pkt-len <value>",
2091         .tokens = {
2092                 (void *)&cmd_config_max_pkt_len_port,
2093                 (void *)&cmd_config_max_pkt_len_keyword,
2094                 (void *)&cmd_config_max_pkt_len_all,
2095                 (void *)&cmd_config_max_pkt_len_name,
2096                 (void *)&cmd_config_max_pkt_len_value,
2097                 NULL,
2098         },
2099 };
2100
2101 /* *** config max LRO aggregated packet size *** */
2102 struct cmd_config_max_lro_pkt_size_result {
2103         cmdline_fixed_string_t port;
2104         cmdline_fixed_string_t keyword;
2105         cmdline_fixed_string_t all;
2106         cmdline_fixed_string_t name;
2107         uint32_t value;
2108 };
2109
2110 static void
2111 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2112                                 __rte_unused struct cmdline *cl,
2113                                 __rte_unused void *data)
2114 {
2115         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2116         portid_t pid;
2117
2118         if (!all_ports_stopped()) {
2119                 printf("Please stop all ports first\n");
2120                 return;
2121         }
2122
2123         RTE_ETH_FOREACH_DEV(pid) {
2124                 struct rte_port *port = &ports[pid];
2125
2126                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2127                         if (res->value ==
2128                                         port->dev_conf.rxmode.max_lro_pkt_size)
2129                                 return;
2130
2131                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2132                 } else {
2133                         printf("Unknown parameter\n");
2134                         return;
2135                 }
2136         }
2137
2138         init_port_config();
2139
2140         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2141 }
2142
2143 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2144         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2145                                  port, "port");
2146 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2147         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2148                                  keyword, "config");
2149 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2150         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2151                                  all, "all");
2152 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2154                                  name, "max-lro-pkt-size");
2155 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2156         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2157                               value, UINT32);
2158
2159 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2160         .f = cmd_config_max_lro_pkt_size_parsed,
2161         .data = NULL,
2162         .help_str = "port config all max-lro-pkt-size <value>",
2163         .tokens = {
2164                 (void *)&cmd_config_max_lro_pkt_size_port,
2165                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2166                 (void *)&cmd_config_max_lro_pkt_size_all,
2167                 (void *)&cmd_config_max_lro_pkt_size_name,
2168                 (void *)&cmd_config_max_lro_pkt_size_value,
2169                 NULL,
2170         },
2171 };
2172
2173 /* *** configure port MTU *** */
2174 struct cmd_config_mtu_result {
2175         cmdline_fixed_string_t port;
2176         cmdline_fixed_string_t keyword;
2177         cmdline_fixed_string_t mtu;
2178         portid_t port_id;
2179         uint16_t value;
2180 };
2181
2182 static void
2183 cmd_config_mtu_parsed(void *parsed_result,
2184                       __rte_unused struct cmdline *cl,
2185                       __rte_unused void *data)
2186 {
2187         struct cmd_config_mtu_result *res = parsed_result;
2188
2189         if (res->value < RTE_ETHER_MIN_LEN) {
2190                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2191                 return;
2192         }
2193         port_mtu_set(res->port_id, res->value);
2194 }
2195
2196 cmdline_parse_token_string_t cmd_config_mtu_port =
2197         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2198                                  "port");
2199 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2200         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2201                                  "config");
2202 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2203         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2204                                  "mtu");
2205 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2206         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2207 cmdline_parse_token_num_t cmd_config_mtu_value =
2208         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2209
2210 cmdline_parse_inst_t cmd_config_mtu = {
2211         .f = cmd_config_mtu_parsed,
2212         .data = NULL,
2213         .help_str = "port config mtu <port_id> <value>",
2214         .tokens = {
2215                 (void *)&cmd_config_mtu_port,
2216                 (void *)&cmd_config_mtu_keyword,
2217                 (void *)&cmd_config_mtu_mtu,
2218                 (void *)&cmd_config_mtu_port_id,
2219                 (void *)&cmd_config_mtu_value,
2220                 NULL,
2221         },
2222 };
2223
2224 /* *** configure rx mode *** */
2225 struct cmd_config_rx_mode_flag {
2226         cmdline_fixed_string_t port;
2227         cmdline_fixed_string_t keyword;
2228         cmdline_fixed_string_t all;
2229         cmdline_fixed_string_t name;
2230         cmdline_fixed_string_t value;
2231 };
2232
2233 static void
2234 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2235                                 __rte_unused struct cmdline *cl,
2236                                 __rte_unused void *data)
2237 {
2238         struct cmd_config_rx_mode_flag *res = parsed_result;
2239
2240         if (!all_ports_stopped()) {
2241                 printf("Please stop all ports first\n");
2242                 return;
2243         }
2244
2245         if (!strcmp(res->name, "drop-en")) {
2246                 if (!strcmp(res->value, "on"))
2247                         rx_drop_en = 1;
2248                 else if (!strcmp(res->value, "off"))
2249                         rx_drop_en = 0;
2250                 else {
2251                         printf("Unknown parameter\n");
2252                         return;
2253                 }
2254         } else {
2255                 printf("Unknown parameter\n");
2256                 return;
2257         }
2258
2259         init_port_config();
2260
2261         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2262 }
2263
2264 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2265         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2266 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2267         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2268                                                                 "config");
2269 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2270         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2271 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2272         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2273                                         "drop-en");
2274 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2275         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2276                                                         "on#off");
2277
2278 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2279         .f = cmd_config_rx_mode_flag_parsed,
2280         .data = NULL,
2281         .help_str = "port config all drop-en on|off",
2282         .tokens = {
2283                 (void *)&cmd_config_rx_mode_flag_port,
2284                 (void *)&cmd_config_rx_mode_flag_keyword,
2285                 (void *)&cmd_config_rx_mode_flag_all,
2286                 (void *)&cmd_config_rx_mode_flag_name,
2287                 (void *)&cmd_config_rx_mode_flag_value,
2288                 NULL,
2289         },
2290 };
2291
2292 /* *** configure rss *** */
2293 struct cmd_config_rss {
2294         cmdline_fixed_string_t port;
2295         cmdline_fixed_string_t keyword;
2296         cmdline_fixed_string_t all;
2297         cmdline_fixed_string_t name;
2298         cmdline_fixed_string_t value;
2299 };
2300
2301 static void
2302 cmd_config_rss_parsed(void *parsed_result,
2303                         __rte_unused struct cmdline *cl,
2304                         __rte_unused void *data)
2305 {
2306         struct cmd_config_rss *res = parsed_result;
2307         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2308         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2309         int use_default = 0;
2310         int all_updated = 1;
2311         int diag;
2312         uint16_t i;
2313         int ret;
2314
2315         if (!strcmp(res->value, "all"))
2316                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2317                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2318                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2319                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2320         else if (!strcmp(res->value, "eth"))
2321                 rss_conf.rss_hf = ETH_RSS_ETH;
2322         else if (!strcmp(res->value, "vlan"))
2323                 rss_conf.rss_hf = ETH_RSS_VLAN;
2324         else if (!strcmp(res->value, "ip"))
2325                 rss_conf.rss_hf = ETH_RSS_IP;
2326         else if (!strcmp(res->value, "udp"))
2327                 rss_conf.rss_hf = ETH_RSS_UDP;
2328         else if (!strcmp(res->value, "tcp"))
2329                 rss_conf.rss_hf = ETH_RSS_TCP;
2330         else if (!strcmp(res->value, "sctp"))
2331                 rss_conf.rss_hf = ETH_RSS_SCTP;
2332         else if (!strcmp(res->value, "ether"))
2333                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2334         else if (!strcmp(res->value, "port"))
2335                 rss_conf.rss_hf = ETH_RSS_PORT;
2336         else if (!strcmp(res->value, "vxlan"))
2337                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2338         else if (!strcmp(res->value, "geneve"))
2339                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2340         else if (!strcmp(res->value, "nvgre"))
2341                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2342         else if (!strcmp(res->value, "l3-pre32"))
2343                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2344         else if (!strcmp(res->value, "l3-pre40"))
2345                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2346         else if (!strcmp(res->value, "l3-pre48"))
2347                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2348         else if (!strcmp(res->value, "l3-pre56"))
2349                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2350         else if (!strcmp(res->value, "l3-pre64"))
2351                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2352         else if (!strcmp(res->value, "l3-pre96"))
2353                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2354         else if (!strcmp(res->value, "l3-src-only"))
2355                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2356         else if (!strcmp(res->value, "l3-dst-only"))
2357                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2358         else if (!strcmp(res->value, "l4-src-only"))
2359                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2360         else if (!strcmp(res->value, "l4-dst-only"))
2361                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2362         else if (!strcmp(res->value, "l2-src-only"))
2363                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2364         else if (!strcmp(res->value, "l2-dst-only"))
2365                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2366         else if (!strcmp(res->value, "l2tpv3"))
2367                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2368         else if (!strcmp(res->value, "esp"))
2369                 rss_conf.rss_hf = ETH_RSS_ESP;
2370         else if (!strcmp(res->value, "ah"))
2371                 rss_conf.rss_hf = ETH_RSS_AH;
2372         else if (!strcmp(res->value, "pfcp"))
2373                 rss_conf.rss_hf = ETH_RSS_PFCP;
2374         else if (!strcmp(res->value, "pppoe"))
2375                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2376         else if (!strcmp(res->value, "gtpu"))
2377                 rss_conf.rss_hf = ETH_RSS_GTPU;
2378         else if (!strcmp(res->value, "none"))
2379                 rss_conf.rss_hf = 0;
2380         else if (!strcmp(res->value, "level-default")) {
2381                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2382                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2383         } else if (!strcmp(res->value, "level-outer")) {
2384                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2385                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2386         } else if (!strcmp(res->value, "level-inner")) {
2387                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2388                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2389         } else if (!strcmp(res->value, "default"))
2390                 use_default = 1;
2391         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2392                                                 atoi(res->value) < 64)
2393                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2394         else {
2395                 printf("Unknown parameter\n");
2396                 return;
2397         }
2398         rss_conf.rss_key = NULL;
2399         /* Update global configuration for RSS types. */
2400         RTE_ETH_FOREACH_DEV(i) {
2401                 struct rte_eth_rss_conf local_rss_conf;
2402
2403                 ret = eth_dev_info_get_print_err(i, &dev_info);
2404                 if (ret != 0)
2405                         return;
2406
2407                 if (use_default)
2408                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2409
2410                 local_rss_conf = rss_conf;
2411                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2412                         dev_info.flow_type_rss_offloads;
2413                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2414                         printf("Port %u modified RSS hash function based on hardware support,"
2415                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2416                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2417                 }
2418                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2419                 if (diag < 0) {
2420                         all_updated = 0;
2421                         printf("Configuration of RSS hash at ethernet port %d "
2422                                 "failed with error (%d): %s.\n",
2423                                 i, -diag, strerror(-diag));
2424                 }
2425         }
2426         if (all_updated && !use_default) {
2427                 rss_hf = rss_conf.rss_hf;
2428                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2429         }
2430 }
2431
2432 cmdline_parse_token_string_t cmd_config_rss_port =
2433         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2434 cmdline_parse_token_string_t cmd_config_rss_keyword =
2435         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2436 cmdline_parse_token_string_t cmd_config_rss_all =
2437         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2438 cmdline_parse_token_string_t cmd_config_rss_name =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2440 cmdline_parse_token_string_t cmd_config_rss_value =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2442
2443 cmdline_parse_inst_t cmd_config_rss = {
2444         .f = cmd_config_rss_parsed,
2445         .data = NULL,
2446         .help_str = "port config all rss "
2447                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2448                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2449                 "level-outer|level-inner|<flowtype_id>",
2450         .tokens = {
2451                 (void *)&cmd_config_rss_port,
2452                 (void *)&cmd_config_rss_keyword,
2453                 (void *)&cmd_config_rss_all,
2454                 (void *)&cmd_config_rss_name,
2455                 (void *)&cmd_config_rss_value,
2456                 NULL,
2457         },
2458 };
2459
2460 /* *** configure rss hash key *** */
2461 struct cmd_config_rss_hash_key {
2462         cmdline_fixed_string_t port;
2463         cmdline_fixed_string_t config;
2464         portid_t port_id;
2465         cmdline_fixed_string_t rss_hash_key;
2466         cmdline_fixed_string_t rss_type;
2467         cmdline_fixed_string_t key;
2468 };
2469
2470 static uint8_t
2471 hexa_digit_to_value(char hexa_digit)
2472 {
2473         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2474                 return (uint8_t) (hexa_digit - '0');
2475         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2476                 return (uint8_t) ((hexa_digit - 'a') + 10);
2477         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2478                 return (uint8_t) ((hexa_digit - 'A') + 10);
2479         /* Invalid hexa digit */
2480         return 0xFF;
2481 }
2482
2483 static uint8_t
2484 parse_and_check_key_hexa_digit(char *key, int idx)
2485 {
2486         uint8_t hexa_v;
2487
2488         hexa_v = hexa_digit_to_value(key[idx]);
2489         if (hexa_v == 0xFF)
2490                 printf("invalid key: character %c at position %d is not a "
2491                        "valid hexa digit\n", key[idx], idx);
2492         return hexa_v;
2493 }
2494
2495 static void
2496 cmd_config_rss_hash_key_parsed(void *parsed_result,
2497                                __rte_unused struct cmdline *cl,
2498                                __rte_unused void *data)
2499 {
2500         struct cmd_config_rss_hash_key *res = parsed_result;
2501         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2502         uint8_t xdgt0;
2503         uint8_t xdgt1;
2504         int i;
2505         struct rte_eth_dev_info dev_info;
2506         uint8_t hash_key_size;
2507         uint32_t key_len;
2508         int ret;
2509
2510         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2511         if (ret != 0)
2512                 return;
2513
2514         if (dev_info.hash_key_size > 0 &&
2515                         dev_info.hash_key_size <= sizeof(hash_key))
2516                 hash_key_size = dev_info.hash_key_size;
2517         else {
2518                 printf("dev_info did not provide a valid hash key size\n");
2519                 return;
2520         }
2521         /* Check the length of the RSS hash key */
2522         key_len = strlen(res->key);
2523         if (key_len != (hash_key_size * 2)) {
2524                 printf("key length: %d invalid - key must be a string of %d"
2525                            " hexa-decimal numbers\n",
2526                            (int) key_len, hash_key_size * 2);
2527                 return;
2528         }
2529         /* Translate RSS hash key into binary representation */
2530         for (i = 0; i < hash_key_size; i++) {
2531                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2532                 if (xdgt0 == 0xFF)
2533                         return;
2534                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2535                 if (xdgt1 == 0xFF)
2536                         return;
2537                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2538         }
2539         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2540                         hash_key_size);
2541 }
2542
2543 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2544         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2545 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2546         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2547                                  "config");
2548 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2549         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2550 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2551         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2552                                  rss_hash_key, "rss-hash-key");
2553 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2554         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2555                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2556                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2557                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2558                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2559                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2560                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2561                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2562 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2564
2565 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2566         .f = cmd_config_rss_hash_key_parsed,
2567         .data = NULL,
2568         .help_str = "port config <port_id> rss-hash-key "
2569                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2570                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2571                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2572                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2573                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2574                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2575                 "<string of hex digits (variable length, NIC dependent)>",
2576         .tokens = {
2577                 (void *)&cmd_config_rss_hash_key_port,
2578                 (void *)&cmd_config_rss_hash_key_config,
2579                 (void *)&cmd_config_rss_hash_key_port_id,
2580                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2581                 (void *)&cmd_config_rss_hash_key_rss_type,
2582                 (void *)&cmd_config_rss_hash_key_value,
2583                 NULL,
2584         },
2585 };
2586
2587 /* *** configure port rxq/txq ring size *** */
2588 struct cmd_config_rxtx_ring_size {
2589         cmdline_fixed_string_t port;
2590         cmdline_fixed_string_t config;
2591         portid_t portid;
2592         cmdline_fixed_string_t rxtxq;
2593         uint16_t qid;
2594         cmdline_fixed_string_t rsize;
2595         uint16_t size;
2596 };
2597
2598 static void
2599 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2600                                  __rte_unused struct cmdline *cl,
2601                                  __rte_unused void *data)
2602 {
2603         struct cmd_config_rxtx_ring_size *res = parsed_result;
2604         struct rte_port *port;
2605         uint8_t isrx;
2606
2607         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2608                 return;
2609
2610         if (res->portid == (portid_t)RTE_PORT_ALL) {
2611                 printf("Invalid port id\n");
2612                 return;
2613         }
2614
2615         port = &ports[res->portid];
2616
2617         if (!strcmp(res->rxtxq, "rxq"))
2618                 isrx = 1;
2619         else if (!strcmp(res->rxtxq, "txq"))
2620                 isrx = 0;
2621         else {
2622                 printf("Unknown parameter\n");
2623                 return;
2624         }
2625
2626         if (isrx && rx_queue_id_is_invalid(res->qid))
2627                 return;
2628         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2629                 return;
2630
2631         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2632                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2633                        rx_free_thresh);
2634                 return;
2635         }
2636
2637         if (isrx)
2638                 port->nb_rx_desc[res->qid] = res->size;
2639         else
2640                 port->nb_tx_desc[res->qid] = res->size;
2641
2642         cmd_reconfig_device_queue(res->portid, 0, 1);
2643 }
2644
2645 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2646         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2647                                  port, "port");
2648 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2649         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2650                                  config, "config");
2651 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2652         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2653                                  portid, UINT16);
2654 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2656                                  rxtxq, "rxq#txq");
2657 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2658         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2659                               qid, UINT16);
2660 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2661         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2662                                  rsize, "ring_size");
2663 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2664         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2665                               size, UINT16);
2666
2667 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2668         .f = cmd_config_rxtx_ring_size_parsed,
2669         .data = NULL,
2670         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2671         .tokens = {
2672                 (void *)&cmd_config_rxtx_ring_size_port,
2673                 (void *)&cmd_config_rxtx_ring_size_config,
2674                 (void *)&cmd_config_rxtx_ring_size_portid,
2675                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2676                 (void *)&cmd_config_rxtx_ring_size_qid,
2677                 (void *)&cmd_config_rxtx_ring_size_rsize,
2678                 (void *)&cmd_config_rxtx_ring_size_size,
2679                 NULL,
2680         },
2681 };
2682
2683 /* *** configure port rxq/txq start/stop *** */
2684 struct cmd_config_rxtx_queue {
2685         cmdline_fixed_string_t port;
2686         portid_t portid;
2687         cmdline_fixed_string_t rxtxq;
2688         uint16_t qid;
2689         cmdline_fixed_string_t opname;
2690 };
2691
2692 static void
2693 cmd_config_rxtx_queue_parsed(void *parsed_result,
2694                         __rte_unused struct cmdline *cl,
2695                         __rte_unused void *data)
2696 {
2697         struct cmd_config_rxtx_queue *res = parsed_result;
2698         uint8_t isrx;
2699         uint8_t isstart;
2700         int ret = 0;
2701
2702         if (test_done == 0) {
2703                 printf("Please stop forwarding first\n");
2704                 return;
2705         }
2706
2707         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2708                 return;
2709
2710         if (port_is_started(res->portid) != 1) {
2711                 printf("Please start port %u first\n", res->portid);
2712                 return;
2713         }
2714
2715         if (!strcmp(res->rxtxq, "rxq"))
2716                 isrx = 1;
2717         else if (!strcmp(res->rxtxq, "txq"))
2718                 isrx = 0;
2719         else {
2720                 printf("Unknown parameter\n");
2721                 return;
2722         }
2723
2724         if (isrx && rx_queue_id_is_invalid(res->qid))
2725                 return;
2726         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2727                 return;
2728
2729         if (!strcmp(res->opname, "start"))
2730                 isstart = 1;
2731         else if (!strcmp(res->opname, "stop"))
2732                 isstart = 0;
2733         else {
2734                 printf("Unknown parameter\n");
2735                 return;
2736         }
2737
2738         if (isstart && isrx)
2739                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2740         else if (!isstart && isrx)
2741                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2742         else if (isstart && !isrx)
2743                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2744         else
2745                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2746
2747         if (ret == -ENOTSUP)
2748                 printf("Function not supported in PMD driver\n");
2749 }
2750
2751 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2752         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2753 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2754         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2755 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2756         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2757 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2758         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2759 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2760         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2761                                                 "start#stop");
2762
2763 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2764         .f = cmd_config_rxtx_queue_parsed,
2765         .data = NULL,
2766         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2767         .tokens = {
2768                 (void *)&cmd_config_rxtx_queue_port,
2769                 (void *)&cmd_config_rxtx_queue_portid,
2770                 (void *)&cmd_config_rxtx_queue_rxtxq,
2771                 (void *)&cmd_config_rxtx_queue_qid,
2772                 (void *)&cmd_config_rxtx_queue_opname,
2773                 NULL,
2774         },
2775 };
2776
2777 /* *** configure port rxq/txq deferred start on/off *** */
2778 struct cmd_config_deferred_start_rxtx_queue {
2779         cmdline_fixed_string_t port;
2780         portid_t port_id;
2781         cmdline_fixed_string_t rxtxq;
2782         uint16_t qid;
2783         cmdline_fixed_string_t opname;
2784         cmdline_fixed_string_t state;
2785 };
2786
2787 static void
2788 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2789                         __rte_unused struct cmdline *cl,
2790                         __rte_unused void *data)
2791 {
2792         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2793         struct rte_port *port;
2794         uint8_t isrx;
2795         uint8_t ison;
2796         uint8_t needreconfig = 0;
2797
2798         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2799                 return;
2800
2801         if (port_is_started(res->port_id) != 0) {
2802                 printf("Please stop port %u first\n", res->port_id);
2803                 return;
2804         }
2805
2806         port = &ports[res->port_id];
2807
2808         isrx = !strcmp(res->rxtxq, "rxq");
2809
2810         if (isrx && rx_queue_id_is_invalid(res->qid))
2811                 return;
2812         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2813                 return;
2814
2815         ison = !strcmp(res->state, "on");
2816
2817         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2818                 port->rx_conf[res->qid].rx_deferred_start = ison;
2819                 needreconfig = 1;
2820         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2821                 port->tx_conf[res->qid].tx_deferred_start = ison;
2822                 needreconfig = 1;
2823         }
2824
2825         if (needreconfig)
2826                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2827 }
2828
2829 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2830         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2831                                                 port, "port");
2832 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2833         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2834                                                 port_id, UINT16);
2835 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2836         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2837                                                 rxtxq, "rxq#txq");
2838 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2839         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2840                                                 qid, UINT16);
2841 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2842         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2843                                                 opname, "deferred_start");
2844 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2845         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2846                                                 state, "on#off");
2847
2848 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2849         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2850         .data = NULL,
2851         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2852         .tokens = {
2853                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2854                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2855                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2856                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2857                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2858                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2859                 NULL,
2860         },
2861 };
2862
2863 /* *** configure port rxq/txq setup *** */
2864 struct cmd_setup_rxtx_queue {
2865         cmdline_fixed_string_t port;
2866         portid_t portid;
2867         cmdline_fixed_string_t rxtxq;
2868         uint16_t qid;
2869         cmdline_fixed_string_t setup;
2870 };
2871
2872 /* Common CLI fields for queue setup */
2873 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2874         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2875 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2876         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2877 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2878         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2879 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2880         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2881 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2882         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2883
2884 static void
2885 cmd_setup_rxtx_queue_parsed(
2886         void *parsed_result,
2887         __rte_unused struct cmdline *cl,
2888         __rte_unused void *data)
2889 {
2890         struct cmd_setup_rxtx_queue *res = parsed_result;
2891         struct rte_port *port;
2892         struct rte_mempool *mp;
2893         unsigned int socket_id;
2894         uint8_t isrx = 0;
2895         int ret;
2896
2897         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2898                 return;
2899
2900         if (res->portid == (portid_t)RTE_PORT_ALL) {
2901                 printf("Invalid port id\n");
2902                 return;
2903         }
2904
2905         if (!strcmp(res->rxtxq, "rxq"))
2906                 isrx = 1;
2907         else if (!strcmp(res->rxtxq, "txq"))
2908                 isrx = 0;
2909         else {
2910                 printf("Unknown parameter\n");
2911                 return;
2912         }
2913
2914         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2915                 printf("Invalid rx queue\n");
2916                 return;
2917         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2918                 printf("Invalid tx queue\n");
2919                 return;
2920         }
2921
2922         port = &ports[res->portid];
2923         if (isrx) {
2924                 socket_id = rxring_numa[res->portid];
2925                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2926                         socket_id = port->socket_id;
2927
2928                 mp = mbuf_pool_find(socket_id, 0);
2929                 if (mp == NULL) {
2930                         printf("Failed to setup RX queue: "
2931                                 "No mempool allocation"
2932                                 " on the socket %d\n",
2933                                 rxring_numa[res->portid]);
2934                         return;
2935                 }
2936                 ret = rte_eth_rx_queue_setup(res->portid,
2937                                              res->qid,
2938                                              port->nb_rx_desc[res->qid],
2939                                              socket_id,
2940                                              &port->rx_conf[res->qid],
2941                                              mp);
2942                 if (ret)
2943                         printf("Failed to setup RX queue\n");
2944         } else {
2945                 socket_id = txring_numa[res->portid];
2946                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2947                         socket_id = port->socket_id;
2948
2949                 ret = rte_eth_tx_queue_setup(res->portid,
2950                                              res->qid,
2951                                              port->nb_tx_desc[res->qid],
2952                                              socket_id,
2953                                              &port->tx_conf[res->qid]);
2954                 if (ret)
2955                         printf("Failed to setup TX queue\n");
2956         }
2957 }
2958
2959 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2960         .f = cmd_setup_rxtx_queue_parsed,
2961         .data = NULL,
2962         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2963         .tokens = {
2964                 (void *)&cmd_setup_rxtx_queue_port,
2965                 (void *)&cmd_setup_rxtx_queue_portid,
2966                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2967                 (void *)&cmd_setup_rxtx_queue_qid,
2968                 (void *)&cmd_setup_rxtx_queue_setup,
2969                 NULL,
2970         },
2971 };
2972
2973
2974 /* *** Configure RSS RETA *** */
2975 struct cmd_config_rss_reta {
2976         cmdline_fixed_string_t port;
2977         cmdline_fixed_string_t keyword;
2978         portid_t port_id;
2979         cmdline_fixed_string_t name;
2980         cmdline_fixed_string_t list_name;
2981         cmdline_fixed_string_t list_of_items;
2982 };
2983
2984 static int
2985 parse_reta_config(const char *str,
2986                   struct rte_eth_rss_reta_entry64 *reta_conf,
2987                   uint16_t nb_entries)
2988 {
2989         int i;
2990         unsigned size;
2991         uint16_t hash_index, idx, shift;
2992         uint16_t nb_queue;
2993         char s[256];
2994         const char *p, *p0 = str;
2995         char *end;
2996         enum fieldnames {
2997                 FLD_HASH_INDEX = 0,
2998                 FLD_QUEUE,
2999                 _NUM_FLD
3000         };
3001         unsigned long int_fld[_NUM_FLD];
3002         char *str_fld[_NUM_FLD];
3003
3004         while ((p = strchr(p0,'(')) != NULL) {
3005                 ++p;
3006                 if((p0 = strchr(p,')')) == NULL)
3007                         return -1;
3008
3009                 size = p0 - p;
3010                 if(size >= sizeof(s))
3011                         return -1;
3012
3013                 snprintf(s, sizeof(s), "%.*s", size, p);
3014                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3015                         return -1;
3016                 for (i = 0; i < _NUM_FLD; i++) {
3017                         errno = 0;
3018                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3019                         if (errno != 0 || end == str_fld[i] ||
3020                                         int_fld[i] > 65535)
3021                                 return -1;
3022                 }
3023
3024                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3025                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3026
3027                 if (hash_index >= nb_entries) {
3028                         printf("Invalid RETA hash index=%d\n", hash_index);
3029                         return -1;
3030                 }
3031
3032                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3033                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3034                 reta_conf[idx].mask |= (1ULL << shift);
3035                 reta_conf[idx].reta[shift] = nb_queue;
3036         }
3037
3038         return 0;
3039 }
3040
3041 static void
3042 cmd_set_rss_reta_parsed(void *parsed_result,
3043                         __rte_unused struct cmdline *cl,
3044                         __rte_unused void *data)
3045 {
3046         int ret;
3047         struct rte_eth_dev_info dev_info;
3048         struct rte_eth_rss_reta_entry64 reta_conf[8];
3049         struct cmd_config_rss_reta *res = parsed_result;
3050
3051         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3052         if (ret != 0)
3053                 return;
3054
3055         if (dev_info.reta_size == 0) {
3056                 printf("Redirection table size is 0 which is "
3057                                         "invalid for RSS\n");
3058                 return;
3059         } else
3060                 printf("The reta size of port %d is %u\n",
3061                         res->port_id, dev_info.reta_size);
3062         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3063                 printf("Currently do not support more than %u entries of "
3064                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3065                 return;
3066         }
3067
3068         memset(reta_conf, 0, sizeof(reta_conf));
3069         if (!strcmp(res->list_name, "reta")) {
3070                 if (parse_reta_config(res->list_of_items, reta_conf,
3071                                                 dev_info.reta_size)) {
3072                         printf("Invalid RSS Redirection Table "
3073                                         "config entered\n");
3074                         return;
3075                 }
3076                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3077                                 reta_conf, dev_info.reta_size);
3078                 if (ret != 0)
3079                         printf("Bad redirection table parameter, "
3080                                         "return code = %d \n", ret);
3081         }
3082 }
3083
3084 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3085         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3086 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3087         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3088 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3089         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3090 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3091         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3092 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3094 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3095         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3096                                  NULL);
3097 cmdline_parse_inst_t cmd_config_rss_reta = {
3098         .f = cmd_set_rss_reta_parsed,
3099         .data = NULL,
3100         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3101         .tokens = {
3102                 (void *)&cmd_config_rss_reta_port,
3103                 (void *)&cmd_config_rss_reta_keyword,
3104                 (void *)&cmd_config_rss_reta_port_id,
3105                 (void *)&cmd_config_rss_reta_name,
3106                 (void *)&cmd_config_rss_reta_list_name,
3107                 (void *)&cmd_config_rss_reta_list_of_items,
3108                 NULL,
3109         },
3110 };
3111
3112 /* *** SHOW PORT RETA INFO *** */
3113 struct cmd_showport_reta {
3114         cmdline_fixed_string_t show;
3115         cmdline_fixed_string_t port;
3116         portid_t port_id;
3117         cmdline_fixed_string_t rss;
3118         cmdline_fixed_string_t reta;
3119         uint16_t size;
3120         cmdline_fixed_string_t list_of_items;
3121 };
3122
3123 static int
3124 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3125                            uint16_t nb_entries,
3126                            char *str)
3127 {
3128         uint32_t size;
3129         const char *p, *p0 = str;
3130         char s[256];
3131         char *end;
3132         char *str_fld[8];
3133         uint16_t i;
3134         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3135                         RTE_RETA_GROUP_SIZE;
3136         int ret;
3137
3138         p = strchr(p0, '(');
3139         if (p == NULL)
3140                 return -1;
3141         p++;
3142         p0 = strchr(p, ')');
3143         if (p0 == NULL)
3144                 return -1;
3145         size = p0 - p;
3146         if (size >= sizeof(s)) {
3147                 printf("The string size exceeds the internal buffer size\n");
3148                 return -1;
3149         }
3150         snprintf(s, sizeof(s), "%.*s", size, p);
3151         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3152         if (ret <= 0 || ret != num) {
3153                 printf("The bits of masks do not match the number of "
3154                                         "reta entries: %u\n", num);
3155                 return -1;
3156         }
3157         for (i = 0; i < ret; i++)
3158                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3159
3160         return 0;
3161 }
3162
3163 static void
3164 cmd_showport_reta_parsed(void *parsed_result,
3165                          __rte_unused struct cmdline *cl,
3166                          __rte_unused void *data)
3167 {
3168         struct cmd_showport_reta *res = parsed_result;
3169         struct rte_eth_rss_reta_entry64 reta_conf[8];
3170         struct rte_eth_dev_info dev_info;
3171         uint16_t max_reta_size;
3172         int ret;
3173
3174         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3175         if (ret != 0)
3176                 return;
3177
3178         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3179         if (res->size == 0 || res->size > max_reta_size) {
3180                 printf("Invalid redirection table size: %u (1-%u)\n",
3181                         res->size, max_reta_size);
3182                 return;
3183         }
3184
3185         memset(reta_conf, 0, sizeof(reta_conf));
3186         if (showport_parse_reta_config(reta_conf, res->size,
3187                                 res->list_of_items) < 0) {
3188                 printf("Invalid string: %s for reta masks\n",
3189                                         res->list_of_items);
3190                 return;
3191         }
3192         port_rss_reta_info(res->port_id, reta_conf, res->size);
3193 }
3194
3195 cmdline_parse_token_string_t cmd_showport_reta_show =
3196         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3197 cmdline_parse_token_string_t cmd_showport_reta_port =
3198         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3199 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3200         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3201 cmdline_parse_token_string_t cmd_showport_reta_rss =
3202         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3203 cmdline_parse_token_string_t cmd_showport_reta_reta =
3204         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3205 cmdline_parse_token_num_t cmd_showport_reta_size =
3206         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3207 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3208         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3209                                         list_of_items, NULL);
3210
3211 cmdline_parse_inst_t cmd_showport_reta = {
3212         .f = cmd_showport_reta_parsed,
3213         .data = NULL,
3214         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3215         .tokens = {
3216                 (void *)&cmd_showport_reta_show,
3217                 (void *)&cmd_showport_reta_port,
3218                 (void *)&cmd_showport_reta_port_id,
3219                 (void *)&cmd_showport_reta_rss,
3220                 (void *)&cmd_showport_reta_reta,
3221                 (void *)&cmd_showport_reta_size,
3222                 (void *)&cmd_showport_reta_list_of_items,
3223                 NULL,
3224         },
3225 };
3226
3227 /* *** Show RSS hash configuration *** */
3228 struct cmd_showport_rss_hash {
3229         cmdline_fixed_string_t show;
3230         cmdline_fixed_string_t port;
3231         portid_t port_id;
3232         cmdline_fixed_string_t rss_hash;
3233         cmdline_fixed_string_t rss_type;
3234         cmdline_fixed_string_t key; /* optional argument */
3235 };
3236
3237 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3238                                 __rte_unused struct cmdline *cl,
3239                                 void *show_rss_key)
3240 {
3241         struct cmd_showport_rss_hash *res = parsed_result;
3242
3243         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3244 }
3245
3246 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3247         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3248 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3249         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3250 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3251         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3252 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3254                                  "rss-hash");
3255 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3256         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3257
3258 cmdline_parse_inst_t cmd_showport_rss_hash = {
3259         .f = cmd_showport_rss_hash_parsed,
3260         .data = NULL,
3261         .help_str = "show port <port_id> rss-hash",
3262         .tokens = {
3263                 (void *)&cmd_showport_rss_hash_show,
3264                 (void *)&cmd_showport_rss_hash_port,
3265                 (void *)&cmd_showport_rss_hash_port_id,
3266                 (void *)&cmd_showport_rss_hash_rss_hash,
3267                 NULL,
3268         },
3269 };
3270
3271 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3272         .f = cmd_showport_rss_hash_parsed,
3273         .data = (void *)1,
3274         .help_str = "show port <port_id> rss-hash key",
3275         .tokens = {
3276                 (void *)&cmd_showport_rss_hash_show,
3277                 (void *)&cmd_showport_rss_hash_port,
3278                 (void *)&cmd_showport_rss_hash_port_id,
3279                 (void *)&cmd_showport_rss_hash_rss_hash,
3280                 (void *)&cmd_showport_rss_hash_rss_key,
3281                 NULL,
3282         },
3283 };
3284
3285 /* *** Configure DCB *** */
3286 struct cmd_config_dcb {
3287         cmdline_fixed_string_t port;
3288         cmdline_fixed_string_t config;
3289         portid_t port_id;
3290         cmdline_fixed_string_t dcb;
3291         cmdline_fixed_string_t vt;
3292         cmdline_fixed_string_t vt_en;
3293         uint8_t num_tcs;
3294         cmdline_fixed_string_t pfc;
3295         cmdline_fixed_string_t pfc_en;
3296 };
3297
3298 static void
3299 cmd_config_dcb_parsed(void *parsed_result,
3300                         __rte_unused struct cmdline *cl,
3301                         __rte_unused void *data)
3302 {
3303         struct cmd_config_dcb *res = parsed_result;
3304         portid_t port_id = res->port_id;
3305         struct rte_port *port;
3306         uint8_t pfc_en;
3307         int ret;
3308
3309         port = &ports[port_id];
3310         /** Check if the port is not started **/
3311         if (port->port_status != RTE_PORT_STOPPED) {
3312                 printf("Please stop port %d first\n", port_id);
3313                 return;
3314         }
3315
3316         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3317                 printf("The invalid number of traffic class,"
3318                         " only 4 or 8 allowed.\n");
3319                 return;
3320         }
3321
3322         if (nb_fwd_lcores < res->num_tcs) {
3323                 printf("nb_cores shouldn't be less than number of TCs.\n");
3324                 return;
3325         }
3326         if (!strncmp(res->pfc_en, "on", 2))
3327                 pfc_en = 1;
3328         else
3329                 pfc_en = 0;
3330
3331         /* DCB in VT mode */
3332         if (!strncmp(res->vt_en, "on", 2))
3333                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3334                                 (enum rte_eth_nb_tcs)res->num_tcs,
3335                                 pfc_en);
3336         else
3337                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3338                                 (enum rte_eth_nb_tcs)res->num_tcs,
3339                                 pfc_en);
3340
3341
3342         if (ret != 0) {
3343                 printf("Cannot initialize network ports.\n");
3344                 return;
3345         }
3346
3347         cmd_reconfig_device_queue(port_id, 1, 1);
3348 }
3349
3350 cmdline_parse_token_string_t cmd_config_dcb_port =
3351         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3352 cmdline_parse_token_string_t cmd_config_dcb_config =
3353         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3354 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3355         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3356 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3357         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3358 cmdline_parse_token_string_t cmd_config_dcb_vt =
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3360 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3361         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3362 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3363         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3364 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3365         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3366 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3368
3369 cmdline_parse_inst_t cmd_config_dcb = {
3370         .f = cmd_config_dcb_parsed,
3371         .data = NULL,
3372         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3373         .tokens = {
3374                 (void *)&cmd_config_dcb_port,
3375                 (void *)&cmd_config_dcb_config,
3376                 (void *)&cmd_config_dcb_port_id,
3377                 (void *)&cmd_config_dcb_dcb,
3378                 (void *)&cmd_config_dcb_vt,
3379                 (void *)&cmd_config_dcb_vt_en,
3380                 (void *)&cmd_config_dcb_num_tcs,
3381                 (void *)&cmd_config_dcb_pfc,
3382                 (void *)&cmd_config_dcb_pfc_en,
3383                 NULL,
3384         },
3385 };
3386
3387 /* *** configure number of packets per burst *** */
3388 struct cmd_config_burst {
3389         cmdline_fixed_string_t port;
3390         cmdline_fixed_string_t keyword;
3391         cmdline_fixed_string_t all;
3392         cmdline_fixed_string_t name;
3393         uint16_t value;
3394 };
3395
3396 static void
3397 cmd_config_burst_parsed(void *parsed_result,
3398                         __rte_unused struct cmdline *cl,
3399                         __rte_unused void *data)
3400 {
3401         struct cmd_config_burst *res = parsed_result;
3402         struct rte_eth_dev_info dev_info;
3403         uint16_t rec_nb_pkts;
3404         int ret;
3405
3406         if (!all_ports_stopped()) {
3407                 printf("Please stop all ports first\n");
3408                 return;
3409         }
3410
3411         if (!strcmp(res->name, "burst")) {
3412                 if (res->value == 0) {
3413                         /* If user gives a value of zero, query the PMD for
3414                          * its recommended Rx burst size. Testpmd uses a single
3415                          * size for all ports, so assume all ports are the same
3416                          * NIC model and use the values from Port 0.
3417                          */
3418                         ret = eth_dev_info_get_print_err(0, &dev_info);
3419                         if (ret != 0)
3420                                 return;
3421
3422                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3423
3424                         if (rec_nb_pkts == 0) {
3425                                 printf("PMD does not recommend a burst size.\n"
3426                                         "User provided value must be between"
3427                                         " 1 and %d\n", MAX_PKT_BURST);
3428                                 return;
3429                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3430                                 printf("PMD recommended burst size of %d"
3431                                         " exceeds maximum value of %d\n",
3432                                         rec_nb_pkts, MAX_PKT_BURST);
3433                                 return;
3434                         }
3435                         printf("Using PMD-provided burst value of %d\n",
3436                                 rec_nb_pkts);
3437                         nb_pkt_per_burst = rec_nb_pkts;
3438                 } else if (res->value > MAX_PKT_BURST) {
3439                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3440                         return;
3441                 } else
3442                         nb_pkt_per_burst = res->value;
3443         } else {
3444                 printf("Unknown parameter\n");
3445                 return;
3446         }
3447
3448         init_port_config();
3449
3450         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3451 }
3452
3453 cmdline_parse_token_string_t cmd_config_burst_port =
3454         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3455 cmdline_parse_token_string_t cmd_config_burst_keyword =
3456         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3457 cmdline_parse_token_string_t cmd_config_burst_all =
3458         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3459 cmdline_parse_token_string_t cmd_config_burst_name =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3461 cmdline_parse_token_num_t cmd_config_burst_value =
3462         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3463
3464 cmdline_parse_inst_t cmd_config_burst = {
3465         .f = cmd_config_burst_parsed,
3466         .data = NULL,
3467         .help_str = "port config all burst <value>",
3468         .tokens = {
3469                 (void *)&cmd_config_burst_port,
3470                 (void *)&cmd_config_burst_keyword,
3471                 (void *)&cmd_config_burst_all,
3472                 (void *)&cmd_config_burst_name,
3473                 (void *)&cmd_config_burst_value,
3474                 NULL,
3475         },
3476 };
3477
3478 /* *** configure rx/tx queues *** */
3479 struct cmd_config_thresh {
3480         cmdline_fixed_string_t port;
3481         cmdline_fixed_string_t keyword;
3482         cmdline_fixed_string_t all;
3483         cmdline_fixed_string_t name;
3484         uint8_t value;
3485 };
3486
3487 static void
3488 cmd_config_thresh_parsed(void *parsed_result,
3489                         __rte_unused struct cmdline *cl,
3490                         __rte_unused void *data)
3491 {
3492         struct cmd_config_thresh *res = parsed_result;
3493
3494         if (!all_ports_stopped()) {
3495                 printf("Please stop all ports first\n");
3496                 return;
3497         }
3498
3499         if (!strcmp(res->name, "txpt"))
3500                 tx_pthresh = res->value;
3501         else if(!strcmp(res->name, "txht"))
3502                 tx_hthresh = res->value;
3503         else if(!strcmp(res->name, "txwt"))
3504                 tx_wthresh = res->value;
3505         else if(!strcmp(res->name, "rxpt"))
3506                 rx_pthresh = res->value;
3507         else if(!strcmp(res->name, "rxht"))
3508                 rx_hthresh = res->value;
3509         else if(!strcmp(res->name, "rxwt"))
3510                 rx_wthresh = res->value;
3511         else {
3512                 printf("Unknown parameter\n");
3513                 return;
3514         }
3515
3516         init_port_config();
3517
3518         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3519 }
3520
3521 cmdline_parse_token_string_t cmd_config_thresh_port =
3522         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3523 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3524         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3525 cmdline_parse_token_string_t cmd_config_thresh_all =
3526         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3527 cmdline_parse_token_string_t cmd_config_thresh_name =
3528         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3529                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3530 cmdline_parse_token_num_t cmd_config_thresh_value =
3531         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3532
3533 cmdline_parse_inst_t cmd_config_thresh = {
3534         .f = cmd_config_thresh_parsed,
3535         .data = NULL,
3536         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3537         .tokens = {
3538                 (void *)&cmd_config_thresh_port,
3539                 (void *)&cmd_config_thresh_keyword,
3540                 (void *)&cmd_config_thresh_all,
3541                 (void *)&cmd_config_thresh_name,
3542                 (void *)&cmd_config_thresh_value,
3543                 NULL,
3544         },
3545 };
3546
3547 /* *** configure free/rs threshold *** */
3548 struct cmd_config_threshold {
3549         cmdline_fixed_string_t port;
3550         cmdline_fixed_string_t keyword;
3551         cmdline_fixed_string_t all;
3552         cmdline_fixed_string_t name;
3553         uint16_t value;
3554 };
3555
3556 static void
3557 cmd_config_threshold_parsed(void *parsed_result,
3558                         __rte_unused struct cmdline *cl,
3559                         __rte_unused void *data)
3560 {
3561         struct cmd_config_threshold *res = parsed_result;
3562
3563         if (!all_ports_stopped()) {
3564                 printf("Please stop all ports first\n");
3565                 return;
3566         }
3567
3568         if (!strcmp(res->name, "txfreet"))
3569                 tx_free_thresh = res->value;
3570         else if (!strcmp(res->name, "txrst"))
3571                 tx_rs_thresh = res->value;
3572         else if (!strcmp(res->name, "rxfreet"))
3573                 rx_free_thresh = res->value;
3574         else {
3575                 printf("Unknown parameter\n");
3576                 return;
3577         }
3578
3579         init_port_config();
3580
3581         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3582 }
3583
3584 cmdline_parse_token_string_t cmd_config_threshold_port =
3585         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3586 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3587         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3588                                                                 "config");
3589 cmdline_parse_token_string_t cmd_config_threshold_all =
3590         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3591 cmdline_parse_token_string_t cmd_config_threshold_name =
3592         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3593                                                 "txfreet#txrst#rxfreet");
3594 cmdline_parse_token_num_t cmd_config_threshold_value =
3595         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3596
3597 cmdline_parse_inst_t cmd_config_threshold = {
3598         .f = cmd_config_threshold_parsed,
3599         .data = NULL,
3600         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3601         .tokens = {
3602                 (void *)&cmd_config_threshold_port,
3603                 (void *)&cmd_config_threshold_keyword,
3604                 (void *)&cmd_config_threshold_all,
3605                 (void *)&cmd_config_threshold_name,
3606                 (void *)&cmd_config_threshold_value,
3607                 NULL,
3608         },
3609 };
3610
3611 /* *** stop *** */
3612 struct cmd_stop_result {
3613         cmdline_fixed_string_t stop;
3614 };
3615
3616 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3617                             __rte_unused struct cmdline *cl,
3618                             __rte_unused void *data)
3619 {
3620         stop_packet_forwarding();
3621 }
3622
3623 cmdline_parse_token_string_t cmd_stop_stop =
3624         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3625
3626 cmdline_parse_inst_t cmd_stop = {
3627         .f = cmd_stop_parsed,
3628         .data = NULL,
3629         .help_str = "stop: Stop packet forwarding",
3630         .tokens = {
3631                 (void *)&cmd_stop_stop,
3632                 NULL,
3633         },
3634 };
3635
3636 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3637
3638 unsigned int
3639 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3640                 unsigned int *parsed_items, int check_unique_values)
3641 {
3642         unsigned int nb_item;
3643         unsigned int value;
3644         unsigned int i;
3645         unsigned int j;
3646         int value_ok;
3647         char c;
3648
3649         /*
3650          * First parse all items in the list and store their value.
3651          */
3652         value = 0;
3653         nb_item = 0;
3654         value_ok = 0;
3655         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3656                 c = str[i];
3657                 if ((c >= '0') && (c <= '9')) {
3658                         value = (unsigned int) (value * 10 + (c - '0'));
3659                         value_ok = 1;
3660                         continue;
3661                 }
3662                 if (c != ',') {
3663                         printf("character %c is not a decimal digit\n", c);
3664                         return 0;
3665                 }
3666                 if (! value_ok) {
3667                         printf("No valid value before comma\n");
3668                         return 0;
3669                 }
3670                 if (nb_item < max_items) {
3671                         parsed_items[nb_item] = value;
3672                         value_ok = 0;
3673                         value = 0;
3674                 }
3675                 nb_item++;
3676         }
3677         if (nb_item >= max_items) {
3678                 printf("Number of %s = %u > %u (maximum items)\n",
3679                        item_name, nb_item + 1, max_items);
3680                 return 0;
3681         }
3682         parsed_items[nb_item++] = value;
3683         if (! check_unique_values)
3684                 return nb_item;
3685
3686         /*
3687          * Then, check that all values in the list are differents.
3688          * No optimization here...
3689          */
3690         for (i = 0; i < nb_item; i++) {
3691                 for (j = i + 1; j < nb_item; j++) {
3692                         if (parsed_items[j] == parsed_items[i]) {
3693                                 printf("duplicated %s %u at index %u and %u\n",
3694                                        item_name, parsed_items[i], i, j);
3695                                 return 0;
3696                         }
3697                 }
3698         }
3699         return nb_item;
3700 }
3701
3702 struct cmd_set_list_result {
3703         cmdline_fixed_string_t cmd_keyword;
3704         cmdline_fixed_string_t list_name;
3705         cmdline_fixed_string_t list_of_items;
3706 };
3707
3708 static void cmd_set_list_parsed(void *parsed_result,
3709                                 __rte_unused struct cmdline *cl,
3710                                 __rte_unused void *data)
3711 {
3712         struct cmd_set_list_result *res;
3713         union {
3714                 unsigned int lcorelist[RTE_MAX_LCORE];
3715                 unsigned int portlist[RTE_MAX_ETHPORTS];
3716         } parsed_items;
3717         unsigned int nb_item;
3718
3719         if (test_done == 0) {
3720                 printf("Please stop forwarding first\n");
3721                 return;
3722         }
3723
3724         res = parsed_result;
3725         if (!strcmp(res->list_name, "corelist")) {
3726                 nb_item = parse_item_list(res->list_of_items, "core",
3727                                           RTE_MAX_LCORE,
3728                                           parsed_items.lcorelist, 1);
3729                 if (nb_item > 0) {
3730                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3731                         fwd_config_setup();
3732                 }
3733                 return;
3734         }
3735         if (!strcmp(res->list_name, "portlist")) {
3736                 nb_item = parse_item_list(res->list_of_items, "port",
3737                                           RTE_MAX_ETHPORTS,
3738                                           parsed_items.portlist, 1);
3739                 if (nb_item > 0) {
3740                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3741                         fwd_config_setup();
3742                 }
3743         }
3744 }
3745
3746 cmdline_parse_token_string_t cmd_set_list_keyword =
3747         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3748                                  "set");
3749 cmdline_parse_token_string_t cmd_set_list_name =
3750         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3751                                  "corelist#portlist");
3752 cmdline_parse_token_string_t cmd_set_list_of_items =
3753         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3754                                  NULL);
3755
3756 cmdline_parse_inst_t cmd_set_fwd_list = {
3757         .f = cmd_set_list_parsed,
3758         .data = NULL,
3759         .help_str = "set corelist|portlist <list0[,list1]*>",
3760         .tokens = {
3761                 (void *)&cmd_set_list_keyword,
3762                 (void *)&cmd_set_list_name,
3763                 (void *)&cmd_set_list_of_items,
3764                 NULL,
3765         },
3766 };
3767
3768 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3769
3770 struct cmd_setmask_result {
3771         cmdline_fixed_string_t set;
3772         cmdline_fixed_string_t mask;
3773         uint64_t hexavalue;
3774 };
3775
3776 static void cmd_set_mask_parsed(void *parsed_result,
3777                                 __rte_unused struct cmdline *cl,
3778                                 __rte_unused void *data)
3779 {
3780         struct cmd_setmask_result *res = parsed_result;
3781
3782         if (test_done == 0) {
3783                 printf("Please stop forwarding first\n");
3784                 return;
3785         }
3786         if (!strcmp(res->mask, "coremask")) {
3787                 set_fwd_lcores_mask(res->hexavalue);
3788                 fwd_config_setup();
3789         } else if (!strcmp(res->mask, "portmask")) {
3790                 set_fwd_ports_mask(res->hexavalue);
3791                 fwd_config_setup();
3792         }
3793 }
3794
3795 cmdline_parse_token_string_t cmd_setmask_set =
3796         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3797 cmdline_parse_token_string_t cmd_setmask_mask =
3798         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3799                                  "coremask#portmask");
3800 cmdline_parse_token_num_t cmd_setmask_value =
3801         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3802
3803 cmdline_parse_inst_t cmd_set_fwd_mask = {
3804         .f = cmd_set_mask_parsed,
3805         .data = NULL,
3806         .help_str = "set coremask|portmask <hexadecimal value>",
3807         .tokens = {
3808                 (void *)&cmd_setmask_set,
3809                 (void *)&cmd_setmask_mask,
3810                 (void *)&cmd_setmask_value,
3811                 NULL,
3812         },
3813 };
3814
3815 /*
3816  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3817  */
3818 struct cmd_set_result {
3819         cmdline_fixed_string_t set;
3820         cmdline_fixed_string_t what;
3821         uint16_t value;
3822 };
3823
3824 static void cmd_set_parsed(void *parsed_result,
3825                            __rte_unused struct cmdline *cl,
3826                            __rte_unused void *data)
3827 {
3828         struct cmd_set_result *res = parsed_result;
3829         if (!strcmp(res->what, "nbport")) {
3830                 set_fwd_ports_number(res->value);
3831                 fwd_config_setup();
3832         } else if (!strcmp(res->what, "nbcore")) {
3833                 set_fwd_lcores_number(res->value);
3834                 fwd_config_setup();
3835         } else if (!strcmp(res->what, "burst"))
3836                 set_nb_pkt_per_burst(res->value);
3837         else if (!strcmp(res->what, "verbose"))
3838                 set_verbose_level(res->value);
3839 }
3840
3841 cmdline_parse_token_string_t cmd_set_set =
3842         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3843 cmdline_parse_token_string_t cmd_set_what =
3844         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3845                                  "nbport#nbcore#burst#verbose");
3846 cmdline_parse_token_num_t cmd_set_value =
3847         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3848
3849 cmdline_parse_inst_t cmd_set_numbers = {
3850         .f = cmd_set_parsed,
3851         .data = NULL,
3852         .help_str = "set nbport|nbcore|burst|verbose <value>",
3853         .tokens = {
3854                 (void *)&cmd_set_set,
3855                 (void *)&cmd_set_what,
3856                 (void *)&cmd_set_value,
3857                 NULL,
3858         },
3859 };
3860
3861 /* *** SET LOG LEVEL CONFIGURATION *** */
3862
3863 struct cmd_set_log_result {
3864         cmdline_fixed_string_t set;
3865         cmdline_fixed_string_t log;
3866         cmdline_fixed_string_t type;
3867         uint32_t level;
3868 };
3869
3870 static void
3871 cmd_set_log_parsed(void *parsed_result,
3872                    __rte_unused struct cmdline *cl,
3873                    __rte_unused void *data)
3874 {
3875         struct cmd_set_log_result *res;
3876         int ret;
3877
3878         res = parsed_result;
3879         if (!strcmp(res->type, "global"))
3880                 rte_log_set_global_level(res->level);
3881         else {
3882                 ret = rte_log_set_level_regexp(res->type, res->level);
3883                 if (ret < 0)
3884                         printf("Unable to set log level\n");
3885         }
3886 }
3887
3888 cmdline_parse_token_string_t cmd_set_log_set =
3889         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3890 cmdline_parse_token_string_t cmd_set_log_log =
3891         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3892 cmdline_parse_token_string_t cmd_set_log_type =
3893         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3894 cmdline_parse_token_num_t cmd_set_log_level =
3895         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3896
3897 cmdline_parse_inst_t cmd_set_log = {
3898         .f = cmd_set_log_parsed,
3899         .data = NULL,
3900         .help_str = "set log global|<type> <level>",
3901         .tokens = {
3902                 (void *)&cmd_set_log_set,
3903                 (void *)&cmd_set_log_log,
3904                 (void *)&cmd_set_log_type,
3905                 (void *)&cmd_set_log_level,
3906                 NULL,
3907         },
3908 };
3909
3910 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3911
3912 struct cmd_set_txpkts_result {
3913         cmdline_fixed_string_t cmd_keyword;
3914         cmdline_fixed_string_t txpkts;
3915         cmdline_fixed_string_t seg_lengths;
3916 };
3917
3918 static void
3919 cmd_set_txpkts_parsed(void *parsed_result,
3920                       __rte_unused struct cmdline *cl,
3921                       __rte_unused void *data)
3922 {
3923         struct cmd_set_txpkts_result *res;
3924         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3925         unsigned int nb_segs;
3926
3927         res = parsed_result;
3928         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3929                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3930         if (nb_segs > 0)
3931                 set_tx_pkt_segments(seg_lengths, nb_segs);
3932 }
3933
3934 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3935         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3936                                  cmd_keyword, "set");
3937 cmdline_parse_token_string_t cmd_set_txpkts_name =
3938         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3939                                  txpkts, "txpkts");
3940 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3941         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3942                                  seg_lengths, NULL);
3943
3944 cmdline_parse_inst_t cmd_set_txpkts = {
3945         .f = cmd_set_txpkts_parsed,
3946         .data = NULL,
3947         .help_str = "set txpkts <len0[,len1]*>",
3948         .tokens = {
3949                 (void *)&cmd_set_txpkts_keyword,
3950                 (void *)&cmd_set_txpkts_name,
3951                 (void *)&cmd_set_txpkts_lengths,
3952                 NULL,
3953         },
3954 };
3955
3956 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3957
3958 struct cmd_set_txsplit_result {
3959         cmdline_fixed_string_t cmd_keyword;
3960         cmdline_fixed_string_t txsplit;
3961         cmdline_fixed_string_t mode;
3962 };
3963
3964 static void
3965 cmd_set_txsplit_parsed(void *parsed_result,
3966                       __rte_unused struct cmdline *cl,
3967                       __rte_unused void *data)
3968 {
3969         struct cmd_set_txsplit_result *res;
3970
3971         res = parsed_result;
3972         set_tx_pkt_split(res->mode);
3973 }
3974
3975 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3976         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3977                                  cmd_keyword, "set");
3978 cmdline_parse_token_string_t cmd_set_txsplit_name =
3979         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3980                                  txsplit, "txsplit");
3981 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3982         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3983                                  mode, NULL);
3984
3985 cmdline_parse_inst_t cmd_set_txsplit = {
3986         .f = cmd_set_txsplit_parsed,
3987         .data = NULL,
3988         .help_str = "set txsplit on|off|rand",
3989         .tokens = {
3990                 (void *)&cmd_set_txsplit_keyword,
3991                 (void *)&cmd_set_txsplit_name,
3992                 (void *)&cmd_set_txsplit_mode,
3993                 NULL,
3994         },
3995 };
3996
3997 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
3998
3999 struct cmd_set_txtimes_result {
4000         cmdline_fixed_string_t cmd_keyword;
4001         cmdline_fixed_string_t txtimes;
4002         cmdline_fixed_string_t tx_times;
4003 };
4004
4005 static void
4006 cmd_set_txtimes_parsed(void *parsed_result,
4007                        __rte_unused struct cmdline *cl,
4008                        __rte_unused void *data)
4009 {
4010         struct cmd_set_txtimes_result *res;
4011         unsigned int tx_times[2] = {0, 0};
4012         unsigned int n_times;
4013
4014         res = parsed_result;
4015         n_times = parse_item_list(res->tx_times, "tx times",
4016                                   2, tx_times, 0);
4017         if (n_times == 2)
4018                 set_tx_pkt_times(tx_times);
4019 }
4020
4021 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4022         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4023                                  cmd_keyword, "set");
4024 cmdline_parse_token_string_t cmd_set_txtimes_name =
4025         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4026                                  txtimes, "txtimes");
4027 cmdline_parse_token_string_t cmd_set_txtimes_value =
4028         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4029                                  tx_times, NULL);
4030
4031 cmdline_parse_inst_t cmd_set_txtimes = {
4032         .f = cmd_set_txtimes_parsed,
4033         .data = NULL,
4034         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4035         .tokens = {
4036                 (void *)&cmd_set_txtimes_keyword,
4037                 (void *)&cmd_set_txtimes_name,
4038                 (void *)&cmd_set_txtimes_value,
4039                 NULL,
4040         },
4041 };
4042
4043 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4044 struct cmd_rx_vlan_filter_all_result {
4045         cmdline_fixed_string_t rx_vlan;
4046         cmdline_fixed_string_t what;
4047         cmdline_fixed_string_t all;
4048         portid_t port_id;
4049 };
4050
4051 static void
4052 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4053                               __rte_unused struct cmdline *cl,
4054                               __rte_unused void *data)
4055 {
4056         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4057
4058         if (!strcmp(res->what, "add"))
4059                 rx_vlan_all_filter_set(res->port_id, 1);
4060         else
4061                 rx_vlan_all_filter_set(res->port_id, 0);
4062 }
4063
4064 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4065         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4066                                  rx_vlan, "rx_vlan");
4067 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4068         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4069                                  what, "add#rm");
4070 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4071         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4072                                  all, "all");
4073 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4074         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4075                               port_id, UINT16);
4076
4077 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4078         .f = cmd_rx_vlan_filter_all_parsed,
4079         .data = NULL,
4080         .help_str = "rx_vlan add|rm all <port_id>: "
4081                 "Add/Remove all identifiers to/from the set of VLAN "
4082                 "identifiers filtered by a port",
4083         .tokens = {
4084                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4085                 (void *)&cmd_rx_vlan_filter_all_what,
4086                 (void *)&cmd_rx_vlan_filter_all_all,
4087                 (void *)&cmd_rx_vlan_filter_all_portid,
4088                 NULL,
4089         },
4090 };
4091
4092 /* *** VLAN OFFLOAD SET ON A PORT *** */
4093 struct cmd_vlan_offload_result {
4094         cmdline_fixed_string_t vlan;
4095         cmdline_fixed_string_t set;
4096         cmdline_fixed_string_t vlan_type;
4097         cmdline_fixed_string_t what;
4098         cmdline_fixed_string_t on;
4099         cmdline_fixed_string_t port_id;
4100 };
4101
4102 static void
4103 cmd_vlan_offload_parsed(void *parsed_result,
4104                           __rte_unused struct cmdline *cl,
4105                           __rte_unused void *data)
4106 {
4107         int on;
4108         struct cmd_vlan_offload_result *res = parsed_result;
4109         char *str;
4110         int i, len = 0;
4111         portid_t port_id = 0;
4112         unsigned int tmp;
4113
4114         str = res->port_id;
4115         len = strnlen(str, STR_TOKEN_SIZE);
4116         i = 0;
4117         /* Get port_id first */
4118         while(i < len){
4119                 if(str[i] == ',')
4120                         break;
4121
4122                 i++;
4123         }
4124         str[i]='\0';
4125         tmp = strtoul(str, NULL, 0);
4126         /* If port_id greater that what portid_t can represent, return */
4127         if(tmp >= RTE_MAX_ETHPORTS)
4128                 return;
4129         port_id = (portid_t)tmp;
4130
4131         if (!strcmp(res->on, "on"))
4132                 on = 1;
4133         else
4134                 on = 0;
4135
4136         if (!strcmp(res->what, "strip"))
4137                 rx_vlan_strip_set(port_id,  on);
4138         else if(!strcmp(res->what, "stripq")){
4139                 uint16_t queue_id = 0;
4140
4141                 /* No queue_id, return */
4142                 if(i + 1 >= len) {
4143                         printf("must specify (port,queue_id)\n");
4144                         return;
4145                 }
4146                 tmp = strtoul(str + i + 1, NULL, 0);
4147                 /* If queue_id greater that what 16-bits can represent, return */
4148                 if(tmp > 0xffff)
4149                         return;
4150
4151                 queue_id = (uint16_t)tmp;
4152                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4153         }
4154         else if (!strcmp(res->what, "filter"))
4155                 rx_vlan_filter_set(port_id, on);
4156         else if (!strcmp(res->what, "qinq_strip"))
4157                 rx_vlan_qinq_strip_set(port_id, on);
4158         else
4159                 vlan_extend_set(port_id, on);
4160
4161         return;
4162 }
4163
4164 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4165         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4166                                  vlan, "vlan");
4167 cmdline_parse_token_string_t cmd_vlan_offload_set =
4168         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4169                                  set, "set");
4170 cmdline_parse_token_string_t cmd_vlan_offload_what =
4171         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4172                                 what, "strip#filter#qinq_strip#extend#stripq");
4173 cmdline_parse_token_string_t cmd_vlan_offload_on =
4174         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4175                               on, "on#off");
4176 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4177         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4178                               port_id, NULL);
4179
4180 cmdline_parse_inst_t cmd_vlan_offload = {
4181         .f = cmd_vlan_offload_parsed,
4182         .data = NULL,
4183         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4184                 "<port_id[,queue_id]>: "
4185                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4186         .tokens = {
4187                 (void *)&cmd_vlan_offload_vlan,
4188                 (void *)&cmd_vlan_offload_set,
4189                 (void *)&cmd_vlan_offload_what,
4190                 (void *)&cmd_vlan_offload_on,
4191                 (void *)&cmd_vlan_offload_portid,
4192                 NULL,
4193         },
4194 };
4195
4196 /* *** VLAN TPID SET ON A PORT *** */
4197 struct cmd_vlan_tpid_result {
4198         cmdline_fixed_string_t vlan;
4199         cmdline_fixed_string_t set;
4200         cmdline_fixed_string_t vlan_type;
4201         cmdline_fixed_string_t what;
4202         uint16_t tp_id;
4203         portid_t port_id;
4204 };
4205
4206 static void
4207 cmd_vlan_tpid_parsed(void *parsed_result,
4208                           __rte_unused struct cmdline *cl,
4209                           __rte_unused void *data)
4210 {
4211         struct cmd_vlan_tpid_result *res = parsed_result;
4212         enum rte_vlan_type vlan_type;
4213
4214         if (!strcmp(res->vlan_type, "inner"))
4215                 vlan_type = ETH_VLAN_TYPE_INNER;
4216         else if (!strcmp(res->vlan_type, "outer"))
4217                 vlan_type = ETH_VLAN_TYPE_OUTER;
4218         else {
4219                 printf("Unknown vlan type\n");
4220                 return;
4221         }
4222         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4223 }
4224
4225 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4226         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4227                                  vlan, "vlan");
4228 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4229         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4230                                  set, "set");
4231 cmdline_parse_token_string_t cmd_vlan_type =
4232         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4233                                  vlan_type, "inner#outer");
4234 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4235         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4236                                  what, "tpid");
4237 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4238         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4239                               tp_id, UINT16);
4240 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4241         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4242                               port_id, UINT16);
4243
4244 cmdline_parse_inst_t cmd_vlan_tpid = {
4245         .f = cmd_vlan_tpid_parsed,
4246         .data = NULL,
4247         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4248                 "Set the VLAN Ether type",
4249         .tokens = {
4250                 (void *)&cmd_vlan_tpid_vlan,
4251                 (void *)&cmd_vlan_tpid_set,
4252                 (void *)&cmd_vlan_type,
4253                 (void *)&cmd_vlan_tpid_what,
4254                 (void *)&cmd_vlan_tpid_tpid,
4255                 (void *)&cmd_vlan_tpid_portid,
4256                 NULL,
4257         },
4258 };
4259
4260 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4261 struct cmd_rx_vlan_filter_result {
4262         cmdline_fixed_string_t rx_vlan;
4263         cmdline_fixed_string_t what;
4264         uint16_t vlan_id;
4265         portid_t port_id;
4266 };
4267
4268 static void
4269 cmd_rx_vlan_filter_parsed(void *parsed_result,
4270                           __rte_unused struct cmdline *cl,
4271                           __rte_unused void *data)
4272 {
4273         struct cmd_rx_vlan_filter_result *res = parsed_result;
4274
4275         if (!strcmp(res->what, "add"))
4276                 rx_vft_set(res->port_id, res->vlan_id, 1);
4277         else
4278                 rx_vft_set(res->port_id, res->vlan_id, 0);
4279 }
4280
4281 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4282         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4283                                  rx_vlan, "rx_vlan");
4284 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4285         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4286                                  what, "add#rm");
4287 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4288         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4289                               vlan_id, UINT16);
4290 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4291         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4292                               port_id, UINT16);
4293
4294 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4295         .f = cmd_rx_vlan_filter_parsed,
4296         .data = NULL,
4297         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4298                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4299                 "identifiers filtered by a port",
4300         .tokens = {
4301                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4302                 (void *)&cmd_rx_vlan_filter_what,
4303                 (void *)&cmd_rx_vlan_filter_vlanid,
4304                 (void *)&cmd_rx_vlan_filter_portid,
4305                 NULL,
4306         },
4307 };
4308
4309 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4310 struct cmd_tx_vlan_set_result {
4311         cmdline_fixed_string_t tx_vlan;
4312         cmdline_fixed_string_t set;
4313         portid_t port_id;
4314         uint16_t vlan_id;
4315 };
4316
4317 static void
4318 cmd_tx_vlan_set_parsed(void *parsed_result,
4319                        __rte_unused struct cmdline *cl,
4320                        __rte_unused void *data)
4321 {
4322         struct cmd_tx_vlan_set_result *res = parsed_result;
4323
4324         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4325                 return;
4326
4327         if (!port_is_stopped(res->port_id)) {
4328                 printf("Please stop port %d first\n", res->port_id);
4329                 return;
4330         }
4331
4332         tx_vlan_set(res->port_id, res->vlan_id);
4333
4334         cmd_reconfig_device_queue(res->port_id, 1, 1);
4335 }
4336
4337 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4338         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4339                                  tx_vlan, "tx_vlan");
4340 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4341         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4342                                  set, "set");
4343 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4344         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4345                               port_id, UINT16);
4346 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4347         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4348                               vlan_id, UINT16);
4349
4350 cmdline_parse_inst_t cmd_tx_vlan_set = {
4351         .f = cmd_tx_vlan_set_parsed,
4352         .data = NULL,
4353         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4354                 "Enable hardware insertion of a single VLAN header "
4355                 "with a given TAG Identifier in packets sent on a port",
4356         .tokens = {
4357                 (void *)&cmd_tx_vlan_set_tx_vlan,
4358                 (void *)&cmd_tx_vlan_set_set,
4359                 (void *)&cmd_tx_vlan_set_portid,
4360                 (void *)&cmd_tx_vlan_set_vlanid,
4361                 NULL,
4362         },
4363 };
4364
4365 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4366 struct cmd_tx_vlan_set_qinq_result {
4367         cmdline_fixed_string_t tx_vlan;
4368         cmdline_fixed_string_t set;
4369         portid_t port_id;
4370         uint16_t vlan_id;
4371         uint16_t vlan_id_outer;
4372 };
4373
4374 static void
4375 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4376                             __rte_unused struct cmdline *cl,
4377                             __rte_unused void *data)
4378 {
4379         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4380
4381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4382                 return;
4383
4384         if (!port_is_stopped(res->port_id)) {
4385                 printf("Please stop port %d first\n", res->port_id);
4386                 return;
4387         }
4388
4389         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4390
4391         cmd_reconfig_device_queue(res->port_id, 1, 1);
4392 }
4393
4394 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4395         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4396                 tx_vlan, "tx_vlan");
4397 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4398         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4399                 set, "set");
4400 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4401         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4402                 port_id, UINT16);
4403 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4404         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4405                 vlan_id, UINT16);
4406 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4407         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4408                 vlan_id_outer, UINT16);
4409
4410 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4411         .f = cmd_tx_vlan_set_qinq_parsed,
4412         .data = NULL,
4413         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4414                 "Enable hardware insertion of double VLAN header "
4415                 "with given TAG Identifiers in packets sent on a port",
4416         .tokens = {
4417                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4418                 (void *)&cmd_tx_vlan_set_qinq_set,
4419                 (void *)&cmd_tx_vlan_set_qinq_portid,
4420                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4421                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4422                 NULL,
4423         },
4424 };
4425
4426 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4427 struct cmd_tx_vlan_set_pvid_result {
4428         cmdline_fixed_string_t tx_vlan;
4429         cmdline_fixed_string_t set;
4430         cmdline_fixed_string_t pvid;
4431         portid_t port_id;
4432         uint16_t vlan_id;
4433         cmdline_fixed_string_t mode;
4434 };
4435
4436 static void
4437 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4438                             __rte_unused struct cmdline *cl,
4439                             __rte_unused void *data)
4440 {
4441         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4442
4443         if (strcmp(res->mode, "on") == 0)
4444                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4445         else
4446                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4447 }
4448
4449 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4450         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4451                                  tx_vlan, "tx_vlan");
4452 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4453         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4454                                  set, "set");
4455 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4456         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4457                                  pvid, "pvid");
4458 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4459         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4460                              port_id, UINT16);
4461 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4462         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4463                               vlan_id, UINT16);
4464 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4465         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4466                                  mode, "on#off");
4467
4468 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4469         .f = cmd_tx_vlan_set_pvid_parsed,
4470         .data = NULL,
4471         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4472         .tokens = {
4473                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4474                 (void *)&cmd_tx_vlan_set_pvid_set,
4475                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4476                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4477                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4478                 (void *)&cmd_tx_vlan_set_pvid_mode,
4479                 NULL,
4480         },
4481 };
4482
4483 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4484 struct cmd_tx_vlan_reset_result {
4485         cmdline_fixed_string_t tx_vlan;
4486         cmdline_fixed_string_t reset;
4487         portid_t port_id;
4488 };
4489
4490 static void
4491 cmd_tx_vlan_reset_parsed(void *parsed_result,
4492                          __rte_unused struct cmdline *cl,
4493                          __rte_unused void *data)
4494 {
4495         struct cmd_tx_vlan_reset_result *res = parsed_result;
4496
4497         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4498                 return;
4499
4500         if (!port_is_stopped(res->port_id)) {
4501                 printf("Please stop port %d first\n", res->port_id);
4502                 return;
4503         }
4504
4505         tx_vlan_reset(res->port_id);
4506
4507         cmd_reconfig_device_queue(res->port_id, 1, 1);
4508 }
4509
4510 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4511         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4512                                  tx_vlan, "tx_vlan");
4513 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4514         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4515                                  reset, "reset");
4516 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4517         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4518                               port_id, UINT16);
4519
4520 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4521         .f = cmd_tx_vlan_reset_parsed,
4522         .data = NULL,
4523         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4524                 "VLAN header in packets sent on a port",
4525         .tokens = {
4526                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4527                 (void *)&cmd_tx_vlan_reset_reset,
4528                 (void *)&cmd_tx_vlan_reset_portid,
4529                 NULL,
4530         },
4531 };
4532
4533
4534 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4535 struct cmd_csum_result {
4536         cmdline_fixed_string_t csum;
4537         cmdline_fixed_string_t mode;
4538         cmdline_fixed_string_t proto;
4539         cmdline_fixed_string_t hwsw;
4540         portid_t port_id;
4541 };
4542
4543 static void
4544 csum_show(int port_id)
4545 {
4546         struct rte_eth_dev_info dev_info;
4547         uint64_t tx_offloads;
4548         int ret;
4549
4550         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4551         printf("Parse tunnel is %s\n",
4552                 (ports[port_id].parse_tunnel) ? "on" : "off");
4553         printf("IP checksum offload is %s\n",
4554                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4555         printf("UDP checksum offload is %s\n",
4556                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4557         printf("TCP checksum offload is %s\n",
4558                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4559         printf("SCTP checksum offload is %s\n",
4560                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4561         printf("Outer-Ip checksum offload is %s\n",
4562                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4563         printf("Outer-Udp checksum offload is %s\n",
4564                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4565
4566         /* display warnings if configuration is not supported by the NIC */
4567         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4568         if (ret != 0)
4569                 return;
4570
4571         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4572                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4573                 printf("Warning: hardware IP checksum enabled but not "
4574                         "supported by port %d\n", port_id);
4575         }
4576         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4577                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4578                 printf("Warning: hardware UDP checksum enabled but not "
4579                         "supported by port %d\n", port_id);
4580         }
4581         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4582                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4583                 printf("Warning: hardware TCP checksum enabled but not "
4584                         "supported by port %d\n", port_id);
4585         }
4586         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4587                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4588                 printf("Warning: hardware SCTP checksum enabled but not "
4589                         "supported by port %d\n", port_id);
4590         }
4591         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4592                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4593                 printf("Warning: hardware outer IP checksum enabled but not "
4594                         "supported by port %d\n", port_id);
4595         }
4596         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4597                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4598                         == 0) {
4599                 printf("Warning: hardware outer UDP checksum enabled but not "
4600                         "supported by port %d\n", port_id);
4601         }
4602 }
4603
4604 static void
4605 cmd_config_queue_tx_offloads(struct rte_port *port)
4606 {
4607         int k;
4608
4609         /* Apply queue tx offloads configuration */
4610         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4611                 port->tx_conf[k].offloads =
4612                         port->dev_conf.txmode.offloads;
4613 }
4614
4615 static void
4616 cmd_csum_parsed(void *parsed_result,
4617                        __rte_unused struct cmdline *cl,
4618                        __rte_unused void *data)
4619 {
4620         struct cmd_csum_result *res = parsed_result;
4621         int hw = 0;
4622         uint64_t csum_offloads = 0;
4623         struct rte_eth_dev_info dev_info;
4624         int ret;
4625
4626         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4627                 printf("invalid port %d\n", res->port_id);
4628                 return;
4629         }
4630         if (!port_is_stopped(res->port_id)) {
4631                 printf("Please stop port %d first\n", res->port_id);
4632                 return;
4633         }
4634
4635         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4636         if (ret != 0)
4637                 return;
4638
4639         if (!strcmp(res->mode, "set")) {
4640
4641                 if (!strcmp(res->hwsw, "hw"))
4642                         hw = 1;
4643
4644                 if (!strcmp(res->proto, "ip")) {
4645                         if (hw == 0 || (dev_info.tx_offload_capa &
4646                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4647                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4648                         } else {
4649                                 printf("IP checksum offload is not supported "
4650                                        "by port %u\n", res->port_id);
4651                         }
4652                 } else if (!strcmp(res->proto, "udp")) {
4653                         if (hw == 0 || (dev_info.tx_offload_capa &
4654                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4655                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4656                         } else {
4657                                 printf("UDP checksum offload is not supported "
4658                                        "by port %u\n", res->port_id);
4659                         }
4660                 } else if (!strcmp(res->proto, "tcp")) {
4661                         if (hw == 0 || (dev_info.tx_offload_capa &
4662                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4663                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4664                         } else {
4665                                 printf("TCP checksum offload is not supported "
4666                                        "by port %u\n", res->port_id);
4667                         }
4668                 } else if (!strcmp(res->proto, "sctp")) {
4669                         if (hw == 0 || (dev_info.tx_offload_capa &
4670                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4671                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4672                         } else {
4673                                 printf("SCTP checksum offload is not supported "
4674                                        "by port %u\n", res->port_id);
4675                         }
4676                 } else if (!strcmp(res->proto, "outer-ip")) {
4677                         if (hw == 0 || (dev_info.tx_offload_capa &
4678                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4679                                 csum_offloads |=
4680                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4681                         } else {
4682                                 printf("Outer IP checksum offload is not "
4683                                        "supported by port %u\n", res->port_id);
4684                         }
4685                 } else if (!strcmp(res->proto, "outer-udp")) {
4686                         if (hw == 0 || (dev_info.tx_offload_capa &
4687                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4688                                 csum_offloads |=
4689                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4690                         } else {
4691                                 printf("Outer UDP checksum offload is not "
4692                                        "supported by port %u\n", res->port_id);
4693                         }
4694                 }
4695
4696                 if (hw) {
4697                         ports[res->port_id].dev_conf.txmode.offloads |=
4698                                                         csum_offloads;
4699                 } else {
4700                         ports[res->port_id].dev_conf.txmode.offloads &=
4701                                                         (~csum_offloads);
4702                 }
4703                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4704         }
4705         csum_show(res->port_id);
4706
4707         cmd_reconfig_device_queue(res->port_id, 1, 1);
4708 }
4709
4710 cmdline_parse_token_string_t cmd_csum_csum =
4711         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4712                                 csum, "csum");
4713 cmdline_parse_token_string_t cmd_csum_mode =
4714         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4715                                 mode, "set");
4716 cmdline_parse_token_string_t cmd_csum_proto =
4717         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4718                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4719 cmdline_parse_token_string_t cmd_csum_hwsw =
4720         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4721                                 hwsw, "hw#sw");
4722 cmdline_parse_token_num_t cmd_csum_portid =
4723         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4724                                 port_id, UINT16);
4725
4726 cmdline_parse_inst_t cmd_csum_set = {
4727         .f = cmd_csum_parsed,
4728         .data = NULL,
4729         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4730                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4731                 "using csum forward engine",
4732         .tokens = {
4733                 (void *)&cmd_csum_csum,
4734                 (void *)&cmd_csum_mode,
4735                 (void *)&cmd_csum_proto,
4736                 (void *)&cmd_csum_hwsw,
4737                 (void *)&cmd_csum_portid,
4738                 NULL,
4739         },
4740 };
4741
4742 cmdline_parse_token_string_t cmd_csum_mode_show =
4743         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4744                                 mode, "show");
4745
4746 cmdline_parse_inst_t cmd_csum_show = {
4747         .f = cmd_csum_parsed,
4748         .data = NULL,
4749         .help_str = "csum show <port_id>: Show checksum offload configuration",
4750         .tokens = {
4751                 (void *)&cmd_csum_csum,
4752                 (void *)&cmd_csum_mode_show,
4753                 (void *)&cmd_csum_portid,
4754                 NULL,
4755         },
4756 };
4757
4758 /* Enable/disable tunnel parsing */
4759 struct cmd_csum_tunnel_result {
4760         cmdline_fixed_string_t csum;
4761         cmdline_fixed_string_t parse;
4762         cmdline_fixed_string_t onoff;
4763         portid_t port_id;
4764 };
4765
4766 static void
4767 cmd_csum_tunnel_parsed(void *parsed_result,
4768                        __rte_unused struct cmdline *cl,
4769                        __rte_unused void *data)
4770 {
4771         struct cmd_csum_tunnel_result *res = parsed_result;
4772
4773         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4774                 return;
4775
4776         if (!strcmp(res->onoff, "on"))
4777                 ports[res->port_id].parse_tunnel = 1;
4778         else
4779                 ports[res->port_id].parse_tunnel = 0;
4780
4781         csum_show(res->port_id);
4782 }
4783
4784 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4785         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4786                                 csum, "csum");
4787 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4788         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4789                                 parse, "parse-tunnel");
4790 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4791         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4792                                 onoff, "on#off");
4793 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4794         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4795                                 port_id, UINT16);
4796
4797 cmdline_parse_inst_t cmd_csum_tunnel = {
4798         .f = cmd_csum_tunnel_parsed,
4799         .data = NULL,
4800         .help_str = "csum parse-tunnel on|off <port_id>: "
4801                 "Enable/Disable parsing of tunnels for csum engine",
4802         .tokens = {
4803                 (void *)&cmd_csum_tunnel_csum,
4804                 (void *)&cmd_csum_tunnel_parse,
4805                 (void *)&cmd_csum_tunnel_onoff,
4806                 (void *)&cmd_csum_tunnel_portid,
4807                 NULL,
4808         },
4809 };
4810
4811 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4812 struct cmd_tso_set_result {
4813         cmdline_fixed_string_t tso;
4814         cmdline_fixed_string_t mode;
4815         uint16_t tso_segsz;
4816         portid_t port_id;
4817 };
4818
4819 static void
4820 cmd_tso_set_parsed(void *parsed_result,
4821                        __rte_unused struct cmdline *cl,
4822                        __rte_unused void *data)
4823 {
4824         struct cmd_tso_set_result *res = parsed_result;
4825         struct rte_eth_dev_info dev_info;
4826         int ret;
4827
4828         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4829                 return;
4830         if (!port_is_stopped(res->port_id)) {
4831                 printf("Please stop port %d first\n", res->port_id);
4832                 return;
4833         }
4834
4835         if (!strcmp(res->mode, "set"))
4836                 ports[res->port_id].tso_segsz = res->tso_segsz;
4837
4838         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4839         if (ret != 0)
4840                 return;
4841
4842         if ((ports[res->port_id].tso_segsz != 0) &&
4843                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4844                 printf("Error: TSO is not supported by port %d\n",
4845                        res->port_id);
4846                 return;
4847         }
4848
4849         if (ports[res->port_id].tso_segsz == 0) {
4850                 ports[res->port_id].dev_conf.txmode.offloads &=
4851                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4852                 printf("TSO for non-tunneled packets is disabled\n");
4853         } else {
4854                 ports[res->port_id].dev_conf.txmode.offloads |=
4855                                                 DEV_TX_OFFLOAD_TCP_TSO;
4856                 printf("TSO segment size for non-tunneled packets is %d\n",
4857                         ports[res->port_id].tso_segsz);
4858         }
4859         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4860
4861         /* display warnings if configuration is not supported by the NIC */
4862         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4863         if (ret != 0)
4864                 return;
4865
4866         if ((ports[res->port_id].tso_segsz != 0) &&
4867                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4868                 printf("Warning: TSO enabled but not "
4869                         "supported by port %d\n", res->port_id);
4870         }
4871
4872         cmd_reconfig_device_queue(res->port_id, 1, 1);
4873 }
4874
4875 cmdline_parse_token_string_t cmd_tso_set_tso =
4876         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4877                                 tso, "tso");
4878 cmdline_parse_token_string_t cmd_tso_set_mode =
4879         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4880                                 mode, "set");
4881 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4882         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4883                                 tso_segsz, UINT16);
4884 cmdline_parse_token_num_t cmd_tso_set_portid =
4885         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4886                                 port_id, UINT16);
4887
4888 cmdline_parse_inst_t cmd_tso_set = {
4889         .f = cmd_tso_set_parsed,
4890         .data = NULL,
4891         .help_str = "tso set <tso_segsz> <port_id>: "
4892                 "Set TSO segment size of non-tunneled packets for csum engine "
4893                 "(0 to disable)",
4894         .tokens = {
4895                 (void *)&cmd_tso_set_tso,
4896                 (void *)&cmd_tso_set_mode,
4897                 (void *)&cmd_tso_set_tso_segsz,
4898                 (void *)&cmd_tso_set_portid,
4899                 NULL,
4900         },
4901 };
4902
4903 cmdline_parse_token_string_t cmd_tso_show_mode =
4904         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4905                                 mode, "show");
4906
4907
4908 cmdline_parse_inst_t cmd_tso_show = {
4909         .f = cmd_tso_set_parsed,
4910         .data = NULL,
4911         .help_str = "tso show <port_id>: "
4912                 "Show TSO segment size of non-tunneled packets for csum engine",
4913         .tokens = {
4914                 (void *)&cmd_tso_set_tso,
4915                 (void *)&cmd_tso_show_mode,
4916                 (void *)&cmd_tso_set_portid,
4917                 NULL,
4918         },
4919 };
4920
4921 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4922 struct cmd_tunnel_tso_set_result {
4923         cmdline_fixed_string_t tso;
4924         cmdline_fixed_string_t mode;
4925         uint16_t tso_segsz;
4926         portid_t port_id;
4927 };
4928
4929 static struct rte_eth_dev_info
4930 check_tunnel_tso_nic_support(portid_t port_id)
4931 {
4932         struct rte_eth_dev_info dev_info;
4933
4934         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4935                 return dev_info;
4936
4937         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4938                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4939                        "not enabled for port %d\n", port_id);
4940         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4941                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4942                        "not enabled for port %d\n", port_id);
4943         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4944                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4945                        "not enabled for port %d\n", port_id);
4946         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4947                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4948                        "not enabled for port %d\n", port_id);
4949         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4950                 printf("Warning: IP TUNNEL TSO not supported therefore "
4951                        "not enabled for port %d\n", port_id);
4952         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4953                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4954                        "not enabled for port %d\n", port_id);
4955         return dev_info;
4956 }
4957
4958 static void
4959 cmd_tunnel_tso_set_parsed(void *parsed_result,
4960                           __rte_unused struct cmdline *cl,
4961                           __rte_unused void *data)
4962 {
4963         struct cmd_tunnel_tso_set_result *res = parsed_result;
4964         struct rte_eth_dev_info dev_info;
4965
4966         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4967                 return;
4968         if (!port_is_stopped(res->port_id)) {
4969                 printf("Please stop port %d first\n", res->port_id);
4970                 return;
4971         }
4972
4973         if (!strcmp(res->mode, "set"))
4974                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
4975
4976         dev_info = check_tunnel_tso_nic_support(res->port_id);
4977         if (ports[res->port_id].tunnel_tso_segsz == 0) {
4978                 ports[res->port_id].dev_conf.txmode.offloads &=
4979                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4980                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
4981                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4982                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4983                           DEV_TX_OFFLOAD_IP_TNL_TSO |
4984                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
4985                 printf("TSO for tunneled packets is disabled\n");
4986         } else {
4987                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
4988                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
4989                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
4990                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
4991                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
4992                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
4993
4994                 ports[res->port_id].dev_conf.txmode.offloads |=
4995                         (tso_offloads & dev_info.tx_offload_capa);
4996                 printf("TSO segment size for tunneled packets is %d\n",
4997                         ports[res->port_id].tunnel_tso_segsz);
4998
4999                 /* Below conditions are needed to make it work:
5000                  * (1) tunnel TSO is supported by the NIC;
5001                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5002                  * are recognized;
5003                  * (3) for tunneled pkts with outer L3 of IPv4,
5004                  * "csum set outer-ip" must be set to hw, because after tso,
5005                  * total_len of outer IP header is changed, and the checksum
5006                  * of outer IP header calculated by sw should be wrong; that
5007                  * is not necessary for IPv6 tunneled pkts because there's no
5008                  * checksum in IP header anymore.
5009                  */
5010
5011                 if (!ports[res->port_id].parse_tunnel)
5012                         printf("Warning: csum parse_tunnel must be set "
5013                                 "so that tunneled packets are recognized\n");
5014                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5015                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5016                         printf("Warning: csum set outer-ip must be set to hw "
5017                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5018         }
5019
5020         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5021         cmd_reconfig_device_queue(res->port_id, 1, 1);
5022 }
5023
5024 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5025         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5026                                 tso, "tunnel_tso");
5027 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5028         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5029                                 mode, "set");
5030 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5031         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5032                                 tso_segsz, UINT16);
5033 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5034         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5035                                 port_id, UINT16);
5036
5037 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5038         .f = cmd_tunnel_tso_set_parsed,
5039         .data = NULL,
5040         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5041                 "Set TSO segment size of tunneled packets for csum engine "
5042                 "(0 to disable)",
5043         .tokens = {
5044                 (void *)&cmd_tunnel_tso_set_tso,
5045                 (void *)&cmd_tunnel_tso_set_mode,
5046                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5047                 (void *)&cmd_tunnel_tso_set_portid,
5048                 NULL,
5049         },
5050 };
5051
5052 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5053         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5054                                 mode, "show");
5055
5056
5057 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5058         .f = cmd_tunnel_tso_set_parsed,
5059         .data = NULL,
5060         .help_str = "tunnel_tso show <port_id> "
5061                 "Show TSO segment size of tunneled packets for csum engine",
5062         .tokens = {
5063                 (void *)&cmd_tunnel_tso_set_tso,
5064                 (void *)&cmd_tunnel_tso_show_mode,
5065                 (void *)&cmd_tunnel_tso_set_portid,
5066                 NULL,
5067         },
5068 };
5069
5070 /* *** SET GRO FOR A PORT *** */
5071 struct cmd_gro_enable_result {
5072         cmdline_fixed_string_t cmd_set;
5073         cmdline_fixed_string_t cmd_port;
5074         cmdline_fixed_string_t cmd_keyword;
5075         cmdline_fixed_string_t cmd_onoff;
5076         portid_t cmd_pid;
5077 };
5078
5079 static void
5080 cmd_gro_enable_parsed(void *parsed_result,
5081                 __rte_unused struct cmdline *cl,
5082                 __rte_unused void *data)
5083 {
5084         struct cmd_gro_enable_result *res;
5085
5086         res = parsed_result;
5087         if (!strcmp(res->cmd_keyword, "gro"))
5088                 setup_gro(res->cmd_onoff, res->cmd_pid);
5089 }
5090
5091 cmdline_parse_token_string_t cmd_gro_enable_set =
5092         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5093                         cmd_set, "set");
5094 cmdline_parse_token_string_t cmd_gro_enable_port =
5095         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5096                         cmd_keyword, "port");
5097 cmdline_parse_token_num_t cmd_gro_enable_pid =
5098         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5099                         cmd_pid, UINT16);
5100 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5101         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5102                         cmd_keyword, "gro");
5103 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5104         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5105                         cmd_onoff, "on#off");
5106
5107 cmdline_parse_inst_t cmd_gro_enable = {
5108         .f = cmd_gro_enable_parsed,
5109         .data = NULL,
5110         .help_str = "set port <port_id> gro on|off",
5111         .tokens = {
5112                 (void *)&cmd_gro_enable_set,
5113                 (void *)&cmd_gro_enable_port,
5114                 (void *)&cmd_gro_enable_pid,
5115                 (void *)&cmd_gro_enable_keyword,
5116                 (void *)&cmd_gro_enable_onoff,
5117                 NULL,
5118         },
5119 };
5120
5121 /* *** DISPLAY GRO CONFIGURATION *** */
5122 struct cmd_gro_show_result {
5123         cmdline_fixed_string_t cmd_show;
5124         cmdline_fixed_string_t cmd_port;
5125         cmdline_fixed_string_t cmd_keyword;
5126         portid_t cmd_pid;
5127 };
5128
5129 static void
5130 cmd_gro_show_parsed(void *parsed_result,
5131                 __rte_unused struct cmdline *cl,
5132                 __rte_unused void *data)
5133 {
5134         struct cmd_gro_show_result *res;
5135
5136         res = parsed_result;
5137         if (!strcmp(res->cmd_keyword, "gro"))
5138                 show_gro(res->cmd_pid);
5139 }
5140
5141 cmdline_parse_token_string_t cmd_gro_show_show =
5142         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5143                         cmd_show, "show");
5144 cmdline_parse_token_string_t cmd_gro_show_port =
5145         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5146                         cmd_port, "port");
5147 cmdline_parse_token_num_t cmd_gro_show_pid =
5148         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5149                         cmd_pid, UINT16);
5150 cmdline_parse_token_string_t cmd_gro_show_keyword =
5151         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5152                         cmd_keyword, "gro");
5153
5154 cmdline_parse_inst_t cmd_gro_show = {
5155         .f = cmd_gro_show_parsed,
5156         .data = NULL,
5157         .help_str = "show port <port_id> gro",
5158         .tokens = {
5159                 (void *)&cmd_gro_show_show,
5160                 (void *)&cmd_gro_show_port,
5161                 (void *)&cmd_gro_show_pid,
5162                 (void *)&cmd_gro_show_keyword,
5163                 NULL,
5164         },
5165 };
5166
5167 /* *** SET FLUSH CYCLES FOR GRO *** */
5168 struct cmd_gro_flush_result {
5169         cmdline_fixed_string_t cmd_set;
5170         cmdline_fixed_string_t cmd_keyword;
5171         cmdline_fixed_string_t cmd_flush;
5172         uint8_t cmd_cycles;
5173 };
5174
5175 static void
5176 cmd_gro_flush_parsed(void *parsed_result,
5177                 __rte_unused struct cmdline *cl,
5178                 __rte_unused void *data)
5179 {
5180         struct cmd_gro_flush_result *res;
5181
5182         res = parsed_result;
5183         if ((!strcmp(res->cmd_keyword, "gro")) &&
5184                         (!strcmp(res->cmd_flush, "flush")))
5185                 setup_gro_flush_cycles(res->cmd_cycles);
5186 }
5187
5188 cmdline_parse_token_string_t cmd_gro_flush_set =
5189         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5190                         cmd_set, "set");
5191 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5192         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5193                         cmd_keyword, "gro");
5194 cmdline_parse_token_string_t cmd_gro_flush_flush =
5195         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5196                         cmd_flush, "flush");
5197 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5198         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5199                         cmd_cycles, UINT8);
5200
5201 cmdline_parse_inst_t cmd_gro_flush = {
5202         .f = cmd_gro_flush_parsed,
5203         .data = NULL,
5204         .help_str = "set gro flush <cycles>",
5205         .tokens = {
5206                 (void *)&cmd_gro_flush_set,
5207                 (void *)&cmd_gro_flush_keyword,
5208                 (void *)&cmd_gro_flush_flush,
5209                 (void *)&cmd_gro_flush_cycles,
5210                 NULL,
5211         },
5212 };
5213
5214 /* *** ENABLE/DISABLE GSO *** */
5215 struct cmd_gso_enable_result {
5216         cmdline_fixed_string_t cmd_set;
5217         cmdline_fixed_string_t cmd_port;
5218         cmdline_fixed_string_t cmd_keyword;
5219         cmdline_fixed_string_t cmd_mode;
5220         portid_t cmd_pid;
5221 };
5222
5223 static void
5224 cmd_gso_enable_parsed(void *parsed_result,
5225                 __rte_unused struct cmdline *cl,
5226                 __rte_unused void *data)
5227 {
5228         struct cmd_gso_enable_result *res;
5229
5230         res = parsed_result;
5231         if (!strcmp(res->cmd_keyword, "gso"))
5232                 setup_gso(res->cmd_mode, res->cmd_pid);
5233 }
5234
5235 cmdline_parse_token_string_t cmd_gso_enable_set =
5236         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5237                         cmd_set, "set");
5238 cmdline_parse_token_string_t cmd_gso_enable_port =
5239         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5240                         cmd_port, "port");
5241 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5242         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5243                         cmd_keyword, "gso");
5244 cmdline_parse_token_string_t cmd_gso_enable_mode =
5245         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5246                         cmd_mode, "on#off");
5247 cmdline_parse_token_num_t cmd_gso_enable_pid =
5248         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5249                         cmd_pid, UINT16);
5250
5251 cmdline_parse_inst_t cmd_gso_enable = {
5252         .f = cmd_gso_enable_parsed,
5253         .data = NULL,
5254         .help_str = "set port <port_id> gso on|off",
5255         .tokens = {
5256                 (void *)&cmd_gso_enable_set,
5257                 (void *)&cmd_gso_enable_port,
5258                 (void *)&cmd_gso_enable_pid,
5259                 (void *)&cmd_gso_enable_keyword,
5260                 (void *)&cmd_gso_enable_mode,
5261                 NULL,
5262         },
5263 };
5264
5265 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5266 struct cmd_gso_size_result {
5267         cmdline_fixed_string_t cmd_set;
5268         cmdline_fixed_string_t cmd_keyword;
5269         cmdline_fixed_string_t cmd_segsz;
5270         uint16_t cmd_size;
5271 };
5272
5273 static void
5274 cmd_gso_size_parsed(void *parsed_result,
5275                        __rte_unused struct cmdline *cl,
5276                        __rte_unused void *data)
5277 {
5278         struct cmd_gso_size_result *res = parsed_result;
5279
5280         if (test_done == 0) {
5281                 printf("Before setting GSO segsz, please first"
5282                                 " stop forwarding\n");
5283                 return;
5284         }
5285
5286         if (!strcmp(res->cmd_keyword, "gso") &&
5287                         !strcmp(res->cmd_segsz, "segsz")) {
5288                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5289                         printf("gso_size should be larger than %zu."
5290                                         " Please input a legal value\n",
5291                                         RTE_GSO_SEG_SIZE_MIN);
5292                 else
5293                         gso_max_segment_size = res->cmd_size;
5294         }
5295 }
5296
5297 cmdline_parse_token_string_t cmd_gso_size_set =
5298         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5299                                 cmd_set, "set");
5300 cmdline_parse_token_string_t cmd_gso_size_keyword =
5301         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5302                                 cmd_keyword, "gso");
5303 cmdline_parse_token_string_t cmd_gso_size_segsz =
5304         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5305                                 cmd_segsz, "segsz");
5306 cmdline_parse_token_num_t cmd_gso_size_size =
5307         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5308                                 cmd_size, UINT16);
5309
5310 cmdline_parse_inst_t cmd_gso_size = {
5311         .f = cmd_gso_size_parsed,
5312         .data = NULL,
5313         .help_str = "set gso segsz <length>",
5314         .tokens = {
5315                 (void *)&cmd_gso_size_set,
5316                 (void *)&cmd_gso_size_keyword,
5317                 (void *)&cmd_gso_size_segsz,
5318                 (void *)&cmd_gso_size_size,
5319                 NULL,
5320         },
5321 };
5322
5323 /* *** SHOW GSO CONFIGURATION *** */
5324 struct cmd_gso_show_result {
5325         cmdline_fixed_string_t cmd_show;
5326         cmdline_fixed_string_t cmd_port;
5327         cmdline_fixed_string_t cmd_keyword;
5328         portid_t cmd_pid;
5329 };
5330
5331 static void
5332 cmd_gso_show_parsed(void *parsed_result,
5333                        __rte_unused struct cmdline *cl,
5334                        __rte_unused void *data)
5335 {
5336         struct cmd_gso_show_result *res = parsed_result;
5337
5338         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5339                 printf("invalid port id %u\n", res->cmd_pid);
5340                 return;
5341         }
5342         if (!strcmp(res->cmd_keyword, "gso")) {
5343                 if (gso_ports[res->cmd_pid].enable) {
5344                         printf("Max GSO'd packet size: %uB\n"
5345                                         "Supported GSO types: TCP/IPv4, "
5346                                         "UDP/IPv4, VxLAN with inner "
5347                                         "TCP/IPv4 packet, GRE with inner "
5348                                         "TCP/IPv4 packet\n",
5349                                         gso_max_segment_size);
5350                 } else
5351                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5352         }
5353 }
5354
5355 cmdline_parse_token_string_t cmd_gso_show_show =
5356 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5357                 cmd_show, "show");
5358 cmdline_parse_token_string_t cmd_gso_show_port =
5359 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5360                 cmd_port, "port");
5361 cmdline_parse_token_string_t cmd_gso_show_keyword =
5362         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5363                                 cmd_keyword, "gso");
5364 cmdline_parse_token_num_t cmd_gso_show_pid =
5365         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5366                                 cmd_pid, UINT16);
5367
5368 cmdline_parse_inst_t cmd_gso_show = {
5369         .f = cmd_gso_show_parsed,
5370         .data = NULL,
5371         .help_str = "show port <port_id> gso",
5372         .tokens = {
5373                 (void *)&cmd_gso_show_show,
5374                 (void *)&cmd_gso_show_port,
5375                 (void *)&cmd_gso_show_pid,
5376                 (void *)&cmd_gso_show_keyword,
5377                 NULL,
5378         },
5379 };
5380
5381 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5382 struct cmd_set_flush_rx {
5383         cmdline_fixed_string_t set;
5384         cmdline_fixed_string_t flush_rx;
5385         cmdline_fixed_string_t mode;
5386 };
5387
5388 static void
5389 cmd_set_flush_rx_parsed(void *parsed_result,
5390                 __rte_unused struct cmdline *cl,
5391                 __rte_unused void *data)
5392 {
5393         struct cmd_set_flush_rx *res = parsed_result;
5394         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5395 }
5396
5397 cmdline_parse_token_string_t cmd_setflushrx_set =
5398         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5399                         set, "set");
5400 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5401         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5402                         flush_rx, "flush_rx");
5403 cmdline_parse_token_string_t cmd_setflushrx_mode =
5404         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5405                         mode, "on#off");
5406
5407
5408 cmdline_parse_inst_t cmd_set_flush_rx = {
5409         .f = cmd_set_flush_rx_parsed,
5410         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5411         .data = NULL,
5412         .tokens = {
5413                 (void *)&cmd_setflushrx_set,
5414                 (void *)&cmd_setflushrx_flush_rx,
5415                 (void *)&cmd_setflushrx_mode,
5416                 NULL,
5417         },
5418 };
5419
5420 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5421 struct cmd_set_link_check {
5422         cmdline_fixed_string_t set;
5423         cmdline_fixed_string_t link_check;
5424         cmdline_fixed_string_t mode;
5425 };
5426
5427 static void
5428 cmd_set_link_check_parsed(void *parsed_result,
5429                 __rte_unused struct cmdline *cl,
5430                 __rte_unused void *data)
5431 {
5432         struct cmd_set_link_check *res = parsed_result;
5433         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5434 }
5435
5436 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5437         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5438                         set, "set");
5439 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5440         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5441                         link_check, "link_check");
5442 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5443         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5444                         mode, "on#off");
5445
5446
5447 cmdline_parse_inst_t cmd_set_link_check = {
5448         .f = cmd_set_link_check_parsed,
5449         .help_str = "set link_check on|off: Enable/Disable link status check "
5450                     "when starting/stopping a port",
5451         .data = NULL,
5452         .tokens = {
5453                 (void *)&cmd_setlinkcheck_set,
5454                 (void *)&cmd_setlinkcheck_link_check,
5455                 (void *)&cmd_setlinkcheck_mode,
5456                 NULL,
5457         },
5458 };
5459
5460 /* *** SET NIC BYPASS MODE *** */
5461 struct cmd_set_bypass_mode_result {
5462         cmdline_fixed_string_t set;
5463         cmdline_fixed_string_t bypass;
5464         cmdline_fixed_string_t mode;
5465         cmdline_fixed_string_t value;
5466         portid_t port_id;
5467 };
5468
5469 static void
5470 cmd_set_bypass_mode_parsed(void *parsed_result,
5471                 __rte_unused struct cmdline *cl,
5472                 __rte_unused void *data)
5473 {
5474         struct cmd_set_bypass_mode_result *res = parsed_result;
5475         portid_t port_id = res->port_id;
5476         int32_t rc = -EINVAL;
5477
5478 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5479         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5480
5481         if (!strcmp(res->value, "bypass"))
5482                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5483         else if (!strcmp(res->value, "isolate"))
5484                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5485         else
5486                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5487
5488         /* Set the bypass mode for the relevant port. */
5489         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5490 #endif
5491         if (rc != 0)
5492                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5493 }
5494
5495 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5496         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5497                         set, "set");
5498 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5499         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5500                         bypass, "bypass");
5501 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5503                         mode, "mode");
5504 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5505         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5506                         value, "normal#bypass#isolate");
5507 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5508         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5509                                 port_id, UINT16);
5510
5511 cmdline_parse_inst_t cmd_set_bypass_mode = {
5512         .f = cmd_set_bypass_mode_parsed,
5513         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5514                     "Set the NIC bypass mode for port_id",
5515         .data = NULL,
5516         .tokens = {
5517                 (void *)&cmd_setbypass_mode_set,
5518                 (void *)&cmd_setbypass_mode_bypass,
5519                 (void *)&cmd_setbypass_mode_mode,
5520                 (void *)&cmd_setbypass_mode_value,
5521                 (void *)&cmd_setbypass_mode_port,
5522                 NULL,
5523         },
5524 };
5525
5526 /* *** SET NIC BYPASS EVENT *** */
5527 struct cmd_set_bypass_event_result {
5528         cmdline_fixed_string_t set;
5529         cmdline_fixed_string_t bypass;
5530         cmdline_fixed_string_t event;
5531         cmdline_fixed_string_t event_value;
5532         cmdline_fixed_string_t mode;
5533         cmdline_fixed_string_t mode_value;
5534         portid_t port_id;
5535 };
5536
5537 static void
5538 cmd_set_bypass_event_parsed(void *parsed_result,
5539                 __rte_unused struct cmdline *cl,
5540                 __rte_unused void *data)
5541 {
5542         int32_t rc = -EINVAL;
5543         struct cmd_set_bypass_event_result *res = parsed_result;
5544         portid_t port_id = res->port_id;
5545
5546 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5547         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5548         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5549
5550         if (!strcmp(res->event_value, "timeout"))
5551                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5552         else if (!strcmp(res->event_value, "os_on"))
5553                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5554         else if (!strcmp(res->event_value, "os_off"))
5555                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5556         else if (!strcmp(res->event_value, "power_on"))
5557                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5558         else if (!strcmp(res->event_value, "power_off"))
5559                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5560         else
5561                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5562
5563         if (!strcmp(res->mode_value, "bypass"))
5564                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5565         else if (!strcmp(res->mode_value, "isolate"))
5566                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5567         else
5568                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5569
5570         /* Set the watchdog timeout. */
5571         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5572
5573                 rc = -EINVAL;
5574                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5575                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5576                                                            bypass_timeout);
5577                 }
5578                 if (rc != 0) {
5579                         printf("Failed to set timeout value %u "
5580                         "for port %d, errto code: %d.\n",
5581                         bypass_timeout, port_id, rc);
5582                 }
5583         }
5584
5585         /* Set the bypass event to transition to bypass mode. */
5586         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5587                                               bypass_mode);
5588 #endif
5589
5590         if (rc != 0)
5591                 printf("\t Failed to set bypass event for port = %d.\n",
5592                        port_id);
5593 }
5594
5595 cmdline_parse_token_string_t cmd_setbypass_event_set =
5596         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5597                         set, "set");
5598 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5599         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5600                         bypass, "bypass");
5601 cmdline_parse_token_string_t cmd_setbypass_event_event =
5602         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5603                         event, "event");
5604 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5605         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5606                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5607 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5608         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5609                         mode, "mode");
5610 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5611         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5612                         mode_value, "normal#bypass#isolate");
5613 cmdline_parse_token_num_t cmd_setbypass_event_port =
5614         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5615                                 port_id, UINT16);
5616
5617 cmdline_parse_inst_t cmd_set_bypass_event = {
5618         .f = cmd_set_bypass_event_parsed,
5619         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5620                 "power_off mode normal|bypass|isolate <port_id>: "
5621                 "Set the NIC bypass event mode for port_id",
5622         .data = NULL,
5623         .tokens = {
5624                 (void *)&cmd_setbypass_event_set,
5625                 (void *)&cmd_setbypass_event_bypass,
5626                 (void *)&cmd_setbypass_event_event,
5627                 (void *)&cmd_setbypass_event_event_value,
5628                 (void *)&cmd_setbypass_event_mode,
5629                 (void *)&cmd_setbypass_event_mode_value,
5630                 (void *)&cmd_setbypass_event_port,
5631                 NULL,
5632         },
5633 };
5634
5635
5636 /* *** SET NIC BYPASS TIMEOUT *** */
5637 struct cmd_set_bypass_timeout_result {
5638         cmdline_fixed_string_t set;
5639         cmdline_fixed_string_t bypass;
5640         cmdline_fixed_string_t timeout;
5641         cmdline_fixed_string_t value;
5642 };
5643
5644 static void
5645 cmd_set_bypass_timeout_parsed(void *parsed_result,
5646                 __rte_unused struct cmdline *cl,
5647                 __rte_unused void *data)
5648 {
5649         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5650
5651 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5652         if (!strcmp(res->value, "1.5"))
5653                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5654         else if (!strcmp(res->value, "2"))
5655                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5656         else if (!strcmp(res->value, "3"))
5657                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5658         else if (!strcmp(res->value, "4"))
5659                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5660         else if (!strcmp(res->value, "8"))
5661                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5662         else if (!strcmp(res->value, "16"))
5663                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5664         else if (!strcmp(res->value, "32"))
5665                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5666         else
5667                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5668 #endif
5669 }
5670
5671 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5672         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5673                         set, "set");
5674 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5675         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5676                         bypass, "bypass");
5677 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5678         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5679                         timeout, "timeout");
5680 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5681         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5682                         value, "0#1.5#2#3#4#8#16#32");
5683
5684 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5685         .f = cmd_set_bypass_timeout_parsed,
5686         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5687                 "Set the NIC bypass watchdog timeout in seconds",
5688         .data = NULL,
5689         .tokens = {
5690                 (void *)&cmd_setbypass_timeout_set,
5691                 (void *)&cmd_setbypass_timeout_bypass,
5692                 (void *)&cmd_setbypass_timeout_timeout,
5693                 (void *)&cmd_setbypass_timeout_value,
5694                 NULL,
5695         },
5696 };
5697
5698 /* *** SHOW NIC BYPASS MODE *** */
5699 struct cmd_show_bypass_config_result {
5700         cmdline_fixed_string_t show;
5701         cmdline_fixed_string_t bypass;
5702         cmdline_fixed_string_t config;
5703         portid_t port_id;
5704 };
5705
5706 static void
5707 cmd_show_bypass_config_parsed(void *parsed_result,
5708                 __rte_unused struct cmdline *cl,
5709                 __rte_unused void *data)
5710 {
5711         struct cmd_show_bypass_config_result *res = parsed_result;
5712         portid_t port_id = res->port_id;
5713         int rc = -EINVAL;
5714 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5715         uint32_t event_mode;
5716         uint32_t bypass_mode;
5717         uint32_t timeout = bypass_timeout;
5718         unsigned int i;
5719
5720         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5721                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5722         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5723                 {"UNKNOWN", "normal", "bypass", "isolate"};
5724         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5725                 "NONE",
5726                 "OS/board on",
5727                 "power supply on",
5728                 "OS/board off",
5729                 "power supply off",
5730                 "timeout"};
5731
5732         /* Display the bypass mode.*/
5733         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5734                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5735                 return;
5736         }
5737         else {
5738                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5739                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5740
5741                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5742         }
5743
5744         /* Display the bypass timeout.*/
5745         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5746                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5747
5748         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5749
5750         /* Display the bypass events and associated modes. */
5751         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5752
5753                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5754                         printf("\tFailed to get bypass mode for event = %s\n",
5755                                 events[i]);
5756                 } else {
5757                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5758                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5759
5760                         printf("\tbypass event: %-16s = %s\n", events[i],
5761                                 modes[event_mode]);
5762                 }
5763         }
5764 #endif
5765         if (rc != 0)
5766                 printf("\tFailed to get bypass configuration for port = %d\n",
5767                        port_id);
5768 }
5769
5770 cmdline_parse_token_string_t cmd_showbypass_config_show =
5771         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5772                         show, "show");
5773 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5774         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5775                         bypass, "bypass");
5776 cmdline_parse_token_string_t cmd_showbypass_config_config =
5777         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5778                         config, "config");
5779 cmdline_parse_token_num_t cmd_showbypass_config_port =
5780         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5781                                 port_id, UINT16);
5782
5783 cmdline_parse_inst_t cmd_show_bypass_config = {
5784         .f = cmd_show_bypass_config_parsed,
5785         .help_str = "show bypass config <port_id>: "
5786                     "Show the NIC bypass config for port_id",
5787         .data = NULL,
5788         .tokens = {
5789                 (void *)&cmd_showbypass_config_show,
5790                 (void *)&cmd_showbypass_config_bypass,
5791                 (void *)&cmd_showbypass_config_config,
5792                 (void *)&cmd_showbypass_config_port,
5793                 NULL,
5794         },
5795 };
5796
5797 #ifdef RTE_LIBRTE_PMD_BOND
5798 /* *** SET BONDING MODE *** */
5799 struct cmd_set_bonding_mode_result {
5800         cmdline_fixed_string_t set;
5801         cmdline_fixed_string_t bonding;
5802         cmdline_fixed_string_t mode;
5803         uint8_t value;
5804         portid_t port_id;
5805 };
5806
5807 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5808                 __rte_unused  struct cmdline *cl,
5809                 __rte_unused void *data)
5810 {
5811         struct cmd_set_bonding_mode_result *res = parsed_result;
5812         portid_t port_id = res->port_id;
5813
5814         /* Set the bonding mode for the relevant port. */
5815         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5816                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5817 }
5818
5819 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5820 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5821                 set, "set");
5822 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5823 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5824                 bonding, "bonding");
5825 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5826 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5827                 mode, "mode");
5828 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5829 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5830                 value, UINT8);
5831 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5832 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5833                 port_id, UINT16);
5834
5835 cmdline_parse_inst_t cmd_set_bonding_mode = {
5836                 .f = cmd_set_bonding_mode_parsed,
5837                 .help_str = "set bonding mode <mode_value> <port_id>: "
5838                         "Set the bonding mode for port_id",
5839                 .data = NULL,
5840                 .tokens = {
5841                                 (void *) &cmd_setbonding_mode_set,
5842                                 (void *) &cmd_setbonding_mode_bonding,
5843                                 (void *) &cmd_setbonding_mode_mode,
5844                                 (void *) &cmd_setbonding_mode_value,
5845                                 (void *) &cmd_setbonding_mode_port,
5846                                 NULL
5847                 }
5848 };
5849
5850 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5851 struct cmd_set_bonding_lacp_dedicated_queues_result {
5852         cmdline_fixed_string_t set;
5853         cmdline_fixed_string_t bonding;
5854         cmdline_fixed_string_t lacp;
5855         cmdline_fixed_string_t dedicated_queues;
5856         portid_t port_id;
5857         cmdline_fixed_string_t mode;
5858 };
5859
5860 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5861                 __rte_unused  struct cmdline *cl,
5862                 __rte_unused void *data)
5863 {
5864         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5865         portid_t port_id = res->port_id;
5866         struct rte_port *port;
5867
5868         port = &ports[port_id];
5869
5870         /** Check if the port is not started **/
5871         if (port->port_status != RTE_PORT_STOPPED) {
5872                 printf("Please stop port %d first\n", port_id);
5873                 return;
5874         }
5875
5876         if (!strcmp(res->mode, "enable")) {
5877                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5878                         printf("Dedicate queues for LACP control packets"
5879                                         " enabled\n");
5880                 else
5881                         printf("Enabling dedicate queues for LACP control "
5882                                         "packets on port %d failed\n", port_id);
5883         } else if (!strcmp(res->mode, "disable")) {
5884                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5885                         printf("Dedicated queues for LACP control packets "
5886                                         "disabled\n");
5887                 else
5888                         printf("Disabling dedicated queues for LACP control "
5889                                         "traffic on port %d failed\n", port_id);
5890         }
5891 }
5892
5893 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5894 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5895                 set, "set");
5896 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5897 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5898                 bonding, "bonding");
5899 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5900 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5901                 lacp, "lacp");
5902 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5903 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5904                 dedicated_queues, "dedicated_queues");
5905 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5906 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5907                 port_id, UINT16);
5908 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5909 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5910                 mode, "enable#disable");
5911
5912 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5913                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5914                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5915                         "enable|disable: "
5916                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5917                 .data = NULL,
5918                 .tokens = {
5919                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5920                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5921                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5922                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5923                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5924                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5925                         NULL
5926                 }
5927 };
5928
5929 /* *** SET BALANCE XMIT POLICY *** */
5930 struct cmd_set_bonding_balance_xmit_policy_result {
5931         cmdline_fixed_string_t set;
5932         cmdline_fixed_string_t bonding;
5933         cmdline_fixed_string_t balance_xmit_policy;
5934         portid_t port_id;
5935         cmdline_fixed_string_t policy;
5936 };
5937
5938 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5939                 __rte_unused  struct cmdline *cl,
5940                 __rte_unused void *data)
5941 {
5942         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5943         portid_t port_id = res->port_id;
5944         uint8_t policy;
5945
5946         if (!strcmp(res->policy, "l2")) {
5947                 policy = BALANCE_XMIT_POLICY_LAYER2;
5948         } else if (!strcmp(res->policy, "l23")) {
5949                 policy = BALANCE_XMIT_POLICY_LAYER23;
5950         } else if (!strcmp(res->policy, "l34")) {
5951                 policy = BALANCE_XMIT_POLICY_LAYER34;
5952         } else {
5953                 printf("\t Invalid xmit policy selection");
5954                 return;
5955         }
5956
5957         /* Set the bonding mode for the relevant port. */
5958         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5959                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5960                                 port_id);
5961         }
5962 }
5963
5964 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5965 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5966                 set, "set");
5967 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
5968 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5969                 bonding, "bonding");
5970 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
5971 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5972                 balance_xmit_policy, "balance_xmit_policy");
5973 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
5974 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5975                 port_id, UINT16);
5976 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
5977 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
5978                 policy, "l2#l23#l34");
5979
5980 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
5981                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
5982                 .help_str = "set bonding balance_xmit_policy <port_id> "
5983                         "l2|l23|l34: "
5984                         "Set the bonding balance_xmit_policy for port_id",
5985                 .data = NULL,
5986                 .tokens = {
5987                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
5988                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
5989                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
5990                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
5991                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
5992                                 NULL
5993                 }
5994 };
5995
5996 /* *** SHOW NIC BONDING CONFIGURATION *** */
5997 struct cmd_show_bonding_config_result {
5998         cmdline_fixed_string_t show;
5999         cmdline_fixed_string_t bonding;
6000         cmdline_fixed_string_t config;
6001         portid_t port_id;
6002 };
6003
6004 static void cmd_show_bonding_config_parsed(void *parsed_result,
6005                 __rte_unused  struct cmdline *cl,
6006                 __rte_unused void *data)
6007 {
6008         struct cmd_show_bonding_config_result *res = parsed_result;
6009         int bonding_mode, agg_mode;
6010         portid_t slaves[RTE_MAX_ETHPORTS];
6011         int num_slaves, num_active_slaves;
6012         int primary_id;
6013         int i;
6014         portid_t port_id = res->port_id;
6015
6016         /* Display the bonding mode.*/
6017         bonding_mode = rte_eth_bond_mode_get(port_id);
6018         if (bonding_mode < 0) {
6019                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6020                 return;
6021         } else
6022                 printf("\tBonding mode: %d\n", bonding_mode);
6023
6024         if (bonding_mode == BONDING_MODE_BALANCE) {
6025                 int balance_xmit_policy;
6026
6027                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6028                 if (balance_xmit_policy < 0) {
6029                         printf("\tFailed to get balance xmit policy for port = %d\n",
6030                                         port_id);
6031                         return;
6032                 } else {
6033                         printf("\tBalance Xmit Policy: ");
6034
6035                         switch (balance_xmit_policy) {
6036                         case BALANCE_XMIT_POLICY_LAYER2:
6037                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6038                                 break;
6039                         case BALANCE_XMIT_POLICY_LAYER23:
6040                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6041                                 break;
6042                         case BALANCE_XMIT_POLICY_LAYER34:
6043                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6044                                 break;
6045                         }
6046                         printf("\n");
6047                 }
6048         }
6049
6050         if (bonding_mode == BONDING_MODE_8023AD) {
6051                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6052                 printf("\tIEEE802.3AD Aggregator Mode: ");
6053                 switch (agg_mode) {
6054                 case AGG_BANDWIDTH:
6055                         printf("bandwidth");
6056                         break;
6057                 case AGG_STABLE:
6058                         printf("stable");
6059                         break;
6060                 case AGG_COUNT:
6061                         printf("count");
6062                         break;
6063                 }
6064                 printf("\n");
6065         }
6066
6067         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6068
6069         if (num_slaves < 0) {
6070                 printf("\tFailed to get slave list for port = %d\n", port_id);
6071                 return;
6072         }
6073         if (num_slaves > 0) {
6074                 printf("\tSlaves (%d): [", num_slaves);
6075                 for (i = 0; i < num_slaves - 1; i++)
6076                         printf("%d ", slaves[i]);
6077
6078                 printf("%d]\n", slaves[num_slaves - 1]);
6079         } else {
6080                 printf("\tSlaves: []\n");
6081
6082         }
6083
6084         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6085                         RTE_MAX_ETHPORTS);
6086
6087         if (num_active_slaves < 0) {
6088                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6089                 return;
6090         }
6091         if (num_active_slaves > 0) {
6092                 printf("\tActive Slaves (%d): [", num_active_slaves);
6093                 for (i = 0; i < num_active_slaves - 1; i++)
6094                         printf("%d ", slaves[i]);
6095
6096                 printf("%d]\n", slaves[num_active_slaves - 1]);
6097
6098         } else {
6099                 printf("\tActive Slaves: []\n");
6100
6101         }
6102
6103         primary_id = rte_eth_bond_primary_get(port_id);
6104         if (primary_id < 0) {
6105                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6106                 return;
6107         } else
6108                 printf("\tPrimary: [%d]\n", primary_id);
6109
6110 }
6111
6112 cmdline_parse_token_string_t cmd_showbonding_config_show =
6113 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6114                 show, "show");
6115 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6116 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6117                 bonding, "bonding");
6118 cmdline_parse_token_string_t cmd_showbonding_config_config =
6119 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6120                 config, "config");
6121 cmdline_parse_token_num_t cmd_showbonding_config_port =
6122 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6123                 port_id, UINT16);
6124
6125 cmdline_parse_inst_t cmd_show_bonding_config = {
6126                 .f = cmd_show_bonding_config_parsed,
6127                 .help_str = "show bonding config <port_id>: "
6128                         "Show the bonding config for port_id",
6129                 .data = NULL,
6130                 .tokens = {
6131                                 (void *)&cmd_showbonding_config_show,
6132                                 (void *)&cmd_showbonding_config_bonding,
6133                                 (void *)&cmd_showbonding_config_config,
6134                                 (void *)&cmd_showbonding_config_port,
6135                                 NULL
6136                 }
6137 };
6138
6139 /* *** SET BONDING PRIMARY *** */
6140 struct cmd_set_bonding_primary_result {
6141         cmdline_fixed_string_t set;
6142         cmdline_fixed_string_t bonding;
6143         cmdline_fixed_string_t primary;
6144         portid_t slave_id;
6145         portid_t port_id;
6146 };
6147
6148 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6149                 __rte_unused  struct cmdline *cl,
6150                 __rte_unused void *data)
6151 {
6152         struct cmd_set_bonding_primary_result *res = parsed_result;
6153         portid_t master_port_id = res->port_id;
6154         portid_t slave_port_id = res->slave_id;
6155
6156         /* Set the primary slave for a bonded device. */
6157         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6158                 printf("\t Failed to set primary slave for port = %d.\n",
6159                                 master_port_id);
6160                 return;
6161         }
6162         init_port_config();
6163 }
6164
6165 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6166 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6167                 set, "set");
6168 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6169 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6170                 bonding, "bonding");
6171 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6172 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6173                 primary, "primary");
6174 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6175 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6176                 slave_id, UINT16);
6177 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6178 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6179                 port_id, UINT16);
6180
6181 cmdline_parse_inst_t cmd_set_bonding_primary = {
6182                 .f = cmd_set_bonding_primary_parsed,
6183                 .help_str = "set bonding primary <slave_id> <port_id>: "
6184                         "Set the primary slave for port_id",
6185                 .data = NULL,
6186                 .tokens = {
6187                                 (void *)&cmd_setbonding_primary_set,
6188                                 (void *)&cmd_setbonding_primary_bonding,
6189                                 (void *)&cmd_setbonding_primary_primary,
6190                                 (void *)&cmd_setbonding_primary_slave,
6191                                 (void *)&cmd_setbonding_primary_port,
6192                                 NULL
6193                 }
6194 };
6195
6196 /* *** ADD SLAVE *** */
6197 struct cmd_add_bonding_slave_result {
6198         cmdline_fixed_string_t add;
6199         cmdline_fixed_string_t bonding;
6200         cmdline_fixed_string_t slave;
6201         portid_t slave_id;
6202         portid_t port_id;
6203 };
6204
6205 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6206                 __rte_unused  struct cmdline *cl,
6207                 __rte_unused void *data)
6208 {
6209         struct cmd_add_bonding_slave_result *res = parsed_result;
6210         portid_t master_port_id = res->port_id;
6211         portid_t slave_port_id = res->slave_id;
6212
6213         /* add the slave for a bonded device. */
6214         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6215                 printf("\t Failed to add slave %d to master port = %d.\n",
6216                                 slave_port_id, master_port_id);
6217                 return;
6218         }
6219         init_port_config();
6220         set_port_slave_flag(slave_port_id);
6221 }
6222
6223 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6224 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6225                 add, "add");
6226 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6227 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6228                 bonding, "bonding");
6229 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6230 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6231                 slave, "slave");
6232 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6233 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6234                 slave_id, UINT16);
6235 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6236 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6237                 port_id, UINT16);
6238
6239 cmdline_parse_inst_t cmd_add_bonding_slave = {
6240                 .f = cmd_add_bonding_slave_parsed,
6241                 .help_str = "add bonding slave <slave_id> <port_id>: "
6242                         "Add a slave device to a bonded device",
6243                 .data = NULL,
6244                 .tokens = {
6245                                 (void *)&cmd_addbonding_slave_add,
6246                                 (void *)&cmd_addbonding_slave_bonding,
6247                                 (void *)&cmd_addbonding_slave_slave,
6248                                 (void *)&cmd_addbonding_slave_slaveid,
6249                                 (void *)&cmd_addbonding_slave_port,
6250                                 NULL
6251                 }
6252 };
6253
6254 /* *** REMOVE SLAVE *** */
6255 struct cmd_remove_bonding_slave_result {
6256         cmdline_fixed_string_t remove;
6257         cmdline_fixed_string_t bonding;
6258         cmdline_fixed_string_t slave;
6259         portid_t slave_id;
6260         portid_t port_id;
6261 };
6262
6263 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6264                 __rte_unused  struct cmdline *cl,
6265                 __rte_unused void *data)
6266 {
6267         struct cmd_remove_bonding_slave_result *res = parsed_result;
6268         portid_t master_port_id = res->port_id;
6269         portid_t slave_port_id = res->slave_id;
6270
6271         /* remove the slave from a bonded device. */
6272         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6273                 printf("\t Failed to remove slave %d from master port = %d.\n",
6274                                 slave_port_id, master_port_id);
6275                 return;
6276         }
6277         init_port_config();
6278         clear_port_slave_flag(slave_port_id);
6279 }
6280
6281 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6282                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6283                                 remove, "remove");
6284 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6285                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6286                                 bonding, "bonding");
6287 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6288                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6289                                 slave, "slave");
6290 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6291                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6292                                 slave_id, UINT16);
6293 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6294                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6295                                 port_id, UINT16);
6296
6297 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6298                 .f = cmd_remove_bonding_slave_parsed,
6299                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6300                         "Remove a slave device from a bonded device",
6301                 .data = NULL,
6302                 .tokens = {
6303                                 (void *)&cmd_removebonding_slave_remove,
6304                                 (void *)&cmd_removebonding_slave_bonding,
6305                                 (void *)&cmd_removebonding_slave_slave,
6306                                 (void *)&cmd_removebonding_slave_slaveid,
6307                                 (void *)&cmd_removebonding_slave_port,
6308                                 NULL
6309                 }
6310 };
6311
6312 /* *** CREATE BONDED DEVICE *** */
6313 struct cmd_create_bonded_device_result {
6314         cmdline_fixed_string_t create;
6315         cmdline_fixed_string_t bonded;
6316         cmdline_fixed_string_t device;
6317         uint8_t mode;
6318         uint8_t socket;
6319 };
6320
6321 static int bond_dev_num = 0;
6322
6323 static void cmd_create_bonded_device_parsed(void *parsed_result,
6324                 __rte_unused  struct cmdline *cl,
6325                 __rte_unused void *data)
6326 {
6327         struct cmd_create_bonded_device_result *res = parsed_result;
6328         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6329         int port_id;
6330         int ret;
6331
6332         if (test_done == 0) {
6333                 printf("Please stop forwarding first\n");
6334                 return;
6335         }
6336
6337         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6338                         bond_dev_num++);
6339
6340         /* Create a new bonded device. */
6341         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6342         if (port_id < 0) {
6343                 printf("\t Failed to create bonded device.\n");
6344                 return;
6345         } else {
6346                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6347                                 port_id);
6348
6349                 /* Update number of ports */
6350                 nb_ports = rte_eth_dev_count_avail();
6351                 reconfig(port_id, res->socket);
6352                 ret = rte_eth_promiscuous_enable(port_id);
6353                 if (ret != 0)
6354                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6355                                 port_id, rte_strerror(-ret));
6356
6357                 ports[port_id].need_setup = 0;
6358                 ports[port_id].port_status = RTE_PORT_STOPPED;
6359         }
6360
6361 }
6362
6363 cmdline_parse_token_string_t cmd_createbonded_device_create =
6364                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6365                                 create, "create");
6366 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6367                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6368                                 bonded, "bonded");
6369 cmdline_parse_token_string_t cmd_createbonded_device_device =
6370                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6371                                 device, "device");
6372 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6373                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6374                                 mode, UINT8);
6375 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6376                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6377                                 socket, UINT8);
6378
6379 cmdline_parse_inst_t cmd_create_bonded_device = {
6380                 .f = cmd_create_bonded_device_parsed,
6381                 .help_str = "create bonded device <mode> <socket>: "
6382                         "Create a new bonded device with specific bonding mode and socket",
6383                 .data = NULL,
6384                 .tokens = {
6385                                 (void *)&cmd_createbonded_device_create,
6386                                 (void *)&cmd_createbonded_device_bonded,
6387                                 (void *)&cmd_createbonded_device_device,
6388                                 (void *)&cmd_createbonded_device_mode,
6389                                 (void *)&cmd_createbonded_device_socket,
6390                                 NULL
6391                 }
6392 };
6393
6394 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6395 struct cmd_set_bond_mac_addr_result {
6396         cmdline_fixed_string_t set;
6397         cmdline_fixed_string_t bonding;
6398         cmdline_fixed_string_t mac_addr;
6399         uint16_t port_num;
6400         struct rte_ether_addr address;
6401 };
6402
6403 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6404                 __rte_unused  struct cmdline *cl,
6405                 __rte_unused void *data)
6406 {
6407         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6408         int ret;
6409
6410         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6411                 return;
6412
6413         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6414
6415         /* check the return value and print it if is < 0 */
6416         if (ret < 0)
6417                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6418 }
6419
6420 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6421                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6422 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6423                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6424                                 "bonding");
6425 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6426                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6427                                 "mac_addr");
6428 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6429                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6430                                 port_num, UINT16);
6431 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6432                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6433
6434 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6435                 .f = cmd_set_bond_mac_addr_parsed,
6436                 .data = (void *) 0,
6437                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6438                 .tokens = {
6439                                 (void *)&cmd_set_bond_mac_addr_set,
6440                                 (void *)&cmd_set_bond_mac_addr_bonding,
6441                                 (void *)&cmd_set_bond_mac_addr_mac,
6442                                 (void *)&cmd_set_bond_mac_addr_portnum,
6443                                 (void *)&cmd_set_bond_mac_addr_addr,
6444                                 NULL
6445                 }
6446 };
6447
6448
6449 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6450 struct cmd_set_bond_mon_period_result {
6451         cmdline_fixed_string_t set;
6452         cmdline_fixed_string_t bonding;
6453         cmdline_fixed_string_t mon_period;
6454         uint16_t port_num;
6455         uint32_t period_ms;
6456 };
6457
6458 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6459                 __rte_unused  struct cmdline *cl,
6460                 __rte_unused void *data)
6461 {
6462         struct cmd_set_bond_mon_period_result *res = parsed_result;
6463         int ret;
6464
6465         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6466
6467         /* check the return value and print it if is < 0 */
6468         if (ret < 0)
6469                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6470 }
6471
6472 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6473                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6474                                 set, "set");
6475 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6476                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6477                                 bonding, "bonding");
6478 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6479                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6480                                 mon_period,     "mon_period");
6481 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6482                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6483                                 port_num, UINT16);
6484 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6485                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6486                                 period_ms, UINT32);
6487
6488 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6489                 .f = cmd_set_bond_mon_period_parsed,
6490                 .data = (void *) 0,
6491                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6492                 .tokens = {
6493                                 (void *)&cmd_set_bond_mon_period_set,
6494                                 (void *)&cmd_set_bond_mon_period_bonding,
6495                                 (void *)&cmd_set_bond_mon_period_mon_period,
6496                                 (void *)&cmd_set_bond_mon_period_portnum,
6497                                 (void *)&cmd_set_bond_mon_period_period_ms,
6498                                 NULL
6499                 }
6500 };
6501
6502
6503
6504 struct cmd_set_bonding_agg_mode_policy_result {
6505         cmdline_fixed_string_t set;
6506         cmdline_fixed_string_t bonding;
6507         cmdline_fixed_string_t agg_mode;
6508         uint16_t port_num;
6509         cmdline_fixed_string_t policy;
6510 };
6511
6512
6513 static void
6514 cmd_set_bonding_agg_mode(void *parsed_result,
6515                 __rte_unused struct cmdline *cl,
6516                 __rte_unused void *data)
6517 {
6518         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6519         uint8_t policy = AGG_BANDWIDTH;
6520
6521         if (!strcmp(res->policy, "bandwidth"))
6522                 policy = AGG_BANDWIDTH;
6523         else if (!strcmp(res->policy, "stable"))
6524                 policy = AGG_STABLE;
6525         else if (!strcmp(res->policy, "count"))
6526                 policy = AGG_COUNT;
6527
6528         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6529 }
6530
6531
6532 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6533         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6534                                 set, "set");
6535 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6536         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6537                                 bonding, "bonding");
6538
6539 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6540         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6541                                 agg_mode, "agg_mode");
6542
6543 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6544         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6545                                 port_num, UINT16);
6546
6547 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6548         TOKEN_STRING_INITIALIZER(
6549                         struct cmd_set_bonding_balance_xmit_policy_result,
6550                 policy, "stable#bandwidth#count");
6551
6552 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6553         .f = cmd_set_bonding_agg_mode,
6554         .data = (void *) 0,
6555         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6556         .tokens = {
6557                         (void *)&cmd_set_bonding_agg_mode_set,
6558                         (void *)&cmd_set_bonding_agg_mode_bonding,
6559                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6560                         (void *)&cmd_set_bonding_agg_mode_portnum,
6561                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6562                         NULL
6563                 }
6564 };
6565
6566
6567 #endif /* RTE_LIBRTE_PMD_BOND */
6568
6569 /* *** SET FORWARDING MODE *** */
6570 struct cmd_set_fwd_mode_result {
6571         cmdline_fixed_string_t set;
6572         cmdline_fixed_string_t fwd;
6573         cmdline_fixed_string_t mode;
6574 };
6575
6576 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6577                                     __rte_unused struct cmdline *cl,
6578                                     __rte_unused void *data)
6579 {
6580         struct cmd_set_fwd_mode_result *res = parsed_result;
6581
6582         retry_enabled = 0;
6583         set_pkt_forwarding_mode(res->mode);
6584 }
6585
6586 cmdline_parse_token_string_t cmd_setfwd_set =
6587         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6588 cmdline_parse_token_string_t cmd_setfwd_fwd =
6589         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6590 cmdline_parse_token_string_t cmd_setfwd_mode =
6591         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6592                 "" /* defined at init */);
6593
6594 cmdline_parse_inst_t cmd_set_fwd_mode = {
6595         .f = cmd_set_fwd_mode_parsed,
6596         .data = NULL,
6597         .help_str = NULL, /* defined at init */
6598         .tokens = {
6599                 (void *)&cmd_setfwd_set,
6600                 (void *)&cmd_setfwd_fwd,
6601                 (void *)&cmd_setfwd_mode,
6602                 NULL,
6603         },
6604 };
6605
6606 static void cmd_set_fwd_mode_init(void)
6607 {
6608         char *modes, *c;
6609         static char token[128];
6610         static char help[256];
6611         cmdline_parse_token_string_t *token_struct;
6612
6613         modes = list_pkt_forwarding_modes();
6614         snprintf(help, sizeof(help), "set fwd %s: "
6615                 "Set packet forwarding mode", modes);
6616         cmd_set_fwd_mode.help_str = help;
6617
6618         /* string token separator is # */
6619         for (c = token; *modes != '\0'; modes++)
6620                 if (*modes == '|')
6621                         *c++ = '#';
6622                 else
6623                         *c++ = *modes;
6624         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6625         token_struct->string_data.str = token;
6626 }
6627
6628 /* *** SET RETRY FORWARDING MODE *** */
6629 struct cmd_set_fwd_retry_mode_result {
6630         cmdline_fixed_string_t set;
6631         cmdline_fixed_string_t fwd;
6632         cmdline_fixed_string_t mode;
6633         cmdline_fixed_string_t retry;
6634 };
6635
6636 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6637                             __rte_unused struct cmdline *cl,
6638                             __rte_unused void *data)
6639 {
6640         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6641
6642         retry_enabled = 1;
6643         set_pkt_forwarding_mode(res->mode);
6644 }
6645
6646 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6647         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6648                         set, "set");
6649 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6650         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6651                         fwd, "fwd");
6652 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6653         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6654                         mode,
6655                 "" /* defined at init */);
6656 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6657         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6658                         retry, "retry");
6659
6660 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6661         .f = cmd_set_fwd_retry_mode_parsed,
6662         .data = NULL,
6663         .help_str = NULL, /* defined at init */
6664         .tokens = {
6665                 (void *)&cmd_setfwd_retry_set,
6666                 (void *)&cmd_setfwd_retry_fwd,
6667                 (void *)&cmd_setfwd_retry_mode,
6668                 (void *)&cmd_setfwd_retry_retry,
6669                 NULL,
6670         },
6671 };
6672
6673 static void cmd_set_fwd_retry_mode_init(void)
6674 {
6675         char *modes, *c;
6676         static char token[128];
6677         static char help[256];
6678         cmdline_parse_token_string_t *token_struct;
6679
6680         modes = list_pkt_forwarding_retry_modes();
6681         snprintf(help, sizeof(help), "set fwd %s retry: "
6682                 "Set packet forwarding mode with retry", modes);
6683         cmd_set_fwd_retry_mode.help_str = help;
6684
6685         /* string token separator is # */
6686         for (c = token; *modes != '\0'; modes++)
6687                 if (*modes == '|')
6688                         *c++ = '#';
6689                 else
6690                         *c++ = *modes;
6691         token_struct = (cmdline_parse_token_string_t *)
6692                 cmd_set_fwd_retry_mode.tokens[2];
6693         token_struct->string_data.str = token;
6694 }
6695
6696 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6697 struct cmd_set_burst_tx_retry_result {
6698         cmdline_fixed_string_t set;
6699         cmdline_fixed_string_t burst;
6700         cmdline_fixed_string_t tx;
6701         cmdline_fixed_string_t delay;
6702         uint32_t time;
6703         cmdline_fixed_string_t retry;
6704         uint32_t retry_num;
6705 };
6706
6707 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6708                                         __rte_unused struct cmdline *cl,
6709                                         __rte_unused void *data)
6710 {
6711         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6712
6713         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6714                 && !strcmp(res->tx, "tx")) {
6715                 if (!strcmp(res->delay, "delay"))
6716                         burst_tx_delay_time = res->time;
6717                 if (!strcmp(res->retry, "retry"))
6718                         burst_tx_retry_num = res->retry_num;
6719         }
6720
6721 }
6722
6723 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6724         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6725 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6726         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6727                                  "burst");
6728 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6729         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6730 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6731         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6732 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6733         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6734 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6735         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6736 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6737         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6738
6739 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6740         .f = cmd_set_burst_tx_retry_parsed,
6741         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6742         .tokens = {
6743                 (void *)&cmd_set_burst_tx_retry_set,
6744                 (void *)&cmd_set_burst_tx_retry_burst,
6745                 (void *)&cmd_set_burst_tx_retry_tx,
6746                 (void *)&cmd_set_burst_tx_retry_delay,
6747                 (void *)&cmd_set_burst_tx_retry_time,
6748                 (void *)&cmd_set_burst_tx_retry_retry,
6749                 (void *)&cmd_set_burst_tx_retry_retry_num,
6750                 NULL,
6751         },
6752 };
6753
6754 /* *** SET PROMISC MODE *** */
6755 struct cmd_set_promisc_mode_result {
6756         cmdline_fixed_string_t set;
6757         cmdline_fixed_string_t promisc;
6758         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6759         uint16_t port_num;               /* valid if "allports" argument == 0 */
6760         cmdline_fixed_string_t mode;
6761 };
6762
6763 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6764                                         __rte_unused struct cmdline *cl,
6765                                         void *allports)
6766 {
6767         struct cmd_set_promisc_mode_result *res = parsed_result;
6768         int enable;
6769         portid_t i;
6770
6771         if (!strcmp(res->mode, "on"))
6772                 enable = 1;
6773         else
6774                 enable = 0;
6775
6776         /* all ports */
6777         if (allports) {
6778                 RTE_ETH_FOREACH_DEV(i)
6779                         eth_set_promisc_mode(i, enable);
6780         } else {
6781                 eth_set_promisc_mode(res->port_num, enable);
6782         }
6783 }
6784
6785 cmdline_parse_token_string_t cmd_setpromisc_set =
6786         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6787 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6788         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6789                                  "promisc");
6790 cmdline_parse_token_string_t cmd_setpromisc_portall =
6791         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6792                                  "all");
6793 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6794         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6795                               UINT16);
6796 cmdline_parse_token_string_t cmd_setpromisc_mode =
6797         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6798                                  "on#off");
6799
6800 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6801         .f = cmd_set_promisc_mode_parsed,
6802         .data = (void *)1,
6803         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6804         .tokens = {
6805                 (void *)&cmd_setpromisc_set,
6806                 (void *)&cmd_setpromisc_promisc,
6807                 (void *)&cmd_setpromisc_portall,
6808                 (void *)&cmd_setpromisc_mode,
6809                 NULL,
6810         },
6811 };
6812
6813 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6814         .f = cmd_set_promisc_mode_parsed,
6815         .data = (void *)0,
6816         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6817         .tokens = {
6818                 (void *)&cmd_setpromisc_set,
6819                 (void *)&cmd_setpromisc_promisc,
6820                 (void *)&cmd_setpromisc_portnum,
6821                 (void *)&cmd_setpromisc_mode,
6822                 NULL,
6823         },
6824 };
6825
6826 /* *** SET ALLMULTI MODE *** */
6827 struct cmd_set_allmulti_mode_result {
6828         cmdline_fixed_string_t set;
6829         cmdline_fixed_string_t allmulti;
6830         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6831         uint16_t port_num;               /* valid if "allports" argument == 0 */
6832         cmdline_fixed_string_t mode;
6833 };
6834
6835 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6836                                         __rte_unused struct cmdline *cl,
6837                                         void *allports)
6838 {
6839         struct cmd_set_allmulti_mode_result *res = parsed_result;
6840         int enable;
6841         portid_t i;
6842
6843         if (!strcmp(res->mode, "on"))
6844                 enable = 1;
6845         else
6846                 enable = 0;
6847
6848         /* all ports */
6849         if (allports) {
6850                 RTE_ETH_FOREACH_DEV(i) {
6851                         eth_set_allmulticast_mode(i, enable);
6852                 }
6853         }
6854         else {
6855                 eth_set_allmulticast_mode(res->port_num, enable);
6856         }
6857 }
6858
6859 cmdline_parse_token_string_t cmd_setallmulti_set =
6860         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6861 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6862         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6863                                  "allmulti");
6864 cmdline_parse_token_string_t cmd_setallmulti_portall =
6865         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6866                                  "all");
6867 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6868         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6869                               UINT16);
6870 cmdline_parse_token_string_t cmd_setallmulti_mode =
6871         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6872                                  "on#off");
6873
6874 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6875         .f = cmd_set_allmulti_mode_parsed,
6876         .data = (void *)1,
6877         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6878         .tokens = {
6879                 (void *)&cmd_setallmulti_set,
6880                 (void *)&cmd_setallmulti_allmulti,
6881                 (void *)&cmd_setallmulti_portall,
6882                 (void *)&cmd_setallmulti_mode,
6883                 NULL,
6884         },
6885 };
6886
6887 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6888         .f = cmd_set_allmulti_mode_parsed,
6889         .data = (void *)0,
6890         .help_str = "set allmulti <port_id> on|off: "
6891                 "Set allmulti mode on port_id",
6892         .tokens = {
6893                 (void *)&cmd_setallmulti_set,
6894                 (void *)&cmd_setallmulti_allmulti,
6895                 (void *)&cmd_setallmulti_portnum,
6896                 (void *)&cmd_setallmulti_mode,
6897                 NULL,
6898         },
6899 };
6900
6901 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6902 struct cmd_link_flow_ctrl_set_result {
6903         cmdline_fixed_string_t set;
6904         cmdline_fixed_string_t flow_ctrl;
6905         cmdline_fixed_string_t rx;
6906         cmdline_fixed_string_t rx_lfc_mode;
6907         cmdline_fixed_string_t tx;
6908         cmdline_fixed_string_t tx_lfc_mode;
6909         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6910         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6911         cmdline_fixed_string_t autoneg_str;
6912         cmdline_fixed_string_t autoneg;
6913         cmdline_fixed_string_t hw_str;
6914         uint32_t high_water;
6915         cmdline_fixed_string_t lw_str;
6916         uint32_t low_water;
6917         cmdline_fixed_string_t pt_str;
6918         uint16_t pause_time;
6919         cmdline_fixed_string_t xon_str;
6920         uint16_t send_xon;
6921         portid_t port_id;
6922 };
6923
6924 cmdline_parse_token_string_t cmd_lfc_set_set =
6925         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6926                                 set, "set");
6927 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6928         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6929                                 flow_ctrl, "flow_ctrl");
6930 cmdline_parse_token_string_t cmd_lfc_set_rx =
6931         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6932                                 rx, "rx");
6933 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6934         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6935                                 rx_lfc_mode, "on#off");
6936 cmdline_parse_token_string_t cmd_lfc_set_tx =
6937         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6938                                 tx, "tx");
6939 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6940         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6941                                 tx_lfc_mode, "on#off");
6942 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6944                                 hw_str, "high_water");
6945 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6946         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6947                                 high_water, UINT32);
6948 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6949         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6950                                 lw_str, "low_water");
6951 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6952         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6953                                 low_water, UINT32);
6954 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6956                                 pt_str, "pause_time");
6957 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6958         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6959                                 pause_time, UINT16);
6960 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6961         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6962                                 xon_str, "send_xon");
6963 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6964         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6965                                 send_xon, UINT16);
6966 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
6967         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6968                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
6969 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
6970         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6971                                 mac_ctrl_frame_fwd_mode, "on#off");
6972 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
6973         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6974                                 autoneg_str, "autoneg");
6975 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
6976         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6977                                 autoneg, "on#off");
6978 cmdline_parse_token_num_t cmd_lfc_set_portid =
6979         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6980                                 port_id, UINT16);
6981
6982 /* forward declaration */
6983 static void
6984 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
6985                               void *data);
6986
6987 cmdline_parse_inst_t cmd_link_flow_control_set = {
6988         .f = cmd_link_flow_ctrl_set_parsed,
6989         .data = NULL,
6990         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
6991                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
6992                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
6993         .tokens = {
6994                 (void *)&cmd_lfc_set_set,
6995                 (void *)&cmd_lfc_set_flow_ctrl,
6996                 (void *)&cmd_lfc_set_rx,
6997                 (void *)&cmd_lfc_set_rx_mode,
6998                 (void *)&cmd_lfc_set_tx,
6999                 (void *)&cmd_lfc_set_tx_mode,
7000                 (void *)&cmd_lfc_set_high_water,
7001                 (void *)&cmd_lfc_set_low_water,
7002                 (void *)&cmd_lfc_set_pause_time,
7003                 (void *)&cmd_lfc_set_send_xon,
7004                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7005                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7006                 (void *)&cmd_lfc_set_autoneg_str,
7007                 (void *)&cmd_lfc_set_autoneg,
7008                 (void *)&cmd_lfc_set_portid,
7009                 NULL,
7010         },
7011 };
7012
7013 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7014         .f = cmd_link_flow_ctrl_set_parsed,
7015         .data = (void *)&cmd_link_flow_control_set_rx,
7016         .help_str = "set flow_ctrl rx on|off <port_id>: "
7017                 "Change rx flow control parameter",
7018         .tokens = {
7019                 (void *)&cmd_lfc_set_set,
7020                 (void *)&cmd_lfc_set_flow_ctrl,
7021                 (void *)&cmd_lfc_set_rx,
7022                 (void *)&cmd_lfc_set_rx_mode,
7023                 (void *)&cmd_lfc_set_portid,
7024                 NULL,
7025         },
7026 };
7027
7028 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7029         .f = cmd_link_flow_ctrl_set_parsed,
7030         .data = (void *)&cmd_link_flow_control_set_tx,
7031         .help_str = "set flow_ctrl tx on|off <port_id>: "
7032                 "Change tx flow control parameter",
7033         .tokens = {
7034                 (void *)&cmd_lfc_set_set,
7035                 (void *)&cmd_lfc_set_flow_ctrl,
7036                 (void *)&cmd_lfc_set_tx,
7037                 (void *)&cmd_lfc_set_tx_mode,
7038                 (void *)&cmd_lfc_set_portid,
7039                 NULL,
7040         },
7041 };
7042
7043 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7044         .f = cmd_link_flow_ctrl_set_parsed,
7045         .data = (void *)&cmd_link_flow_control_set_hw,
7046         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7047                 "Change high water flow control parameter",
7048         .tokens = {
7049                 (void *)&cmd_lfc_set_set,
7050                 (void *)&cmd_lfc_set_flow_ctrl,
7051                 (void *)&cmd_lfc_set_high_water_str,
7052                 (void *)&cmd_lfc_set_high_water,
7053                 (void *)&cmd_lfc_set_portid,
7054                 NULL,
7055         },
7056 };
7057
7058 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7059         .f = cmd_link_flow_ctrl_set_parsed,
7060         .data = (void *)&cmd_link_flow_control_set_lw,
7061         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7062                 "Change low water flow control parameter",
7063         .tokens = {
7064                 (void *)&cmd_lfc_set_set,
7065                 (void *)&cmd_lfc_set_flow_ctrl,
7066                 (void *)&cmd_lfc_set_low_water_str,
7067                 (void *)&cmd_lfc_set_low_water,
7068                 (void *)&cmd_lfc_set_portid,
7069                 NULL,
7070         },
7071 };
7072
7073 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7074         .f = cmd_link_flow_ctrl_set_parsed,
7075         .data = (void *)&cmd_link_flow_control_set_pt,
7076         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7077                 "Change pause time flow control parameter",
7078         .tokens = {
7079                 (void *)&cmd_lfc_set_set,
7080                 (void *)&cmd_lfc_set_flow_ctrl,
7081                 (void *)&cmd_lfc_set_pause_time_str,
7082                 (void *)&cmd_lfc_set_pause_time,
7083                 (void *)&cmd_lfc_set_portid,
7084                 NULL,
7085         },
7086 };
7087
7088 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7089         .f = cmd_link_flow_ctrl_set_parsed,
7090         .data = (void *)&cmd_link_flow_control_set_xon,
7091         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7092                 "Change send_xon flow control parameter",
7093         .tokens = {
7094                 (void *)&cmd_lfc_set_set,
7095                 (void *)&cmd_lfc_set_flow_ctrl,
7096                 (void *)&cmd_lfc_set_send_xon_str,
7097                 (void *)&cmd_lfc_set_send_xon,
7098                 (void *)&cmd_lfc_set_portid,
7099                 NULL,
7100         },
7101 };
7102
7103 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7104         .f = cmd_link_flow_ctrl_set_parsed,
7105         .data = (void *)&cmd_link_flow_control_set_macfwd,
7106         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7107                 "Change mac ctrl fwd flow control parameter",
7108         .tokens = {
7109                 (void *)&cmd_lfc_set_set,
7110                 (void *)&cmd_lfc_set_flow_ctrl,
7111                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7112                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7113                 (void *)&cmd_lfc_set_portid,
7114                 NULL,
7115         },
7116 };
7117
7118 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7119         .f = cmd_link_flow_ctrl_set_parsed,
7120         .data = (void *)&cmd_link_flow_control_set_autoneg,
7121         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7122                 "Change autoneg flow control parameter",
7123         .tokens = {
7124                 (void *)&cmd_lfc_set_set,
7125                 (void *)&cmd_lfc_set_flow_ctrl,
7126                 (void *)&cmd_lfc_set_autoneg_str,
7127                 (void *)&cmd_lfc_set_autoneg,
7128                 (void *)&cmd_lfc_set_portid,
7129                 NULL,
7130         },
7131 };
7132
7133 static void
7134 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7135                               __rte_unused struct cmdline *cl,
7136                               void *data)
7137 {
7138         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7139         cmdline_parse_inst_t *cmd = data;
7140         struct rte_eth_fc_conf fc_conf;
7141         int rx_fc_en = 0;
7142         int tx_fc_en = 0;
7143         int ret;
7144
7145         /*
7146          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7147          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7148          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7149          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7150          */
7151         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7152                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7153         };
7154
7155         /* Partial command line, retrieve current configuration */
7156         if (cmd) {
7157                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7158                 if (ret != 0) {
7159                         printf("cannot get current flow ctrl parameters, return"
7160                                "code = %d\n", ret);
7161                         return;
7162                 }
7163
7164                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7165                     (fc_conf.mode == RTE_FC_FULL))
7166                         rx_fc_en = 1;
7167                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7168                     (fc_conf.mode == RTE_FC_FULL))
7169                         tx_fc_en = 1;
7170         }
7171
7172         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7173                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7174
7175         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7176                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7177
7178         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7179
7180         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7181                 fc_conf.high_water = res->high_water;
7182
7183         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7184                 fc_conf.low_water = res->low_water;
7185
7186         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7187                 fc_conf.pause_time = res->pause_time;
7188
7189         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7190                 fc_conf.send_xon = res->send_xon;
7191
7192         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7193                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7194                         fc_conf.mac_ctrl_frame_fwd = 1;
7195                 else
7196                         fc_conf.mac_ctrl_frame_fwd = 0;
7197         }
7198
7199         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7200                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7201
7202         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7203         if (ret != 0)
7204                 printf("bad flow contrl parameter, return code = %d \n", ret);
7205 }
7206
7207 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7208 struct cmd_priority_flow_ctrl_set_result {
7209         cmdline_fixed_string_t set;
7210         cmdline_fixed_string_t pfc_ctrl;
7211         cmdline_fixed_string_t rx;
7212         cmdline_fixed_string_t rx_pfc_mode;
7213         cmdline_fixed_string_t tx;
7214         cmdline_fixed_string_t tx_pfc_mode;
7215         uint32_t high_water;
7216         uint32_t low_water;
7217         uint16_t pause_time;
7218         uint8_t  priority;
7219         portid_t port_id;
7220 };
7221
7222 static void
7223 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7224                        __rte_unused struct cmdline *cl,
7225                        __rte_unused void *data)
7226 {
7227         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7228         struct rte_eth_pfc_conf pfc_conf;
7229         int rx_fc_enable, tx_fc_enable;
7230         int ret;
7231
7232         /*
7233          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7234          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7235          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7236          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7237          */
7238         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7239                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7240         };
7241
7242         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7243         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7244         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7245         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7246         pfc_conf.fc.high_water = res->high_water;
7247         pfc_conf.fc.low_water  = res->low_water;
7248         pfc_conf.fc.pause_time = res->pause_time;
7249         pfc_conf.priority      = res->priority;
7250
7251         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7252         if (ret != 0)
7253                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7254 }
7255
7256 cmdline_parse_token_string_t cmd_pfc_set_set =
7257         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7258                                 set, "set");
7259 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7260         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7261                                 pfc_ctrl, "pfc_ctrl");
7262 cmdline_parse_token_string_t cmd_pfc_set_rx =
7263         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7264                                 rx, "rx");
7265 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7266         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7267                                 rx_pfc_mode, "on#off");
7268 cmdline_parse_token_string_t cmd_pfc_set_tx =
7269         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7270                                 tx, "tx");
7271 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7272         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7273                                 tx_pfc_mode, "on#off");
7274 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7275         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7276                                 high_water, UINT32);
7277 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7278         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7279                                 low_water, UINT32);
7280 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7281         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7282                                 pause_time, UINT16);
7283 cmdline_parse_token_num_t cmd_pfc_set_priority =
7284         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7285                                 priority, UINT8);
7286 cmdline_parse_token_num_t cmd_pfc_set_portid =
7287         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7288                                 port_id, UINT16);
7289
7290 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7291         .f = cmd_priority_flow_ctrl_set_parsed,
7292         .data = NULL,
7293         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7294                 "<pause_time> <priority> <port_id>: "
7295                 "Configure the Ethernet priority flow control",
7296         .tokens = {
7297                 (void *)&cmd_pfc_set_set,
7298                 (void *)&cmd_pfc_set_flow_ctrl,
7299                 (void *)&cmd_pfc_set_rx,
7300                 (void *)&cmd_pfc_set_rx_mode,
7301                 (void *)&cmd_pfc_set_tx,
7302                 (void *)&cmd_pfc_set_tx_mode,
7303                 (void *)&cmd_pfc_set_high_water,
7304                 (void *)&cmd_pfc_set_low_water,
7305                 (void *)&cmd_pfc_set_pause_time,
7306                 (void *)&cmd_pfc_set_priority,
7307                 (void *)&cmd_pfc_set_portid,
7308                 NULL,
7309         },
7310 };
7311
7312 /* *** RESET CONFIGURATION *** */
7313 struct cmd_reset_result {
7314         cmdline_fixed_string_t reset;
7315         cmdline_fixed_string_t def;
7316 };
7317
7318 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7319                              struct cmdline *cl,
7320                              __rte_unused void *data)
7321 {
7322         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7323         set_def_fwd_config();
7324 }
7325
7326 cmdline_parse_token_string_t cmd_reset_set =
7327         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7328 cmdline_parse_token_string_t cmd_reset_def =
7329         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7330                                  "default");
7331
7332 cmdline_parse_inst_t cmd_reset = {
7333         .f = cmd_reset_parsed,
7334         .data = NULL,
7335         .help_str = "set default: Reset default forwarding configuration",
7336         .tokens = {
7337                 (void *)&cmd_reset_set,
7338                 (void *)&cmd_reset_def,
7339                 NULL,
7340         },
7341 };
7342
7343 /* *** START FORWARDING *** */
7344 struct cmd_start_result {
7345         cmdline_fixed_string_t start;
7346 };
7347
7348 cmdline_parse_token_string_t cmd_start_start =
7349         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7350
7351 static void cmd_start_parsed(__rte_unused void *parsed_result,
7352                              __rte_unused struct cmdline *cl,
7353                              __rte_unused void *data)
7354 {
7355         start_packet_forwarding(0);
7356 }
7357
7358 cmdline_parse_inst_t cmd_start = {
7359         .f = cmd_start_parsed,
7360         .data = NULL,
7361         .help_str = "start: Start packet forwarding",
7362         .tokens = {
7363                 (void *)&cmd_start_start,
7364                 NULL,
7365         },
7366 };
7367
7368 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7369 struct cmd_start_tx_first_result {
7370         cmdline_fixed_string_t start;
7371         cmdline_fixed_string_t tx_first;
7372 };
7373
7374 static void
7375 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7376                           __rte_unused struct cmdline *cl,
7377                           __rte_unused void *data)
7378 {
7379         start_packet_forwarding(1);
7380 }
7381
7382 cmdline_parse_token_string_t cmd_start_tx_first_start =
7383         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7384                                  "start");
7385 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7386         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7387                                  tx_first, "tx_first");
7388
7389 cmdline_parse_inst_t cmd_start_tx_first = {
7390         .f = cmd_start_tx_first_parsed,
7391         .data = NULL,
7392         .help_str = "start tx_first: Start packet forwarding, "
7393                 "after sending 1 burst of packets",
7394         .tokens = {
7395                 (void *)&cmd_start_tx_first_start,
7396                 (void *)&cmd_start_tx_first_tx_first,
7397                 NULL,
7398         },
7399 };
7400
7401 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7402 struct cmd_start_tx_first_n_result {
7403         cmdline_fixed_string_t start;
7404         cmdline_fixed_string_t tx_first;
7405         uint32_t tx_num;
7406 };
7407
7408 static void
7409 cmd_start_tx_first_n_parsed(void *parsed_result,
7410                           __rte_unused struct cmdline *cl,
7411                           __rte_unused void *data)
7412 {
7413         struct cmd_start_tx_first_n_result *res = parsed_result;
7414
7415         start_packet_forwarding(res->tx_num);
7416 }
7417
7418 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7419         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7420                         start, "start");
7421 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7422         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7423                         tx_first, "tx_first");
7424 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7425         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7426                         tx_num, UINT32);
7427
7428 cmdline_parse_inst_t cmd_start_tx_first_n = {
7429         .f = cmd_start_tx_first_n_parsed,
7430         .data = NULL,
7431         .help_str = "start tx_first <num>: "
7432                 "packet forwarding, after sending <num> bursts of packets",
7433         .tokens = {
7434                 (void *)&cmd_start_tx_first_n_start,
7435                 (void *)&cmd_start_tx_first_n_tx_first,
7436                 (void *)&cmd_start_tx_first_n_tx_num,
7437                 NULL,
7438         },
7439 };
7440
7441 /* *** SET LINK UP *** */
7442 struct cmd_set_link_up_result {
7443         cmdline_fixed_string_t set;
7444         cmdline_fixed_string_t link_up;
7445         cmdline_fixed_string_t port;
7446         portid_t port_id;
7447 };
7448
7449 cmdline_parse_token_string_t cmd_set_link_up_set =
7450         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7451 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7452         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7453                                 "link-up");
7454 cmdline_parse_token_string_t cmd_set_link_up_port =
7455         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7456 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7457         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7458
7459 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7460                              __rte_unused struct cmdline *cl,
7461                              __rte_unused void *data)
7462 {
7463         struct cmd_set_link_up_result *res = parsed_result;
7464         dev_set_link_up(res->port_id);
7465 }
7466
7467 cmdline_parse_inst_t cmd_set_link_up = {
7468         .f = cmd_set_link_up_parsed,
7469         .data = NULL,
7470         .help_str = "set link-up port <port id>",
7471         .tokens = {
7472                 (void *)&cmd_set_link_up_set,
7473                 (void *)&cmd_set_link_up_link_up,
7474                 (void *)&cmd_set_link_up_port,
7475                 (void *)&cmd_set_link_up_port_id,
7476                 NULL,
7477         },
7478 };
7479
7480 /* *** SET LINK DOWN *** */
7481 struct cmd_set_link_down_result {
7482         cmdline_fixed_string_t set;
7483         cmdline_fixed_string_t link_down;
7484         cmdline_fixed_string_t port;
7485         portid_t port_id;
7486 };
7487
7488 cmdline_parse_token_string_t cmd_set_link_down_set =
7489         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7490 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7491         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7492                                 "link-down");
7493 cmdline_parse_token_string_t cmd_set_link_down_port =
7494         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7495 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7496         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7497
7498 static void cmd_set_link_down_parsed(
7499                                 __rte_unused void *parsed_result,
7500                                 __rte_unused struct cmdline *cl,
7501                                 __rte_unused void *data)
7502 {
7503         struct cmd_set_link_down_result *res = parsed_result;
7504         dev_set_link_down(res->port_id);
7505 }
7506
7507 cmdline_parse_inst_t cmd_set_link_down = {
7508         .f = cmd_set_link_down_parsed,
7509         .data = NULL,
7510         .help_str = "set link-down port <port id>",
7511         .tokens = {
7512                 (void *)&cmd_set_link_down_set,
7513                 (void *)&cmd_set_link_down_link_down,
7514                 (void *)&cmd_set_link_down_port,
7515                 (void *)&cmd_set_link_down_port_id,
7516                 NULL,
7517         },
7518 };
7519
7520 /* *** SHOW CFG *** */
7521 struct cmd_showcfg_result {
7522         cmdline_fixed_string_t show;
7523         cmdline_fixed_string_t cfg;
7524         cmdline_fixed_string_t what;
7525 };
7526
7527 static void cmd_showcfg_parsed(void *parsed_result,
7528                                __rte_unused struct cmdline *cl,
7529                                __rte_unused void *data)
7530 {
7531         struct cmd_showcfg_result *res = parsed_result;
7532         if (!strcmp(res->what, "rxtx"))
7533                 rxtx_config_display();
7534         else if (!strcmp(res->what, "cores"))
7535                 fwd_lcores_config_display();
7536         else if (!strcmp(res->what, "fwd"))
7537                 pkt_fwd_config_display(&cur_fwd_config);
7538         else if (!strcmp(res->what, "txpkts"))
7539                 show_tx_pkt_segments();
7540         else if (!strcmp(res->what, "txtimes"))
7541                 show_tx_pkt_times();
7542 }
7543
7544 cmdline_parse_token_string_t cmd_showcfg_show =
7545         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7546 cmdline_parse_token_string_t cmd_showcfg_port =
7547         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7548 cmdline_parse_token_string_t cmd_showcfg_what =
7549         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7550                                  "rxtx#cores#fwd#txpkts#txtimes");
7551
7552 cmdline_parse_inst_t cmd_showcfg = {
7553         .f = cmd_showcfg_parsed,
7554         .data = NULL,
7555         .help_str = "show config rxtx|cores|fwd|txpkts|txtimes",
7556         .tokens = {
7557                 (void *)&cmd_showcfg_show,
7558                 (void *)&cmd_showcfg_port,
7559                 (void *)&cmd_showcfg_what,
7560                 NULL,
7561         },
7562 };
7563
7564 /* *** SHOW ALL PORT INFO *** */
7565 struct cmd_showportall_result {
7566         cmdline_fixed_string_t show;
7567         cmdline_fixed_string_t port;
7568         cmdline_fixed_string_t what;
7569         cmdline_fixed_string_t all;
7570 };
7571
7572 static void cmd_showportall_parsed(void *parsed_result,
7573                                 __rte_unused struct cmdline *cl,
7574                                 __rte_unused void *data)
7575 {
7576         portid_t i;
7577
7578         struct cmd_showportall_result *res = parsed_result;
7579         if (!strcmp(res->show, "clear")) {
7580                 if (!strcmp(res->what, "stats"))
7581                         RTE_ETH_FOREACH_DEV(i)
7582                                 nic_stats_clear(i);
7583                 else if (!strcmp(res->what, "xstats"))
7584                         RTE_ETH_FOREACH_DEV(i)
7585                                 nic_xstats_clear(i);
7586         } else if (!strcmp(res->what, "info"))
7587                 RTE_ETH_FOREACH_DEV(i)
7588                         port_infos_display(i);
7589         else if (!strcmp(res->what, "summary")) {
7590                 port_summary_header_display();
7591                 RTE_ETH_FOREACH_DEV(i)
7592                         port_summary_display(i);
7593         }
7594         else if (!strcmp(res->what, "stats"))
7595                 RTE_ETH_FOREACH_DEV(i)
7596                         nic_stats_display(i);
7597         else if (!strcmp(res->what, "xstats"))
7598                 RTE_ETH_FOREACH_DEV(i)
7599                         nic_xstats_display(i);
7600         else if (!strcmp(res->what, "fdir"))
7601                 RTE_ETH_FOREACH_DEV(i)
7602                         fdir_get_infos(i);
7603         else if (!strcmp(res->what, "stat_qmap"))
7604                 RTE_ETH_FOREACH_DEV(i)
7605                         nic_stats_mapping_display(i);
7606         else if (!strcmp(res->what, "dcb_tc"))
7607                 RTE_ETH_FOREACH_DEV(i)
7608                         port_dcb_info_display(i);
7609         else if (!strcmp(res->what, "cap"))
7610                 RTE_ETH_FOREACH_DEV(i)
7611                         port_offload_cap_display(i);
7612 }
7613
7614 cmdline_parse_token_string_t cmd_showportall_show =
7615         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7616                                  "show#clear");
7617 cmdline_parse_token_string_t cmd_showportall_port =
7618         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7619 cmdline_parse_token_string_t cmd_showportall_what =
7620         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7621                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7622 cmdline_parse_token_string_t cmd_showportall_all =
7623         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7624 cmdline_parse_inst_t cmd_showportall = {
7625         .f = cmd_showportall_parsed,
7626         .data = NULL,
7627         .help_str = "show|clear port "
7628                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7629         .tokens = {
7630                 (void *)&cmd_showportall_show,
7631                 (void *)&cmd_showportall_port,
7632                 (void *)&cmd_showportall_what,
7633                 (void *)&cmd_showportall_all,
7634                 NULL,
7635         },
7636 };
7637
7638 /* *** SHOW PORT INFO *** */
7639 struct cmd_showport_result {
7640         cmdline_fixed_string_t show;
7641         cmdline_fixed_string_t port;
7642         cmdline_fixed_string_t what;
7643         uint16_t portnum;
7644 };
7645
7646 static void cmd_showport_parsed(void *parsed_result,
7647                                 __rte_unused struct cmdline *cl,
7648                                 __rte_unused void *data)
7649 {
7650         struct cmd_showport_result *res = parsed_result;
7651         if (!strcmp(res->show, "clear")) {
7652                 if (!strcmp(res->what, "stats"))
7653                         nic_stats_clear(res->portnum);
7654                 else if (!strcmp(res->what, "xstats"))
7655                         nic_xstats_clear(res->portnum);
7656         } else if (!strcmp(res->what, "info"))
7657                 port_infos_display(res->portnum);
7658         else if (!strcmp(res->what, "summary")) {
7659                 port_summary_header_display();
7660                 port_summary_display(res->portnum);
7661         }
7662         else if (!strcmp(res->what, "stats"))
7663                 nic_stats_display(res->portnum);
7664         else if (!strcmp(res->what, "xstats"))
7665                 nic_xstats_display(res->portnum);
7666         else if (!strcmp(res->what, "fdir"))
7667                  fdir_get_infos(res->portnum);
7668         else if (!strcmp(res->what, "stat_qmap"))
7669                 nic_stats_mapping_display(res->portnum);
7670         else if (!strcmp(res->what, "dcb_tc"))
7671                 port_dcb_info_display(res->portnum);
7672         else if (!strcmp(res->what, "cap"))
7673                 port_offload_cap_display(res->portnum);
7674 }
7675
7676 cmdline_parse_token_string_t cmd_showport_show =
7677         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7678                                  "show#clear");
7679 cmdline_parse_token_string_t cmd_showport_port =
7680         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7681 cmdline_parse_token_string_t cmd_showport_what =
7682         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7683                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7684 cmdline_parse_token_num_t cmd_showport_portnum =
7685         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7686
7687 cmdline_parse_inst_t cmd_showport = {
7688         .f = cmd_showport_parsed,
7689         .data = NULL,
7690         .help_str = "show|clear port "
7691                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7692                 "<port_id>",
7693         .tokens = {
7694                 (void *)&cmd_showport_show,
7695                 (void *)&cmd_showport_port,
7696                 (void *)&cmd_showport_what,
7697                 (void *)&cmd_showport_portnum,
7698                 NULL,
7699         },
7700 };
7701
7702 /* *** SHOW DEVICE INFO *** */
7703 struct cmd_showdevice_result {
7704         cmdline_fixed_string_t show;
7705         cmdline_fixed_string_t device;
7706         cmdline_fixed_string_t what;
7707         cmdline_fixed_string_t identifier;
7708 };
7709
7710 static void cmd_showdevice_parsed(void *parsed_result,
7711                                 __rte_unused struct cmdline *cl,
7712                                 __rte_unused void *data)
7713 {
7714         struct cmd_showdevice_result *res = parsed_result;
7715         if (!strcmp(res->what, "info")) {
7716                 if (!strcmp(res->identifier, "all"))
7717                         device_infos_display(NULL);
7718                 else
7719                         device_infos_display(res->identifier);
7720         }
7721 }
7722
7723 cmdline_parse_token_string_t cmd_showdevice_show =
7724         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7725                                  "show");
7726 cmdline_parse_token_string_t cmd_showdevice_device =
7727         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7728 cmdline_parse_token_string_t cmd_showdevice_what =
7729         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7730                                  "info");
7731 cmdline_parse_token_string_t cmd_showdevice_identifier =
7732         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7733                         identifier, NULL);
7734
7735 cmdline_parse_inst_t cmd_showdevice = {
7736         .f = cmd_showdevice_parsed,
7737         .data = NULL,
7738         .help_str = "show device info <identifier>|all",
7739         .tokens = {
7740                 (void *)&cmd_showdevice_show,
7741                 (void *)&cmd_showdevice_device,
7742                 (void *)&cmd_showdevice_what,
7743                 (void *)&cmd_showdevice_identifier,
7744                 NULL,
7745         },
7746 };
7747
7748 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7749 struct cmd_showeeprom_result {
7750         cmdline_fixed_string_t show;
7751         cmdline_fixed_string_t port;
7752         uint16_t portnum;
7753         cmdline_fixed_string_t type;
7754 };
7755
7756 static void cmd_showeeprom_parsed(void *parsed_result,
7757                 __rte_unused struct cmdline *cl,
7758                 __rte_unused void *data)
7759 {
7760         struct cmd_showeeprom_result *res = parsed_result;
7761
7762         if (!strcmp(res->type, "eeprom"))
7763                 port_eeprom_display(res->portnum);
7764         else if (!strcmp(res->type, "module_eeprom"))
7765                 port_module_eeprom_display(res->portnum);
7766         else
7767                 printf("Unknown argument\n");
7768 }
7769
7770 cmdline_parse_token_string_t cmd_showeeprom_show =
7771         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7772 cmdline_parse_token_string_t cmd_showeeprom_port =
7773         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7774 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7775         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7776 cmdline_parse_token_string_t cmd_showeeprom_type =
7777         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7778
7779 cmdline_parse_inst_t cmd_showeeprom = {
7780         .f = cmd_showeeprom_parsed,
7781         .data = NULL,
7782         .help_str = "show port <port_id> module_eeprom|eeprom",
7783         .tokens = {
7784                 (void *)&cmd_showeeprom_show,
7785                 (void *)&cmd_showeeprom_port,
7786                 (void *)&cmd_showeeprom_portnum,
7787                 (void *)&cmd_showeeprom_type,
7788                 NULL,
7789         },
7790 };
7791
7792 /* *** SHOW QUEUE INFO *** */
7793 struct cmd_showqueue_result {
7794         cmdline_fixed_string_t show;
7795         cmdline_fixed_string_t type;
7796         cmdline_fixed_string_t what;
7797         uint16_t portnum;
7798         uint16_t queuenum;
7799 };
7800
7801 static void
7802 cmd_showqueue_parsed(void *parsed_result,
7803         __rte_unused struct cmdline *cl,
7804         __rte_unused void *data)
7805 {
7806         struct cmd_showqueue_result *res = parsed_result;
7807
7808         if (!strcmp(res->type, "rxq"))
7809                 rx_queue_infos_display(res->portnum, res->queuenum);
7810         else if (!strcmp(res->type, "txq"))
7811                 tx_queue_infos_display(res->portnum, res->queuenum);
7812 }
7813
7814 cmdline_parse_token_string_t cmd_showqueue_show =
7815         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7816 cmdline_parse_token_string_t cmd_showqueue_type =
7817         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7818 cmdline_parse_token_string_t cmd_showqueue_what =
7819         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7820 cmdline_parse_token_num_t cmd_showqueue_portnum =
7821         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7822 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7823         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7824
7825 cmdline_parse_inst_t cmd_showqueue = {
7826         .f = cmd_showqueue_parsed,
7827         .data = NULL,
7828         .help_str = "show rxq|txq info <port_id> <queue_id>",
7829         .tokens = {
7830                 (void *)&cmd_showqueue_show,
7831                 (void *)&cmd_showqueue_type,
7832                 (void *)&cmd_showqueue_what,
7833                 (void *)&cmd_showqueue_portnum,
7834                 (void *)&cmd_showqueue_queuenum,
7835                 NULL,
7836         },
7837 };
7838
7839 /* show/clear fwd engine statistics */
7840 struct fwd_result {
7841         cmdline_fixed_string_t action;
7842         cmdline_fixed_string_t fwd;
7843         cmdline_fixed_string_t stats;
7844         cmdline_fixed_string_t all;
7845 };
7846
7847 cmdline_parse_token_string_t cmd_fwd_action =
7848         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7849 cmdline_parse_token_string_t cmd_fwd_fwd =
7850         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7851 cmdline_parse_token_string_t cmd_fwd_stats =
7852         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7853 cmdline_parse_token_string_t cmd_fwd_all =
7854         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7855
7856 static void
7857 cmd_showfwdall_parsed(void *parsed_result,
7858                       __rte_unused struct cmdline *cl,
7859                       __rte_unused void *data)
7860 {
7861         struct fwd_result *res = parsed_result;
7862
7863         if (!strcmp(res->action, "show"))
7864                 fwd_stats_display();
7865         else
7866                 fwd_stats_reset();
7867 }
7868
7869 static cmdline_parse_inst_t cmd_showfwdall = {
7870         .f = cmd_showfwdall_parsed,
7871         .data = NULL,
7872         .help_str = "show|clear fwd stats all",
7873         .tokens = {
7874                 (void *)&cmd_fwd_action,
7875                 (void *)&cmd_fwd_fwd,
7876                 (void *)&cmd_fwd_stats,
7877                 (void *)&cmd_fwd_all,
7878                 NULL,
7879         },
7880 };
7881
7882 /* *** READ PORT REGISTER *** */
7883 struct cmd_read_reg_result {
7884         cmdline_fixed_string_t read;
7885         cmdline_fixed_string_t reg;
7886         portid_t port_id;
7887         uint32_t reg_off;
7888 };
7889
7890 static void
7891 cmd_read_reg_parsed(void *parsed_result,
7892                     __rte_unused struct cmdline *cl,
7893                     __rte_unused void *data)
7894 {
7895         struct cmd_read_reg_result *res = parsed_result;
7896         port_reg_display(res->port_id, res->reg_off);
7897 }
7898
7899 cmdline_parse_token_string_t cmd_read_reg_read =
7900         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7901 cmdline_parse_token_string_t cmd_read_reg_reg =
7902         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7903 cmdline_parse_token_num_t cmd_read_reg_port_id =
7904         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7905 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7906         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7907
7908 cmdline_parse_inst_t cmd_read_reg = {
7909         .f = cmd_read_reg_parsed,
7910         .data = NULL,
7911         .help_str = "read reg <port_id> <reg_off>",
7912         .tokens = {
7913                 (void *)&cmd_read_reg_read,
7914                 (void *)&cmd_read_reg_reg,
7915                 (void *)&cmd_read_reg_port_id,
7916                 (void *)&cmd_read_reg_reg_off,
7917                 NULL,
7918         },
7919 };
7920
7921 /* *** READ PORT REGISTER BIT FIELD *** */
7922 struct cmd_read_reg_bit_field_result {
7923         cmdline_fixed_string_t read;
7924         cmdline_fixed_string_t regfield;
7925         portid_t port_id;
7926         uint32_t reg_off;
7927         uint8_t bit1_pos;
7928         uint8_t bit2_pos;
7929 };
7930
7931 static void
7932 cmd_read_reg_bit_field_parsed(void *parsed_result,
7933                               __rte_unused struct cmdline *cl,
7934                               __rte_unused void *data)
7935 {
7936         struct cmd_read_reg_bit_field_result *res = parsed_result;
7937         port_reg_bit_field_display(res->port_id, res->reg_off,
7938                                    res->bit1_pos, res->bit2_pos);
7939 }
7940
7941 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7942         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7943                                  "read");
7944 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7945         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7946                                  regfield, "regfield");
7947 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7948         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7949                               UINT16);
7950 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7951         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7952                               UINT32);
7953 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7954         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7955                               UINT8);
7956 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7957         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7958                               UINT8);
7959
7960 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7961         .f = cmd_read_reg_bit_field_parsed,
7962         .data = NULL,
7963         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
7964         "Read register bit field between bit_x and bit_y included",
7965         .tokens = {
7966                 (void *)&cmd_read_reg_bit_field_read,
7967                 (void *)&cmd_read_reg_bit_field_regfield,
7968                 (void *)&cmd_read_reg_bit_field_port_id,
7969                 (void *)&cmd_read_reg_bit_field_reg_off,
7970                 (void *)&cmd_read_reg_bit_field_bit1_pos,
7971                 (void *)&cmd_read_reg_bit_field_bit2_pos,
7972                 NULL,
7973         },
7974 };
7975
7976 /* *** READ PORT REGISTER BIT *** */
7977 struct cmd_read_reg_bit_result {
7978         cmdline_fixed_string_t read;
7979         cmdline_fixed_string_t regbit;
7980         portid_t port_id;
7981         uint32_t reg_off;
7982         uint8_t bit_pos;
7983 };
7984
7985 static void
7986 cmd_read_reg_bit_parsed(void *parsed_result,
7987                         __rte_unused struct cmdline *cl,
7988                         __rte_unused void *data)
7989 {
7990         struct cmd_read_reg_bit_result *res = parsed_result;
7991         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
7992 }
7993
7994 cmdline_parse_token_string_t cmd_read_reg_bit_read =
7995         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
7996 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
7997         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
7998                                  regbit, "regbit");
7999 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8000         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8001 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8002         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8003 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8004         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8005
8006 cmdline_parse_inst_t cmd_read_reg_bit = {
8007         .f = cmd_read_reg_bit_parsed,
8008         .data = NULL,
8009         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8010         .tokens = {
8011                 (void *)&cmd_read_reg_bit_read,
8012                 (void *)&cmd_read_reg_bit_regbit,
8013                 (void *)&cmd_read_reg_bit_port_id,
8014                 (void *)&cmd_read_reg_bit_reg_off,
8015                 (void *)&cmd_read_reg_bit_bit_pos,
8016                 NULL,
8017         },
8018 };
8019
8020 /* *** WRITE PORT REGISTER *** */
8021 struct cmd_write_reg_result {
8022         cmdline_fixed_string_t write;
8023         cmdline_fixed_string_t reg;
8024         portid_t port_id;
8025         uint32_t reg_off;
8026         uint32_t value;
8027 };
8028
8029 static void
8030 cmd_write_reg_parsed(void *parsed_result,
8031                      __rte_unused struct cmdline *cl,
8032                      __rte_unused void *data)
8033 {
8034         struct cmd_write_reg_result *res = parsed_result;
8035         port_reg_set(res->port_id, res->reg_off, res->value);
8036 }
8037
8038 cmdline_parse_token_string_t cmd_write_reg_write =
8039         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8040 cmdline_parse_token_string_t cmd_write_reg_reg =
8041         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8042 cmdline_parse_token_num_t cmd_write_reg_port_id =
8043         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8044 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8045         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8046 cmdline_parse_token_num_t cmd_write_reg_value =
8047         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8048
8049 cmdline_parse_inst_t cmd_write_reg = {
8050         .f = cmd_write_reg_parsed,
8051         .data = NULL,
8052         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8053         .tokens = {
8054                 (void *)&cmd_write_reg_write,
8055                 (void *)&cmd_write_reg_reg,
8056                 (void *)&cmd_write_reg_port_id,
8057                 (void *)&cmd_write_reg_reg_off,
8058                 (void *)&cmd_write_reg_value,
8059                 NULL,
8060         },
8061 };
8062
8063 /* *** WRITE PORT REGISTER BIT FIELD *** */
8064 struct cmd_write_reg_bit_field_result {
8065         cmdline_fixed_string_t write;
8066         cmdline_fixed_string_t regfield;
8067         portid_t port_id;
8068         uint32_t reg_off;
8069         uint8_t bit1_pos;
8070         uint8_t bit2_pos;
8071         uint32_t value;
8072 };
8073
8074 static void
8075 cmd_write_reg_bit_field_parsed(void *parsed_result,
8076                                __rte_unused struct cmdline *cl,
8077                                __rte_unused void *data)
8078 {
8079         struct cmd_write_reg_bit_field_result *res = parsed_result;
8080         port_reg_bit_field_set(res->port_id, res->reg_off,
8081                           res->bit1_pos, res->bit2_pos, res->value);
8082 }
8083
8084 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8085         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8086                                  "write");
8087 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8088         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8089                                  regfield, "regfield");
8090 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8091         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8092                               UINT16);
8093 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8094         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8095                               UINT32);
8096 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8097         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8098                               UINT8);
8099 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8100         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8101                               UINT8);
8102 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8103         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8104                               UINT32);
8105
8106 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8107         .f = cmd_write_reg_bit_field_parsed,
8108         .data = NULL,
8109         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8110                 "<reg_value>: "
8111                 "Set register bit field between bit_x and bit_y included",
8112         .tokens = {
8113                 (void *)&cmd_write_reg_bit_field_write,
8114                 (void *)&cmd_write_reg_bit_field_regfield,
8115                 (void *)&cmd_write_reg_bit_field_port_id,
8116                 (void *)&cmd_write_reg_bit_field_reg_off,
8117                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8118                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8119                 (void *)&cmd_write_reg_bit_field_value,
8120                 NULL,
8121         },
8122 };
8123
8124 /* *** WRITE PORT REGISTER BIT *** */
8125 struct cmd_write_reg_bit_result {
8126         cmdline_fixed_string_t write;
8127         cmdline_fixed_string_t regbit;
8128         portid_t port_id;
8129         uint32_t reg_off;
8130         uint8_t bit_pos;
8131         uint8_t value;
8132 };
8133
8134 static void
8135 cmd_write_reg_bit_parsed(void *parsed_result,
8136                          __rte_unused struct cmdline *cl,
8137                          __rte_unused void *data)
8138 {
8139         struct cmd_write_reg_bit_result *res = parsed_result;
8140         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8141 }
8142
8143 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8144         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8145                                  "write");
8146 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8147         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8148                                  regbit, "regbit");
8149 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8150         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8151 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8152         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8153 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8154         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8155 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8156         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8157
8158 cmdline_parse_inst_t cmd_write_reg_bit = {
8159         .f = cmd_write_reg_bit_parsed,
8160         .data = NULL,
8161         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8162                 "0 <= bit_x <= 31",
8163         .tokens = {
8164                 (void *)&cmd_write_reg_bit_write,
8165                 (void *)&cmd_write_reg_bit_regbit,
8166                 (void *)&cmd_write_reg_bit_port_id,
8167                 (void *)&cmd_write_reg_bit_reg_off,
8168                 (void *)&cmd_write_reg_bit_bit_pos,
8169                 (void *)&cmd_write_reg_bit_value,
8170                 NULL,
8171         },
8172 };
8173
8174 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8175 struct cmd_read_rxd_txd_result {
8176         cmdline_fixed_string_t read;
8177         cmdline_fixed_string_t rxd_txd;
8178         portid_t port_id;
8179         uint16_t queue_id;
8180         uint16_t desc_id;
8181 };
8182
8183 static void
8184 cmd_read_rxd_txd_parsed(void *parsed_result,
8185                         __rte_unused struct cmdline *cl,
8186                         __rte_unused void *data)
8187 {
8188         struct cmd_read_rxd_txd_result *res = parsed_result;
8189
8190         if (!strcmp(res->rxd_txd, "rxd"))
8191                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8192         else if (!strcmp(res->rxd_txd, "txd"))
8193                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8194 }
8195
8196 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8197         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8198 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8199         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8200                                  "rxd#txd");
8201 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8202         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8203 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8204         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8205 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8206         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8207
8208 cmdline_parse_inst_t cmd_read_rxd_txd = {
8209         .f = cmd_read_rxd_txd_parsed,
8210         .data = NULL,
8211         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8212         .tokens = {
8213                 (void *)&cmd_read_rxd_txd_read,
8214                 (void *)&cmd_read_rxd_txd_rxd_txd,
8215                 (void *)&cmd_read_rxd_txd_port_id,
8216                 (void *)&cmd_read_rxd_txd_queue_id,
8217                 (void *)&cmd_read_rxd_txd_desc_id,
8218                 NULL,
8219         },
8220 };
8221
8222 /* *** QUIT *** */
8223 struct cmd_quit_result {
8224         cmdline_fixed_string_t quit;
8225 };
8226
8227 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8228                             struct cmdline *cl,
8229                             __rte_unused void *data)
8230 {
8231         cmdline_quit(cl);
8232 }
8233
8234 cmdline_parse_token_string_t cmd_quit_quit =
8235         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8236
8237 cmdline_parse_inst_t cmd_quit = {
8238         .f = cmd_quit_parsed,
8239         .data = NULL,
8240         .help_str = "quit: Exit application",
8241         .tokens = {
8242                 (void *)&cmd_quit_quit,
8243                 NULL,
8244         },
8245 };
8246
8247 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8248 struct cmd_mac_addr_result {
8249         cmdline_fixed_string_t mac_addr_cmd;
8250         cmdline_fixed_string_t what;
8251         uint16_t port_num;
8252         struct rte_ether_addr address;
8253 };
8254
8255 static void cmd_mac_addr_parsed(void *parsed_result,
8256                 __rte_unused struct cmdline *cl,
8257                 __rte_unused void *data)
8258 {
8259         struct cmd_mac_addr_result *res = parsed_result;
8260         int ret;
8261
8262         if (strcmp(res->what, "add") == 0)
8263                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8264         else if (strcmp(res->what, "set") == 0)
8265                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8266                                                        &res->address);
8267         else
8268                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8269
8270         /* check the return value and print it if is < 0 */
8271         if(ret < 0)
8272                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8273
8274 }
8275
8276 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8277         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8278                                 "mac_addr");
8279 cmdline_parse_token_string_t cmd_mac_addr_what =
8280         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8281                                 "add#remove#set");
8282 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8283                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8284                                         UINT16);
8285 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8286                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8287
8288 cmdline_parse_inst_t cmd_mac_addr = {
8289         .f = cmd_mac_addr_parsed,
8290         .data = (void *)0,
8291         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8292                         "Add/Remove/Set MAC address on port_id",
8293         .tokens = {
8294                 (void *)&cmd_mac_addr_cmd,
8295                 (void *)&cmd_mac_addr_what,
8296                 (void *)&cmd_mac_addr_portnum,
8297                 (void *)&cmd_mac_addr_addr,
8298                 NULL,
8299         },
8300 };
8301
8302 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8303 struct cmd_eth_peer_result {
8304         cmdline_fixed_string_t set;
8305         cmdline_fixed_string_t eth_peer;
8306         portid_t port_id;
8307         cmdline_fixed_string_t peer_addr;
8308 };
8309
8310 static void cmd_set_eth_peer_parsed(void *parsed_result,
8311                         __rte_unused struct cmdline *cl,
8312                         __rte_unused void *data)
8313 {
8314                 struct cmd_eth_peer_result *res = parsed_result;
8315
8316                 if (test_done == 0) {
8317                         printf("Please stop forwarding first\n");
8318                         return;
8319                 }
8320                 if (!strcmp(res->eth_peer, "eth-peer")) {
8321                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8322                         fwd_config_setup();
8323                 }
8324 }
8325 cmdline_parse_token_string_t cmd_eth_peer_set =
8326         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8327 cmdline_parse_token_string_t cmd_eth_peer =
8328         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8329 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8330         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8331 cmdline_parse_token_string_t cmd_eth_peer_addr =
8332         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8333
8334 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8335         .f = cmd_set_eth_peer_parsed,
8336         .data = NULL,
8337         .help_str = "set eth-peer <port_id> <peer_mac>",
8338         .tokens = {
8339                 (void *)&cmd_eth_peer_set,
8340                 (void *)&cmd_eth_peer,
8341                 (void *)&cmd_eth_peer_port_id,
8342                 (void *)&cmd_eth_peer_addr,
8343                 NULL,
8344         },
8345 };
8346
8347 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8348 struct cmd_set_qmap_result {
8349         cmdline_fixed_string_t set;
8350         cmdline_fixed_string_t qmap;
8351         cmdline_fixed_string_t what;
8352         portid_t port_id;
8353         uint16_t queue_id;
8354         uint8_t map_value;
8355 };
8356
8357 static void
8358 cmd_set_qmap_parsed(void *parsed_result,
8359                        __rte_unused struct cmdline *cl,
8360                        __rte_unused void *data)
8361 {
8362         struct cmd_set_qmap_result *res = parsed_result;
8363         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8364
8365         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8366 }
8367
8368 cmdline_parse_token_string_t cmd_setqmap_set =
8369         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8370                                  set, "set");
8371 cmdline_parse_token_string_t cmd_setqmap_qmap =
8372         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8373                                  qmap, "stat_qmap");
8374 cmdline_parse_token_string_t cmd_setqmap_what =
8375         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8376                                  what, "tx#rx");
8377 cmdline_parse_token_num_t cmd_setqmap_portid =
8378         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8379                               port_id, UINT16);
8380 cmdline_parse_token_num_t cmd_setqmap_queueid =
8381         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8382                               queue_id, UINT16);
8383 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8384         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8385                               map_value, UINT8);
8386
8387 cmdline_parse_inst_t cmd_set_qmap = {
8388         .f = cmd_set_qmap_parsed,
8389         .data = NULL,
8390         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8391                 "Set statistics mapping value on tx|rx queue_id of port_id",
8392         .tokens = {
8393                 (void *)&cmd_setqmap_set,
8394                 (void *)&cmd_setqmap_qmap,
8395                 (void *)&cmd_setqmap_what,
8396                 (void *)&cmd_setqmap_portid,
8397                 (void *)&cmd_setqmap_queueid,
8398                 (void *)&cmd_setqmap_mapvalue,
8399                 NULL,
8400         },
8401 };
8402
8403 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8404 struct cmd_set_xstats_hide_zero_result {
8405         cmdline_fixed_string_t keyword;
8406         cmdline_fixed_string_t name;
8407         cmdline_fixed_string_t on_off;
8408 };
8409
8410 static void
8411 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8412                         __rte_unused struct cmdline *cl,
8413                         __rte_unused void *data)
8414 {
8415         struct cmd_set_xstats_hide_zero_result *res;
8416         uint16_t on_off = 0;
8417
8418         res = parsed_result;
8419         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8420         set_xstats_hide_zero(on_off);
8421 }
8422
8423 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8424         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8425                                  keyword, "set");
8426 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8427         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8428                                  name, "xstats-hide-zero");
8429 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8430         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8431                                  on_off, "on#off");
8432
8433 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8434         .f = cmd_set_xstats_hide_zero_parsed,
8435         .data = NULL,
8436         .help_str = "set xstats-hide-zero on|off",
8437         .tokens = {
8438                 (void *)&cmd_set_xstats_hide_zero_keyword,
8439                 (void *)&cmd_set_xstats_hide_zero_name,
8440                 (void *)&cmd_set_xstats_hide_zero_on_off,
8441                 NULL,
8442         },
8443 };
8444
8445 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8446 struct cmd_set_record_core_cycles_result {
8447         cmdline_fixed_string_t keyword;
8448         cmdline_fixed_string_t name;
8449         cmdline_fixed_string_t on_off;
8450 };
8451
8452 static void
8453 cmd_set_record_core_cycles_parsed(void *parsed_result,
8454                         __rte_unused struct cmdline *cl,
8455                         __rte_unused void *data)
8456 {
8457         struct cmd_set_record_core_cycles_result *res;
8458         uint16_t on_off = 0;
8459
8460         res = parsed_result;
8461         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8462         set_record_core_cycles(on_off);
8463 }
8464
8465 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8466         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8467                                  keyword, "set");
8468 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8469         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8470                                  name, "record-core-cycles");
8471 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8472         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8473                                  on_off, "on#off");
8474
8475 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8476         .f = cmd_set_record_core_cycles_parsed,
8477         .data = NULL,
8478         .help_str = "set record-core-cycles on|off",
8479         .tokens = {
8480                 (void *)&cmd_set_record_core_cycles_keyword,
8481                 (void *)&cmd_set_record_core_cycles_name,
8482                 (void *)&cmd_set_record_core_cycles_on_off,
8483                 NULL,
8484         },
8485 };
8486
8487 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8488 struct cmd_set_record_burst_stats_result {
8489         cmdline_fixed_string_t keyword;
8490         cmdline_fixed_string_t name;
8491         cmdline_fixed_string_t on_off;
8492 };
8493
8494 static void
8495 cmd_set_record_burst_stats_parsed(void *parsed_result,
8496                         __rte_unused struct cmdline *cl,
8497                         __rte_unused void *data)
8498 {
8499         struct cmd_set_record_burst_stats_result *res;
8500         uint16_t on_off = 0;
8501
8502         res = parsed_result;
8503         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8504         set_record_burst_stats(on_off);
8505 }
8506
8507 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8508         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8509                                  keyword, "set");
8510 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8511         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8512                                  name, "record-burst-stats");
8513 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8514         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8515                                  on_off, "on#off");
8516
8517 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8518         .f = cmd_set_record_burst_stats_parsed,
8519         .data = NULL,
8520         .help_str = "set record-burst-stats on|off",
8521         .tokens = {
8522                 (void *)&cmd_set_record_burst_stats_keyword,
8523                 (void *)&cmd_set_record_burst_stats_name,
8524                 (void *)&cmd_set_record_burst_stats_on_off,
8525                 NULL,
8526         },
8527 };
8528
8529 /* *** CONFIGURE UNICAST HASH TABLE *** */
8530 struct cmd_set_uc_hash_table {
8531         cmdline_fixed_string_t set;
8532         cmdline_fixed_string_t port;
8533         portid_t port_id;
8534         cmdline_fixed_string_t what;
8535         struct rte_ether_addr address;
8536         cmdline_fixed_string_t mode;
8537 };
8538
8539 static void
8540 cmd_set_uc_hash_parsed(void *parsed_result,
8541                        __rte_unused struct cmdline *cl,
8542                        __rte_unused void *data)
8543 {
8544         int ret=0;
8545         struct cmd_set_uc_hash_table *res = parsed_result;
8546
8547         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8548
8549         if (strcmp(res->what, "uta") == 0)
8550                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8551                                                 &res->address,(uint8_t)is_on);
8552         if (ret < 0)
8553                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8554
8555 }
8556
8557 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8558         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8559                                  set, "set");
8560 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8561         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8562                                  port, "port");
8563 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8564         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8565                               port_id, UINT16);
8566 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8567         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8568                                  what, "uta");
8569 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8570         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8571                                 address);
8572 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8573         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8574                                  mode, "on#off");
8575
8576 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8577         .f = cmd_set_uc_hash_parsed,
8578         .data = NULL,
8579         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8580         .tokens = {
8581                 (void *)&cmd_set_uc_hash_set,
8582                 (void *)&cmd_set_uc_hash_port,
8583                 (void *)&cmd_set_uc_hash_portid,
8584                 (void *)&cmd_set_uc_hash_what,
8585                 (void *)&cmd_set_uc_hash_mac,
8586                 (void *)&cmd_set_uc_hash_mode,
8587                 NULL,
8588         },
8589 };
8590
8591 struct cmd_set_uc_all_hash_table {
8592         cmdline_fixed_string_t set;
8593         cmdline_fixed_string_t port;
8594         portid_t port_id;
8595         cmdline_fixed_string_t what;
8596         cmdline_fixed_string_t value;
8597         cmdline_fixed_string_t mode;
8598 };
8599
8600 static void
8601 cmd_set_uc_all_hash_parsed(void *parsed_result,
8602                        __rte_unused struct cmdline *cl,
8603                        __rte_unused void *data)
8604 {
8605         int ret=0;
8606         struct cmd_set_uc_all_hash_table *res = parsed_result;
8607
8608         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8609
8610         if ((strcmp(res->what, "uta") == 0) &&
8611                 (strcmp(res->value, "all") == 0))
8612                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8613         if (ret < 0)
8614                 printf("bad unicast hash table parameter,"
8615                         "return code = %d \n", ret);
8616 }
8617
8618 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8620                                  set, "set");
8621 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8623                                  port, "port");
8624 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8625         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8626                               port_id, UINT16);
8627 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8628         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8629                                  what, "uta");
8630 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8631         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8632                                 value,"all");
8633 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8634         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8635                                  mode, "on#off");
8636
8637 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8638         .f = cmd_set_uc_all_hash_parsed,
8639         .data = NULL,
8640         .help_str = "set port <port_id> uta all on|off",
8641         .tokens = {
8642                 (void *)&cmd_set_uc_all_hash_set,
8643                 (void *)&cmd_set_uc_all_hash_port,
8644                 (void *)&cmd_set_uc_all_hash_portid,
8645                 (void *)&cmd_set_uc_all_hash_what,
8646                 (void *)&cmd_set_uc_all_hash_value,
8647                 (void *)&cmd_set_uc_all_hash_mode,
8648                 NULL,
8649         },
8650 };
8651
8652 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8653 struct cmd_set_vf_macvlan_filter {
8654         cmdline_fixed_string_t set;
8655         cmdline_fixed_string_t port;
8656         portid_t port_id;
8657         cmdline_fixed_string_t vf;
8658         uint8_t vf_id;
8659         struct rte_ether_addr address;
8660         cmdline_fixed_string_t filter_type;
8661         cmdline_fixed_string_t mode;
8662 };
8663
8664 static void
8665 cmd_set_vf_macvlan_parsed(void *parsed_result,
8666                        __rte_unused struct cmdline *cl,
8667                        __rte_unused void *data)
8668 {
8669         int is_on, ret = 0;
8670         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8671         struct rte_eth_mac_filter filter;
8672
8673         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8674
8675         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8676
8677         /* set VF MAC filter */
8678         filter.is_vf = 1;
8679
8680         /* set VF ID */
8681         filter.dst_id = res->vf_id;
8682
8683         if (!strcmp(res->filter_type, "exact-mac"))
8684                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8685         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8686                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8687         else if (!strcmp(res->filter_type, "hashmac"))
8688                 filter.filter_type = RTE_MAC_HASH_MATCH;
8689         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8690                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8691
8692         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8693
8694         if (is_on)
8695                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8696                                         RTE_ETH_FILTER_MACVLAN,
8697                                         RTE_ETH_FILTER_ADD,
8698                                          &filter);
8699         else
8700                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8701                                         RTE_ETH_FILTER_MACVLAN,
8702                                         RTE_ETH_FILTER_DELETE,
8703                                         &filter);
8704
8705         if (ret < 0)
8706                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8707
8708 }
8709
8710 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8711         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8712                                  set, "set");
8713 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8714         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8715                                  port, "port");
8716 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8717         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8718                               port_id, UINT16);
8719 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8720         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8721                                  vf, "vf");
8722 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8723         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8724                                 vf_id, UINT8);
8725 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8726         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8727                                 address);
8728 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8729         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8730                                 filter_type, "exact-mac#exact-mac-vlan"
8731                                 "#hashmac#hashmac-vlan");
8732 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8733         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8734                                  mode, "on#off");
8735
8736 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8737         .f = cmd_set_vf_macvlan_parsed,
8738         .data = NULL,
8739         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8740                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8741                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8742                 "hash match rule: hash match of MAC and exact match of VLAN",
8743         .tokens = {
8744                 (void *)&cmd_set_vf_macvlan_set,
8745                 (void *)&cmd_set_vf_macvlan_port,
8746                 (void *)&cmd_set_vf_macvlan_portid,
8747                 (void *)&cmd_set_vf_macvlan_vf,
8748                 (void *)&cmd_set_vf_macvlan_vf_id,
8749                 (void *)&cmd_set_vf_macvlan_mac,
8750                 (void *)&cmd_set_vf_macvlan_filter_type,
8751                 (void *)&cmd_set_vf_macvlan_mode,
8752                 NULL,
8753         },
8754 };
8755
8756 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8757 struct cmd_set_vf_traffic {
8758         cmdline_fixed_string_t set;
8759         cmdline_fixed_string_t port;
8760         portid_t port_id;
8761         cmdline_fixed_string_t vf;
8762         uint8_t vf_id;
8763         cmdline_fixed_string_t what;
8764         cmdline_fixed_string_t mode;
8765 };
8766
8767 static void
8768 cmd_set_vf_traffic_parsed(void *parsed_result,
8769                        __rte_unused struct cmdline *cl,
8770                        __rte_unused void *data)
8771 {
8772         struct cmd_set_vf_traffic *res = parsed_result;
8773         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8774         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8775
8776         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8777 }
8778
8779 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8780         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8781                                  set, "set");
8782 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8783         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8784                                  port, "port");
8785 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8786         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8787                               port_id, UINT16);
8788 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8789         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8790                                  vf, "vf");
8791 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8792         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8793                               vf_id, UINT8);
8794 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8795         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8796                                  what, "tx#rx");
8797 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8798         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8799                                  mode, "on#off");
8800
8801 cmdline_parse_inst_t cmd_set_vf_traffic = {
8802         .f = cmd_set_vf_traffic_parsed,
8803         .data = NULL,
8804         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8805         .tokens = {
8806                 (void *)&cmd_setvf_traffic_set,
8807                 (void *)&cmd_setvf_traffic_port,
8808                 (void *)&cmd_setvf_traffic_portid,
8809                 (void *)&cmd_setvf_traffic_vf,
8810                 (void *)&cmd_setvf_traffic_vfid,
8811                 (void *)&cmd_setvf_traffic_what,
8812                 (void *)&cmd_setvf_traffic_mode,
8813                 NULL,
8814         },
8815 };
8816
8817 /* *** CONFIGURE VF RECEIVE MODE *** */
8818 struct cmd_set_vf_rxmode {
8819         cmdline_fixed_string_t set;
8820         cmdline_fixed_string_t port;
8821         portid_t port_id;
8822         cmdline_fixed_string_t vf;
8823         uint8_t vf_id;
8824         cmdline_fixed_string_t what;
8825         cmdline_fixed_string_t mode;
8826         cmdline_fixed_string_t on;
8827 };
8828
8829 static void
8830 cmd_set_vf_rxmode_parsed(void *parsed_result,
8831                        __rte_unused struct cmdline *cl,
8832                        __rte_unused void *data)
8833 {
8834         int ret = -ENOTSUP;
8835         uint16_t vf_rxmode = 0;
8836         struct cmd_set_vf_rxmode *res = parsed_result;
8837
8838         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8839         if (!strcmp(res->what,"rxmode")) {
8840                 if (!strcmp(res->mode, "AUPE"))
8841                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8842                 else if (!strcmp(res->mode, "ROPE"))
8843                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8844                 else if (!strcmp(res->mode, "BAM"))
8845                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8846                 else if (!strncmp(res->mode, "MPE",3))
8847                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8848         }
8849
8850         RTE_SET_USED(is_on);
8851
8852 #ifdef RTE_LIBRTE_IXGBE_PMD
8853         if (ret == -ENOTSUP)
8854                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8855                                                   vf_rxmode, (uint8_t)is_on);
8856 #endif
8857 #ifdef RTE_LIBRTE_BNXT_PMD
8858         if (ret == -ENOTSUP)
8859                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8860                                                  vf_rxmode, (uint8_t)is_on);
8861 #endif
8862         if (ret < 0)
8863                 printf("bad VF receive mode parameter, return code = %d \n",
8864                 ret);
8865 }
8866
8867 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8868         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8869                                  set, "set");
8870 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8871         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8872                                  port, "port");
8873 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8874         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8875                               port_id, UINT16);
8876 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8877         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8878                                  vf, "vf");
8879 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8880         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8881                               vf_id, UINT8);
8882 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8883         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8884                                  what, "rxmode");
8885 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8886         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8887                                  mode, "AUPE#ROPE#BAM#MPE");
8888 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8889         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8890                                  on, "on#off");
8891
8892 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8893         .f = cmd_set_vf_rxmode_parsed,
8894         .data = NULL,
8895         .help_str = "set port <port_id> vf <vf_id> rxmode "
8896                 "AUPE|ROPE|BAM|MPE on|off",
8897         .tokens = {
8898                 (void *)&cmd_set_vf_rxmode_set,
8899                 (void *)&cmd_set_vf_rxmode_port,
8900                 (void *)&cmd_set_vf_rxmode_portid,
8901                 (void *)&cmd_set_vf_rxmode_vf,
8902                 (void *)&cmd_set_vf_rxmode_vfid,
8903                 (void *)&cmd_set_vf_rxmode_what,
8904                 (void *)&cmd_set_vf_rxmode_mode,
8905                 (void *)&cmd_set_vf_rxmode_on,
8906                 NULL,
8907         },
8908 };
8909
8910 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8911 struct cmd_vf_mac_addr_result {
8912         cmdline_fixed_string_t mac_addr_cmd;
8913         cmdline_fixed_string_t what;
8914         cmdline_fixed_string_t port;
8915         uint16_t port_num;
8916         cmdline_fixed_string_t vf;
8917         uint8_t vf_num;
8918         struct rte_ether_addr address;
8919 };
8920
8921 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8922                 __rte_unused struct cmdline *cl,
8923                 __rte_unused void *data)
8924 {
8925         struct cmd_vf_mac_addr_result *res = parsed_result;
8926         int ret = -ENOTSUP;
8927
8928         if (strcmp(res->what, "add") != 0)
8929                 return;
8930
8931 #ifdef RTE_LIBRTE_I40E_PMD
8932         if (ret == -ENOTSUP)
8933                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8934                                                    &res->address);
8935 #endif
8936 #ifdef RTE_LIBRTE_BNXT_PMD
8937         if (ret == -ENOTSUP)
8938                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8939                                                 res->vf_num);
8940 #endif
8941
8942         if(ret < 0)
8943                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8944
8945 }
8946
8947 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8948         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8949                                 mac_addr_cmd,"mac_addr");
8950 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8951         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8952                                 what,"add");
8953 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8954         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8955                                 port,"port");
8956 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8957         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8958                                 port_num, UINT16);
8959 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8960         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8961                                 vf,"vf");
8962 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8963         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8964                                 vf_num, UINT8);
8965 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8966         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8967                                 address);
8968
8969 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8970         .f = cmd_vf_mac_addr_parsed,
8971         .data = (void *)0,
8972         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8973                 "Add MAC address filtering for a VF on port_id",
8974         .tokens = {
8975                 (void *)&cmd_vf_mac_addr_cmd,
8976                 (void *)&cmd_vf_mac_addr_what,
8977                 (void *)&cmd_vf_mac_addr_port,
8978                 (void *)&cmd_vf_mac_addr_portnum,
8979                 (void *)&cmd_vf_mac_addr_vf,
8980                 (void *)&cmd_vf_mac_addr_vfnum,
8981                 (void *)&cmd_vf_mac_addr_addr,
8982                 NULL,
8983         },
8984 };
8985
8986 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8987 struct cmd_vf_rx_vlan_filter {
8988         cmdline_fixed_string_t rx_vlan;
8989         cmdline_fixed_string_t what;
8990         uint16_t vlan_id;
8991         cmdline_fixed_string_t port;
8992         portid_t port_id;
8993         cmdline_fixed_string_t vf;
8994         uint64_t vf_mask;
8995 };
8996
8997 static void
8998 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8999                           __rte_unused struct cmdline *cl,
9000                           __rte_unused void *data)
9001 {
9002         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9003         int ret = -ENOTSUP;
9004
9005         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9006
9007 #ifdef RTE_LIBRTE_IXGBE_PMD
9008         if (ret == -ENOTSUP)
9009                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9010                                 res->vlan_id, res->vf_mask, is_add);
9011 #endif
9012 #ifdef RTE_LIBRTE_I40E_PMD
9013         if (ret == -ENOTSUP)
9014                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9015                                 res->vlan_id, res->vf_mask, is_add);
9016 #endif
9017 #ifdef RTE_LIBRTE_BNXT_PMD
9018         if (ret == -ENOTSUP)
9019                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9020                                 res->vlan_id, res->vf_mask, is_add);
9021 #endif
9022
9023         switch (ret) {
9024         case 0:
9025                 break;
9026         case -EINVAL:
9027                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9028                                 res->vlan_id, res->vf_mask);
9029                 break;
9030         case -ENODEV:
9031                 printf("invalid port_id %d\n", res->port_id);
9032                 break;
9033         case -ENOTSUP:
9034                 printf("function not implemented or supported\n");
9035                 break;
9036         default:
9037                 printf("programming error: (%s)\n", strerror(-ret));
9038         }
9039 }
9040
9041 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9042         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9043                                  rx_vlan, "rx_vlan");
9044 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9045         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9046                                  what, "add#rm");
9047 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9048         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9049                               vlan_id, UINT16);
9050 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9051         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9052                                  port, "port");
9053 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9054         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9055                               port_id, UINT16);
9056 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9057         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9058                                  vf, "vf");
9059 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9060         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9061                               vf_mask, UINT64);
9062
9063 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9064         .f = cmd_vf_rx_vlan_filter_parsed,
9065         .data = NULL,
9066         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9067                 "(vf_mask = hexadecimal VF mask)",
9068         .tokens = {
9069                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9070                 (void *)&cmd_vf_rx_vlan_filter_what,
9071                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9072                 (void *)&cmd_vf_rx_vlan_filter_port,
9073                 (void *)&cmd_vf_rx_vlan_filter_portid,
9074                 (void *)&cmd_vf_rx_vlan_filter_vf,
9075                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9076                 NULL,
9077         },
9078 };
9079
9080 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9081 struct cmd_queue_rate_limit_result {
9082         cmdline_fixed_string_t set;
9083         cmdline_fixed_string_t port;
9084         uint16_t port_num;
9085         cmdline_fixed_string_t queue;
9086         uint8_t queue_num;
9087         cmdline_fixed_string_t rate;
9088         uint16_t rate_num;
9089 };
9090
9091 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9092                 __rte_unused struct cmdline *cl,
9093                 __rte_unused void *data)
9094 {
9095         struct cmd_queue_rate_limit_result *res = parsed_result;
9096         int ret = 0;
9097
9098         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9099                 && (strcmp(res->queue, "queue") == 0)
9100                 && (strcmp(res->rate, "rate") == 0))
9101                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9102                                         res->rate_num);
9103         if (ret < 0)
9104                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9105
9106 }
9107
9108 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9109         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9110                                 set, "set");
9111 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9112         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9113                                 port, "port");
9114 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9115         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9116                                 port_num, UINT16);
9117 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9118         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9119                                 queue, "queue");
9120 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9121         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9122                                 queue_num, UINT8);
9123 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9124         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9125                                 rate, "rate");
9126 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9127         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9128                                 rate_num, UINT16);
9129
9130 cmdline_parse_inst_t cmd_queue_rate_limit = {
9131         .f = cmd_queue_rate_limit_parsed,
9132         .data = (void *)0,
9133         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9134                 "Set rate limit for a queue on port_id",
9135         .tokens = {
9136                 (void *)&cmd_queue_rate_limit_set,
9137                 (void *)&cmd_queue_rate_limit_port,
9138                 (void *)&cmd_queue_rate_limit_portnum,
9139                 (void *)&cmd_queue_rate_limit_queue,
9140                 (void *)&cmd_queue_rate_limit_queuenum,
9141                 (void *)&cmd_queue_rate_limit_rate,
9142                 (void *)&cmd_queue_rate_limit_ratenum,
9143                 NULL,
9144         },
9145 };
9146
9147 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9148 struct cmd_vf_rate_limit_result {
9149         cmdline_fixed_string_t set;
9150         cmdline_fixed_string_t port;
9151         uint16_t port_num;
9152         cmdline_fixed_string_t vf;
9153         uint8_t vf_num;
9154         cmdline_fixed_string_t rate;
9155         uint16_t rate_num;
9156         cmdline_fixed_string_t q_msk;
9157         uint64_t q_msk_val;
9158 };
9159
9160 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9161                 __rte_unused struct cmdline *cl,
9162                 __rte_unused void *data)
9163 {
9164         struct cmd_vf_rate_limit_result *res = parsed_result;
9165         int ret = 0;
9166
9167         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9168                 && (strcmp(res->vf, "vf") == 0)
9169                 && (strcmp(res->rate, "rate") == 0)
9170                 && (strcmp(res->q_msk, "queue_mask") == 0))
9171                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9172                                         res->rate_num, res->q_msk_val);
9173         if (ret < 0)
9174                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9175
9176 }
9177
9178 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9179         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9180                                 set, "set");
9181 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9182         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9183                                 port, "port");
9184 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9185         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9186                                 port_num, UINT16);
9187 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9188         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9189                                 vf, "vf");
9190 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9191         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9192                                 vf_num, UINT8);
9193 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9194         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9195                                 rate, "rate");
9196 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9197         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9198                                 rate_num, UINT16);
9199 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9200         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9201                                 q_msk, "queue_mask");
9202 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9203         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9204                                 q_msk_val, UINT64);
9205
9206 cmdline_parse_inst_t cmd_vf_rate_limit = {
9207         .f = cmd_vf_rate_limit_parsed,
9208         .data = (void *)0,
9209         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9210                 "queue_mask <queue_mask_value>: "
9211                 "Set rate limit for queues of VF on port_id",
9212         .tokens = {
9213                 (void *)&cmd_vf_rate_limit_set,
9214                 (void *)&cmd_vf_rate_limit_port,
9215                 (void *)&cmd_vf_rate_limit_portnum,
9216                 (void *)&cmd_vf_rate_limit_vf,
9217                 (void *)&cmd_vf_rate_limit_vfnum,
9218                 (void *)&cmd_vf_rate_limit_rate,
9219                 (void *)&cmd_vf_rate_limit_ratenum,
9220                 (void *)&cmd_vf_rate_limit_q_msk,
9221                 (void *)&cmd_vf_rate_limit_q_msk_val,
9222                 NULL,
9223         },
9224 };
9225
9226 /* *** ADD TUNNEL FILTER OF A PORT *** */
9227 struct cmd_tunnel_filter_result {
9228         cmdline_fixed_string_t cmd;
9229         cmdline_fixed_string_t what;
9230         portid_t port_id;
9231         struct rte_ether_addr outer_mac;
9232         struct rte_ether_addr inner_mac;
9233         cmdline_ipaddr_t ip_value;
9234         uint16_t inner_vlan;
9235         cmdline_fixed_string_t tunnel_type;
9236         cmdline_fixed_string_t filter_type;
9237         uint32_t tenant_id;
9238         uint16_t queue_num;
9239 };
9240
9241 static void
9242 cmd_tunnel_filter_parsed(void *parsed_result,
9243                           __rte_unused struct cmdline *cl,
9244                           __rte_unused void *data)
9245 {
9246         struct cmd_tunnel_filter_result *res = parsed_result;
9247         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9248         int ret = 0;
9249
9250         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9251
9252         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9253         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9254         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9255
9256         if (res->ip_value.family == AF_INET) {
9257                 tunnel_filter_conf.ip_addr.ipv4_addr =
9258                         res->ip_value.addr.ipv4.s_addr;
9259                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9260         } else {
9261                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9262                         &(res->ip_value.addr.ipv6),
9263                         sizeof(struct in6_addr));
9264                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9265         }
9266
9267         if (!strcmp(res->filter_type, "imac-ivlan"))
9268                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9269         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9270                 tunnel_filter_conf.filter_type =
9271                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9272         else if (!strcmp(res->filter_type, "imac-tenid"))
9273                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9274         else if (!strcmp(res->filter_type, "imac"))
9275                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9276         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9277                 tunnel_filter_conf.filter_type =
9278                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9279         else if (!strcmp(res->filter_type, "oip"))
9280                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9281         else if (!strcmp(res->filter_type, "iip"))
9282                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9283         else {
9284                 printf("The filter type is not supported");
9285                 return;
9286         }
9287
9288         if (!strcmp(res->tunnel_type, "vxlan"))
9289                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9290         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9291                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9292         else if (!strcmp(res->tunnel_type, "nvgre"))
9293                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9294         else if (!strcmp(res->tunnel_type, "ipingre"))
9295                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9296         else {
9297                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9298                 return;
9299         }
9300
9301         tunnel_filter_conf.tenant_id = res->tenant_id;
9302         tunnel_filter_conf.queue_id = res->queue_num;
9303         if (!strcmp(res->what, "add"))
9304                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9305                                         RTE_ETH_FILTER_TUNNEL,
9306                                         RTE_ETH_FILTER_ADD,
9307                                         &tunnel_filter_conf);
9308         else
9309                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9310                                         RTE_ETH_FILTER_TUNNEL,
9311                                         RTE_ETH_FILTER_DELETE,
9312                                         &tunnel_filter_conf);
9313         if (ret < 0)
9314                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9315                                 strerror(-ret));
9316
9317 }
9318 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9319         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9320         cmd, "tunnel_filter");
9321 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9322         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9323         what, "add#rm");
9324 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9325         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9326         port_id, UINT16);
9327 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9328         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9329         outer_mac);
9330 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9331         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9332         inner_mac);
9333 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9334         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9335         inner_vlan, UINT16);
9336 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9337         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9338         ip_value);
9339 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9340         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9341         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9342
9343 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9344         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9345         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9346                 "imac#omac-imac-tenid");
9347 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9348         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9349         tenant_id, UINT32);
9350 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9351         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9352         queue_num, UINT16);
9353
9354 cmdline_parse_inst_t cmd_tunnel_filter = {
9355         .f = cmd_tunnel_filter_parsed,
9356         .data = (void *)0,
9357         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9358                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9359                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9360                 "<queue_id>: Add/Rm tunnel filter of a port",
9361         .tokens = {
9362                 (void *)&cmd_tunnel_filter_cmd,
9363                 (void *)&cmd_tunnel_filter_what,
9364                 (void *)&cmd_tunnel_filter_port_id,
9365                 (void *)&cmd_tunnel_filter_outer_mac,
9366                 (void *)&cmd_tunnel_filter_inner_mac,
9367                 (void *)&cmd_tunnel_filter_ip_value,
9368                 (void *)&cmd_tunnel_filter_innner_vlan,
9369                 (void *)&cmd_tunnel_filter_tunnel_type,
9370                 (void *)&cmd_tunnel_filter_filter_type,
9371                 (void *)&cmd_tunnel_filter_tenant_id,
9372                 (void *)&cmd_tunnel_filter_queue_num,
9373                 NULL,
9374         },
9375 };
9376
9377 /* *** CONFIGURE TUNNEL UDP PORT *** */
9378 struct cmd_tunnel_udp_config {
9379         cmdline_fixed_string_t cmd;
9380         cmdline_fixed_string_t what;
9381         uint16_t udp_port;
9382         portid_t port_id;
9383 };
9384
9385 static void
9386 cmd_tunnel_udp_config_parsed(void *parsed_result,
9387                           __rte_unused struct cmdline *cl,
9388                           __rte_unused void *data)
9389 {
9390         struct cmd_tunnel_udp_config *res = parsed_result;
9391         struct rte_eth_udp_tunnel tunnel_udp;
9392         int ret;
9393
9394         tunnel_udp.udp_port = res->udp_port;
9395
9396         if (!strcmp(res->cmd, "rx_vxlan_port"))
9397                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9398
9399         if (!strcmp(res->what, "add"))
9400                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9401                                                       &tunnel_udp);
9402         else
9403                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9404                                                          &tunnel_udp);
9405
9406         if (ret < 0)
9407                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9408 }
9409
9410 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9411         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9412                                 cmd, "rx_vxlan_port");
9413 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9414         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9415                                 what, "add#rm");
9416 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9417         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9418                                 udp_port, UINT16);
9419 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9420         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9421                                 port_id, UINT16);
9422
9423 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9424         .f = cmd_tunnel_udp_config_parsed,
9425         .data = (void *)0,
9426         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9427                 "Add/Remove a tunneling UDP port filter",
9428         .tokens = {
9429                 (void *)&cmd_tunnel_udp_config_cmd,
9430                 (void *)&cmd_tunnel_udp_config_what,
9431                 (void *)&cmd_tunnel_udp_config_udp_port,
9432                 (void *)&cmd_tunnel_udp_config_port_id,
9433                 NULL,
9434         },
9435 };
9436
9437 struct cmd_config_tunnel_udp_port {
9438         cmdline_fixed_string_t port;
9439         cmdline_fixed_string_t config;
9440         portid_t port_id;
9441         cmdline_fixed_string_t udp_tunnel_port;
9442         cmdline_fixed_string_t action;
9443         cmdline_fixed_string_t tunnel_type;
9444         uint16_t udp_port;
9445 };
9446
9447 static void
9448 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9449                                __rte_unused struct cmdline *cl,
9450                                __rte_unused void *data)
9451 {
9452         struct cmd_config_tunnel_udp_port *res = parsed_result;
9453         struct rte_eth_udp_tunnel tunnel_udp;
9454         int ret = 0;
9455
9456         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9457                 return;
9458
9459         tunnel_udp.udp_port = res->udp_port;
9460
9461         if (!strcmp(res->tunnel_type, "vxlan")) {
9462                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9463         } else if (!strcmp(res->tunnel_type, "geneve")) {
9464                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9465         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9466                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9467         } else {
9468                 printf("Invalid tunnel type\n");
9469                 return;
9470         }
9471
9472         if (!strcmp(res->action, "add"))
9473                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9474                                                       &tunnel_udp);
9475         else
9476                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9477                                                          &tunnel_udp);
9478
9479         if (ret < 0)
9480                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9481 }
9482
9483 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9484         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9485                                  "port");
9486 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9487         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9488                                  "config");
9489 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9490         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9491                               UINT16);
9492 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9493         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9494                                  udp_tunnel_port,
9495                                  "udp_tunnel_port");
9496 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9497         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9498                                  "add#rm");
9499 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9500         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9501                                  "vxlan#geneve#vxlan-gpe");
9502 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9503         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9504                               UINT16);
9505
9506 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9507         .f = cmd_cfg_tunnel_udp_port_parsed,
9508         .data = NULL,
9509         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9510         .tokens = {
9511                 (void *)&cmd_config_tunnel_udp_port_port,
9512                 (void *)&cmd_config_tunnel_udp_port_config,
9513                 (void *)&cmd_config_tunnel_udp_port_port_id,
9514                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9515                 (void *)&cmd_config_tunnel_udp_port_action,
9516                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9517                 (void *)&cmd_config_tunnel_udp_port_value,
9518                 NULL,
9519         },
9520 };
9521
9522 /* *** GLOBAL CONFIG *** */
9523 struct cmd_global_config_result {
9524         cmdline_fixed_string_t cmd;
9525         portid_t port_id;
9526         cmdline_fixed_string_t cfg_type;
9527         uint8_t len;
9528 };
9529
9530 static void
9531 cmd_global_config_parsed(void *parsed_result,
9532                          __rte_unused struct cmdline *cl,
9533                          __rte_unused void *data)
9534 {
9535         struct cmd_global_config_result *res = parsed_result;
9536         struct rte_eth_global_cfg conf;
9537         int ret;
9538
9539         memset(&conf, 0, sizeof(conf));
9540         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9541         conf.cfg.gre_key_len = res->len;
9542         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9543                                       RTE_ETH_FILTER_SET, &conf);
9544 #ifdef RTE_LIBRTE_I40E_PMD
9545         if (ret == -ENOTSUP)
9546                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9547 #endif
9548         if (ret != 0)
9549                 printf("Global config error\n");
9550 }
9551
9552 cmdline_parse_token_string_t cmd_global_config_cmd =
9553         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9554                 "global_config");
9555 cmdline_parse_token_num_t cmd_global_config_port_id =
9556         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9557                                UINT16);
9558 cmdline_parse_token_string_t cmd_global_config_type =
9559         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9560                 cfg_type, "gre-key-len");
9561 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9562         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9563                 len, UINT8);
9564
9565 cmdline_parse_inst_t cmd_global_config = {
9566         .f = cmd_global_config_parsed,
9567         .data = (void *)NULL,
9568         .help_str = "global_config <port_id> gre-key-len <key_len>",
9569         .tokens = {
9570                 (void *)&cmd_global_config_cmd,
9571                 (void *)&cmd_global_config_port_id,
9572                 (void *)&cmd_global_config_type,
9573                 (void *)&cmd_global_config_gre_key_len,
9574                 NULL,
9575         },
9576 };
9577
9578 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9579 struct cmd_set_mirror_mask_result {
9580         cmdline_fixed_string_t set;
9581         cmdline_fixed_string_t port;
9582         portid_t port_id;
9583         cmdline_fixed_string_t mirror;
9584         uint8_t rule_id;
9585         cmdline_fixed_string_t what;
9586         cmdline_fixed_string_t value;
9587         cmdline_fixed_string_t dstpool;
9588         uint8_t dstpool_id;
9589         cmdline_fixed_string_t on;
9590 };
9591
9592 cmdline_parse_token_string_t cmd_mirror_mask_set =
9593         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9594                                 set, "set");
9595 cmdline_parse_token_string_t cmd_mirror_mask_port =
9596         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9597                                 port, "port");
9598 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9599         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9600                                 port_id, UINT16);
9601 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9602         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9603                                 mirror, "mirror-rule");
9604 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9605         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9606                                 rule_id, UINT8);
9607 cmdline_parse_token_string_t cmd_mirror_mask_what =
9608         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9609                                 what, "pool-mirror-up#pool-mirror-down"
9610                                       "#vlan-mirror");
9611 cmdline_parse_token_string_t cmd_mirror_mask_value =
9612         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9613                                 value, NULL);
9614 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9615         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9616                                 dstpool, "dst-pool");
9617 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9618         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9619                                 dstpool_id, UINT8);
9620 cmdline_parse_token_string_t cmd_mirror_mask_on =
9621         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9622                                 on, "on#off");
9623
9624 static void
9625 cmd_set_mirror_mask_parsed(void *parsed_result,
9626                        __rte_unused struct cmdline *cl,
9627                        __rte_unused void *data)
9628 {
9629         int ret,nb_item,i;
9630         struct cmd_set_mirror_mask_result *res = parsed_result;
9631         struct rte_eth_mirror_conf mr_conf;
9632
9633         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9634
9635         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9636
9637         mr_conf.dst_pool = res->dstpool_id;
9638
9639         if (!strcmp(res->what, "pool-mirror-up")) {
9640                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9641                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9642         } else if (!strcmp(res->what, "pool-mirror-down")) {
9643                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9644                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9645         } else if (!strcmp(res->what, "vlan-mirror")) {
9646                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9647                 nb_item = parse_item_list(res->value, "vlan",
9648                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9649                 if (nb_item <= 0)
9650                         return;
9651
9652                 for (i = 0; i < nb_item; i++) {
9653                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9654                                 printf("Invalid vlan_id: must be < 4096\n");
9655                                 return;
9656                         }
9657
9658                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9659                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9660                 }
9661         }
9662
9663         if (!strcmp(res->on, "on"))
9664                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9665                                                 res->rule_id, 1);
9666         else
9667                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9668                                                 res->rule_id, 0);
9669         if (ret < 0)
9670                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9671 }
9672
9673 cmdline_parse_inst_t cmd_set_mirror_mask = {
9674                 .f = cmd_set_mirror_mask_parsed,
9675                 .data = NULL,
9676                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9677                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9678                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9679                 .tokens = {
9680                         (void *)&cmd_mirror_mask_set,
9681                         (void *)&cmd_mirror_mask_port,
9682                         (void *)&cmd_mirror_mask_portid,
9683                         (void *)&cmd_mirror_mask_mirror,
9684                         (void *)&cmd_mirror_mask_ruleid,
9685                         (void *)&cmd_mirror_mask_what,
9686                         (void *)&cmd_mirror_mask_value,
9687                         (void *)&cmd_mirror_mask_dstpool,
9688                         (void *)&cmd_mirror_mask_poolid,
9689                         (void *)&cmd_mirror_mask_on,
9690                         NULL,
9691                 },
9692 };
9693
9694 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9695 struct cmd_set_mirror_link_result {
9696         cmdline_fixed_string_t set;
9697         cmdline_fixed_string_t port;
9698         portid_t port_id;
9699         cmdline_fixed_string_t mirror;
9700         uint8_t rule_id;
9701         cmdline_fixed_string_t what;
9702         cmdline_fixed_string_t dstpool;
9703         uint8_t dstpool_id;
9704         cmdline_fixed_string_t on;
9705 };
9706
9707 cmdline_parse_token_string_t cmd_mirror_link_set =
9708         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9709                                  set, "set");
9710 cmdline_parse_token_string_t cmd_mirror_link_port =
9711         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9712                                 port, "port");
9713 cmdline_parse_token_num_t cmd_mirror_link_portid =
9714         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9715                                 port_id, UINT16);
9716 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9717         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9718                                 mirror, "mirror-rule");
9719 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9720         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9721                             rule_id, UINT8);
9722 cmdline_parse_token_string_t cmd_mirror_link_what =
9723         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9724                                 what, "uplink-mirror#downlink-mirror");
9725 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9726         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9727                                 dstpool, "dst-pool");
9728 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9729         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9730                                 dstpool_id, UINT8);
9731 cmdline_parse_token_string_t cmd_mirror_link_on =
9732         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9733                                 on, "on#off");
9734
9735 static void
9736 cmd_set_mirror_link_parsed(void *parsed_result,
9737                        __rte_unused struct cmdline *cl,
9738                        __rte_unused void *data)
9739 {
9740         int ret;
9741         struct cmd_set_mirror_link_result *res = parsed_result;
9742         struct rte_eth_mirror_conf mr_conf;
9743
9744         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9745         if (!strcmp(res->what, "uplink-mirror"))
9746                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9747         else
9748                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9749
9750         mr_conf.dst_pool = res->dstpool_id;
9751
9752         if (!strcmp(res->on, "on"))
9753                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9754                                                 res->rule_id, 1);
9755         else
9756                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9757                                                 res->rule_id, 0);
9758
9759         /* check the return value and print it if is < 0 */
9760         if (ret < 0)
9761                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9762
9763 }
9764
9765 cmdline_parse_inst_t cmd_set_mirror_link = {
9766                 .f = cmd_set_mirror_link_parsed,
9767                 .data = NULL,
9768                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9769                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9770                 .tokens = {
9771                         (void *)&cmd_mirror_link_set,
9772                         (void *)&cmd_mirror_link_port,
9773                         (void *)&cmd_mirror_link_portid,
9774                         (void *)&cmd_mirror_link_mirror,
9775                         (void *)&cmd_mirror_link_ruleid,
9776                         (void *)&cmd_mirror_link_what,
9777                         (void *)&cmd_mirror_link_dstpool,
9778                         (void *)&cmd_mirror_link_poolid,
9779                         (void *)&cmd_mirror_link_on,
9780                         NULL,
9781                 },
9782 };
9783
9784 /* *** RESET VM MIRROR RULE *** */
9785 struct cmd_rm_mirror_rule_result {
9786         cmdline_fixed_string_t reset;
9787         cmdline_fixed_string_t port;
9788         portid_t port_id;
9789         cmdline_fixed_string_t mirror;
9790         uint8_t rule_id;
9791 };
9792
9793 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9794         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9795                                  reset, "reset");
9796 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9797         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9798                                 port, "port");
9799 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9800         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9801                                 port_id, UINT16);
9802 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9803         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9804                                 mirror, "mirror-rule");
9805 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9806         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9807                                 rule_id, UINT8);
9808
9809 static void
9810 cmd_reset_mirror_rule_parsed(void *parsed_result,
9811                        __rte_unused struct cmdline *cl,
9812                        __rte_unused void *data)
9813 {
9814         int ret;
9815         struct cmd_set_mirror_link_result *res = parsed_result;
9816         /* check rule_id */
9817         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9818         if(ret < 0)
9819                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9820 }
9821
9822 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9823                 .f = cmd_reset_mirror_rule_parsed,
9824                 .data = NULL,
9825                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9826                 .tokens = {
9827                         (void *)&cmd_rm_mirror_rule_reset,
9828                         (void *)&cmd_rm_mirror_rule_port,
9829                         (void *)&cmd_rm_mirror_rule_portid,
9830                         (void *)&cmd_rm_mirror_rule_mirror,
9831                         (void *)&cmd_rm_mirror_rule_ruleid,
9832                         NULL,
9833                 },
9834 };
9835
9836 /* ******************************************************************************** */
9837
9838 struct cmd_dump_result {
9839         cmdline_fixed_string_t dump;
9840 };
9841
9842 static void
9843 dump_struct_sizes(void)
9844 {
9845 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9846         DUMP_SIZE(struct rte_mbuf);
9847         DUMP_SIZE(struct rte_mempool);
9848         DUMP_SIZE(struct rte_ring);
9849 #undef DUMP_SIZE
9850 }
9851
9852
9853 /* Dump the socket memory statistics on console */
9854 static void
9855 dump_socket_mem(FILE *f)
9856 {
9857         struct rte_malloc_socket_stats socket_stats;
9858         unsigned int i;
9859         size_t total = 0;
9860         size_t alloc = 0;
9861         size_t free = 0;
9862         unsigned int n_alloc = 0;
9863         unsigned int n_free = 0;
9864         static size_t last_allocs;
9865         static size_t last_total;
9866
9867
9868         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9869                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9870                     !socket_stats.heap_totalsz_bytes)
9871                         continue;
9872                 total += socket_stats.heap_totalsz_bytes;
9873                 alloc += socket_stats.heap_allocsz_bytes;
9874                 free += socket_stats.heap_freesz_bytes;
9875                 n_alloc += socket_stats.alloc_count;
9876                 n_free += socket_stats.free_count;
9877                 fprintf(f,
9878                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9879                         i,
9880                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9881                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9882                         (double)socket_stats.heap_allocsz_bytes * 100 /
9883                         (double)socket_stats.heap_totalsz_bytes,
9884                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9885                         socket_stats.alloc_count,
9886                         socket_stats.free_count);
9887         }
9888         fprintf(f,
9889                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9890                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9891                 (double)alloc * 100 / (double)total,
9892                 (double)free / (1024 * 1024),
9893                 n_alloc, n_free);
9894         if (last_allocs)
9895                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9896                         ((double)total - (double)last_total) / (1024 * 1024),
9897                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9898         last_allocs = alloc;
9899         last_total = total;
9900 }
9901
9902 static void cmd_dump_parsed(void *parsed_result,
9903                             __rte_unused struct cmdline *cl,
9904                             __rte_unused void *data)
9905 {
9906         struct cmd_dump_result *res = parsed_result;
9907
9908         if (!strcmp(res->dump, "dump_physmem"))
9909                 rte_dump_physmem_layout(stdout);
9910         else if (!strcmp(res->dump, "dump_socket_mem"))
9911                 dump_socket_mem(stdout);
9912         else if (!strcmp(res->dump, "dump_memzone"))
9913                 rte_memzone_dump(stdout);
9914         else if (!strcmp(res->dump, "dump_struct_sizes"))
9915                 dump_struct_sizes();
9916         else if (!strcmp(res->dump, "dump_ring"))
9917                 rte_ring_list_dump(stdout);
9918         else if (!strcmp(res->dump, "dump_mempool"))
9919                 rte_mempool_list_dump(stdout);
9920         else if (!strcmp(res->dump, "dump_devargs"))
9921                 rte_devargs_dump(stdout);
9922         else if (!strcmp(res->dump, "dump_log_types"))
9923                 rte_log_dump(stdout);
9924 }
9925
9926 cmdline_parse_token_string_t cmd_dump_dump =
9927         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9928                 "dump_physmem#"
9929                 "dump_memzone#"
9930                 "dump_socket_mem#"
9931                 "dump_struct_sizes#"
9932                 "dump_ring#"
9933                 "dump_mempool#"
9934                 "dump_devargs#"
9935                 "dump_log_types");
9936
9937 cmdline_parse_inst_t cmd_dump = {
9938         .f = cmd_dump_parsed,  /* function to call */
9939         .data = NULL,      /* 2nd arg of func */
9940         .help_str = "Dump status",
9941         .tokens = {        /* token list, NULL terminated */
9942                 (void *)&cmd_dump_dump,
9943                 NULL,
9944         },
9945 };
9946
9947 /* ******************************************************************************** */
9948
9949 struct cmd_dump_one_result {
9950         cmdline_fixed_string_t dump;
9951         cmdline_fixed_string_t name;
9952 };
9953
9954 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9955                                 __rte_unused void *data)
9956 {
9957         struct cmd_dump_one_result *res = parsed_result;
9958
9959         if (!strcmp(res->dump, "dump_ring")) {
9960                 struct rte_ring *r;
9961                 r = rte_ring_lookup(res->name);
9962                 if (r == NULL) {
9963                         cmdline_printf(cl, "Cannot find ring\n");
9964                         return;
9965                 }
9966                 rte_ring_dump(stdout, r);
9967         } else if (!strcmp(res->dump, "dump_mempool")) {
9968                 struct rte_mempool *mp;
9969                 mp = rte_mempool_lookup(res->name);
9970                 if (mp == NULL) {
9971                         cmdline_printf(cl, "Cannot find mempool\n");
9972                         return;
9973                 }
9974                 rte_mempool_dump(stdout, mp);
9975         }
9976 }
9977
9978 cmdline_parse_token_string_t cmd_dump_one_dump =
9979         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9980                                  "dump_ring#dump_mempool");
9981
9982 cmdline_parse_token_string_t cmd_dump_one_name =
9983         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9984
9985 cmdline_parse_inst_t cmd_dump_one = {
9986         .f = cmd_dump_one_parsed,  /* function to call */
9987         .data = NULL,      /* 2nd arg of func */
9988         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9989         .tokens = {        /* token list, NULL terminated */
9990                 (void *)&cmd_dump_one_dump,
9991                 (void *)&cmd_dump_one_name,
9992                 NULL,
9993         },
9994 };
9995
9996 /* *** Add/Del syn filter *** */
9997 struct cmd_syn_filter_result {
9998         cmdline_fixed_string_t filter;
9999         portid_t port_id;
10000         cmdline_fixed_string_t ops;
10001         cmdline_fixed_string_t priority;
10002         cmdline_fixed_string_t high;
10003         cmdline_fixed_string_t queue;
10004         uint16_t queue_id;
10005 };
10006
10007 static void
10008 cmd_syn_filter_parsed(void *parsed_result,
10009                         __rte_unused struct cmdline *cl,
10010                         __rte_unused void *data)
10011 {
10012         struct cmd_syn_filter_result *res = parsed_result;
10013         struct rte_eth_syn_filter syn_filter;
10014         int ret = 0;
10015
10016         ret = rte_eth_dev_filter_supported(res->port_id,
10017                                         RTE_ETH_FILTER_SYN);
10018         if (ret < 0) {
10019                 printf("syn filter is not supported on port %u.\n",
10020                                 res->port_id);
10021                 return;
10022         }
10023
10024         memset(&syn_filter, 0, sizeof(syn_filter));
10025
10026         if (!strcmp(res->ops, "add")) {
10027                 if (!strcmp(res->high, "high"))
10028                         syn_filter.hig_pri = 1;
10029                 else
10030                         syn_filter.hig_pri = 0;
10031
10032                 syn_filter.queue = res->queue_id;
10033                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10034                                                 RTE_ETH_FILTER_SYN,
10035                                                 RTE_ETH_FILTER_ADD,
10036                                                 &syn_filter);
10037         } else
10038                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10039                                                 RTE_ETH_FILTER_SYN,
10040                                                 RTE_ETH_FILTER_DELETE,
10041                                                 &syn_filter);
10042
10043         if (ret < 0)
10044                 printf("syn filter programming error: (%s)\n",
10045                                 strerror(-ret));
10046 }
10047
10048 cmdline_parse_token_string_t cmd_syn_filter_filter =
10049         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10050         filter, "syn_filter");
10051 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10052         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10053         port_id, UINT16);
10054 cmdline_parse_token_string_t cmd_syn_filter_ops =
10055         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10056         ops, "add#del");
10057 cmdline_parse_token_string_t cmd_syn_filter_priority =
10058         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10059                                 priority, "priority");
10060 cmdline_parse_token_string_t cmd_syn_filter_high =
10061         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10062                                 high, "high#low");
10063 cmdline_parse_token_string_t cmd_syn_filter_queue =
10064         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10065                                 queue, "queue");
10066 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10067         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10068                                 queue_id, UINT16);
10069
10070 cmdline_parse_inst_t cmd_syn_filter = {
10071         .f = cmd_syn_filter_parsed,
10072         .data = NULL,
10073         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10074                 "<queue_id>: Add/Delete syn filter",
10075         .tokens = {
10076                 (void *)&cmd_syn_filter_filter,
10077                 (void *)&cmd_syn_filter_port_id,
10078                 (void *)&cmd_syn_filter_ops,
10079                 (void *)&cmd_syn_filter_priority,
10080                 (void *)&cmd_syn_filter_high,
10081                 (void *)&cmd_syn_filter_queue,
10082                 (void *)&cmd_syn_filter_queue_id,
10083                 NULL,
10084         },
10085 };
10086
10087 /* *** queue region set *** */
10088 struct cmd_queue_region_result {
10089         cmdline_fixed_string_t set;
10090         cmdline_fixed_string_t port;
10091         portid_t port_id;
10092         cmdline_fixed_string_t cmd;
10093         cmdline_fixed_string_t region;
10094         uint8_t  region_id;
10095         cmdline_fixed_string_t queue_start_index;
10096         uint8_t  queue_id;
10097         cmdline_fixed_string_t queue_num;
10098         uint8_t  queue_num_value;
10099 };
10100
10101 static void
10102 cmd_queue_region_parsed(void *parsed_result,
10103                         __rte_unused struct cmdline *cl,
10104                         __rte_unused void *data)
10105 {
10106         struct cmd_queue_region_result *res = parsed_result;
10107         int ret = -ENOTSUP;
10108 #ifdef RTE_LIBRTE_I40E_PMD
10109         struct rte_pmd_i40e_queue_region_conf region_conf;
10110         enum rte_pmd_i40e_queue_region_op op_type;
10111 #endif
10112
10113         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10114                 return;
10115
10116 #ifdef RTE_LIBRTE_I40E_PMD
10117         memset(&region_conf, 0, sizeof(region_conf));
10118         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10119         region_conf.region_id = res->region_id;
10120         region_conf.queue_num = res->queue_num_value;
10121         region_conf.queue_start_index = res->queue_id;
10122
10123         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10124                                 op_type, &region_conf);
10125 #endif
10126
10127         switch (ret) {
10128         case 0:
10129                 break;
10130         case -ENOTSUP:
10131                 printf("function not implemented or supported\n");
10132                 break;
10133         default:
10134                 printf("queue region config error: (%s)\n", strerror(-ret));
10135         }
10136 }
10137
10138 cmdline_parse_token_string_t cmd_queue_region_set =
10139 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10140                 set, "set");
10141 cmdline_parse_token_string_t cmd_queue_region_port =
10142         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10143 cmdline_parse_token_num_t cmd_queue_region_port_id =
10144         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10145                                 port_id, UINT16);
10146 cmdline_parse_token_string_t cmd_queue_region_cmd =
10147         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10148                                  cmd, "queue-region");
10149 cmdline_parse_token_string_t cmd_queue_region_id =
10150         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10151                                 region, "region_id");
10152 cmdline_parse_token_num_t cmd_queue_region_index =
10153         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10154                                 region_id, UINT8);
10155 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10156         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10157                                 queue_start_index, "queue_start_index");
10158 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10159         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10160                                 queue_id, UINT8);
10161 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10162         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10163                                 queue_num, "queue_num");
10164 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10165         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10166                                 queue_num_value, UINT8);
10167
10168 cmdline_parse_inst_t cmd_queue_region = {
10169         .f = cmd_queue_region_parsed,
10170         .data = NULL,
10171         .help_str = "set port <port_id> queue-region region_id <value> "
10172                 "queue_start_index <value> queue_num <value>: Set a queue region",
10173         .tokens = {
10174                 (void *)&cmd_queue_region_set,
10175                 (void *)&cmd_queue_region_port,
10176                 (void *)&cmd_queue_region_port_id,
10177                 (void *)&cmd_queue_region_cmd,
10178                 (void *)&cmd_queue_region_id,
10179                 (void *)&cmd_queue_region_index,
10180                 (void *)&cmd_queue_region_queue_start_index,
10181                 (void *)&cmd_queue_region_queue_id,
10182                 (void *)&cmd_queue_region_queue_num,
10183                 (void *)&cmd_queue_region_queue_num_value,
10184                 NULL,
10185         },
10186 };
10187
10188 /* *** queue region and flowtype set *** */
10189 struct cmd_region_flowtype_result {
10190         cmdline_fixed_string_t set;
10191         cmdline_fixed_string_t port;
10192         portid_t port_id;
10193         cmdline_fixed_string_t cmd;
10194         cmdline_fixed_string_t region;
10195         uint8_t  region_id;
10196         cmdline_fixed_string_t flowtype;
10197         uint8_t  flowtype_id;
10198 };
10199
10200 static void
10201 cmd_region_flowtype_parsed(void *parsed_result,
10202                         __rte_unused struct cmdline *cl,
10203                         __rte_unused void *data)
10204 {
10205         struct cmd_region_flowtype_result *res = parsed_result;
10206         int ret = -ENOTSUP;
10207 #ifdef RTE_LIBRTE_I40E_PMD
10208         struct rte_pmd_i40e_queue_region_conf region_conf;
10209         enum rte_pmd_i40e_queue_region_op op_type;
10210 #endif
10211
10212         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10213                 return;
10214
10215 #ifdef RTE_LIBRTE_I40E_PMD
10216         memset(&region_conf, 0, sizeof(region_conf));
10217
10218         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10219         region_conf.region_id = res->region_id;
10220         region_conf.hw_flowtype = res->flowtype_id;
10221
10222         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10223                         op_type, &region_conf);
10224 #endif
10225
10226         switch (ret) {
10227         case 0:
10228                 break;
10229         case -ENOTSUP:
10230                 printf("function not implemented or supported\n");
10231                 break;
10232         default:
10233                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10234         }
10235 }
10236
10237 cmdline_parse_token_string_t cmd_region_flowtype_set =
10238 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10239                                 set, "set");
10240 cmdline_parse_token_string_t cmd_region_flowtype_port =
10241         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10242                                 port, "port");
10243 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10244         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10245                                 port_id, UINT16);
10246 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10247         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10248                                 cmd, "queue-region");
10249 cmdline_parse_token_string_t cmd_region_flowtype_index =
10250         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10251                                 region, "region_id");
10252 cmdline_parse_token_num_t cmd_region_flowtype_id =
10253         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10254                                 region_id, UINT8);
10255 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10256         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10257                                 flowtype, "flowtype");
10258 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10259         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10260                                 flowtype_id, UINT8);
10261 cmdline_parse_inst_t cmd_region_flowtype = {
10262         .f = cmd_region_flowtype_parsed,
10263         .data = NULL,
10264         .help_str = "set port <port_id> queue-region region_id <value> "
10265                 "flowtype <value>: Set a flowtype region index",
10266         .tokens = {
10267                 (void *)&cmd_region_flowtype_set,
10268                 (void *)&cmd_region_flowtype_port,
10269                 (void *)&cmd_region_flowtype_port_index,
10270                 (void *)&cmd_region_flowtype_cmd,
10271                 (void *)&cmd_region_flowtype_index,
10272                 (void *)&cmd_region_flowtype_id,
10273                 (void *)&cmd_region_flowtype_flow_index,
10274                 (void *)&cmd_region_flowtype_flow_id,
10275                 NULL,
10276         },
10277 };
10278
10279 /* *** User Priority (UP) to queue region (region_id) set *** */
10280 struct cmd_user_priority_region_result {
10281         cmdline_fixed_string_t set;
10282         cmdline_fixed_string_t port;
10283         portid_t port_id;
10284         cmdline_fixed_string_t cmd;
10285         cmdline_fixed_string_t user_priority;
10286         uint8_t  user_priority_id;
10287         cmdline_fixed_string_t region;
10288         uint8_t  region_id;
10289 };
10290
10291 static void
10292 cmd_user_priority_region_parsed(void *parsed_result,
10293                         __rte_unused struct cmdline *cl,
10294                         __rte_unused void *data)
10295 {
10296         struct cmd_user_priority_region_result *res = parsed_result;
10297         int ret = -ENOTSUP;
10298 #ifdef RTE_LIBRTE_I40E_PMD
10299         struct rte_pmd_i40e_queue_region_conf region_conf;
10300         enum rte_pmd_i40e_queue_region_op op_type;
10301 #endif
10302
10303         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10304                 return;
10305
10306 #ifdef RTE_LIBRTE_I40E_PMD
10307         memset(&region_conf, 0, sizeof(region_conf));
10308         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10309         region_conf.user_priority = res->user_priority_id;
10310         region_conf.region_id = res->region_id;
10311
10312         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10313                                 op_type, &region_conf);
10314 #endif
10315
10316         switch (ret) {
10317         case 0:
10318                 break;
10319         case -ENOTSUP:
10320                 printf("function not implemented or supported\n");
10321                 break;
10322         default:
10323                 printf("user_priority region config error: (%s)\n",
10324                                 strerror(-ret));
10325         }
10326 }
10327
10328 cmdline_parse_token_string_t cmd_user_priority_region_set =
10329         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10330                                 set, "set");
10331 cmdline_parse_token_string_t cmd_user_priority_region_port =
10332         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10333                                 port, "port");
10334 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10335         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10336                                 port_id, UINT16);
10337 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10338         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10339                                 cmd, "queue-region");
10340 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10341         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10342                                 user_priority, "UP");
10343 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10344         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10345                                 user_priority_id, UINT8);
10346 cmdline_parse_token_string_t cmd_user_priority_region_region =
10347         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10348                                 region, "region_id");
10349 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10350         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10351                                 region_id, UINT8);
10352
10353 cmdline_parse_inst_t cmd_user_priority_region = {
10354         .f = cmd_user_priority_region_parsed,
10355         .data = NULL,
10356         .help_str = "set port <port_id> queue-region UP <value> "
10357                 "region_id <value>: Set the mapping of User Priority (UP) "
10358                 "to queue region (region_id) ",
10359         .tokens = {
10360                 (void *)&cmd_user_priority_region_set,
10361                 (void *)&cmd_user_priority_region_port,
10362                 (void *)&cmd_user_priority_region_port_index,
10363                 (void *)&cmd_user_priority_region_cmd,
10364                 (void *)&cmd_user_priority_region_UP,
10365                 (void *)&cmd_user_priority_region_UP_id,
10366                 (void *)&cmd_user_priority_region_region,
10367                 (void *)&cmd_user_priority_region_region_id,
10368                 NULL,
10369         },
10370 };
10371
10372 /* *** flush all queue region related configuration *** */
10373 struct cmd_flush_queue_region_result {
10374         cmdline_fixed_string_t set;
10375         cmdline_fixed_string_t port;
10376         portid_t port_id;
10377         cmdline_fixed_string_t cmd;
10378         cmdline_fixed_string_t flush;
10379         cmdline_fixed_string_t what;
10380 };
10381
10382 static void
10383 cmd_flush_queue_region_parsed(void *parsed_result,
10384                         __rte_unused struct cmdline *cl,
10385                         __rte_unused void *data)
10386 {
10387         struct cmd_flush_queue_region_result *res = parsed_result;
10388         int ret = -ENOTSUP;
10389 #ifdef RTE_LIBRTE_I40E_PMD
10390         struct rte_pmd_i40e_queue_region_conf region_conf;
10391         enum rte_pmd_i40e_queue_region_op op_type;
10392 #endif
10393
10394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10395                 return;
10396
10397 #ifdef RTE_LIBRTE_I40E_PMD
10398         memset(&region_conf, 0, sizeof(region_conf));
10399
10400         if (strcmp(res->what, "on") == 0)
10401                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10402         else
10403                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10404
10405         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10406                                 op_type, &region_conf);
10407 #endif
10408
10409         switch (ret) {
10410         case 0:
10411                 break;
10412         case -ENOTSUP:
10413                 printf("function not implemented or supported\n");
10414                 break;
10415         default:
10416                 printf("queue region config flush error: (%s)\n",
10417                                 strerror(-ret));
10418         }
10419 }
10420
10421 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10422         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10423                                 set, "set");
10424 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10425         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10426                                 port, "port");
10427 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10428         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10429                                 port_id, UINT16);
10430 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10432                                 cmd, "queue-region");
10433 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10434         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10435                                 flush, "flush");
10436 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10437         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10438                                 what, "on#off");
10439
10440 cmdline_parse_inst_t cmd_flush_queue_region = {
10441         .f = cmd_flush_queue_region_parsed,
10442         .data = NULL,
10443         .help_str = "set port <port_id> queue-region flush on|off"
10444                 ": flush all queue region related configuration",
10445         .tokens = {
10446                 (void *)&cmd_flush_queue_region_set,
10447                 (void *)&cmd_flush_queue_region_port,
10448                 (void *)&cmd_flush_queue_region_port_index,
10449                 (void *)&cmd_flush_queue_region_cmd,
10450                 (void *)&cmd_flush_queue_region_flush,
10451                 (void *)&cmd_flush_queue_region_what,
10452                 NULL,
10453         },
10454 };
10455
10456 /* *** get all queue region related configuration info *** */
10457 struct cmd_show_queue_region_info {
10458         cmdline_fixed_string_t show;
10459         cmdline_fixed_string_t port;
10460         portid_t port_id;
10461         cmdline_fixed_string_t cmd;
10462 };
10463
10464 static void
10465 cmd_show_queue_region_info_parsed(void *parsed_result,
10466                         __rte_unused struct cmdline *cl,
10467                         __rte_unused void *data)
10468 {
10469         struct cmd_show_queue_region_info *res = parsed_result;
10470         int ret = -ENOTSUP;
10471 #ifdef RTE_LIBRTE_I40E_PMD
10472         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10473         enum rte_pmd_i40e_queue_region_op op_type;
10474 #endif
10475
10476         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10477                 return;
10478
10479 #ifdef RTE_LIBRTE_I40E_PMD
10480         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10481
10482         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10483
10484         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10485                                         op_type, &rte_pmd_regions);
10486
10487         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10488 #endif
10489
10490         switch (ret) {
10491         case 0:
10492                 break;
10493         case -ENOTSUP:
10494                 printf("function not implemented or supported\n");
10495                 break;
10496         default:
10497                 printf("queue region config info show error: (%s)\n",
10498                                 strerror(-ret));
10499         }
10500 }
10501
10502 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10503 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10504                                 show, "show");
10505 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10506         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10507                                 port, "port");
10508 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10509         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10510                                 port_id, UINT16);
10511 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10512         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10513                                 cmd, "queue-region");
10514
10515 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10516         .f = cmd_show_queue_region_info_parsed,
10517         .data = NULL,
10518         .help_str = "show port <port_id> queue-region"
10519                 ": show all queue region related configuration info",
10520         .tokens = {
10521                 (void *)&cmd_show_queue_region_info_get,
10522                 (void *)&cmd_show_queue_region_info_port,
10523                 (void *)&cmd_show_queue_region_info_port_index,
10524                 (void *)&cmd_show_queue_region_info_cmd,
10525                 NULL,
10526         },
10527 };
10528
10529 /* *** ADD/REMOVE A 2tuple FILTER *** */
10530 struct cmd_2tuple_filter_result {
10531         cmdline_fixed_string_t filter;
10532         portid_t port_id;
10533         cmdline_fixed_string_t ops;
10534         cmdline_fixed_string_t dst_port;
10535         uint16_t dst_port_value;
10536         cmdline_fixed_string_t protocol;
10537         uint8_t protocol_value;
10538         cmdline_fixed_string_t mask;
10539         uint8_t  mask_value;
10540         cmdline_fixed_string_t tcp_flags;
10541         uint8_t tcp_flags_value;
10542         cmdline_fixed_string_t priority;
10543         uint8_t  priority_value;
10544         cmdline_fixed_string_t queue;
10545         uint16_t  queue_id;
10546 };
10547
10548 static void
10549 cmd_2tuple_filter_parsed(void *parsed_result,
10550                         __rte_unused struct cmdline *cl,
10551                         __rte_unused void *data)
10552 {
10553         struct rte_eth_ntuple_filter filter;
10554         struct cmd_2tuple_filter_result *res = parsed_result;
10555         int ret = 0;
10556
10557         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10558         if (ret < 0) {
10559                 printf("ntuple filter is not supported on port %u.\n",
10560                         res->port_id);
10561                 return;
10562         }
10563
10564         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10565
10566         filter.flags = RTE_2TUPLE_FLAGS;
10567         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10568         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10569         filter.proto = res->protocol_value;
10570         filter.priority = res->priority_value;
10571         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10572                 printf("nonzero tcp_flags is only meaningful"
10573                         " when protocol is TCP.\n");
10574                 return;
10575         }
10576         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10577                 printf("invalid TCP flags.\n");
10578                 return;
10579         }
10580
10581         if (res->tcp_flags_value != 0) {
10582                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10583                 filter.tcp_flags = res->tcp_flags_value;
10584         }
10585
10586         /* need convert to big endian. */
10587         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10588         filter.queue = res->queue_id;
10589
10590         if (!strcmp(res->ops, "add"))
10591                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10592                                 RTE_ETH_FILTER_NTUPLE,
10593                                 RTE_ETH_FILTER_ADD,
10594                                 &filter);
10595         else
10596                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10597                                 RTE_ETH_FILTER_NTUPLE,
10598                                 RTE_ETH_FILTER_DELETE,
10599                                 &filter);
10600         if (ret < 0)
10601                 printf("2tuple filter programming error: (%s)\n",
10602                         strerror(-ret));
10603
10604 }
10605
10606 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10607         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10608                                  filter, "2tuple_filter");
10609 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10610         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10611                                 port_id, UINT16);
10612 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10613         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10614                                  ops, "add#del");
10615 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10616         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10617                                 dst_port, "dst_port");
10618 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10619         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10620                                 dst_port_value, UINT16);
10621 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10622         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10623                                 protocol, "protocol");
10624 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10625         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10626                                 protocol_value, UINT8);
10627 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10628         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10629                                 mask, "mask");
10630 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10631         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10632                                 mask_value, INT8);
10633 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10634         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10635                                 tcp_flags, "tcp_flags");
10636 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10637         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10638                                 tcp_flags_value, UINT8);
10639 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10640         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10641                                 priority, "priority");
10642 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10643         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10644                                 priority_value, UINT8);
10645 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10646         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10647                                 queue, "queue");
10648 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10649         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10650                                 queue_id, UINT16);
10651
10652 cmdline_parse_inst_t cmd_2tuple_filter = {
10653         .f = cmd_2tuple_filter_parsed,
10654         .data = NULL,
10655         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10656                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10657                 "<queue_id>: Add a 2tuple filter",
10658         .tokens = {
10659                 (void *)&cmd_2tuple_filter_filter,
10660                 (void *)&cmd_2tuple_filter_port_id,
10661                 (void *)&cmd_2tuple_filter_ops,
10662                 (void *)&cmd_2tuple_filter_dst_port,
10663                 (void *)&cmd_2tuple_filter_dst_port_value,
10664                 (void *)&cmd_2tuple_filter_protocol,
10665                 (void *)&cmd_2tuple_filter_protocol_value,
10666                 (void *)&cmd_2tuple_filter_mask,
10667                 (void *)&cmd_2tuple_filter_mask_value,
10668                 (void *)&cmd_2tuple_filter_tcp_flags,
10669                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10670                 (void *)&cmd_2tuple_filter_priority,
10671                 (void *)&cmd_2tuple_filter_priority_value,
10672                 (void *)&cmd_2tuple_filter_queue,
10673                 (void *)&cmd_2tuple_filter_queue_id,
10674                 NULL,
10675         },
10676 };
10677
10678 /* *** ADD/REMOVE A 5tuple FILTER *** */
10679 struct cmd_5tuple_filter_result {
10680         cmdline_fixed_string_t filter;
10681         portid_t port_id;
10682         cmdline_fixed_string_t ops;
10683         cmdline_fixed_string_t dst_ip;
10684         cmdline_ipaddr_t dst_ip_value;
10685         cmdline_fixed_string_t src_ip;
10686         cmdline_ipaddr_t src_ip_value;
10687         cmdline_fixed_string_t dst_port;
10688         uint16_t dst_port_value;
10689         cmdline_fixed_string_t src_port;
10690         uint16_t src_port_value;
10691         cmdline_fixed_string_t protocol;
10692         uint8_t protocol_value;
10693         cmdline_fixed_string_t mask;
10694         uint8_t  mask_value;
10695         cmdline_fixed_string_t tcp_flags;
10696         uint8_t tcp_flags_value;
10697         cmdline_fixed_string_t priority;
10698         uint8_t  priority_value;
10699         cmdline_fixed_string_t queue;
10700         uint16_t  queue_id;
10701 };
10702
10703 static void
10704 cmd_5tuple_filter_parsed(void *parsed_result,
10705                         __rte_unused struct cmdline *cl,
10706                         __rte_unused void *data)
10707 {
10708         struct rte_eth_ntuple_filter filter;
10709         struct cmd_5tuple_filter_result *res = parsed_result;
10710         int ret = 0;
10711
10712         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10713         if (ret < 0) {
10714                 printf("ntuple filter is not supported on port %u.\n",
10715                         res->port_id);
10716                 return;
10717         }
10718
10719         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10720
10721         filter.flags = RTE_5TUPLE_FLAGS;
10722         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10723         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10724         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10725         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10726         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10727         filter.proto = res->protocol_value;
10728         filter.priority = res->priority_value;
10729         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10730                 printf("nonzero tcp_flags is only meaningful"
10731                         " when protocol is TCP.\n");
10732                 return;
10733         }
10734         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10735                 printf("invalid TCP flags.\n");
10736                 return;
10737         }
10738
10739         if (res->tcp_flags_value != 0) {
10740                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10741                 filter.tcp_flags = res->tcp_flags_value;
10742         }
10743
10744         if (res->dst_ip_value.family == AF_INET)
10745                 /* no need to convert, already big endian. */
10746                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10747         else {
10748                 if (filter.dst_ip_mask == 0) {
10749                         printf("can not support ipv6 involved compare.\n");
10750                         return;
10751                 }
10752                 filter.dst_ip = 0;
10753         }
10754
10755         if (res->src_ip_value.family == AF_INET)
10756                 /* no need to convert, already big endian. */
10757                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10758         else {
10759                 if (filter.src_ip_mask == 0) {
10760                         printf("can not support ipv6 involved compare.\n");
10761                         return;
10762                 }
10763                 filter.src_ip = 0;
10764         }
10765         /* need convert to big endian. */
10766         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10767         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10768         filter.queue = res->queue_id;
10769
10770         if (!strcmp(res->ops, "add"))
10771                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10772                                 RTE_ETH_FILTER_NTUPLE,
10773                                 RTE_ETH_FILTER_ADD,
10774                                 &filter);
10775         else
10776                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10777                                 RTE_ETH_FILTER_NTUPLE,
10778                                 RTE_ETH_FILTER_DELETE,
10779                                 &filter);
10780         if (ret < 0)
10781                 printf("5tuple filter programming error: (%s)\n",
10782                         strerror(-ret));
10783 }
10784
10785 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10786         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10787                                  filter, "5tuple_filter");
10788 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10789         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10790                                 port_id, UINT16);
10791 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10792         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10793                                  ops, "add#del");
10794 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10795         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10796                                 dst_ip, "dst_ip");
10797 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10798         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10799                                 dst_ip_value);
10800 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10801         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10802                                 src_ip, "src_ip");
10803 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10804         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10805                                 src_ip_value);
10806 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10807         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10808                                 dst_port, "dst_port");
10809 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10810         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10811                                 dst_port_value, UINT16);
10812 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10813         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10814                                 src_port, "src_port");
10815 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10816         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10817                                 src_port_value, UINT16);
10818 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10819         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10820                                 protocol, "protocol");
10821 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10822         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10823                                 protocol_value, UINT8);
10824 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10825         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10826                                 mask, "mask");
10827 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10828         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10829                                 mask_value, INT8);
10830 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10831         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10832                                 tcp_flags, "tcp_flags");
10833 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10834         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10835                                 tcp_flags_value, UINT8);
10836 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10837         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10838                                 priority, "priority");
10839 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10840         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10841                                 priority_value, UINT8);
10842 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10843         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10844                                 queue, "queue");
10845 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10846         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10847                                 queue_id, UINT16);
10848
10849 cmdline_parse_inst_t cmd_5tuple_filter = {
10850         .f = cmd_5tuple_filter_parsed,
10851         .data = NULL,
10852         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10853                 "src_ip <value> dst_port <value> src_port <value> "
10854                 "protocol <value>  mask <value> tcp_flags <value> "
10855                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10856         .tokens = {
10857                 (void *)&cmd_5tuple_filter_filter,
10858                 (void *)&cmd_5tuple_filter_port_id,
10859                 (void *)&cmd_5tuple_filter_ops,
10860                 (void *)&cmd_5tuple_filter_dst_ip,
10861                 (void *)&cmd_5tuple_filter_dst_ip_value,
10862                 (void *)&cmd_5tuple_filter_src_ip,
10863                 (void *)&cmd_5tuple_filter_src_ip_value,
10864                 (void *)&cmd_5tuple_filter_dst_port,
10865                 (void *)&cmd_5tuple_filter_dst_port_value,
10866                 (void *)&cmd_5tuple_filter_src_port,
10867                 (void *)&cmd_5tuple_filter_src_port_value,
10868                 (void *)&cmd_5tuple_filter_protocol,
10869                 (void *)&cmd_5tuple_filter_protocol_value,
10870                 (void *)&cmd_5tuple_filter_mask,
10871                 (void *)&cmd_5tuple_filter_mask_value,
10872                 (void *)&cmd_5tuple_filter_tcp_flags,
10873                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10874                 (void *)&cmd_5tuple_filter_priority,
10875                 (void *)&cmd_5tuple_filter_priority_value,
10876                 (void *)&cmd_5tuple_filter_queue,
10877                 (void *)&cmd_5tuple_filter_queue_id,
10878                 NULL,
10879         },
10880 };
10881
10882 /* *** ADD/REMOVE A flex FILTER *** */
10883 struct cmd_flex_filter_result {
10884         cmdline_fixed_string_t filter;
10885         cmdline_fixed_string_t ops;
10886         portid_t port_id;
10887         cmdline_fixed_string_t len;
10888         uint8_t len_value;
10889         cmdline_fixed_string_t bytes;
10890         cmdline_fixed_string_t bytes_value;
10891         cmdline_fixed_string_t mask;
10892         cmdline_fixed_string_t mask_value;
10893         cmdline_fixed_string_t priority;
10894         uint8_t priority_value;
10895         cmdline_fixed_string_t queue;
10896         uint16_t queue_id;
10897 };
10898
10899 static int xdigit2val(unsigned char c)
10900 {
10901         int val;
10902         if (isdigit(c))
10903                 val = c - '0';
10904         else if (isupper(c))
10905                 val = c - 'A' + 10;
10906         else
10907                 val = c - 'a' + 10;
10908         return val;
10909 }
10910
10911 static void
10912 cmd_flex_filter_parsed(void *parsed_result,
10913                           __rte_unused struct cmdline *cl,
10914                           __rte_unused void *data)
10915 {
10916         int ret = 0;
10917         struct rte_eth_flex_filter filter;
10918         struct cmd_flex_filter_result *res = parsed_result;
10919         char *bytes_ptr, *mask_ptr;
10920         uint16_t len, i, j = 0;
10921         char c;
10922         int val;
10923         uint8_t byte = 0;
10924
10925         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10926                 printf("the len exceed the max length 128\n");
10927                 return;
10928         }
10929         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10930         filter.len = res->len_value;
10931         filter.priority = res->priority_value;
10932         filter.queue = res->queue_id;
10933         bytes_ptr = res->bytes_value;
10934         mask_ptr = res->mask_value;
10935
10936          /* translate bytes string to array. */
10937         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10938                 (bytes_ptr[1] == 'X')))
10939                 bytes_ptr += 2;
10940         len = strnlen(bytes_ptr, res->len_value * 2);
10941         if (len == 0 || (len % 8 != 0)) {
10942                 printf("please check len and bytes input\n");
10943                 return;
10944         }
10945         for (i = 0; i < len; i++) {
10946                 c = bytes_ptr[i];
10947                 if (isxdigit(c) == 0) {
10948                         /* invalid characters. */
10949                         printf("invalid input\n");
10950                         return;
10951                 }
10952                 val = xdigit2val(c);
10953                 if (i % 2) {
10954                         byte |= val;
10955                         filter.bytes[j] = byte;
10956                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
10957                         j++;
10958                         byte = 0;
10959                 } else
10960                         byte |= val << 4;
10961         }
10962         printf("\n");
10963          /* translate mask string to uint8_t array. */
10964         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
10965                 (mask_ptr[1] == 'X')))
10966                 mask_ptr += 2;
10967         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
10968         if (len == 0) {
10969                 printf("invalid input\n");
10970                 return;
10971         }
10972         j = 0;
10973         byte = 0;
10974         for (i = 0; i < len; i++) {
10975                 c = mask_ptr[i];
10976                 if (isxdigit(c) == 0) {
10977                         /* invalid characters. */
10978                         printf("invalid input\n");
10979                         return;
10980                 }
10981                 val = xdigit2val(c);
10982                 if (i % 2) {
10983                         byte |= val;
10984                         filter.mask[j] = byte;
10985                         printf("mask[%d]:%02x ", j, filter.mask[j]);
10986                         j++;
10987                         byte = 0;
10988                 } else
10989                         byte |= val << 4;
10990         }
10991         printf("\n");
10992
10993         if (!strcmp(res->ops, "add"))
10994                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10995                                 RTE_ETH_FILTER_FLEXIBLE,
10996                                 RTE_ETH_FILTER_ADD,
10997                                 &filter);
10998         else
10999                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11000                                 RTE_ETH_FILTER_FLEXIBLE,
11001                                 RTE_ETH_FILTER_DELETE,
11002                                 &filter);
11003
11004         if (ret < 0)
11005                 printf("flex filter setting error: (%s)\n", strerror(-ret));
11006 }
11007
11008 cmdline_parse_token_string_t cmd_flex_filter_filter =
11009         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11010                                 filter, "flex_filter");
11011 cmdline_parse_token_num_t cmd_flex_filter_port_id =
11012         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11013                                 port_id, UINT16);
11014 cmdline_parse_token_string_t cmd_flex_filter_ops =
11015         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11016                                 ops, "add#del");
11017 cmdline_parse_token_string_t cmd_flex_filter_len =
11018         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11019                                 len, "len");
11020 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11021         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11022                                 len_value, UINT8);
11023 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11024         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11025                                 bytes, "bytes");
11026 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11027         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11028                                 bytes_value, NULL);
11029 cmdline_parse_token_string_t cmd_flex_filter_mask =
11030         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11031                                 mask, "mask");
11032 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11033         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11034                                 mask_value, NULL);
11035 cmdline_parse_token_string_t cmd_flex_filter_priority =
11036         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11037                                 priority, "priority");
11038 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11039         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11040                                 priority_value, UINT8);
11041 cmdline_parse_token_string_t cmd_flex_filter_queue =
11042         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11043                                 queue, "queue");
11044 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11045         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11046                                 queue_id, UINT16);
11047 cmdline_parse_inst_t cmd_flex_filter = {
11048         .f = cmd_flex_filter_parsed,
11049         .data = NULL,
11050         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11051                 "<value> mask <value> priority <value> queue <queue_id>: "
11052                 "Add/Del a flex filter",
11053         .tokens = {
11054                 (void *)&cmd_flex_filter_filter,
11055                 (void *)&cmd_flex_filter_port_id,
11056                 (void *)&cmd_flex_filter_ops,
11057                 (void *)&cmd_flex_filter_len,
11058                 (void *)&cmd_flex_filter_len_value,
11059                 (void *)&cmd_flex_filter_bytes,
11060                 (void *)&cmd_flex_filter_bytes_value,
11061                 (void *)&cmd_flex_filter_mask,
11062                 (void *)&cmd_flex_filter_mask_value,
11063                 (void *)&cmd_flex_filter_priority,
11064                 (void *)&cmd_flex_filter_priority_value,
11065                 (void *)&cmd_flex_filter_queue,
11066                 (void *)&cmd_flex_filter_queue_id,
11067                 NULL,
11068         },
11069 };
11070
11071 /* *** Filters Control *** */
11072
11073 /* *** deal with ethertype filter *** */
11074 struct cmd_ethertype_filter_result {
11075         cmdline_fixed_string_t filter;
11076         portid_t port_id;
11077         cmdline_fixed_string_t ops;
11078         cmdline_fixed_string_t mac;
11079         struct rte_ether_addr mac_addr;
11080         cmdline_fixed_string_t ethertype;
11081         uint16_t ethertype_value;
11082         cmdline_fixed_string_t drop;
11083         cmdline_fixed_string_t queue;
11084         uint16_t  queue_id;
11085 };
11086
11087 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11088         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11089                                  filter, "ethertype_filter");
11090 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11091         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11092                               port_id, UINT16);
11093 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11094         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11095                                  ops, "add#del");
11096 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11097         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11098                                  mac, "mac_addr#mac_ignr");
11099 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11100         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11101                                      mac_addr);
11102 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11103         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11104                                  ethertype, "ethertype");
11105 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11106         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11107                               ethertype_value, UINT16);
11108 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11109         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11110                                  drop, "drop#fwd");
11111 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11112         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11113                                  queue, "queue");
11114 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11115         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11116                               queue_id, UINT16);
11117
11118 static void
11119 cmd_ethertype_filter_parsed(void *parsed_result,
11120                           __rte_unused struct cmdline *cl,
11121                           __rte_unused void *data)
11122 {
11123         struct cmd_ethertype_filter_result *res = parsed_result;
11124         struct rte_eth_ethertype_filter filter;
11125         int ret = 0;
11126
11127         ret = rte_eth_dev_filter_supported(res->port_id,
11128                         RTE_ETH_FILTER_ETHERTYPE);
11129         if (ret < 0) {
11130                 printf("ethertype filter is not supported on port %u.\n",
11131                         res->port_id);
11132                 return;
11133         }
11134
11135         memset(&filter, 0, sizeof(filter));
11136         if (!strcmp(res->mac, "mac_addr")) {
11137                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11138                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11139                         sizeof(struct rte_ether_addr));
11140         }
11141         if (!strcmp(res->drop, "drop"))
11142                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11143         filter.ether_type = res->ethertype_value;
11144         filter.queue = res->queue_id;
11145
11146         if (!strcmp(res->ops, "add"))
11147                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11148                                 RTE_ETH_FILTER_ETHERTYPE,
11149                                 RTE_ETH_FILTER_ADD,
11150                                 &filter);
11151         else
11152                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11153                                 RTE_ETH_FILTER_ETHERTYPE,
11154                                 RTE_ETH_FILTER_DELETE,
11155                                 &filter);
11156         if (ret < 0)
11157                 printf("ethertype filter programming error: (%s)\n",
11158                         strerror(-ret));
11159 }
11160
11161 cmdline_parse_inst_t cmd_ethertype_filter = {
11162         .f = cmd_ethertype_filter_parsed,
11163         .data = NULL,
11164         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11165                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11166                 "Add or delete an ethertype filter entry",
11167         .tokens = {
11168                 (void *)&cmd_ethertype_filter_filter,
11169                 (void *)&cmd_ethertype_filter_port_id,
11170                 (void *)&cmd_ethertype_filter_ops,
11171                 (void *)&cmd_ethertype_filter_mac,
11172                 (void *)&cmd_ethertype_filter_mac_addr,
11173                 (void *)&cmd_ethertype_filter_ethertype,
11174                 (void *)&cmd_ethertype_filter_ethertype_value,
11175                 (void *)&cmd_ethertype_filter_drop,
11176                 (void *)&cmd_ethertype_filter_queue,
11177                 (void *)&cmd_ethertype_filter_queue_id,
11178                 NULL,
11179         },
11180 };
11181
11182 /* *** deal with flow director filter *** */
11183 struct cmd_flow_director_result {
11184         cmdline_fixed_string_t flow_director_filter;
11185         portid_t port_id;
11186         cmdline_fixed_string_t mode;
11187         cmdline_fixed_string_t mode_value;
11188         cmdline_fixed_string_t ops;
11189         cmdline_fixed_string_t flow;
11190         cmdline_fixed_string_t flow_type;
11191         cmdline_fixed_string_t ether;
11192         uint16_t ether_type;
11193         cmdline_fixed_string_t src;
11194         cmdline_ipaddr_t ip_src;
11195         uint16_t port_src;
11196         cmdline_fixed_string_t dst;
11197         cmdline_ipaddr_t ip_dst;
11198         uint16_t port_dst;
11199         cmdline_fixed_string_t verify_tag;
11200         uint32_t verify_tag_value;
11201         cmdline_fixed_string_t tos;
11202         uint8_t tos_value;
11203         cmdline_fixed_string_t proto;
11204         uint8_t proto_value;
11205         cmdline_fixed_string_t ttl;
11206         uint8_t ttl_value;
11207         cmdline_fixed_string_t vlan;
11208         uint16_t vlan_value;
11209         cmdline_fixed_string_t flexbytes;
11210         cmdline_fixed_string_t flexbytes_value;
11211         cmdline_fixed_string_t pf_vf;
11212         cmdline_fixed_string_t drop;
11213         cmdline_fixed_string_t queue;
11214         uint16_t  queue_id;
11215         cmdline_fixed_string_t fd_id;
11216         uint32_t  fd_id_value;
11217         cmdline_fixed_string_t mac;
11218         struct rte_ether_addr mac_addr;
11219         cmdline_fixed_string_t tunnel;
11220         cmdline_fixed_string_t tunnel_type;
11221         cmdline_fixed_string_t tunnel_id;
11222         uint32_t tunnel_id_value;
11223         cmdline_fixed_string_t packet;
11224         char filepath[];
11225 };
11226
11227 static inline int
11228 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11229 {
11230         char s[256];
11231         const char *p, *p0 = q_arg;
11232         char *end;
11233         unsigned long int_fld;
11234         char *str_fld[max_num];
11235         int i;
11236         unsigned size;
11237         int ret = -1;
11238
11239         p = strchr(p0, '(');
11240         if (p == NULL)
11241                 return -1;
11242         ++p;
11243         p0 = strchr(p, ')');
11244         if (p0 == NULL)
11245                 return -1;
11246
11247         size = p0 - p;
11248         if (size >= sizeof(s))
11249                 return -1;
11250
11251         snprintf(s, sizeof(s), "%.*s", size, p);
11252         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11253         if (ret < 0 || ret > max_num)
11254                 return -1;
11255         for (i = 0; i < ret; i++) {
11256                 errno = 0;
11257                 int_fld = strtoul(str_fld[i], &end, 0);
11258                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11259                         return -1;
11260                 flexbytes[i] = (uint8_t)int_fld;
11261         }
11262         return ret;
11263 }
11264
11265 static uint16_t
11266 str2flowtype(char *string)
11267 {
11268         uint8_t i = 0;
11269         static const struct {
11270                 char str[32];
11271                 uint16_t type;
11272         } flowtype_str[] = {
11273                 {"raw", RTE_ETH_FLOW_RAW},
11274                 {"ipv4", RTE_ETH_FLOW_IPV4},
11275                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11276                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11277                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11278                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11279                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11280                 {"ipv6", RTE_ETH_FLOW_IPV6},
11281                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11282                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11283                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11284                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11285                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11286                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11287         };
11288
11289         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11290                 if (!strcmp(flowtype_str[i].str, string))
11291                         return flowtype_str[i].type;
11292         }
11293
11294         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11295                 return (uint16_t)atoi(string);
11296
11297         return RTE_ETH_FLOW_UNKNOWN;
11298 }
11299
11300 static enum rte_eth_fdir_tunnel_type
11301 str2fdir_tunneltype(char *string)
11302 {
11303         uint8_t i = 0;
11304
11305         static const struct {
11306                 char str[32];
11307                 enum rte_eth_fdir_tunnel_type type;
11308         } tunneltype_str[] = {
11309                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11310                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11311         };
11312
11313         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11314                 if (!strcmp(tunneltype_str[i].str, string))
11315                         return tunneltype_str[i].type;
11316         }
11317         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11318 }
11319
11320 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11321 do { \
11322         if ((ip_addr).family == AF_INET) \
11323                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11324         else { \
11325                 printf("invalid parameter.\n"); \
11326                 return; \
11327         } \
11328 } while (0)
11329
11330 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11331 do { \
11332         if ((ip_addr).family == AF_INET6) \
11333                 rte_memcpy(&(ip), \
11334                                  &((ip_addr).addr.ipv6), \
11335                                  sizeof(struct in6_addr)); \
11336         else { \
11337                 printf("invalid parameter.\n"); \
11338                 return; \
11339         } \
11340 } while (0)
11341
11342 static void
11343 cmd_flow_director_filter_parsed(void *parsed_result,
11344                           __rte_unused struct cmdline *cl,
11345                           __rte_unused void *data)
11346 {
11347         struct cmd_flow_director_result *res = parsed_result;
11348         struct rte_eth_fdir_filter entry;
11349         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11350         char *end;
11351         unsigned long vf_id;
11352         int ret = 0;
11353
11354         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11355         if (ret < 0) {
11356                 printf("flow director is not supported on port %u.\n",
11357                         res->port_id);
11358                 return;
11359         }
11360         memset(flexbytes, 0, sizeof(flexbytes));
11361         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11362
11363         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11364                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11365                         printf("Please set mode to MAC-VLAN.\n");
11366                         return;
11367                 }
11368         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11369                 if (strcmp(res->mode_value, "Tunnel")) {
11370                         printf("Please set mode to Tunnel.\n");
11371                         return;
11372                 }
11373         } else {
11374                 if (!strcmp(res->mode_value, "raw")) {
11375 #ifdef RTE_LIBRTE_I40E_PMD
11376                         struct rte_pmd_i40e_flow_type_mapping
11377                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11378                         struct rte_pmd_i40e_pkt_template_conf conf;
11379                         uint16_t flow_type = str2flowtype(res->flow_type);
11380                         uint16_t i, port = res->port_id;
11381                         uint8_t add;
11382
11383                         memset(&conf, 0, sizeof(conf));
11384
11385                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11386                                 printf("Invalid flow type specified.\n");
11387                                 return;
11388                         }
11389                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11390                                                                  mapping);
11391                         if (ret)
11392                                 return;
11393                         if (mapping[flow_type].pctype == 0ULL) {
11394                                 printf("Invalid flow type specified.\n");
11395                                 return;
11396                         }
11397                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11398                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11399                                         conf.input.pctype = i;
11400                                         break;
11401                                 }
11402                         }
11403
11404                         conf.input.packet = open_file(res->filepath,
11405                                                 &conf.input.length);
11406                         if (!conf.input.packet)
11407                                 return;
11408                         if (!strcmp(res->drop, "drop"))
11409                                 conf.action.behavior =
11410                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11411                         else
11412                                 conf.action.behavior =
11413                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11414                         conf.action.report_status =
11415                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11416                         conf.action.rx_queue = res->queue_id;
11417                         conf.soft_id = res->fd_id_value;
11418                         add  = strcmp(res->ops, "del") ? 1 : 0;
11419                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11420                                                                         &conf,
11421                                                                         add);
11422                         if (ret < 0)
11423                                 printf("flow director config error: (%s)\n",
11424                                        strerror(-ret));
11425                         close_file(conf.input.packet);
11426 #endif
11427                         return;
11428                 } else if (strcmp(res->mode_value, "IP")) {
11429                         printf("Please set mode to IP or raw.\n");
11430                         return;
11431                 }
11432                 entry.input.flow_type = str2flowtype(res->flow_type);
11433         }
11434
11435         ret = parse_flexbytes(res->flexbytes_value,
11436                                         flexbytes,
11437                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11438         if (ret < 0) {
11439                 printf("error: Cannot parse flexbytes input.\n");
11440                 return;
11441         }
11442
11443         switch (entry.input.flow_type) {
11444         case RTE_ETH_FLOW_FRAG_IPV4:
11445         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11446                 entry.input.flow.ip4_flow.proto = res->proto_value;
11447                 /* fall-through */
11448         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11449         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11450                 IPV4_ADDR_TO_UINT(res->ip_dst,
11451                         entry.input.flow.ip4_flow.dst_ip);
11452                 IPV4_ADDR_TO_UINT(res->ip_src,
11453                         entry.input.flow.ip4_flow.src_ip);
11454                 entry.input.flow.ip4_flow.tos = res->tos_value;
11455                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11456                 /* need convert to big endian. */
11457                 entry.input.flow.udp4_flow.dst_port =
11458                                 rte_cpu_to_be_16(res->port_dst);
11459                 entry.input.flow.udp4_flow.src_port =
11460                                 rte_cpu_to_be_16(res->port_src);
11461                 break;
11462         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11463                 IPV4_ADDR_TO_UINT(res->ip_dst,
11464                         entry.input.flow.sctp4_flow.ip.dst_ip);
11465                 IPV4_ADDR_TO_UINT(res->ip_src,
11466                         entry.input.flow.sctp4_flow.ip.src_ip);
11467                 entry.input.flow.ip4_flow.tos = res->tos_value;
11468                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11469                 /* need convert to big endian. */
11470                 entry.input.flow.sctp4_flow.dst_port =
11471                                 rte_cpu_to_be_16(res->port_dst);
11472                 entry.input.flow.sctp4_flow.src_port =
11473                                 rte_cpu_to_be_16(res->port_src);
11474                 entry.input.flow.sctp4_flow.verify_tag =
11475                                 rte_cpu_to_be_32(res->verify_tag_value);
11476                 break;
11477         case RTE_ETH_FLOW_FRAG_IPV6:
11478         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11479                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11480                 /* fall-through */
11481         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11482         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11483                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11484                         entry.input.flow.ipv6_flow.dst_ip);
11485                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11486                         entry.input.flow.ipv6_flow.src_ip);
11487                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11488                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11489                 /* need convert to big endian. */
11490                 entry.input.flow.udp6_flow.dst_port =
11491                                 rte_cpu_to_be_16(res->port_dst);
11492                 entry.input.flow.udp6_flow.src_port =
11493                                 rte_cpu_to_be_16(res->port_src);
11494                 break;
11495         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11496                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11497                         entry.input.flow.sctp6_flow.ip.dst_ip);
11498                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11499                         entry.input.flow.sctp6_flow.ip.src_ip);
11500                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11501                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11502                 /* need convert to big endian. */
11503                 entry.input.flow.sctp6_flow.dst_port =
11504                                 rte_cpu_to_be_16(res->port_dst);
11505                 entry.input.flow.sctp6_flow.src_port =
11506                                 rte_cpu_to_be_16(res->port_src);
11507                 entry.input.flow.sctp6_flow.verify_tag =
11508                                 rte_cpu_to_be_32(res->verify_tag_value);
11509                 break;
11510         case RTE_ETH_FLOW_L2_PAYLOAD:
11511                 entry.input.flow.l2_flow.ether_type =
11512                         rte_cpu_to_be_16(res->ether_type);
11513                 break;
11514         default:
11515                 break;
11516         }
11517
11518         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11519                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11520                                  &res->mac_addr,
11521                                  sizeof(struct rte_ether_addr));
11522
11523         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11524                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11525                                  &res->mac_addr,
11526                                  sizeof(struct rte_ether_addr));
11527                 entry.input.flow.tunnel_flow.tunnel_type =
11528                         str2fdir_tunneltype(res->tunnel_type);
11529                 entry.input.flow.tunnel_flow.tunnel_id =
11530                         rte_cpu_to_be_32(res->tunnel_id_value);
11531         }
11532
11533         rte_memcpy(entry.input.flow_ext.flexbytes,
11534                    flexbytes,
11535                    RTE_ETH_FDIR_MAX_FLEXLEN);
11536
11537         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11538
11539         entry.action.flex_off = 0;  /*use 0 by default */
11540         if (!strcmp(res->drop, "drop"))
11541                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11542         else
11543                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11544
11545         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11546             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11547                 if (!strcmp(res->pf_vf, "pf"))
11548                         entry.input.flow_ext.is_vf = 0;
11549                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11550                         struct rte_eth_dev_info dev_info;
11551
11552                         ret = eth_dev_info_get_print_err(res->port_id,
11553                                                 &dev_info);
11554                         if (ret != 0)
11555                                 return;
11556
11557                         errno = 0;
11558                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11559                         if (errno != 0 || *end != '\0' ||
11560                             vf_id >= dev_info.max_vfs) {
11561                                 printf("invalid parameter %s.\n", res->pf_vf);
11562                                 return;
11563                         }
11564                         entry.input.flow_ext.is_vf = 1;
11565                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11566                 } else {
11567                         printf("invalid parameter %s.\n", res->pf_vf);
11568                         return;
11569                 }
11570         }
11571
11572         /* set to report FD ID by default */
11573         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11574         entry.action.rx_queue = res->queue_id;
11575         entry.soft_id = res->fd_id_value;
11576         if (!strcmp(res->ops, "add"))
11577                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11578                                              RTE_ETH_FILTER_ADD, &entry);
11579         else if (!strcmp(res->ops, "del"))
11580                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11581                                              RTE_ETH_FILTER_DELETE, &entry);
11582         else
11583                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11584                                              RTE_ETH_FILTER_UPDATE, &entry);
11585         if (ret < 0)
11586                 printf("flow director programming error: (%s)\n",
11587                         strerror(-ret));
11588 }
11589
11590 cmdline_parse_token_string_t cmd_flow_director_filter =
11591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11592                                  flow_director_filter, "flow_director_filter");
11593 cmdline_parse_token_num_t cmd_flow_director_port_id =
11594         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11595                               port_id, UINT16);
11596 cmdline_parse_token_string_t cmd_flow_director_ops =
11597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11598                                  ops, "add#del#update");
11599 cmdline_parse_token_string_t cmd_flow_director_flow =
11600         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11601                                  flow, "flow");
11602 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11604                 flow_type, NULL);
11605 cmdline_parse_token_string_t cmd_flow_director_ether =
11606         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11607                                  ether, "ether");
11608 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11609         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11610                               ether_type, UINT16);
11611 cmdline_parse_token_string_t cmd_flow_director_src =
11612         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11613                                  src, "src");
11614 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11615         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11616                                  ip_src);
11617 cmdline_parse_token_num_t cmd_flow_director_port_src =
11618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11619                               port_src, UINT16);
11620 cmdline_parse_token_string_t cmd_flow_director_dst =
11621         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11622                                  dst, "dst");
11623 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11624         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11625                                  ip_dst);
11626 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11627         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11628                               port_dst, UINT16);
11629 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11630         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11631                                   verify_tag, "verify_tag");
11632 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11633         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11634                               verify_tag_value, UINT32);
11635 cmdline_parse_token_string_t cmd_flow_director_tos =
11636         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11637                                  tos, "tos");
11638 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11639         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11640                               tos_value, UINT8);
11641 cmdline_parse_token_string_t cmd_flow_director_proto =
11642         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11643                                  proto, "proto");
11644 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11645         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11646                               proto_value, UINT8);
11647 cmdline_parse_token_string_t cmd_flow_director_ttl =
11648         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11649                                  ttl, "ttl");
11650 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11651         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11652                               ttl_value, UINT8);
11653 cmdline_parse_token_string_t cmd_flow_director_vlan =
11654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11655                                  vlan, "vlan");
11656 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11657         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11658                               vlan_value, UINT16);
11659 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11661                                  flexbytes, "flexbytes");
11662 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11663         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11664                               flexbytes_value, NULL);
11665 cmdline_parse_token_string_t cmd_flow_director_drop =
11666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11667                                  drop, "drop#fwd");
11668 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11669         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11670                               pf_vf, NULL);
11671 cmdline_parse_token_string_t cmd_flow_director_queue =
11672         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11673                                  queue, "queue");
11674 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11675         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11676                               queue_id, UINT16);
11677 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11678         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11679                                  fd_id, "fd_id");
11680 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11681         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11682                               fd_id_value, UINT32);
11683
11684 cmdline_parse_token_string_t cmd_flow_director_mode =
11685         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11686                                  mode, "mode");
11687 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11688         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11689                                  mode_value, "IP");
11690 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11691         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11692                                  mode_value, "MAC-VLAN");
11693 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11694         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11695                                  mode_value, "Tunnel");
11696 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11697         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11698                                  mode_value, "raw");
11699 cmdline_parse_token_string_t cmd_flow_director_mac =
11700         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11701                                  mac, "mac");
11702 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11703         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11704                                     mac_addr);
11705 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11706         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11707                                  tunnel, "tunnel");
11708 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11709         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11710                                  tunnel_type, "NVGRE#VxLAN");
11711 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11712         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11713                                  tunnel_id, "tunnel-id");
11714 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11715         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11716                               tunnel_id_value, UINT32);
11717 cmdline_parse_token_string_t cmd_flow_director_packet =
11718         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11719                                  packet, "packet");
11720 cmdline_parse_token_string_t cmd_flow_director_filepath =
11721         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11722                                  filepath, NULL);
11723
11724 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11725         .f = cmd_flow_director_filter_parsed,
11726         .data = NULL,
11727         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11728                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11729                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11730                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11731                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11732                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11733                 "fd_id <fd_id_value>: "
11734                 "Add or delete an ip flow director entry on NIC",
11735         .tokens = {
11736                 (void *)&cmd_flow_director_filter,
11737                 (void *)&cmd_flow_director_port_id,
11738                 (void *)&cmd_flow_director_mode,
11739                 (void *)&cmd_flow_director_mode_ip,
11740                 (void *)&cmd_flow_director_ops,
11741                 (void *)&cmd_flow_director_flow,
11742                 (void *)&cmd_flow_director_flow_type,
11743                 (void *)&cmd_flow_director_src,
11744                 (void *)&cmd_flow_director_ip_src,
11745                 (void *)&cmd_flow_director_dst,
11746                 (void *)&cmd_flow_director_ip_dst,
11747                 (void *)&cmd_flow_director_tos,
11748                 (void *)&cmd_flow_director_tos_value,
11749                 (void *)&cmd_flow_director_proto,
11750                 (void *)&cmd_flow_director_proto_value,
11751                 (void *)&cmd_flow_director_ttl,
11752                 (void *)&cmd_flow_director_ttl_value,
11753                 (void *)&cmd_flow_director_vlan,
11754                 (void *)&cmd_flow_director_vlan_value,
11755                 (void *)&cmd_flow_director_flexbytes,
11756                 (void *)&cmd_flow_director_flexbytes_value,
11757                 (void *)&cmd_flow_director_drop,
11758                 (void *)&cmd_flow_director_pf_vf,
11759                 (void *)&cmd_flow_director_queue,
11760                 (void *)&cmd_flow_director_queue_id,
11761                 (void *)&cmd_flow_director_fd_id,
11762                 (void *)&cmd_flow_director_fd_id_value,
11763                 NULL,
11764         },
11765 };
11766
11767 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11768         .f = cmd_flow_director_filter_parsed,
11769         .data = NULL,
11770         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11771                 "director entry on NIC",
11772         .tokens = {
11773                 (void *)&cmd_flow_director_filter,
11774                 (void *)&cmd_flow_director_port_id,
11775                 (void *)&cmd_flow_director_mode,
11776                 (void *)&cmd_flow_director_mode_ip,
11777                 (void *)&cmd_flow_director_ops,
11778                 (void *)&cmd_flow_director_flow,
11779                 (void *)&cmd_flow_director_flow_type,
11780                 (void *)&cmd_flow_director_src,
11781                 (void *)&cmd_flow_director_ip_src,
11782                 (void *)&cmd_flow_director_port_src,
11783                 (void *)&cmd_flow_director_dst,
11784                 (void *)&cmd_flow_director_ip_dst,
11785                 (void *)&cmd_flow_director_port_dst,
11786                 (void *)&cmd_flow_director_tos,
11787                 (void *)&cmd_flow_director_tos_value,
11788                 (void *)&cmd_flow_director_ttl,
11789                 (void *)&cmd_flow_director_ttl_value,
11790                 (void *)&cmd_flow_director_vlan,
11791                 (void *)&cmd_flow_director_vlan_value,
11792                 (void *)&cmd_flow_director_flexbytes,
11793                 (void *)&cmd_flow_director_flexbytes_value,
11794                 (void *)&cmd_flow_director_drop,
11795                 (void *)&cmd_flow_director_pf_vf,
11796                 (void *)&cmd_flow_director_queue,
11797                 (void *)&cmd_flow_director_queue_id,
11798                 (void *)&cmd_flow_director_fd_id,
11799                 (void *)&cmd_flow_director_fd_id_value,
11800                 NULL,
11801         },
11802 };
11803
11804 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11805         .f = cmd_flow_director_filter_parsed,
11806         .data = NULL,
11807         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11808                 "director entry on NIC",
11809         .tokens = {
11810                 (void *)&cmd_flow_director_filter,
11811                 (void *)&cmd_flow_director_port_id,
11812                 (void *)&cmd_flow_director_mode,
11813                 (void *)&cmd_flow_director_mode_ip,
11814                 (void *)&cmd_flow_director_ops,
11815                 (void *)&cmd_flow_director_flow,
11816                 (void *)&cmd_flow_director_flow_type,
11817                 (void *)&cmd_flow_director_src,
11818                 (void *)&cmd_flow_director_ip_src,
11819                 (void *)&cmd_flow_director_port_src,
11820                 (void *)&cmd_flow_director_dst,
11821                 (void *)&cmd_flow_director_ip_dst,
11822                 (void *)&cmd_flow_director_port_dst,
11823                 (void *)&cmd_flow_director_verify_tag,
11824                 (void *)&cmd_flow_director_verify_tag_value,
11825                 (void *)&cmd_flow_director_tos,
11826                 (void *)&cmd_flow_director_tos_value,
11827                 (void *)&cmd_flow_director_ttl,
11828                 (void *)&cmd_flow_director_ttl_value,
11829                 (void *)&cmd_flow_director_vlan,
11830                 (void *)&cmd_flow_director_vlan_value,
11831                 (void *)&cmd_flow_director_flexbytes,
11832                 (void *)&cmd_flow_director_flexbytes_value,
11833                 (void *)&cmd_flow_director_drop,
11834                 (void *)&cmd_flow_director_pf_vf,
11835                 (void *)&cmd_flow_director_queue,
11836                 (void *)&cmd_flow_director_queue_id,
11837                 (void *)&cmd_flow_director_fd_id,
11838                 (void *)&cmd_flow_director_fd_id_value,
11839                 NULL,
11840         },
11841 };
11842
11843 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11844         .f = cmd_flow_director_filter_parsed,
11845         .data = NULL,
11846         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11847                 "director entry on NIC",
11848         .tokens = {
11849                 (void *)&cmd_flow_director_filter,
11850                 (void *)&cmd_flow_director_port_id,
11851                 (void *)&cmd_flow_director_mode,
11852                 (void *)&cmd_flow_director_mode_ip,
11853                 (void *)&cmd_flow_director_ops,
11854                 (void *)&cmd_flow_director_flow,
11855                 (void *)&cmd_flow_director_flow_type,
11856                 (void *)&cmd_flow_director_ether,
11857                 (void *)&cmd_flow_director_ether_type,
11858                 (void *)&cmd_flow_director_flexbytes,
11859                 (void *)&cmd_flow_director_flexbytes_value,
11860                 (void *)&cmd_flow_director_drop,
11861                 (void *)&cmd_flow_director_pf_vf,
11862                 (void *)&cmd_flow_director_queue,
11863                 (void *)&cmd_flow_director_queue_id,
11864                 (void *)&cmd_flow_director_fd_id,
11865                 (void *)&cmd_flow_director_fd_id_value,
11866                 NULL,
11867         },
11868 };
11869
11870 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11871         .f = cmd_flow_director_filter_parsed,
11872         .data = NULL,
11873         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11874                 "director entry on NIC",
11875         .tokens = {
11876                 (void *)&cmd_flow_director_filter,
11877                 (void *)&cmd_flow_director_port_id,
11878                 (void *)&cmd_flow_director_mode,
11879                 (void *)&cmd_flow_director_mode_mac_vlan,
11880                 (void *)&cmd_flow_director_ops,
11881                 (void *)&cmd_flow_director_mac,
11882                 (void *)&cmd_flow_director_mac_addr,
11883                 (void *)&cmd_flow_director_vlan,
11884                 (void *)&cmd_flow_director_vlan_value,
11885                 (void *)&cmd_flow_director_flexbytes,
11886                 (void *)&cmd_flow_director_flexbytes_value,
11887                 (void *)&cmd_flow_director_drop,
11888                 (void *)&cmd_flow_director_queue,
11889                 (void *)&cmd_flow_director_queue_id,
11890                 (void *)&cmd_flow_director_fd_id,
11891                 (void *)&cmd_flow_director_fd_id_value,
11892                 NULL,
11893         },
11894 };
11895
11896 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11897         .f = cmd_flow_director_filter_parsed,
11898         .data = NULL,
11899         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11900                 "director entry on NIC",
11901         .tokens = {
11902                 (void *)&cmd_flow_director_filter,
11903                 (void *)&cmd_flow_director_port_id,
11904                 (void *)&cmd_flow_director_mode,
11905                 (void *)&cmd_flow_director_mode_tunnel,
11906                 (void *)&cmd_flow_director_ops,
11907                 (void *)&cmd_flow_director_mac,
11908                 (void *)&cmd_flow_director_mac_addr,
11909                 (void *)&cmd_flow_director_vlan,
11910                 (void *)&cmd_flow_director_vlan_value,
11911                 (void *)&cmd_flow_director_tunnel,
11912                 (void *)&cmd_flow_director_tunnel_type,
11913                 (void *)&cmd_flow_director_tunnel_id,
11914                 (void *)&cmd_flow_director_tunnel_id_value,
11915                 (void *)&cmd_flow_director_flexbytes,
11916                 (void *)&cmd_flow_director_flexbytes_value,
11917                 (void *)&cmd_flow_director_drop,
11918                 (void *)&cmd_flow_director_queue,
11919                 (void *)&cmd_flow_director_queue_id,
11920                 (void *)&cmd_flow_director_fd_id,
11921                 (void *)&cmd_flow_director_fd_id_value,
11922                 NULL,
11923         },
11924 };
11925
11926 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11927         .f = cmd_flow_director_filter_parsed,
11928         .data = NULL,
11929         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11930                 "director entry on NIC",
11931         .tokens = {
11932                 (void *)&cmd_flow_director_filter,
11933                 (void *)&cmd_flow_director_port_id,
11934                 (void *)&cmd_flow_director_mode,
11935                 (void *)&cmd_flow_director_mode_raw,
11936                 (void *)&cmd_flow_director_ops,
11937                 (void *)&cmd_flow_director_flow,
11938                 (void *)&cmd_flow_director_flow_type,
11939                 (void *)&cmd_flow_director_drop,
11940                 (void *)&cmd_flow_director_queue,
11941                 (void *)&cmd_flow_director_queue_id,
11942                 (void *)&cmd_flow_director_fd_id,
11943                 (void *)&cmd_flow_director_fd_id_value,
11944                 (void *)&cmd_flow_director_packet,
11945                 (void *)&cmd_flow_director_filepath,
11946                 NULL,
11947         },
11948 };
11949
11950 struct cmd_flush_flow_director_result {
11951         cmdline_fixed_string_t flush_flow_director;
11952         portid_t port_id;
11953 };
11954
11955 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
11956         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
11957                                  flush_flow_director, "flush_flow_director");
11958 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11959         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11960                               port_id, UINT16);
11961
11962 static void
11963 cmd_flush_flow_director_parsed(void *parsed_result,
11964                           __rte_unused struct cmdline *cl,
11965                           __rte_unused void *data)
11966 {
11967         struct cmd_flow_director_result *res = parsed_result;
11968         int ret = 0;
11969
11970         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11971         if (ret < 0) {
11972                 printf("flow director is not supported on port %u.\n",
11973                         res->port_id);
11974                 return;
11975         }
11976
11977         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11978                         RTE_ETH_FILTER_FLUSH, NULL);
11979         if (ret < 0)
11980                 printf("flow director table flushing error: (%s)\n",
11981                         strerror(-ret));
11982 }
11983
11984 cmdline_parse_inst_t cmd_flush_flow_director = {
11985         .f = cmd_flush_flow_director_parsed,
11986         .data = NULL,
11987         .help_str = "flush_flow_director <port_id>: "
11988                 "Flush all flow director entries of a device on NIC",
11989         .tokens = {
11990                 (void *)&cmd_flush_flow_director_flush,
11991                 (void *)&cmd_flush_flow_director_port_id,
11992                 NULL,
11993         },
11994 };
11995
11996 /* *** deal with flow director mask *** */
11997 struct cmd_flow_director_mask_result {
11998         cmdline_fixed_string_t flow_director_mask;
11999         portid_t port_id;
12000         cmdline_fixed_string_t mode;
12001         cmdline_fixed_string_t mode_value;
12002         cmdline_fixed_string_t vlan;
12003         uint16_t vlan_mask;
12004         cmdline_fixed_string_t src_mask;
12005         cmdline_ipaddr_t ipv4_src;
12006         cmdline_ipaddr_t ipv6_src;
12007         uint16_t port_src;
12008         cmdline_fixed_string_t dst_mask;
12009         cmdline_ipaddr_t ipv4_dst;
12010         cmdline_ipaddr_t ipv6_dst;
12011         uint16_t port_dst;
12012         cmdline_fixed_string_t mac;
12013         uint8_t mac_addr_byte_mask;
12014         cmdline_fixed_string_t tunnel_id;
12015         uint32_t tunnel_id_mask;
12016         cmdline_fixed_string_t tunnel_type;
12017         uint8_t tunnel_type_mask;
12018 };
12019
12020 static void
12021 cmd_flow_director_mask_parsed(void *parsed_result,
12022                           __rte_unused struct cmdline *cl,
12023                           __rte_unused void *data)
12024 {
12025         struct cmd_flow_director_mask_result *res = parsed_result;
12026         struct rte_eth_fdir_masks *mask;
12027         struct rte_port *port;
12028
12029         port = &ports[res->port_id];
12030         /** Check if the port is not started **/
12031         if (port->port_status != RTE_PORT_STOPPED) {
12032                 printf("Please stop port %d first\n", res->port_id);
12033                 return;
12034         }
12035
12036         mask = &port->dev_conf.fdir_conf.mask;
12037
12038         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12039                 if (strcmp(res->mode_value, "MAC-VLAN")) {
12040                         printf("Please set mode to MAC-VLAN.\n");
12041                         return;
12042                 }
12043
12044                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12045         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12046                 if (strcmp(res->mode_value, "Tunnel")) {
12047                         printf("Please set mode to Tunnel.\n");
12048                         return;
12049                 }
12050
12051                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12052                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12053                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12054                 mask->tunnel_type_mask = res->tunnel_type_mask;
12055         } else {
12056                 if (strcmp(res->mode_value, "IP")) {
12057                         printf("Please set mode to IP.\n");
12058                         return;
12059                 }
12060
12061                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12062                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12063                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12064                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12065                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12066                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12067                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12068         }
12069
12070         cmd_reconfig_device_queue(res->port_id, 1, 1);
12071 }
12072
12073 cmdline_parse_token_string_t cmd_flow_director_mask =
12074         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12075                                  flow_director_mask, "flow_director_mask");
12076 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12077         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12078                               port_id, UINT16);
12079 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12080         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12081                                  vlan, "vlan");
12082 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12083         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12084                               vlan_mask, UINT16);
12085 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12086         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12087                                  src_mask, "src_mask");
12088 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12089         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12090                                  ipv4_src);
12091 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12092         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12093                                  ipv6_src);
12094 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12095         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12096                               port_src, UINT16);
12097 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12098         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12099                                  dst_mask, "dst_mask");
12100 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12101         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12102                                  ipv4_dst);
12103 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12104         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12105                                  ipv6_dst);
12106 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12107         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12108                               port_dst, UINT16);
12109
12110 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12111         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12112                                  mode, "mode");
12113 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12114         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12115                                  mode_value, "IP");
12116 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12117         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12118                                  mode_value, "MAC-VLAN");
12119 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12121                                  mode_value, "Tunnel");
12122 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12123         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12124                                  mac, "mac");
12125 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12127                               mac_addr_byte_mask, UINT8);
12128 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12130                                  tunnel_type, "tunnel-type");
12131 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12132         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12133                               tunnel_type_mask, UINT8);
12134 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12135         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12136                                  tunnel_id, "tunnel-id");
12137 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12138         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12139                               tunnel_id_mask, UINT32);
12140
12141 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12142         .f = cmd_flow_director_mask_parsed,
12143         .data = NULL,
12144         .help_str = "flow_director_mask ... : "
12145                 "Set IP mode flow director's mask on NIC",
12146         .tokens = {
12147                 (void *)&cmd_flow_director_mask,
12148                 (void *)&cmd_flow_director_mask_port_id,
12149                 (void *)&cmd_flow_director_mask_mode,
12150                 (void *)&cmd_flow_director_mask_mode_ip,
12151                 (void *)&cmd_flow_director_mask_vlan,
12152                 (void *)&cmd_flow_director_mask_vlan_value,
12153                 (void *)&cmd_flow_director_mask_src,
12154                 (void *)&cmd_flow_director_mask_ipv4_src,
12155                 (void *)&cmd_flow_director_mask_ipv6_src,
12156                 (void *)&cmd_flow_director_mask_port_src,
12157                 (void *)&cmd_flow_director_mask_dst,
12158                 (void *)&cmd_flow_director_mask_ipv4_dst,
12159                 (void *)&cmd_flow_director_mask_ipv6_dst,
12160                 (void *)&cmd_flow_director_mask_port_dst,
12161                 NULL,
12162         },
12163 };
12164
12165 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12166         .f = cmd_flow_director_mask_parsed,
12167         .data = NULL,
12168         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12169                 "flow director's mask on NIC",
12170         .tokens = {
12171                 (void *)&cmd_flow_director_mask,
12172                 (void *)&cmd_flow_director_mask_port_id,
12173                 (void *)&cmd_flow_director_mask_mode,
12174                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12175                 (void *)&cmd_flow_director_mask_vlan,
12176                 (void *)&cmd_flow_director_mask_vlan_value,
12177                 NULL,
12178         },
12179 };
12180
12181 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12182         .f = cmd_flow_director_mask_parsed,
12183         .data = NULL,
12184         .help_str = "flow_director_mask ... : Set tunnel mode "
12185                 "flow director's mask on NIC",
12186         .tokens = {
12187                 (void *)&cmd_flow_director_mask,
12188                 (void *)&cmd_flow_director_mask_port_id,
12189                 (void *)&cmd_flow_director_mask_mode,
12190                 (void *)&cmd_flow_director_mask_mode_tunnel,
12191                 (void *)&cmd_flow_director_mask_vlan,
12192                 (void *)&cmd_flow_director_mask_vlan_value,
12193                 (void *)&cmd_flow_director_mask_mac,
12194                 (void *)&cmd_flow_director_mask_mac_value,
12195                 (void *)&cmd_flow_director_mask_tunnel_type,
12196                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12197                 (void *)&cmd_flow_director_mask_tunnel_id,
12198                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12199                 NULL,
12200         },
12201 };
12202
12203 /* *** deal with flow director mask on flexible payload *** */
12204 struct cmd_flow_director_flex_mask_result {
12205         cmdline_fixed_string_t flow_director_flexmask;
12206         portid_t port_id;
12207         cmdline_fixed_string_t flow;
12208         cmdline_fixed_string_t flow_type;
12209         cmdline_fixed_string_t mask;
12210 };
12211
12212 static void
12213 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12214                           __rte_unused struct cmdline *cl,
12215                           __rte_unused void *data)
12216 {
12217         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12218         struct rte_eth_fdir_info fdir_info;
12219         struct rte_eth_fdir_flex_mask flex_mask;
12220         struct rte_port *port;
12221         uint64_t flow_type_mask;
12222         uint16_t i;
12223         int ret;
12224
12225         port = &ports[res->port_id];
12226         /** Check if the port is not started **/
12227         if (port->port_status != RTE_PORT_STOPPED) {
12228                 printf("Please stop port %d first\n", res->port_id);
12229                 return;
12230         }
12231
12232         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12233         ret = parse_flexbytes(res->mask,
12234                         flex_mask.mask,
12235                         RTE_ETH_FDIR_MAX_FLEXLEN);
12236         if (ret < 0) {
12237                 printf("error: Cannot parse mask input.\n");
12238                 return;
12239         }
12240
12241         memset(&fdir_info, 0, sizeof(fdir_info));
12242         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12243                                 RTE_ETH_FILTER_INFO, &fdir_info);
12244         if (ret < 0) {
12245                 printf("Cannot get FDir filter info\n");
12246                 return;
12247         }
12248
12249         if (!strcmp(res->flow_type, "none")) {
12250                 /* means don't specify the flow type */
12251                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12252                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12253                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12254                                0, sizeof(struct rte_eth_fdir_flex_mask));
12255                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12256                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12257                                  &flex_mask,
12258                                  sizeof(struct rte_eth_fdir_flex_mask));
12259                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12260                 return;
12261         }
12262         flow_type_mask = fdir_info.flow_types_mask[0];
12263         if (!strcmp(res->flow_type, "all")) {
12264                 if (!flow_type_mask) {
12265                         printf("No flow type supported\n");
12266                         return;
12267                 }
12268                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12269                         if (flow_type_mask & (1ULL << i)) {
12270                                 flex_mask.flow_type = i;
12271                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12272                         }
12273                 }
12274                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12275                 return;
12276         }
12277         flex_mask.flow_type = str2flowtype(res->flow_type);
12278         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12279                 printf("Flow type %s not supported on port %d\n",
12280                                 res->flow_type, res->port_id);
12281                 return;
12282         }
12283         fdir_set_flex_mask(res->port_id, &flex_mask);
12284         cmd_reconfig_device_queue(res->port_id, 1, 1);
12285 }
12286
12287 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12288         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12289                                  flow_director_flexmask,
12290                                  "flow_director_flex_mask");
12291 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12292         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12293                               port_id, UINT16);
12294 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12295         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12296                                  flow, "flow");
12297 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12298         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12299                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12300                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12301 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12302         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12303                                  mask, NULL);
12304
12305 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12306         .f = cmd_flow_director_flex_mask_parsed,
12307         .data = NULL,
12308         .help_str = "flow_director_flex_mask ... : "
12309                 "Set flow director's flex mask on NIC",
12310         .tokens = {
12311                 (void *)&cmd_flow_director_flexmask,
12312                 (void *)&cmd_flow_director_flexmask_port_id,
12313                 (void *)&cmd_flow_director_flexmask_flow,
12314                 (void *)&cmd_flow_director_flexmask_flow_type,
12315                 (void *)&cmd_flow_director_flexmask_mask,
12316                 NULL,
12317         },
12318 };
12319
12320 /* *** deal with flow director flexible payload configuration *** */
12321 struct cmd_flow_director_flexpayload_result {
12322         cmdline_fixed_string_t flow_director_flexpayload;
12323         portid_t port_id;
12324         cmdline_fixed_string_t payload_layer;
12325         cmdline_fixed_string_t payload_cfg;
12326 };
12327
12328 static inline int
12329 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12330 {
12331         char s[256];
12332         const char *p, *p0 = q_arg;
12333         char *end;
12334         unsigned long int_fld;
12335         char *str_fld[max_num];
12336         int i;
12337         unsigned size;
12338         int ret = -1;
12339
12340         p = strchr(p0, '(');
12341         if (p == NULL)
12342                 return -1;
12343         ++p;
12344         p0 = strchr(p, ')');
12345         if (p0 == NULL)
12346                 return -1;
12347
12348         size = p0 - p;
12349         if (size >= sizeof(s))
12350                 return -1;
12351
12352         snprintf(s, sizeof(s), "%.*s", size, p);
12353         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12354         if (ret < 0 || ret > max_num)
12355                 return -1;
12356         for (i = 0; i < ret; i++) {
12357                 errno = 0;
12358                 int_fld = strtoul(str_fld[i], &end, 0);
12359                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12360                         return -1;
12361                 offsets[i] = (uint16_t)int_fld;
12362         }
12363         return ret;
12364 }
12365
12366 static void
12367 cmd_flow_director_flxpld_parsed(void *parsed_result,
12368                           __rte_unused struct cmdline *cl,
12369                           __rte_unused void *data)
12370 {
12371         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12372         struct rte_eth_flex_payload_cfg flex_cfg;
12373         struct rte_port *port;
12374         int ret = 0;
12375
12376         port = &ports[res->port_id];
12377         /** Check if the port is not started **/
12378         if (port->port_status != RTE_PORT_STOPPED) {
12379                 printf("Please stop port %d first\n", res->port_id);
12380                 return;
12381         }
12382
12383         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12384
12385         if (!strcmp(res->payload_layer, "raw"))
12386                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12387         else if (!strcmp(res->payload_layer, "l2"))
12388                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12389         else if (!strcmp(res->payload_layer, "l3"))
12390                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12391         else if (!strcmp(res->payload_layer, "l4"))
12392                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12393
12394         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12395                             RTE_ETH_FDIR_MAX_FLEXLEN);
12396         if (ret < 0) {
12397                 printf("error: Cannot parse flex payload input.\n");
12398                 return;
12399         }
12400
12401         fdir_set_flex_payload(res->port_id, &flex_cfg);
12402         cmd_reconfig_device_queue(res->port_id, 1, 1);
12403 }
12404
12405 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12407                                  flow_director_flexpayload,
12408                                  "flow_director_flex_payload");
12409 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12410         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12411                               port_id, UINT16);
12412 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12413         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12414                                  payload_layer, "raw#l2#l3#l4");
12415 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12416         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12417                                  payload_cfg, NULL);
12418
12419 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12420         .f = cmd_flow_director_flxpld_parsed,
12421         .data = NULL,
12422         .help_str = "flow_director_flexpayload ... : "
12423                 "Set flow director's flex payload on NIC",
12424         .tokens = {
12425                 (void *)&cmd_flow_director_flexpayload,
12426                 (void *)&cmd_flow_director_flexpayload_port_id,
12427                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12428                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12429                 NULL,
12430         },
12431 };
12432
12433 /* Generic flow interface command. */
12434 extern cmdline_parse_inst_t cmd_flow;
12435
12436 /* *** Classification Filters Control *** */
12437 /* *** Get symmetric hash enable per port *** */
12438 struct cmd_get_sym_hash_ena_per_port_result {
12439         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12440         portid_t port_id;
12441 };
12442
12443 static void
12444 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12445                                  __rte_unused struct cmdline *cl,
12446                                  __rte_unused void *data)
12447 {
12448         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12449         struct rte_eth_hash_filter_info info;
12450         int ret;
12451
12452         if (rte_eth_dev_filter_supported(res->port_id,
12453                                 RTE_ETH_FILTER_HASH) < 0) {
12454                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12455                                                         res->port_id);
12456                 return;
12457         }
12458
12459         memset(&info, 0, sizeof(info));
12460         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12461         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12462                                                 RTE_ETH_FILTER_GET, &info);
12463
12464         if (ret < 0) {
12465                 printf("Cannot get symmetric hash enable per port "
12466                                         "on port %u\n", res->port_id);
12467                 return;
12468         }
12469
12470         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12471                                 "enabled" : "disabled", res->port_id);
12472 }
12473
12474 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12475         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12476                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12477 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12478         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12479                 port_id, UINT16);
12480
12481 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12482         .f = cmd_get_sym_hash_per_port_parsed,
12483         .data = NULL,
12484         .help_str = "get_sym_hash_ena_per_port <port_id>",
12485         .tokens = {
12486                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12487                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12488                 NULL,
12489         },
12490 };
12491
12492 /* *** Set symmetric hash enable per port *** */
12493 struct cmd_set_sym_hash_ena_per_port_result {
12494         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12495         cmdline_fixed_string_t enable;
12496         portid_t port_id;
12497 };
12498
12499 static void
12500 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12501                                  __rte_unused struct cmdline *cl,
12502                                  __rte_unused void *data)
12503 {
12504         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12505         struct rte_eth_hash_filter_info info;
12506         int ret;
12507
12508         if (rte_eth_dev_filter_supported(res->port_id,
12509                                 RTE_ETH_FILTER_HASH) < 0) {
12510                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12511                                                         res->port_id);
12512                 return;
12513         }
12514
12515         memset(&info, 0, sizeof(info));
12516         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12517         if (!strcmp(res->enable, "enable"))
12518                 info.info.enable = 1;
12519         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12520                                         RTE_ETH_FILTER_SET, &info);
12521         if (ret < 0) {
12522                 printf("Cannot set symmetric hash enable per port on "
12523                                         "port %u\n", res->port_id);
12524                 return;
12525         }
12526         printf("Symmetric hash has been set to %s on port %u\n",
12527                                         res->enable, res->port_id);
12528 }
12529
12530 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12531         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12532                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12533 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12534         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12535                 port_id, UINT16);
12536 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12537         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12538                 enable, "enable#disable");
12539
12540 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12541         .f = cmd_set_sym_hash_per_port_parsed,
12542         .data = NULL,
12543         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12544         .tokens = {
12545                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12546                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12547                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12548                 NULL,
12549         },
12550 };
12551
12552 /* Get global config of hash function */
12553 struct cmd_get_hash_global_config_result {
12554         cmdline_fixed_string_t get_hash_global_config;
12555         portid_t port_id;
12556 };
12557
12558 static char *
12559 flowtype_to_str(uint16_t ftype)
12560 {
12561         uint16_t i;
12562         static struct {
12563                 char str[16];
12564                 uint16_t ftype;
12565         } ftype_table[] = {
12566                 {"ipv4", RTE_ETH_FLOW_IPV4},
12567                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12568                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12569                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12570                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12571                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12572                 {"ipv6", RTE_ETH_FLOW_IPV6},
12573                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12574                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12575                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12576                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12577                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12578                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12579                 {"port", RTE_ETH_FLOW_PORT},
12580                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12581                 {"geneve", RTE_ETH_FLOW_GENEVE},
12582                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12583                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12584         };
12585
12586         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12587                 if (ftype_table[i].ftype == ftype)
12588                         return ftype_table[i].str;
12589         }
12590
12591         return NULL;
12592 }
12593
12594 static void
12595 cmd_get_hash_global_config_parsed(void *parsed_result,
12596                                   __rte_unused struct cmdline *cl,
12597                                   __rte_unused void *data)
12598 {
12599         struct cmd_get_hash_global_config_result *res = parsed_result;
12600         struct rte_eth_hash_filter_info info;
12601         uint32_t idx, offset;
12602         uint16_t i;
12603         char *str;
12604         int ret;
12605
12606         if (rte_eth_dev_filter_supported(res->port_id,
12607                         RTE_ETH_FILTER_HASH) < 0) {
12608                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12609                                                         res->port_id);
12610                 return;
12611         }
12612
12613         memset(&info, 0, sizeof(info));
12614         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12615         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12616                                         RTE_ETH_FILTER_GET, &info);
12617         if (ret < 0) {
12618                 printf("Cannot get hash global configurations by port %d\n",
12619                                                         res->port_id);
12620                 return;
12621         }
12622
12623         switch (info.info.global_conf.hash_func) {
12624         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12625                 printf("Hash function is Toeplitz\n");
12626                 break;
12627         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12628                 printf("Hash function is Simple XOR\n");
12629                 break;
12630         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12631                 printf("Hash function is Symmetric Toeplitz\n");
12632                 break;
12633         default:
12634                 printf("Unknown hash function\n");
12635                 break;
12636         }
12637
12638         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12639                 idx = i / UINT64_BIT;
12640                 offset = i % UINT64_BIT;
12641                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12642                                                 (1ULL << offset)))
12643                         continue;
12644                 str = flowtype_to_str(i);
12645                 if (!str)
12646                         continue;
12647                 printf("Symmetric hash is %s globally for flow type %s "
12648                                                         "by port %d\n",
12649                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12650                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12651                                                         res->port_id);
12652         }
12653 }
12654
12655 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12656         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12657                 get_hash_global_config, "get_hash_global_config");
12658 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12659         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12660                 port_id, UINT16);
12661
12662 cmdline_parse_inst_t cmd_get_hash_global_config = {
12663         .f = cmd_get_hash_global_config_parsed,
12664         .data = NULL,
12665         .help_str = "get_hash_global_config <port_id>",
12666         .tokens = {
12667                 (void *)&cmd_get_hash_global_config_all,
12668                 (void *)&cmd_get_hash_global_config_port_id,
12669                 NULL,
12670         },
12671 };
12672
12673 /* Set global config of hash function */
12674 struct cmd_set_hash_global_config_result {
12675         cmdline_fixed_string_t set_hash_global_config;
12676         portid_t port_id;
12677         cmdline_fixed_string_t hash_func;
12678         cmdline_fixed_string_t flow_type;
12679         cmdline_fixed_string_t enable;
12680 };
12681
12682 static void
12683 cmd_set_hash_global_config_parsed(void *parsed_result,
12684                                   __rte_unused struct cmdline *cl,
12685                                   __rte_unused void *data)
12686 {
12687         struct cmd_set_hash_global_config_result *res = parsed_result;
12688         struct rte_eth_hash_filter_info info;
12689         uint32_t ftype, idx, offset;
12690         int ret;
12691
12692         if (rte_eth_dev_filter_supported(res->port_id,
12693                                 RTE_ETH_FILTER_HASH) < 0) {
12694                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12695                                                         res->port_id);
12696                 return;
12697         }
12698         memset(&info, 0, sizeof(info));
12699         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12700         if (!strcmp(res->hash_func, "toeplitz"))
12701                 info.info.global_conf.hash_func =
12702                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12703         else if (!strcmp(res->hash_func, "simple_xor"))
12704                 info.info.global_conf.hash_func =
12705                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12706         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12707                 info.info.global_conf.hash_func =
12708                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12709         else if (!strcmp(res->hash_func, "default"))
12710                 info.info.global_conf.hash_func =
12711                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12712
12713         ftype = str2flowtype(res->flow_type);
12714         idx = ftype / UINT64_BIT;
12715         offset = ftype % UINT64_BIT;
12716         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12717         if (!strcmp(res->enable, "enable"))
12718                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12719                                                 (1ULL << offset);
12720         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12721                                         RTE_ETH_FILTER_SET, &info);
12722         if (ret < 0)
12723                 printf("Cannot set global hash configurations by port %d\n",
12724                                                         res->port_id);
12725         else
12726                 printf("Global hash configurations have been set "
12727                         "successfully by port %d\n", res->port_id);
12728 }
12729
12730 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12731         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12732                 set_hash_global_config, "set_hash_global_config");
12733 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12734         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12735                 port_id, UINT16);
12736 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12737         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12738                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12739 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12740         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12741                 flow_type,
12742                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12743                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12744 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12745         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12746                 enable, "enable#disable");
12747
12748 cmdline_parse_inst_t cmd_set_hash_global_config = {
12749         .f = cmd_set_hash_global_config_parsed,
12750         .data = NULL,
12751         .help_str = "set_hash_global_config <port_id> "
12752                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12753                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12754                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12755                 "l2_payload enable|disable",
12756         .tokens = {
12757                 (void *)&cmd_set_hash_global_config_all,
12758                 (void *)&cmd_set_hash_global_config_port_id,
12759                 (void *)&cmd_set_hash_global_config_hash_func,
12760                 (void *)&cmd_set_hash_global_config_flow_type,
12761                 (void *)&cmd_set_hash_global_config_enable,
12762                 NULL,
12763         },
12764 };
12765
12766 /* Set hash input set */
12767 struct cmd_set_hash_input_set_result {
12768         cmdline_fixed_string_t set_hash_input_set;
12769         portid_t port_id;
12770         cmdline_fixed_string_t flow_type;
12771         cmdline_fixed_string_t inset_field;
12772         cmdline_fixed_string_t select;
12773 };
12774
12775 static enum rte_eth_input_set_field
12776 str2inset(char *string)
12777 {
12778         uint16_t i;
12779
12780         static const struct {
12781                 char str[32];
12782                 enum rte_eth_input_set_field inset;
12783         } inset_table[] = {
12784                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12785                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12786                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12787                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12788                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12789                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12790                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12791                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12792                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12793                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12794                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12795                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12796                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12797                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12798                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12799                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12800                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12801                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12802                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12803                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12804                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12805                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12806                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12807                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12808                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12809                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12810                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12811                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12812                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12813                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12814                 {"none", RTE_ETH_INPUT_SET_NONE},
12815         };
12816
12817         for (i = 0; i < RTE_DIM(inset_table); i++) {
12818                 if (!strcmp(string, inset_table[i].str))
12819                         return inset_table[i].inset;
12820         }
12821
12822         return RTE_ETH_INPUT_SET_UNKNOWN;
12823 }
12824
12825 static void
12826 cmd_set_hash_input_set_parsed(void *parsed_result,
12827                               __rte_unused struct cmdline *cl,
12828                               __rte_unused void *data)
12829 {
12830         struct cmd_set_hash_input_set_result *res = parsed_result;
12831         struct rte_eth_hash_filter_info info;
12832
12833         memset(&info, 0, sizeof(info));
12834         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12835         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12836         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12837         info.info.input_set_conf.inset_size = 1;
12838         if (!strcmp(res->select, "select"))
12839                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12840         else if (!strcmp(res->select, "add"))
12841                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12842         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12843                                 RTE_ETH_FILTER_SET, &info);
12844 }
12845
12846 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12847         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12848                 set_hash_input_set, "set_hash_input_set");
12849 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12850         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12851                 port_id, UINT16);
12852 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12853         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12854                 flow_type, NULL);
12855 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12856         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12857                 inset_field,
12858                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12859                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12860                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12861                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12862                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12863                 "fld-8th#none");
12864 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12865         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12866                 select, "select#add");
12867
12868 cmdline_parse_inst_t cmd_set_hash_input_set = {
12869         .f = cmd_set_hash_input_set_parsed,
12870         .data = NULL,
12871         .help_str = "set_hash_input_set <port_id> "
12872         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12873         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12874         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12875         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12876         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12877         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12878         "fld-7th|fld-8th|none select|add",
12879         .tokens = {
12880                 (void *)&cmd_set_hash_input_set_cmd,
12881                 (void *)&cmd_set_hash_input_set_port_id,
12882                 (void *)&cmd_set_hash_input_set_flow_type,
12883                 (void *)&cmd_set_hash_input_set_field,
12884                 (void *)&cmd_set_hash_input_set_select,
12885                 NULL,
12886         },
12887 };
12888
12889 /* Set flow director input set */
12890 struct cmd_set_fdir_input_set_result {
12891         cmdline_fixed_string_t set_fdir_input_set;
12892         portid_t port_id;
12893         cmdline_fixed_string_t flow_type;
12894         cmdline_fixed_string_t inset_field;
12895         cmdline_fixed_string_t select;
12896 };
12897
12898 static void
12899 cmd_set_fdir_input_set_parsed(void *parsed_result,
12900         __rte_unused struct cmdline *cl,
12901         __rte_unused void *data)
12902 {
12903         struct cmd_set_fdir_input_set_result *res = parsed_result;
12904         struct rte_eth_fdir_filter_info info;
12905
12906         memset(&info, 0, sizeof(info));
12907         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12908         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12909         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12910         info.info.input_set_conf.inset_size = 1;
12911         if (!strcmp(res->select, "select"))
12912                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12913         else if (!strcmp(res->select, "add"))
12914                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12915         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12916                 RTE_ETH_FILTER_SET, &info);
12917 }
12918
12919 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12920         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12921         set_fdir_input_set, "set_fdir_input_set");
12922 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12923         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12924         port_id, UINT16);
12925 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12926         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12927         flow_type,
12928         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12929         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12930 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12931         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12932         inset_field,
12933         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12934         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12935         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12936         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12937         "sctp-veri-tag#none");
12938 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12939         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12940         select, "select#add");
12941
12942 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12943         .f = cmd_set_fdir_input_set_parsed,
12944         .data = NULL,
12945         .help_str = "set_fdir_input_set <port_id> "
12946         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12947         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
12948         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
12949         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
12950         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
12951         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
12952         "sctp-veri-tag|none select|add",
12953         .tokens = {
12954                 (void *)&cmd_set_fdir_input_set_cmd,
12955                 (void *)&cmd_set_fdir_input_set_port_id,
12956                 (void *)&cmd_set_fdir_input_set_flow_type,
12957                 (void *)&cmd_set_fdir_input_set_field,
12958                 (void *)&cmd_set_fdir_input_set_select,
12959                 NULL,
12960         },
12961 };
12962
12963 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
12964 struct cmd_mcast_addr_result {
12965         cmdline_fixed_string_t mcast_addr_cmd;
12966         cmdline_fixed_string_t what;
12967         uint16_t port_num;
12968         struct rte_ether_addr mc_addr;
12969 };
12970
12971 static void cmd_mcast_addr_parsed(void *parsed_result,
12972                 __rte_unused struct cmdline *cl,
12973                 __rte_unused void *data)
12974 {
12975         struct cmd_mcast_addr_result *res = parsed_result;
12976
12977         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
12978                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
12979                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
12980                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
12981                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
12982                 return;
12983         }
12984         if (strcmp(res->what, "add") == 0)
12985                 mcast_addr_add(res->port_num, &res->mc_addr);
12986         else
12987                 mcast_addr_remove(res->port_num, &res->mc_addr);
12988 }
12989
12990 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
12991         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
12992                                  mcast_addr_cmd, "mcast_addr");
12993 cmdline_parse_token_string_t cmd_mcast_addr_what =
12994         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
12995                                  "add#remove");
12996 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
12997         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
12998 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
12999         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
13000
13001 cmdline_parse_inst_t cmd_mcast_addr = {
13002         .f = cmd_mcast_addr_parsed,
13003         .data = (void *)0,
13004         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
13005                 "Add/Remove multicast MAC address on port_id",
13006         .tokens = {
13007                 (void *)&cmd_mcast_addr_cmd,
13008                 (void *)&cmd_mcast_addr_what,
13009                 (void *)&cmd_mcast_addr_portnum,
13010                 (void *)&cmd_mcast_addr_addr,
13011                 NULL,
13012         },
13013 };
13014
13015 /* l2 tunnel config
13016  * only support E-tag now.
13017  */
13018
13019 /* Ether type config */
13020 struct cmd_config_l2_tunnel_eth_type_result {
13021         cmdline_fixed_string_t port;
13022         cmdline_fixed_string_t config;
13023         cmdline_fixed_string_t all;
13024         portid_t id;
13025         cmdline_fixed_string_t l2_tunnel;
13026         cmdline_fixed_string_t l2_tunnel_type;
13027         cmdline_fixed_string_t eth_type;
13028         uint16_t eth_type_val;
13029 };
13030
13031 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13032         TOKEN_STRING_INITIALIZER
13033                 (struct cmd_config_l2_tunnel_eth_type_result,
13034                  port, "port");
13035 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13036         TOKEN_STRING_INITIALIZER
13037                 (struct cmd_config_l2_tunnel_eth_type_result,
13038                  config, "config");
13039 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13040         TOKEN_STRING_INITIALIZER
13041                 (struct cmd_config_l2_tunnel_eth_type_result,
13042                  all, "all");
13043 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13044         TOKEN_NUM_INITIALIZER
13045                 (struct cmd_config_l2_tunnel_eth_type_result,
13046                  id, UINT16);
13047 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13048         TOKEN_STRING_INITIALIZER
13049                 (struct cmd_config_l2_tunnel_eth_type_result,
13050                  l2_tunnel, "l2-tunnel");
13051 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13052         TOKEN_STRING_INITIALIZER
13053                 (struct cmd_config_l2_tunnel_eth_type_result,
13054                  l2_tunnel_type, "E-tag");
13055 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13056         TOKEN_STRING_INITIALIZER
13057                 (struct cmd_config_l2_tunnel_eth_type_result,
13058                  eth_type, "ether-type");
13059 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13060         TOKEN_NUM_INITIALIZER
13061                 (struct cmd_config_l2_tunnel_eth_type_result,
13062                  eth_type_val, UINT16);
13063
13064 static enum rte_eth_tunnel_type
13065 str2fdir_l2_tunnel_type(char *string)
13066 {
13067         uint32_t i = 0;
13068
13069         static const struct {
13070                 char str[32];
13071                 enum rte_eth_tunnel_type type;
13072         } l2_tunnel_type_str[] = {
13073                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13074         };
13075
13076         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13077                 if (!strcmp(l2_tunnel_type_str[i].str, string))
13078                         return l2_tunnel_type_str[i].type;
13079         }
13080         return RTE_TUNNEL_TYPE_NONE;
13081 }
13082
13083 /* ether type config for all ports */
13084 static void
13085 cmd_config_l2_tunnel_eth_type_all_parsed
13086         (void *parsed_result,
13087          __rte_unused struct cmdline *cl,
13088          __rte_unused void *data)
13089 {
13090         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13091         struct rte_eth_l2_tunnel_conf entry;
13092         portid_t pid;
13093
13094         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13095         entry.ether_type = res->eth_type_val;
13096
13097         RTE_ETH_FOREACH_DEV(pid) {
13098                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13099         }
13100 }
13101
13102 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13103         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13104         .data = NULL,
13105         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13106         .tokens = {
13107                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13108                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13109                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13110                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13111                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13112                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13113                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13114                 NULL,
13115         },
13116 };
13117
13118 /* ether type config for a specific port */
13119 static void
13120 cmd_config_l2_tunnel_eth_type_specific_parsed(
13121         void *parsed_result,
13122         __rte_unused struct cmdline *cl,
13123         __rte_unused void *data)
13124 {
13125         struct cmd_config_l2_tunnel_eth_type_result *res =
13126                  parsed_result;
13127         struct rte_eth_l2_tunnel_conf entry;
13128
13129         if (port_id_is_invalid(res->id, ENABLED_WARN))
13130                 return;
13131
13132         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13133         entry.ether_type = res->eth_type_val;
13134
13135         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13136 }
13137
13138 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13139         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13140         .data = NULL,
13141         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13142         .tokens = {
13143                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13144                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13145                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13146                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13147                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13148                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13149                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13150                 NULL,
13151         },
13152 };
13153
13154 /* Enable/disable l2 tunnel */
13155 struct cmd_config_l2_tunnel_en_dis_result {
13156         cmdline_fixed_string_t port;
13157         cmdline_fixed_string_t config;
13158         cmdline_fixed_string_t all;
13159         portid_t id;
13160         cmdline_fixed_string_t l2_tunnel;
13161         cmdline_fixed_string_t l2_tunnel_type;
13162         cmdline_fixed_string_t en_dis;
13163 };
13164
13165 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13166         TOKEN_STRING_INITIALIZER
13167                 (struct cmd_config_l2_tunnel_en_dis_result,
13168                  port, "port");
13169 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13170         TOKEN_STRING_INITIALIZER
13171                 (struct cmd_config_l2_tunnel_en_dis_result,
13172                  config, "config");
13173 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13174         TOKEN_STRING_INITIALIZER
13175                 (struct cmd_config_l2_tunnel_en_dis_result,
13176                  all, "all");
13177 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13178         TOKEN_NUM_INITIALIZER
13179                 (struct cmd_config_l2_tunnel_en_dis_result,
13180                  id, UINT16);
13181 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13182         TOKEN_STRING_INITIALIZER
13183                 (struct cmd_config_l2_tunnel_en_dis_result,
13184                  l2_tunnel, "l2-tunnel");
13185 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13186         TOKEN_STRING_INITIALIZER
13187                 (struct cmd_config_l2_tunnel_en_dis_result,
13188                  l2_tunnel_type, "E-tag");
13189 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13190         TOKEN_STRING_INITIALIZER
13191                 (struct cmd_config_l2_tunnel_en_dis_result,
13192                  en_dis, "enable#disable");
13193
13194 /* enable/disable l2 tunnel for all ports */
13195 static void
13196 cmd_config_l2_tunnel_en_dis_all_parsed(
13197         void *parsed_result,
13198         __rte_unused struct cmdline *cl,
13199         __rte_unused void *data)
13200 {
13201         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13202         struct rte_eth_l2_tunnel_conf entry;
13203         portid_t pid;
13204         uint8_t en;
13205
13206         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13207
13208         if (!strcmp("enable", res->en_dis))
13209                 en = 1;
13210         else
13211                 en = 0;
13212
13213         RTE_ETH_FOREACH_DEV(pid) {
13214                 rte_eth_dev_l2_tunnel_offload_set(pid,
13215                                                   &entry,
13216                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13217                                                   en);
13218         }
13219 }
13220
13221 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13222         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13223         .data = NULL,
13224         .help_str = "port config all l2-tunnel E-tag enable|disable",
13225         .tokens = {
13226                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13227                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13228                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13229                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13230                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13231                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13232                 NULL,
13233         },
13234 };
13235
13236 /* enable/disable l2 tunnel for a port */
13237 static void
13238 cmd_config_l2_tunnel_en_dis_specific_parsed(
13239         void *parsed_result,
13240         __rte_unused struct cmdline *cl,
13241         __rte_unused void *data)
13242 {
13243         struct cmd_config_l2_tunnel_en_dis_result *res =
13244                 parsed_result;
13245         struct rte_eth_l2_tunnel_conf entry;
13246
13247         if (port_id_is_invalid(res->id, ENABLED_WARN))
13248                 return;
13249
13250         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13251
13252         if (!strcmp("enable", res->en_dis))
13253                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13254                                                   &entry,
13255                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13256                                                   1);
13257         else
13258                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13259                                                   &entry,
13260                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13261                                                   0);
13262 }
13263
13264 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13265         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13266         .data = NULL,
13267         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13268         .tokens = {
13269                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13270                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13271                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13272                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13273                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13274                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13275                 NULL,
13276         },
13277 };
13278
13279 /* E-tag configuration */
13280
13281 /* Common result structure for all E-tag configuration */
13282 struct cmd_config_e_tag_result {
13283         cmdline_fixed_string_t e_tag;
13284         cmdline_fixed_string_t set;
13285         cmdline_fixed_string_t insertion;
13286         cmdline_fixed_string_t stripping;
13287         cmdline_fixed_string_t forwarding;
13288         cmdline_fixed_string_t filter;
13289         cmdline_fixed_string_t add;
13290         cmdline_fixed_string_t del;
13291         cmdline_fixed_string_t on;
13292         cmdline_fixed_string_t off;
13293         cmdline_fixed_string_t on_off;
13294         cmdline_fixed_string_t port_tag_id;
13295         uint32_t port_tag_id_val;
13296         cmdline_fixed_string_t e_tag_id;
13297         uint16_t e_tag_id_val;
13298         cmdline_fixed_string_t dst_pool;
13299         uint8_t dst_pool_val;
13300         cmdline_fixed_string_t port;
13301         portid_t port_id;
13302         cmdline_fixed_string_t vf;
13303         uint8_t vf_id;
13304 };
13305
13306 /* Common CLI fields for all E-tag configuration */
13307 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13308         TOKEN_STRING_INITIALIZER
13309                 (struct cmd_config_e_tag_result,
13310                  e_tag, "E-tag");
13311 cmdline_parse_token_string_t cmd_config_e_tag_set =
13312         TOKEN_STRING_INITIALIZER
13313                 (struct cmd_config_e_tag_result,
13314                  set, "set");
13315 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13316         TOKEN_STRING_INITIALIZER
13317                 (struct cmd_config_e_tag_result,
13318                  insertion, "insertion");
13319 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13320         TOKEN_STRING_INITIALIZER
13321                 (struct cmd_config_e_tag_result,
13322                  stripping, "stripping");
13323 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13324         TOKEN_STRING_INITIALIZER
13325                 (struct cmd_config_e_tag_result,
13326                  forwarding, "forwarding");
13327 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13328         TOKEN_STRING_INITIALIZER
13329                 (struct cmd_config_e_tag_result,
13330                  filter, "filter");
13331 cmdline_parse_token_string_t cmd_config_e_tag_add =
13332         TOKEN_STRING_INITIALIZER
13333                 (struct cmd_config_e_tag_result,
13334                  add, "add");
13335 cmdline_parse_token_string_t cmd_config_e_tag_del =
13336         TOKEN_STRING_INITIALIZER
13337                 (struct cmd_config_e_tag_result,
13338                  del, "del");
13339 cmdline_parse_token_string_t cmd_config_e_tag_on =
13340         TOKEN_STRING_INITIALIZER
13341                 (struct cmd_config_e_tag_result,
13342                  on, "on");
13343 cmdline_parse_token_string_t cmd_config_e_tag_off =
13344         TOKEN_STRING_INITIALIZER
13345                 (struct cmd_config_e_tag_result,
13346                  off, "off");
13347 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13348         TOKEN_STRING_INITIALIZER
13349                 (struct cmd_config_e_tag_result,
13350                  on_off, "on#off");
13351 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13352         TOKEN_STRING_INITIALIZER
13353                 (struct cmd_config_e_tag_result,
13354                  port_tag_id, "port-tag-id");
13355 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13356         TOKEN_NUM_INITIALIZER
13357                 (struct cmd_config_e_tag_result,
13358                  port_tag_id_val, UINT32);
13359 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13360         TOKEN_STRING_INITIALIZER
13361                 (struct cmd_config_e_tag_result,
13362                  e_tag_id, "e-tag-id");
13363 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13364         TOKEN_NUM_INITIALIZER
13365                 (struct cmd_config_e_tag_result,
13366                  e_tag_id_val, UINT16);
13367 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13368         TOKEN_STRING_INITIALIZER
13369                 (struct cmd_config_e_tag_result,
13370                  dst_pool, "dst-pool");
13371 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13372         TOKEN_NUM_INITIALIZER
13373                 (struct cmd_config_e_tag_result,
13374                  dst_pool_val, UINT8);
13375 cmdline_parse_token_string_t cmd_config_e_tag_port =
13376         TOKEN_STRING_INITIALIZER
13377                 (struct cmd_config_e_tag_result,
13378                  port, "port");
13379 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13380         TOKEN_NUM_INITIALIZER
13381                 (struct cmd_config_e_tag_result,
13382                  port_id, UINT16);
13383 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13384         TOKEN_STRING_INITIALIZER
13385                 (struct cmd_config_e_tag_result,
13386                  vf, "vf");
13387 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13388         TOKEN_NUM_INITIALIZER
13389                 (struct cmd_config_e_tag_result,
13390                  vf_id, UINT8);
13391
13392 /* E-tag insertion configuration */
13393 static void
13394 cmd_config_e_tag_insertion_en_parsed(
13395         void *parsed_result,
13396         __rte_unused struct cmdline *cl,
13397         __rte_unused void *data)
13398 {
13399         struct cmd_config_e_tag_result *res =
13400                 parsed_result;
13401         struct rte_eth_l2_tunnel_conf entry;
13402
13403         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13404                 return;
13405
13406         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13407         entry.tunnel_id = res->port_tag_id_val;
13408         entry.vf_id = res->vf_id;
13409         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13410                                           &entry,
13411                                           ETH_L2_TUNNEL_INSERTION_MASK,
13412                                           1);
13413 }
13414
13415 static void
13416 cmd_config_e_tag_insertion_dis_parsed(
13417         void *parsed_result,
13418         __rte_unused struct cmdline *cl,
13419         __rte_unused void *data)
13420 {
13421         struct cmd_config_e_tag_result *res =
13422                 parsed_result;
13423         struct rte_eth_l2_tunnel_conf entry;
13424
13425         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13426                 return;
13427
13428         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13429         entry.vf_id = res->vf_id;
13430
13431         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13432                                           &entry,
13433                                           ETH_L2_TUNNEL_INSERTION_MASK,
13434                                           0);
13435 }
13436
13437 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13438         .f = cmd_config_e_tag_insertion_en_parsed,
13439         .data = NULL,
13440         .help_str = "E-tag ... : E-tag insertion enable",
13441         .tokens = {
13442                 (void *)&cmd_config_e_tag_e_tag,
13443                 (void *)&cmd_config_e_tag_set,
13444                 (void *)&cmd_config_e_tag_insertion,
13445                 (void *)&cmd_config_e_tag_on,
13446                 (void *)&cmd_config_e_tag_port_tag_id,
13447                 (void *)&cmd_config_e_tag_port_tag_id_val,
13448                 (void *)&cmd_config_e_tag_port,
13449                 (void *)&cmd_config_e_tag_port_id,
13450                 (void *)&cmd_config_e_tag_vf,
13451                 (void *)&cmd_config_e_tag_vf_id,
13452                 NULL,
13453         },
13454 };
13455
13456 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13457         .f = cmd_config_e_tag_insertion_dis_parsed,
13458         .data = NULL,
13459         .help_str = "E-tag ... : E-tag insertion disable",
13460         .tokens = {
13461                 (void *)&cmd_config_e_tag_e_tag,
13462                 (void *)&cmd_config_e_tag_set,
13463                 (void *)&cmd_config_e_tag_insertion,
13464                 (void *)&cmd_config_e_tag_off,
13465                 (void *)&cmd_config_e_tag_port,
13466                 (void *)&cmd_config_e_tag_port_id,
13467                 (void *)&cmd_config_e_tag_vf,
13468                 (void *)&cmd_config_e_tag_vf_id,
13469                 NULL,
13470         },
13471 };
13472
13473 /* E-tag stripping configuration */
13474 static void
13475 cmd_config_e_tag_stripping_parsed(
13476         void *parsed_result,
13477         __rte_unused struct cmdline *cl,
13478         __rte_unused void *data)
13479 {
13480         struct cmd_config_e_tag_result *res =
13481                 parsed_result;
13482         struct rte_eth_l2_tunnel_conf entry;
13483
13484         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13485                 return;
13486
13487         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13488
13489         if (!strcmp(res->on_off, "on"))
13490                 rte_eth_dev_l2_tunnel_offload_set
13491                         (res->port_id,
13492                          &entry,
13493                          ETH_L2_TUNNEL_STRIPPING_MASK,
13494                          1);
13495         else
13496                 rte_eth_dev_l2_tunnel_offload_set
13497                         (res->port_id,
13498                          &entry,
13499                          ETH_L2_TUNNEL_STRIPPING_MASK,
13500                          0);
13501 }
13502
13503 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13504         .f = cmd_config_e_tag_stripping_parsed,
13505         .data = NULL,
13506         .help_str = "E-tag ... : E-tag stripping enable/disable",
13507         .tokens = {
13508                 (void *)&cmd_config_e_tag_e_tag,
13509                 (void *)&cmd_config_e_tag_set,
13510                 (void *)&cmd_config_e_tag_stripping,
13511                 (void *)&cmd_config_e_tag_on_off,
13512                 (void *)&cmd_config_e_tag_port,
13513                 (void *)&cmd_config_e_tag_port_id,
13514                 NULL,
13515         },
13516 };
13517
13518 /* E-tag forwarding configuration */
13519 static void
13520 cmd_config_e_tag_forwarding_parsed(
13521         void *parsed_result,
13522         __rte_unused struct cmdline *cl,
13523         __rte_unused void *data)
13524 {
13525         struct cmd_config_e_tag_result *res = parsed_result;
13526         struct rte_eth_l2_tunnel_conf entry;
13527
13528         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13529                 return;
13530
13531         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13532
13533         if (!strcmp(res->on_off, "on"))
13534                 rte_eth_dev_l2_tunnel_offload_set
13535                         (res->port_id,
13536                          &entry,
13537                          ETH_L2_TUNNEL_FORWARDING_MASK,
13538                          1);
13539         else
13540                 rte_eth_dev_l2_tunnel_offload_set
13541                         (res->port_id,
13542                          &entry,
13543                          ETH_L2_TUNNEL_FORWARDING_MASK,
13544                          0);
13545 }
13546
13547 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13548         .f = cmd_config_e_tag_forwarding_parsed,
13549         .data = NULL,
13550         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13551         .tokens = {
13552                 (void *)&cmd_config_e_tag_e_tag,
13553                 (void *)&cmd_config_e_tag_set,
13554                 (void *)&cmd_config_e_tag_forwarding,
13555                 (void *)&cmd_config_e_tag_on_off,
13556                 (void *)&cmd_config_e_tag_port,
13557                 (void *)&cmd_config_e_tag_port_id,
13558                 NULL,
13559         },
13560 };
13561
13562 /* E-tag filter configuration */
13563 static void
13564 cmd_config_e_tag_filter_add_parsed(
13565         void *parsed_result,
13566         __rte_unused struct cmdline *cl,
13567         __rte_unused void *data)
13568 {
13569         struct cmd_config_e_tag_result *res = parsed_result;
13570         struct rte_eth_l2_tunnel_conf entry;
13571         int ret = 0;
13572
13573         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13574                 return;
13575
13576         if (res->e_tag_id_val > 0x3fff) {
13577                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13578                 return;
13579         }
13580
13581         ret = rte_eth_dev_filter_supported(res->port_id,
13582                                            RTE_ETH_FILTER_L2_TUNNEL);
13583         if (ret < 0) {
13584                 printf("E-tag filter is not supported on port %u.\n",
13585                        res->port_id);
13586                 return;
13587         }
13588
13589         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13590         entry.tunnel_id = res->e_tag_id_val;
13591         entry.pool = res->dst_pool_val;
13592
13593         ret = rte_eth_dev_filter_ctrl(res->port_id,
13594                                       RTE_ETH_FILTER_L2_TUNNEL,
13595                                       RTE_ETH_FILTER_ADD,
13596                                       &entry);
13597         if (ret < 0)
13598                 printf("E-tag filter programming error: (%s)\n",
13599                        strerror(-ret));
13600 }
13601
13602 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13603         .f = cmd_config_e_tag_filter_add_parsed,
13604         .data = NULL,
13605         .help_str = "E-tag ... : E-tag filter add",
13606         .tokens = {
13607                 (void *)&cmd_config_e_tag_e_tag,
13608                 (void *)&cmd_config_e_tag_set,
13609                 (void *)&cmd_config_e_tag_filter,
13610                 (void *)&cmd_config_e_tag_add,
13611                 (void *)&cmd_config_e_tag_e_tag_id,
13612                 (void *)&cmd_config_e_tag_e_tag_id_val,
13613                 (void *)&cmd_config_e_tag_dst_pool,
13614                 (void *)&cmd_config_e_tag_dst_pool_val,
13615                 (void *)&cmd_config_e_tag_port,
13616                 (void *)&cmd_config_e_tag_port_id,
13617                 NULL,
13618         },
13619 };
13620
13621 static void
13622 cmd_config_e_tag_filter_del_parsed(
13623         void *parsed_result,
13624         __rte_unused struct cmdline *cl,
13625         __rte_unused void *data)
13626 {
13627         struct cmd_config_e_tag_result *res = parsed_result;
13628         struct rte_eth_l2_tunnel_conf entry;
13629         int ret = 0;
13630
13631         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13632                 return;
13633
13634         if (res->e_tag_id_val > 0x3fff) {
13635                 printf("e-tag-id must be less than 0x3fff.\n");
13636                 return;
13637         }
13638
13639         ret = rte_eth_dev_filter_supported(res->port_id,
13640                                            RTE_ETH_FILTER_L2_TUNNEL);
13641         if (ret < 0) {
13642                 printf("E-tag filter is not supported on port %u.\n",
13643                        res->port_id);
13644                 return;
13645         }
13646
13647         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13648         entry.tunnel_id = res->e_tag_id_val;
13649
13650         ret = rte_eth_dev_filter_ctrl(res->port_id,
13651                                       RTE_ETH_FILTER_L2_TUNNEL,
13652                                       RTE_ETH_FILTER_DELETE,
13653                                       &entry);
13654         if (ret < 0)
13655                 printf("E-tag filter programming error: (%s)\n",
13656                        strerror(-ret));
13657 }
13658
13659 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13660         .f = cmd_config_e_tag_filter_del_parsed,
13661         .data = NULL,
13662         .help_str = "E-tag ... : E-tag filter delete",
13663         .tokens = {
13664                 (void *)&cmd_config_e_tag_e_tag,
13665                 (void *)&cmd_config_e_tag_set,
13666                 (void *)&cmd_config_e_tag_filter,
13667                 (void *)&cmd_config_e_tag_del,
13668                 (void *)&cmd_config_e_tag_e_tag_id,
13669                 (void *)&cmd_config_e_tag_e_tag_id_val,
13670                 (void *)&cmd_config_e_tag_port,
13671                 (void *)&cmd_config_e_tag_port_id,
13672                 NULL,
13673         },
13674 };
13675
13676 /* vf vlan anti spoof configuration */
13677
13678 /* Common result structure for vf vlan anti spoof */
13679 struct cmd_vf_vlan_anti_spoof_result {
13680         cmdline_fixed_string_t set;
13681         cmdline_fixed_string_t vf;
13682         cmdline_fixed_string_t vlan;
13683         cmdline_fixed_string_t antispoof;
13684         portid_t port_id;
13685         uint32_t vf_id;
13686         cmdline_fixed_string_t on_off;
13687 };
13688
13689 /* Common CLI fields for vf vlan anti spoof enable disable */
13690 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13691         TOKEN_STRING_INITIALIZER
13692                 (struct cmd_vf_vlan_anti_spoof_result,
13693                  set, "set");
13694 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13695         TOKEN_STRING_INITIALIZER
13696                 (struct cmd_vf_vlan_anti_spoof_result,
13697                  vf, "vf");
13698 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13699         TOKEN_STRING_INITIALIZER
13700                 (struct cmd_vf_vlan_anti_spoof_result,
13701                  vlan, "vlan");
13702 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13703         TOKEN_STRING_INITIALIZER
13704                 (struct cmd_vf_vlan_anti_spoof_result,
13705                  antispoof, "antispoof");
13706 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13707         TOKEN_NUM_INITIALIZER
13708                 (struct cmd_vf_vlan_anti_spoof_result,
13709                  port_id, UINT16);
13710 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13711         TOKEN_NUM_INITIALIZER
13712                 (struct cmd_vf_vlan_anti_spoof_result,
13713                  vf_id, UINT32);
13714 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13715         TOKEN_STRING_INITIALIZER
13716                 (struct cmd_vf_vlan_anti_spoof_result,
13717                  on_off, "on#off");
13718
13719 static void
13720 cmd_set_vf_vlan_anti_spoof_parsed(
13721         void *parsed_result,
13722         __rte_unused struct cmdline *cl,
13723         __rte_unused void *data)
13724 {
13725         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13726         int ret = -ENOTSUP;
13727
13728         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13729
13730         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13731                 return;
13732
13733 #ifdef RTE_LIBRTE_IXGBE_PMD
13734         if (ret == -ENOTSUP)
13735                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13736                                 res->vf_id, is_on);
13737 #endif
13738 #ifdef RTE_LIBRTE_I40E_PMD
13739         if (ret == -ENOTSUP)
13740                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13741                                 res->vf_id, is_on);
13742 #endif
13743 #ifdef RTE_LIBRTE_BNXT_PMD
13744         if (ret == -ENOTSUP)
13745                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13746                                 res->vf_id, is_on);
13747 #endif
13748
13749         switch (ret) {
13750         case 0:
13751                 break;
13752         case -EINVAL:
13753                 printf("invalid vf_id %d\n", res->vf_id);
13754                 break;
13755         case -ENODEV:
13756                 printf("invalid port_id %d\n", res->port_id);
13757                 break;
13758         case -ENOTSUP:
13759                 printf("function not implemented\n");
13760                 break;
13761         default:
13762                 printf("programming error: (%s)\n", strerror(-ret));
13763         }
13764 }
13765
13766 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13767         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13768         .data = NULL,
13769         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13770         .tokens = {
13771                 (void *)&cmd_vf_vlan_anti_spoof_set,
13772                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13773                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13774                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13775                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13776                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13777                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13778                 NULL,
13779         },
13780 };
13781
13782 /* vf mac anti spoof configuration */
13783
13784 /* Common result structure for vf mac anti spoof */
13785 struct cmd_vf_mac_anti_spoof_result {
13786         cmdline_fixed_string_t set;
13787         cmdline_fixed_string_t vf;
13788         cmdline_fixed_string_t mac;
13789         cmdline_fixed_string_t antispoof;
13790         portid_t port_id;
13791         uint32_t vf_id;
13792         cmdline_fixed_string_t on_off;
13793 };
13794
13795 /* Common CLI fields for vf mac anti spoof enable disable */
13796 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13797         TOKEN_STRING_INITIALIZER
13798                 (struct cmd_vf_mac_anti_spoof_result,
13799                  set, "set");
13800 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13801         TOKEN_STRING_INITIALIZER
13802                 (struct cmd_vf_mac_anti_spoof_result,
13803                  vf, "vf");
13804 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13805         TOKEN_STRING_INITIALIZER
13806                 (struct cmd_vf_mac_anti_spoof_result,
13807                  mac, "mac");
13808 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13809         TOKEN_STRING_INITIALIZER
13810                 (struct cmd_vf_mac_anti_spoof_result,
13811                  antispoof, "antispoof");
13812 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13813         TOKEN_NUM_INITIALIZER
13814                 (struct cmd_vf_mac_anti_spoof_result,
13815                  port_id, UINT16);
13816 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13817         TOKEN_NUM_INITIALIZER
13818                 (struct cmd_vf_mac_anti_spoof_result,
13819                  vf_id, UINT32);
13820 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13821         TOKEN_STRING_INITIALIZER
13822                 (struct cmd_vf_mac_anti_spoof_result,
13823                  on_off, "on#off");
13824
13825 static void
13826 cmd_set_vf_mac_anti_spoof_parsed(
13827         void *parsed_result,
13828         __rte_unused struct cmdline *cl,
13829         __rte_unused void *data)
13830 {
13831         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13832         int ret = -ENOTSUP;
13833
13834         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13835
13836         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13837                 return;
13838
13839 #ifdef RTE_LIBRTE_IXGBE_PMD
13840         if (ret == -ENOTSUP)
13841                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13842                         res->vf_id, is_on);
13843 #endif
13844 #ifdef RTE_LIBRTE_I40E_PMD
13845         if (ret == -ENOTSUP)
13846                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13847                         res->vf_id, is_on);
13848 #endif
13849 #ifdef RTE_LIBRTE_BNXT_PMD
13850         if (ret == -ENOTSUP)
13851                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13852                         res->vf_id, is_on);
13853 #endif
13854
13855         switch (ret) {
13856         case 0:
13857                 break;
13858         case -EINVAL:
13859                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13860                 break;
13861         case -ENODEV:
13862                 printf("invalid port_id %d\n", res->port_id);
13863                 break;
13864         case -ENOTSUP:
13865                 printf("function not implemented\n");
13866                 break;
13867         default:
13868                 printf("programming error: (%s)\n", strerror(-ret));
13869         }
13870 }
13871
13872 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13873         .f = cmd_set_vf_mac_anti_spoof_parsed,
13874         .data = NULL,
13875         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13876         .tokens = {
13877                 (void *)&cmd_vf_mac_anti_spoof_set,
13878                 (void *)&cmd_vf_mac_anti_spoof_vf,
13879                 (void *)&cmd_vf_mac_anti_spoof_mac,
13880                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13881                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13882                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13883                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13884                 NULL,
13885         },
13886 };
13887
13888 /* vf vlan strip queue configuration */
13889
13890 /* Common result structure for vf mac anti spoof */
13891 struct cmd_vf_vlan_stripq_result {
13892         cmdline_fixed_string_t set;
13893         cmdline_fixed_string_t vf;
13894         cmdline_fixed_string_t vlan;
13895         cmdline_fixed_string_t stripq;
13896         portid_t port_id;
13897         uint16_t vf_id;
13898         cmdline_fixed_string_t on_off;
13899 };
13900
13901 /* Common CLI fields for vf vlan strip enable disable */
13902 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13903         TOKEN_STRING_INITIALIZER
13904                 (struct cmd_vf_vlan_stripq_result,
13905                  set, "set");
13906 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13907         TOKEN_STRING_INITIALIZER
13908                 (struct cmd_vf_vlan_stripq_result,
13909                  vf, "vf");
13910 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13911         TOKEN_STRING_INITIALIZER
13912                 (struct cmd_vf_vlan_stripq_result,
13913                  vlan, "vlan");
13914 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13915         TOKEN_STRING_INITIALIZER
13916                 (struct cmd_vf_vlan_stripq_result,
13917                  stripq, "stripq");
13918 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13919         TOKEN_NUM_INITIALIZER
13920                 (struct cmd_vf_vlan_stripq_result,
13921                  port_id, UINT16);
13922 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13923         TOKEN_NUM_INITIALIZER
13924                 (struct cmd_vf_vlan_stripq_result,
13925                  vf_id, UINT16);
13926 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13927         TOKEN_STRING_INITIALIZER
13928                 (struct cmd_vf_vlan_stripq_result,
13929                  on_off, "on#off");
13930
13931 static void
13932 cmd_set_vf_vlan_stripq_parsed(
13933         void *parsed_result,
13934         __rte_unused struct cmdline *cl,
13935         __rte_unused void *data)
13936 {
13937         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13938         int ret = -ENOTSUP;
13939
13940         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13941
13942         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13943                 return;
13944
13945 #ifdef RTE_LIBRTE_IXGBE_PMD
13946         if (ret == -ENOTSUP)
13947                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
13948                         res->vf_id, is_on);
13949 #endif
13950 #ifdef RTE_LIBRTE_I40E_PMD
13951         if (ret == -ENOTSUP)
13952                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
13953                         res->vf_id, is_on);
13954 #endif
13955 #ifdef RTE_LIBRTE_BNXT_PMD
13956         if (ret == -ENOTSUP)
13957                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
13958                         res->vf_id, is_on);
13959 #endif
13960
13961         switch (ret) {
13962         case 0:
13963                 break;
13964         case -EINVAL:
13965                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13966                 break;
13967         case -ENODEV:
13968                 printf("invalid port_id %d\n", res->port_id);
13969                 break;
13970         case -ENOTSUP:
13971                 printf("function not implemented\n");
13972                 break;
13973         default:
13974                 printf("programming error: (%s)\n", strerror(-ret));
13975         }
13976 }
13977
13978 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
13979         .f = cmd_set_vf_vlan_stripq_parsed,
13980         .data = NULL,
13981         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
13982         .tokens = {
13983                 (void *)&cmd_vf_vlan_stripq_set,
13984                 (void *)&cmd_vf_vlan_stripq_vf,
13985                 (void *)&cmd_vf_vlan_stripq_vlan,
13986                 (void *)&cmd_vf_vlan_stripq_stripq,
13987                 (void *)&cmd_vf_vlan_stripq_port_id,
13988                 (void *)&cmd_vf_vlan_stripq_vf_id,
13989                 (void *)&cmd_vf_vlan_stripq_on_off,
13990                 NULL,
13991         },
13992 };
13993
13994 /* vf vlan insert configuration */
13995
13996 /* Common result structure for vf vlan insert */
13997 struct cmd_vf_vlan_insert_result {
13998         cmdline_fixed_string_t set;
13999         cmdline_fixed_string_t vf;
14000         cmdline_fixed_string_t vlan;
14001         cmdline_fixed_string_t insert;
14002         portid_t port_id;
14003         uint16_t vf_id;
14004         uint16_t vlan_id;
14005 };
14006
14007 /* Common CLI fields for vf vlan insert enable disable */
14008 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
14009         TOKEN_STRING_INITIALIZER
14010                 (struct cmd_vf_vlan_insert_result,
14011                  set, "set");
14012 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
14013         TOKEN_STRING_INITIALIZER
14014                 (struct cmd_vf_vlan_insert_result,
14015                  vf, "vf");
14016 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
14017         TOKEN_STRING_INITIALIZER
14018                 (struct cmd_vf_vlan_insert_result,
14019                  vlan, "vlan");
14020 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
14021         TOKEN_STRING_INITIALIZER
14022                 (struct cmd_vf_vlan_insert_result,
14023                  insert, "insert");
14024 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
14025         TOKEN_NUM_INITIALIZER
14026                 (struct cmd_vf_vlan_insert_result,
14027                  port_id, UINT16);
14028 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14029         TOKEN_NUM_INITIALIZER
14030                 (struct cmd_vf_vlan_insert_result,
14031                  vf_id, UINT16);
14032 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14033         TOKEN_NUM_INITIALIZER
14034                 (struct cmd_vf_vlan_insert_result,
14035                  vlan_id, UINT16);
14036
14037 static void
14038 cmd_set_vf_vlan_insert_parsed(
14039         void *parsed_result,
14040         __rte_unused struct cmdline *cl,
14041         __rte_unused void *data)
14042 {
14043         struct cmd_vf_vlan_insert_result *res = parsed_result;
14044         int ret = -ENOTSUP;
14045
14046         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14047                 return;
14048
14049 #ifdef RTE_LIBRTE_IXGBE_PMD
14050         if (ret == -ENOTSUP)
14051                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14052                         res->vlan_id);
14053 #endif
14054 #ifdef RTE_LIBRTE_I40E_PMD
14055         if (ret == -ENOTSUP)
14056                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14057                         res->vlan_id);
14058 #endif
14059 #ifdef RTE_LIBRTE_BNXT_PMD
14060         if (ret == -ENOTSUP)
14061                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14062                         res->vlan_id);
14063 #endif
14064
14065         switch (ret) {
14066         case 0:
14067                 break;
14068         case -EINVAL:
14069                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14070                 break;
14071         case -ENODEV:
14072                 printf("invalid port_id %d\n", res->port_id);
14073                 break;
14074         case -ENOTSUP:
14075                 printf("function not implemented\n");
14076                 break;
14077         default:
14078                 printf("programming error: (%s)\n", strerror(-ret));
14079         }
14080 }
14081
14082 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14083         .f = cmd_set_vf_vlan_insert_parsed,
14084         .data = NULL,
14085         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14086         .tokens = {
14087                 (void *)&cmd_vf_vlan_insert_set,
14088                 (void *)&cmd_vf_vlan_insert_vf,
14089                 (void *)&cmd_vf_vlan_insert_vlan,
14090                 (void *)&cmd_vf_vlan_insert_insert,
14091                 (void *)&cmd_vf_vlan_insert_port_id,
14092                 (void *)&cmd_vf_vlan_insert_vf_id,
14093                 (void *)&cmd_vf_vlan_insert_vlan_id,
14094                 NULL,
14095         },
14096 };
14097
14098 /* tx loopback configuration */
14099
14100 /* Common result structure for tx loopback */
14101 struct cmd_tx_loopback_result {
14102         cmdline_fixed_string_t set;
14103         cmdline_fixed_string_t tx;
14104         cmdline_fixed_string_t loopback;
14105         portid_t port_id;
14106         cmdline_fixed_string_t on_off;
14107 };
14108
14109 /* Common CLI fields for tx loopback enable disable */
14110 cmdline_parse_token_string_t cmd_tx_loopback_set =
14111         TOKEN_STRING_INITIALIZER
14112                 (struct cmd_tx_loopback_result,
14113                  set, "set");
14114 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14115         TOKEN_STRING_INITIALIZER
14116                 (struct cmd_tx_loopback_result,
14117                  tx, "tx");
14118 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14119         TOKEN_STRING_INITIALIZER
14120                 (struct cmd_tx_loopback_result,
14121                  loopback, "loopback");
14122 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14123         TOKEN_NUM_INITIALIZER
14124                 (struct cmd_tx_loopback_result,
14125                  port_id, UINT16);
14126 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14127         TOKEN_STRING_INITIALIZER
14128                 (struct cmd_tx_loopback_result,
14129                  on_off, "on#off");
14130
14131 static void
14132 cmd_set_tx_loopback_parsed(
14133         void *parsed_result,
14134         __rte_unused struct cmdline *cl,
14135         __rte_unused void *data)
14136 {
14137         struct cmd_tx_loopback_result *res = parsed_result;
14138         int ret = -ENOTSUP;
14139
14140         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14141
14142         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14143                 return;
14144
14145 #ifdef RTE_LIBRTE_IXGBE_PMD
14146         if (ret == -ENOTSUP)
14147                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14148 #endif
14149 #ifdef RTE_LIBRTE_I40E_PMD
14150         if (ret == -ENOTSUP)
14151                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14152 #endif
14153 #ifdef RTE_LIBRTE_BNXT_PMD
14154         if (ret == -ENOTSUP)
14155                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14156 #endif
14157 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14158         if (ret == -ENOTSUP)
14159                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14160 #endif
14161
14162         switch (ret) {
14163         case 0:
14164                 break;
14165         case -EINVAL:
14166                 printf("invalid is_on %d\n", is_on);
14167                 break;
14168         case -ENODEV:
14169                 printf("invalid port_id %d\n", res->port_id);
14170                 break;
14171         case -ENOTSUP:
14172                 printf("function not implemented\n");
14173                 break;
14174         default:
14175                 printf("programming error: (%s)\n", strerror(-ret));
14176         }
14177 }
14178
14179 cmdline_parse_inst_t cmd_set_tx_loopback = {
14180         .f = cmd_set_tx_loopback_parsed,
14181         .data = NULL,
14182         .help_str = "set tx loopback <port_id> on|off",
14183         .tokens = {
14184                 (void *)&cmd_tx_loopback_set,
14185                 (void *)&cmd_tx_loopback_tx,
14186                 (void *)&cmd_tx_loopback_loopback,
14187                 (void *)&cmd_tx_loopback_port_id,
14188                 (void *)&cmd_tx_loopback_on_off,
14189                 NULL,
14190         },
14191 };
14192
14193 /* all queues drop enable configuration */
14194
14195 /* Common result structure for all queues drop enable */
14196 struct cmd_all_queues_drop_en_result {
14197         cmdline_fixed_string_t set;
14198         cmdline_fixed_string_t all;
14199         cmdline_fixed_string_t queues;
14200         cmdline_fixed_string_t drop;
14201         portid_t port_id;
14202         cmdline_fixed_string_t on_off;
14203 };
14204
14205 /* Common CLI fields for tx loopback enable disable */
14206 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14207         TOKEN_STRING_INITIALIZER
14208                 (struct cmd_all_queues_drop_en_result,
14209                  set, "set");
14210 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14211         TOKEN_STRING_INITIALIZER
14212                 (struct cmd_all_queues_drop_en_result,
14213                  all, "all");
14214 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14215         TOKEN_STRING_INITIALIZER
14216                 (struct cmd_all_queues_drop_en_result,
14217                  queues, "queues");
14218 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14219         TOKEN_STRING_INITIALIZER
14220                 (struct cmd_all_queues_drop_en_result,
14221                  drop, "drop");
14222 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14223         TOKEN_NUM_INITIALIZER
14224                 (struct cmd_all_queues_drop_en_result,
14225                  port_id, UINT16);
14226 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14227         TOKEN_STRING_INITIALIZER
14228                 (struct cmd_all_queues_drop_en_result,
14229                  on_off, "on#off");
14230
14231 static void
14232 cmd_set_all_queues_drop_en_parsed(
14233         void *parsed_result,
14234         __rte_unused struct cmdline *cl,
14235         __rte_unused void *data)
14236 {
14237         struct cmd_all_queues_drop_en_result *res = parsed_result;
14238         int ret = -ENOTSUP;
14239         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14240
14241         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14242                 return;
14243
14244 #ifdef RTE_LIBRTE_IXGBE_PMD
14245         if (ret == -ENOTSUP)
14246                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14247 #endif
14248 #ifdef RTE_LIBRTE_BNXT_PMD
14249         if (ret == -ENOTSUP)
14250                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14251 #endif
14252         switch (ret) {
14253         case 0:
14254                 break;
14255         case -EINVAL:
14256                 printf("invalid is_on %d\n", is_on);
14257                 break;
14258         case -ENODEV:
14259                 printf("invalid port_id %d\n", res->port_id);
14260                 break;
14261         case -ENOTSUP:
14262                 printf("function not implemented\n");
14263                 break;
14264         default:
14265                 printf("programming error: (%s)\n", strerror(-ret));
14266         }
14267 }
14268
14269 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14270         .f = cmd_set_all_queues_drop_en_parsed,
14271         .data = NULL,
14272         .help_str = "set all queues drop <port_id> on|off",
14273         .tokens = {
14274                 (void *)&cmd_all_queues_drop_en_set,
14275                 (void *)&cmd_all_queues_drop_en_all,
14276                 (void *)&cmd_all_queues_drop_en_queues,
14277                 (void *)&cmd_all_queues_drop_en_drop,
14278                 (void *)&cmd_all_queues_drop_en_port_id,
14279                 (void *)&cmd_all_queues_drop_en_on_off,
14280                 NULL,
14281         },
14282 };
14283
14284 /* vf split drop enable configuration */
14285
14286 /* Common result structure for vf split drop enable */
14287 struct cmd_vf_split_drop_en_result {
14288         cmdline_fixed_string_t set;
14289         cmdline_fixed_string_t vf;
14290         cmdline_fixed_string_t split;
14291         cmdline_fixed_string_t drop;
14292         portid_t port_id;
14293         uint16_t vf_id;
14294         cmdline_fixed_string_t on_off;
14295 };
14296
14297 /* Common CLI fields for vf split drop enable disable */
14298 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14299         TOKEN_STRING_INITIALIZER
14300                 (struct cmd_vf_split_drop_en_result,
14301                  set, "set");
14302 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14303         TOKEN_STRING_INITIALIZER
14304                 (struct cmd_vf_split_drop_en_result,
14305                  vf, "vf");
14306 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14307         TOKEN_STRING_INITIALIZER
14308                 (struct cmd_vf_split_drop_en_result,
14309                  split, "split");
14310 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14311         TOKEN_STRING_INITIALIZER
14312                 (struct cmd_vf_split_drop_en_result,
14313                  drop, "drop");
14314 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14315         TOKEN_NUM_INITIALIZER
14316                 (struct cmd_vf_split_drop_en_result,
14317                  port_id, UINT16);
14318 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14319         TOKEN_NUM_INITIALIZER
14320                 (struct cmd_vf_split_drop_en_result,
14321                  vf_id, UINT16);
14322 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14323         TOKEN_STRING_INITIALIZER
14324                 (struct cmd_vf_split_drop_en_result,
14325                  on_off, "on#off");
14326
14327 static void
14328 cmd_set_vf_split_drop_en_parsed(
14329         void *parsed_result,
14330         __rte_unused struct cmdline *cl,
14331         __rte_unused void *data)
14332 {
14333         struct cmd_vf_split_drop_en_result *res = parsed_result;
14334         int ret = -ENOTSUP;
14335         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14336
14337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14338                 return;
14339
14340 #ifdef RTE_LIBRTE_IXGBE_PMD
14341         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14342                         is_on);
14343 #endif
14344         switch (ret) {
14345         case 0:
14346                 break;
14347         case -EINVAL:
14348                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14349                 break;
14350         case -ENODEV:
14351                 printf("invalid port_id %d\n", res->port_id);
14352                 break;
14353         case -ENOTSUP:
14354                 printf("not supported on port %d\n", res->port_id);
14355                 break;
14356         default:
14357                 printf("programming error: (%s)\n", strerror(-ret));
14358         }
14359 }
14360
14361 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14362         .f = cmd_set_vf_split_drop_en_parsed,
14363         .data = NULL,
14364         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14365         .tokens = {
14366                 (void *)&cmd_vf_split_drop_en_set,
14367                 (void *)&cmd_vf_split_drop_en_vf,
14368                 (void *)&cmd_vf_split_drop_en_split,
14369                 (void *)&cmd_vf_split_drop_en_drop,
14370                 (void *)&cmd_vf_split_drop_en_port_id,
14371                 (void *)&cmd_vf_split_drop_en_vf_id,
14372                 (void *)&cmd_vf_split_drop_en_on_off,
14373                 NULL,
14374         },
14375 };
14376
14377 /* vf mac address configuration */
14378
14379 /* Common result structure for vf mac address */
14380 struct cmd_set_vf_mac_addr_result {
14381         cmdline_fixed_string_t set;
14382         cmdline_fixed_string_t vf;
14383         cmdline_fixed_string_t mac;
14384         cmdline_fixed_string_t addr;
14385         portid_t port_id;
14386         uint16_t vf_id;
14387         struct rte_ether_addr mac_addr;
14388
14389 };
14390
14391 /* Common CLI fields for vf split drop enable disable */
14392 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14393         TOKEN_STRING_INITIALIZER
14394                 (struct cmd_set_vf_mac_addr_result,
14395                  set, "set");
14396 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14397         TOKEN_STRING_INITIALIZER
14398                 (struct cmd_set_vf_mac_addr_result,
14399                  vf, "vf");
14400 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14401         TOKEN_STRING_INITIALIZER
14402                 (struct cmd_set_vf_mac_addr_result,
14403                  mac, "mac");
14404 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14405         TOKEN_STRING_INITIALIZER
14406                 (struct cmd_set_vf_mac_addr_result,
14407                  addr, "addr");
14408 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14409         TOKEN_NUM_INITIALIZER
14410                 (struct cmd_set_vf_mac_addr_result,
14411                  port_id, UINT16);
14412 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14413         TOKEN_NUM_INITIALIZER
14414                 (struct cmd_set_vf_mac_addr_result,
14415                  vf_id, UINT16);
14416 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14417         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14418                  mac_addr);
14419
14420 static void
14421 cmd_set_vf_mac_addr_parsed(
14422         void *parsed_result,
14423         __rte_unused struct cmdline *cl,
14424         __rte_unused void *data)
14425 {
14426         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14427         int ret = -ENOTSUP;
14428
14429         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14430                 return;
14431
14432 #ifdef RTE_LIBRTE_IXGBE_PMD
14433         if (ret == -ENOTSUP)
14434                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14435                                 &res->mac_addr);
14436 #endif
14437 #ifdef RTE_LIBRTE_I40E_PMD
14438         if (ret == -ENOTSUP)
14439                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14440                                 &res->mac_addr);
14441 #endif
14442 #ifdef RTE_LIBRTE_BNXT_PMD
14443         if (ret == -ENOTSUP)
14444                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14445                                 &res->mac_addr);
14446 #endif
14447
14448         switch (ret) {
14449         case 0:
14450                 break;
14451         case -EINVAL:
14452                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14453                 break;
14454         case -ENODEV:
14455                 printf("invalid port_id %d\n", res->port_id);
14456                 break;
14457         case -ENOTSUP:
14458                 printf("function not implemented\n");
14459                 break;
14460         default:
14461                 printf("programming error: (%s)\n", strerror(-ret));
14462         }
14463 }
14464
14465 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14466         .f = cmd_set_vf_mac_addr_parsed,
14467         .data = NULL,
14468         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14469         .tokens = {
14470                 (void *)&cmd_set_vf_mac_addr_set,
14471                 (void *)&cmd_set_vf_mac_addr_vf,
14472                 (void *)&cmd_set_vf_mac_addr_mac,
14473                 (void *)&cmd_set_vf_mac_addr_addr,
14474                 (void *)&cmd_set_vf_mac_addr_port_id,
14475                 (void *)&cmd_set_vf_mac_addr_vf_id,
14476                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14477                 NULL,
14478         },
14479 };
14480
14481 /* MACsec configuration */
14482
14483 /* Common result structure for MACsec offload enable */
14484 struct cmd_macsec_offload_on_result {
14485         cmdline_fixed_string_t set;
14486         cmdline_fixed_string_t macsec;
14487         cmdline_fixed_string_t offload;
14488         portid_t port_id;
14489         cmdline_fixed_string_t on;
14490         cmdline_fixed_string_t encrypt;
14491         cmdline_fixed_string_t en_on_off;
14492         cmdline_fixed_string_t replay_protect;
14493         cmdline_fixed_string_t rp_on_off;
14494 };
14495
14496 /* Common CLI fields for MACsec offload disable */
14497 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14498         TOKEN_STRING_INITIALIZER
14499                 (struct cmd_macsec_offload_on_result,
14500                  set, "set");
14501 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14502         TOKEN_STRING_INITIALIZER
14503                 (struct cmd_macsec_offload_on_result,
14504                  macsec, "macsec");
14505 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14506         TOKEN_STRING_INITIALIZER
14507                 (struct cmd_macsec_offload_on_result,
14508                  offload, "offload");
14509 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14510         TOKEN_NUM_INITIALIZER
14511                 (struct cmd_macsec_offload_on_result,
14512                  port_id, UINT16);
14513 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14514         TOKEN_STRING_INITIALIZER
14515                 (struct cmd_macsec_offload_on_result,
14516                  on, "on");
14517 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14518         TOKEN_STRING_INITIALIZER
14519                 (struct cmd_macsec_offload_on_result,
14520                  encrypt, "encrypt");
14521 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14522         TOKEN_STRING_INITIALIZER
14523                 (struct cmd_macsec_offload_on_result,
14524                  en_on_off, "on#off");
14525 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14526         TOKEN_STRING_INITIALIZER
14527                 (struct cmd_macsec_offload_on_result,
14528                  replay_protect, "replay-protect");
14529 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14530         TOKEN_STRING_INITIALIZER
14531                 (struct cmd_macsec_offload_on_result,
14532                  rp_on_off, "on#off");
14533
14534 static void
14535 cmd_set_macsec_offload_on_parsed(
14536         void *parsed_result,
14537         __rte_unused struct cmdline *cl,
14538         __rte_unused void *data)
14539 {
14540         struct cmd_macsec_offload_on_result *res = parsed_result;
14541         int ret = -ENOTSUP;
14542         portid_t port_id = res->port_id;
14543         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14544         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14545         struct rte_eth_dev_info dev_info;
14546
14547         if (port_id_is_invalid(port_id, ENABLED_WARN))
14548                 return;
14549         if (!port_is_stopped(port_id)) {
14550                 printf("Please stop port %d first\n", port_id);
14551                 return;
14552         }
14553
14554         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14555         if (ret != 0)
14556                 return;
14557
14558         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14559 #ifdef RTE_LIBRTE_IXGBE_PMD
14560                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14561 #endif
14562         }
14563         RTE_SET_USED(en);
14564         RTE_SET_USED(rp);
14565
14566         switch (ret) {
14567         case 0:
14568                 ports[port_id].dev_conf.txmode.offloads |=
14569                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14570                 cmd_reconfig_device_queue(port_id, 1, 1);
14571                 break;
14572         case -ENODEV:
14573                 printf("invalid port_id %d\n", port_id);
14574                 break;
14575         case -ENOTSUP:
14576                 printf("not supported on port %d\n", port_id);
14577                 break;
14578         default:
14579                 printf("programming error: (%s)\n", strerror(-ret));
14580         }
14581 }
14582
14583 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14584         .f = cmd_set_macsec_offload_on_parsed,
14585         .data = NULL,
14586         .help_str = "set macsec offload <port_id> on "
14587                 "encrypt on|off replay-protect on|off",
14588         .tokens = {
14589                 (void *)&cmd_macsec_offload_on_set,
14590                 (void *)&cmd_macsec_offload_on_macsec,
14591                 (void *)&cmd_macsec_offload_on_offload,
14592                 (void *)&cmd_macsec_offload_on_port_id,
14593                 (void *)&cmd_macsec_offload_on_on,
14594                 (void *)&cmd_macsec_offload_on_encrypt,
14595                 (void *)&cmd_macsec_offload_on_en_on_off,
14596                 (void *)&cmd_macsec_offload_on_replay_protect,
14597                 (void *)&cmd_macsec_offload_on_rp_on_off,
14598                 NULL,
14599         },
14600 };
14601
14602 /* Common result structure for MACsec offload disable */
14603 struct cmd_macsec_offload_off_result {
14604         cmdline_fixed_string_t set;
14605         cmdline_fixed_string_t macsec;
14606         cmdline_fixed_string_t offload;
14607         portid_t port_id;
14608         cmdline_fixed_string_t off;
14609 };
14610
14611 /* Common CLI fields for MACsec offload disable */
14612 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14613         TOKEN_STRING_INITIALIZER
14614                 (struct cmd_macsec_offload_off_result,
14615                  set, "set");
14616 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14617         TOKEN_STRING_INITIALIZER
14618                 (struct cmd_macsec_offload_off_result,
14619                  macsec, "macsec");
14620 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14621         TOKEN_STRING_INITIALIZER
14622                 (struct cmd_macsec_offload_off_result,
14623                  offload, "offload");
14624 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14625         TOKEN_NUM_INITIALIZER
14626                 (struct cmd_macsec_offload_off_result,
14627                  port_id, UINT16);
14628 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14629         TOKEN_STRING_INITIALIZER
14630                 (struct cmd_macsec_offload_off_result,
14631                  off, "off");
14632
14633 static void
14634 cmd_set_macsec_offload_off_parsed(
14635         void *parsed_result,
14636         __rte_unused struct cmdline *cl,
14637         __rte_unused void *data)
14638 {
14639         struct cmd_macsec_offload_off_result *res = parsed_result;
14640         int ret = -ENOTSUP;
14641         struct rte_eth_dev_info dev_info;
14642         portid_t port_id = res->port_id;
14643
14644         if (port_id_is_invalid(port_id, ENABLED_WARN))
14645                 return;
14646         if (!port_is_stopped(port_id)) {
14647                 printf("Please stop port %d first\n", port_id);
14648                 return;
14649         }
14650
14651         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14652         if (ret != 0)
14653                 return;
14654
14655         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14656 #ifdef RTE_LIBRTE_IXGBE_PMD
14657                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14658 #endif
14659         }
14660         switch (ret) {
14661         case 0:
14662                 ports[port_id].dev_conf.txmode.offloads &=
14663                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14664                 cmd_reconfig_device_queue(port_id, 1, 1);
14665                 break;
14666         case -ENODEV:
14667                 printf("invalid port_id %d\n", port_id);
14668                 break;
14669         case -ENOTSUP:
14670                 printf("not supported on port %d\n", port_id);
14671                 break;
14672         default:
14673                 printf("programming error: (%s)\n", strerror(-ret));
14674         }
14675 }
14676
14677 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14678         .f = cmd_set_macsec_offload_off_parsed,
14679         .data = NULL,
14680         .help_str = "set macsec offload <port_id> off",
14681         .tokens = {
14682                 (void *)&cmd_macsec_offload_off_set,
14683                 (void *)&cmd_macsec_offload_off_macsec,
14684                 (void *)&cmd_macsec_offload_off_offload,
14685                 (void *)&cmd_macsec_offload_off_port_id,
14686                 (void *)&cmd_macsec_offload_off_off,
14687                 NULL,
14688         },
14689 };
14690
14691 /* Common result structure for MACsec secure connection configure */
14692 struct cmd_macsec_sc_result {
14693         cmdline_fixed_string_t set;
14694         cmdline_fixed_string_t macsec;
14695         cmdline_fixed_string_t sc;
14696         cmdline_fixed_string_t tx_rx;
14697         portid_t port_id;
14698         struct rte_ether_addr mac;
14699         uint16_t pi;
14700 };
14701
14702 /* Common CLI fields for MACsec secure connection configure */
14703 cmdline_parse_token_string_t cmd_macsec_sc_set =
14704         TOKEN_STRING_INITIALIZER
14705                 (struct cmd_macsec_sc_result,
14706                  set, "set");
14707 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14708         TOKEN_STRING_INITIALIZER
14709                 (struct cmd_macsec_sc_result,
14710                  macsec, "macsec");
14711 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14712         TOKEN_STRING_INITIALIZER
14713                 (struct cmd_macsec_sc_result,
14714                  sc, "sc");
14715 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14716         TOKEN_STRING_INITIALIZER
14717                 (struct cmd_macsec_sc_result,
14718                  tx_rx, "tx#rx");
14719 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14720         TOKEN_NUM_INITIALIZER
14721                 (struct cmd_macsec_sc_result,
14722                  port_id, UINT16);
14723 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14724         TOKEN_ETHERADDR_INITIALIZER
14725                 (struct cmd_macsec_sc_result,
14726                  mac);
14727 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14728         TOKEN_NUM_INITIALIZER
14729                 (struct cmd_macsec_sc_result,
14730                  pi, UINT16);
14731
14732 static void
14733 cmd_set_macsec_sc_parsed(
14734         void *parsed_result,
14735         __rte_unused struct cmdline *cl,
14736         __rte_unused void *data)
14737 {
14738         struct cmd_macsec_sc_result *res = parsed_result;
14739         int ret = -ENOTSUP;
14740         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14741
14742 #ifdef RTE_LIBRTE_IXGBE_PMD
14743         ret = is_tx ?
14744                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14745                                 res->mac.addr_bytes) :
14746                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14747                                 res->mac.addr_bytes, res->pi);
14748 #endif
14749         RTE_SET_USED(is_tx);
14750
14751         switch (ret) {
14752         case 0:
14753                 break;
14754         case -ENODEV:
14755                 printf("invalid port_id %d\n", res->port_id);
14756                 break;
14757         case -ENOTSUP:
14758                 printf("not supported on port %d\n", res->port_id);
14759                 break;
14760         default:
14761                 printf("programming error: (%s)\n", strerror(-ret));
14762         }
14763 }
14764
14765 cmdline_parse_inst_t cmd_set_macsec_sc = {
14766         .f = cmd_set_macsec_sc_parsed,
14767         .data = NULL,
14768         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14769         .tokens = {
14770                 (void *)&cmd_macsec_sc_set,
14771                 (void *)&cmd_macsec_sc_macsec,
14772                 (void *)&cmd_macsec_sc_sc,
14773                 (void *)&cmd_macsec_sc_tx_rx,
14774                 (void *)&cmd_macsec_sc_port_id,
14775                 (void *)&cmd_macsec_sc_mac,
14776                 (void *)&cmd_macsec_sc_pi,
14777                 NULL,
14778         },
14779 };
14780
14781 /* Common result structure for MACsec secure connection configure */
14782 struct cmd_macsec_sa_result {
14783         cmdline_fixed_string_t set;
14784         cmdline_fixed_string_t macsec;
14785         cmdline_fixed_string_t sa;
14786         cmdline_fixed_string_t tx_rx;
14787         portid_t port_id;
14788         uint8_t idx;
14789         uint8_t an;
14790         uint32_t pn;
14791         cmdline_fixed_string_t key;
14792 };
14793
14794 /* Common CLI fields for MACsec secure connection configure */
14795 cmdline_parse_token_string_t cmd_macsec_sa_set =
14796         TOKEN_STRING_INITIALIZER
14797                 (struct cmd_macsec_sa_result,
14798                  set, "set");
14799 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14800         TOKEN_STRING_INITIALIZER
14801                 (struct cmd_macsec_sa_result,
14802                  macsec, "macsec");
14803 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14804         TOKEN_STRING_INITIALIZER
14805                 (struct cmd_macsec_sa_result,
14806                  sa, "sa");
14807 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14808         TOKEN_STRING_INITIALIZER
14809                 (struct cmd_macsec_sa_result,
14810                  tx_rx, "tx#rx");
14811 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14812         TOKEN_NUM_INITIALIZER
14813                 (struct cmd_macsec_sa_result,
14814                  port_id, UINT16);
14815 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14816         TOKEN_NUM_INITIALIZER
14817                 (struct cmd_macsec_sa_result,
14818                  idx, UINT8);
14819 cmdline_parse_token_num_t cmd_macsec_sa_an =
14820         TOKEN_NUM_INITIALIZER
14821                 (struct cmd_macsec_sa_result,
14822                  an, UINT8);
14823 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14824         TOKEN_NUM_INITIALIZER
14825                 (struct cmd_macsec_sa_result,
14826                  pn, UINT32);
14827 cmdline_parse_token_string_t cmd_macsec_sa_key =
14828         TOKEN_STRING_INITIALIZER
14829                 (struct cmd_macsec_sa_result,
14830                  key, NULL);
14831
14832 static void
14833 cmd_set_macsec_sa_parsed(
14834         void *parsed_result,
14835         __rte_unused struct cmdline *cl,
14836         __rte_unused void *data)
14837 {
14838         struct cmd_macsec_sa_result *res = parsed_result;
14839         int ret = -ENOTSUP;
14840         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14841         uint8_t key[16] = { 0 };
14842         uint8_t xdgt0;
14843         uint8_t xdgt1;
14844         int key_len;
14845         int i;
14846
14847         key_len = strlen(res->key) / 2;
14848         if (key_len > 16)
14849                 key_len = 16;
14850
14851         for (i = 0; i < key_len; i++) {
14852                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14853                 if (xdgt0 == 0xFF)
14854                         return;
14855                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14856                 if (xdgt1 == 0xFF)
14857                         return;
14858                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14859         }
14860
14861 #ifdef RTE_LIBRTE_IXGBE_PMD
14862         ret = is_tx ?
14863                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14864                         res->idx, res->an, res->pn, key) :
14865                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14866                         res->idx, res->an, res->pn, key);
14867 #endif
14868         RTE_SET_USED(is_tx);
14869         RTE_SET_USED(key);
14870
14871         switch (ret) {
14872         case 0:
14873                 break;
14874         case -EINVAL:
14875                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14876                 break;
14877         case -ENODEV:
14878                 printf("invalid port_id %d\n", res->port_id);
14879                 break;
14880         case -ENOTSUP:
14881                 printf("not supported on port %d\n", res->port_id);
14882                 break;
14883         default:
14884                 printf("programming error: (%s)\n", strerror(-ret));
14885         }
14886 }
14887
14888 cmdline_parse_inst_t cmd_set_macsec_sa = {
14889         .f = cmd_set_macsec_sa_parsed,
14890         .data = NULL,
14891         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14892         .tokens = {
14893                 (void *)&cmd_macsec_sa_set,
14894                 (void *)&cmd_macsec_sa_macsec,
14895                 (void *)&cmd_macsec_sa_sa,
14896                 (void *)&cmd_macsec_sa_tx_rx,
14897                 (void *)&cmd_macsec_sa_port_id,
14898                 (void *)&cmd_macsec_sa_idx,
14899                 (void *)&cmd_macsec_sa_an,
14900                 (void *)&cmd_macsec_sa_pn,
14901                 (void *)&cmd_macsec_sa_key,
14902                 NULL,
14903         },
14904 };
14905
14906 /* VF unicast promiscuous mode configuration */
14907
14908 /* Common result structure for VF unicast promiscuous mode */
14909 struct cmd_vf_promisc_result {
14910         cmdline_fixed_string_t set;
14911         cmdline_fixed_string_t vf;
14912         cmdline_fixed_string_t promisc;
14913         portid_t port_id;
14914         uint32_t vf_id;
14915         cmdline_fixed_string_t on_off;
14916 };
14917
14918 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14919 cmdline_parse_token_string_t cmd_vf_promisc_set =
14920         TOKEN_STRING_INITIALIZER
14921                 (struct cmd_vf_promisc_result,
14922                  set, "set");
14923 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14924         TOKEN_STRING_INITIALIZER
14925                 (struct cmd_vf_promisc_result,
14926                  vf, "vf");
14927 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14928         TOKEN_STRING_INITIALIZER
14929                 (struct cmd_vf_promisc_result,
14930                  promisc, "promisc");
14931 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14932         TOKEN_NUM_INITIALIZER
14933                 (struct cmd_vf_promisc_result,
14934                  port_id, UINT16);
14935 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14936         TOKEN_NUM_INITIALIZER
14937                 (struct cmd_vf_promisc_result,
14938                  vf_id, UINT32);
14939 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14940         TOKEN_STRING_INITIALIZER
14941                 (struct cmd_vf_promisc_result,
14942                  on_off, "on#off");
14943
14944 static void
14945 cmd_set_vf_promisc_parsed(
14946         void *parsed_result,
14947         __rte_unused struct cmdline *cl,
14948         __rte_unused void *data)
14949 {
14950         struct cmd_vf_promisc_result *res = parsed_result;
14951         int ret = -ENOTSUP;
14952
14953         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14954
14955         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14956                 return;
14957
14958 #ifdef RTE_LIBRTE_I40E_PMD
14959         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
14960                                                   res->vf_id, is_on);
14961 #endif
14962
14963         switch (ret) {
14964         case 0:
14965                 break;
14966         case -EINVAL:
14967                 printf("invalid vf_id %d\n", res->vf_id);
14968                 break;
14969         case -ENODEV:
14970                 printf("invalid port_id %d\n", res->port_id);
14971                 break;
14972         case -ENOTSUP:
14973                 printf("function not implemented\n");
14974                 break;
14975         default:
14976                 printf("programming error: (%s)\n", strerror(-ret));
14977         }
14978 }
14979
14980 cmdline_parse_inst_t cmd_set_vf_promisc = {
14981         .f = cmd_set_vf_promisc_parsed,
14982         .data = NULL,
14983         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
14984                 "Set unicast promiscuous mode for a VF from the PF",
14985         .tokens = {
14986                 (void *)&cmd_vf_promisc_set,
14987                 (void *)&cmd_vf_promisc_vf,
14988                 (void *)&cmd_vf_promisc_promisc,
14989                 (void *)&cmd_vf_promisc_port_id,
14990                 (void *)&cmd_vf_promisc_vf_id,
14991                 (void *)&cmd_vf_promisc_on_off,
14992                 NULL,
14993         },
14994 };
14995
14996 /* VF multicast promiscuous mode configuration */
14997
14998 /* Common result structure for VF multicast promiscuous mode */
14999 struct cmd_vf_allmulti_result {
15000         cmdline_fixed_string_t set;
15001         cmdline_fixed_string_t vf;
15002         cmdline_fixed_string_t allmulti;
15003         portid_t port_id;
15004         uint32_t vf_id;
15005         cmdline_fixed_string_t on_off;
15006 };
15007
15008 /* Common CLI fields for VF multicast promiscuous mode enable disable */
15009 cmdline_parse_token_string_t cmd_vf_allmulti_set =
15010         TOKEN_STRING_INITIALIZER
15011                 (struct cmd_vf_allmulti_result,
15012                  set, "set");
15013 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
15014         TOKEN_STRING_INITIALIZER
15015                 (struct cmd_vf_allmulti_result,
15016                  vf, "vf");
15017 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
15018         TOKEN_STRING_INITIALIZER
15019                 (struct cmd_vf_allmulti_result,
15020                  allmulti, "allmulti");
15021 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
15022         TOKEN_NUM_INITIALIZER
15023                 (struct cmd_vf_allmulti_result,
15024                  port_id, UINT16);
15025 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
15026         TOKEN_NUM_INITIALIZER
15027                 (struct cmd_vf_allmulti_result,
15028                  vf_id, UINT32);
15029 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15030         TOKEN_STRING_INITIALIZER
15031                 (struct cmd_vf_allmulti_result,
15032                  on_off, "on#off");
15033
15034 static void
15035 cmd_set_vf_allmulti_parsed(
15036         void *parsed_result,
15037         __rte_unused struct cmdline *cl,
15038         __rte_unused void *data)
15039 {
15040         struct cmd_vf_allmulti_result *res = parsed_result;
15041         int ret = -ENOTSUP;
15042
15043         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15044
15045         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15046                 return;
15047
15048 #ifdef RTE_LIBRTE_I40E_PMD
15049         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15050                                                     res->vf_id, is_on);
15051 #endif
15052
15053         switch (ret) {
15054         case 0:
15055                 break;
15056         case -EINVAL:
15057                 printf("invalid vf_id %d\n", res->vf_id);
15058                 break;
15059         case -ENODEV:
15060                 printf("invalid port_id %d\n", res->port_id);
15061                 break;
15062         case -ENOTSUP:
15063                 printf("function not implemented\n");
15064                 break;
15065         default:
15066                 printf("programming error: (%s)\n", strerror(-ret));
15067         }
15068 }
15069
15070 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15071         .f = cmd_set_vf_allmulti_parsed,
15072         .data = NULL,
15073         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15074                 "Set multicast promiscuous mode for a VF from the PF",
15075         .tokens = {
15076                 (void *)&cmd_vf_allmulti_set,
15077                 (void *)&cmd_vf_allmulti_vf,
15078                 (void *)&cmd_vf_allmulti_allmulti,
15079                 (void *)&cmd_vf_allmulti_port_id,
15080                 (void *)&cmd_vf_allmulti_vf_id,
15081                 (void *)&cmd_vf_allmulti_on_off,
15082                 NULL,
15083         },
15084 };
15085
15086 /* vf broadcast mode configuration */
15087
15088 /* Common result structure for vf broadcast */
15089 struct cmd_set_vf_broadcast_result {
15090         cmdline_fixed_string_t set;
15091         cmdline_fixed_string_t vf;
15092         cmdline_fixed_string_t broadcast;
15093         portid_t port_id;
15094         uint16_t vf_id;
15095         cmdline_fixed_string_t on_off;
15096 };
15097
15098 /* Common CLI fields for vf broadcast enable disable */
15099 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15100         TOKEN_STRING_INITIALIZER
15101                 (struct cmd_set_vf_broadcast_result,
15102                  set, "set");
15103 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15104         TOKEN_STRING_INITIALIZER
15105                 (struct cmd_set_vf_broadcast_result,
15106                  vf, "vf");
15107 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15108         TOKEN_STRING_INITIALIZER
15109                 (struct cmd_set_vf_broadcast_result,
15110                  broadcast, "broadcast");
15111 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15112         TOKEN_NUM_INITIALIZER
15113                 (struct cmd_set_vf_broadcast_result,
15114                  port_id, UINT16);
15115 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15116         TOKEN_NUM_INITIALIZER
15117                 (struct cmd_set_vf_broadcast_result,
15118                  vf_id, UINT16);
15119 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15120         TOKEN_STRING_INITIALIZER
15121                 (struct cmd_set_vf_broadcast_result,
15122                  on_off, "on#off");
15123
15124 static void
15125 cmd_set_vf_broadcast_parsed(
15126         void *parsed_result,
15127         __rte_unused struct cmdline *cl,
15128         __rte_unused void *data)
15129 {
15130         struct cmd_set_vf_broadcast_result *res = parsed_result;
15131         int ret = -ENOTSUP;
15132
15133         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15134
15135         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15136                 return;
15137
15138 #ifdef RTE_LIBRTE_I40E_PMD
15139         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15140                                             res->vf_id, is_on);
15141 #endif
15142
15143         switch (ret) {
15144         case 0:
15145                 break;
15146         case -EINVAL:
15147                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15148                 break;
15149         case -ENODEV:
15150                 printf("invalid port_id %d\n", res->port_id);
15151                 break;
15152         case -ENOTSUP:
15153                 printf("function not implemented\n");
15154                 break;
15155         default:
15156                 printf("programming error: (%s)\n", strerror(-ret));
15157         }
15158 }
15159
15160 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15161         .f = cmd_set_vf_broadcast_parsed,
15162         .data = NULL,
15163         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15164         .tokens = {
15165                 (void *)&cmd_set_vf_broadcast_set,
15166                 (void *)&cmd_set_vf_broadcast_vf,
15167                 (void *)&cmd_set_vf_broadcast_broadcast,
15168                 (void *)&cmd_set_vf_broadcast_port_id,
15169                 (void *)&cmd_set_vf_broadcast_vf_id,
15170                 (void *)&cmd_set_vf_broadcast_on_off,
15171                 NULL,
15172         },
15173 };
15174
15175 /* vf vlan tag configuration */
15176
15177 /* Common result structure for vf vlan tag */
15178 struct cmd_set_vf_vlan_tag_result {
15179         cmdline_fixed_string_t set;
15180         cmdline_fixed_string_t vf;
15181         cmdline_fixed_string_t vlan;
15182         cmdline_fixed_string_t tag;
15183         portid_t port_id;
15184         uint16_t vf_id;
15185         cmdline_fixed_string_t on_off;
15186 };
15187
15188 /* Common CLI fields for vf vlan tag enable disable */
15189 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15190         TOKEN_STRING_INITIALIZER
15191                 (struct cmd_set_vf_vlan_tag_result,
15192                  set, "set");
15193 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15194         TOKEN_STRING_INITIALIZER
15195                 (struct cmd_set_vf_vlan_tag_result,
15196                  vf, "vf");
15197 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15198         TOKEN_STRING_INITIALIZER
15199                 (struct cmd_set_vf_vlan_tag_result,
15200                  vlan, "vlan");
15201 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15202         TOKEN_STRING_INITIALIZER
15203                 (struct cmd_set_vf_vlan_tag_result,
15204                  tag, "tag");
15205 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15206         TOKEN_NUM_INITIALIZER
15207                 (struct cmd_set_vf_vlan_tag_result,
15208                  port_id, UINT16);
15209 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15210         TOKEN_NUM_INITIALIZER
15211                 (struct cmd_set_vf_vlan_tag_result,
15212                  vf_id, UINT16);
15213 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15214         TOKEN_STRING_INITIALIZER
15215                 (struct cmd_set_vf_vlan_tag_result,
15216                  on_off, "on#off");
15217
15218 static void
15219 cmd_set_vf_vlan_tag_parsed(
15220         void *parsed_result,
15221         __rte_unused struct cmdline *cl,
15222         __rte_unused void *data)
15223 {
15224         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15225         int ret = -ENOTSUP;
15226
15227         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15228
15229         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15230                 return;
15231
15232 #ifdef RTE_LIBRTE_I40E_PMD
15233         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15234                                            res->vf_id, is_on);
15235 #endif
15236
15237         switch (ret) {
15238         case 0:
15239                 break;
15240         case -EINVAL:
15241                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15242                 break;
15243         case -ENODEV:
15244                 printf("invalid port_id %d\n", res->port_id);
15245                 break;
15246         case -ENOTSUP:
15247                 printf("function not implemented\n");
15248                 break;
15249         default:
15250                 printf("programming error: (%s)\n", strerror(-ret));
15251         }
15252 }
15253
15254 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15255         .f = cmd_set_vf_vlan_tag_parsed,
15256         .data = NULL,
15257         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15258         .tokens = {
15259                 (void *)&cmd_set_vf_vlan_tag_set,
15260                 (void *)&cmd_set_vf_vlan_tag_vf,
15261                 (void *)&cmd_set_vf_vlan_tag_vlan,
15262                 (void *)&cmd_set_vf_vlan_tag_tag,
15263                 (void *)&cmd_set_vf_vlan_tag_port_id,
15264                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15265                 (void *)&cmd_set_vf_vlan_tag_on_off,
15266                 NULL,
15267         },
15268 };
15269
15270 /* Common definition of VF and TC TX bandwidth configuration */
15271 struct cmd_vf_tc_bw_result {
15272         cmdline_fixed_string_t set;
15273         cmdline_fixed_string_t vf;
15274         cmdline_fixed_string_t tc;
15275         cmdline_fixed_string_t tx;
15276         cmdline_fixed_string_t min_bw;
15277         cmdline_fixed_string_t max_bw;
15278         cmdline_fixed_string_t strict_link_prio;
15279         portid_t port_id;
15280         uint16_t vf_id;
15281         uint8_t tc_no;
15282         uint32_t bw;
15283         cmdline_fixed_string_t bw_list;
15284         uint8_t tc_map;
15285 };
15286
15287 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15288         TOKEN_STRING_INITIALIZER
15289                 (struct cmd_vf_tc_bw_result,
15290                  set, "set");
15291 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15292         TOKEN_STRING_INITIALIZER
15293                 (struct cmd_vf_tc_bw_result,
15294                  vf, "vf");
15295 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15296         TOKEN_STRING_INITIALIZER
15297                 (struct cmd_vf_tc_bw_result,
15298                  tc, "tc");
15299 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15300         TOKEN_STRING_INITIALIZER
15301                 (struct cmd_vf_tc_bw_result,
15302                  tx, "tx");
15303 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15304         TOKEN_STRING_INITIALIZER
15305                 (struct cmd_vf_tc_bw_result,
15306                  strict_link_prio, "strict-link-priority");
15307 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15308         TOKEN_STRING_INITIALIZER
15309                 (struct cmd_vf_tc_bw_result,
15310                  min_bw, "min-bandwidth");
15311 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15312         TOKEN_STRING_INITIALIZER
15313                 (struct cmd_vf_tc_bw_result,
15314                  max_bw, "max-bandwidth");
15315 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15316         TOKEN_NUM_INITIALIZER
15317                 (struct cmd_vf_tc_bw_result,
15318                  port_id, UINT16);
15319 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15320         TOKEN_NUM_INITIALIZER
15321                 (struct cmd_vf_tc_bw_result,
15322                  vf_id, UINT16);
15323 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15324         TOKEN_NUM_INITIALIZER
15325                 (struct cmd_vf_tc_bw_result,
15326                  tc_no, UINT8);
15327 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15328         TOKEN_NUM_INITIALIZER
15329                 (struct cmd_vf_tc_bw_result,
15330                  bw, UINT32);
15331 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15332         TOKEN_STRING_INITIALIZER
15333                 (struct cmd_vf_tc_bw_result,
15334                  bw_list, NULL);
15335 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15336         TOKEN_NUM_INITIALIZER
15337                 (struct cmd_vf_tc_bw_result,
15338                  tc_map, UINT8);
15339
15340 /* VF max bandwidth setting */
15341 static void
15342 cmd_vf_max_bw_parsed(
15343         void *parsed_result,
15344         __rte_unused struct cmdline *cl,
15345         __rte_unused void *data)
15346 {
15347         struct cmd_vf_tc_bw_result *res = parsed_result;
15348         int ret = -ENOTSUP;
15349
15350         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15351                 return;
15352
15353 #ifdef RTE_LIBRTE_I40E_PMD
15354         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15355                                          res->vf_id, res->bw);
15356 #endif
15357
15358         switch (ret) {
15359         case 0:
15360                 break;
15361         case -EINVAL:
15362                 printf("invalid vf_id %d or bandwidth %d\n",
15363                        res->vf_id, res->bw);
15364                 break;
15365         case -ENODEV:
15366                 printf("invalid port_id %d\n", res->port_id);
15367                 break;
15368         case -ENOTSUP:
15369                 printf("function not implemented\n");
15370                 break;
15371         default:
15372                 printf("programming error: (%s)\n", strerror(-ret));
15373         }
15374 }
15375
15376 cmdline_parse_inst_t cmd_vf_max_bw = {
15377         .f = cmd_vf_max_bw_parsed,
15378         .data = NULL,
15379         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15380         .tokens = {
15381                 (void *)&cmd_vf_tc_bw_set,
15382                 (void *)&cmd_vf_tc_bw_vf,
15383                 (void *)&cmd_vf_tc_bw_tx,
15384                 (void *)&cmd_vf_tc_bw_max_bw,
15385                 (void *)&cmd_vf_tc_bw_port_id,
15386                 (void *)&cmd_vf_tc_bw_vf_id,
15387                 (void *)&cmd_vf_tc_bw_bw,
15388                 NULL,
15389         },
15390 };
15391
15392 static int
15393 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15394                            uint8_t *tc_num,
15395                            char *str)
15396 {
15397         uint32_t size;
15398         const char *p, *p0 = str;
15399         char s[256];
15400         char *end;
15401         char *str_fld[16];
15402         uint16_t i;
15403         int ret;
15404
15405         p = strchr(p0, '(');
15406         if (p == NULL) {
15407                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15408                 return -1;
15409         }
15410         p++;
15411         p0 = strchr(p, ')');
15412         if (p0 == NULL) {
15413                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15414                 return -1;
15415         }
15416         size = p0 - p;
15417         if (size >= sizeof(s)) {
15418                 printf("The string size exceeds the internal buffer size\n");
15419                 return -1;
15420         }
15421         snprintf(s, sizeof(s), "%.*s", size, p);
15422         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15423         if (ret <= 0) {
15424                 printf("Failed to get the bandwidth list. ");
15425                 return -1;
15426         }
15427         *tc_num = ret;
15428         for (i = 0; i < ret; i++)
15429                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15430
15431         return 0;
15432 }
15433
15434 /* TC min bandwidth setting */
15435 static void
15436 cmd_vf_tc_min_bw_parsed(
15437         void *parsed_result,
15438         __rte_unused struct cmdline *cl,
15439         __rte_unused void *data)
15440 {
15441         struct cmd_vf_tc_bw_result *res = parsed_result;
15442         uint8_t tc_num;
15443         uint8_t bw[16];
15444         int ret = -ENOTSUP;
15445
15446         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15447                 return;
15448
15449         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15450         if (ret)
15451                 return;
15452
15453 #ifdef RTE_LIBRTE_I40E_PMD
15454         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15455                                               tc_num, bw);
15456 #endif
15457
15458         switch (ret) {
15459         case 0:
15460                 break;
15461         case -EINVAL:
15462                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15463                 break;
15464         case -ENODEV:
15465                 printf("invalid port_id %d\n", res->port_id);
15466                 break;
15467         case -ENOTSUP:
15468                 printf("function not implemented\n");
15469                 break;
15470         default:
15471                 printf("programming error: (%s)\n", strerror(-ret));
15472         }
15473 }
15474
15475 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15476         .f = cmd_vf_tc_min_bw_parsed,
15477         .data = NULL,
15478         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15479                     " <bw1, bw2, ...>",
15480         .tokens = {
15481                 (void *)&cmd_vf_tc_bw_set,
15482                 (void *)&cmd_vf_tc_bw_vf,
15483                 (void *)&cmd_vf_tc_bw_tc,
15484                 (void *)&cmd_vf_tc_bw_tx,
15485                 (void *)&cmd_vf_tc_bw_min_bw,
15486                 (void *)&cmd_vf_tc_bw_port_id,
15487                 (void *)&cmd_vf_tc_bw_vf_id,
15488                 (void *)&cmd_vf_tc_bw_bw_list,
15489                 NULL,
15490         },
15491 };
15492
15493 static void
15494 cmd_tc_min_bw_parsed(
15495         void *parsed_result,
15496         __rte_unused struct cmdline *cl,
15497         __rte_unused void *data)
15498 {
15499         struct cmd_vf_tc_bw_result *res = parsed_result;
15500         struct rte_port *port;
15501         uint8_t tc_num;
15502         uint8_t bw[16];
15503         int ret = -ENOTSUP;
15504
15505         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15506                 return;
15507
15508         port = &ports[res->port_id];
15509         /** Check if the port is not started **/
15510         if (port->port_status != RTE_PORT_STOPPED) {
15511                 printf("Please stop port %d first\n", res->port_id);
15512                 return;
15513         }
15514
15515         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15516         if (ret)
15517                 return;
15518
15519 #ifdef RTE_LIBRTE_IXGBE_PMD
15520         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15521 #endif
15522
15523         switch (ret) {
15524         case 0:
15525                 break;
15526         case -EINVAL:
15527                 printf("invalid bandwidth\n");
15528                 break;
15529         case -ENODEV:
15530                 printf("invalid port_id %d\n", res->port_id);
15531                 break;
15532         case -ENOTSUP:
15533                 printf("function not implemented\n");
15534                 break;
15535         default:
15536                 printf("programming error: (%s)\n", strerror(-ret));
15537         }
15538 }
15539
15540 cmdline_parse_inst_t cmd_tc_min_bw = {
15541         .f = cmd_tc_min_bw_parsed,
15542         .data = NULL,
15543         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15544         .tokens = {
15545                 (void *)&cmd_vf_tc_bw_set,
15546                 (void *)&cmd_vf_tc_bw_tc,
15547                 (void *)&cmd_vf_tc_bw_tx,
15548                 (void *)&cmd_vf_tc_bw_min_bw,
15549                 (void *)&cmd_vf_tc_bw_port_id,
15550                 (void *)&cmd_vf_tc_bw_bw_list,
15551                 NULL,
15552         },
15553 };
15554
15555 /* TC max bandwidth setting */
15556 static void
15557 cmd_vf_tc_max_bw_parsed(
15558         void *parsed_result,
15559         __rte_unused struct cmdline *cl,
15560         __rte_unused void *data)
15561 {
15562         struct cmd_vf_tc_bw_result *res = parsed_result;
15563         int ret = -ENOTSUP;
15564
15565         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15566                 return;
15567
15568 #ifdef RTE_LIBRTE_I40E_PMD
15569         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15570                                             res->tc_no, res->bw);
15571 #endif
15572
15573         switch (ret) {
15574         case 0:
15575                 break;
15576         case -EINVAL:
15577                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15578                        res->vf_id, res->tc_no, res->bw);
15579                 break;
15580         case -ENODEV:
15581                 printf("invalid port_id %d\n", res->port_id);
15582                 break;
15583         case -ENOTSUP:
15584                 printf("function not implemented\n");
15585                 break;
15586         default:
15587                 printf("programming error: (%s)\n", strerror(-ret));
15588         }
15589 }
15590
15591 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15592         .f = cmd_vf_tc_max_bw_parsed,
15593         .data = NULL,
15594         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15595                     " <bandwidth>",
15596         .tokens = {
15597                 (void *)&cmd_vf_tc_bw_set,
15598                 (void *)&cmd_vf_tc_bw_vf,
15599                 (void *)&cmd_vf_tc_bw_tc,
15600                 (void *)&cmd_vf_tc_bw_tx,
15601                 (void *)&cmd_vf_tc_bw_max_bw,
15602                 (void *)&cmd_vf_tc_bw_port_id,
15603                 (void *)&cmd_vf_tc_bw_vf_id,
15604                 (void *)&cmd_vf_tc_bw_tc_no,
15605                 (void *)&cmd_vf_tc_bw_bw,
15606                 NULL,
15607         },
15608 };
15609
15610 /** Set VXLAN encapsulation details */
15611 struct cmd_set_vxlan_result {
15612         cmdline_fixed_string_t set;
15613         cmdline_fixed_string_t vxlan;
15614         cmdline_fixed_string_t pos_token;
15615         cmdline_fixed_string_t ip_version;
15616         uint32_t vlan_present:1;
15617         uint32_t vni;
15618         uint16_t udp_src;
15619         uint16_t udp_dst;
15620         cmdline_ipaddr_t ip_src;
15621         cmdline_ipaddr_t ip_dst;
15622         uint16_t tci;
15623         uint8_t tos;
15624         uint8_t ttl;
15625         struct rte_ether_addr eth_src;
15626         struct rte_ether_addr eth_dst;
15627 };
15628
15629 cmdline_parse_token_string_t cmd_set_vxlan_set =
15630         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15631 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15632         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15633 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15634         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15635                                  "vxlan-tos-ttl");
15636 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15637         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15638                                  "vxlan-with-vlan");
15639 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15640         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15641                                  "ip-version");
15642 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15643         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15644                                  "ipv4#ipv6");
15645 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15646         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15647                                  "vni");
15648 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15649         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15650 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15651         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15652                                  "udp-src");
15653 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15654         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15655 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15656         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15657                                  "udp-dst");
15658 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15659         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15660 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15661         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15662                                  "ip-tos");
15663 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15664         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15665 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15666         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15667                                  "ip-ttl");
15668 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15669         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15670 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15671         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15672                                  "ip-src");
15673 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15674         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15675 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15676         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15677                                  "ip-dst");
15678 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15679         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15680 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15681         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15682                                  "vlan-tci");
15683 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15684         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15685 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15686         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15687                                  "eth-src");
15688 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15689         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15690 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15691         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15692                                  "eth-dst");
15693 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15694         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15695
15696 static void cmd_set_vxlan_parsed(void *parsed_result,
15697         __rte_unused struct cmdline *cl,
15698         __rte_unused void *data)
15699 {
15700         struct cmd_set_vxlan_result *res = parsed_result;
15701         union {
15702                 uint32_t vxlan_id;
15703                 uint8_t vni[4];
15704         } id = {
15705                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15706         };
15707
15708         vxlan_encap_conf.select_tos_ttl = 0;
15709         if (strcmp(res->vxlan, "vxlan") == 0)
15710                 vxlan_encap_conf.select_vlan = 0;
15711         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15712                 vxlan_encap_conf.select_vlan = 1;
15713         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15714                 vxlan_encap_conf.select_vlan = 0;
15715                 vxlan_encap_conf.select_tos_ttl = 1;
15716         }
15717         if (strcmp(res->ip_version, "ipv4") == 0)
15718                 vxlan_encap_conf.select_ipv4 = 1;
15719         else if (strcmp(res->ip_version, "ipv6") == 0)
15720                 vxlan_encap_conf.select_ipv4 = 0;
15721         else
15722                 return;
15723         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15724         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15725         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15726         vxlan_encap_conf.ip_tos = res->tos;
15727         vxlan_encap_conf.ip_ttl = res->ttl;
15728         if (vxlan_encap_conf.select_ipv4) {
15729                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15730                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15731         } else {
15732                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15733                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15734         }
15735         if (vxlan_encap_conf.select_vlan)
15736                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15737         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15738                    RTE_ETHER_ADDR_LEN);
15739         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15740                    RTE_ETHER_ADDR_LEN);
15741 }
15742
15743 cmdline_parse_inst_t cmd_set_vxlan = {
15744         .f = cmd_set_vxlan_parsed,
15745         .data = NULL,
15746         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15747                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15748                 " eth-src <eth-src> eth-dst <eth-dst>",
15749         .tokens = {
15750                 (void *)&cmd_set_vxlan_set,
15751                 (void *)&cmd_set_vxlan_vxlan,
15752                 (void *)&cmd_set_vxlan_ip_version,
15753                 (void *)&cmd_set_vxlan_ip_version_value,
15754                 (void *)&cmd_set_vxlan_vni,
15755                 (void *)&cmd_set_vxlan_vni_value,
15756                 (void *)&cmd_set_vxlan_udp_src,
15757                 (void *)&cmd_set_vxlan_udp_src_value,
15758                 (void *)&cmd_set_vxlan_udp_dst,
15759                 (void *)&cmd_set_vxlan_udp_dst_value,
15760                 (void *)&cmd_set_vxlan_ip_src,
15761                 (void *)&cmd_set_vxlan_ip_src_value,
15762                 (void *)&cmd_set_vxlan_ip_dst,
15763                 (void *)&cmd_set_vxlan_ip_dst_value,
15764                 (void *)&cmd_set_vxlan_eth_src,
15765                 (void *)&cmd_set_vxlan_eth_src_value,
15766                 (void *)&cmd_set_vxlan_eth_dst,
15767                 (void *)&cmd_set_vxlan_eth_dst_value,
15768                 NULL,
15769         },
15770 };
15771
15772 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15773         .f = cmd_set_vxlan_parsed,
15774         .data = NULL,
15775         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15776                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15777                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15778                 " eth-dst <eth-dst>",
15779         .tokens = {
15780                 (void *)&cmd_set_vxlan_set,
15781                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15782                 (void *)&cmd_set_vxlan_ip_version,
15783                 (void *)&cmd_set_vxlan_ip_version_value,
15784                 (void *)&cmd_set_vxlan_vni,
15785                 (void *)&cmd_set_vxlan_vni_value,
15786                 (void *)&cmd_set_vxlan_udp_src,
15787                 (void *)&cmd_set_vxlan_udp_src_value,
15788                 (void *)&cmd_set_vxlan_udp_dst,
15789                 (void *)&cmd_set_vxlan_udp_dst_value,
15790                 (void *)&cmd_set_vxlan_ip_tos,
15791                 (void *)&cmd_set_vxlan_ip_tos_value,
15792                 (void *)&cmd_set_vxlan_ip_ttl,
15793                 (void *)&cmd_set_vxlan_ip_ttl_value,
15794                 (void *)&cmd_set_vxlan_ip_src,
15795                 (void *)&cmd_set_vxlan_ip_src_value,
15796                 (void *)&cmd_set_vxlan_ip_dst,
15797                 (void *)&cmd_set_vxlan_ip_dst_value,
15798                 (void *)&cmd_set_vxlan_eth_src,
15799                 (void *)&cmd_set_vxlan_eth_src_value,
15800                 (void *)&cmd_set_vxlan_eth_dst,
15801                 (void *)&cmd_set_vxlan_eth_dst_value,
15802                 NULL,
15803         },
15804 };
15805
15806 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15807         .f = cmd_set_vxlan_parsed,
15808         .data = NULL,
15809         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15810                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15811                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15812                 " <eth-dst>",
15813         .tokens = {
15814                 (void *)&cmd_set_vxlan_set,
15815                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15816                 (void *)&cmd_set_vxlan_ip_version,
15817                 (void *)&cmd_set_vxlan_ip_version_value,
15818                 (void *)&cmd_set_vxlan_vni,
15819                 (void *)&cmd_set_vxlan_vni_value,
15820                 (void *)&cmd_set_vxlan_udp_src,
15821                 (void *)&cmd_set_vxlan_udp_src_value,
15822                 (void *)&cmd_set_vxlan_udp_dst,
15823                 (void *)&cmd_set_vxlan_udp_dst_value,
15824                 (void *)&cmd_set_vxlan_ip_src,
15825                 (void *)&cmd_set_vxlan_ip_src_value,
15826                 (void *)&cmd_set_vxlan_ip_dst,
15827                 (void *)&cmd_set_vxlan_ip_dst_value,
15828                 (void *)&cmd_set_vxlan_vlan,
15829                 (void *)&cmd_set_vxlan_vlan_value,
15830                 (void *)&cmd_set_vxlan_eth_src,
15831                 (void *)&cmd_set_vxlan_eth_src_value,
15832                 (void *)&cmd_set_vxlan_eth_dst,
15833                 (void *)&cmd_set_vxlan_eth_dst_value,
15834                 NULL,
15835         },
15836 };
15837
15838 /** Set NVGRE encapsulation details */
15839 struct cmd_set_nvgre_result {
15840         cmdline_fixed_string_t set;
15841         cmdline_fixed_string_t nvgre;
15842         cmdline_fixed_string_t pos_token;
15843         cmdline_fixed_string_t ip_version;
15844         uint32_t tni;
15845         cmdline_ipaddr_t ip_src;
15846         cmdline_ipaddr_t ip_dst;
15847         uint16_t tci;
15848         struct rte_ether_addr eth_src;
15849         struct rte_ether_addr eth_dst;
15850 };
15851
15852 cmdline_parse_token_string_t cmd_set_nvgre_set =
15853         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15854 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15855         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15856 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15857         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15858                                  "nvgre-with-vlan");
15859 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15860         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15861                                  "ip-version");
15862 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15863         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15864                                  "ipv4#ipv6");
15865 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15866         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15867                                  "tni");
15868 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15869         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15870 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15871         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15872                                  "ip-src");
15873 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15874         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15875 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15876         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15877                                  "ip-dst");
15878 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15879         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15880 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15881         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15882                                  "vlan-tci");
15883 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15884         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15885 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15886         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15887                                  "eth-src");
15888 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15889         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15890 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15891         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15892                                  "eth-dst");
15893 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15894         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15895
15896 static void cmd_set_nvgre_parsed(void *parsed_result,
15897         __rte_unused struct cmdline *cl,
15898         __rte_unused void *data)
15899 {
15900         struct cmd_set_nvgre_result *res = parsed_result;
15901         union {
15902                 uint32_t nvgre_tni;
15903                 uint8_t tni[4];
15904         } id = {
15905                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15906         };
15907
15908         if (strcmp(res->nvgre, "nvgre") == 0)
15909                 nvgre_encap_conf.select_vlan = 0;
15910         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15911                 nvgre_encap_conf.select_vlan = 1;
15912         if (strcmp(res->ip_version, "ipv4") == 0)
15913                 nvgre_encap_conf.select_ipv4 = 1;
15914         else if (strcmp(res->ip_version, "ipv6") == 0)
15915                 nvgre_encap_conf.select_ipv4 = 0;
15916         else
15917                 return;
15918         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15919         if (nvgre_encap_conf.select_ipv4) {
15920                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15921                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15922         } else {
15923                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15924                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15925         }
15926         if (nvgre_encap_conf.select_vlan)
15927                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15928         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15929                    RTE_ETHER_ADDR_LEN);
15930         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15931                    RTE_ETHER_ADDR_LEN);
15932 }
15933
15934 cmdline_parse_inst_t cmd_set_nvgre = {
15935         .f = cmd_set_nvgre_parsed,
15936         .data = NULL,
15937         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15938                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15939                 " eth-dst <eth-dst>",
15940         .tokens = {
15941                 (void *)&cmd_set_nvgre_set,
15942                 (void *)&cmd_set_nvgre_nvgre,
15943                 (void *)&cmd_set_nvgre_ip_version,
15944                 (void *)&cmd_set_nvgre_ip_version_value,
15945                 (void *)&cmd_set_nvgre_tni,
15946                 (void *)&cmd_set_nvgre_tni_value,
15947                 (void *)&cmd_set_nvgre_ip_src,
15948                 (void *)&cmd_set_nvgre_ip_src_value,
15949                 (void *)&cmd_set_nvgre_ip_dst,
15950                 (void *)&cmd_set_nvgre_ip_dst_value,
15951                 (void *)&cmd_set_nvgre_eth_src,
15952                 (void *)&cmd_set_nvgre_eth_src_value,
15953                 (void *)&cmd_set_nvgre_eth_dst,
15954                 (void *)&cmd_set_nvgre_eth_dst_value,
15955                 NULL,
15956         },
15957 };
15958
15959 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
15960         .f = cmd_set_nvgre_parsed,
15961         .data = NULL,
15962         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
15963                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15964                 " eth-src <eth-src> eth-dst <eth-dst>",
15965         .tokens = {
15966                 (void *)&cmd_set_nvgre_set,
15967                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
15968                 (void *)&cmd_set_nvgre_ip_version,
15969                 (void *)&cmd_set_nvgre_ip_version_value,
15970                 (void *)&cmd_set_nvgre_tni,
15971                 (void *)&cmd_set_nvgre_tni_value,
15972                 (void *)&cmd_set_nvgre_ip_src,
15973                 (void *)&cmd_set_nvgre_ip_src_value,
15974                 (void *)&cmd_set_nvgre_ip_dst,
15975                 (void *)&cmd_set_nvgre_ip_dst_value,
15976                 (void *)&cmd_set_nvgre_vlan,
15977                 (void *)&cmd_set_nvgre_vlan_value,
15978                 (void *)&cmd_set_nvgre_eth_src,
15979                 (void *)&cmd_set_nvgre_eth_src_value,
15980                 (void *)&cmd_set_nvgre_eth_dst,
15981                 (void *)&cmd_set_nvgre_eth_dst_value,
15982                 NULL,
15983         },
15984 };
15985
15986 /** Set L2 encapsulation details */
15987 struct cmd_set_l2_encap_result {
15988         cmdline_fixed_string_t set;
15989         cmdline_fixed_string_t l2_encap;
15990         cmdline_fixed_string_t pos_token;
15991         cmdline_fixed_string_t ip_version;
15992         uint32_t vlan_present:1;
15993         uint16_t tci;
15994         struct rte_ether_addr eth_src;
15995         struct rte_ether_addr eth_dst;
15996 };
15997
15998 cmdline_parse_token_string_t cmd_set_l2_encap_set =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
16000 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
16001         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
16002 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
16003         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
16004                                  "l2_encap-with-vlan");
16005 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
16006         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16007                                  "ip-version");
16008 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
16009         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
16010                                  "ipv4#ipv6");
16011 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
16012         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16013                                  "vlan-tci");
16014 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
16015         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
16016 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
16017         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16018                                  "eth-src");
16019 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
16020         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
16021 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
16022         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16023                                  "eth-dst");
16024 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
16025         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
16026
16027 static void cmd_set_l2_encap_parsed(void *parsed_result,
16028         __rte_unused struct cmdline *cl,
16029         __rte_unused void *data)
16030 {
16031         struct cmd_set_l2_encap_result *res = parsed_result;
16032
16033         if (strcmp(res->l2_encap, "l2_encap") == 0)
16034                 l2_encap_conf.select_vlan = 0;
16035         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16036                 l2_encap_conf.select_vlan = 1;
16037         if (strcmp(res->ip_version, "ipv4") == 0)
16038                 l2_encap_conf.select_ipv4 = 1;
16039         else if (strcmp(res->ip_version, "ipv6") == 0)
16040                 l2_encap_conf.select_ipv4 = 0;
16041         else
16042                 return;
16043         if (l2_encap_conf.select_vlan)
16044                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16045         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16046                    RTE_ETHER_ADDR_LEN);
16047         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16048                    RTE_ETHER_ADDR_LEN);
16049 }
16050
16051 cmdline_parse_inst_t cmd_set_l2_encap = {
16052         .f = cmd_set_l2_encap_parsed,
16053         .data = NULL,
16054         .help_str = "set l2_encap ip-version ipv4|ipv6"
16055                 " eth-src <eth-src> eth-dst <eth-dst>",
16056         .tokens = {
16057                 (void *)&cmd_set_l2_encap_set,
16058                 (void *)&cmd_set_l2_encap_l2_encap,
16059                 (void *)&cmd_set_l2_encap_ip_version,
16060                 (void *)&cmd_set_l2_encap_ip_version_value,
16061                 (void *)&cmd_set_l2_encap_eth_src,
16062                 (void *)&cmd_set_l2_encap_eth_src_value,
16063                 (void *)&cmd_set_l2_encap_eth_dst,
16064                 (void *)&cmd_set_l2_encap_eth_dst_value,
16065                 NULL,
16066         },
16067 };
16068
16069 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16070         .f = cmd_set_l2_encap_parsed,
16071         .data = NULL,
16072         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16073                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16074         .tokens = {
16075                 (void *)&cmd_set_l2_encap_set,
16076                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16077                 (void *)&cmd_set_l2_encap_ip_version,
16078                 (void *)&cmd_set_l2_encap_ip_version_value,
16079                 (void *)&cmd_set_l2_encap_vlan,
16080                 (void *)&cmd_set_l2_encap_vlan_value,
16081                 (void *)&cmd_set_l2_encap_eth_src,
16082                 (void *)&cmd_set_l2_encap_eth_src_value,
16083                 (void *)&cmd_set_l2_encap_eth_dst,
16084                 (void *)&cmd_set_l2_encap_eth_dst_value,
16085                 NULL,
16086         },
16087 };
16088
16089 /** Set L2 decapsulation details */
16090 struct cmd_set_l2_decap_result {
16091         cmdline_fixed_string_t set;
16092         cmdline_fixed_string_t l2_decap;
16093         cmdline_fixed_string_t pos_token;
16094         uint32_t vlan_present:1;
16095 };
16096
16097 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16098         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16099 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16100         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16101                                  "l2_decap");
16102 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16103         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16104                                  "l2_decap-with-vlan");
16105
16106 static void cmd_set_l2_decap_parsed(void *parsed_result,
16107         __rte_unused struct cmdline *cl,
16108         __rte_unused void *data)
16109 {
16110         struct cmd_set_l2_decap_result *res = parsed_result;
16111
16112         if (strcmp(res->l2_decap, "l2_decap") == 0)
16113                 l2_decap_conf.select_vlan = 0;
16114         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16115                 l2_decap_conf.select_vlan = 1;
16116 }
16117
16118 cmdline_parse_inst_t cmd_set_l2_decap = {
16119         .f = cmd_set_l2_decap_parsed,
16120         .data = NULL,
16121         .help_str = "set l2_decap",
16122         .tokens = {
16123                 (void *)&cmd_set_l2_decap_set,
16124                 (void *)&cmd_set_l2_decap_l2_decap,
16125                 NULL,
16126         },
16127 };
16128
16129 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16130         .f = cmd_set_l2_decap_parsed,
16131         .data = NULL,
16132         .help_str = "set l2_decap-with-vlan",
16133         .tokens = {
16134                 (void *)&cmd_set_l2_decap_set,
16135                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16136                 NULL,
16137         },
16138 };
16139
16140 /** Set MPLSoGRE encapsulation details */
16141 struct cmd_set_mplsogre_encap_result {
16142         cmdline_fixed_string_t set;
16143         cmdline_fixed_string_t mplsogre;
16144         cmdline_fixed_string_t pos_token;
16145         cmdline_fixed_string_t ip_version;
16146         uint32_t vlan_present:1;
16147         uint32_t label;
16148         cmdline_ipaddr_t ip_src;
16149         cmdline_ipaddr_t ip_dst;
16150         uint16_t tci;
16151         struct rte_ether_addr eth_src;
16152         struct rte_ether_addr eth_dst;
16153 };
16154
16155 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16156         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16157                                  "set");
16158 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16159         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16160                                  "mplsogre_encap");
16161 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16162         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16163                                  mplsogre, "mplsogre_encap-with-vlan");
16164 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16165         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16166                                  pos_token, "ip-version");
16167 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16168         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16169                                  ip_version, "ipv4#ipv6");
16170 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16171         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16172                                  pos_token, "label");
16173 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16174         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16175                               UINT32);
16176 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16177         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16178                                  pos_token, "ip-src");
16179 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16180         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16181 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16182         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16183                                  pos_token, "ip-dst");
16184 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16185         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16186 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16187         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16188                                  pos_token, "vlan-tci");
16189 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16190         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16191                               UINT16);
16192 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16193         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16194                                  pos_token, "eth-src");
16195 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16196         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16197                                     eth_src);
16198 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16199         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16200                                  pos_token, "eth-dst");
16201 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16202         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16203                                     eth_dst);
16204
16205 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16206         __rte_unused struct cmdline *cl,
16207         __rte_unused void *data)
16208 {
16209         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16210         union {
16211                 uint32_t mplsogre_label;
16212                 uint8_t label[4];
16213         } id = {
16214                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16215         };
16216
16217         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16218                 mplsogre_encap_conf.select_vlan = 0;
16219         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16220                 mplsogre_encap_conf.select_vlan = 1;
16221         if (strcmp(res->ip_version, "ipv4") == 0)
16222                 mplsogre_encap_conf.select_ipv4 = 1;
16223         else if (strcmp(res->ip_version, "ipv6") == 0)
16224                 mplsogre_encap_conf.select_ipv4 = 0;
16225         else
16226                 return;
16227         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16228         if (mplsogre_encap_conf.select_ipv4) {
16229                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16230                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16231         } else {
16232                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16233                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16234         }
16235         if (mplsogre_encap_conf.select_vlan)
16236                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16237         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16238                    RTE_ETHER_ADDR_LEN);
16239         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16240                    RTE_ETHER_ADDR_LEN);
16241 }
16242
16243 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16244         .f = cmd_set_mplsogre_encap_parsed,
16245         .data = NULL,
16246         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16247                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16248                 " eth-dst <eth-dst>",
16249         .tokens = {
16250                 (void *)&cmd_set_mplsogre_encap_set,
16251                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16252                 (void *)&cmd_set_mplsogre_encap_ip_version,
16253                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16254                 (void *)&cmd_set_mplsogre_encap_label,
16255                 (void *)&cmd_set_mplsogre_encap_label_value,
16256                 (void *)&cmd_set_mplsogre_encap_ip_src,
16257                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16258                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16259                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16260                 (void *)&cmd_set_mplsogre_encap_eth_src,
16261                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16262                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16263                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16264                 NULL,
16265         },
16266 };
16267
16268 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16269         .f = cmd_set_mplsogre_encap_parsed,
16270         .data = NULL,
16271         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16272                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16273                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16274         .tokens = {
16275                 (void *)&cmd_set_mplsogre_encap_set,
16276                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16277                 (void *)&cmd_set_mplsogre_encap_ip_version,
16278                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16279                 (void *)&cmd_set_mplsogre_encap_label,
16280                 (void *)&cmd_set_mplsogre_encap_label_value,
16281                 (void *)&cmd_set_mplsogre_encap_ip_src,
16282                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16283                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16284                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16285                 (void *)&cmd_set_mplsogre_encap_vlan,
16286                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16287                 (void *)&cmd_set_mplsogre_encap_eth_src,
16288                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16289                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16290                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16291                 NULL,
16292         },
16293 };
16294
16295 /** Set MPLSoGRE decapsulation details */
16296 struct cmd_set_mplsogre_decap_result {
16297         cmdline_fixed_string_t set;
16298         cmdline_fixed_string_t mplsogre;
16299         cmdline_fixed_string_t pos_token;
16300         cmdline_fixed_string_t ip_version;
16301         uint32_t vlan_present:1;
16302 };
16303
16304 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16305         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16306                                  "set");
16307 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16308         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16309                                  "mplsogre_decap");
16310 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16311         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16312                                  mplsogre, "mplsogre_decap-with-vlan");
16313 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16314         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16315                                  pos_token, "ip-version");
16316 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16317         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16318                                  ip_version, "ipv4#ipv6");
16319
16320 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16321         __rte_unused struct cmdline *cl,
16322         __rte_unused void *data)
16323 {
16324         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16325
16326         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16327                 mplsogre_decap_conf.select_vlan = 0;
16328         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16329                 mplsogre_decap_conf.select_vlan = 1;
16330         if (strcmp(res->ip_version, "ipv4") == 0)
16331                 mplsogre_decap_conf.select_ipv4 = 1;
16332         else if (strcmp(res->ip_version, "ipv6") == 0)
16333                 mplsogre_decap_conf.select_ipv4 = 0;
16334 }
16335
16336 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16337         .f = cmd_set_mplsogre_decap_parsed,
16338         .data = NULL,
16339         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16340         .tokens = {
16341                 (void *)&cmd_set_mplsogre_decap_set,
16342                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16343                 (void *)&cmd_set_mplsogre_decap_ip_version,
16344                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16345                 NULL,
16346         },
16347 };
16348
16349 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16350         .f = cmd_set_mplsogre_decap_parsed,
16351         .data = NULL,
16352         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16353         .tokens = {
16354                 (void *)&cmd_set_mplsogre_decap_set,
16355                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16356                 (void *)&cmd_set_mplsogre_decap_ip_version,
16357                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16358                 NULL,
16359         },
16360 };
16361
16362 /** Set MPLSoUDP encapsulation details */
16363 struct cmd_set_mplsoudp_encap_result {
16364         cmdline_fixed_string_t set;
16365         cmdline_fixed_string_t mplsoudp;
16366         cmdline_fixed_string_t pos_token;
16367         cmdline_fixed_string_t ip_version;
16368         uint32_t vlan_present:1;
16369         uint32_t label;
16370         uint16_t udp_src;
16371         uint16_t udp_dst;
16372         cmdline_ipaddr_t ip_src;
16373         cmdline_ipaddr_t ip_dst;
16374         uint16_t tci;
16375         struct rte_ether_addr eth_src;
16376         struct rte_ether_addr eth_dst;
16377 };
16378
16379 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16380         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16381                                  "set");
16382 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16383         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16384                                  "mplsoudp_encap");
16385 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16386         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16387                                  mplsoudp, "mplsoudp_encap-with-vlan");
16388 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16389         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16390                                  pos_token, "ip-version");
16391 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16392         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16393                                  ip_version, "ipv4#ipv6");
16394 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16395         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16396                                  pos_token, "label");
16397 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16398         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16399                               UINT32);
16400 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16401         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16402                                  pos_token, "udp-src");
16403 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16404         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16405                               UINT16);
16406 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16407         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16408                                  pos_token, "udp-dst");
16409 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16410         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16411                               UINT16);
16412 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16413         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16414                                  pos_token, "ip-src");
16415 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16416         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16417 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16418         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16419                                  pos_token, "ip-dst");
16420 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16421         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16422 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16423         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16424                                  pos_token, "vlan-tci");
16425 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16426         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16427                               UINT16);
16428 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16429         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16430                                  pos_token, "eth-src");
16431 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16432         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16433                                     eth_src);
16434 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16435         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16436                                  pos_token, "eth-dst");
16437 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16438         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16439                                     eth_dst);
16440
16441 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16442         __rte_unused struct cmdline *cl,
16443         __rte_unused void *data)
16444 {
16445         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16446         union {
16447                 uint32_t mplsoudp_label;
16448                 uint8_t label[4];
16449         } id = {
16450                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16451         };
16452
16453         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16454                 mplsoudp_encap_conf.select_vlan = 0;
16455         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16456                 mplsoudp_encap_conf.select_vlan = 1;
16457         if (strcmp(res->ip_version, "ipv4") == 0)
16458                 mplsoudp_encap_conf.select_ipv4 = 1;
16459         else if (strcmp(res->ip_version, "ipv6") == 0)
16460                 mplsoudp_encap_conf.select_ipv4 = 0;
16461         else
16462                 return;
16463         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16464         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16465         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16466         if (mplsoudp_encap_conf.select_ipv4) {
16467                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16468                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16469         } else {
16470                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16471                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16472         }
16473         if (mplsoudp_encap_conf.select_vlan)
16474                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16475         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16476                    RTE_ETHER_ADDR_LEN);
16477         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16478                    RTE_ETHER_ADDR_LEN);
16479 }
16480
16481 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16482         .f = cmd_set_mplsoudp_encap_parsed,
16483         .data = NULL,
16484         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16485                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16486                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16487         .tokens = {
16488                 (void *)&cmd_set_mplsoudp_encap_set,
16489                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16490                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16491                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16492                 (void *)&cmd_set_mplsoudp_encap_label,
16493                 (void *)&cmd_set_mplsoudp_encap_label_value,
16494                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16495                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16496                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16497                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16498                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16499                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16500                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16501                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16502                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16503                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16504                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16505                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16506                 NULL,
16507         },
16508 };
16509
16510 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16511         .f = cmd_set_mplsoudp_encap_parsed,
16512         .data = NULL,
16513         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16514                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16515                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16516                 " eth-src <eth-src> eth-dst <eth-dst>",
16517         .tokens = {
16518                 (void *)&cmd_set_mplsoudp_encap_set,
16519                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16520                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16521                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16522                 (void *)&cmd_set_mplsoudp_encap_label,
16523                 (void *)&cmd_set_mplsoudp_encap_label_value,
16524                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16525                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16526                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16527                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16528                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16529                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16530                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16531                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16532                 (void *)&cmd_set_mplsoudp_encap_vlan,
16533                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16534                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16535                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16536                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16537                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16538                 NULL,
16539         },
16540 };
16541
16542 /** Set MPLSoUDP decapsulation details */
16543 struct cmd_set_mplsoudp_decap_result {
16544         cmdline_fixed_string_t set;
16545         cmdline_fixed_string_t mplsoudp;
16546         cmdline_fixed_string_t pos_token;
16547         cmdline_fixed_string_t ip_version;
16548         uint32_t vlan_present:1;
16549 };
16550
16551 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16552         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16553                                  "set");
16554 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16555         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16556                                  "mplsoudp_decap");
16557 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16558         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16559                                  mplsoudp, "mplsoudp_decap-with-vlan");
16560 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16561         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16562                                  pos_token, "ip-version");
16563 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16564         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16565                                  ip_version, "ipv4#ipv6");
16566
16567 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16568         __rte_unused struct cmdline *cl,
16569         __rte_unused void *data)
16570 {
16571         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16572
16573         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16574                 mplsoudp_decap_conf.select_vlan = 0;
16575         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16576                 mplsoudp_decap_conf.select_vlan = 1;
16577         if (strcmp(res->ip_version, "ipv4") == 0)
16578                 mplsoudp_decap_conf.select_ipv4 = 1;
16579         else if (strcmp(res->ip_version, "ipv6") == 0)
16580                 mplsoudp_decap_conf.select_ipv4 = 0;
16581 }
16582
16583 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16584         .f = cmd_set_mplsoudp_decap_parsed,
16585         .data = NULL,
16586         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16587         .tokens = {
16588                 (void *)&cmd_set_mplsoudp_decap_set,
16589                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16590                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16591                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16592                 NULL,
16593         },
16594 };
16595
16596 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16597         .f = cmd_set_mplsoudp_decap_parsed,
16598         .data = NULL,
16599         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16600         .tokens = {
16601                 (void *)&cmd_set_mplsoudp_decap_set,
16602                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16603                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16604                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16605                 NULL,
16606         },
16607 };
16608
16609 /* Strict link priority scheduling mode setting */
16610 static void
16611 cmd_strict_link_prio_parsed(
16612         void *parsed_result,
16613         __rte_unused struct cmdline *cl,
16614         __rte_unused void *data)
16615 {
16616         struct cmd_vf_tc_bw_result *res = parsed_result;
16617         int ret = -ENOTSUP;
16618
16619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16620                 return;
16621
16622 #ifdef RTE_LIBRTE_I40E_PMD
16623         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16624 #endif
16625
16626         switch (ret) {
16627         case 0:
16628                 break;
16629         case -EINVAL:
16630                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16631                 break;
16632         case -ENODEV:
16633                 printf("invalid port_id %d\n", res->port_id);
16634                 break;
16635         case -ENOTSUP:
16636                 printf("function not implemented\n");
16637                 break;
16638         default:
16639                 printf("programming error: (%s)\n", strerror(-ret));
16640         }
16641 }
16642
16643 cmdline_parse_inst_t cmd_strict_link_prio = {
16644         .f = cmd_strict_link_prio_parsed,
16645         .data = NULL,
16646         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16647         .tokens = {
16648                 (void *)&cmd_vf_tc_bw_set,
16649                 (void *)&cmd_vf_tc_bw_tx,
16650                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16651                 (void *)&cmd_vf_tc_bw_port_id,
16652                 (void *)&cmd_vf_tc_bw_tc_map,
16653                 NULL,
16654         },
16655 };
16656
16657 /* Load dynamic device personalization*/
16658 struct cmd_ddp_add_result {
16659         cmdline_fixed_string_t ddp;
16660         cmdline_fixed_string_t add;
16661         portid_t port_id;
16662         char filepath[];
16663 };
16664
16665 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16666         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16667 cmdline_parse_token_string_t cmd_ddp_add_add =
16668         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16669 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16670         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16671 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16672         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16673
16674 static void
16675 cmd_ddp_add_parsed(
16676         void *parsed_result,
16677         __rte_unused struct cmdline *cl,
16678         __rte_unused void *data)
16679 {
16680         struct cmd_ddp_add_result *res = parsed_result;
16681         uint8_t *buff;
16682         uint32_t size;
16683         char *filepath;
16684         char *file_fld[2];
16685         int file_num;
16686         int ret = -ENOTSUP;
16687
16688         if (!all_ports_stopped()) {
16689                 printf("Please stop all ports first\n");
16690                 return;
16691         }
16692
16693         filepath = strdup(res->filepath);
16694         if (filepath == NULL) {
16695                 printf("Failed to allocate memory\n");
16696                 return;
16697         }
16698         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16699
16700         buff = open_file(file_fld[0], &size);
16701         if (!buff) {
16702                 free((void *)filepath);
16703                 return;
16704         }
16705
16706 #ifdef RTE_LIBRTE_I40E_PMD
16707         if (ret == -ENOTSUP)
16708                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16709                                                buff, size,
16710                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16711 #endif
16712
16713         if (ret == -EEXIST)
16714                 printf("Profile has already existed.\n");
16715         else if (ret < 0)
16716                 printf("Failed to load profile.\n");
16717         else if (file_num == 2)
16718                 save_file(file_fld[1], buff, size);
16719
16720         close_file(buff);
16721         free((void *)filepath);
16722 }
16723
16724 cmdline_parse_inst_t cmd_ddp_add = {
16725         .f = cmd_ddp_add_parsed,
16726         .data = NULL,
16727         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16728         .tokens = {
16729                 (void *)&cmd_ddp_add_ddp,
16730                 (void *)&cmd_ddp_add_add,
16731                 (void *)&cmd_ddp_add_port_id,
16732                 (void *)&cmd_ddp_add_filepath,
16733                 NULL,
16734         },
16735 };
16736
16737 /* Delete dynamic device personalization*/
16738 struct cmd_ddp_del_result {
16739         cmdline_fixed_string_t ddp;
16740         cmdline_fixed_string_t del;
16741         portid_t port_id;
16742         char filepath[];
16743 };
16744
16745 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16746         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16747 cmdline_parse_token_string_t cmd_ddp_del_del =
16748         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16749 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16750         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16751 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16752         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16753
16754 static void
16755 cmd_ddp_del_parsed(
16756         void *parsed_result,
16757         __rte_unused struct cmdline *cl,
16758         __rte_unused void *data)
16759 {
16760         struct cmd_ddp_del_result *res = parsed_result;
16761         uint8_t *buff;
16762         uint32_t size;
16763         int ret = -ENOTSUP;
16764
16765         if (!all_ports_stopped()) {
16766                 printf("Please stop all ports first\n");
16767                 return;
16768         }
16769
16770         buff = open_file(res->filepath, &size);
16771         if (!buff)
16772                 return;
16773
16774 #ifdef RTE_LIBRTE_I40E_PMD
16775         if (ret == -ENOTSUP)
16776                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16777                                                buff, size,
16778                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16779 #endif
16780
16781         if (ret == -EACCES)
16782                 printf("Profile does not exist.\n");
16783         else if (ret < 0)
16784                 printf("Failed to delete profile.\n");
16785
16786         close_file(buff);
16787 }
16788
16789 cmdline_parse_inst_t cmd_ddp_del = {
16790         .f = cmd_ddp_del_parsed,
16791         .data = NULL,
16792         .help_str = "ddp del <port_id> <backup_profile_path>",
16793         .tokens = {
16794                 (void *)&cmd_ddp_del_ddp,
16795                 (void *)&cmd_ddp_del_del,
16796                 (void *)&cmd_ddp_del_port_id,
16797                 (void *)&cmd_ddp_del_filepath,
16798                 NULL,
16799         },
16800 };
16801
16802 /* Get dynamic device personalization profile info */
16803 struct cmd_ddp_info_result {
16804         cmdline_fixed_string_t ddp;
16805         cmdline_fixed_string_t get;
16806         cmdline_fixed_string_t info;
16807         char filepath[];
16808 };
16809
16810 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16811         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16812 cmdline_parse_token_string_t cmd_ddp_info_get =
16813         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16814 cmdline_parse_token_string_t cmd_ddp_info_info =
16815         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16816 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16817         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16818
16819 static void
16820 cmd_ddp_info_parsed(
16821         void *parsed_result,
16822         __rte_unused struct cmdline *cl,
16823         __rte_unused void *data)
16824 {
16825         struct cmd_ddp_info_result *res = parsed_result;
16826         uint8_t *pkg;
16827         uint32_t pkg_size;
16828         int ret = -ENOTSUP;
16829 #ifdef RTE_LIBRTE_I40E_PMD
16830         uint32_t i, j, n;
16831         uint8_t *buff;
16832         uint32_t buff_size = 0;
16833         struct rte_pmd_i40e_profile_info info;
16834         uint32_t dev_num = 0;
16835         struct rte_pmd_i40e_ddp_device_id *devs;
16836         uint32_t proto_num = 0;
16837         struct rte_pmd_i40e_proto_info *proto = NULL;
16838         uint32_t pctype_num = 0;
16839         struct rte_pmd_i40e_ptype_info *pctype;
16840         uint32_t ptype_num = 0;
16841         struct rte_pmd_i40e_ptype_info *ptype;
16842         uint8_t proto_id;
16843
16844 #endif
16845
16846         pkg = open_file(res->filepath, &pkg_size);
16847         if (!pkg)
16848                 return;
16849
16850 #ifdef RTE_LIBRTE_I40E_PMD
16851         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16852                                 (uint8_t *)&info, sizeof(info),
16853                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16854         if (!ret) {
16855                 printf("Global Track id:       0x%x\n", info.track_id);
16856                 printf("Global Version:        %d.%d.%d.%d\n",
16857                         info.version.major,
16858                         info.version.minor,
16859                         info.version.update,
16860                         info.version.draft);
16861                 printf("Global Package name:   %s\n\n", info.name);
16862         }
16863
16864         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16865                                 (uint8_t *)&info, sizeof(info),
16866                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16867         if (!ret) {
16868                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16869                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16870                         info.version.major,
16871                         info.version.minor,
16872                         info.version.update,
16873                         info.version.draft);
16874                 printf("i40e Profile name:     %s\n\n", info.name);
16875         }
16876
16877         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16878                                 (uint8_t *)&buff_size, sizeof(buff_size),
16879                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16880         if (!ret && buff_size) {
16881                 buff = (uint8_t *)malloc(buff_size);
16882                 if (buff) {
16883                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16884                                                 buff, buff_size,
16885                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16886                         if (!ret)
16887                                 printf("Package Notes:\n%s\n\n", buff);
16888                         free(buff);
16889                 }
16890         }
16891
16892         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16893                                 (uint8_t *)&dev_num, sizeof(dev_num),
16894                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16895         if (!ret && dev_num) {
16896                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16897                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16898                 if (devs) {
16899                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16900                                                 (uint8_t *)devs, buff_size,
16901                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16902                         if (!ret) {
16903                                 printf("List of supported devices:\n");
16904                                 for (i = 0; i < dev_num; i++) {
16905                                         printf("  %04X:%04X %04X:%04X\n",
16906                                                 devs[i].vendor_dev_id >> 16,
16907                                                 devs[i].vendor_dev_id & 0xFFFF,
16908                                                 devs[i].sub_vendor_dev_id >> 16,
16909                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16910                                 }
16911                                 printf("\n");
16912                         }
16913                         free(devs);
16914                 }
16915         }
16916
16917         /* get information about protocols and packet types */
16918         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16919                 (uint8_t *)&proto_num, sizeof(proto_num),
16920                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16921         if (ret || !proto_num)
16922                 goto no_print_return;
16923
16924         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16925         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16926         if (!proto)
16927                 goto no_print_return;
16928
16929         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16930                                         buff_size,
16931                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16932         if (!ret) {
16933                 printf("List of used protocols:\n");
16934                 for (i = 0; i < proto_num; i++)
16935                         printf("  %2u: %s\n", proto[i].proto_id,
16936                                proto[i].name);
16937                 printf("\n");
16938         }
16939         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16940                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16941                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16942         if (ret || !pctype_num)
16943                 goto no_print_pctypes;
16944
16945         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16946         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16947         if (!pctype)
16948                 goto no_print_pctypes;
16949
16950         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
16951                                         buff_size,
16952                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
16953         if (ret) {
16954                 free(pctype);
16955                 goto no_print_pctypes;
16956         }
16957
16958         printf("List of defined packet classification types:\n");
16959         for (i = 0; i < pctype_num; i++) {
16960                 printf("  %2u:", pctype[i].ptype_id);
16961                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
16962                         proto_id = pctype[i].protocols[j];
16963                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
16964                                 for (n = 0; n < proto_num; n++) {
16965                                         if (proto[n].proto_id == proto_id) {
16966                                                 printf(" %s", proto[n].name);
16967                                                 break;
16968                                         }
16969                                 }
16970                         }
16971                 }
16972                 printf("\n");
16973         }
16974         printf("\n");
16975         free(pctype);
16976
16977 no_print_pctypes:
16978
16979         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
16980                                         sizeof(ptype_num),
16981                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
16982         if (ret || !ptype_num)
16983                 goto no_print_return;
16984
16985         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
16986         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
16987         if (!ptype)
16988                 goto no_print_return;
16989
16990         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
16991                                         buff_size,
16992                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
16993         if (ret) {
16994                 free(ptype);
16995                 goto no_print_return;
16996         }
16997         printf("List of defined packet types:\n");
16998         for (i = 0; i < ptype_num; i++) {
16999                 printf("  %2u:", ptype[i].ptype_id);
17000                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17001                         proto_id = ptype[i].protocols[j];
17002                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17003                                 for (n = 0; n < proto_num; n++) {
17004                                         if (proto[n].proto_id == proto_id) {
17005                                                 printf(" %s", proto[n].name);
17006                                                 break;
17007                                         }
17008                                 }
17009                         }
17010                 }
17011                 printf("\n");
17012         }
17013         free(ptype);
17014         printf("\n");
17015
17016         ret = 0;
17017 no_print_return:
17018         if (proto)
17019                 free(proto);
17020 #endif
17021         if (ret == -ENOTSUP)
17022                 printf("Function not supported in PMD driver\n");
17023         close_file(pkg);
17024 }
17025
17026 cmdline_parse_inst_t cmd_ddp_get_info = {
17027         .f = cmd_ddp_info_parsed,
17028         .data = NULL,
17029         .help_str = "ddp get info <profile_path>",
17030         .tokens = {
17031                 (void *)&cmd_ddp_info_ddp,
17032                 (void *)&cmd_ddp_info_get,
17033                 (void *)&cmd_ddp_info_info,
17034                 (void *)&cmd_ddp_info_filepath,
17035                 NULL,
17036         },
17037 };
17038
17039 /* Get dynamic device personalization profile info list*/
17040 #define PROFILE_INFO_SIZE 48
17041 #define MAX_PROFILE_NUM 16
17042
17043 struct cmd_ddp_get_list_result {
17044         cmdline_fixed_string_t ddp;
17045         cmdline_fixed_string_t get;
17046         cmdline_fixed_string_t list;
17047         portid_t port_id;
17048 };
17049
17050 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17051         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17052 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17053         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17054 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17055         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17056 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17057         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17058
17059 static void
17060 cmd_ddp_get_list_parsed(
17061         __rte_unused void *parsed_result,
17062         __rte_unused struct cmdline *cl,
17063         __rte_unused void *data)
17064 {
17065 #ifdef RTE_LIBRTE_I40E_PMD
17066         struct cmd_ddp_get_list_result *res = parsed_result;
17067         struct rte_pmd_i40e_profile_list *p_list;
17068         struct rte_pmd_i40e_profile_info *p_info;
17069         uint32_t p_num;
17070         uint32_t size;
17071         uint32_t i;
17072 #endif
17073         int ret = -ENOTSUP;
17074
17075 #ifdef RTE_LIBRTE_I40E_PMD
17076         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17077         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17078         if (!p_list) {
17079                 printf("%s: Failed to malloc buffer\n", __func__);
17080                 return;
17081         }
17082
17083         if (ret == -ENOTSUP)
17084                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17085                                                 (uint8_t *)p_list, size);
17086
17087         if (!ret) {
17088                 p_num = p_list->p_count;
17089                 printf("Profile number is: %d\n\n", p_num);
17090
17091                 for (i = 0; i < p_num; i++) {
17092                         p_info = &p_list->p_info[i];
17093                         printf("Profile %d:\n", i);
17094                         printf("Track id:     0x%x\n", p_info->track_id);
17095                         printf("Version:      %d.%d.%d.%d\n",
17096                                p_info->version.major,
17097                                p_info->version.minor,
17098                                p_info->version.update,
17099                                p_info->version.draft);
17100                         printf("Profile name: %s\n\n", p_info->name);
17101                 }
17102         }
17103
17104         free(p_list);
17105 #endif
17106
17107         if (ret < 0)
17108                 printf("Failed to get ddp list\n");
17109 }
17110
17111 cmdline_parse_inst_t cmd_ddp_get_list = {
17112         .f = cmd_ddp_get_list_parsed,
17113         .data = NULL,
17114         .help_str = "ddp get list <port_id>",
17115         .tokens = {
17116                 (void *)&cmd_ddp_get_list_ddp,
17117                 (void *)&cmd_ddp_get_list_get,
17118                 (void *)&cmd_ddp_get_list_list,
17119                 (void *)&cmd_ddp_get_list_port_id,
17120                 NULL,
17121         },
17122 };
17123
17124 /* Configure input set */
17125 struct cmd_cfg_input_set_result {
17126         cmdline_fixed_string_t port;
17127         cmdline_fixed_string_t cfg;
17128         portid_t port_id;
17129         cmdline_fixed_string_t pctype;
17130         uint8_t pctype_id;
17131         cmdline_fixed_string_t inset_type;
17132         cmdline_fixed_string_t opt;
17133         cmdline_fixed_string_t field;
17134         uint8_t field_idx;
17135 };
17136
17137 static void
17138 cmd_cfg_input_set_parsed(
17139         __rte_unused void *parsed_result,
17140         __rte_unused struct cmdline *cl,
17141         __rte_unused void *data)
17142 {
17143 #ifdef RTE_LIBRTE_I40E_PMD
17144         struct cmd_cfg_input_set_result *res = parsed_result;
17145         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17146         struct rte_pmd_i40e_inset inset;
17147 #endif
17148         int ret = -ENOTSUP;
17149
17150         if (!all_ports_stopped()) {
17151                 printf("Please stop all ports first\n");
17152                 return;
17153         }
17154
17155 #ifdef RTE_LIBRTE_I40E_PMD
17156         if (!strcmp(res->inset_type, "hash_inset"))
17157                 inset_type = INSET_HASH;
17158         else if (!strcmp(res->inset_type, "fdir_inset"))
17159                 inset_type = INSET_FDIR;
17160         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17161                 inset_type = INSET_FDIR_FLX;
17162         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17163                                      &inset, inset_type);
17164         if (ret) {
17165                 printf("Failed to get input set.\n");
17166                 return;
17167         }
17168
17169         if (!strcmp(res->opt, "get")) {
17170                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17171                                                    res->field_idx);
17172                 if (ret)
17173                         printf("Field index %d is enabled.\n", res->field_idx);
17174                 else
17175                         printf("Field index %d is disabled.\n", res->field_idx);
17176                 return;
17177         } else if (!strcmp(res->opt, "set"))
17178                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17179                                                    res->field_idx);
17180         else if (!strcmp(res->opt, "clear"))
17181                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17182                                                      res->field_idx);
17183         if (ret) {
17184                 printf("Failed to configure input set field.\n");
17185                 return;
17186         }
17187
17188         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17189                                      &inset, inset_type);
17190         if (ret) {
17191                 printf("Failed to set input set.\n");
17192                 return;
17193         }
17194 #endif
17195
17196         if (ret == -ENOTSUP)
17197                 printf("Function not supported\n");
17198 }
17199
17200 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17201         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17202                                  port, "port");
17203 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17204         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17205                                  cfg, "config");
17206 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17207         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17208                               port_id, UINT16);
17209 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17210         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17211                                  pctype, "pctype");
17212 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17213         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17214                               pctype_id, UINT8);
17215 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17216         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17217                                  inset_type,
17218                                  "hash_inset#fdir_inset#fdir_flx_inset");
17219 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17220         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17221                                  opt, "get#set#clear");
17222 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17223         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17224                                  field, "field");
17225 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17226         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17227                               field_idx, UINT8);
17228
17229 cmdline_parse_inst_t cmd_cfg_input_set = {
17230         .f = cmd_cfg_input_set_parsed,
17231         .data = NULL,
17232         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17233                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17234         .tokens = {
17235                 (void *)&cmd_cfg_input_set_port,
17236                 (void *)&cmd_cfg_input_set_cfg,
17237                 (void *)&cmd_cfg_input_set_port_id,
17238                 (void *)&cmd_cfg_input_set_pctype,
17239                 (void *)&cmd_cfg_input_set_pctype_id,
17240                 (void *)&cmd_cfg_input_set_inset_type,
17241                 (void *)&cmd_cfg_input_set_opt,
17242                 (void *)&cmd_cfg_input_set_field,
17243                 (void *)&cmd_cfg_input_set_field_idx,
17244                 NULL,
17245         },
17246 };
17247
17248 /* Clear input set */
17249 struct cmd_clear_input_set_result {
17250         cmdline_fixed_string_t port;
17251         cmdline_fixed_string_t cfg;
17252         portid_t port_id;
17253         cmdline_fixed_string_t pctype;
17254         uint8_t pctype_id;
17255         cmdline_fixed_string_t inset_type;
17256         cmdline_fixed_string_t clear;
17257         cmdline_fixed_string_t all;
17258 };
17259
17260 static void
17261 cmd_clear_input_set_parsed(
17262         __rte_unused void *parsed_result,
17263         __rte_unused struct cmdline *cl,
17264         __rte_unused void *data)
17265 {
17266 #ifdef RTE_LIBRTE_I40E_PMD
17267         struct cmd_clear_input_set_result *res = parsed_result;
17268         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17269         struct rte_pmd_i40e_inset inset;
17270 #endif
17271         int ret = -ENOTSUP;
17272
17273         if (!all_ports_stopped()) {
17274                 printf("Please stop all ports first\n");
17275                 return;
17276         }
17277
17278 #ifdef RTE_LIBRTE_I40E_PMD
17279         if (!strcmp(res->inset_type, "hash_inset"))
17280                 inset_type = INSET_HASH;
17281         else if (!strcmp(res->inset_type, "fdir_inset"))
17282                 inset_type = INSET_FDIR;
17283         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17284                 inset_type = INSET_FDIR_FLX;
17285
17286         memset(&inset, 0, sizeof(inset));
17287
17288         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17289                                      &inset, inset_type);
17290         if (ret) {
17291                 printf("Failed to clear input set.\n");
17292                 return;
17293         }
17294
17295 #endif
17296
17297         if (ret == -ENOTSUP)
17298                 printf("Function not supported\n");
17299 }
17300
17301 cmdline_parse_token_string_t cmd_clear_input_set_port =
17302         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17303                                  port, "port");
17304 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17305         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17306                                  cfg, "config");
17307 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17308         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17309                               port_id, UINT16);
17310 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17311         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17312                                  pctype, "pctype");
17313 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17314         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17315                               pctype_id, UINT8);
17316 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17317         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17318                                  inset_type,
17319                                  "hash_inset#fdir_inset#fdir_flx_inset");
17320 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17321         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17322                                  clear, "clear");
17323 cmdline_parse_token_string_t cmd_clear_input_set_all =
17324         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17325                                  all, "all");
17326
17327 cmdline_parse_inst_t cmd_clear_input_set = {
17328         .f = cmd_clear_input_set_parsed,
17329         .data = NULL,
17330         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17331                     "fdir_inset|fdir_flx_inset clear all",
17332         .tokens = {
17333                 (void *)&cmd_clear_input_set_port,
17334                 (void *)&cmd_clear_input_set_cfg,
17335                 (void *)&cmd_clear_input_set_port_id,
17336                 (void *)&cmd_clear_input_set_pctype,
17337                 (void *)&cmd_clear_input_set_pctype_id,
17338                 (void *)&cmd_clear_input_set_inset_type,
17339                 (void *)&cmd_clear_input_set_clear,
17340                 (void *)&cmd_clear_input_set_all,
17341                 NULL,
17342         },
17343 };
17344
17345 /* show vf stats */
17346
17347 /* Common result structure for show vf stats */
17348 struct cmd_show_vf_stats_result {
17349         cmdline_fixed_string_t show;
17350         cmdline_fixed_string_t vf;
17351         cmdline_fixed_string_t stats;
17352         portid_t port_id;
17353         uint16_t vf_id;
17354 };
17355
17356 /* Common CLI fields show vf stats*/
17357 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17358         TOKEN_STRING_INITIALIZER
17359                 (struct cmd_show_vf_stats_result,
17360                  show, "show");
17361 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17362         TOKEN_STRING_INITIALIZER
17363                 (struct cmd_show_vf_stats_result,
17364                  vf, "vf");
17365 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17366         TOKEN_STRING_INITIALIZER
17367                 (struct cmd_show_vf_stats_result,
17368                  stats, "stats");
17369 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17370         TOKEN_NUM_INITIALIZER
17371                 (struct cmd_show_vf_stats_result,
17372                  port_id, UINT16);
17373 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17374         TOKEN_NUM_INITIALIZER
17375                 (struct cmd_show_vf_stats_result,
17376                  vf_id, UINT16);
17377
17378 static void
17379 cmd_show_vf_stats_parsed(
17380         void *parsed_result,
17381         __rte_unused struct cmdline *cl,
17382         __rte_unused void *data)
17383 {
17384         struct cmd_show_vf_stats_result *res = parsed_result;
17385         struct rte_eth_stats stats;
17386         int ret = -ENOTSUP;
17387         static const char *nic_stats_border = "########################";
17388
17389         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17390                 return;
17391
17392         memset(&stats, 0, sizeof(stats));
17393
17394 #ifdef RTE_LIBRTE_I40E_PMD
17395         if (ret == -ENOTSUP)
17396                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17397                                                 res->vf_id,
17398                                                 &stats);
17399 #endif
17400 #ifdef RTE_LIBRTE_BNXT_PMD
17401         if (ret == -ENOTSUP)
17402                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17403                                                 res->vf_id,
17404                                                 &stats);
17405 #endif
17406
17407         switch (ret) {
17408         case 0:
17409                 break;
17410         case -EINVAL:
17411                 printf("invalid vf_id %d\n", res->vf_id);
17412                 break;
17413         case -ENODEV:
17414                 printf("invalid port_id %d\n", res->port_id);
17415                 break;
17416         case -ENOTSUP:
17417                 printf("function not implemented\n");
17418                 break;
17419         default:
17420                 printf("programming error: (%s)\n", strerror(-ret));
17421         }
17422
17423         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17424                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17425
17426         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17427                "%-"PRIu64"\n",
17428                stats.ipackets, stats.imissed, stats.ibytes);
17429         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17430         printf("  RX-nombuf:  %-10"PRIu64"\n",
17431                stats.rx_nombuf);
17432         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17433                "%-"PRIu64"\n",
17434                stats.opackets, stats.oerrors, stats.obytes);
17435
17436         printf("  %s############################%s\n",
17437                                nic_stats_border, nic_stats_border);
17438 }
17439
17440 cmdline_parse_inst_t cmd_show_vf_stats = {
17441         .f = cmd_show_vf_stats_parsed,
17442         .data = NULL,
17443         .help_str = "show vf stats <port_id> <vf_id>",
17444         .tokens = {
17445                 (void *)&cmd_show_vf_stats_show,
17446                 (void *)&cmd_show_vf_stats_vf,
17447                 (void *)&cmd_show_vf_stats_stats,
17448                 (void *)&cmd_show_vf_stats_port_id,
17449                 (void *)&cmd_show_vf_stats_vf_id,
17450                 NULL,
17451         },
17452 };
17453
17454 /* clear vf stats */
17455
17456 /* Common result structure for clear vf stats */
17457 struct cmd_clear_vf_stats_result {
17458         cmdline_fixed_string_t clear;
17459         cmdline_fixed_string_t vf;
17460         cmdline_fixed_string_t stats;
17461         portid_t port_id;
17462         uint16_t vf_id;
17463 };
17464
17465 /* Common CLI fields clear vf stats*/
17466 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17467         TOKEN_STRING_INITIALIZER
17468                 (struct cmd_clear_vf_stats_result,
17469                  clear, "clear");
17470 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17471         TOKEN_STRING_INITIALIZER
17472                 (struct cmd_clear_vf_stats_result,
17473                  vf, "vf");
17474 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17475         TOKEN_STRING_INITIALIZER
17476                 (struct cmd_clear_vf_stats_result,
17477                  stats, "stats");
17478 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17479         TOKEN_NUM_INITIALIZER
17480                 (struct cmd_clear_vf_stats_result,
17481                  port_id, UINT16);
17482 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17483         TOKEN_NUM_INITIALIZER
17484                 (struct cmd_clear_vf_stats_result,
17485                  vf_id, UINT16);
17486
17487 static void
17488 cmd_clear_vf_stats_parsed(
17489         void *parsed_result,
17490         __rte_unused struct cmdline *cl,
17491         __rte_unused void *data)
17492 {
17493         struct cmd_clear_vf_stats_result *res = parsed_result;
17494         int ret = -ENOTSUP;
17495
17496         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17497                 return;
17498
17499 #ifdef RTE_LIBRTE_I40E_PMD
17500         if (ret == -ENOTSUP)
17501                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17502                                                   res->vf_id);
17503 #endif
17504 #ifdef RTE_LIBRTE_BNXT_PMD
17505         if (ret == -ENOTSUP)
17506                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17507                                                   res->vf_id);
17508 #endif
17509
17510         switch (ret) {
17511         case 0:
17512                 break;
17513         case -EINVAL:
17514                 printf("invalid vf_id %d\n", res->vf_id);
17515                 break;
17516         case -ENODEV:
17517                 printf("invalid port_id %d\n", res->port_id);
17518                 break;
17519         case -ENOTSUP:
17520                 printf("function not implemented\n");
17521                 break;
17522         default:
17523                 printf("programming error: (%s)\n", strerror(-ret));
17524         }
17525 }
17526
17527 cmdline_parse_inst_t cmd_clear_vf_stats = {
17528         .f = cmd_clear_vf_stats_parsed,
17529         .data = NULL,
17530         .help_str = "clear vf stats <port_id> <vf_id>",
17531         .tokens = {
17532                 (void *)&cmd_clear_vf_stats_clear,
17533                 (void *)&cmd_clear_vf_stats_vf,
17534                 (void *)&cmd_clear_vf_stats_stats,
17535                 (void *)&cmd_clear_vf_stats_port_id,
17536                 (void *)&cmd_clear_vf_stats_vf_id,
17537                 NULL,
17538         },
17539 };
17540
17541 /* port config pctype mapping reset */
17542
17543 /* Common result structure for port config pctype mapping reset */
17544 struct cmd_pctype_mapping_reset_result {
17545         cmdline_fixed_string_t port;
17546         cmdline_fixed_string_t config;
17547         portid_t port_id;
17548         cmdline_fixed_string_t pctype;
17549         cmdline_fixed_string_t mapping;
17550         cmdline_fixed_string_t reset;
17551 };
17552
17553 /* Common CLI fields for port config pctype mapping reset*/
17554 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17555         TOKEN_STRING_INITIALIZER
17556                 (struct cmd_pctype_mapping_reset_result,
17557                  port, "port");
17558 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17559         TOKEN_STRING_INITIALIZER
17560                 (struct cmd_pctype_mapping_reset_result,
17561                  config, "config");
17562 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17563         TOKEN_NUM_INITIALIZER
17564                 (struct cmd_pctype_mapping_reset_result,
17565                  port_id, UINT16);
17566 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17567         TOKEN_STRING_INITIALIZER
17568                 (struct cmd_pctype_mapping_reset_result,
17569                  pctype, "pctype");
17570 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17571         TOKEN_STRING_INITIALIZER
17572                 (struct cmd_pctype_mapping_reset_result,
17573                  mapping, "mapping");
17574 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17575         TOKEN_STRING_INITIALIZER
17576                 (struct cmd_pctype_mapping_reset_result,
17577                  reset, "reset");
17578
17579 static void
17580 cmd_pctype_mapping_reset_parsed(
17581         void *parsed_result,
17582         __rte_unused struct cmdline *cl,
17583         __rte_unused void *data)
17584 {
17585         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17586         int ret = -ENOTSUP;
17587
17588         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17589                 return;
17590
17591 #ifdef RTE_LIBRTE_I40E_PMD
17592         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17593 #endif
17594
17595         switch (ret) {
17596         case 0:
17597                 break;
17598         case -ENODEV:
17599                 printf("invalid port_id %d\n", res->port_id);
17600                 break;
17601         case -ENOTSUP:
17602                 printf("function not implemented\n");
17603                 break;
17604         default:
17605                 printf("programming error: (%s)\n", strerror(-ret));
17606         }
17607 }
17608
17609 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17610         .f = cmd_pctype_mapping_reset_parsed,
17611         .data = NULL,
17612         .help_str = "port config <port_id> pctype mapping reset",
17613         .tokens = {
17614                 (void *)&cmd_pctype_mapping_reset_port,
17615                 (void *)&cmd_pctype_mapping_reset_config,
17616                 (void *)&cmd_pctype_mapping_reset_port_id,
17617                 (void *)&cmd_pctype_mapping_reset_pctype,
17618                 (void *)&cmd_pctype_mapping_reset_mapping,
17619                 (void *)&cmd_pctype_mapping_reset_reset,
17620                 NULL,
17621         },
17622 };
17623
17624 /* show port pctype mapping */
17625
17626 /* Common result structure for show port pctype mapping */
17627 struct cmd_pctype_mapping_get_result {
17628         cmdline_fixed_string_t show;
17629         cmdline_fixed_string_t port;
17630         portid_t port_id;
17631         cmdline_fixed_string_t pctype;
17632         cmdline_fixed_string_t mapping;
17633 };
17634
17635 /* Common CLI fields for pctype mapping get */
17636 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17637         TOKEN_STRING_INITIALIZER
17638                 (struct cmd_pctype_mapping_get_result,
17639                  show, "show");
17640 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17641         TOKEN_STRING_INITIALIZER
17642                 (struct cmd_pctype_mapping_get_result,
17643                  port, "port");
17644 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17645         TOKEN_NUM_INITIALIZER
17646                 (struct cmd_pctype_mapping_get_result,
17647                  port_id, UINT16);
17648 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17649         TOKEN_STRING_INITIALIZER
17650                 (struct cmd_pctype_mapping_get_result,
17651                  pctype, "pctype");
17652 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17653         TOKEN_STRING_INITIALIZER
17654                 (struct cmd_pctype_mapping_get_result,
17655                  mapping, "mapping");
17656
17657 static void
17658 cmd_pctype_mapping_get_parsed(
17659         void *parsed_result,
17660         __rte_unused struct cmdline *cl,
17661         __rte_unused void *data)
17662 {
17663         struct cmd_pctype_mapping_get_result *res = parsed_result;
17664         int ret = -ENOTSUP;
17665 #ifdef RTE_LIBRTE_I40E_PMD
17666         struct rte_pmd_i40e_flow_type_mapping
17667                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17668         int i, j, first_pctype;
17669 #endif
17670
17671         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17672                 return;
17673
17674 #ifdef RTE_LIBRTE_I40E_PMD
17675         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17676 #endif
17677
17678         switch (ret) {
17679         case 0:
17680                 break;
17681         case -ENODEV:
17682                 printf("invalid port_id %d\n", res->port_id);
17683                 return;
17684         case -ENOTSUP:
17685                 printf("function not implemented\n");
17686                 return;
17687         default:
17688                 printf("programming error: (%s)\n", strerror(-ret));
17689                 return;
17690         }
17691
17692 #ifdef RTE_LIBRTE_I40E_PMD
17693         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17694                 if (mapping[i].pctype != 0ULL) {
17695                         first_pctype = 1;
17696
17697                         printf("pctype: ");
17698                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17699                                 if (mapping[i].pctype & (1ULL << j)) {
17700                                         printf(first_pctype ?
17701                                                "%02d" : ",%02d", j);
17702                                         first_pctype = 0;
17703                                 }
17704                         }
17705                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17706                 }
17707         }
17708 #endif
17709 }
17710
17711 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17712         .f = cmd_pctype_mapping_get_parsed,
17713         .data = NULL,
17714         .help_str = "show port <port_id> pctype mapping",
17715         .tokens = {
17716                 (void *)&cmd_pctype_mapping_get_show,
17717                 (void *)&cmd_pctype_mapping_get_port,
17718                 (void *)&cmd_pctype_mapping_get_port_id,
17719                 (void *)&cmd_pctype_mapping_get_pctype,
17720                 (void *)&cmd_pctype_mapping_get_mapping,
17721                 NULL,
17722         },
17723 };
17724
17725 /* port config pctype mapping update */
17726
17727 /* Common result structure for port config pctype mapping update */
17728 struct cmd_pctype_mapping_update_result {
17729         cmdline_fixed_string_t port;
17730         cmdline_fixed_string_t config;
17731         portid_t port_id;
17732         cmdline_fixed_string_t pctype;
17733         cmdline_fixed_string_t mapping;
17734         cmdline_fixed_string_t update;
17735         cmdline_fixed_string_t pctype_list;
17736         uint16_t flow_type;
17737 };
17738
17739 /* Common CLI fields for pctype mapping update*/
17740 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17741         TOKEN_STRING_INITIALIZER
17742                 (struct cmd_pctype_mapping_update_result,
17743                  port, "port");
17744 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17745         TOKEN_STRING_INITIALIZER
17746                 (struct cmd_pctype_mapping_update_result,
17747                  config, "config");
17748 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17749         TOKEN_NUM_INITIALIZER
17750                 (struct cmd_pctype_mapping_update_result,
17751                  port_id, UINT16);
17752 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17753         TOKEN_STRING_INITIALIZER
17754                 (struct cmd_pctype_mapping_update_result,
17755                  pctype, "pctype");
17756 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17757         TOKEN_STRING_INITIALIZER
17758                 (struct cmd_pctype_mapping_update_result,
17759                  mapping, "mapping");
17760 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17761         TOKEN_STRING_INITIALIZER
17762                 (struct cmd_pctype_mapping_update_result,
17763                  update, "update");
17764 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17765         TOKEN_STRING_INITIALIZER
17766                 (struct cmd_pctype_mapping_update_result,
17767                  pctype_list, NULL);
17768 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17769         TOKEN_NUM_INITIALIZER
17770                 (struct cmd_pctype_mapping_update_result,
17771                  flow_type, UINT16);
17772
17773 static void
17774 cmd_pctype_mapping_update_parsed(
17775         void *parsed_result,
17776         __rte_unused struct cmdline *cl,
17777         __rte_unused void *data)
17778 {
17779         struct cmd_pctype_mapping_update_result *res = parsed_result;
17780         int ret = -ENOTSUP;
17781 #ifdef RTE_LIBRTE_I40E_PMD
17782         struct rte_pmd_i40e_flow_type_mapping mapping;
17783         unsigned int i;
17784         unsigned int nb_item;
17785         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17786 #endif
17787
17788         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17789                 return;
17790
17791 #ifdef RTE_LIBRTE_I40E_PMD
17792         nb_item = parse_item_list(res->pctype_list, "pctypes",
17793                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17794         mapping.flow_type = res->flow_type;
17795         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17796                 mapping.pctype |= (1ULL << pctype_list[i]);
17797         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17798                                                 &mapping,
17799                                                 1,
17800                                                 0);
17801 #endif
17802
17803         switch (ret) {
17804         case 0:
17805                 break;
17806         case -EINVAL:
17807                 printf("invalid pctype or flow type\n");
17808                 break;
17809         case -ENODEV:
17810                 printf("invalid port_id %d\n", res->port_id);
17811                 break;
17812         case -ENOTSUP:
17813                 printf("function not implemented\n");
17814                 break;
17815         default:
17816                 printf("programming error: (%s)\n", strerror(-ret));
17817         }
17818 }
17819
17820 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17821         .f = cmd_pctype_mapping_update_parsed,
17822         .data = NULL,
17823         .help_str = "port config <port_id> pctype mapping update"
17824         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17825         .tokens = {
17826                 (void *)&cmd_pctype_mapping_update_port,
17827                 (void *)&cmd_pctype_mapping_update_config,
17828                 (void *)&cmd_pctype_mapping_update_port_id,
17829                 (void *)&cmd_pctype_mapping_update_pctype,
17830                 (void *)&cmd_pctype_mapping_update_mapping,
17831                 (void *)&cmd_pctype_mapping_update_update,
17832                 (void *)&cmd_pctype_mapping_update_pc_type,
17833                 (void *)&cmd_pctype_mapping_update_flow_type,
17834                 NULL,
17835         },
17836 };
17837
17838 /* ptype mapping get */
17839
17840 /* Common result structure for ptype mapping get */
17841 struct cmd_ptype_mapping_get_result {
17842         cmdline_fixed_string_t ptype;
17843         cmdline_fixed_string_t mapping;
17844         cmdline_fixed_string_t get;
17845         portid_t port_id;
17846         uint8_t valid_only;
17847 };
17848
17849 /* Common CLI fields for ptype mapping get */
17850 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17851         TOKEN_STRING_INITIALIZER
17852                 (struct cmd_ptype_mapping_get_result,
17853                  ptype, "ptype");
17854 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17855         TOKEN_STRING_INITIALIZER
17856                 (struct cmd_ptype_mapping_get_result,
17857                  mapping, "mapping");
17858 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17859         TOKEN_STRING_INITIALIZER
17860                 (struct cmd_ptype_mapping_get_result,
17861                  get, "get");
17862 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17863         TOKEN_NUM_INITIALIZER
17864                 (struct cmd_ptype_mapping_get_result,
17865                  port_id, UINT16);
17866 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17867         TOKEN_NUM_INITIALIZER
17868                 (struct cmd_ptype_mapping_get_result,
17869                  valid_only, UINT8);
17870
17871 static void
17872 cmd_ptype_mapping_get_parsed(
17873         void *parsed_result,
17874         __rte_unused struct cmdline *cl,
17875         __rte_unused void *data)
17876 {
17877         struct cmd_ptype_mapping_get_result *res = parsed_result;
17878         int ret = -ENOTSUP;
17879 #ifdef RTE_LIBRTE_I40E_PMD
17880         int max_ptype_num = 256;
17881         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17882         uint16_t count;
17883         int i;
17884 #endif
17885
17886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17887                 return;
17888
17889 #ifdef RTE_LIBRTE_I40E_PMD
17890         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17891                                         mapping,
17892                                         max_ptype_num,
17893                                         &count,
17894                                         res->valid_only);
17895 #endif
17896
17897         switch (ret) {
17898         case 0:
17899                 break;
17900         case -ENODEV:
17901                 printf("invalid port_id %d\n", res->port_id);
17902                 break;
17903         case -ENOTSUP:
17904                 printf("function not implemented\n");
17905                 break;
17906         default:
17907                 printf("programming error: (%s)\n", strerror(-ret));
17908         }
17909
17910 #ifdef RTE_LIBRTE_I40E_PMD
17911         if (!ret) {
17912                 for (i = 0; i < count; i++)
17913                         printf("%3d\t0x%08x\n",
17914                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17915         }
17916 #endif
17917 }
17918
17919 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17920         .f = cmd_ptype_mapping_get_parsed,
17921         .data = NULL,
17922         .help_str = "ptype mapping get <port_id> <valid_only>",
17923         .tokens = {
17924                 (void *)&cmd_ptype_mapping_get_ptype,
17925                 (void *)&cmd_ptype_mapping_get_mapping,
17926                 (void *)&cmd_ptype_mapping_get_get,
17927                 (void *)&cmd_ptype_mapping_get_port_id,
17928                 (void *)&cmd_ptype_mapping_get_valid_only,
17929                 NULL,
17930         },
17931 };
17932
17933 /* ptype mapping replace */
17934
17935 /* Common result structure for ptype mapping replace */
17936 struct cmd_ptype_mapping_replace_result {
17937         cmdline_fixed_string_t ptype;
17938         cmdline_fixed_string_t mapping;
17939         cmdline_fixed_string_t replace;
17940         portid_t port_id;
17941         uint32_t target;
17942         uint8_t mask;
17943         uint32_t pkt_type;
17944 };
17945
17946 /* Common CLI fields for ptype mapping replace */
17947 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
17948         TOKEN_STRING_INITIALIZER
17949                 (struct cmd_ptype_mapping_replace_result,
17950                  ptype, "ptype");
17951 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
17952         TOKEN_STRING_INITIALIZER
17953                 (struct cmd_ptype_mapping_replace_result,
17954                  mapping, "mapping");
17955 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
17956         TOKEN_STRING_INITIALIZER
17957                 (struct cmd_ptype_mapping_replace_result,
17958                  replace, "replace");
17959 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
17960         TOKEN_NUM_INITIALIZER
17961                 (struct cmd_ptype_mapping_replace_result,
17962                  port_id, UINT16);
17963 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
17964         TOKEN_NUM_INITIALIZER
17965                 (struct cmd_ptype_mapping_replace_result,
17966                  target, UINT32);
17967 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
17968         TOKEN_NUM_INITIALIZER
17969                 (struct cmd_ptype_mapping_replace_result,
17970                  mask, UINT8);
17971 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
17972         TOKEN_NUM_INITIALIZER
17973                 (struct cmd_ptype_mapping_replace_result,
17974                  pkt_type, UINT32);
17975
17976 static void
17977 cmd_ptype_mapping_replace_parsed(
17978         void *parsed_result,
17979         __rte_unused struct cmdline *cl,
17980         __rte_unused void *data)
17981 {
17982         struct cmd_ptype_mapping_replace_result *res = parsed_result;
17983         int ret = -ENOTSUP;
17984
17985         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17986                 return;
17987
17988 #ifdef RTE_LIBRTE_I40E_PMD
17989         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
17990                                         res->target,
17991                                         res->mask,
17992                                         res->pkt_type);
17993 #endif
17994
17995         switch (ret) {
17996         case 0:
17997                 break;
17998         case -EINVAL:
17999                 printf("invalid ptype 0x%8x or 0x%8x\n",
18000                                 res->target, res->pkt_type);
18001                 break;
18002         case -ENODEV:
18003                 printf("invalid port_id %d\n", res->port_id);
18004                 break;
18005         case -ENOTSUP:
18006                 printf("function not implemented\n");
18007                 break;
18008         default:
18009                 printf("programming error: (%s)\n", strerror(-ret));
18010         }
18011 }
18012
18013 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
18014         .f = cmd_ptype_mapping_replace_parsed,
18015         .data = NULL,
18016         .help_str =
18017                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
18018         .tokens = {
18019                 (void *)&cmd_ptype_mapping_replace_ptype,
18020                 (void *)&cmd_ptype_mapping_replace_mapping,
18021                 (void *)&cmd_ptype_mapping_replace_replace,
18022                 (void *)&cmd_ptype_mapping_replace_port_id,
18023                 (void *)&cmd_ptype_mapping_replace_target,
18024                 (void *)&cmd_ptype_mapping_replace_mask,
18025                 (void *)&cmd_ptype_mapping_replace_pkt_type,
18026                 NULL,
18027         },
18028 };
18029
18030 /* ptype mapping reset */
18031
18032 /* Common result structure for ptype mapping reset */
18033 struct cmd_ptype_mapping_reset_result {
18034         cmdline_fixed_string_t ptype;
18035         cmdline_fixed_string_t mapping;
18036         cmdline_fixed_string_t reset;
18037         portid_t port_id;
18038 };
18039
18040 /* Common CLI fields for ptype mapping reset*/
18041 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18042         TOKEN_STRING_INITIALIZER
18043                 (struct cmd_ptype_mapping_reset_result,
18044                  ptype, "ptype");
18045 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18046         TOKEN_STRING_INITIALIZER
18047                 (struct cmd_ptype_mapping_reset_result,
18048                  mapping, "mapping");
18049 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18050         TOKEN_STRING_INITIALIZER
18051                 (struct cmd_ptype_mapping_reset_result,
18052                  reset, "reset");
18053 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18054         TOKEN_NUM_INITIALIZER
18055                 (struct cmd_ptype_mapping_reset_result,
18056                  port_id, UINT16);
18057
18058 static void
18059 cmd_ptype_mapping_reset_parsed(
18060         void *parsed_result,
18061         __rte_unused struct cmdline *cl,
18062         __rte_unused void *data)
18063 {
18064         struct cmd_ptype_mapping_reset_result *res = parsed_result;
18065         int ret = -ENOTSUP;
18066
18067         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18068                 return;
18069
18070 #ifdef RTE_LIBRTE_I40E_PMD
18071         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18072 #endif
18073
18074         switch (ret) {
18075         case 0:
18076                 break;
18077         case -ENODEV:
18078                 printf("invalid port_id %d\n", res->port_id);
18079                 break;
18080         case -ENOTSUP:
18081                 printf("function not implemented\n");
18082                 break;
18083         default:
18084                 printf("programming error: (%s)\n", strerror(-ret));
18085         }
18086 }
18087
18088 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18089         .f = cmd_ptype_mapping_reset_parsed,
18090         .data = NULL,
18091         .help_str = "ptype mapping reset <port_id>",
18092         .tokens = {
18093                 (void *)&cmd_ptype_mapping_reset_ptype,
18094                 (void *)&cmd_ptype_mapping_reset_mapping,
18095                 (void *)&cmd_ptype_mapping_reset_reset,
18096                 (void *)&cmd_ptype_mapping_reset_port_id,
18097                 NULL,
18098         },
18099 };
18100
18101 /* ptype mapping update */
18102
18103 /* Common result structure for ptype mapping update */
18104 struct cmd_ptype_mapping_update_result {
18105         cmdline_fixed_string_t ptype;
18106         cmdline_fixed_string_t mapping;
18107         cmdline_fixed_string_t reset;
18108         portid_t port_id;
18109         uint8_t hw_ptype;
18110         uint32_t sw_ptype;
18111 };
18112
18113 /* Common CLI fields for ptype mapping update*/
18114 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18115         TOKEN_STRING_INITIALIZER
18116                 (struct cmd_ptype_mapping_update_result,
18117                  ptype, "ptype");
18118 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18119         TOKEN_STRING_INITIALIZER
18120                 (struct cmd_ptype_mapping_update_result,
18121                  mapping, "mapping");
18122 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18123         TOKEN_STRING_INITIALIZER
18124                 (struct cmd_ptype_mapping_update_result,
18125                  reset, "update");
18126 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18127         TOKEN_NUM_INITIALIZER
18128                 (struct cmd_ptype_mapping_update_result,
18129                  port_id, UINT16);
18130 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18131         TOKEN_NUM_INITIALIZER
18132                 (struct cmd_ptype_mapping_update_result,
18133                  hw_ptype, UINT8);
18134 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18135         TOKEN_NUM_INITIALIZER
18136                 (struct cmd_ptype_mapping_update_result,
18137                  sw_ptype, UINT32);
18138
18139 static void
18140 cmd_ptype_mapping_update_parsed(
18141         void *parsed_result,
18142         __rte_unused struct cmdline *cl,
18143         __rte_unused void *data)
18144 {
18145         struct cmd_ptype_mapping_update_result *res = parsed_result;
18146         int ret = -ENOTSUP;
18147 #ifdef RTE_LIBRTE_I40E_PMD
18148         struct rte_pmd_i40e_ptype_mapping mapping;
18149 #endif
18150         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18151                 return;
18152
18153 #ifdef RTE_LIBRTE_I40E_PMD
18154         mapping.hw_ptype = res->hw_ptype;
18155         mapping.sw_ptype = res->sw_ptype;
18156         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18157                                                 &mapping,
18158                                                 1,
18159                                                 0);
18160 #endif
18161
18162         switch (ret) {
18163         case 0:
18164                 break;
18165         case -EINVAL:
18166                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18167                 break;
18168         case -ENODEV:
18169                 printf("invalid port_id %d\n", res->port_id);
18170                 break;
18171         case -ENOTSUP:
18172                 printf("function not implemented\n");
18173                 break;
18174         default:
18175                 printf("programming error: (%s)\n", strerror(-ret));
18176         }
18177 }
18178
18179 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18180         .f = cmd_ptype_mapping_update_parsed,
18181         .data = NULL,
18182         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18183         .tokens = {
18184                 (void *)&cmd_ptype_mapping_update_ptype,
18185                 (void *)&cmd_ptype_mapping_update_mapping,
18186                 (void *)&cmd_ptype_mapping_update_update,
18187                 (void *)&cmd_ptype_mapping_update_port_id,
18188                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18189                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18190                 NULL,
18191         },
18192 };
18193
18194 /* Common result structure for file commands */
18195 struct cmd_cmdfile_result {
18196         cmdline_fixed_string_t load;
18197         cmdline_fixed_string_t filename;
18198 };
18199
18200 /* Common CLI fields for file commands */
18201 cmdline_parse_token_string_t cmd_load_cmdfile =
18202         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18203 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18204         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18205
18206 static void
18207 cmd_load_from_file_parsed(
18208         void *parsed_result,
18209         __rte_unused struct cmdline *cl,
18210         __rte_unused void *data)
18211 {
18212         struct cmd_cmdfile_result *res = parsed_result;
18213
18214         cmdline_read_from_file(res->filename);
18215 }
18216
18217 cmdline_parse_inst_t cmd_load_from_file = {
18218         .f = cmd_load_from_file_parsed,
18219         .data = NULL,
18220         .help_str = "load <filename>",
18221         .tokens = {
18222                 (void *)&cmd_load_cmdfile,
18223                 (void *)&cmd_load_cmdfile_filename,
18224                 NULL,
18225         },
18226 };
18227
18228 /* Get Rx offloads capabilities */
18229 struct cmd_rx_offload_get_capa_result {
18230         cmdline_fixed_string_t show;
18231         cmdline_fixed_string_t port;
18232         portid_t port_id;
18233         cmdline_fixed_string_t rx_offload;
18234         cmdline_fixed_string_t capabilities;
18235 };
18236
18237 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18238         TOKEN_STRING_INITIALIZER
18239                 (struct cmd_rx_offload_get_capa_result,
18240                  show, "show");
18241 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18242         TOKEN_STRING_INITIALIZER
18243                 (struct cmd_rx_offload_get_capa_result,
18244                  port, "port");
18245 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18246         TOKEN_NUM_INITIALIZER
18247                 (struct cmd_rx_offload_get_capa_result,
18248                  port_id, UINT16);
18249 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18250         TOKEN_STRING_INITIALIZER
18251                 (struct cmd_rx_offload_get_capa_result,
18252                  rx_offload, "rx_offload");
18253 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18254         TOKEN_STRING_INITIALIZER
18255                 (struct cmd_rx_offload_get_capa_result,
18256                  capabilities, "capabilities");
18257
18258 static void
18259 print_rx_offloads(uint64_t offloads)
18260 {
18261         uint64_t single_offload;
18262         int begin;
18263         int end;
18264         int bit;
18265
18266         if (offloads == 0)
18267                 return;
18268
18269         begin = __builtin_ctzll(offloads);
18270         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18271
18272         single_offload = 1ULL << begin;
18273         for (bit = begin; bit < end; bit++) {
18274                 if (offloads & single_offload)
18275                         printf(" %s",
18276                                rte_eth_dev_rx_offload_name(single_offload));
18277                 single_offload <<= 1;
18278         }
18279 }
18280
18281 static void
18282 cmd_rx_offload_get_capa_parsed(
18283         void *parsed_result,
18284         __rte_unused struct cmdline *cl,
18285         __rte_unused void *data)
18286 {
18287         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18288         struct rte_eth_dev_info dev_info;
18289         portid_t port_id = res->port_id;
18290         uint64_t queue_offloads;
18291         uint64_t port_offloads;
18292         int ret;
18293
18294         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18295         if (ret != 0)
18296                 return;
18297
18298         queue_offloads = dev_info.rx_queue_offload_capa;
18299         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18300
18301         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18302         printf("  Per Queue :");
18303         print_rx_offloads(queue_offloads);
18304
18305         printf("\n");
18306         printf("  Per Port  :");
18307         print_rx_offloads(port_offloads);
18308         printf("\n\n");
18309 }
18310
18311 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18312         .f = cmd_rx_offload_get_capa_parsed,
18313         .data = NULL,
18314         .help_str = "show port <port_id> rx_offload capabilities",
18315         .tokens = {
18316                 (void *)&cmd_rx_offload_get_capa_show,
18317                 (void *)&cmd_rx_offload_get_capa_port,
18318                 (void *)&cmd_rx_offload_get_capa_port_id,
18319                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18320                 (void *)&cmd_rx_offload_get_capa_capabilities,
18321                 NULL,
18322         }
18323 };
18324
18325 /* Get Rx offloads configuration */
18326 struct cmd_rx_offload_get_configuration_result {
18327         cmdline_fixed_string_t show;
18328         cmdline_fixed_string_t port;
18329         portid_t port_id;
18330         cmdline_fixed_string_t rx_offload;
18331         cmdline_fixed_string_t configuration;
18332 };
18333
18334 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18335         TOKEN_STRING_INITIALIZER
18336                 (struct cmd_rx_offload_get_configuration_result,
18337                  show, "show");
18338 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18339         TOKEN_STRING_INITIALIZER
18340                 (struct cmd_rx_offload_get_configuration_result,
18341                  port, "port");
18342 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18343         TOKEN_NUM_INITIALIZER
18344                 (struct cmd_rx_offload_get_configuration_result,
18345                  port_id, UINT16);
18346 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18347         TOKEN_STRING_INITIALIZER
18348                 (struct cmd_rx_offload_get_configuration_result,
18349                  rx_offload, "rx_offload");
18350 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18351         TOKEN_STRING_INITIALIZER
18352                 (struct cmd_rx_offload_get_configuration_result,
18353                  configuration, "configuration");
18354
18355 static void
18356 cmd_rx_offload_get_configuration_parsed(
18357         void *parsed_result,
18358         __rte_unused struct cmdline *cl,
18359         __rte_unused void *data)
18360 {
18361         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18362         struct rte_eth_dev_info dev_info;
18363         portid_t port_id = res->port_id;
18364         struct rte_port *port = &ports[port_id];
18365         uint64_t port_offloads;
18366         uint64_t queue_offloads;
18367         uint16_t nb_rx_queues;
18368         int q;
18369         int ret;
18370
18371         printf("Rx Offloading Configuration of port %d :\n", port_id);
18372
18373         port_offloads = port->dev_conf.rxmode.offloads;
18374         printf("  Port :");
18375         print_rx_offloads(port_offloads);
18376         printf("\n");
18377
18378         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18379         if (ret != 0)
18380                 return;
18381
18382         nb_rx_queues = dev_info.nb_rx_queues;
18383         for (q = 0; q < nb_rx_queues; q++) {
18384                 queue_offloads = port->rx_conf[q].offloads;
18385                 printf("  Queue[%2d] :", q);
18386                 print_rx_offloads(queue_offloads);
18387                 printf("\n");
18388         }
18389         printf("\n");
18390 }
18391
18392 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18393         .f = cmd_rx_offload_get_configuration_parsed,
18394         .data = NULL,
18395         .help_str = "show port <port_id> rx_offload configuration",
18396         .tokens = {
18397                 (void *)&cmd_rx_offload_get_configuration_show,
18398                 (void *)&cmd_rx_offload_get_configuration_port,
18399                 (void *)&cmd_rx_offload_get_configuration_port_id,
18400                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18401                 (void *)&cmd_rx_offload_get_configuration_configuration,
18402                 NULL,
18403         }
18404 };
18405
18406 /* Enable/Disable a per port offloading */
18407 struct cmd_config_per_port_rx_offload_result {
18408         cmdline_fixed_string_t port;
18409         cmdline_fixed_string_t config;
18410         portid_t port_id;
18411         cmdline_fixed_string_t rx_offload;
18412         cmdline_fixed_string_t offload;
18413         cmdline_fixed_string_t on_off;
18414 };
18415
18416 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18417         TOKEN_STRING_INITIALIZER
18418                 (struct cmd_config_per_port_rx_offload_result,
18419                  port, "port");
18420 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18421         TOKEN_STRING_INITIALIZER
18422                 (struct cmd_config_per_port_rx_offload_result,
18423                  config, "config");
18424 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18425         TOKEN_NUM_INITIALIZER
18426                 (struct cmd_config_per_port_rx_offload_result,
18427                  port_id, UINT16);
18428 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18429         TOKEN_STRING_INITIALIZER
18430                 (struct cmd_config_per_port_rx_offload_result,
18431                  rx_offload, "rx_offload");
18432 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18433         TOKEN_STRING_INITIALIZER
18434                 (struct cmd_config_per_port_rx_offload_result,
18435                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18436                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18437                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18438                            "scatter#timestamp#security#keep_crc#rss_hash");
18439 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18440         TOKEN_STRING_INITIALIZER
18441                 (struct cmd_config_per_port_rx_offload_result,
18442                  on_off, "on#off");
18443
18444 static uint64_t
18445 search_rx_offload(const char *name)
18446 {
18447         uint64_t single_offload;
18448         const char *single_name;
18449         int found = 0;
18450         unsigned int bit;
18451
18452         single_offload = 1;
18453         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18454                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18455                 if (!strcasecmp(single_name, name)) {
18456                         found = 1;
18457                         break;
18458                 }
18459                 single_offload <<= 1;
18460         }
18461
18462         if (found)
18463                 return single_offload;
18464
18465         return 0;
18466 }
18467
18468 static void
18469 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18470                                 __rte_unused struct cmdline *cl,
18471                                 __rte_unused void *data)
18472 {
18473         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18474         portid_t port_id = res->port_id;
18475         struct rte_eth_dev_info dev_info;
18476         struct rte_port *port = &ports[port_id];
18477         uint64_t single_offload;
18478         uint16_t nb_rx_queues;
18479         int q;
18480         int ret;
18481
18482         if (port->port_status != RTE_PORT_STOPPED) {
18483                 printf("Error: Can't config offload when Port %d "
18484                        "is not stopped\n", port_id);
18485                 return;
18486         }
18487
18488         single_offload = search_rx_offload(res->offload);
18489         if (single_offload == 0) {
18490                 printf("Unknown offload name: %s\n", res->offload);
18491                 return;
18492         }
18493
18494         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18495         if (ret != 0)
18496                 return;
18497
18498         nb_rx_queues = dev_info.nb_rx_queues;
18499         if (!strcmp(res->on_off, "on")) {
18500                 port->dev_conf.rxmode.offloads |= single_offload;
18501                 for (q = 0; q < nb_rx_queues; q++)
18502                         port->rx_conf[q].offloads |= single_offload;
18503         } else {
18504                 port->dev_conf.rxmode.offloads &= ~single_offload;
18505                 for (q = 0; q < nb_rx_queues; q++)
18506                         port->rx_conf[q].offloads &= ~single_offload;
18507         }
18508
18509         cmd_reconfig_device_queue(port_id, 1, 1);
18510 }
18511
18512 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18513         .f = cmd_config_per_port_rx_offload_parsed,
18514         .data = NULL,
18515         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18516                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18517                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18518                     "jumbo_frame|scatter|timestamp|security|keep_crc|rss_hash "
18519                     "on|off",
18520         .tokens = {
18521                 (void *)&cmd_config_per_port_rx_offload_result_port,
18522                 (void *)&cmd_config_per_port_rx_offload_result_config,
18523                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18524                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18525                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18526                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18527                 NULL,
18528         }
18529 };
18530
18531 /* Enable/Disable a per queue offloading */
18532 struct cmd_config_per_queue_rx_offload_result {
18533         cmdline_fixed_string_t port;
18534         portid_t port_id;
18535         cmdline_fixed_string_t rxq;
18536         uint16_t queue_id;
18537         cmdline_fixed_string_t rx_offload;
18538         cmdline_fixed_string_t offload;
18539         cmdline_fixed_string_t on_off;
18540 };
18541
18542 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18543         TOKEN_STRING_INITIALIZER
18544                 (struct cmd_config_per_queue_rx_offload_result,
18545                  port, "port");
18546 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18547         TOKEN_NUM_INITIALIZER
18548                 (struct cmd_config_per_queue_rx_offload_result,
18549                  port_id, UINT16);
18550 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18551         TOKEN_STRING_INITIALIZER
18552                 (struct cmd_config_per_queue_rx_offload_result,
18553                  rxq, "rxq");
18554 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18555         TOKEN_NUM_INITIALIZER
18556                 (struct cmd_config_per_queue_rx_offload_result,
18557                  queue_id, UINT16);
18558 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18559         TOKEN_STRING_INITIALIZER
18560                 (struct cmd_config_per_queue_rx_offload_result,
18561                  rx_offload, "rx_offload");
18562 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18563         TOKEN_STRING_INITIALIZER
18564                 (struct cmd_config_per_queue_rx_offload_result,
18565                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18566                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18567                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18568                            "scatter#timestamp#security#keep_crc");
18569 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18570         TOKEN_STRING_INITIALIZER
18571                 (struct cmd_config_per_queue_rx_offload_result,
18572                  on_off, "on#off");
18573
18574 static void
18575 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18576                                 __rte_unused struct cmdline *cl,
18577                                 __rte_unused void *data)
18578 {
18579         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18580         struct rte_eth_dev_info dev_info;
18581         portid_t port_id = res->port_id;
18582         uint16_t queue_id = res->queue_id;
18583         struct rte_port *port = &ports[port_id];
18584         uint64_t single_offload;
18585         int ret;
18586
18587         if (port->port_status != RTE_PORT_STOPPED) {
18588                 printf("Error: Can't config offload when Port %d "
18589                        "is not stopped\n", port_id);
18590                 return;
18591         }
18592
18593         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18594         if (ret != 0)
18595                 return;
18596
18597         if (queue_id >= dev_info.nb_rx_queues) {
18598                 printf("Error: input queue_id should be 0 ... "
18599                        "%d\n", dev_info.nb_rx_queues - 1);
18600                 return;
18601         }
18602
18603         single_offload = search_rx_offload(res->offload);
18604         if (single_offload == 0) {
18605                 printf("Unknown offload name: %s\n", res->offload);
18606                 return;
18607         }
18608
18609         if (!strcmp(res->on_off, "on"))
18610                 port->rx_conf[queue_id].offloads |= single_offload;
18611         else
18612                 port->rx_conf[queue_id].offloads &= ~single_offload;
18613
18614         cmd_reconfig_device_queue(port_id, 1, 1);
18615 }
18616
18617 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18618         .f = cmd_config_per_queue_rx_offload_parsed,
18619         .data = NULL,
18620         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18621                     "vlan_strip|ipv4_cksum|"
18622                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18623                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18624                     "jumbo_frame|scatter|timestamp|security|keep_crc "
18625                     "on|off",
18626         .tokens = {
18627                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18628                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18629                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18630                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18631                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18632                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18633                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18634                 NULL,
18635         }
18636 };
18637
18638 /* Get Tx offloads capabilities */
18639 struct cmd_tx_offload_get_capa_result {
18640         cmdline_fixed_string_t show;
18641         cmdline_fixed_string_t port;
18642         portid_t port_id;
18643         cmdline_fixed_string_t tx_offload;
18644         cmdline_fixed_string_t capabilities;
18645 };
18646
18647 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18648         TOKEN_STRING_INITIALIZER
18649                 (struct cmd_tx_offload_get_capa_result,
18650                  show, "show");
18651 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18652         TOKEN_STRING_INITIALIZER
18653                 (struct cmd_tx_offload_get_capa_result,
18654                  port, "port");
18655 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18656         TOKEN_NUM_INITIALIZER
18657                 (struct cmd_tx_offload_get_capa_result,
18658                  port_id, UINT16);
18659 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18660         TOKEN_STRING_INITIALIZER
18661                 (struct cmd_tx_offload_get_capa_result,
18662                  tx_offload, "tx_offload");
18663 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18664         TOKEN_STRING_INITIALIZER
18665                 (struct cmd_tx_offload_get_capa_result,
18666                  capabilities, "capabilities");
18667
18668 static void
18669 print_tx_offloads(uint64_t offloads)
18670 {
18671         uint64_t single_offload;
18672         int begin;
18673         int end;
18674         int bit;
18675
18676         if (offloads == 0)
18677                 return;
18678
18679         begin = __builtin_ctzll(offloads);
18680         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18681
18682         single_offload = 1ULL << begin;
18683         for (bit = begin; bit < end; bit++) {
18684                 if (offloads & single_offload)
18685                         printf(" %s",
18686                                rte_eth_dev_tx_offload_name(single_offload));
18687                 single_offload <<= 1;
18688         }
18689 }
18690
18691 static void
18692 cmd_tx_offload_get_capa_parsed(
18693         void *parsed_result,
18694         __rte_unused struct cmdline *cl,
18695         __rte_unused void *data)
18696 {
18697         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18698         struct rte_eth_dev_info dev_info;
18699         portid_t port_id = res->port_id;
18700         uint64_t queue_offloads;
18701         uint64_t port_offloads;
18702         int ret;
18703
18704         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18705         if (ret != 0)
18706                 return;
18707
18708         queue_offloads = dev_info.tx_queue_offload_capa;
18709         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18710
18711         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18712         printf("  Per Queue :");
18713         print_tx_offloads(queue_offloads);
18714
18715         printf("\n");
18716         printf("  Per Port  :");
18717         print_tx_offloads(port_offloads);
18718         printf("\n\n");
18719 }
18720
18721 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18722         .f = cmd_tx_offload_get_capa_parsed,
18723         .data = NULL,
18724         .help_str = "show port <port_id> tx_offload capabilities",
18725         .tokens = {
18726                 (void *)&cmd_tx_offload_get_capa_show,
18727                 (void *)&cmd_tx_offload_get_capa_port,
18728                 (void *)&cmd_tx_offload_get_capa_port_id,
18729                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18730                 (void *)&cmd_tx_offload_get_capa_capabilities,
18731                 NULL,
18732         }
18733 };
18734
18735 /* Get Tx offloads configuration */
18736 struct cmd_tx_offload_get_configuration_result {
18737         cmdline_fixed_string_t show;
18738         cmdline_fixed_string_t port;
18739         portid_t port_id;
18740         cmdline_fixed_string_t tx_offload;
18741         cmdline_fixed_string_t configuration;
18742 };
18743
18744 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18745         TOKEN_STRING_INITIALIZER
18746                 (struct cmd_tx_offload_get_configuration_result,
18747                  show, "show");
18748 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18749         TOKEN_STRING_INITIALIZER
18750                 (struct cmd_tx_offload_get_configuration_result,
18751                  port, "port");
18752 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18753         TOKEN_NUM_INITIALIZER
18754                 (struct cmd_tx_offload_get_configuration_result,
18755                  port_id, UINT16);
18756 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18757         TOKEN_STRING_INITIALIZER
18758                 (struct cmd_tx_offload_get_configuration_result,
18759                  tx_offload, "tx_offload");
18760 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18761         TOKEN_STRING_INITIALIZER
18762                 (struct cmd_tx_offload_get_configuration_result,
18763                  configuration, "configuration");
18764
18765 static void
18766 cmd_tx_offload_get_configuration_parsed(
18767         void *parsed_result,
18768         __rte_unused struct cmdline *cl,
18769         __rte_unused void *data)
18770 {
18771         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18772         struct rte_eth_dev_info dev_info;
18773         portid_t port_id = res->port_id;
18774         struct rte_port *port = &ports[port_id];
18775         uint64_t port_offloads;
18776         uint64_t queue_offloads;
18777         uint16_t nb_tx_queues;
18778         int q;
18779         int ret;
18780
18781         printf("Tx Offloading Configuration of port %d :\n", port_id);
18782
18783         port_offloads = port->dev_conf.txmode.offloads;
18784         printf("  Port :");
18785         print_tx_offloads(port_offloads);
18786         printf("\n");
18787
18788         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18789         if (ret != 0)
18790                 return;
18791
18792         nb_tx_queues = dev_info.nb_tx_queues;
18793         for (q = 0; q < nb_tx_queues; q++) {
18794                 queue_offloads = port->tx_conf[q].offloads;
18795                 printf("  Queue[%2d] :", q);
18796                 print_tx_offloads(queue_offloads);
18797                 printf("\n");
18798         }
18799         printf("\n");
18800 }
18801
18802 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18803         .f = cmd_tx_offload_get_configuration_parsed,
18804         .data = NULL,
18805         .help_str = "show port <port_id> tx_offload configuration",
18806         .tokens = {
18807                 (void *)&cmd_tx_offload_get_configuration_show,
18808                 (void *)&cmd_tx_offload_get_configuration_port,
18809                 (void *)&cmd_tx_offload_get_configuration_port_id,
18810                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18811                 (void *)&cmd_tx_offload_get_configuration_configuration,
18812                 NULL,
18813         }
18814 };
18815
18816 /* Enable/Disable a per port offloading */
18817 struct cmd_config_per_port_tx_offload_result {
18818         cmdline_fixed_string_t port;
18819         cmdline_fixed_string_t config;
18820         portid_t port_id;
18821         cmdline_fixed_string_t tx_offload;
18822         cmdline_fixed_string_t offload;
18823         cmdline_fixed_string_t on_off;
18824 };
18825
18826 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18827         TOKEN_STRING_INITIALIZER
18828                 (struct cmd_config_per_port_tx_offload_result,
18829                  port, "port");
18830 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18831         TOKEN_STRING_INITIALIZER
18832                 (struct cmd_config_per_port_tx_offload_result,
18833                  config, "config");
18834 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18835         TOKEN_NUM_INITIALIZER
18836                 (struct cmd_config_per_port_tx_offload_result,
18837                  port_id, UINT16);
18838 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18839         TOKEN_STRING_INITIALIZER
18840                 (struct cmd_config_per_port_tx_offload_result,
18841                  tx_offload, "tx_offload");
18842 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18843         TOKEN_STRING_INITIALIZER
18844                 (struct cmd_config_per_port_tx_offload_result,
18845                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18846                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18847                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18848                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18849                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18850                           "send_on_timestamp");
18851 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18852         TOKEN_STRING_INITIALIZER
18853                 (struct cmd_config_per_port_tx_offload_result,
18854                  on_off, "on#off");
18855
18856 static uint64_t
18857 search_tx_offload(const char *name)
18858 {
18859         uint64_t single_offload;
18860         const char *single_name;
18861         int found = 0;
18862         unsigned int bit;
18863
18864         single_offload = 1;
18865         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18866                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18867                 if (single_name == NULL)
18868                         break;
18869                 if (!strcasecmp(single_name, name)) {
18870                         found = 1;
18871                         break;
18872                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18873                         break;
18874                 single_offload <<= 1;
18875         }
18876
18877         if (found)
18878                 return single_offload;
18879
18880         return 0;
18881 }
18882
18883 static void
18884 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18885                                 __rte_unused struct cmdline *cl,
18886                                 __rte_unused void *data)
18887 {
18888         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18889         portid_t port_id = res->port_id;
18890         struct rte_eth_dev_info dev_info;
18891         struct rte_port *port = &ports[port_id];
18892         uint64_t single_offload;
18893         uint16_t nb_tx_queues;
18894         int q;
18895         int ret;
18896
18897         if (port->port_status != RTE_PORT_STOPPED) {
18898                 printf("Error: Can't config offload when Port %d "
18899                        "is not stopped\n", port_id);
18900                 return;
18901         }
18902
18903         single_offload = search_tx_offload(res->offload);
18904         if (single_offload == 0) {
18905                 printf("Unknown offload name: %s\n", res->offload);
18906                 return;
18907         }
18908
18909         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18910         if (ret != 0)
18911                 return;
18912
18913         nb_tx_queues = dev_info.nb_tx_queues;
18914         if (!strcmp(res->on_off, "on")) {
18915                 port->dev_conf.txmode.offloads |= single_offload;
18916                 for (q = 0; q < nb_tx_queues; q++)
18917                         port->tx_conf[q].offloads |= single_offload;
18918         } else {
18919                 port->dev_conf.txmode.offloads &= ~single_offload;
18920                 for (q = 0; q < nb_tx_queues; q++)
18921                         port->tx_conf[q].offloads &= ~single_offload;
18922         }
18923
18924         cmd_reconfig_device_queue(port_id, 1, 1);
18925 }
18926
18927 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18928         .f = cmd_config_per_port_tx_offload_parsed,
18929         .data = NULL,
18930         .help_str = "port config <port_id> tx_offload "
18931                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18932                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18933                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18934                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18935                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18936                     "send_on_timestamp on|off",
18937         .tokens = {
18938                 (void *)&cmd_config_per_port_tx_offload_result_port,
18939                 (void *)&cmd_config_per_port_tx_offload_result_config,
18940                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18941                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18942                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18943                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18944                 NULL,
18945         }
18946 };
18947
18948 /* Enable/Disable a per queue offloading */
18949 struct cmd_config_per_queue_tx_offload_result {
18950         cmdline_fixed_string_t port;
18951         portid_t port_id;
18952         cmdline_fixed_string_t txq;
18953         uint16_t queue_id;
18954         cmdline_fixed_string_t tx_offload;
18955         cmdline_fixed_string_t offload;
18956         cmdline_fixed_string_t on_off;
18957 };
18958
18959 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
18960         TOKEN_STRING_INITIALIZER
18961                 (struct cmd_config_per_queue_tx_offload_result,
18962                  port, "port");
18963 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
18964         TOKEN_NUM_INITIALIZER
18965                 (struct cmd_config_per_queue_tx_offload_result,
18966                  port_id, UINT16);
18967 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
18968         TOKEN_STRING_INITIALIZER
18969                 (struct cmd_config_per_queue_tx_offload_result,
18970                  txq, "txq");
18971 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
18972         TOKEN_NUM_INITIALIZER
18973                 (struct cmd_config_per_queue_tx_offload_result,
18974                  queue_id, UINT16);
18975 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
18976         TOKEN_STRING_INITIALIZER
18977                 (struct cmd_config_per_queue_tx_offload_result,
18978                  tx_offload, "tx_offload");
18979 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
18980         TOKEN_STRING_INITIALIZER
18981                 (struct cmd_config_per_queue_tx_offload_result,
18982                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18983                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18984                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18985                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18986                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
18987 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
18988         TOKEN_STRING_INITIALIZER
18989                 (struct cmd_config_per_queue_tx_offload_result,
18990                  on_off, "on#off");
18991
18992 static void
18993 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
18994                                 __rte_unused struct cmdline *cl,
18995                                 __rte_unused void *data)
18996 {
18997         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
18998         struct rte_eth_dev_info dev_info;
18999         portid_t port_id = res->port_id;
19000         uint16_t queue_id = res->queue_id;
19001         struct rte_port *port = &ports[port_id];
19002         uint64_t single_offload;
19003         int ret;
19004
19005         if (port->port_status != RTE_PORT_STOPPED) {
19006                 printf("Error: Can't config offload when Port %d "
19007                        "is not stopped\n", port_id);
19008                 return;
19009         }
19010
19011         ret = eth_dev_info_get_print_err(port_id, &dev_info);
19012         if (ret != 0)
19013                 return;
19014
19015         if (queue_id >= dev_info.nb_tx_queues) {
19016                 printf("Error: input queue_id should be 0 ... "
19017                        "%d\n", dev_info.nb_tx_queues - 1);
19018                 return;
19019         }
19020
19021         single_offload = search_tx_offload(res->offload);
19022         if (single_offload == 0) {
19023                 printf("Unknown offload name: %s\n", res->offload);
19024                 return;
19025         }
19026
19027         if (!strcmp(res->on_off, "on"))
19028                 port->tx_conf[queue_id].offloads |= single_offload;
19029         else
19030                 port->tx_conf[queue_id].offloads &= ~single_offload;
19031
19032         cmd_reconfig_device_queue(port_id, 1, 1);
19033 }
19034
19035 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19036         .f = cmd_config_per_queue_tx_offload_parsed,
19037         .data = NULL,
19038         .help_str = "port <port_id> txq <queue_id> tx_offload "
19039                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19040                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19041                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19042                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19043                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
19044                     "on|off",
19045         .tokens = {
19046                 (void *)&cmd_config_per_queue_tx_offload_result_port,
19047                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
19048                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
19049                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19050                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19051                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
19052                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
19053                 NULL,
19054         }
19055 };
19056
19057 /* *** configure tx_metadata for specific port *** */
19058 struct cmd_config_tx_metadata_specific_result {
19059         cmdline_fixed_string_t port;
19060         cmdline_fixed_string_t keyword;
19061         uint16_t port_id;
19062         cmdline_fixed_string_t item;
19063         uint32_t value;
19064 };
19065
19066 static void
19067 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19068                                 __rte_unused struct cmdline *cl,
19069                                 __rte_unused void *data)
19070 {
19071         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19072
19073         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19074                 return;
19075         ports[res->port_id].tx_metadata = res->value;
19076         /* Add/remove callback to insert valid metadata in every Tx packet. */
19077         if (ports[res->port_id].tx_metadata)
19078                 add_tx_md_callback(res->port_id);
19079         else
19080                 remove_tx_md_callback(res->port_id);
19081         rte_flow_dynf_metadata_register();
19082 }
19083
19084 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19085         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19086                         port, "port");
19087 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19088         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19089                         keyword, "config");
19090 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19091         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19092                         port_id, UINT16);
19093 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19094         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19095                         item, "tx_metadata");
19096 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19097         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19098                         value, UINT32);
19099
19100 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19101         .f = cmd_config_tx_metadata_specific_parsed,
19102         .data = NULL,
19103         .help_str = "port config <port_id> tx_metadata <value>",
19104         .tokens = {
19105                 (void *)&cmd_config_tx_metadata_specific_port,
19106                 (void *)&cmd_config_tx_metadata_specific_keyword,
19107                 (void *)&cmd_config_tx_metadata_specific_id,
19108                 (void *)&cmd_config_tx_metadata_specific_item,
19109                 (void *)&cmd_config_tx_metadata_specific_value,
19110                 NULL,
19111         },
19112 };
19113
19114 /* *** set dynf *** */
19115 struct cmd_config_tx_dynf_specific_result {
19116         cmdline_fixed_string_t port;
19117         cmdline_fixed_string_t keyword;
19118         uint16_t port_id;
19119         cmdline_fixed_string_t item;
19120         cmdline_fixed_string_t name;
19121         cmdline_fixed_string_t value;
19122 };
19123
19124 static void
19125 cmd_config_dynf_specific_parsed(void *parsed_result,
19126                                 __rte_unused struct cmdline *cl,
19127                                 __rte_unused void *data)
19128 {
19129         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19130         struct rte_mbuf_dynflag desc_flag;
19131         int flag;
19132         uint64_t old_port_flags;
19133
19134         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19135                 return;
19136         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19137         if (flag <= 0) {
19138                 if (strlcpy(desc_flag.name, res->name,
19139                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19140                         printf("Flag name too long\n");
19141                         return;
19142                 }
19143                 desc_flag.flags = 0;
19144                 flag = rte_mbuf_dynflag_register(&desc_flag);
19145                 if (flag < 0) {
19146                         printf("Can't register flag\n");
19147                         return;
19148                 }
19149                 strcpy(dynf_names[flag], desc_flag.name);
19150         }
19151         old_port_flags = ports[res->port_id].mbuf_dynf;
19152         if (!strcmp(res->value, "set")) {
19153                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19154                 if (old_port_flags == 0)
19155                         add_tx_dynf_callback(res->port_id);
19156         } else {
19157                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19158                 if (ports[res->port_id].mbuf_dynf == 0)
19159                         remove_tx_dynf_callback(res->port_id);
19160         }
19161 }
19162
19163 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19164         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19165                         keyword, "port");
19166 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19167         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19168                         keyword, "config");
19169 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19170         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19171                         port_id, UINT16);
19172 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19173         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19174                         item, "dynf");
19175 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19176         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19177                         name, NULL);
19178 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19179         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19180                         value, "set#clear");
19181
19182 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19183         .f = cmd_config_dynf_specific_parsed,
19184         .data = NULL,
19185         .help_str = "port config <port id> dynf <name> set|clear",
19186         .tokens = {
19187                 (void *)&cmd_config_tx_dynf_specific_port,
19188                 (void *)&cmd_config_tx_dynf_specific_keyword,
19189                 (void *)&cmd_config_tx_dynf_specific_port_id,
19190                 (void *)&cmd_config_tx_dynf_specific_item,
19191                 (void *)&cmd_config_tx_dynf_specific_name,
19192                 (void *)&cmd_config_tx_dynf_specific_value,
19193                 NULL,
19194         },
19195 };
19196
19197 /* *** display tx_metadata per port configuration *** */
19198 struct cmd_show_tx_metadata_result {
19199         cmdline_fixed_string_t cmd_show;
19200         cmdline_fixed_string_t cmd_port;
19201         cmdline_fixed_string_t cmd_keyword;
19202         portid_t cmd_pid;
19203 };
19204
19205 static void
19206 cmd_show_tx_metadata_parsed(void *parsed_result,
19207                 __rte_unused struct cmdline *cl,
19208                 __rte_unused void *data)
19209 {
19210         struct cmd_show_tx_metadata_result *res = parsed_result;
19211
19212         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19213                 printf("invalid port id %u\n", res->cmd_pid);
19214                 return;
19215         }
19216         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19217                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19218                        ports[res->cmd_pid].tx_metadata);
19219         }
19220 }
19221
19222 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19223         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19224                         cmd_show, "show");
19225 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19226         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19227                         cmd_port, "port");
19228 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19229         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19230                         cmd_pid, UINT16);
19231 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19232         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19233                         cmd_keyword, "tx_metadata");
19234
19235 cmdline_parse_inst_t cmd_show_tx_metadata = {
19236         .f = cmd_show_tx_metadata_parsed,
19237         .data = NULL,
19238         .help_str = "show port <port_id> tx_metadata",
19239         .tokens = {
19240                 (void *)&cmd_show_tx_metadata_show,
19241                 (void *)&cmd_show_tx_metadata_port,
19242                 (void *)&cmd_show_tx_metadata_pid,
19243                 (void *)&cmd_show_tx_metadata_keyword,
19244                 NULL,
19245         },
19246 };
19247
19248 /* *** show fec capability per port configuration *** */
19249 struct cmd_show_fec_capability_result {
19250         cmdline_fixed_string_t cmd_show;
19251         cmdline_fixed_string_t cmd_port;
19252         cmdline_fixed_string_t cmd_fec;
19253         cmdline_fixed_string_t cmd_keyword;
19254         portid_t cmd_pid;
19255 };
19256
19257 static void
19258 cmd_show_fec_capability_parsed(void *parsed_result,
19259                 __rte_unused struct cmdline *cl,
19260                 __rte_unused void *data)
19261 {
19262 #define FEC_CAP_NUM 2
19263         struct cmd_show_fec_capability_result *res = parsed_result;
19264         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19265         unsigned int num = FEC_CAP_NUM;
19266         unsigned int ret_num;
19267         int ret;
19268
19269         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19270                 printf("Invalid port id %u\n", res->cmd_pid);
19271                 return;
19272         }
19273
19274         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19275         if (ret == -ENOTSUP) {
19276                 printf("Function not implemented\n");
19277                 return;
19278         } else if (ret < 0) {
19279                 printf("Get FEC capability failed\n");
19280                 return;
19281         }
19282
19283         ret_num = (unsigned int)ret;
19284         show_fec_capability(ret_num, speed_fec_capa);
19285 }
19286
19287 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19288         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19289                         cmd_show, "show");
19290 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19291         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19292                         cmd_port, "port");
19293 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19294         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19295                         cmd_pid, UINT16);
19296 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19297         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19298                         cmd_fec, "fec");
19299 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19300         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19301                         cmd_keyword, "capabilities");
19302
19303 cmdline_parse_inst_t cmd_show_capability = {
19304         .f = cmd_show_fec_capability_parsed,
19305         .data = NULL,
19306         .help_str = "show port <port_id> fec capabilities",
19307         .tokens = {
19308                 (void *)&cmd_show_fec_capability_show,
19309                 (void *)&cmd_show_fec_capability_port,
19310                 (void *)&cmd_show_fec_capability_pid,
19311                 (void *)&cmd_show_fec_capability_fec,
19312                 (void *)&cmd_show_fec_capability_keyword,
19313                 NULL,
19314         },
19315 };
19316
19317 /* *** show fec mode per port configuration *** */
19318 struct cmd_show_fec_metadata_result {
19319         cmdline_fixed_string_t cmd_show;
19320         cmdline_fixed_string_t cmd_port;
19321         cmdline_fixed_string_t cmd_keyword;
19322         portid_t cmd_pid;
19323 };
19324
19325 static void
19326 cmd_show_fec_mode_parsed(void *parsed_result,
19327                 __rte_unused struct cmdline *cl,
19328                 __rte_unused void *data)
19329 {
19330 #define FEC_NAME_SIZE 16
19331         struct cmd_show_fec_metadata_result *res = parsed_result;
19332         uint32_t mode;
19333         char buf[FEC_NAME_SIZE];
19334         int ret;
19335
19336         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19337                 printf("Invalid port id %u\n", res->cmd_pid);
19338                 return;
19339         }
19340         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19341         if (ret == -ENOTSUP) {
19342                 printf("Function not implemented\n");
19343                 return;
19344         } else if (ret < 0) {
19345                 printf("Get FEC mode failed\n");
19346                 return;
19347         }
19348
19349         switch (mode) {
19350         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19351                 strlcpy(buf, "off", sizeof(buf));
19352                 break;
19353         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19354                 strlcpy(buf, "auto", sizeof(buf));
19355                 break;
19356         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19357                 strlcpy(buf, "baser", sizeof(buf));
19358                 break;
19359         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19360                 strlcpy(buf, "rs", sizeof(buf));
19361                 break;
19362         default:
19363                 return;
19364         }
19365
19366         printf("%s\n", buf);
19367 }
19368
19369 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19370         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19371                         cmd_show, "show");
19372 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19373         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19374                         cmd_port, "port");
19375 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19376         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19377                         cmd_pid, UINT16);
19378 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19379         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19380                         cmd_keyword, "fec_mode");
19381
19382 cmdline_parse_inst_t cmd_show_fec_mode = {
19383         .f = cmd_show_fec_mode_parsed,
19384         .data = NULL,
19385         .help_str = "show port <port_id> fec_mode",
19386         .tokens = {
19387                 (void *)&cmd_show_fec_mode_show,
19388                 (void *)&cmd_show_fec_mode_port,
19389                 (void *)&cmd_show_fec_mode_pid,
19390                 (void *)&cmd_show_fec_mode_keyword,
19391                 NULL,
19392         },
19393 };
19394
19395 /* *** set fec mode per port configuration *** */
19396 struct cmd_set_port_fec_mode {
19397         cmdline_fixed_string_t set;
19398         cmdline_fixed_string_t port;
19399         portid_t port_id;
19400         cmdline_fixed_string_t fec_mode;
19401         cmdline_fixed_string_t fec_value;
19402 };
19403
19404 /* Common CLI fields for set fec mode */
19405 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19406         TOKEN_STRING_INITIALIZER
19407                 (struct cmd_set_port_fec_mode,
19408                  set, "set");
19409 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19410         TOKEN_STRING_INITIALIZER
19411                 (struct cmd_set_port_fec_mode,
19412                  port, "port");
19413 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19414         TOKEN_NUM_INITIALIZER
19415                 (struct cmd_set_port_fec_mode,
19416                  port_id, UINT16);
19417 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19418         TOKEN_STRING_INITIALIZER
19419                 (struct cmd_set_port_fec_mode,
19420                  fec_mode, "fec_mode");
19421 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19422         TOKEN_STRING_INITIALIZER
19423                 (struct cmd_set_port_fec_mode,
19424                  fec_value, NULL);
19425
19426 static void
19427 cmd_set_port_fec_mode_parsed(
19428         void *parsed_result,
19429         __rte_unused struct cmdline *cl,
19430         __rte_unused void *data)
19431 {
19432         struct cmd_set_port_fec_mode *res = parsed_result;
19433         uint16_t port_id = res->port_id;
19434         uint32_t mode;
19435         int ret;
19436
19437         ret = parse_fec_mode(res->fec_value, &mode);
19438         if (ret < 0) {
19439                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19440                         port_id);
19441                 return;
19442         }
19443
19444         ret = rte_eth_fec_set(port_id, mode);
19445         if (ret == -ENOTSUP) {
19446                 printf("Function not implemented\n");
19447                 return;
19448         } else if (ret < 0) {
19449                 printf("Set FEC mode failed\n");
19450                 return;
19451         }
19452 }
19453
19454 cmdline_parse_inst_t cmd_set_fec_mode = {
19455         .f = cmd_set_port_fec_mode_parsed,
19456         .data = NULL,
19457         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19458         .tokens = {
19459                 (void *)&cmd_set_port_fec_mode_set,
19460                 (void *)&cmd_set_port_fec_mode_port,
19461                 (void *)&cmd_set_port_fec_mode_port_id,
19462                 (void *)&cmd_set_port_fec_mode_str,
19463                 (void *)&cmd_set_port_fec_mode_value,
19464                 NULL,
19465         },
19466 };
19467
19468 /* show port supported ptypes */
19469
19470 /* Common result structure for show port ptypes */
19471 struct cmd_show_port_supported_ptypes_result {
19472         cmdline_fixed_string_t show;
19473         cmdline_fixed_string_t port;
19474         portid_t port_id;
19475         cmdline_fixed_string_t ptypes;
19476 };
19477
19478 /* Common CLI fields for show port ptypes */
19479 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19480         TOKEN_STRING_INITIALIZER
19481                 (struct cmd_show_port_supported_ptypes_result,
19482                  show, "show");
19483 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19484         TOKEN_STRING_INITIALIZER
19485                 (struct cmd_show_port_supported_ptypes_result,
19486                  port, "port");
19487 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19488         TOKEN_NUM_INITIALIZER
19489                 (struct cmd_show_port_supported_ptypes_result,
19490                  port_id, UINT16);
19491 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19492         TOKEN_STRING_INITIALIZER
19493                 (struct cmd_show_port_supported_ptypes_result,
19494                  ptypes, "ptypes");
19495
19496 static void
19497 cmd_show_port_supported_ptypes_parsed(
19498         void *parsed_result,
19499         __rte_unused struct cmdline *cl,
19500         __rte_unused void *data)
19501 {
19502 #define RSVD_PTYPE_MASK       0xf0000000
19503 #define MAX_PTYPES_PER_LAYER  16
19504 #define LTYPE_NAMESIZE        32
19505 #define PTYPE_NAMESIZE        256
19506         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19507         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19508         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19509         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19510         uint16_t port_id = res->port_id;
19511         int ret, i;
19512
19513         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19514         if (ret < 0)
19515                 return;
19516
19517         while (ptype_mask != RSVD_PTYPE_MASK) {
19518
19519                 switch (ptype_mask) {
19520                 case RTE_PTYPE_L2_MASK:
19521                         strlcpy(ltype, "L2", sizeof(ltype));
19522                         break;
19523                 case RTE_PTYPE_L3_MASK:
19524                         strlcpy(ltype, "L3", sizeof(ltype));
19525                         break;
19526                 case RTE_PTYPE_L4_MASK:
19527                         strlcpy(ltype, "L4", sizeof(ltype));
19528                         break;
19529                 case RTE_PTYPE_TUNNEL_MASK:
19530                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19531                         break;
19532                 case RTE_PTYPE_INNER_L2_MASK:
19533                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19534                         break;
19535                 case RTE_PTYPE_INNER_L3_MASK:
19536                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19537                         break;
19538                 case RTE_PTYPE_INNER_L4_MASK:
19539                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19540                         break;
19541                 default:
19542                         return;
19543                 }
19544
19545                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19546                                                        ptype_mask, ptypes,
19547                                                        MAX_PTYPES_PER_LAYER);
19548
19549                 if (ret > 0)
19550                         printf("Supported %s ptypes:\n", ltype);
19551                 else
19552                         printf("%s ptypes unsupported\n", ltype);
19553
19554                 for (i = 0; i < ret; ++i) {
19555                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19556                         printf("%s\n", buf);
19557                 }
19558
19559                 ptype_mask <<= 4;
19560         }
19561 }
19562
19563 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19564         .f = cmd_show_port_supported_ptypes_parsed,
19565         .data = NULL,
19566         .help_str = "show port <port_id> ptypes",
19567         .tokens = {
19568                 (void *)&cmd_show_port_supported_ptypes_show,
19569                 (void *)&cmd_show_port_supported_ptypes_port,
19570                 (void *)&cmd_show_port_supported_ptypes_port_id,
19571                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19572                 NULL,
19573         },
19574 };
19575
19576 /* *** display rx/tx descriptor status *** */
19577 struct cmd_show_rx_tx_desc_status_result {
19578         cmdline_fixed_string_t cmd_show;
19579         cmdline_fixed_string_t cmd_port;
19580         cmdline_fixed_string_t cmd_keyword;
19581         cmdline_fixed_string_t cmd_desc;
19582         cmdline_fixed_string_t cmd_status;
19583         portid_t cmd_pid;
19584         portid_t cmd_qid;
19585         portid_t cmd_did;
19586 };
19587
19588 static void
19589 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19590                 __rte_unused struct cmdline *cl,
19591                 __rte_unused void *data)
19592 {
19593         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19594         int rc;
19595
19596         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19597                 printf("invalid port id %u\n", res->cmd_pid);
19598                 return;
19599         }
19600
19601         if (!strcmp(res->cmd_keyword, "rxq")) {
19602                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19603                                              res->cmd_did);
19604                 if (rc < 0) {
19605                         printf("Invalid queueid = %d\n", res->cmd_qid);
19606                         return;
19607                 }
19608                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19609                         printf("Desc status = AVAILABLE\n");
19610                 else if (rc == RTE_ETH_RX_DESC_DONE)
19611                         printf("Desc status = DONE\n");
19612                 else
19613                         printf("Desc status = UNAVAILABLE\n");
19614         } else if (!strcmp(res->cmd_keyword, "txq")) {
19615                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19616                                              res->cmd_did);
19617                 if (rc < 0) {
19618                         printf("Invalid queueid = %d\n", res->cmd_qid);
19619                         return;
19620                 }
19621                 if (rc == RTE_ETH_TX_DESC_FULL)
19622                         printf("Desc status = FULL\n");
19623                 else if (rc == RTE_ETH_TX_DESC_DONE)
19624                         printf("Desc status = DONE\n");
19625                 else
19626                         printf("Desc status = UNAVAILABLE\n");
19627         }
19628 }
19629
19630 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19631         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19632                         cmd_show, "show");
19633 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19634         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19635                         cmd_port, "port");
19636 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19637         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19638                         cmd_pid, UINT16);
19639 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19640         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19641                         cmd_keyword, "rxq#txq");
19642 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19643         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19644                         cmd_qid, UINT16);
19645 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19646         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19647                         cmd_desc, "desc");
19648 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19649         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19650                         cmd_did, UINT16);
19651 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19652         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19653                         cmd_status, "status");
19654 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19655         .f = cmd_show_rx_tx_desc_status_parsed,
19656         .data = NULL,
19657         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19658                 "status",
19659         .tokens = {
19660                 (void *)&cmd_show_rx_tx_desc_status_show,
19661                 (void *)&cmd_show_rx_tx_desc_status_port,
19662                 (void *)&cmd_show_rx_tx_desc_status_pid,
19663                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19664                 (void *)&cmd_show_rx_tx_desc_status_qid,
19665                 (void *)&cmd_show_rx_tx_desc_status_desc,
19666                 (void *)&cmd_show_rx_tx_desc_status_did,
19667                 (void *)&cmd_show_rx_tx_desc_status_status,
19668                 NULL,
19669         },
19670 };
19671
19672 /* Common result structure for set port ptypes */
19673 struct cmd_set_port_ptypes_result {
19674         cmdline_fixed_string_t set;
19675         cmdline_fixed_string_t port;
19676         portid_t port_id;
19677         cmdline_fixed_string_t ptype_mask;
19678         uint32_t mask;
19679 };
19680
19681 /* Common CLI fields for set port ptypes */
19682 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19683         TOKEN_STRING_INITIALIZER
19684                 (struct cmd_set_port_ptypes_result,
19685                  set, "set");
19686 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19687         TOKEN_STRING_INITIALIZER
19688                 (struct cmd_set_port_ptypes_result,
19689                  port, "port");
19690 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19691         TOKEN_NUM_INITIALIZER
19692                 (struct cmd_set_port_ptypes_result,
19693                  port_id, UINT16);
19694 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19695         TOKEN_STRING_INITIALIZER
19696                 (struct cmd_set_port_ptypes_result,
19697                  ptype_mask, "ptype_mask");
19698 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19699         TOKEN_NUM_INITIALIZER
19700                 (struct cmd_set_port_ptypes_result,
19701                  mask, UINT32);
19702
19703 static void
19704 cmd_set_port_ptypes_parsed(
19705         void *parsed_result,
19706         __rte_unused struct cmdline *cl,
19707         __rte_unused void *data)
19708 {
19709         struct cmd_set_port_ptypes_result *res = parsed_result;
19710 #define PTYPE_NAMESIZE        256
19711         char ptype_name[PTYPE_NAMESIZE];
19712         uint16_t port_id = res->port_id;
19713         uint32_t ptype_mask = res->mask;
19714         int ret, i;
19715
19716         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19717                                                NULL, 0);
19718         if (ret <= 0) {
19719                 printf("Port %d doesn't support any ptypes.\n", port_id);
19720                 return;
19721         }
19722
19723         uint32_t ptypes[ret];
19724
19725         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19726         if (ret < 0) {
19727                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19728                 return;
19729         }
19730
19731         printf("Successfully set following ptypes for Port %d\n", port_id);
19732         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19733                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19734                 printf("%s\n", ptype_name);
19735         }
19736
19737         clear_ptypes = false;
19738 }
19739
19740 cmdline_parse_inst_t cmd_set_port_ptypes = {
19741         .f = cmd_set_port_ptypes_parsed,
19742         .data = NULL,
19743         .help_str = "set port <port_id> ptype_mask <mask>",
19744         .tokens = {
19745                 (void *)&cmd_set_port_ptypes_set,
19746                 (void *)&cmd_set_port_ptypes_port,
19747                 (void *)&cmd_set_port_ptypes_port_id,
19748                 (void *)&cmd_set_port_ptypes_mask_str,
19749                 (void *)&cmd_set_port_ptypes_mask_u32,
19750                 NULL,
19751         },
19752 };
19753
19754 /* *** display mac addresses added to a port *** */
19755 struct cmd_showport_macs_result {
19756         cmdline_fixed_string_t cmd_show;
19757         cmdline_fixed_string_t cmd_port;
19758         cmdline_fixed_string_t cmd_keyword;
19759         portid_t cmd_pid;
19760 };
19761
19762 static void
19763 cmd_showport_macs_parsed(void *parsed_result,
19764                 __rte_unused struct cmdline *cl,
19765                 __rte_unused void *data)
19766 {
19767         struct cmd_showport_macs_result *res = parsed_result;
19768
19769         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19770                 return;
19771
19772         if (!strcmp(res->cmd_keyword, "macs"))
19773                 show_macs(res->cmd_pid);
19774         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19775                 show_mcast_macs(res->cmd_pid);
19776 }
19777
19778 cmdline_parse_token_string_t cmd_showport_macs_show =
19779         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19780                         cmd_show, "show");
19781 cmdline_parse_token_string_t cmd_showport_macs_port =
19782         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19783                         cmd_port, "port");
19784 cmdline_parse_token_num_t cmd_showport_macs_pid =
19785         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19786                         cmd_pid, UINT16);
19787 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19788         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19789                         cmd_keyword, "macs#mcast_macs");
19790
19791 cmdline_parse_inst_t cmd_showport_macs = {
19792         .f = cmd_showport_macs_parsed,
19793         .data = NULL,
19794         .help_str = "show port <port_id> macs|mcast_macs",
19795         .tokens = {
19796                 (void *)&cmd_showport_macs_show,
19797                 (void *)&cmd_showport_macs_port,
19798                 (void *)&cmd_showport_macs_pid,
19799                 (void *)&cmd_showport_macs_keyword,
19800                 NULL,
19801         },
19802 };
19803
19804 /* ******************************************************************************** */
19805
19806 /* list of instructions */
19807 cmdline_parse_ctx_t main_ctx[] = {
19808         (cmdline_parse_inst_t *)&cmd_help_brief,
19809         (cmdline_parse_inst_t *)&cmd_help_long,
19810         (cmdline_parse_inst_t *)&cmd_quit,
19811         (cmdline_parse_inst_t *)&cmd_load_from_file,
19812         (cmdline_parse_inst_t *)&cmd_showport,
19813         (cmdline_parse_inst_t *)&cmd_showqueue,
19814         (cmdline_parse_inst_t *)&cmd_showeeprom,
19815         (cmdline_parse_inst_t *)&cmd_showportall,
19816         (cmdline_parse_inst_t *)&cmd_showdevice,
19817         (cmdline_parse_inst_t *)&cmd_showcfg,
19818         (cmdline_parse_inst_t *)&cmd_showfwdall,
19819         (cmdline_parse_inst_t *)&cmd_start,
19820         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19821         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19822         (cmdline_parse_inst_t *)&cmd_set_link_up,
19823         (cmdline_parse_inst_t *)&cmd_set_link_down,
19824         (cmdline_parse_inst_t *)&cmd_reset,
19825         (cmdline_parse_inst_t *)&cmd_set_numbers,
19826         (cmdline_parse_inst_t *)&cmd_set_log,
19827         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19828         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19829         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19830         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19831         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19832         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19833         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19834         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19835         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19836         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19837         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19838         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19839         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19840         (cmdline_parse_inst_t *)&cmd_set_link_check,
19841         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19842         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19843         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19844         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19845 #ifdef RTE_LIBRTE_PMD_BOND
19846         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19847         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19848         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19849         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19850         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19851         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19852         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19853         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19854         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19855         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19856         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19857 #endif
19858         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19859         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19860         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19861         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19862         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19863         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19864         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19865         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19866         (cmdline_parse_inst_t *)&cmd_csum_set,
19867         (cmdline_parse_inst_t *)&cmd_csum_show,
19868         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19869         (cmdline_parse_inst_t *)&cmd_tso_set,
19870         (cmdline_parse_inst_t *)&cmd_tso_show,
19871         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19872         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19873         (cmdline_parse_inst_t *)&cmd_gro_enable,
19874         (cmdline_parse_inst_t *)&cmd_gro_flush,
19875         (cmdline_parse_inst_t *)&cmd_gro_show,
19876         (cmdline_parse_inst_t *)&cmd_gso_enable,
19877         (cmdline_parse_inst_t *)&cmd_gso_size,
19878         (cmdline_parse_inst_t *)&cmd_gso_show,
19879         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19880         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19881         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19882         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19883         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19884         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19885         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19886         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19887         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19888         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19889         (cmdline_parse_inst_t *)&cmd_config_dcb,
19890         (cmdline_parse_inst_t *)&cmd_read_reg,
19891         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19892         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19893         (cmdline_parse_inst_t *)&cmd_write_reg,
19894         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19895         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19896         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19897         (cmdline_parse_inst_t *)&cmd_stop,
19898         (cmdline_parse_inst_t *)&cmd_mac_addr,
19899         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19900         (cmdline_parse_inst_t *)&cmd_set_qmap,
19901         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19902         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19903         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19904         (cmdline_parse_inst_t *)&cmd_operate_port,
19905         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19906         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19907         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19908         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19909         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19910         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19911         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19912         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19913         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19914         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19915         (cmdline_parse_inst_t *)&cmd_config_mtu,
19916         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19917         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19918         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19919         (cmdline_parse_inst_t *)&cmd_config_rss,
19920         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19921         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19922         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19923         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19924         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19925         (cmdline_parse_inst_t *)&cmd_showport_reta,
19926         (cmdline_parse_inst_t *)&cmd_showport_macs,
19927         (cmdline_parse_inst_t *)&cmd_config_burst,
19928         (cmdline_parse_inst_t *)&cmd_config_thresh,
19929         (cmdline_parse_inst_t *)&cmd_config_threshold,
19930         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19931         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19932         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19933         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19934         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19935         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19936         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19937         (cmdline_parse_inst_t *)&cmd_global_config,
19938         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19939         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19940         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19941         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19942         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19943         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
19944         (cmdline_parse_inst_t *)&cmd_dump,
19945         (cmdline_parse_inst_t *)&cmd_dump_one,
19946         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
19947         (cmdline_parse_inst_t *)&cmd_syn_filter,
19948         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
19949         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
19950         (cmdline_parse_inst_t *)&cmd_flex_filter,
19951         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
19952         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
19953         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
19954         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
19955         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
19956         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
19957         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
19958         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
19959         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
19960         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
19961         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
19962         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
19963         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
19964         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
19965         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
19966         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
19967         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
19968         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
19969         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
19970         (cmdline_parse_inst_t *)&cmd_flow,
19971         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
19972         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
19973         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
19974         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
19975         (cmdline_parse_inst_t *)&cmd_create_port_meter,
19976         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
19977         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
19978         (cmdline_parse_inst_t *)&cmd_del_port_meter,
19979         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
19980         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
19981         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
19982         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
19983         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
19984         (cmdline_parse_inst_t *)&cmd_mcast_addr,
19985         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
19986         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
19987         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
19988         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
19989         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
19990         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
19991         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
19992         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
19993         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
19994         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
19995         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
19996         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
19997         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
19998         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
19999         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
20000         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
20001         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
20002         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
20003         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
20004         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
20005         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
20006         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
20007         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
20008         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
20009         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
20010         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
20011         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
20012         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
20013         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
20014         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
20015         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
20016         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
20017         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
20018         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
20019         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
20020         (cmdline_parse_inst_t *)&cmd_set_vxlan,
20021         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
20022         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
20023         (cmdline_parse_inst_t *)&cmd_set_nvgre,
20024         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
20025         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
20026         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
20027         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
20028         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
20029         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
20030         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
20031         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
20032         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
20033         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
20034         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
20035         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
20036         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
20037         (cmdline_parse_inst_t *)&cmd_ddp_add,
20038         (cmdline_parse_inst_t *)&cmd_ddp_del,
20039         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
20040         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
20041         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
20042         (cmdline_parse_inst_t *)&cmd_clear_input_set,
20043         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
20044         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
20045         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
20046         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
20047         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
20048         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
20049         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
20050         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
20051
20052         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
20053         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
20054         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
20055         (cmdline_parse_inst_t *)&cmd_queue_region,
20056         (cmdline_parse_inst_t *)&cmd_region_flowtype,
20057         (cmdline_parse_inst_t *)&cmd_user_priority_region,
20058         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
20059         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
20060         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
20061         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
20062         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
20063         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
20064         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
20065         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
20066         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
20067         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
20068         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
20069         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
20070         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
20071         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
20072         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
20073         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
20074         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
20075         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
20076         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
20077         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
20078         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
20079         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
20080         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
20081         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
20082         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
20083         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
20084         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
20085         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
20086         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
20087         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
20088         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
20089         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
20090         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
20091         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
20092 #ifdef RTE_LIBRTE_BPF
20093         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
20094         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
20095 #endif
20096         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
20097         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
20098         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
20099         (cmdline_parse_inst_t *)&cmd_set_raw,
20100         (cmdline_parse_inst_t *)&cmd_show_set_raw,
20101         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
20102         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
20103         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
20104         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
20105         (cmdline_parse_inst_t *)&cmd_show_capability,
20106         NULL,
20107 };
20108
20109 /* read cmdline commands from file */
20110 void
20111 cmdline_read_from_file(const char *filename)
20112 {
20113         struct cmdline *cl;
20114
20115         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20116         if (cl == NULL) {
20117                 printf("Failed to create file based cmdline context: %s\n",
20118                        filename);
20119                 return;
20120         }
20121
20122         cmdline_interact(cl);
20123         cmdline_quit(cl);
20124
20125         cmdline_free(cl);
20126
20127         printf("Read CLI commands from %s\n", filename);
20128 }
20129
20130 /* prompt function, called from main on MASTER lcore */
20131 void
20132 prompt(void)
20133 {
20134         /* initialize non-constant commands */
20135         cmd_set_fwd_mode_init();
20136         cmd_set_fwd_retry_mode_init();
20137
20138         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20139         if (testpmd_cl == NULL)
20140                 return;
20141         cmdline_interact(testpmd_cl);
20142         cmdline_stdin_exit(testpmd_cl);
20143 }
20144
20145 void
20146 prompt_exit(void)
20147 {
20148         if (testpmd_cl != NULL)
20149                 cmdline_quit(testpmd_cl);
20150 }
20151
20152 static void
20153 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20154 {
20155         if (id == (portid_t)RTE_PORT_ALL) {
20156                 portid_t pid;
20157
20158                 RTE_ETH_FOREACH_DEV(pid) {
20159                         /* check if need_reconfig has been set to 1 */
20160                         if (ports[pid].need_reconfig == 0)
20161                                 ports[pid].need_reconfig = dev;
20162                         /* check if need_reconfig_queues has been set to 1 */
20163                         if (ports[pid].need_reconfig_queues == 0)
20164                                 ports[pid].need_reconfig_queues = queue;
20165                 }
20166         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20167                 /* check if need_reconfig has been set to 1 */
20168                 if (ports[id].need_reconfig == 0)
20169                         ports[id].need_reconfig = dev;
20170                 /* check if need_reconfig_queues has been set to 1 */
20171                 if (ports[id].need_reconfig_queues == 0)
20172                         ports[id].need_reconfig_queues = queue;
20173         }
20174 }