cb9ffd8dc137ba4cd750216e43b9735ea2565a24
[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_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
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|rxoffs|rxpkts|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 rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
412                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
413                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
414                         "   add a tunnel filter of a port.\n\n"
415
416                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
417                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
418                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
419                         "   remove a tunnel filter of a port.\n\n"
420
421                         "rx_vxlan_port add (udp_port) (port_id)\n"
422                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
423
424                         "rx_vxlan_port rm (udp_port) (port_id)\n"
425                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
426
427                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
428                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
429                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
430
431                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
432                         "    Set port based TX VLAN insertion.\n\n"
433
434                         "tx_vlan reset (port_id)\n"
435                         "    Disable hardware insertion of a VLAN header in"
436                         " packets sent on a port.\n\n"
437
438                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
439                         "    Select hardware or software calculation of the"
440                         " checksum when transmitting a packet using the"
441                         " csum forward engine.\n"
442                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
443                         "    outer-ip concerns the outer IP layer in"
444                         "    outer-udp concerns the outer UDP layer in"
445                         " case the packet is recognized as a tunnel packet by"
446                         " the forward engine (vxlan, gre and ipip are supported)\n"
447                         "    Please check the NIC datasheet for HW limits.\n\n"
448
449                         "csum parse-tunnel (on|off) (tx_port_id)\n"
450                         "    If disabled, treat tunnel packets as non-tunneled"
451                         " packets (treat inner headers as payload). The port\n"
452                         "    argument is the port used for TX in csum forward"
453                         " engine.\n\n"
454
455                         "csum show (port_id)\n"
456                         "    Display tx checksum offload configuration\n\n"
457
458                         "tso set (segsize) (portid)\n"
459                         "    Enable TCP Segmentation Offload in csum forward"
460                         " engine.\n"
461                         "    Please check the NIC datasheet for HW limits.\n\n"
462
463                         "tso show (portid)"
464                         "    Display the status of TCP Segmentation Offload.\n\n"
465
466                         "set port (port_id) gro on|off\n"
467                         "    Enable or disable Generic Receive Offload in"
468                         " csum forwarding engine.\n\n"
469
470                         "show port (port_id) gro\n"
471                         "    Display GRO configuration.\n\n"
472
473                         "set gro flush (cycles)\n"
474                         "    Set the cycle to flush GROed packets from"
475                         " reassembly tables.\n\n"
476
477                         "set port (port_id) gso (on|off)"
478                         "    Enable or disable Generic Segmentation Offload in"
479                         " csum forwarding engine.\n\n"
480
481                         "set gso segsz (length)\n"
482                         "    Set max packet length for output GSO segments,"
483                         " including packet header and payload.\n\n"
484
485                         "show port (port_id) gso\n"
486                         "    Show GSO configuration.\n\n"
487
488                         "set fwd (%s)\n"
489                         "    Set packet forwarding mode.\n\n"
490
491                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Add a MAC address on port_id.\n\n"
493
494                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
495                         "    Remove a MAC address from port_id.\n\n"
496
497                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the default MAC address for port_id.\n\n"
499
500                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
501                         "    Add a MAC address for a VF on the port.\n\n"
502
503                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
504                         "    Set the MAC address for a VF from the PF.\n\n"
505
506                         "set eth-peer (port_id) (peer_addr)\n"
507                         "    set the peer address for certain port.\n\n"
508
509                         "set port (port_id) uta (mac_address|all) (on|off)\n"
510                         "    Add/Remove a or all unicast hash filter(s)"
511                         "from port X.\n\n"
512
513                         "set promisc (port_id|all) (on|off)\n"
514                         "    Set the promiscuous mode on port_id, or all.\n\n"
515
516                         "set allmulti (port_id|all) (on|off)\n"
517                         "    Set the allmulti mode on port_id, or all.\n\n"
518
519                         "set vf promisc (port_id) (vf_id) (on|off)\n"
520                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
521
522                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
523                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
524
525                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
526                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
527                         " (on|off) autoneg (on|off) (port_id)\n"
528                         "set flow_ctrl rx (on|off) (portid)\n"
529                         "set flow_ctrl tx (on|off) (portid)\n"
530                         "set flow_ctrl high_water (high_water) (portid)\n"
531                         "set flow_ctrl low_water (low_water) (portid)\n"
532                         "set flow_ctrl pause_time (pause_time) (portid)\n"
533                         "set flow_ctrl send_xon (send_xon) (portid)\n"
534                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
535                         "set flow_ctrl autoneg (on|off) (port_id)\n"
536                         "    Set the link flow control parameter on a port.\n\n"
537
538                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
539                         " (low_water) (pause_time) (priority) (port_id)\n"
540                         "    Set the priority flow control parameter on a"
541                         " port.\n\n"
542
543                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
544                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
545                         " queue on port.\n"
546                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
547                         " on port 0 to mapping 5.\n\n"
548
549                         "set xstats-hide-zero on|off\n"
550                         "    Set the option to hide the zero values"
551                         " for xstats display.\n"
552
553                         "set record-core-cycles on|off\n"
554                         "    Set the option to enable measurement of CPU cycles.\n"
555
556                         "set record-burst-stats on|off\n"
557                         "    Set the option to enable display of RX and TX bursts.\n"
558
559                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
560                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
561
562                         "set port (port_id) vf (vf_id) (mac_addr)"
563                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
564                         "   Add/Remove unicast or multicast MAC addr filter"
565                         " for a VF.\n\n"
566
567                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
568                         "|MPE) (on|off)\n"
569                         "    AUPE:accepts untagged VLAN;"
570                         "ROPE:accept unicast hash\n\n"
571                         "    BAM:accepts broadcast packets;"
572                         "MPE:accepts all multicast packets\n\n"
573                         "    Enable/Disable a VF receive mode of a port\n\n"
574
575                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
576                         "    Set rate limit for a queue of a port\n\n"
577
578                         "set port (port_id) vf (vf_id) rate (rate_num) "
579                         "queue_mask (queue_mask_value)\n"
580                         "    Set rate limit for queues in VF of a port\n\n"
581
582                         "set port (port_id) mirror-rule (rule_id)"
583                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
584                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
585                         "   Set pool or vlan type mirror rule on a port.\n"
586                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
587                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
588                         " to pool 0.\n\n"
589
590                         "set port (port_id) mirror-rule (rule_id)"
591                         " (uplink-mirror|downlink-mirror) dst-pool"
592                         " (pool_id) (on|off)\n"
593                         "   Set uplink or downlink type mirror rule on a port.\n"
594                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
595                         " 0 on' enable mirror income traffic to pool 0.\n\n"
596
597                         "reset port (port_id) mirror-rule (rule_id)\n"
598                         "   Reset a mirror rule.\n\n"
599
600                         "set flush_rx (on|off)\n"
601                         "   Flush (default) or don't flush RX streams before"
602                         " forwarding. Mainly used with PCAP drivers.\n\n"
603
604                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
605                         "   Set the bypass mode for the lowest port on bypass enabled"
606                         " NIC.\n\n"
607
608                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
609                         "mode (normal|bypass|isolate) (port_id)\n"
610                         "   Set the event required to initiate specified bypass mode for"
611                         " the lowest port on a bypass enabled NIC where:\n"
612                         "       timeout   = enable bypass after watchdog timeout.\n"
613                         "       os_on     = enable bypass when OS/board is powered on.\n"
614                         "       os_off    = enable bypass when OS/board is powered off.\n"
615                         "       power_on  = enable bypass when power supply is turned on.\n"
616                         "       power_off = enable bypass when power supply is turned off."
617                         "\n\n"
618
619                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
620                         "   Set the bypass watchdog timeout to 'n' seconds"
621                         " where 0 = instant.\n\n"
622
623                         "show bypass config (port_id)\n"
624                         "   Show the bypass configuration for a bypass enabled NIC"
625                         " using the lowest port on the NIC.\n\n"
626
627 #ifdef RTE_NET_BOND
628                         "create bonded device (mode) (socket)\n"
629                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
630
631                         "add bonding slave (slave_id) (port_id)\n"
632                         "       Add a slave device to a bonded device.\n\n"
633
634                         "remove bonding slave (slave_id) (port_id)\n"
635                         "       Remove a slave device from a bonded device.\n\n"
636
637                         "set bonding mode (value) (port_id)\n"
638                         "       Set the bonding mode on a bonded device.\n\n"
639
640                         "set bonding primary (slave_id) (port_id)\n"
641                         "       Set the primary slave for a bonded device.\n\n"
642
643                         "show bonding config (port_id)\n"
644                         "       Show the bonding config for port_id.\n\n"
645
646                         "set bonding mac_addr (port_id) (address)\n"
647                         "       Set the MAC address of a bonded device.\n\n"
648
649                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
650                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
651
652                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
653                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
654
655                         "set bonding mon_period (port_id) (value)\n"
656                         "       Set the bonding link status monitoring polling period in ms.\n\n"
657
658                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
659                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
660
661 #endif
662                         "set link-up port (port_id)\n"
663                         "       Set link up for a port.\n\n"
664
665                         "set link-down port (port_id)\n"
666                         "       Set link down for a port.\n\n"
667
668                         "E-tag set insertion on port-tag-id (value)"
669                         " port (port_id) vf (vf_id)\n"
670                         "    Enable E-tag insertion for a VF on a port\n\n"
671
672                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
673                         "    Disable E-tag insertion for a VF on a port\n\n"
674
675                         "E-tag set stripping (on|off) port (port_id)\n"
676                         "    Enable/disable E-tag stripping on a port\n\n"
677
678                         "E-tag set forwarding (on|off) port (port_id)\n"
679                         "    Enable/disable E-tag based forwarding"
680                         " on a port\n\n"
681
682                         "E-tag set filter add e-tag-id (value) dst-pool"
683                         " (pool_id) port (port_id)\n"
684                         "    Add an E-tag forwarding filter on a port\n\n"
685
686                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
687                         "    Delete an E-tag forwarding filter on a port\n\n"
688
689                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
690                         "    Load a profile package on a port\n\n"
691
692                         "ddp del (port_id) (backup_profile_path)\n"
693                         "    Delete a profile package from a port\n\n"
694
695                         "ptype mapping get (port_id) (valid_only)\n"
696                         "    Get ptype mapping on a port\n\n"
697
698                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
699                         "    Replace target with the pkt_type in ptype mapping\n\n"
700
701                         "ptype mapping reset (port_id)\n"
702                         "    Reset ptype mapping on a port\n\n"
703
704                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
705                         "    Update a ptype mapping item on a port\n\n"
706
707                         "set port (port_id) ptype_mask (ptype_mask)\n"
708                         "    set packet types classification for a specific port\n\n"
709
710                         "set port (port_id) queue-region region_id (value) "
711                         "queue_start_index (value) queue_num (value)\n"
712                         "    Set a queue region on a port\n\n"
713
714                         "set port (port_id) queue-region region_id (value) "
715                         "flowtype (value)\n"
716                         "    Set a flowtype region index on a port\n\n"
717
718                         "set port (port_id) queue-region UP (value) region_id (value)\n"
719                         "    Set the mapping of User Priority to "
720                         "queue region on a port\n\n"
721
722                         "set port (port_id) queue-region flush (on|off)\n"
723                         "    flush all queue region related configuration\n\n"
724
725                         "show port meter cap (port_id)\n"
726                         "    Show port meter capability information\n\n"
727
728                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
729                         "    meter profile add - srtcm rfc 2697\n\n"
730
731                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
732                         "    meter profile add - trtcm rfc 2698\n\n"
733
734                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
735                         "    meter profile add - trtcm rfc 4115\n\n"
736
737                         "del port meter profile (port_id) (profile_id)\n"
738                         "    meter profile delete\n\n"
739
740                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
741                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
742                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
743                         "(dscp_tbl_entry63)]\n"
744                         "    meter create\n\n"
745
746                         "enable port meter (port_id) (mtr_id)\n"
747                         "    meter enable\n\n"
748
749                         "disable port meter (port_id) (mtr_id)\n"
750                         "    meter disable\n\n"
751
752                         "del port meter (port_id) (mtr_id)\n"
753                         "    meter delete\n\n"
754
755                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
756                         "    meter update meter profile\n\n"
757
758                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
759                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
760                         "    update meter dscp table entries\n\n"
761
762                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
763                         "(action0) [(action1) (action2)]\n"
764                         "    meter update policer action\n\n"
765
766                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
767                         "    meter update stats\n\n"
768
769                         "show port (port_id) queue-region\n"
770                         "    show all queue region related configuration info\n\n"
771
772                         "set port (port_id) fec_mode auto|off|rs|baser\n"
773                         "    set fec mode for a specific port\n\n"
774
775                         , list_pkt_forwarding_modes()
776                 );
777         }
778
779         if (show_all || !strcmp(res->section, "ports")) {
780
781                 cmdline_printf(
782                         cl,
783                         "\n"
784                         "Port Operations:\n"
785                         "----------------\n\n"
786
787                         "port start (port_id|all)\n"
788                         "    Start all ports or port_id.\n\n"
789
790                         "port stop (port_id|all)\n"
791                         "    Stop all ports or port_id.\n\n"
792
793                         "port close (port_id|all)\n"
794                         "    Close all ports or port_id.\n\n"
795
796                         "port reset (port_id|all)\n"
797                         "    Reset all ports or port_id.\n\n"
798
799                         "port attach (ident)\n"
800                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
801
802                         "port detach (port_id)\n"
803                         "    Detach physical or virtual dev by port_id\n\n"
804
805                         "port config (port_id|all)"
806                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
807                         " duplex (half|full|auto)\n"
808                         "    Set speed and duplex for all ports or port_id\n\n"
809
810                         "port config (port_id|all) loopback (mode)\n"
811                         "    Set loopback mode for all ports or port_id\n\n"
812
813                         "port config all (rxq|txq|rxd|txd) (value)\n"
814                         "    Set number for rxq/txq/rxd/txd.\n\n"
815
816                         "port config all max-pkt-len (value)\n"
817                         "    Set the max packet length.\n\n"
818
819                         "port config all max-lro-pkt-size (value)\n"
820                         "    Set the max LRO aggregated packet size.\n\n"
821
822                         "port config all drop-en (on|off)\n"
823                         "    Enable or disable packet drop on all RX queues of all ports when no "
824                         "receive buffers available.\n\n"
825
826                         "port config all rss (all|default|ip|tcp|udp|sctp|"
827                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
828                         "level-outer|level-inner|<flowtype_id>)\n"
829                         "    Set the RSS mode.\n\n"
830
831                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
832                         "    Set the RSS redirection table.\n\n"
833
834                         "port config (port_id) dcb vt (on|off) (traffic_class)"
835                         " pfc (on|off)\n"
836                         "    Set the DCB mode.\n\n"
837
838                         "port config all burst (value)\n"
839                         "    Set the number of packets per burst.\n\n"
840
841                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
842                         " (value)\n"
843                         "    Set the ring prefetch/host/writeback threshold"
844                         " for tx/rx queue.\n\n"
845
846                         "port config all (txfreet|txrst|rxfreet) (value)\n"
847                         "    Set free threshold for rx/tx, or set"
848                         " tx rs bit threshold.\n\n"
849                         "port config mtu X value\n"
850                         "    Set the MTU of port X to a given value\n\n"
851
852                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
853                         "    Set a rx/tx queue's ring size configuration, the new"
854                         " value will take effect after command that (re-)start the port"
855                         " or command that setup the specific queue\n\n"
856
857                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
858                         "    Start/stop a rx/tx queue of port X. Only take effect"
859                         " when port X is started\n\n"
860
861                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
862                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
863                         " take effect when port X is stopped.\n\n"
864
865                         "port (port_id) (rxq|txq) (queue_id) setup\n"
866                         "    Setup a rx/tx queue of port X.\n\n"
867
868                         "port config (port_id|all) l2-tunnel E-tag ether-type"
869                         " (value)\n"
870                         "    Set the value of E-tag ether-type.\n\n"
871
872                         "port config (port_id|all) l2-tunnel E-tag"
873                         " (enable|disable)\n"
874                         "    Enable/disable the E-tag support.\n\n"
875
876                         "port config (port_id) pctype mapping reset\n"
877                         "    Reset flow type to pctype mapping on a port\n\n"
878
879                         "port config (port_id) pctype mapping update"
880                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
881                         "    Update a flow type to pctype mapping item on a port\n\n"
882
883                         "port config (port_id) pctype (pctype_id) hash_inset|"
884                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
885                         " (field_idx)\n"
886                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
887
888                         "port config (port_id) pctype (pctype_id) hash_inset|"
889                         "fdir_inset|fdir_flx_inset clear all"
890                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
891
892                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
893                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
894
895                         "port config <port_id> rx_offload vlan_strip|"
896                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
897                         "outer_ipv4_cksum|macsec_strip|header_split|"
898                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
899                         "buffer_split|timestamp|security|keep_crc on|off\n"
900                         "     Enable or disable a per port Rx offloading"
901                         " on all Rx queues of a port\n\n"
902
903                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
904                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
905                         "outer_ipv4_cksum|macsec_strip|header_split|"
906                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
907                         "buffer_split|timestamp|security|keep_crc on|off\n"
908                         "    Enable or disable a per queue Rx offloading"
909                         " only on a specific Rx queue\n\n"
910
911                         "port config (port_id) tx_offload vlan_insert|"
912                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
913                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
914                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
915                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
916                         "security on|off\n"
917                         "    Enable or disable a per port Tx offloading"
918                         " on all Tx queues of a port\n\n"
919
920                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
921                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
922                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
923                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
924                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
925                         " on|off\n"
926                         "    Enable or disable a per queue Tx offloading"
927                         " only on a specific Tx queue\n\n"
928
929                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
930                         "    Load an eBPF program as a callback"
931                         " for particular RX/TX queue\n\n"
932
933                         "bpf-unload rx|tx (port) (queue)\n"
934                         "    Unload previously loaded eBPF program"
935                         " for particular RX/TX queue\n\n"
936
937                         "port config (port_id) tx_metadata (value)\n"
938                         "    Set Tx metadata value per port. Testpmd will add this value"
939                         " to any Tx packet sent from this port\n\n"
940
941                         "port config (port_id) dynf (name) set|clear\n"
942                         "    Register a dynf and Set/clear this flag on Tx. "
943                         "Testpmd will set this value to any Tx packet "
944                         "sent from this port\n\n"
945                 );
946         }
947
948         if (show_all || !strcmp(res->section, "registers")) {
949
950                 cmdline_printf(
951                         cl,
952                         "\n"
953                         "Registers:\n"
954                         "----------\n\n"
955
956                         "read reg (port_id) (address)\n"
957                         "    Display value of a port register.\n\n"
958
959                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
960                         "    Display a port register bit field.\n\n"
961
962                         "read regbit (port_id) (address) (bit_x)\n"
963                         "    Display a single port register bit.\n\n"
964
965                         "write reg (port_id) (address) (value)\n"
966                         "    Set value of a port register.\n\n"
967
968                         "write regfield (port_id) (address) (bit_x) (bit_y)"
969                         " (value)\n"
970                         "    Set bit field of a port register.\n\n"
971
972                         "write regbit (port_id) (address) (bit_x) (value)\n"
973                         "    Set single bit value of a port register.\n\n"
974                 );
975         }
976         if (show_all || !strcmp(res->section, "filters")) {
977
978                 cmdline_printf(
979                         cl,
980                         "\n"
981                         "filters:\n"
982                         "--------\n\n"
983
984                         "ethertype_filter (port_id) (add|del)"
985                         " (mac_addr|mac_ignr) (mac_address) ethertype"
986                         " (ether_type) (drop|fwd) queue (queue_id)\n"
987                         "    Add/Del an ethertype filter.\n\n"
988
989                         "2tuple_filter (port_id) (add|del)"
990                         " dst_port (dst_port_value) protocol (protocol_value)"
991                         " mask (mask_value) tcp_flags (tcp_flags_value)"
992                         " priority (prio_value) queue (queue_id)\n"
993                         "    Add/Del a 2tuple filter.\n\n"
994
995                         "5tuple_filter (port_id) (add|del)"
996                         " dst_ip (dst_address) src_ip (src_address)"
997                         " dst_port (dst_port_value) src_port (src_port_value)"
998                         " protocol (protocol_value)"
999                         " mask (mask_value) tcp_flags (tcp_flags_value)"
1000                         " priority (prio_value) queue (queue_id)\n"
1001                         "    Add/Del a 5tuple filter.\n\n"
1002
1003                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
1004                         "    Add/Del syn filter.\n\n"
1005
1006                         "flex_filter (port_id) (add|del) len (len_value)"
1007                         " bytes (bytes_value) mask (mask_value)"
1008                         " priority (prio_value) queue (queue_id)\n"
1009                         "    Add/Del a flex filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode IP (add|del|update)"
1012                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1013                         " src (src_ip_address) dst (dst_ip_address)"
1014                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1015                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1016                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1017                         " fd_id (fd_id_value)\n"
1018                         "    Add/Del an IP type flow director filter.\n\n"
1019
1020                         "flow_director_filter (port_id) mode IP (add|del|update)"
1021                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1022                         " src (src_ip_address) (src_port)"
1023                         " dst (dst_ip_address) (dst_port)"
1024                         " tos (tos_value) ttl (ttl_value)"
1025                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1026                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1027                         " fd_id (fd_id_value)\n"
1028                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1029
1030                         "flow_director_filter (port_id) mode IP (add|del|update)"
1031                         " flow (ipv4-sctp|ipv6-sctp)"
1032                         " src (src_ip_address) (src_port)"
1033                         " dst (dst_ip_address) (dst_port)"
1034                         " tag (verification_tag) "
1035                         " tos (tos_value) ttl (ttl_value)"
1036                         " vlan (vlan_value)"
1037                         " flexbytes (flexbytes_value) (drop|fwd)"
1038                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1039                         "    Add/Del a SCTP type flow director filter.\n\n"
1040
1041                         "flow_director_filter (port_id) mode IP (add|del|update)"
1042                         " flow l2_payload ether (ethertype)"
1043                         " flexbytes (flexbytes_value) (drop|fwd)"
1044                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1045                         "    Add/Del a l2 payload type flow director filter.\n\n"
1046
1047                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1048                         " mac (mac_address) vlan (vlan_value)"
1049                         " flexbytes (flexbytes_value) (drop|fwd)"
1050                         " queue (queue_id) fd_id (fd_id_value)\n"
1051                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1052
1053                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1054                         " mac (mac_address) vlan (vlan_value)"
1055                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1056                         " flexbytes (flexbytes_value) (drop|fwd)"
1057                         " queue (queue_id) fd_id (fd_id_value)\n"
1058                         "    Add/Del a Tunnel flow director filter.\n\n"
1059
1060                         "flow_director_filter (port_id) mode raw (add|del|update)"
1061                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1062                         " fd_id (fd_id_value) packet (packet file name)\n"
1063                         "    Add/Del a raw type flow director filter.\n\n"
1064
1065                         "flush_flow_director (port_id)\n"
1066                         "    Flush all flow director entries of a device.\n\n"
1067
1068                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1069                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1070                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1071                         "    Set flow director IP mask.\n\n"
1072
1073                         "flow_director_mask (port_id) mode MAC-VLAN"
1074                         " vlan (vlan_value)\n"
1075                         "    Set flow director MAC-VLAN mask.\n\n"
1076
1077                         "flow_director_mask (port_id) mode Tunnel"
1078                         " vlan (vlan_value) mac (mac_value)"
1079                         " tunnel-type (tunnel_type_value)"
1080                         " tunnel-id (tunnel_id_value)\n"
1081                         "    Set flow director Tunnel mask.\n\n"
1082
1083                         "flow_director_flex_mask (port_id)"
1084                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1085                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1086                         " (mask)\n"
1087                         "    Configure mask of flex payload.\n\n"
1088
1089                         "flow_director_flex_payload (port_id)"
1090                         " (raw|l2|l3|l4) (config)\n"
1091                         "    Configure flex payload selection.\n\n"
1092
1093                         "get_sym_hash_ena_per_port (port_id)\n"
1094                         "    get symmetric hash enable configuration per port.\n\n"
1095
1096                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1097                         "    set symmetric hash enable configuration per port"
1098                         " to enable or disable.\n\n"
1099
1100                         "get_hash_global_config (port_id)\n"
1101                         "    Get the global configurations of hash filters.\n\n"
1102
1103                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1104                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1105                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1106                         " (enable|disable)\n"
1107                         "    Set the global configurations of hash filters.\n\n"
1108
1109                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1110                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1111                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1112                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1113                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1114                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1115                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1116                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1117                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1118                         "fld-8th|none) (select|add)\n"
1119                         "    Set the input set for hash.\n\n"
1120
1121                         "set_fdir_input_set (port_id) "
1122                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1123                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1124                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1125                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1126                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1127                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1128                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1129                         " (select|add)\n"
1130                         "    Set the input set for FDir.\n\n"
1131
1132                         "flow validate {port_id}"
1133                         " [group {group_id}] [priority {level}]"
1134                         " [ingress] [egress]"
1135                         " pattern {item} [/ {item} [...]] / end"
1136                         " actions {action} [/ {action} [...]] / end\n"
1137                         "    Check whether a flow rule can be created.\n\n"
1138
1139                         "flow create {port_id}"
1140                         " [group {group_id}] [priority {level}]"
1141                         " [ingress] [egress]"
1142                         " pattern {item} [/ {item} [...]] / end"
1143                         " actions {action} [/ {action} [...]] / end\n"
1144                         "    Create a flow rule.\n\n"
1145
1146                         "flow destroy {port_id} rule {rule_id} [...]\n"
1147                         "    Destroy specific flow rules.\n\n"
1148
1149                         "flow flush {port_id}\n"
1150                         "    Destroy all flow rules.\n\n"
1151
1152                         "flow query {port_id} {rule_id} {action}\n"
1153                         "    Query an existing flow rule.\n\n"
1154
1155                         "flow list {port_id} [group {group_id}] [...]\n"
1156                         "    List existing flow rules sorted by priority,"
1157                         " filtered by group identifiers.\n\n"
1158
1159                         "flow isolate {port_id} {boolean}\n"
1160                         "    Restrict ingress traffic to the defined"
1161                         " flow rules\n\n"
1162
1163                         "flow aged {port_id} [destroy]\n"
1164                         "    List and destroy aged flows"
1165                         " flow rules\n\n"
1166
1167                         "flow shared_action {port_id} create"
1168                         " [action_id {shared_action_id}]"
1169                         " [ingress] [egress]"
1170                         " action {action} / end\n"
1171                         "    Create shared action.\n\n"
1172
1173                         "flow shared_action {port_id} update"
1174                         " {shared_action_id} action {action} / end\n"
1175                         "    Update shared action.\n\n"
1176
1177                         "flow shared_action {port_id} destroy"
1178                         " action_id {shared_action_id} [...]\n"
1179                         "    Destroy specific shared actions.\n\n"
1180
1181                         "flow shared_action {port_id} query"
1182                         " {shared_action_id}\n"
1183                         "    Query an existing shared action.\n\n"
1184
1185                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1186                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1187                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1188                         "       Configure the VXLAN encapsulation for flows.\n\n"
1189
1190                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1191                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1192                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1193                         " eth-dst (eth-dst)\n"
1194                         "       Configure the VXLAN encapsulation for flows.\n\n"
1195
1196                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1197                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1198                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1199                         " eth-dst (eth-dst)\n"
1200                         "       Configure the VXLAN encapsulation for flows.\n\n"
1201
1202                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1203                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1204                         " (eth-dst)\n"
1205                         "       Configure the NVGRE encapsulation for flows.\n\n"
1206
1207                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1208                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1209                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1210                         "       Configure the NVGRE encapsulation for flows.\n\n"
1211
1212                         "set raw_encap {flow items}\n"
1213                         "       Configure the encapsulation with raw data.\n\n"
1214
1215                         "set raw_decap {flow items}\n"
1216                         "       Configure the decapsulation with raw data.\n\n"
1217
1218                 );
1219         }
1220
1221         if (show_all || !strcmp(res->section, "traffic_management")) {
1222                 cmdline_printf(
1223                         cl,
1224                         "\n"
1225                         "Traffic Management:\n"
1226                         "--------------\n"
1227                         "show port tm cap (port_id)\n"
1228                         "       Display the port TM capability.\n\n"
1229
1230                         "show port tm level cap (port_id) (level_id)\n"
1231                         "       Display the port TM hierarchical level capability.\n\n"
1232
1233                         "show port tm node cap (port_id) (node_id)\n"
1234                         "       Display the port TM node capability.\n\n"
1235
1236                         "show port tm node type (port_id) (node_id)\n"
1237                         "       Display the port TM node type.\n\n"
1238
1239                         "show port tm node stats (port_id) (node_id) (clear)\n"
1240                         "       Display the port TM node stats.\n\n"
1241
1242                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1243                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1244                         " (packet_length_adjust) (packet_mode)\n"
1245                         "       Add port tm node private shaper profile.\n\n"
1246
1247                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1248                         "       Delete port tm node private shaper profile.\n\n"
1249
1250                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1251                         " (shaper_profile_id)\n"
1252                         "       Add/update port tm node shared shaper.\n\n"
1253
1254                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1255                         "       Delete port tm node shared shaper.\n\n"
1256
1257                         "set port tm node shaper profile (port_id) (node_id)"
1258                         " (shaper_profile_id)\n"
1259                         "       Set port tm node shaper profile.\n\n"
1260
1261                         "add port tm node wred profile (port_id) (wred_profile_id)"
1262                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1263                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1264                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1265                         "       Add port tm node wred profile.\n\n"
1266
1267                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1268                         "       Delete port tm node wred profile.\n\n"
1269
1270                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1271                         " (priority) (weight) (level_id) (shaper_profile_id)"
1272                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1273                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1274                         "       Add port tm nonleaf node.\n\n"
1275
1276                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1277                         " (priority) (weight) (level_id) (shaper_profile_id)"
1278                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1279                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1280                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1281
1282                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1283                         " (priority) (weight) (level_id) (shaper_profile_id)"
1284                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1285                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1286                         "       Add port tm leaf node.\n\n"
1287
1288                         "del port tm node (port_id) (node_id)\n"
1289                         "       Delete port tm node.\n\n"
1290
1291                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1292                         " (priority) (weight)\n"
1293                         "       Set port tm node parent.\n\n"
1294
1295                         "suspend port tm node (port_id) (node_id)"
1296                         "       Suspend tm node.\n\n"
1297
1298                         "resume port tm node (port_id) (node_id)"
1299                         "       Resume tm node.\n\n"
1300
1301                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1302                         "       Commit tm hierarchy.\n\n"
1303
1304                         "set port tm mark ip_ecn (port) (green) (yellow)"
1305                         " (red)\n"
1306                         "    Enables/Disables the traffic management marking"
1307                         " for IP ECN (Explicit Congestion Notification)"
1308                         " packets on a given port\n\n"
1309
1310                         "set port tm mark ip_dscp (port) (green) (yellow)"
1311                         " (red)\n"
1312                         "    Enables/Disables the traffic management marking"
1313                         " on the port for IP dscp packets\n\n"
1314
1315                         "set port tm mark vlan_dei (port) (green) (yellow)"
1316                         " (red)\n"
1317                         "    Enables/Disables the traffic management marking"
1318                         " on the port for VLAN packets with DEI enabled\n\n"
1319                 );
1320         }
1321
1322         if (show_all || !strcmp(res->section, "devices")) {
1323                 cmdline_printf(
1324                         cl,
1325                         "\n"
1326                         "Device Operations:\n"
1327                         "--------------\n"
1328                         "device detach (identifier)\n"
1329                         "       Detach device by identifier.\n\n"
1330                 );
1331         }
1332
1333 }
1334
1335 cmdline_parse_token_string_t cmd_help_long_help =
1336         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1337
1338 cmdline_parse_token_string_t cmd_help_long_section =
1339         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1340                         "all#control#display#config#"
1341                         "ports#registers#filters#traffic_management#devices");
1342
1343 cmdline_parse_inst_t cmd_help_long = {
1344         .f = cmd_help_long_parsed,
1345         .data = NULL,
1346         .help_str = "help all|control|display|config|ports|register|"
1347                 "filters|traffic_management|devices: "
1348                 "Show help",
1349         .tokens = {
1350                 (void *)&cmd_help_long_help,
1351                 (void *)&cmd_help_long_section,
1352                 NULL,
1353         },
1354 };
1355
1356
1357 /* *** start/stop/close all ports *** */
1358 struct cmd_operate_port_result {
1359         cmdline_fixed_string_t keyword;
1360         cmdline_fixed_string_t name;
1361         cmdline_fixed_string_t value;
1362 };
1363
1364 static void cmd_operate_port_parsed(void *parsed_result,
1365                                 __rte_unused struct cmdline *cl,
1366                                 __rte_unused void *data)
1367 {
1368         struct cmd_operate_port_result *res = parsed_result;
1369
1370         if (!strcmp(res->name, "start"))
1371                 start_port(RTE_PORT_ALL);
1372         else if (!strcmp(res->name, "stop"))
1373                 stop_port(RTE_PORT_ALL);
1374         else if (!strcmp(res->name, "close"))
1375                 close_port(RTE_PORT_ALL);
1376         else if (!strcmp(res->name, "reset"))
1377                 reset_port(RTE_PORT_ALL);
1378         else
1379                 printf("Unknown parameter\n");
1380 }
1381
1382 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1383         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1384                                                                 "port");
1385 cmdline_parse_token_string_t cmd_operate_port_all_port =
1386         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1387                                                 "start#stop#close#reset");
1388 cmdline_parse_token_string_t cmd_operate_port_all_all =
1389         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1390
1391 cmdline_parse_inst_t cmd_operate_port = {
1392         .f = cmd_operate_port_parsed,
1393         .data = NULL,
1394         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1395         .tokens = {
1396                 (void *)&cmd_operate_port_all_cmd,
1397                 (void *)&cmd_operate_port_all_port,
1398                 (void *)&cmd_operate_port_all_all,
1399                 NULL,
1400         },
1401 };
1402
1403 /* *** start/stop/close specific port *** */
1404 struct cmd_operate_specific_port_result {
1405         cmdline_fixed_string_t keyword;
1406         cmdline_fixed_string_t name;
1407         uint8_t value;
1408 };
1409
1410 static void cmd_operate_specific_port_parsed(void *parsed_result,
1411                         __rte_unused struct cmdline *cl,
1412                                 __rte_unused void *data)
1413 {
1414         struct cmd_operate_specific_port_result *res = parsed_result;
1415
1416         if (!strcmp(res->name, "start"))
1417                 start_port(res->value);
1418         else if (!strcmp(res->name, "stop"))
1419                 stop_port(res->value);
1420         else if (!strcmp(res->name, "close"))
1421                 close_port(res->value);
1422         else if (!strcmp(res->name, "reset"))
1423                 reset_port(res->value);
1424         else
1425                 printf("Unknown parameter\n");
1426 }
1427
1428 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1429         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1430                                                         keyword, "port");
1431 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1432         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1433                                                 name, "start#stop#close#reset");
1434 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1435         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1436                                                         value, UINT8);
1437
1438 cmdline_parse_inst_t cmd_operate_specific_port = {
1439         .f = cmd_operate_specific_port_parsed,
1440         .data = NULL,
1441         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1442         .tokens = {
1443                 (void *)&cmd_operate_specific_port_cmd,
1444                 (void *)&cmd_operate_specific_port_port,
1445                 (void *)&cmd_operate_specific_port_id,
1446                 NULL,
1447         },
1448 };
1449
1450 /* *** enable port setup (after attach) via iterator or event *** */
1451 struct cmd_set_port_setup_on_result {
1452         cmdline_fixed_string_t set;
1453         cmdline_fixed_string_t port;
1454         cmdline_fixed_string_t setup;
1455         cmdline_fixed_string_t on;
1456         cmdline_fixed_string_t mode;
1457 };
1458
1459 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1460                                 __rte_unused struct cmdline *cl,
1461                                 __rte_unused void *data)
1462 {
1463         struct cmd_set_port_setup_on_result *res = parsed_result;
1464
1465         if (strcmp(res->mode, "event") == 0)
1466                 setup_on_probe_event = true;
1467         else if (strcmp(res->mode, "iterator") == 0)
1468                 setup_on_probe_event = false;
1469         else
1470                 printf("Unknown mode\n");
1471 }
1472
1473 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1474         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1475                         set, "set");
1476 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1477         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1478                         port, "port");
1479 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1480         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1481                         setup, "setup");
1482 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1483         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1484                         on, "on");
1485 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1486         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1487                         mode, "iterator#event");
1488
1489 cmdline_parse_inst_t cmd_set_port_setup_on = {
1490         .f = cmd_set_port_setup_on_parsed,
1491         .data = NULL,
1492         .help_str = "set port setup on iterator|event",
1493         .tokens = {
1494                 (void *)&cmd_set_port_setup_on_set,
1495                 (void *)&cmd_set_port_setup_on_port,
1496                 (void *)&cmd_set_port_setup_on_setup,
1497                 (void *)&cmd_set_port_setup_on_on,
1498                 (void *)&cmd_set_port_setup_on_mode,
1499                 NULL,
1500         },
1501 };
1502
1503 /* *** attach a specified port *** */
1504 struct cmd_operate_attach_port_result {
1505         cmdline_fixed_string_t port;
1506         cmdline_fixed_string_t keyword;
1507         cmdline_multi_string_t identifier;
1508 };
1509
1510 static void cmd_operate_attach_port_parsed(void *parsed_result,
1511                                 __rte_unused struct cmdline *cl,
1512                                 __rte_unused void *data)
1513 {
1514         struct cmd_operate_attach_port_result *res = parsed_result;
1515
1516         if (!strcmp(res->keyword, "attach"))
1517                 attach_port(res->identifier);
1518         else
1519                 printf("Unknown parameter\n");
1520 }
1521
1522 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1523         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1524                         port, "port");
1525 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1526         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1527                         keyword, "attach");
1528 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1529         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1530                         identifier, TOKEN_STRING_MULTI);
1531
1532 cmdline_parse_inst_t cmd_operate_attach_port = {
1533         .f = cmd_operate_attach_port_parsed,
1534         .data = NULL,
1535         .help_str = "port attach <identifier>: "
1536                 "(identifier: pci address or virtual dev name)",
1537         .tokens = {
1538                 (void *)&cmd_operate_attach_port_port,
1539                 (void *)&cmd_operate_attach_port_keyword,
1540                 (void *)&cmd_operate_attach_port_identifier,
1541                 NULL,
1542         },
1543 };
1544
1545 /* *** detach a specified port *** */
1546 struct cmd_operate_detach_port_result {
1547         cmdline_fixed_string_t port;
1548         cmdline_fixed_string_t keyword;
1549         portid_t port_id;
1550 };
1551
1552 static void cmd_operate_detach_port_parsed(void *parsed_result,
1553                                 __rte_unused struct cmdline *cl,
1554                                 __rte_unused void *data)
1555 {
1556         struct cmd_operate_detach_port_result *res = parsed_result;
1557
1558         if (!strcmp(res->keyword, "detach")) {
1559                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1560                 detach_port_device(res->port_id);
1561         } else {
1562                 printf("Unknown parameter\n");
1563         }
1564 }
1565
1566 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1567         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1568                         port, "port");
1569 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1570         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1571                         keyword, "detach");
1572 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1573         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1574                         port_id, UINT16);
1575
1576 cmdline_parse_inst_t cmd_operate_detach_port = {
1577         .f = cmd_operate_detach_port_parsed,
1578         .data = NULL,
1579         .help_str = "port detach <port_id>",
1580         .tokens = {
1581                 (void *)&cmd_operate_detach_port_port,
1582                 (void *)&cmd_operate_detach_port_keyword,
1583                 (void *)&cmd_operate_detach_port_port_id,
1584                 NULL,
1585         },
1586 };
1587
1588 /* *** detach device by identifier *** */
1589 struct cmd_operate_detach_device_result {
1590         cmdline_fixed_string_t device;
1591         cmdline_fixed_string_t keyword;
1592         cmdline_fixed_string_t identifier;
1593 };
1594
1595 static void cmd_operate_detach_device_parsed(void *parsed_result,
1596                                 __rte_unused struct cmdline *cl,
1597                                 __rte_unused void *data)
1598 {
1599         struct cmd_operate_detach_device_result *res = parsed_result;
1600
1601         if (!strcmp(res->keyword, "detach"))
1602                 detach_devargs(res->identifier);
1603         else
1604                 printf("Unknown parameter\n");
1605 }
1606
1607 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1608         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1609                         device, "device");
1610 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1611         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1612                         keyword, "detach");
1613 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1614         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1615                         identifier, NULL);
1616
1617 cmdline_parse_inst_t cmd_operate_detach_device = {
1618         .f = cmd_operate_detach_device_parsed,
1619         .data = NULL,
1620         .help_str = "device detach <identifier>:"
1621                 "(identifier: pci address or virtual dev name)",
1622         .tokens = {
1623                 (void *)&cmd_operate_detach_device_device,
1624                 (void *)&cmd_operate_detach_device_keyword,
1625                 (void *)&cmd_operate_detach_device_identifier,
1626                 NULL,
1627         },
1628 };
1629 /* *** configure speed for all ports *** */
1630 struct cmd_config_speed_all {
1631         cmdline_fixed_string_t port;
1632         cmdline_fixed_string_t keyword;
1633         cmdline_fixed_string_t all;
1634         cmdline_fixed_string_t item1;
1635         cmdline_fixed_string_t item2;
1636         cmdline_fixed_string_t value1;
1637         cmdline_fixed_string_t value2;
1638 };
1639
1640 static int
1641 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1642 {
1643
1644         int duplex;
1645
1646         if (!strcmp(duplexstr, "half")) {
1647                 duplex = ETH_LINK_HALF_DUPLEX;
1648         } else if (!strcmp(duplexstr, "full")) {
1649                 duplex = ETH_LINK_FULL_DUPLEX;
1650         } else if (!strcmp(duplexstr, "auto")) {
1651                 duplex = ETH_LINK_FULL_DUPLEX;
1652         } else {
1653                 printf("Unknown duplex parameter\n");
1654                 return -1;
1655         }
1656
1657         if (!strcmp(speedstr, "10")) {
1658                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1659                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1660         } else if (!strcmp(speedstr, "100")) {
1661                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1662                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1663         } else {
1664                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1665                         printf("Invalid speed/duplex parameters\n");
1666                         return -1;
1667                 }
1668                 if (!strcmp(speedstr, "1000")) {
1669                         *speed = ETH_LINK_SPEED_1G;
1670                 } else if (!strcmp(speedstr, "10000")) {
1671                         *speed = ETH_LINK_SPEED_10G;
1672                 } else if (!strcmp(speedstr, "25000")) {
1673                         *speed = ETH_LINK_SPEED_25G;
1674                 } else if (!strcmp(speedstr, "40000")) {
1675                         *speed = ETH_LINK_SPEED_40G;
1676                 } else if (!strcmp(speedstr, "50000")) {
1677                         *speed = ETH_LINK_SPEED_50G;
1678                 } else if (!strcmp(speedstr, "100000")) {
1679                         *speed = ETH_LINK_SPEED_100G;
1680                 } else if (!strcmp(speedstr, "200000")) {
1681                         *speed = ETH_LINK_SPEED_200G;
1682                 } else if (!strcmp(speedstr, "auto")) {
1683                         *speed = ETH_LINK_SPEED_AUTONEG;
1684                 } else {
1685                         printf("Unknown speed parameter\n");
1686                         return -1;
1687                 }
1688         }
1689
1690         return 0;
1691 }
1692
1693 static void
1694 cmd_config_speed_all_parsed(void *parsed_result,
1695                         __rte_unused struct cmdline *cl,
1696                         __rte_unused void *data)
1697 {
1698         struct cmd_config_speed_all *res = parsed_result;
1699         uint32_t link_speed;
1700         portid_t pid;
1701
1702         if (!all_ports_stopped()) {
1703                 printf("Please stop all ports first\n");
1704                 return;
1705         }
1706
1707         if (parse_and_check_speed_duplex(res->value1, res->value2,
1708                         &link_speed) < 0)
1709                 return;
1710
1711         RTE_ETH_FOREACH_DEV(pid) {
1712                 ports[pid].dev_conf.link_speeds = link_speed;
1713         }
1714
1715         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1716 }
1717
1718 cmdline_parse_token_string_t cmd_config_speed_all_port =
1719         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1720 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1721         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1722                                                         "config");
1723 cmdline_parse_token_string_t cmd_config_speed_all_all =
1724         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1725 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1726         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1727 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1728         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1729                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1730 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1731         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1732 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1734                                                 "half#full#auto");
1735
1736 cmdline_parse_inst_t cmd_config_speed_all = {
1737         .f = cmd_config_speed_all_parsed,
1738         .data = NULL,
1739         .help_str = "port config all speed "
1740                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1741                                                         "half|full|auto",
1742         .tokens = {
1743                 (void *)&cmd_config_speed_all_port,
1744                 (void *)&cmd_config_speed_all_keyword,
1745                 (void *)&cmd_config_speed_all_all,
1746                 (void *)&cmd_config_speed_all_item1,
1747                 (void *)&cmd_config_speed_all_value1,
1748                 (void *)&cmd_config_speed_all_item2,
1749                 (void *)&cmd_config_speed_all_value2,
1750                 NULL,
1751         },
1752 };
1753
1754 /* *** configure speed for specific port *** */
1755 struct cmd_config_speed_specific {
1756         cmdline_fixed_string_t port;
1757         cmdline_fixed_string_t keyword;
1758         portid_t id;
1759         cmdline_fixed_string_t item1;
1760         cmdline_fixed_string_t item2;
1761         cmdline_fixed_string_t value1;
1762         cmdline_fixed_string_t value2;
1763 };
1764
1765 static void
1766 cmd_config_speed_specific_parsed(void *parsed_result,
1767                                 __rte_unused struct cmdline *cl,
1768                                 __rte_unused void *data)
1769 {
1770         struct cmd_config_speed_specific *res = parsed_result;
1771         uint32_t link_speed;
1772
1773         if (!all_ports_stopped()) {
1774                 printf("Please stop all ports first\n");
1775                 return;
1776         }
1777
1778         if (port_id_is_invalid(res->id, ENABLED_WARN))
1779                 return;
1780
1781         if (parse_and_check_speed_duplex(res->value1, res->value2,
1782                         &link_speed) < 0)
1783                 return;
1784
1785         ports[res->id].dev_conf.link_speeds = link_speed;
1786
1787         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1788 }
1789
1790
1791 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1793                                                                 "port");
1794 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1795         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1796                                                                 "config");
1797 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1798         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1799 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1801                                                                 "speed");
1802 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1804                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1805 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1806         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1807                                                                 "duplex");
1808 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1809         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1810                                                         "half#full#auto");
1811
1812 cmdline_parse_inst_t cmd_config_speed_specific = {
1813         .f = cmd_config_speed_specific_parsed,
1814         .data = NULL,
1815         .help_str = "port config <port_id> speed "
1816                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1817                                                         "half|full|auto",
1818         .tokens = {
1819                 (void *)&cmd_config_speed_specific_port,
1820                 (void *)&cmd_config_speed_specific_keyword,
1821                 (void *)&cmd_config_speed_specific_id,
1822                 (void *)&cmd_config_speed_specific_item1,
1823                 (void *)&cmd_config_speed_specific_value1,
1824                 (void *)&cmd_config_speed_specific_item2,
1825                 (void *)&cmd_config_speed_specific_value2,
1826                 NULL,
1827         },
1828 };
1829
1830 /* *** configure loopback for all ports *** */
1831 struct cmd_config_loopback_all {
1832         cmdline_fixed_string_t port;
1833         cmdline_fixed_string_t keyword;
1834         cmdline_fixed_string_t all;
1835         cmdline_fixed_string_t item;
1836         uint32_t mode;
1837 };
1838
1839 static void
1840 cmd_config_loopback_all_parsed(void *parsed_result,
1841                         __rte_unused struct cmdline *cl,
1842                         __rte_unused void *data)
1843 {
1844         struct cmd_config_loopback_all *res = parsed_result;
1845         portid_t pid;
1846
1847         if (!all_ports_stopped()) {
1848                 printf("Please stop all ports first\n");
1849                 return;
1850         }
1851
1852         RTE_ETH_FOREACH_DEV(pid) {
1853                 ports[pid].dev_conf.lpbk_mode = res->mode;
1854         }
1855
1856         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1857 }
1858
1859 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1860         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1861 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1862         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1863                                                         "config");
1864 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1865         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1866 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1867         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1868                                                         "loopback");
1869 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1870         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1871
1872 cmdline_parse_inst_t cmd_config_loopback_all = {
1873         .f = cmd_config_loopback_all_parsed,
1874         .data = NULL,
1875         .help_str = "port config all loopback <mode>",
1876         .tokens = {
1877                 (void *)&cmd_config_loopback_all_port,
1878                 (void *)&cmd_config_loopback_all_keyword,
1879                 (void *)&cmd_config_loopback_all_all,
1880                 (void *)&cmd_config_loopback_all_item,
1881                 (void *)&cmd_config_loopback_all_mode,
1882                 NULL,
1883         },
1884 };
1885
1886 /* *** configure loopback for specific port *** */
1887 struct cmd_config_loopback_specific {
1888         cmdline_fixed_string_t port;
1889         cmdline_fixed_string_t keyword;
1890         uint16_t port_id;
1891         cmdline_fixed_string_t item;
1892         uint32_t mode;
1893 };
1894
1895 static void
1896 cmd_config_loopback_specific_parsed(void *parsed_result,
1897                                 __rte_unused struct cmdline *cl,
1898                                 __rte_unused void *data)
1899 {
1900         struct cmd_config_loopback_specific *res = parsed_result;
1901
1902         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1903                 return;
1904
1905         if (!port_is_stopped(res->port_id)) {
1906                 printf("Please stop port %u first\n", res->port_id);
1907                 return;
1908         }
1909
1910         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1911
1912         cmd_reconfig_device_queue(res->port_id, 1, 1);
1913 }
1914
1915
1916 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1917         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1918                                                                 "port");
1919 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1921                                                                 "config");
1922 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1923         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1924                                                                 UINT16);
1925 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1926         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1927                                                                 "loopback");
1928 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1929         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1930                               UINT32);
1931
1932 cmdline_parse_inst_t cmd_config_loopback_specific = {
1933         .f = cmd_config_loopback_specific_parsed,
1934         .data = NULL,
1935         .help_str = "port config <port_id> loopback <mode>",
1936         .tokens = {
1937                 (void *)&cmd_config_loopback_specific_port,
1938                 (void *)&cmd_config_loopback_specific_keyword,
1939                 (void *)&cmd_config_loopback_specific_id,
1940                 (void *)&cmd_config_loopback_specific_item,
1941                 (void *)&cmd_config_loopback_specific_mode,
1942                 NULL,
1943         },
1944 };
1945
1946 /* *** configure txq/rxq, txd/rxd *** */
1947 struct cmd_config_rx_tx {
1948         cmdline_fixed_string_t port;
1949         cmdline_fixed_string_t keyword;
1950         cmdline_fixed_string_t all;
1951         cmdline_fixed_string_t name;
1952         uint16_t value;
1953 };
1954
1955 static void
1956 cmd_config_rx_tx_parsed(void *parsed_result,
1957                         __rte_unused struct cmdline *cl,
1958                         __rte_unused void *data)
1959 {
1960         struct cmd_config_rx_tx *res = parsed_result;
1961
1962         if (!all_ports_stopped()) {
1963                 printf("Please stop all ports first\n");
1964                 return;
1965         }
1966         if (!strcmp(res->name, "rxq")) {
1967                 if (!res->value && !nb_txq) {
1968                         printf("Warning: Either rx or tx queues should be non zero\n");
1969                         return;
1970                 }
1971                 if (check_nb_rxq(res->value) != 0)
1972                         return;
1973                 nb_rxq = res->value;
1974         }
1975         else if (!strcmp(res->name, "txq")) {
1976                 if (!res->value && !nb_rxq) {
1977                         printf("Warning: Either rx or tx queues should be non zero\n");
1978                         return;
1979                 }
1980                 if (check_nb_txq(res->value) != 0)
1981                         return;
1982                 nb_txq = res->value;
1983         }
1984         else if (!strcmp(res->name, "rxd")) {
1985                 if (check_nb_rxd(res->value) != 0)
1986                         return;
1987                 nb_rxd = res->value;
1988         } else if (!strcmp(res->name, "txd")) {
1989                 if (check_nb_txd(res->value) != 0)
1990                         return;
1991
1992                 nb_txd = res->value;
1993         } else {
1994                 printf("Unknown parameter\n");
1995                 return;
1996         }
1997
1998         fwd_config_setup();
1999
2000         init_port_config();
2001
2002         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2003 }
2004
2005 cmdline_parse_token_string_t cmd_config_rx_tx_port =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
2007 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
2009 cmdline_parse_token_string_t cmd_config_rx_tx_all =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
2011 cmdline_parse_token_string_t cmd_config_rx_tx_name =
2012         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
2013                                                 "rxq#txq#rxd#txd");
2014 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2015         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2016
2017 cmdline_parse_inst_t cmd_config_rx_tx = {
2018         .f = cmd_config_rx_tx_parsed,
2019         .data = NULL,
2020         .help_str = "port config all rxq|txq|rxd|txd <value>",
2021         .tokens = {
2022                 (void *)&cmd_config_rx_tx_port,
2023                 (void *)&cmd_config_rx_tx_keyword,
2024                 (void *)&cmd_config_rx_tx_all,
2025                 (void *)&cmd_config_rx_tx_name,
2026                 (void *)&cmd_config_rx_tx_value,
2027                 NULL,
2028         },
2029 };
2030
2031 /* *** config max packet length *** */
2032 struct cmd_config_max_pkt_len_result {
2033         cmdline_fixed_string_t port;
2034         cmdline_fixed_string_t keyword;
2035         cmdline_fixed_string_t all;
2036         cmdline_fixed_string_t name;
2037         uint32_t value;
2038 };
2039
2040 static void
2041 cmd_config_max_pkt_len_parsed(void *parsed_result,
2042                                 __rte_unused struct cmdline *cl,
2043                                 __rte_unused void *data)
2044 {
2045         struct cmd_config_max_pkt_len_result *res = parsed_result;
2046         portid_t pid;
2047
2048         if (!all_ports_stopped()) {
2049                 printf("Please stop all ports first\n");
2050                 return;
2051         }
2052
2053         RTE_ETH_FOREACH_DEV(pid) {
2054                 struct rte_port *port = &ports[pid];
2055                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2056
2057                 if (!strcmp(res->name, "max-pkt-len")) {
2058                         if (res->value < RTE_ETHER_MIN_LEN) {
2059                                 printf("max-pkt-len can not be less than %d\n",
2060                                                 RTE_ETHER_MIN_LEN);
2061                                 return;
2062                         }
2063                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2064                                 return;
2065
2066                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2067                         if (res->value > RTE_ETHER_MAX_LEN)
2068                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2069                         else
2070                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2071                         port->dev_conf.rxmode.offloads = rx_offloads;
2072                 } else {
2073                         printf("Unknown parameter\n");
2074                         return;
2075                 }
2076         }
2077
2078         init_port_config();
2079
2080         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2081 }
2082
2083 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2084         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2085                                                                 "port");
2086 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2087         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2088                                                                 "config");
2089 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2090         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2091                                                                 "all");
2092 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2093         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2094                                                                 "max-pkt-len");
2095 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2096         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2097                                                                 UINT32);
2098
2099 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2100         .f = cmd_config_max_pkt_len_parsed,
2101         .data = NULL,
2102         .help_str = "port config all max-pkt-len <value>",
2103         .tokens = {
2104                 (void *)&cmd_config_max_pkt_len_port,
2105                 (void *)&cmd_config_max_pkt_len_keyword,
2106                 (void *)&cmd_config_max_pkt_len_all,
2107                 (void *)&cmd_config_max_pkt_len_name,
2108                 (void *)&cmd_config_max_pkt_len_value,
2109                 NULL,
2110         },
2111 };
2112
2113 /* *** config max LRO aggregated packet size *** */
2114 struct cmd_config_max_lro_pkt_size_result {
2115         cmdline_fixed_string_t port;
2116         cmdline_fixed_string_t keyword;
2117         cmdline_fixed_string_t all;
2118         cmdline_fixed_string_t name;
2119         uint32_t value;
2120 };
2121
2122 static void
2123 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2124                                 __rte_unused struct cmdline *cl,
2125                                 __rte_unused void *data)
2126 {
2127         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2128         portid_t pid;
2129
2130         if (!all_ports_stopped()) {
2131                 printf("Please stop all ports first\n");
2132                 return;
2133         }
2134
2135         RTE_ETH_FOREACH_DEV(pid) {
2136                 struct rte_port *port = &ports[pid];
2137
2138                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2139                         if (res->value ==
2140                                         port->dev_conf.rxmode.max_lro_pkt_size)
2141                                 return;
2142
2143                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2144                 } else {
2145                         printf("Unknown parameter\n");
2146                         return;
2147                 }
2148         }
2149
2150         init_port_config();
2151
2152         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2153 }
2154
2155 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2157                                  port, "port");
2158 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2160                                  keyword, "config");
2161 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2162         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2163                                  all, "all");
2164 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2165         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2166                                  name, "max-lro-pkt-size");
2167 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2168         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2169                               value, UINT32);
2170
2171 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2172         .f = cmd_config_max_lro_pkt_size_parsed,
2173         .data = NULL,
2174         .help_str = "port config all max-lro-pkt-size <value>",
2175         .tokens = {
2176                 (void *)&cmd_config_max_lro_pkt_size_port,
2177                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2178                 (void *)&cmd_config_max_lro_pkt_size_all,
2179                 (void *)&cmd_config_max_lro_pkt_size_name,
2180                 (void *)&cmd_config_max_lro_pkt_size_value,
2181                 NULL,
2182         },
2183 };
2184
2185 /* *** configure port MTU *** */
2186 struct cmd_config_mtu_result {
2187         cmdline_fixed_string_t port;
2188         cmdline_fixed_string_t keyword;
2189         cmdline_fixed_string_t mtu;
2190         portid_t port_id;
2191         uint16_t value;
2192 };
2193
2194 static void
2195 cmd_config_mtu_parsed(void *parsed_result,
2196                       __rte_unused struct cmdline *cl,
2197                       __rte_unused void *data)
2198 {
2199         struct cmd_config_mtu_result *res = parsed_result;
2200
2201         if (res->value < RTE_ETHER_MIN_LEN) {
2202                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2203                 return;
2204         }
2205         port_mtu_set(res->port_id, res->value);
2206 }
2207
2208 cmdline_parse_token_string_t cmd_config_mtu_port =
2209         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2210                                  "port");
2211 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2212         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2213                                  "config");
2214 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2215         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2216                                  "mtu");
2217 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2218         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2219 cmdline_parse_token_num_t cmd_config_mtu_value =
2220         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2221
2222 cmdline_parse_inst_t cmd_config_mtu = {
2223         .f = cmd_config_mtu_parsed,
2224         .data = NULL,
2225         .help_str = "port config mtu <port_id> <value>",
2226         .tokens = {
2227                 (void *)&cmd_config_mtu_port,
2228                 (void *)&cmd_config_mtu_keyword,
2229                 (void *)&cmd_config_mtu_mtu,
2230                 (void *)&cmd_config_mtu_port_id,
2231                 (void *)&cmd_config_mtu_value,
2232                 NULL,
2233         },
2234 };
2235
2236 /* *** configure rx mode *** */
2237 struct cmd_config_rx_mode_flag {
2238         cmdline_fixed_string_t port;
2239         cmdline_fixed_string_t keyword;
2240         cmdline_fixed_string_t all;
2241         cmdline_fixed_string_t name;
2242         cmdline_fixed_string_t value;
2243 };
2244
2245 static void
2246 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2247                                 __rte_unused struct cmdline *cl,
2248                                 __rte_unused void *data)
2249 {
2250         struct cmd_config_rx_mode_flag *res = parsed_result;
2251
2252         if (!all_ports_stopped()) {
2253                 printf("Please stop all ports first\n");
2254                 return;
2255         }
2256
2257         if (!strcmp(res->name, "drop-en")) {
2258                 if (!strcmp(res->value, "on"))
2259                         rx_drop_en = 1;
2260                 else if (!strcmp(res->value, "off"))
2261                         rx_drop_en = 0;
2262                 else {
2263                         printf("Unknown parameter\n");
2264                         return;
2265                 }
2266         } else {
2267                 printf("Unknown parameter\n");
2268                 return;
2269         }
2270
2271         init_port_config();
2272
2273         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2274 }
2275
2276 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2277         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2278 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2279         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2280                                                                 "config");
2281 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2282         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2283 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2284         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2285                                         "drop-en");
2286 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2288                                                         "on#off");
2289
2290 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2291         .f = cmd_config_rx_mode_flag_parsed,
2292         .data = NULL,
2293         .help_str = "port config all drop-en on|off",
2294         .tokens = {
2295                 (void *)&cmd_config_rx_mode_flag_port,
2296                 (void *)&cmd_config_rx_mode_flag_keyword,
2297                 (void *)&cmd_config_rx_mode_flag_all,
2298                 (void *)&cmd_config_rx_mode_flag_name,
2299                 (void *)&cmd_config_rx_mode_flag_value,
2300                 NULL,
2301         },
2302 };
2303
2304 /* *** configure rss *** */
2305 struct cmd_config_rss {
2306         cmdline_fixed_string_t port;
2307         cmdline_fixed_string_t keyword;
2308         cmdline_fixed_string_t all;
2309         cmdline_fixed_string_t name;
2310         cmdline_fixed_string_t value;
2311 };
2312
2313 static void
2314 cmd_config_rss_parsed(void *parsed_result,
2315                         __rte_unused struct cmdline *cl,
2316                         __rte_unused void *data)
2317 {
2318         struct cmd_config_rss *res = parsed_result;
2319         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2320         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2321         int use_default = 0;
2322         int all_updated = 1;
2323         int diag;
2324         uint16_t i;
2325         int ret;
2326
2327         if (!strcmp(res->value, "all"))
2328                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2329                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2330                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2331                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2332         else if (!strcmp(res->value, "eth"))
2333                 rss_conf.rss_hf = ETH_RSS_ETH;
2334         else if (!strcmp(res->value, "vlan"))
2335                 rss_conf.rss_hf = ETH_RSS_VLAN;
2336         else if (!strcmp(res->value, "ip"))
2337                 rss_conf.rss_hf = ETH_RSS_IP;
2338         else if (!strcmp(res->value, "udp"))
2339                 rss_conf.rss_hf = ETH_RSS_UDP;
2340         else if (!strcmp(res->value, "tcp"))
2341                 rss_conf.rss_hf = ETH_RSS_TCP;
2342         else if (!strcmp(res->value, "sctp"))
2343                 rss_conf.rss_hf = ETH_RSS_SCTP;
2344         else if (!strcmp(res->value, "ether"))
2345                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2346         else if (!strcmp(res->value, "port"))
2347                 rss_conf.rss_hf = ETH_RSS_PORT;
2348         else if (!strcmp(res->value, "vxlan"))
2349                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2350         else if (!strcmp(res->value, "geneve"))
2351                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2352         else if (!strcmp(res->value, "nvgre"))
2353                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2354         else if (!strcmp(res->value, "l3-pre32"))
2355                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2356         else if (!strcmp(res->value, "l3-pre40"))
2357                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2358         else if (!strcmp(res->value, "l3-pre48"))
2359                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2360         else if (!strcmp(res->value, "l3-pre56"))
2361                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2362         else if (!strcmp(res->value, "l3-pre64"))
2363                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2364         else if (!strcmp(res->value, "l3-pre96"))
2365                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2366         else if (!strcmp(res->value, "l3-src-only"))
2367                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2368         else if (!strcmp(res->value, "l3-dst-only"))
2369                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2370         else if (!strcmp(res->value, "l4-src-only"))
2371                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2372         else if (!strcmp(res->value, "l4-dst-only"))
2373                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2374         else if (!strcmp(res->value, "l2-src-only"))
2375                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2376         else if (!strcmp(res->value, "l2-dst-only"))
2377                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2378         else if (!strcmp(res->value, "l2tpv3"))
2379                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2380         else if (!strcmp(res->value, "esp"))
2381                 rss_conf.rss_hf = ETH_RSS_ESP;
2382         else if (!strcmp(res->value, "ah"))
2383                 rss_conf.rss_hf = ETH_RSS_AH;
2384         else if (!strcmp(res->value, "pfcp"))
2385                 rss_conf.rss_hf = ETH_RSS_PFCP;
2386         else if (!strcmp(res->value, "pppoe"))
2387                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2388         else if (!strcmp(res->value, "gtpu"))
2389                 rss_conf.rss_hf = ETH_RSS_GTPU;
2390         else if (!strcmp(res->value, "none"))
2391                 rss_conf.rss_hf = 0;
2392         else if (!strcmp(res->value, "level-default")) {
2393                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2394                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2395         } else if (!strcmp(res->value, "level-outer")) {
2396                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2397                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2398         } else if (!strcmp(res->value, "level-inner")) {
2399                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2400                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2401         } else if (!strcmp(res->value, "default"))
2402                 use_default = 1;
2403         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2404                                                 atoi(res->value) < 64)
2405                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2406         else {
2407                 printf("Unknown parameter\n");
2408                 return;
2409         }
2410         rss_conf.rss_key = NULL;
2411         /* Update global configuration for RSS types. */
2412         RTE_ETH_FOREACH_DEV(i) {
2413                 struct rte_eth_rss_conf local_rss_conf;
2414
2415                 ret = eth_dev_info_get_print_err(i, &dev_info);
2416                 if (ret != 0)
2417                         return;
2418
2419                 if (use_default)
2420                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2421
2422                 local_rss_conf = rss_conf;
2423                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2424                         dev_info.flow_type_rss_offloads;
2425                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2426                         printf("Port %u modified RSS hash function based on hardware support,"
2427                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2428                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2429                 }
2430                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2431                 if (diag < 0) {
2432                         all_updated = 0;
2433                         printf("Configuration of RSS hash at ethernet port %d "
2434                                 "failed with error (%d): %s.\n",
2435                                 i, -diag, strerror(-diag));
2436                 }
2437         }
2438         if (all_updated && !use_default) {
2439                 rss_hf = rss_conf.rss_hf;
2440                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2441         }
2442 }
2443
2444 cmdline_parse_token_string_t cmd_config_rss_port =
2445         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2446 cmdline_parse_token_string_t cmd_config_rss_keyword =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2448 cmdline_parse_token_string_t cmd_config_rss_all =
2449         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2450 cmdline_parse_token_string_t cmd_config_rss_name =
2451         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2452 cmdline_parse_token_string_t cmd_config_rss_value =
2453         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2454
2455 cmdline_parse_inst_t cmd_config_rss = {
2456         .f = cmd_config_rss_parsed,
2457         .data = NULL,
2458         .help_str = "port config all rss "
2459                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2460                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2461                 "level-outer|level-inner|<flowtype_id>",
2462         .tokens = {
2463                 (void *)&cmd_config_rss_port,
2464                 (void *)&cmd_config_rss_keyword,
2465                 (void *)&cmd_config_rss_all,
2466                 (void *)&cmd_config_rss_name,
2467                 (void *)&cmd_config_rss_value,
2468                 NULL,
2469         },
2470 };
2471
2472 /* *** configure rss hash key *** */
2473 struct cmd_config_rss_hash_key {
2474         cmdline_fixed_string_t port;
2475         cmdline_fixed_string_t config;
2476         portid_t port_id;
2477         cmdline_fixed_string_t rss_hash_key;
2478         cmdline_fixed_string_t rss_type;
2479         cmdline_fixed_string_t key;
2480 };
2481
2482 static uint8_t
2483 hexa_digit_to_value(char hexa_digit)
2484 {
2485         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2486                 return (uint8_t) (hexa_digit - '0');
2487         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2488                 return (uint8_t) ((hexa_digit - 'a') + 10);
2489         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2490                 return (uint8_t) ((hexa_digit - 'A') + 10);
2491         /* Invalid hexa digit */
2492         return 0xFF;
2493 }
2494
2495 static uint8_t
2496 parse_and_check_key_hexa_digit(char *key, int idx)
2497 {
2498         uint8_t hexa_v;
2499
2500         hexa_v = hexa_digit_to_value(key[idx]);
2501         if (hexa_v == 0xFF)
2502                 printf("invalid key: character %c at position %d is not a "
2503                        "valid hexa digit\n", key[idx], idx);
2504         return hexa_v;
2505 }
2506
2507 static void
2508 cmd_config_rss_hash_key_parsed(void *parsed_result,
2509                                __rte_unused struct cmdline *cl,
2510                                __rte_unused void *data)
2511 {
2512         struct cmd_config_rss_hash_key *res = parsed_result;
2513         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2514         uint8_t xdgt0;
2515         uint8_t xdgt1;
2516         int i;
2517         struct rte_eth_dev_info dev_info;
2518         uint8_t hash_key_size;
2519         uint32_t key_len;
2520         int ret;
2521
2522         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2523         if (ret != 0)
2524                 return;
2525
2526         if (dev_info.hash_key_size > 0 &&
2527                         dev_info.hash_key_size <= sizeof(hash_key))
2528                 hash_key_size = dev_info.hash_key_size;
2529         else {
2530                 printf("dev_info did not provide a valid hash key size\n");
2531                 return;
2532         }
2533         /* Check the length of the RSS hash key */
2534         key_len = strlen(res->key);
2535         if (key_len != (hash_key_size * 2)) {
2536                 printf("key length: %d invalid - key must be a string of %d"
2537                            " hexa-decimal numbers\n",
2538                            (int) key_len, hash_key_size * 2);
2539                 return;
2540         }
2541         /* Translate RSS hash key into binary representation */
2542         for (i = 0; i < hash_key_size; i++) {
2543                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2544                 if (xdgt0 == 0xFF)
2545                         return;
2546                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2547                 if (xdgt1 == 0xFF)
2548                         return;
2549                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2550         }
2551         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2552                         hash_key_size);
2553 }
2554
2555 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2556         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2557 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2558         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2559                                  "config");
2560 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2561         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2562 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2563         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2564                                  rss_hash_key, "rss-hash-key");
2565 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2566         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2567                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2568                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2569                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2570                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2571                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2572                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2573                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2574 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2575         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2576
2577 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2578         .f = cmd_config_rss_hash_key_parsed,
2579         .data = NULL,
2580         .help_str = "port config <port_id> rss-hash-key "
2581                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2582                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2583                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2584                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2585                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2586                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2587                 "<string of hex digits (variable length, NIC dependent)>",
2588         .tokens = {
2589                 (void *)&cmd_config_rss_hash_key_port,
2590                 (void *)&cmd_config_rss_hash_key_config,
2591                 (void *)&cmd_config_rss_hash_key_port_id,
2592                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2593                 (void *)&cmd_config_rss_hash_key_rss_type,
2594                 (void *)&cmd_config_rss_hash_key_value,
2595                 NULL,
2596         },
2597 };
2598
2599 /* *** configure port rxq/txq ring size *** */
2600 struct cmd_config_rxtx_ring_size {
2601         cmdline_fixed_string_t port;
2602         cmdline_fixed_string_t config;
2603         portid_t portid;
2604         cmdline_fixed_string_t rxtxq;
2605         uint16_t qid;
2606         cmdline_fixed_string_t rsize;
2607         uint16_t size;
2608 };
2609
2610 static void
2611 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2612                                  __rte_unused struct cmdline *cl,
2613                                  __rte_unused void *data)
2614 {
2615         struct cmd_config_rxtx_ring_size *res = parsed_result;
2616         struct rte_port *port;
2617         uint8_t isrx;
2618
2619         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2620                 return;
2621
2622         if (res->portid == (portid_t)RTE_PORT_ALL) {
2623                 printf("Invalid port id\n");
2624                 return;
2625         }
2626
2627         port = &ports[res->portid];
2628
2629         if (!strcmp(res->rxtxq, "rxq"))
2630                 isrx = 1;
2631         else if (!strcmp(res->rxtxq, "txq"))
2632                 isrx = 0;
2633         else {
2634                 printf("Unknown parameter\n");
2635                 return;
2636         }
2637
2638         if (isrx && rx_queue_id_is_invalid(res->qid))
2639                 return;
2640         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2641                 return;
2642
2643         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2644                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2645                        rx_free_thresh);
2646                 return;
2647         }
2648
2649         if (isrx)
2650                 port->nb_rx_desc[res->qid] = res->size;
2651         else
2652                 port->nb_tx_desc[res->qid] = res->size;
2653
2654         cmd_reconfig_device_queue(res->portid, 0, 1);
2655 }
2656
2657 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2658         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2659                                  port, "port");
2660 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2661         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2662                                  config, "config");
2663 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2664         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2665                                  portid, UINT16);
2666 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2667         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2668                                  rxtxq, "rxq#txq");
2669 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2670         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2671                               qid, UINT16);
2672 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2673         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2674                                  rsize, "ring_size");
2675 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2676         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2677                               size, UINT16);
2678
2679 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2680         .f = cmd_config_rxtx_ring_size_parsed,
2681         .data = NULL,
2682         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2683         .tokens = {
2684                 (void *)&cmd_config_rxtx_ring_size_port,
2685                 (void *)&cmd_config_rxtx_ring_size_config,
2686                 (void *)&cmd_config_rxtx_ring_size_portid,
2687                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2688                 (void *)&cmd_config_rxtx_ring_size_qid,
2689                 (void *)&cmd_config_rxtx_ring_size_rsize,
2690                 (void *)&cmd_config_rxtx_ring_size_size,
2691                 NULL,
2692         },
2693 };
2694
2695 /* *** configure port rxq/txq start/stop *** */
2696 struct cmd_config_rxtx_queue {
2697         cmdline_fixed_string_t port;
2698         portid_t portid;
2699         cmdline_fixed_string_t rxtxq;
2700         uint16_t qid;
2701         cmdline_fixed_string_t opname;
2702 };
2703
2704 static void
2705 cmd_config_rxtx_queue_parsed(void *parsed_result,
2706                         __rte_unused struct cmdline *cl,
2707                         __rte_unused void *data)
2708 {
2709         struct cmd_config_rxtx_queue *res = parsed_result;
2710         uint8_t isrx;
2711         uint8_t isstart;
2712         int ret = 0;
2713
2714         if (test_done == 0) {
2715                 printf("Please stop forwarding first\n");
2716                 return;
2717         }
2718
2719         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2720                 return;
2721
2722         if (port_is_started(res->portid) != 1) {
2723                 printf("Please start port %u first\n", res->portid);
2724                 return;
2725         }
2726
2727         if (!strcmp(res->rxtxq, "rxq"))
2728                 isrx = 1;
2729         else if (!strcmp(res->rxtxq, "txq"))
2730                 isrx = 0;
2731         else {
2732                 printf("Unknown parameter\n");
2733                 return;
2734         }
2735
2736         if (isrx && rx_queue_id_is_invalid(res->qid))
2737                 return;
2738         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2739                 return;
2740
2741         if (!strcmp(res->opname, "start"))
2742                 isstart = 1;
2743         else if (!strcmp(res->opname, "stop"))
2744                 isstart = 0;
2745         else {
2746                 printf("Unknown parameter\n");
2747                 return;
2748         }
2749
2750         if (isstart && isrx)
2751                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2752         else if (!isstart && isrx)
2753                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2754         else if (isstart && !isrx)
2755                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2756         else
2757                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2758
2759         if (ret == -ENOTSUP)
2760                 printf("Function not supported in PMD driver\n");
2761 }
2762
2763 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2764         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2765 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2766         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2767 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2768         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2769 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2770         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2771 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2772         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2773                                                 "start#stop");
2774
2775 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2776         .f = cmd_config_rxtx_queue_parsed,
2777         .data = NULL,
2778         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2779         .tokens = {
2780                 (void *)&cmd_config_rxtx_queue_port,
2781                 (void *)&cmd_config_rxtx_queue_portid,
2782                 (void *)&cmd_config_rxtx_queue_rxtxq,
2783                 (void *)&cmd_config_rxtx_queue_qid,
2784                 (void *)&cmd_config_rxtx_queue_opname,
2785                 NULL,
2786         },
2787 };
2788
2789 /* *** configure port rxq/txq deferred start on/off *** */
2790 struct cmd_config_deferred_start_rxtx_queue {
2791         cmdline_fixed_string_t port;
2792         portid_t port_id;
2793         cmdline_fixed_string_t rxtxq;
2794         uint16_t qid;
2795         cmdline_fixed_string_t opname;
2796         cmdline_fixed_string_t state;
2797 };
2798
2799 static void
2800 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2801                         __rte_unused struct cmdline *cl,
2802                         __rte_unused void *data)
2803 {
2804         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2805         struct rte_port *port;
2806         uint8_t isrx;
2807         uint8_t ison;
2808         uint8_t needreconfig = 0;
2809
2810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2811                 return;
2812
2813         if (port_is_started(res->port_id) != 0) {
2814                 printf("Please stop port %u first\n", res->port_id);
2815                 return;
2816         }
2817
2818         port = &ports[res->port_id];
2819
2820         isrx = !strcmp(res->rxtxq, "rxq");
2821
2822         if (isrx && rx_queue_id_is_invalid(res->qid))
2823                 return;
2824         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2825                 return;
2826
2827         ison = !strcmp(res->state, "on");
2828
2829         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2830                 port->rx_conf[res->qid].rx_deferred_start = ison;
2831                 needreconfig = 1;
2832         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2833                 port->tx_conf[res->qid].tx_deferred_start = ison;
2834                 needreconfig = 1;
2835         }
2836
2837         if (needreconfig)
2838                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2839 }
2840
2841 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2842         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2843                                                 port, "port");
2844 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2845         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2846                                                 port_id, UINT16);
2847 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2848         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2849                                                 rxtxq, "rxq#txq");
2850 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2851         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2852                                                 qid, UINT16);
2853 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2854         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2855                                                 opname, "deferred_start");
2856 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2857         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2858                                                 state, "on#off");
2859
2860 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2861         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2862         .data = NULL,
2863         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2864         .tokens = {
2865                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2866                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2867                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2868                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2869                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2870                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2871                 NULL,
2872         },
2873 };
2874
2875 /* *** configure port rxq/txq setup *** */
2876 struct cmd_setup_rxtx_queue {
2877         cmdline_fixed_string_t port;
2878         portid_t portid;
2879         cmdline_fixed_string_t rxtxq;
2880         uint16_t qid;
2881         cmdline_fixed_string_t setup;
2882 };
2883
2884 /* Common CLI fields for queue setup */
2885 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2886         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2887 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2888         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2889 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2890         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2891 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2892         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2893 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2894         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2895
2896 static void
2897 cmd_setup_rxtx_queue_parsed(
2898         void *parsed_result,
2899         __rte_unused struct cmdline *cl,
2900         __rte_unused void *data)
2901 {
2902         struct cmd_setup_rxtx_queue *res = parsed_result;
2903         struct rte_port *port;
2904         struct rte_mempool *mp;
2905         unsigned int socket_id;
2906         uint8_t isrx = 0;
2907         int ret;
2908
2909         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2910                 return;
2911
2912         if (res->portid == (portid_t)RTE_PORT_ALL) {
2913                 printf("Invalid port id\n");
2914                 return;
2915         }
2916
2917         if (!strcmp(res->rxtxq, "rxq"))
2918                 isrx = 1;
2919         else if (!strcmp(res->rxtxq, "txq"))
2920                 isrx = 0;
2921         else {
2922                 printf("Unknown parameter\n");
2923                 return;
2924         }
2925
2926         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2927                 printf("Invalid rx queue\n");
2928                 return;
2929         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2930                 printf("Invalid tx queue\n");
2931                 return;
2932         }
2933
2934         port = &ports[res->portid];
2935         if (isrx) {
2936                 socket_id = rxring_numa[res->portid];
2937                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2938                         socket_id = port->socket_id;
2939
2940                 mp = mbuf_pool_find(socket_id, 0);
2941                 if (mp == NULL) {
2942                         printf("Failed to setup RX queue: "
2943                                 "No mempool allocation"
2944                                 " on the socket %d\n",
2945                                 rxring_numa[res->portid]);
2946                         return;
2947                 }
2948                 ret = rx_queue_setup(res->portid,
2949                                      res->qid,
2950                                      port->nb_rx_desc[res->qid],
2951                                      socket_id,
2952                                      &port->rx_conf[res->qid],
2953                                      mp);
2954                 if (ret)
2955                         printf("Failed to setup RX queue\n");
2956         } else {
2957                 socket_id = txring_numa[res->portid];
2958                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2959                         socket_id = port->socket_id;
2960
2961                 ret = rte_eth_tx_queue_setup(res->portid,
2962                                              res->qid,
2963                                              port->nb_tx_desc[res->qid],
2964                                              socket_id,
2965                                              &port->tx_conf[res->qid]);
2966                 if (ret)
2967                         printf("Failed to setup TX queue\n");
2968         }
2969 }
2970
2971 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2972         .f = cmd_setup_rxtx_queue_parsed,
2973         .data = NULL,
2974         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2975         .tokens = {
2976                 (void *)&cmd_setup_rxtx_queue_port,
2977                 (void *)&cmd_setup_rxtx_queue_portid,
2978                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2979                 (void *)&cmd_setup_rxtx_queue_qid,
2980                 (void *)&cmd_setup_rxtx_queue_setup,
2981                 NULL,
2982         },
2983 };
2984
2985
2986 /* *** Configure RSS RETA *** */
2987 struct cmd_config_rss_reta {
2988         cmdline_fixed_string_t port;
2989         cmdline_fixed_string_t keyword;
2990         portid_t port_id;
2991         cmdline_fixed_string_t name;
2992         cmdline_fixed_string_t list_name;
2993         cmdline_fixed_string_t list_of_items;
2994 };
2995
2996 static int
2997 parse_reta_config(const char *str,
2998                   struct rte_eth_rss_reta_entry64 *reta_conf,
2999                   uint16_t nb_entries)
3000 {
3001         int i;
3002         unsigned size;
3003         uint16_t hash_index, idx, shift;
3004         uint16_t nb_queue;
3005         char s[256];
3006         const char *p, *p0 = str;
3007         char *end;
3008         enum fieldnames {
3009                 FLD_HASH_INDEX = 0,
3010                 FLD_QUEUE,
3011                 _NUM_FLD
3012         };
3013         unsigned long int_fld[_NUM_FLD];
3014         char *str_fld[_NUM_FLD];
3015
3016         while ((p = strchr(p0,'(')) != NULL) {
3017                 ++p;
3018                 if((p0 = strchr(p,')')) == NULL)
3019                         return -1;
3020
3021                 size = p0 - p;
3022                 if(size >= sizeof(s))
3023                         return -1;
3024
3025                 snprintf(s, sizeof(s), "%.*s", size, p);
3026                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3027                         return -1;
3028                 for (i = 0; i < _NUM_FLD; i++) {
3029                         errno = 0;
3030                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3031                         if (errno != 0 || end == str_fld[i] ||
3032                                         int_fld[i] > 65535)
3033                                 return -1;
3034                 }
3035
3036                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3037                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3038
3039                 if (hash_index >= nb_entries) {
3040                         printf("Invalid RETA hash index=%d\n", hash_index);
3041                         return -1;
3042                 }
3043
3044                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3045                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3046                 reta_conf[idx].mask |= (1ULL << shift);
3047                 reta_conf[idx].reta[shift] = nb_queue;
3048         }
3049
3050         return 0;
3051 }
3052
3053 static void
3054 cmd_set_rss_reta_parsed(void *parsed_result,
3055                         __rte_unused struct cmdline *cl,
3056                         __rte_unused void *data)
3057 {
3058         int ret;
3059         struct rte_eth_dev_info dev_info;
3060         struct rte_eth_rss_reta_entry64 reta_conf[8];
3061         struct cmd_config_rss_reta *res = parsed_result;
3062
3063         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3064         if (ret != 0)
3065                 return;
3066
3067         if (dev_info.reta_size == 0) {
3068                 printf("Redirection table size is 0 which is "
3069                                         "invalid for RSS\n");
3070                 return;
3071         } else
3072                 printf("The reta size of port %d is %u\n",
3073                         res->port_id, dev_info.reta_size);
3074         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3075                 printf("Currently do not support more than %u entries of "
3076                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3077                 return;
3078         }
3079
3080         memset(reta_conf, 0, sizeof(reta_conf));
3081         if (!strcmp(res->list_name, "reta")) {
3082                 if (parse_reta_config(res->list_of_items, reta_conf,
3083                                                 dev_info.reta_size)) {
3084                         printf("Invalid RSS Redirection Table "
3085                                         "config entered\n");
3086                         return;
3087                 }
3088                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3089                                 reta_conf, dev_info.reta_size);
3090                 if (ret != 0)
3091                         printf("Bad redirection table parameter, "
3092                                         "return code = %d \n", ret);
3093         }
3094 }
3095
3096 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3097         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3098 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3099         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3100 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3101         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3102 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3103         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3104 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3105         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3106 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3107         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3108                                  NULL);
3109 cmdline_parse_inst_t cmd_config_rss_reta = {
3110         .f = cmd_set_rss_reta_parsed,
3111         .data = NULL,
3112         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3113         .tokens = {
3114                 (void *)&cmd_config_rss_reta_port,
3115                 (void *)&cmd_config_rss_reta_keyword,
3116                 (void *)&cmd_config_rss_reta_port_id,
3117                 (void *)&cmd_config_rss_reta_name,
3118                 (void *)&cmd_config_rss_reta_list_name,
3119                 (void *)&cmd_config_rss_reta_list_of_items,
3120                 NULL,
3121         },
3122 };
3123
3124 /* *** SHOW PORT RETA INFO *** */
3125 struct cmd_showport_reta {
3126         cmdline_fixed_string_t show;
3127         cmdline_fixed_string_t port;
3128         portid_t port_id;
3129         cmdline_fixed_string_t rss;
3130         cmdline_fixed_string_t reta;
3131         uint16_t size;
3132         cmdline_fixed_string_t list_of_items;
3133 };
3134
3135 static int
3136 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3137                            uint16_t nb_entries,
3138                            char *str)
3139 {
3140         uint32_t size;
3141         const char *p, *p0 = str;
3142         char s[256];
3143         char *end;
3144         char *str_fld[8];
3145         uint16_t i;
3146         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3147                         RTE_RETA_GROUP_SIZE;
3148         int ret;
3149
3150         p = strchr(p0, '(');
3151         if (p == NULL)
3152                 return -1;
3153         p++;
3154         p0 = strchr(p, ')');
3155         if (p0 == NULL)
3156                 return -1;
3157         size = p0 - p;
3158         if (size >= sizeof(s)) {
3159                 printf("The string size exceeds the internal buffer size\n");
3160                 return -1;
3161         }
3162         snprintf(s, sizeof(s), "%.*s", size, p);
3163         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3164         if (ret <= 0 || ret != num) {
3165                 printf("The bits of masks do not match the number of "
3166                                         "reta entries: %u\n", num);
3167                 return -1;
3168         }
3169         for (i = 0; i < ret; i++)
3170                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3171
3172         return 0;
3173 }
3174
3175 static void
3176 cmd_showport_reta_parsed(void *parsed_result,
3177                          __rte_unused struct cmdline *cl,
3178                          __rte_unused void *data)
3179 {
3180         struct cmd_showport_reta *res = parsed_result;
3181         struct rte_eth_rss_reta_entry64 reta_conf[8];
3182         struct rte_eth_dev_info dev_info;
3183         uint16_t max_reta_size;
3184         int ret;
3185
3186         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3187         if (ret != 0)
3188                 return;
3189
3190         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3191         if (res->size == 0 || res->size > max_reta_size) {
3192                 printf("Invalid redirection table size: %u (1-%u)\n",
3193                         res->size, max_reta_size);
3194                 return;
3195         }
3196
3197         memset(reta_conf, 0, sizeof(reta_conf));
3198         if (showport_parse_reta_config(reta_conf, res->size,
3199                                 res->list_of_items) < 0) {
3200                 printf("Invalid string: %s for reta masks\n",
3201                                         res->list_of_items);
3202                 return;
3203         }
3204         port_rss_reta_info(res->port_id, reta_conf, res->size);
3205 }
3206
3207 cmdline_parse_token_string_t cmd_showport_reta_show =
3208         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3209 cmdline_parse_token_string_t cmd_showport_reta_port =
3210         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3211 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3212         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3213 cmdline_parse_token_string_t cmd_showport_reta_rss =
3214         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3215 cmdline_parse_token_string_t cmd_showport_reta_reta =
3216         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3217 cmdline_parse_token_num_t cmd_showport_reta_size =
3218         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3219 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3220         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3221                                         list_of_items, NULL);
3222
3223 cmdline_parse_inst_t cmd_showport_reta = {
3224         .f = cmd_showport_reta_parsed,
3225         .data = NULL,
3226         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3227         .tokens = {
3228                 (void *)&cmd_showport_reta_show,
3229                 (void *)&cmd_showport_reta_port,
3230                 (void *)&cmd_showport_reta_port_id,
3231                 (void *)&cmd_showport_reta_rss,
3232                 (void *)&cmd_showport_reta_reta,
3233                 (void *)&cmd_showport_reta_size,
3234                 (void *)&cmd_showport_reta_list_of_items,
3235                 NULL,
3236         },
3237 };
3238
3239 /* *** Show RSS hash configuration *** */
3240 struct cmd_showport_rss_hash {
3241         cmdline_fixed_string_t show;
3242         cmdline_fixed_string_t port;
3243         portid_t port_id;
3244         cmdline_fixed_string_t rss_hash;
3245         cmdline_fixed_string_t rss_type;
3246         cmdline_fixed_string_t key; /* optional argument */
3247 };
3248
3249 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3250                                 __rte_unused struct cmdline *cl,
3251                                 void *show_rss_key)
3252 {
3253         struct cmd_showport_rss_hash *res = parsed_result;
3254
3255         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3256 }
3257
3258 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3259         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3260 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3261         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3262 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3263         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3264 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3265         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3266                                  "rss-hash");
3267 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3268         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3269
3270 cmdline_parse_inst_t cmd_showport_rss_hash = {
3271         .f = cmd_showport_rss_hash_parsed,
3272         .data = NULL,
3273         .help_str = "show port <port_id> rss-hash",
3274         .tokens = {
3275                 (void *)&cmd_showport_rss_hash_show,
3276                 (void *)&cmd_showport_rss_hash_port,
3277                 (void *)&cmd_showport_rss_hash_port_id,
3278                 (void *)&cmd_showport_rss_hash_rss_hash,
3279                 NULL,
3280         },
3281 };
3282
3283 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3284         .f = cmd_showport_rss_hash_parsed,
3285         .data = (void *)1,
3286         .help_str = "show port <port_id> rss-hash key",
3287         .tokens = {
3288                 (void *)&cmd_showport_rss_hash_show,
3289                 (void *)&cmd_showport_rss_hash_port,
3290                 (void *)&cmd_showport_rss_hash_port_id,
3291                 (void *)&cmd_showport_rss_hash_rss_hash,
3292                 (void *)&cmd_showport_rss_hash_rss_key,
3293                 NULL,
3294         },
3295 };
3296
3297 /* *** Configure DCB *** */
3298 struct cmd_config_dcb {
3299         cmdline_fixed_string_t port;
3300         cmdline_fixed_string_t config;
3301         portid_t port_id;
3302         cmdline_fixed_string_t dcb;
3303         cmdline_fixed_string_t vt;
3304         cmdline_fixed_string_t vt_en;
3305         uint8_t num_tcs;
3306         cmdline_fixed_string_t pfc;
3307         cmdline_fixed_string_t pfc_en;
3308 };
3309
3310 static void
3311 cmd_config_dcb_parsed(void *parsed_result,
3312                         __rte_unused struct cmdline *cl,
3313                         __rte_unused void *data)
3314 {
3315         struct cmd_config_dcb *res = parsed_result;
3316         portid_t port_id = res->port_id;
3317         struct rte_port *port;
3318         uint8_t pfc_en;
3319         int ret;
3320
3321         port = &ports[port_id];
3322         /** Check if the port is not started **/
3323         if (port->port_status != RTE_PORT_STOPPED) {
3324                 printf("Please stop port %d first\n", port_id);
3325                 return;
3326         }
3327
3328         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3329                 printf("The invalid number of traffic class,"
3330                         " only 4 or 8 allowed.\n");
3331                 return;
3332         }
3333
3334         if (nb_fwd_lcores < res->num_tcs) {
3335                 printf("nb_cores shouldn't be less than number of TCs.\n");
3336                 return;
3337         }
3338         if (!strncmp(res->pfc_en, "on", 2))
3339                 pfc_en = 1;
3340         else
3341                 pfc_en = 0;
3342
3343         /* DCB in VT mode */
3344         if (!strncmp(res->vt_en, "on", 2))
3345                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3346                                 (enum rte_eth_nb_tcs)res->num_tcs,
3347                                 pfc_en);
3348         else
3349                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3350                                 (enum rte_eth_nb_tcs)res->num_tcs,
3351                                 pfc_en);
3352
3353
3354         if (ret != 0) {
3355                 printf("Cannot initialize network ports.\n");
3356                 return;
3357         }
3358
3359         cmd_reconfig_device_queue(port_id, 1, 1);
3360 }
3361
3362 cmdline_parse_token_string_t cmd_config_dcb_port =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3364 cmdline_parse_token_string_t cmd_config_dcb_config =
3365         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3366 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3367         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3368 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3369         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3370 cmdline_parse_token_string_t cmd_config_dcb_vt =
3371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3372 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3373         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3374 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3375         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3376 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3377         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3378 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3379         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3380
3381 cmdline_parse_inst_t cmd_config_dcb = {
3382         .f = cmd_config_dcb_parsed,
3383         .data = NULL,
3384         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3385         .tokens = {
3386                 (void *)&cmd_config_dcb_port,
3387                 (void *)&cmd_config_dcb_config,
3388                 (void *)&cmd_config_dcb_port_id,
3389                 (void *)&cmd_config_dcb_dcb,
3390                 (void *)&cmd_config_dcb_vt,
3391                 (void *)&cmd_config_dcb_vt_en,
3392                 (void *)&cmd_config_dcb_num_tcs,
3393                 (void *)&cmd_config_dcb_pfc,
3394                 (void *)&cmd_config_dcb_pfc_en,
3395                 NULL,
3396         },
3397 };
3398
3399 /* *** configure number of packets per burst *** */
3400 struct cmd_config_burst {
3401         cmdline_fixed_string_t port;
3402         cmdline_fixed_string_t keyword;
3403         cmdline_fixed_string_t all;
3404         cmdline_fixed_string_t name;
3405         uint16_t value;
3406 };
3407
3408 static void
3409 cmd_config_burst_parsed(void *parsed_result,
3410                         __rte_unused struct cmdline *cl,
3411                         __rte_unused void *data)
3412 {
3413         struct cmd_config_burst *res = parsed_result;
3414         struct rte_eth_dev_info dev_info;
3415         uint16_t rec_nb_pkts;
3416         int ret;
3417
3418         if (!all_ports_stopped()) {
3419                 printf("Please stop all ports first\n");
3420                 return;
3421         }
3422
3423         if (!strcmp(res->name, "burst")) {
3424                 if (res->value == 0) {
3425                         /* If user gives a value of zero, query the PMD for
3426                          * its recommended Rx burst size. Testpmd uses a single
3427                          * size for all ports, so assume all ports are the same
3428                          * NIC model and use the values from Port 0.
3429                          */
3430                         ret = eth_dev_info_get_print_err(0, &dev_info);
3431                         if (ret != 0)
3432                                 return;
3433
3434                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3435
3436                         if (rec_nb_pkts == 0) {
3437                                 printf("PMD does not recommend a burst size.\n"
3438                                         "User provided value must be between"
3439                                         " 1 and %d\n", MAX_PKT_BURST);
3440                                 return;
3441                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3442                                 printf("PMD recommended burst size of %d"
3443                                         " exceeds maximum value of %d\n",
3444                                         rec_nb_pkts, MAX_PKT_BURST);
3445                                 return;
3446                         }
3447                         printf("Using PMD-provided burst value of %d\n",
3448                                 rec_nb_pkts);
3449                         nb_pkt_per_burst = rec_nb_pkts;
3450                 } else if (res->value > MAX_PKT_BURST) {
3451                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3452                         return;
3453                 } else
3454                         nb_pkt_per_burst = res->value;
3455         } else {
3456                 printf("Unknown parameter\n");
3457                 return;
3458         }
3459
3460         init_port_config();
3461
3462         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3463 }
3464
3465 cmdline_parse_token_string_t cmd_config_burst_port =
3466         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3467 cmdline_parse_token_string_t cmd_config_burst_keyword =
3468         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3469 cmdline_parse_token_string_t cmd_config_burst_all =
3470         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3471 cmdline_parse_token_string_t cmd_config_burst_name =
3472         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3473 cmdline_parse_token_num_t cmd_config_burst_value =
3474         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3475
3476 cmdline_parse_inst_t cmd_config_burst = {
3477         .f = cmd_config_burst_parsed,
3478         .data = NULL,
3479         .help_str = "port config all burst <value>",
3480         .tokens = {
3481                 (void *)&cmd_config_burst_port,
3482                 (void *)&cmd_config_burst_keyword,
3483                 (void *)&cmd_config_burst_all,
3484                 (void *)&cmd_config_burst_name,
3485                 (void *)&cmd_config_burst_value,
3486                 NULL,
3487         },
3488 };
3489
3490 /* *** configure rx/tx queues *** */
3491 struct cmd_config_thresh {
3492         cmdline_fixed_string_t port;
3493         cmdline_fixed_string_t keyword;
3494         cmdline_fixed_string_t all;
3495         cmdline_fixed_string_t name;
3496         uint8_t value;
3497 };
3498
3499 static void
3500 cmd_config_thresh_parsed(void *parsed_result,
3501                         __rte_unused struct cmdline *cl,
3502                         __rte_unused void *data)
3503 {
3504         struct cmd_config_thresh *res = parsed_result;
3505
3506         if (!all_ports_stopped()) {
3507                 printf("Please stop all ports first\n");
3508                 return;
3509         }
3510
3511         if (!strcmp(res->name, "txpt"))
3512                 tx_pthresh = res->value;
3513         else if(!strcmp(res->name, "txht"))
3514                 tx_hthresh = res->value;
3515         else if(!strcmp(res->name, "txwt"))
3516                 tx_wthresh = res->value;
3517         else if(!strcmp(res->name, "rxpt"))
3518                 rx_pthresh = res->value;
3519         else if(!strcmp(res->name, "rxht"))
3520                 rx_hthresh = res->value;
3521         else if(!strcmp(res->name, "rxwt"))
3522                 rx_wthresh = res->value;
3523         else {
3524                 printf("Unknown parameter\n");
3525                 return;
3526         }
3527
3528         init_port_config();
3529
3530         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3531 }
3532
3533 cmdline_parse_token_string_t cmd_config_thresh_port =
3534         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3535 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3536         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3537 cmdline_parse_token_string_t cmd_config_thresh_all =
3538         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3539 cmdline_parse_token_string_t cmd_config_thresh_name =
3540         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3541                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3542 cmdline_parse_token_num_t cmd_config_thresh_value =
3543         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3544
3545 cmdline_parse_inst_t cmd_config_thresh = {
3546         .f = cmd_config_thresh_parsed,
3547         .data = NULL,
3548         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3549         .tokens = {
3550                 (void *)&cmd_config_thresh_port,
3551                 (void *)&cmd_config_thresh_keyword,
3552                 (void *)&cmd_config_thresh_all,
3553                 (void *)&cmd_config_thresh_name,
3554                 (void *)&cmd_config_thresh_value,
3555                 NULL,
3556         },
3557 };
3558
3559 /* *** configure free/rs threshold *** */
3560 struct cmd_config_threshold {
3561         cmdline_fixed_string_t port;
3562         cmdline_fixed_string_t keyword;
3563         cmdline_fixed_string_t all;
3564         cmdline_fixed_string_t name;
3565         uint16_t value;
3566 };
3567
3568 static void
3569 cmd_config_threshold_parsed(void *parsed_result,
3570                         __rte_unused struct cmdline *cl,
3571                         __rte_unused void *data)
3572 {
3573         struct cmd_config_threshold *res = parsed_result;
3574
3575         if (!all_ports_stopped()) {
3576                 printf("Please stop all ports first\n");
3577                 return;
3578         }
3579
3580         if (!strcmp(res->name, "txfreet"))
3581                 tx_free_thresh = res->value;
3582         else if (!strcmp(res->name, "txrst"))
3583                 tx_rs_thresh = res->value;
3584         else if (!strcmp(res->name, "rxfreet"))
3585                 rx_free_thresh = res->value;
3586         else {
3587                 printf("Unknown parameter\n");
3588                 return;
3589         }
3590
3591         init_port_config();
3592
3593         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3594 }
3595
3596 cmdline_parse_token_string_t cmd_config_threshold_port =
3597         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3598 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3599         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3600                                                                 "config");
3601 cmdline_parse_token_string_t cmd_config_threshold_all =
3602         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3603 cmdline_parse_token_string_t cmd_config_threshold_name =
3604         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3605                                                 "txfreet#txrst#rxfreet");
3606 cmdline_parse_token_num_t cmd_config_threshold_value =
3607         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3608
3609 cmdline_parse_inst_t cmd_config_threshold = {
3610         .f = cmd_config_threshold_parsed,
3611         .data = NULL,
3612         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3613         .tokens = {
3614                 (void *)&cmd_config_threshold_port,
3615                 (void *)&cmd_config_threshold_keyword,
3616                 (void *)&cmd_config_threshold_all,
3617                 (void *)&cmd_config_threshold_name,
3618                 (void *)&cmd_config_threshold_value,
3619                 NULL,
3620         },
3621 };
3622
3623 /* *** stop *** */
3624 struct cmd_stop_result {
3625         cmdline_fixed_string_t stop;
3626 };
3627
3628 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3629                             __rte_unused struct cmdline *cl,
3630                             __rte_unused void *data)
3631 {
3632         stop_packet_forwarding();
3633 }
3634
3635 cmdline_parse_token_string_t cmd_stop_stop =
3636         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3637
3638 cmdline_parse_inst_t cmd_stop = {
3639         .f = cmd_stop_parsed,
3640         .data = NULL,
3641         .help_str = "stop: Stop packet forwarding",
3642         .tokens = {
3643                 (void *)&cmd_stop_stop,
3644                 NULL,
3645         },
3646 };
3647
3648 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3649
3650 unsigned int
3651 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3652                 unsigned int *parsed_items, int check_unique_values)
3653 {
3654         unsigned int nb_item;
3655         unsigned int value;
3656         unsigned int i;
3657         unsigned int j;
3658         int value_ok;
3659         char c;
3660
3661         /*
3662          * First parse all items in the list and store their value.
3663          */
3664         value = 0;
3665         nb_item = 0;
3666         value_ok = 0;
3667         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3668                 c = str[i];
3669                 if ((c >= '0') && (c <= '9')) {
3670                         value = (unsigned int) (value * 10 + (c - '0'));
3671                         value_ok = 1;
3672                         continue;
3673                 }
3674                 if (c != ',') {
3675                         printf("character %c is not a decimal digit\n", c);
3676                         return 0;
3677                 }
3678                 if (! value_ok) {
3679                         printf("No valid value before comma\n");
3680                         return 0;
3681                 }
3682                 if (nb_item < max_items) {
3683                         parsed_items[nb_item] = value;
3684                         value_ok = 0;
3685                         value = 0;
3686                 }
3687                 nb_item++;
3688         }
3689         if (nb_item >= max_items) {
3690                 printf("Number of %s = %u > %u (maximum items)\n",
3691                        item_name, nb_item + 1, max_items);
3692                 return 0;
3693         }
3694         parsed_items[nb_item++] = value;
3695         if (! check_unique_values)
3696                 return nb_item;
3697
3698         /*
3699          * Then, check that all values in the list are differents.
3700          * No optimization here...
3701          */
3702         for (i = 0; i < nb_item; i++) {
3703                 for (j = i + 1; j < nb_item; j++) {
3704                         if (parsed_items[j] == parsed_items[i]) {
3705                                 printf("duplicated %s %u at index %u and %u\n",
3706                                        item_name, parsed_items[i], i, j);
3707                                 return 0;
3708                         }
3709                 }
3710         }
3711         return nb_item;
3712 }
3713
3714 struct cmd_set_list_result {
3715         cmdline_fixed_string_t cmd_keyword;
3716         cmdline_fixed_string_t list_name;
3717         cmdline_fixed_string_t list_of_items;
3718 };
3719
3720 static void cmd_set_list_parsed(void *parsed_result,
3721                                 __rte_unused struct cmdline *cl,
3722                                 __rte_unused void *data)
3723 {
3724         struct cmd_set_list_result *res;
3725         union {
3726                 unsigned int lcorelist[RTE_MAX_LCORE];
3727                 unsigned int portlist[RTE_MAX_ETHPORTS];
3728         } parsed_items;
3729         unsigned int nb_item;
3730
3731         if (test_done == 0) {
3732                 printf("Please stop forwarding first\n");
3733                 return;
3734         }
3735
3736         res = parsed_result;
3737         if (!strcmp(res->list_name, "corelist")) {
3738                 nb_item = parse_item_list(res->list_of_items, "core",
3739                                           RTE_MAX_LCORE,
3740                                           parsed_items.lcorelist, 1);
3741                 if (nb_item > 0) {
3742                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3743                         fwd_config_setup();
3744                 }
3745                 return;
3746         }
3747         if (!strcmp(res->list_name, "portlist")) {
3748                 nb_item = parse_item_list(res->list_of_items, "port",
3749                                           RTE_MAX_ETHPORTS,
3750                                           parsed_items.portlist, 1);
3751                 if (nb_item > 0) {
3752                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3753                         fwd_config_setup();
3754                 }
3755         }
3756 }
3757
3758 cmdline_parse_token_string_t cmd_set_list_keyword =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3760                                  "set");
3761 cmdline_parse_token_string_t cmd_set_list_name =
3762         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3763                                  "corelist#portlist");
3764 cmdline_parse_token_string_t cmd_set_list_of_items =
3765         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3766                                  NULL);
3767
3768 cmdline_parse_inst_t cmd_set_fwd_list = {
3769         .f = cmd_set_list_parsed,
3770         .data = NULL,
3771         .help_str = "set corelist|portlist <list0[,list1]*>",
3772         .tokens = {
3773                 (void *)&cmd_set_list_keyword,
3774                 (void *)&cmd_set_list_name,
3775                 (void *)&cmd_set_list_of_items,
3776                 NULL,
3777         },
3778 };
3779
3780 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3781
3782 struct cmd_setmask_result {
3783         cmdline_fixed_string_t set;
3784         cmdline_fixed_string_t mask;
3785         uint64_t hexavalue;
3786 };
3787
3788 static void cmd_set_mask_parsed(void *parsed_result,
3789                                 __rte_unused struct cmdline *cl,
3790                                 __rte_unused void *data)
3791 {
3792         struct cmd_setmask_result *res = parsed_result;
3793
3794         if (test_done == 0) {
3795                 printf("Please stop forwarding first\n");
3796                 return;
3797         }
3798         if (!strcmp(res->mask, "coremask")) {
3799                 set_fwd_lcores_mask(res->hexavalue);
3800                 fwd_config_setup();
3801         } else if (!strcmp(res->mask, "portmask")) {
3802                 set_fwd_ports_mask(res->hexavalue);
3803                 fwd_config_setup();
3804         }
3805 }
3806
3807 cmdline_parse_token_string_t cmd_setmask_set =
3808         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3809 cmdline_parse_token_string_t cmd_setmask_mask =
3810         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3811                                  "coremask#portmask");
3812 cmdline_parse_token_num_t cmd_setmask_value =
3813         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3814
3815 cmdline_parse_inst_t cmd_set_fwd_mask = {
3816         .f = cmd_set_mask_parsed,
3817         .data = NULL,
3818         .help_str = "set coremask|portmask <hexadecimal value>",
3819         .tokens = {
3820                 (void *)&cmd_setmask_set,
3821                 (void *)&cmd_setmask_mask,
3822                 (void *)&cmd_setmask_value,
3823                 NULL,
3824         },
3825 };
3826
3827 /*
3828  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3829  */
3830 struct cmd_set_result {
3831         cmdline_fixed_string_t set;
3832         cmdline_fixed_string_t what;
3833         uint16_t value;
3834 };
3835
3836 static void cmd_set_parsed(void *parsed_result,
3837                            __rte_unused struct cmdline *cl,
3838                            __rte_unused void *data)
3839 {
3840         struct cmd_set_result *res = parsed_result;
3841         if (!strcmp(res->what, "nbport")) {
3842                 set_fwd_ports_number(res->value);
3843                 fwd_config_setup();
3844         } else if (!strcmp(res->what, "nbcore")) {
3845                 set_fwd_lcores_number(res->value);
3846                 fwd_config_setup();
3847         } else if (!strcmp(res->what, "burst"))
3848                 set_nb_pkt_per_burst(res->value);
3849         else if (!strcmp(res->what, "verbose"))
3850                 set_verbose_level(res->value);
3851 }
3852
3853 cmdline_parse_token_string_t cmd_set_set =
3854         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3855 cmdline_parse_token_string_t cmd_set_what =
3856         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3857                                  "nbport#nbcore#burst#verbose");
3858 cmdline_parse_token_num_t cmd_set_value =
3859         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3860
3861 cmdline_parse_inst_t cmd_set_numbers = {
3862         .f = cmd_set_parsed,
3863         .data = NULL,
3864         .help_str = "set nbport|nbcore|burst|verbose <value>",
3865         .tokens = {
3866                 (void *)&cmd_set_set,
3867                 (void *)&cmd_set_what,
3868                 (void *)&cmd_set_value,
3869                 NULL,
3870         },
3871 };
3872
3873 /* *** SET LOG LEVEL CONFIGURATION *** */
3874
3875 struct cmd_set_log_result {
3876         cmdline_fixed_string_t set;
3877         cmdline_fixed_string_t log;
3878         cmdline_fixed_string_t type;
3879         uint32_t level;
3880 };
3881
3882 static void
3883 cmd_set_log_parsed(void *parsed_result,
3884                    __rte_unused struct cmdline *cl,
3885                    __rte_unused void *data)
3886 {
3887         struct cmd_set_log_result *res;
3888         int ret;
3889
3890         res = parsed_result;
3891         if (!strcmp(res->type, "global"))
3892                 rte_log_set_global_level(res->level);
3893         else {
3894                 ret = rte_log_set_level_regexp(res->type, res->level);
3895                 if (ret < 0)
3896                         printf("Unable to set log level\n");
3897         }
3898 }
3899
3900 cmdline_parse_token_string_t cmd_set_log_set =
3901         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3902 cmdline_parse_token_string_t cmd_set_log_log =
3903         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3904 cmdline_parse_token_string_t cmd_set_log_type =
3905         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3906 cmdline_parse_token_num_t cmd_set_log_level =
3907         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3908
3909 cmdline_parse_inst_t cmd_set_log = {
3910         .f = cmd_set_log_parsed,
3911         .data = NULL,
3912         .help_str = "set log global|<type> <level>",
3913         .tokens = {
3914                 (void *)&cmd_set_log_set,
3915                 (void *)&cmd_set_log_log,
3916                 (void *)&cmd_set_log_type,
3917                 (void *)&cmd_set_log_level,
3918                 NULL,
3919         },
3920 };
3921
3922 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3923
3924 struct cmd_set_rxoffs_result {
3925         cmdline_fixed_string_t cmd_keyword;
3926         cmdline_fixed_string_t rxoffs;
3927         cmdline_fixed_string_t seg_offsets;
3928 };
3929
3930 static void
3931 cmd_set_rxoffs_parsed(void *parsed_result,
3932                       __rte_unused struct cmdline *cl,
3933                       __rte_unused void *data)
3934 {
3935         struct cmd_set_rxoffs_result *res;
3936         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3937         unsigned int nb_segs;
3938
3939         res = parsed_result;
3940         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3941                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3942         if (nb_segs > 0)
3943                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3944 }
3945
3946 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3947         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3948                                  cmd_keyword, "set");
3949 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3950         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3951                                  rxoffs, "rxoffs");
3952 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3953         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3954                                  seg_offsets, NULL);
3955
3956 cmdline_parse_inst_t cmd_set_rxoffs = {
3957         .f = cmd_set_rxoffs_parsed,
3958         .data = NULL,
3959         .help_str = "set rxoffs <len0[,len1]*>",
3960         .tokens = {
3961                 (void *)&cmd_set_rxoffs_keyword,
3962                 (void *)&cmd_set_rxoffs_name,
3963                 (void *)&cmd_set_rxoffs_offsets,
3964                 NULL,
3965         },
3966 };
3967
3968 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3969
3970 struct cmd_set_rxpkts_result {
3971         cmdline_fixed_string_t cmd_keyword;
3972         cmdline_fixed_string_t rxpkts;
3973         cmdline_fixed_string_t seg_lengths;
3974 };
3975
3976 static void
3977 cmd_set_rxpkts_parsed(void *parsed_result,
3978                       __rte_unused struct cmdline *cl,
3979                       __rte_unused void *data)
3980 {
3981         struct cmd_set_rxpkts_result *res;
3982         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3983         unsigned int nb_segs;
3984
3985         res = parsed_result;
3986         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3987                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3988         if (nb_segs > 0)
3989                 set_rx_pkt_segments(seg_lengths, nb_segs);
3990 }
3991
3992 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3993         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3994                                  cmd_keyword, "set");
3995 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3996         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3997                                  rxpkts, "rxpkts");
3998 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3999         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
4000                                  seg_lengths, NULL);
4001
4002 cmdline_parse_inst_t cmd_set_rxpkts = {
4003         .f = cmd_set_rxpkts_parsed,
4004         .data = NULL,
4005         .help_str = "set rxpkts <len0[,len1]*>",
4006         .tokens = {
4007                 (void *)&cmd_set_rxpkts_keyword,
4008                 (void *)&cmd_set_rxpkts_name,
4009                 (void *)&cmd_set_rxpkts_lengths,
4010                 NULL,
4011         },
4012 };
4013
4014 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
4015
4016 struct cmd_set_txpkts_result {
4017         cmdline_fixed_string_t cmd_keyword;
4018         cmdline_fixed_string_t txpkts;
4019         cmdline_fixed_string_t seg_lengths;
4020 };
4021
4022 static void
4023 cmd_set_txpkts_parsed(void *parsed_result,
4024                       __rte_unused struct cmdline *cl,
4025                       __rte_unused void *data)
4026 {
4027         struct cmd_set_txpkts_result *res;
4028         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
4029         unsigned int nb_segs;
4030
4031         res = parsed_result;
4032         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
4033                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
4034         if (nb_segs > 0)
4035                 set_tx_pkt_segments(seg_lengths, nb_segs);
4036 }
4037
4038 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
4039         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4040                                  cmd_keyword, "set");
4041 cmdline_parse_token_string_t cmd_set_txpkts_name =
4042         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4043                                  txpkts, "txpkts");
4044 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
4045         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
4046                                  seg_lengths, NULL);
4047
4048 cmdline_parse_inst_t cmd_set_txpkts = {
4049         .f = cmd_set_txpkts_parsed,
4050         .data = NULL,
4051         .help_str = "set txpkts <len0[,len1]*>",
4052         .tokens = {
4053                 (void *)&cmd_set_txpkts_keyword,
4054                 (void *)&cmd_set_txpkts_name,
4055                 (void *)&cmd_set_txpkts_lengths,
4056                 NULL,
4057         },
4058 };
4059
4060 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4061
4062 struct cmd_set_txsplit_result {
4063         cmdline_fixed_string_t cmd_keyword;
4064         cmdline_fixed_string_t txsplit;
4065         cmdline_fixed_string_t mode;
4066 };
4067
4068 static void
4069 cmd_set_txsplit_parsed(void *parsed_result,
4070                       __rte_unused struct cmdline *cl,
4071                       __rte_unused void *data)
4072 {
4073         struct cmd_set_txsplit_result *res;
4074
4075         res = parsed_result;
4076         set_tx_pkt_split(res->mode);
4077 }
4078
4079 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4080         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4081                                  cmd_keyword, "set");
4082 cmdline_parse_token_string_t cmd_set_txsplit_name =
4083         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4084                                  txsplit, "txsplit");
4085 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4086         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4087                                  mode, NULL);
4088
4089 cmdline_parse_inst_t cmd_set_txsplit = {
4090         .f = cmd_set_txsplit_parsed,
4091         .data = NULL,
4092         .help_str = "set txsplit on|off|rand",
4093         .tokens = {
4094                 (void *)&cmd_set_txsplit_keyword,
4095                 (void *)&cmd_set_txsplit_name,
4096                 (void *)&cmd_set_txsplit_mode,
4097                 NULL,
4098         },
4099 };
4100
4101 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4102
4103 struct cmd_set_txtimes_result {
4104         cmdline_fixed_string_t cmd_keyword;
4105         cmdline_fixed_string_t txtimes;
4106         cmdline_fixed_string_t tx_times;
4107 };
4108
4109 static void
4110 cmd_set_txtimes_parsed(void *parsed_result,
4111                        __rte_unused struct cmdline *cl,
4112                        __rte_unused void *data)
4113 {
4114         struct cmd_set_txtimes_result *res;
4115         unsigned int tx_times[2] = {0, 0};
4116         unsigned int n_times;
4117
4118         res = parsed_result;
4119         n_times = parse_item_list(res->tx_times, "tx times",
4120                                   2, tx_times, 0);
4121         if (n_times == 2)
4122                 set_tx_pkt_times(tx_times);
4123 }
4124
4125 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4126         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4127                                  cmd_keyword, "set");
4128 cmdline_parse_token_string_t cmd_set_txtimes_name =
4129         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4130                                  txtimes, "txtimes");
4131 cmdline_parse_token_string_t cmd_set_txtimes_value =
4132         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4133                                  tx_times, NULL);
4134
4135 cmdline_parse_inst_t cmd_set_txtimes = {
4136         .f = cmd_set_txtimes_parsed,
4137         .data = NULL,
4138         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4139         .tokens = {
4140                 (void *)&cmd_set_txtimes_keyword,
4141                 (void *)&cmd_set_txtimes_name,
4142                 (void *)&cmd_set_txtimes_value,
4143                 NULL,
4144         },
4145 };
4146
4147 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4148 struct cmd_rx_vlan_filter_all_result {
4149         cmdline_fixed_string_t rx_vlan;
4150         cmdline_fixed_string_t what;
4151         cmdline_fixed_string_t all;
4152         portid_t port_id;
4153 };
4154
4155 static void
4156 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4157                               __rte_unused struct cmdline *cl,
4158                               __rte_unused void *data)
4159 {
4160         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4161
4162         if (!strcmp(res->what, "add"))
4163                 rx_vlan_all_filter_set(res->port_id, 1);
4164         else
4165                 rx_vlan_all_filter_set(res->port_id, 0);
4166 }
4167
4168 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4169         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4170                                  rx_vlan, "rx_vlan");
4171 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4172         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4173                                  what, "add#rm");
4174 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4175         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4176                                  all, "all");
4177 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4178         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4179                               port_id, UINT16);
4180
4181 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4182         .f = cmd_rx_vlan_filter_all_parsed,
4183         .data = NULL,
4184         .help_str = "rx_vlan add|rm all <port_id>: "
4185                 "Add/Remove all identifiers to/from the set of VLAN "
4186                 "identifiers filtered by a port",
4187         .tokens = {
4188                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4189                 (void *)&cmd_rx_vlan_filter_all_what,
4190                 (void *)&cmd_rx_vlan_filter_all_all,
4191                 (void *)&cmd_rx_vlan_filter_all_portid,
4192                 NULL,
4193         },
4194 };
4195
4196 /* *** VLAN OFFLOAD SET ON A PORT *** */
4197 struct cmd_vlan_offload_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         cmdline_fixed_string_t on;
4203         cmdline_fixed_string_t port_id;
4204 };
4205
4206 static void
4207 cmd_vlan_offload_parsed(void *parsed_result,
4208                           __rte_unused struct cmdline *cl,
4209                           __rte_unused void *data)
4210 {
4211         int on;
4212         struct cmd_vlan_offload_result *res = parsed_result;
4213         char *str;
4214         int i, len = 0;
4215         portid_t port_id = 0;
4216         unsigned int tmp;
4217
4218         str = res->port_id;
4219         len = strnlen(str, STR_TOKEN_SIZE);
4220         i = 0;
4221         /* Get port_id first */
4222         while(i < len){
4223                 if(str[i] == ',')
4224                         break;
4225
4226                 i++;
4227         }
4228         str[i]='\0';
4229         tmp = strtoul(str, NULL, 0);
4230         /* If port_id greater that what portid_t can represent, return */
4231         if(tmp >= RTE_MAX_ETHPORTS)
4232                 return;
4233         port_id = (portid_t)tmp;
4234
4235         if (!strcmp(res->on, "on"))
4236                 on = 1;
4237         else
4238                 on = 0;
4239
4240         if (!strcmp(res->what, "strip"))
4241                 rx_vlan_strip_set(port_id,  on);
4242         else if(!strcmp(res->what, "stripq")){
4243                 uint16_t queue_id = 0;
4244
4245                 /* No queue_id, return */
4246                 if(i + 1 >= len) {
4247                         printf("must specify (port,queue_id)\n");
4248                         return;
4249                 }
4250                 tmp = strtoul(str + i + 1, NULL, 0);
4251                 /* If queue_id greater that what 16-bits can represent, return */
4252                 if(tmp > 0xffff)
4253                         return;
4254
4255                 queue_id = (uint16_t)tmp;
4256                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4257         }
4258         else if (!strcmp(res->what, "filter"))
4259                 rx_vlan_filter_set(port_id, on);
4260         else if (!strcmp(res->what, "qinq_strip"))
4261                 rx_vlan_qinq_strip_set(port_id, on);
4262         else
4263                 vlan_extend_set(port_id, on);
4264
4265         return;
4266 }
4267
4268 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4269         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4270                                  vlan, "vlan");
4271 cmdline_parse_token_string_t cmd_vlan_offload_set =
4272         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4273                                  set, "set");
4274 cmdline_parse_token_string_t cmd_vlan_offload_what =
4275         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4276                                 what, "strip#filter#qinq_strip#extend#stripq");
4277 cmdline_parse_token_string_t cmd_vlan_offload_on =
4278         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4279                               on, "on#off");
4280 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4281         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4282                               port_id, NULL);
4283
4284 cmdline_parse_inst_t cmd_vlan_offload = {
4285         .f = cmd_vlan_offload_parsed,
4286         .data = NULL,
4287         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4288                 "<port_id[,queue_id]>: "
4289                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4290         .tokens = {
4291                 (void *)&cmd_vlan_offload_vlan,
4292                 (void *)&cmd_vlan_offload_set,
4293                 (void *)&cmd_vlan_offload_what,
4294                 (void *)&cmd_vlan_offload_on,
4295                 (void *)&cmd_vlan_offload_portid,
4296                 NULL,
4297         },
4298 };
4299
4300 /* *** VLAN TPID SET ON A PORT *** */
4301 struct cmd_vlan_tpid_result {
4302         cmdline_fixed_string_t vlan;
4303         cmdline_fixed_string_t set;
4304         cmdline_fixed_string_t vlan_type;
4305         cmdline_fixed_string_t what;
4306         uint16_t tp_id;
4307         portid_t port_id;
4308 };
4309
4310 static void
4311 cmd_vlan_tpid_parsed(void *parsed_result,
4312                           __rte_unused struct cmdline *cl,
4313                           __rte_unused void *data)
4314 {
4315         struct cmd_vlan_tpid_result *res = parsed_result;
4316         enum rte_vlan_type vlan_type;
4317
4318         if (!strcmp(res->vlan_type, "inner"))
4319                 vlan_type = ETH_VLAN_TYPE_INNER;
4320         else if (!strcmp(res->vlan_type, "outer"))
4321                 vlan_type = ETH_VLAN_TYPE_OUTER;
4322         else {
4323                 printf("Unknown vlan type\n");
4324                 return;
4325         }
4326         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4327 }
4328
4329 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4330         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4331                                  vlan, "vlan");
4332 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4333         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4334                                  set, "set");
4335 cmdline_parse_token_string_t cmd_vlan_type =
4336         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4337                                  vlan_type, "inner#outer");
4338 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4339         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4340                                  what, "tpid");
4341 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4342         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4343                               tp_id, UINT16);
4344 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4345         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4346                               port_id, UINT16);
4347
4348 cmdline_parse_inst_t cmd_vlan_tpid = {
4349         .f = cmd_vlan_tpid_parsed,
4350         .data = NULL,
4351         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4352                 "Set the VLAN Ether type",
4353         .tokens = {
4354                 (void *)&cmd_vlan_tpid_vlan,
4355                 (void *)&cmd_vlan_tpid_set,
4356                 (void *)&cmd_vlan_type,
4357                 (void *)&cmd_vlan_tpid_what,
4358                 (void *)&cmd_vlan_tpid_tpid,
4359                 (void *)&cmd_vlan_tpid_portid,
4360                 NULL,
4361         },
4362 };
4363
4364 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4365 struct cmd_rx_vlan_filter_result {
4366         cmdline_fixed_string_t rx_vlan;
4367         cmdline_fixed_string_t what;
4368         uint16_t vlan_id;
4369         portid_t port_id;
4370 };
4371
4372 static void
4373 cmd_rx_vlan_filter_parsed(void *parsed_result,
4374                           __rte_unused struct cmdline *cl,
4375                           __rte_unused void *data)
4376 {
4377         struct cmd_rx_vlan_filter_result *res = parsed_result;
4378
4379         if (!strcmp(res->what, "add"))
4380                 rx_vft_set(res->port_id, res->vlan_id, 1);
4381         else
4382                 rx_vft_set(res->port_id, res->vlan_id, 0);
4383 }
4384
4385 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4386         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4387                                  rx_vlan, "rx_vlan");
4388 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4389         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4390                                  what, "add#rm");
4391 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4392         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4393                               vlan_id, UINT16);
4394 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4395         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4396                               port_id, UINT16);
4397
4398 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4399         .f = cmd_rx_vlan_filter_parsed,
4400         .data = NULL,
4401         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4402                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4403                 "identifiers filtered by a port",
4404         .tokens = {
4405                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4406                 (void *)&cmd_rx_vlan_filter_what,
4407                 (void *)&cmd_rx_vlan_filter_vlanid,
4408                 (void *)&cmd_rx_vlan_filter_portid,
4409                 NULL,
4410         },
4411 };
4412
4413 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4414 struct cmd_tx_vlan_set_result {
4415         cmdline_fixed_string_t tx_vlan;
4416         cmdline_fixed_string_t set;
4417         portid_t port_id;
4418         uint16_t vlan_id;
4419 };
4420
4421 static void
4422 cmd_tx_vlan_set_parsed(void *parsed_result,
4423                        __rte_unused struct cmdline *cl,
4424                        __rte_unused void *data)
4425 {
4426         struct cmd_tx_vlan_set_result *res = parsed_result;
4427
4428         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4429                 return;
4430
4431         if (!port_is_stopped(res->port_id)) {
4432                 printf("Please stop port %d first\n", res->port_id);
4433                 return;
4434         }
4435
4436         tx_vlan_set(res->port_id, res->vlan_id);
4437
4438         cmd_reconfig_device_queue(res->port_id, 1, 1);
4439 }
4440
4441 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4442         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4443                                  tx_vlan, "tx_vlan");
4444 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4445         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4446                                  set, "set");
4447 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4448         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4449                               port_id, UINT16);
4450 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4451         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4452                               vlan_id, UINT16);
4453
4454 cmdline_parse_inst_t cmd_tx_vlan_set = {
4455         .f = cmd_tx_vlan_set_parsed,
4456         .data = NULL,
4457         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4458                 "Enable hardware insertion of a single VLAN header "
4459                 "with a given TAG Identifier in packets sent on a port",
4460         .tokens = {
4461                 (void *)&cmd_tx_vlan_set_tx_vlan,
4462                 (void *)&cmd_tx_vlan_set_set,
4463                 (void *)&cmd_tx_vlan_set_portid,
4464                 (void *)&cmd_tx_vlan_set_vlanid,
4465                 NULL,
4466         },
4467 };
4468
4469 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4470 struct cmd_tx_vlan_set_qinq_result {
4471         cmdline_fixed_string_t tx_vlan;
4472         cmdline_fixed_string_t set;
4473         portid_t port_id;
4474         uint16_t vlan_id;
4475         uint16_t vlan_id_outer;
4476 };
4477
4478 static void
4479 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4480                             __rte_unused struct cmdline *cl,
4481                             __rte_unused void *data)
4482 {
4483         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4484
4485         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4486                 return;
4487
4488         if (!port_is_stopped(res->port_id)) {
4489                 printf("Please stop port %d first\n", res->port_id);
4490                 return;
4491         }
4492
4493         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4494
4495         cmd_reconfig_device_queue(res->port_id, 1, 1);
4496 }
4497
4498 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4499         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4500                 tx_vlan, "tx_vlan");
4501 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4502         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4503                 set, "set");
4504 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4505         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4506                 port_id, UINT16);
4507 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4508         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4509                 vlan_id, UINT16);
4510 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4511         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4512                 vlan_id_outer, UINT16);
4513
4514 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4515         .f = cmd_tx_vlan_set_qinq_parsed,
4516         .data = NULL,
4517         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4518                 "Enable hardware insertion of double VLAN header "
4519                 "with given TAG Identifiers in packets sent on a port",
4520         .tokens = {
4521                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4522                 (void *)&cmd_tx_vlan_set_qinq_set,
4523                 (void *)&cmd_tx_vlan_set_qinq_portid,
4524                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4525                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4526                 NULL,
4527         },
4528 };
4529
4530 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4531 struct cmd_tx_vlan_set_pvid_result {
4532         cmdline_fixed_string_t tx_vlan;
4533         cmdline_fixed_string_t set;
4534         cmdline_fixed_string_t pvid;
4535         portid_t port_id;
4536         uint16_t vlan_id;
4537         cmdline_fixed_string_t mode;
4538 };
4539
4540 static void
4541 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4542                             __rte_unused struct cmdline *cl,
4543                             __rte_unused void *data)
4544 {
4545         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4546
4547         if (strcmp(res->mode, "on") == 0)
4548                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4549         else
4550                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4551 }
4552
4553 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4554         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4555                                  tx_vlan, "tx_vlan");
4556 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4557         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4558                                  set, "set");
4559 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4560         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4561                                  pvid, "pvid");
4562 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4563         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4564                              port_id, UINT16);
4565 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4566         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4567                               vlan_id, UINT16);
4568 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4569         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4570                                  mode, "on#off");
4571
4572 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4573         .f = cmd_tx_vlan_set_pvid_parsed,
4574         .data = NULL,
4575         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4576         .tokens = {
4577                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4578                 (void *)&cmd_tx_vlan_set_pvid_set,
4579                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4580                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4581                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4582                 (void *)&cmd_tx_vlan_set_pvid_mode,
4583                 NULL,
4584         },
4585 };
4586
4587 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4588 struct cmd_tx_vlan_reset_result {
4589         cmdline_fixed_string_t tx_vlan;
4590         cmdline_fixed_string_t reset;
4591         portid_t port_id;
4592 };
4593
4594 static void
4595 cmd_tx_vlan_reset_parsed(void *parsed_result,
4596                          __rte_unused struct cmdline *cl,
4597                          __rte_unused void *data)
4598 {
4599         struct cmd_tx_vlan_reset_result *res = parsed_result;
4600
4601         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4602                 return;
4603
4604         if (!port_is_stopped(res->port_id)) {
4605                 printf("Please stop port %d first\n", res->port_id);
4606                 return;
4607         }
4608
4609         tx_vlan_reset(res->port_id);
4610
4611         cmd_reconfig_device_queue(res->port_id, 1, 1);
4612 }
4613
4614 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4615         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4616                                  tx_vlan, "tx_vlan");
4617 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4618         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4619                                  reset, "reset");
4620 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4621         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4622                               port_id, UINT16);
4623
4624 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4625         .f = cmd_tx_vlan_reset_parsed,
4626         .data = NULL,
4627         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4628                 "VLAN header in packets sent on a port",
4629         .tokens = {
4630                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4631                 (void *)&cmd_tx_vlan_reset_reset,
4632                 (void *)&cmd_tx_vlan_reset_portid,
4633                 NULL,
4634         },
4635 };
4636
4637
4638 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4639 struct cmd_csum_result {
4640         cmdline_fixed_string_t csum;
4641         cmdline_fixed_string_t mode;
4642         cmdline_fixed_string_t proto;
4643         cmdline_fixed_string_t hwsw;
4644         portid_t port_id;
4645 };
4646
4647 static void
4648 csum_show(int port_id)
4649 {
4650         struct rte_eth_dev_info dev_info;
4651         uint64_t tx_offloads;
4652         int ret;
4653
4654         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4655         printf("Parse tunnel is %s\n",
4656                 (ports[port_id].parse_tunnel) ? "on" : "off");
4657         printf("IP checksum offload is %s\n",
4658                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4659         printf("UDP checksum offload is %s\n",
4660                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4661         printf("TCP checksum offload is %s\n",
4662                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4663         printf("SCTP checksum offload is %s\n",
4664                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4665         printf("Outer-Ip checksum offload is %s\n",
4666                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4667         printf("Outer-Udp checksum offload is %s\n",
4668                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4669
4670         /* display warnings if configuration is not supported by the NIC */
4671         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4672         if (ret != 0)
4673                 return;
4674
4675         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4677                 printf("Warning: hardware IP checksum enabled but not "
4678                         "supported by port %d\n", port_id);
4679         }
4680         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4682                 printf("Warning: hardware UDP checksum enabled but not "
4683                         "supported by port %d\n", port_id);
4684         }
4685         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4687                 printf("Warning: hardware TCP checksum enabled but not "
4688                         "supported by port %d\n", port_id);
4689         }
4690         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4691                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4692                 printf("Warning: hardware SCTP checksum enabled but not "
4693                         "supported by port %d\n", port_id);
4694         }
4695         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4696                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4697                 printf("Warning: hardware outer IP checksum enabled but not "
4698                         "supported by port %d\n", port_id);
4699         }
4700         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4701                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4702                         == 0) {
4703                 printf("Warning: hardware outer UDP checksum enabled but not "
4704                         "supported by port %d\n", port_id);
4705         }
4706 }
4707
4708 static void
4709 cmd_config_queue_tx_offloads(struct rte_port *port)
4710 {
4711         int k;
4712
4713         /* Apply queue tx offloads configuration */
4714         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4715                 port->tx_conf[k].offloads =
4716                         port->dev_conf.txmode.offloads;
4717 }
4718
4719 static void
4720 cmd_csum_parsed(void *parsed_result,
4721                        __rte_unused struct cmdline *cl,
4722                        __rte_unused void *data)
4723 {
4724         struct cmd_csum_result *res = parsed_result;
4725         int hw = 0;
4726         uint64_t csum_offloads = 0;
4727         struct rte_eth_dev_info dev_info;
4728         int ret;
4729
4730         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4731                 printf("invalid port %d\n", res->port_id);
4732                 return;
4733         }
4734         if (!port_is_stopped(res->port_id)) {
4735                 printf("Please stop port %d first\n", res->port_id);
4736                 return;
4737         }
4738
4739         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4740         if (ret != 0)
4741                 return;
4742
4743         if (!strcmp(res->mode, "set")) {
4744
4745                 if (!strcmp(res->hwsw, "hw"))
4746                         hw = 1;
4747
4748                 if (!strcmp(res->proto, "ip")) {
4749                         if (hw == 0 || (dev_info.tx_offload_capa &
4750                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4751                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4752                         } else {
4753                                 printf("IP checksum offload is not supported "
4754                                        "by port %u\n", res->port_id);
4755                         }
4756                 } else if (!strcmp(res->proto, "udp")) {
4757                         if (hw == 0 || (dev_info.tx_offload_capa &
4758                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4759                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4760                         } else {
4761                                 printf("UDP checksum offload is not supported "
4762                                        "by port %u\n", res->port_id);
4763                         }
4764                 } else if (!strcmp(res->proto, "tcp")) {
4765                         if (hw == 0 || (dev_info.tx_offload_capa &
4766                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4767                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4768                         } else {
4769                                 printf("TCP checksum offload is not supported "
4770                                        "by port %u\n", res->port_id);
4771                         }
4772                 } else if (!strcmp(res->proto, "sctp")) {
4773                         if (hw == 0 || (dev_info.tx_offload_capa &
4774                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4775                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4776                         } else {
4777                                 printf("SCTP checksum offload is not supported "
4778                                        "by port %u\n", res->port_id);
4779                         }
4780                 } else if (!strcmp(res->proto, "outer-ip")) {
4781                         if (hw == 0 || (dev_info.tx_offload_capa &
4782                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4783                                 csum_offloads |=
4784                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4785                         } else {
4786                                 printf("Outer IP checksum offload is not "
4787                                        "supported by port %u\n", res->port_id);
4788                         }
4789                 } else if (!strcmp(res->proto, "outer-udp")) {
4790                         if (hw == 0 || (dev_info.tx_offload_capa &
4791                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4792                                 csum_offloads |=
4793                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4794                         } else {
4795                                 printf("Outer UDP checksum offload is not "
4796                                        "supported by port %u\n", res->port_id);
4797                         }
4798                 }
4799
4800                 if (hw) {
4801                         ports[res->port_id].dev_conf.txmode.offloads |=
4802                                                         csum_offloads;
4803                 } else {
4804                         ports[res->port_id].dev_conf.txmode.offloads &=
4805                                                         (~csum_offloads);
4806                 }
4807                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4808         }
4809         csum_show(res->port_id);
4810
4811         cmd_reconfig_device_queue(res->port_id, 1, 1);
4812 }
4813
4814 cmdline_parse_token_string_t cmd_csum_csum =
4815         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4816                                 csum, "csum");
4817 cmdline_parse_token_string_t cmd_csum_mode =
4818         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4819                                 mode, "set");
4820 cmdline_parse_token_string_t cmd_csum_proto =
4821         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4822                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4823 cmdline_parse_token_string_t cmd_csum_hwsw =
4824         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4825                                 hwsw, "hw#sw");
4826 cmdline_parse_token_num_t cmd_csum_portid =
4827         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4828                                 port_id, UINT16);
4829
4830 cmdline_parse_inst_t cmd_csum_set = {
4831         .f = cmd_csum_parsed,
4832         .data = NULL,
4833         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4834                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4835                 "using csum forward engine",
4836         .tokens = {
4837                 (void *)&cmd_csum_csum,
4838                 (void *)&cmd_csum_mode,
4839                 (void *)&cmd_csum_proto,
4840                 (void *)&cmd_csum_hwsw,
4841                 (void *)&cmd_csum_portid,
4842                 NULL,
4843         },
4844 };
4845
4846 cmdline_parse_token_string_t cmd_csum_mode_show =
4847         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4848                                 mode, "show");
4849
4850 cmdline_parse_inst_t cmd_csum_show = {
4851         .f = cmd_csum_parsed,
4852         .data = NULL,
4853         .help_str = "csum show <port_id>: Show checksum offload configuration",
4854         .tokens = {
4855                 (void *)&cmd_csum_csum,
4856                 (void *)&cmd_csum_mode_show,
4857                 (void *)&cmd_csum_portid,
4858                 NULL,
4859         },
4860 };
4861
4862 /* Enable/disable tunnel parsing */
4863 struct cmd_csum_tunnel_result {
4864         cmdline_fixed_string_t csum;
4865         cmdline_fixed_string_t parse;
4866         cmdline_fixed_string_t onoff;
4867         portid_t port_id;
4868 };
4869
4870 static void
4871 cmd_csum_tunnel_parsed(void *parsed_result,
4872                        __rte_unused struct cmdline *cl,
4873                        __rte_unused void *data)
4874 {
4875         struct cmd_csum_tunnel_result *res = parsed_result;
4876
4877         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4878                 return;
4879
4880         if (!strcmp(res->onoff, "on"))
4881                 ports[res->port_id].parse_tunnel = 1;
4882         else
4883                 ports[res->port_id].parse_tunnel = 0;
4884
4885         csum_show(res->port_id);
4886 }
4887
4888 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4889         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4890                                 csum, "csum");
4891 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4892         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4893                                 parse, "parse-tunnel");
4894 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4895         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4896                                 onoff, "on#off");
4897 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4898         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4899                                 port_id, UINT16);
4900
4901 cmdline_parse_inst_t cmd_csum_tunnel = {
4902         .f = cmd_csum_tunnel_parsed,
4903         .data = NULL,
4904         .help_str = "csum parse-tunnel on|off <port_id>: "
4905                 "Enable/Disable parsing of tunnels for csum engine",
4906         .tokens = {
4907                 (void *)&cmd_csum_tunnel_csum,
4908                 (void *)&cmd_csum_tunnel_parse,
4909                 (void *)&cmd_csum_tunnel_onoff,
4910                 (void *)&cmd_csum_tunnel_portid,
4911                 NULL,
4912         },
4913 };
4914
4915 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4916 struct cmd_tso_set_result {
4917         cmdline_fixed_string_t tso;
4918         cmdline_fixed_string_t mode;
4919         uint16_t tso_segsz;
4920         portid_t port_id;
4921 };
4922
4923 static void
4924 cmd_tso_set_parsed(void *parsed_result,
4925                        __rte_unused struct cmdline *cl,
4926                        __rte_unused void *data)
4927 {
4928         struct cmd_tso_set_result *res = parsed_result;
4929         struct rte_eth_dev_info dev_info;
4930         int ret;
4931
4932         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4933                 return;
4934         if (!port_is_stopped(res->port_id)) {
4935                 printf("Please stop port %d first\n", res->port_id);
4936                 return;
4937         }
4938
4939         if (!strcmp(res->mode, "set"))
4940                 ports[res->port_id].tso_segsz = res->tso_segsz;
4941
4942         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4943         if (ret != 0)
4944                 return;
4945
4946         if ((ports[res->port_id].tso_segsz != 0) &&
4947                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4948                 printf("Error: TSO is not supported by port %d\n",
4949                        res->port_id);
4950                 return;
4951         }
4952
4953         if (ports[res->port_id].tso_segsz == 0) {
4954                 ports[res->port_id].dev_conf.txmode.offloads &=
4955                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4956                 printf("TSO for non-tunneled packets is disabled\n");
4957         } else {
4958                 ports[res->port_id].dev_conf.txmode.offloads |=
4959                                                 DEV_TX_OFFLOAD_TCP_TSO;
4960                 printf("TSO segment size for non-tunneled packets is %d\n",
4961                         ports[res->port_id].tso_segsz);
4962         }
4963         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4964
4965         /* display warnings if configuration is not supported by the NIC */
4966         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4967         if (ret != 0)
4968                 return;
4969
4970         if ((ports[res->port_id].tso_segsz != 0) &&
4971                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4972                 printf("Warning: TSO enabled but not "
4973                         "supported by port %d\n", res->port_id);
4974         }
4975
4976         cmd_reconfig_device_queue(res->port_id, 1, 1);
4977 }
4978
4979 cmdline_parse_token_string_t cmd_tso_set_tso =
4980         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4981                                 tso, "tso");
4982 cmdline_parse_token_string_t cmd_tso_set_mode =
4983         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4984                                 mode, "set");
4985 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4986         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4987                                 tso_segsz, UINT16);
4988 cmdline_parse_token_num_t cmd_tso_set_portid =
4989         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4990                                 port_id, UINT16);
4991
4992 cmdline_parse_inst_t cmd_tso_set = {
4993         .f = cmd_tso_set_parsed,
4994         .data = NULL,
4995         .help_str = "tso set <tso_segsz> <port_id>: "
4996                 "Set TSO segment size of non-tunneled packets for csum engine "
4997                 "(0 to disable)",
4998         .tokens = {
4999                 (void *)&cmd_tso_set_tso,
5000                 (void *)&cmd_tso_set_mode,
5001                 (void *)&cmd_tso_set_tso_segsz,
5002                 (void *)&cmd_tso_set_portid,
5003                 NULL,
5004         },
5005 };
5006
5007 cmdline_parse_token_string_t cmd_tso_show_mode =
5008         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
5009                                 mode, "show");
5010
5011
5012 cmdline_parse_inst_t cmd_tso_show = {
5013         .f = cmd_tso_set_parsed,
5014         .data = NULL,
5015         .help_str = "tso show <port_id>: "
5016                 "Show TSO segment size of non-tunneled packets for csum engine",
5017         .tokens = {
5018                 (void *)&cmd_tso_set_tso,
5019                 (void *)&cmd_tso_show_mode,
5020                 (void *)&cmd_tso_set_portid,
5021                 NULL,
5022         },
5023 };
5024
5025 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
5026 struct cmd_tunnel_tso_set_result {
5027         cmdline_fixed_string_t tso;
5028         cmdline_fixed_string_t mode;
5029         uint16_t tso_segsz;
5030         portid_t port_id;
5031 };
5032
5033 static struct rte_eth_dev_info
5034 check_tunnel_tso_nic_support(portid_t port_id)
5035 {
5036         struct rte_eth_dev_info dev_info;
5037
5038         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
5039                 return dev_info;
5040
5041         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
5042                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
5043                        "not enabled for port %d\n", port_id);
5044         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
5045                 printf("Warning: GRE TUNNEL TSO not supported therefore "
5046                        "not enabled for port %d\n", port_id);
5047         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
5048                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
5049                        "not enabled for port %d\n", port_id);
5050         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
5051                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5052                        "not enabled for port %d\n", port_id);
5053         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5054                 printf("Warning: IP TUNNEL TSO not supported therefore "
5055                        "not enabled for port %d\n", port_id);
5056         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5057                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5058                        "not enabled for port %d\n", port_id);
5059         return dev_info;
5060 }
5061
5062 static void
5063 cmd_tunnel_tso_set_parsed(void *parsed_result,
5064                           __rte_unused struct cmdline *cl,
5065                           __rte_unused void *data)
5066 {
5067         struct cmd_tunnel_tso_set_result *res = parsed_result;
5068         struct rte_eth_dev_info dev_info;
5069
5070         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5071                 return;
5072         if (!port_is_stopped(res->port_id)) {
5073                 printf("Please stop port %d first\n", res->port_id);
5074                 return;
5075         }
5076
5077         if (!strcmp(res->mode, "set"))
5078                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5079
5080         dev_info = check_tunnel_tso_nic_support(res->port_id);
5081         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5082                 ports[res->port_id].dev_conf.txmode.offloads &=
5083                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5084                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5085                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5086                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5087                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5088                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5089                 printf("TSO for tunneled packets is disabled\n");
5090         } else {
5091                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5092                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5093                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5094                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5095                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5096                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5097
5098                 ports[res->port_id].dev_conf.txmode.offloads |=
5099                         (tso_offloads & dev_info.tx_offload_capa);
5100                 printf("TSO segment size for tunneled packets is %d\n",
5101                         ports[res->port_id].tunnel_tso_segsz);
5102
5103                 /* Below conditions are needed to make it work:
5104                  * (1) tunnel TSO is supported by the NIC;
5105                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5106                  * are recognized;
5107                  * (3) for tunneled pkts with outer L3 of IPv4,
5108                  * "csum set outer-ip" must be set to hw, because after tso,
5109                  * total_len of outer IP header is changed, and the checksum
5110                  * of outer IP header calculated by sw should be wrong; that
5111                  * is not necessary for IPv6 tunneled pkts because there's no
5112                  * checksum in IP header anymore.
5113                  */
5114
5115                 if (!ports[res->port_id].parse_tunnel)
5116                         printf("Warning: csum parse_tunnel must be set "
5117                                 "so that tunneled packets are recognized\n");
5118                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5119                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5120                         printf("Warning: csum set outer-ip must be set to hw "
5121                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5122         }
5123
5124         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5125         cmd_reconfig_device_queue(res->port_id, 1, 1);
5126 }
5127
5128 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5129         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5130                                 tso, "tunnel_tso");
5131 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5132         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5133                                 mode, "set");
5134 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5135         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5136                                 tso_segsz, UINT16);
5137 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5138         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5139                                 port_id, UINT16);
5140
5141 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5142         .f = cmd_tunnel_tso_set_parsed,
5143         .data = NULL,
5144         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5145                 "Set TSO segment size of tunneled packets for csum engine "
5146                 "(0 to disable)",
5147         .tokens = {
5148                 (void *)&cmd_tunnel_tso_set_tso,
5149                 (void *)&cmd_tunnel_tso_set_mode,
5150                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5151                 (void *)&cmd_tunnel_tso_set_portid,
5152                 NULL,
5153         },
5154 };
5155
5156 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5157         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5158                                 mode, "show");
5159
5160
5161 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5162         .f = cmd_tunnel_tso_set_parsed,
5163         .data = NULL,
5164         .help_str = "tunnel_tso show <port_id> "
5165                 "Show TSO segment size of tunneled packets for csum engine",
5166         .tokens = {
5167                 (void *)&cmd_tunnel_tso_set_tso,
5168                 (void *)&cmd_tunnel_tso_show_mode,
5169                 (void *)&cmd_tunnel_tso_set_portid,
5170                 NULL,
5171         },
5172 };
5173
5174 /* *** SET GRO FOR A PORT *** */
5175 struct cmd_gro_enable_result {
5176         cmdline_fixed_string_t cmd_set;
5177         cmdline_fixed_string_t cmd_port;
5178         cmdline_fixed_string_t cmd_keyword;
5179         cmdline_fixed_string_t cmd_onoff;
5180         portid_t cmd_pid;
5181 };
5182
5183 static void
5184 cmd_gro_enable_parsed(void *parsed_result,
5185                 __rte_unused struct cmdline *cl,
5186                 __rte_unused void *data)
5187 {
5188         struct cmd_gro_enable_result *res;
5189
5190         res = parsed_result;
5191         if (!strcmp(res->cmd_keyword, "gro"))
5192                 setup_gro(res->cmd_onoff, res->cmd_pid);
5193 }
5194
5195 cmdline_parse_token_string_t cmd_gro_enable_set =
5196         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5197                         cmd_set, "set");
5198 cmdline_parse_token_string_t cmd_gro_enable_port =
5199         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5200                         cmd_keyword, "port");
5201 cmdline_parse_token_num_t cmd_gro_enable_pid =
5202         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5203                         cmd_pid, UINT16);
5204 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5205         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5206                         cmd_keyword, "gro");
5207 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5208         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5209                         cmd_onoff, "on#off");
5210
5211 cmdline_parse_inst_t cmd_gro_enable = {
5212         .f = cmd_gro_enable_parsed,
5213         .data = NULL,
5214         .help_str = "set port <port_id> gro on|off",
5215         .tokens = {
5216                 (void *)&cmd_gro_enable_set,
5217                 (void *)&cmd_gro_enable_port,
5218                 (void *)&cmd_gro_enable_pid,
5219                 (void *)&cmd_gro_enable_keyword,
5220                 (void *)&cmd_gro_enable_onoff,
5221                 NULL,
5222         },
5223 };
5224
5225 /* *** DISPLAY GRO CONFIGURATION *** */
5226 struct cmd_gro_show_result {
5227         cmdline_fixed_string_t cmd_show;
5228         cmdline_fixed_string_t cmd_port;
5229         cmdline_fixed_string_t cmd_keyword;
5230         portid_t cmd_pid;
5231 };
5232
5233 static void
5234 cmd_gro_show_parsed(void *parsed_result,
5235                 __rte_unused struct cmdline *cl,
5236                 __rte_unused void *data)
5237 {
5238         struct cmd_gro_show_result *res;
5239
5240         res = parsed_result;
5241         if (!strcmp(res->cmd_keyword, "gro"))
5242                 show_gro(res->cmd_pid);
5243 }
5244
5245 cmdline_parse_token_string_t cmd_gro_show_show =
5246         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5247                         cmd_show, "show");
5248 cmdline_parse_token_string_t cmd_gro_show_port =
5249         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5250                         cmd_port, "port");
5251 cmdline_parse_token_num_t cmd_gro_show_pid =
5252         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5253                         cmd_pid, UINT16);
5254 cmdline_parse_token_string_t cmd_gro_show_keyword =
5255         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5256                         cmd_keyword, "gro");
5257
5258 cmdline_parse_inst_t cmd_gro_show = {
5259         .f = cmd_gro_show_parsed,
5260         .data = NULL,
5261         .help_str = "show port <port_id> gro",
5262         .tokens = {
5263                 (void *)&cmd_gro_show_show,
5264                 (void *)&cmd_gro_show_port,
5265                 (void *)&cmd_gro_show_pid,
5266                 (void *)&cmd_gro_show_keyword,
5267                 NULL,
5268         },
5269 };
5270
5271 /* *** SET FLUSH CYCLES FOR GRO *** */
5272 struct cmd_gro_flush_result {
5273         cmdline_fixed_string_t cmd_set;
5274         cmdline_fixed_string_t cmd_keyword;
5275         cmdline_fixed_string_t cmd_flush;
5276         uint8_t cmd_cycles;
5277 };
5278
5279 static void
5280 cmd_gro_flush_parsed(void *parsed_result,
5281                 __rte_unused struct cmdline *cl,
5282                 __rte_unused void *data)
5283 {
5284         struct cmd_gro_flush_result *res;
5285
5286         res = parsed_result;
5287         if ((!strcmp(res->cmd_keyword, "gro")) &&
5288                         (!strcmp(res->cmd_flush, "flush")))
5289                 setup_gro_flush_cycles(res->cmd_cycles);
5290 }
5291
5292 cmdline_parse_token_string_t cmd_gro_flush_set =
5293         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5294                         cmd_set, "set");
5295 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5296         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5297                         cmd_keyword, "gro");
5298 cmdline_parse_token_string_t cmd_gro_flush_flush =
5299         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5300                         cmd_flush, "flush");
5301 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5302         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5303                         cmd_cycles, UINT8);
5304
5305 cmdline_parse_inst_t cmd_gro_flush = {
5306         .f = cmd_gro_flush_parsed,
5307         .data = NULL,
5308         .help_str = "set gro flush <cycles>",
5309         .tokens = {
5310                 (void *)&cmd_gro_flush_set,
5311                 (void *)&cmd_gro_flush_keyword,
5312                 (void *)&cmd_gro_flush_flush,
5313                 (void *)&cmd_gro_flush_cycles,
5314                 NULL,
5315         },
5316 };
5317
5318 /* *** ENABLE/DISABLE GSO *** */
5319 struct cmd_gso_enable_result {
5320         cmdline_fixed_string_t cmd_set;
5321         cmdline_fixed_string_t cmd_port;
5322         cmdline_fixed_string_t cmd_keyword;
5323         cmdline_fixed_string_t cmd_mode;
5324         portid_t cmd_pid;
5325 };
5326
5327 static void
5328 cmd_gso_enable_parsed(void *parsed_result,
5329                 __rte_unused struct cmdline *cl,
5330                 __rte_unused void *data)
5331 {
5332         struct cmd_gso_enable_result *res;
5333
5334         res = parsed_result;
5335         if (!strcmp(res->cmd_keyword, "gso"))
5336                 setup_gso(res->cmd_mode, res->cmd_pid);
5337 }
5338
5339 cmdline_parse_token_string_t cmd_gso_enable_set =
5340         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5341                         cmd_set, "set");
5342 cmdline_parse_token_string_t cmd_gso_enable_port =
5343         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5344                         cmd_port, "port");
5345 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5346         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5347                         cmd_keyword, "gso");
5348 cmdline_parse_token_string_t cmd_gso_enable_mode =
5349         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5350                         cmd_mode, "on#off");
5351 cmdline_parse_token_num_t cmd_gso_enable_pid =
5352         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5353                         cmd_pid, UINT16);
5354
5355 cmdline_parse_inst_t cmd_gso_enable = {
5356         .f = cmd_gso_enable_parsed,
5357         .data = NULL,
5358         .help_str = "set port <port_id> gso on|off",
5359         .tokens = {
5360                 (void *)&cmd_gso_enable_set,
5361                 (void *)&cmd_gso_enable_port,
5362                 (void *)&cmd_gso_enable_pid,
5363                 (void *)&cmd_gso_enable_keyword,
5364                 (void *)&cmd_gso_enable_mode,
5365                 NULL,
5366         },
5367 };
5368
5369 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5370 struct cmd_gso_size_result {
5371         cmdline_fixed_string_t cmd_set;
5372         cmdline_fixed_string_t cmd_keyword;
5373         cmdline_fixed_string_t cmd_segsz;
5374         uint16_t cmd_size;
5375 };
5376
5377 static void
5378 cmd_gso_size_parsed(void *parsed_result,
5379                        __rte_unused struct cmdline *cl,
5380                        __rte_unused void *data)
5381 {
5382         struct cmd_gso_size_result *res = parsed_result;
5383
5384         if (test_done == 0) {
5385                 printf("Before setting GSO segsz, please first"
5386                                 " stop forwarding\n");
5387                 return;
5388         }
5389
5390         if (!strcmp(res->cmd_keyword, "gso") &&
5391                         !strcmp(res->cmd_segsz, "segsz")) {
5392                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5393                         printf("gso_size should be larger than %zu."
5394                                         " Please input a legal value\n",
5395                                         RTE_GSO_SEG_SIZE_MIN);
5396                 else
5397                         gso_max_segment_size = res->cmd_size;
5398         }
5399 }
5400
5401 cmdline_parse_token_string_t cmd_gso_size_set =
5402         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5403                                 cmd_set, "set");
5404 cmdline_parse_token_string_t cmd_gso_size_keyword =
5405         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5406                                 cmd_keyword, "gso");
5407 cmdline_parse_token_string_t cmd_gso_size_segsz =
5408         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5409                                 cmd_segsz, "segsz");
5410 cmdline_parse_token_num_t cmd_gso_size_size =
5411         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5412                                 cmd_size, UINT16);
5413
5414 cmdline_parse_inst_t cmd_gso_size = {
5415         .f = cmd_gso_size_parsed,
5416         .data = NULL,
5417         .help_str = "set gso segsz <length>",
5418         .tokens = {
5419                 (void *)&cmd_gso_size_set,
5420                 (void *)&cmd_gso_size_keyword,
5421                 (void *)&cmd_gso_size_segsz,
5422                 (void *)&cmd_gso_size_size,
5423                 NULL,
5424         },
5425 };
5426
5427 /* *** SHOW GSO CONFIGURATION *** */
5428 struct cmd_gso_show_result {
5429         cmdline_fixed_string_t cmd_show;
5430         cmdline_fixed_string_t cmd_port;
5431         cmdline_fixed_string_t cmd_keyword;
5432         portid_t cmd_pid;
5433 };
5434
5435 static void
5436 cmd_gso_show_parsed(void *parsed_result,
5437                        __rte_unused struct cmdline *cl,
5438                        __rte_unused void *data)
5439 {
5440         struct cmd_gso_show_result *res = parsed_result;
5441
5442         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5443                 printf("invalid port id %u\n", res->cmd_pid);
5444                 return;
5445         }
5446         if (!strcmp(res->cmd_keyword, "gso")) {
5447                 if (gso_ports[res->cmd_pid].enable) {
5448                         printf("Max GSO'd packet size: %uB\n"
5449                                         "Supported GSO types: TCP/IPv4, "
5450                                         "UDP/IPv4, VxLAN with inner "
5451                                         "TCP/IPv4 packet, GRE with inner "
5452                                         "TCP/IPv4 packet\n",
5453                                         gso_max_segment_size);
5454                 } else
5455                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5456         }
5457 }
5458
5459 cmdline_parse_token_string_t cmd_gso_show_show =
5460 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5461                 cmd_show, "show");
5462 cmdline_parse_token_string_t cmd_gso_show_port =
5463 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5464                 cmd_port, "port");
5465 cmdline_parse_token_string_t cmd_gso_show_keyword =
5466         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5467                                 cmd_keyword, "gso");
5468 cmdline_parse_token_num_t cmd_gso_show_pid =
5469         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5470                                 cmd_pid, UINT16);
5471
5472 cmdline_parse_inst_t cmd_gso_show = {
5473         .f = cmd_gso_show_parsed,
5474         .data = NULL,
5475         .help_str = "show port <port_id> gso",
5476         .tokens = {
5477                 (void *)&cmd_gso_show_show,
5478                 (void *)&cmd_gso_show_port,
5479                 (void *)&cmd_gso_show_pid,
5480                 (void *)&cmd_gso_show_keyword,
5481                 NULL,
5482         },
5483 };
5484
5485 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5486 struct cmd_set_flush_rx {
5487         cmdline_fixed_string_t set;
5488         cmdline_fixed_string_t flush_rx;
5489         cmdline_fixed_string_t mode;
5490 };
5491
5492 static void
5493 cmd_set_flush_rx_parsed(void *parsed_result,
5494                 __rte_unused struct cmdline *cl,
5495                 __rte_unused void *data)
5496 {
5497         struct cmd_set_flush_rx *res = parsed_result;
5498         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5499 }
5500
5501 cmdline_parse_token_string_t cmd_setflushrx_set =
5502         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5503                         set, "set");
5504 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5505         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5506                         flush_rx, "flush_rx");
5507 cmdline_parse_token_string_t cmd_setflushrx_mode =
5508         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5509                         mode, "on#off");
5510
5511
5512 cmdline_parse_inst_t cmd_set_flush_rx = {
5513         .f = cmd_set_flush_rx_parsed,
5514         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5515         .data = NULL,
5516         .tokens = {
5517                 (void *)&cmd_setflushrx_set,
5518                 (void *)&cmd_setflushrx_flush_rx,
5519                 (void *)&cmd_setflushrx_mode,
5520                 NULL,
5521         },
5522 };
5523
5524 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5525 struct cmd_set_link_check {
5526         cmdline_fixed_string_t set;
5527         cmdline_fixed_string_t link_check;
5528         cmdline_fixed_string_t mode;
5529 };
5530
5531 static void
5532 cmd_set_link_check_parsed(void *parsed_result,
5533                 __rte_unused struct cmdline *cl,
5534                 __rte_unused void *data)
5535 {
5536         struct cmd_set_link_check *res = parsed_result;
5537         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5538 }
5539
5540 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5542                         set, "set");
5543 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5545                         link_check, "link_check");
5546 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5547         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5548                         mode, "on#off");
5549
5550
5551 cmdline_parse_inst_t cmd_set_link_check = {
5552         .f = cmd_set_link_check_parsed,
5553         .help_str = "set link_check on|off: Enable/Disable link status check "
5554                     "when starting/stopping a port",
5555         .data = NULL,
5556         .tokens = {
5557                 (void *)&cmd_setlinkcheck_set,
5558                 (void *)&cmd_setlinkcheck_link_check,
5559                 (void *)&cmd_setlinkcheck_mode,
5560                 NULL,
5561         },
5562 };
5563
5564 /* *** SET NIC BYPASS MODE *** */
5565 struct cmd_set_bypass_mode_result {
5566         cmdline_fixed_string_t set;
5567         cmdline_fixed_string_t bypass;
5568         cmdline_fixed_string_t mode;
5569         cmdline_fixed_string_t value;
5570         portid_t port_id;
5571 };
5572
5573 static void
5574 cmd_set_bypass_mode_parsed(void *parsed_result,
5575                 __rte_unused struct cmdline *cl,
5576                 __rte_unused void *data)
5577 {
5578         struct cmd_set_bypass_mode_result *res = parsed_result;
5579         portid_t port_id = res->port_id;
5580         int32_t rc = -EINVAL;
5581
5582 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5583         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5584
5585         if (!strcmp(res->value, "bypass"))
5586                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5587         else if (!strcmp(res->value, "isolate"))
5588                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5589         else
5590                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5591
5592         /* Set the bypass mode for the relevant port. */
5593         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5594 #endif
5595         if (rc != 0)
5596                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5597 }
5598
5599 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5600         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5601                         set, "set");
5602 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5603         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5604                         bypass, "bypass");
5605 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5606         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5607                         mode, "mode");
5608 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5609         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5610                         value, "normal#bypass#isolate");
5611 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5612         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5613                                 port_id, UINT16);
5614
5615 cmdline_parse_inst_t cmd_set_bypass_mode = {
5616         .f = cmd_set_bypass_mode_parsed,
5617         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5618                     "Set the NIC bypass mode for port_id",
5619         .data = NULL,
5620         .tokens = {
5621                 (void *)&cmd_setbypass_mode_set,
5622                 (void *)&cmd_setbypass_mode_bypass,
5623                 (void *)&cmd_setbypass_mode_mode,
5624                 (void *)&cmd_setbypass_mode_value,
5625                 (void *)&cmd_setbypass_mode_port,
5626                 NULL,
5627         },
5628 };
5629
5630 /* *** SET NIC BYPASS EVENT *** */
5631 struct cmd_set_bypass_event_result {
5632         cmdline_fixed_string_t set;
5633         cmdline_fixed_string_t bypass;
5634         cmdline_fixed_string_t event;
5635         cmdline_fixed_string_t event_value;
5636         cmdline_fixed_string_t mode;
5637         cmdline_fixed_string_t mode_value;
5638         portid_t port_id;
5639 };
5640
5641 static void
5642 cmd_set_bypass_event_parsed(void *parsed_result,
5643                 __rte_unused struct cmdline *cl,
5644                 __rte_unused void *data)
5645 {
5646         int32_t rc = -EINVAL;
5647         struct cmd_set_bypass_event_result *res = parsed_result;
5648         portid_t port_id = res->port_id;
5649
5650 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5651         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5652         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5653
5654         if (!strcmp(res->event_value, "timeout"))
5655                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5656         else if (!strcmp(res->event_value, "os_on"))
5657                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5658         else if (!strcmp(res->event_value, "os_off"))
5659                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5660         else if (!strcmp(res->event_value, "power_on"))
5661                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5662         else if (!strcmp(res->event_value, "power_off"))
5663                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5664         else
5665                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5666
5667         if (!strcmp(res->mode_value, "bypass"))
5668                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5669         else if (!strcmp(res->mode_value, "isolate"))
5670                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5671         else
5672                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5673
5674         /* Set the watchdog timeout. */
5675         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5676
5677                 rc = -EINVAL;
5678                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5679                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5680                                                            bypass_timeout);
5681                 }
5682                 if (rc != 0) {
5683                         printf("Failed to set timeout value %u "
5684                         "for port %d, errto code: %d.\n",
5685                         bypass_timeout, port_id, rc);
5686                 }
5687         }
5688
5689         /* Set the bypass event to transition to bypass mode. */
5690         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5691                                               bypass_mode);
5692 #endif
5693
5694         if (rc != 0)
5695                 printf("\t Failed to set bypass event for port = %d.\n",
5696                        port_id);
5697 }
5698
5699 cmdline_parse_token_string_t cmd_setbypass_event_set =
5700         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5701                         set, "set");
5702 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5703         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5704                         bypass, "bypass");
5705 cmdline_parse_token_string_t cmd_setbypass_event_event =
5706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5707                         event, "event");
5708 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5709         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5710                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5711 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5712         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5713                         mode, "mode");
5714 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5715         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5716                         mode_value, "normal#bypass#isolate");
5717 cmdline_parse_token_num_t cmd_setbypass_event_port =
5718         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5719                                 port_id, UINT16);
5720
5721 cmdline_parse_inst_t cmd_set_bypass_event = {
5722         .f = cmd_set_bypass_event_parsed,
5723         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5724                 "power_off mode normal|bypass|isolate <port_id>: "
5725                 "Set the NIC bypass event mode for port_id",
5726         .data = NULL,
5727         .tokens = {
5728                 (void *)&cmd_setbypass_event_set,
5729                 (void *)&cmd_setbypass_event_bypass,
5730                 (void *)&cmd_setbypass_event_event,
5731                 (void *)&cmd_setbypass_event_event_value,
5732                 (void *)&cmd_setbypass_event_mode,
5733                 (void *)&cmd_setbypass_event_mode_value,
5734                 (void *)&cmd_setbypass_event_port,
5735                 NULL,
5736         },
5737 };
5738
5739
5740 /* *** SET NIC BYPASS TIMEOUT *** */
5741 struct cmd_set_bypass_timeout_result {
5742         cmdline_fixed_string_t set;
5743         cmdline_fixed_string_t bypass;
5744         cmdline_fixed_string_t timeout;
5745         cmdline_fixed_string_t value;
5746 };
5747
5748 static void
5749 cmd_set_bypass_timeout_parsed(void *parsed_result,
5750                 __rte_unused struct cmdline *cl,
5751                 __rte_unused void *data)
5752 {
5753         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5754
5755 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5756         if (!strcmp(res->value, "1.5"))
5757                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5758         else if (!strcmp(res->value, "2"))
5759                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5760         else if (!strcmp(res->value, "3"))
5761                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5762         else if (!strcmp(res->value, "4"))
5763                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5764         else if (!strcmp(res->value, "8"))
5765                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5766         else if (!strcmp(res->value, "16"))
5767                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5768         else if (!strcmp(res->value, "32"))
5769                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5770         else
5771                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5772 #endif
5773 }
5774
5775 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5776         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5777                         set, "set");
5778 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5779         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5780                         bypass, "bypass");
5781 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5782         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5783                         timeout, "timeout");
5784 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5785         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5786                         value, "0#1.5#2#3#4#8#16#32");
5787
5788 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5789         .f = cmd_set_bypass_timeout_parsed,
5790         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5791                 "Set the NIC bypass watchdog timeout in seconds",
5792         .data = NULL,
5793         .tokens = {
5794                 (void *)&cmd_setbypass_timeout_set,
5795                 (void *)&cmd_setbypass_timeout_bypass,
5796                 (void *)&cmd_setbypass_timeout_timeout,
5797                 (void *)&cmd_setbypass_timeout_value,
5798                 NULL,
5799         },
5800 };
5801
5802 /* *** SHOW NIC BYPASS MODE *** */
5803 struct cmd_show_bypass_config_result {
5804         cmdline_fixed_string_t show;
5805         cmdline_fixed_string_t bypass;
5806         cmdline_fixed_string_t config;
5807         portid_t port_id;
5808 };
5809
5810 static void
5811 cmd_show_bypass_config_parsed(void *parsed_result,
5812                 __rte_unused struct cmdline *cl,
5813                 __rte_unused void *data)
5814 {
5815         struct cmd_show_bypass_config_result *res = parsed_result;
5816         portid_t port_id = res->port_id;
5817         int rc = -EINVAL;
5818 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5819         uint32_t event_mode;
5820         uint32_t bypass_mode;
5821         uint32_t timeout = bypass_timeout;
5822         unsigned int i;
5823
5824         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5825                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5826         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5827                 {"UNKNOWN", "normal", "bypass", "isolate"};
5828         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5829                 "NONE",
5830                 "OS/board on",
5831                 "power supply on",
5832                 "OS/board off",
5833                 "power supply off",
5834                 "timeout"};
5835
5836         /* Display the bypass mode.*/
5837         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5838                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5839                 return;
5840         }
5841         else {
5842                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5843                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5844
5845                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5846         }
5847
5848         /* Display the bypass timeout.*/
5849         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5850                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5851
5852         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5853
5854         /* Display the bypass events and associated modes. */
5855         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5856
5857                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5858                         printf("\tFailed to get bypass mode for event = %s\n",
5859                                 events[i]);
5860                 } else {
5861                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5862                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5863
5864                         printf("\tbypass event: %-16s = %s\n", events[i],
5865                                 modes[event_mode]);
5866                 }
5867         }
5868 #endif
5869         if (rc != 0)
5870                 printf("\tFailed to get bypass configuration for port = %d\n",
5871                        port_id);
5872 }
5873
5874 cmdline_parse_token_string_t cmd_showbypass_config_show =
5875         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5876                         show, "show");
5877 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5878         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5879                         bypass, "bypass");
5880 cmdline_parse_token_string_t cmd_showbypass_config_config =
5881         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5882                         config, "config");
5883 cmdline_parse_token_num_t cmd_showbypass_config_port =
5884         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5885                                 port_id, UINT16);
5886
5887 cmdline_parse_inst_t cmd_show_bypass_config = {
5888         .f = cmd_show_bypass_config_parsed,
5889         .help_str = "show bypass config <port_id>: "
5890                     "Show the NIC bypass config for port_id",
5891         .data = NULL,
5892         .tokens = {
5893                 (void *)&cmd_showbypass_config_show,
5894                 (void *)&cmd_showbypass_config_bypass,
5895                 (void *)&cmd_showbypass_config_config,
5896                 (void *)&cmd_showbypass_config_port,
5897                 NULL,
5898         },
5899 };
5900
5901 #ifdef RTE_NET_BOND
5902 /* *** SET BONDING MODE *** */
5903 struct cmd_set_bonding_mode_result {
5904         cmdline_fixed_string_t set;
5905         cmdline_fixed_string_t bonding;
5906         cmdline_fixed_string_t mode;
5907         uint8_t value;
5908         portid_t port_id;
5909 };
5910
5911 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5912                 __rte_unused  struct cmdline *cl,
5913                 __rte_unused void *data)
5914 {
5915         struct cmd_set_bonding_mode_result *res = parsed_result;
5916         portid_t port_id = res->port_id;
5917
5918         /* Set the bonding mode for the relevant port. */
5919         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5920                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5921 }
5922
5923 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5924 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5925                 set, "set");
5926 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5927 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5928                 bonding, "bonding");
5929 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5930 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5931                 mode, "mode");
5932 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5933 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5934                 value, UINT8);
5935 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5936 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5937                 port_id, UINT16);
5938
5939 cmdline_parse_inst_t cmd_set_bonding_mode = {
5940                 .f = cmd_set_bonding_mode_parsed,
5941                 .help_str = "set bonding mode <mode_value> <port_id>: "
5942                         "Set the bonding mode for port_id",
5943                 .data = NULL,
5944                 .tokens = {
5945                                 (void *) &cmd_setbonding_mode_set,
5946                                 (void *) &cmd_setbonding_mode_bonding,
5947                                 (void *) &cmd_setbonding_mode_mode,
5948                                 (void *) &cmd_setbonding_mode_value,
5949                                 (void *) &cmd_setbonding_mode_port,
5950                                 NULL
5951                 }
5952 };
5953
5954 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5955 struct cmd_set_bonding_lacp_dedicated_queues_result {
5956         cmdline_fixed_string_t set;
5957         cmdline_fixed_string_t bonding;
5958         cmdline_fixed_string_t lacp;
5959         cmdline_fixed_string_t dedicated_queues;
5960         portid_t port_id;
5961         cmdline_fixed_string_t mode;
5962 };
5963
5964 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5965                 __rte_unused  struct cmdline *cl,
5966                 __rte_unused void *data)
5967 {
5968         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5969         portid_t port_id = res->port_id;
5970         struct rte_port *port;
5971
5972         port = &ports[port_id];
5973
5974         /** Check if the port is not started **/
5975         if (port->port_status != RTE_PORT_STOPPED) {
5976                 printf("Please stop port %d first\n", port_id);
5977                 return;
5978         }
5979
5980         if (!strcmp(res->mode, "enable")) {
5981                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5982                         printf("Dedicate queues for LACP control packets"
5983                                         " enabled\n");
5984                 else
5985                         printf("Enabling dedicate queues for LACP control "
5986                                         "packets on port %d failed\n", port_id);
5987         } else if (!strcmp(res->mode, "disable")) {
5988                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5989                         printf("Dedicated queues for LACP control packets "
5990                                         "disabled\n");
5991                 else
5992                         printf("Disabling dedicated queues for LACP control "
5993                                         "traffic on port %d failed\n", port_id);
5994         }
5995 }
5996
5997 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5998 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5999                 set, "set");
6000 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
6001 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6002                 bonding, "bonding");
6003 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
6004 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6005                 lacp, "lacp");
6006 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
6007 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6008                 dedicated_queues, "dedicated_queues");
6009 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
6010 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6011                 port_id, UINT16);
6012 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
6013 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
6014                 mode, "enable#disable");
6015
6016 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
6017                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
6018                 .help_str = "set bonding lacp dedicated_queues <port_id> "
6019                         "enable|disable: "
6020                         "Enable/disable dedicated queues for LACP control traffic for port_id",
6021                 .data = NULL,
6022                 .tokens = {
6023                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
6024                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
6025                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
6026                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
6027                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
6028                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
6029                         NULL
6030                 }
6031 };
6032
6033 /* *** SET BALANCE XMIT POLICY *** */
6034 struct cmd_set_bonding_balance_xmit_policy_result {
6035         cmdline_fixed_string_t set;
6036         cmdline_fixed_string_t bonding;
6037         cmdline_fixed_string_t balance_xmit_policy;
6038         portid_t port_id;
6039         cmdline_fixed_string_t policy;
6040 };
6041
6042 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
6043                 __rte_unused  struct cmdline *cl,
6044                 __rte_unused void *data)
6045 {
6046         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
6047         portid_t port_id = res->port_id;
6048         uint8_t policy;
6049
6050         if (!strcmp(res->policy, "l2")) {
6051                 policy = BALANCE_XMIT_POLICY_LAYER2;
6052         } else if (!strcmp(res->policy, "l23")) {
6053                 policy = BALANCE_XMIT_POLICY_LAYER23;
6054         } else if (!strcmp(res->policy, "l34")) {
6055                 policy = BALANCE_XMIT_POLICY_LAYER34;
6056         } else {
6057                 printf("\t Invalid xmit policy selection");
6058                 return;
6059         }
6060
6061         /* Set the bonding mode for the relevant port. */
6062         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6063                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6064                                 port_id);
6065         }
6066 }
6067
6068 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6069 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6070                 set, "set");
6071 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6072 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6073                 bonding, "bonding");
6074 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6075 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6076                 balance_xmit_policy, "balance_xmit_policy");
6077 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6078 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6079                 port_id, UINT16);
6080 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6081 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6082                 policy, "l2#l23#l34");
6083
6084 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6085                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6086                 .help_str = "set bonding balance_xmit_policy <port_id> "
6087                         "l2|l23|l34: "
6088                         "Set the bonding balance_xmit_policy for port_id",
6089                 .data = NULL,
6090                 .tokens = {
6091                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6092                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6093                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6094                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6095                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6096                                 NULL
6097                 }
6098 };
6099
6100 /* *** SHOW NIC BONDING CONFIGURATION *** */
6101 struct cmd_show_bonding_config_result {
6102         cmdline_fixed_string_t show;
6103         cmdline_fixed_string_t bonding;
6104         cmdline_fixed_string_t config;
6105         portid_t port_id;
6106 };
6107
6108 static void cmd_show_bonding_config_parsed(void *parsed_result,
6109                 __rte_unused  struct cmdline *cl,
6110                 __rte_unused void *data)
6111 {
6112         struct cmd_show_bonding_config_result *res = parsed_result;
6113         int bonding_mode, agg_mode;
6114         portid_t slaves[RTE_MAX_ETHPORTS];
6115         int num_slaves, num_active_slaves;
6116         int primary_id;
6117         int i;
6118         portid_t port_id = res->port_id;
6119
6120         /* Display the bonding mode.*/
6121         bonding_mode = rte_eth_bond_mode_get(port_id);
6122         if (bonding_mode < 0) {
6123                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6124                 return;
6125         } else
6126                 printf("\tBonding mode: %d\n", bonding_mode);
6127
6128         if (bonding_mode == BONDING_MODE_BALANCE) {
6129                 int balance_xmit_policy;
6130
6131                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6132                 if (balance_xmit_policy < 0) {
6133                         printf("\tFailed to get balance xmit policy for port = %d\n",
6134                                         port_id);
6135                         return;
6136                 } else {
6137                         printf("\tBalance Xmit Policy: ");
6138
6139                         switch (balance_xmit_policy) {
6140                         case BALANCE_XMIT_POLICY_LAYER2:
6141                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6142                                 break;
6143                         case BALANCE_XMIT_POLICY_LAYER23:
6144                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6145                                 break;
6146                         case BALANCE_XMIT_POLICY_LAYER34:
6147                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6148                                 break;
6149                         }
6150                         printf("\n");
6151                 }
6152         }
6153
6154         if (bonding_mode == BONDING_MODE_8023AD) {
6155                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6156                 printf("\tIEEE802.3AD Aggregator Mode: ");
6157                 switch (agg_mode) {
6158                 case AGG_BANDWIDTH:
6159                         printf("bandwidth");
6160                         break;
6161                 case AGG_STABLE:
6162                         printf("stable");
6163                         break;
6164                 case AGG_COUNT:
6165                         printf("count");
6166                         break;
6167                 }
6168                 printf("\n");
6169         }
6170
6171         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6172
6173         if (num_slaves < 0) {
6174                 printf("\tFailed to get slave list for port = %d\n", port_id);
6175                 return;
6176         }
6177         if (num_slaves > 0) {
6178                 printf("\tSlaves (%d): [", num_slaves);
6179                 for (i = 0; i < num_slaves - 1; i++)
6180                         printf("%d ", slaves[i]);
6181
6182                 printf("%d]\n", slaves[num_slaves - 1]);
6183         } else {
6184                 printf("\tSlaves: []\n");
6185
6186         }
6187
6188         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6189                         RTE_MAX_ETHPORTS);
6190
6191         if (num_active_slaves < 0) {
6192                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6193                 return;
6194         }
6195         if (num_active_slaves > 0) {
6196                 printf("\tActive Slaves (%d): [", num_active_slaves);
6197                 for (i = 0; i < num_active_slaves - 1; i++)
6198                         printf("%d ", slaves[i]);
6199
6200                 printf("%d]\n", slaves[num_active_slaves - 1]);
6201
6202         } else {
6203                 printf("\tActive Slaves: []\n");
6204
6205         }
6206
6207         primary_id = rte_eth_bond_primary_get(port_id);
6208         if (primary_id < 0) {
6209                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6210                 return;
6211         } else
6212                 printf("\tPrimary: [%d]\n", primary_id);
6213
6214 }
6215
6216 cmdline_parse_token_string_t cmd_showbonding_config_show =
6217 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6218                 show, "show");
6219 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6220 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6221                 bonding, "bonding");
6222 cmdline_parse_token_string_t cmd_showbonding_config_config =
6223 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6224                 config, "config");
6225 cmdline_parse_token_num_t cmd_showbonding_config_port =
6226 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6227                 port_id, UINT16);
6228
6229 cmdline_parse_inst_t cmd_show_bonding_config = {
6230                 .f = cmd_show_bonding_config_parsed,
6231                 .help_str = "show bonding config <port_id>: "
6232                         "Show the bonding config for port_id",
6233                 .data = NULL,
6234                 .tokens = {
6235                                 (void *)&cmd_showbonding_config_show,
6236                                 (void *)&cmd_showbonding_config_bonding,
6237                                 (void *)&cmd_showbonding_config_config,
6238                                 (void *)&cmd_showbonding_config_port,
6239                                 NULL
6240                 }
6241 };
6242
6243 /* *** SET BONDING PRIMARY *** */
6244 struct cmd_set_bonding_primary_result {
6245         cmdline_fixed_string_t set;
6246         cmdline_fixed_string_t bonding;
6247         cmdline_fixed_string_t primary;
6248         portid_t slave_id;
6249         portid_t port_id;
6250 };
6251
6252 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6253                 __rte_unused  struct cmdline *cl,
6254                 __rte_unused void *data)
6255 {
6256         struct cmd_set_bonding_primary_result *res = parsed_result;
6257         portid_t master_port_id = res->port_id;
6258         portid_t slave_port_id = res->slave_id;
6259
6260         /* Set the primary slave for a bonded device. */
6261         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6262                 printf("\t Failed to set primary slave for port = %d.\n",
6263                                 master_port_id);
6264                 return;
6265         }
6266         init_port_config();
6267 }
6268
6269 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6270 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6271                 set, "set");
6272 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6273 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6274                 bonding, "bonding");
6275 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6276 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6277                 primary, "primary");
6278 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6279 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6280                 slave_id, UINT16);
6281 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6282 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6283                 port_id, UINT16);
6284
6285 cmdline_parse_inst_t cmd_set_bonding_primary = {
6286                 .f = cmd_set_bonding_primary_parsed,
6287                 .help_str = "set bonding primary <slave_id> <port_id>: "
6288                         "Set the primary slave for port_id",
6289                 .data = NULL,
6290                 .tokens = {
6291                                 (void *)&cmd_setbonding_primary_set,
6292                                 (void *)&cmd_setbonding_primary_bonding,
6293                                 (void *)&cmd_setbonding_primary_primary,
6294                                 (void *)&cmd_setbonding_primary_slave,
6295                                 (void *)&cmd_setbonding_primary_port,
6296                                 NULL
6297                 }
6298 };
6299
6300 /* *** ADD SLAVE *** */
6301 struct cmd_add_bonding_slave_result {
6302         cmdline_fixed_string_t add;
6303         cmdline_fixed_string_t bonding;
6304         cmdline_fixed_string_t slave;
6305         portid_t slave_id;
6306         portid_t port_id;
6307 };
6308
6309 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6310                 __rte_unused  struct cmdline *cl,
6311                 __rte_unused void *data)
6312 {
6313         struct cmd_add_bonding_slave_result *res = parsed_result;
6314         portid_t master_port_id = res->port_id;
6315         portid_t slave_port_id = res->slave_id;
6316
6317         /* add the slave for a bonded device. */
6318         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6319                 printf("\t Failed to add slave %d to master port = %d.\n",
6320                                 slave_port_id, master_port_id);
6321                 return;
6322         }
6323         init_port_config();
6324         set_port_slave_flag(slave_port_id);
6325 }
6326
6327 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6328 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6329                 add, "add");
6330 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6331 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6332                 bonding, "bonding");
6333 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6334 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6335                 slave, "slave");
6336 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6337 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6338                 slave_id, UINT16);
6339 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6340 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6341                 port_id, UINT16);
6342
6343 cmdline_parse_inst_t cmd_add_bonding_slave = {
6344                 .f = cmd_add_bonding_slave_parsed,
6345                 .help_str = "add bonding slave <slave_id> <port_id>: "
6346                         "Add a slave device to a bonded device",
6347                 .data = NULL,
6348                 .tokens = {
6349                                 (void *)&cmd_addbonding_slave_add,
6350                                 (void *)&cmd_addbonding_slave_bonding,
6351                                 (void *)&cmd_addbonding_slave_slave,
6352                                 (void *)&cmd_addbonding_slave_slaveid,
6353                                 (void *)&cmd_addbonding_slave_port,
6354                                 NULL
6355                 }
6356 };
6357
6358 /* *** REMOVE SLAVE *** */
6359 struct cmd_remove_bonding_slave_result {
6360         cmdline_fixed_string_t remove;
6361         cmdline_fixed_string_t bonding;
6362         cmdline_fixed_string_t slave;
6363         portid_t slave_id;
6364         portid_t port_id;
6365 };
6366
6367 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6368                 __rte_unused  struct cmdline *cl,
6369                 __rte_unused void *data)
6370 {
6371         struct cmd_remove_bonding_slave_result *res = parsed_result;
6372         portid_t master_port_id = res->port_id;
6373         portid_t slave_port_id = res->slave_id;
6374
6375         /* remove the slave from a bonded device. */
6376         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6377                 printf("\t Failed to remove slave %d from master port = %d.\n",
6378                                 slave_port_id, master_port_id);
6379                 return;
6380         }
6381         init_port_config();
6382         clear_port_slave_flag(slave_port_id);
6383 }
6384
6385 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6386                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6387                                 remove, "remove");
6388 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6389                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6390                                 bonding, "bonding");
6391 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6392                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6393                                 slave, "slave");
6394 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6395                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6396                                 slave_id, UINT16);
6397 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6398                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6399                                 port_id, UINT16);
6400
6401 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6402                 .f = cmd_remove_bonding_slave_parsed,
6403                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6404                         "Remove a slave device from a bonded device",
6405                 .data = NULL,
6406                 .tokens = {
6407                                 (void *)&cmd_removebonding_slave_remove,
6408                                 (void *)&cmd_removebonding_slave_bonding,
6409                                 (void *)&cmd_removebonding_slave_slave,
6410                                 (void *)&cmd_removebonding_slave_slaveid,
6411                                 (void *)&cmd_removebonding_slave_port,
6412                                 NULL
6413                 }
6414 };
6415
6416 /* *** CREATE BONDED DEVICE *** */
6417 struct cmd_create_bonded_device_result {
6418         cmdline_fixed_string_t create;
6419         cmdline_fixed_string_t bonded;
6420         cmdline_fixed_string_t device;
6421         uint8_t mode;
6422         uint8_t socket;
6423 };
6424
6425 static int bond_dev_num = 0;
6426
6427 static void cmd_create_bonded_device_parsed(void *parsed_result,
6428                 __rte_unused  struct cmdline *cl,
6429                 __rte_unused void *data)
6430 {
6431         struct cmd_create_bonded_device_result *res = parsed_result;
6432         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6433         int port_id;
6434         int ret;
6435
6436         if (test_done == 0) {
6437                 printf("Please stop forwarding first\n");
6438                 return;
6439         }
6440
6441         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6442                         bond_dev_num++);
6443
6444         /* Create a new bonded device. */
6445         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6446         if (port_id < 0) {
6447                 printf("\t Failed to create bonded device.\n");
6448                 return;
6449         } else {
6450                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6451                                 port_id);
6452
6453                 /* Update number of ports */
6454                 nb_ports = rte_eth_dev_count_avail();
6455                 reconfig(port_id, res->socket);
6456                 ret = rte_eth_promiscuous_enable(port_id);
6457                 if (ret != 0)
6458                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6459                                 port_id, rte_strerror(-ret));
6460
6461                 ports[port_id].need_setup = 0;
6462                 ports[port_id].port_status = RTE_PORT_STOPPED;
6463         }
6464
6465 }
6466
6467 cmdline_parse_token_string_t cmd_createbonded_device_create =
6468                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6469                                 create, "create");
6470 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6471                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6472                                 bonded, "bonded");
6473 cmdline_parse_token_string_t cmd_createbonded_device_device =
6474                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6475                                 device, "device");
6476 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6477                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6478                                 mode, UINT8);
6479 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6480                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6481                                 socket, UINT8);
6482
6483 cmdline_parse_inst_t cmd_create_bonded_device = {
6484                 .f = cmd_create_bonded_device_parsed,
6485                 .help_str = "create bonded device <mode> <socket>: "
6486                         "Create a new bonded device with specific bonding mode and socket",
6487                 .data = NULL,
6488                 .tokens = {
6489                                 (void *)&cmd_createbonded_device_create,
6490                                 (void *)&cmd_createbonded_device_bonded,
6491                                 (void *)&cmd_createbonded_device_device,
6492                                 (void *)&cmd_createbonded_device_mode,
6493                                 (void *)&cmd_createbonded_device_socket,
6494                                 NULL
6495                 }
6496 };
6497
6498 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6499 struct cmd_set_bond_mac_addr_result {
6500         cmdline_fixed_string_t set;
6501         cmdline_fixed_string_t bonding;
6502         cmdline_fixed_string_t mac_addr;
6503         uint16_t port_num;
6504         struct rte_ether_addr address;
6505 };
6506
6507 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6508                 __rte_unused  struct cmdline *cl,
6509                 __rte_unused void *data)
6510 {
6511         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6512         int ret;
6513
6514         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6515                 return;
6516
6517         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6518
6519         /* check the return value and print it if is < 0 */
6520         if (ret < 0)
6521                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6522 }
6523
6524 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6525                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6526 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6527                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6528                                 "bonding");
6529 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6530                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6531                                 "mac_addr");
6532 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6533                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6534                                 port_num, UINT16);
6535 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6536                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6537
6538 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6539                 .f = cmd_set_bond_mac_addr_parsed,
6540                 .data = (void *) 0,
6541                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6542                 .tokens = {
6543                                 (void *)&cmd_set_bond_mac_addr_set,
6544                                 (void *)&cmd_set_bond_mac_addr_bonding,
6545                                 (void *)&cmd_set_bond_mac_addr_mac,
6546                                 (void *)&cmd_set_bond_mac_addr_portnum,
6547                                 (void *)&cmd_set_bond_mac_addr_addr,
6548                                 NULL
6549                 }
6550 };
6551
6552
6553 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6554 struct cmd_set_bond_mon_period_result {
6555         cmdline_fixed_string_t set;
6556         cmdline_fixed_string_t bonding;
6557         cmdline_fixed_string_t mon_period;
6558         uint16_t port_num;
6559         uint32_t period_ms;
6560 };
6561
6562 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6563                 __rte_unused  struct cmdline *cl,
6564                 __rte_unused void *data)
6565 {
6566         struct cmd_set_bond_mon_period_result *res = parsed_result;
6567         int ret;
6568
6569         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6570
6571         /* check the return value and print it if is < 0 */
6572         if (ret < 0)
6573                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6574 }
6575
6576 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6577                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6578                                 set, "set");
6579 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6580                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6581                                 bonding, "bonding");
6582 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6583                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6584                                 mon_period,     "mon_period");
6585 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6586                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6587                                 port_num, UINT16);
6588 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6589                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6590                                 period_ms, UINT32);
6591
6592 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6593                 .f = cmd_set_bond_mon_period_parsed,
6594                 .data = (void *) 0,
6595                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6596                 .tokens = {
6597                                 (void *)&cmd_set_bond_mon_period_set,
6598                                 (void *)&cmd_set_bond_mon_period_bonding,
6599                                 (void *)&cmd_set_bond_mon_period_mon_period,
6600                                 (void *)&cmd_set_bond_mon_period_portnum,
6601                                 (void *)&cmd_set_bond_mon_period_period_ms,
6602                                 NULL
6603                 }
6604 };
6605
6606
6607
6608 struct cmd_set_bonding_agg_mode_policy_result {
6609         cmdline_fixed_string_t set;
6610         cmdline_fixed_string_t bonding;
6611         cmdline_fixed_string_t agg_mode;
6612         uint16_t port_num;
6613         cmdline_fixed_string_t policy;
6614 };
6615
6616
6617 static void
6618 cmd_set_bonding_agg_mode(void *parsed_result,
6619                 __rte_unused struct cmdline *cl,
6620                 __rte_unused void *data)
6621 {
6622         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6623         uint8_t policy = AGG_BANDWIDTH;
6624
6625         if (!strcmp(res->policy, "bandwidth"))
6626                 policy = AGG_BANDWIDTH;
6627         else if (!strcmp(res->policy, "stable"))
6628                 policy = AGG_STABLE;
6629         else if (!strcmp(res->policy, "count"))
6630                 policy = AGG_COUNT;
6631
6632         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6633 }
6634
6635
6636 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6637         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6638                                 set, "set");
6639 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6640         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6641                                 bonding, "bonding");
6642
6643 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6644         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6645                                 agg_mode, "agg_mode");
6646
6647 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6648         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6649                                 port_num, UINT16);
6650
6651 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6652         TOKEN_STRING_INITIALIZER(
6653                         struct cmd_set_bonding_balance_xmit_policy_result,
6654                 policy, "stable#bandwidth#count");
6655
6656 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6657         .f = cmd_set_bonding_agg_mode,
6658         .data = (void *) 0,
6659         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6660         .tokens = {
6661                         (void *)&cmd_set_bonding_agg_mode_set,
6662                         (void *)&cmd_set_bonding_agg_mode_bonding,
6663                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6664                         (void *)&cmd_set_bonding_agg_mode_portnum,
6665                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6666                         NULL
6667                 }
6668 };
6669
6670
6671 #endif /* RTE_NET_BOND */
6672
6673 /* *** SET FORWARDING MODE *** */
6674 struct cmd_set_fwd_mode_result {
6675         cmdline_fixed_string_t set;
6676         cmdline_fixed_string_t fwd;
6677         cmdline_fixed_string_t mode;
6678 };
6679
6680 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6681                                     __rte_unused struct cmdline *cl,
6682                                     __rte_unused void *data)
6683 {
6684         struct cmd_set_fwd_mode_result *res = parsed_result;
6685
6686         retry_enabled = 0;
6687         set_pkt_forwarding_mode(res->mode);
6688 }
6689
6690 cmdline_parse_token_string_t cmd_setfwd_set =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6692 cmdline_parse_token_string_t cmd_setfwd_fwd =
6693         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6694 cmdline_parse_token_string_t cmd_setfwd_mode =
6695         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6696                 "" /* defined at init */);
6697
6698 cmdline_parse_inst_t cmd_set_fwd_mode = {
6699         .f = cmd_set_fwd_mode_parsed,
6700         .data = NULL,
6701         .help_str = NULL, /* defined at init */
6702         .tokens = {
6703                 (void *)&cmd_setfwd_set,
6704                 (void *)&cmd_setfwd_fwd,
6705                 (void *)&cmd_setfwd_mode,
6706                 NULL,
6707         },
6708 };
6709
6710 static void cmd_set_fwd_mode_init(void)
6711 {
6712         char *modes, *c;
6713         static char token[128];
6714         static char help[256];
6715         cmdline_parse_token_string_t *token_struct;
6716
6717         modes = list_pkt_forwarding_modes();
6718         snprintf(help, sizeof(help), "set fwd %s: "
6719                 "Set packet forwarding mode", modes);
6720         cmd_set_fwd_mode.help_str = help;
6721
6722         /* string token separator is # */
6723         for (c = token; *modes != '\0'; modes++)
6724                 if (*modes == '|')
6725                         *c++ = '#';
6726                 else
6727                         *c++ = *modes;
6728         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6729         token_struct->string_data.str = token;
6730 }
6731
6732 /* *** SET RETRY FORWARDING MODE *** */
6733 struct cmd_set_fwd_retry_mode_result {
6734         cmdline_fixed_string_t set;
6735         cmdline_fixed_string_t fwd;
6736         cmdline_fixed_string_t mode;
6737         cmdline_fixed_string_t retry;
6738 };
6739
6740 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6741                             __rte_unused struct cmdline *cl,
6742                             __rte_unused void *data)
6743 {
6744         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6745
6746         retry_enabled = 1;
6747         set_pkt_forwarding_mode(res->mode);
6748 }
6749
6750 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6751         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6752                         set, "set");
6753 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6754         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6755                         fwd, "fwd");
6756 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6757         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6758                         mode,
6759                 "" /* defined at init */);
6760 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6761         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6762                         retry, "retry");
6763
6764 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6765         .f = cmd_set_fwd_retry_mode_parsed,
6766         .data = NULL,
6767         .help_str = NULL, /* defined at init */
6768         .tokens = {
6769                 (void *)&cmd_setfwd_retry_set,
6770                 (void *)&cmd_setfwd_retry_fwd,
6771                 (void *)&cmd_setfwd_retry_mode,
6772                 (void *)&cmd_setfwd_retry_retry,
6773                 NULL,
6774         },
6775 };
6776
6777 static void cmd_set_fwd_retry_mode_init(void)
6778 {
6779         char *modes, *c;
6780         static char token[128];
6781         static char help[256];
6782         cmdline_parse_token_string_t *token_struct;
6783
6784         modes = list_pkt_forwarding_retry_modes();
6785         snprintf(help, sizeof(help), "set fwd %s retry: "
6786                 "Set packet forwarding mode with retry", modes);
6787         cmd_set_fwd_retry_mode.help_str = help;
6788
6789         /* string token separator is # */
6790         for (c = token; *modes != '\0'; modes++)
6791                 if (*modes == '|')
6792                         *c++ = '#';
6793                 else
6794                         *c++ = *modes;
6795         token_struct = (cmdline_parse_token_string_t *)
6796                 cmd_set_fwd_retry_mode.tokens[2];
6797         token_struct->string_data.str = token;
6798 }
6799
6800 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6801 struct cmd_set_burst_tx_retry_result {
6802         cmdline_fixed_string_t set;
6803         cmdline_fixed_string_t burst;
6804         cmdline_fixed_string_t tx;
6805         cmdline_fixed_string_t delay;
6806         uint32_t time;
6807         cmdline_fixed_string_t retry;
6808         uint32_t retry_num;
6809 };
6810
6811 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6812                                         __rte_unused struct cmdline *cl,
6813                                         __rte_unused void *data)
6814 {
6815         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6816
6817         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6818                 && !strcmp(res->tx, "tx")) {
6819                 if (!strcmp(res->delay, "delay"))
6820                         burst_tx_delay_time = res->time;
6821                 if (!strcmp(res->retry, "retry"))
6822                         burst_tx_retry_num = res->retry_num;
6823         }
6824
6825 }
6826
6827 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6828         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6829 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6830         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6831                                  "burst");
6832 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6833         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6834 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6835         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6836 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6837         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6838 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6839         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6840 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6841         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6842
6843 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6844         .f = cmd_set_burst_tx_retry_parsed,
6845         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6846         .tokens = {
6847                 (void *)&cmd_set_burst_tx_retry_set,
6848                 (void *)&cmd_set_burst_tx_retry_burst,
6849                 (void *)&cmd_set_burst_tx_retry_tx,
6850                 (void *)&cmd_set_burst_tx_retry_delay,
6851                 (void *)&cmd_set_burst_tx_retry_time,
6852                 (void *)&cmd_set_burst_tx_retry_retry,
6853                 (void *)&cmd_set_burst_tx_retry_retry_num,
6854                 NULL,
6855         },
6856 };
6857
6858 /* *** SET PROMISC MODE *** */
6859 struct cmd_set_promisc_mode_result {
6860         cmdline_fixed_string_t set;
6861         cmdline_fixed_string_t promisc;
6862         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6863         uint16_t port_num;               /* valid if "allports" argument == 0 */
6864         cmdline_fixed_string_t mode;
6865 };
6866
6867 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6868                                         __rte_unused struct cmdline *cl,
6869                                         void *allports)
6870 {
6871         struct cmd_set_promisc_mode_result *res = parsed_result;
6872         int enable;
6873         portid_t i;
6874
6875         if (!strcmp(res->mode, "on"))
6876                 enable = 1;
6877         else
6878                 enable = 0;
6879
6880         /* all ports */
6881         if (allports) {
6882                 RTE_ETH_FOREACH_DEV(i)
6883                         eth_set_promisc_mode(i, enable);
6884         } else {
6885                 eth_set_promisc_mode(res->port_num, enable);
6886         }
6887 }
6888
6889 cmdline_parse_token_string_t cmd_setpromisc_set =
6890         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6891 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6892         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6893                                  "promisc");
6894 cmdline_parse_token_string_t cmd_setpromisc_portall =
6895         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6896                                  "all");
6897 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6898         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6899                               UINT16);
6900 cmdline_parse_token_string_t cmd_setpromisc_mode =
6901         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6902                                  "on#off");
6903
6904 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6905         .f = cmd_set_promisc_mode_parsed,
6906         .data = (void *)1,
6907         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6908         .tokens = {
6909                 (void *)&cmd_setpromisc_set,
6910                 (void *)&cmd_setpromisc_promisc,
6911                 (void *)&cmd_setpromisc_portall,
6912                 (void *)&cmd_setpromisc_mode,
6913                 NULL,
6914         },
6915 };
6916
6917 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6918         .f = cmd_set_promisc_mode_parsed,
6919         .data = (void *)0,
6920         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6921         .tokens = {
6922                 (void *)&cmd_setpromisc_set,
6923                 (void *)&cmd_setpromisc_promisc,
6924                 (void *)&cmd_setpromisc_portnum,
6925                 (void *)&cmd_setpromisc_mode,
6926                 NULL,
6927         },
6928 };
6929
6930 /* *** SET ALLMULTI MODE *** */
6931 struct cmd_set_allmulti_mode_result {
6932         cmdline_fixed_string_t set;
6933         cmdline_fixed_string_t allmulti;
6934         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6935         uint16_t port_num;               /* valid if "allports" argument == 0 */
6936         cmdline_fixed_string_t mode;
6937 };
6938
6939 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6940                                         __rte_unused struct cmdline *cl,
6941                                         void *allports)
6942 {
6943         struct cmd_set_allmulti_mode_result *res = parsed_result;
6944         int enable;
6945         portid_t i;
6946
6947         if (!strcmp(res->mode, "on"))
6948                 enable = 1;
6949         else
6950                 enable = 0;
6951
6952         /* all ports */
6953         if (allports) {
6954                 RTE_ETH_FOREACH_DEV(i) {
6955                         eth_set_allmulticast_mode(i, enable);
6956                 }
6957         }
6958         else {
6959                 eth_set_allmulticast_mode(res->port_num, enable);
6960         }
6961 }
6962
6963 cmdline_parse_token_string_t cmd_setallmulti_set =
6964         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6965 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6966         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6967                                  "allmulti");
6968 cmdline_parse_token_string_t cmd_setallmulti_portall =
6969         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6970                                  "all");
6971 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6972         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6973                               UINT16);
6974 cmdline_parse_token_string_t cmd_setallmulti_mode =
6975         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6976                                  "on#off");
6977
6978 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6979         .f = cmd_set_allmulti_mode_parsed,
6980         .data = (void *)1,
6981         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6982         .tokens = {
6983                 (void *)&cmd_setallmulti_set,
6984                 (void *)&cmd_setallmulti_allmulti,
6985                 (void *)&cmd_setallmulti_portall,
6986                 (void *)&cmd_setallmulti_mode,
6987                 NULL,
6988         },
6989 };
6990
6991 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6992         .f = cmd_set_allmulti_mode_parsed,
6993         .data = (void *)0,
6994         .help_str = "set allmulti <port_id> on|off: "
6995                 "Set allmulti mode on port_id",
6996         .tokens = {
6997                 (void *)&cmd_setallmulti_set,
6998                 (void *)&cmd_setallmulti_allmulti,
6999                 (void *)&cmd_setallmulti_portnum,
7000                 (void *)&cmd_setallmulti_mode,
7001                 NULL,
7002         },
7003 };
7004
7005 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
7006 struct cmd_link_flow_ctrl_set_result {
7007         cmdline_fixed_string_t set;
7008         cmdline_fixed_string_t flow_ctrl;
7009         cmdline_fixed_string_t rx;
7010         cmdline_fixed_string_t rx_lfc_mode;
7011         cmdline_fixed_string_t tx;
7012         cmdline_fixed_string_t tx_lfc_mode;
7013         cmdline_fixed_string_t mac_ctrl_frame_fwd;
7014         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
7015         cmdline_fixed_string_t autoneg_str;
7016         cmdline_fixed_string_t autoneg;
7017         cmdline_fixed_string_t hw_str;
7018         uint32_t high_water;
7019         cmdline_fixed_string_t lw_str;
7020         uint32_t low_water;
7021         cmdline_fixed_string_t pt_str;
7022         uint16_t pause_time;
7023         cmdline_fixed_string_t xon_str;
7024         uint16_t send_xon;
7025         portid_t port_id;
7026 };
7027
7028 cmdline_parse_token_string_t cmd_lfc_set_set =
7029         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7030                                 set, "set");
7031 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
7032         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7033                                 flow_ctrl, "flow_ctrl");
7034 cmdline_parse_token_string_t cmd_lfc_set_rx =
7035         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7036                                 rx, "rx");
7037 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
7038         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7039                                 rx_lfc_mode, "on#off");
7040 cmdline_parse_token_string_t cmd_lfc_set_tx =
7041         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7042                                 tx, "tx");
7043 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
7044         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7045                                 tx_lfc_mode, "on#off");
7046 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
7047         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7048                                 hw_str, "high_water");
7049 cmdline_parse_token_num_t cmd_lfc_set_high_water =
7050         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7051                                 high_water, UINT32);
7052 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7053         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7054                                 lw_str, "low_water");
7055 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7056         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7057                                 low_water, UINT32);
7058 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7059         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7060                                 pt_str, "pause_time");
7061 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7062         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7063                                 pause_time, UINT16);
7064 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7065         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7066                                 xon_str, "send_xon");
7067 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7068         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7069                                 send_xon, UINT16);
7070 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7071         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7072                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7073 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7074         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7075                                 mac_ctrl_frame_fwd_mode, "on#off");
7076 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7077         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7078                                 autoneg_str, "autoneg");
7079 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7080         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7081                                 autoneg, "on#off");
7082 cmdline_parse_token_num_t cmd_lfc_set_portid =
7083         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7084                                 port_id, UINT16);
7085
7086 /* forward declaration */
7087 static void
7088 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7089                               void *data);
7090
7091 cmdline_parse_inst_t cmd_link_flow_control_set = {
7092         .f = cmd_link_flow_ctrl_set_parsed,
7093         .data = NULL,
7094         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7095                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7096                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7097         .tokens = {
7098                 (void *)&cmd_lfc_set_set,
7099                 (void *)&cmd_lfc_set_flow_ctrl,
7100                 (void *)&cmd_lfc_set_rx,
7101                 (void *)&cmd_lfc_set_rx_mode,
7102                 (void *)&cmd_lfc_set_tx,
7103                 (void *)&cmd_lfc_set_tx_mode,
7104                 (void *)&cmd_lfc_set_high_water,
7105                 (void *)&cmd_lfc_set_low_water,
7106                 (void *)&cmd_lfc_set_pause_time,
7107                 (void *)&cmd_lfc_set_send_xon,
7108                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7109                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7110                 (void *)&cmd_lfc_set_autoneg_str,
7111                 (void *)&cmd_lfc_set_autoneg,
7112                 (void *)&cmd_lfc_set_portid,
7113                 NULL,
7114         },
7115 };
7116
7117 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7118         .f = cmd_link_flow_ctrl_set_parsed,
7119         .data = (void *)&cmd_link_flow_control_set_rx,
7120         .help_str = "set flow_ctrl rx on|off <port_id>: "
7121                 "Change rx flow control parameter",
7122         .tokens = {
7123                 (void *)&cmd_lfc_set_set,
7124                 (void *)&cmd_lfc_set_flow_ctrl,
7125                 (void *)&cmd_lfc_set_rx,
7126                 (void *)&cmd_lfc_set_rx_mode,
7127                 (void *)&cmd_lfc_set_portid,
7128                 NULL,
7129         },
7130 };
7131
7132 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7133         .f = cmd_link_flow_ctrl_set_parsed,
7134         .data = (void *)&cmd_link_flow_control_set_tx,
7135         .help_str = "set flow_ctrl tx on|off <port_id>: "
7136                 "Change tx flow control parameter",
7137         .tokens = {
7138                 (void *)&cmd_lfc_set_set,
7139                 (void *)&cmd_lfc_set_flow_ctrl,
7140                 (void *)&cmd_lfc_set_tx,
7141                 (void *)&cmd_lfc_set_tx_mode,
7142                 (void *)&cmd_lfc_set_portid,
7143                 NULL,
7144         },
7145 };
7146
7147 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7148         .f = cmd_link_flow_ctrl_set_parsed,
7149         .data = (void *)&cmd_link_flow_control_set_hw,
7150         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7151                 "Change high water flow control parameter",
7152         .tokens = {
7153                 (void *)&cmd_lfc_set_set,
7154                 (void *)&cmd_lfc_set_flow_ctrl,
7155                 (void *)&cmd_lfc_set_high_water_str,
7156                 (void *)&cmd_lfc_set_high_water,
7157                 (void *)&cmd_lfc_set_portid,
7158                 NULL,
7159         },
7160 };
7161
7162 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7163         .f = cmd_link_flow_ctrl_set_parsed,
7164         .data = (void *)&cmd_link_flow_control_set_lw,
7165         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7166                 "Change low water flow control parameter",
7167         .tokens = {
7168                 (void *)&cmd_lfc_set_set,
7169                 (void *)&cmd_lfc_set_flow_ctrl,
7170                 (void *)&cmd_lfc_set_low_water_str,
7171                 (void *)&cmd_lfc_set_low_water,
7172                 (void *)&cmd_lfc_set_portid,
7173                 NULL,
7174         },
7175 };
7176
7177 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7178         .f = cmd_link_flow_ctrl_set_parsed,
7179         .data = (void *)&cmd_link_flow_control_set_pt,
7180         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7181                 "Change pause time flow control parameter",
7182         .tokens = {
7183                 (void *)&cmd_lfc_set_set,
7184                 (void *)&cmd_lfc_set_flow_ctrl,
7185                 (void *)&cmd_lfc_set_pause_time_str,
7186                 (void *)&cmd_lfc_set_pause_time,
7187                 (void *)&cmd_lfc_set_portid,
7188                 NULL,
7189         },
7190 };
7191
7192 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7193         .f = cmd_link_flow_ctrl_set_parsed,
7194         .data = (void *)&cmd_link_flow_control_set_xon,
7195         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7196                 "Change send_xon flow control parameter",
7197         .tokens = {
7198                 (void *)&cmd_lfc_set_set,
7199                 (void *)&cmd_lfc_set_flow_ctrl,
7200                 (void *)&cmd_lfc_set_send_xon_str,
7201                 (void *)&cmd_lfc_set_send_xon,
7202                 (void *)&cmd_lfc_set_portid,
7203                 NULL,
7204         },
7205 };
7206
7207 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7208         .f = cmd_link_flow_ctrl_set_parsed,
7209         .data = (void *)&cmd_link_flow_control_set_macfwd,
7210         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7211                 "Change mac ctrl fwd flow control parameter",
7212         .tokens = {
7213                 (void *)&cmd_lfc_set_set,
7214                 (void *)&cmd_lfc_set_flow_ctrl,
7215                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7216                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7217                 (void *)&cmd_lfc_set_portid,
7218                 NULL,
7219         },
7220 };
7221
7222 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7223         .f = cmd_link_flow_ctrl_set_parsed,
7224         .data = (void *)&cmd_link_flow_control_set_autoneg,
7225         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7226                 "Change autoneg flow control parameter",
7227         .tokens = {
7228                 (void *)&cmd_lfc_set_set,
7229                 (void *)&cmd_lfc_set_flow_ctrl,
7230                 (void *)&cmd_lfc_set_autoneg_str,
7231                 (void *)&cmd_lfc_set_autoneg,
7232                 (void *)&cmd_lfc_set_portid,
7233                 NULL,
7234         },
7235 };
7236
7237 static void
7238 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7239                               __rte_unused struct cmdline *cl,
7240                               void *data)
7241 {
7242         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7243         cmdline_parse_inst_t *cmd = data;
7244         struct rte_eth_fc_conf fc_conf;
7245         int rx_fc_en = 0;
7246         int tx_fc_en = 0;
7247         int ret;
7248
7249         /*
7250          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7251          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7252          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7253          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7254          */
7255         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7256                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7257         };
7258
7259         /* Partial command line, retrieve current configuration */
7260         if (cmd) {
7261                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7262                 if (ret != 0) {
7263                         printf("cannot get current flow ctrl parameters, return"
7264                                "code = %d\n", ret);
7265                         return;
7266                 }
7267
7268                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7269                     (fc_conf.mode == RTE_FC_FULL))
7270                         rx_fc_en = 1;
7271                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7272                     (fc_conf.mode == RTE_FC_FULL))
7273                         tx_fc_en = 1;
7274         }
7275
7276         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7277                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7278
7279         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7280                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7281
7282         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7283
7284         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7285                 fc_conf.high_water = res->high_water;
7286
7287         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7288                 fc_conf.low_water = res->low_water;
7289
7290         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7291                 fc_conf.pause_time = res->pause_time;
7292
7293         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7294                 fc_conf.send_xon = res->send_xon;
7295
7296         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7297                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7298                         fc_conf.mac_ctrl_frame_fwd = 1;
7299                 else
7300                         fc_conf.mac_ctrl_frame_fwd = 0;
7301         }
7302
7303         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7304                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7305
7306         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7307         if (ret != 0)
7308                 printf("bad flow contrl parameter, return code = %d \n", ret);
7309 }
7310
7311 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7312 struct cmd_priority_flow_ctrl_set_result {
7313         cmdline_fixed_string_t set;
7314         cmdline_fixed_string_t pfc_ctrl;
7315         cmdline_fixed_string_t rx;
7316         cmdline_fixed_string_t rx_pfc_mode;
7317         cmdline_fixed_string_t tx;
7318         cmdline_fixed_string_t tx_pfc_mode;
7319         uint32_t high_water;
7320         uint32_t low_water;
7321         uint16_t pause_time;
7322         uint8_t  priority;
7323         portid_t port_id;
7324 };
7325
7326 static void
7327 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7328                        __rte_unused struct cmdline *cl,
7329                        __rte_unused void *data)
7330 {
7331         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7332         struct rte_eth_pfc_conf pfc_conf;
7333         int rx_fc_enable, tx_fc_enable;
7334         int ret;
7335
7336         /*
7337          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7338          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7339          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7340          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7341          */
7342         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7343                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7344         };
7345
7346         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7347         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7348         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7349         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7350         pfc_conf.fc.high_water = res->high_water;
7351         pfc_conf.fc.low_water  = res->low_water;
7352         pfc_conf.fc.pause_time = res->pause_time;
7353         pfc_conf.priority      = res->priority;
7354
7355         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7356         if (ret != 0)
7357                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7358 }
7359
7360 cmdline_parse_token_string_t cmd_pfc_set_set =
7361         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7362                                 set, "set");
7363 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7364         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7365                                 pfc_ctrl, "pfc_ctrl");
7366 cmdline_parse_token_string_t cmd_pfc_set_rx =
7367         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7368                                 rx, "rx");
7369 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7370         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7371                                 rx_pfc_mode, "on#off");
7372 cmdline_parse_token_string_t cmd_pfc_set_tx =
7373         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7374                                 tx, "tx");
7375 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7376         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7377                                 tx_pfc_mode, "on#off");
7378 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7379         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7380                                 high_water, UINT32);
7381 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7382         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7383                                 low_water, UINT32);
7384 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7385         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7386                                 pause_time, UINT16);
7387 cmdline_parse_token_num_t cmd_pfc_set_priority =
7388         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7389                                 priority, UINT8);
7390 cmdline_parse_token_num_t cmd_pfc_set_portid =
7391         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7392                                 port_id, UINT16);
7393
7394 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7395         .f = cmd_priority_flow_ctrl_set_parsed,
7396         .data = NULL,
7397         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7398                 "<pause_time> <priority> <port_id>: "
7399                 "Configure the Ethernet priority flow control",
7400         .tokens = {
7401                 (void *)&cmd_pfc_set_set,
7402                 (void *)&cmd_pfc_set_flow_ctrl,
7403                 (void *)&cmd_pfc_set_rx,
7404                 (void *)&cmd_pfc_set_rx_mode,
7405                 (void *)&cmd_pfc_set_tx,
7406                 (void *)&cmd_pfc_set_tx_mode,
7407                 (void *)&cmd_pfc_set_high_water,
7408                 (void *)&cmd_pfc_set_low_water,
7409                 (void *)&cmd_pfc_set_pause_time,
7410                 (void *)&cmd_pfc_set_priority,
7411                 (void *)&cmd_pfc_set_portid,
7412                 NULL,
7413         },
7414 };
7415
7416 /* *** RESET CONFIGURATION *** */
7417 struct cmd_reset_result {
7418         cmdline_fixed_string_t reset;
7419         cmdline_fixed_string_t def;
7420 };
7421
7422 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7423                              struct cmdline *cl,
7424                              __rte_unused void *data)
7425 {
7426         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7427         set_def_fwd_config();
7428 }
7429
7430 cmdline_parse_token_string_t cmd_reset_set =
7431         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7432 cmdline_parse_token_string_t cmd_reset_def =
7433         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7434                                  "default");
7435
7436 cmdline_parse_inst_t cmd_reset = {
7437         .f = cmd_reset_parsed,
7438         .data = NULL,
7439         .help_str = "set default: Reset default forwarding configuration",
7440         .tokens = {
7441                 (void *)&cmd_reset_set,
7442                 (void *)&cmd_reset_def,
7443                 NULL,
7444         },
7445 };
7446
7447 /* *** START FORWARDING *** */
7448 struct cmd_start_result {
7449         cmdline_fixed_string_t start;
7450 };
7451
7452 cmdline_parse_token_string_t cmd_start_start =
7453         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7454
7455 static void cmd_start_parsed(__rte_unused void *parsed_result,
7456                              __rte_unused struct cmdline *cl,
7457                              __rte_unused void *data)
7458 {
7459         start_packet_forwarding(0);
7460 }
7461
7462 cmdline_parse_inst_t cmd_start = {
7463         .f = cmd_start_parsed,
7464         .data = NULL,
7465         .help_str = "start: Start packet forwarding",
7466         .tokens = {
7467                 (void *)&cmd_start_start,
7468                 NULL,
7469         },
7470 };
7471
7472 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7473 struct cmd_start_tx_first_result {
7474         cmdline_fixed_string_t start;
7475         cmdline_fixed_string_t tx_first;
7476 };
7477
7478 static void
7479 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7480                           __rte_unused struct cmdline *cl,
7481                           __rte_unused void *data)
7482 {
7483         start_packet_forwarding(1);
7484 }
7485
7486 cmdline_parse_token_string_t cmd_start_tx_first_start =
7487         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7488                                  "start");
7489 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7490         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7491                                  tx_first, "tx_first");
7492
7493 cmdline_parse_inst_t cmd_start_tx_first = {
7494         .f = cmd_start_tx_first_parsed,
7495         .data = NULL,
7496         .help_str = "start tx_first: Start packet forwarding, "
7497                 "after sending 1 burst of packets",
7498         .tokens = {
7499                 (void *)&cmd_start_tx_first_start,
7500                 (void *)&cmd_start_tx_first_tx_first,
7501                 NULL,
7502         },
7503 };
7504
7505 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7506 struct cmd_start_tx_first_n_result {
7507         cmdline_fixed_string_t start;
7508         cmdline_fixed_string_t tx_first;
7509         uint32_t tx_num;
7510 };
7511
7512 static void
7513 cmd_start_tx_first_n_parsed(void *parsed_result,
7514                           __rte_unused struct cmdline *cl,
7515                           __rte_unused void *data)
7516 {
7517         struct cmd_start_tx_first_n_result *res = parsed_result;
7518
7519         start_packet_forwarding(res->tx_num);
7520 }
7521
7522 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7523         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7524                         start, "start");
7525 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7526         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7527                         tx_first, "tx_first");
7528 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7529         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7530                         tx_num, UINT32);
7531
7532 cmdline_parse_inst_t cmd_start_tx_first_n = {
7533         .f = cmd_start_tx_first_n_parsed,
7534         .data = NULL,
7535         .help_str = "start tx_first <num>: "
7536                 "packet forwarding, after sending <num> bursts of packets",
7537         .tokens = {
7538                 (void *)&cmd_start_tx_first_n_start,
7539                 (void *)&cmd_start_tx_first_n_tx_first,
7540                 (void *)&cmd_start_tx_first_n_tx_num,
7541                 NULL,
7542         },
7543 };
7544
7545 /* *** SET LINK UP *** */
7546 struct cmd_set_link_up_result {
7547         cmdline_fixed_string_t set;
7548         cmdline_fixed_string_t link_up;
7549         cmdline_fixed_string_t port;
7550         portid_t port_id;
7551 };
7552
7553 cmdline_parse_token_string_t cmd_set_link_up_set =
7554         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7555 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7556         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7557                                 "link-up");
7558 cmdline_parse_token_string_t cmd_set_link_up_port =
7559         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7560 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7561         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7562
7563 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7564                              __rte_unused struct cmdline *cl,
7565                              __rte_unused void *data)
7566 {
7567         struct cmd_set_link_up_result *res = parsed_result;
7568         dev_set_link_up(res->port_id);
7569 }
7570
7571 cmdline_parse_inst_t cmd_set_link_up = {
7572         .f = cmd_set_link_up_parsed,
7573         .data = NULL,
7574         .help_str = "set link-up port <port id>",
7575         .tokens = {
7576                 (void *)&cmd_set_link_up_set,
7577                 (void *)&cmd_set_link_up_link_up,
7578                 (void *)&cmd_set_link_up_port,
7579                 (void *)&cmd_set_link_up_port_id,
7580                 NULL,
7581         },
7582 };
7583
7584 /* *** SET LINK DOWN *** */
7585 struct cmd_set_link_down_result {
7586         cmdline_fixed_string_t set;
7587         cmdline_fixed_string_t link_down;
7588         cmdline_fixed_string_t port;
7589         portid_t port_id;
7590 };
7591
7592 cmdline_parse_token_string_t cmd_set_link_down_set =
7593         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7594 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7595         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7596                                 "link-down");
7597 cmdline_parse_token_string_t cmd_set_link_down_port =
7598         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7599 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7600         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7601
7602 static void cmd_set_link_down_parsed(
7603                                 __rte_unused void *parsed_result,
7604                                 __rte_unused struct cmdline *cl,
7605                                 __rte_unused void *data)
7606 {
7607         struct cmd_set_link_down_result *res = parsed_result;
7608         dev_set_link_down(res->port_id);
7609 }
7610
7611 cmdline_parse_inst_t cmd_set_link_down = {
7612         .f = cmd_set_link_down_parsed,
7613         .data = NULL,
7614         .help_str = "set link-down port <port id>",
7615         .tokens = {
7616                 (void *)&cmd_set_link_down_set,
7617                 (void *)&cmd_set_link_down_link_down,
7618                 (void *)&cmd_set_link_down_port,
7619                 (void *)&cmd_set_link_down_port_id,
7620                 NULL,
7621         },
7622 };
7623
7624 /* *** SHOW CFG *** */
7625 struct cmd_showcfg_result {
7626         cmdline_fixed_string_t show;
7627         cmdline_fixed_string_t cfg;
7628         cmdline_fixed_string_t what;
7629 };
7630
7631 static void cmd_showcfg_parsed(void *parsed_result,
7632                                __rte_unused struct cmdline *cl,
7633                                __rte_unused void *data)
7634 {
7635         struct cmd_showcfg_result *res = parsed_result;
7636         if (!strcmp(res->what, "rxtx"))
7637                 rxtx_config_display();
7638         else if (!strcmp(res->what, "cores"))
7639                 fwd_lcores_config_display();
7640         else if (!strcmp(res->what, "fwd"))
7641                 pkt_fwd_config_display(&cur_fwd_config);
7642         else if (!strcmp(res->what, "rxoffs"))
7643                 show_rx_pkt_offsets();
7644         else if (!strcmp(res->what, "rxpkts"))
7645                 show_rx_pkt_segments();
7646         else if (!strcmp(res->what, "txpkts"))
7647                 show_tx_pkt_segments();
7648         else if (!strcmp(res->what, "txtimes"))
7649                 show_tx_pkt_times();
7650 }
7651
7652 cmdline_parse_token_string_t cmd_showcfg_show =
7653         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7654 cmdline_parse_token_string_t cmd_showcfg_port =
7655         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7656 cmdline_parse_token_string_t cmd_showcfg_what =
7657         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7658                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7659
7660 cmdline_parse_inst_t cmd_showcfg = {
7661         .f = cmd_showcfg_parsed,
7662         .data = NULL,
7663         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7664         .tokens = {
7665                 (void *)&cmd_showcfg_show,
7666                 (void *)&cmd_showcfg_port,
7667                 (void *)&cmd_showcfg_what,
7668                 NULL,
7669         },
7670 };
7671
7672 /* *** SHOW ALL PORT INFO *** */
7673 struct cmd_showportall_result {
7674         cmdline_fixed_string_t show;
7675         cmdline_fixed_string_t port;
7676         cmdline_fixed_string_t what;
7677         cmdline_fixed_string_t all;
7678 };
7679
7680 static void cmd_showportall_parsed(void *parsed_result,
7681                                 __rte_unused struct cmdline *cl,
7682                                 __rte_unused void *data)
7683 {
7684         portid_t i;
7685
7686         struct cmd_showportall_result *res = parsed_result;
7687         if (!strcmp(res->show, "clear")) {
7688                 if (!strcmp(res->what, "stats"))
7689                         RTE_ETH_FOREACH_DEV(i)
7690                                 nic_stats_clear(i);
7691                 else if (!strcmp(res->what, "xstats"))
7692                         RTE_ETH_FOREACH_DEV(i)
7693                                 nic_xstats_clear(i);
7694         } else if (!strcmp(res->what, "info"))
7695                 RTE_ETH_FOREACH_DEV(i)
7696                         port_infos_display(i);
7697         else if (!strcmp(res->what, "summary")) {
7698                 port_summary_header_display();
7699                 RTE_ETH_FOREACH_DEV(i)
7700                         port_summary_display(i);
7701         }
7702         else if (!strcmp(res->what, "stats"))
7703                 RTE_ETH_FOREACH_DEV(i)
7704                         nic_stats_display(i);
7705         else if (!strcmp(res->what, "xstats"))
7706                 RTE_ETH_FOREACH_DEV(i)
7707                         nic_xstats_display(i);
7708         else if (!strcmp(res->what, "fdir"))
7709                 RTE_ETH_FOREACH_DEV(i)
7710                         fdir_get_infos(i);
7711         else if (!strcmp(res->what, "stat_qmap"))
7712                 RTE_ETH_FOREACH_DEV(i)
7713                         nic_stats_mapping_display(i);
7714         else if (!strcmp(res->what, "dcb_tc"))
7715                 RTE_ETH_FOREACH_DEV(i)
7716                         port_dcb_info_display(i);
7717         else if (!strcmp(res->what, "cap"))
7718                 RTE_ETH_FOREACH_DEV(i)
7719                         port_offload_cap_display(i);
7720 }
7721
7722 cmdline_parse_token_string_t cmd_showportall_show =
7723         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7724                                  "show#clear");
7725 cmdline_parse_token_string_t cmd_showportall_port =
7726         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7727 cmdline_parse_token_string_t cmd_showportall_what =
7728         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7729                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7730 cmdline_parse_token_string_t cmd_showportall_all =
7731         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7732 cmdline_parse_inst_t cmd_showportall = {
7733         .f = cmd_showportall_parsed,
7734         .data = NULL,
7735         .help_str = "show|clear port "
7736                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7737         .tokens = {
7738                 (void *)&cmd_showportall_show,
7739                 (void *)&cmd_showportall_port,
7740                 (void *)&cmd_showportall_what,
7741                 (void *)&cmd_showportall_all,
7742                 NULL,
7743         },
7744 };
7745
7746 /* *** SHOW PORT INFO *** */
7747 struct cmd_showport_result {
7748         cmdline_fixed_string_t show;
7749         cmdline_fixed_string_t port;
7750         cmdline_fixed_string_t what;
7751         uint16_t portnum;
7752 };
7753
7754 static void cmd_showport_parsed(void *parsed_result,
7755                                 __rte_unused struct cmdline *cl,
7756                                 __rte_unused void *data)
7757 {
7758         struct cmd_showport_result *res = parsed_result;
7759         if (!strcmp(res->show, "clear")) {
7760                 if (!strcmp(res->what, "stats"))
7761                         nic_stats_clear(res->portnum);
7762                 else if (!strcmp(res->what, "xstats"))
7763                         nic_xstats_clear(res->portnum);
7764         } else if (!strcmp(res->what, "info"))
7765                 port_infos_display(res->portnum);
7766         else if (!strcmp(res->what, "summary")) {
7767                 port_summary_header_display();
7768                 port_summary_display(res->portnum);
7769         }
7770         else if (!strcmp(res->what, "stats"))
7771                 nic_stats_display(res->portnum);
7772         else if (!strcmp(res->what, "xstats"))
7773                 nic_xstats_display(res->portnum);
7774         else if (!strcmp(res->what, "fdir"))
7775                  fdir_get_infos(res->portnum);
7776         else if (!strcmp(res->what, "stat_qmap"))
7777                 nic_stats_mapping_display(res->portnum);
7778         else if (!strcmp(res->what, "dcb_tc"))
7779                 port_dcb_info_display(res->portnum);
7780         else if (!strcmp(res->what, "cap"))
7781                 port_offload_cap_display(res->portnum);
7782 }
7783
7784 cmdline_parse_token_string_t cmd_showport_show =
7785         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7786                                  "show#clear");
7787 cmdline_parse_token_string_t cmd_showport_port =
7788         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7789 cmdline_parse_token_string_t cmd_showport_what =
7790         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7791                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7792 cmdline_parse_token_num_t cmd_showport_portnum =
7793         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7794
7795 cmdline_parse_inst_t cmd_showport = {
7796         .f = cmd_showport_parsed,
7797         .data = NULL,
7798         .help_str = "show|clear port "
7799                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7800                 "<port_id>",
7801         .tokens = {
7802                 (void *)&cmd_showport_show,
7803                 (void *)&cmd_showport_port,
7804                 (void *)&cmd_showport_what,
7805                 (void *)&cmd_showport_portnum,
7806                 NULL,
7807         },
7808 };
7809
7810 /* *** SHOW DEVICE INFO *** */
7811 struct cmd_showdevice_result {
7812         cmdline_fixed_string_t show;
7813         cmdline_fixed_string_t device;
7814         cmdline_fixed_string_t what;
7815         cmdline_fixed_string_t identifier;
7816 };
7817
7818 static void cmd_showdevice_parsed(void *parsed_result,
7819                                 __rte_unused struct cmdline *cl,
7820                                 __rte_unused void *data)
7821 {
7822         struct cmd_showdevice_result *res = parsed_result;
7823         if (!strcmp(res->what, "info")) {
7824                 if (!strcmp(res->identifier, "all"))
7825                         device_infos_display(NULL);
7826                 else
7827                         device_infos_display(res->identifier);
7828         }
7829 }
7830
7831 cmdline_parse_token_string_t cmd_showdevice_show =
7832         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7833                                  "show");
7834 cmdline_parse_token_string_t cmd_showdevice_device =
7835         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7836 cmdline_parse_token_string_t cmd_showdevice_what =
7837         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7838                                  "info");
7839 cmdline_parse_token_string_t cmd_showdevice_identifier =
7840         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7841                         identifier, NULL);
7842
7843 cmdline_parse_inst_t cmd_showdevice = {
7844         .f = cmd_showdevice_parsed,
7845         .data = NULL,
7846         .help_str = "show device info <identifier>|all",
7847         .tokens = {
7848                 (void *)&cmd_showdevice_show,
7849                 (void *)&cmd_showdevice_device,
7850                 (void *)&cmd_showdevice_what,
7851                 (void *)&cmd_showdevice_identifier,
7852                 NULL,
7853         },
7854 };
7855
7856 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7857 struct cmd_showeeprom_result {
7858         cmdline_fixed_string_t show;
7859         cmdline_fixed_string_t port;
7860         uint16_t portnum;
7861         cmdline_fixed_string_t type;
7862 };
7863
7864 static void cmd_showeeprom_parsed(void *parsed_result,
7865                 __rte_unused struct cmdline *cl,
7866                 __rte_unused void *data)
7867 {
7868         struct cmd_showeeprom_result *res = parsed_result;
7869
7870         if (!strcmp(res->type, "eeprom"))
7871                 port_eeprom_display(res->portnum);
7872         else if (!strcmp(res->type, "module_eeprom"))
7873                 port_module_eeprom_display(res->portnum);
7874         else
7875                 printf("Unknown argument\n");
7876 }
7877
7878 cmdline_parse_token_string_t cmd_showeeprom_show =
7879         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7880 cmdline_parse_token_string_t cmd_showeeprom_port =
7881         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7882 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7883         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7884 cmdline_parse_token_string_t cmd_showeeprom_type =
7885         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7886
7887 cmdline_parse_inst_t cmd_showeeprom = {
7888         .f = cmd_showeeprom_parsed,
7889         .data = NULL,
7890         .help_str = "show port <port_id> module_eeprom|eeprom",
7891         .tokens = {
7892                 (void *)&cmd_showeeprom_show,
7893                 (void *)&cmd_showeeprom_port,
7894                 (void *)&cmd_showeeprom_portnum,
7895                 (void *)&cmd_showeeprom_type,
7896                 NULL,
7897         },
7898 };
7899
7900 /* *** SHOW QUEUE INFO *** */
7901 struct cmd_showqueue_result {
7902         cmdline_fixed_string_t show;
7903         cmdline_fixed_string_t type;
7904         cmdline_fixed_string_t what;
7905         uint16_t portnum;
7906         uint16_t queuenum;
7907 };
7908
7909 static void
7910 cmd_showqueue_parsed(void *parsed_result,
7911         __rte_unused struct cmdline *cl,
7912         __rte_unused void *data)
7913 {
7914         struct cmd_showqueue_result *res = parsed_result;
7915
7916         if (!strcmp(res->type, "rxq"))
7917                 rx_queue_infos_display(res->portnum, res->queuenum);
7918         else if (!strcmp(res->type, "txq"))
7919                 tx_queue_infos_display(res->portnum, res->queuenum);
7920 }
7921
7922 cmdline_parse_token_string_t cmd_showqueue_show =
7923         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7924 cmdline_parse_token_string_t cmd_showqueue_type =
7925         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7926 cmdline_parse_token_string_t cmd_showqueue_what =
7927         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7928 cmdline_parse_token_num_t cmd_showqueue_portnum =
7929         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7930 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7931         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7932
7933 cmdline_parse_inst_t cmd_showqueue = {
7934         .f = cmd_showqueue_parsed,
7935         .data = NULL,
7936         .help_str = "show rxq|txq info <port_id> <queue_id>",
7937         .tokens = {
7938                 (void *)&cmd_showqueue_show,
7939                 (void *)&cmd_showqueue_type,
7940                 (void *)&cmd_showqueue_what,
7941                 (void *)&cmd_showqueue_portnum,
7942                 (void *)&cmd_showqueue_queuenum,
7943                 NULL,
7944         },
7945 };
7946
7947 /* show/clear fwd engine statistics */
7948 struct fwd_result {
7949         cmdline_fixed_string_t action;
7950         cmdline_fixed_string_t fwd;
7951         cmdline_fixed_string_t stats;
7952         cmdline_fixed_string_t all;
7953 };
7954
7955 cmdline_parse_token_string_t cmd_fwd_action =
7956         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7957 cmdline_parse_token_string_t cmd_fwd_fwd =
7958         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7959 cmdline_parse_token_string_t cmd_fwd_stats =
7960         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7961 cmdline_parse_token_string_t cmd_fwd_all =
7962         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7963
7964 static void
7965 cmd_showfwdall_parsed(void *parsed_result,
7966                       __rte_unused struct cmdline *cl,
7967                       __rte_unused void *data)
7968 {
7969         struct fwd_result *res = parsed_result;
7970
7971         if (!strcmp(res->action, "show"))
7972                 fwd_stats_display();
7973         else
7974                 fwd_stats_reset();
7975 }
7976
7977 static cmdline_parse_inst_t cmd_showfwdall = {
7978         .f = cmd_showfwdall_parsed,
7979         .data = NULL,
7980         .help_str = "show|clear fwd stats all",
7981         .tokens = {
7982                 (void *)&cmd_fwd_action,
7983                 (void *)&cmd_fwd_fwd,
7984                 (void *)&cmd_fwd_stats,
7985                 (void *)&cmd_fwd_all,
7986                 NULL,
7987         },
7988 };
7989
7990 /* *** READ PORT REGISTER *** */
7991 struct cmd_read_reg_result {
7992         cmdline_fixed_string_t read;
7993         cmdline_fixed_string_t reg;
7994         portid_t port_id;
7995         uint32_t reg_off;
7996 };
7997
7998 static void
7999 cmd_read_reg_parsed(void *parsed_result,
8000                     __rte_unused struct cmdline *cl,
8001                     __rte_unused void *data)
8002 {
8003         struct cmd_read_reg_result *res = parsed_result;
8004         port_reg_display(res->port_id, res->reg_off);
8005 }
8006
8007 cmdline_parse_token_string_t cmd_read_reg_read =
8008         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
8009 cmdline_parse_token_string_t cmd_read_reg_reg =
8010         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
8011 cmdline_parse_token_num_t cmd_read_reg_port_id =
8012         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
8013 cmdline_parse_token_num_t cmd_read_reg_reg_off =
8014         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
8015
8016 cmdline_parse_inst_t cmd_read_reg = {
8017         .f = cmd_read_reg_parsed,
8018         .data = NULL,
8019         .help_str = "read reg <port_id> <reg_off>",
8020         .tokens = {
8021                 (void *)&cmd_read_reg_read,
8022                 (void *)&cmd_read_reg_reg,
8023                 (void *)&cmd_read_reg_port_id,
8024                 (void *)&cmd_read_reg_reg_off,
8025                 NULL,
8026         },
8027 };
8028
8029 /* *** READ PORT REGISTER BIT FIELD *** */
8030 struct cmd_read_reg_bit_field_result {
8031         cmdline_fixed_string_t read;
8032         cmdline_fixed_string_t regfield;
8033         portid_t port_id;
8034         uint32_t reg_off;
8035         uint8_t bit1_pos;
8036         uint8_t bit2_pos;
8037 };
8038
8039 static void
8040 cmd_read_reg_bit_field_parsed(void *parsed_result,
8041                               __rte_unused struct cmdline *cl,
8042                               __rte_unused void *data)
8043 {
8044         struct cmd_read_reg_bit_field_result *res = parsed_result;
8045         port_reg_bit_field_display(res->port_id, res->reg_off,
8046                                    res->bit1_pos, res->bit2_pos);
8047 }
8048
8049 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
8050         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
8051                                  "read");
8052 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
8053         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8054                                  regfield, "regfield");
8055 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8056         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8057                               UINT16);
8058 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8059         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8060                               UINT32);
8061 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8062         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8063                               UINT8);
8064 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8065         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8066                               UINT8);
8067
8068 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8069         .f = cmd_read_reg_bit_field_parsed,
8070         .data = NULL,
8071         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8072         "Read register bit field between bit_x and bit_y included",
8073         .tokens = {
8074                 (void *)&cmd_read_reg_bit_field_read,
8075                 (void *)&cmd_read_reg_bit_field_regfield,
8076                 (void *)&cmd_read_reg_bit_field_port_id,
8077                 (void *)&cmd_read_reg_bit_field_reg_off,
8078                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8079                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8080                 NULL,
8081         },
8082 };
8083
8084 /* *** READ PORT REGISTER BIT *** */
8085 struct cmd_read_reg_bit_result {
8086         cmdline_fixed_string_t read;
8087         cmdline_fixed_string_t regbit;
8088         portid_t port_id;
8089         uint32_t reg_off;
8090         uint8_t bit_pos;
8091 };
8092
8093 static void
8094 cmd_read_reg_bit_parsed(void *parsed_result,
8095                         __rte_unused struct cmdline *cl,
8096                         __rte_unused void *data)
8097 {
8098         struct cmd_read_reg_bit_result *res = parsed_result;
8099         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8100 }
8101
8102 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8103         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8104 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8105         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8106                                  regbit, "regbit");
8107 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8108         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8109 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8110         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8111 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8112         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8113
8114 cmdline_parse_inst_t cmd_read_reg_bit = {
8115         .f = cmd_read_reg_bit_parsed,
8116         .data = NULL,
8117         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8118         .tokens = {
8119                 (void *)&cmd_read_reg_bit_read,
8120                 (void *)&cmd_read_reg_bit_regbit,
8121                 (void *)&cmd_read_reg_bit_port_id,
8122                 (void *)&cmd_read_reg_bit_reg_off,
8123                 (void *)&cmd_read_reg_bit_bit_pos,
8124                 NULL,
8125         },
8126 };
8127
8128 /* *** WRITE PORT REGISTER *** */
8129 struct cmd_write_reg_result {
8130         cmdline_fixed_string_t write;
8131         cmdline_fixed_string_t reg;
8132         portid_t port_id;
8133         uint32_t reg_off;
8134         uint32_t value;
8135 };
8136
8137 static void
8138 cmd_write_reg_parsed(void *parsed_result,
8139                      __rte_unused struct cmdline *cl,
8140                      __rte_unused void *data)
8141 {
8142         struct cmd_write_reg_result *res = parsed_result;
8143         port_reg_set(res->port_id, res->reg_off, res->value);
8144 }
8145
8146 cmdline_parse_token_string_t cmd_write_reg_write =
8147         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8148 cmdline_parse_token_string_t cmd_write_reg_reg =
8149         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8150 cmdline_parse_token_num_t cmd_write_reg_port_id =
8151         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8152 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8153         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8154 cmdline_parse_token_num_t cmd_write_reg_value =
8155         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8156
8157 cmdline_parse_inst_t cmd_write_reg = {
8158         .f = cmd_write_reg_parsed,
8159         .data = NULL,
8160         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8161         .tokens = {
8162                 (void *)&cmd_write_reg_write,
8163                 (void *)&cmd_write_reg_reg,
8164                 (void *)&cmd_write_reg_port_id,
8165                 (void *)&cmd_write_reg_reg_off,
8166                 (void *)&cmd_write_reg_value,
8167                 NULL,
8168         },
8169 };
8170
8171 /* *** WRITE PORT REGISTER BIT FIELD *** */
8172 struct cmd_write_reg_bit_field_result {
8173         cmdline_fixed_string_t write;
8174         cmdline_fixed_string_t regfield;
8175         portid_t port_id;
8176         uint32_t reg_off;
8177         uint8_t bit1_pos;
8178         uint8_t bit2_pos;
8179         uint32_t value;
8180 };
8181
8182 static void
8183 cmd_write_reg_bit_field_parsed(void *parsed_result,
8184                                __rte_unused struct cmdline *cl,
8185                                __rte_unused void *data)
8186 {
8187         struct cmd_write_reg_bit_field_result *res = parsed_result;
8188         port_reg_bit_field_set(res->port_id, res->reg_off,
8189                           res->bit1_pos, res->bit2_pos, res->value);
8190 }
8191
8192 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8193         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8194                                  "write");
8195 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8196         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8197                                  regfield, "regfield");
8198 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8199         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8200                               UINT16);
8201 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8202         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8203                               UINT32);
8204 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8205         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8206                               UINT8);
8207 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8208         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8209                               UINT8);
8210 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8211         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8212                               UINT32);
8213
8214 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8215         .f = cmd_write_reg_bit_field_parsed,
8216         .data = NULL,
8217         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8218                 "<reg_value>: "
8219                 "Set register bit field between bit_x and bit_y included",
8220         .tokens = {
8221                 (void *)&cmd_write_reg_bit_field_write,
8222                 (void *)&cmd_write_reg_bit_field_regfield,
8223                 (void *)&cmd_write_reg_bit_field_port_id,
8224                 (void *)&cmd_write_reg_bit_field_reg_off,
8225                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8226                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8227                 (void *)&cmd_write_reg_bit_field_value,
8228                 NULL,
8229         },
8230 };
8231
8232 /* *** WRITE PORT REGISTER BIT *** */
8233 struct cmd_write_reg_bit_result {
8234         cmdline_fixed_string_t write;
8235         cmdline_fixed_string_t regbit;
8236         portid_t port_id;
8237         uint32_t reg_off;
8238         uint8_t bit_pos;
8239         uint8_t value;
8240 };
8241
8242 static void
8243 cmd_write_reg_bit_parsed(void *parsed_result,
8244                          __rte_unused struct cmdline *cl,
8245                          __rte_unused void *data)
8246 {
8247         struct cmd_write_reg_bit_result *res = parsed_result;
8248         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8249 }
8250
8251 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8252         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8253                                  "write");
8254 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8255         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8256                                  regbit, "regbit");
8257 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8258         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8259 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8260         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8261 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8262         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8263 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8264         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8265
8266 cmdline_parse_inst_t cmd_write_reg_bit = {
8267         .f = cmd_write_reg_bit_parsed,
8268         .data = NULL,
8269         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8270                 "0 <= bit_x <= 31",
8271         .tokens = {
8272                 (void *)&cmd_write_reg_bit_write,
8273                 (void *)&cmd_write_reg_bit_regbit,
8274                 (void *)&cmd_write_reg_bit_port_id,
8275                 (void *)&cmd_write_reg_bit_reg_off,
8276                 (void *)&cmd_write_reg_bit_bit_pos,
8277                 (void *)&cmd_write_reg_bit_value,
8278                 NULL,
8279         },
8280 };
8281
8282 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8283 struct cmd_read_rxd_txd_result {
8284         cmdline_fixed_string_t read;
8285         cmdline_fixed_string_t rxd_txd;
8286         portid_t port_id;
8287         uint16_t queue_id;
8288         uint16_t desc_id;
8289 };
8290
8291 static void
8292 cmd_read_rxd_txd_parsed(void *parsed_result,
8293                         __rte_unused struct cmdline *cl,
8294                         __rte_unused void *data)
8295 {
8296         struct cmd_read_rxd_txd_result *res = parsed_result;
8297
8298         if (!strcmp(res->rxd_txd, "rxd"))
8299                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8300         else if (!strcmp(res->rxd_txd, "txd"))
8301                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8302 }
8303
8304 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8305         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8306 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8307         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8308                                  "rxd#txd");
8309 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8310         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8311 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8312         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8313 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8314         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8315
8316 cmdline_parse_inst_t cmd_read_rxd_txd = {
8317         .f = cmd_read_rxd_txd_parsed,
8318         .data = NULL,
8319         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8320         .tokens = {
8321                 (void *)&cmd_read_rxd_txd_read,
8322                 (void *)&cmd_read_rxd_txd_rxd_txd,
8323                 (void *)&cmd_read_rxd_txd_port_id,
8324                 (void *)&cmd_read_rxd_txd_queue_id,
8325                 (void *)&cmd_read_rxd_txd_desc_id,
8326                 NULL,
8327         },
8328 };
8329
8330 /* *** QUIT *** */
8331 struct cmd_quit_result {
8332         cmdline_fixed_string_t quit;
8333 };
8334
8335 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8336                             struct cmdline *cl,
8337                             __rte_unused void *data)
8338 {
8339         cmdline_quit(cl);
8340 }
8341
8342 cmdline_parse_token_string_t cmd_quit_quit =
8343         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8344
8345 cmdline_parse_inst_t cmd_quit = {
8346         .f = cmd_quit_parsed,
8347         .data = NULL,
8348         .help_str = "quit: Exit application",
8349         .tokens = {
8350                 (void *)&cmd_quit_quit,
8351                 NULL,
8352         },
8353 };
8354
8355 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8356 struct cmd_mac_addr_result {
8357         cmdline_fixed_string_t mac_addr_cmd;
8358         cmdline_fixed_string_t what;
8359         uint16_t port_num;
8360         struct rte_ether_addr address;
8361 };
8362
8363 static void cmd_mac_addr_parsed(void *parsed_result,
8364                 __rte_unused struct cmdline *cl,
8365                 __rte_unused void *data)
8366 {
8367         struct cmd_mac_addr_result *res = parsed_result;
8368         int ret;
8369
8370         if (strcmp(res->what, "add") == 0)
8371                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8372         else if (strcmp(res->what, "set") == 0)
8373                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8374                                                        &res->address);
8375         else
8376                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8377
8378         /* check the return value and print it if is < 0 */
8379         if(ret < 0)
8380                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8381
8382 }
8383
8384 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8385         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8386                                 "mac_addr");
8387 cmdline_parse_token_string_t cmd_mac_addr_what =
8388         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8389                                 "add#remove#set");
8390 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8391                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8392                                         UINT16);
8393 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8394                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8395
8396 cmdline_parse_inst_t cmd_mac_addr = {
8397         .f = cmd_mac_addr_parsed,
8398         .data = (void *)0,
8399         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8400                         "Add/Remove/Set MAC address on port_id",
8401         .tokens = {
8402                 (void *)&cmd_mac_addr_cmd,
8403                 (void *)&cmd_mac_addr_what,
8404                 (void *)&cmd_mac_addr_portnum,
8405                 (void *)&cmd_mac_addr_addr,
8406                 NULL,
8407         },
8408 };
8409
8410 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8411 struct cmd_eth_peer_result {
8412         cmdline_fixed_string_t set;
8413         cmdline_fixed_string_t eth_peer;
8414         portid_t port_id;
8415         cmdline_fixed_string_t peer_addr;
8416 };
8417
8418 static void cmd_set_eth_peer_parsed(void *parsed_result,
8419                         __rte_unused struct cmdline *cl,
8420                         __rte_unused void *data)
8421 {
8422                 struct cmd_eth_peer_result *res = parsed_result;
8423
8424                 if (test_done == 0) {
8425                         printf("Please stop forwarding first\n");
8426                         return;
8427                 }
8428                 if (!strcmp(res->eth_peer, "eth-peer")) {
8429                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8430                         fwd_config_setup();
8431                 }
8432 }
8433 cmdline_parse_token_string_t cmd_eth_peer_set =
8434         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8435 cmdline_parse_token_string_t cmd_eth_peer =
8436         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8437 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8438         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8439 cmdline_parse_token_string_t cmd_eth_peer_addr =
8440         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8441
8442 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8443         .f = cmd_set_eth_peer_parsed,
8444         .data = NULL,
8445         .help_str = "set eth-peer <port_id> <peer_mac>",
8446         .tokens = {
8447                 (void *)&cmd_eth_peer_set,
8448                 (void *)&cmd_eth_peer,
8449                 (void *)&cmd_eth_peer_port_id,
8450                 (void *)&cmd_eth_peer_addr,
8451                 NULL,
8452         },
8453 };
8454
8455 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8456 struct cmd_set_qmap_result {
8457         cmdline_fixed_string_t set;
8458         cmdline_fixed_string_t qmap;
8459         cmdline_fixed_string_t what;
8460         portid_t port_id;
8461         uint16_t queue_id;
8462         uint8_t map_value;
8463 };
8464
8465 static void
8466 cmd_set_qmap_parsed(void *parsed_result,
8467                        __rte_unused struct cmdline *cl,
8468                        __rte_unused void *data)
8469 {
8470         struct cmd_set_qmap_result *res = parsed_result;
8471         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8472
8473         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8474 }
8475
8476 cmdline_parse_token_string_t cmd_setqmap_set =
8477         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8478                                  set, "set");
8479 cmdline_parse_token_string_t cmd_setqmap_qmap =
8480         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8481                                  qmap, "stat_qmap");
8482 cmdline_parse_token_string_t cmd_setqmap_what =
8483         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8484                                  what, "tx#rx");
8485 cmdline_parse_token_num_t cmd_setqmap_portid =
8486         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8487                               port_id, UINT16);
8488 cmdline_parse_token_num_t cmd_setqmap_queueid =
8489         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8490                               queue_id, UINT16);
8491 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8492         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8493                               map_value, UINT8);
8494
8495 cmdline_parse_inst_t cmd_set_qmap = {
8496         .f = cmd_set_qmap_parsed,
8497         .data = NULL,
8498         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8499                 "Set statistics mapping value on tx|rx queue_id of port_id",
8500         .tokens = {
8501                 (void *)&cmd_setqmap_set,
8502                 (void *)&cmd_setqmap_qmap,
8503                 (void *)&cmd_setqmap_what,
8504                 (void *)&cmd_setqmap_portid,
8505                 (void *)&cmd_setqmap_queueid,
8506                 (void *)&cmd_setqmap_mapvalue,
8507                 NULL,
8508         },
8509 };
8510
8511 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8512 struct cmd_set_xstats_hide_zero_result {
8513         cmdline_fixed_string_t keyword;
8514         cmdline_fixed_string_t name;
8515         cmdline_fixed_string_t on_off;
8516 };
8517
8518 static void
8519 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8520                         __rte_unused struct cmdline *cl,
8521                         __rte_unused void *data)
8522 {
8523         struct cmd_set_xstats_hide_zero_result *res;
8524         uint16_t on_off = 0;
8525
8526         res = parsed_result;
8527         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8528         set_xstats_hide_zero(on_off);
8529 }
8530
8531 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8532         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8533                                  keyword, "set");
8534 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8535         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8536                                  name, "xstats-hide-zero");
8537 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8538         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8539                                  on_off, "on#off");
8540
8541 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8542         .f = cmd_set_xstats_hide_zero_parsed,
8543         .data = NULL,
8544         .help_str = "set xstats-hide-zero on|off",
8545         .tokens = {
8546                 (void *)&cmd_set_xstats_hide_zero_keyword,
8547                 (void *)&cmd_set_xstats_hide_zero_name,
8548                 (void *)&cmd_set_xstats_hide_zero_on_off,
8549                 NULL,
8550         },
8551 };
8552
8553 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8554 struct cmd_set_record_core_cycles_result {
8555         cmdline_fixed_string_t keyword;
8556         cmdline_fixed_string_t name;
8557         cmdline_fixed_string_t on_off;
8558 };
8559
8560 static void
8561 cmd_set_record_core_cycles_parsed(void *parsed_result,
8562                         __rte_unused struct cmdline *cl,
8563                         __rte_unused void *data)
8564 {
8565         struct cmd_set_record_core_cycles_result *res;
8566         uint16_t on_off = 0;
8567
8568         res = parsed_result;
8569         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8570         set_record_core_cycles(on_off);
8571 }
8572
8573 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8574         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8575                                  keyword, "set");
8576 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8577         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8578                                  name, "record-core-cycles");
8579 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8580         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8581                                  on_off, "on#off");
8582
8583 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8584         .f = cmd_set_record_core_cycles_parsed,
8585         .data = NULL,
8586         .help_str = "set record-core-cycles on|off",
8587         .tokens = {
8588                 (void *)&cmd_set_record_core_cycles_keyword,
8589                 (void *)&cmd_set_record_core_cycles_name,
8590                 (void *)&cmd_set_record_core_cycles_on_off,
8591                 NULL,
8592         },
8593 };
8594
8595 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8596 struct cmd_set_record_burst_stats_result {
8597         cmdline_fixed_string_t keyword;
8598         cmdline_fixed_string_t name;
8599         cmdline_fixed_string_t on_off;
8600 };
8601
8602 static void
8603 cmd_set_record_burst_stats_parsed(void *parsed_result,
8604                         __rte_unused struct cmdline *cl,
8605                         __rte_unused void *data)
8606 {
8607         struct cmd_set_record_burst_stats_result *res;
8608         uint16_t on_off = 0;
8609
8610         res = parsed_result;
8611         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8612         set_record_burst_stats(on_off);
8613 }
8614
8615 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8616         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8617                                  keyword, "set");
8618 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8619         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8620                                  name, "record-burst-stats");
8621 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8622         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8623                                  on_off, "on#off");
8624
8625 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8626         .f = cmd_set_record_burst_stats_parsed,
8627         .data = NULL,
8628         .help_str = "set record-burst-stats on|off",
8629         .tokens = {
8630                 (void *)&cmd_set_record_burst_stats_keyword,
8631                 (void *)&cmd_set_record_burst_stats_name,
8632                 (void *)&cmd_set_record_burst_stats_on_off,
8633                 NULL,
8634         },
8635 };
8636
8637 /* *** CONFIGURE UNICAST HASH TABLE *** */
8638 struct cmd_set_uc_hash_table {
8639         cmdline_fixed_string_t set;
8640         cmdline_fixed_string_t port;
8641         portid_t port_id;
8642         cmdline_fixed_string_t what;
8643         struct rte_ether_addr address;
8644         cmdline_fixed_string_t mode;
8645 };
8646
8647 static void
8648 cmd_set_uc_hash_parsed(void *parsed_result,
8649                        __rte_unused struct cmdline *cl,
8650                        __rte_unused void *data)
8651 {
8652         int ret=0;
8653         struct cmd_set_uc_hash_table *res = parsed_result;
8654
8655         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8656
8657         if (strcmp(res->what, "uta") == 0)
8658                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8659                                                 &res->address,(uint8_t)is_on);
8660         if (ret < 0)
8661                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8662
8663 }
8664
8665 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8666         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8667                                  set, "set");
8668 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8669         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8670                                  port, "port");
8671 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8672         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8673                               port_id, UINT16);
8674 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8675         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8676                                  what, "uta");
8677 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8678         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8679                                 address);
8680 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8681         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8682                                  mode, "on#off");
8683
8684 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8685         .f = cmd_set_uc_hash_parsed,
8686         .data = NULL,
8687         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8688         .tokens = {
8689                 (void *)&cmd_set_uc_hash_set,
8690                 (void *)&cmd_set_uc_hash_port,
8691                 (void *)&cmd_set_uc_hash_portid,
8692                 (void *)&cmd_set_uc_hash_what,
8693                 (void *)&cmd_set_uc_hash_mac,
8694                 (void *)&cmd_set_uc_hash_mode,
8695                 NULL,
8696         },
8697 };
8698
8699 struct cmd_set_uc_all_hash_table {
8700         cmdline_fixed_string_t set;
8701         cmdline_fixed_string_t port;
8702         portid_t port_id;
8703         cmdline_fixed_string_t what;
8704         cmdline_fixed_string_t value;
8705         cmdline_fixed_string_t mode;
8706 };
8707
8708 static void
8709 cmd_set_uc_all_hash_parsed(void *parsed_result,
8710                        __rte_unused struct cmdline *cl,
8711                        __rte_unused void *data)
8712 {
8713         int ret=0;
8714         struct cmd_set_uc_all_hash_table *res = parsed_result;
8715
8716         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8717
8718         if ((strcmp(res->what, "uta") == 0) &&
8719                 (strcmp(res->value, "all") == 0))
8720                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8721         if (ret < 0)
8722                 printf("bad unicast hash table parameter,"
8723                         "return code = %d \n", ret);
8724 }
8725
8726 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8727         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8728                                  set, "set");
8729 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8730         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8731                                  port, "port");
8732 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8733         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8734                               port_id, UINT16);
8735 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8736         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8737                                  what, "uta");
8738 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8739         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8740                                 value,"all");
8741 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8742         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8743                                  mode, "on#off");
8744
8745 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8746         .f = cmd_set_uc_all_hash_parsed,
8747         .data = NULL,
8748         .help_str = "set port <port_id> uta all on|off",
8749         .tokens = {
8750                 (void *)&cmd_set_uc_all_hash_set,
8751                 (void *)&cmd_set_uc_all_hash_port,
8752                 (void *)&cmd_set_uc_all_hash_portid,
8753                 (void *)&cmd_set_uc_all_hash_what,
8754                 (void *)&cmd_set_uc_all_hash_value,
8755                 (void *)&cmd_set_uc_all_hash_mode,
8756                 NULL,
8757         },
8758 };
8759
8760 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8761 struct cmd_set_vf_macvlan_filter {
8762         cmdline_fixed_string_t set;
8763         cmdline_fixed_string_t port;
8764         portid_t port_id;
8765         cmdline_fixed_string_t vf;
8766         uint8_t vf_id;
8767         struct rte_ether_addr address;
8768         cmdline_fixed_string_t filter_type;
8769         cmdline_fixed_string_t mode;
8770 };
8771
8772 static void
8773 cmd_set_vf_macvlan_parsed(void *parsed_result,
8774                        __rte_unused struct cmdline *cl,
8775                        __rte_unused void *data)
8776 {
8777         int is_on, ret = 0;
8778         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8779         struct rte_eth_mac_filter filter;
8780
8781         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8782
8783         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8784
8785         /* set VF MAC filter */
8786         filter.is_vf = 1;
8787
8788         /* set VF ID */
8789         filter.dst_id = res->vf_id;
8790
8791         if (!strcmp(res->filter_type, "exact-mac"))
8792                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8793         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8794                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8795         else if (!strcmp(res->filter_type, "hashmac"))
8796                 filter.filter_type = RTE_MAC_HASH_MATCH;
8797         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8798                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8799
8800         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8801
8802         if (is_on)
8803                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8804                                         RTE_ETH_FILTER_MACVLAN,
8805                                         RTE_ETH_FILTER_ADD,
8806                                          &filter);
8807         else
8808                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8809                                         RTE_ETH_FILTER_MACVLAN,
8810                                         RTE_ETH_FILTER_DELETE,
8811                                         &filter);
8812
8813         if (ret < 0)
8814                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8815
8816 }
8817
8818 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8819         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8820                                  set, "set");
8821 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8822         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8823                                  port, "port");
8824 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8825         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8826                               port_id, UINT16);
8827 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8828         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8829                                  vf, "vf");
8830 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8831         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8832                                 vf_id, UINT8);
8833 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8834         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8835                                 address);
8836 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8837         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8838                                 filter_type, "exact-mac#exact-mac-vlan"
8839                                 "#hashmac#hashmac-vlan");
8840 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8841         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8842                                  mode, "on#off");
8843
8844 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8845         .f = cmd_set_vf_macvlan_parsed,
8846         .data = NULL,
8847         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8848                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8849                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8850                 "hash match rule: hash match of MAC and exact match of VLAN",
8851         .tokens = {
8852                 (void *)&cmd_set_vf_macvlan_set,
8853                 (void *)&cmd_set_vf_macvlan_port,
8854                 (void *)&cmd_set_vf_macvlan_portid,
8855                 (void *)&cmd_set_vf_macvlan_vf,
8856                 (void *)&cmd_set_vf_macvlan_vf_id,
8857                 (void *)&cmd_set_vf_macvlan_mac,
8858                 (void *)&cmd_set_vf_macvlan_filter_type,
8859                 (void *)&cmd_set_vf_macvlan_mode,
8860                 NULL,
8861         },
8862 };
8863
8864 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8865 struct cmd_set_vf_traffic {
8866         cmdline_fixed_string_t set;
8867         cmdline_fixed_string_t port;
8868         portid_t port_id;
8869         cmdline_fixed_string_t vf;
8870         uint8_t vf_id;
8871         cmdline_fixed_string_t what;
8872         cmdline_fixed_string_t mode;
8873 };
8874
8875 static void
8876 cmd_set_vf_traffic_parsed(void *parsed_result,
8877                        __rte_unused struct cmdline *cl,
8878                        __rte_unused void *data)
8879 {
8880         struct cmd_set_vf_traffic *res = parsed_result;
8881         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8882         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8883
8884         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8885 }
8886
8887 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8888         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8889                                  set, "set");
8890 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8891         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8892                                  port, "port");
8893 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8894         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8895                               port_id, UINT16);
8896 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8897         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8898                                  vf, "vf");
8899 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8900         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8901                               vf_id, UINT8);
8902 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8903         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8904                                  what, "tx#rx");
8905 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8906         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8907                                  mode, "on#off");
8908
8909 cmdline_parse_inst_t cmd_set_vf_traffic = {
8910         .f = cmd_set_vf_traffic_parsed,
8911         .data = NULL,
8912         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8913         .tokens = {
8914                 (void *)&cmd_setvf_traffic_set,
8915                 (void *)&cmd_setvf_traffic_port,
8916                 (void *)&cmd_setvf_traffic_portid,
8917                 (void *)&cmd_setvf_traffic_vf,
8918                 (void *)&cmd_setvf_traffic_vfid,
8919                 (void *)&cmd_setvf_traffic_what,
8920                 (void *)&cmd_setvf_traffic_mode,
8921                 NULL,
8922         },
8923 };
8924
8925 /* *** CONFIGURE VF RECEIVE MODE *** */
8926 struct cmd_set_vf_rxmode {
8927         cmdline_fixed_string_t set;
8928         cmdline_fixed_string_t port;
8929         portid_t port_id;
8930         cmdline_fixed_string_t vf;
8931         uint8_t vf_id;
8932         cmdline_fixed_string_t what;
8933         cmdline_fixed_string_t mode;
8934         cmdline_fixed_string_t on;
8935 };
8936
8937 static void
8938 cmd_set_vf_rxmode_parsed(void *parsed_result,
8939                        __rte_unused struct cmdline *cl,
8940                        __rte_unused void *data)
8941 {
8942         int ret = -ENOTSUP;
8943         uint16_t vf_rxmode = 0;
8944         struct cmd_set_vf_rxmode *res = parsed_result;
8945
8946         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8947         if (!strcmp(res->what,"rxmode")) {
8948                 if (!strcmp(res->mode, "AUPE"))
8949                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8950                 else if (!strcmp(res->mode, "ROPE"))
8951                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8952                 else if (!strcmp(res->mode, "BAM"))
8953                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8954                 else if (!strncmp(res->mode, "MPE",3))
8955                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8956         }
8957
8958         RTE_SET_USED(is_on);
8959
8960 #ifdef RTE_NET_IXGBE
8961         if (ret == -ENOTSUP)
8962                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8963                                                   vf_rxmode, (uint8_t)is_on);
8964 #endif
8965 #ifdef RTE_NET_BNXT
8966         if (ret == -ENOTSUP)
8967                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8968                                                  vf_rxmode, (uint8_t)is_on);
8969 #endif
8970         if (ret < 0)
8971                 printf("bad VF receive mode parameter, return code = %d \n",
8972                 ret);
8973 }
8974
8975 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8976         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8977                                  set, "set");
8978 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8979         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8980                                  port, "port");
8981 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8982         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8983                               port_id, UINT16);
8984 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8985         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8986                                  vf, "vf");
8987 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8988         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8989                               vf_id, UINT8);
8990 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8991         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8992                                  what, "rxmode");
8993 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8994         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8995                                  mode, "AUPE#ROPE#BAM#MPE");
8996 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8997         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8998                                  on, "on#off");
8999
9000 cmdline_parse_inst_t cmd_set_vf_rxmode = {
9001         .f = cmd_set_vf_rxmode_parsed,
9002         .data = NULL,
9003         .help_str = "set port <port_id> vf <vf_id> rxmode "
9004                 "AUPE|ROPE|BAM|MPE on|off",
9005         .tokens = {
9006                 (void *)&cmd_set_vf_rxmode_set,
9007                 (void *)&cmd_set_vf_rxmode_port,
9008                 (void *)&cmd_set_vf_rxmode_portid,
9009                 (void *)&cmd_set_vf_rxmode_vf,
9010                 (void *)&cmd_set_vf_rxmode_vfid,
9011                 (void *)&cmd_set_vf_rxmode_what,
9012                 (void *)&cmd_set_vf_rxmode_mode,
9013                 (void *)&cmd_set_vf_rxmode_on,
9014                 NULL,
9015         },
9016 };
9017
9018 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
9019 struct cmd_vf_mac_addr_result {
9020         cmdline_fixed_string_t mac_addr_cmd;
9021         cmdline_fixed_string_t what;
9022         cmdline_fixed_string_t port;
9023         uint16_t port_num;
9024         cmdline_fixed_string_t vf;
9025         uint8_t vf_num;
9026         struct rte_ether_addr address;
9027 };
9028
9029 static void cmd_vf_mac_addr_parsed(void *parsed_result,
9030                 __rte_unused struct cmdline *cl,
9031                 __rte_unused void *data)
9032 {
9033         struct cmd_vf_mac_addr_result *res = parsed_result;
9034         int ret = -ENOTSUP;
9035
9036         if (strcmp(res->what, "add") != 0)
9037                 return;
9038
9039 #ifdef RTE_NET_I40E
9040         if (ret == -ENOTSUP)
9041                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
9042                                                    &res->address);
9043 #endif
9044 #ifdef RTE_NET_BNXT
9045         if (ret == -ENOTSUP)
9046                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
9047                                                 res->vf_num);
9048 #endif
9049
9050         if(ret < 0)
9051                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
9052
9053 }
9054
9055 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9056         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9057                                 mac_addr_cmd,"mac_addr");
9058 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9059         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9060                                 what,"add");
9061 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9062         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9063                                 port,"port");
9064 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9065         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9066                                 port_num, UINT16);
9067 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9068         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9069                                 vf,"vf");
9070 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9071         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9072                                 vf_num, UINT8);
9073 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9074         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9075                                 address);
9076
9077 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9078         .f = cmd_vf_mac_addr_parsed,
9079         .data = (void *)0,
9080         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9081                 "Add MAC address filtering for a VF on port_id",
9082         .tokens = {
9083                 (void *)&cmd_vf_mac_addr_cmd,
9084                 (void *)&cmd_vf_mac_addr_what,
9085                 (void *)&cmd_vf_mac_addr_port,
9086                 (void *)&cmd_vf_mac_addr_portnum,
9087                 (void *)&cmd_vf_mac_addr_vf,
9088                 (void *)&cmd_vf_mac_addr_vfnum,
9089                 (void *)&cmd_vf_mac_addr_addr,
9090                 NULL,
9091         },
9092 };
9093
9094 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9095 struct cmd_vf_rx_vlan_filter {
9096         cmdline_fixed_string_t rx_vlan;
9097         cmdline_fixed_string_t what;
9098         uint16_t vlan_id;
9099         cmdline_fixed_string_t port;
9100         portid_t port_id;
9101         cmdline_fixed_string_t vf;
9102         uint64_t vf_mask;
9103 };
9104
9105 static void
9106 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9107                           __rte_unused struct cmdline *cl,
9108                           __rte_unused void *data)
9109 {
9110         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9111         int ret = -ENOTSUP;
9112
9113         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9114
9115 #ifdef RTE_NET_IXGBE
9116         if (ret == -ENOTSUP)
9117                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9118                                 res->vlan_id, res->vf_mask, is_add);
9119 #endif
9120 #ifdef RTE_NET_I40E
9121         if (ret == -ENOTSUP)
9122                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9123                                 res->vlan_id, res->vf_mask, is_add);
9124 #endif
9125 #ifdef RTE_NET_BNXT
9126         if (ret == -ENOTSUP)
9127                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9128                                 res->vlan_id, res->vf_mask, is_add);
9129 #endif
9130
9131         switch (ret) {
9132         case 0:
9133                 break;
9134         case -EINVAL:
9135                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9136                                 res->vlan_id, res->vf_mask);
9137                 break;
9138         case -ENODEV:
9139                 printf("invalid port_id %d\n", res->port_id);
9140                 break;
9141         case -ENOTSUP:
9142                 printf("function not implemented or supported\n");
9143                 break;
9144         default:
9145                 printf("programming error: (%s)\n", strerror(-ret));
9146         }
9147 }
9148
9149 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9150         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9151                                  rx_vlan, "rx_vlan");
9152 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9153         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9154                                  what, "add#rm");
9155 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9156         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9157                               vlan_id, UINT16);
9158 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9159         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9160                                  port, "port");
9161 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9162         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9163                               port_id, UINT16);
9164 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9165         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9166                                  vf, "vf");
9167 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9168         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9169                               vf_mask, UINT64);
9170
9171 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9172         .f = cmd_vf_rx_vlan_filter_parsed,
9173         .data = NULL,
9174         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9175                 "(vf_mask = hexadecimal VF mask)",
9176         .tokens = {
9177                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9178                 (void *)&cmd_vf_rx_vlan_filter_what,
9179                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9180                 (void *)&cmd_vf_rx_vlan_filter_port,
9181                 (void *)&cmd_vf_rx_vlan_filter_portid,
9182                 (void *)&cmd_vf_rx_vlan_filter_vf,
9183                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9184                 NULL,
9185         },
9186 };
9187
9188 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9189 struct cmd_queue_rate_limit_result {
9190         cmdline_fixed_string_t set;
9191         cmdline_fixed_string_t port;
9192         uint16_t port_num;
9193         cmdline_fixed_string_t queue;
9194         uint8_t queue_num;
9195         cmdline_fixed_string_t rate;
9196         uint16_t rate_num;
9197 };
9198
9199 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9200                 __rte_unused struct cmdline *cl,
9201                 __rte_unused void *data)
9202 {
9203         struct cmd_queue_rate_limit_result *res = parsed_result;
9204         int ret = 0;
9205
9206         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9207                 && (strcmp(res->queue, "queue") == 0)
9208                 && (strcmp(res->rate, "rate") == 0))
9209                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9210                                         res->rate_num);
9211         if (ret < 0)
9212                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9213
9214 }
9215
9216 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9217         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9218                                 set, "set");
9219 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9220         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9221                                 port, "port");
9222 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9223         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9224                                 port_num, UINT16);
9225 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9226         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9227                                 queue, "queue");
9228 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9229         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9230                                 queue_num, UINT8);
9231 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9232         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9233                                 rate, "rate");
9234 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9235         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9236                                 rate_num, UINT16);
9237
9238 cmdline_parse_inst_t cmd_queue_rate_limit = {
9239         .f = cmd_queue_rate_limit_parsed,
9240         .data = (void *)0,
9241         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9242                 "Set rate limit for a queue on port_id",
9243         .tokens = {
9244                 (void *)&cmd_queue_rate_limit_set,
9245                 (void *)&cmd_queue_rate_limit_port,
9246                 (void *)&cmd_queue_rate_limit_portnum,
9247                 (void *)&cmd_queue_rate_limit_queue,
9248                 (void *)&cmd_queue_rate_limit_queuenum,
9249                 (void *)&cmd_queue_rate_limit_rate,
9250                 (void *)&cmd_queue_rate_limit_ratenum,
9251                 NULL,
9252         },
9253 };
9254
9255 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9256 struct cmd_vf_rate_limit_result {
9257         cmdline_fixed_string_t set;
9258         cmdline_fixed_string_t port;
9259         uint16_t port_num;
9260         cmdline_fixed_string_t vf;
9261         uint8_t vf_num;
9262         cmdline_fixed_string_t rate;
9263         uint16_t rate_num;
9264         cmdline_fixed_string_t q_msk;
9265         uint64_t q_msk_val;
9266 };
9267
9268 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9269                 __rte_unused struct cmdline *cl,
9270                 __rte_unused void *data)
9271 {
9272         struct cmd_vf_rate_limit_result *res = parsed_result;
9273         int ret = 0;
9274
9275         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9276                 && (strcmp(res->vf, "vf") == 0)
9277                 && (strcmp(res->rate, "rate") == 0)
9278                 && (strcmp(res->q_msk, "queue_mask") == 0))
9279                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9280                                         res->rate_num, res->q_msk_val);
9281         if (ret < 0)
9282                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9283
9284 }
9285
9286 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9287         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9288                                 set, "set");
9289 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9290         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9291                                 port, "port");
9292 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9293         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9294                                 port_num, UINT16);
9295 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9296         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9297                                 vf, "vf");
9298 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9299         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9300                                 vf_num, UINT8);
9301 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9302         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9303                                 rate, "rate");
9304 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9305         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9306                                 rate_num, UINT16);
9307 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9308         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9309                                 q_msk, "queue_mask");
9310 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9311         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9312                                 q_msk_val, UINT64);
9313
9314 cmdline_parse_inst_t cmd_vf_rate_limit = {
9315         .f = cmd_vf_rate_limit_parsed,
9316         .data = (void *)0,
9317         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9318                 "queue_mask <queue_mask_value>: "
9319                 "Set rate limit for queues of VF on port_id",
9320         .tokens = {
9321                 (void *)&cmd_vf_rate_limit_set,
9322                 (void *)&cmd_vf_rate_limit_port,
9323                 (void *)&cmd_vf_rate_limit_portnum,
9324                 (void *)&cmd_vf_rate_limit_vf,
9325                 (void *)&cmd_vf_rate_limit_vfnum,
9326                 (void *)&cmd_vf_rate_limit_rate,
9327                 (void *)&cmd_vf_rate_limit_ratenum,
9328                 (void *)&cmd_vf_rate_limit_q_msk,
9329                 (void *)&cmd_vf_rate_limit_q_msk_val,
9330                 NULL,
9331         },
9332 };
9333
9334 /* *** ADD TUNNEL FILTER OF A PORT *** */
9335 struct cmd_tunnel_filter_result {
9336         cmdline_fixed_string_t cmd;
9337         cmdline_fixed_string_t what;
9338         portid_t port_id;
9339         struct rte_ether_addr outer_mac;
9340         struct rte_ether_addr inner_mac;
9341         cmdline_ipaddr_t ip_value;
9342         uint16_t inner_vlan;
9343         cmdline_fixed_string_t tunnel_type;
9344         cmdline_fixed_string_t filter_type;
9345         uint32_t tenant_id;
9346         uint16_t queue_num;
9347 };
9348
9349 static void
9350 cmd_tunnel_filter_parsed(void *parsed_result,
9351                           __rte_unused struct cmdline *cl,
9352                           __rte_unused void *data)
9353 {
9354         struct cmd_tunnel_filter_result *res = parsed_result;
9355         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9356         int ret = 0;
9357
9358         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9359
9360         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9361         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9362         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9363
9364         if (res->ip_value.family == AF_INET) {
9365                 tunnel_filter_conf.ip_addr.ipv4_addr =
9366                         res->ip_value.addr.ipv4.s_addr;
9367                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9368         } else {
9369                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9370                         &(res->ip_value.addr.ipv6),
9371                         sizeof(struct in6_addr));
9372                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9373         }
9374
9375         if (!strcmp(res->filter_type, "imac-ivlan"))
9376                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9377         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9378                 tunnel_filter_conf.filter_type =
9379                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9380         else if (!strcmp(res->filter_type, "imac-tenid"))
9381                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9382         else if (!strcmp(res->filter_type, "imac"))
9383                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9384         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9385                 tunnel_filter_conf.filter_type =
9386                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9387         else if (!strcmp(res->filter_type, "oip"))
9388                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9389         else if (!strcmp(res->filter_type, "iip"))
9390                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9391         else {
9392                 printf("The filter type is not supported");
9393                 return;
9394         }
9395
9396         if (!strcmp(res->tunnel_type, "vxlan"))
9397                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9398         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9399                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9400         else if (!strcmp(res->tunnel_type, "nvgre"))
9401                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9402         else if (!strcmp(res->tunnel_type, "ipingre"))
9403                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9404         else {
9405                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9406                 return;
9407         }
9408
9409         tunnel_filter_conf.tenant_id = res->tenant_id;
9410         tunnel_filter_conf.queue_id = res->queue_num;
9411         if (!strcmp(res->what, "add"))
9412                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9413                                         RTE_ETH_FILTER_TUNNEL,
9414                                         RTE_ETH_FILTER_ADD,
9415                                         &tunnel_filter_conf);
9416         else
9417                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9418                                         RTE_ETH_FILTER_TUNNEL,
9419                                         RTE_ETH_FILTER_DELETE,
9420                                         &tunnel_filter_conf);
9421         if (ret < 0)
9422                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9423                                 strerror(-ret));
9424
9425 }
9426 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9427         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9428         cmd, "tunnel_filter");
9429 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9430         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9431         what, "add#rm");
9432 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9433         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9434         port_id, UINT16);
9435 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9436         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9437         outer_mac);
9438 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9439         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9440         inner_mac);
9441 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9442         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9443         inner_vlan, UINT16);
9444 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9445         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9446         ip_value);
9447 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9448         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9449         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9450
9451 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9452         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9453         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9454                 "imac#omac-imac-tenid");
9455 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9456         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9457         tenant_id, UINT32);
9458 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9459         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9460         queue_num, UINT16);
9461
9462 cmdline_parse_inst_t cmd_tunnel_filter = {
9463         .f = cmd_tunnel_filter_parsed,
9464         .data = (void *)0,
9465         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9466                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9467                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9468                 "<queue_id>: Add/Rm tunnel filter of a port",
9469         .tokens = {
9470                 (void *)&cmd_tunnel_filter_cmd,
9471                 (void *)&cmd_tunnel_filter_what,
9472                 (void *)&cmd_tunnel_filter_port_id,
9473                 (void *)&cmd_tunnel_filter_outer_mac,
9474                 (void *)&cmd_tunnel_filter_inner_mac,
9475                 (void *)&cmd_tunnel_filter_ip_value,
9476                 (void *)&cmd_tunnel_filter_innner_vlan,
9477                 (void *)&cmd_tunnel_filter_tunnel_type,
9478                 (void *)&cmd_tunnel_filter_filter_type,
9479                 (void *)&cmd_tunnel_filter_tenant_id,
9480                 (void *)&cmd_tunnel_filter_queue_num,
9481                 NULL,
9482         },
9483 };
9484
9485 /* *** CONFIGURE TUNNEL UDP PORT *** */
9486 struct cmd_tunnel_udp_config {
9487         cmdline_fixed_string_t cmd;
9488         cmdline_fixed_string_t what;
9489         uint16_t udp_port;
9490         portid_t port_id;
9491 };
9492
9493 static void
9494 cmd_tunnel_udp_config_parsed(void *parsed_result,
9495                           __rte_unused struct cmdline *cl,
9496                           __rte_unused void *data)
9497 {
9498         struct cmd_tunnel_udp_config *res = parsed_result;
9499         struct rte_eth_udp_tunnel tunnel_udp;
9500         int ret;
9501
9502         tunnel_udp.udp_port = res->udp_port;
9503
9504         if (!strcmp(res->cmd, "rx_vxlan_port"))
9505                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9506
9507         if (!strcmp(res->what, "add"))
9508                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9509                                                       &tunnel_udp);
9510         else
9511                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9512                                                          &tunnel_udp);
9513
9514         if (ret < 0)
9515                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9516 }
9517
9518 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9519         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9520                                 cmd, "rx_vxlan_port");
9521 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9522         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9523                                 what, "add#rm");
9524 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9525         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9526                                 udp_port, UINT16);
9527 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9528         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9529                                 port_id, UINT16);
9530
9531 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9532         .f = cmd_tunnel_udp_config_parsed,
9533         .data = (void *)0,
9534         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9535                 "Add/Remove a tunneling UDP port filter",
9536         .tokens = {
9537                 (void *)&cmd_tunnel_udp_config_cmd,
9538                 (void *)&cmd_tunnel_udp_config_what,
9539                 (void *)&cmd_tunnel_udp_config_udp_port,
9540                 (void *)&cmd_tunnel_udp_config_port_id,
9541                 NULL,
9542         },
9543 };
9544
9545 struct cmd_config_tunnel_udp_port {
9546         cmdline_fixed_string_t port;
9547         cmdline_fixed_string_t config;
9548         portid_t port_id;
9549         cmdline_fixed_string_t udp_tunnel_port;
9550         cmdline_fixed_string_t action;
9551         cmdline_fixed_string_t tunnel_type;
9552         uint16_t udp_port;
9553 };
9554
9555 static void
9556 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9557                                __rte_unused struct cmdline *cl,
9558                                __rte_unused void *data)
9559 {
9560         struct cmd_config_tunnel_udp_port *res = parsed_result;
9561         struct rte_eth_udp_tunnel tunnel_udp;
9562         int ret = 0;
9563
9564         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9565                 return;
9566
9567         tunnel_udp.udp_port = res->udp_port;
9568
9569         if (!strcmp(res->tunnel_type, "vxlan")) {
9570                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9571         } else if (!strcmp(res->tunnel_type, "geneve")) {
9572                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9573         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9574                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9575         } else {
9576                 printf("Invalid tunnel type\n");
9577                 return;
9578         }
9579
9580         if (!strcmp(res->action, "add"))
9581                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9582                                                       &tunnel_udp);
9583         else
9584                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9585                                                          &tunnel_udp);
9586
9587         if (ret < 0)
9588                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9589 }
9590
9591 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9592         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9593                                  "port");
9594 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9595         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9596                                  "config");
9597 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9598         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9599                               UINT16);
9600 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9601         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9602                                  udp_tunnel_port,
9603                                  "udp_tunnel_port");
9604 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9605         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9606                                  "add#rm");
9607 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9608         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9609                                  "vxlan#geneve#vxlan-gpe");
9610 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9611         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9612                               UINT16);
9613
9614 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9615         .f = cmd_cfg_tunnel_udp_port_parsed,
9616         .data = NULL,
9617         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9618         .tokens = {
9619                 (void *)&cmd_config_tunnel_udp_port_port,
9620                 (void *)&cmd_config_tunnel_udp_port_config,
9621                 (void *)&cmd_config_tunnel_udp_port_port_id,
9622                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9623                 (void *)&cmd_config_tunnel_udp_port_action,
9624                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9625                 (void *)&cmd_config_tunnel_udp_port_value,
9626                 NULL,
9627         },
9628 };
9629
9630 /* *** GLOBAL CONFIG *** */
9631 struct cmd_global_config_result {
9632         cmdline_fixed_string_t cmd;
9633         portid_t port_id;
9634         cmdline_fixed_string_t cfg_type;
9635         uint8_t len;
9636 };
9637
9638 static void
9639 cmd_global_config_parsed(void *parsed_result,
9640                          __rte_unused struct cmdline *cl,
9641                          __rte_unused void *data)
9642 {
9643         struct cmd_global_config_result *res = parsed_result;
9644         struct rte_eth_global_cfg conf;
9645         int ret;
9646
9647         memset(&conf, 0, sizeof(conf));
9648         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9649         conf.cfg.gre_key_len = res->len;
9650         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9651                                       RTE_ETH_FILTER_SET, &conf);
9652 #ifdef RTE_NET_I40E
9653         if (ret == -ENOTSUP)
9654                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9655 #endif
9656         if (ret != 0)
9657                 printf("Global config error\n");
9658 }
9659
9660 cmdline_parse_token_string_t cmd_global_config_cmd =
9661         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9662                 "global_config");
9663 cmdline_parse_token_num_t cmd_global_config_port_id =
9664         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9665                                UINT16);
9666 cmdline_parse_token_string_t cmd_global_config_type =
9667         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9668                 cfg_type, "gre-key-len");
9669 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9670         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9671                 len, UINT8);
9672
9673 cmdline_parse_inst_t cmd_global_config = {
9674         .f = cmd_global_config_parsed,
9675         .data = (void *)NULL,
9676         .help_str = "global_config <port_id> gre-key-len <key_len>",
9677         .tokens = {
9678                 (void *)&cmd_global_config_cmd,
9679                 (void *)&cmd_global_config_port_id,
9680                 (void *)&cmd_global_config_type,
9681                 (void *)&cmd_global_config_gre_key_len,
9682                 NULL,
9683         },
9684 };
9685
9686 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9687 struct cmd_set_mirror_mask_result {
9688         cmdline_fixed_string_t set;
9689         cmdline_fixed_string_t port;
9690         portid_t port_id;
9691         cmdline_fixed_string_t mirror;
9692         uint8_t rule_id;
9693         cmdline_fixed_string_t what;
9694         cmdline_fixed_string_t value;
9695         cmdline_fixed_string_t dstpool;
9696         uint8_t dstpool_id;
9697         cmdline_fixed_string_t on;
9698 };
9699
9700 cmdline_parse_token_string_t cmd_mirror_mask_set =
9701         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9702                                 set, "set");
9703 cmdline_parse_token_string_t cmd_mirror_mask_port =
9704         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9705                                 port, "port");
9706 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9707         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9708                                 port_id, UINT16);
9709 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9710         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9711                                 mirror, "mirror-rule");
9712 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9713         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9714                                 rule_id, UINT8);
9715 cmdline_parse_token_string_t cmd_mirror_mask_what =
9716         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9717                                 what, "pool-mirror-up#pool-mirror-down"
9718                                       "#vlan-mirror");
9719 cmdline_parse_token_string_t cmd_mirror_mask_value =
9720         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9721                                 value, NULL);
9722 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9723         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9724                                 dstpool, "dst-pool");
9725 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9726         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9727                                 dstpool_id, UINT8);
9728 cmdline_parse_token_string_t cmd_mirror_mask_on =
9729         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9730                                 on, "on#off");
9731
9732 static void
9733 cmd_set_mirror_mask_parsed(void *parsed_result,
9734                        __rte_unused struct cmdline *cl,
9735                        __rte_unused void *data)
9736 {
9737         int ret,nb_item,i;
9738         struct cmd_set_mirror_mask_result *res = parsed_result;
9739         struct rte_eth_mirror_conf mr_conf;
9740
9741         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9742
9743         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9744
9745         mr_conf.dst_pool = res->dstpool_id;
9746
9747         if (!strcmp(res->what, "pool-mirror-up")) {
9748                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9749                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9750         } else if (!strcmp(res->what, "pool-mirror-down")) {
9751                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9752                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9753         } else if (!strcmp(res->what, "vlan-mirror")) {
9754                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9755                 nb_item = parse_item_list(res->value, "vlan",
9756                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9757                 if (nb_item <= 0)
9758                         return;
9759
9760                 for (i = 0; i < nb_item; i++) {
9761                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9762                                 printf("Invalid vlan_id: must be < 4096\n");
9763                                 return;
9764                         }
9765
9766                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9767                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9768                 }
9769         }
9770
9771         if (!strcmp(res->on, "on"))
9772                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9773                                                 res->rule_id, 1);
9774         else
9775                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9776                                                 res->rule_id, 0);
9777         if (ret < 0)
9778                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9779 }
9780
9781 cmdline_parse_inst_t cmd_set_mirror_mask = {
9782                 .f = cmd_set_mirror_mask_parsed,
9783                 .data = NULL,
9784                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9785                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9786                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9787                 .tokens = {
9788                         (void *)&cmd_mirror_mask_set,
9789                         (void *)&cmd_mirror_mask_port,
9790                         (void *)&cmd_mirror_mask_portid,
9791                         (void *)&cmd_mirror_mask_mirror,
9792                         (void *)&cmd_mirror_mask_ruleid,
9793                         (void *)&cmd_mirror_mask_what,
9794                         (void *)&cmd_mirror_mask_value,
9795                         (void *)&cmd_mirror_mask_dstpool,
9796                         (void *)&cmd_mirror_mask_poolid,
9797                         (void *)&cmd_mirror_mask_on,
9798                         NULL,
9799                 },
9800 };
9801
9802 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9803 struct cmd_set_mirror_link_result {
9804         cmdline_fixed_string_t set;
9805         cmdline_fixed_string_t port;
9806         portid_t port_id;
9807         cmdline_fixed_string_t mirror;
9808         uint8_t rule_id;
9809         cmdline_fixed_string_t what;
9810         cmdline_fixed_string_t dstpool;
9811         uint8_t dstpool_id;
9812         cmdline_fixed_string_t on;
9813 };
9814
9815 cmdline_parse_token_string_t cmd_mirror_link_set =
9816         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9817                                  set, "set");
9818 cmdline_parse_token_string_t cmd_mirror_link_port =
9819         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9820                                 port, "port");
9821 cmdline_parse_token_num_t cmd_mirror_link_portid =
9822         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9823                                 port_id, UINT16);
9824 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9825         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9826                                 mirror, "mirror-rule");
9827 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9828         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9829                             rule_id, UINT8);
9830 cmdline_parse_token_string_t cmd_mirror_link_what =
9831         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9832                                 what, "uplink-mirror#downlink-mirror");
9833 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9834         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9835                                 dstpool, "dst-pool");
9836 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9837         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9838                                 dstpool_id, UINT8);
9839 cmdline_parse_token_string_t cmd_mirror_link_on =
9840         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9841                                 on, "on#off");
9842
9843 static void
9844 cmd_set_mirror_link_parsed(void *parsed_result,
9845                        __rte_unused struct cmdline *cl,
9846                        __rte_unused void *data)
9847 {
9848         int ret;
9849         struct cmd_set_mirror_link_result *res = parsed_result;
9850         struct rte_eth_mirror_conf mr_conf;
9851
9852         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9853         if (!strcmp(res->what, "uplink-mirror"))
9854                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9855         else
9856                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9857
9858         mr_conf.dst_pool = res->dstpool_id;
9859
9860         if (!strcmp(res->on, "on"))
9861                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9862                                                 res->rule_id, 1);
9863         else
9864                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9865                                                 res->rule_id, 0);
9866
9867         /* check the return value and print it if is < 0 */
9868         if (ret < 0)
9869                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9870
9871 }
9872
9873 cmdline_parse_inst_t cmd_set_mirror_link = {
9874                 .f = cmd_set_mirror_link_parsed,
9875                 .data = NULL,
9876                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9877                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9878                 .tokens = {
9879                         (void *)&cmd_mirror_link_set,
9880                         (void *)&cmd_mirror_link_port,
9881                         (void *)&cmd_mirror_link_portid,
9882                         (void *)&cmd_mirror_link_mirror,
9883                         (void *)&cmd_mirror_link_ruleid,
9884                         (void *)&cmd_mirror_link_what,
9885                         (void *)&cmd_mirror_link_dstpool,
9886                         (void *)&cmd_mirror_link_poolid,
9887                         (void *)&cmd_mirror_link_on,
9888                         NULL,
9889                 },
9890 };
9891
9892 /* *** RESET VM MIRROR RULE *** */
9893 struct cmd_rm_mirror_rule_result {
9894         cmdline_fixed_string_t reset;
9895         cmdline_fixed_string_t port;
9896         portid_t port_id;
9897         cmdline_fixed_string_t mirror;
9898         uint8_t rule_id;
9899 };
9900
9901 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9902         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9903                                  reset, "reset");
9904 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9905         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9906                                 port, "port");
9907 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9908         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9909                                 port_id, UINT16);
9910 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9911         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9912                                 mirror, "mirror-rule");
9913 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9914         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9915                                 rule_id, UINT8);
9916
9917 static void
9918 cmd_reset_mirror_rule_parsed(void *parsed_result,
9919                        __rte_unused struct cmdline *cl,
9920                        __rte_unused void *data)
9921 {
9922         int ret;
9923         struct cmd_set_mirror_link_result *res = parsed_result;
9924         /* check rule_id */
9925         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9926         if(ret < 0)
9927                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9928 }
9929
9930 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9931                 .f = cmd_reset_mirror_rule_parsed,
9932                 .data = NULL,
9933                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9934                 .tokens = {
9935                         (void *)&cmd_rm_mirror_rule_reset,
9936                         (void *)&cmd_rm_mirror_rule_port,
9937                         (void *)&cmd_rm_mirror_rule_portid,
9938                         (void *)&cmd_rm_mirror_rule_mirror,
9939                         (void *)&cmd_rm_mirror_rule_ruleid,
9940                         NULL,
9941                 },
9942 };
9943
9944 /* ******************************************************************************** */
9945
9946 struct cmd_dump_result {
9947         cmdline_fixed_string_t dump;
9948 };
9949
9950 static void
9951 dump_struct_sizes(void)
9952 {
9953 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9954         DUMP_SIZE(struct rte_mbuf);
9955         DUMP_SIZE(struct rte_mempool);
9956         DUMP_SIZE(struct rte_ring);
9957 #undef DUMP_SIZE
9958 }
9959
9960
9961 /* Dump the socket memory statistics on console */
9962 static void
9963 dump_socket_mem(FILE *f)
9964 {
9965         struct rte_malloc_socket_stats socket_stats;
9966         unsigned int i;
9967         size_t total = 0;
9968         size_t alloc = 0;
9969         size_t free = 0;
9970         unsigned int n_alloc = 0;
9971         unsigned int n_free = 0;
9972         static size_t last_allocs;
9973         static size_t last_total;
9974
9975
9976         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9977                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9978                     !socket_stats.heap_totalsz_bytes)
9979                         continue;
9980                 total += socket_stats.heap_totalsz_bytes;
9981                 alloc += socket_stats.heap_allocsz_bytes;
9982                 free += socket_stats.heap_freesz_bytes;
9983                 n_alloc += socket_stats.alloc_count;
9984                 n_free += socket_stats.free_count;
9985                 fprintf(f,
9986                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9987                         i,
9988                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9989                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9990                         (double)socket_stats.heap_allocsz_bytes * 100 /
9991                         (double)socket_stats.heap_totalsz_bytes,
9992                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9993                         socket_stats.alloc_count,
9994                         socket_stats.free_count);
9995         }
9996         fprintf(f,
9997                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9998                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9999                 (double)alloc * 100 / (double)total,
10000                 (double)free / (1024 * 1024),
10001                 n_alloc, n_free);
10002         if (last_allocs)
10003                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
10004                         ((double)total - (double)last_total) / (1024 * 1024),
10005                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
10006         last_allocs = alloc;
10007         last_total = total;
10008 }
10009
10010 static void cmd_dump_parsed(void *parsed_result,
10011                             __rte_unused struct cmdline *cl,
10012                             __rte_unused void *data)
10013 {
10014         struct cmd_dump_result *res = parsed_result;
10015
10016         if (!strcmp(res->dump, "dump_physmem"))
10017                 rte_dump_physmem_layout(stdout);
10018         else if (!strcmp(res->dump, "dump_socket_mem"))
10019                 dump_socket_mem(stdout);
10020         else if (!strcmp(res->dump, "dump_memzone"))
10021                 rte_memzone_dump(stdout);
10022         else if (!strcmp(res->dump, "dump_struct_sizes"))
10023                 dump_struct_sizes();
10024         else if (!strcmp(res->dump, "dump_ring"))
10025                 rte_ring_list_dump(stdout);
10026         else if (!strcmp(res->dump, "dump_mempool"))
10027                 rte_mempool_list_dump(stdout);
10028         else if (!strcmp(res->dump, "dump_devargs"))
10029                 rte_devargs_dump(stdout);
10030         else if (!strcmp(res->dump, "dump_log_types"))
10031                 rte_log_dump(stdout);
10032 }
10033
10034 cmdline_parse_token_string_t cmd_dump_dump =
10035         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
10036                 "dump_physmem#"
10037                 "dump_memzone#"
10038                 "dump_socket_mem#"
10039                 "dump_struct_sizes#"
10040                 "dump_ring#"
10041                 "dump_mempool#"
10042                 "dump_devargs#"
10043                 "dump_log_types");
10044
10045 cmdline_parse_inst_t cmd_dump = {
10046         .f = cmd_dump_parsed,  /* function to call */
10047         .data = NULL,      /* 2nd arg of func */
10048         .help_str = "Dump status",
10049         .tokens = {        /* token list, NULL terminated */
10050                 (void *)&cmd_dump_dump,
10051                 NULL,
10052         },
10053 };
10054
10055 /* ******************************************************************************** */
10056
10057 struct cmd_dump_one_result {
10058         cmdline_fixed_string_t dump;
10059         cmdline_fixed_string_t name;
10060 };
10061
10062 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10063                                 __rte_unused void *data)
10064 {
10065         struct cmd_dump_one_result *res = parsed_result;
10066
10067         if (!strcmp(res->dump, "dump_ring")) {
10068                 struct rte_ring *r;
10069                 r = rte_ring_lookup(res->name);
10070                 if (r == NULL) {
10071                         cmdline_printf(cl, "Cannot find ring\n");
10072                         return;
10073                 }
10074                 rte_ring_dump(stdout, r);
10075         } else if (!strcmp(res->dump, "dump_mempool")) {
10076                 struct rte_mempool *mp;
10077                 mp = rte_mempool_lookup(res->name);
10078                 if (mp == NULL) {
10079                         cmdline_printf(cl, "Cannot find mempool\n");
10080                         return;
10081                 }
10082                 rte_mempool_dump(stdout, mp);
10083         }
10084 }
10085
10086 cmdline_parse_token_string_t cmd_dump_one_dump =
10087         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10088                                  "dump_ring#dump_mempool");
10089
10090 cmdline_parse_token_string_t cmd_dump_one_name =
10091         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10092
10093 cmdline_parse_inst_t cmd_dump_one = {
10094         .f = cmd_dump_one_parsed,  /* function to call */
10095         .data = NULL,      /* 2nd arg of func */
10096         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10097         .tokens = {        /* token list, NULL terminated */
10098                 (void *)&cmd_dump_one_dump,
10099                 (void *)&cmd_dump_one_name,
10100                 NULL,
10101         },
10102 };
10103
10104 /* *** Add/Del syn filter *** */
10105 struct cmd_syn_filter_result {
10106         cmdline_fixed_string_t filter;
10107         portid_t port_id;
10108         cmdline_fixed_string_t ops;
10109         cmdline_fixed_string_t priority;
10110         cmdline_fixed_string_t high;
10111         cmdline_fixed_string_t queue;
10112         uint16_t queue_id;
10113 };
10114
10115 static void
10116 cmd_syn_filter_parsed(void *parsed_result,
10117                         __rte_unused struct cmdline *cl,
10118                         __rte_unused void *data)
10119 {
10120         struct cmd_syn_filter_result *res = parsed_result;
10121         struct rte_eth_syn_filter syn_filter;
10122         int ret = 0;
10123
10124         ret = rte_eth_dev_filter_supported(res->port_id,
10125                                         RTE_ETH_FILTER_SYN);
10126         if (ret < 0) {
10127                 printf("syn filter is not supported on port %u.\n",
10128                                 res->port_id);
10129                 return;
10130         }
10131
10132         memset(&syn_filter, 0, sizeof(syn_filter));
10133
10134         if (!strcmp(res->ops, "add")) {
10135                 if (!strcmp(res->high, "high"))
10136                         syn_filter.hig_pri = 1;
10137                 else
10138                         syn_filter.hig_pri = 0;
10139
10140                 syn_filter.queue = res->queue_id;
10141                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10142                                                 RTE_ETH_FILTER_SYN,
10143                                                 RTE_ETH_FILTER_ADD,
10144                                                 &syn_filter);
10145         } else
10146                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10147                                                 RTE_ETH_FILTER_SYN,
10148                                                 RTE_ETH_FILTER_DELETE,
10149                                                 &syn_filter);
10150
10151         if (ret < 0)
10152                 printf("syn filter programming error: (%s)\n",
10153                                 strerror(-ret));
10154 }
10155
10156 cmdline_parse_token_string_t cmd_syn_filter_filter =
10157         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10158         filter, "syn_filter");
10159 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10160         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10161         port_id, UINT16);
10162 cmdline_parse_token_string_t cmd_syn_filter_ops =
10163         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10164         ops, "add#del");
10165 cmdline_parse_token_string_t cmd_syn_filter_priority =
10166         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10167                                 priority, "priority");
10168 cmdline_parse_token_string_t cmd_syn_filter_high =
10169         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10170                                 high, "high#low");
10171 cmdline_parse_token_string_t cmd_syn_filter_queue =
10172         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10173                                 queue, "queue");
10174 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10175         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10176                                 queue_id, UINT16);
10177
10178 cmdline_parse_inst_t cmd_syn_filter = {
10179         .f = cmd_syn_filter_parsed,
10180         .data = NULL,
10181         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10182                 "<queue_id>: Add/Delete syn filter",
10183         .tokens = {
10184                 (void *)&cmd_syn_filter_filter,
10185                 (void *)&cmd_syn_filter_port_id,
10186                 (void *)&cmd_syn_filter_ops,
10187                 (void *)&cmd_syn_filter_priority,
10188                 (void *)&cmd_syn_filter_high,
10189                 (void *)&cmd_syn_filter_queue,
10190                 (void *)&cmd_syn_filter_queue_id,
10191                 NULL,
10192         },
10193 };
10194
10195 /* *** queue region set *** */
10196 struct cmd_queue_region_result {
10197         cmdline_fixed_string_t set;
10198         cmdline_fixed_string_t port;
10199         portid_t port_id;
10200         cmdline_fixed_string_t cmd;
10201         cmdline_fixed_string_t region;
10202         uint8_t  region_id;
10203         cmdline_fixed_string_t queue_start_index;
10204         uint8_t  queue_id;
10205         cmdline_fixed_string_t queue_num;
10206         uint8_t  queue_num_value;
10207 };
10208
10209 static void
10210 cmd_queue_region_parsed(void *parsed_result,
10211                         __rte_unused struct cmdline *cl,
10212                         __rte_unused void *data)
10213 {
10214         struct cmd_queue_region_result *res = parsed_result;
10215         int ret = -ENOTSUP;
10216 #ifdef RTE_NET_I40E
10217         struct rte_pmd_i40e_queue_region_conf region_conf;
10218         enum rte_pmd_i40e_queue_region_op op_type;
10219 #endif
10220
10221         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10222                 return;
10223
10224 #ifdef RTE_NET_I40E
10225         memset(&region_conf, 0, sizeof(region_conf));
10226         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10227         region_conf.region_id = res->region_id;
10228         region_conf.queue_num = res->queue_num_value;
10229         region_conf.queue_start_index = res->queue_id;
10230
10231         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10232                                 op_type, &region_conf);
10233 #endif
10234
10235         switch (ret) {
10236         case 0:
10237                 break;
10238         case -ENOTSUP:
10239                 printf("function not implemented or supported\n");
10240                 break;
10241         default:
10242                 printf("queue region config error: (%s)\n", strerror(-ret));
10243         }
10244 }
10245
10246 cmdline_parse_token_string_t cmd_queue_region_set =
10247 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10248                 set, "set");
10249 cmdline_parse_token_string_t cmd_queue_region_port =
10250         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10251 cmdline_parse_token_num_t cmd_queue_region_port_id =
10252         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10253                                 port_id, UINT16);
10254 cmdline_parse_token_string_t cmd_queue_region_cmd =
10255         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10256                                  cmd, "queue-region");
10257 cmdline_parse_token_string_t cmd_queue_region_id =
10258         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10259                                 region, "region_id");
10260 cmdline_parse_token_num_t cmd_queue_region_index =
10261         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10262                                 region_id, UINT8);
10263 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10264         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10265                                 queue_start_index, "queue_start_index");
10266 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10267         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10268                                 queue_id, UINT8);
10269 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10270         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10271                                 queue_num, "queue_num");
10272 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10273         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10274                                 queue_num_value, UINT8);
10275
10276 cmdline_parse_inst_t cmd_queue_region = {
10277         .f = cmd_queue_region_parsed,
10278         .data = NULL,
10279         .help_str = "set port <port_id> queue-region region_id <value> "
10280                 "queue_start_index <value> queue_num <value>: Set a queue region",
10281         .tokens = {
10282                 (void *)&cmd_queue_region_set,
10283                 (void *)&cmd_queue_region_port,
10284                 (void *)&cmd_queue_region_port_id,
10285                 (void *)&cmd_queue_region_cmd,
10286                 (void *)&cmd_queue_region_id,
10287                 (void *)&cmd_queue_region_index,
10288                 (void *)&cmd_queue_region_queue_start_index,
10289                 (void *)&cmd_queue_region_queue_id,
10290                 (void *)&cmd_queue_region_queue_num,
10291                 (void *)&cmd_queue_region_queue_num_value,
10292                 NULL,
10293         },
10294 };
10295
10296 /* *** queue region and flowtype set *** */
10297 struct cmd_region_flowtype_result {
10298         cmdline_fixed_string_t set;
10299         cmdline_fixed_string_t port;
10300         portid_t port_id;
10301         cmdline_fixed_string_t cmd;
10302         cmdline_fixed_string_t region;
10303         uint8_t  region_id;
10304         cmdline_fixed_string_t flowtype;
10305         uint8_t  flowtype_id;
10306 };
10307
10308 static void
10309 cmd_region_flowtype_parsed(void *parsed_result,
10310                         __rte_unused struct cmdline *cl,
10311                         __rte_unused void *data)
10312 {
10313         struct cmd_region_flowtype_result *res = parsed_result;
10314         int ret = -ENOTSUP;
10315 #ifdef RTE_NET_I40E
10316         struct rte_pmd_i40e_queue_region_conf region_conf;
10317         enum rte_pmd_i40e_queue_region_op op_type;
10318 #endif
10319
10320         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10321                 return;
10322
10323 #ifdef RTE_NET_I40E
10324         memset(&region_conf, 0, sizeof(region_conf));
10325
10326         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10327         region_conf.region_id = res->region_id;
10328         region_conf.hw_flowtype = res->flowtype_id;
10329
10330         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10331                         op_type, &region_conf);
10332 #endif
10333
10334         switch (ret) {
10335         case 0:
10336                 break;
10337         case -ENOTSUP:
10338                 printf("function not implemented or supported\n");
10339                 break;
10340         default:
10341                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10342         }
10343 }
10344
10345 cmdline_parse_token_string_t cmd_region_flowtype_set =
10346 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10347                                 set, "set");
10348 cmdline_parse_token_string_t cmd_region_flowtype_port =
10349         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10350                                 port, "port");
10351 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10352         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10353                                 port_id, UINT16);
10354 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10355         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10356                                 cmd, "queue-region");
10357 cmdline_parse_token_string_t cmd_region_flowtype_index =
10358         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10359                                 region, "region_id");
10360 cmdline_parse_token_num_t cmd_region_flowtype_id =
10361         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10362                                 region_id, UINT8);
10363 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10364         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10365                                 flowtype, "flowtype");
10366 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10367         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10368                                 flowtype_id, UINT8);
10369 cmdline_parse_inst_t cmd_region_flowtype = {
10370         .f = cmd_region_flowtype_parsed,
10371         .data = NULL,
10372         .help_str = "set port <port_id> queue-region region_id <value> "
10373                 "flowtype <value>: Set a flowtype region index",
10374         .tokens = {
10375                 (void *)&cmd_region_flowtype_set,
10376                 (void *)&cmd_region_flowtype_port,
10377                 (void *)&cmd_region_flowtype_port_index,
10378                 (void *)&cmd_region_flowtype_cmd,
10379                 (void *)&cmd_region_flowtype_index,
10380                 (void *)&cmd_region_flowtype_id,
10381                 (void *)&cmd_region_flowtype_flow_index,
10382                 (void *)&cmd_region_flowtype_flow_id,
10383                 NULL,
10384         },
10385 };
10386
10387 /* *** User Priority (UP) to queue region (region_id) set *** */
10388 struct cmd_user_priority_region_result {
10389         cmdline_fixed_string_t set;
10390         cmdline_fixed_string_t port;
10391         portid_t port_id;
10392         cmdline_fixed_string_t cmd;
10393         cmdline_fixed_string_t user_priority;
10394         uint8_t  user_priority_id;
10395         cmdline_fixed_string_t region;
10396         uint8_t  region_id;
10397 };
10398
10399 static void
10400 cmd_user_priority_region_parsed(void *parsed_result,
10401                         __rte_unused struct cmdline *cl,
10402                         __rte_unused void *data)
10403 {
10404         struct cmd_user_priority_region_result *res = parsed_result;
10405         int ret = -ENOTSUP;
10406 #ifdef RTE_NET_I40E
10407         struct rte_pmd_i40e_queue_region_conf region_conf;
10408         enum rte_pmd_i40e_queue_region_op op_type;
10409 #endif
10410
10411         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10412                 return;
10413
10414 #ifdef RTE_NET_I40E
10415         memset(&region_conf, 0, sizeof(region_conf));
10416         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10417         region_conf.user_priority = res->user_priority_id;
10418         region_conf.region_id = res->region_id;
10419
10420         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10421                                 op_type, &region_conf);
10422 #endif
10423
10424         switch (ret) {
10425         case 0:
10426                 break;
10427         case -ENOTSUP:
10428                 printf("function not implemented or supported\n");
10429                 break;
10430         default:
10431                 printf("user_priority region config error: (%s)\n",
10432                                 strerror(-ret));
10433         }
10434 }
10435
10436 cmdline_parse_token_string_t cmd_user_priority_region_set =
10437         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10438                                 set, "set");
10439 cmdline_parse_token_string_t cmd_user_priority_region_port =
10440         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10441                                 port, "port");
10442 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10443         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10444                                 port_id, UINT16);
10445 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10446         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10447                                 cmd, "queue-region");
10448 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10449         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10450                                 user_priority, "UP");
10451 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10452         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10453                                 user_priority_id, UINT8);
10454 cmdline_parse_token_string_t cmd_user_priority_region_region =
10455         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10456                                 region, "region_id");
10457 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10458         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10459                                 region_id, UINT8);
10460
10461 cmdline_parse_inst_t cmd_user_priority_region = {
10462         .f = cmd_user_priority_region_parsed,
10463         .data = NULL,
10464         .help_str = "set port <port_id> queue-region UP <value> "
10465                 "region_id <value>: Set the mapping of User Priority (UP) "
10466                 "to queue region (region_id) ",
10467         .tokens = {
10468                 (void *)&cmd_user_priority_region_set,
10469                 (void *)&cmd_user_priority_region_port,
10470                 (void *)&cmd_user_priority_region_port_index,
10471                 (void *)&cmd_user_priority_region_cmd,
10472                 (void *)&cmd_user_priority_region_UP,
10473                 (void *)&cmd_user_priority_region_UP_id,
10474                 (void *)&cmd_user_priority_region_region,
10475                 (void *)&cmd_user_priority_region_region_id,
10476                 NULL,
10477         },
10478 };
10479
10480 /* *** flush all queue region related configuration *** */
10481 struct cmd_flush_queue_region_result {
10482         cmdline_fixed_string_t set;
10483         cmdline_fixed_string_t port;
10484         portid_t port_id;
10485         cmdline_fixed_string_t cmd;
10486         cmdline_fixed_string_t flush;
10487         cmdline_fixed_string_t what;
10488 };
10489
10490 static void
10491 cmd_flush_queue_region_parsed(void *parsed_result,
10492                         __rte_unused struct cmdline *cl,
10493                         __rte_unused void *data)
10494 {
10495         struct cmd_flush_queue_region_result *res = parsed_result;
10496         int ret = -ENOTSUP;
10497 #ifdef RTE_NET_I40E
10498         struct rte_pmd_i40e_queue_region_conf region_conf;
10499         enum rte_pmd_i40e_queue_region_op op_type;
10500 #endif
10501
10502         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10503                 return;
10504
10505 #ifdef RTE_NET_I40E
10506         memset(&region_conf, 0, sizeof(region_conf));
10507
10508         if (strcmp(res->what, "on") == 0)
10509                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10510         else
10511                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10512
10513         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10514                                 op_type, &region_conf);
10515 #endif
10516
10517         switch (ret) {
10518         case 0:
10519                 break;
10520         case -ENOTSUP:
10521                 printf("function not implemented or supported\n");
10522                 break;
10523         default:
10524                 printf("queue region config flush error: (%s)\n",
10525                                 strerror(-ret));
10526         }
10527 }
10528
10529 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10530         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10531                                 set, "set");
10532 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10533         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10534                                 port, "port");
10535 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10536         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10537                                 port_id, UINT16);
10538 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10539         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10540                                 cmd, "queue-region");
10541 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10542         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10543                                 flush, "flush");
10544 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10545         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10546                                 what, "on#off");
10547
10548 cmdline_parse_inst_t cmd_flush_queue_region = {
10549         .f = cmd_flush_queue_region_parsed,
10550         .data = NULL,
10551         .help_str = "set port <port_id> queue-region flush on|off"
10552                 ": flush all queue region related configuration",
10553         .tokens = {
10554                 (void *)&cmd_flush_queue_region_set,
10555                 (void *)&cmd_flush_queue_region_port,
10556                 (void *)&cmd_flush_queue_region_port_index,
10557                 (void *)&cmd_flush_queue_region_cmd,
10558                 (void *)&cmd_flush_queue_region_flush,
10559                 (void *)&cmd_flush_queue_region_what,
10560                 NULL,
10561         },
10562 };
10563
10564 /* *** get all queue region related configuration info *** */
10565 struct cmd_show_queue_region_info {
10566         cmdline_fixed_string_t show;
10567         cmdline_fixed_string_t port;
10568         portid_t port_id;
10569         cmdline_fixed_string_t cmd;
10570 };
10571
10572 static void
10573 cmd_show_queue_region_info_parsed(void *parsed_result,
10574                         __rte_unused struct cmdline *cl,
10575                         __rte_unused void *data)
10576 {
10577         struct cmd_show_queue_region_info *res = parsed_result;
10578         int ret = -ENOTSUP;
10579 #ifdef RTE_NET_I40E
10580         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10581         enum rte_pmd_i40e_queue_region_op op_type;
10582 #endif
10583
10584         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10585                 return;
10586
10587 #ifdef RTE_NET_I40E
10588         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10589
10590         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10591
10592         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10593                                         op_type, &rte_pmd_regions);
10594
10595         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10596 #endif
10597
10598         switch (ret) {
10599         case 0:
10600                 break;
10601         case -ENOTSUP:
10602                 printf("function not implemented or supported\n");
10603                 break;
10604         default:
10605                 printf("queue region config info show error: (%s)\n",
10606                                 strerror(-ret));
10607         }
10608 }
10609
10610 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10611 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10612                                 show, "show");
10613 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10614         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10615                                 port, "port");
10616 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10617         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10618                                 port_id, UINT16);
10619 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10620         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10621                                 cmd, "queue-region");
10622
10623 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10624         .f = cmd_show_queue_region_info_parsed,
10625         .data = NULL,
10626         .help_str = "show port <port_id> queue-region"
10627                 ": show all queue region related configuration info",
10628         .tokens = {
10629                 (void *)&cmd_show_queue_region_info_get,
10630                 (void *)&cmd_show_queue_region_info_port,
10631                 (void *)&cmd_show_queue_region_info_port_index,
10632                 (void *)&cmd_show_queue_region_info_cmd,
10633                 NULL,
10634         },
10635 };
10636
10637 /* *** ADD/REMOVE A 2tuple FILTER *** */
10638 struct cmd_2tuple_filter_result {
10639         cmdline_fixed_string_t filter;
10640         portid_t port_id;
10641         cmdline_fixed_string_t ops;
10642         cmdline_fixed_string_t dst_port;
10643         uint16_t dst_port_value;
10644         cmdline_fixed_string_t protocol;
10645         uint8_t protocol_value;
10646         cmdline_fixed_string_t mask;
10647         uint8_t  mask_value;
10648         cmdline_fixed_string_t tcp_flags;
10649         uint8_t tcp_flags_value;
10650         cmdline_fixed_string_t priority;
10651         uint8_t  priority_value;
10652         cmdline_fixed_string_t queue;
10653         uint16_t  queue_id;
10654 };
10655
10656 static void
10657 cmd_2tuple_filter_parsed(void *parsed_result,
10658                         __rte_unused struct cmdline *cl,
10659                         __rte_unused void *data)
10660 {
10661         struct rte_eth_ntuple_filter filter;
10662         struct cmd_2tuple_filter_result *res = parsed_result;
10663         int ret = 0;
10664
10665         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10666         if (ret < 0) {
10667                 printf("ntuple filter is not supported on port %u.\n",
10668                         res->port_id);
10669                 return;
10670         }
10671
10672         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10673
10674         filter.flags = RTE_2TUPLE_FLAGS;
10675         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10676         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10677         filter.proto = res->protocol_value;
10678         filter.priority = res->priority_value;
10679         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10680                 printf("nonzero tcp_flags is only meaningful"
10681                         " when protocol is TCP.\n");
10682                 return;
10683         }
10684         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10685                 printf("invalid TCP flags.\n");
10686                 return;
10687         }
10688
10689         if (res->tcp_flags_value != 0) {
10690                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10691                 filter.tcp_flags = res->tcp_flags_value;
10692         }
10693
10694         /* need convert to big endian. */
10695         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10696         filter.queue = res->queue_id;
10697
10698         if (!strcmp(res->ops, "add"))
10699                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10700                                 RTE_ETH_FILTER_NTUPLE,
10701                                 RTE_ETH_FILTER_ADD,
10702                                 &filter);
10703         else
10704                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10705                                 RTE_ETH_FILTER_NTUPLE,
10706                                 RTE_ETH_FILTER_DELETE,
10707                                 &filter);
10708         if (ret < 0)
10709                 printf("2tuple filter programming error: (%s)\n",
10710                         strerror(-ret));
10711
10712 }
10713
10714 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10715         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10716                                  filter, "2tuple_filter");
10717 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10718         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10719                                 port_id, UINT16);
10720 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10721         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10722                                  ops, "add#del");
10723 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10724         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10725                                 dst_port, "dst_port");
10726 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10727         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10728                                 dst_port_value, UINT16);
10729 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10730         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10731                                 protocol, "protocol");
10732 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10733         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10734                                 protocol_value, UINT8);
10735 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10736         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10737                                 mask, "mask");
10738 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10739         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10740                                 mask_value, INT8);
10741 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10742         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10743                                 tcp_flags, "tcp_flags");
10744 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10745         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10746                                 tcp_flags_value, UINT8);
10747 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10748         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10749                                 priority, "priority");
10750 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10751         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10752                                 priority_value, UINT8);
10753 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10754         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10755                                 queue, "queue");
10756 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10757         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10758                                 queue_id, UINT16);
10759
10760 cmdline_parse_inst_t cmd_2tuple_filter = {
10761         .f = cmd_2tuple_filter_parsed,
10762         .data = NULL,
10763         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10764                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10765                 "<queue_id>: Add a 2tuple filter",
10766         .tokens = {
10767                 (void *)&cmd_2tuple_filter_filter,
10768                 (void *)&cmd_2tuple_filter_port_id,
10769                 (void *)&cmd_2tuple_filter_ops,
10770                 (void *)&cmd_2tuple_filter_dst_port,
10771                 (void *)&cmd_2tuple_filter_dst_port_value,
10772                 (void *)&cmd_2tuple_filter_protocol,
10773                 (void *)&cmd_2tuple_filter_protocol_value,
10774                 (void *)&cmd_2tuple_filter_mask,
10775                 (void *)&cmd_2tuple_filter_mask_value,
10776                 (void *)&cmd_2tuple_filter_tcp_flags,
10777                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10778                 (void *)&cmd_2tuple_filter_priority,
10779                 (void *)&cmd_2tuple_filter_priority_value,
10780                 (void *)&cmd_2tuple_filter_queue,
10781                 (void *)&cmd_2tuple_filter_queue_id,
10782                 NULL,
10783         },
10784 };
10785
10786 /* *** ADD/REMOVE A 5tuple FILTER *** */
10787 struct cmd_5tuple_filter_result {
10788         cmdline_fixed_string_t filter;
10789         portid_t port_id;
10790         cmdline_fixed_string_t ops;
10791         cmdline_fixed_string_t dst_ip;
10792         cmdline_ipaddr_t dst_ip_value;
10793         cmdline_fixed_string_t src_ip;
10794         cmdline_ipaddr_t src_ip_value;
10795         cmdline_fixed_string_t dst_port;
10796         uint16_t dst_port_value;
10797         cmdline_fixed_string_t src_port;
10798         uint16_t src_port_value;
10799         cmdline_fixed_string_t protocol;
10800         uint8_t protocol_value;
10801         cmdline_fixed_string_t mask;
10802         uint8_t  mask_value;
10803         cmdline_fixed_string_t tcp_flags;
10804         uint8_t tcp_flags_value;
10805         cmdline_fixed_string_t priority;
10806         uint8_t  priority_value;
10807         cmdline_fixed_string_t queue;
10808         uint16_t  queue_id;
10809 };
10810
10811 static void
10812 cmd_5tuple_filter_parsed(void *parsed_result,
10813                         __rte_unused struct cmdline *cl,
10814                         __rte_unused void *data)
10815 {
10816         struct rte_eth_ntuple_filter filter;
10817         struct cmd_5tuple_filter_result *res = parsed_result;
10818         int ret = 0;
10819
10820         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10821         if (ret < 0) {
10822                 printf("ntuple filter is not supported on port %u.\n",
10823                         res->port_id);
10824                 return;
10825         }
10826
10827         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10828
10829         filter.flags = RTE_5TUPLE_FLAGS;
10830         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10831         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10832         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10833         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10834         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10835         filter.proto = res->protocol_value;
10836         filter.priority = res->priority_value;
10837         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10838                 printf("nonzero tcp_flags is only meaningful"
10839                         " when protocol is TCP.\n");
10840                 return;
10841         }
10842         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10843                 printf("invalid TCP flags.\n");
10844                 return;
10845         }
10846
10847         if (res->tcp_flags_value != 0) {
10848                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10849                 filter.tcp_flags = res->tcp_flags_value;
10850         }
10851
10852         if (res->dst_ip_value.family == AF_INET)
10853                 /* no need to convert, already big endian. */
10854                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10855         else {
10856                 if (filter.dst_ip_mask == 0) {
10857                         printf("can not support ipv6 involved compare.\n");
10858                         return;
10859                 }
10860                 filter.dst_ip = 0;
10861         }
10862
10863         if (res->src_ip_value.family == AF_INET)
10864                 /* no need to convert, already big endian. */
10865                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10866         else {
10867                 if (filter.src_ip_mask == 0) {
10868                         printf("can not support ipv6 involved compare.\n");
10869                         return;
10870                 }
10871                 filter.src_ip = 0;
10872         }
10873         /* need convert to big endian. */
10874         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10875         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10876         filter.queue = res->queue_id;
10877
10878         if (!strcmp(res->ops, "add"))
10879                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10880                                 RTE_ETH_FILTER_NTUPLE,
10881                                 RTE_ETH_FILTER_ADD,
10882                                 &filter);
10883         else
10884                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10885                                 RTE_ETH_FILTER_NTUPLE,
10886                                 RTE_ETH_FILTER_DELETE,
10887                                 &filter);
10888         if (ret < 0)
10889                 printf("5tuple filter programming error: (%s)\n",
10890                         strerror(-ret));
10891 }
10892
10893 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10894         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10895                                  filter, "5tuple_filter");
10896 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10897         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10898                                 port_id, UINT16);
10899 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10900         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10901                                  ops, "add#del");
10902 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10903         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10904                                 dst_ip, "dst_ip");
10905 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10906         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10907                                 dst_ip_value);
10908 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10909         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10910                                 src_ip, "src_ip");
10911 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10912         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10913                                 src_ip_value);
10914 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10915         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10916                                 dst_port, "dst_port");
10917 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10918         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10919                                 dst_port_value, UINT16);
10920 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10921         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10922                                 src_port, "src_port");
10923 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10924         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10925                                 src_port_value, UINT16);
10926 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10927         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10928                                 protocol, "protocol");
10929 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10930         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10931                                 protocol_value, UINT8);
10932 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10933         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10934                                 mask, "mask");
10935 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10936         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10937                                 mask_value, INT8);
10938 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10939         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10940                                 tcp_flags, "tcp_flags");
10941 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10942         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10943                                 tcp_flags_value, UINT8);
10944 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10945         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10946                                 priority, "priority");
10947 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10948         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10949                                 priority_value, UINT8);
10950 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10951         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10952                                 queue, "queue");
10953 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10954         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10955                                 queue_id, UINT16);
10956
10957 cmdline_parse_inst_t cmd_5tuple_filter = {
10958         .f = cmd_5tuple_filter_parsed,
10959         .data = NULL,
10960         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10961                 "src_ip <value> dst_port <value> src_port <value> "
10962                 "protocol <value>  mask <value> tcp_flags <value> "
10963                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10964         .tokens = {
10965                 (void *)&cmd_5tuple_filter_filter,
10966                 (void *)&cmd_5tuple_filter_port_id,
10967                 (void *)&cmd_5tuple_filter_ops,
10968                 (void *)&cmd_5tuple_filter_dst_ip,
10969                 (void *)&cmd_5tuple_filter_dst_ip_value,
10970                 (void *)&cmd_5tuple_filter_src_ip,
10971                 (void *)&cmd_5tuple_filter_src_ip_value,
10972                 (void *)&cmd_5tuple_filter_dst_port,
10973                 (void *)&cmd_5tuple_filter_dst_port_value,
10974                 (void *)&cmd_5tuple_filter_src_port,
10975                 (void *)&cmd_5tuple_filter_src_port_value,
10976                 (void *)&cmd_5tuple_filter_protocol,
10977                 (void *)&cmd_5tuple_filter_protocol_value,
10978                 (void *)&cmd_5tuple_filter_mask,
10979                 (void *)&cmd_5tuple_filter_mask_value,
10980                 (void *)&cmd_5tuple_filter_tcp_flags,
10981                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10982                 (void *)&cmd_5tuple_filter_priority,
10983                 (void *)&cmd_5tuple_filter_priority_value,
10984                 (void *)&cmd_5tuple_filter_queue,
10985                 (void *)&cmd_5tuple_filter_queue_id,
10986                 NULL,
10987         },
10988 };
10989
10990 /* *** ADD/REMOVE A flex FILTER *** */
10991 struct cmd_flex_filter_result {
10992         cmdline_fixed_string_t filter;
10993         cmdline_fixed_string_t ops;
10994         portid_t port_id;
10995         cmdline_fixed_string_t len;
10996         uint8_t len_value;
10997         cmdline_fixed_string_t bytes;
10998         cmdline_fixed_string_t bytes_value;
10999         cmdline_fixed_string_t mask;
11000         cmdline_fixed_string_t mask_value;
11001         cmdline_fixed_string_t priority;
11002         uint8_t priority_value;
11003         cmdline_fixed_string_t queue;
11004         uint16_t queue_id;
11005 };
11006
11007 static int xdigit2val(unsigned char c)
11008 {
11009         int val;
11010         if (isdigit(c))
11011                 val = c - '0';
11012         else if (isupper(c))
11013                 val = c - 'A' + 10;
11014         else
11015                 val = c - 'a' + 10;
11016         return val;
11017 }
11018
11019 static void
11020 cmd_flex_filter_parsed(void *parsed_result,
11021                           __rte_unused struct cmdline *cl,
11022                           __rte_unused void *data)
11023 {
11024         int ret = 0;
11025         struct rte_eth_flex_filter filter;
11026         struct cmd_flex_filter_result *res = parsed_result;
11027         char *bytes_ptr, *mask_ptr;
11028         uint16_t len, i, j = 0;
11029         char c;
11030         int val;
11031         uint8_t byte = 0;
11032
11033         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
11034                 printf("the len exceed the max length 128\n");
11035                 return;
11036         }
11037         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
11038         filter.len = res->len_value;
11039         filter.priority = res->priority_value;
11040         filter.queue = res->queue_id;
11041         bytes_ptr = res->bytes_value;
11042         mask_ptr = res->mask_value;
11043
11044          /* translate bytes string to array. */
11045         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
11046                 (bytes_ptr[1] == 'X')))
11047                 bytes_ptr += 2;
11048         len = strnlen(bytes_ptr, res->len_value * 2);
11049         if (len == 0 || (len % 8 != 0)) {
11050                 printf("please check len and bytes input\n");
11051                 return;
11052         }
11053         for (i = 0; i < len; i++) {
11054                 c = bytes_ptr[i];
11055                 if (isxdigit(c) == 0) {
11056                         /* invalid characters. */
11057                         printf("invalid input\n");
11058                         return;
11059                 }
11060                 val = xdigit2val(c);
11061                 if (i % 2) {
11062                         byte |= val;
11063                         filter.bytes[j] = byte;
11064                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
11065                         j++;
11066                         byte = 0;
11067                 } else
11068                         byte |= val << 4;
11069         }
11070         printf("\n");
11071          /* translate mask string to uint8_t array. */
11072         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
11073                 (mask_ptr[1] == 'X')))
11074                 mask_ptr += 2;
11075         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
11076         if (len == 0) {
11077                 printf("invalid input\n");
11078                 return;
11079         }
11080         j = 0;
11081         byte = 0;
11082         for (i = 0; i < len; i++) {
11083                 c = mask_ptr[i];
11084                 if (isxdigit(c) == 0) {
11085                         /* invalid characters. */
11086                         printf("invalid input\n");
11087                         return;
11088                 }
11089                 val = xdigit2val(c);
11090                 if (i % 2) {
11091                         byte |= val;
11092                         filter.mask[j] = byte;
11093                         printf("mask[%d]:%02x ", j, filter.mask[j]);
11094                         j++;
11095                         byte = 0;
11096                 } else
11097                         byte |= val << 4;
11098         }
11099         printf("\n");
11100
11101         if (!strcmp(res->ops, "add"))
11102                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11103                                 RTE_ETH_FILTER_FLEXIBLE,
11104                                 RTE_ETH_FILTER_ADD,
11105                                 &filter);
11106         else
11107                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11108                                 RTE_ETH_FILTER_FLEXIBLE,
11109                                 RTE_ETH_FILTER_DELETE,
11110                                 &filter);
11111
11112         if (ret < 0)
11113                 printf("flex filter setting error: (%s)\n", strerror(-ret));
11114 }
11115
11116 cmdline_parse_token_string_t cmd_flex_filter_filter =
11117         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11118                                 filter, "flex_filter");
11119 cmdline_parse_token_num_t cmd_flex_filter_port_id =
11120         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11121                                 port_id, UINT16);
11122 cmdline_parse_token_string_t cmd_flex_filter_ops =
11123         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11124                                 ops, "add#del");
11125 cmdline_parse_token_string_t cmd_flex_filter_len =
11126         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11127                                 len, "len");
11128 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11129         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11130                                 len_value, UINT8);
11131 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11132         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11133                                 bytes, "bytes");
11134 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11135         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11136                                 bytes_value, NULL);
11137 cmdline_parse_token_string_t cmd_flex_filter_mask =
11138         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11139                                 mask, "mask");
11140 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11141         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11142                                 mask_value, NULL);
11143 cmdline_parse_token_string_t cmd_flex_filter_priority =
11144         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11145                                 priority, "priority");
11146 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11147         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11148                                 priority_value, UINT8);
11149 cmdline_parse_token_string_t cmd_flex_filter_queue =
11150         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11151                                 queue, "queue");
11152 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11153         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11154                                 queue_id, UINT16);
11155 cmdline_parse_inst_t cmd_flex_filter = {
11156         .f = cmd_flex_filter_parsed,
11157         .data = NULL,
11158         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11159                 "<value> mask <value> priority <value> queue <queue_id>: "
11160                 "Add/Del a flex filter",
11161         .tokens = {
11162                 (void *)&cmd_flex_filter_filter,
11163                 (void *)&cmd_flex_filter_port_id,
11164                 (void *)&cmd_flex_filter_ops,
11165                 (void *)&cmd_flex_filter_len,
11166                 (void *)&cmd_flex_filter_len_value,
11167                 (void *)&cmd_flex_filter_bytes,
11168                 (void *)&cmd_flex_filter_bytes_value,
11169                 (void *)&cmd_flex_filter_mask,
11170                 (void *)&cmd_flex_filter_mask_value,
11171                 (void *)&cmd_flex_filter_priority,
11172                 (void *)&cmd_flex_filter_priority_value,
11173                 (void *)&cmd_flex_filter_queue,
11174                 (void *)&cmd_flex_filter_queue_id,
11175                 NULL,
11176         },
11177 };
11178
11179 /* *** Filters Control *** */
11180
11181 /* *** deal with ethertype filter *** */
11182 struct cmd_ethertype_filter_result {
11183         cmdline_fixed_string_t filter;
11184         portid_t port_id;
11185         cmdline_fixed_string_t ops;
11186         cmdline_fixed_string_t mac;
11187         struct rte_ether_addr mac_addr;
11188         cmdline_fixed_string_t ethertype;
11189         uint16_t ethertype_value;
11190         cmdline_fixed_string_t drop;
11191         cmdline_fixed_string_t queue;
11192         uint16_t  queue_id;
11193 };
11194
11195 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11196         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11197                                  filter, "ethertype_filter");
11198 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11199         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11200                               port_id, UINT16);
11201 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11202         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11203                                  ops, "add#del");
11204 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11205         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11206                                  mac, "mac_addr#mac_ignr");
11207 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11209                                      mac_addr);
11210 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11211         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11212                                  ethertype, "ethertype");
11213 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11214         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11215                               ethertype_value, UINT16);
11216 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11217         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11218                                  drop, "drop#fwd");
11219 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11220         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11221                                  queue, "queue");
11222 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11223         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11224                               queue_id, UINT16);
11225
11226 static void
11227 cmd_ethertype_filter_parsed(void *parsed_result,
11228                           __rte_unused struct cmdline *cl,
11229                           __rte_unused void *data)
11230 {
11231         struct cmd_ethertype_filter_result *res = parsed_result;
11232         struct rte_eth_ethertype_filter filter;
11233         int ret = 0;
11234
11235         ret = rte_eth_dev_filter_supported(res->port_id,
11236                         RTE_ETH_FILTER_ETHERTYPE);
11237         if (ret < 0) {
11238                 printf("ethertype filter is not supported on port %u.\n",
11239                         res->port_id);
11240                 return;
11241         }
11242
11243         memset(&filter, 0, sizeof(filter));
11244         if (!strcmp(res->mac, "mac_addr")) {
11245                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11246                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11247                         sizeof(struct rte_ether_addr));
11248         }
11249         if (!strcmp(res->drop, "drop"))
11250                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11251         filter.ether_type = res->ethertype_value;
11252         filter.queue = res->queue_id;
11253
11254         if (!strcmp(res->ops, "add"))
11255                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11256                                 RTE_ETH_FILTER_ETHERTYPE,
11257                                 RTE_ETH_FILTER_ADD,
11258                                 &filter);
11259         else
11260                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11261                                 RTE_ETH_FILTER_ETHERTYPE,
11262                                 RTE_ETH_FILTER_DELETE,
11263                                 &filter);
11264         if (ret < 0)
11265                 printf("ethertype filter programming error: (%s)\n",
11266                         strerror(-ret));
11267 }
11268
11269 cmdline_parse_inst_t cmd_ethertype_filter = {
11270         .f = cmd_ethertype_filter_parsed,
11271         .data = NULL,
11272         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11273                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11274                 "Add or delete an ethertype filter entry",
11275         .tokens = {
11276                 (void *)&cmd_ethertype_filter_filter,
11277                 (void *)&cmd_ethertype_filter_port_id,
11278                 (void *)&cmd_ethertype_filter_ops,
11279                 (void *)&cmd_ethertype_filter_mac,
11280                 (void *)&cmd_ethertype_filter_mac_addr,
11281                 (void *)&cmd_ethertype_filter_ethertype,
11282                 (void *)&cmd_ethertype_filter_ethertype_value,
11283                 (void *)&cmd_ethertype_filter_drop,
11284                 (void *)&cmd_ethertype_filter_queue,
11285                 (void *)&cmd_ethertype_filter_queue_id,
11286                 NULL,
11287         },
11288 };
11289
11290 /* *** deal with flow director filter *** */
11291 struct cmd_flow_director_result {
11292         cmdline_fixed_string_t flow_director_filter;
11293         portid_t port_id;
11294         cmdline_fixed_string_t mode;
11295         cmdline_fixed_string_t mode_value;
11296         cmdline_fixed_string_t ops;
11297         cmdline_fixed_string_t flow;
11298         cmdline_fixed_string_t flow_type;
11299         cmdline_fixed_string_t ether;
11300         uint16_t ether_type;
11301         cmdline_fixed_string_t src;
11302         cmdline_ipaddr_t ip_src;
11303         uint16_t port_src;
11304         cmdline_fixed_string_t dst;
11305         cmdline_ipaddr_t ip_dst;
11306         uint16_t port_dst;
11307         cmdline_fixed_string_t verify_tag;
11308         uint32_t verify_tag_value;
11309         cmdline_fixed_string_t tos;
11310         uint8_t tos_value;
11311         cmdline_fixed_string_t proto;
11312         uint8_t proto_value;
11313         cmdline_fixed_string_t ttl;
11314         uint8_t ttl_value;
11315         cmdline_fixed_string_t vlan;
11316         uint16_t vlan_value;
11317         cmdline_fixed_string_t flexbytes;
11318         cmdline_fixed_string_t flexbytes_value;
11319         cmdline_fixed_string_t pf_vf;
11320         cmdline_fixed_string_t drop;
11321         cmdline_fixed_string_t queue;
11322         uint16_t  queue_id;
11323         cmdline_fixed_string_t fd_id;
11324         uint32_t  fd_id_value;
11325         cmdline_fixed_string_t mac;
11326         struct rte_ether_addr mac_addr;
11327         cmdline_fixed_string_t tunnel;
11328         cmdline_fixed_string_t tunnel_type;
11329         cmdline_fixed_string_t tunnel_id;
11330         uint32_t tunnel_id_value;
11331         cmdline_fixed_string_t packet;
11332         char filepath[];
11333 };
11334
11335 static inline int
11336 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11337 {
11338         char s[256];
11339         const char *p, *p0 = q_arg;
11340         char *end;
11341         unsigned long int_fld;
11342         char *str_fld[max_num];
11343         int i;
11344         unsigned size;
11345         int ret = -1;
11346
11347         p = strchr(p0, '(');
11348         if (p == NULL)
11349                 return -1;
11350         ++p;
11351         p0 = strchr(p, ')');
11352         if (p0 == NULL)
11353                 return -1;
11354
11355         size = p0 - p;
11356         if (size >= sizeof(s))
11357                 return -1;
11358
11359         snprintf(s, sizeof(s), "%.*s", size, p);
11360         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11361         if (ret < 0 || ret > max_num)
11362                 return -1;
11363         for (i = 0; i < ret; i++) {
11364                 errno = 0;
11365                 int_fld = strtoul(str_fld[i], &end, 0);
11366                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11367                         return -1;
11368                 flexbytes[i] = (uint8_t)int_fld;
11369         }
11370         return ret;
11371 }
11372
11373 static uint16_t
11374 str2flowtype(char *string)
11375 {
11376         uint8_t i = 0;
11377         static const struct {
11378                 char str[32];
11379                 uint16_t type;
11380         } flowtype_str[] = {
11381                 {"raw", RTE_ETH_FLOW_RAW},
11382                 {"ipv4", RTE_ETH_FLOW_IPV4},
11383                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11384                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11385                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11386                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11387                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11388                 {"ipv6", RTE_ETH_FLOW_IPV6},
11389                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11390                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11391                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11392                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11393                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11394                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11395         };
11396
11397         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11398                 if (!strcmp(flowtype_str[i].str, string))
11399                         return flowtype_str[i].type;
11400         }
11401
11402         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11403                 return (uint16_t)atoi(string);
11404
11405         return RTE_ETH_FLOW_UNKNOWN;
11406 }
11407
11408 static enum rte_eth_fdir_tunnel_type
11409 str2fdir_tunneltype(char *string)
11410 {
11411         uint8_t i = 0;
11412
11413         static const struct {
11414                 char str[32];
11415                 enum rte_eth_fdir_tunnel_type type;
11416         } tunneltype_str[] = {
11417                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11418                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11419         };
11420
11421         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11422                 if (!strcmp(tunneltype_str[i].str, string))
11423                         return tunneltype_str[i].type;
11424         }
11425         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11426 }
11427
11428 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11429 do { \
11430         if ((ip_addr).family == AF_INET) \
11431                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11432         else { \
11433                 printf("invalid parameter.\n"); \
11434                 return; \
11435         } \
11436 } while (0)
11437
11438 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11439 do { \
11440         if ((ip_addr).family == AF_INET6) \
11441                 rte_memcpy(&(ip), \
11442                                  &((ip_addr).addr.ipv6), \
11443                                  sizeof(struct in6_addr)); \
11444         else { \
11445                 printf("invalid parameter.\n"); \
11446                 return; \
11447         } \
11448 } while (0)
11449
11450 static void
11451 cmd_flow_director_filter_parsed(void *parsed_result,
11452                           __rte_unused struct cmdline *cl,
11453                           __rte_unused void *data)
11454 {
11455         struct cmd_flow_director_result *res = parsed_result;
11456         struct rte_eth_fdir_filter entry;
11457         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11458         char *end;
11459         unsigned long vf_id;
11460         int ret = 0;
11461
11462         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11463         if (ret < 0) {
11464                 printf("flow director is not supported on port %u.\n",
11465                         res->port_id);
11466                 return;
11467         }
11468         memset(flexbytes, 0, sizeof(flexbytes));
11469         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11470
11471         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11472                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11473                         printf("Please set mode to MAC-VLAN.\n");
11474                         return;
11475                 }
11476         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11477                 if (strcmp(res->mode_value, "Tunnel")) {
11478                         printf("Please set mode to Tunnel.\n");
11479                         return;
11480                 }
11481         } else {
11482                 if (!strcmp(res->mode_value, "raw")) {
11483 #ifdef RTE_NET_I40E
11484                         struct rte_pmd_i40e_flow_type_mapping
11485                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11486                         struct rte_pmd_i40e_pkt_template_conf conf;
11487                         uint16_t flow_type = str2flowtype(res->flow_type);
11488                         uint16_t i, port = res->port_id;
11489                         uint8_t add;
11490
11491                         memset(&conf, 0, sizeof(conf));
11492
11493                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11494                                 printf("Invalid flow type specified.\n");
11495                                 return;
11496                         }
11497                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11498                                                                  mapping);
11499                         if (ret)
11500                                 return;
11501                         if (mapping[flow_type].pctype == 0ULL) {
11502                                 printf("Invalid flow type specified.\n");
11503                                 return;
11504                         }
11505                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11506                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11507                                         conf.input.pctype = i;
11508                                         break;
11509                                 }
11510                         }
11511
11512                         conf.input.packet = open_file(res->filepath,
11513                                                 &conf.input.length);
11514                         if (!conf.input.packet)
11515                                 return;
11516                         if (!strcmp(res->drop, "drop"))
11517                                 conf.action.behavior =
11518                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11519                         else
11520                                 conf.action.behavior =
11521                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11522                         conf.action.report_status =
11523                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11524                         conf.action.rx_queue = res->queue_id;
11525                         conf.soft_id = res->fd_id_value;
11526                         add  = strcmp(res->ops, "del") ? 1 : 0;
11527                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11528                                                                         &conf,
11529                                                                         add);
11530                         if (ret < 0)
11531                                 printf("flow director config error: (%s)\n",
11532                                        strerror(-ret));
11533                         close_file(conf.input.packet);
11534 #endif
11535                         return;
11536                 } else if (strcmp(res->mode_value, "IP")) {
11537                         printf("Please set mode to IP or raw.\n");
11538                         return;
11539                 }
11540                 entry.input.flow_type = str2flowtype(res->flow_type);
11541         }
11542
11543         ret = parse_flexbytes(res->flexbytes_value,
11544                                         flexbytes,
11545                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11546         if (ret < 0) {
11547                 printf("error: Cannot parse flexbytes input.\n");
11548                 return;
11549         }
11550
11551         switch (entry.input.flow_type) {
11552         case RTE_ETH_FLOW_FRAG_IPV4:
11553         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11554                 entry.input.flow.ip4_flow.proto = res->proto_value;
11555                 /* fall-through */
11556         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11557         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11558                 IPV4_ADDR_TO_UINT(res->ip_dst,
11559                         entry.input.flow.ip4_flow.dst_ip);
11560                 IPV4_ADDR_TO_UINT(res->ip_src,
11561                         entry.input.flow.ip4_flow.src_ip);
11562                 entry.input.flow.ip4_flow.tos = res->tos_value;
11563                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11564                 /* need convert to big endian. */
11565                 entry.input.flow.udp4_flow.dst_port =
11566                                 rte_cpu_to_be_16(res->port_dst);
11567                 entry.input.flow.udp4_flow.src_port =
11568                                 rte_cpu_to_be_16(res->port_src);
11569                 break;
11570         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11571                 IPV4_ADDR_TO_UINT(res->ip_dst,
11572                         entry.input.flow.sctp4_flow.ip.dst_ip);
11573                 IPV4_ADDR_TO_UINT(res->ip_src,
11574                         entry.input.flow.sctp4_flow.ip.src_ip);
11575                 entry.input.flow.ip4_flow.tos = res->tos_value;
11576                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11577                 /* need convert to big endian. */
11578                 entry.input.flow.sctp4_flow.dst_port =
11579                                 rte_cpu_to_be_16(res->port_dst);
11580                 entry.input.flow.sctp4_flow.src_port =
11581                                 rte_cpu_to_be_16(res->port_src);
11582                 entry.input.flow.sctp4_flow.verify_tag =
11583                                 rte_cpu_to_be_32(res->verify_tag_value);
11584                 break;
11585         case RTE_ETH_FLOW_FRAG_IPV6:
11586         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11587                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11588                 /* fall-through */
11589         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11590         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11591                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11592                         entry.input.flow.ipv6_flow.dst_ip);
11593                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11594                         entry.input.flow.ipv6_flow.src_ip);
11595                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11596                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11597                 /* need convert to big endian. */
11598                 entry.input.flow.udp6_flow.dst_port =
11599                                 rte_cpu_to_be_16(res->port_dst);
11600                 entry.input.flow.udp6_flow.src_port =
11601                                 rte_cpu_to_be_16(res->port_src);
11602                 break;
11603         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11604                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11605                         entry.input.flow.sctp6_flow.ip.dst_ip);
11606                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11607                         entry.input.flow.sctp6_flow.ip.src_ip);
11608                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11609                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11610                 /* need convert to big endian. */
11611                 entry.input.flow.sctp6_flow.dst_port =
11612                                 rte_cpu_to_be_16(res->port_dst);
11613                 entry.input.flow.sctp6_flow.src_port =
11614                                 rte_cpu_to_be_16(res->port_src);
11615                 entry.input.flow.sctp6_flow.verify_tag =
11616                                 rte_cpu_to_be_32(res->verify_tag_value);
11617                 break;
11618         case RTE_ETH_FLOW_L2_PAYLOAD:
11619                 entry.input.flow.l2_flow.ether_type =
11620                         rte_cpu_to_be_16(res->ether_type);
11621                 break;
11622         default:
11623                 break;
11624         }
11625
11626         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11627                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11628                                  &res->mac_addr,
11629                                  sizeof(struct rte_ether_addr));
11630
11631         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11632                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11633                                  &res->mac_addr,
11634                                  sizeof(struct rte_ether_addr));
11635                 entry.input.flow.tunnel_flow.tunnel_type =
11636                         str2fdir_tunneltype(res->tunnel_type);
11637                 entry.input.flow.tunnel_flow.tunnel_id =
11638                         rte_cpu_to_be_32(res->tunnel_id_value);
11639         }
11640
11641         rte_memcpy(entry.input.flow_ext.flexbytes,
11642                    flexbytes,
11643                    RTE_ETH_FDIR_MAX_FLEXLEN);
11644
11645         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11646
11647         entry.action.flex_off = 0;  /*use 0 by default */
11648         if (!strcmp(res->drop, "drop"))
11649                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11650         else
11651                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11652
11653         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11654             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11655                 if (!strcmp(res->pf_vf, "pf"))
11656                         entry.input.flow_ext.is_vf = 0;
11657                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11658                         struct rte_eth_dev_info dev_info;
11659
11660                         ret = eth_dev_info_get_print_err(res->port_id,
11661                                                 &dev_info);
11662                         if (ret != 0)
11663                                 return;
11664
11665                         errno = 0;
11666                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11667                         if (errno != 0 || *end != '\0' ||
11668                             vf_id >= dev_info.max_vfs) {
11669                                 printf("invalid parameter %s.\n", res->pf_vf);
11670                                 return;
11671                         }
11672                         entry.input.flow_ext.is_vf = 1;
11673                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11674                 } else {
11675                         printf("invalid parameter %s.\n", res->pf_vf);
11676                         return;
11677                 }
11678         }
11679
11680         /* set to report FD ID by default */
11681         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11682         entry.action.rx_queue = res->queue_id;
11683         entry.soft_id = res->fd_id_value;
11684         if (!strcmp(res->ops, "add"))
11685                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11686                                              RTE_ETH_FILTER_ADD, &entry);
11687         else if (!strcmp(res->ops, "del"))
11688                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11689                                              RTE_ETH_FILTER_DELETE, &entry);
11690         else
11691                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11692                                              RTE_ETH_FILTER_UPDATE, &entry);
11693         if (ret < 0)
11694                 printf("flow director programming error: (%s)\n",
11695                         strerror(-ret));
11696 }
11697
11698 cmdline_parse_token_string_t cmd_flow_director_filter =
11699         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11700                                  flow_director_filter, "flow_director_filter");
11701 cmdline_parse_token_num_t cmd_flow_director_port_id =
11702         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11703                               port_id, UINT16);
11704 cmdline_parse_token_string_t cmd_flow_director_ops =
11705         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11706                                  ops, "add#del#update");
11707 cmdline_parse_token_string_t cmd_flow_director_flow =
11708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11709                                  flow, "flow");
11710 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11711         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11712                 flow_type, NULL);
11713 cmdline_parse_token_string_t cmd_flow_director_ether =
11714         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11715                                  ether, "ether");
11716 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11717         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11718                               ether_type, UINT16);
11719 cmdline_parse_token_string_t cmd_flow_director_src =
11720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11721                                  src, "src");
11722 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11723         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11724                                  ip_src);
11725 cmdline_parse_token_num_t cmd_flow_director_port_src =
11726         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11727                               port_src, UINT16);
11728 cmdline_parse_token_string_t cmd_flow_director_dst =
11729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11730                                  dst, "dst");
11731 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11732         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11733                                  ip_dst);
11734 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11735         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11736                               port_dst, UINT16);
11737 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11739                                   verify_tag, "verify_tag");
11740 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11741         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11742                               verify_tag_value, UINT32);
11743 cmdline_parse_token_string_t cmd_flow_director_tos =
11744         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11745                                  tos, "tos");
11746 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11747         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11748                               tos_value, UINT8);
11749 cmdline_parse_token_string_t cmd_flow_director_proto =
11750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11751                                  proto, "proto");
11752 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11753         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11754                               proto_value, UINT8);
11755 cmdline_parse_token_string_t cmd_flow_director_ttl =
11756         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11757                                  ttl, "ttl");
11758 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11759         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11760                               ttl_value, UINT8);
11761 cmdline_parse_token_string_t cmd_flow_director_vlan =
11762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11763                                  vlan, "vlan");
11764 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11765         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11766                               vlan_value, UINT16);
11767 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11768         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11769                                  flexbytes, "flexbytes");
11770 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11771         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11772                               flexbytes_value, NULL);
11773 cmdline_parse_token_string_t cmd_flow_director_drop =
11774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11775                                  drop, "drop#fwd");
11776 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11777         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11778                               pf_vf, NULL);
11779 cmdline_parse_token_string_t cmd_flow_director_queue =
11780         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11781                                  queue, "queue");
11782 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11783         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11784                               queue_id, UINT16);
11785 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11786         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11787                                  fd_id, "fd_id");
11788 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11789         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11790                               fd_id_value, UINT32);
11791
11792 cmdline_parse_token_string_t cmd_flow_director_mode =
11793         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11794                                  mode, "mode");
11795 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11796         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11797                                  mode_value, "IP");
11798 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11799         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11800                                  mode_value, "MAC-VLAN");
11801 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11802         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11803                                  mode_value, "Tunnel");
11804 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11805         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11806                                  mode_value, "raw");
11807 cmdline_parse_token_string_t cmd_flow_director_mac =
11808         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11809                                  mac, "mac");
11810 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11811         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11812                                     mac_addr);
11813 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11814         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11815                                  tunnel, "tunnel");
11816 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11817         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11818                                  tunnel_type, "NVGRE#VxLAN");
11819 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11820         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11821                                  tunnel_id, "tunnel-id");
11822 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11823         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11824                               tunnel_id_value, UINT32);
11825 cmdline_parse_token_string_t cmd_flow_director_packet =
11826         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11827                                  packet, "packet");
11828 cmdline_parse_token_string_t cmd_flow_director_filepath =
11829         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11830                                  filepath, NULL);
11831
11832 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11833         .f = cmd_flow_director_filter_parsed,
11834         .data = NULL,
11835         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11836                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11837                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11838                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11839                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11840                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11841                 "fd_id <fd_id_value>: "
11842                 "Add or delete an ip flow director entry on NIC",
11843         .tokens = {
11844                 (void *)&cmd_flow_director_filter,
11845                 (void *)&cmd_flow_director_port_id,
11846                 (void *)&cmd_flow_director_mode,
11847                 (void *)&cmd_flow_director_mode_ip,
11848                 (void *)&cmd_flow_director_ops,
11849                 (void *)&cmd_flow_director_flow,
11850                 (void *)&cmd_flow_director_flow_type,
11851                 (void *)&cmd_flow_director_src,
11852                 (void *)&cmd_flow_director_ip_src,
11853                 (void *)&cmd_flow_director_dst,
11854                 (void *)&cmd_flow_director_ip_dst,
11855                 (void *)&cmd_flow_director_tos,
11856                 (void *)&cmd_flow_director_tos_value,
11857                 (void *)&cmd_flow_director_proto,
11858                 (void *)&cmd_flow_director_proto_value,
11859                 (void *)&cmd_flow_director_ttl,
11860                 (void *)&cmd_flow_director_ttl_value,
11861                 (void *)&cmd_flow_director_vlan,
11862                 (void *)&cmd_flow_director_vlan_value,
11863                 (void *)&cmd_flow_director_flexbytes,
11864                 (void *)&cmd_flow_director_flexbytes_value,
11865                 (void *)&cmd_flow_director_drop,
11866                 (void *)&cmd_flow_director_pf_vf,
11867                 (void *)&cmd_flow_director_queue,
11868                 (void *)&cmd_flow_director_queue_id,
11869                 (void *)&cmd_flow_director_fd_id,
11870                 (void *)&cmd_flow_director_fd_id_value,
11871                 NULL,
11872         },
11873 };
11874
11875 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11876         .f = cmd_flow_director_filter_parsed,
11877         .data = NULL,
11878         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11879                 "director entry on NIC",
11880         .tokens = {
11881                 (void *)&cmd_flow_director_filter,
11882                 (void *)&cmd_flow_director_port_id,
11883                 (void *)&cmd_flow_director_mode,
11884                 (void *)&cmd_flow_director_mode_ip,
11885                 (void *)&cmd_flow_director_ops,
11886                 (void *)&cmd_flow_director_flow,
11887                 (void *)&cmd_flow_director_flow_type,
11888                 (void *)&cmd_flow_director_src,
11889                 (void *)&cmd_flow_director_ip_src,
11890                 (void *)&cmd_flow_director_port_src,
11891                 (void *)&cmd_flow_director_dst,
11892                 (void *)&cmd_flow_director_ip_dst,
11893                 (void *)&cmd_flow_director_port_dst,
11894                 (void *)&cmd_flow_director_tos,
11895                 (void *)&cmd_flow_director_tos_value,
11896                 (void *)&cmd_flow_director_ttl,
11897                 (void *)&cmd_flow_director_ttl_value,
11898                 (void *)&cmd_flow_director_vlan,
11899                 (void *)&cmd_flow_director_vlan_value,
11900                 (void *)&cmd_flow_director_flexbytes,
11901                 (void *)&cmd_flow_director_flexbytes_value,
11902                 (void *)&cmd_flow_director_drop,
11903                 (void *)&cmd_flow_director_pf_vf,
11904                 (void *)&cmd_flow_director_queue,
11905                 (void *)&cmd_flow_director_queue_id,
11906                 (void *)&cmd_flow_director_fd_id,
11907                 (void *)&cmd_flow_director_fd_id_value,
11908                 NULL,
11909         },
11910 };
11911
11912 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11913         .f = cmd_flow_director_filter_parsed,
11914         .data = NULL,
11915         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11916                 "director entry on NIC",
11917         .tokens = {
11918                 (void *)&cmd_flow_director_filter,
11919                 (void *)&cmd_flow_director_port_id,
11920                 (void *)&cmd_flow_director_mode,
11921                 (void *)&cmd_flow_director_mode_ip,
11922                 (void *)&cmd_flow_director_ops,
11923                 (void *)&cmd_flow_director_flow,
11924                 (void *)&cmd_flow_director_flow_type,
11925                 (void *)&cmd_flow_director_src,
11926                 (void *)&cmd_flow_director_ip_src,
11927                 (void *)&cmd_flow_director_port_src,
11928                 (void *)&cmd_flow_director_dst,
11929                 (void *)&cmd_flow_director_ip_dst,
11930                 (void *)&cmd_flow_director_port_dst,
11931                 (void *)&cmd_flow_director_verify_tag,
11932                 (void *)&cmd_flow_director_verify_tag_value,
11933                 (void *)&cmd_flow_director_tos,
11934                 (void *)&cmd_flow_director_tos_value,
11935                 (void *)&cmd_flow_director_ttl,
11936                 (void *)&cmd_flow_director_ttl_value,
11937                 (void *)&cmd_flow_director_vlan,
11938                 (void *)&cmd_flow_director_vlan_value,
11939                 (void *)&cmd_flow_director_flexbytes,
11940                 (void *)&cmd_flow_director_flexbytes_value,
11941                 (void *)&cmd_flow_director_drop,
11942                 (void *)&cmd_flow_director_pf_vf,
11943                 (void *)&cmd_flow_director_queue,
11944                 (void *)&cmd_flow_director_queue_id,
11945                 (void *)&cmd_flow_director_fd_id,
11946                 (void *)&cmd_flow_director_fd_id_value,
11947                 NULL,
11948         },
11949 };
11950
11951 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11952         .f = cmd_flow_director_filter_parsed,
11953         .data = NULL,
11954         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11955                 "director entry on NIC",
11956         .tokens = {
11957                 (void *)&cmd_flow_director_filter,
11958                 (void *)&cmd_flow_director_port_id,
11959                 (void *)&cmd_flow_director_mode,
11960                 (void *)&cmd_flow_director_mode_ip,
11961                 (void *)&cmd_flow_director_ops,
11962                 (void *)&cmd_flow_director_flow,
11963                 (void *)&cmd_flow_director_flow_type,
11964                 (void *)&cmd_flow_director_ether,
11965                 (void *)&cmd_flow_director_ether_type,
11966                 (void *)&cmd_flow_director_flexbytes,
11967                 (void *)&cmd_flow_director_flexbytes_value,
11968                 (void *)&cmd_flow_director_drop,
11969                 (void *)&cmd_flow_director_pf_vf,
11970                 (void *)&cmd_flow_director_queue,
11971                 (void *)&cmd_flow_director_queue_id,
11972                 (void *)&cmd_flow_director_fd_id,
11973                 (void *)&cmd_flow_director_fd_id_value,
11974                 NULL,
11975         },
11976 };
11977
11978 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11979         .f = cmd_flow_director_filter_parsed,
11980         .data = NULL,
11981         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11982                 "director entry on NIC",
11983         .tokens = {
11984                 (void *)&cmd_flow_director_filter,
11985                 (void *)&cmd_flow_director_port_id,
11986                 (void *)&cmd_flow_director_mode,
11987                 (void *)&cmd_flow_director_mode_mac_vlan,
11988                 (void *)&cmd_flow_director_ops,
11989                 (void *)&cmd_flow_director_mac,
11990                 (void *)&cmd_flow_director_mac_addr,
11991                 (void *)&cmd_flow_director_vlan,
11992                 (void *)&cmd_flow_director_vlan_value,
11993                 (void *)&cmd_flow_director_flexbytes,
11994                 (void *)&cmd_flow_director_flexbytes_value,
11995                 (void *)&cmd_flow_director_drop,
11996                 (void *)&cmd_flow_director_queue,
11997                 (void *)&cmd_flow_director_queue_id,
11998                 (void *)&cmd_flow_director_fd_id,
11999                 (void *)&cmd_flow_director_fd_id_value,
12000                 NULL,
12001         },
12002 };
12003
12004 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
12005         .f = cmd_flow_director_filter_parsed,
12006         .data = NULL,
12007         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
12008                 "director entry on NIC",
12009         .tokens = {
12010                 (void *)&cmd_flow_director_filter,
12011                 (void *)&cmd_flow_director_port_id,
12012                 (void *)&cmd_flow_director_mode,
12013                 (void *)&cmd_flow_director_mode_tunnel,
12014                 (void *)&cmd_flow_director_ops,
12015                 (void *)&cmd_flow_director_mac,
12016                 (void *)&cmd_flow_director_mac_addr,
12017                 (void *)&cmd_flow_director_vlan,
12018                 (void *)&cmd_flow_director_vlan_value,
12019                 (void *)&cmd_flow_director_tunnel,
12020                 (void *)&cmd_flow_director_tunnel_type,
12021                 (void *)&cmd_flow_director_tunnel_id,
12022                 (void *)&cmd_flow_director_tunnel_id_value,
12023                 (void *)&cmd_flow_director_flexbytes,
12024                 (void *)&cmd_flow_director_flexbytes_value,
12025                 (void *)&cmd_flow_director_drop,
12026                 (void *)&cmd_flow_director_queue,
12027                 (void *)&cmd_flow_director_queue_id,
12028                 (void *)&cmd_flow_director_fd_id,
12029                 (void *)&cmd_flow_director_fd_id_value,
12030                 NULL,
12031         },
12032 };
12033
12034 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
12035         .f = cmd_flow_director_filter_parsed,
12036         .data = NULL,
12037         .help_str = "flow_director_filter ... : Add or delete a raw flow "
12038                 "director entry on NIC",
12039         .tokens = {
12040                 (void *)&cmd_flow_director_filter,
12041                 (void *)&cmd_flow_director_port_id,
12042                 (void *)&cmd_flow_director_mode,
12043                 (void *)&cmd_flow_director_mode_raw,
12044                 (void *)&cmd_flow_director_ops,
12045                 (void *)&cmd_flow_director_flow,
12046                 (void *)&cmd_flow_director_flow_type,
12047                 (void *)&cmd_flow_director_drop,
12048                 (void *)&cmd_flow_director_queue,
12049                 (void *)&cmd_flow_director_queue_id,
12050                 (void *)&cmd_flow_director_fd_id,
12051                 (void *)&cmd_flow_director_fd_id_value,
12052                 (void *)&cmd_flow_director_packet,
12053                 (void *)&cmd_flow_director_filepath,
12054                 NULL,
12055         },
12056 };
12057
12058 struct cmd_flush_flow_director_result {
12059         cmdline_fixed_string_t flush_flow_director;
12060         portid_t port_id;
12061 };
12062
12063 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
12064         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
12065                                  flush_flow_director, "flush_flow_director");
12066 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
12067         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
12068                               port_id, UINT16);
12069
12070 static void
12071 cmd_flush_flow_director_parsed(void *parsed_result,
12072                           __rte_unused struct cmdline *cl,
12073                           __rte_unused void *data)
12074 {
12075         struct cmd_flow_director_result *res = parsed_result;
12076         int ret = 0;
12077
12078         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
12079         if (ret < 0) {
12080                 printf("flow director is not supported on port %u.\n",
12081                         res->port_id);
12082                 return;
12083         }
12084
12085         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12086                         RTE_ETH_FILTER_FLUSH, NULL);
12087         if (ret < 0)
12088                 printf("flow director table flushing error: (%s)\n",
12089                         strerror(-ret));
12090 }
12091
12092 cmdline_parse_inst_t cmd_flush_flow_director = {
12093         .f = cmd_flush_flow_director_parsed,
12094         .data = NULL,
12095         .help_str = "flush_flow_director <port_id>: "
12096                 "Flush all flow director entries of a device on NIC",
12097         .tokens = {
12098                 (void *)&cmd_flush_flow_director_flush,
12099                 (void *)&cmd_flush_flow_director_port_id,
12100                 NULL,
12101         },
12102 };
12103
12104 /* *** deal with flow director mask *** */
12105 struct cmd_flow_director_mask_result {
12106         cmdline_fixed_string_t flow_director_mask;
12107         portid_t port_id;
12108         cmdline_fixed_string_t mode;
12109         cmdline_fixed_string_t mode_value;
12110         cmdline_fixed_string_t vlan;
12111         uint16_t vlan_mask;
12112         cmdline_fixed_string_t src_mask;
12113         cmdline_ipaddr_t ipv4_src;
12114         cmdline_ipaddr_t ipv6_src;
12115         uint16_t port_src;
12116         cmdline_fixed_string_t dst_mask;
12117         cmdline_ipaddr_t ipv4_dst;
12118         cmdline_ipaddr_t ipv6_dst;
12119         uint16_t port_dst;
12120         cmdline_fixed_string_t mac;
12121         uint8_t mac_addr_byte_mask;
12122         cmdline_fixed_string_t tunnel_id;
12123         uint32_t tunnel_id_mask;
12124         cmdline_fixed_string_t tunnel_type;
12125         uint8_t tunnel_type_mask;
12126 };
12127
12128 static void
12129 cmd_flow_director_mask_parsed(void *parsed_result,
12130                           __rte_unused struct cmdline *cl,
12131                           __rte_unused void *data)
12132 {
12133         struct cmd_flow_director_mask_result *res = parsed_result;
12134         struct rte_eth_fdir_masks *mask;
12135         struct rte_port *port;
12136
12137         port = &ports[res->port_id];
12138         /** Check if the port is not started **/
12139         if (port->port_status != RTE_PORT_STOPPED) {
12140                 printf("Please stop port %d first\n", res->port_id);
12141                 return;
12142         }
12143
12144         mask = &port->dev_conf.fdir_conf.mask;
12145
12146         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12147                 if (strcmp(res->mode_value, "MAC-VLAN")) {
12148                         printf("Please set mode to MAC-VLAN.\n");
12149                         return;
12150                 }
12151
12152                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12153         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12154                 if (strcmp(res->mode_value, "Tunnel")) {
12155                         printf("Please set mode to Tunnel.\n");
12156                         return;
12157                 }
12158
12159                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12160                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12161                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12162                 mask->tunnel_type_mask = res->tunnel_type_mask;
12163         } else {
12164                 if (strcmp(res->mode_value, "IP")) {
12165                         printf("Please set mode to IP.\n");
12166                         return;
12167                 }
12168
12169                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12170                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12171                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12172                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12173                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12174                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12175                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12176         }
12177
12178         cmd_reconfig_device_queue(res->port_id, 1, 1);
12179 }
12180
12181 cmdline_parse_token_string_t cmd_flow_director_mask =
12182         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12183                                  flow_director_mask, "flow_director_mask");
12184 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12185         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12186                               port_id, UINT16);
12187 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12188         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12189                                  vlan, "vlan");
12190 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12191         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12192                               vlan_mask, UINT16);
12193 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12194         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12195                                  src_mask, "src_mask");
12196 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12197         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12198                                  ipv4_src);
12199 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12200         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12201                                  ipv6_src);
12202 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12203         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12204                               port_src, UINT16);
12205 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12206         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12207                                  dst_mask, "dst_mask");
12208 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12209         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12210                                  ipv4_dst);
12211 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12212         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12213                                  ipv6_dst);
12214 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12215         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12216                               port_dst, UINT16);
12217
12218 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12219         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12220                                  mode, "mode");
12221 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12222         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12223                                  mode_value, "IP");
12224 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12225         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12226                                  mode_value, "MAC-VLAN");
12227 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12228         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12229                                  mode_value, "Tunnel");
12230 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12231         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12232                                  mac, "mac");
12233 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12234         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12235                               mac_addr_byte_mask, UINT8);
12236 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12237         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12238                                  tunnel_type, "tunnel-type");
12239 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12240         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12241                               tunnel_type_mask, UINT8);
12242 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12243         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12244                                  tunnel_id, "tunnel-id");
12245 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12246         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12247                               tunnel_id_mask, UINT32);
12248
12249 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12250         .f = cmd_flow_director_mask_parsed,
12251         .data = NULL,
12252         .help_str = "flow_director_mask ... : "
12253                 "Set IP mode flow director's mask on NIC",
12254         .tokens = {
12255                 (void *)&cmd_flow_director_mask,
12256                 (void *)&cmd_flow_director_mask_port_id,
12257                 (void *)&cmd_flow_director_mask_mode,
12258                 (void *)&cmd_flow_director_mask_mode_ip,
12259                 (void *)&cmd_flow_director_mask_vlan,
12260                 (void *)&cmd_flow_director_mask_vlan_value,
12261                 (void *)&cmd_flow_director_mask_src,
12262                 (void *)&cmd_flow_director_mask_ipv4_src,
12263                 (void *)&cmd_flow_director_mask_ipv6_src,
12264                 (void *)&cmd_flow_director_mask_port_src,
12265                 (void *)&cmd_flow_director_mask_dst,
12266                 (void *)&cmd_flow_director_mask_ipv4_dst,
12267                 (void *)&cmd_flow_director_mask_ipv6_dst,
12268                 (void *)&cmd_flow_director_mask_port_dst,
12269                 NULL,
12270         },
12271 };
12272
12273 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12274         .f = cmd_flow_director_mask_parsed,
12275         .data = NULL,
12276         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12277                 "flow director's mask on NIC",
12278         .tokens = {
12279                 (void *)&cmd_flow_director_mask,
12280                 (void *)&cmd_flow_director_mask_port_id,
12281                 (void *)&cmd_flow_director_mask_mode,
12282                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12283                 (void *)&cmd_flow_director_mask_vlan,
12284                 (void *)&cmd_flow_director_mask_vlan_value,
12285                 NULL,
12286         },
12287 };
12288
12289 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12290         .f = cmd_flow_director_mask_parsed,
12291         .data = NULL,
12292         .help_str = "flow_director_mask ... : Set tunnel mode "
12293                 "flow director's mask on NIC",
12294         .tokens = {
12295                 (void *)&cmd_flow_director_mask,
12296                 (void *)&cmd_flow_director_mask_port_id,
12297                 (void *)&cmd_flow_director_mask_mode,
12298                 (void *)&cmd_flow_director_mask_mode_tunnel,
12299                 (void *)&cmd_flow_director_mask_vlan,
12300                 (void *)&cmd_flow_director_mask_vlan_value,
12301                 (void *)&cmd_flow_director_mask_mac,
12302                 (void *)&cmd_flow_director_mask_mac_value,
12303                 (void *)&cmd_flow_director_mask_tunnel_type,
12304                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12305                 (void *)&cmd_flow_director_mask_tunnel_id,
12306                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12307                 NULL,
12308         },
12309 };
12310
12311 /* *** deal with flow director mask on flexible payload *** */
12312 struct cmd_flow_director_flex_mask_result {
12313         cmdline_fixed_string_t flow_director_flexmask;
12314         portid_t port_id;
12315         cmdline_fixed_string_t flow;
12316         cmdline_fixed_string_t flow_type;
12317         cmdline_fixed_string_t mask;
12318 };
12319
12320 static void
12321 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12322                           __rte_unused struct cmdline *cl,
12323                           __rte_unused void *data)
12324 {
12325         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12326         struct rte_eth_fdir_info fdir_info;
12327         struct rte_eth_fdir_flex_mask flex_mask;
12328         struct rte_port *port;
12329         uint64_t flow_type_mask;
12330         uint16_t i;
12331         int ret;
12332
12333         port = &ports[res->port_id];
12334         /** Check if the port is not started **/
12335         if (port->port_status != RTE_PORT_STOPPED) {
12336                 printf("Please stop port %d first\n", res->port_id);
12337                 return;
12338         }
12339
12340         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12341         ret = parse_flexbytes(res->mask,
12342                         flex_mask.mask,
12343                         RTE_ETH_FDIR_MAX_FLEXLEN);
12344         if (ret < 0) {
12345                 printf("error: Cannot parse mask input.\n");
12346                 return;
12347         }
12348
12349         memset(&fdir_info, 0, sizeof(fdir_info));
12350         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12351                                 RTE_ETH_FILTER_INFO, &fdir_info);
12352         if (ret < 0) {
12353                 printf("Cannot get FDir filter info\n");
12354                 return;
12355         }
12356
12357         if (!strcmp(res->flow_type, "none")) {
12358                 /* means don't specify the flow type */
12359                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12360                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12361                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12362                                0, sizeof(struct rte_eth_fdir_flex_mask));
12363                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12364                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12365                                  &flex_mask,
12366                                  sizeof(struct rte_eth_fdir_flex_mask));
12367                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12368                 return;
12369         }
12370         flow_type_mask = fdir_info.flow_types_mask[0];
12371         if (!strcmp(res->flow_type, "all")) {
12372                 if (!flow_type_mask) {
12373                         printf("No flow type supported\n");
12374                         return;
12375                 }
12376                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12377                         if (flow_type_mask & (1ULL << i)) {
12378                                 flex_mask.flow_type = i;
12379                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12380                         }
12381                 }
12382                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12383                 return;
12384         }
12385         flex_mask.flow_type = str2flowtype(res->flow_type);
12386         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12387                 printf("Flow type %s not supported on port %d\n",
12388                                 res->flow_type, res->port_id);
12389                 return;
12390         }
12391         fdir_set_flex_mask(res->port_id, &flex_mask);
12392         cmd_reconfig_device_queue(res->port_id, 1, 1);
12393 }
12394
12395 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12397                                  flow_director_flexmask,
12398                                  "flow_director_flex_mask");
12399 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12400         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12401                               port_id, UINT16);
12402 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12403         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12404                                  flow, "flow");
12405 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12406         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12407                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12408                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12409 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12410         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12411                                  mask, NULL);
12412
12413 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12414         .f = cmd_flow_director_flex_mask_parsed,
12415         .data = NULL,
12416         .help_str = "flow_director_flex_mask ... : "
12417                 "Set flow director's flex mask on NIC",
12418         .tokens = {
12419                 (void *)&cmd_flow_director_flexmask,
12420                 (void *)&cmd_flow_director_flexmask_port_id,
12421                 (void *)&cmd_flow_director_flexmask_flow,
12422                 (void *)&cmd_flow_director_flexmask_flow_type,
12423                 (void *)&cmd_flow_director_flexmask_mask,
12424                 NULL,
12425         },
12426 };
12427
12428 /* *** deal with flow director flexible payload configuration *** */
12429 struct cmd_flow_director_flexpayload_result {
12430         cmdline_fixed_string_t flow_director_flexpayload;
12431         portid_t port_id;
12432         cmdline_fixed_string_t payload_layer;
12433         cmdline_fixed_string_t payload_cfg;
12434 };
12435
12436 static inline int
12437 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12438 {
12439         char s[256];
12440         const char *p, *p0 = q_arg;
12441         char *end;
12442         unsigned long int_fld;
12443         char *str_fld[max_num];
12444         int i;
12445         unsigned size;
12446         int ret = -1;
12447
12448         p = strchr(p0, '(');
12449         if (p == NULL)
12450                 return -1;
12451         ++p;
12452         p0 = strchr(p, ')');
12453         if (p0 == NULL)
12454                 return -1;
12455
12456         size = p0 - p;
12457         if (size >= sizeof(s))
12458                 return -1;
12459
12460         snprintf(s, sizeof(s), "%.*s", size, p);
12461         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12462         if (ret < 0 || ret > max_num)
12463                 return -1;
12464         for (i = 0; i < ret; i++) {
12465                 errno = 0;
12466                 int_fld = strtoul(str_fld[i], &end, 0);
12467                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12468                         return -1;
12469                 offsets[i] = (uint16_t)int_fld;
12470         }
12471         return ret;
12472 }
12473
12474 static void
12475 cmd_flow_director_flxpld_parsed(void *parsed_result,
12476                           __rte_unused struct cmdline *cl,
12477                           __rte_unused void *data)
12478 {
12479         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12480         struct rte_eth_flex_payload_cfg flex_cfg;
12481         struct rte_port *port;
12482         int ret = 0;
12483
12484         port = &ports[res->port_id];
12485         /** Check if the port is not started **/
12486         if (port->port_status != RTE_PORT_STOPPED) {
12487                 printf("Please stop port %d first\n", res->port_id);
12488                 return;
12489         }
12490
12491         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12492
12493         if (!strcmp(res->payload_layer, "raw"))
12494                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12495         else if (!strcmp(res->payload_layer, "l2"))
12496                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12497         else if (!strcmp(res->payload_layer, "l3"))
12498                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12499         else if (!strcmp(res->payload_layer, "l4"))
12500                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12501
12502         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12503                             RTE_ETH_FDIR_MAX_FLEXLEN);
12504         if (ret < 0) {
12505                 printf("error: Cannot parse flex payload input.\n");
12506                 return;
12507         }
12508
12509         fdir_set_flex_payload(res->port_id, &flex_cfg);
12510         cmd_reconfig_device_queue(res->port_id, 1, 1);
12511 }
12512
12513 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12514         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12515                                  flow_director_flexpayload,
12516                                  "flow_director_flex_payload");
12517 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12518         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12519                               port_id, UINT16);
12520 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12521         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12522                                  payload_layer, "raw#l2#l3#l4");
12523 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12524         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12525                                  payload_cfg, NULL);
12526
12527 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12528         .f = cmd_flow_director_flxpld_parsed,
12529         .data = NULL,
12530         .help_str = "flow_director_flexpayload ... : "
12531                 "Set flow director's flex payload on NIC",
12532         .tokens = {
12533                 (void *)&cmd_flow_director_flexpayload,
12534                 (void *)&cmd_flow_director_flexpayload_port_id,
12535                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12536                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12537                 NULL,
12538         },
12539 };
12540
12541 /* Generic flow interface command. */
12542 extern cmdline_parse_inst_t cmd_flow;
12543
12544 /* *** Classification Filters Control *** */
12545 /* *** Get symmetric hash enable per port *** */
12546 struct cmd_get_sym_hash_ena_per_port_result {
12547         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12548         portid_t port_id;
12549 };
12550
12551 static void
12552 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12553                                  __rte_unused struct cmdline *cl,
12554                                  __rte_unused void *data)
12555 {
12556         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12557         struct rte_eth_hash_filter_info info;
12558         int ret;
12559
12560         if (rte_eth_dev_filter_supported(res->port_id,
12561                                 RTE_ETH_FILTER_HASH) < 0) {
12562                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12563                                                         res->port_id);
12564                 return;
12565         }
12566
12567         memset(&info, 0, sizeof(info));
12568         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12569         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12570                                                 RTE_ETH_FILTER_GET, &info);
12571
12572         if (ret < 0) {
12573                 printf("Cannot get symmetric hash enable per port "
12574                                         "on port %u\n", res->port_id);
12575                 return;
12576         }
12577
12578         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12579                                 "enabled" : "disabled", res->port_id);
12580 }
12581
12582 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12583         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12584                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12585 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12586         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12587                 port_id, UINT16);
12588
12589 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12590         .f = cmd_get_sym_hash_per_port_parsed,
12591         .data = NULL,
12592         .help_str = "get_sym_hash_ena_per_port <port_id>",
12593         .tokens = {
12594                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12595                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12596                 NULL,
12597         },
12598 };
12599
12600 /* *** Set symmetric hash enable per port *** */
12601 struct cmd_set_sym_hash_ena_per_port_result {
12602         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12603         cmdline_fixed_string_t enable;
12604         portid_t port_id;
12605 };
12606
12607 static void
12608 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12609                                  __rte_unused struct cmdline *cl,
12610                                  __rte_unused void *data)
12611 {
12612         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12613         struct rte_eth_hash_filter_info info;
12614         int ret;
12615
12616         if (rte_eth_dev_filter_supported(res->port_id,
12617                                 RTE_ETH_FILTER_HASH) < 0) {
12618                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12619                                                         res->port_id);
12620                 return;
12621         }
12622
12623         memset(&info, 0, sizeof(info));
12624         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12625         if (!strcmp(res->enable, "enable"))
12626                 info.info.enable = 1;
12627         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12628                                         RTE_ETH_FILTER_SET, &info);
12629         if (ret < 0) {
12630                 printf("Cannot set symmetric hash enable per port on "
12631                                         "port %u\n", res->port_id);
12632                 return;
12633         }
12634         printf("Symmetric hash has been set to %s on port %u\n",
12635                                         res->enable, res->port_id);
12636 }
12637
12638 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12639         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12640                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12641 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12642         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12643                 port_id, UINT16);
12644 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12645         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12646                 enable, "enable#disable");
12647
12648 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12649         .f = cmd_set_sym_hash_per_port_parsed,
12650         .data = NULL,
12651         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12652         .tokens = {
12653                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12654                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12655                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12656                 NULL,
12657         },
12658 };
12659
12660 /* Get global config of hash function */
12661 struct cmd_get_hash_global_config_result {
12662         cmdline_fixed_string_t get_hash_global_config;
12663         portid_t port_id;
12664 };
12665
12666 static char *
12667 flowtype_to_str(uint16_t ftype)
12668 {
12669         uint16_t i;
12670         static struct {
12671                 char str[16];
12672                 uint16_t ftype;
12673         } ftype_table[] = {
12674                 {"ipv4", RTE_ETH_FLOW_IPV4},
12675                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12676                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12677                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12678                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12679                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12680                 {"ipv6", RTE_ETH_FLOW_IPV6},
12681                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12682                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12683                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12684                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12685                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12686                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12687                 {"port", RTE_ETH_FLOW_PORT},
12688                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12689                 {"geneve", RTE_ETH_FLOW_GENEVE},
12690                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12691                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12692         };
12693
12694         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12695                 if (ftype_table[i].ftype == ftype)
12696                         return ftype_table[i].str;
12697         }
12698
12699         return NULL;
12700 }
12701
12702 static void
12703 cmd_get_hash_global_config_parsed(void *parsed_result,
12704                                   __rte_unused struct cmdline *cl,
12705                                   __rte_unused void *data)
12706 {
12707         struct cmd_get_hash_global_config_result *res = parsed_result;
12708         struct rte_eth_hash_filter_info info;
12709         uint32_t idx, offset;
12710         uint16_t i;
12711         char *str;
12712         int ret;
12713
12714         if (rte_eth_dev_filter_supported(res->port_id,
12715                         RTE_ETH_FILTER_HASH) < 0) {
12716                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12717                                                         res->port_id);
12718                 return;
12719         }
12720
12721         memset(&info, 0, sizeof(info));
12722         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12723         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12724                                         RTE_ETH_FILTER_GET, &info);
12725         if (ret < 0) {
12726                 printf("Cannot get hash global configurations by port %d\n",
12727                                                         res->port_id);
12728                 return;
12729         }
12730
12731         switch (info.info.global_conf.hash_func) {
12732         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12733                 printf("Hash function is Toeplitz\n");
12734                 break;
12735         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12736                 printf("Hash function is Simple XOR\n");
12737                 break;
12738         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12739                 printf("Hash function is Symmetric Toeplitz\n");
12740                 break;
12741         default:
12742                 printf("Unknown hash function\n");
12743                 break;
12744         }
12745
12746         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12747                 idx = i / UINT64_BIT;
12748                 offset = i % UINT64_BIT;
12749                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12750                                                 (1ULL << offset)))
12751                         continue;
12752                 str = flowtype_to_str(i);
12753                 if (!str)
12754                         continue;
12755                 printf("Symmetric hash is %s globally for flow type %s "
12756                                                         "by port %d\n",
12757                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12758                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12759                                                         res->port_id);
12760         }
12761 }
12762
12763 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12764         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12765                 get_hash_global_config, "get_hash_global_config");
12766 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12767         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12768                 port_id, UINT16);
12769
12770 cmdline_parse_inst_t cmd_get_hash_global_config = {
12771         .f = cmd_get_hash_global_config_parsed,
12772         .data = NULL,
12773         .help_str = "get_hash_global_config <port_id>",
12774         .tokens = {
12775                 (void *)&cmd_get_hash_global_config_all,
12776                 (void *)&cmd_get_hash_global_config_port_id,
12777                 NULL,
12778         },
12779 };
12780
12781 /* Set global config of hash function */
12782 struct cmd_set_hash_global_config_result {
12783         cmdline_fixed_string_t set_hash_global_config;
12784         portid_t port_id;
12785         cmdline_fixed_string_t hash_func;
12786         cmdline_fixed_string_t flow_type;
12787         cmdline_fixed_string_t enable;
12788 };
12789
12790 static void
12791 cmd_set_hash_global_config_parsed(void *parsed_result,
12792                                   __rte_unused struct cmdline *cl,
12793                                   __rte_unused void *data)
12794 {
12795         struct cmd_set_hash_global_config_result *res = parsed_result;
12796         struct rte_eth_hash_filter_info info;
12797         uint32_t ftype, idx, offset;
12798         int ret;
12799
12800         if (rte_eth_dev_filter_supported(res->port_id,
12801                                 RTE_ETH_FILTER_HASH) < 0) {
12802                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12803                                                         res->port_id);
12804                 return;
12805         }
12806         memset(&info, 0, sizeof(info));
12807         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12808         if (!strcmp(res->hash_func, "toeplitz"))
12809                 info.info.global_conf.hash_func =
12810                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12811         else if (!strcmp(res->hash_func, "simple_xor"))
12812                 info.info.global_conf.hash_func =
12813                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12814         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12815                 info.info.global_conf.hash_func =
12816                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12817         else if (!strcmp(res->hash_func, "default"))
12818                 info.info.global_conf.hash_func =
12819                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12820
12821         ftype = str2flowtype(res->flow_type);
12822         idx = ftype / UINT64_BIT;
12823         offset = ftype % UINT64_BIT;
12824         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12825         if (!strcmp(res->enable, "enable"))
12826                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12827                                                 (1ULL << offset);
12828         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12829                                         RTE_ETH_FILTER_SET, &info);
12830         if (ret < 0)
12831                 printf("Cannot set global hash configurations by port %d\n",
12832                                                         res->port_id);
12833         else
12834                 printf("Global hash configurations have been set "
12835                         "successfully by port %d\n", res->port_id);
12836 }
12837
12838 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12839         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12840                 set_hash_global_config, "set_hash_global_config");
12841 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12842         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12843                 port_id, UINT16);
12844 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12845         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12846                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12847 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12848         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12849                 flow_type,
12850                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12851                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12852 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12853         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12854                 enable, "enable#disable");
12855
12856 cmdline_parse_inst_t cmd_set_hash_global_config = {
12857         .f = cmd_set_hash_global_config_parsed,
12858         .data = NULL,
12859         .help_str = "set_hash_global_config <port_id> "
12860                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12861                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12862                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12863                 "l2_payload enable|disable",
12864         .tokens = {
12865                 (void *)&cmd_set_hash_global_config_all,
12866                 (void *)&cmd_set_hash_global_config_port_id,
12867                 (void *)&cmd_set_hash_global_config_hash_func,
12868                 (void *)&cmd_set_hash_global_config_flow_type,
12869                 (void *)&cmd_set_hash_global_config_enable,
12870                 NULL,
12871         },
12872 };
12873
12874 /* Set hash input set */
12875 struct cmd_set_hash_input_set_result {
12876         cmdline_fixed_string_t set_hash_input_set;
12877         portid_t port_id;
12878         cmdline_fixed_string_t flow_type;
12879         cmdline_fixed_string_t inset_field;
12880         cmdline_fixed_string_t select;
12881 };
12882
12883 static enum rte_eth_input_set_field
12884 str2inset(char *string)
12885 {
12886         uint16_t i;
12887
12888         static const struct {
12889                 char str[32];
12890                 enum rte_eth_input_set_field inset;
12891         } inset_table[] = {
12892                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12893                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12894                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12895                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12896                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12897                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12898                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12899                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12900                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12901                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12902                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12903                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12904                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12905                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12906                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12907                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12908                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12909                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12910                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12911                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12912                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12913                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12914                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12915                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12916                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12917                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12918                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12919                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12920                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12921                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12922                 {"none", RTE_ETH_INPUT_SET_NONE},
12923         };
12924
12925         for (i = 0; i < RTE_DIM(inset_table); i++) {
12926                 if (!strcmp(string, inset_table[i].str))
12927                         return inset_table[i].inset;
12928         }
12929
12930         return RTE_ETH_INPUT_SET_UNKNOWN;
12931 }
12932
12933 static void
12934 cmd_set_hash_input_set_parsed(void *parsed_result,
12935                               __rte_unused struct cmdline *cl,
12936                               __rte_unused void *data)
12937 {
12938         struct cmd_set_hash_input_set_result *res = parsed_result;
12939         struct rte_eth_hash_filter_info info;
12940
12941         memset(&info, 0, sizeof(info));
12942         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12943         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12944         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12945         info.info.input_set_conf.inset_size = 1;
12946         if (!strcmp(res->select, "select"))
12947                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12948         else if (!strcmp(res->select, "add"))
12949                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12950         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12951                                 RTE_ETH_FILTER_SET, &info);
12952 }
12953
12954 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12955         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12956                 set_hash_input_set, "set_hash_input_set");
12957 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12958         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12959                 port_id, UINT16);
12960 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12961         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12962                 flow_type, NULL);
12963 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12964         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12965                 inset_field,
12966                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12967                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12968                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12969                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12970                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12971                 "fld-8th#none");
12972 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12973         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12974                 select, "select#add");
12975
12976 cmdline_parse_inst_t cmd_set_hash_input_set = {
12977         .f = cmd_set_hash_input_set_parsed,
12978         .data = NULL,
12979         .help_str = "set_hash_input_set <port_id> "
12980         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12981         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12982         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12983         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12984         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12985         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12986         "fld-7th|fld-8th|none select|add",
12987         .tokens = {
12988                 (void *)&cmd_set_hash_input_set_cmd,
12989                 (void *)&cmd_set_hash_input_set_port_id,
12990                 (void *)&cmd_set_hash_input_set_flow_type,
12991                 (void *)&cmd_set_hash_input_set_field,
12992                 (void *)&cmd_set_hash_input_set_select,
12993                 NULL,
12994         },
12995 };
12996
12997 /* Set flow director input set */
12998 struct cmd_set_fdir_input_set_result {
12999         cmdline_fixed_string_t set_fdir_input_set;
13000         portid_t port_id;
13001         cmdline_fixed_string_t flow_type;
13002         cmdline_fixed_string_t inset_field;
13003         cmdline_fixed_string_t select;
13004 };
13005
13006 static void
13007 cmd_set_fdir_input_set_parsed(void *parsed_result,
13008         __rte_unused struct cmdline *cl,
13009         __rte_unused void *data)
13010 {
13011         struct cmd_set_fdir_input_set_result *res = parsed_result;
13012         struct rte_eth_fdir_filter_info info;
13013
13014         memset(&info, 0, sizeof(info));
13015         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
13016         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
13017         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
13018         info.info.input_set_conf.inset_size = 1;
13019         if (!strcmp(res->select, "select"))
13020                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
13021         else if (!strcmp(res->select, "add"))
13022                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
13023         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
13024                 RTE_ETH_FILTER_SET, &info);
13025 }
13026
13027 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
13028         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
13029         set_fdir_input_set, "set_fdir_input_set");
13030 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
13031         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
13032         port_id, UINT16);
13033 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
13034         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
13035         flow_type,
13036         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
13037         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
13038 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
13039         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
13040         inset_field,
13041         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
13042         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
13043         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
13044         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
13045         "sctp-veri-tag#none");
13046 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
13047         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
13048         select, "select#add");
13049
13050 cmdline_parse_inst_t cmd_set_fdir_input_set = {
13051         .f = cmd_set_fdir_input_set_parsed,
13052         .data = NULL,
13053         .help_str = "set_fdir_input_set <port_id> "
13054         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
13055         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
13056         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
13057         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
13058         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
13059         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
13060         "sctp-veri-tag|none select|add",
13061         .tokens = {
13062                 (void *)&cmd_set_fdir_input_set_cmd,
13063                 (void *)&cmd_set_fdir_input_set_port_id,
13064                 (void *)&cmd_set_fdir_input_set_flow_type,
13065                 (void *)&cmd_set_fdir_input_set_field,
13066                 (void *)&cmd_set_fdir_input_set_select,
13067                 NULL,
13068         },
13069 };
13070
13071 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
13072 struct cmd_mcast_addr_result {
13073         cmdline_fixed_string_t mcast_addr_cmd;
13074         cmdline_fixed_string_t what;
13075         uint16_t port_num;
13076         struct rte_ether_addr mc_addr;
13077 };
13078
13079 static void cmd_mcast_addr_parsed(void *parsed_result,
13080                 __rte_unused struct cmdline *cl,
13081                 __rte_unused void *data)
13082 {
13083         struct cmd_mcast_addr_result *res = parsed_result;
13084
13085         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
13086                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
13087                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
13088                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
13089                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
13090                 return;
13091         }
13092         if (strcmp(res->what, "add") == 0)
13093                 mcast_addr_add(res->port_num, &res->mc_addr);
13094         else
13095                 mcast_addr_remove(res->port_num, &res->mc_addr);
13096 }
13097
13098 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
13099         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
13100                                  mcast_addr_cmd, "mcast_addr");
13101 cmdline_parse_token_string_t cmd_mcast_addr_what =
13102         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
13103                                  "add#remove");
13104 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
13105         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
13106 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
13107         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
13108
13109 cmdline_parse_inst_t cmd_mcast_addr = {
13110         .f = cmd_mcast_addr_parsed,
13111         .data = (void *)0,
13112         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
13113                 "Add/Remove multicast MAC address on port_id",
13114         .tokens = {
13115                 (void *)&cmd_mcast_addr_cmd,
13116                 (void *)&cmd_mcast_addr_what,
13117                 (void *)&cmd_mcast_addr_portnum,
13118                 (void *)&cmd_mcast_addr_addr,
13119                 NULL,
13120         },
13121 };
13122
13123 /* l2 tunnel config
13124  * only support E-tag now.
13125  */
13126
13127 /* Ether type config */
13128 struct cmd_config_l2_tunnel_eth_type_result {
13129         cmdline_fixed_string_t port;
13130         cmdline_fixed_string_t config;
13131         cmdline_fixed_string_t all;
13132         portid_t id;
13133         cmdline_fixed_string_t l2_tunnel;
13134         cmdline_fixed_string_t l2_tunnel_type;
13135         cmdline_fixed_string_t eth_type;
13136         uint16_t eth_type_val;
13137 };
13138
13139 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13140         TOKEN_STRING_INITIALIZER
13141                 (struct cmd_config_l2_tunnel_eth_type_result,
13142                  port, "port");
13143 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13144         TOKEN_STRING_INITIALIZER
13145                 (struct cmd_config_l2_tunnel_eth_type_result,
13146                  config, "config");
13147 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13148         TOKEN_STRING_INITIALIZER
13149                 (struct cmd_config_l2_tunnel_eth_type_result,
13150                  all, "all");
13151 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13152         TOKEN_NUM_INITIALIZER
13153                 (struct cmd_config_l2_tunnel_eth_type_result,
13154                  id, UINT16);
13155 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13156         TOKEN_STRING_INITIALIZER
13157                 (struct cmd_config_l2_tunnel_eth_type_result,
13158                  l2_tunnel, "l2-tunnel");
13159 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13160         TOKEN_STRING_INITIALIZER
13161                 (struct cmd_config_l2_tunnel_eth_type_result,
13162                  l2_tunnel_type, "E-tag");
13163 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13164         TOKEN_STRING_INITIALIZER
13165                 (struct cmd_config_l2_tunnel_eth_type_result,
13166                  eth_type, "ether-type");
13167 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13168         TOKEN_NUM_INITIALIZER
13169                 (struct cmd_config_l2_tunnel_eth_type_result,
13170                  eth_type_val, UINT16);
13171
13172 static enum rte_eth_tunnel_type
13173 str2fdir_l2_tunnel_type(char *string)
13174 {
13175         uint32_t i = 0;
13176
13177         static const struct {
13178                 char str[32];
13179                 enum rte_eth_tunnel_type type;
13180         } l2_tunnel_type_str[] = {
13181                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13182         };
13183
13184         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13185                 if (!strcmp(l2_tunnel_type_str[i].str, string))
13186                         return l2_tunnel_type_str[i].type;
13187         }
13188         return RTE_TUNNEL_TYPE_NONE;
13189 }
13190
13191 /* ether type config for all ports */
13192 static void
13193 cmd_config_l2_tunnel_eth_type_all_parsed
13194         (void *parsed_result,
13195          __rte_unused struct cmdline *cl,
13196          __rte_unused void *data)
13197 {
13198         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13199         struct rte_eth_l2_tunnel_conf entry;
13200         portid_t pid;
13201
13202         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13203         entry.ether_type = res->eth_type_val;
13204
13205         RTE_ETH_FOREACH_DEV(pid) {
13206                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13207         }
13208 }
13209
13210 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13211         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13212         .data = NULL,
13213         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13214         .tokens = {
13215                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13216                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13217                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13218                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13219                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13220                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13221                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13222                 NULL,
13223         },
13224 };
13225
13226 /* ether type config for a specific port */
13227 static void
13228 cmd_config_l2_tunnel_eth_type_specific_parsed(
13229         void *parsed_result,
13230         __rte_unused struct cmdline *cl,
13231         __rte_unused void *data)
13232 {
13233         struct cmd_config_l2_tunnel_eth_type_result *res =
13234                  parsed_result;
13235         struct rte_eth_l2_tunnel_conf entry;
13236
13237         if (port_id_is_invalid(res->id, ENABLED_WARN))
13238                 return;
13239
13240         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13241         entry.ether_type = res->eth_type_val;
13242
13243         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13244 }
13245
13246 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13247         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13248         .data = NULL,
13249         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13250         .tokens = {
13251                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13252                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13253                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13254                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13255                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13256                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13257                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13258                 NULL,
13259         },
13260 };
13261
13262 /* Enable/disable l2 tunnel */
13263 struct cmd_config_l2_tunnel_en_dis_result {
13264         cmdline_fixed_string_t port;
13265         cmdline_fixed_string_t config;
13266         cmdline_fixed_string_t all;
13267         portid_t id;
13268         cmdline_fixed_string_t l2_tunnel;
13269         cmdline_fixed_string_t l2_tunnel_type;
13270         cmdline_fixed_string_t en_dis;
13271 };
13272
13273 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13274         TOKEN_STRING_INITIALIZER
13275                 (struct cmd_config_l2_tunnel_en_dis_result,
13276                  port, "port");
13277 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13278         TOKEN_STRING_INITIALIZER
13279                 (struct cmd_config_l2_tunnel_en_dis_result,
13280                  config, "config");
13281 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13282         TOKEN_STRING_INITIALIZER
13283                 (struct cmd_config_l2_tunnel_en_dis_result,
13284                  all, "all");
13285 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13286         TOKEN_NUM_INITIALIZER
13287                 (struct cmd_config_l2_tunnel_en_dis_result,
13288                  id, UINT16);
13289 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13290         TOKEN_STRING_INITIALIZER
13291                 (struct cmd_config_l2_tunnel_en_dis_result,
13292                  l2_tunnel, "l2-tunnel");
13293 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13294         TOKEN_STRING_INITIALIZER
13295                 (struct cmd_config_l2_tunnel_en_dis_result,
13296                  l2_tunnel_type, "E-tag");
13297 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13298         TOKEN_STRING_INITIALIZER
13299                 (struct cmd_config_l2_tunnel_en_dis_result,
13300                  en_dis, "enable#disable");
13301
13302 /* enable/disable l2 tunnel for all ports */
13303 static void
13304 cmd_config_l2_tunnel_en_dis_all_parsed(
13305         void *parsed_result,
13306         __rte_unused struct cmdline *cl,
13307         __rte_unused void *data)
13308 {
13309         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13310         struct rte_eth_l2_tunnel_conf entry;
13311         portid_t pid;
13312         uint8_t en;
13313
13314         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13315
13316         if (!strcmp("enable", res->en_dis))
13317                 en = 1;
13318         else
13319                 en = 0;
13320
13321         RTE_ETH_FOREACH_DEV(pid) {
13322                 rte_eth_dev_l2_tunnel_offload_set(pid,
13323                                                   &entry,
13324                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13325                                                   en);
13326         }
13327 }
13328
13329 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13330         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13331         .data = NULL,
13332         .help_str = "port config all l2-tunnel E-tag enable|disable",
13333         .tokens = {
13334                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13335                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13336                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13337                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13338                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13339                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13340                 NULL,
13341         },
13342 };
13343
13344 /* enable/disable l2 tunnel for a port */
13345 static void
13346 cmd_config_l2_tunnel_en_dis_specific_parsed(
13347         void *parsed_result,
13348         __rte_unused struct cmdline *cl,
13349         __rte_unused void *data)
13350 {
13351         struct cmd_config_l2_tunnel_en_dis_result *res =
13352                 parsed_result;
13353         struct rte_eth_l2_tunnel_conf entry;
13354
13355         if (port_id_is_invalid(res->id, ENABLED_WARN))
13356                 return;
13357
13358         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13359
13360         if (!strcmp("enable", res->en_dis))
13361                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13362                                                   &entry,
13363                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13364                                                   1);
13365         else
13366                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13367                                                   &entry,
13368                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13369                                                   0);
13370 }
13371
13372 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13373         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13374         .data = NULL,
13375         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13376         .tokens = {
13377                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13378                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13379                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13380                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13381                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13382                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13383                 NULL,
13384         },
13385 };
13386
13387 /* E-tag configuration */
13388
13389 /* Common result structure for all E-tag configuration */
13390 struct cmd_config_e_tag_result {
13391         cmdline_fixed_string_t e_tag;
13392         cmdline_fixed_string_t set;
13393         cmdline_fixed_string_t insertion;
13394         cmdline_fixed_string_t stripping;
13395         cmdline_fixed_string_t forwarding;
13396         cmdline_fixed_string_t filter;
13397         cmdline_fixed_string_t add;
13398         cmdline_fixed_string_t del;
13399         cmdline_fixed_string_t on;
13400         cmdline_fixed_string_t off;
13401         cmdline_fixed_string_t on_off;
13402         cmdline_fixed_string_t port_tag_id;
13403         uint32_t port_tag_id_val;
13404         cmdline_fixed_string_t e_tag_id;
13405         uint16_t e_tag_id_val;
13406         cmdline_fixed_string_t dst_pool;
13407         uint8_t dst_pool_val;
13408         cmdline_fixed_string_t port;
13409         portid_t port_id;
13410         cmdline_fixed_string_t vf;
13411         uint8_t vf_id;
13412 };
13413
13414 /* Common CLI fields for all E-tag configuration */
13415 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13416         TOKEN_STRING_INITIALIZER
13417                 (struct cmd_config_e_tag_result,
13418                  e_tag, "E-tag");
13419 cmdline_parse_token_string_t cmd_config_e_tag_set =
13420         TOKEN_STRING_INITIALIZER
13421                 (struct cmd_config_e_tag_result,
13422                  set, "set");
13423 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13424         TOKEN_STRING_INITIALIZER
13425                 (struct cmd_config_e_tag_result,
13426                  insertion, "insertion");
13427 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13428         TOKEN_STRING_INITIALIZER
13429                 (struct cmd_config_e_tag_result,
13430                  stripping, "stripping");
13431 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13432         TOKEN_STRING_INITIALIZER
13433                 (struct cmd_config_e_tag_result,
13434                  forwarding, "forwarding");
13435 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13436         TOKEN_STRING_INITIALIZER
13437                 (struct cmd_config_e_tag_result,
13438                  filter, "filter");
13439 cmdline_parse_token_string_t cmd_config_e_tag_add =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_config_e_tag_result,
13442                  add, "add");
13443 cmdline_parse_token_string_t cmd_config_e_tag_del =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_config_e_tag_result,
13446                  del, "del");
13447 cmdline_parse_token_string_t cmd_config_e_tag_on =
13448         TOKEN_STRING_INITIALIZER
13449                 (struct cmd_config_e_tag_result,
13450                  on, "on");
13451 cmdline_parse_token_string_t cmd_config_e_tag_off =
13452         TOKEN_STRING_INITIALIZER
13453                 (struct cmd_config_e_tag_result,
13454                  off, "off");
13455 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13456         TOKEN_STRING_INITIALIZER
13457                 (struct cmd_config_e_tag_result,
13458                  on_off, "on#off");
13459 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13460         TOKEN_STRING_INITIALIZER
13461                 (struct cmd_config_e_tag_result,
13462                  port_tag_id, "port-tag-id");
13463 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13464         TOKEN_NUM_INITIALIZER
13465                 (struct cmd_config_e_tag_result,
13466                  port_tag_id_val, UINT32);
13467 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13468         TOKEN_STRING_INITIALIZER
13469                 (struct cmd_config_e_tag_result,
13470                  e_tag_id, "e-tag-id");
13471 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13472         TOKEN_NUM_INITIALIZER
13473                 (struct cmd_config_e_tag_result,
13474                  e_tag_id_val, UINT16);
13475 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13476         TOKEN_STRING_INITIALIZER
13477                 (struct cmd_config_e_tag_result,
13478                  dst_pool, "dst-pool");
13479 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13480         TOKEN_NUM_INITIALIZER
13481                 (struct cmd_config_e_tag_result,
13482                  dst_pool_val, UINT8);
13483 cmdline_parse_token_string_t cmd_config_e_tag_port =
13484         TOKEN_STRING_INITIALIZER
13485                 (struct cmd_config_e_tag_result,
13486                  port, "port");
13487 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13488         TOKEN_NUM_INITIALIZER
13489                 (struct cmd_config_e_tag_result,
13490                  port_id, UINT16);
13491 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13492         TOKEN_STRING_INITIALIZER
13493                 (struct cmd_config_e_tag_result,
13494                  vf, "vf");
13495 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13496         TOKEN_NUM_INITIALIZER
13497                 (struct cmd_config_e_tag_result,
13498                  vf_id, UINT8);
13499
13500 /* E-tag insertion configuration */
13501 static void
13502 cmd_config_e_tag_insertion_en_parsed(
13503         void *parsed_result,
13504         __rte_unused struct cmdline *cl,
13505         __rte_unused void *data)
13506 {
13507         struct cmd_config_e_tag_result *res =
13508                 parsed_result;
13509         struct rte_eth_l2_tunnel_conf entry;
13510
13511         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13512                 return;
13513
13514         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13515         entry.tunnel_id = res->port_tag_id_val;
13516         entry.vf_id = res->vf_id;
13517         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13518                                           &entry,
13519                                           ETH_L2_TUNNEL_INSERTION_MASK,
13520                                           1);
13521 }
13522
13523 static void
13524 cmd_config_e_tag_insertion_dis_parsed(
13525         void *parsed_result,
13526         __rte_unused struct cmdline *cl,
13527         __rte_unused void *data)
13528 {
13529         struct cmd_config_e_tag_result *res =
13530                 parsed_result;
13531         struct rte_eth_l2_tunnel_conf entry;
13532
13533         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13534                 return;
13535
13536         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13537         entry.vf_id = res->vf_id;
13538
13539         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13540                                           &entry,
13541                                           ETH_L2_TUNNEL_INSERTION_MASK,
13542                                           0);
13543 }
13544
13545 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13546         .f = cmd_config_e_tag_insertion_en_parsed,
13547         .data = NULL,
13548         .help_str = "E-tag ... : E-tag insertion enable",
13549         .tokens = {
13550                 (void *)&cmd_config_e_tag_e_tag,
13551                 (void *)&cmd_config_e_tag_set,
13552                 (void *)&cmd_config_e_tag_insertion,
13553                 (void *)&cmd_config_e_tag_on,
13554                 (void *)&cmd_config_e_tag_port_tag_id,
13555                 (void *)&cmd_config_e_tag_port_tag_id_val,
13556                 (void *)&cmd_config_e_tag_port,
13557                 (void *)&cmd_config_e_tag_port_id,
13558                 (void *)&cmd_config_e_tag_vf,
13559                 (void *)&cmd_config_e_tag_vf_id,
13560                 NULL,
13561         },
13562 };
13563
13564 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13565         .f = cmd_config_e_tag_insertion_dis_parsed,
13566         .data = NULL,
13567         .help_str = "E-tag ... : E-tag insertion disable",
13568         .tokens = {
13569                 (void *)&cmd_config_e_tag_e_tag,
13570                 (void *)&cmd_config_e_tag_set,
13571                 (void *)&cmd_config_e_tag_insertion,
13572                 (void *)&cmd_config_e_tag_off,
13573                 (void *)&cmd_config_e_tag_port,
13574                 (void *)&cmd_config_e_tag_port_id,
13575                 (void *)&cmd_config_e_tag_vf,
13576                 (void *)&cmd_config_e_tag_vf_id,
13577                 NULL,
13578         },
13579 };
13580
13581 /* E-tag stripping configuration */
13582 static void
13583 cmd_config_e_tag_stripping_parsed(
13584         void *parsed_result,
13585         __rte_unused struct cmdline *cl,
13586         __rte_unused void *data)
13587 {
13588         struct cmd_config_e_tag_result *res =
13589                 parsed_result;
13590         struct rte_eth_l2_tunnel_conf entry;
13591
13592         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13593                 return;
13594
13595         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13596
13597         if (!strcmp(res->on_off, "on"))
13598                 rte_eth_dev_l2_tunnel_offload_set
13599                         (res->port_id,
13600                          &entry,
13601                          ETH_L2_TUNNEL_STRIPPING_MASK,
13602                          1);
13603         else
13604                 rte_eth_dev_l2_tunnel_offload_set
13605                         (res->port_id,
13606                          &entry,
13607                          ETH_L2_TUNNEL_STRIPPING_MASK,
13608                          0);
13609 }
13610
13611 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13612         .f = cmd_config_e_tag_stripping_parsed,
13613         .data = NULL,
13614         .help_str = "E-tag ... : E-tag stripping enable/disable",
13615         .tokens = {
13616                 (void *)&cmd_config_e_tag_e_tag,
13617                 (void *)&cmd_config_e_tag_set,
13618                 (void *)&cmd_config_e_tag_stripping,
13619                 (void *)&cmd_config_e_tag_on_off,
13620                 (void *)&cmd_config_e_tag_port,
13621                 (void *)&cmd_config_e_tag_port_id,
13622                 NULL,
13623         },
13624 };
13625
13626 /* E-tag forwarding configuration */
13627 static void
13628 cmd_config_e_tag_forwarding_parsed(
13629         void *parsed_result,
13630         __rte_unused struct cmdline *cl,
13631         __rte_unused void *data)
13632 {
13633         struct cmd_config_e_tag_result *res = parsed_result;
13634         struct rte_eth_l2_tunnel_conf entry;
13635
13636         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13637                 return;
13638
13639         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13640
13641         if (!strcmp(res->on_off, "on"))
13642                 rte_eth_dev_l2_tunnel_offload_set
13643                         (res->port_id,
13644                          &entry,
13645                          ETH_L2_TUNNEL_FORWARDING_MASK,
13646                          1);
13647         else
13648                 rte_eth_dev_l2_tunnel_offload_set
13649                         (res->port_id,
13650                          &entry,
13651                          ETH_L2_TUNNEL_FORWARDING_MASK,
13652                          0);
13653 }
13654
13655 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13656         .f = cmd_config_e_tag_forwarding_parsed,
13657         .data = NULL,
13658         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13659         .tokens = {
13660                 (void *)&cmd_config_e_tag_e_tag,
13661                 (void *)&cmd_config_e_tag_set,
13662                 (void *)&cmd_config_e_tag_forwarding,
13663                 (void *)&cmd_config_e_tag_on_off,
13664                 (void *)&cmd_config_e_tag_port,
13665                 (void *)&cmd_config_e_tag_port_id,
13666                 NULL,
13667         },
13668 };
13669
13670 /* E-tag filter configuration */
13671 static void
13672 cmd_config_e_tag_filter_add_parsed(
13673         void *parsed_result,
13674         __rte_unused struct cmdline *cl,
13675         __rte_unused void *data)
13676 {
13677         struct cmd_config_e_tag_result *res = parsed_result;
13678         struct rte_eth_l2_tunnel_conf entry;
13679         int ret = 0;
13680
13681         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13682                 return;
13683
13684         if (res->e_tag_id_val > 0x3fff) {
13685                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13686                 return;
13687         }
13688
13689         ret = rte_eth_dev_filter_supported(res->port_id,
13690                                            RTE_ETH_FILTER_L2_TUNNEL);
13691         if (ret < 0) {
13692                 printf("E-tag filter is not supported on port %u.\n",
13693                        res->port_id);
13694                 return;
13695         }
13696
13697         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13698         entry.tunnel_id = res->e_tag_id_val;
13699         entry.pool = res->dst_pool_val;
13700
13701         ret = rte_eth_dev_filter_ctrl(res->port_id,
13702                                       RTE_ETH_FILTER_L2_TUNNEL,
13703                                       RTE_ETH_FILTER_ADD,
13704                                       &entry);
13705         if (ret < 0)
13706                 printf("E-tag filter programming error: (%s)\n",
13707                        strerror(-ret));
13708 }
13709
13710 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13711         .f = cmd_config_e_tag_filter_add_parsed,
13712         .data = NULL,
13713         .help_str = "E-tag ... : E-tag filter add",
13714         .tokens = {
13715                 (void *)&cmd_config_e_tag_e_tag,
13716                 (void *)&cmd_config_e_tag_set,
13717                 (void *)&cmd_config_e_tag_filter,
13718                 (void *)&cmd_config_e_tag_add,
13719                 (void *)&cmd_config_e_tag_e_tag_id,
13720                 (void *)&cmd_config_e_tag_e_tag_id_val,
13721                 (void *)&cmd_config_e_tag_dst_pool,
13722                 (void *)&cmd_config_e_tag_dst_pool_val,
13723                 (void *)&cmd_config_e_tag_port,
13724                 (void *)&cmd_config_e_tag_port_id,
13725                 NULL,
13726         },
13727 };
13728
13729 static void
13730 cmd_config_e_tag_filter_del_parsed(
13731         void *parsed_result,
13732         __rte_unused struct cmdline *cl,
13733         __rte_unused void *data)
13734 {
13735         struct cmd_config_e_tag_result *res = parsed_result;
13736         struct rte_eth_l2_tunnel_conf entry;
13737         int ret = 0;
13738
13739         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13740                 return;
13741
13742         if (res->e_tag_id_val > 0x3fff) {
13743                 printf("e-tag-id must be less than 0x3fff.\n");
13744                 return;
13745         }
13746
13747         ret = rte_eth_dev_filter_supported(res->port_id,
13748                                            RTE_ETH_FILTER_L2_TUNNEL);
13749         if (ret < 0) {
13750                 printf("E-tag filter is not supported on port %u.\n",
13751                        res->port_id);
13752                 return;
13753         }
13754
13755         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13756         entry.tunnel_id = res->e_tag_id_val;
13757
13758         ret = rte_eth_dev_filter_ctrl(res->port_id,
13759                                       RTE_ETH_FILTER_L2_TUNNEL,
13760                                       RTE_ETH_FILTER_DELETE,
13761                                       &entry);
13762         if (ret < 0)
13763                 printf("E-tag filter programming error: (%s)\n",
13764                        strerror(-ret));
13765 }
13766
13767 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13768         .f = cmd_config_e_tag_filter_del_parsed,
13769         .data = NULL,
13770         .help_str = "E-tag ... : E-tag filter delete",
13771         .tokens = {
13772                 (void *)&cmd_config_e_tag_e_tag,
13773                 (void *)&cmd_config_e_tag_set,
13774                 (void *)&cmd_config_e_tag_filter,
13775                 (void *)&cmd_config_e_tag_del,
13776                 (void *)&cmd_config_e_tag_e_tag_id,
13777                 (void *)&cmd_config_e_tag_e_tag_id_val,
13778                 (void *)&cmd_config_e_tag_port,
13779                 (void *)&cmd_config_e_tag_port_id,
13780                 NULL,
13781         },
13782 };
13783
13784 /* vf vlan anti spoof configuration */
13785
13786 /* Common result structure for vf vlan anti spoof */
13787 struct cmd_vf_vlan_anti_spoof_result {
13788         cmdline_fixed_string_t set;
13789         cmdline_fixed_string_t vf;
13790         cmdline_fixed_string_t vlan;
13791         cmdline_fixed_string_t antispoof;
13792         portid_t port_id;
13793         uint32_t vf_id;
13794         cmdline_fixed_string_t on_off;
13795 };
13796
13797 /* Common CLI fields for vf vlan anti spoof enable disable */
13798 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13799         TOKEN_STRING_INITIALIZER
13800                 (struct cmd_vf_vlan_anti_spoof_result,
13801                  set, "set");
13802 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13803         TOKEN_STRING_INITIALIZER
13804                 (struct cmd_vf_vlan_anti_spoof_result,
13805                  vf, "vf");
13806 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13807         TOKEN_STRING_INITIALIZER
13808                 (struct cmd_vf_vlan_anti_spoof_result,
13809                  vlan, "vlan");
13810 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13811         TOKEN_STRING_INITIALIZER
13812                 (struct cmd_vf_vlan_anti_spoof_result,
13813                  antispoof, "antispoof");
13814 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13815         TOKEN_NUM_INITIALIZER
13816                 (struct cmd_vf_vlan_anti_spoof_result,
13817                  port_id, UINT16);
13818 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13819         TOKEN_NUM_INITIALIZER
13820                 (struct cmd_vf_vlan_anti_spoof_result,
13821                  vf_id, UINT32);
13822 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13823         TOKEN_STRING_INITIALIZER
13824                 (struct cmd_vf_vlan_anti_spoof_result,
13825                  on_off, "on#off");
13826
13827 static void
13828 cmd_set_vf_vlan_anti_spoof_parsed(
13829         void *parsed_result,
13830         __rte_unused struct cmdline *cl,
13831         __rte_unused void *data)
13832 {
13833         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13834         int ret = -ENOTSUP;
13835
13836         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13837
13838         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13839                 return;
13840
13841 #ifdef RTE_NET_IXGBE
13842         if (ret == -ENOTSUP)
13843                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13844                                 res->vf_id, is_on);
13845 #endif
13846 #ifdef RTE_NET_I40E
13847         if (ret == -ENOTSUP)
13848                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13849                                 res->vf_id, is_on);
13850 #endif
13851 #ifdef RTE_NET_BNXT
13852         if (ret == -ENOTSUP)
13853                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13854                                 res->vf_id, is_on);
13855 #endif
13856
13857         switch (ret) {
13858         case 0:
13859                 break;
13860         case -EINVAL:
13861                 printf("invalid vf_id %d\n", res->vf_id);
13862                 break;
13863         case -ENODEV:
13864                 printf("invalid port_id %d\n", res->port_id);
13865                 break;
13866         case -ENOTSUP:
13867                 printf("function not implemented\n");
13868                 break;
13869         default:
13870                 printf("programming error: (%s)\n", strerror(-ret));
13871         }
13872 }
13873
13874 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13875         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13876         .data = NULL,
13877         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13878         .tokens = {
13879                 (void *)&cmd_vf_vlan_anti_spoof_set,
13880                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13881                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13882                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13883                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13884                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13885                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13886                 NULL,
13887         },
13888 };
13889
13890 /* vf mac anti spoof configuration */
13891
13892 /* Common result structure for vf mac anti spoof */
13893 struct cmd_vf_mac_anti_spoof_result {
13894         cmdline_fixed_string_t set;
13895         cmdline_fixed_string_t vf;
13896         cmdline_fixed_string_t mac;
13897         cmdline_fixed_string_t antispoof;
13898         portid_t port_id;
13899         uint32_t vf_id;
13900         cmdline_fixed_string_t on_off;
13901 };
13902
13903 /* Common CLI fields for vf mac anti spoof enable disable */
13904 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13905         TOKEN_STRING_INITIALIZER
13906                 (struct cmd_vf_mac_anti_spoof_result,
13907                  set, "set");
13908 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13909         TOKEN_STRING_INITIALIZER
13910                 (struct cmd_vf_mac_anti_spoof_result,
13911                  vf, "vf");
13912 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13913         TOKEN_STRING_INITIALIZER
13914                 (struct cmd_vf_mac_anti_spoof_result,
13915                  mac, "mac");
13916 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13917         TOKEN_STRING_INITIALIZER
13918                 (struct cmd_vf_mac_anti_spoof_result,
13919                  antispoof, "antispoof");
13920 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13921         TOKEN_NUM_INITIALIZER
13922                 (struct cmd_vf_mac_anti_spoof_result,
13923                  port_id, UINT16);
13924 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13925         TOKEN_NUM_INITIALIZER
13926                 (struct cmd_vf_mac_anti_spoof_result,
13927                  vf_id, UINT32);
13928 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13929         TOKEN_STRING_INITIALIZER
13930                 (struct cmd_vf_mac_anti_spoof_result,
13931                  on_off, "on#off");
13932
13933 static void
13934 cmd_set_vf_mac_anti_spoof_parsed(
13935         void *parsed_result,
13936         __rte_unused struct cmdline *cl,
13937         __rte_unused void *data)
13938 {
13939         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13940         int ret = -ENOTSUP;
13941
13942         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13943
13944         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13945                 return;
13946
13947 #ifdef RTE_NET_IXGBE
13948         if (ret == -ENOTSUP)
13949                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13950                         res->vf_id, is_on);
13951 #endif
13952 #ifdef RTE_NET_I40E
13953         if (ret == -ENOTSUP)
13954                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13955                         res->vf_id, is_on);
13956 #endif
13957 #ifdef RTE_NET_BNXT
13958         if (ret == -ENOTSUP)
13959                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13960                         res->vf_id, is_on);
13961 #endif
13962
13963         switch (ret) {
13964         case 0:
13965                 break;
13966         case -EINVAL:
13967                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13968                 break;
13969         case -ENODEV:
13970                 printf("invalid port_id %d\n", res->port_id);
13971                 break;
13972         case -ENOTSUP:
13973                 printf("function not implemented\n");
13974                 break;
13975         default:
13976                 printf("programming error: (%s)\n", strerror(-ret));
13977         }
13978 }
13979
13980 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13981         .f = cmd_set_vf_mac_anti_spoof_parsed,
13982         .data = NULL,
13983         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13984         .tokens = {
13985                 (void *)&cmd_vf_mac_anti_spoof_set,
13986                 (void *)&cmd_vf_mac_anti_spoof_vf,
13987                 (void *)&cmd_vf_mac_anti_spoof_mac,
13988                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13989                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13990                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13991                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13992                 NULL,
13993         },
13994 };
13995
13996 /* vf vlan strip queue configuration */
13997
13998 /* Common result structure for vf mac anti spoof */
13999 struct cmd_vf_vlan_stripq_result {
14000         cmdline_fixed_string_t set;
14001         cmdline_fixed_string_t vf;
14002         cmdline_fixed_string_t vlan;
14003         cmdline_fixed_string_t stripq;
14004         portid_t port_id;
14005         uint16_t vf_id;
14006         cmdline_fixed_string_t on_off;
14007 };
14008
14009 /* Common CLI fields for vf vlan strip enable disable */
14010 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
14011         TOKEN_STRING_INITIALIZER
14012                 (struct cmd_vf_vlan_stripq_result,
14013                  set, "set");
14014 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
14015         TOKEN_STRING_INITIALIZER
14016                 (struct cmd_vf_vlan_stripq_result,
14017                  vf, "vf");
14018 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
14019         TOKEN_STRING_INITIALIZER
14020                 (struct cmd_vf_vlan_stripq_result,
14021                  vlan, "vlan");
14022 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
14023         TOKEN_STRING_INITIALIZER
14024                 (struct cmd_vf_vlan_stripq_result,
14025                  stripq, "stripq");
14026 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
14027         TOKEN_NUM_INITIALIZER
14028                 (struct cmd_vf_vlan_stripq_result,
14029                  port_id, UINT16);
14030 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
14031         TOKEN_NUM_INITIALIZER
14032                 (struct cmd_vf_vlan_stripq_result,
14033                  vf_id, UINT16);
14034 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
14035         TOKEN_STRING_INITIALIZER
14036                 (struct cmd_vf_vlan_stripq_result,
14037                  on_off, "on#off");
14038
14039 static void
14040 cmd_set_vf_vlan_stripq_parsed(
14041         void *parsed_result,
14042         __rte_unused struct cmdline *cl,
14043         __rte_unused void *data)
14044 {
14045         struct cmd_vf_vlan_stripq_result *res = parsed_result;
14046         int ret = -ENOTSUP;
14047
14048         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14049
14050         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14051                 return;
14052
14053 #ifdef RTE_NET_IXGBE
14054         if (ret == -ENOTSUP)
14055                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
14056                         res->vf_id, is_on);
14057 #endif
14058 #ifdef RTE_NET_I40E
14059         if (ret == -ENOTSUP)
14060                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
14061                         res->vf_id, is_on);
14062 #endif
14063 #ifdef RTE_NET_BNXT
14064         if (ret == -ENOTSUP)
14065                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
14066                         res->vf_id, is_on);
14067 #endif
14068
14069         switch (ret) {
14070         case 0:
14071                 break;
14072         case -EINVAL:
14073                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14074                 break;
14075         case -ENODEV:
14076                 printf("invalid port_id %d\n", res->port_id);
14077                 break;
14078         case -ENOTSUP:
14079                 printf("function not implemented\n");
14080                 break;
14081         default:
14082                 printf("programming error: (%s)\n", strerror(-ret));
14083         }
14084 }
14085
14086 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
14087         .f = cmd_set_vf_vlan_stripq_parsed,
14088         .data = NULL,
14089         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
14090         .tokens = {
14091                 (void *)&cmd_vf_vlan_stripq_set,
14092                 (void *)&cmd_vf_vlan_stripq_vf,
14093                 (void *)&cmd_vf_vlan_stripq_vlan,
14094                 (void *)&cmd_vf_vlan_stripq_stripq,
14095                 (void *)&cmd_vf_vlan_stripq_port_id,
14096                 (void *)&cmd_vf_vlan_stripq_vf_id,
14097                 (void *)&cmd_vf_vlan_stripq_on_off,
14098                 NULL,
14099         },
14100 };
14101
14102 /* vf vlan insert configuration */
14103
14104 /* Common result structure for vf vlan insert */
14105 struct cmd_vf_vlan_insert_result {
14106         cmdline_fixed_string_t set;
14107         cmdline_fixed_string_t vf;
14108         cmdline_fixed_string_t vlan;
14109         cmdline_fixed_string_t insert;
14110         portid_t port_id;
14111         uint16_t vf_id;
14112         uint16_t vlan_id;
14113 };
14114
14115 /* Common CLI fields for vf vlan insert enable disable */
14116 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
14117         TOKEN_STRING_INITIALIZER
14118                 (struct cmd_vf_vlan_insert_result,
14119                  set, "set");
14120 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
14121         TOKEN_STRING_INITIALIZER
14122                 (struct cmd_vf_vlan_insert_result,
14123                  vf, "vf");
14124 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
14125         TOKEN_STRING_INITIALIZER
14126                 (struct cmd_vf_vlan_insert_result,
14127                  vlan, "vlan");
14128 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
14129         TOKEN_STRING_INITIALIZER
14130                 (struct cmd_vf_vlan_insert_result,
14131                  insert, "insert");
14132 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
14133         TOKEN_NUM_INITIALIZER
14134                 (struct cmd_vf_vlan_insert_result,
14135                  port_id, UINT16);
14136 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14137         TOKEN_NUM_INITIALIZER
14138                 (struct cmd_vf_vlan_insert_result,
14139                  vf_id, UINT16);
14140 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14141         TOKEN_NUM_INITIALIZER
14142                 (struct cmd_vf_vlan_insert_result,
14143                  vlan_id, UINT16);
14144
14145 static void
14146 cmd_set_vf_vlan_insert_parsed(
14147         void *parsed_result,
14148         __rte_unused struct cmdline *cl,
14149         __rte_unused void *data)
14150 {
14151         struct cmd_vf_vlan_insert_result *res = parsed_result;
14152         int ret = -ENOTSUP;
14153
14154         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14155                 return;
14156
14157 #ifdef RTE_NET_IXGBE
14158         if (ret == -ENOTSUP)
14159                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14160                         res->vlan_id);
14161 #endif
14162 #ifdef RTE_NET_I40E
14163         if (ret == -ENOTSUP)
14164                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14165                         res->vlan_id);
14166 #endif
14167 #ifdef RTE_NET_BNXT
14168         if (ret == -ENOTSUP)
14169                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14170                         res->vlan_id);
14171 #endif
14172
14173         switch (ret) {
14174         case 0:
14175                 break;
14176         case -EINVAL:
14177                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14178                 break;
14179         case -ENODEV:
14180                 printf("invalid port_id %d\n", res->port_id);
14181                 break;
14182         case -ENOTSUP:
14183                 printf("function not implemented\n");
14184                 break;
14185         default:
14186                 printf("programming error: (%s)\n", strerror(-ret));
14187         }
14188 }
14189
14190 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14191         .f = cmd_set_vf_vlan_insert_parsed,
14192         .data = NULL,
14193         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14194         .tokens = {
14195                 (void *)&cmd_vf_vlan_insert_set,
14196                 (void *)&cmd_vf_vlan_insert_vf,
14197                 (void *)&cmd_vf_vlan_insert_vlan,
14198                 (void *)&cmd_vf_vlan_insert_insert,
14199                 (void *)&cmd_vf_vlan_insert_port_id,
14200                 (void *)&cmd_vf_vlan_insert_vf_id,
14201                 (void *)&cmd_vf_vlan_insert_vlan_id,
14202                 NULL,
14203         },
14204 };
14205
14206 /* tx loopback configuration */
14207
14208 /* Common result structure for tx loopback */
14209 struct cmd_tx_loopback_result {
14210         cmdline_fixed_string_t set;
14211         cmdline_fixed_string_t tx;
14212         cmdline_fixed_string_t loopback;
14213         portid_t port_id;
14214         cmdline_fixed_string_t on_off;
14215 };
14216
14217 /* Common CLI fields for tx loopback enable disable */
14218 cmdline_parse_token_string_t cmd_tx_loopback_set =
14219         TOKEN_STRING_INITIALIZER
14220                 (struct cmd_tx_loopback_result,
14221                  set, "set");
14222 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14223         TOKEN_STRING_INITIALIZER
14224                 (struct cmd_tx_loopback_result,
14225                  tx, "tx");
14226 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14227         TOKEN_STRING_INITIALIZER
14228                 (struct cmd_tx_loopback_result,
14229                  loopback, "loopback");
14230 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14231         TOKEN_NUM_INITIALIZER
14232                 (struct cmd_tx_loopback_result,
14233                  port_id, UINT16);
14234 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14235         TOKEN_STRING_INITIALIZER
14236                 (struct cmd_tx_loopback_result,
14237                  on_off, "on#off");
14238
14239 static void
14240 cmd_set_tx_loopback_parsed(
14241         void *parsed_result,
14242         __rte_unused struct cmdline *cl,
14243         __rte_unused void *data)
14244 {
14245         struct cmd_tx_loopback_result *res = parsed_result;
14246         int ret = -ENOTSUP;
14247
14248         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14249
14250         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14251                 return;
14252
14253 #ifdef RTE_NET_IXGBE
14254         if (ret == -ENOTSUP)
14255                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14256 #endif
14257 #ifdef RTE_NET_I40E
14258         if (ret == -ENOTSUP)
14259                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14260 #endif
14261 #ifdef RTE_NET_BNXT
14262         if (ret == -ENOTSUP)
14263                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14264 #endif
14265 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
14266         if (ret == -ENOTSUP)
14267                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14268 #endif
14269
14270         switch (ret) {
14271         case 0:
14272                 break;
14273         case -EINVAL:
14274                 printf("invalid is_on %d\n", is_on);
14275                 break;
14276         case -ENODEV:
14277                 printf("invalid port_id %d\n", res->port_id);
14278                 break;
14279         case -ENOTSUP:
14280                 printf("function not implemented\n");
14281                 break;
14282         default:
14283                 printf("programming error: (%s)\n", strerror(-ret));
14284         }
14285 }
14286
14287 cmdline_parse_inst_t cmd_set_tx_loopback = {
14288         .f = cmd_set_tx_loopback_parsed,
14289         .data = NULL,
14290         .help_str = "set tx loopback <port_id> on|off",
14291         .tokens = {
14292                 (void *)&cmd_tx_loopback_set,
14293                 (void *)&cmd_tx_loopback_tx,
14294                 (void *)&cmd_tx_loopback_loopback,
14295                 (void *)&cmd_tx_loopback_port_id,
14296                 (void *)&cmd_tx_loopback_on_off,
14297                 NULL,
14298         },
14299 };
14300
14301 /* all queues drop enable configuration */
14302
14303 /* Common result structure for all queues drop enable */
14304 struct cmd_all_queues_drop_en_result {
14305         cmdline_fixed_string_t set;
14306         cmdline_fixed_string_t all;
14307         cmdline_fixed_string_t queues;
14308         cmdline_fixed_string_t drop;
14309         portid_t port_id;
14310         cmdline_fixed_string_t on_off;
14311 };
14312
14313 /* Common CLI fields for tx loopback enable disable */
14314 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14315         TOKEN_STRING_INITIALIZER
14316                 (struct cmd_all_queues_drop_en_result,
14317                  set, "set");
14318 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14319         TOKEN_STRING_INITIALIZER
14320                 (struct cmd_all_queues_drop_en_result,
14321                  all, "all");
14322 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14323         TOKEN_STRING_INITIALIZER
14324                 (struct cmd_all_queues_drop_en_result,
14325                  queues, "queues");
14326 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14327         TOKEN_STRING_INITIALIZER
14328                 (struct cmd_all_queues_drop_en_result,
14329                  drop, "drop");
14330 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14331         TOKEN_NUM_INITIALIZER
14332                 (struct cmd_all_queues_drop_en_result,
14333                  port_id, UINT16);
14334 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14335         TOKEN_STRING_INITIALIZER
14336                 (struct cmd_all_queues_drop_en_result,
14337                  on_off, "on#off");
14338
14339 static void
14340 cmd_set_all_queues_drop_en_parsed(
14341         void *parsed_result,
14342         __rte_unused struct cmdline *cl,
14343         __rte_unused void *data)
14344 {
14345         struct cmd_all_queues_drop_en_result *res = parsed_result;
14346         int ret = -ENOTSUP;
14347         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14348
14349         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14350                 return;
14351
14352 #ifdef RTE_NET_IXGBE
14353         if (ret == -ENOTSUP)
14354                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14355 #endif
14356 #ifdef RTE_NET_BNXT
14357         if (ret == -ENOTSUP)
14358                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14359 #endif
14360         switch (ret) {
14361         case 0:
14362                 break;
14363         case -EINVAL:
14364                 printf("invalid is_on %d\n", is_on);
14365                 break;
14366         case -ENODEV:
14367                 printf("invalid port_id %d\n", res->port_id);
14368                 break;
14369         case -ENOTSUP:
14370                 printf("function not implemented\n");
14371                 break;
14372         default:
14373                 printf("programming error: (%s)\n", strerror(-ret));
14374         }
14375 }
14376
14377 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14378         .f = cmd_set_all_queues_drop_en_parsed,
14379         .data = NULL,
14380         .help_str = "set all queues drop <port_id> on|off",
14381         .tokens = {
14382                 (void *)&cmd_all_queues_drop_en_set,
14383                 (void *)&cmd_all_queues_drop_en_all,
14384                 (void *)&cmd_all_queues_drop_en_queues,
14385                 (void *)&cmd_all_queues_drop_en_drop,
14386                 (void *)&cmd_all_queues_drop_en_port_id,
14387                 (void *)&cmd_all_queues_drop_en_on_off,
14388                 NULL,
14389         },
14390 };
14391
14392 /* vf split drop enable configuration */
14393
14394 /* Common result structure for vf split drop enable */
14395 struct cmd_vf_split_drop_en_result {
14396         cmdline_fixed_string_t set;
14397         cmdline_fixed_string_t vf;
14398         cmdline_fixed_string_t split;
14399         cmdline_fixed_string_t drop;
14400         portid_t port_id;
14401         uint16_t vf_id;
14402         cmdline_fixed_string_t on_off;
14403 };
14404
14405 /* Common CLI fields for vf split drop enable disable */
14406 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14407         TOKEN_STRING_INITIALIZER
14408                 (struct cmd_vf_split_drop_en_result,
14409                  set, "set");
14410 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14411         TOKEN_STRING_INITIALIZER
14412                 (struct cmd_vf_split_drop_en_result,
14413                  vf, "vf");
14414 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14415         TOKEN_STRING_INITIALIZER
14416                 (struct cmd_vf_split_drop_en_result,
14417                  split, "split");
14418 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14419         TOKEN_STRING_INITIALIZER
14420                 (struct cmd_vf_split_drop_en_result,
14421                  drop, "drop");
14422 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14423         TOKEN_NUM_INITIALIZER
14424                 (struct cmd_vf_split_drop_en_result,
14425                  port_id, UINT16);
14426 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14427         TOKEN_NUM_INITIALIZER
14428                 (struct cmd_vf_split_drop_en_result,
14429                  vf_id, UINT16);
14430 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14431         TOKEN_STRING_INITIALIZER
14432                 (struct cmd_vf_split_drop_en_result,
14433                  on_off, "on#off");
14434
14435 static void
14436 cmd_set_vf_split_drop_en_parsed(
14437         void *parsed_result,
14438         __rte_unused struct cmdline *cl,
14439         __rte_unused void *data)
14440 {
14441         struct cmd_vf_split_drop_en_result *res = parsed_result;
14442         int ret = -ENOTSUP;
14443         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14444
14445         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14446                 return;
14447
14448 #ifdef RTE_NET_IXGBE
14449         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14450                         is_on);
14451 #endif
14452         switch (ret) {
14453         case 0:
14454                 break;
14455         case -EINVAL:
14456                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14457                 break;
14458         case -ENODEV:
14459                 printf("invalid port_id %d\n", res->port_id);
14460                 break;
14461         case -ENOTSUP:
14462                 printf("not supported on port %d\n", res->port_id);
14463                 break;
14464         default:
14465                 printf("programming error: (%s)\n", strerror(-ret));
14466         }
14467 }
14468
14469 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14470         .f = cmd_set_vf_split_drop_en_parsed,
14471         .data = NULL,
14472         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14473         .tokens = {
14474                 (void *)&cmd_vf_split_drop_en_set,
14475                 (void *)&cmd_vf_split_drop_en_vf,
14476                 (void *)&cmd_vf_split_drop_en_split,
14477                 (void *)&cmd_vf_split_drop_en_drop,
14478                 (void *)&cmd_vf_split_drop_en_port_id,
14479                 (void *)&cmd_vf_split_drop_en_vf_id,
14480                 (void *)&cmd_vf_split_drop_en_on_off,
14481                 NULL,
14482         },
14483 };
14484
14485 /* vf mac address configuration */
14486
14487 /* Common result structure for vf mac address */
14488 struct cmd_set_vf_mac_addr_result {
14489         cmdline_fixed_string_t set;
14490         cmdline_fixed_string_t vf;
14491         cmdline_fixed_string_t mac;
14492         cmdline_fixed_string_t addr;
14493         portid_t port_id;
14494         uint16_t vf_id;
14495         struct rte_ether_addr mac_addr;
14496
14497 };
14498
14499 /* Common CLI fields for vf split drop enable disable */
14500 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14501         TOKEN_STRING_INITIALIZER
14502                 (struct cmd_set_vf_mac_addr_result,
14503                  set, "set");
14504 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14505         TOKEN_STRING_INITIALIZER
14506                 (struct cmd_set_vf_mac_addr_result,
14507                  vf, "vf");
14508 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14509         TOKEN_STRING_INITIALIZER
14510                 (struct cmd_set_vf_mac_addr_result,
14511                  mac, "mac");
14512 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14513         TOKEN_STRING_INITIALIZER
14514                 (struct cmd_set_vf_mac_addr_result,
14515                  addr, "addr");
14516 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14517         TOKEN_NUM_INITIALIZER
14518                 (struct cmd_set_vf_mac_addr_result,
14519                  port_id, UINT16);
14520 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14521         TOKEN_NUM_INITIALIZER
14522                 (struct cmd_set_vf_mac_addr_result,
14523                  vf_id, UINT16);
14524 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14525         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14526                  mac_addr);
14527
14528 static void
14529 cmd_set_vf_mac_addr_parsed(
14530         void *parsed_result,
14531         __rte_unused struct cmdline *cl,
14532         __rte_unused void *data)
14533 {
14534         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14535         int ret = -ENOTSUP;
14536
14537         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14538                 return;
14539
14540 #ifdef RTE_NET_IXGBE
14541         if (ret == -ENOTSUP)
14542                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14543                                 &res->mac_addr);
14544 #endif
14545 #ifdef RTE_NET_I40E
14546         if (ret == -ENOTSUP)
14547                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14548                                 &res->mac_addr);
14549 #endif
14550 #ifdef RTE_NET_BNXT
14551         if (ret == -ENOTSUP)
14552                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14553                                 &res->mac_addr);
14554 #endif
14555
14556         switch (ret) {
14557         case 0:
14558                 break;
14559         case -EINVAL:
14560                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14561                 break;
14562         case -ENODEV:
14563                 printf("invalid port_id %d\n", res->port_id);
14564                 break;
14565         case -ENOTSUP:
14566                 printf("function not implemented\n");
14567                 break;
14568         default:
14569                 printf("programming error: (%s)\n", strerror(-ret));
14570         }
14571 }
14572
14573 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14574         .f = cmd_set_vf_mac_addr_parsed,
14575         .data = NULL,
14576         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14577         .tokens = {
14578                 (void *)&cmd_set_vf_mac_addr_set,
14579                 (void *)&cmd_set_vf_mac_addr_vf,
14580                 (void *)&cmd_set_vf_mac_addr_mac,
14581                 (void *)&cmd_set_vf_mac_addr_addr,
14582                 (void *)&cmd_set_vf_mac_addr_port_id,
14583                 (void *)&cmd_set_vf_mac_addr_vf_id,
14584                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14585                 NULL,
14586         },
14587 };
14588
14589 /* MACsec configuration */
14590
14591 /* Common result structure for MACsec offload enable */
14592 struct cmd_macsec_offload_on_result {
14593         cmdline_fixed_string_t set;
14594         cmdline_fixed_string_t macsec;
14595         cmdline_fixed_string_t offload;
14596         portid_t port_id;
14597         cmdline_fixed_string_t on;
14598         cmdline_fixed_string_t encrypt;
14599         cmdline_fixed_string_t en_on_off;
14600         cmdline_fixed_string_t replay_protect;
14601         cmdline_fixed_string_t rp_on_off;
14602 };
14603
14604 /* Common CLI fields for MACsec offload disable */
14605 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14606         TOKEN_STRING_INITIALIZER
14607                 (struct cmd_macsec_offload_on_result,
14608                  set, "set");
14609 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14610         TOKEN_STRING_INITIALIZER
14611                 (struct cmd_macsec_offload_on_result,
14612                  macsec, "macsec");
14613 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14614         TOKEN_STRING_INITIALIZER
14615                 (struct cmd_macsec_offload_on_result,
14616                  offload, "offload");
14617 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14618         TOKEN_NUM_INITIALIZER
14619                 (struct cmd_macsec_offload_on_result,
14620                  port_id, UINT16);
14621 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14622         TOKEN_STRING_INITIALIZER
14623                 (struct cmd_macsec_offload_on_result,
14624                  on, "on");
14625 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14626         TOKEN_STRING_INITIALIZER
14627                 (struct cmd_macsec_offload_on_result,
14628                  encrypt, "encrypt");
14629 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14630         TOKEN_STRING_INITIALIZER
14631                 (struct cmd_macsec_offload_on_result,
14632                  en_on_off, "on#off");
14633 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14634         TOKEN_STRING_INITIALIZER
14635                 (struct cmd_macsec_offload_on_result,
14636                  replay_protect, "replay-protect");
14637 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14638         TOKEN_STRING_INITIALIZER
14639                 (struct cmd_macsec_offload_on_result,
14640                  rp_on_off, "on#off");
14641
14642 static void
14643 cmd_set_macsec_offload_on_parsed(
14644         void *parsed_result,
14645         __rte_unused struct cmdline *cl,
14646         __rte_unused void *data)
14647 {
14648         struct cmd_macsec_offload_on_result *res = parsed_result;
14649         int ret = -ENOTSUP;
14650         portid_t port_id = res->port_id;
14651         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14652         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14653         struct rte_eth_dev_info dev_info;
14654
14655         if (port_id_is_invalid(port_id, ENABLED_WARN))
14656                 return;
14657         if (!port_is_stopped(port_id)) {
14658                 printf("Please stop port %d first\n", port_id);
14659                 return;
14660         }
14661
14662         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14663         if (ret != 0)
14664                 return;
14665
14666         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14667 #ifdef RTE_NET_IXGBE
14668                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14669 #endif
14670         }
14671         RTE_SET_USED(en);
14672         RTE_SET_USED(rp);
14673
14674         switch (ret) {
14675         case 0:
14676                 ports[port_id].dev_conf.txmode.offloads |=
14677                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14678                 cmd_reconfig_device_queue(port_id, 1, 1);
14679                 break;
14680         case -ENODEV:
14681                 printf("invalid port_id %d\n", port_id);
14682                 break;
14683         case -ENOTSUP:
14684                 printf("not supported on port %d\n", port_id);
14685                 break;
14686         default:
14687                 printf("programming error: (%s)\n", strerror(-ret));
14688         }
14689 }
14690
14691 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14692         .f = cmd_set_macsec_offload_on_parsed,
14693         .data = NULL,
14694         .help_str = "set macsec offload <port_id> on "
14695                 "encrypt on|off replay-protect on|off",
14696         .tokens = {
14697                 (void *)&cmd_macsec_offload_on_set,
14698                 (void *)&cmd_macsec_offload_on_macsec,
14699                 (void *)&cmd_macsec_offload_on_offload,
14700                 (void *)&cmd_macsec_offload_on_port_id,
14701                 (void *)&cmd_macsec_offload_on_on,
14702                 (void *)&cmd_macsec_offload_on_encrypt,
14703                 (void *)&cmd_macsec_offload_on_en_on_off,
14704                 (void *)&cmd_macsec_offload_on_replay_protect,
14705                 (void *)&cmd_macsec_offload_on_rp_on_off,
14706                 NULL,
14707         },
14708 };
14709
14710 /* Common result structure for MACsec offload disable */
14711 struct cmd_macsec_offload_off_result {
14712         cmdline_fixed_string_t set;
14713         cmdline_fixed_string_t macsec;
14714         cmdline_fixed_string_t offload;
14715         portid_t port_id;
14716         cmdline_fixed_string_t off;
14717 };
14718
14719 /* Common CLI fields for MACsec offload disable */
14720 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14721         TOKEN_STRING_INITIALIZER
14722                 (struct cmd_macsec_offload_off_result,
14723                  set, "set");
14724 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14725         TOKEN_STRING_INITIALIZER
14726                 (struct cmd_macsec_offload_off_result,
14727                  macsec, "macsec");
14728 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14729         TOKEN_STRING_INITIALIZER
14730                 (struct cmd_macsec_offload_off_result,
14731                  offload, "offload");
14732 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14733         TOKEN_NUM_INITIALIZER
14734                 (struct cmd_macsec_offload_off_result,
14735                  port_id, UINT16);
14736 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14737         TOKEN_STRING_INITIALIZER
14738                 (struct cmd_macsec_offload_off_result,
14739                  off, "off");
14740
14741 static void
14742 cmd_set_macsec_offload_off_parsed(
14743         void *parsed_result,
14744         __rte_unused struct cmdline *cl,
14745         __rte_unused void *data)
14746 {
14747         struct cmd_macsec_offload_off_result *res = parsed_result;
14748         int ret = -ENOTSUP;
14749         struct rte_eth_dev_info dev_info;
14750         portid_t port_id = res->port_id;
14751
14752         if (port_id_is_invalid(port_id, ENABLED_WARN))
14753                 return;
14754         if (!port_is_stopped(port_id)) {
14755                 printf("Please stop port %d first\n", port_id);
14756                 return;
14757         }
14758
14759         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14760         if (ret != 0)
14761                 return;
14762
14763         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14764 #ifdef RTE_NET_IXGBE
14765                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14766 #endif
14767         }
14768         switch (ret) {
14769         case 0:
14770                 ports[port_id].dev_conf.txmode.offloads &=
14771                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14772                 cmd_reconfig_device_queue(port_id, 1, 1);
14773                 break;
14774         case -ENODEV:
14775                 printf("invalid port_id %d\n", port_id);
14776                 break;
14777         case -ENOTSUP:
14778                 printf("not supported on port %d\n", port_id);
14779                 break;
14780         default:
14781                 printf("programming error: (%s)\n", strerror(-ret));
14782         }
14783 }
14784
14785 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14786         .f = cmd_set_macsec_offload_off_parsed,
14787         .data = NULL,
14788         .help_str = "set macsec offload <port_id> off",
14789         .tokens = {
14790                 (void *)&cmd_macsec_offload_off_set,
14791                 (void *)&cmd_macsec_offload_off_macsec,
14792                 (void *)&cmd_macsec_offload_off_offload,
14793                 (void *)&cmd_macsec_offload_off_port_id,
14794                 (void *)&cmd_macsec_offload_off_off,
14795                 NULL,
14796         },
14797 };
14798
14799 /* Common result structure for MACsec secure connection configure */
14800 struct cmd_macsec_sc_result {
14801         cmdline_fixed_string_t set;
14802         cmdline_fixed_string_t macsec;
14803         cmdline_fixed_string_t sc;
14804         cmdline_fixed_string_t tx_rx;
14805         portid_t port_id;
14806         struct rte_ether_addr mac;
14807         uint16_t pi;
14808 };
14809
14810 /* Common CLI fields for MACsec secure connection configure */
14811 cmdline_parse_token_string_t cmd_macsec_sc_set =
14812         TOKEN_STRING_INITIALIZER
14813                 (struct cmd_macsec_sc_result,
14814                  set, "set");
14815 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14816         TOKEN_STRING_INITIALIZER
14817                 (struct cmd_macsec_sc_result,
14818                  macsec, "macsec");
14819 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14820         TOKEN_STRING_INITIALIZER
14821                 (struct cmd_macsec_sc_result,
14822                  sc, "sc");
14823 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14824         TOKEN_STRING_INITIALIZER
14825                 (struct cmd_macsec_sc_result,
14826                  tx_rx, "tx#rx");
14827 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14828         TOKEN_NUM_INITIALIZER
14829                 (struct cmd_macsec_sc_result,
14830                  port_id, UINT16);
14831 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14832         TOKEN_ETHERADDR_INITIALIZER
14833                 (struct cmd_macsec_sc_result,
14834                  mac);
14835 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14836         TOKEN_NUM_INITIALIZER
14837                 (struct cmd_macsec_sc_result,
14838                  pi, UINT16);
14839
14840 static void
14841 cmd_set_macsec_sc_parsed(
14842         void *parsed_result,
14843         __rte_unused struct cmdline *cl,
14844         __rte_unused void *data)
14845 {
14846         struct cmd_macsec_sc_result *res = parsed_result;
14847         int ret = -ENOTSUP;
14848         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14849
14850 #ifdef RTE_NET_IXGBE
14851         ret = is_tx ?
14852                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14853                                 res->mac.addr_bytes) :
14854                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14855                                 res->mac.addr_bytes, res->pi);
14856 #endif
14857         RTE_SET_USED(is_tx);
14858
14859         switch (ret) {
14860         case 0:
14861                 break;
14862         case -ENODEV:
14863                 printf("invalid port_id %d\n", res->port_id);
14864                 break;
14865         case -ENOTSUP:
14866                 printf("not supported on port %d\n", res->port_id);
14867                 break;
14868         default:
14869                 printf("programming error: (%s)\n", strerror(-ret));
14870         }
14871 }
14872
14873 cmdline_parse_inst_t cmd_set_macsec_sc = {
14874         .f = cmd_set_macsec_sc_parsed,
14875         .data = NULL,
14876         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14877         .tokens = {
14878                 (void *)&cmd_macsec_sc_set,
14879                 (void *)&cmd_macsec_sc_macsec,
14880                 (void *)&cmd_macsec_sc_sc,
14881                 (void *)&cmd_macsec_sc_tx_rx,
14882                 (void *)&cmd_macsec_sc_port_id,
14883                 (void *)&cmd_macsec_sc_mac,
14884                 (void *)&cmd_macsec_sc_pi,
14885                 NULL,
14886         },
14887 };
14888
14889 /* Common result structure for MACsec secure connection configure */
14890 struct cmd_macsec_sa_result {
14891         cmdline_fixed_string_t set;
14892         cmdline_fixed_string_t macsec;
14893         cmdline_fixed_string_t sa;
14894         cmdline_fixed_string_t tx_rx;
14895         portid_t port_id;
14896         uint8_t idx;
14897         uint8_t an;
14898         uint32_t pn;
14899         cmdline_fixed_string_t key;
14900 };
14901
14902 /* Common CLI fields for MACsec secure connection configure */
14903 cmdline_parse_token_string_t cmd_macsec_sa_set =
14904         TOKEN_STRING_INITIALIZER
14905                 (struct cmd_macsec_sa_result,
14906                  set, "set");
14907 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14908         TOKEN_STRING_INITIALIZER
14909                 (struct cmd_macsec_sa_result,
14910                  macsec, "macsec");
14911 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14912         TOKEN_STRING_INITIALIZER
14913                 (struct cmd_macsec_sa_result,
14914                  sa, "sa");
14915 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14916         TOKEN_STRING_INITIALIZER
14917                 (struct cmd_macsec_sa_result,
14918                  tx_rx, "tx#rx");
14919 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14920         TOKEN_NUM_INITIALIZER
14921                 (struct cmd_macsec_sa_result,
14922                  port_id, UINT16);
14923 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14924         TOKEN_NUM_INITIALIZER
14925                 (struct cmd_macsec_sa_result,
14926                  idx, UINT8);
14927 cmdline_parse_token_num_t cmd_macsec_sa_an =
14928         TOKEN_NUM_INITIALIZER
14929                 (struct cmd_macsec_sa_result,
14930                  an, UINT8);
14931 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14932         TOKEN_NUM_INITIALIZER
14933                 (struct cmd_macsec_sa_result,
14934                  pn, UINT32);
14935 cmdline_parse_token_string_t cmd_macsec_sa_key =
14936         TOKEN_STRING_INITIALIZER
14937                 (struct cmd_macsec_sa_result,
14938                  key, NULL);
14939
14940 static void
14941 cmd_set_macsec_sa_parsed(
14942         void *parsed_result,
14943         __rte_unused struct cmdline *cl,
14944         __rte_unused void *data)
14945 {
14946         struct cmd_macsec_sa_result *res = parsed_result;
14947         int ret = -ENOTSUP;
14948         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14949         uint8_t key[16] = { 0 };
14950         uint8_t xdgt0;
14951         uint8_t xdgt1;
14952         int key_len;
14953         int i;
14954
14955         key_len = strlen(res->key) / 2;
14956         if (key_len > 16)
14957                 key_len = 16;
14958
14959         for (i = 0; i < key_len; i++) {
14960                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14961                 if (xdgt0 == 0xFF)
14962                         return;
14963                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14964                 if (xdgt1 == 0xFF)
14965                         return;
14966                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14967         }
14968
14969 #ifdef RTE_NET_IXGBE
14970         ret = is_tx ?
14971                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14972                         res->idx, res->an, res->pn, key) :
14973                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14974                         res->idx, res->an, res->pn, key);
14975 #endif
14976         RTE_SET_USED(is_tx);
14977         RTE_SET_USED(key);
14978
14979         switch (ret) {
14980         case 0:
14981                 break;
14982         case -EINVAL:
14983                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14984                 break;
14985         case -ENODEV:
14986                 printf("invalid port_id %d\n", res->port_id);
14987                 break;
14988         case -ENOTSUP:
14989                 printf("not supported on port %d\n", res->port_id);
14990                 break;
14991         default:
14992                 printf("programming error: (%s)\n", strerror(-ret));
14993         }
14994 }
14995
14996 cmdline_parse_inst_t cmd_set_macsec_sa = {
14997         .f = cmd_set_macsec_sa_parsed,
14998         .data = NULL,
14999         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
15000         .tokens = {
15001                 (void *)&cmd_macsec_sa_set,
15002                 (void *)&cmd_macsec_sa_macsec,
15003                 (void *)&cmd_macsec_sa_sa,
15004                 (void *)&cmd_macsec_sa_tx_rx,
15005                 (void *)&cmd_macsec_sa_port_id,
15006                 (void *)&cmd_macsec_sa_idx,
15007                 (void *)&cmd_macsec_sa_an,
15008                 (void *)&cmd_macsec_sa_pn,
15009                 (void *)&cmd_macsec_sa_key,
15010                 NULL,
15011         },
15012 };
15013
15014 /* VF unicast promiscuous mode configuration */
15015
15016 /* Common result structure for VF unicast promiscuous mode */
15017 struct cmd_vf_promisc_result {
15018         cmdline_fixed_string_t set;
15019         cmdline_fixed_string_t vf;
15020         cmdline_fixed_string_t promisc;
15021         portid_t port_id;
15022         uint32_t vf_id;
15023         cmdline_fixed_string_t on_off;
15024 };
15025
15026 /* Common CLI fields for VF unicast promiscuous mode enable disable */
15027 cmdline_parse_token_string_t cmd_vf_promisc_set =
15028         TOKEN_STRING_INITIALIZER
15029                 (struct cmd_vf_promisc_result,
15030                  set, "set");
15031 cmdline_parse_token_string_t cmd_vf_promisc_vf =
15032         TOKEN_STRING_INITIALIZER
15033                 (struct cmd_vf_promisc_result,
15034                  vf, "vf");
15035 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
15036         TOKEN_STRING_INITIALIZER
15037                 (struct cmd_vf_promisc_result,
15038                  promisc, "promisc");
15039 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
15040         TOKEN_NUM_INITIALIZER
15041                 (struct cmd_vf_promisc_result,
15042                  port_id, UINT16);
15043 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
15044         TOKEN_NUM_INITIALIZER
15045                 (struct cmd_vf_promisc_result,
15046                  vf_id, UINT32);
15047 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
15048         TOKEN_STRING_INITIALIZER
15049                 (struct cmd_vf_promisc_result,
15050                  on_off, "on#off");
15051
15052 static void
15053 cmd_set_vf_promisc_parsed(
15054         void *parsed_result,
15055         __rte_unused struct cmdline *cl,
15056         __rte_unused void *data)
15057 {
15058         struct cmd_vf_promisc_result *res = parsed_result;
15059         int ret = -ENOTSUP;
15060
15061         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15062
15063         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15064                 return;
15065
15066 #ifdef RTE_NET_I40E
15067         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
15068                                                   res->vf_id, is_on);
15069 #endif
15070
15071         switch (ret) {
15072         case 0:
15073                 break;
15074         case -EINVAL:
15075                 printf("invalid vf_id %d\n", res->vf_id);
15076                 break;
15077         case -ENODEV:
15078                 printf("invalid port_id %d\n", res->port_id);
15079                 break;
15080         case -ENOTSUP:
15081                 printf("function not implemented\n");
15082                 break;
15083         default:
15084                 printf("programming error: (%s)\n", strerror(-ret));
15085         }
15086 }
15087
15088 cmdline_parse_inst_t cmd_set_vf_promisc = {
15089         .f = cmd_set_vf_promisc_parsed,
15090         .data = NULL,
15091         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
15092                 "Set unicast promiscuous mode for a VF from the PF",
15093         .tokens = {
15094                 (void *)&cmd_vf_promisc_set,
15095                 (void *)&cmd_vf_promisc_vf,
15096                 (void *)&cmd_vf_promisc_promisc,
15097                 (void *)&cmd_vf_promisc_port_id,
15098                 (void *)&cmd_vf_promisc_vf_id,
15099                 (void *)&cmd_vf_promisc_on_off,
15100                 NULL,
15101         },
15102 };
15103
15104 /* VF multicast promiscuous mode configuration */
15105
15106 /* Common result structure for VF multicast promiscuous mode */
15107 struct cmd_vf_allmulti_result {
15108         cmdline_fixed_string_t set;
15109         cmdline_fixed_string_t vf;
15110         cmdline_fixed_string_t allmulti;
15111         portid_t port_id;
15112         uint32_t vf_id;
15113         cmdline_fixed_string_t on_off;
15114 };
15115
15116 /* Common CLI fields for VF multicast promiscuous mode enable disable */
15117 cmdline_parse_token_string_t cmd_vf_allmulti_set =
15118         TOKEN_STRING_INITIALIZER
15119                 (struct cmd_vf_allmulti_result,
15120                  set, "set");
15121 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
15122         TOKEN_STRING_INITIALIZER
15123                 (struct cmd_vf_allmulti_result,
15124                  vf, "vf");
15125 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
15126         TOKEN_STRING_INITIALIZER
15127                 (struct cmd_vf_allmulti_result,
15128                  allmulti, "allmulti");
15129 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
15130         TOKEN_NUM_INITIALIZER
15131                 (struct cmd_vf_allmulti_result,
15132                  port_id, UINT16);
15133 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
15134         TOKEN_NUM_INITIALIZER
15135                 (struct cmd_vf_allmulti_result,
15136                  vf_id, UINT32);
15137 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15138         TOKEN_STRING_INITIALIZER
15139                 (struct cmd_vf_allmulti_result,
15140                  on_off, "on#off");
15141
15142 static void
15143 cmd_set_vf_allmulti_parsed(
15144         void *parsed_result,
15145         __rte_unused struct cmdline *cl,
15146         __rte_unused void *data)
15147 {
15148         struct cmd_vf_allmulti_result *res = parsed_result;
15149         int ret = -ENOTSUP;
15150
15151         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15152
15153         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15154                 return;
15155
15156 #ifdef RTE_NET_I40E
15157         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15158                                                     res->vf_id, is_on);
15159 #endif
15160
15161         switch (ret) {
15162         case 0:
15163                 break;
15164         case -EINVAL:
15165                 printf("invalid vf_id %d\n", res->vf_id);
15166                 break;
15167         case -ENODEV:
15168                 printf("invalid port_id %d\n", res->port_id);
15169                 break;
15170         case -ENOTSUP:
15171                 printf("function not implemented\n");
15172                 break;
15173         default:
15174                 printf("programming error: (%s)\n", strerror(-ret));
15175         }
15176 }
15177
15178 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15179         .f = cmd_set_vf_allmulti_parsed,
15180         .data = NULL,
15181         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15182                 "Set multicast promiscuous mode for a VF from the PF",
15183         .tokens = {
15184                 (void *)&cmd_vf_allmulti_set,
15185                 (void *)&cmd_vf_allmulti_vf,
15186                 (void *)&cmd_vf_allmulti_allmulti,
15187                 (void *)&cmd_vf_allmulti_port_id,
15188                 (void *)&cmd_vf_allmulti_vf_id,
15189                 (void *)&cmd_vf_allmulti_on_off,
15190                 NULL,
15191         },
15192 };
15193
15194 /* vf broadcast mode configuration */
15195
15196 /* Common result structure for vf broadcast */
15197 struct cmd_set_vf_broadcast_result {
15198         cmdline_fixed_string_t set;
15199         cmdline_fixed_string_t vf;
15200         cmdline_fixed_string_t broadcast;
15201         portid_t port_id;
15202         uint16_t vf_id;
15203         cmdline_fixed_string_t on_off;
15204 };
15205
15206 /* Common CLI fields for vf broadcast enable disable */
15207 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15208         TOKEN_STRING_INITIALIZER
15209                 (struct cmd_set_vf_broadcast_result,
15210                  set, "set");
15211 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15212         TOKEN_STRING_INITIALIZER
15213                 (struct cmd_set_vf_broadcast_result,
15214                  vf, "vf");
15215 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15216         TOKEN_STRING_INITIALIZER
15217                 (struct cmd_set_vf_broadcast_result,
15218                  broadcast, "broadcast");
15219 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15220         TOKEN_NUM_INITIALIZER
15221                 (struct cmd_set_vf_broadcast_result,
15222                  port_id, UINT16);
15223 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15224         TOKEN_NUM_INITIALIZER
15225                 (struct cmd_set_vf_broadcast_result,
15226                  vf_id, UINT16);
15227 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15228         TOKEN_STRING_INITIALIZER
15229                 (struct cmd_set_vf_broadcast_result,
15230                  on_off, "on#off");
15231
15232 static void
15233 cmd_set_vf_broadcast_parsed(
15234         void *parsed_result,
15235         __rte_unused struct cmdline *cl,
15236         __rte_unused void *data)
15237 {
15238         struct cmd_set_vf_broadcast_result *res = parsed_result;
15239         int ret = -ENOTSUP;
15240
15241         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15242
15243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15244                 return;
15245
15246 #ifdef RTE_NET_I40E
15247         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15248                                             res->vf_id, is_on);
15249 #endif
15250
15251         switch (ret) {
15252         case 0:
15253                 break;
15254         case -EINVAL:
15255                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15256                 break;
15257         case -ENODEV:
15258                 printf("invalid port_id %d\n", res->port_id);
15259                 break;
15260         case -ENOTSUP:
15261                 printf("function not implemented\n");
15262                 break;
15263         default:
15264                 printf("programming error: (%s)\n", strerror(-ret));
15265         }
15266 }
15267
15268 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15269         .f = cmd_set_vf_broadcast_parsed,
15270         .data = NULL,
15271         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15272         .tokens = {
15273                 (void *)&cmd_set_vf_broadcast_set,
15274                 (void *)&cmd_set_vf_broadcast_vf,
15275                 (void *)&cmd_set_vf_broadcast_broadcast,
15276                 (void *)&cmd_set_vf_broadcast_port_id,
15277                 (void *)&cmd_set_vf_broadcast_vf_id,
15278                 (void *)&cmd_set_vf_broadcast_on_off,
15279                 NULL,
15280         },
15281 };
15282
15283 /* vf vlan tag configuration */
15284
15285 /* Common result structure for vf vlan tag */
15286 struct cmd_set_vf_vlan_tag_result {
15287         cmdline_fixed_string_t set;
15288         cmdline_fixed_string_t vf;
15289         cmdline_fixed_string_t vlan;
15290         cmdline_fixed_string_t tag;
15291         portid_t port_id;
15292         uint16_t vf_id;
15293         cmdline_fixed_string_t on_off;
15294 };
15295
15296 /* Common CLI fields for vf vlan tag enable disable */
15297 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15298         TOKEN_STRING_INITIALIZER
15299                 (struct cmd_set_vf_vlan_tag_result,
15300                  set, "set");
15301 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15302         TOKEN_STRING_INITIALIZER
15303                 (struct cmd_set_vf_vlan_tag_result,
15304                  vf, "vf");
15305 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15306         TOKEN_STRING_INITIALIZER
15307                 (struct cmd_set_vf_vlan_tag_result,
15308                  vlan, "vlan");
15309 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15310         TOKEN_STRING_INITIALIZER
15311                 (struct cmd_set_vf_vlan_tag_result,
15312                  tag, "tag");
15313 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15314         TOKEN_NUM_INITIALIZER
15315                 (struct cmd_set_vf_vlan_tag_result,
15316                  port_id, UINT16);
15317 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15318         TOKEN_NUM_INITIALIZER
15319                 (struct cmd_set_vf_vlan_tag_result,
15320                  vf_id, UINT16);
15321 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15322         TOKEN_STRING_INITIALIZER
15323                 (struct cmd_set_vf_vlan_tag_result,
15324                  on_off, "on#off");
15325
15326 static void
15327 cmd_set_vf_vlan_tag_parsed(
15328         void *parsed_result,
15329         __rte_unused struct cmdline *cl,
15330         __rte_unused void *data)
15331 {
15332         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15333         int ret = -ENOTSUP;
15334
15335         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15336
15337         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15338                 return;
15339
15340 #ifdef RTE_NET_I40E
15341         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15342                                            res->vf_id, is_on);
15343 #endif
15344
15345         switch (ret) {
15346         case 0:
15347                 break;
15348         case -EINVAL:
15349                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15350                 break;
15351         case -ENODEV:
15352                 printf("invalid port_id %d\n", res->port_id);
15353                 break;
15354         case -ENOTSUP:
15355                 printf("function not implemented\n");
15356                 break;
15357         default:
15358                 printf("programming error: (%s)\n", strerror(-ret));
15359         }
15360 }
15361
15362 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15363         .f = cmd_set_vf_vlan_tag_parsed,
15364         .data = NULL,
15365         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15366         .tokens = {
15367                 (void *)&cmd_set_vf_vlan_tag_set,
15368                 (void *)&cmd_set_vf_vlan_tag_vf,
15369                 (void *)&cmd_set_vf_vlan_tag_vlan,
15370                 (void *)&cmd_set_vf_vlan_tag_tag,
15371                 (void *)&cmd_set_vf_vlan_tag_port_id,
15372                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15373                 (void *)&cmd_set_vf_vlan_tag_on_off,
15374                 NULL,
15375         },
15376 };
15377
15378 /* Common definition of VF and TC TX bandwidth configuration */
15379 struct cmd_vf_tc_bw_result {
15380         cmdline_fixed_string_t set;
15381         cmdline_fixed_string_t vf;
15382         cmdline_fixed_string_t tc;
15383         cmdline_fixed_string_t tx;
15384         cmdline_fixed_string_t min_bw;
15385         cmdline_fixed_string_t max_bw;
15386         cmdline_fixed_string_t strict_link_prio;
15387         portid_t port_id;
15388         uint16_t vf_id;
15389         uint8_t tc_no;
15390         uint32_t bw;
15391         cmdline_fixed_string_t bw_list;
15392         uint8_t tc_map;
15393 };
15394
15395 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15396         TOKEN_STRING_INITIALIZER
15397                 (struct cmd_vf_tc_bw_result,
15398                  set, "set");
15399 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15400         TOKEN_STRING_INITIALIZER
15401                 (struct cmd_vf_tc_bw_result,
15402                  vf, "vf");
15403 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15404         TOKEN_STRING_INITIALIZER
15405                 (struct cmd_vf_tc_bw_result,
15406                  tc, "tc");
15407 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15408         TOKEN_STRING_INITIALIZER
15409                 (struct cmd_vf_tc_bw_result,
15410                  tx, "tx");
15411 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15412         TOKEN_STRING_INITIALIZER
15413                 (struct cmd_vf_tc_bw_result,
15414                  strict_link_prio, "strict-link-priority");
15415 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15416         TOKEN_STRING_INITIALIZER
15417                 (struct cmd_vf_tc_bw_result,
15418                  min_bw, "min-bandwidth");
15419 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15420         TOKEN_STRING_INITIALIZER
15421                 (struct cmd_vf_tc_bw_result,
15422                  max_bw, "max-bandwidth");
15423 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15424         TOKEN_NUM_INITIALIZER
15425                 (struct cmd_vf_tc_bw_result,
15426                  port_id, UINT16);
15427 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15428         TOKEN_NUM_INITIALIZER
15429                 (struct cmd_vf_tc_bw_result,
15430                  vf_id, UINT16);
15431 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15432         TOKEN_NUM_INITIALIZER
15433                 (struct cmd_vf_tc_bw_result,
15434                  tc_no, UINT8);
15435 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15436         TOKEN_NUM_INITIALIZER
15437                 (struct cmd_vf_tc_bw_result,
15438                  bw, UINT32);
15439 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15440         TOKEN_STRING_INITIALIZER
15441                 (struct cmd_vf_tc_bw_result,
15442                  bw_list, NULL);
15443 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15444         TOKEN_NUM_INITIALIZER
15445                 (struct cmd_vf_tc_bw_result,
15446                  tc_map, UINT8);
15447
15448 /* VF max bandwidth setting */
15449 static void
15450 cmd_vf_max_bw_parsed(
15451         void *parsed_result,
15452         __rte_unused struct cmdline *cl,
15453         __rte_unused void *data)
15454 {
15455         struct cmd_vf_tc_bw_result *res = parsed_result;
15456         int ret = -ENOTSUP;
15457
15458         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15459                 return;
15460
15461 #ifdef RTE_NET_I40E
15462         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15463                                          res->vf_id, res->bw);
15464 #endif
15465
15466         switch (ret) {
15467         case 0:
15468                 break;
15469         case -EINVAL:
15470                 printf("invalid vf_id %d or bandwidth %d\n",
15471                        res->vf_id, res->bw);
15472                 break;
15473         case -ENODEV:
15474                 printf("invalid port_id %d\n", res->port_id);
15475                 break;
15476         case -ENOTSUP:
15477                 printf("function not implemented\n");
15478                 break;
15479         default:
15480                 printf("programming error: (%s)\n", strerror(-ret));
15481         }
15482 }
15483
15484 cmdline_parse_inst_t cmd_vf_max_bw = {
15485         .f = cmd_vf_max_bw_parsed,
15486         .data = NULL,
15487         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15488         .tokens = {
15489                 (void *)&cmd_vf_tc_bw_set,
15490                 (void *)&cmd_vf_tc_bw_vf,
15491                 (void *)&cmd_vf_tc_bw_tx,
15492                 (void *)&cmd_vf_tc_bw_max_bw,
15493                 (void *)&cmd_vf_tc_bw_port_id,
15494                 (void *)&cmd_vf_tc_bw_vf_id,
15495                 (void *)&cmd_vf_tc_bw_bw,
15496                 NULL,
15497         },
15498 };
15499
15500 static int
15501 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15502                            uint8_t *tc_num,
15503                            char *str)
15504 {
15505         uint32_t size;
15506         const char *p, *p0 = str;
15507         char s[256];
15508         char *end;
15509         char *str_fld[16];
15510         uint16_t i;
15511         int ret;
15512
15513         p = strchr(p0, '(');
15514         if (p == NULL) {
15515                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15516                 return -1;
15517         }
15518         p++;
15519         p0 = strchr(p, ')');
15520         if (p0 == NULL) {
15521                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15522                 return -1;
15523         }
15524         size = p0 - p;
15525         if (size >= sizeof(s)) {
15526                 printf("The string size exceeds the internal buffer size\n");
15527                 return -1;
15528         }
15529         snprintf(s, sizeof(s), "%.*s", size, p);
15530         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15531         if (ret <= 0) {
15532                 printf("Failed to get the bandwidth list. ");
15533                 return -1;
15534         }
15535         *tc_num = ret;
15536         for (i = 0; i < ret; i++)
15537                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15538
15539         return 0;
15540 }
15541
15542 /* TC min bandwidth setting */
15543 static void
15544 cmd_vf_tc_min_bw_parsed(
15545         void *parsed_result,
15546         __rte_unused struct cmdline *cl,
15547         __rte_unused void *data)
15548 {
15549         struct cmd_vf_tc_bw_result *res = parsed_result;
15550         uint8_t tc_num;
15551         uint8_t bw[16];
15552         int ret = -ENOTSUP;
15553
15554         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15555                 return;
15556
15557         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15558         if (ret)
15559                 return;
15560
15561 #ifdef RTE_NET_I40E
15562         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15563                                               tc_num, bw);
15564 #endif
15565
15566         switch (ret) {
15567         case 0:
15568                 break;
15569         case -EINVAL:
15570                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15571                 break;
15572         case -ENODEV:
15573                 printf("invalid port_id %d\n", res->port_id);
15574                 break;
15575         case -ENOTSUP:
15576                 printf("function not implemented\n");
15577                 break;
15578         default:
15579                 printf("programming error: (%s)\n", strerror(-ret));
15580         }
15581 }
15582
15583 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15584         .f = cmd_vf_tc_min_bw_parsed,
15585         .data = NULL,
15586         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15587                     " <bw1, bw2, ...>",
15588         .tokens = {
15589                 (void *)&cmd_vf_tc_bw_set,
15590                 (void *)&cmd_vf_tc_bw_vf,
15591                 (void *)&cmd_vf_tc_bw_tc,
15592                 (void *)&cmd_vf_tc_bw_tx,
15593                 (void *)&cmd_vf_tc_bw_min_bw,
15594                 (void *)&cmd_vf_tc_bw_port_id,
15595                 (void *)&cmd_vf_tc_bw_vf_id,
15596                 (void *)&cmd_vf_tc_bw_bw_list,
15597                 NULL,
15598         },
15599 };
15600
15601 static void
15602 cmd_tc_min_bw_parsed(
15603         void *parsed_result,
15604         __rte_unused struct cmdline *cl,
15605         __rte_unused void *data)
15606 {
15607         struct cmd_vf_tc_bw_result *res = parsed_result;
15608         struct rte_port *port;
15609         uint8_t tc_num;
15610         uint8_t bw[16];
15611         int ret = -ENOTSUP;
15612
15613         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15614                 return;
15615
15616         port = &ports[res->port_id];
15617         /** Check if the port is not started **/
15618         if (port->port_status != RTE_PORT_STOPPED) {
15619                 printf("Please stop port %d first\n", res->port_id);
15620                 return;
15621         }
15622
15623         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15624         if (ret)
15625                 return;
15626
15627 #ifdef RTE_NET_IXGBE
15628         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15629 #endif
15630
15631         switch (ret) {
15632         case 0:
15633                 break;
15634         case -EINVAL:
15635                 printf("invalid bandwidth\n");
15636                 break;
15637         case -ENODEV:
15638                 printf("invalid port_id %d\n", res->port_id);
15639                 break;
15640         case -ENOTSUP:
15641                 printf("function not implemented\n");
15642                 break;
15643         default:
15644                 printf("programming error: (%s)\n", strerror(-ret));
15645         }
15646 }
15647
15648 cmdline_parse_inst_t cmd_tc_min_bw = {
15649         .f = cmd_tc_min_bw_parsed,
15650         .data = NULL,
15651         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15652         .tokens = {
15653                 (void *)&cmd_vf_tc_bw_set,
15654                 (void *)&cmd_vf_tc_bw_tc,
15655                 (void *)&cmd_vf_tc_bw_tx,
15656                 (void *)&cmd_vf_tc_bw_min_bw,
15657                 (void *)&cmd_vf_tc_bw_port_id,
15658                 (void *)&cmd_vf_tc_bw_bw_list,
15659                 NULL,
15660         },
15661 };
15662
15663 /* TC max bandwidth setting */
15664 static void
15665 cmd_vf_tc_max_bw_parsed(
15666         void *parsed_result,
15667         __rte_unused struct cmdline *cl,
15668         __rte_unused void *data)
15669 {
15670         struct cmd_vf_tc_bw_result *res = parsed_result;
15671         int ret = -ENOTSUP;
15672
15673         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15674                 return;
15675
15676 #ifdef RTE_NET_I40E
15677         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15678                                             res->tc_no, res->bw);
15679 #endif
15680
15681         switch (ret) {
15682         case 0:
15683                 break;
15684         case -EINVAL:
15685                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15686                        res->vf_id, res->tc_no, res->bw);
15687                 break;
15688         case -ENODEV:
15689                 printf("invalid port_id %d\n", res->port_id);
15690                 break;
15691         case -ENOTSUP:
15692                 printf("function not implemented\n");
15693                 break;
15694         default:
15695                 printf("programming error: (%s)\n", strerror(-ret));
15696         }
15697 }
15698
15699 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15700         .f = cmd_vf_tc_max_bw_parsed,
15701         .data = NULL,
15702         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15703                     " <bandwidth>",
15704         .tokens = {
15705                 (void *)&cmd_vf_tc_bw_set,
15706                 (void *)&cmd_vf_tc_bw_vf,
15707                 (void *)&cmd_vf_tc_bw_tc,
15708                 (void *)&cmd_vf_tc_bw_tx,
15709                 (void *)&cmd_vf_tc_bw_max_bw,
15710                 (void *)&cmd_vf_tc_bw_port_id,
15711                 (void *)&cmd_vf_tc_bw_vf_id,
15712                 (void *)&cmd_vf_tc_bw_tc_no,
15713                 (void *)&cmd_vf_tc_bw_bw,
15714                 NULL,
15715         },
15716 };
15717
15718 /** Set VXLAN encapsulation details */
15719 struct cmd_set_vxlan_result {
15720         cmdline_fixed_string_t set;
15721         cmdline_fixed_string_t vxlan;
15722         cmdline_fixed_string_t pos_token;
15723         cmdline_fixed_string_t ip_version;
15724         uint32_t vlan_present:1;
15725         uint32_t vni;
15726         uint16_t udp_src;
15727         uint16_t udp_dst;
15728         cmdline_ipaddr_t ip_src;
15729         cmdline_ipaddr_t ip_dst;
15730         uint16_t tci;
15731         uint8_t tos;
15732         uint8_t ttl;
15733         struct rte_ether_addr eth_src;
15734         struct rte_ether_addr eth_dst;
15735 };
15736
15737 cmdline_parse_token_string_t cmd_set_vxlan_set =
15738         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15739 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15741 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15742         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15743                                  "vxlan-tos-ttl");
15744 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15746                                  "vxlan-with-vlan");
15747 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15748         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15749                                  "ip-version");
15750 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15751         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15752                                  "ipv4#ipv6");
15753 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15754         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15755                                  "vni");
15756 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15757         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15758 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15759         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15760                                  "udp-src");
15761 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15762         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15763 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15764         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15765                                  "udp-dst");
15766 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15767         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15768 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15769         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15770                                  "ip-tos");
15771 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15772         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15773 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15774         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15775                                  "ip-ttl");
15776 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15777         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15778 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15779         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15780                                  "ip-src");
15781 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15782         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15783 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15784         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15785                                  "ip-dst");
15786 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15787         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15788 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15789         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15790                                  "vlan-tci");
15791 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15792         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15793 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15794         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15795                                  "eth-src");
15796 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15797         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15798 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15799         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15800                                  "eth-dst");
15801 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15802         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15803
15804 static void cmd_set_vxlan_parsed(void *parsed_result,
15805         __rte_unused struct cmdline *cl,
15806         __rte_unused void *data)
15807 {
15808         struct cmd_set_vxlan_result *res = parsed_result;
15809         union {
15810                 uint32_t vxlan_id;
15811                 uint8_t vni[4];
15812         } id = {
15813                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15814         };
15815
15816         vxlan_encap_conf.select_tos_ttl = 0;
15817         if (strcmp(res->vxlan, "vxlan") == 0)
15818                 vxlan_encap_conf.select_vlan = 0;
15819         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15820                 vxlan_encap_conf.select_vlan = 1;
15821         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15822                 vxlan_encap_conf.select_vlan = 0;
15823                 vxlan_encap_conf.select_tos_ttl = 1;
15824         }
15825         if (strcmp(res->ip_version, "ipv4") == 0)
15826                 vxlan_encap_conf.select_ipv4 = 1;
15827         else if (strcmp(res->ip_version, "ipv6") == 0)
15828                 vxlan_encap_conf.select_ipv4 = 0;
15829         else
15830                 return;
15831         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15832         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15833         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15834         vxlan_encap_conf.ip_tos = res->tos;
15835         vxlan_encap_conf.ip_ttl = res->ttl;
15836         if (vxlan_encap_conf.select_ipv4) {
15837                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15838                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15839         } else {
15840                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15841                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15842         }
15843         if (vxlan_encap_conf.select_vlan)
15844                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15845         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15846                    RTE_ETHER_ADDR_LEN);
15847         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15848                    RTE_ETHER_ADDR_LEN);
15849 }
15850
15851 cmdline_parse_inst_t cmd_set_vxlan = {
15852         .f = cmd_set_vxlan_parsed,
15853         .data = NULL,
15854         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15855                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15856                 " eth-src <eth-src> eth-dst <eth-dst>",
15857         .tokens = {
15858                 (void *)&cmd_set_vxlan_set,
15859                 (void *)&cmd_set_vxlan_vxlan,
15860                 (void *)&cmd_set_vxlan_ip_version,
15861                 (void *)&cmd_set_vxlan_ip_version_value,
15862                 (void *)&cmd_set_vxlan_vni,
15863                 (void *)&cmd_set_vxlan_vni_value,
15864                 (void *)&cmd_set_vxlan_udp_src,
15865                 (void *)&cmd_set_vxlan_udp_src_value,
15866                 (void *)&cmd_set_vxlan_udp_dst,
15867                 (void *)&cmd_set_vxlan_udp_dst_value,
15868                 (void *)&cmd_set_vxlan_ip_src,
15869                 (void *)&cmd_set_vxlan_ip_src_value,
15870                 (void *)&cmd_set_vxlan_ip_dst,
15871                 (void *)&cmd_set_vxlan_ip_dst_value,
15872                 (void *)&cmd_set_vxlan_eth_src,
15873                 (void *)&cmd_set_vxlan_eth_src_value,
15874                 (void *)&cmd_set_vxlan_eth_dst,
15875                 (void *)&cmd_set_vxlan_eth_dst_value,
15876                 NULL,
15877         },
15878 };
15879
15880 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15881         .f = cmd_set_vxlan_parsed,
15882         .data = NULL,
15883         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15884                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15885                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15886                 " eth-dst <eth-dst>",
15887         .tokens = {
15888                 (void *)&cmd_set_vxlan_set,
15889                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15890                 (void *)&cmd_set_vxlan_ip_version,
15891                 (void *)&cmd_set_vxlan_ip_version_value,
15892                 (void *)&cmd_set_vxlan_vni,
15893                 (void *)&cmd_set_vxlan_vni_value,
15894                 (void *)&cmd_set_vxlan_udp_src,
15895                 (void *)&cmd_set_vxlan_udp_src_value,
15896                 (void *)&cmd_set_vxlan_udp_dst,
15897                 (void *)&cmd_set_vxlan_udp_dst_value,
15898                 (void *)&cmd_set_vxlan_ip_tos,
15899                 (void *)&cmd_set_vxlan_ip_tos_value,
15900                 (void *)&cmd_set_vxlan_ip_ttl,
15901                 (void *)&cmd_set_vxlan_ip_ttl_value,
15902                 (void *)&cmd_set_vxlan_ip_src,
15903                 (void *)&cmd_set_vxlan_ip_src_value,
15904                 (void *)&cmd_set_vxlan_ip_dst,
15905                 (void *)&cmd_set_vxlan_ip_dst_value,
15906                 (void *)&cmd_set_vxlan_eth_src,
15907                 (void *)&cmd_set_vxlan_eth_src_value,
15908                 (void *)&cmd_set_vxlan_eth_dst,
15909                 (void *)&cmd_set_vxlan_eth_dst_value,
15910                 NULL,
15911         },
15912 };
15913
15914 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15915         .f = cmd_set_vxlan_parsed,
15916         .data = NULL,
15917         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15918                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15919                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15920                 " <eth-dst>",
15921         .tokens = {
15922                 (void *)&cmd_set_vxlan_set,
15923                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15924                 (void *)&cmd_set_vxlan_ip_version,
15925                 (void *)&cmd_set_vxlan_ip_version_value,
15926                 (void *)&cmd_set_vxlan_vni,
15927                 (void *)&cmd_set_vxlan_vni_value,
15928                 (void *)&cmd_set_vxlan_udp_src,
15929                 (void *)&cmd_set_vxlan_udp_src_value,
15930                 (void *)&cmd_set_vxlan_udp_dst,
15931                 (void *)&cmd_set_vxlan_udp_dst_value,
15932                 (void *)&cmd_set_vxlan_ip_src,
15933                 (void *)&cmd_set_vxlan_ip_src_value,
15934                 (void *)&cmd_set_vxlan_ip_dst,
15935                 (void *)&cmd_set_vxlan_ip_dst_value,
15936                 (void *)&cmd_set_vxlan_vlan,
15937                 (void *)&cmd_set_vxlan_vlan_value,
15938                 (void *)&cmd_set_vxlan_eth_src,
15939                 (void *)&cmd_set_vxlan_eth_src_value,
15940                 (void *)&cmd_set_vxlan_eth_dst,
15941                 (void *)&cmd_set_vxlan_eth_dst_value,
15942                 NULL,
15943         },
15944 };
15945
15946 /** Set NVGRE encapsulation details */
15947 struct cmd_set_nvgre_result {
15948         cmdline_fixed_string_t set;
15949         cmdline_fixed_string_t nvgre;
15950         cmdline_fixed_string_t pos_token;
15951         cmdline_fixed_string_t ip_version;
15952         uint32_t tni;
15953         cmdline_ipaddr_t ip_src;
15954         cmdline_ipaddr_t ip_dst;
15955         uint16_t tci;
15956         struct rte_ether_addr eth_src;
15957         struct rte_ether_addr eth_dst;
15958 };
15959
15960 cmdline_parse_token_string_t cmd_set_nvgre_set =
15961         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15962 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15963         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15964 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15965         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15966                                  "nvgre-with-vlan");
15967 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15968         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15969                                  "ip-version");
15970 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15971         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15972                                  "ipv4#ipv6");
15973 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15974         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15975                                  "tni");
15976 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15977         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15978 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15979         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15980                                  "ip-src");
15981 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15982         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15983 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15984         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15985                                  "ip-dst");
15986 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15987         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15988 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15989         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15990                                  "vlan-tci");
15991 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15992         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15993 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15994         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15995                                  "eth-src");
15996 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15997         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15998 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15999         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
16000                                  "eth-dst");
16001 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
16002         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
16003
16004 static void cmd_set_nvgre_parsed(void *parsed_result,
16005         __rte_unused struct cmdline *cl,
16006         __rte_unused void *data)
16007 {
16008         struct cmd_set_nvgre_result *res = parsed_result;
16009         union {
16010                 uint32_t nvgre_tni;
16011                 uint8_t tni[4];
16012         } id = {
16013                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
16014         };
16015
16016         if (strcmp(res->nvgre, "nvgre") == 0)
16017                 nvgre_encap_conf.select_vlan = 0;
16018         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
16019                 nvgre_encap_conf.select_vlan = 1;
16020         if (strcmp(res->ip_version, "ipv4") == 0)
16021                 nvgre_encap_conf.select_ipv4 = 1;
16022         else if (strcmp(res->ip_version, "ipv6") == 0)
16023                 nvgre_encap_conf.select_ipv4 = 0;
16024         else
16025                 return;
16026         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
16027         if (nvgre_encap_conf.select_ipv4) {
16028                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
16029                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
16030         } else {
16031                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
16032                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
16033         }
16034         if (nvgre_encap_conf.select_vlan)
16035                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16036         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
16037                    RTE_ETHER_ADDR_LEN);
16038         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16039                    RTE_ETHER_ADDR_LEN);
16040 }
16041
16042 cmdline_parse_inst_t cmd_set_nvgre = {
16043         .f = cmd_set_nvgre_parsed,
16044         .data = NULL,
16045         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
16046                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16047                 " eth-dst <eth-dst>",
16048         .tokens = {
16049                 (void *)&cmd_set_nvgre_set,
16050                 (void *)&cmd_set_nvgre_nvgre,
16051                 (void *)&cmd_set_nvgre_ip_version,
16052                 (void *)&cmd_set_nvgre_ip_version_value,
16053                 (void *)&cmd_set_nvgre_tni,
16054                 (void *)&cmd_set_nvgre_tni_value,
16055                 (void *)&cmd_set_nvgre_ip_src,
16056                 (void *)&cmd_set_nvgre_ip_src_value,
16057                 (void *)&cmd_set_nvgre_ip_dst,
16058                 (void *)&cmd_set_nvgre_ip_dst_value,
16059                 (void *)&cmd_set_nvgre_eth_src,
16060                 (void *)&cmd_set_nvgre_eth_src_value,
16061                 (void *)&cmd_set_nvgre_eth_dst,
16062                 (void *)&cmd_set_nvgre_eth_dst_value,
16063                 NULL,
16064         },
16065 };
16066
16067 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
16068         .f = cmd_set_nvgre_parsed,
16069         .data = NULL,
16070         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
16071                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16072                 " eth-src <eth-src> eth-dst <eth-dst>",
16073         .tokens = {
16074                 (void *)&cmd_set_nvgre_set,
16075                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
16076                 (void *)&cmd_set_nvgre_ip_version,
16077                 (void *)&cmd_set_nvgre_ip_version_value,
16078                 (void *)&cmd_set_nvgre_tni,
16079                 (void *)&cmd_set_nvgre_tni_value,
16080                 (void *)&cmd_set_nvgre_ip_src,
16081                 (void *)&cmd_set_nvgre_ip_src_value,
16082                 (void *)&cmd_set_nvgre_ip_dst,
16083                 (void *)&cmd_set_nvgre_ip_dst_value,
16084                 (void *)&cmd_set_nvgre_vlan,
16085                 (void *)&cmd_set_nvgre_vlan_value,
16086                 (void *)&cmd_set_nvgre_eth_src,
16087                 (void *)&cmd_set_nvgre_eth_src_value,
16088                 (void *)&cmd_set_nvgre_eth_dst,
16089                 (void *)&cmd_set_nvgre_eth_dst_value,
16090                 NULL,
16091         },
16092 };
16093
16094 /** Set L2 encapsulation details */
16095 struct cmd_set_l2_encap_result {
16096         cmdline_fixed_string_t set;
16097         cmdline_fixed_string_t l2_encap;
16098         cmdline_fixed_string_t pos_token;
16099         cmdline_fixed_string_t ip_version;
16100         uint32_t vlan_present:1;
16101         uint16_t tci;
16102         struct rte_ether_addr eth_src;
16103         struct rte_ether_addr eth_dst;
16104 };
16105
16106 cmdline_parse_token_string_t cmd_set_l2_encap_set =
16107         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
16108 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
16109         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
16110 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
16111         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
16112                                  "l2_encap-with-vlan");
16113 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
16114         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16115                                  "ip-version");
16116 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
16117         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
16118                                  "ipv4#ipv6");
16119 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
16120         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16121                                  "vlan-tci");
16122 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
16123         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
16124 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
16125         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16126                                  "eth-src");
16127 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
16128         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
16129 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
16130         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16131                                  "eth-dst");
16132 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
16133         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
16134
16135 static void cmd_set_l2_encap_parsed(void *parsed_result,
16136         __rte_unused struct cmdline *cl,
16137         __rte_unused void *data)
16138 {
16139         struct cmd_set_l2_encap_result *res = parsed_result;
16140
16141         if (strcmp(res->l2_encap, "l2_encap") == 0)
16142                 l2_encap_conf.select_vlan = 0;
16143         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16144                 l2_encap_conf.select_vlan = 1;
16145         if (strcmp(res->ip_version, "ipv4") == 0)
16146                 l2_encap_conf.select_ipv4 = 1;
16147         else if (strcmp(res->ip_version, "ipv6") == 0)
16148                 l2_encap_conf.select_ipv4 = 0;
16149         else
16150                 return;
16151         if (l2_encap_conf.select_vlan)
16152                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16153         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16154                    RTE_ETHER_ADDR_LEN);
16155         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16156                    RTE_ETHER_ADDR_LEN);
16157 }
16158
16159 cmdline_parse_inst_t cmd_set_l2_encap = {
16160         .f = cmd_set_l2_encap_parsed,
16161         .data = NULL,
16162         .help_str = "set l2_encap ip-version ipv4|ipv6"
16163                 " eth-src <eth-src> eth-dst <eth-dst>",
16164         .tokens = {
16165                 (void *)&cmd_set_l2_encap_set,
16166                 (void *)&cmd_set_l2_encap_l2_encap,
16167                 (void *)&cmd_set_l2_encap_ip_version,
16168                 (void *)&cmd_set_l2_encap_ip_version_value,
16169                 (void *)&cmd_set_l2_encap_eth_src,
16170                 (void *)&cmd_set_l2_encap_eth_src_value,
16171                 (void *)&cmd_set_l2_encap_eth_dst,
16172                 (void *)&cmd_set_l2_encap_eth_dst_value,
16173                 NULL,
16174         },
16175 };
16176
16177 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16178         .f = cmd_set_l2_encap_parsed,
16179         .data = NULL,
16180         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16181                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16182         .tokens = {
16183                 (void *)&cmd_set_l2_encap_set,
16184                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16185                 (void *)&cmd_set_l2_encap_ip_version,
16186                 (void *)&cmd_set_l2_encap_ip_version_value,
16187                 (void *)&cmd_set_l2_encap_vlan,
16188                 (void *)&cmd_set_l2_encap_vlan_value,
16189                 (void *)&cmd_set_l2_encap_eth_src,
16190                 (void *)&cmd_set_l2_encap_eth_src_value,
16191                 (void *)&cmd_set_l2_encap_eth_dst,
16192                 (void *)&cmd_set_l2_encap_eth_dst_value,
16193                 NULL,
16194         },
16195 };
16196
16197 /** Set L2 decapsulation details */
16198 struct cmd_set_l2_decap_result {
16199         cmdline_fixed_string_t set;
16200         cmdline_fixed_string_t l2_decap;
16201         cmdline_fixed_string_t pos_token;
16202         uint32_t vlan_present:1;
16203 };
16204
16205 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16206         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16207 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16208         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16209                                  "l2_decap");
16210 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16211         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16212                                  "l2_decap-with-vlan");
16213
16214 static void cmd_set_l2_decap_parsed(void *parsed_result,
16215         __rte_unused struct cmdline *cl,
16216         __rte_unused void *data)
16217 {
16218         struct cmd_set_l2_decap_result *res = parsed_result;
16219
16220         if (strcmp(res->l2_decap, "l2_decap") == 0)
16221                 l2_decap_conf.select_vlan = 0;
16222         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16223                 l2_decap_conf.select_vlan = 1;
16224 }
16225
16226 cmdline_parse_inst_t cmd_set_l2_decap = {
16227         .f = cmd_set_l2_decap_parsed,
16228         .data = NULL,
16229         .help_str = "set l2_decap",
16230         .tokens = {
16231                 (void *)&cmd_set_l2_decap_set,
16232                 (void *)&cmd_set_l2_decap_l2_decap,
16233                 NULL,
16234         },
16235 };
16236
16237 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16238         .f = cmd_set_l2_decap_parsed,
16239         .data = NULL,
16240         .help_str = "set l2_decap-with-vlan",
16241         .tokens = {
16242                 (void *)&cmd_set_l2_decap_set,
16243                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16244                 NULL,
16245         },
16246 };
16247
16248 /** Set MPLSoGRE encapsulation details */
16249 struct cmd_set_mplsogre_encap_result {
16250         cmdline_fixed_string_t set;
16251         cmdline_fixed_string_t mplsogre;
16252         cmdline_fixed_string_t pos_token;
16253         cmdline_fixed_string_t ip_version;
16254         uint32_t vlan_present:1;
16255         uint32_t label;
16256         cmdline_ipaddr_t ip_src;
16257         cmdline_ipaddr_t ip_dst;
16258         uint16_t tci;
16259         struct rte_ether_addr eth_src;
16260         struct rte_ether_addr eth_dst;
16261 };
16262
16263 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16264         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16265                                  "set");
16266 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16267         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16268                                  "mplsogre_encap");
16269 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16270         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16271                                  mplsogre, "mplsogre_encap-with-vlan");
16272 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16273         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16274                                  pos_token, "ip-version");
16275 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16276         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16277                                  ip_version, "ipv4#ipv6");
16278 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16279         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16280                                  pos_token, "label");
16281 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16282         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16283                               UINT32);
16284 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16285         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16286                                  pos_token, "ip-src");
16287 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16288         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16289 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16290         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16291                                  pos_token, "ip-dst");
16292 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16293         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16294 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16295         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16296                                  pos_token, "vlan-tci");
16297 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16298         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16299                               UINT16);
16300 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16301         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16302                                  pos_token, "eth-src");
16303 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16304         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16305                                     eth_src);
16306 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16307         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16308                                  pos_token, "eth-dst");
16309 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16310         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16311                                     eth_dst);
16312
16313 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16314         __rte_unused struct cmdline *cl,
16315         __rte_unused void *data)
16316 {
16317         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16318         union {
16319                 uint32_t mplsogre_label;
16320                 uint8_t label[4];
16321         } id = {
16322                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16323         };
16324
16325         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16326                 mplsogre_encap_conf.select_vlan = 0;
16327         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16328                 mplsogre_encap_conf.select_vlan = 1;
16329         if (strcmp(res->ip_version, "ipv4") == 0)
16330                 mplsogre_encap_conf.select_ipv4 = 1;
16331         else if (strcmp(res->ip_version, "ipv6") == 0)
16332                 mplsogre_encap_conf.select_ipv4 = 0;
16333         else
16334                 return;
16335         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16336         if (mplsogre_encap_conf.select_ipv4) {
16337                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16338                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16339         } else {
16340                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16341                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16342         }
16343         if (mplsogre_encap_conf.select_vlan)
16344                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16345         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16346                    RTE_ETHER_ADDR_LEN);
16347         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16348                    RTE_ETHER_ADDR_LEN);
16349 }
16350
16351 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16352         .f = cmd_set_mplsogre_encap_parsed,
16353         .data = NULL,
16354         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16355                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16356                 " eth-dst <eth-dst>",
16357         .tokens = {
16358                 (void *)&cmd_set_mplsogre_encap_set,
16359                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16360                 (void *)&cmd_set_mplsogre_encap_ip_version,
16361                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16362                 (void *)&cmd_set_mplsogre_encap_label,
16363                 (void *)&cmd_set_mplsogre_encap_label_value,
16364                 (void *)&cmd_set_mplsogre_encap_ip_src,
16365                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16366                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16367                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16368                 (void *)&cmd_set_mplsogre_encap_eth_src,
16369                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16370                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16371                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16372                 NULL,
16373         },
16374 };
16375
16376 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16377         .f = cmd_set_mplsogre_encap_parsed,
16378         .data = NULL,
16379         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16380                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16381                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16382         .tokens = {
16383                 (void *)&cmd_set_mplsogre_encap_set,
16384                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16385                 (void *)&cmd_set_mplsogre_encap_ip_version,
16386                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16387                 (void *)&cmd_set_mplsogre_encap_label,
16388                 (void *)&cmd_set_mplsogre_encap_label_value,
16389                 (void *)&cmd_set_mplsogre_encap_ip_src,
16390                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16391                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16392                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16393                 (void *)&cmd_set_mplsogre_encap_vlan,
16394                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16395                 (void *)&cmd_set_mplsogre_encap_eth_src,
16396                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16397                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16398                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16399                 NULL,
16400         },
16401 };
16402
16403 /** Set MPLSoGRE decapsulation details */
16404 struct cmd_set_mplsogre_decap_result {
16405         cmdline_fixed_string_t set;
16406         cmdline_fixed_string_t mplsogre;
16407         cmdline_fixed_string_t pos_token;
16408         cmdline_fixed_string_t ip_version;
16409         uint32_t vlan_present:1;
16410 };
16411
16412 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16413         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16414                                  "set");
16415 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16416         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16417                                  "mplsogre_decap");
16418 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16419         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16420                                  mplsogre, "mplsogre_decap-with-vlan");
16421 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16422         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16423                                  pos_token, "ip-version");
16424 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16425         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16426                                  ip_version, "ipv4#ipv6");
16427
16428 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16429         __rte_unused struct cmdline *cl,
16430         __rte_unused void *data)
16431 {
16432         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16433
16434         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16435                 mplsogre_decap_conf.select_vlan = 0;
16436         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16437                 mplsogre_decap_conf.select_vlan = 1;
16438         if (strcmp(res->ip_version, "ipv4") == 0)
16439                 mplsogre_decap_conf.select_ipv4 = 1;
16440         else if (strcmp(res->ip_version, "ipv6") == 0)
16441                 mplsogre_decap_conf.select_ipv4 = 0;
16442 }
16443
16444 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16445         .f = cmd_set_mplsogre_decap_parsed,
16446         .data = NULL,
16447         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16448         .tokens = {
16449                 (void *)&cmd_set_mplsogre_decap_set,
16450                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16451                 (void *)&cmd_set_mplsogre_decap_ip_version,
16452                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16453                 NULL,
16454         },
16455 };
16456
16457 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16458         .f = cmd_set_mplsogre_decap_parsed,
16459         .data = NULL,
16460         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16461         .tokens = {
16462                 (void *)&cmd_set_mplsogre_decap_set,
16463                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16464                 (void *)&cmd_set_mplsogre_decap_ip_version,
16465                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16466                 NULL,
16467         },
16468 };
16469
16470 /** Set MPLSoUDP encapsulation details */
16471 struct cmd_set_mplsoudp_encap_result {
16472         cmdline_fixed_string_t set;
16473         cmdline_fixed_string_t mplsoudp;
16474         cmdline_fixed_string_t pos_token;
16475         cmdline_fixed_string_t ip_version;
16476         uint32_t vlan_present:1;
16477         uint32_t label;
16478         uint16_t udp_src;
16479         uint16_t udp_dst;
16480         cmdline_ipaddr_t ip_src;
16481         cmdline_ipaddr_t ip_dst;
16482         uint16_t tci;
16483         struct rte_ether_addr eth_src;
16484         struct rte_ether_addr eth_dst;
16485 };
16486
16487 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16488         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16489                                  "set");
16490 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16491         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16492                                  "mplsoudp_encap");
16493 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16494         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16495                                  mplsoudp, "mplsoudp_encap-with-vlan");
16496 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16497         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16498                                  pos_token, "ip-version");
16499 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16500         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16501                                  ip_version, "ipv4#ipv6");
16502 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16503         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16504                                  pos_token, "label");
16505 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16506         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16507                               UINT32);
16508 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16509         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16510                                  pos_token, "udp-src");
16511 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16512         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16513                               UINT16);
16514 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16515         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16516                                  pos_token, "udp-dst");
16517 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16518         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16519                               UINT16);
16520 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16521         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16522                                  pos_token, "ip-src");
16523 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16524         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16525 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16526         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16527                                  pos_token, "ip-dst");
16528 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16529         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16530 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16531         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16532                                  pos_token, "vlan-tci");
16533 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16534         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16535                               UINT16);
16536 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16537         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16538                                  pos_token, "eth-src");
16539 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16540         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16541                                     eth_src);
16542 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16543         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16544                                  pos_token, "eth-dst");
16545 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16546         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16547                                     eth_dst);
16548
16549 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16550         __rte_unused struct cmdline *cl,
16551         __rte_unused void *data)
16552 {
16553         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16554         union {
16555                 uint32_t mplsoudp_label;
16556                 uint8_t label[4];
16557         } id = {
16558                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16559         };
16560
16561         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16562                 mplsoudp_encap_conf.select_vlan = 0;
16563         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16564                 mplsoudp_encap_conf.select_vlan = 1;
16565         if (strcmp(res->ip_version, "ipv4") == 0)
16566                 mplsoudp_encap_conf.select_ipv4 = 1;
16567         else if (strcmp(res->ip_version, "ipv6") == 0)
16568                 mplsoudp_encap_conf.select_ipv4 = 0;
16569         else
16570                 return;
16571         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16572         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16573         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16574         if (mplsoudp_encap_conf.select_ipv4) {
16575                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16576                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16577         } else {
16578                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16579                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16580         }
16581         if (mplsoudp_encap_conf.select_vlan)
16582                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16583         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16584                    RTE_ETHER_ADDR_LEN);
16585         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16586                    RTE_ETHER_ADDR_LEN);
16587 }
16588
16589 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16590         .f = cmd_set_mplsoudp_encap_parsed,
16591         .data = NULL,
16592         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16593                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16594                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16595         .tokens = {
16596                 (void *)&cmd_set_mplsoudp_encap_set,
16597                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16598                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16599                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16600                 (void *)&cmd_set_mplsoudp_encap_label,
16601                 (void *)&cmd_set_mplsoudp_encap_label_value,
16602                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16603                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16604                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16605                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16606                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16607                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16608                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16609                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16610                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16611                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16612                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16613                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16614                 NULL,
16615         },
16616 };
16617
16618 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16619         .f = cmd_set_mplsoudp_encap_parsed,
16620         .data = NULL,
16621         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16622                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16623                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16624                 " eth-src <eth-src> eth-dst <eth-dst>",
16625         .tokens = {
16626                 (void *)&cmd_set_mplsoudp_encap_set,
16627                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16628                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16629                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16630                 (void *)&cmd_set_mplsoudp_encap_label,
16631                 (void *)&cmd_set_mplsoudp_encap_label_value,
16632                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16633                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16634                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16635                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16636                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16637                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16638                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16639                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16640                 (void *)&cmd_set_mplsoudp_encap_vlan,
16641                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16642                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16643                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16644                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16645                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16646                 NULL,
16647         },
16648 };
16649
16650 /** Set MPLSoUDP decapsulation details */
16651 struct cmd_set_mplsoudp_decap_result {
16652         cmdline_fixed_string_t set;
16653         cmdline_fixed_string_t mplsoudp;
16654         cmdline_fixed_string_t pos_token;
16655         cmdline_fixed_string_t ip_version;
16656         uint32_t vlan_present:1;
16657 };
16658
16659 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16660         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16661                                  "set");
16662 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16663         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16664                                  "mplsoudp_decap");
16665 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16666         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16667                                  mplsoudp, "mplsoudp_decap-with-vlan");
16668 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16669         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16670                                  pos_token, "ip-version");
16671 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16672         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16673                                  ip_version, "ipv4#ipv6");
16674
16675 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16676         __rte_unused struct cmdline *cl,
16677         __rte_unused void *data)
16678 {
16679         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16680
16681         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16682                 mplsoudp_decap_conf.select_vlan = 0;
16683         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16684                 mplsoudp_decap_conf.select_vlan = 1;
16685         if (strcmp(res->ip_version, "ipv4") == 0)
16686                 mplsoudp_decap_conf.select_ipv4 = 1;
16687         else if (strcmp(res->ip_version, "ipv6") == 0)
16688                 mplsoudp_decap_conf.select_ipv4 = 0;
16689 }
16690
16691 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16692         .f = cmd_set_mplsoudp_decap_parsed,
16693         .data = NULL,
16694         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16695         .tokens = {
16696                 (void *)&cmd_set_mplsoudp_decap_set,
16697                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16698                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16699                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16700                 NULL,
16701         },
16702 };
16703
16704 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16705         .f = cmd_set_mplsoudp_decap_parsed,
16706         .data = NULL,
16707         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16708         .tokens = {
16709                 (void *)&cmd_set_mplsoudp_decap_set,
16710                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16711                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16712                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16713                 NULL,
16714         },
16715 };
16716
16717 /* Strict link priority scheduling mode setting */
16718 static void
16719 cmd_strict_link_prio_parsed(
16720         void *parsed_result,
16721         __rte_unused struct cmdline *cl,
16722         __rte_unused void *data)
16723 {
16724         struct cmd_vf_tc_bw_result *res = parsed_result;
16725         int ret = -ENOTSUP;
16726
16727         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16728                 return;
16729
16730 #ifdef RTE_NET_I40E
16731         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16732 #endif
16733
16734         switch (ret) {
16735         case 0:
16736                 break;
16737         case -EINVAL:
16738                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16739                 break;
16740         case -ENODEV:
16741                 printf("invalid port_id %d\n", res->port_id);
16742                 break;
16743         case -ENOTSUP:
16744                 printf("function not implemented\n");
16745                 break;
16746         default:
16747                 printf("programming error: (%s)\n", strerror(-ret));
16748         }
16749 }
16750
16751 cmdline_parse_inst_t cmd_strict_link_prio = {
16752         .f = cmd_strict_link_prio_parsed,
16753         .data = NULL,
16754         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16755         .tokens = {
16756                 (void *)&cmd_vf_tc_bw_set,
16757                 (void *)&cmd_vf_tc_bw_tx,
16758                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16759                 (void *)&cmd_vf_tc_bw_port_id,
16760                 (void *)&cmd_vf_tc_bw_tc_map,
16761                 NULL,
16762         },
16763 };
16764
16765 /* Load dynamic device personalization*/
16766 struct cmd_ddp_add_result {
16767         cmdline_fixed_string_t ddp;
16768         cmdline_fixed_string_t add;
16769         portid_t port_id;
16770         char filepath[];
16771 };
16772
16773 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16774         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16775 cmdline_parse_token_string_t cmd_ddp_add_add =
16776         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16777 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16778         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16779 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16780         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16781
16782 static void
16783 cmd_ddp_add_parsed(
16784         void *parsed_result,
16785         __rte_unused struct cmdline *cl,
16786         __rte_unused void *data)
16787 {
16788         struct cmd_ddp_add_result *res = parsed_result;
16789         uint8_t *buff;
16790         uint32_t size;
16791         char *filepath;
16792         char *file_fld[2];
16793         int file_num;
16794         int ret = -ENOTSUP;
16795
16796         if (!all_ports_stopped()) {
16797                 printf("Please stop all ports first\n");
16798                 return;
16799         }
16800
16801         filepath = strdup(res->filepath);
16802         if (filepath == NULL) {
16803                 printf("Failed to allocate memory\n");
16804                 return;
16805         }
16806         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16807
16808         buff = open_file(file_fld[0], &size);
16809         if (!buff) {
16810                 free((void *)filepath);
16811                 return;
16812         }
16813
16814 #ifdef RTE_NET_I40E
16815         if (ret == -ENOTSUP)
16816                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16817                                                buff, size,
16818                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16819 #endif
16820
16821         if (ret == -EEXIST)
16822                 printf("Profile has already existed.\n");
16823         else if (ret < 0)
16824                 printf("Failed to load profile.\n");
16825         else if (file_num == 2)
16826                 save_file(file_fld[1], buff, size);
16827
16828         close_file(buff);
16829         free((void *)filepath);
16830 }
16831
16832 cmdline_parse_inst_t cmd_ddp_add = {
16833         .f = cmd_ddp_add_parsed,
16834         .data = NULL,
16835         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16836         .tokens = {
16837                 (void *)&cmd_ddp_add_ddp,
16838                 (void *)&cmd_ddp_add_add,
16839                 (void *)&cmd_ddp_add_port_id,
16840                 (void *)&cmd_ddp_add_filepath,
16841                 NULL,
16842         },
16843 };
16844
16845 /* Delete dynamic device personalization*/
16846 struct cmd_ddp_del_result {
16847         cmdline_fixed_string_t ddp;
16848         cmdline_fixed_string_t del;
16849         portid_t port_id;
16850         char filepath[];
16851 };
16852
16853 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16854         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16855 cmdline_parse_token_string_t cmd_ddp_del_del =
16856         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16857 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16858         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16859 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16860         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16861
16862 static void
16863 cmd_ddp_del_parsed(
16864         void *parsed_result,
16865         __rte_unused struct cmdline *cl,
16866         __rte_unused void *data)
16867 {
16868         struct cmd_ddp_del_result *res = parsed_result;
16869         uint8_t *buff;
16870         uint32_t size;
16871         int ret = -ENOTSUP;
16872
16873         if (!all_ports_stopped()) {
16874                 printf("Please stop all ports first\n");
16875                 return;
16876         }
16877
16878         buff = open_file(res->filepath, &size);
16879         if (!buff)
16880                 return;
16881
16882 #ifdef RTE_NET_I40E
16883         if (ret == -ENOTSUP)
16884                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16885                                                buff, size,
16886                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16887 #endif
16888
16889         if (ret == -EACCES)
16890                 printf("Profile does not exist.\n");
16891         else if (ret < 0)
16892                 printf("Failed to delete profile.\n");
16893
16894         close_file(buff);
16895 }
16896
16897 cmdline_parse_inst_t cmd_ddp_del = {
16898         .f = cmd_ddp_del_parsed,
16899         .data = NULL,
16900         .help_str = "ddp del <port_id> <backup_profile_path>",
16901         .tokens = {
16902                 (void *)&cmd_ddp_del_ddp,
16903                 (void *)&cmd_ddp_del_del,
16904                 (void *)&cmd_ddp_del_port_id,
16905                 (void *)&cmd_ddp_del_filepath,
16906                 NULL,
16907         },
16908 };
16909
16910 /* Get dynamic device personalization profile info */
16911 struct cmd_ddp_info_result {
16912         cmdline_fixed_string_t ddp;
16913         cmdline_fixed_string_t get;
16914         cmdline_fixed_string_t info;
16915         char filepath[];
16916 };
16917
16918 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16919         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16920 cmdline_parse_token_string_t cmd_ddp_info_get =
16921         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16922 cmdline_parse_token_string_t cmd_ddp_info_info =
16923         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16924 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16925         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16926
16927 static void
16928 cmd_ddp_info_parsed(
16929         void *parsed_result,
16930         __rte_unused struct cmdline *cl,
16931         __rte_unused void *data)
16932 {
16933         struct cmd_ddp_info_result *res = parsed_result;
16934         uint8_t *pkg;
16935         uint32_t pkg_size;
16936         int ret = -ENOTSUP;
16937 #ifdef RTE_NET_I40E
16938         uint32_t i, j, n;
16939         uint8_t *buff;
16940         uint32_t buff_size = 0;
16941         struct rte_pmd_i40e_profile_info info;
16942         uint32_t dev_num = 0;
16943         struct rte_pmd_i40e_ddp_device_id *devs;
16944         uint32_t proto_num = 0;
16945         struct rte_pmd_i40e_proto_info *proto = NULL;
16946         uint32_t pctype_num = 0;
16947         struct rte_pmd_i40e_ptype_info *pctype;
16948         uint32_t ptype_num = 0;
16949         struct rte_pmd_i40e_ptype_info *ptype;
16950         uint8_t proto_id;
16951
16952 #endif
16953
16954         pkg = open_file(res->filepath, &pkg_size);
16955         if (!pkg)
16956                 return;
16957
16958 #ifdef RTE_NET_I40E
16959         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16960                                 (uint8_t *)&info, sizeof(info),
16961                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16962         if (!ret) {
16963                 printf("Global Track id:       0x%x\n", info.track_id);
16964                 printf("Global Version:        %d.%d.%d.%d\n",
16965                         info.version.major,
16966                         info.version.minor,
16967                         info.version.update,
16968                         info.version.draft);
16969                 printf("Global Package name:   %s\n\n", info.name);
16970         }
16971
16972         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16973                                 (uint8_t *)&info, sizeof(info),
16974                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16975         if (!ret) {
16976                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16977                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16978                         info.version.major,
16979                         info.version.minor,
16980                         info.version.update,
16981                         info.version.draft);
16982                 printf("i40e Profile name:     %s\n\n", info.name);
16983         }
16984
16985         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16986                                 (uint8_t *)&buff_size, sizeof(buff_size),
16987                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16988         if (!ret && buff_size) {
16989                 buff = (uint8_t *)malloc(buff_size);
16990                 if (buff) {
16991                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16992                                                 buff, buff_size,
16993                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16994                         if (!ret)
16995                                 printf("Package Notes:\n%s\n\n", buff);
16996                         free(buff);
16997                 }
16998         }
16999
17000         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
17001                                 (uint8_t *)&dev_num, sizeof(dev_num),
17002                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
17003         if (!ret && dev_num) {
17004                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
17005                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
17006                 if (devs) {
17007                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
17008                                                 (uint8_t *)devs, buff_size,
17009                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
17010                         if (!ret) {
17011                                 printf("List of supported devices:\n");
17012                                 for (i = 0; i < dev_num; i++) {
17013                                         printf("  %04X:%04X %04X:%04X\n",
17014                                                 devs[i].vendor_dev_id >> 16,
17015                                                 devs[i].vendor_dev_id & 0xFFFF,
17016                                                 devs[i].sub_vendor_dev_id >> 16,
17017                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
17018                                 }
17019                                 printf("\n");
17020                         }
17021                         free(devs);
17022                 }
17023         }
17024
17025         /* get information about protocols and packet types */
17026         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
17027                 (uint8_t *)&proto_num, sizeof(proto_num),
17028                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
17029         if (ret || !proto_num)
17030                 goto no_print_return;
17031
17032         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
17033         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
17034         if (!proto)
17035                 goto no_print_return;
17036
17037         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
17038                                         buff_size,
17039                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
17040         if (!ret) {
17041                 printf("List of used protocols:\n");
17042                 for (i = 0; i < proto_num; i++)
17043                         printf("  %2u: %s\n", proto[i].proto_id,
17044                                proto[i].name);
17045                 printf("\n");
17046         }
17047         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
17048                 (uint8_t *)&pctype_num, sizeof(pctype_num),
17049                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
17050         if (ret || !pctype_num)
17051                 goto no_print_pctypes;
17052
17053         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
17054         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
17055         if (!pctype)
17056                 goto no_print_pctypes;
17057
17058         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
17059                                         buff_size,
17060                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
17061         if (ret) {
17062                 free(pctype);
17063                 goto no_print_pctypes;
17064         }
17065
17066         printf("List of defined packet classification types:\n");
17067         for (i = 0; i < pctype_num; i++) {
17068                 printf("  %2u:", pctype[i].ptype_id);
17069                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17070                         proto_id = pctype[i].protocols[j];
17071                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17072                                 for (n = 0; n < proto_num; n++) {
17073                                         if (proto[n].proto_id == proto_id) {
17074                                                 printf(" %s", proto[n].name);
17075                                                 break;
17076                                         }
17077                                 }
17078                         }
17079                 }
17080                 printf("\n");
17081         }
17082         printf("\n");
17083         free(pctype);
17084
17085 no_print_pctypes:
17086
17087         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
17088                                         sizeof(ptype_num),
17089                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
17090         if (ret || !ptype_num)
17091                 goto no_print_return;
17092
17093         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
17094         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
17095         if (!ptype)
17096                 goto no_print_return;
17097
17098         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
17099                                         buff_size,
17100                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
17101         if (ret) {
17102                 free(ptype);
17103                 goto no_print_return;
17104         }
17105         printf("List of defined packet types:\n");
17106         for (i = 0; i < ptype_num; i++) {
17107                 printf("  %2u:", ptype[i].ptype_id);
17108                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17109                         proto_id = ptype[i].protocols[j];
17110                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17111                                 for (n = 0; n < proto_num; n++) {
17112                                         if (proto[n].proto_id == proto_id) {
17113                                                 printf(" %s", proto[n].name);
17114                                                 break;
17115                                         }
17116                                 }
17117                         }
17118                 }
17119                 printf("\n");
17120         }
17121         free(ptype);
17122         printf("\n");
17123
17124         ret = 0;
17125 no_print_return:
17126         if (proto)
17127                 free(proto);
17128 #endif
17129         if (ret == -ENOTSUP)
17130                 printf("Function not supported in PMD driver\n");
17131         close_file(pkg);
17132 }
17133
17134 cmdline_parse_inst_t cmd_ddp_get_info = {
17135         .f = cmd_ddp_info_parsed,
17136         .data = NULL,
17137         .help_str = "ddp get info <profile_path>",
17138         .tokens = {
17139                 (void *)&cmd_ddp_info_ddp,
17140                 (void *)&cmd_ddp_info_get,
17141                 (void *)&cmd_ddp_info_info,
17142                 (void *)&cmd_ddp_info_filepath,
17143                 NULL,
17144         },
17145 };
17146
17147 /* Get dynamic device personalization profile info list*/
17148 #define PROFILE_INFO_SIZE 48
17149 #define MAX_PROFILE_NUM 16
17150
17151 struct cmd_ddp_get_list_result {
17152         cmdline_fixed_string_t ddp;
17153         cmdline_fixed_string_t get;
17154         cmdline_fixed_string_t list;
17155         portid_t port_id;
17156 };
17157
17158 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17159         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17160 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17161         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17162 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17163         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17164 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17165         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17166
17167 static void
17168 cmd_ddp_get_list_parsed(
17169         __rte_unused void *parsed_result,
17170         __rte_unused struct cmdline *cl,
17171         __rte_unused void *data)
17172 {
17173 #ifdef RTE_NET_I40E
17174         struct cmd_ddp_get_list_result *res = parsed_result;
17175         struct rte_pmd_i40e_profile_list *p_list;
17176         struct rte_pmd_i40e_profile_info *p_info;
17177         uint32_t p_num;
17178         uint32_t size;
17179         uint32_t i;
17180 #endif
17181         int ret = -ENOTSUP;
17182
17183 #ifdef RTE_NET_I40E
17184         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17185         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17186         if (!p_list) {
17187                 printf("%s: Failed to malloc buffer\n", __func__);
17188                 return;
17189         }
17190
17191         if (ret == -ENOTSUP)
17192                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17193                                                 (uint8_t *)p_list, size);
17194
17195         if (!ret) {
17196                 p_num = p_list->p_count;
17197                 printf("Profile number is: %d\n\n", p_num);
17198
17199                 for (i = 0; i < p_num; i++) {
17200                         p_info = &p_list->p_info[i];
17201                         printf("Profile %d:\n", i);
17202                         printf("Track id:     0x%x\n", p_info->track_id);
17203                         printf("Version:      %d.%d.%d.%d\n",
17204                                p_info->version.major,
17205                                p_info->version.minor,
17206                                p_info->version.update,
17207                                p_info->version.draft);
17208                         printf("Profile name: %s\n\n", p_info->name);
17209                 }
17210         }
17211
17212         free(p_list);
17213 #endif
17214
17215         if (ret < 0)
17216                 printf("Failed to get ddp list\n");
17217 }
17218
17219 cmdline_parse_inst_t cmd_ddp_get_list = {
17220         .f = cmd_ddp_get_list_parsed,
17221         .data = NULL,
17222         .help_str = "ddp get list <port_id>",
17223         .tokens = {
17224                 (void *)&cmd_ddp_get_list_ddp,
17225                 (void *)&cmd_ddp_get_list_get,
17226                 (void *)&cmd_ddp_get_list_list,
17227                 (void *)&cmd_ddp_get_list_port_id,
17228                 NULL,
17229         },
17230 };
17231
17232 /* Configure input set */
17233 struct cmd_cfg_input_set_result {
17234         cmdline_fixed_string_t port;
17235         cmdline_fixed_string_t cfg;
17236         portid_t port_id;
17237         cmdline_fixed_string_t pctype;
17238         uint8_t pctype_id;
17239         cmdline_fixed_string_t inset_type;
17240         cmdline_fixed_string_t opt;
17241         cmdline_fixed_string_t field;
17242         uint8_t field_idx;
17243 };
17244
17245 static void
17246 cmd_cfg_input_set_parsed(
17247         __rte_unused void *parsed_result,
17248         __rte_unused struct cmdline *cl,
17249         __rte_unused void *data)
17250 {
17251 #ifdef RTE_NET_I40E
17252         struct cmd_cfg_input_set_result *res = parsed_result;
17253         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17254         struct rte_pmd_i40e_inset inset;
17255 #endif
17256         int ret = -ENOTSUP;
17257
17258         if (!all_ports_stopped()) {
17259                 printf("Please stop all ports first\n");
17260                 return;
17261         }
17262
17263 #ifdef RTE_NET_I40E
17264         if (!strcmp(res->inset_type, "hash_inset"))
17265                 inset_type = INSET_HASH;
17266         else if (!strcmp(res->inset_type, "fdir_inset"))
17267                 inset_type = INSET_FDIR;
17268         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17269                 inset_type = INSET_FDIR_FLX;
17270         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17271                                      &inset, inset_type);
17272         if (ret) {
17273                 printf("Failed to get input set.\n");
17274                 return;
17275         }
17276
17277         if (!strcmp(res->opt, "get")) {
17278                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17279                                                    res->field_idx);
17280                 if (ret)
17281                         printf("Field index %d is enabled.\n", res->field_idx);
17282                 else
17283                         printf("Field index %d is disabled.\n", res->field_idx);
17284                 return;
17285         } else if (!strcmp(res->opt, "set"))
17286                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17287                                                    res->field_idx);
17288         else if (!strcmp(res->opt, "clear"))
17289                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17290                                                      res->field_idx);
17291         if (ret) {
17292                 printf("Failed to configure input set field.\n");
17293                 return;
17294         }
17295
17296         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17297                                      &inset, inset_type);
17298         if (ret) {
17299                 printf("Failed to set input set.\n");
17300                 return;
17301         }
17302 #endif
17303
17304         if (ret == -ENOTSUP)
17305                 printf("Function not supported\n");
17306 }
17307
17308 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17309         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17310                                  port, "port");
17311 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17312         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17313                                  cfg, "config");
17314 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17315         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17316                               port_id, UINT16);
17317 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17318         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17319                                  pctype, "pctype");
17320 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17321         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17322                               pctype_id, UINT8);
17323 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17324         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17325                                  inset_type,
17326                                  "hash_inset#fdir_inset#fdir_flx_inset");
17327 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17328         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17329                                  opt, "get#set#clear");
17330 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17331         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17332                                  field, "field");
17333 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17334         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17335                               field_idx, UINT8);
17336
17337 cmdline_parse_inst_t cmd_cfg_input_set = {
17338         .f = cmd_cfg_input_set_parsed,
17339         .data = NULL,
17340         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17341                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17342         .tokens = {
17343                 (void *)&cmd_cfg_input_set_port,
17344                 (void *)&cmd_cfg_input_set_cfg,
17345                 (void *)&cmd_cfg_input_set_port_id,
17346                 (void *)&cmd_cfg_input_set_pctype,
17347                 (void *)&cmd_cfg_input_set_pctype_id,
17348                 (void *)&cmd_cfg_input_set_inset_type,
17349                 (void *)&cmd_cfg_input_set_opt,
17350                 (void *)&cmd_cfg_input_set_field,
17351                 (void *)&cmd_cfg_input_set_field_idx,
17352                 NULL,
17353         },
17354 };
17355
17356 /* Clear input set */
17357 struct cmd_clear_input_set_result {
17358         cmdline_fixed_string_t port;
17359         cmdline_fixed_string_t cfg;
17360         portid_t port_id;
17361         cmdline_fixed_string_t pctype;
17362         uint8_t pctype_id;
17363         cmdline_fixed_string_t inset_type;
17364         cmdline_fixed_string_t clear;
17365         cmdline_fixed_string_t all;
17366 };
17367
17368 static void
17369 cmd_clear_input_set_parsed(
17370         __rte_unused void *parsed_result,
17371         __rte_unused struct cmdline *cl,
17372         __rte_unused void *data)
17373 {
17374 #ifdef RTE_NET_I40E
17375         struct cmd_clear_input_set_result *res = parsed_result;
17376         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17377         struct rte_pmd_i40e_inset inset;
17378 #endif
17379         int ret = -ENOTSUP;
17380
17381         if (!all_ports_stopped()) {
17382                 printf("Please stop all ports first\n");
17383                 return;
17384         }
17385
17386 #ifdef RTE_NET_I40E
17387         if (!strcmp(res->inset_type, "hash_inset"))
17388                 inset_type = INSET_HASH;
17389         else if (!strcmp(res->inset_type, "fdir_inset"))
17390                 inset_type = INSET_FDIR;
17391         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17392                 inset_type = INSET_FDIR_FLX;
17393
17394         memset(&inset, 0, sizeof(inset));
17395
17396         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17397                                      &inset, inset_type);
17398         if (ret) {
17399                 printf("Failed to clear input set.\n");
17400                 return;
17401         }
17402
17403 #endif
17404
17405         if (ret == -ENOTSUP)
17406                 printf("Function not supported\n");
17407 }
17408
17409 cmdline_parse_token_string_t cmd_clear_input_set_port =
17410         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17411                                  port, "port");
17412 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17413         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17414                                  cfg, "config");
17415 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17416         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17417                               port_id, UINT16);
17418 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17419         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17420                                  pctype, "pctype");
17421 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17422         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17423                               pctype_id, UINT8);
17424 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17425         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17426                                  inset_type,
17427                                  "hash_inset#fdir_inset#fdir_flx_inset");
17428 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17429         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17430                                  clear, "clear");
17431 cmdline_parse_token_string_t cmd_clear_input_set_all =
17432         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17433                                  all, "all");
17434
17435 cmdline_parse_inst_t cmd_clear_input_set = {
17436         .f = cmd_clear_input_set_parsed,
17437         .data = NULL,
17438         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17439                     "fdir_inset|fdir_flx_inset clear all",
17440         .tokens = {
17441                 (void *)&cmd_clear_input_set_port,
17442                 (void *)&cmd_clear_input_set_cfg,
17443                 (void *)&cmd_clear_input_set_port_id,
17444                 (void *)&cmd_clear_input_set_pctype,
17445                 (void *)&cmd_clear_input_set_pctype_id,
17446                 (void *)&cmd_clear_input_set_inset_type,
17447                 (void *)&cmd_clear_input_set_clear,
17448                 (void *)&cmd_clear_input_set_all,
17449                 NULL,
17450         },
17451 };
17452
17453 /* show vf stats */
17454
17455 /* Common result structure for show vf stats */
17456 struct cmd_show_vf_stats_result {
17457         cmdline_fixed_string_t show;
17458         cmdline_fixed_string_t vf;
17459         cmdline_fixed_string_t stats;
17460         portid_t port_id;
17461         uint16_t vf_id;
17462 };
17463
17464 /* Common CLI fields show vf stats*/
17465 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17466         TOKEN_STRING_INITIALIZER
17467                 (struct cmd_show_vf_stats_result,
17468                  show, "show");
17469 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17470         TOKEN_STRING_INITIALIZER
17471                 (struct cmd_show_vf_stats_result,
17472                  vf, "vf");
17473 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17474         TOKEN_STRING_INITIALIZER
17475                 (struct cmd_show_vf_stats_result,
17476                  stats, "stats");
17477 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17478         TOKEN_NUM_INITIALIZER
17479                 (struct cmd_show_vf_stats_result,
17480                  port_id, UINT16);
17481 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17482         TOKEN_NUM_INITIALIZER
17483                 (struct cmd_show_vf_stats_result,
17484                  vf_id, UINT16);
17485
17486 static void
17487 cmd_show_vf_stats_parsed(
17488         void *parsed_result,
17489         __rte_unused struct cmdline *cl,
17490         __rte_unused void *data)
17491 {
17492         struct cmd_show_vf_stats_result *res = parsed_result;
17493         struct rte_eth_stats stats;
17494         int ret = -ENOTSUP;
17495         static const char *nic_stats_border = "########################";
17496
17497         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17498                 return;
17499
17500         memset(&stats, 0, sizeof(stats));
17501
17502 #ifdef RTE_NET_I40E
17503         if (ret == -ENOTSUP)
17504                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17505                                                 res->vf_id,
17506                                                 &stats);
17507 #endif
17508 #ifdef RTE_NET_BNXT
17509         if (ret == -ENOTSUP)
17510                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17511                                                 res->vf_id,
17512                                                 &stats);
17513 #endif
17514
17515         switch (ret) {
17516         case 0:
17517                 break;
17518         case -EINVAL:
17519                 printf("invalid vf_id %d\n", res->vf_id);
17520                 break;
17521         case -ENODEV:
17522                 printf("invalid port_id %d\n", res->port_id);
17523                 break;
17524         case -ENOTSUP:
17525                 printf("function not implemented\n");
17526                 break;
17527         default:
17528                 printf("programming error: (%s)\n", strerror(-ret));
17529         }
17530
17531         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17532                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17533
17534         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17535                "%-"PRIu64"\n",
17536                stats.ipackets, stats.imissed, stats.ibytes);
17537         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17538         printf("  RX-nombuf:  %-10"PRIu64"\n",
17539                stats.rx_nombuf);
17540         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17541                "%-"PRIu64"\n",
17542                stats.opackets, stats.oerrors, stats.obytes);
17543
17544         printf("  %s############################%s\n",
17545                                nic_stats_border, nic_stats_border);
17546 }
17547
17548 cmdline_parse_inst_t cmd_show_vf_stats = {
17549         .f = cmd_show_vf_stats_parsed,
17550         .data = NULL,
17551         .help_str = "show vf stats <port_id> <vf_id>",
17552         .tokens = {
17553                 (void *)&cmd_show_vf_stats_show,
17554                 (void *)&cmd_show_vf_stats_vf,
17555                 (void *)&cmd_show_vf_stats_stats,
17556                 (void *)&cmd_show_vf_stats_port_id,
17557                 (void *)&cmd_show_vf_stats_vf_id,
17558                 NULL,
17559         },
17560 };
17561
17562 /* clear vf stats */
17563
17564 /* Common result structure for clear vf stats */
17565 struct cmd_clear_vf_stats_result {
17566         cmdline_fixed_string_t clear;
17567         cmdline_fixed_string_t vf;
17568         cmdline_fixed_string_t stats;
17569         portid_t port_id;
17570         uint16_t vf_id;
17571 };
17572
17573 /* Common CLI fields clear vf stats*/
17574 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17575         TOKEN_STRING_INITIALIZER
17576                 (struct cmd_clear_vf_stats_result,
17577                  clear, "clear");
17578 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17579         TOKEN_STRING_INITIALIZER
17580                 (struct cmd_clear_vf_stats_result,
17581                  vf, "vf");
17582 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17583         TOKEN_STRING_INITIALIZER
17584                 (struct cmd_clear_vf_stats_result,
17585                  stats, "stats");
17586 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17587         TOKEN_NUM_INITIALIZER
17588                 (struct cmd_clear_vf_stats_result,
17589                  port_id, UINT16);
17590 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17591         TOKEN_NUM_INITIALIZER
17592                 (struct cmd_clear_vf_stats_result,
17593                  vf_id, UINT16);
17594
17595 static void
17596 cmd_clear_vf_stats_parsed(
17597         void *parsed_result,
17598         __rte_unused struct cmdline *cl,
17599         __rte_unused void *data)
17600 {
17601         struct cmd_clear_vf_stats_result *res = parsed_result;
17602         int ret = -ENOTSUP;
17603
17604         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17605                 return;
17606
17607 #ifdef RTE_NET_I40E
17608         if (ret == -ENOTSUP)
17609                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17610                                                   res->vf_id);
17611 #endif
17612 #ifdef RTE_NET_BNXT
17613         if (ret == -ENOTSUP)
17614                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17615                                                   res->vf_id);
17616 #endif
17617
17618         switch (ret) {
17619         case 0:
17620                 break;
17621         case -EINVAL:
17622                 printf("invalid vf_id %d\n", res->vf_id);
17623                 break;
17624         case -ENODEV:
17625                 printf("invalid port_id %d\n", res->port_id);
17626                 break;
17627         case -ENOTSUP:
17628                 printf("function not implemented\n");
17629                 break;
17630         default:
17631                 printf("programming error: (%s)\n", strerror(-ret));
17632         }
17633 }
17634
17635 cmdline_parse_inst_t cmd_clear_vf_stats = {
17636         .f = cmd_clear_vf_stats_parsed,
17637         .data = NULL,
17638         .help_str = "clear vf stats <port_id> <vf_id>",
17639         .tokens = {
17640                 (void *)&cmd_clear_vf_stats_clear,
17641                 (void *)&cmd_clear_vf_stats_vf,
17642                 (void *)&cmd_clear_vf_stats_stats,
17643                 (void *)&cmd_clear_vf_stats_port_id,
17644                 (void *)&cmd_clear_vf_stats_vf_id,
17645                 NULL,
17646         },
17647 };
17648
17649 /* port config pctype mapping reset */
17650
17651 /* Common result structure for port config pctype mapping reset */
17652 struct cmd_pctype_mapping_reset_result {
17653         cmdline_fixed_string_t port;
17654         cmdline_fixed_string_t config;
17655         portid_t port_id;
17656         cmdline_fixed_string_t pctype;
17657         cmdline_fixed_string_t mapping;
17658         cmdline_fixed_string_t reset;
17659 };
17660
17661 /* Common CLI fields for port config pctype mapping reset*/
17662 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17663         TOKEN_STRING_INITIALIZER
17664                 (struct cmd_pctype_mapping_reset_result,
17665                  port, "port");
17666 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17667         TOKEN_STRING_INITIALIZER
17668                 (struct cmd_pctype_mapping_reset_result,
17669                  config, "config");
17670 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17671         TOKEN_NUM_INITIALIZER
17672                 (struct cmd_pctype_mapping_reset_result,
17673                  port_id, UINT16);
17674 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17675         TOKEN_STRING_INITIALIZER
17676                 (struct cmd_pctype_mapping_reset_result,
17677                  pctype, "pctype");
17678 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17679         TOKEN_STRING_INITIALIZER
17680                 (struct cmd_pctype_mapping_reset_result,
17681                  mapping, "mapping");
17682 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17683         TOKEN_STRING_INITIALIZER
17684                 (struct cmd_pctype_mapping_reset_result,
17685                  reset, "reset");
17686
17687 static void
17688 cmd_pctype_mapping_reset_parsed(
17689         void *parsed_result,
17690         __rte_unused struct cmdline *cl,
17691         __rte_unused void *data)
17692 {
17693         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17694         int ret = -ENOTSUP;
17695
17696         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17697                 return;
17698
17699 #ifdef RTE_NET_I40E
17700         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17701 #endif
17702
17703         switch (ret) {
17704         case 0:
17705                 break;
17706         case -ENODEV:
17707                 printf("invalid port_id %d\n", res->port_id);
17708                 break;
17709         case -ENOTSUP:
17710                 printf("function not implemented\n");
17711                 break;
17712         default:
17713                 printf("programming error: (%s)\n", strerror(-ret));
17714         }
17715 }
17716
17717 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17718         .f = cmd_pctype_mapping_reset_parsed,
17719         .data = NULL,
17720         .help_str = "port config <port_id> pctype mapping reset",
17721         .tokens = {
17722                 (void *)&cmd_pctype_mapping_reset_port,
17723                 (void *)&cmd_pctype_mapping_reset_config,
17724                 (void *)&cmd_pctype_mapping_reset_port_id,
17725                 (void *)&cmd_pctype_mapping_reset_pctype,
17726                 (void *)&cmd_pctype_mapping_reset_mapping,
17727                 (void *)&cmd_pctype_mapping_reset_reset,
17728                 NULL,
17729         },
17730 };
17731
17732 /* show port pctype mapping */
17733
17734 /* Common result structure for show port pctype mapping */
17735 struct cmd_pctype_mapping_get_result {
17736         cmdline_fixed_string_t show;
17737         cmdline_fixed_string_t port;
17738         portid_t port_id;
17739         cmdline_fixed_string_t pctype;
17740         cmdline_fixed_string_t mapping;
17741 };
17742
17743 /* Common CLI fields for pctype mapping get */
17744 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17745         TOKEN_STRING_INITIALIZER
17746                 (struct cmd_pctype_mapping_get_result,
17747                  show, "show");
17748 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17749         TOKEN_STRING_INITIALIZER
17750                 (struct cmd_pctype_mapping_get_result,
17751                  port, "port");
17752 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17753         TOKEN_NUM_INITIALIZER
17754                 (struct cmd_pctype_mapping_get_result,
17755                  port_id, UINT16);
17756 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17757         TOKEN_STRING_INITIALIZER
17758                 (struct cmd_pctype_mapping_get_result,
17759                  pctype, "pctype");
17760 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17761         TOKEN_STRING_INITIALIZER
17762                 (struct cmd_pctype_mapping_get_result,
17763                  mapping, "mapping");
17764
17765 static void
17766 cmd_pctype_mapping_get_parsed(
17767         void *parsed_result,
17768         __rte_unused struct cmdline *cl,
17769         __rte_unused void *data)
17770 {
17771         struct cmd_pctype_mapping_get_result *res = parsed_result;
17772         int ret = -ENOTSUP;
17773 #ifdef RTE_NET_I40E
17774         struct rte_pmd_i40e_flow_type_mapping
17775                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17776         int i, j, first_pctype;
17777 #endif
17778
17779         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17780                 return;
17781
17782 #ifdef RTE_NET_I40E
17783         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17784 #endif
17785
17786         switch (ret) {
17787         case 0:
17788                 break;
17789         case -ENODEV:
17790                 printf("invalid port_id %d\n", res->port_id);
17791                 return;
17792         case -ENOTSUP:
17793                 printf("function not implemented\n");
17794                 return;
17795         default:
17796                 printf("programming error: (%s)\n", strerror(-ret));
17797                 return;
17798         }
17799
17800 #ifdef RTE_NET_I40E
17801         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17802                 if (mapping[i].pctype != 0ULL) {
17803                         first_pctype = 1;
17804
17805                         printf("pctype: ");
17806                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17807                                 if (mapping[i].pctype & (1ULL << j)) {
17808                                         printf(first_pctype ?
17809                                                "%02d" : ",%02d", j);
17810                                         first_pctype = 0;
17811                                 }
17812                         }
17813                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17814                 }
17815         }
17816 #endif
17817 }
17818
17819 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17820         .f = cmd_pctype_mapping_get_parsed,
17821         .data = NULL,
17822         .help_str = "show port <port_id> pctype mapping",
17823         .tokens = {
17824                 (void *)&cmd_pctype_mapping_get_show,
17825                 (void *)&cmd_pctype_mapping_get_port,
17826                 (void *)&cmd_pctype_mapping_get_port_id,
17827                 (void *)&cmd_pctype_mapping_get_pctype,
17828                 (void *)&cmd_pctype_mapping_get_mapping,
17829                 NULL,
17830         },
17831 };
17832
17833 /* port config pctype mapping update */
17834
17835 /* Common result structure for port config pctype mapping update */
17836 struct cmd_pctype_mapping_update_result {
17837         cmdline_fixed_string_t port;
17838         cmdline_fixed_string_t config;
17839         portid_t port_id;
17840         cmdline_fixed_string_t pctype;
17841         cmdline_fixed_string_t mapping;
17842         cmdline_fixed_string_t update;
17843         cmdline_fixed_string_t pctype_list;
17844         uint16_t flow_type;
17845 };
17846
17847 /* Common CLI fields for pctype mapping update*/
17848 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17849         TOKEN_STRING_INITIALIZER
17850                 (struct cmd_pctype_mapping_update_result,
17851                  port, "port");
17852 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17853         TOKEN_STRING_INITIALIZER
17854                 (struct cmd_pctype_mapping_update_result,
17855                  config, "config");
17856 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17857         TOKEN_NUM_INITIALIZER
17858                 (struct cmd_pctype_mapping_update_result,
17859                  port_id, UINT16);
17860 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17861         TOKEN_STRING_INITIALIZER
17862                 (struct cmd_pctype_mapping_update_result,
17863                  pctype, "pctype");
17864 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17865         TOKEN_STRING_INITIALIZER
17866                 (struct cmd_pctype_mapping_update_result,
17867                  mapping, "mapping");
17868 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17869         TOKEN_STRING_INITIALIZER
17870                 (struct cmd_pctype_mapping_update_result,
17871                  update, "update");
17872 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17873         TOKEN_STRING_INITIALIZER
17874                 (struct cmd_pctype_mapping_update_result,
17875                  pctype_list, NULL);
17876 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17877         TOKEN_NUM_INITIALIZER
17878                 (struct cmd_pctype_mapping_update_result,
17879                  flow_type, UINT16);
17880
17881 static void
17882 cmd_pctype_mapping_update_parsed(
17883         void *parsed_result,
17884         __rte_unused struct cmdline *cl,
17885         __rte_unused void *data)
17886 {
17887         struct cmd_pctype_mapping_update_result *res = parsed_result;
17888         int ret = -ENOTSUP;
17889 #ifdef RTE_NET_I40E
17890         struct rte_pmd_i40e_flow_type_mapping mapping;
17891         unsigned int i;
17892         unsigned int nb_item;
17893         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17894 #endif
17895
17896         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17897                 return;
17898
17899 #ifdef RTE_NET_I40E
17900         nb_item = parse_item_list(res->pctype_list, "pctypes",
17901                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17902         mapping.flow_type = res->flow_type;
17903         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17904                 mapping.pctype |= (1ULL << pctype_list[i]);
17905         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17906                                                 &mapping,
17907                                                 1,
17908                                                 0);
17909 #endif
17910
17911         switch (ret) {
17912         case 0:
17913                 break;
17914         case -EINVAL:
17915                 printf("invalid pctype or flow type\n");
17916                 break;
17917         case -ENODEV:
17918                 printf("invalid port_id %d\n", res->port_id);
17919                 break;
17920         case -ENOTSUP:
17921                 printf("function not implemented\n");
17922                 break;
17923         default:
17924                 printf("programming error: (%s)\n", strerror(-ret));
17925         }
17926 }
17927
17928 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17929         .f = cmd_pctype_mapping_update_parsed,
17930         .data = NULL,
17931         .help_str = "port config <port_id> pctype mapping update"
17932         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17933         .tokens = {
17934                 (void *)&cmd_pctype_mapping_update_port,
17935                 (void *)&cmd_pctype_mapping_update_config,
17936                 (void *)&cmd_pctype_mapping_update_port_id,
17937                 (void *)&cmd_pctype_mapping_update_pctype,
17938                 (void *)&cmd_pctype_mapping_update_mapping,
17939                 (void *)&cmd_pctype_mapping_update_update,
17940                 (void *)&cmd_pctype_mapping_update_pc_type,
17941                 (void *)&cmd_pctype_mapping_update_flow_type,
17942                 NULL,
17943         },
17944 };
17945
17946 /* ptype mapping get */
17947
17948 /* Common result structure for ptype mapping get */
17949 struct cmd_ptype_mapping_get_result {
17950         cmdline_fixed_string_t ptype;
17951         cmdline_fixed_string_t mapping;
17952         cmdline_fixed_string_t get;
17953         portid_t port_id;
17954         uint8_t valid_only;
17955 };
17956
17957 /* Common CLI fields for ptype mapping get */
17958 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17959         TOKEN_STRING_INITIALIZER
17960                 (struct cmd_ptype_mapping_get_result,
17961                  ptype, "ptype");
17962 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17963         TOKEN_STRING_INITIALIZER
17964                 (struct cmd_ptype_mapping_get_result,
17965                  mapping, "mapping");
17966 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17967         TOKEN_STRING_INITIALIZER
17968                 (struct cmd_ptype_mapping_get_result,
17969                  get, "get");
17970 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17971         TOKEN_NUM_INITIALIZER
17972                 (struct cmd_ptype_mapping_get_result,
17973                  port_id, UINT16);
17974 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17975         TOKEN_NUM_INITIALIZER
17976                 (struct cmd_ptype_mapping_get_result,
17977                  valid_only, UINT8);
17978
17979 static void
17980 cmd_ptype_mapping_get_parsed(
17981         void *parsed_result,
17982         __rte_unused struct cmdline *cl,
17983         __rte_unused void *data)
17984 {
17985         struct cmd_ptype_mapping_get_result *res = parsed_result;
17986         int ret = -ENOTSUP;
17987 #ifdef RTE_NET_I40E
17988         int max_ptype_num = 256;
17989         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17990         uint16_t count;
17991         int i;
17992 #endif
17993
17994         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17995                 return;
17996
17997 #ifdef RTE_NET_I40E
17998         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17999                                         mapping,
18000                                         max_ptype_num,
18001                                         &count,
18002                                         res->valid_only);
18003 #endif
18004
18005         switch (ret) {
18006         case 0:
18007                 break;
18008         case -ENODEV:
18009                 printf("invalid port_id %d\n", res->port_id);
18010                 break;
18011         case -ENOTSUP:
18012                 printf("function not implemented\n");
18013                 break;
18014         default:
18015                 printf("programming error: (%s)\n", strerror(-ret));
18016         }
18017
18018 #ifdef RTE_NET_I40E
18019         if (!ret) {
18020                 for (i = 0; i < count; i++)
18021                         printf("%3d\t0x%08x\n",
18022                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
18023         }
18024 #endif
18025 }
18026
18027 cmdline_parse_inst_t cmd_ptype_mapping_get = {
18028         .f = cmd_ptype_mapping_get_parsed,
18029         .data = NULL,
18030         .help_str = "ptype mapping get <port_id> <valid_only>",
18031         .tokens = {
18032                 (void *)&cmd_ptype_mapping_get_ptype,
18033                 (void *)&cmd_ptype_mapping_get_mapping,
18034                 (void *)&cmd_ptype_mapping_get_get,
18035                 (void *)&cmd_ptype_mapping_get_port_id,
18036                 (void *)&cmd_ptype_mapping_get_valid_only,
18037                 NULL,
18038         },
18039 };
18040
18041 /* ptype mapping replace */
18042
18043 /* Common result structure for ptype mapping replace */
18044 struct cmd_ptype_mapping_replace_result {
18045         cmdline_fixed_string_t ptype;
18046         cmdline_fixed_string_t mapping;
18047         cmdline_fixed_string_t replace;
18048         portid_t port_id;
18049         uint32_t target;
18050         uint8_t mask;
18051         uint32_t pkt_type;
18052 };
18053
18054 /* Common CLI fields for ptype mapping replace */
18055 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
18056         TOKEN_STRING_INITIALIZER
18057                 (struct cmd_ptype_mapping_replace_result,
18058                  ptype, "ptype");
18059 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
18060         TOKEN_STRING_INITIALIZER
18061                 (struct cmd_ptype_mapping_replace_result,
18062                  mapping, "mapping");
18063 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
18064         TOKEN_STRING_INITIALIZER
18065                 (struct cmd_ptype_mapping_replace_result,
18066                  replace, "replace");
18067 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
18068         TOKEN_NUM_INITIALIZER
18069                 (struct cmd_ptype_mapping_replace_result,
18070                  port_id, UINT16);
18071 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
18072         TOKEN_NUM_INITIALIZER
18073                 (struct cmd_ptype_mapping_replace_result,
18074                  target, UINT32);
18075 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
18076         TOKEN_NUM_INITIALIZER
18077                 (struct cmd_ptype_mapping_replace_result,
18078                  mask, UINT8);
18079 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
18080         TOKEN_NUM_INITIALIZER
18081                 (struct cmd_ptype_mapping_replace_result,
18082                  pkt_type, UINT32);
18083
18084 static void
18085 cmd_ptype_mapping_replace_parsed(
18086         void *parsed_result,
18087         __rte_unused struct cmdline *cl,
18088         __rte_unused void *data)
18089 {
18090         struct cmd_ptype_mapping_replace_result *res = parsed_result;
18091         int ret = -ENOTSUP;
18092
18093         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18094                 return;
18095
18096 #ifdef RTE_NET_I40E
18097         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
18098                                         res->target,
18099                                         res->mask,
18100                                         res->pkt_type);
18101 #endif
18102
18103         switch (ret) {
18104         case 0:
18105                 break;
18106         case -EINVAL:
18107                 printf("invalid ptype 0x%8x or 0x%8x\n",
18108                                 res->target, res->pkt_type);
18109                 break;
18110         case -ENODEV:
18111                 printf("invalid port_id %d\n", res->port_id);
18112                 break;
18113         case -ENOTSUP:
18114                 printf("function not implemented\n");
18115                 break;
18116         default:
18117                 printf("programming error: (%s)\n", strerror(-ret));
18118         }
18119 }
18120
18121 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
18122         .f = cmd_ptype_mapping_replace_parsed,
18123         .data = NULL,
18124         .help_str =
18125                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
18126         .tokens = {
18127                 (void *)&cmd_ptype_mapping_replace_ptype,
18128                 (void *)&cmd_ptype_mapping_replace_mapping,
18129                 (void *)&cmd_ptype_mapping_replace_replace,
18130                 (void *)&cmd_ptype_mapping_replace_port_id,
18131                 (void *)&cmd_ptype_mapping_replace_target,
18132                 (void *)&cmd_ptype_mapping_replace_mask,
18133                 (void *)&cmd_ptype_mapping_replace_pkt_type,
18134                 NULL,
18135         },
18136 };
18137
18138 /* ptype mapping reset */
18139
18140 /* Common result structure for ptype mapping reset */
18141 struct cmd_ptype_mapping_reset_result {
18142         cmdline_fixed_string_t ptype;
18143         cmdline_fixed_string_t mapping;
18144         cmdline_fixed_string_t reset;
18145         portid_t port_id;
18146 };
18147
18148 /* Common CLI fields for ptype mapping reset*/
18149 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18150         TOKEN_STRING_INITIALIZER
18151                 (struct cmd_ptype_mapping_reset_result,
18152                  ptype, "ptype");
18153 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18154         TOKEN_STRING_INITIALIZER
18155                 (struct cmd_ptype_mapping_reset_result,
18156                  mapping, "mapping");
18157 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18158         TOKEN_STRING_INITIALIZER
18159                 (struct cmd_ptype_mapping_reset_result,
18160                  reset, "reset");
18161 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18162         TOKEN_NUM_INITIALIZER
18163                 (struct cmd_ptype_mapping_reset_result,
18164                  port_id, UINT16);
18165
18166 static void
18167 cmd_ptype_mapping_reset_parsed(
18168         void *parsed_result,
18169         __rte_unused struct cmdline *cl,
18170         __rte_unused void *data)
18171 {
18172         struct cmd_ptype_mapping_reset_result *res = parsed_result;
18173         int ret = -ENOTSUP;
18174
18175         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18176                 return;
18177
18178 #ifdef RTE_NET_I40E
18179         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18180 #endif
18181
18182         switch (ret) {
18183         case 0:
18184                 break;
18185         case -ENODEV:
18186                 printf("invalid port_id %d\n", res->port_id);
18187                 break;
18188         case -ENOTSUP:
18189                 printf("function not implemented\n");
18190                 break;
18191         default:
18192                 printf("programming error: (%s)\n", strerror(-ret));
18193         }
18194 }
18195
18196 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18197         .f = cmd_ptype_mapping_reset_parsed,
18198         .data = NULL,
18199         .help_str = "ptype mapping reset <port_id>",
18200         .tokens = {
18201                 (void *)&cmd_ptype_mapping_reset_ptype,
18202                 (void *)&cmd_ptype_mapping_reset_mapping,
18203                 (void *)&cmd_ptype_mapping_reset_reset,
18204                 (void *)&cmd_ptype_mapping_reset_port_id,
18205                 NULL,
18206         },
18207 };
18208
18209 /* ptype mapping update */
18210
18211 /* Common result structure for ptype mapping update */
18212 struct cmd_ptype_mapping_update_result {
18213         cmdline_fixed_string_t ptype;
18214         cmdline_fixed_string_t mapping;
18215         cmdline_fixed_string_t reset;
18216         portid_t port_id;
18217         uint8_t hw_ptype;
18218         uint32_t sw_ptype;
18219 };
18220
18221 /* Common CLI fields for ptype mapping update*/
18222 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18223         TOKEN_STRING_INITIALIZER
18224                 (struct cmd_ptype_mapping_update_result,
18225                  ptype, "ptype");
18226 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18227         TOKEN_STRING_INITIALIZER
18228                 (struct cmd_ptype_mapping_update_result,
18229                  mapping, "mapping");
18230 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18231         TOKEN_STRING_INITIALIZER
18232                 (struct cmd_ptype_mapping_update_result,
18233                  reset, "update");
18234 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18235         TOKEN_NUM_INITIALIZER
18236                 (struct cmd_ptype_mapping_update_result,
18237                  port_id, UINT16);
18238 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18239         TOKEN_NUM_INITIALIZER
18240                 (struct cmd_ptype_mapping_update_result,
18241                  hw_ptype, UINT8);
18242 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18243         TOKEN_NUM_INITIALIZER
18244                 (struct cmd_ptype_mapping_update_result,
18245                  sw_ptype, UINT32);
18246
18247 static void
18248 cmd_ptype_mapping_update_parsed(
18249         void *parsed_result,
18250         __rte_unused struct cmdline *cl,
18251         __rte_unused void *data)
18252 {
18253         struct cmd_ptype_mapping_update_result *res = parsed_result;
18254         int ret = -ENOTSUP;
18255 #ifdef RTE_NET_I40E
18256         struct rte_pmd_i40e_ptype_mapping mapping;
18257 #endif
18258         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18259                 return;
18260
18261 #ifdef RTE_NET_I40E
18262         mapping.hw_ptype = res->hw_ptype;
18263         mapping.sw_ptype = res->sw_ptype;
18264         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18265                                                 &mapping,
18266                                                 1,
18267                                                 0);
18268 #endif
18269
18270         switch (ret) {
18271         case 0:
18272                 break;
18273         case -EINVAL:
18274                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18275                 break;
18276         case -ENODEV:
18277                 printf("invalid port_id %d\n", res->port_id);
18278                 break;
18279         case -ENOTSUP:
18280                 printf("function not implemented\n");
18281                 break;
18282         default:
18283                 printf("programming error: (%s)\n", strerror(-ret));
18284         }
18285 }
18286
18287 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18288         .f = cmd_ptype_mapping_update_parsed,
18289         .data = NULL,
18290         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18291         .tokens = {
18292                 (void *)&cmd_ptype_mapping_update_ptype,
18293                 (void *)&cmd_ptype_mapping_update_mapping,
18294                 (void *)&cmd_ptype_mapping_update_update,
18295                 (void *)&cmd_ptype_mapping_update_port_id,
18296                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18297                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18298                 NULL,
18299         },
18300 };
18301
18302 /* Common result structure for file commands */
18303 struct cmd_cmdfile_result {
18304         cmdline_fixed_string_t load;
18305         cmdline_fixed_string_t filename;
18306 };
18307
18308 /* Common CLI fields for file commands */
18309 cmdline_parse_token_string_t cmd_load_cmdfile =
18310         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18311 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18312         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18313
18314 static void
18315 cmd_load_from_file_parsed(
18316         void *parsed_result,
18317         __rte_unused struct cmdline *cl,
18318         __rte_unused void *data)
18319 {
18320         struct cmd_cmdfile_result *res = parsed_result;
18321
18322         cmdline_read_from_file(res->filename);
18323 }
18324
18325 cmdline_parse_inst_t cmd_load_from_file = {
18326         .f = cmd_load_from_file_parsed,
18327         .data = NULL,
18328         .help_str = "load <filename>",
18329         .tokens = {
18330                 (void *)&cmd_load_cmdfile,
18331                 (void *)&cmd_load_cmdfile_filename,
18332                 NULL,
18333         },
18334 };
18335
18336 /* Get Rx offloads capabilities */
18337 struct cmd_rx_offload_get_capa_result {
18338         cmdline_fixed_string_t show;
18339         cmdline_fixed_string_t port;
18340         portid_t port_id;
18341         cmdline_fixed_string_t rx_offload;
18342         cmdline_fixed_string_t capabilities;
18343 };
18344
18345 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18346         TOKEN_STRING_INITIALIZER
18347                 (struct cmd_rx_offload_get_capa_result,
18348                  show, "show");
18349 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18350         TOKEN_STRING_INITIALIZER
18351                 (struct cmd_rx_offload_get_capa_result,
18352                  port, "port");
18353 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18354         TOKEN_NUM_INITIALIZER
18355                 (struct cmd_rx_offload_get_capa_result,
18356                  port_id, UINT16);
18357 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18358         TOKEN_STRING_INITIALIZER
18359                 (struct cmd_rx_offload_get_capa_result,
18360                  rx_offload, "rx_offload");
18361 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18362         TOKEN_STRING_INITIALIZER
18363                 (struct cmd_rx_offload_get_capa_result,
18364                  capabilities, "capabilities");
18365
18366 static void
18367 print_rx_offloads(uint64_t offloads)
18368 {
18369         uint64_t single_offload;
18370         int begin;
18371         int end;
18372         int bit;
18373
18374         if (offloads == 0)
18375                 return;
18376
18377         begin = __builtin_ctzll(offloads);
18378         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18379
18380         single_offload = 1ULL << begin;
18381         for (bit = begin; bit < end; bit++) {
18382                 if (offloads & single_offload)
18383                         printf(" %s",
18384                                rte_eth_dev_rx_offload_name(single_offload));
18385                 single_offload <<= 1;
18386         }
18387 }
18388
18389 static void
18390 cmd_rx_offload_get_capa_parsed(
18391         void *parsed_result,
18392         __rte_unused struct cmdline *cl,
18393         __rte_unused void *data)
18394 {
18395         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18396         struct rte_eth_dev_info dev_info;
18397         portid_t port_id = res->port_id;
18398         uint64_t queue_offloads;
18399         uint64_t port_offloads;
18400         int ret;
18401
18402         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18403         if (ret != 0)
18404                 return;
18405
18406         queue_offloads = dev_info.rx_queue_offload_capa;
18407         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18408
18409         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18410         printf("  Per Queue :");
18411         print_rx_offloads(queue_offloads);
18412
18413         printf("\n");
18414         printf("  Per Port  :");
18415         print_rx_offloads(port_offloads);
18416         printf("\n\n");
18417 }
18418
18419 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18420         .f = cmd_rx_offload_get_capa_parsed,
18421         .data = NULL,
18422         .help_str = "show port <port_id> rx_offload capabilities",
18423         .tokens = {
18424                 (void *)&cmd_rx_offload_get_capa_show,
18425                 (void *)&cmd_rx_offload_get_capa_port,
18426                 (void *)&cmd_rx_offload_get_capa_port_id,
18427                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18428                 (void *)&cmd_rx_offload_get_capa_capabilities,
18429                 NULL,
18430         }
18431 };
18432
18433 /* Get Rx offloads configuration */
18434 struct cmd_rx_offload_get_configuration_result {
18435         cmdline_fixed_string_t show;
18436         cmdline_fixed_string_t port;
18437         portid_t port_id;
18438         cmdline_fixed_string_t rx_offload;
18439         cmdline_fixed_string_t configuration;
18440 };
18441
18442 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18443         TOKEN_STRING_INITIALIZER
18444                 (struct cmd_rx_offload_get_configuration_result,
18445                  show, "show");
18446 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18447         TOKEN_STRING_INITIALIZER
18448                 (struct cmd_rx_offload_get_configuration_result,
18449                  port, "port");
18450 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18451         TOKEN_NUM_INITIALIZER
18452                 (struct cmd_rx_offload_get_configuration_result,
18453                  port_id, UINT16);
18454 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18455         TOKEN_STRING_INITIALIZER
18456                 (struct cmd_rx_offload_get_configuration_result,
18457                  rx_offload, "rx_offload");
18458 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18459         TOKEN_STRING_INITIALIZER
18460                 (struct cmd_rx_offload_get_configuration_result,
18461                  configuration, "configuration");
18462
18463 static void
18464 cmd_rx_offload_get_configuration_parsed(
18465         void *parsed_result,
18466         __rte_unused struct cmdline *cl,
18467         __rte_unused void *data)
18468 {
18469         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18470         struct rte_eth_dev_info dev_info;
18471         portid_t port_id = res->port_id;
18472         struct rte_port *port = &ports[port_id];
18473         uint64_t port_offloads;
18474         uint64_t queue_offloads;
18475         uint16_t nb_rx_queues;
18476         int q;
18477         int ret;
18478
18479         printf("Rx Offloading Configuration of port %d :\n", port_id);
18480
18481         port_offloads = port->dev_conf.rxmode.offloads;
18482         printf("  Port :");
18483         print_rx_offloads(port_offloads);
18484         printf("\n");
18485
18486         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18487         if (ret != 0)
18488                 return;
18489
18490         nb_rx_queues = dev_info.nb_rx_queues;
18491         for (q = 0; q < nb_rx_queues; q++) {
18492                 queue_offloads = port->rx_conf[q].offloads;
18493                 printf("  Queue[%2d] :", q);
18494                 print_rx_offloads(queue_offloads);
18495                 printf("\n");
18496         }
18497         printf("\n");
18498 }
18499
18500 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18501         .f = cmd_rx_offload_get_configuration_parsed,
18502         .data = NULL,
18503         .help_str = "show port <port_id> rx_offload configuration",
18504         .tokens = {
18505                 (void *)&cmd_rx_offload_get_configuration_show,
18506                 (void *)&cmd_rx_offload_get_configuration_port,
18507                 (void *)&cmd_rx_offload_get_configuration_port_id,
18508                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18509                 (void *)&cmd_rx_offload_get_configuration_configuration,
18510                 NULL,
18511         }
18512 };
18513
18514 /* Enable/Disable a per port offloading */
18515 struct cmd_config_per_port_rx_offload_result {
18516         cmdline_fixed_string_t port;
18517         cmdline_fixed_string_t config;
18518         portid_t port_id;
18519         cmdline_fixed_string_t rx_offload;
18520         cmdline_fixed_string_t offload;
18521         cmdline_fixed_string_t on_off;
18522 };
18523
18524 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18525         TOKEN_STRING_INITIALIZER
18526                 (struct cmd_config_per_port_rx_offload_result,
18527                  port, "port");
18528 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18529         TOKEN_STRING_INITIALIZER
18530                 (struct cmd_config_per_port_rx_offload_result,
18531                  config, "config");
18532 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18533         TOKEN_NUM_INITIALIZER
18534                 (struct cmd_config_per_port_rx_offload_result,
18535                  port_id, UINT16);
18536 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18537         TOKEN_STRING_INITIALIZER
18538                 (struct cmd_config_per_port_rx_offload_result,
18539                  rx_offload, "rx_offload");
18540 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18541         TOKEN_STRING_INITIALIZER
18542                 (struct cmd_config_per_port_rx_offload_result,
18543                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18544                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18545                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18546                            "scatter#buffer_split#timestamp#security#"
18547                            "keep_crc#rss_hash");
18548 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18549         TOKEN_STRING_INITIALIZER
18550                 (struct cmd_config_per_port_rx_offload_result,
18551                  on_off, "on#off");
18552
18553 static uint64_t
18554 search_rx_offload(const char *name)
18555 {
18556         uint64_t single_offload;
18557         const char *single_name;
18558         int found = 0;
18559         unsigned int bit;
18560
18561         single_offload = 1;
18562         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18563                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18564                 if (!strcasecmp(single_name, name)) {
18565                         found = 1;
18566                         break;
18567                 }
18568                 single_offload <<= 1;
18569         }
18570
18571         if (found)
18572                 return single_offload;
18573
18574         return 0;
18575 }
18576
18577 static void
18578 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18579                                 __rte_unused struct cmdline *cl,
18580                                 __rte_unused void *data)
18581 {
18582         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18583         portid_t port_id = res->port_id;
18584         struct rte_eth_dev_info dev_info;
18585         struct rte_port *port = &ports[port_id];
18586         uint64_t single_offload;
18587         uint16_t nb_rx_queues;
18588         int q;
18589         int ret;
18590
18591         if (port->port_status != RTE_PORT_STOPPED) {
18592                 printf("Error: Can't config offload when Port %d "
18593                        "is not stopped\n", port_id);
18594                 return;
18595         }
18596
18597         single_offload = search_rx_offload(res->offload);
18598         if (single_offload == 0) {
18599                 printf("Unknown offload name: %s\n", res->offload);
18600                 return;
18601         }
18602
18603         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18604         if (ret != 0)
18605                 return;
18606
18607         nb_rx_queues = dev_info.nb_rx_queues;
18608         if (!strcmp(res->on_off, "on")) {
18609                 port->dev_conf.rxmode.offloads |= single_offload;
18610                 for (q = 0; q < nb_rx_queues; q++)
18611                         port->rx_conf[q].offloads |= single_offload;
18612         } else {
18613                 port->dev_conf.rxmode.offloads &= ~single_offload;
18614                 for (q = 0; q < nb_rx_queues; q++)
18615                         port->rx_conf[q].offloads &= ~single_offload;
18616         }
18617
18618         cmd_reconfig_device_queue(port_id, 1, 1);
18619 }
18620
18621 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18622         .f = cmd_config_per_port_rx_offload_parsed,
18623         .data = NULL,
18624         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18625                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18626                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18627                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18628                     "keep_crc|rss_hash on|off",
18629         .tokens = {
18630                 (void *)&cmd_config_per_port_rx_offload_result_port,
18631                 (void *)&cmd_config_per_port_rx_offload_result_config,
18632                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18633                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18634                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18635                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18636                 NULL,
18637         }
18638 };
18639
18640 /* Enable/Disable a per queue offloading */
18641 struct cmd_config_per_queue_rx_offload_result {
18642         cmdline_fixed_string_t port;
18643         portid_t port_id;
18644         cmdline_fixed_string_t rxq;
18645         uint16_t queue_id;
18646         cmdline_fixed_string_t rx_offload;
18647         cmdline_fixed_string_t offload;
18648         cmdline_fixed_string_t on_off;
18649 };
18650
18651 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18652         TOKEN_STRING_INITIALIZER
18653                 (struct cmd_config_per_queue_rx_offload_result,
18654                  port, "port");
18655 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18656         TOKEN_NUM_INITIALIZER
18657                 (struct cmd_config_per_queue_rx_offload_result,
18658                  port_id, UINT16);
18659 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18660         TOKEN_STRING_INITIALIZER
18661                 (struct cmd_config_per_queue_rx_offload_result,
18662                  rxq, "rxq");
18663 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18664         TOKEN_NUM_INITIALIZER
18665                 (struct cmd_config_per_queue_rx_offload_result,
18666                  queue_id, UINT16);
18667 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18668         TOKEN_STRING_INITIALIZER
18669                 (struct cmd_config_per_queue_rx_offload_result,
18670                  rx_offload, "rx_offload");
18671 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18672         TOKEN_STRING_INITIALIZER
18673                 (struct cmd_config_per_queue_rx_offload_result,
18674                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18675                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18676                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18677                            "scatter#buffer_split#timestamp#security#keep_crc");
18678 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18679         TOKEN_STRING_INITIALIZER
18680                 (struct cmd_config_per_queue_rx_offload_result,
18681                  on_off, "on#off");
18682
18683 static void
18684 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18685                                 __rte_unused struct cmdline *cl,
18686                                 __rte_unused void *data)
18687 {
18688         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18689         struct rte_eth_dev_info dev_info;
18690         portid_t port_id = res->port_id;
18691         uint16_t queue_id = res->queue_id;
18692         struct rte_port *port = &ports[port_id];
18693         uint64_t single_offload;
18694         int ret;
18695
18696         if (port->port_status != RTE_PORT_STOPPED) {
18697                 printf("Error: Can't config offload when Port %d "
18698                        "is not stopped\n", port_id);
18699                 return;
18700         }
18701
18702         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18703         if (ret != 0)
18704                 return;
18705
18706         if (queue_id >= dev_info.nb_rx_queues) {
18707                 printf("Error: input queue_id should be 0 ... "
18708                        "%d\n", dev_info.nb_rx_queues - 1);
18709                 return;
18710         }
18711
18712         single_offload = search_rx_offload(res->offload);
18713         if (single_offload == 0) {
18714                 printf("Unknown offload name: %s\n", res->offload);
18715                 return;
18716         }
18717
18718         if (!strcmp(res->on_off, "on"))
18719                 port->rx_conf[queue_id].offloads |= single_offload;
18720         else
18721                 port->rx_conf[queue_id].offloads &= ~single_offload;
18722
18723         cmd_reconfig_device_queue(port_id, 1, 1);
18724 }
18725
18726 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18727         .f = cmd_config_per_queue_rx_offload_parsed,
18728         .data = NULL,
18729         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18730                     "vlan_strip|ipv4_cksum|"
18731                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18732                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18733                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18734                     "keep_crc on|off",
18735         .tokens = {
18736                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18737                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18738                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18739                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18740                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18741                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18742                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18743                 NULL,
18744         }
18745 };
18746
18747 /* Get Tx offloads capabilities */
18748 struct cmd_tx_offload_get_capa_result {
18749         cmdline_fixed_string_t show;
18750         cmdline_fixed_string_t port;
18751         portid_t port_id;
18752         cmdline_fixed_string_t tx_offload;
18753         cmdline_fixed_string_t capabilities;
18754 };
18755
18756 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18757         TOKEN_STRING_INITIALIZER
18758                 (struct cmd_tx_offload_get_capa_result,
18759                  show, "show");
18760 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18761         TOKEN_STRING_INITIALIZER
18762                 (struct cmd_tx_offload_get_capa_result,
18763                  port, "port");
18764 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18765         TOKEN_NUM_INITIALIZER
18766                 (struct cmd_tx_offload_get_capa_result,
18767                  port_id, UINT16);
18768 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18769         TOKEN_STRING_INITIALIZER
18770                 (struct cmd_tx_offload_get_capa_result,
18771                  tx_offload, "tx_offload");
18772 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18773         TOKEN_STRING_INITIALIZER
18774                 (struct cmd_tx_offload_get_capa_result,
18775                  capabilities, "capabilities");
18776
18777 static void
18778 print_tx_offloads(uint64_t offloads)
18779 {
18780         uint64_t single_offload;
18781         int begin;
18782         int end;
18783         int bit;
18784
18785         if (offloads == 0)
18786                 return;
18787
18788         begin = __builtin_ctzll(offloads);
18789         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18790
18791         single_offload = 1ULL << begin;
18792         for (bit = begin; bit < end; bit++) {
18793                 if (offloads & single_offload)
18794                         printf(" %s",
18795                                rte_eth_dev_tx_offload_name(single_offload));
18796                 single_offload <<= 1;
18797         }
18798 }
18799
18800 static void
18801 cmd_tx_offload_get_capa_parsed(
18802         void *parsed_result,
18803         __rte_unused struct cmdline *cl,
18804         __rte_unused void *data)
18805 {
18806         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18807         struct rte_eth_dev_info dev_info;
18808         portid_t port_id = res->port_id;
18809         uint64_t queue_offloads;
18810         uint64_t port_offloads;
18811         int ret;
18812
18813         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18814         if (ret != 0)
18815                 return;
18816
18817         queue_offloads = dev_info.tx_queue_offload_capa;
18818         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18819
18820         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18821         printf("  Per Queue :");
18822         print_tx_offloads(queue_offloads);
18823
18824         printf("\n");
18825         printf("  Per Port  :");
18826         print_tx_offloads(port_offloads);
18827         printf("\n\n");
18828 }
18829
18830 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18831         .f = cmd_tx_offload_get_capa_parsed,
18832         .data = NULL,
18833         .help_str = "show port <port_id> tx_offload capabilities",
18834         .tokens = {
18835                 (void *)&cmd_tx_offload_get_capa_show,
18836                 (void *)&cmd_tx_offload_get_capa_port,
18837                 (void *)&cmd_tx_offload_get_capa_port_id,
18838                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18839                 (void *)&cmd_tx_offload_get_capa_capabilities,
18840                 NULL,
18841         }
18842 };
18843
18844 /* Get Tx offloads configuration */
18845 struct cmd_tx_offload_get_configuration_result {
18846         cmdline_fixed_string_t show;
18847         cmdline_fixed_string_t port;
18848         portid_t port_id;
18849         cmdline_fixed_string_t tx_offload;
18850         cmdline_fixed_string_t configuration;
18851 };
18852
18853 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18854         TOKEN_STRING_INITIALIZER
18855                 (struct cmd_tx_offload_get_configuration_result,
18856                  show, "show");
18857 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18858         TOKEN_STRING_INITIALIZER
18859                 (struct cmd_tx_offload_get_configuration_result,
18860                  port, "port");
18861 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18862         TOKEN_NUM_INITIALIZER
18863                 (struct cmd_tx_offload_get_configuration_result,
18864                  port_id, UINT16);
18865 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18866         TOKEN_STRING_INITIALIZER
18867                 (struct cmd_tx_offload_get_configuration_result,
18868                  tx_offload, "tx_offload");
18869 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18870         TOKEN_STRING_INITIALIZER
18871                 (struct cmd_tx_offload_get_configuration_result,
18872                  configuration, "configuration");
18873
18874 static void
18875 cmd_tx_offload_get_configuration_parsed(
18876         void *parsed_result,
18877         __rte_unused struct cmdline *cl,
18878         __rte_unused void *data)
18879 {
18880         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18881         struct rte_eth_dev_info dev_info;
18882         portid_t port_id = res->port_id;
18883         struct rte_port *port = &ports[port_id];
18884         uint64_t port_offloads;
18885         uint64_t queue_offloads;
18886         uint16_t nb_tx_queues;
18887         int q;
18888         int ret;
18889
18890         printf("Tx Offloading Configuration of port %d :\n", port_id);
18891
18892         port_offloads = port->dev_conf.txmode.offloads;
18893         printf("  Port :");
18894         print_tx_offloads(port_offloads);
18895         printf("\n");
18896
18897         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18898         if (ret != 0)
18899                 return;
18900
18901         nb_tx_queues = dev_info.nb_tx_queues;
18902         for (q = 0; q < nb_tx_queues; q++) {
18903                 queue_offloads = port->tx_conf[q].offloads;
18904                 printf("  Queue[%2d] :", q);
18905                 print_tx_offloads(queue_offloads);
18906                 printf("\n");
18907         }
18908         printf("\n");
18909 }
18910
18911 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18912         .f = cmd_tx_offload_get_configuration_parsed,
18913         .data = NULL,
18914         .help_str = "show port <port_id> tx_offload configuration",
18915         .tokens = {
18916                 (void *)&cmd_tx_offload_get_configuration_show,
18917                 (void *)&cmd_tx_offload_get_configuration_port,
18918                 (void *)&cmd_tx_offload_get_configuration_port_id,
18919                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18920                 (void *)&cmd_tx_offload_get_configuration_configuration,
18921                 NULL,
18922         }
18923 };
18924
18925 /* Enable/Disable a per port offloading */
18926 struct cmd_config_per_port_tx_offload_result {
18927         cmdline_fixed_string_t port;
18928         cmdline_fixed_string_t config;
18929         portid_t port_id;
18930         cmdline_fixed_string_t tx_offload;
18931         cmdline_fixed_string_t offload;
18932         cmdline_fixed_string_t on_off;
18933 };
18934
18935 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18936         TOKEN_STRING_INITIALIZER
18937                 (struct cmd_config_per_port_tx_offload_result,
18938                  port, "port");
18939 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18940         TOKEN_STRING_INITIALIZER
18941                 (struct cmd_config_per_port_tx_offload_result,
18942                  config, "config");
18943 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18944         TOKEN_NUM_INITIALIZER
18945                 (struct cmd_config_per_port_tx_offload_result,
18946                  port_id, UINT16);
18947 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18948         TOKEN_STRING_INITIALIZER
18949                 (struct cmd_config_per_port_tx_offload_result,
18950                  tx_offload, "tx_offload");
18951 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18952         TOKEN_STRING_INITIALIZER
18953                 (struct cmd_config_per_port_tx_offload_result,
18954                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18955                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18956                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18957                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18958                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18959                           "send_on_timestamp");
18960 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18961         TOKEN_STRING_INITIALIZER
18962                 (struct cmd_config_per_port_tx_offload_result,
18963                  on_off, "on#off");
18964
18965 static uint64_t
18966 search_tx_offload(const char *name)
18967 {
18968         uint64_t single_offload;
18969         const char *single_name;
18970         int found = 0;
18971         unsigned int bit;
18972
18973         single_offload = 1;
18974         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18975                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18976                 if (single_name == NULL)
18977                         break;
18978                 if (!strcasecmp(single_name, name)) {
18979                         found = 1;
18980                         break;
18981                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18982                         break;
18983                 single_offload <<= 1;
18984         }
18985
18986         if (found)
18987                 return single_offload;
18988
18989         return 0;
18990 }
18991
18992 static void
18993 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18994                                 __rte_unused struct cmdline *cl,
18995                                 __rte_unused void *data)
18996 {
18997         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18998         portid_t port_id = res->port_id;
18999         struct rte_eth_dev_info dev_info;
19000         struct rte_port *port = &ports[port_id];
19001         uint64_t single_offload;
19002         uint16_t nb_tx_queues;
19003         int q;
19004         int ret;
19005
19006         if (port->port_status != RTE_PORT_STOPPED) {
19007                 printf("Error: Can't config offload when Port %d "
19008                        "is not stopped\n", port_id);
19009                 return;
19010         }
19011
19012         single_offload = search_tx_offload(res->offload);
19013         if (single_offload == 0) {
19014                 printf("Unknown offload name: %s\n", res->offload);
19015                 return;
19016         }
19017
19018         ret = eth_dev_info_get_print_err(port_id, &dev_info);
19019         if (ret != 0)
19020                 return;
19021
19022         nb_tx_queues = dev_info.nb_tx_queues;
19023         if (!strcmp(res->on_off, "on")) {
19024                 port->dev_conf.txmode.offloads |= single_offload;
19025                 for (q = 0; q < nb_tx_queues; q++)
19026                         port->tx_conf[q].offloads |= single_offload;
19027         } else {
19028                 port->dev_conf.txmode.offloads &= ~single_offload;
19029                 for (q = 0; q < nb_tx_queues; q++)
19030                         port->tx_conf[q].offloads &= ~single_offload;
19031         }
19032
19033         cmd_reconfig_device_queue(port_id, 1, 1);
19034 }
19035
19036 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
19037         .f = cmd_config_per_port_tx_offload_parsed,
19038         .data = NULL,
19039         .help_str = "port config <port_id> tx_offload "
19040                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19041                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19042                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19043                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19044                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
19045                     "send_on_timestamp on|off",
19046         .tokens = {
19047                 (void *)&cmd_config_per_port_tx_offload_result_port,
19048                 (void *)&cmd_config_per_port_tx_offload_result_config,
19049                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
19050                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
19051                 (void *)&cmd_config_per_port_tx_offload_result_offload,
19052                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
19053                 NULL,
19054         }
19055 };
19056
19057 /* Enable/Disable a per queue offloading */
19058 struct cmd_config_per_queue_tx_offload_result {
19059         cmdline_fixed_string_t port;
19060         portid_t port_id;
19061         cmdline_fixed_string_t txq;
19062         uint16_t queue_id;
19063         cmdline_fixed_string_t tx_offload;
19064         cmdline_fixed_string_t offload;
19065         cmdline_fixed_string_t on_off;
19066 };
19067
19068 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
19069         TOKEN_STRING_INITIALIZER
19070                 (struct cmd_config_per_queue_tx_offload_result,
19071                  port, "port");
19072 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
19073         TOKEN_NUM_INITIALIZER
19074                 (struct cmd_config_per_queue_tx_offload_result,
19075                  port_id, UINT16);
19076 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
19077         TOKEN_STRING_INITIALIZER
19078                 (struct cmd_config_per_queue_tx_offload_result,
19079                  txq, "txq");
19080 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
19081         TOKEN_NUM_INITIALIZER
19082                 (struct cmd_config_per_queue_tx_offload_result,
19083                  queue_id, UINT16);
19084 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
19085         TOKEN_STRING_INITIALIZER
19086                 (struct cmd_config_per_queue_tx_offload_result,
19087                  tx_offload, "tx_offload");
19088 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
19089         TOKEN_STRING_INITIALIZER
19090                 (struct cmd_config_per_queue_tx_offload_result,
19091                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
19092                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
19093                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
19094                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
19095                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
19096 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
19097         TOKEN_STRING_INITIALIZER
19098                 (struct cmd_config_per_queue_tx_offload_result,
19099                  on_off, "on#off");
19100
19101 static void
19102 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
19103                                 __rte_unused struct cmdline *cl,
19104                                 __rte_unused void *data)
19105 {
19106         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
19107         struct rte_eth_dev_info dev_info;
19108         portid_t port_id = res->port_id;
19109         uint16_t queue_id = res->queue_id;
19110         struct rte_port *port = &ports[port_id];
19111         uint64_t single_offload;
19112         int ret;
19113
19114         if (port->port_status != RTE_PORT_STOPPED) {
19115                 printf("Error: Can't config offload when Port %d "
19116                        "is not stopped\n", port_id);
19117                 return;
19118         }
19119
19120         ret = eth_dev_info_get_print_err(port_id, &dev_info);
19121         if (ret != 0)
19122                 return;
19123
19124         if (queue_id >= dev_info.nb_tx_queues) {
19125                 printf("Error: input queue_id should be 0 ... "
19126                        "%d\n", dev_info.nb_tx_queues - 1);
19127                 return;
19128         }
19129
19130         single_offload = search_tx_offload(res->offload);
19131         if (single_offload == 0) {
19132                 printf("Unknown offload name: %s\n", res->offload);
19133                 return;
19134         }
19135
19136         if (!strcmp(res->on_off, "on"))
19137                 port->tx_conf[queue_id].offloads |= single_offload;
19138         else
19139                 port->tx_conf[queue_id].offloads &= ~single_offload;
19140
19141         cmd_reconfig_device_queue(port_id, 1, 1);
19142 }
19143
19144 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19145         .f = cmd_config_per_queue_tx_offload_parsed,
19146         .data = NULL,
19147         .help_str = "port <port_id> txq <queue_id> tx_offload "
19148                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19149                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19150                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19151                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19152                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
19153                     "on|off",
19154         .tokens = {
19155                 (void *)&cmd_config_per_queue_tx_offload_result_port,
19156                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
19157                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
19158                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19159                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19160                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
19161                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
19162                 NULL,
19163         }
19164 };
19165
19166 /* *** configure tx_metadata for specific port *** */
19167 struct cmd_config_tx_metadata_specific_result {
19168         cmdline_fixed_string_t port;
19169         cmdline_fixed_string_t keyword;
19170         uint16_t port_id;
19171         cmdline_fixed_string_t item;
19172         uint32_t value;
19173 };
19174
19175 static void
19176 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19177                                 __rte_unused struct cmdline *cl,
19178                                 __rte_unused void *data)
19179 {
19180         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19181
19182         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19183                 return;
19184         ports[res->port_id].tx_metadata = res->value;
19185         /* Add/remove callback to insert valid metadata in every Tx packet. */
19186         if (ports[res->port_id].tx_metadata)
19187                 add_tx_md_callback(res->port_id);
19188         else
19189                 remove_tx_md_callback(res->port_id);
19190         rte_flow_dynf_metadata_register();
19191 }
19192
19193 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19194         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19195                         port, "port");
19196 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19197         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19198                         keyword, "config");
19199 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19200         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19201                         port_id, UINT16);
19202 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19203         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19204                         item, "tx_metadata");
19205 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19206         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19207                         value, UINT32);
19208
19209 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19210         .f = cmd_config_tx_metadata_specific_parsed,
19211         .data = NULL,
19212         .help_str = "port config <port_id> tx_metadata <value>",
19213         .tokens = {
19214                 (void *)&cmd_config_tx_metadata_specific_port,
19215                 (void *)&cmd_config_tx_metadata_specific_keyword,
19216                 (void *)&cmd_config_tx_metadata_specific_id,
19217                 (void *)&cmd_config_tx_metadata_specific_item,
19218                 (void *)&cmd_config_tx_metadata_specific_value,
19219                 NULL,
19220         },
19221 };
19222
19223 /* *** set dynf *** */
19224 struct cmd_config_tx_dynf_specific_result {
19225         cmdline_fixed_string_t port;
19226         cmdline_fixed_string_t keyword;
19227         uint16_t port_id;
19228         cmdline_fixed_string_t item;
19229         cmdline_fixed_string_t name;
19230         cmdline_fixed_string_t value;
19231 };
19232
19233 static void
19234 cmd_config_dynf_specific_parsed(void *parsed_result,
19235                                 __rte_unused struct cmdline *cl,
19236                                 __rte_unused void *data)
19237 {
19238         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19239         struct rte_mbuf_dynflag desc_flag;
19240         int flag;
19241         uint64_t old_port_flags;
19242
19243         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19244                 return;
19245         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19246         if (flag <= 0) {
19247                 if (strlcpy(desc_flag.name, res->name,
19248                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19249                         printf("Flag name too long\n");
19250                         return;
19251                 }
19252                 desc_flag.flags = 0;
19253                 flag = rte_mbuf_dynflag_register(&desc_flag);
19254                 if (flag < 0) {
19255                         printf("Can't register flag\n");
19256                         return;
19257                 }
19258                 strcpy(dynf_names[flag], desc_flag.name);
19259         }
19260         old_port_flags = ports[res->port_id].mbuf_dynf;
19261         if (!strcmp(res->value, "set")) {
19262                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19263                 if (old_port_flags == 0)
19264                         add_tx_dynf_callback(res->port_id);
19265         } else {
19266                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19267                 if (ports[res->port_id].mbuf_dynf == 0)
19268                         remove_tx_dynf_callback(res->port_id);
19269         }
19270 }
19271
19272 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19273         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19274                         keyword, "port");
19275 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19276         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19277                         keyword, "config");
19278 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19279         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19280                         port_id, UINT16);
19281 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19282         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19283                         item, "dynf");
19284 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19285         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19286                         name, NULL);
19287 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19288         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19289                         value, "set#clear");
19290
19291 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19292         .f = cmd_config_dynf_specific_parsed,
19293         .data = NULL,
19294         .help_str = "port config <port id> dynf <name> set|clear",
19295         .tokens = {
19296                 (void *)&cmd_config_tx_dynf_specific_port,
19297                 (void *)&cmd_config_tx_dynf_specific_keyword,
19298                 (void *)&cmd_config_tx_dynf_specific_port_id,
19299                 (void *)&cmd_config_tx_dynf_specific_item,
19300                 (void *)&cmd_config_tx_dynf_specific_name,
19301                 (void *)&cmd_config_tx_dynf_specific_value,
19302                 NULL,
19303         },
19304 };
19305
19306 /* *** display tx_metadata per port configuration *** */
19307 struct cmd_show_tx_metadata_result {
19308         cmdline_fixed_string_t cmd_show;
19309         cmdline_fixed_string_t cmd_port;
19310         cmdline_fixed_string_t cmd_keyword;
19311         portid_t cmd_pid;
19312 };
19313
19314 static void
19315 cmd_show_tx_metadata_parsed(void *parsed_result,
19316                 __rte_unused struct cmdline *cl,
19317                 __rte_unused void *data)
19318 {
19319         struct cmd_show_tx_metadata_result *res = parsed_result;
19320
19321         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19322                 printf("invalid port id %u\n", res->cmd_pid);
19323                 return;
19324         }
19325         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19326                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19327                        ports[res->cmd_pid].tx_metadata);
19328         }
19329 }
19330
19331 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19332         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19333                         cmd_show, "show");
19334 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19335         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19336                         cmd_port, "port");
19337 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19338         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19339                         cmd_pid, UINT16);
19340 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19341         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19342                         cmd_keyword, "tx_metadata");
19343
19344 cmdline_parse_inst_t cmd_show_tx_metadata = {
19345         .f = cmd_show_tx_metadata_parsed,
19346         .data = NULL,
19347         .help_str = "show port <port_id> tx_metadata",
19348         .tokens = {
19349                 (void *)&cmd_show_tx_metadata_show,
19350                 (void *)&cmd_show_tx_metadata_port,
19351                 (void *)&cmd_show_tx_metadata_pid,
19352                 (void *)&cmd_show_tx_metadata_keyword,
19353                 NULL,
19354         },
19355 };
19356
19357 /* *** show fec capability per port configuration *** */
19358 struct cmd_show_fec_capability_result {
19359         cmdline_fixed_string_t cmd_show;
19360         cmdline_fixed_string_t cmd_port;
19361         cmdline_fixed_string_t cmd_fec;
19362         cmdline_fixed_string_t cmd_keyword;
19363         portid_t cmd_pid;
19364 };
19365
19366 static void
19367 cmd_show_fec_capability_parsed(void *parsed_result,
19368                 __rte_unused struct cmdline *cl,
19369                 __rte_unused void *data)
19370 {
19371 #define FEC_CAP_NUM 2
19372         struct cmd_show_fec_capability_result *res = parsed_result;
19373         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19374         unsigned int num = FEC_CAP_NUM;
19375         unsigned int ret_num;
19376         int ret;
19377
19378         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19379                 printf("Invalid port id %u\n", res->cmd_pid);
19380                 return;
19381         }
19382
19383         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19384         if (ret == -ENOTSUP) {
19385                 printf("Function not implemented\n");
19386                 return;
19387         } else if (ret < 0) {
19388                 printf("Get FEC capability failed\n");
19389                 return;
19390         }
19391
19392         ret_num = (unsigned int)ret;
19393         show_fec_capability(ret_num, speed_fec_capa);
19394 }
19395
19396 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19397         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19398                         cmd_show, "show");
19399 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19400         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19401                         cmd_port, "port");
19402 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19403         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19404                         cmd_pid, UINT16);
19405 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19406         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19407                         cmd_fec, "fec");
19408 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19409         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19410                         cmd_keyword, "capabilities");
19411
19412 cmdline_parse_inst_t cmd_show_capability = {
19413         .f = cmd_show_fec_capability_parsed,
19414         .data = NULL,
19415         .help_str = "show port <port_id> fec capabilities",
19416         .tokens = {
19417                 (void *)&cmd_show_fec_capability_show,
19418                 (void *)&cmd_show_fec_capability_port,
19419                 (void *)&cmd_show_fec_capability_pid,
19420                 (void *)&cmd_show_fec_capability_fec,
19421                 (void *)&cmd_show_fec_capability_keyword,
19422                 NULL,
19423         },
19424 };
19425
19426 /* *** show fec mode per port configuration *** */
19427 struct cmd_show_fec_metadata_result {
19428         cmdline_fixed_string_t cmd_show;
19429         cmdline_fixed_string_t cmd_port;
19430         cmdline_fixed_string_t cmd_keyword;
19431         portid_t cmd_pid;
19432 };
19433
19434 static void
19435 cmd_show_fec_mode_parsed(void *parsed_result,
19436                 __rte_unused struct cmdline *cl,
19437                 __rte_unused void *data)
19438 {
19439 #define FEC_NAME_SIZE 16
19440         struct cmd_show_fec_metadata_result *res = parsed_result;
19441         uint32_t mode;
19442         char buf[FEC_NAME_SIZE];
19443         int ret;
19444
19445         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19446                 printf("Invalid port id %u\n", res->cmd_pid);
19447                 return;
19448         }
19449         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19450         if (ret == -ENOTSUP) {
19451                 printf("Function not implemented\n");
19452                 return;
19453         } else if (ret < 0) {
19454                 printf("Get FEC mode failed\n");
19455                 return;
19456         }
19457
19458         switch (mode) {
19459         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19460                 strlcpy(buf, "off", sizeof(buf));
19461                 break;
19462         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19463                 strlcpy(buf, "auto", sizeof(buf));
19464                 break;
19465         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19466                 strlcpy(buf, "baser", sizeof(buf));
19467                 break;
19468         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19469                 strlcpy(buf, "rs", sizeof(buf));
19470                 break;
19471         default:
19472                 return;
19473         }
19474
19475         printf("%s\n", buf);
19476 }
19477
19478 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19479         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19480                         cmd_show, "show");
19481 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19482         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19483                         cmd_port, "port");
19484 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19485         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19486                         cmd_pid, UINT16);
19487 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19488         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19489                         cmd_keyword, "fec_mode");
19490
19491 cmdline_parse_inst_t cmd_show_fec_mode = {
19492         .f = cmd_show_fec_mode_parsed,
19493         .data = NULL,
19494         .help_str = "show port <port_id> fec_mode",
19495         .tokens = {
19496                 (void *)&cmd_show_fec_mode_show,
19497                 (void *)&cmd_show_fec_mode_port,
19498                 (void *)&cmd_show_fec_mode_pid,
19499                 (void *)&cmd_show_fec_mode_keyword,
19500                 NULL,
19501         },
19502 };
19503
19504 /* *** set fec mode per port configuration *** */
19505 struct cmd_set_port_fec_mode {
19506         cmdline_fixed_string_t set;
19507         cmdline_fixed_string_t port;
19508         portid_t port_id;
19509         cmdline_fixed_string_t fec_mode;
19510         cmdline_fixed_string_t fec_value;
19511 };
19512
19513 /* Common CLI fields for set fec mode */
19514 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19515         TOKEN_STRING_INITIALIZER
19516                 (struct cmd_set_port_fec_mode,
19517                  set, "set");
19518 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19519         TOKEN_STRING_INITIALIZER
19520                 (struct cmd_set_port_fec_mode,
19521                  port, "port");
19522 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19523         TOKEN_NUM_INITIALIZER
19524                 (struct cmd_set_port_fec_mode,
19525                  port_id, UINT16);
19526 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19527         TOKEN_STRING_INITIALIZER
19528                 (struct cmd_set_port_fec_mode,
19529                  fec_mode, "fec_mode");
19530 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19531         TOKEN_STRING_INITIALIZER
19532                 (struct cmd_set_port_fec_mode,
19533                  fec_value, NULL);
19534
19535 static void
19536 cmd_set_port_fec_mode_parsed(
19537         void *parsed_result,
19538         __rte_unused struct cmdline *cl,
19539         __rte_unused void *data)
19540 {
19541         struct cmd_set_port_fec_mode *res = parsed_result;
19542         uint16_t port_id = res->port_id;
19543         uint32_t mode;
19544         int ret;
19545
19546         ret = parse_fec_mode(res->fec_value, &mode);
19547         if (ret < 0) {
19548                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19549                         port_id);
19550                 return;
19551         }
19552
19553         ret = rte_eth_fec_set(port_id, mode);
19554         if (ret == -ENOTSUP) {
19555                 printf("Function not implemented\n");
19556                 return;
19557         } else if (ret < 0) {
19558                 printf("Set FEC mode failed\n");
19559                 return;
19560         }
19561 }
19562
19563 cmdline_parse_inst_t cmd_set_fec_mode = {
19564         .f = cmd_set_port_fec_mode_parsed,
19565         .data = NULL,
19566         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19567         .tokens = {
19568                 (void *)&cmd_set_port_fec_mode_set,
19569                 (void *)&cmd_set_port_fec_mode_port,
19570                 (void *)&cmd_set_port_fec_mode_port_id,
19571                 (void *)&cmd_set_port_fec_mode_str,
19572                 (void *)&cmd_set_port_fec_mode_value,
19573                 NULL,
19574         },
19575 };
19576
19577 /* show port supported ptypes */
19578
19579 /* Common result structure for show port ptypes */
19580 struct cmd_show_port_supported_ptypes_result {
19581         cmdline_fixed_string_t show;
19582         cmdline_fixed_string_t port;
19583         portid_t port_id;
19584         cmdline_fixed_string_t ptypes;
19585 };
19586
19587 /* Common CLI fields for show port ptypes */
19588 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19589         TOKEN_STRING_INITIALIZER
19590                 (struct cmd_show_port_supported_ptypes_result,
19591                  show, "show");
19592 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19593         TOKEN_STRING_INITIALIZER
19594                 (struct cmd_show_port_supported_ptypes_result,
19595                  port, "port");
19596 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19597         TOKEN_NUM_INITIALIZER
19598                 (struct cmd_show_port_supported_ptypes_result,
19599                  port_id, UINT16);
19600 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19601         TOKEN_STRING_INITIALIZER
19602                 (struct cmd_show_port_supported_ptypes_result,
19603                  ptypes, "ptypes");
19604
19605 static void
19606 cmd_show_port_supported_ptypes_parsed(
19607         void *parsed_result,
19608         __rte_unused struct cmdline *cl,
19609         __rte_unused void *data)
19610 {
19611 #define RSVD_PTYPE_MASK       0xf0000000
19612 #define MAX_PTYPES_PER_LAYER  16
19613 #define LTYPE_NAMESIZE        32
19614 #define PTYPE_NAMESIZE        256
19615         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19616         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19617         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19618         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19619         uint16_t port_id = res->port_id;
19620         int ret, i;
19621
19622         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19623         if (ret < 0)
19624                 return;
19625
19626         while (ptype_mask != RSVD_PTYPE_MASK) {
19627
19628                 switch (ptype_mask) {
19629                 case RTE_PTYPE_L2_MASK:
19630                         strlcpy(ltype, "L2", sizeof(ltype));
19631                         break;
19632                 case RTE_PTYPE_L3_MASK:
19633                         strlcpy(ltype, "L3", sizeof(ltype));
19634                         break;
19635                 case RTE_PTYPE_L4_MASK:
19636                         strlcpy(ltype, "L4", sizeof(ltype));
19637                         break;
19638                 case RTE_PTYPE_TUNNEL_MASK:
19639                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19640                         break;
19641                 case RTE_PTYPE_INNER_L2_MASK:
19642                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19643                         break;
19644                 case RTE_PTYPE_INNER_L3_MASK:
19645                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19646                         break;
19647                 case RTE_PTYPE_INNER_L4_MASK:
19648                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19649                         break;
19650                 default:
19651                         return;
19652                 }
19653
19654                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19655                                                        ptype_mask, ptypes,
19656                                                        MAX_PTYPES_PER_LAYER);
19657
19658                 if (ret > 0)
19659                         printf("Supported %s ptypes:\n", ltype);
19660                 else
19661                         printf("%s ptypes unsupported\n", ltype);
19662
19663                 for (i = 0; i < ret; ++i) {
19664                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19665                         printf("%s\n", buf);
19666                 }
19667
19668                 ptype_mask <<= 4;
19669         }
19670 }
19671
19672 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19673         .f = cmd_show_port_supported_ptypes_parsed,
19674         .data = NULL,
19675         .help_str = "show port <port_id> ptypes",
19676         .tokens = {
19677                 (void *)&cmd_show_port_supported_ptypes_show,
19678                 (void *)&cmd_show_port_supported_ptypes_port,
19679                 (void *)&cmd_show_port_supported_ptypes_port_id,
19680                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19681                 NULL,
19682         },
19683 };
19684
19685 /* *** display rx/tx descriptor status *** */
19686 struct cmd_show_rx_tx_desc_status_result {
19687         cmdline_fixed_string_t cmd_show;
19688         cmdline_fixed_string_t cmd_port;
19689         cmdline_fixed_string_t cmd_keyword;
19690         cmdline_fixed_string_t cmd_desc;
19691         cmdline_fixed_string_t cmd_status;
19692         portid_t cmd_pid;
19693         portid_t cmd_qid;
19694         portid_t cmd_did;
19695 };
19696
19697 static void
19698 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19699                 __rte_unused struct cmdline *cl,
19700                 __rte_unused void *data)
19701 {
19702         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19703         int rc;
19704
19705         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19706                 printf("invalid port id %u\n", res->cmd_pid);
19707                 return;
19708         }
19709
19710         if (!strcmp(res->cmd_keyword, "rxq")) {
19711                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19712                                              res->cmd_did);
19713                 if (rc < 0) {
19714                         printf("Invalid queueid = %d\n", res->cmd_qid);
19715                         return;
19716                 }
19717                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19718                         printf("Desc status = AVAILABLE\n");
19719                 else if (rc == RTE_ETH_RX_DESC_DONE)
19720                         printf("Desc status = DONE\n");
19721                 else
19722                         printf("Desc status = UNAVAILABLE\n");
19723         } else if (!strcmp(res->cmd_keyword, "txq")) {
19724                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19725                                              res->cmd_did);
19726                 if (rc < 0) {
19727                         printf("Invalid queueid = %d\n", res->cmd_qid);
19728                         return;
19729                 }
19730                 if (rc == RTE_ETH_TX_DESC_FULL)
19731                         printf("Desc status = FULL\n");
19732                 else if (rc == RTE_ETH_TX_DESC_DONE)
19733                         printf("Desc status = DONE\n");
19734                 else
19735                         printf("Desc status = UNAVAILABLE\n");
19736         }
19737 }
19738
19739 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19740         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19741                         cmd_show, "show");
19742 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19743         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19744                         cmd_port, "port");
19745 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19746         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19747                         cmd_pid, UINT16);
19748 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19749         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19750                         cmd_keyword, "rxq#txq");
19751 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19752         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19753                         cmd_qid, UINT16);
19754 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19755         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19756                         cmd_desc, "desc");
19757 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19758         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19759                         cmd_did, UINT16);
19760 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19761         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19762                         cmd_status, "status");
19763 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19764         .f = cmd_show_rx_tx_desc_status_parsed,
19765         .data = NULL,
19766         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19767                 "status",
19768         .tokens = {
19769                 (void *)&cmd_show_rx_tx_desc_status_show,
19770                 (void *)&cmd_show_rx_tx_desc_status_port,
19771                 (void *)&cmd_show_rx_tx_desc_status_pid,
19772                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19773                 (void *)&cmd_show_rx_tx_desc_status_qid,
19774                 (void *)&cmd_show_rx_tx_desc_status_desc,
19775                 (void *)&cmd_show_rx_tx_desc_status_did,
19776                 (void *)&cmd_show_rx_tx_desc_status_status,
19777                 NULL,
19778         },
19779 };
19780
19781 /* Common result structure for set port ptypes */
19782 struct cmd_set_port_ptypes_result {
19783         cmdline_fixed_string_t set;
19784         cmdline_fixed_string_t port;
19785         portid_t port_id;
19786         cmdline_fixed_string_t ptype_mask;
19787         uint32_t mask;
19788 };
19789
19790 /* Common CLI fields for set port ptypes */
19791 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19792         TOKEN_STRING_INITIALIZER
19793                 (struct cmd_set_port_ptypes_result,
19794                  set, "set");
19795 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19796         TOKEN_STRING_INITIALIZER
19797                 (struct cmd_set_port_ptypes_result,
19798                  port, "port");
19799 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19800         TOKEN_NUM_INITIALIZER
19801                 (struct cmd_set_port_ptypes_result,
19802                  port_id, UINT16);
19803 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19804         TOKEN_STRING_INITIALIZER
19805                 (struct cmd_set_port_ptypes_result,
19806                  ptype_mask, "ptype_mask");
19807 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19808         TOKEN_NUM_INITIALIZER
19809                 (struct cmd_set_port_ptypes_result,
19810                  mask, UINT32);
19811
19812 static void
19813 cmd_set_port_ptypes_parsed(
19814         void *parsed_result,
19815         __rte_unused struct cmdline *cl,
19816         __rte_unused void *data)
19817 {
19818         struct cmd_set_port_ptypes_result *res = parsed_result;
19819 #define PTYPE_NAMESIZE        256
19820         char ptype_name[PTYPE_NAMESIZE];
19821         uint16_t port_id = res->port_id;
19822         uint32_t ptype_mask = res->mask;
19823         int ret, i;
19824
19825         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19826                                                NULL, 0);
19827         if (ret <= 0) {
19828                 printf("Port %d doesn't support any ptypes.\n", port_id);
19829                 return;
19830         }
19831
19832         uint32_t ptypes[ret];
19833
19834         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19835         if (ret < 0) {
19836                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19837                 return;
19838         }
19839
19840         printf("Successfully set following ptypes for Port %d\n", port_id);
19841         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19842                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19843                 printf("%s\n", ptype_name);
19844         }
19845
19846         clear_ptypes = false;
19847 }
19848
19849 cmdline_parse_inst_t cmd_set_port_ptypes = {
19850         .f = cmd_set_port_ptypes_parsed,
19851         .data = NULL,
19852         .help_str = "set port <port_id> ptype_mask <mask>",
19853         .tokens = {
19854                 (void *)&cmd_set_port_ptypes_set,
19855                 (void *)&cmd_set_port_ptypes_port,
19856                 (void *)&cmd_set_port_ptypes_port_id,
19857                 (void *)&cmd_set_port_ptypes_mask_str,
19858                 (void *)&cmd_set_port_ptypes_mask_u32,
19859                 NULL,
19860         },
19861 };
19862
19863 /* *** display mac addresses added to a port *** */
19864 struct cmd_showport_macs_result {
19865         cmdline_fixed_string_t cmd_show;
19866         cmdline_fixed_string_t cmd_port;
19867         cmdline_fixed_string_t cmd_keyword;
19868         portid_t cmd_pid;
19869 };
19870
19871 static void
19872 cmd_showport_macs_parsed(void *parsed_result,
19873                 __rte_unused struct cmdline *cl,
19874                 __rte_unused void *data)
19875 {
19876         struct cmd_showport_macs_result *res = parsed_result;
19877
19878         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19879                 return;
19880
19881         if (!strcmp(res->cmd_keyword, "macs"))
19882                 show_macs(res->cmd_pid);
19883         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19884                 show_mcast_macs(res->cmd_pid);
19885 }
19886
19887 cmdline_parse_token_string_t cmd_showport_macs_show =
19888         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19889                         cmd_show, "show");
19890 cmdline_parse_token_string_t cmd_showport_macs_port =
19891         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19892                         cmd_port, "port");
19893 cmdline_parse_token_num_t cmd_showport_macs_pid =
19894         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19895                         cmd_pid, UINT16);
19896 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19897         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19898                         cmd_keyword, "macs#mcast_macs");
19899
19900 cmdline_parse_inst_t cmd_showport_macs = {
19901         .f = cmd_showport_macs_parsed,
19902         .data = NULL,
19903         .help_str = "show port <port_id> macs|mcast_macs",
19904         .tokens = {
19905                 (void *)&cmd_showport_macs_show,
19906                 (void *)&cmd_showport_macs_port,
19907                 (void *)&cmd_showport_macs_pid,
19908                 (void *)&cmd_showport_macs_keyword,
19909                 NULL,
19910         },
19911 };
19912
19913 /* ******************************************************************************** */
19914
19915 /* list of instructions */
19916 cmdline_parse_ctx_t main_ctx[] = {
19917         (cmdline_parse_inst_t *)&cmd_help_brief,
19918         (cmdline_parse_inst_t *)&cmd_help_long,
19919         (cmdline_parse_inst_t *)&cmd_quit,
19920         (cmdline_parse_inst_t *)&cmd_load_from_file,
19921         (cmdline_parse_inst_t *)&cmd_showport,
19922         (cmdline_parse_inst_t *)&cmd_showqueue,
19923         (cmdline_parse_inst_t *)&cmd_showeeprom,
19924         (cmdline_parse_inst_t *)&cmd_showportall,
19925         (cmdline_parse_inst_t *)&cmd_showdevice,
19926         (cmdline_parse_inst_t *)&cmd_showcfg,
19927         (cmdline_parse_inst_t *)&cmd_showfwdall,
19928         (cmdline_parse_inst_t *)&cmd_start,
19929         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19930         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19931         (cmdline_parse_inst_t *)&cmd_set_link_up,
19932         (cmdline_parse_inst_t *)&cmd_set_link_down,
19933         (cmdline_parse_inst_t *)&cmd_reset,
19934         (cmdline_parse_inst_t *)&cmd_set_numbers,
19935         (cmdline_parse_inst_t *)&cmd_set_log,
19936         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
19937         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19938         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19939         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19940         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19941         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19942         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19943         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19944         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19945         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19946         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19947         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19948         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19949         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19950         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19951         (cmdline_parse_inst_t *)&cmd_set_link_check,
19952         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19953         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19954         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19955         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19956 #ifdef RTE_NET_BOND
19957         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19958         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19959         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19960         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19961         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19962         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19963         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19964         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19965         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19966         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19967         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19968 #endif
19969         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19970         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19971         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19972         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19973         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19974         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19975         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19976         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19977         (cmdline_parse_inst_t *)&cmd_csum_set,
19978         (cmdline_parse_inst_t *)&cmd_csum_show,
19979         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19980         (cmdline_parse_inst_t *)&cmd_tso_set,
19981         (cmdline_parse_inst_t *)&cmd_tso_show,
19982         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19983         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19984         (cmdline_parse_inst_t *)&cmd_gro_enable,
19985         (cmdline_parse_inst_t *)&cmd_gro_flush,
19986         (cmdline_parse_inst_t *)&cmd_gro_show,
19987         (cmdline_parse_inst_t *)&cmd_gso_enable,
19988         (cmdline_parse_inst_t *)&cmd_gso_size,
19989         (cmdline_parse_inst_t *)&cmd_gso_show,
19990         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19991         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19992         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19993         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19994         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19995         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19996         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19997         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19998         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19999         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
20000         (cmdline_parse_inst_t *)&cmd_config_dcb,
20001         (cmdline_parse_inst_t *)&cmd_read_reg,
20002         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
20003         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
20004         (cmdline_parse_inst_t *)&cmd_write_reg,
20005         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
20006         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
20007         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
20008         (cmdline_parse_inst_t *)&cmd_stop,
20009         (cmdline_parse_inst_t *)&cmd_mac_addr,
20010         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
20011         (cmdline_parse_inst_t *)&cmd_set_qmap,
20012         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
20013         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
20014         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
20015         (cmdline_parse_inst_t *)&cmd_operate_port,
20016         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
20017         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
20018         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
20019         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
20020         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
20021         (cmdline_parse_inst_t *)&cmd_config_speed_all,
20022         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
20023         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
20024         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
20025         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
20026         (cmdline_parse_inst_t *)&cmd_config_mtu,
20027         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
20028         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
20029         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
20030         (cmdline_parse_inst_t *)&cmd_config_rss,
20031         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
20032         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
20033         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
20034         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
20035         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
20036         (cmdline_parse_inst_t *)&cmd_showport_reta,
20037         (cmdline_parse_inst_t *)&cmd_showport_macs,
20038         (cmdline_parse_inst_t *)&cmd_config_burst,
20039         (cmdline_parse_inst_t *)&cmd_config_thresh,
20040         (cmdline_parse_inst_t *)&cmd_config_threshold,
20041         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
20042         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
20043         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
20044         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
20045         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
20046         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
20047         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
20048         (cmdline_parse_inst_t *)&cmd_global_config,
20049         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
20050         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
20051         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
20052         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
20053         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
20054         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
20055         (cmdline_parse_inst_t *)&cmd_dump,
20056         (cmdline_parse_inst_t *)&cmd_dump_one,
20057         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
20058         (cmdline_parse_inst_t *)&cmd_syn_filter,
20059         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
20060         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
20061         (cmdline_parse_inst_t *)&cmd_flex_filter,
20062         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
20063         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
20064         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
20065         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
20066         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
20067         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
20068         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
20069         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
20070         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
20071         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
20072         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
20073         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
20074         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
20075         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
20076         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
20077         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
20078         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
20079         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
20080         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
20081         (cmdline_parse_inst_t *)&cmd_flow,
20082         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
20083         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
20084         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
20085         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
20086         (cmdline_parse_inst_t *)&cmd_create_port_meter,
20087         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
20088         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
20089         (cmdline_parse_inst_t *)&cmd_del_port_meter,
20090         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
20091         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
20092         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
20093         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
20094         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
20095         (cmdline_parse_inst_t *)&cmd_mcast_addr,
20096         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
20097         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
20098         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
20099         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
20100         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
20101         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
20102         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
20103         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
20104         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
20105         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
20106         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
20107         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
20108         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
20109         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
20110         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
20111         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
20112         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
20113         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
20114         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
20115         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
20116         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
20117         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
20118         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
20119         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
20120         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
20121         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
20122         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
20123         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
20124         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
20125         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
20126         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
20127         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
20128         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
20129         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
20130         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
20131         (cmdline_parse_inst_t *)&cmd_set_vxlan,
20132         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
20133         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
20134         (cmdline_parse_inst_t *)&cmd_set_nvgre,
20135         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
20136         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
20137         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
20138         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
20139         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
20140         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
20141         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
20142         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
20143         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
20144         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
20145         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
20146         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
20147         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
20148         (cmdline_parse_inst_t *)&cmd_ddp_add,
20149         (cmdline_parse_inst_t *)&cmd_ddp_del,
20150         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
20151         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
20152         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
20153         (cmdline_parse_inst_t *)&cmd_clear_input_set,
20154         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
20155         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
20156         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
20157         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
20158         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
20159         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
20160         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
20161         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
20162
20163         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
20164         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
20165         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
20166         (cmdline_parse_inst_t *)&cmd_queue_region,
20167         (cmdline_parse_inst_t *)&cmd_region_flowtype,
20168         (cmdline_parse_inst_t *)&cmd_user_priority_region,
20169         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
20170         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
20171         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
20172         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
20173         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
20174         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
20175         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
20176         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
20177         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
20178         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
20179         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
20180         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
20181         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
20182         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
20183         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
20184         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
20185         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
20186         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
20187         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
20188         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
20189         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
20190         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
20191         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
20192         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
20193         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
20194         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
20195         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
20196         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
20197         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
20198         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
20199         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
20200         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
20201         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
20202         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
20203 #ifdef RTE_LIB_BPF
20204         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
20205         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
20206 #endif
20207         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
20208         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
20209         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
20210         (cmdline_parse_inst_t *)&cmd_set_raw,
20211         (cmdline_parse_inst_t *)&cmd_show_set_raw,
20212         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
20213         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
20214         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
20215         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
20216         (cmdline_parse_inst_t *)&cmd_show_capability,
20217         NULL,
20218 };
20219
20220 /* read cmdline commands from file */
20221 void
20222 cmdline_read_from_file(const char *filename)
20223 {
20224         struct cmdline *cl;
20225
20226         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20227         if (cl == NULL) {
20228                 printf("Failed to create file based cmdline context: %s\n",
20229                        filename);
20230                 return;
20231         }
20232
20233         cmdline_interact(cl);
20234         cmdline_quit(cl);
20235
20236         cmdline_free(cl);
20237
20238         printf("Read CLI commands from %s\n", filename);
20239 }
20240
20241 /* prompt function, called from main on MASTER lcore */
20242 void
20243 prompt(void)
20244 {
20245         /* initialize non-constant commands */
20246         cmd_set_fwd_mode_init();
20247         cmd_set_fwd_retry_mode_init();
20248
20249         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20250         if (testpmd_cl == NULL)
20251                 return;
20252         cmdline_interact(testpmd_cl);
20253         cmdline_stdin_exit(testpmd_cl);
20254 }
20255
20256 void
20257 prompt_exit(void)
20258 {
20259         if (testpmd_cl != NULL)
20260                 cmdline_quit(testpmd_cl);
20261 }
20262
20263 static void
20264 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20265 {
20266         if (id == (portid_t)RTE_PORT_ALL) {
20267                 portid_t pid;
20268
20269                 RTE_ETH_FOREACH_DEV(pid) {
20270                         /* check if need_reconfig has been set to 1 */
20271                         if (ports[pid].need_reconfig == 0)
20272                                 ports[pid].need_reconfig = dev;
20273                         /* check if need_reconfig_queues has been set to 1 */
20274                         if (ports[pid].need_reconfig_queues == 0)
20275                                 ports[pid].need_reconfig_queues = queue;
20276                 }
20277         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20278                 /* check if need_reconfig has been set to 1 */
20279                 if (ports[id].need_reconfig == 0)
20280                         ports[id].need_reconfig = dev;
20281                 /* check if need_reconfig_queues has been set to 1 */
20282                 if (ports[id].need_reconfig_queues == 0)
20283                         ports[id].need_reconfig_queues = queue;
20284         }
20285 }