app/testpmd: add rxpkts commands and parameters
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_LIBRTE_PMD_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_LIBRTE_IXGBE_PMD
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_LIBRTE_I40E_PMD
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_LIBRTE_BNXT_PMD
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|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 rxpkts (x[,y]*)\n"
298                         "    Set the length of each segment to scatter"
299                         " packets on receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set txpkts (x[,y]*)\n"
304                         "    Set the length of each segment of TXONLY"
305                         " and optionally CSUM packets.\n\n"
306
307                         "set txsplit (off|on|rand)\n"
308                         "    Set the split policy for the TX packets."
309                         " Right now only applicable for CSUM and TXONLY"
310                         " modes\n\n"
311
312                         "set txtimes (x, y)\n"
313                         "    Set the scheduling on timestamps"
314                         " timings for the TXONLY mode\n\n"
315
316                         "set corelist (x[,y]*)\n"
317                         "    Set the list of forwarding cores.\n\n"
318
319                         "set portlist (x[,y]*)\n"
320                         "    Set the list of forwarding ports.\n\n"
321
322                         "set port setup on (iterator|event)\n"
323                         "    Select how attached port is retrieved for setup.\n\n"
324
325                         "set tx loopback (port_id) (on|off)\n"
326                         "    Enable or disable tx loopback.\n\n"
327
328                         "set all queues drop (port_id) (on|off)\n"
329                         "    Set drop enable bit for all queues.\n\n"
330
331                         "set vf split drop (port_id) (vf_id) (on|off)\n"
332                         "    Set split drop enable bit for a VF from the PF.\n\n"
333
334                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
335                         "    Set MAC antispoof for a VF from the PF.\n\n"
336
337                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
338                         "    Enable MACsec offload.\n\n"
339
340                         "set macsec offload (port_id) off\n"
341                         "    Disable MACsec offload.\n\n"
342
343                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
344                         "    Configure MACsec secure connection (SC).\n\n"
345
346                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
347                         "    Configure MACsec secure association (SA).\n\n"
348
349                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
350                         "    Set VF broadcast for a VF from the PF.\n\n"
351
352                         "vlan set stripq (on|off) (port_id,queue_id)\n"
353                         "    Set the VLAN strip for a queue on a port.\n\n"
354
355                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
356                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
357
358                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
359                         "    Set VLAN insert for a VF from the PF.\n\n"
360
361                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
362                         "    Set VLAN antispoof for a VF from the PF.\n\n"
363
364                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
365                         "    Set VLAN tag for a VF from the PF.\n\n"
366
367                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
368                         "    Set a VF's max bandwidth(Mbps).\n\n"
369
370                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
371                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
372
373                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
374                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
375
376                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
377                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
378
379                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
380                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
381
382                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
383                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
384
385                         "vlan set (inner|outer) tpid (value) (port_id)\n"
386                         "    Set the VLAN TPID for Packet Filtering on"
387                         " a port\n\n"
388
389                         "rx_vlan add (vlan_id|all) (port_id)\n"
390                         "    Add a vlan_id, or all identifiers, to the set"
391                         " of VLAN identifiers filtered by port_id.\n\n"
392
393                         "rx_vlan rm (vlan_id|all) (port_id)\n"
394                         "    Remove a vlan_id, or all identifiers, from the set"
395                         " of VLAN identifiers filtered by port_id.\n\n"
396
397                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
398                         "    Add a vlan_id, to the set of VLAN identifiers"
399                         "filtered for VF(s) from port_id.\n\n"
400
401                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
402                         "    Remove a vlan_id, to the set of VLAN identifiers"
403                         "filtered for VF(s) from port_id.\n\n"
404
405                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
406                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
407                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
408                         "   add a tunnel filter of a port.\n\n"
409
410                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
411                         "(inner_vlan) (vxlan|nvgre|ipingre|vxlan-gpe) (imac-ivlan|imac-ivlan-tenid|"
412                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
413                         "   remove a tunnel filter of a port.\n\n"
414
415                         "rx_vxlan_port add (udp_port) (port_id)\n"
416                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
417
418                         "rx_vxlan_port rm (udp_port) (port_id)\n"
419                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
420
421                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
422                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
423                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
424
425                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
426                         "    Set port based TX VLAN insertion.\n\n"
427
428                         "tx_vlan reset (port_id)\n"
429                         "    Disable hardware insertion of a VLAN header in"
430                         " packets sent on a port.\n\n"
431
432                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
433                         "    Select hardware or software calculation of the"
434                         " checksum when transmitting a packet using the"
435                         " csum forward engine.\n"
436                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
437                         "    outer-ip concerns the outer IP layer in"
438                         "    outer-udp concerns the outer UDP layer in"
439                         " case the packet is recognized as a tunnel packet by"
440                         " the forward engine (vxlan, gre and ipip are supported)\n"
441                         "    Please check the NIC datasheet for HW limits.\n\n"
442
443                         "csum parse-tunnel (on|off) (tx_port_id)\n"
444                         "    If disabled, treat tunnel packets as non-tunneled"
445                         " packets (treat inner headers as payload). The port\n"
446                         "    argument is the port used for TX in csum forward"
447                         " engine.\n\n"
448
449                         "csum show (port_id)\n"
450                         "    Display tx checksum offload configuration\n\n"
451
452                         "tso set (segsize) (portid)\n"
453                         "    Enable TCP Segmentation Offload in csum forward"
454                         " engine.\n"
455                         "    Please check the NIC datasheet for HW limits.\n\n"
456
457                         "tso show (portid)"
458                         "    Display the status of TCP Segmentation Offload.\n\n"
459
460                         "set port (port_id) gro on|off\n"
461                         "    Enable or disable Generic Receive Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "show port (port_id) gro\n"
465                         "    Display GRO configuration.\n\n"
466
467                         "set gro flush (cycles)\n"
468                         "    Set the cycle to flush GROed packets from"
469                         " reassembly tables.\n\n"
470
471                         "set port (port_id) gso (on|off)"
472                         "    Enable or disable Generic Segmentation Offload in"
473                         " csum forwarding engine.\n\n"
474
475                         "set gso segsz (length)\n"
476                         "    Set max packet length for output GSO segments,"
477                         " including packet header and payload.\n\n"
478
479                         "show port (port_id) gso\n"
480                         "    Show GSO configuration.\n\n"
481
482                         "set fwd (%s)\n"
483                         "    Set packet forwarding mode.\n\n"
484
485                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
486                         "    Add a MAC address on port_id.\n\n"
487
488                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
489                         "    Remove a MAC address from port_id.\n\n"
490
491                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
492                         "    Set the default MAC address for port_id.\n\n"
493
494                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
495                         "    Add a MAC address for a VF on the port.\n\n"
496
497                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
498                         "    Set the MAC address for a VF from the PF.\n\n"
499
500                         "set eth-peer (port_id) (peer_addr)\n"
501                         "    set the peer address for certain port.\n\n"
502
503                         "set port (port_id) uta (mac_address|all) (on|off)\n"
504                         "    Add/Remove a or all unicast hash filter(s)"
505                         "from port X.\n\n"
506
507                         "set promisc (port_id|all) (on|off)\n"
508                         "    Set the promiscuous mode on port_id, or all.\n\n"
509
510                         "set allmulti (port_id|all) (on|off)\n"
511                         "    Set the allmulti mode on port_id, or all.\n\n"
512
513                         "set vf promisc (port_id) (vf_id) (on|off)\n"
514                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
515
516                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
517                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
518
519                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
520                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
521                         " (on|off) autoneg (on|off) (port_id)\n"
522                         "set flow_ctrl rx (on|off) (portid)\n"
523                         "set flow_ctrl tx (on|off) (portid)\n"
524                         "set flow_ctrl high_water (high_water) (portid)\n"
525                         "set flow_ctrl low_water (low_water) (portid)\n"
526                         "set flow_ctrl pause_time (pause_time) (portid)\n"
527                         "set flow_ctrl send_xon (send_xon) (portid)\n"
528                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
529                         "set flow_ctrl autoneg (on|off) (port_id)\n"
530                         "    Set the link flow control parameter on a port.\n\n"
531
532                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
533                         " (low_water) (pause_time) (priority) (port_id)\n"
534                         "    Set the priority flow control parameter on a"
535                         " port.\n\n"
536
537                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
538                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
539                         " queue on port.\n"
540                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
541                         " on port 0 to mapping 5.\n\n"
542
543                         "set xstats-hide-zero on|off\n"
544                         "    Set the option to hide the zero values"
545                         " for xstats display.\n"
546
547                         "set record-core-cycles on|off\n"
548                         "    Set the option to enable measurement of CPU cycles.\n"
549
550                         "set record-burst-stats on|off\n"
551                         "    Set the option to enable display of RX and TX bursts.\n"
552
553                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
554                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
555
556                         "set port (port_id) vf (vf_id) (mac_addr)"
557                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
558                         "   Add/Remove unicast or multicast MAC addr filter"
559                         " for a VF.\n\n"
560
561                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
562                         "|MPE) (on|off)\n"
563                         "    AUPE:accepts untagged VLAN;"
564                         "ROPE:accept unicast hash\n\n"
565                         "    BAM:accepts broadcast packets;"
566                         "MPE:accepts all multicast packets\n\n"
567                         "    Enable/Disable a VF receive mode of a port\n\n"
568
569                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
570                         "    Set rate limit for a queue of a port\n\n"
571
572                         "set port (port_id) vf (vf_id) rate (rate_num) "
573                         "queue_mask (queue_mask_value)\n"
574                         "    Set rate limit for queues in VF of a port\n\n"
575
576                         "set port (port_id) mirror-rule (rule_id)"
577                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
578                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
579                         "   Set pool or vlan type mirror rule on a port.\n"
580                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
581                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
582                         " to pool 0.\n\n"
583
584                         "set port (port_id) mirror-rule (rule_id)"
585                         " (uplink-mirror|downlink-mirror) dst-pool"
586                         " (pool_id) (on|off)\n"
587                         "   Set uplink or downlink type mirror rule on a port.\n"
588                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
589                         " 0 on' enable mirror income traffic to pool 0.\n\n"
590
591                         "reset port (port_id) mirror-rule (rule_id)\n"
592                         "   Reset a mirror rule.\n\n"
593
594                         "set flush_rx (on|off)\n"
595                         "   Flush (default) or don't flush RX streams before"
596                         " forwarding. Mainly used with PCAP drivers.\n\n"
597
598                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
599                         "   Set the bypass mode for the lowest port on bypass enabled"
600                         " NIC.\n\n"
601
602                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
603                         "mode (normal|bypass|isolate) (port_id)\n"
604                         "   Set the event required to initiate specified bypass mode for"
605                         " the lowest port on a bypass enabled NIC where:\n"
606                         "       timeout   = enable bypass after watchdog timeout.\n"
607                         "       os_on     = enable bypass when OS/board is powered on.\n"
608                         "       os_off    = enable bypass when OS/board is powered off.\n"
609                         "       power_on  = enable bypass when power supply is turned on.\n"
610                         "       power_off = enable bypass when power supply is turned off."
611                         "\n\n"
612
613                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
614                         "   Set the bypass watchdog timeout to 'n' seconds"
615                         " where 0 = instant.\n\n"
616
617                         "show bypass config (port_id)\n"
618                         "   Show the bypass configuration for a bypass enabled NIC"
619                         " using the lowest port on the NIC.\n\n"
620
621 #ifdef RTE_LIBRTE_PMD_BOND
622                         "create bonded device (mode) (socket)\n"
623                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
624
625                         "add bonding slave (slave_id) (port_id)\n"
626                         "       Add a slave device to a bonded device.\n\n"
627
628                         "remove bonding slave (slave_id) (port_id)\n"
629                         "       Remove a slave device from a bonded device.\n\n"
630
631                         "set bonding mode (value) (port_id)\n"
632                         "       Set the bonding mode on a bonded device.\n\n"
633
634                         "set bonding primary (slave_id) (port_id)\n"
635                         "       Set the primary slave for a bonded device.\n\n"
636
637                         "show bonding config (port_id)\n"
638                         "       Show the bonding config for port_id.\n\n"
639
640                         "set bonding mac_addr (port_id) (address)\n"
641                         "       Set the MAC address of a bonded device.\n\n"
642
643                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
644                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
645
646                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
647                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
648
649                         "set bonding mon_period (port_id) (value)\n"
650                         "       Set the bonding link status monitoring polling period in ms.\n\n"
651
652                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
653                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
654
655 #endif
656                         "set link-up port (port_id)\n"
657                         "       Set link up for a port.\n\n"
658
659                         "set link-down port (port_id)\n"
660                         "       Set link down for a port.\n\n"
661
662                         "E-tag set insertion on port-tag-id (value)"
663                         " port (port_id) vf (vf_id)\n"
664                         "    Enable E-tag insertion for a VF on a port\n\n"
665
666                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
667                         "    Disable E-tag insertion for a VF on a port\n\n"
668
669                         "E-tag set stripping (on|off) port (port_id)\n"
670                         "    Enable/disable E-tag stripping on a port\n\n"
671
672                         "E-tag set forwarding (on|off) port (port_id)\n"
673                         "    Enable/disable E-tag based forwarding"
674                         " on a port\n\n"
675
676                         "E-tag set filter add e-tag-id (value) dst-pool"
677                         " (pool_id) port (port_id)\n"
678                         "    Add an E-tag forwarding filter on a port\n\n"
679
680                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
681                         "    Delete an E-tag forwarding filter on a port\n\n"
682
683                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
684                         "    Load a profile package on a port\n\n"
685
686                         "ddp del (port_id) (backup_profile_path)\n"
687                         "    Delete a profile package from a port\n\n"
688
689                         "ptype mapping get (port_id) (valid_only)\n"
690                         "    Get ptype mapping on a port\n\n"
691
692                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
693                         "    Replace target with the pkt_type in ptype mapping\n\n"
694
695                         "ptype mapping reset (port_id)\n"
696                         "    Reset ptype mapping on a port\n\n"
697
698                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
699                         "    Update a ptype mapping item on a port\n\n"
700
701                         "set port (port_id) ptype_mask (ptype_mask)\n"
702                         "    set packet types classification for a specific port\n\n"
703
704                         "set port (port_id) queue-region region_id (value) "
705                         "queue_start_index (value) queue_num (value)\n"
706                         "    Set a queue region on a port\n\n"
707
708                         "set port (port_id) queue-region region_id (value) "
709                         "flowtype (value)\n"
710                         "    Set a flowtype region index on a port\n\n"
711
712                         "set port (port_id) queue-region UP (value) region_id (value)\n"
713                         "    Set the mapping of User Priority to "
714                         "queue region on a port\n\n"
715
716                         "set port (port_id) queue-region flush (on|off)\n"
717                         "    flush all queue region related configuration\n\n"
718
719                         "show port meter cap (port_id)\n"
720                         "    Show port meter capability information\n\n"
721
722                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
723                         "    meter profile add - srtcm rfc 2697\n\n"
724
725                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
726                         "    meter profile add - trtcm rfc 2698\n\n"
727
728                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
729                         "    meter profile add - trtcm rfc 4115\n\n"
730
731                         "del port meter profile (port_id) (profile_id)\n"
732                         "    meter profile delete\n\n"
733
734                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
735                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
736                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
737                         "(dscp_tbl_entry63)]\n"
738                         "    meter create\n\n"
739
740                         "enable port meter (port_id) (mtr_id)\n"
741                         "    meter enable\n\n"
742
743                         "disable port meter (port_id) (mtr_id)\n"
744                         "    meter disable\n\n"
745
746                         "del port meter (port_id) (mtr_id)\n"
747                         "    meter delete\n\n"
748
749                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
750                         "    meter update meter profile\n\n"
751
752                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
753                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
754                         "    update meter dscp table entries\n\n"
755
756                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
757                         "(action0) [(action1) (action2)]\n"
758                         "    meter update policer action\n\n"
759
760                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
761                         "    meter update stats\n\n"
762
763                         "show port (port_id) queue-region\n"
764                         "    show all queue region related configuration info\n\n"
765
766                         "set port (port_id) fec_mode auto|off|rs|baser\n"
767                         "    set fec mode for a specific port\n\n"
768
769                         , list_pkt_forwarding_modes()
770                 );
771         }
772
773         if (show_all || !strcmp(res->section, "ports")) {
774
775                 cmdline_printf(
776                         cl,
777                         "\n"
778                         "Port Operations:\n"
779                         "----------------\n\n"
780
781                         "port start (port_id|all)\n"
782                         "    Start all ports or port_id.\n\n"
783
784                         "port stop (port_id|all)\n"
785                         "    Stop all ports or port_id.\n\n"
786
787                         "port close (port_id|all)\n"
788                         "    Close all ports or port_id.\n\n"
789
790                         "port reset (port_id|all)\n"
791                         "    Reset all ports or port_id.\n\n"
792
793                         "port attach (ident)\n"
794                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
795
796                         "port detach (port_id)\n"
797                         "    Detach physical or virtual dev by port_id\n\n"
798
799                         "port config (port_id|all)"
800                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
801                         " duplex (half|full|auto)\n"
802                         "    Set speed and duplex for all ports or port_id\n\n"
803
804                         "port config (port_id|all) loopback (mode)\n"
805                         "    Set loopback mode for all ports or port_id\n\n"
806
807                         "port config all (rxq|txq|rxd|txd) (value)\n"
808                         "    Set number for rxq/txq/rxd/txd.\n\n"
809
810                         "port config all max-pkt-len (value)\n"
811                         "    Set the max packet length.\n\n"
812
813                         "port config all max-lro-pkt-size (value)\n"
814                         "    Set the max LRO aggregated packet size.\n\n"
815
816                         "port config all drop-en (on|off)\n"
817                         "    Enable or disable packet drop on all RX queues of all ports when no "
818                         "receive buffers available.\n\n"
819
820                         "port config all rss (all|default|ip|tcp|udp|sctp|"
821                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
822                         "level-outer|level-inner|<flowtype_id>)\n"
823                         "    Set the RSS mode.\n\n"
824
825                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
826                         "    Set the RSS redirection table.\n\n"
827
828                         "port config (port_id) dcb vt (on|off) (traffic_class)"
829                         " pfc (on|off)\n"
830                         "    Set the DCB mode.\n\n"
831
832                         "port config all burst (value)\n"
833                         "    Set the number of packets per burst.\n\n"
834
835                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
836                         " (value)\n"
837                         "    Set the ring prefetch/host/writeback threshold"
838                         " for tx/rx queue.\n\n"
839
840                         "port config all (txfreet|txrst|rxfreet) (value)\n"
841                         "    Set free threshold for rx/tx, or set"
842                         " tx rs bit threshold.\n\n"
843                         "port config mtu X value\n"
844                         "    Set the MTU of port X to a given value\n\n"
845
846                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
847                         "    Set a rx/tx queue's ring size configuration, the new"
848                         " value will take effect after command that (re-)start the port"
849                         " or command that setup the specific queue\n\n"
850
851                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
852                         "    Start/stop a rx/tx queue of port X. Only take effect"
853                         " when port X is started\n\n"
854
855                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
856                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
857                         " take effect when port X is stopped.\n\n"
858
859                         "port (port_id) (rxq|txq) (queue_id) setup\n"
860                         "    Setup a rx/tx queue of port X.\n\n"
861
862                         "port config (port_id|all) l2-tunnel E-tag ether-type"
863                         " (value)\n"
864                         "    Set the value of E-tag ether-type.\n\n"
865
866                         "port config (port_id|all) l2-tunnel E-tag"
867                         " (enable|disable)\n"
868                         "    Enable/disable the E-tag support.\n\n"
869
870                         "port config (port_id) pctype mapping reset\n"
871                         "    Reset flow type to pctype mapping on a port\n\n"
872
873                         "port config (port_id) pctype mapping update"
874                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
875                         "    Update a flow type to pctype mapping item on a port\n\n"
876
877                         "port config (port_id) pctype (pctype_id) hash_inset|"
878                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
879                         " (field_idx)\n"
880                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
881
882                         "port config (port_id) pctype (pctype_id) hash_inset|"
883                         "fdir_inset|fdir_flx_inset clear all"
884                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
885
886                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
887                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
888
889                         "port config <port_id> rx_offload vlan_strip|"
890                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
891                         "outer_ipv4_cksum|macsec_strip|header_split|"
892                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
893                         "buffer_split|timestamp|security|keep_crc on|off\n"
894                         "     Enable or disable a per port Rx offloading"
895                         " on all Rx queues of a port\n\n"
896
897                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
898                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
899                         "outer_ipv4_cksum|macsec_strip|header_split|"
900                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
901                         "buffer_split|timestamp|security|keep_crc on|off\n"
902                         "    Enable or disable a per queue Rx offloading"
903                         " only on a specific Rx queue\n\n"
904
905                         "port config (port_id) tx_offload vlan_insert|"
906                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
907                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
908                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
909                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
910                         "security on|off\n"
911                         "    Enable or disable a per port Tx offloading"
912                         " on all Tx queues of a port\n\n"
913
914                         "port (port_id) txq (queue_id) tx_offload vlan_insert|"
915                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
916                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
917                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|macsec_insert"
918                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
919                         " on|off\n"
920                         "    Enable or disable a per queue Tx offloading"
921                         " only on a specific Tx queue\n\n"
922
923                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
924                         "    Load an eBPF program as a callback"
925                         " for particular RX/TX queue\n\n"
926
927                         "bpf-unload rx|tx (port) (queue)\n"
928                         "    Unload previously loaded eBPF program"
929                         " for particular RX/TX queue\n\n"
930
931                         "port config (port_id) tx_metadata (value)\n"
932                         "    Set Tx metadata value per port. Testpmd will add this value"
933                         " to any Tx packet sent from this port\n\n"
934
935                         "port config (port_id) dynf (name) set|clear\n"
936                         "    Register a dynf and Set/clear this flag on Tx. "
937                         "Testpmd will set this value to any Tx packet "
938                         "sent from this port\n\n"
939                 );
940         }
941
942         if (show_all || !strcmp(res->section, "registers")) {
943
944                 cmdline_printf(
945                         cl,
946                         "\n"
947                         "Registers:\n"
948                         "----------\n\n"
949
950                         "read reg (port_id) (address)\n"
951                         "    Display value of a port register.\n\n"
952
953                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
954                         "    Display a port register bit field.\n\n"
955
956                         "read regbit (port_id) (address) (bit_x)\n"
957                         "    Display a single port register bit.\n\n"
958
959                         "write reg (port_id) (address) (value)\n"
960                         "    Set value of a port register.\n\n"
961
962                         "write regfield (port_id) (address) (bit_x) (bit_y)"
963                         " (value)\n"
964                         "    Set bit field of a port register.\n\n"
965
966                         "write regbit (port_id) (address) (bit_x) (value)\n"
967                         "    Set single bit value of a port register.\n\n"
968                 );
969         }
970         if (show_all || !strcmp(res->section, "filters")) {
971
972                 cmdline_printf(
973                         cl,
974                         "\n"
975                         "filters:\n"
976                         "--------\n\n"
977
978                         "ethertype_filter (port_id) (add|del)"
979                         " (mac_addr|mac_ignr) (mac_address) ethertype"
980                         " (ether_type) (drop|fwd) queue (queue_id)\n"
981                         "    Add/Del an ethertype filter.\n\n"
982
983                         "2tuple_filter (port_id) (add|del)"
984                         " dst_port (dst_port_value) protocol (protocol_value)"
985                         " mask (mask_value) tcp_flags (tcp_flags_value)"
986                         " priority (prio_value) queue (queue_id)\n"
987                         "    Add/Del a 2tuple filter.\n\n"
988
989                         "5tuple_filter (port_id) (add|del)"
990                         " dst_ip (dst_address) src_ip (src_address)"
991                         " dst_port (dst_port_value) src_port (src_port_value)"
992                         " protocol (protocol_value)"
993                         " mask (mask_value) tcp_flags (tcp_flags_value)"
994                         " priority (prio_value) queue (queue_id)\n"
995                         "    Add/Del a 5tuple filter.\n\n"
996
997                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
998                         "    Add/Del syn filter.\n\n"
999
1000                         "flex_filter (port_id) (add|del) len (len_value)"
1001                         " bytes (bytes_value) mask (mask_value)"
1002                         " priority (prio_value) queue (queue_id)\n"
1003                         "    Add/Del a flex filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode IP (add|del|update)"
1006                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
1007                         " src (src_ip_address) dst (dst_ip_address)"
1008                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
1009                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1010                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1011                         " fd_id (fd_id_value)\n"
1012                         "    Add/Del an IP type flow director filter.\n\n"
1013
1014                         "flow_director_filter (port_id) mode IP (add|del|update)"
1015                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
1016                         " src (src_ip_address) (src_port)"
1017                         " dst (dst_ip_address) (dst_port)"
1018                         " tos (tos_value) ttl (ttl_value)"
1019                         " vlan (vlan_value) flexbytes (flexbytes_value)"
1020                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
1021                         " fd_id (fd_id_value)\n"
1022                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
1023
1024                         "flow_director_filter (port_id) mode IP (add|del|update)"
1025                         " flow (ipv4-sctp|ipv6-sctp)"
1026                         " src (src_ip_address) (src_port)"
1027                         " dst (dst_ip_address) (dst_port)"
1028                         " tag (verification_tag) "
1029                         " tos (tos_value) ttl (ttl_value)"
1030                         " vlan (vlan_value)"
1031                         " flexbytes (flexbytes_value) (drop|fwd)"
1032                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1033                         "    Add/Del a SCTP type flow director filter.\n\n"
1034
1035                         "flow_director_filter (port_id) mode IP (add|del|update)"
1036                         " flow l2_payload ether (ethertype)"
1037                         " flexbytes (flexbytes_value) (drop|fwd)"
1038                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1039                         "    Add/Del a l2 payload type flow director filter.\n\n"
1040
1041                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1042                         " mac (mac_address) vlan (vlan_value)"
1043                         " flexbytes (flexbytes_value) (drop|fwd)"
1044                         " queue (queue_id) fd_id (fd_id_value)\n"
1045                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1046
1047                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1048                         " mac (mac_address) vlan (vlan_value)"
1049                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1050                         " flexbytes (flexbytes_value) (drop|fwd)"
1051                         " queue (queue_id) fd_id (fd_id_value)\n"
1052                         "    Add/Del a Tunnel flow director filter.\n\n"
1053
1054                         "flow_director_filter (port_id) mode raw (add|del|update)"
1055                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1056                         " fd_id (fd_id_value) packet (packet file name)\n"
1057                         "    Add/Del a raw type flow director filter.\n\n"
1058
1059                         "flush_flow_director (port_id)\n"
1060                         "    Flush all flow director entries of a device.\n\n"
1061
1062                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1063                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1064                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1065                         "    Set flow director IP mask.\n\n"
1066
1067                         "flow_director_mask (port_id) mode MAC-VLAN"
1068                         " vlan (vlan_value)\n"
1069                         "    Set flow director MAC-VLAN mask.\n\n"
1070
1071                         "flow_director_mask (port_id) mode Tunnel"
1072                         " vlan (vlan_value) mac (mac_value)"
1073                         " tunnel-type (tunnel_type_value)"
1074                         " tunnel-id (tunnel_id_value)\n"
1075                         "    Set flow director Tunnel mask.\n\n"
1076
1077                         "flow_director_flex_mask (port_id)"
1078                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1079                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1080                         " (mask)\n"
1081                         "    Configure mask of flex payload.\n\n"
1082
1083                         "flow_director_flex_payload (port_id)"
1084                         " (raw|l2|l3|l4) (config)\n"
1085                         "    Configure flex payload selection.\n\n"
1086
1087                         "get_sym_hash_ena_per_port (port_id)\n"
1088                         "    get symmetric hash enable configuration per port.\n\n"
1089
1090                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1091                         "    set symmetric hash enable configuration per port"
1092                         " to enable or disable.\n\n"
1093
1094                         "get_hash_global_config (port_id)\n"
1095                         "    Get the global configurations of hash filters.\n\n"
1096
1097                         "set_hash_global_config (port_id) (toeplitz|simple_xor|symmetric_toeplitz|default)"
1098                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1099                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1100                         " (enable|disable)\n"
1101                         "    Set the global configurations of hash filters.\n\n"
1102
1103                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1104                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1105                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1106                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1107                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1108                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1109                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1110                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1111                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1112                         "fld-8th|none) (select|add)\n"
1113                         "    Set the input set for hash.\n\n"
1114
1115                         "set_fdir_input_set (port_id) "
1116                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1117                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1118                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1119                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1120                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1121                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1122                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1123                         " (select|add)\n"
1124                         "    Set the input set for FDir.\n\n"
1125
1126                         "flow validate {port_id}"
1127                         " [group {group_id}] [priority {level}]"
1128                         " [ingress] [egress]"
1129                         " pattern {item} [/ {item} [...]] / end"
1130                         " actions {action} [/ {action} [...]] / end\n"
1131                         "    Check whether a flow rule can be created.\n\n"
1132
1133                         "flow create {port_id}"
1134                         " [group {group_id}] [priority {level}]"
1135                         " [ingress] [egress]"
1136                         " pattern {item} [/ {item} [...]] / end"
1137                         " actions {action} [/ {action} [...]] / end\n"
1138                         "    Create a flow rule.\n\n"
1139
1140                         "flow destroy {port_id} rule {rule_id} [...]\n"
1141                         "    Destroy specific flow rules.\n\n"
1142
1143                         "flow flush {port_id}\n"
1144                         "    Destroy all flow rules.\n\n"
1145
1146                         "flow query {port_id} {rule_id} {action}\n"
1147                         "    Query an existing flow rule.\n\n"
1148
1149                         "flow list {port_id} [group {group_id}] [...]\n"
1150                         "    List existing flow rules sorted by priority,"
1151                         " filtered by group identifiers.\n\n"
1152
1153                         "flow isolate {port_id} {boolean}\n"
1154                         "    Restrict ingress traffic to the defined"
1155                         " flow rules\n\n"
1156
1157                         "flow aged {port_id} [destroy]\n"
1158                         "    List and destroy aged flows"
1159                         " flow rules\n\n"
1160
1161                         "flow shared_action {port_id} create"
1162                         " [action_id {shared_action_id}]"
1163                         " [ingress] [egress]"
1164                         " action {action} / end\n"
1165                         "    Create shared action.\n\n"
1166
1167                         "flow shared_action {port_id} update"
1168                         " {shared_action_id} action {action} / end\n"
1169                         "    Update shared action.\n\n"
1170
1171                         "flow shared_action {port_id} destroy"
1172                         " action_id {shared_action_id} [...]\n"
1173                         "    Destroy specific shared actions.\n\n"
1174
1175                         "flow shared_action {port_id} query"
1176                         " {shared_action_id}\n"
1177                         "    Query an existing shared action.\n\n"
1178
1179                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1180                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1181                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1182                         "       Configure the VXLAN encapsulation for flows.\n\n"
1183
1184                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1185                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1186                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1187                         " eth-dst (eth-dst)\n"
1188                         "       Configure the VXLAN encapsulation for flows.\n\n"
1189
1190                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1191                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1192                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1193                         " eth-dst (eth-dst)\n"
1194                         "       Configure the VXLAN encapsulation for flows.\n\n"
1195
1196                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1197                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1198                         " (eth-dst)\n"
1199                         "       Configure the NVGRE encapsulation for flows.\n\n"
1200
1201                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1202                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1203                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1204                         "       Configure the NVGRE encapsulation for flows.\n\n"
1205
1206                         "set raw_encap {flow items}\n"
1207                         "       Configure the encapsulation with raw data.\n\n"
1208
1209                         "set raw_decap {flow items}\n"
1210                         "       Configure the decapsulation with raw data.\n\n"
1211
1212                 );
1213         }
1214
1215         if (show_all || !strcmp(res->section, "traffic_management")) {
1216                 cmdline_printf(
1217                         cl,
1218                         "\n"
1219                         "Traffic Management:\n"
1220                         "--------------\n"
1221                         "show port tm cap (port_id)\n"
1222                         "       Display the port TM capability.\n\n"
1223
1224                         "show port tm level cap (port_id) (level_id)\n"
1225                         "       Display the port TM hierarchical level capability.\n\n"
1226
1227                         "show port tm node cap (port_id) (node_id)\n"
1228                         "       Display the port TM node capability.\n\n"
1229
1230                         "show port tm node type (port_id) (node_id)\n"
1231                         "       Display the port TM node type.\n\n"
1232
1233                         "show port tm node stats (port_id) (node_id) (clear)\n"
1234                         "       Display the port TM node stats.\n\n"
1235
1236                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1237                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1238                         " (packet_length_adjust) (packet_mode)\n"
1239                         "       Add port tm node private shaper profile.\n\n"
1240
1241                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1242                         "       Delete port tm node private shaper profile.\n\n"
1243
1244                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1245                         " (shaper_profile_id)\n"
1246                         "       Add/update port tm node shared shaper.\n\n"
1247
1248                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1249                         "       Delete port tm node shared shaper.\n\n"
1250
1251                         "set port tm node shaper profile (port_id) (node_id)"
1252                         " (shaper_profile_id)\n"
1253                         "       Set port tm node shaper profile.\n\n"
1254
1255                         "add port tm node wred profile (port_id) (wred_profile_id)"
1256                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1257                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1258                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1259                         "       Add port tm node wred profile.\n\n"
1260
1261                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1262                         "       Delete port tm node wred profile.\n\n"
1263
1264                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1265                         " (priority) (weight) (level_id) (shaper_profile_id)"
1266                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1267                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1268                         "       Add port tm nonleaf node.\n\n"
1269
1270                         "add port tm nonleaf node pktmode (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 with pkt mode enabled.\n\n"
1275
1276                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1277                         " (priority) (weight) (level_id) (shaper_profile_id)"
1278                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1279                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1280                         "       Add port tm leaf node.\n\n"
1281
1282                         "del port tm node (port_id) (node_id)\n"
1283                         "       Delete port tm node.\n\n"
1284
1285                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1286                         " (priority) (weight)\n"
1287                         "       Set port tm node parent.\n\n"
1288
1289                         "suspend port tm node (port_id) (node_id)"
1290                         "       Suspend tm node.\n\n"
1291
1292                         "resume port tm node (port_id) (node_id)"
1293                         "       Resume tm node.\n\n"
1294
1295                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1296                         "       Commit tm hierarchy.\n\n"
1297
1298                         "set port tm mark ip_ecn (port) (green) (yellow)"
1299                         " (red)\n"
1300                         "    Enables/Disables the traffic management marking"
1301                         " for IP ECN (Explicit Congestion Notification)"
1302                         " packets on a given port\n\n"
1303
1304                         "set port tm mark ip_dscp (port) (green) (yellow)"
1305                         " (red)\n"
1306                         "    Enables/Disables the traffic management marking"
1307                         " on the port for IP dscp packets\n\n"
1308
1309                         "set port tm mark vlan_dei (port) (green) (yellow)"
1310                         " (red)\n"
1311                         "    Enables/Disables the traffic management marking"
1312                         " on the port for VLAN packets with DEI enabled\n\n"
1313                 );
1314         }
1315
1316         if (show_all || !strcmp(res->section, "devices")) {
1317                 cmdline_printf(
1318                         cl,
1319                         "\n"
1320                         "Device Operations:\n"
1321                         "--------------\n"
1322                         "device detach (identifier)\n"
1323                         "       Detach device by identifier.\n\n"
1324                 );
1325         }
1326
1327 }
1328
1329 cmdline_parse_token_string_t cmd_help_long_help =
1330         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1331
1332 cmdline_parse_token_string_t cmd_help_long_section =
1333         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1334                         "all#control#display#config#"
1335                         "ports#registers#filters#traffic_management#devices");
1336
1337 cmdline_parse_inst_t cmd_help_long = {
1338         .f = cmd_help_long_parsed,
1339         .data = NULL,
1340         .help_str = "help all|control|display|config|ports|register|"
1341                 "filters|traffic_management|devices: "
1342                 "Show help",
1343         .tokens = {
1344                 (void *)&cmd_help_long_help,
1345                 (void *)&cmd_help_long_section,
1346                 NULL,
1347         },
1348 };
1349
1350
1351 /* *** start/stop/close all ports *** */
1352 struct cmd_operate_port_result {
1353         cmdline_fixed_string_t keyword;
1354         cmdline_fixed_string_t name;
1355         cmdline_fixed_string_t value;
1356 };
1357
1358 static void cmd_operate_port_parsed(void *parsed_result,
1359                                 __rte_unused struct cmdline *cl,
1360                                 __rte_unused void *data)
1361 {
1362         struct cmd_operate_port_result *res = parsed_result;
1363
1364         if (!strcmp(res->name, "start"))
1365                 start_port(RTE_PORT_ALL);
1366         else if (!strcmp(res->name, "stop"))
1367                 stop_port(RTE_PORT_ALL);
1368         else if (!strcmp(res->name, "close"))
1369                 close_port(RTE_PORT_ALL);
1370         else if (!strcmp(res->name, "reset"))
1371                 reset_port(RTE_PORT_ALL);
1372         else
1373                 printf("Unknown parameter\n");
1374 }
1375
1376 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1377         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1378                                                                 "port");
1379 cmdline_parse_token_string_t cmd_operate_port_all_port =
1380         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1381                                                 "start#stop#close#reset");
1382 cmdline_parse_token_string_t cmd_operate_port_all_all =
1383         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1384
1385 cmdline_parse_inst_t cmd_operate_port = {
1386         .f = cmd_operate_port_parsed,
1387         .data = NULL,
1388         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1389         .tokens = {
1390                 (void *)&cmd_operate_port_all_cmd,
1391                 (void *)&cmd_operate_port_all_port,
1392                 (void *)&cmd_operate_port_all_all,
1393                 NULL,
1394         },
1395 };
1396
1397 /* *** start/stop/close specific port *** */
1398 struct cmd_operate_specific_port_result {
1399         cmdline_fixed_string_t keyword;
1400         cmdline_fixed_string_t name;
1401         uint8_t value;
1402 };
1403
1404 static void cmd_operate_specific_port_parsed(void *parsed_result,
1405                         __rte_unused struct cmdline *cl,
1406                                 __rte_unused void *data)
1407 {
1408         struct cmd_operate_specific_port_result *res = parsed_result;
1409
1410         if (!strcmp(res->name, "start"))
1411                 start_port(res->value);
1412         else if (!strcmp(res->name, "stop"))
1413                 stop_port(res->value);
1414         else if (!strcmp(res->name, "close"))
1415                 close_port(res->value);
1416         else if (!strcmp(res->name, "reset"))
1417                 reset_port(res->value);
1418         else
1419                 printf("Unknown parameter\n");
1420 }
1421
1422 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1423         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1424                                                         keyword, "port");
1425 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1426         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1427                                                 name, "start#stop#close#reset");
1428 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1429         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1430                                                         value, UINT8);
1431
1432 cmdline_parse_inst_t cmd_operate_specific_port = {
1433         .f = cmd_operate_specific_port_parsed,
1434         .data = NULL,
1435         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1436         .tokens = {
1437                 (void *)&cmd_operate_specific_port_cmd,
1438                 (void *)&cmd_operate_specific_port_port,
1439                 (void *)&cmd_operate_specific_port_id,
1440                 NULL,
1441         },
1442 };
1443
1444 /* *** enable port setup (after attach) via iterator or event *** */
1445 struct cmd_set_port_setup_on_result {
1446         cmdline_fixed_string_t set;
1447         cmdline_fixed_string_t port;
1448         cmdline_fixed_string_t setup;
1449         cmdline_fixed_string_t on;
1450         cmdline_fixed_string_t mode;
1451 };
1452
1453 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1454                                 __rte_unused struct cmdline *cl,
1455                                 __rte_unused void *data)
1456 {
1457         struct cmd_set_port_setup_on_result *res = parsed_result;
1458
1459         if (strcmp(res->mode, "event") == 0)
1460                 setup_on_probe_event = true;
1461         else if (strcmp(res->mode, "iterator") == 0)
1462                 setup_on_probe_event = false;
1463         else
1464                 printf("Unknown mode\n");
1465 }
1466
1467 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1468         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1469                         set, "set");
1470 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1471         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1472                         port, "port");
1473 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1474         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1475                         setup, "setup");
1476 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1477         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1478                         on, "on");
1479 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1480         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1481                         mode, "iterator#event");
1482
1483 cmdline_parse_inst_t cmd_set_port_setup_on = {
1484         .f = cmd_set_port_setup_on_parsed,
1485         .data = NULL,
1486         .help_str = "set port setup on iterator|event",
1487         .tokens = {
1488                 (void *)&cmd_set_port_setup_on_set,
1489                 (void *)&cmd_set_port_setup_on_port,
1490                 (void *)&cmd_set_port_setup_on_setup,
1491                 (void *)&cmd_set_port_setup_on_on,
1492                 (void *)&cmd_set_port_setup_on_mode,
1493                 NULL,
1494         },
1495 };
1496
1497 /* *** attach a specified port *** */
1498 struct cmd_operate_attach_port_result {
1499         cmdline_fixed_string_t port;
1500         cmdline_fixed_string_t keyword;
1501         cmdline_multi_string_t identifier;
1502 };
1503
1504 static void cmd_operate_attach_port_parsed(void *parsed_result,
1505                                 __rte_unused struct cmdline *cl,
1506                                 __rte_unused void *data)
1507 {
1508         struct cmd_operate_attach_port_result *res = parsed_result;
1509
1510         if (!strcmp(res->keyword, "attach"))
1511                 attach_port(res->identifier);
1512         else
1513                 printf("Unknown parameter\n");
1514 }
1515
1516 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1517         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1518                         port, "port");
1519 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1520         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1521                         keyword, "attach");
1522 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1523         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1524                         identifier, TOKEN_STRING_MULTI);
1525
1526 cmdline_parse_inst_t cmd_operate_attach_port = {
1527         .f = cmd_operate_attach_port_parsed,
1528         .data = NULL,
1529         .help_str = "port attach <identifier>: "
1530                 "(identifier: pci address or virtual dev name)",
1531         .tokens = {
1532                 (void *)&cmd_operate_attach_port_port,
1533                 (void *)&cmd_operate_attach_port_keyword,
1534                 (void *)&cmd_operate_attach_port_identifier,
1535                 NULL,
1536         },
1537 };
1538
1539 /* *** detach a specified port *** */
1540 struct cmd_operate_detach_port_result {
1541         cmdline_fixed_string_t port;
1542         cmdline_fixed_string_t keyword;
1543         portid_t port_id;
1544 };
1545
1546 static void cmd_operate_detach_port_parsed(void *parsed_result,
1547                                 __rte_unused struct cmdline *cl,
1548                                 __rte_unused void *data)
1549 {
1550         struct cmd_operate_detach_port_result *res = parsed_result;
1551
1552         if (!strcmp(res->keyword, "detach")) {
1553                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1554                 detach_port_device(res->port_id);
1555         } else {
1556                 printf("Unknown parameter\n");
1557         }
1558 }
1559
1560 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1561         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1562                         port, "port");
1563 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1564         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1565                         keyword, "detach");
1566 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1567         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1568                         port_id, UINT16);
1569
1570 cmdline_parse_inst_t cmd_operate_detach_port = {
1571         .f = cmd_operate_detach_port_parsed,
1572         .data = NULL,
1573         .help_str = "port detach <port_id>",
1574         .tokens = {
1575                 (void *)&cmd_operate_detach_port_port,
1576                 (void *)&cmd_operate_detach_port_keyword,
1577                 (void *)&cmd_operate_detach_port_port_id,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** detach device by identifier *** */
1583 struct cmd_operate_detach_device_result {
1584         cmdline_fixed_string_t device;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t identifier;
1587 };
1588
1589 static void cmd_operate_detach_device_parsed(void *parsed_result,
1590                                 __rte_unused struct cmdline *cl,
1591                                 __rte_unused void *data)
1592 {
1593         struct cmd_operate_detach_device_result *res = parsed_result;
1594
1595         if (!strcmp(res->keyword, "detach"))
1596                 detach_devargs(res->identifier);
1597         else
1598                 printf("Unknown parameter\n");
1599 }
1600
1601 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1602         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1603                         device, "device");
1604 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1605         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1606                         keyword, "detach");
1607 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1608         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1609                         identifier, NULL);
1610
1611 cmdline_parse_inst_t cmd_operate_detach_device = {
1612         .f = cmd_operate_detach_device_parsed,
1613         .data = NULL,
1614         .help_str = "device detach <identifier>:"
1615                 "(identifier: pci address or virtual dev name)",
1616         .tokens = {
1617                 (void *)&cmd_operate_detach_device_device,
1618                 (void *)&cmd_operate_detach_device_keyword,
1619                 (void *)&cmd_operate_detach_device_identifier,
1620                 NULL,
1621         },
1622 };
1623 /* *** configure speed for all ports *** */
1624 struct cmd_config_speed_all {
1625         cmdline_fixed_string_t port;
1626         cmdline_fixed_string_t keyword;
1627         cmdline_fixed_string_t all;
1628         cmdline_fixed_string_t item1;
1629         cmdline_fixed_string_t item2;
1630         cmdline_fixed_string_t value1;
1631         cmdline_fixed_string_t value2;
1632 };
1633
1634 static int
1635 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1636 {
1637
1638         int duplex;
1639
1640         if (!strcmp(duplexstr, "half")) {
1641                 duplex = ETH_LINK_HALF_DUPLEX;
1642         } else if (!strcmp(duplexstr, "full")) {
1643                 duplex = ETH_LINK_FULL_DUPLEX;
1644         } else if (!strcmp(duplexstr, "auto")) {
1645                 duplex = ETH_LINK_FULL_DUPLEX;
1646         } else {
1647                 printf("Unknown duplex parameter\n");
1648                 return -1;
1649         }
1650
1651         if (!strcmp(speedstr, "10")) {
1652                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1653                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1654         } else if (!strcmp(speedstr, "100")) {
1655                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1656                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1657         } else {
1658                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1659                         printf("Invalid speed/duplex parameters\n");
1660                         return -1;
1661                 }
1662                 if (!strcmp(speedstr, "1000")) {
1663                         *speed = ETH_LINK_SPEED_1G;
1664                 } else if (!strcmp(speedstr, "10000")) {
1665                         *speed = ETH_LINK_SPEED_10G;
1666                 } else if (!strcmp(speedstr, "25000")) {
1667                         *speed = ETH_LINK_SPEED_25G;
1668                 } else if (!strcmp(speedstr, "40000")) {
1669                         *speed = ETH_LINK_SPEED_40G;
1670                 } else if (!strcmp(speedstr, "50000")) {
1671                         *speed = ETH_LINK_SPEED_50G;
1672                 } else if (!strcmp(speedstr, "100000")) {
1673                         *speed = ETH_LINK_SPEED_100G;
1674                 } else if (!strcmp(speedstr, "200000")) {
1675                         *speed = ETH_LINK_SPEED_200G;
1676                 } else if (!strcmp(speedstr, "auto")) {
1677                         *speed = ETH_LINK_SPEED_AUTONEG;
1678                 } else {
1679                         printf("Unknown speed parameter\n");
1680                         return -1;
1681                 }
1682         }
1683
1684         return 0;
1685 }
1686
1687 static void
1688 cmd_config_speed_all_parsed(void *parsed_result,
1689                         __rte_unused struct cmdline *cl,
1690                         __rte_unused void *data)
1691 {
1692         struct cmd_config_speed_all *res = parsed_result;
1693         uint32_t link_speed;
1694         portid_t pid;
1695
1696         if (!all_ports_stopped()) {
1697                 printf("Please stop all ports first\n");
1698                 return;
1699         }
1700
1701         if (parse_and_check_speed_duplex(res->value1, res->value2,
1702                         &link_speed) < 0)
1703                 return;
1704
1705         RTE_ETH_FOREACH_DEV(pid) {
1706                 ports[pid].dev_conf.link_speeds = link_speed;
1707         }
1708
1709         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1710 }
1711
1712 cmdline_parse_token_string_t cmd_config_speed_all_port =
1713         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1714 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1715         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1716                                                         "config");
1717 cmdline_parse_token_string_t cmd_config_speed_all_all =
1718         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1719 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1720         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1721 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1722         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1723                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1724 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1726 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1727         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1728                                                 "half#full#auto");
1729
1730 cmdline_parse_inst_t cmd_config_speed_all = {
1731         .f = cmd_config_speed_all_parsed,
1732         .data = NULL,
1733         .help_str = "port config all speed "
1734                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1735                                                         "half|full|auto",
1736         .tokens = {
1737                 (void *)&cmd_config_speed_all_port,
1738                 (void *)&cmd_config_speed_all_keyword,
1739                 (void *)&cmd_config_speed_all_all,
1740                 (void *)&cmd_config_speed_all_item1,
1741                 (void *)&cmd_config_speed_all_value1,
1742                 (void *)&cmd_config_speed_all_item2,
1743                 (void *)&cmd_config_speed_all_value2,
1744                 NULL,
1745         },
1746 };
1747
1748 /* *** configure speed for specific port *** */
1749 struct cmd_config_speed_specific {
1750         cmdline_fixed_string_t port;
1751         cmdline_fixed_string_t keyword;
1752         portid_t id;
1753         cmdline_fixed_string_t item1;
1754         cmdline_fixed_string_t item2;
1755         cmdline_fixed_string_t value1;
1756         cmdline_fixed_string_t value2;
1757 };
1758
1759 static void
1760 cmd_config_speed_specific_parsed(void *parsed_result,
1761                                 __rte_unused struct cmdline *cl,
1762                                 __rte_unused void *data)
1763 {
1764         struct cmd_config_speed_specific *res = parsed_result;
1765         uint32_t link_speed;
1766
1767         if (!all_ports_stopped()) {
1768                 printf("Please stop all ports first\n");
1769                 return;
1770         }
1771
1772         if (port_id_is_invalid(res->id, ENABLED_WARN))
1773                 return;
1774
1775         if (parse_and_check_speed_duplex(res->value1, res->value2,
1776                         &link_speed) < 0)
1777                 return;
1778
1779         ports[res->id].dev_conf.link_speeds = link_speed;
1780
1781         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1782 }
1783
1784
1785 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1786         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1787                                                                 "port");
1788 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1789         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1790                                                                 "config");
1791 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1792         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1793 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1794         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1795                                                                 "speed");
1796 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1798                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1799 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1800         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1801                                                                 "duplex");
1802 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1803         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1804                                                         "half#full#auto");
1805
1806 cmdline_parse_inst_t cmd_config_speed_specific = {
1807         .f = cmd_config_speed_specific_parsed,
1808         .data = NULL,
1809         .help_str = "port config <port_id> speed "
1810                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1811                                                         "half|full|auto",
1812         .tokens = {
1813                 (void *)&cmd_config_speed_specific_port,
1814                 (void *)&cmd_config_speed_specific_keyword,
1815                 (void *)&cmd_config_speed_specific_id,
1816                 (void *)&cmd_config_speed_specific_item1,
1817                 (void *)&cmd_config_speed_specific_value1,
1818                 (void *)&cmd_config_speed_specific_item2,
1819                 (void *)&cmd_config_speed_specific_value2,
1820                 NULL,
1821         },
1822 };
1823
1824 /* *** configure loopback for all ports *** */
1825 struct cmd_config_loopback_all {
1826         cmdline_fixed_string_t port;
1827         cmdline_fixed_string_t keyword;
1828         cmdline_fixed_string_t all;
1829         cmdline_fixed_string_t item;
1830         uint32_t mode;
1831 };
1832
1833 static void
1834 cmd_config_loopback_all_parsed(void *parsed_result,
1835                         __rte_unused struct cmdline *cl,
1836                         __rte_unused void *data)
1837 {
1838         struct cmd_config_loopback_all *res = parsed_result;
1839         portid_t pid;
1840
1841         if (!all_ports_stopped()) {
1842                 printf("Please stop all ports first\n");
1843                 return;
1844         }
1845
1846         RTE_ETH_FOREACH_DEV(pid) {
1847                 ports[pid].dev_conf.lpbk_mode = res->mode;
1848         }
1849
1850         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1851 }
1852
1853 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1854         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1855 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1856         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1857                                                         "config");
1858 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1859         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1860 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1861         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1862                                                         "loopback");
1863 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1864         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1865
1866 cmdline_parse_inst_t cmd_config_loopback_all = {
1867         .f = cmd_config_loopback_all_parsed,
1868         .data = NULL,
1869         .help_str = "port config all loopback <mode>",
1870         .tokens = {
1871                 (void *)&cmd_config_loopback_all_port,
1872                 (void *)&cmd_config_loopback_all_keyword,
1873                 (void *)&cmd_config_loopback_all_all,
1874                 (void *)&cmd_config_loopback_all_item,
1875                 (void *)&cmd_config_loopback_all_mode,
1876                 NULL,
1877         },
1878 };
1879
1880 /* *** configure loopback for specific port *** */
1881 struct cmd_config_loopback_specific {
1882         cmdline_fixed_string_t port;
1883         cmdline_fixed_string_t keyword;
1884         uint16_t port_id;
1885         cmdline_fixed_string_t item;
1886         uint32_t mode;
1887 };
1888
1889 static void
1890 cmd_config_loopback_specific_parsed(void *parsed_result,
1891                                 __rte_unused struct cmdline *cl,
1892                                 __rte_unused void *data)
1893 {
1894         struct cmd_config_loopback_specific *res = parsed_result;
1895
1896         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1897                 return;
1898
1899         if (!port_is_stopped(res->port_id)) {
1900                 printf("Please stop port %u first\n", res->port_id);
1901                 return;
1902         }
1903
1904         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1905
1906         cmd_reconfig_device_queue(res->port_id, 1, 1);
1907 }
1908
1909
1910 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1911         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1912                                                                 "port");
1913 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1914         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1915                                                                 "config");
1916 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1917         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1918                                                                 UINT16);
1919 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1920         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1921                                                                 "loopback");
1922 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1923         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1924                               UINT32);
1925
1926 cmdline_parse_inst_t cmd_config_loopback_specific = {
1927         .f = cmd_config_loopback_specific_parsed,
1928         .data = NULL,
1929         .help_str = "port config <port_id> loopback <mode>",
1930         .tokens = {
1931                 (void *)&cmd_config_loopback_specific_port,
1932                 (void *)&cmd_config_loopback_specific_keyword,
1933                 (void *)&cmd_config_loopback_specific_id,
1934                 (void *)&cmd_config_loopback_specific_item,
1935                 (void *)&cmd_config_loopback_specific_mode,
1936                 NULL,
1937         },
1938 };
1939
1940 /* *** configure txq/rxq, txd/rxd *** */
1941 struct cmd_config_rx_tx {
1942         cmdline_fixed_string_t port;
1943         cmdline_fixed_string_t keyword;
1944         cmdline_fixed_string_t all;
1945         cmdline_fixed_string_t name;
1946         uint16_t value;
1947 };
1948
1949 static void
1950 cmd_config_rx_tx_parsed(void *parsed_result,
1951                         __rte_unused struct cmdline *cl,
1952                         __rte_unused void *data)
1953 {
1954         struct cmd_config_rx_tx *res = parsed_result;
1955
1956         if (!all_ports_stopped()) {
1957                 printf("Please stop all ports first\n");
1958                 return;
1959         }
1960         if (!strcmp(res->name, "rxq")) {
1961                 if (!res->value && !nb_txq) {
1962                         printf("Warning: Either rx or tx queues should be non zero\n");
1963                         return;
1964                 }
1965                 if (check_nb_rxq(res->value) != 0)
1966                         return;
1967                 nb_rxq = res->value;
1968         }
1969         else if (!strcmp(res->name, "txq")) {
1970                 if (!res->value && !nb_rxq) {
1971                         printf("Warning: Either rx or tx queues should be non zero\n");
1972                         return;
1973                 }
1974                 if (check_nb_txq(res->value) != 0)
1975                         return;
1976                 nb_txq = res->value;
1977         }
1978         else if (!strcmp(res->name, "rxd")) {
1979                 if (check_nb_rxd(res->value) != 0)
1980                         return;
1981                 nb_rxd = res->value;
1982         } else if (!strcmp(res->name, "txd")) {
1983                 if (check_nb_txd(res->value) != 0)
1984                         return;
1985
1986                 nb_txd = res->value;
1987         } else {
1988                 printf("Unknown parameter\n");
1989                 return;
1990         }
1991
1992         fwd_config_setup();
1993
1994         init_port_config();
1995
1996         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1997 }
1998
1999 cmdline_parse_token_string_t cmd_config_rx_tx_port =
2000         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
2001 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
2002         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
2003 cmdline_parse_token_string_t cmd_config_rx_tx_all =
2004         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
2005 cmdline_parse_token_string_t cmd_config_rx_tx_name =
2006         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
2007                                                 "rxq#txq#rxd#txd");
2008 cmdline_parse_token_num_t cmd_config_rx_tx_value =
2009         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
2010
2011 cmdline_parse_inst_t cmd_config_rx_tx = {
2012         .f = cmd_config_rx_tx_parsed,
2013         .data = NULL,
2014         .help_str = "port config all rxq|txq|rxd|txd <value>",
2015         .tokens = {
2016                 (void *)&cmd_config_rx_tx_port,
2017                 (void *)&cmd_config_rx_tx_keyword,
2018                 (void *)&cmd_config_rx_tx_all,
2019                 (void *)&cmd_config_rx_tx_name,
2020                 (void *)&cmd_config_rx_tx_value,
2021                 NULL,
2022         },
2023 };
2024
2025 /* *** config max packet length *** */
2026 struct cmd_config_max_pkt_len_result {
2027         cmdline_fixed_string_t port;
2028         cmdline_fixed_string_t keyword;
2029         cmdline_fixed_string_t all;
2030         cmdline_fixed_string_t name;
2031         uint32_t value;
2032 };
2033
2034 static void
2035 cmd_config_max_pkt_len_parsed(void *parsed_result,
2036                                 __rte_unused struct cmdline *cl,
2037                                 __rte_unused void *data)
2038 {
2039         struct cmd_config_max_pkt_len_result *res = parsed_result;
2040         portid_t pid;
2041
2042         if (!all_ports_stopped()) {
2043                 printf("Please stop all ports first\n");
2044                 return;
2045         }
2046
2047         RTE_ETH_FOREACH_DEV(pid) {
2048                 struct rte_port *port = &ports[pid];
2049                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
2050
2051                 if (!strcmp(res->name, "max-pkt-len")) {
2052                         if (res->value < RTE_ETHER_MIN_LEN) {
2053                                 printf("max-pkt-len can not be less than %d\n",
2054                                                 RTE_ETHER_MIN_LEN);
2055                                 return;
2056                         }
2057                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
2058                                 return;
2059
2060                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
2061                         if (res->value > RTE_ETHER_MAX_LEN)
2062                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
2063                         else
2064                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2065                         port->dev_conf.rxmode.offloads = rx_offloads;
2066                 } else {
2067                         printf("Unknown parameter\n");
2068                         return;
2069                 }
2070         }
2071
2072         init_port_config();
2073
2074         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2075 }
2076
2077 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2078         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2079                                                                 "port");
2080 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2081         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2082                                                                 "config");
2083 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2084         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2085                                                                 "all");
2086 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2087         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2088                                                                 "max-pkt-len");
2089 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2090         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2091                                                                 UINT32);
2092
2093 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2094         .f = cmd_config_max_pkt_len_parsed,
2095         .data = NULL,
2096         .help_str = "port config all max-pkt-len <value>",
2097         .tokens = {
2098                 (void *)&cmd_config_max_pkt_len_port,
2099                 (void *)&cmd_config_max_pkt_len_keyword,
2100                 (void *)&cmd_config_max_pkt_len_all,
2101                 (void *)&cmd_config_max_pkt_len_name,
2102                 (void *)&cmd_config_max_pkt_len_value,
2103                 NULL,
2104         },
2105 };
2106
2107 /* *** config max LRO aggregated packet size *** */
2108 struct cmd_config_max_lro_pkt_size_result {
2109         cmdline_fixed_string_t port;
2110         cmdline_fixed_string_t keyword;
2111         cmdline_fixed_string_t all;
2112         cmdline_fixed_string_t name;
2113         uint32_t value;
2114 };
2115
2116 static void
2117 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2118                                 __rte_unused struct cmdline *cl,
2119                                 __rte_unused void *data)
2120 {
2121         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2122         portid_t pid;
2123
2124         if (!all_ports_stopped()) {
2125                 printf("Please stop all ports first\n");
2126                 return;
2127         }
2128
2129         RTE_ETH_FOREACH_DEV(pid) {
2130                 struct rte_port *port = &ports[pid];
2131
2132                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2133                         if (res->value ==
2134                                         port->dev_conf.rxmode.max_lro_pkt_size)
2135                                 return;
2136
2137                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2138                 } else {
2139                         printf("Unknown parameter\n");
2140                         return;
2141                 }
2142         }
2143
2144         init_port_config();
2145
2146         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2147 }
2148
2149 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2150         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2151                                  port, "port");
2152 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2154                                  keyword, "config");
2155 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2156         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2157                                  all, "all");
2158 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2160                                  name, "max-lro-pkt-size");
2161 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2162         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2163                               value, UINT32);
2164
2165 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2166         .f = cmd_config_max_lro_pkt_size_parsed,
2167         .data = NULL,
2168         .help_str = "port config all max-lro-pkt-size <value>",
2169         .tokens = {
2170                 (void *)&cmd_config_max_lro_pkt_size_port,
2171                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2172                 (void *)&cmd_config_max_lro_pkt_size_all,
2173                 (void *)&cmd_config_max_lro_pkt_size_name,
2174                 (void *)&cmd_config_max_lro_pkt_size_value,
2175                 NULL,
2176         },
2177 };
2178
2179 /* *** configure port MTU *** */
2180 struct cmd_config_mtu_result {
2181         cmdline_fixed_string_t port;
2182         cmdline_fixed_string_t keyword;
2183         cmdline_fixed_string_t mtu;
2184         portid_t port_id;
2185         uint16_t value;
2186 };
2187
2188 static void
2189 cmd_config_mtu_parsed(void *parsed_result,
2190                       __rte_unused struct cmdline *cl,
2191                       __rte_unused void *data)
2192 {
2193         struct cmd_config_mtu_result *res = parsed_result;
2194
2195         if (res->value < RTE_ETHER_MIN_LEN) {
2196                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2197                 return;
2198         }
2199         port_mtu_set(res->port_id, res->value);
2200 }
2201
2202 cmdline_parse_token_string_t cmd_config_mtu_port =
2203         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2204                                  "port");
2205 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2206         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2207                                  "config");
2208 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2209         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2210                                  "mtu");
2211 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2212         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2213 cmdline_parse_token_num_t cmd_config_mtu_value =
2214         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2215
2216 cmdline_parse_inst_t cmd_config_mtu = {
2217         .f = cmd_config_mtu_parsed,
2218         .data = NULL,
2219         .help_str = "port config mtu <port_id> <value>",
2220         .tokens = {
2221                 (void *)&cmd_config_mtu_port,
2222                 (void *)&cmd_config_mtu_keyword,
2223                 (void *)&cmd_config_mtu_mtu,
2224                 (void *)&cmd_config_mtu_port_id,
2225                 (void *)&cmd_config_mtu_value,
2226                 NULL,
2227         },
2228 };
2229
2230 /* *** configure rx mode *** */
2231 struct cmd_config_rx_mode_flag {
2232         cmdline_fixed_string_t port;
2233         cmdline_fixed_string_t keyword;
2234         cmdline_fixed_string_t all;
2235         cmdline_fixed_string_t name;
2236         cmdline_fixed_string_t value;
2237 };
2238
2239 static void
2240 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2241                                 __rte_unused struct cmdline *cl,
2242                                 __rte_unused void *data)
2243 {
2244         struct cmd_config_rx_mode_flag *res = parsed_result;
2245
2246         if (!all_ports_stopped()) {
2247                 printf("Please stop all ports first\n");
2248                 return;
2249         }
2250
2251         if (!strcmp(res->name, "drop-en")) {
2252                 if (!strcmp(res->value, "on"))
2253                         rx_drop_en = 1;
2254                 else if (!strcmp(res->value, "off"))
2255                         rx_drop_en = 0;
2256                 else {
2257                         printf("Unknown parameter\n");
2258                         return;
2259                 }
2260         } else {
2261                 printf("Unknown parameter\n");
2262                 return;
2263         }
2264
2265         init_port_config();
2266
2267         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2268 }
2269
2270 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2271         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2272 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2273         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2274                                                                 "config");
2275 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2276         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2277 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2278         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2279                                         "drop-en");
2280 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2281         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2282                                                         "on#off");
2283
2284 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2285         .f = cmd_config_rx_mode_flag_parsed,
2286         .data = NULL,
2287         .help_str = "port config all drop-en on|off",
2288         .tokens = {
2289                 (void *)&cmd_config_rx_mode_flag_port,
2290                 (void *)&cmd_config_rx_mode_flag_keyword,
2291                 (void *)&cmd_config_rx_mode_flag_all,
2292                 (void *)&cmd_config_rx_mode_flag_name,
2293                 (void *)&cmd_config_rx_mode_flag_value,
2294                 NULL,
2295         },
2296 };
2297
2298 /* *** configure rss *** */
2299 struct cmd_config_rss {
2300         cmdline_fixed_string_t port;
2301         cmdline_fixed_string_t keyword;
2302         cmdline_fixed_string_t all;
2303         cmdline_fixed_string_t name;
2304         cmdline_fixed_string_t value;
2305 };
2306
2307 static void
2308 cmd_config_rss_parsed(void *parsed_result,
2309                         __rte_unused struct cmdline *cl,
2310                         __rte_unused void *data)
2311 {
2312         struct cmd_config_rss *res = parsed_result;
2313         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2314         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2315         int use_default = 0;
2316         int all_updated = 1;
2317         int diag;
2318         uint16_t i;
2319         int ret;
2320
2321         if (!strcmp(res->value, "all"))
2322                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2323                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2324                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2325                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2326         else if (!strcmp(res->value, "eth"))
2327                 rss_conf.rss_hf = ETH_RSS_ETH;
2328         else if (!strcmp(res->value, "vlan"))
2329                 rss_conf.rss_hf = ETH_RSS_VLAN;
2330         else if (!strcmp(res->value, "ip"))
2331                 rss_conf.rss_hf = ETH_RSS_IP;
2332         else if (!strcmp(res->value, "udp"))
2333                 rss_conf.rss_hf = ETH_RSS_UDP;
2334         else if (!strcmp(res->value, "tcp"))
2335                 rss_conf.rss_hf = ETH_RSS_TCP;
2336         else if (!strcmp(res->value, "sctp"))
2337                 rss_conf.rss_hf = ETH_RSS_SCTP;
2338         else if (!strcmp(res->value, "ether"))
2339                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2340         else if (!strcmp(res->value, "port"))
2341                 rss_conf.rss_hf = ETH_RSS_PORT;
2342         else if (!strcmp(res->value, "vxlan"))
2343                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2344         else if (!strcmp(res->value, "geneve"))
2345                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2346         else if (!strcmp(res->value, "nvgre"))
2347                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2348         else if (!strcmp(res->value, "l3-pre32"))
2349                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2350         else if (!strcmp(res->value, "l3-pre40"))
2351                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2352         else if (!strcmp(res->value, "l3-pre48"))
2353                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2354         else if (!strcmp(res->value, "l3-pre56"))
2355                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2356         else if (!strcmp(res->value, "l3-pre64"))
2357                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2358         else if (!strcmp(res->value, "l3-pre96"))
2359                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2360         else if (!strcmp(res->value, "l3-src-only"))
2361                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2362         else if (!strcmp(res->value, "l3-dst-only"))
2363                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2364         else if (!strcmp(res->value, "l4-src-only"))
2365                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2366         else if (!strcmp(res->value, "l4-dst-only"))
2367                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2368         else if (!strcmp(res->value, "l2-src-only"))
2369                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2370         else if (!strcmp(res->value, "l2-dst-only"))
2371                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2372         else if (!strcmp(res->value, "l2tpv3"))
2373                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2374         else if (!strcmp(res->value, "esp"))
2375                 rss_conf.rss_hf = ETH_RSS_ESP;
2376         else if (!strcmp(res->value, "ah"))
2377                 rss_conf.rss_hf = ETH_RSS_AH;
2378         else if (!strcmp(res->value, "pfcp"))
2379                 rss_conf.rss_hf = ETH_RSS_PFCP;
2380         else if (!strcmp(res->value, "pppoe"))
2381                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2382         else if (!strcmp(res->value, "gtpu"))
2383                 rss_conf.rss_hf = ETH_RSS_GTPU;
2384         else if (!strcmp(res->value, "none"))
2385                 rss_conf.rss_hf = 0;
2386         else if (!strcmp(res->value, "level-default")) {
2387                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2388                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2389         } else if (!strcmp(res->value, "level-outer")) {
2390                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2391                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2392         } else if (!strcmp(res->value, "level-inner")) {
2393                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2394                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2395         } else if (!strcmp(res->value, "default"))
2396                 use_default = 1;
2397         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2398                                                 atoi(res->value) < 64)
2399                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2400         else {
2401                 printf("Unknown parameter\n");
2402                 return;
2403         }
2404         rss_conf.rss_key = NULL;
2405         /* Update global configuration for RSS types. */
2406         RTE_ETH_FOREACH_DEV(i) {
2407                 struct rte_eth_rss_conf local_rss_conf;
2408
2409                 ret = eth_dev_info_get_print_err(i, &dev_info);
2410                 if (ret != 0)
2411                         return;
2412
2413                 if (use_default)
2414                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2415
2416                 local_rss_conf = rss_conf;
2417                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2418                         dev_info.flow_type_rss_offloads;
2419                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2420                         printf("Port %u modified RSS hash function based on hardware support,"
2421                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2422                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2423                 }
2424                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2425                 if (diag < 0) {
2426                         all_updated = 0;
2427                         printf("Configuration of RSS hash at ethernet port %d "
2428                                 "failed with error (%d): %s.\n",
2429                                 i, -diag, strerror(-diag));
2430                 }
2431         }
2432         if (all_updated && !use_default) {
2433                 rss_hf = rss_conf.rss_hf;
2434                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2435         }
2436 }
2437
2438 cmdline_parse_token_string_t cmd_config_rss_port =
2439         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2440 cmdline_parse_token_string_t cmd_config_rss_keyword =
2441         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2442 cmdline_parse_token_string_t cmd_config_rss_all =
2443         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2444 cmdline_parse_token_string_t cmd_config_rss_name =
2445         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2446 cmdline_parse_token_string_t cmd_config_rss_value =
2447         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2448
2449 cmdline_parse_inst_t cmd_config_rss = {
2450         .f = cmd_config_rss_parsed,
2451         .data = NULL,
2452         .help_str = "port config all rss "
2453                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2454                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2455                 "level-outer|level-inner|<flowtype_id>",
2456         .tokens = {
2457                 (void *)&cmd_config_rss_port,
2458                 (void *)&cmd_config_rss_keyword,
2459                 (void *)&cmd_config_rss_all,
2460                 (void *)&cmd_config_rss_name,
2461                 (void *)&cmd_config_rss_value,
2462                 NULL,
2463         },
2464 };
2465
2466 /* *** configure rss hash key *** */
2467 struct cmd_config_rss_hash_key {
2468         cmdline_fixed_string_t port;
2469         cmdline_fixed_string_t config;
2470         portid_t port_id;
2471         cmdline_fixed_string_t rss_hash_key;
2472         cmdline_fixed_string_t rss_type;
2473         cmdline_fixed_string_t key;
2474 };
2475
2476 static uint8_t
2477 hexa_digit_to_value(char hexa_digit)
2478 {
2479         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2480                 return (uint8_t) (hexa_digit - '0');
2481         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2482                 return (uint8_t) ((hexa_digit - 'a') + 10);
2483         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2484                 return (uint8_t) ((hexa_digit - 'A') + 10);
2485         /* Invalid hexa digit */
2486         return 0xFF;
2487 }
2488
2489 static uint8_t
2490 parse_and_check_key_hexa_digit(char *key, int idx)
2491 {
2492         uint8_t hexa_v;
2493
2494         hexa_v = hexa_digit_to_value(key[idx]);
2495         if (hexa_v == 0xFF)
2496                 printf("invalid key: character %c at position %d is not a "
2497                        "valid hexa digit\n", key[idx], idx);
2498         return hexa_v;
2499 }
2500
2501 static void
2502 cmd_config_rss_hash_key_parsed(void *parsed_result,
2503                                __rte_unused struct cmdline *cl,
2504                                __rte_unused void *data)
2505 {
2506         struct cmd_config_rss_hash_key *res = parsed_result;
2507         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2508         uint8_t xdgt0;
2509         uint8_t xdgt1;
2510         int i;
2511         struct rte_eth_dev_info dev_info;
2512         uint8_t hash_key_size;
2513         uint32_t key_len;
2514         int ret;
2515
2516         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2517         if (ret != 0)
2518                 return;
2519
2520         if (dev_info.hash_key_size > 0 &&
2521                         dev_info.hash_key_size <= sizeof(hash_key))
2522                 hash_key_size = dev_info.hash_key_size;
2523         else {
2524                 printf("dev_info did not provide a valid hash key size\n");
2525                 return;
2526         }
2527         /* Check the length of the RSS hash key */
2528         key_len = strlen(res->key);
2529         if (key_len != (hash_key_size * 2)) {
2530                 printf("key length: %d invalid - key must be a string of %d"
2531                            " hexa-decimal numbers\n",
2532                            (int) key_len, hash_key_size * 2);
2533                 return;
2534         }
2535         /* Translate RSS hash key into binary representation */
2536         for (i = 0; i < hash_key_size; i++) {
2537                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2538                 if (xdgt0 == 0xFF)
2539                         return;
2540                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2541                 if (xdgt1 == 0xFF)
2542                         return;
2543                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2544         }
2545         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2546                         hash_key_size);
2547 }
2548
2549 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2550         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2551 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2552         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2553                                  "config");
2554 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2555         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2556 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2557         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2558                                  rss_hash_key, "rss-hash-key");
2559 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2560         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2561                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2562                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2563                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2564                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2565                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2566                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2567                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2568 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2569         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2570
2571 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2572         .f = cmd_config_rss_hash_key_parsed,
2573         .data = NULL,
2574         .help_str = "port config <port_id> rss-hash-key "
2575                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2576                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2577                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2578                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2579                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2580                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2581                 "<string of hex digits (variable length, NIC dependent)>",
2582         .tokens = {
2583                 (void *)&cmd_config_rss_hash_key_port,
2584                 (void *)&cmd_config_rss_hash_key_config,
2585                 (void *)&cmd_config_rss_hash_key_port_id,
2586                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2587                 (void *)&cmd_config_rss_hash_key_rss_type,
2588                 (void *)&cmd_config_rss_hash_key_value,
2589                 NULL,
2590         },
2591 };
2592
2593 /* *** configure port rxq/txq ring size *** */
2594 struct cmd_config_rxtx_ring_size {
2595         cmdline_fixed_string_t port;
2596         cmdline_fixed_string_t config;
2597         portid_t portid;
2598         cmdline_fixed_string_t rxtxq;
2599         uint16_t qid;
2600         cmdline_fixed_string_t rsize;
2601         uint16_t size;
2602 };
2603
2604 static void
2605 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2606                                  __rte_unused struct cmdline *cl,
2607                                  __rte_unused void *data)
2608 {
2609         struct cmd_config_rxtx_ring_size *res = parsed_result;
2610         struct rte_port *port;
2611         uint8_t isrx;
2612
2613         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2614                 return;
2615
2616         if (res->portid == (portid_t)RTE_PORT_ALL) {
2617                 printf("Invalid port id\n");
2618                 return;
2619         }
2620
2621         port = &ports[res->portid];
2622
2623         if (!strcmp(res->rxtxq, "rxq"))
2624                 isrx = 1;
2625         else if (!strcmp(res->rxtxq, "txq"))
2626                 isrx = 0;
2627         else {
2628                 printf("Unknown parameter\n");
2629                 return;
2630         }
2631
2632         if (isrx && rx_queue_id_is_invalid(res->qid))
2633                 return;
2634         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2635                 return;
2636
2637         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2638                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2639                        rx_free_thresh);
2640                 return;
2641         }
2642
2643         if (isrx)
2644                 port->nb_rx_desc[res->qid] = res->size;
2645         else
2646                 port->nb_tx_desc[res->qid] = res->size;
2647
2648         cmd_reconfig_device_queue(res->portid, 0, 1);
2649 }
2650
2651 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2652         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2653                                  port, "port");
2654 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2655         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2656                                  config, "config");
2657 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2658         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2659                                  portid, UINT16);
2660 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2661         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2662                                  rxtxq, "rxq#txq");
2663 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2664         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2665                               qid, UINT16);
2666 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2667         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2668                                  rsize, "ring_size");
2669 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2670         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2671                               size, UINT16);
2672
2673 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2674         .f = cmd_config_rxtx_ring_size_parsed,
2675         .data = NULL,
2676         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2677         .tokens = {
2678                 (void *)&cmd_config_rxtx_ring_size_port,
2679                 (void *)&cmd_config_rxtx_ring_size_config,
2680                 (void *)&cmd_config_rxtx_ring_size_portid,
2681                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2682                 (void *)&cmd_config_rxtx_ring_size_qid,
2683                 (void *)&cmd_config_rxtx_ring_size_rsize,
2684                 (void *)&cmd_config_rxtx_ring_size_size,
2685                 NULL,
2686         },
2687 };
2688
2689 /* *** configure port rxq/txq start/stop *** */
2690 struct cmd_config_rxtx_queue {
2691         cmdline_fixed_string_t port;
2692         portid_t portid;
2693         cmdline_fixed_string_t rxtxq;
2694         uint16_t qid;
2695         cmdline_fixed_string_t opname;
2696 };
2697
2698 static void
2699 cmd_config_rxtx_queue_parsed(void *parsed_result,
2700                         __rte_unused struct cmdline *cl,
2701                         __rte_unused void *data)
2702 {
2703         struct cmd_config_rxtx_queue *res = parsed_result;
2704         uint8_t isrx;
2705         uint8_t isstart;
2706         int ret = 0;
2707
2708         if (test_done == 0) {
2709                 printf("Please stop forwarding first\n");
2710                 return;
2711         }
2712
2713         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2714                 return;
2715
2716         if (port_is_started(res->portid) != 1) {
2717                 printf("Please start port %u first\n", res->portid);
2718                 return;
2719         }
2720
2721         if (!strcmp(res->rxtxq, "rxq"))
2722                 isrx = 1;
2723         else if (!strcmp(res->rxtxq, "txq"))
2724                 isrx = 0;
2725         else {
2726                 printf("Unknown parameter\n");
2727                 return;
2728         }
2729
2730         if (isrx && rx_queue_id_is_invalid(res->qid))
2731                 return;
2732         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2733                 return;
2734
2735         if (!strcmp(res->opname, "start"))
2736                 isstart = 1;
2737         else if (!strcmp(res->opname, "stop"))
2738                 isstart = 0;
2739         else {
2740                 printf("Unknown parameter\n");
2741                 return;
2742         }
2743
2744         if (isstart && isrx)
2745                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2746         else if (!isstart && isrx)
2747                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2748         else if (isstart && !isrx)
2749                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2750         else
2751                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2752
2753         if (ret == -ENOTSUP)
2754                 printf("Function not supported in PMD driver\n");
2755 }
2756
2757 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2758         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2759 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2760         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2761 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2762         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2763 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2764         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2765 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2766         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2767                                                 "start#stop");
2768
2769 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2770         .f = cmd_config_rxtx_queue_parsed,
2771         .data = NULL,
2772         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2773         .tokens = {
2774                 (void *)&cmd_config_rxtx_queue_port,
2775                 (void *)&cmd_config_rxtx_queue_portid,
2776                 (void *)&cmd_config_rxtx_queue_rxtxq,
2777                 (void *)&cmd_config_rxtx_queue_qid,
2778                 (void *)&cmd_config_rxtx_queue_opname,
2779                 NULL,
2780         },
2781 };
2782
2783 /* *** configure port rxq/txq deferred start on/off *** */
2784 struct cmd_config_deferred_start_rxtx_queue {
2785         cmdline_fixed_string_t port;
2786         portid_t port_id;
2787         cmdline_fixed_string_t rxtxq;
2788         uint16_t qid;
2789         cmdline_fixed_string_t opname;
2790         cmdline_fixed_string_t state;
2791 };
2792
2793 static void
2794 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2795                         __rte_unused struct cmdline *cl,
2796                         __rte_unused void *data)
2797 {
2798         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2799         struct rte_port *port;
2800         uint8_t isrx;
2801         uint8_t ison;
2802         uint8_t needreconfig = 0;
2803
2804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2805                 return;
2806
2807         if (port_is_started(res->port_id) != 0) {
2808                 printf("Please stop port %u first\n", res->port_id);
2809                 return;
2810         }
2811
2812         port = &ports[res->port_id];
2813
2814         isrx = !strcmp(res->rxtxq, "rxq");
2815
2816         if (isrx && rx_queue_id_is_invalid(res->qid))
2817                 return;
2818         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2819                 return;
2820
2821         ison = !strcmp(res->state, "on");
2822
2823         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2824                 port->rx_conf[res->qid].rx_deferred_start = ison;
2825                 needreconfig = 1;
2826         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2827                 port->tx_conf[res->qid].tx_deferred_start = ison;
2828                 needreconfig = 1;
2829         }
2830
2831         if (needreconfig)
2832                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2833 }
2834
2835 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2836         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2837                                                 port, "port");
2838 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2839         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2840                                                 port_id, UINT16);
2841 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2842         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2843                                                 rxtxq, "rxq#txq");
2844 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2845         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2846                                                 qid, UINT16);
2847 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2848         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2849                                                 opname, "deferred_start");
2850 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2851         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2852                                                 state, "on#off");
2853
2854 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2855         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2856         .data = NULL,
2857         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2858         .tokens = {
2859                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2860                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2861                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2862                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2863                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2864                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2865                 NULL,
2866         },
2867 };
2868
2869 /* *** configure port rxq/txq setup *** */
2870 struct cmd_setup_rxtx_queue {
2871         cmdline_fixed_string_t port;
2872         portid_t portid;
2873         cmdline_fixed_string_t rxtxq;
2874         uint16_t qid;
2875         cmdline_fixed_string_t setup;
2876 };
2877
2878 /* Common CLI fields for queue setup */
2879 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2880         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2881 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2882         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2883 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2884         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2885 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2886         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2887 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2888         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2889
2890 static void
2891 cmd_setup_rxtx_queue_parsed(
2892         void *parsed_result,
2893         __rte_unused struct cmdline *cl,
2894         __rte_unused void *data)
2895 {
2896         struct cmd_setup_rxtx_queue *res = parsed_result;
2897         struct rte_port *port;
2898         struct rte_mempool *mp;
2899         unsigned int socket_id;
2900         uint8_t isrx = 0;
2901         int ret;
2902
2903         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2904                 return;
2905
2906         if (res->portid == (portid_t)RTE_PORT_ALL) {
2907                 printf("Invalid port id\n");
2908                 return;
2909         }
2910
2911         if (!strcmp(res->rxtxq, "rxq"))
2912                 isrx = 1;
2913         else if (!strcmp(res->rxtxq, "txq"))
2914                 isrx = 0;
2915         else {
2916                 printf("Unknown parameter\n");
2917                 return;
2918         }
2919
2920         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2921                 printf("Invalid rx queue\n");
2922                 return;
2923         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2924                 printf("Invalid tx queue\n");
2925                 return;
2926         }
2927
2928         port = &ports[res->portid];
2929         if (isrx) {
2930                 socket_id = rxring_numa[res->portid];
2931                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2932                         socket_id = port->socket_id;
2933
2934                 mp = mbuf_pool_find(socket_id, 0);
2935                 if (mp == NULL) {
2936                         printf("Failed to setup RX queue: "
2937                                 "No mempool allocation"
2938                                 " on the socket %d\n",
2939                                 rxring_numa[res->portid]);
2940                         return;
2941                 }
2942                 ret = rte_eth_rx_queue_setup(res->portid,
2943                                              res->qid,
2944                                              port->nb_rx_desc[res->qid],
2945                                              socket_id,
2946                                              &port->rx_conf[res->qid],
2947                                              mp);
2948                 if (ret)
2949                         printf("Failed to setup RX queue\n");
2950         } else {
2951                 socket_id = txring_numa[res->portid];
2952                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2953                         socket_id = port->socket_id;
2954
2955                 ret = rte_eth_tx_queue_setup(res->portid,
2956                                              res->qid,
2957                                              port->nb_tx_desc[res->qid],
2958                                              socket_id,
2959                                              &port->tx_conf[res->qid]);
2960                 if (ret)
2961                         printf("Failed to setup TX queue\n");
2962         }
2963 }
2964
2965 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2966         .f = cmd_setup_rxtx_queue_parsed,
2967         .data = NULL,
2968         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2969         .tokens = {
2970                 (void *)&cmd_setup_rxtx_queue_port,
2971                 (void *)&cmd_setup_rxtx_queue_portid,
2972                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2973                 (void *)&cmd_setup_rxtx_queue_qid,
2974                 (void *)&cmd_setup_rxtx_queue_setup,
2975                 NULL,
2976         },
2977 };
2978
2979
2980 /* *** Configure RSS RETA *** */
2981 struct cmd_config_rss_reta {
2982         cmdline_fixed_string_t port;
2983         cmdline_fixed_string_t keyword;
2984         portid_t port_id;
2985         cmdline_fixed_string_t name;
2986         cmdline_fixed_string_t list_name;
2987         cmdline_fixed_string_t list_of_items;
2988 };
2989
2990 static int
2991 parse_reta_config(const char *str,
2992                   struct rte_eth_rss_reta_entry64 *reta_conf,
2993                   uint16_t nb_entries)
2994 {
2995         int i;
2996         unsigned size;
2997         uint16_t hash_index, idx, shift;
2998         uint16_t nb_queue;
2999         char s[256];
3000         const char *p, *p0 = str;
3001         char *end;
3002         enum fieldnames {
3003                 FLD_HASH_INDEX = 0,
3004                 FLD_QUEUE,
3005                 _NUM_FLD
3006         };
3007         unsigned long int_fld[_NUM_FLD];
3008         char *str_fld[_NUM_FLD];
3009
3010         while ((p = strchr(p0,'(')) != NULL) {
3011                 ++p;
3012                 if((p0 = strchr(p,')')) == NULL)
3013                         return -1;
3014
3015                 size = p0 - p;
3016                 if(size >= sizeof(s))
3017                         return -1;
3018
3019                 snprintf(s, sizeof(s), "%.*s", size, p);
3020                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
3021                         return -1;
3022                 for (i = 0; i < _NUM_FLD; i++) {
3023                         errno = 0;
3024                         int_fld[i] = strtoul(str_fld[i], &end, 0);
3025                         if (errno != 0 || end == str_fld[i] ||
3026                                         int_fld[i] > 65535)
3027                                 return -1;
3028                 }
3029
3030                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
3031                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
3032
3033                 if (hash_index >= nb_entries) {
3034                         printf("Invalid RETA hash index=%d\n", hash_index);
3035                         return -1;
3036                 }
3037
3038                 idx = hash_index / RTE_RETA_GROUP_SIZE;
3039                 shift = hash_index % RTE_RETA_GROUP_SIZE;
3040                 reta_conf[idx].mask |= (1ULL << shift);
3041                 reta_conf[idx].reta[shift] = nb_queue;
3042         }
3043
3044         return 0;
3045 }
3046
3047 static void
3048 cmd_set_rss_reta_parsed(void *parsed_result,
3049                         __rte_unused struct cmdline *cl,
3050                         __rte_unused void *data)
3051 {
3052         int ret;
3053         struct rte_eth_dev_info dev_info;
3054         struct rte_eth_rss_reta_entry64 reta_conf[8];
3055         struct cmd_config_rss_reta *res = parsed_result;
3056
3057         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3058         if (ret != 0)
3059                 return;
3060
3061         if (dev_info.reta_size == 0) {
3062                 printf("Redirection table size is 0 which is "
3063                                         "invalid for RSS\n");
3064                 return;
3065         } else
3066                 printf("The reta size of port %d is %u\n",
3067                         res->port_id, dev_info.reta_size);
3068         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3069                 printf("Currently do not support more than %u entries of "
3070                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3071                 return;
3072         }
3073
3074         memset(reta_conf, 0, sizeof(reta_conf));
3075         if (!strcmp(res->list_name, "reta")) {
3076                 if (parse_reta_config(res->list_of_items, reta_conf,
3077                                                 dev_info.reta_size)) {
3078                         printf("Invalid RSS Redirection Table "
3079                                         "config entered\n");
3080                         return;
3081                 }
3082                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3083                                 reta_conf, dev_info.reta_size);
3084                 if (ret != 0)
3085                         printf("Bad redirection table parameter, "
3086                                         "return code = %d \n", ret);
3087         }
3088 }
3089
3090 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3091         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3092 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3093         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3094 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3095         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3096 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3097         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3098 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3099         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3100 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3101         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3102                                  NULL);
3103 cmdline_parse_inst_t cmd_config_rss_reta = {
3104         .f = cmd_set_rss_reta_parsed,
3105         .data = NULL,
3106         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3107         .tokens = {
3108                 (void *)&cmd_config_rss_reta_port,
3109                 (void *)&cmd_config_rss_reta_keyword,
3110                 (void *)&cmd_config_rss_reta_port_id,
3111                 (void *)&cmd_config_rss_reta_name,
3112                 (void *)&cmd_config_rss_reta_list_name,
3113                 (void *)&cmd_config_rss_reta_list_of_items,
3114                 NULL,
3115         },
3116 };
3117
3118 /* *** SHOW PORT RETA INFO *** */
3119 struct cmd_showport_reta {
3120         cmdline_fixed_string_t show;
3121         cmdline_fixed_string_t port;
3122         portid_t port_id;
3123         cmdline_fixed_string_t rss;
3124         cmdline_fixed_string_t reta;
3125         uint16_t size;
3126         cmdline_fixed_string_t list_of_items;
3127 };
3128
3129 static int
3130 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3131                            uint16_t nb_entries,
3132                            char *str)
3133 {
3134         uint32_t size;
3135         const char *p, *p0 = str;
3136         char s[256];
3137         char *end;
3138         char *str_fld[8];
3139         uint16_t i;
3140         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3141                         RTE_RETA_GROUP_SIZE;
3142         int ret;
3143
3144         p = strchr(p0, '(');
3145         if (p == NULL)
3146                 return -1;
3147         p++;
3148         p0 = strchr(p, ')');
3149         if (p0 == NULL)
3150                 return -1;
3151         size = p0 - p;
3152         if (size >= sizeof(s)) {
3153                 printf("The string size exceeds the internal buffer size\n");
3154                 return -1;
3155         }
3156         snprintf(s, sizeof(s), "%.*s", size, p);
3157         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3158         if (ret <= 0 || ret != num) {
3159                 printf("The bits of masks do not match the number of "
3160                                         "reta entries: %u\n", num);
3161                 return -1;
3162         }
3163         for (i = 0; i < ret; i++)
3164                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3165
3166         return 0;
3167 }
3168
3169 static void
3170 cmd_showport_reta_parsed(void *parsed_result,
3171                          __rte_unused struct cmdline *cl,
3172                          __rte_unused void *data)
3173 {
3174         struct cmd_showport_reta *res = parsed_result;
3175         struct rte_eth_rss_reta_entry64 reta_conf[8];
3176         struct rte_eth_dev_info dev_info;
3177         uint16_t max_reta_size;
3178         int ret;
3179
3180         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3181         if (ret != 0)
3182                 return;
3183
3184         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3185         if (res->size == 0 || res->size > max_reta_size) {
3186                 printf("Invalid redirection table size: %u (1-%u)\n",
3187                         res->size, max_reta_size);
3188                 return;
3189         }
3190
3191         memset(reta_conf, 0, sizeof(reta_conf));
3192         if (showport_parse_reta_config(reta_conf, res->size,
3193                                 res->list_of_items) < 0) {
3194                 printf("Invalid string: %s for reta masks\n",
3195                                         res->list_of_items);
3196                 return;
3197         }
3198         port_rss_reta_info(res->port_id, reta_conf, res->size);
3199 }
3200
3201 cmdline_parse_token_string_t cmd_showport_reta_show =
3202         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3203 cmdline_parse_token_string_t cmd_showport_reta_port =
3204         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3205 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3206         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3207 cmdline_parse_token_string_t cmd_showport_reta_rss =
3208         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3209 cmdline_parse_token_string_t cmd_showport_reta_reta =
3210         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3211 cmdline_parse_token_num_t cmd_showport_reta_size =
3212         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3213 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3214         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3215                                         list_of_items, NULL);
3216
3217 cmdline_parse_inst_t cmd_showport_reta = {
3218         .f = cmd_showport_reta_parsed,
3219         .data = NULL,
3220         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3221         .tokens = {
3222                 (void *)&cmd_showport_reta_show,
3223                 (void *)&cmd_showport_reta_port,
3224                 (void *)&cmd_showport_reta_port_id,
3225                 (void *)&cmd_showport_reta_rss,
3226                 (void *)&cmd_showport_reta_reta,
3227                 (void *)&cmd_showport_reta_size,
3228                 (void *)&cmd_showport_reta_list_of_items,
3229                 NULL,
3230         },
3231 };
3232
3233 /* *** Show RSS hash configuration *** */
3234 struct cmd_showport_rss_hash {
3235         cmdline_fixed_string_t show;
3236         cmdline_fixed_string_t port;
3237         portid_t port_id;
3238         cmdline_fixed_string_t rss_hash;
3239         cmdline_fixed_string_t rss_type;
3240         cmdline_fixed_string_t key; /* optional argument */
3241 };
3242
3243 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3244                                 __rte_unused struct cmdline *cl,
3245                                 void *show_rss_key)
3246 {
3247         struct cmd_showport_rss_hash *res = parsed_result;
3248
3249         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3250 }
3251
3252 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3253         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3254 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3255         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3256 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3257         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3258 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3259         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3260                                  "rss-hash");
3261 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3262         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3263
3264 cmdline_parse_inst_t cmd_showport_rss_hash = {
3265         .f = cmd_showport_rss_hash_parsed,
3266         .data = NULL,
3267         .help_str = "show port <port_id> rss-hash",
3268         .tokens = {
3269                 (void *)&cmd_showport_rss_hash_show,
3270                 (void *)&cmd_showport_rss_hash_port,
3271                 (void *)&cmd_showport_rss_hash_port_id,
3272                 (void *)&cmd_showport_rss_hash_rss_hash,
3273                 NULL,
3274         },
3275 };
3276
3277 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3278         .f = cmd_showport_rss_hash_parsed,
3279         .data = (void *)1,
3280         .help_str = "show port <port_id> rss-hash key",
3281         .tokens = {
3282                 (void *)&cmd_showport_rss_hash_show,
3283                 (void *)&cmd_showport_rss_hash_port,
3284                 (void *)&cmd_showport_rss_hash_port_id,
3285                 (void *)&cmd_showport_rss_hash_rss_hash,
3286                 (void *)&cmd_showport_rss_hash_rss_key,
3287                 NULL,
3288         },
3289 };
3290
3291 /* *** Configure DCB *** */
3292 struct cmd_config_dcb {
3293         cmdline_fixed_string_t port;
3294         cmdline_fixed_string_t config;
3295         portid_t port_id;
3296         cmdline_fixed_string_t dcb;
3297         cmdline_fixed_string_t vt;
3298         cmdline_fixed_string_t vt_en;
3299         uint8_t num_tcs;
3300         cmdline_fixed_string_t pfc;
3301         cmdline_fixed_string_t pfc_en;
3302 };
3303
3304 static void
3305 cmd_config_dcb_parsed(void *parsed_result,
3306                         __rte_unused struct cmdline *cl,
3307                         __rte_unused void *data)
3308 {
3309         struct cmd_config_dcb *res = parsed_result;
3310         portid_t port_id = res->port_id;
3311         struct rte_port *port;
3312         uint8_t pfc_en;
3313         int ret;
3314
3315         port = &ports[port_id];
3316         /** Check if the port is not started **/
3317         if (port->port_status != RTE_PORT_STOPPED) {
3318                 printf("Please stop port %d first\n", port_id);
3319                 return;
3320         }
3321
3322         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3323                 printf("The invalid number of traffic class,"
3324                         " only 4 or 8 allowed.\n");
3325                 return;
3326         }
3327
3328         if (nb_fwd_lcores < res->num_tcs) {
3329                 printf("nb_cores shouldn't be less than number of TCs.\n");
3330                 return;
3331         }
3332         if (!strncmp(res->pfc_en, "on", 2))
3333                 pfc_en = 1;
3334         else
3335                 pfc_en = 0;
3336
3337         /* DCB in VT mode */
3338         if (!strncmp(res->vt_en, "on", 2))
3339                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3340                                 (enum rte_eth_nb_tcs)res->num_tcs,
3341                                 pfc_en);
3342         else
3343                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3344                                 (enum rte_eth_nb_tcs)res->num_tcs,
3345                                 pfc_en);
3346
3347
3348         if (ret != 0) {
3349                 printf("Cannot initialize network ports.\n");
3350                 return;
3351         }
3352
3353         cmd_reconfig_device_queue(port_id, 1, 1);
3354 }
3355
3356 cmdline_parse_token_string_t cmd_config_dcb_port =
3357         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3358 cmdline_parse_token_string_t cmd_config_dcb_config =
3359         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3360 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3361         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3362 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3363         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3364 cmdline_parse_token_string_t cmd_config_dcb_vt =
3365         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3366 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3367         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3368 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3369         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3370 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3371         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3372 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3373         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3374
3375 cmdline_parse_inst_t cmd_config_dcb = {
3376         .f = cmd_config_dcb_parsed,
3377         .data = NULL,
3378         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3379         .tokens = {
3380                 (void *)&cmd_config_dcb_port,
3381                 (void *)&cmd_config_dcb_config,
3382                 (void *)&cmd_config_dcb_port_id,
3383                 (void *)&cmd_config_dcb_dcb,
3384                 (void *)&cmd_config_dcb_vt,
3385                 (void *)&cmd_config_dcb_vt_en,
3386                 (void *)&cmd_config_dcb_num_tcs,
3387                 (void *)&cmd_config_dcb_pfc,
3388                 (void *)&cmd_config_dcb_pfc_en,
3389                 NULL,
3390         },
3391 };
3392
3393 /* *** configure number of packets per burst *** */
3394 struct cmd_config_burst {
3395         cmdline_fixed_string_t port;
3396         cmdline_fixed_string_t keyword;
3397         cmdline_fixed_string_t all;
3398         cmdline_fixed_string_t name;
3399         uint16_t value;
3400 };
3401
3402 static void
3403 cmd_config_burst_parsed(void *parsed_result,
3404                         __rte_unused struct cmdline *cl,
3405                         __rte_unused void *data)
3406 {
3407         struct cmd_config_burst *res = parsed_result;
3408         struct rte_eth_dev_info dev_info;
3409         uint16_t rec_nb_pkts;
3410         int ret;
3411
3412         if (!all_ports_stopped()) {
3413                 printf("Please stop all ports first\n");
3414                 return;
3415         }
3416
3417         if (!strcmp(res->name, "burst")) {
3418                 if (res->value == 0) {
3419                         /* If user gives a value of zero, query the PMD for
3420                          * its recommended Rx burst size. Testpmd uses a single
3421                          * size for all ports, so assume all ports are the same
3422                          * NIC model and use the values from Port 0.
3423                          */
3424                         ret = eth_dev_info_get_print_err(0, &dev_info);
3425                         if (ret != 0)
3426                                 return;
3427
3428                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3429
3430                         if (rec_nb_pkts == 0) {
3431                                 printf("PMD does not recommend a burst size.\n"
3432                                         "User provided value must be between"
3433                                         " 1 and %d\n", MAX_PKT_BURST);
3434                                 return;
3435                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3436                                 printf("PMD recommended burst size of %d"
3437                                         " exceeds maximum value of %d\n",
3438                                         rec_nb_pkts, MAX_PKT_BURST);
3439                                 return;
3440                         }
3441                         printf("Using PMD-provided burst value of %d\n",
3442                                 rec_nb_pkts);
3443                         nb_pkt_per_burst = rec_nb_pkts;
3444                 } else if (res->value > MAX_PKT_BURST) {
3445                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3446                         return;
3447                 } else
3448                         nb_pkt_per_burst = res->value;
3449         } else {
3450                 printf("Unknown parameter\n");
3451                 return;
3452         }
3453
3454         init_port_config();
3455
3456         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3457 }
3458
3459 cmdline_parse_token_string_t cmd_config_burst_port =
3460         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3461 cmdline_parse_token_string_t cmd_config_burst_keyword =
3462         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3463 cmdline_parse_token_string_t cmd_config_burst_all =
3464         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3465 cmdline_parse_token_string_t cmd_config_burst_name =
3466         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3467 cmdline_parse_token_num_t cmd_config_burst_value =
3468         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3469
3470 cmdline_parse_inst_t cmd_config_burst = {
3471         .f = cmd_config_burst_parsed,
3472         .data = NULL,
3473         .help_str = "port config all burst <value>",
3474         .tokens = {
3475                 (void *)&cmd_config_burst_port,
3476                 (void *)&cmd_config_burst_keyword,
3477                 (void *)&cmd_config_burst_all,
3478                 (void *)&cmd_config_burst_name,
3479                 (void *)&cmd_config_burst_value,
3480                 NULL,
3481         },
3482 };
3483
3484 /* *** configure rx/tx queues *** */
3485 struct cmd_config_thresh {
3486         cmdline_fixed_string_t port;
3487         cmdline_fixed_string_t keyword;
3488         cmdline_fixed_string_t all;
3489         cmdline_fixed_string_t name;
3490         uint8_t value;
3491 };
3492
3493 static void
3494 cmd_config_thresh_parsed(void *parsed_result,
3495                         __rte_unused struct cmdline *cl,
3496                         __rte_unused void *data)
3497 {
3498         struct cmd_config_thresh *res = parsed_result;
3499
3500         if (!all_ports_stopped()) {
3501                 printf("Please stop all ports first\n");
3502                 return;
3503         }
3504
3505         if (!strcmp(res->name, "txpt"))
3506                 tx_pthresh = res->value;
3507         else if(!strcmp(res->name, "txht"))
3508                 tx_hthresh = res->value;
3509         else if(!strcmp(res->name, "txwt"))
3510                 tx_wthresh = res->value;
3511         else if(!strcmp(res->name, "rxpt"))
3512                 rx_pthresh = res->value;
3513         else if(!strcmp(res->name, "rxht"))
3514                 rx_hthresh = res->value;
3515         else if(!strcmp(res->name, "rxwt"))
3516                 rx_wthresh = res->value;
3517         else {
3518                 printf("Unknown parameter\n");
3519                 return;
3520         }
3521
3522         init_port_config();
3523
3524         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3525 }
3526
3527 cmdline_parse_token_string_t cmd_config_thresh_port =
3528         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3529 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3530         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3531 cmdline_parse_token_string_t cmd_config_thresh_all =
3532         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3533 cmdline_parse_token_string_t cmd_config_thresh_name =
3534         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3535                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3536 cmdline_parse_token_num_t cmd_config_thresh_value =
3537         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3538
3539 cmdline_parse_inst_t cmd_config_thresh = {
3540         .f = cmd_config_thresh_parsed,
3541         .data = NULL,
3542         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3543         .tokens = {
3544                 (void *)&cmd_config_thresh_port,
3545                 (void *)&cmd_config_thresh_keyword,
3546                 (void *)&cmd_config_thresh_all,
3547                 (void *)&cmd_config_thresh_name,
3548                 (void *)&cmd_config_thresh_value,
3549                 NULL,
3550         },
3551 };
3552
3553 /* *** configure free/rs threshold *** */
3554 struct cmd_config_threshold {
3555         cmdline_fixed_string_t port;
3556         cmdline_fixed_string_t keyword;
3557         cmdline_fixed_string_t all;
3558         cmdline_fixed_string_t name;
3559         uint16_t value;
3560 };
3561
3562 static void
3563 cmd_config_threshold_parsed(void *parsed_result,
3564                         __rte_unused struct cmdline *cl,
3565                         __rte_unused void *data)
3566 {
3567         struct cmd_config_threshold *res = parsed_result;
3568
3569         if (!all_ports_stopped()) {
3570                 printf("Please stop all ports first\n");
3571                 return;
3572         }
3573
3574         if (!strcmp(res->name, "txfreet"))
3575                 tx_free_thresh = res->value;
3576         else if (!strcmp(res->name, "txrst"))
3577                 tx_rs_thresh = res->value;
3578         else if (!strcmp(res->name, "rxfreet"))
3579                 rx_free_thresh = res->value;
3580         else {
3581                 printf("Unknown parameter\n");
3582                 return;
3583         }
3584
3585         init_port_config();
3586
3587         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3588 }
3589
3590 cmdline_parse_token_string_t cmd_config_threshold_port =
3591         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3592 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3593         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3594                                                                 "config");
3595 cmdline_parse_token_string_t cmd_config_threshold_all =
3596         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3597 cmdline_parse_token_string_t cmd_config_threshold_name =
3598         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3599                                                 "txfreet#txrst#rxfreet");
3600 cmdline_parse_token_num_t cmd_config_threshold_value =
3601         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3602
3603 cmdline_parse_inst_t cmd_config_threshold = {
3604         .f = cmd_config_threshold_parsed,
3605         .data = NULL,
3606         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3607         .tokens = {
3608                 (void *)&cmd_config_threshold_port,
3609                 (void *)&cmd_config_threshold_keyword,
3610                 (void *)&cmd_config_threshold_all,
3611                 (void *)&cmd_config_threshold_name,
3612                 (void *)&cmd_config_threshold_value,
3613                 NULL,
3614         },
3615 };
3616
3617 /* *** stop *** */
3618 struct cmd_stop_result {
3619         cmdline_fixed_string_t stop;
3620 };
3621
3622 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3623                             __rte_unused struct cmdline *cl,
3624                             __rte_unused void *data)
3625 {
3626         stop_packet_forwarding();
3627 }
3628
3629 cmdline_parse_token_string_t cmd_stop_stop =
3630         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3631
3632 cmdline_parse_inst_t cmd_stop = {
3633         .f = cmd_stop_parsed,
3634         .data = NULL,
3635         .help_str = "stop: Stop packet forwarding",
3636         .tokens = {
3637                 (void *)&cmd_stop_stop,
3638                 NULL,
3639         },
3640 };
3641
3642 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3643
3644 unsigned int
3645 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3646                 unsigned int *parsed_items, int check_unique_values)
3647 {
3648         unsigned int nb_item;
3649         unsigned int value;
3650         unsigned int i;
3651         unsigned int j;
3652         int value_ok;
3653         char c;
3654
3655         /*
3656          * First parse all items in the list and store their value.
3657          */
3658         value = 0;
3659         nb_item = 0;
3660         value_ok = 0;
3661         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3662                 c = str[i];
3663                 if ((c >= '0') && (c <= '9')) {
3664                         value = (unsigned int) (value * 10 + (c - '0'));
3665                         value_ok = 1;
3666                         continue;
3667                 }
3668                 if (c != ',') {
3669                         printf("character %c is not a decimal digit\n", c);
3670                         return 0;
3671                 }
3672                 if (! value_ok) {
3673                         printf("No valid value before comma\n");
3674                         return 0;
3675                 }
3676                 if (nb_item < max_items) {
3677                         parsed_items[nb_item] = value;
3678                         value_ok = 0;
3679                         value = 0;
3680                 }
3681                 nb_item++;
3682         }
3683         if (nb_item >= max_items) {
3684                 printf("Number of %s = %u > %u (maximum items)\n",
3685                        item_name, nb_item + 1, max_items);
3686                 return 0;
3687         }
3688         parsed_items[nb_item++] = value;
3689         if (! check_unique_values)
3690                 return nb_item;
3691
3692         /*
3693          * Then, check that all values in the list are differents.
3694          * No optimization here...
3695          */
3696         for (i = 0; i < nb_item; i++) {
3697                 for (j = i + 1; j < nb_item; j++) {
3698                         if (parsed_items[j] == parsed_items[i]) {
3699                                 printf("duplicated %s %u at index %u and %u\n",
3700                                        item_name, parsed_items[i], i, j);
3701                                 return 0;
3702                         }
3703                 }
3704         }
3705         return nb_item;
3706 }
3707
3708 struct cmd_set_list_result {
3709         cmdline_fixed_string_t cmd_keyword;
3710         cmdline_fixed_string_t list_name;
3711         cmdline_fixed_string_t list_of_items;
3712 };
3713
3714 static void cmd_set_list_parsed(void *parsed_result,
3715                                 __rte_unused struct cmdline *cl,
3716                                 __rte_unused void *data)
3717 {
3718         struct cmd_set_list_result *res;
3719         union {
3720                 unsigned int lcorelist[RTE_MAX_LCORE];
3721                 unsigned int portlist[RTE_MAX_ETHPORTS];
3722         } parsed_items;
3723         unsigned int nb_item;
3724
3725         if (test_done == 0) {
3726                 printf("Please stop forwarding first\n");
3727                 return;
3728         }
3729
3730         res = parsed_result;
3731         if (!strcmp(res->list_name, "corelist")) {
3732                 nb_item = parse_item_list(res->list_of_items, "core",
3733                                           RTE_MAX_LCORE,
3734                                           parsed_items.lcorelist, 1);
3735                 if (nb_item > 0) {
3736                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3737                         fwd_config_setup();
3738                 }
3739                 return;
3740         }
3741         if (!strcmp(res->list_name, "portlist")) {
3742                 nb_item = parse_item_list(res->list_of_items, "port",
3743                                           RTE_MAX_ETHPORTS,
3744                                           parsed_items.portlist, 1);
3745                 if (nb_item > 0) {
3746                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3747                         fwd_config_setup();
3748                 }
3749         }
3750 }
3751
3752 cmdline_parse_token_string_t cmd_set_list_keyword =
3753         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3754                                  "set");
3755 cmdline_parse_token_string_t cmd_set_list_name =
3756         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3757                                  "corelist#portlist");
3758 cmdline_parse_token_string_t cmd_set_list_of_items =
3759         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3760                                  NULL);
3761
3762 cmdline_parse_inst_t cmd_set_fwd_list = {
3763         .f = cmd_set_list_parsed,
3764         .data = NULL,
3765         .help_str = "set corelist|portlist <list0[,list1]*>",
3766         .tokens = {
3767                 (void *)&cmd_set_list_keyword,
3768                 (void *)&cmd_set_list_name,
3769                 (void *)&cmd_set_list_of_items,
3770                 NULL,
3771         },
3772 };
3773
3774 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3775
3776 struct cmd_setmask_result {
3777         cmdline_fixed_string_t set;
3778         cmdline_fixed_string_t mask;
3779         uint64_t hexavalue;
3780 };
3781
3782 static void cmd_set_mask_parsed(void *parsed_result,
3783                                 __rte_unused struct cmdline *cl,
3784                                 __rte_unused void *data)
3785 {
3786         struct cmd_setmask_result *res = parsed_result;
3787
3788         if (test_done == 0) {
3789                 printf("Please stop forwarding first\n");
3790                 return;
3791         }
3792         if (!strcmp(res->mask, "coremask")) {
3793                 set_fwd_lcores_mask(res->hexavalue);
3794                 fwd_config_setup();
3795         } else if (!strcmp(res->mask, "portmask")) {
3796                 set_fwd_ports_mask(res->hexavalue);
3797                 fwd_config_setup();
3798         }
3799 }
3800
3801 cmdline_parse_token_string_t cmd_setmask_set =
3802         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3803 cmdline_parse_token_string_t cmd_setmask_mask =
3804         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3805                                  "coremask#portmask");
3806 cmdline_parse_token_num_t cmd_setmask_value =
3807         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3808
3809 cmdline_parse_inst_t cmd_set_fwd_mask = {
3810         .f = cmd_set_mask_parsed,
3811         .data = NULL,
3812         .help_str = "set coremask|portmask <hexadecimal value>",
3813         .tokens = {
3814                 (void *)&cmd_setmask_set,
3815                 (void *)&cmd_setmask_mask,
3816                 (void *)&cmd_setmask_value,
3817                 NULL,
3818         },
3819 };
3820
3821 /*
3822  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3823  */
3824 struct cmd_set_result {
3825         cmdline_fixed_string_t set;
3826         cmdline_fixed_string_t what;
3827         uint16_t value;
3828 };
3829
3830 static void cmd_set_parsed(void *parsed_result,
3831                            __rte_unused struct cmdline *cl,
3832                            __rte_unused void *data)
3833 {
3834         struct cmd_set_result *res = parsed_result;
3835         if (!strcmp(res->what, "nbport")) {
3836                 set_fwd_ports_number(res->value);
3837                 fwd_config_setup();
3838         } else if (!strcmp(res->what, "nbcore")) {
3839                 set_fwd_lcores_number(res->value);
3840                 fwd_config_setup();
3841         } else if (!strcmp(res->what, "burst"))
3842                 set_nb_pkt_per_burst(res->value);
3843         else if (!strcmp(res->what, "verbose"))
3844                 set_verbose_level(res->value);
3845 }
3846
3847 cmdline_parse_token_string_t cmd_set_set =
3848         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3849 cmdline_parse_token_string_t cmd_set_what =
3850         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3851                                  "nbport#nbcore#burst#verbose");
3852 cmdline_parse_token_num_t cmd_set_value =
3853         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3854
3855 cmdline_parse_inst_t cmd_set_numbers = {
3856         .f = cmd_set_parsed,
3857         .data = NULL,
3858         .help_str = "set nbport|nbcore|burst|verbose <value>",
3859         .tokens = {
3860                 (void *)&cmd_set_set,
3861                 (void *)&cmd_set_what,
3862                 (void *)&cmd_set_value,
3863                 NULL,
3864         },
3865 };
3866
3867 /* *** SET LOG LEVEL CONFIGURATION *** */
3868
3869 struct cmd_set_log_result {
3870         cmdline_fixed_string_t set;
3871         cmdline_fixed_string_t log;
3872         cmdline_fixed_string_t type;
3873         uint32_t level;
3874 };
3875
3876 static void
3877 cmd_set_log_parsed(void *parsed_result,
3878                    __rte_unused struct cmdline *cl,
3879                    __rte_unused void *data)
3880 {
3881         struct cmd_set_log_result *res;
3882         int ret;
3883
3884         res = parsed_result;
3885         if (!strcmp(res->type, "global"))
3886                 rte_log_set_global_level(res->level);
3887         else {
3888                 ret = rte_log_set_level_regexp(res->type, res->level);
3889                 if (ret < 0)
3890                         printf("Unable to set log level\n");
3891         }
3892 }
3893
3894 cmdline_parse_token_string_t cmd_set_log_set =
3895         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3896 cmdline_parse_token_string_t cmd_set_log_log =
3897         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3898 cmdline_parse_token_string_t cmd_set_log_type =
3899         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3900 cmdline_parse_token_num_t cmd_set_log_level =
3901         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3902
3903 cmdline_parse_inst_t cmd_set_log = {
3904         .f = cmd_set_log_parsed,
3905         .data = NULL,
3906         .help_str = "set log global|<type> <level>",
3907         .tokens = {
3908                 (void *)&cmd_set_log_set,
3909                 (void *)&cmd_set_log_log,
3910                 (void *)&cmd_set_log_type,
3911                 (void *)&cmd_set_log_level,
3912                 NULL,
3913         },
3914 };
3915
3916 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3917
3918 struct cmd_set_rxpkts_result {
3919         cmdline_fixed_string_t cmd_keyword;
3920         cmdline_fixed_string_t rxpkts;
3921         cmdline_fixed_string_t seg_lengths;
3922 };
3923
3924 static void
3925 cmd_set_rxpkts_parsed(void *parsed_result,
3926                       __rte_unused struct cmdline *cl,
3927                       __rte_unused void *data)
3928 {
3929         struct cmd_set_rxpkts_result *res;
3930         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3931         unsigned int nb_segs;
3932
3933         res = parsed_result;
3934         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3935                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3936         if (nb_segs > 0)
3937                 set_rx_pkt_segments(seg_lengths, nb_segs);
3938 }
3939
3940 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3941         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3942                                  cmd_keyword, "set");
3943 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3944         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3945                                  rxpkts, "rxpkts");
3946 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3947         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3948                                  seg_lengths, NULL);
3949
3950 cmdline_parse_inst_t cmd_set_rxpkts = {
3951         .f = cmd_set_rxpkts_parsed,
3952         .data = NULL,
3953         .help_str = "set rxpkts <len0[,len1]*>",
3954         .tokens = {
3955                 (void *)&cmd_set_rxpkts_keyword,
3956                 (void *)&cmd_set_rxpkts_name,
3957                 (void *)&cmd_set_rxpkts_lengths,
3958                 NULL,
3959         },
3960 };
3961
3962 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3963
3964 struct cmd_set_txpkts_result {
3965         cmdline_fixed_string_t cmd_keyword;
3966         cmdline_fixed_string_t txpkts;
3967         cmdline_fixed_string_t seg_lengths;
3968 };
3969
3970 static void
3971 cmd_set_txpkts_parsed(void *parsed_result,
3972                       __rte_unused struct cmdline *cl,
3973                       __rte_unused void *data)
3974 {
3975         struct cmd_set_txpkts_result *res;
3976         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3977         unsigned int nb_segs;
3978
3979         res = parsed_result;
3980         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3981                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3982         if (nb_segs > 0)
3983                 set_tx_pkt_segments(seg_lengths, nb_segs);
3984 }
3985
3986 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3987         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3988                                  cmd_keyword, "set");
3989 cmdline_parse_token_string_t cmd_set_txpkts_name =
3990         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3991                                  txpkts, "txpkts");
3992 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3993         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3994                                  seg_lengths, NULL);
3995
3996 cmdline_parse_inst_t cmd_set_txpkts = {
3997         .f = cmd_set_txpkts_parsed,
3998         .data = NULL,
3999         .help_str = "set txpkts <len0[,len1]*>",
4000         .tokens = {
4001                 (void *)&cmd_set_txpkts_keyword,
4002                 (void *)&cmd_set_txpkts_name,
4003                 (void *)&cmd_set_txpkts_lengths,
4004                 NULL,
4005         },
4006 };
4007
4008 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
4009
4010 struct cmd_set_txsplit_result {
4011         cmdline_fixed_string_t cmd_keyword;
4012         cmdline_fixed_string_t txsplit;
4013         cmdline_fixed_string_t mode;
4014 };
4015
4016 static void
4017 cmd_set_txsplit_parsed(void *parsed_result,
4018                       __rte_unused struct cmdline *cl,
4019                       __rte_unused void *data)
4020 {
4021         struct cmd_set_txsplit_result *res;
4022
4023         res = parsed_result;
4024         set_tx_pkt_split(res->mode);
4025 }
4026
4027 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4028         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4029                                  cmd_keyword, "set");
4030 cmdline_parse_token_string_t cmd_set_txsplit_name =
4031         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4032                                  txsplit, "txsplit");
4033 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4034         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4035                                  mode, NULL);
4036
4037 cmdline_parse_inst_t cmd_set_txsplit = {
4038         .f = cmd_set_txsplit_parsed,
4039         .data = NULL,
4040         .help_str = "set txsplit on|off|rand",
4041         .tokens = {
4042                 (void *)&cmd_set_txsplit_keyword,
4043                 (void *)&cmd_set_txsplit_name,
4044                 (void *)&cmd_set_txsplit_mode,
4045                 NULL,
4046         },
4047 };
4048
4049 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4050
4051 struct cmd_set_txtimes_result {
4052         cmdline_fixed_string_t cmd_keyword;
4053         cmdline_fixed_string_t txtimes;
4054         cmdline_fixed_string_t tx_times;
4055 };
4056
4057 static void
4058 cmd_set_txtimes_parsed(void *parsed_result,
4059                        __rte_unused struct cmdline *cl,
4060                        __rte_unused void *data)
4061 {
4062         struct cmd_set_txtimes_result *res;
4063         unsigned int tx_times[2] = {0, 0};
4064         unsigned int n_times;
4065
4066         res = parsed_result;
4067         n_times = parse_item_list(res->tx_times, "tx times",
4068                                   2, tx_times, 0);
4069         if (n_times == 2)
4070                 set_tx_pkt_times(tx_times);
4071 }
4072
4073 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4074         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4075                                  cmd_keyword, "set");
4076 cmdline_parse_token_string_t cmd_set_txtimes_name =
4077         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4078                                  txtimes, "txtimes");
4079 cmdline_parse_token_string_t cmd_set_txtimes_value =
4080         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4081                                  tx_times, NULL);
4082
4083 cmdline_parse_inst_t cmd_set_txtimes = {
4084         .f = cmd_set_txtimes_parsed,
4085         .data = NULL,
4086         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4087         .tokens = {
4088                 (void *)&cmd_set_txtimes_keyword,
4089                 (void *)&cmd_set_txtimes_name,
4090                 (void *)&cmd_set_txtimes_value,
4091                 NULL,
4092         },
4093 };
4094
4095 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4096 struct cmd_rx_vlan_filter_all_result {
4097         cmdline_fixed_string_t rx_vlan;
4098         cmdline_fixed_string_t what;
4099         cmdline_fixed_string_t all;
4100         portid_t port_id;
4101 };
4102
4103 static void
4104 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4105                               __rte_unused struct cmdline *cl,
4106                               __rte_unused void *data)
4107 {
4108         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4109
4110         if (!strcmp(res->what, "add"))
4111                 rx_vlan_all_filter_set(res->port_id, 1);
4112         else
4113                 rx_vlan_all_filter_set(res->port_id, 0);
4114 }
4115
4116 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4117         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4118                                  rx_vlan, "rx_vlan");
4119 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4120         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4121                                  what, "add#rm");
4122 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4123         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4124                                  all, "all");
4125 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4126         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4127                               port_id, UINT16);
4128
4129 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4130         .f = cmd_rx_vlan_filter_all_parsed,
4131         .data = NULL,
4132         .help_str = "rx_vlan add|rm all <port_id>: "
4133                 "Add/Remove all identifiers to/from the set of VLAN "
4134                 "identifiers filtered by a port",
4135         .tokens = {
4136                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4137                 (void *)&cmd_rx_vlan_filter_all_what,
4138                 (void *)&cmd_rx_vlan_filter_all_all,
4139                 (void *)&cmd_rx_vlan_filter_all_portid,
4140                 NULL,
4141         },
4142 };
4143
4144 /* *** VLAN OFFLOAD SET ON A PORT *** */
4145 struct cmd_vlan_offload_result {
4146         cmdline_fixed_string_t vlan;
4147         cmdline_fixed_string_t set;
4148         cmdline_fixed_string_t vlan_type;
4149         cmdline_fixed_string_t what;
4150         cmdline_fixed_string_t on;
4151         cmdline_fixed_string_t port_id;
4152 };
4153
4154 static void
4155 cmd_vlan_offload_parsed(void *parsed_result,
4156                           __rte_unused struct cmdline *cl,
4157                           __rte_unused void *data)
4158 {
4159         int on;
4160         struct cmd_vlan_offload_result *res = parsed_result;
4161         char *str;
4162         int i, len = 0;
4163         portid_t port_id = 0;
4164         unsigned int tmp;
4165
4166         str = res->port_id;
4167         len = strnlen(str, STR_TOKEN_SIZE);
4168         i = 0;
4169         /* Get port_id first */
4170         while(i < len){
4171                 if(str[i] == ',')
4172                         break;
4173
4174                 i++;
4175         }
4176         str[i]='\0';
4177         tmp = strtoul(str, NULL, 0);
4178         /* If port_id greater that what portid_t can represent, return */
4179         if(tmp >= RTE_MAX_ETHPORTS)
4180                 return;
4181         port_id = (portid_t)tmp;
4182
4183         if (!strcmp(res->on, "on"))
4184                 on = 1;
4185         else
4186                 on = 0;
4187
4188         if (!strcmp(res->what, "strip"))
4189                 rx_vlan_strip_set(port_id,  on);
4190         else if(!strcmp(res->what, "stripq")){
4191                 uint16_t queue_id = 0;
4192
4193                 /* No queue_id, return */
4194                 if(i + 1 >= len) {
4195                         printf("must specify (port,queue_id)\n");
4196                         return;
4197                 }
4198                 tmp = strtoul(str + i + 1, NULL, 0);
4199                 /* If queue_id greater that what 16-bits can represent, return */
4200                 if(tmp > 0xffff)
4201                         return;
4202
4203                 queue_id = (uint16_t)tmp;
4204                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4205         }
4206         else if (!strcmp(res->what, "filter"))
4207                 rx_vlan_filter_set(port_id, on);
4208         else if (!strcmp(res->what, "qinq_strip"))
4209                 rx_vlan_qinq_strip_set(port_id, on);
4210         else
4211                 vlan_extend_set(port_id, on);
4212
4213         return;
4214 }
4215
4216 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4217         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4218                                  vlan, "vlan");
4219 cmdline_parse_token_string_t cmd_vlan_offload_set =
4220         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4221                                  set, "set");
4222 cmdline_parse_token_string_t cmd_vlan_offload_what =
4223         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4224                                 what, "strip#filter#qinq_strip#extend#stripq");
4225 cmdline_parse_token_string_t cmd_vlan_offload_on =
4226         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4227                               on, "on#off");
4228 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4229         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4230                               port_id, NULL);
4231
4232 cmdline_parse_inst_t cmd_vlan_offload = {
4233         .f = cmd_vlan_offload_parsed,
4234         .data = NULL,
4235         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4236                 "<port_id[,queue_id]>: "
4237                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4238         .tokens = {
4239                 (void *)&cmd_vlan_offload_vlan,
4240                 (void *)&cmd_vlan_offload_set,
4241                 (void *)&cmd_vlan_offload_what,
4242                 (void *)&cmd_vlan_offload_on,
4243                 (void *)&cmd_vlan_offload_portid,
4244                 NULL,
4245         },
4246 };
4247
4248 /* *** VLAN TPID SET ON A PORT *** */
4249 struct cmd_vlan_tpid_result {
4250         cmdline_fixed_string_t vlan;
4251         cmdline_fixed_string_t set;
4252         cmdline_fixed_string_t vlan_type;
4253         cmdline_fixed_string_t what;
4254         uint16_t tp_id;
4255         portid_t port_id;
4256 };
4257
4258 static void
4259 cmd_vlan_tpid_parsed(void *parsed_result,
4260                           __rte_unused struct cmdline *cl,
4261                           __rte_unused void *data)
4262 {
4263         struct cmd_vlan_tpid_result *res = parsed_result;
4264         enum rte_vlan_type vlan_type;
4265
4266         if (!strcmp(res->vlan_type, "inner"))
4267                 vlan_type = ETH_VLAN_TYPE_INNER;
4268         else if (!strcmp(res->vlan_type, "outer"))
4269                 vlan_type = ETH_VLAN_TYPE_OUTER;
4270         else {
4271                 printf("Unknown vlan type\n");
4272                 return;
4273         }
4274         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4275 }
4276
4277 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4278         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4279                                  vlan, "vlan");
4280 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4281         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4282                                  set, "set");
4283 cmdline_parse_token_string_t cmd_vlan_type =
4284         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4285                                  vlan_type, "inner#outer");
4286 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4287         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4288                                  what, "tpid");
4289 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4290         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4291                               tp_id, UINT16);
4292 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4293         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4294                               port_id, UINT16);
4295
4296 cmdline_parse_inst_t cmd_vlan_tpid = {
4297         .f = cmd_vlan_tpid_parsed,
4298         .data = NULL,
4299         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4300                 "Set the VLAN Ether type",
4301         .tokens = {
4302                 (void *)&cmd_vlan_tpid_vlan,
4303                 (void *)&cmd_vlan_tpid_set,
4304                 (void *)&cmd_vlan_type,
4305                 (void *)&cmd_vlan_tpid_what,
4306                 (void *)&cmd_vlan_tpid_tpid,
4307                 (void *)&cmd_vlan_tpid_portid,
4308                 NULL,
4309         },
4310 };
4311
4312 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4313 struct cmd_rx_vlan_filter_result {
4314         cmdline_fixed_string_t rx_vlan;
4315         cmdline_fixed_string_t what;
4316         uint16_t vlan_id;
4317         portid_t port_id;
4318 };
4319
4320 static void
4321 cmd_rx_vlan_filter_parsed(void *parsed_result,
4322                           __rte_unused struct cmdline *cl,
4323                           __rte_unused void *data)
4324 {
4325         struct cmd_rx_vlan_filter_result *res = parsed_result;
4326
4327         if (!strcmp(res->what, "add"))
4328                 rx_vft_set(res->port_id, res->vlan_id, 1);
4329         else
4330                 rx_vft_set(res->port_id, res->vlan_id, 0);
4331 }
4332
4333 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4334         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4335                                  rx_vlan, "rx_vlan");
4336 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4337         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4338                                  what, "add#rm");
4339 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4340         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4341                               vlan_id, UINT16);
4342 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4343         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4344                               port_id, UINT16);
4345
4346 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4347         .f = cmd_rx_vlan_filter_parsed,
4348         .data = NULL,
4349         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4350                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4351                 "identifiers filtered by a port",
4352         .tokens = {
4353                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4354                 (void *)&cmd_rx_vlan_filter_what,
4355                 (void *)&cmd_rx_vlan_filter_vlanid,
4356                 (void *)&cmd_rx_vlan_filter_portid,
4357                 NULL,
4358         },
4359 };
4360
4361 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4362 struct cmd_tx_vlan_set_result {
4363         cmdline_fixed_string_t tx_vlan;
4364         cmdline_fixed_string_t set;
4365         portid_t port_id;
4366         uint16_t vlan_id;
4367 };
4368
4369 static void
4370 cmd_tx_vlan_set_parsed(void *parsed_result,
4371                        __rte_unused struct cmdline *cl,
4372                        __rte_unused void *data)
4373 {
4374         struct cmd_tx_vlan_set_result *res = parsed_result;
4375
4376         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4377                 return;
4378
4379         if (!port_is_stopped(res->port_id)) {
4380                 printf("Please stop port %d first\n", res->port_id);
4381                 return;
4382         }
4383
4384         tx_vlan_set(res->port_id, res->vlan_id);
4385
4386         cmd_reconfig_device_queue(res->port_id, 1, 1);
4387 }
4388
4389 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4390         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4391                                  tx_vlan, "tx_vlan");
4392 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4393         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4394                                  set, "set");
4395 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4396         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4397                               port_id, UINT16);
4398 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4399         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4400                               vlan_id, UINT16);
4401
4402 cmdline_parse_inst_t cmd_tx_vlan_set = {
4403         .f = cmd_tx_vlan_set_parsed,
4404         .data = NULL,
4405         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4406                 "Enable hardware insertion of a single VLAN header "
4407                 "with a given TAG Identifier in packets sent on a port",
4408         .tokens = {
4409                 (void *)&cmd_tx_vlan_set_tx_vlan,
4410                 (void *)&cmd_tx_vlan_set_set,
4411                 (void *)&cmd_tx_vlan_set_portid,
4412                 (void *)&cmd_tx_vlan_set_vlanid,
4413                 NULL,
4414         },
4415 };
4416
4417 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4418 struct cmd_tx_vlan_set_qinq_result {
4419         cmdline_fixed_string_t tx_vlan;
4420         cmdline_fixed_string_t set;
4421         portid_t port_id;
4422         uint16_t vlan_id;
4423         uint16_t vlan_id_outer;
4424 };
4425
4426 static void
4427 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4428                             __rte_unused struct cmdline *cl,
4429                             __rte_unused void *data)
4430 {
4431         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4432
4433         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4434                 return;
4435
4436         if (!port_is_stopped(res->port_id)) {
4437                 printf("Please stop port %d first\n", res->port_id);
4438                 return;
4439         }
4440
4441         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4442
4443         cmd_reconfig_device_queue(res->port_id, 1, 1);
4444 }
4445
4446 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4447         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4448                 tx_vlan, "tx_vlan");
4449 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4450         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4451                 set, "set");
4452 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4453         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4454                 port_id, UINT16);
4455 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4456         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4457                 vlan_id, UINT16);
4458 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4459         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4460                 vlan_id_outer, UINT16);
4461
4462 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4463         .f = cmd_tx_vlan_set_qinq_parsed,
4464         .data = NULL,
4465         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4466                 "Enable hardware insertion of double VLAN header "
4467                 "with given TAG Identifiers in packets sent on a port",
4468         .tokens = {
4469                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4470                 (void *)&cmd_tx_vlan_set_qinq_set,
4471                 (void *)&cmd_tx_vlan_set_qinq_portid,
4472                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4473                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4474                 NULL,
4475         },
4476 };
4477
4478 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4479 struct cmd_tx_vlan_set_pvid_result {
4480         cmdline_fixed_string_t tx_vlan;
4481         cmdline_fixed_string_t set;
4482         cmdline_fixed_string_t pvid;
4483         portid_t port_id;
4484         uint16_t vlan_id;
4485         cmdline_fixed_string_t mode;
4486 };
4487
4488 static void
4489 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4490                             __rte_unused struct cmdline *cl,
4491                             __rte_unused void *data)
4492 {
4493         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4494
4495         if (strcmp(res->mode, "on") == 0)
4496                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4497         else
4498                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4499 }
4500
4501 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4502         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4503                                  tx_vlan, "tx_vlan");
4504 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4505         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4506                                  set, "set");
4507 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4508         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4509                                  pvid, "pvid");
4510 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4511         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4512                              port_id, UINT16);
4513 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4514         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4515                               vlan_id, UINT16);
4516 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4517         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4518                                  mode, "on#off");
4519
4520 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4521         .f = cmd_tx_vlan_set_pvid_parsed,
4522         .data = NULL,
4523         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4524         .tokens = {
4525                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4526                 (void *)&cmd_tx_vlan_set_pvid_set,
4527                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4528                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4529                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4530                 (void *)&cmd_tx_vlan_set_pvid_mode,
4531                 NULL,
4532         },
4533 };
4534
4535 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4536 struct cmd_tx_vlan_reset_result {
4537         cmdline_fixed_string_t tx_vlan;
4538         cmdline_fixed_string_t reset;
4539         portid_t port_id;
4540 };
4541
4542 static void
4543 cmd_tx_vlan_reset_parsed(void *parsed_result,
4544                          __rte_unused struct cmdline *cl,
4545                          __rte_unused void *data)
4546 {
4547         struct cmd_tx_vlan_reset_result *res = parsed_result;
4548
4549         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4550                 return;
4551
4552         if (!port_is_stopped(res->port_id)) {
4553                 printf("Please stop port %d first\n", res->port_id);
4554                 return;
4555         }
4556
4557         tx_vlan_reset(res->port_id);
4558
4559         cmd_reconfig_device_queue(res->port_id, 1, 1);
4560 }
4561
4562 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4563         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4564                                  tx_vlan, "tx_vlan");
4565 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4566         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4567                                  reset, "reset");
4568 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4569         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4570                               port_id, UINT16);
4571
4572 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4573         .f = cmd_tx_vlan_reset_parsed,
4574         .data = NULL,
4575         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4576                 "VLAN header in packets sent on a port",
4577         .tokens = {
4578                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4579                 (void *)&cmd_tx_vlan_reset_reset,
4580                 (void *)&cmd_tx_vlan_reset_portid,
4581                 NULL,
4582         },
4583 };
4584
4585
4586 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4587 struct cmd_csum_result {
4588         cmdline_fixed_string_t csum;
4589         cmdline_fixed_string_t mode;
4590         cmdline_fixed_string_t proto;
4591         cmdline_fixed_string_t hwsw;
4592         portid_t port_id;
4593 };
4594
4595 static void
4596 csum_show(int port_id)
4597 {
4598         struct rte_eth_dev_info dev_info;
4599         uint64_t tx_offloads;
4600         int ret;
4601
4602         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4603         printf("Parse tunnel is %s\n",
4604                 (ports[port_id].parse_tunnel) ? "on" : "off");
4605         printf("IP checksum offload is %s\n",
4606                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4607         printf("UDP checksum offload is %s\n",
4608                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4609         printf("TCP checksum offload is %s\n",
4610                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4611         printf("SCTP checksum offload is %s\n",
4612                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4613         printf("Outer-Ip checksum offload is %s\n",
4614                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4615         printf("Outer-Udp checksum offload is %s\n",
4616                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4617
4618         /* display warnings if configuration is not supported by the NIC */
4619         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4620         if (ret != 0)
4621                 return;
4622
4623         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4624                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4625                 printf("Warning: hardware IP checksum enabled but not "
4626                         "supported by port %d\n", port_id);
4627         }
4628         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4629                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4630                 printf("Warning: hardware UDP checksum enabled but not "
4631                         "supported by port %d\n", port_id);
4632         }
4633         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4634                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4635                 printf("Warning: hardware TCP checksum enabled but not "
4636                         "supported by port %d\n", port_id);
4637         }
4638         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4639                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4640                 printf("Warning: hardware SCTP checksum enabled but not "
4641                         "supported by port %d\n", port_id);
4642         }
4643         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4644                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4645                 printf("Warning: hardware outer IP checksum enabled but not "
4646                         "supported by port %d\n", port_id);
4647         }
4648         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4649                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4650                         == 0) {
4651                 printf("Warning: hardware outer UDP checksum enabled but not "
4652                         "supported by port %d\n", port_id);
4653         }
4654 }
4655
4656 static void
4657 cmd_config_queue_tx_offloads(struct rte_port *port)
4658 {
4659         int k;
4660
4661         /* Apply queue tx offloads configuration */
4662         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4663                 port->tx_conf[k].offloads =
4664                         port->dev_conf.txmode.offloads;
4665 }
4666
4667 static void
4668 cmd_csum_parsed(void *parsed_result,
4669                        __rte_unused struct cmdline *cl,
4670                        __rte_unused void *data)
4671 {
4672         struct cmd_csum_result *res = parsed_result;
4673         int hw = 0;
4674         uint64_t csum_offloads = 0;
4675         struct rte_eth_dev_info dev_info;
4676         int ret;
4677
4678         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4679                 printf("invalid port %d\n", res->port_id);
4680                 return;
4681         }
4682         if (!port_is_stopped(res->port_id)) {
4683                 printf("Please stop port %d first\n", res->port_id);
4684                 return;
4685         }
4686
4687         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4688         if (ret != 0)
4689                 return;
4690
4691         if (!strcmp(res->mode, "set")) {
4692
4693                 if (!strcmp(res->hwsw, "hw"))
4694                         hw = 1;
4695
4696                 if (!strcmp(res->proto, "ip")) {
4697                         if (hw == 0 || (dev_info.tx_offload_capa &
4698                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4699                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4700                         } else {
4701                                 printf("IP checksum offload is not supported "
4702                                        "by port %u\n", res->port_id);
4703                         }
4704                 } else if (!strcmp(res->proto, "udp")) {
4705                         if (hw == 0 || (dev_info.tx_offload_capa &
4706                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4707                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4708                         } else {
4709                                 printf("UDP checksum offload is not supported "
4710                                        "by port %u\n", res->port_id);
4711                         }
4712                 } else if (!strcmp(res->proto, "tcp")) {
4713                         if (hw == 0 || (dev_info.tx_offload_capa &
4714                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4715                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4716                         } else {
4717                                 printf("TCP checksum offload is not supported "
4718                                        "by port %u\n", res->port_id);
4719                         }
4720                 } else if (!strcmp(res->proto, "sctp")) {
4721                         if (hw == 0 || (dev_info.tx_offload_capa &
4722                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4723                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4724                         } else {
4725                                 printf("SCTP checksum offload is not supported "
4726                                        "by port %u\n", res->port_id);
4727                         }
4728                 } else if (!strcmp(res->proto, "outer-ip")) {
4729                         if (hw == 0 || (dev_info.tx_offload_capa &
4730                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4731                                 csum_offloads |=
4732                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4733                         } else {
4734                                 printf("Outer IP checksum offload is not "
4735                                        "supported by port %u\n", res->port_id);
4736                         }
4737                 } else if (!strcmp(res->proto, "outer-udp")) {
4738                         if (hw == 0 || (dev_info.tx_offload_capa &
4739                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4740                                 csum_offloads |=
4741                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4742                         } else {
4743                                 printf("Outer UDP checksum offload is not "
4744                                        "supported by port %u\n", res->port_id);
4745                         }
4746                 }
4747
4748                 if (hw) {
4749                         ports[res->port_id].dev_conf.txmode.offloads |=
4750                                                         csum_offloads;
4751                 } else {
4752                         ports[res->port_id].dev_conf.txmode.offloads &=
4753                                                         (~csum_offloads);
4754                 }
4755                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4756         }
4757         csum_show(res->port_id);
4758
4759         cmd_reconfig_device_queue(res->port_id, 1, 1);
4760 }
4761
4762 cmdline_parse_token_string_t cmd_csum_csum =
4763         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4764                                 csum, "csum");
4765 cmdline_parse_token_string_t cmd_csum_mode =
4766         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4767                                 mode, "set");
4768 cmdline_parse_token_string_t cmd_csum_proto =
4769         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4770                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4771 cmdline_parse_token_string_t cmd_csum_hwsw =
4772         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4773                                 hwsw, "hw#sw");
4774 cmdline_parse_token_num_t cmd_csum_portid =
4775         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4776                                 port_id, UINT16);
4777
4778 cmdline_parse_inst_t cmd_csum_set = {
4779         .f = cmd_csum_parsed,
4780         .data = NULL,
4781         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4782                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4783                 "using csum forward engine",
4784         .tokens = {
4785                 (void *)&cmd_csum_csum,
4786                 (void *)&cmd_csum_mode,
4787                 (void *)&cmd_csum_proto,
4788                 (void *)&cmd_csum_hwsw,
4789                 (void *)&cmd_csum_portid,
4790                 NULL,
4791         },
4792 };
4793
4794 cmdline_parse_token_string_t cmd_csum_mode_show =
4795         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4796                                 mode, "show");
4797
4798 cmdline_parse_inst_t cmd_csum_show = {
4799         .f = cmd_csum_parsed,
4800         .data = NULL,
4801         .help_str = "csum show <port_id>: Show checksum offload configuration",
4802         .tokens = {
4803                 (void *)&cmd_csum_csum,
4804                 (void *)&cmd_csum_mode_show,
4805                 (void *)&cmd_csum_portid,
4806                 NULL,
4807         },
4808 };
4809
4810 /* Enable/disable tunnel parsing */
4811 struct cmd_csum_tunnel_result {
4812         cmdline_fixed_string_t csum;
4813         cmdline_fixed_string_t parse;
4814         cmdline_fixed_string_t onoff;
4815         portid_t port_id;
4816 };
4817
4818 static void
4819 cmd_csum_tunnel_parsed(void *parsed_result,
4820                        __rte_unused struct cmdline *cl,
4821                        __rte_unused void *data)
4822 {
4823         struct cmd_csum_tunnel_result *res = parsed_result;
4824
4825         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4826                 return;
4827
4828         if (!strcmp(res->onoff, "on"))
4829                 ports[res->port_id].parse_tunnel = 1;
4830         else
4831                 ports[res->port_id].parse_tunnel = 0;
4832
4833         csum_show(res->port_id);
4834 }
4835
4836 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4837         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4838                                 csum, "csum");
4839 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4840         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4841                                 parse, "parse-tunnel");
4842 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4843         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4844                                 onoff, "on#off");
4845 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4846         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4847                                 port_id, UINT16);
4848
4849 cmdline_parse_inst_t cmd_csum_tunnel = {
4850         .f = cmd_csum_tunnel_parsed,
4851         .data = NULL,
4852         .help_str = "csum parse-tunnel on|off <port_id>: "
4853                 "Enable/Disable parsing of tunnels for csum engine",
4854         .tokens = {
4855                 (void *)&cmd_csum_tunnel_csum,
4856                 (void *)&cmd_csum_tunnel_parse,
4857                 (void *)&cmd_csum_tunnel_onoff,
4858                 (void *)&cmd_csum_tunnel_portid,
4859                 NULL,
4860         },
4861 };
4862
4863 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4864 struct cmd_tso_set_result {
4865         cmdline_fixed_string_t tso;
4866         cmdline_fixed_string_t mode;
4867         uint16_t tso_segsz;
4868         portid_t port_id;
4869 };
4870
4871 static void
4872 cmd_tso_set_parsed(void *parsed_result,
4873                        __rte_unused struct cmdline *cl,
4874                        __rte_unused void *data)
4875 {
4876         struct cmd_tso_set_result *res = parsed_result;
4877         struct rte_eth_dev_info dev_info;
4878         int ret;
4879
4880         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4881                 return;
4882         if (!port_is_stopped(res->port_id)) {
4883                 printf("Please stop port %d first\n", res->port_id);
4884                 return;
4885         }
4886
4887         if (!strcmp(res->mode, "set"))
4888                 ports[res->port_id].tso_segsz = res->tso_segsz;
4889
4890         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4891         if (ret != 0)
4892                 return;
4893
4894         if ((ports[res->port_id].tso_segsz != 0) &&
4895                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4896                 printf("Error: TSO is not supported by port %d\n",
4897                        res->port_id);
4898                 return;
4899         }
4900
4901         if (ports[res->port_id].tso_segsz == 0) {
4902                 ports[res->port_id].dev_conf.txmode.offloads &=
4903                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4904                 printf("TSO for non-tunneled packets is disabled\n");
4905         } else {
4906                 ports[res->port_id].dev_conf.txmode.offloads |=
4907                                                 DEV_TX_OFFLOAD_TCP_TSO;
4908                 printf("TSO segment size for non-tunneled packets is %d\n",
4909                         ports[res->port_id].tso_segsz);
4910         }
4911         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4912
4913         /* display warnings if configuration is not supported by the NIC */
4914         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4915         if (ret != 0)
4916                 return;
4917
4918         if ((ports[res->port_id].tso_segsz != 0) &&
4919                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4920                 printf("Warning: TSO enabled but not "
4921                         "supported by port %d\n", res->port_id);
4922         }
4923
4924         cmd_reconfig_device_queue(res->port_id, 1, 1);
4925 }
4926
4927 cmdline_parse_token_string_t cmd_tso_set_tso =
4928         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4929                                 tso, "tso");
4930 cmdline_parse_token_string_t cmd_tso_set_mode =
4931         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4932                                 mode, "set");
4933 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4934         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4935                                 tso_segsz, UINT16);
4936 cmdline_parse_token_num_t cmd_tso_set_portid =
4937         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4938                                 port_id, UINT16);
4939
4940 cmdline_parse_inst_t cmd_tso_set = {
4941         .f = cmd_tso_set_parsed,
4942         .data = NULL,
4943         .help_str = "tso set <tso_segsz> <port_id>: "
4944                 "Set TSO segment size of non-tunneled packets for csum engine "
4945                 "(0 to disable)",
4946         .tokens = {
4947                 (void *)&cmd_tso_set_tso,
4948                 (void *)&cmd_tso_set_mode,
4949                 (void *)&cmd_tso_set_tso_segsz,
4950                 (void *)&cmd_tso_set_portid,
4951                 NULL,
4952         },
4953 };
4954
4955 cmdline_parse_token_string_t cmd_tso_show_mode =
4956         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4957                                 mode, "show");
4958
4959
4960 cmdline_parse_inst_t cmd_tso_show = {
4961         .f = cmd_tso_set_parsed,
4962         .data = NULL,
4963         .help_str = "tso show <port_id>: "
4964                 "Show TSO segment size of non-tunneled packets for csum engine",
4965         .tokens = {
4966                 (void *)&cmd_tso_set_tso,
4967                 (void *)&cmd_tso_show_mode,
4968                 (void *)&cmd_tso_set_portid,
4969                 NULL,
4970         },
4971 };
4972
4973 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4974 struct cmd_tunnel_tso_set_result {
4975         cmdline_fixed_string_t tso;
4976         cmdline_fixed_string_t mode;
4977         uint16_t tso_segsz;
4978         portid_t port_id;
4979 };
4980
4981 static struct rte_eth_dev_info
4982 check_tunnel_tso_nic_support(portid_t port_id)
4983 {
4984         struct rte_eth_dev_info dev_info;
4985
4986         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4987                 return dev_info;
4988
4989         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4990                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4991                        "not enabled for port %d\n", port_id);
4992         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4993                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4994                        "not enabled for port %d\n", port_id);
4995         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4996                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4997                        "not enabled for port %d\n", port_id);
4998         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4999                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
5000                        "not enabled for port %d\n", port_id);
5001         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
5002                 printf("Warning: IP TUNNEL TSO not supported therefore "
5003                        "not enabled for port %d\n", port_id);
5004         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
5005                 printf("Warning: UDP TUNNEL TSO not supported therefore "
5006                        "not enabled for port %d\n", port_id);
5007         return dev_info;
5008 }
5009
5010 static void
5011 cmd_tunnel_tso_set_parsed(void *parsed_result,
5012                           __rte_unused struct cmdline *cl,
5013                           __rte_unused void *data)
5014 {
5015         struct cmd_tunnel_tso_set_result *res = parsed_result;
5016         struct rte_eth_dev_info dev_info;
5017
5018         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5019                 return;
5020         if (!port_is_stopped(res->port_id)) {
5021                 printf("Please stop port %d first\n", res->port_id);
5022                 return;
5023         }
5024
5025         if (!strcmp(res->mode, "set"))
5026                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5027
5028         dev_info = check_tunnel_tso_nic_support(res->port_id);
5029         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5030                 ports[res->port_id].dev_conf.txmode.offloads &=
5031                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5032                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5033                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5034                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5035                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5036                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5037                 printf("TSO for tunneled packets is disabled\n");
5038         } else {
5039                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5040                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5041                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5042                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5043                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5044                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5045
5046                 ports[res->port_id].dev_conf.txmode.offloads |=
5047                         (tso_offloads & dev_info.tx_offload_capa);
5048                 printf("TSO segment size for tunneled packets is %d\n",
5049                         ports[res->port_id].tunnel_tso_segsz);
5050
5051                 /* Below conditions are needed to make it work:
5052                  * (1) tunnel TSO is supported by the NIC;
5053                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5054                  * are recognized;
5055                  * (3) for tunneled pkts with outer L3 of IPv4,
5056                  * "csum set outer-ip" must be set to hw, because after tso,
5057                  * total_len of outer IP header is changed, and the checksum
5058                  * of outer IP header calculated by sw should be wrong; that
5059                  * is not necessary for IPv6 tunneled pkts because there's no
5060                  * checksum in IP header anymore.
5061                  */
5062
5063                 if (!ports[res->port_id].parse_tunnel)
5064                         printf("Warning: csum parse_tunnel must be set "
5065                                 "so that tunneled packets are recognized\n");
5066                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5067                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5068                         printf("Warning: csum set outer-ip must be set to hw "
5069                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5070         }
5071
5072         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5073         cmd_reconfig_device_queue(res->port_id, 1, 1);
5074 }
5075
5076 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5077         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5078                                 tso, "tunnel_tso");
5079 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5080         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5081                                 mode, "set");
5082 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5083         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5084                                 tso_segsz, UINT16);
5085 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5086         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5087                                 port_id, UINT16);
5088
5089 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5090         .f = cmd_tunnel_tso_set_parsed,
5091         .data = NULL,
5092         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5093                 "Set TSO segment size of tunneled packets for csum engine "
5094                 "(0 to disable)",
5095         .tokens = {
5096                 (void *)&cmd_tunnel_tso_set_tso,
5097                 (void *)&cmd_tunnel_tso_set_mode,
5098                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5099                 (void *)&cmd_tunnel_tso_set_portid,
5100                 NULL,
5101         },
5102 };
5103
5104 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5105         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5106                                 mode, "show");
5107
5108
5109 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5110         .f = cmd_tunnel_tso_set_parsed,
5111         .data = NULL,
5112         .help_str = "tunnel_tso show <port_id> "
5113                 "Show TSO segment size of tunneled packets for csum engine",
5114         .tokens = {
5115                 (void *)&cmd_tunnel_tso_set_tso,
5116                 (void *)&cmd_tunnel_tso_show_mode,
5117                 (void *)&cmd_tunnel_tso_set_portid,
5118                 NULL,
5119         },
5120 };
5121
5122 /* *** SET GRO FOR A PORT *** */
5123 struct cmd_gro_enable_result {
5124         cmdline_fixed_string_t cmd_set;
5125         cmdline_fixed_string_t cmd_port;
5126         cmdline_fixed_string_t cmd_keyword;
5127         cmdline_fixed_string_t cmd_onoff;
5128         portid_t cmd_pid;
5129 };
5130
5131 static void
5132 cmd_gro_enable_parsed(void *parsed_result,
5133                 __rte_unused struct cmdline *cl,
5134                 __rte_unused void *data)
5135 {
5136         struct cmd_gro_enable_result *res;
5137
5138         res = parsed_result;
5139         if (!strcmp(res->cmd_keyword, "gro"))
5140                 setup_gro(res->cmd_onoff, res->cmd_pid);
5141 }
5142
5143 cmdline_parse_token_string_t cmd_gro_enable_set =
5144         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5145                         cmd_set, "set");
5146 cmdline_parse_token_string_t cmd_gro_enable_port =
5147         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5148                         cmd_keyword, "port");
5149 cmdline_parse_token_num_t cmd_gro_enable_pid =
5150         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5151                         cmd_pid, UINT16);
5152 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5153         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5154                         cmd_keyword, "gro");
5155 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5156         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5157                         cmd_onoff, "on#off");
5158
5159 cmdline_parse_inst_t cmd_gro_enable = {
5160         .f = cmd_gro_enable_parsed,
5161         .data = NULL,
5162         .help_str = "set port <port_id> gro on|off",
5163         .tokens = {
5164                 (void *)&cmd_gro_enable_set,
5165                 (void *)&cmd_gro_enable_port,
5166                 (void *)&cmd_gro_enable_pid,
5167                 (void *)&cmd_gro_enable_keyword,
5168                 (void *)&cmd_gro_enable_onoff,
5169                 NULL,
5170         },
5171 };
5172
5173 /* *** DISPLAY GRO CONFIGURATION *** */
5174 struct cmd_gro_show_result {
5175         cmdline_fixed_string_t cmd_show;
5176         cmdline_fixed_string_t cmd_port;
5177         cmdline_fixed_string_t cmd_keyword;
5178         portid_t cmd_pid;
5179 };
5180
5181 static void
5182 cmd_gro_show_parsed(void *parsed_result,
5183                 __rte_unused struct cmdline *cl,
5184                 __rte_unused void *data)
5185 {
5186         struct cmd_gro_show_result *res;
5187
5188         res = parsed_result;
5189         if (!strcmp(res->cmd_keyword, "gro"))
5190                 show_gro(res->cmd_pid);
5191 }
5192
5193 cmdline_parse_token_string_t cmd_gro_show_show =
5194         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5195                         cmd_show, "show");
5196 cmdline_parse_token_string_t cmd_gro_show_port =
5197         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5198                         cmd_port, "port");
5199 cmdline_parse_token_num_t cmd_gro_show_pid =
5200         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5201                         cmd_pid, UINT16);
5202 cmdline_parse_token_string_t cmd_gro_show_keyword =
5203         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5204                         cmd_keyword, "gro");
5205
5206 cmdline_parse_inst_t cmd_gro_show = {
5207         .f = cmd_gro_show_parsed,
5208         .data = NULL,
5209         .help_str = "show port <port_id> gro",
5210         .tokens = {
5211                 (void *)&cmd_gro_show_show,
5212                 (void *)&cmd_gro_show_port,
5213                 (void *)&cmd_gro_show_pid,
5214                 (void *)&cmd_gro_show_keyword,
5215                 NULL,
5216         },
5217 };
5218
5219 /* *** SET FLUSH CYCLES FOR GRO *** */
5220 struct cmd_gro_flush_result {
5221         cmdline_fixed_string_t cmd_set;
5222         cmdline_fixed_string_t cmd_keyword;
5223         cmdline_fixed_string_t cmd_flush;
5224         uint8_t cmd_cycles;
5225 };
5226
5227 static void
5228 cmd_gro_flush_parsed(void *parsed_result,
5229                 __rte_unused struct cmdline *cl,
5230                 __rte_unused void *data)
5231 {
5232         struct cmd_gro_flush_result *res;
5233
5234         res = parsed_result;
5235         if ((!strcmp(res->cmd_keyword, "gro")) &&
5236                         (!strcmp(res->cmd_flush, "flush")))
5237                 setup_gro_flush_cycles(res->cmd_cycles);
5238 }
5239
5240 cmdline_parse_token_string_t cmd_gro_flush_set =
5241         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5242                         cmd_set, "set");
5243 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5244         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5245                         cmd_keyword, "gro");
5246 cmdline_parse_token_string_t cmd_gro_flush_flush =
5247         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5248                         cmd_flush, "flush");
5249 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5250         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5251                         cmd_cycles, UINT8);
5252
5253 cmdline_parse_inst_t cmd_gro_flush = {
5254         .f = cmd_gro_flush_parsed,
5255         .data = NULL,
5256         .help_str = "set gro flush <cycles>",
5257         .tokens = {
5258                 (void *)&cmd_gro_flush_set,
5259                 (void *)&cmd_gro_flush_keyword,
5260                 (void *)&cmd_gro_flush_flush,
5261                 (void *)&cmd_gro_flush_cycles,
5262                 NULL,
5263         },
5264 };
5265
5266 /* *** ENABLE/DISABLE GSO *** */
5267 struct cmd_gso_enable_result {
5268         cmdline_fixed_string_t cmd_set;
5269         cmdline_fixed_string_t cmd_port;
5270         cmdline_fixed_string_t cmd_keyword;
5271         cmdline_fixed_string_t cmd_mode;
5272         portid_t cmd_pid;
5273 };
5274
5275 static void
5276 cmd_gso_enable_parsed(void *parsed_result,
5277                 __rte_unused struct cmdline *cl,
5278                 __rte_unused void *data)
5279 {
5280         struct cmd_gso_enable_result *res;
5281
5282         res = parsed_result;
5283         if (!strcmp(res->cmd_keyword, "gso"))
5284                 setup_gso(res->cmd_mode, res->cmd_pid);
5285 }
5286
5287 cmdline_parse_token_string_t cmd_gso_enable_set =
5288         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5289                         cmd_set, "set");
5290 cmdline_parse_token_string_t cmd_gso_enable_port =
5291         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5292                         cmd_port, "port");
5293 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5294         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5295                         cmd_keyword, "gso");
5296 cmdline_parse_token_string_t cmd_gso_enable_mode =
5297         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5298                         cmd_mode, "on#off");
5299 cmdline_parse_token_num_t cmd_gso_enable_pid =
5300         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5301                         cmd_pid, UINT16);
5302
5303 cmdline_parse_inst_t cmd_gso_enable = {
5304         .f = cmd_gso_enable_parsed,
5305         .data = NULL,
5306         .help_str = "set port <port_id> gso on|off",
5307         .tokens = {
5308                 (void *)&cmd_gso_enable_set,
5309                 (void *)&cmd_gso_enable_port,
5310                 (void *)&cmd_gso_enable_pid,
5311                 (void *)&cmd_gso_enable_keyword,
5312                 (void *)&cmd_gso_enable_mode,
5313                 NULL,
5314         },
5315 };
5316
5317 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5318 struct cmd_gso_size_result {
5319         cmdline_fixed_string_t cmd_set;
5320         cmdline_fixed_string_t cmd_keyword;
5321         cmdline_fixed_string_t cmd_segsz;
5322         uint16_t cmd_size;
5323 };
5324
5325 static void
5326 cmd_gso_size_parsed(void *parsed_result,
5327                        __rte_unused struct cmdline *cl,
5328                        __rte_unused void *data)
5329 {
5330         struct cmd_gso_size_result *res = parsed_result;
5331
5332         if (test_done == 0) {
5333                 printf("Before setting GSO segsz, please first"
5334                                 " stop forwarding\n");
5335                 return;
5336         }
5337
5338         if (!strcmp(res->cmd_keyword, "gso") &&
5339                         !strcmp(res->cmd_segsz, "segsz")) {
5340                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5341                         printf("gso_size should be larger than %zu."
5342                                         " Please input a legal value\n",
5343                                         RTE_GSO_SEG_SIZE_MIN);
5344                 else
5345                         gso_max_segment_size = res->cmd_size;
5346         }
5347 }
5348
5349 cmdline_parse_token_string_t cmd_gso_size_set =
5350         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5351                                 cmd_set, "set");
5352 cmdline_parse_token_string_t cmd_gso_size_keyword =
5353         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5354                                 cmd_keyword, "gso");
5355 cmdline_parse_token_string_t cmd_gso_size_segsz =
5356         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5357                                 cmd_segsz, "segsz");
5358 cmdline_parse_token_num_t cmd_gso_size_size =
5359         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5360                                 cmd_size, UINT16);
5361
5362 cmdline_parse_inst_t cmd_gso_size = {
5363         .f = cmd_gso_size_parsed,
5364         .data = NULL,
5365         .help_str = "set gso segsz <length>",
5366         .tokens = {
5367                 (void *)&cmd_gso_size_set,
5368                 (void *)&cmd_gso_size_keyword,
5369                 (void *)&cmd_gso_size_segsz,
5370                 (void *)&cmd_gso_size_size,
5371                 NULL,
5372         },
5373 };
5374
5375 /* *** SHOW GSO CONFIGURATION *** */
5376 struct cmd_gso_show_result {
5377         cmdline_fixed_string_t cmd_show;
5378         cmdline_fixed_string_t cmd_port;
5379         cmdline_fixed_string_t cmd_keyword;
5380         portid_t cmd_pid;
5381 };
5382
5383 static void
5384 cmd_gso_show_parsed(void *parsed_result,
5385                        __rte_unused struct cmdline *cl,
5386                        __rte_unused void *data)
5387 {
5388         struct cmd_gso_show_result *res = parsed_result;
5389
5390         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5391                 printf("invalid port id %u\n", res->cmd_pid);
5392                 return;
5393         }
5394         if (!strcmp(res->cmd_keyword, "gso")) {
5395                 if (gso_ports[res->cmd_pid].enable) {
5396                         printf("Max GSO'd packet size: %uB\n"
5397                                         "Supported GSO types: TCP/IPv4, "
5398                                         "UDP/IPv4, VxLAN with inner "
5399                                         "TCP/IPv4 packet, GRE with inner "
5400                                         "TCP/IPv4 packet\n",
5401                                         gso_max_segment_size);
5402                 } else
5403                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5404         }
5405 }
5406
5407 cmdline_parse_token_string_t cmd_gso_show_show =
5408 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5409                 cmd_show, "show");
5410 cmdline_parse_token_string_t cmd_gso_show_port =
5411 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5412                 cmd_port, "port");
5413 cmdline_parse_token_string_t cmd_gso_show_keyword =
5414         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5415                                 cmd_keyword, "gso");
5416 cmdline_parse_token_num_t cmd_gso_show_pid =
5417         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5418                                 cmd_pid, UINT16);
5419
5420 cmdline_parse_inst_t cmd_gso_show = {
5421         .f = cmd_gso_show_parsed,
5422         .data = NULL,
5423         .help_str = "show port <port_id> gso",
5424         .tokens = {
5425                 (void *)&cmd_gso_show_show,
5426                 (void *)&cmd_gso_show_port,
5427                 (void *)&cmd_gso_show_pid,
5428                 (void *)&cmd_gso_show_keyword,
5429                 NULL,
5430         },
5431 };
5432
5433 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5434 struct cmd_set_flush_rx {
5435         cmdline_fixed_string_t set;
5436         cmdline_fixed_string_t flush_rx;
5437         cmdline_fixed_string_t mode;
5438 };
5439
5440 static void
5441 cmd_set_flush_rx_parsed(void *parsed_result,
5442                 __rte_unused struct cmdline *cl,
5443                 __rte_unused void *data)
5444 {
5445         struct cmd_set_flush_rx *res = parsed_result;
5446         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5447 }
5448
5449 cmdline_parse_token_string_t cmd_setflushrx_set =
5450         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5451                         set, "set");
5452 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5453         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5454                         flush_rx, "flush_rx");
5455 cmdline_parse_token_string_t cmd_setflushrx_mode =
5456         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5457                         mode, "on#off");
5458
5459
5460 cmdline_parse_inst_t cmd_set_flush_rx = {
5461         .f = cmd_set_flush_rx_parsed,
5462         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5463         .data = NULL,
5464         .tokens = {
5465                 (void *)&cmd_setflushrx_set,
5466                 (void *)&cmd_setflushrx_flush_rx,
5467                 (void *)&cmd_setflushrx_mode,
5468                 NULL,
5469         },
5470 };
5471
5472 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5473 struct cmd_set_link_check {
5474         cmdline_fixed_string_t set;
5475         cmdline_fixed_string_t link_check;
5476         cmdline_fixed_string_t mode;
5477 };
5478
5479 static void
5480 cmd_set_link_check_parsed(void *parsed_result,
5481                 __rte_unused struct cmdline *cl,
5482                 __rte_unused void *data)
5483 {
5484         struct cmd_set_link_check *res = parsed_result;
5485         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5486 }
5487
5488 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5489         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5490                         set, "set");
5491 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5492         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5493                         link_check, "link_check");
5494 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5495         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5496                         mode, "on#off");
5497
5498
5499 cmdline_parse_inst_t cmd_set_link_check = {
5500         .f = cmd_set_link_check_parsed,
5501         .help_str = "set link_check on|off: Enable/Disable link status check "
5502                     "when starting/stopping a port",
5503         .data = NULL,
5504         .tokens = {
5505                 (void *)&cmd_setlinkcheck_set,
5506                 (void *)&cmd_setlinkcheck_link_check,
5507                 (void *)&cmd_setlinkcheck_mode,
5508                 NULL,
5509         },
5510 };
5511
5512 /* *** SET NIC BYPASS MODE *** */
5513 struct cmd_set_bypass_mode_result {
5514         cmdline_fixed_string_t set;
5515         cmdline_fixed_string_t bypass;
5516         cmdline_fixed_string_t mode;
5517         cmdline_fixed_string_t value;
5518         portid_t port_id;
5519 };
5520
5521 static void
5522 cmd_set_bypass_mode_parsed(void *parsed_result,
5523                 __rte_unused struct cmdline *cl,
5524                 __rte_unused void *data)
5525 {
5526         struct cmd_set_bypass_mode_result *res = parsed_result;
5527         portid_t port_id = res->port_id;
5528         int32_t rc = -EINVAL;
5529
5530 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5531         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5532
5533         if (!strcmp(res->value, "bypass"))
5534                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5535         else if (!strcmp(res->value, "isolate"))
5536                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5537         else
5538                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5539
5540         /* Set the bypass mode for the relevant port. */
5541         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5542 #endif
5543         if (rc != 0)
5544                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5545 }
5546
5547 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5548         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5549                         set, "set");
5550 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5551         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5552                         bypass, "bypass");
5553 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5554         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5555                         mode, "mode");
5556 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5557         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5558                         value, "normal#bypass#isolate");
5559 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5560         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5561                                 port_id, UINT16);
5562
5563 cmdline_parse_inst_t cmd_set_bypass_mode = {
5564         .f = cmd_set_bypass_mode_parsed,
5565         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5566                     "Set the NIC bypass mode for port_id",
5567         .data = NULL,
5568         .tokens = {
5569                 (void *)&cmd_setbypass_mode_set,
5570                 (void *)&cmd_setbypass_mode_bypass,
5571                 (void *)&cmd_setbypass_mode_mode,
5572                 (void *)&cmd_setbypass_mode_value,
5573                 (void *)&cmd_setbypass_mode_port,
5574                 NULL,
5575         },
5576 };
5577
5578 /* *** SET NIC BYPASS EVENT *** */
5579 struct cmd_set_bypass_event_result {
5580         cmdline_fixed_string_t set;
5581         cmdline_fixed_string_t bypass;
5582         cmdline_fixed_string_t event;
5583         cmdline_fixed_string_t event_value;
5584         cmdline_fixed_string_t mode;
5585         cmdline_fixed_string_t mode_value;
5586         portid_t port_id;
5587 };
5588
5589 static void
5590 cmd_set_bypass_event_parsed(void *parsed_result,
5591                 __rte_unused struct cmdline *cl,
5592                 __rte_unused void *data)
5593 {
5594         int32_t rc = -EINVAL;
5595         struct cmd_set_bypass_event_result *res = parsed_result;
5596         portid_t port_id = res->port_id;
5597
5598 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5599         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5600         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5601
5602         if (!strcmp(res->event_value, "timeout"))
5603                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5604         else if (!strcmp(res->event_value, "os_on"))
5605                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5606         else if (!strcmp(res->event_value, "os_off"))
5607                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5608         else if (!strcmp(res->event_value, "power_on"))
5609                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5610         else if (!strcmp(res->event_value, "power_off"))
5611                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5612         else
5613                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5614
5615         if (!strcmp(res->mode_value, "bypass"))
5616                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5617         else if (!strcmp(res->mode_value, "isolate"))
5618                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5619         else
5620                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5621
5622         /* Set the watchdog timeout. */
5623         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5624
5625                 rc = -EINVAL;
5626                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5627                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5628                                                            bypass_timeout);
5629                 }
5630                 if (rc != 0) {
5631                         printf("Failed to set timeout value %u "
5632                         "for port %d, errto code: %d.\n",
5633                         bypass_timeout, port_id, rc);
5634                 }
5635         }
5636
5637         /* Set the bypass event to transition to bypass mode. */
5638         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5639                                               bypass_mode);
5640 #endif
5641
5642         if (rc != 0)
5643                 printf("\t Failed to set bypass event for port = %d.\n",
5644                        port_id);
5645 }
5646
5647 cmdline_parse_token_string_t cmd_setbypass_event_set =
5648         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5649                         set, "set");
5650 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5651         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5652                         bypass, "bypass");
5653 cmdline_parse_token_string_t cmd_setbypass_event_event =
5654         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5655                         event, "event");
5656 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5657         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5658                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5659 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5660         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5661                         mode, "mode");
5662 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5663         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5664                         mode_value, "normal#bypass#isolate");
5665 cmdline_parse_token_num_t cmd_setbypass_event_port =
5666         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5667                                 port_id, UINT16);
5668
5669 cmdline_parse_inst_t cmd_set_bypass_event = {
5670         .f = cmd_set_bypass_event_parsed,
5671         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5672                 "power_off mode normal|bypass|isolate <port_id>: "
5673                 "Set the NIC bypass event mode for port_id",
5674         .data = NULL,
5675         .tokens = {
5676                 (void *)&cmd_setbypass_event_set,
5677                 (void *)&cmd_setbypass_event_bypass,
5678                 (void *)&cmd_setbypass_event_event,
5679                 (void *)&cmd_setbypass_event_event_value,
5680                 (void *)&cmd_setbypass_event_mode,
5681                 (void *)&cmd_setbypass_event_mode_value,
5682                 (void *)&cmd_setbypass_event_port,
5683                 NULL,
5684         },
5685 };
5686
5687
5688 /* *** SET NIC BYPASS TIMEOUT *** */
5689 struct cmd_set_bypass_timeout_result {
5690         cmdline_fixed_string_t set;
5691         cmdline_fixed_string_t bypass;
5692         cmdline_fixed_string_t timeout;
5693         cmdline_fixed_string_t value;
5694 };
5695
5696 static void
5697 cmd_set_bypass_timeout_parsed(void *parsed_result,
5698                 __rte_unused struct cmdline *cl,
5699                 __rte_unused void *data)
5700 {
5701         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5702
5703 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5704         if (!strcmp(res->value, "1.5"))
5705                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5706         else if (!strcmp(res->value, "2"))
5707                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5708         else if (!strcmp(res->value, "3"))
5709                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5710         else if (!strcmp(res->value, "4"))
5711                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5712         else if (!strcmp(res->value, "8"))
5713                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5714         else if (!strcmp(res->value, "16"))
5715                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5716         else if (!strcmp(res->value, "32"))
5717                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5718         else
5719                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5720 #endif
5721 }
5722
5723 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5724         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5725                         set, "set");
5726 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5727         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5728                         bypass, "bypass");
5729 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5730         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5731                         timeout, "timeout");
5732 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5733         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5734                         value, "0#1.5#2#3#4#8#16#32");
5735
5736 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5737         .f = cmd_set_bypass_timeout_parsed,
5738         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5739                 "Set the NIC bypass watchdog timeout in seconds",
5740         .data = NULL,
5741         .tokens = {
5742                 (void *)&cmd_setbypass_timeout_set,
5743                 (void *)&cmd_setbypass_timeout_bypass,
5744                 (void *)&cmd_setbypass_timeout_timeout,
5745                 (void *)&cmd_setbypass_timeout_value,
5746                 NULL,
5747         },
5748 };
5749
5750 /* *** SHOW NIC BYPASS MODE *** */
5751 struct cmd_show_bypass_config_result {
5752         cmdline_fixed_string_t show;
5753         cmdline_fixed_string_t bypass;
5754         cmdline_fixed_string_t config;
5755         portid_t port_id;
5756 };
5757
5758 static void
5759 cmd_show_bypass_config_parsed(void *parsed_result,
5760                 __rte_unused struct cmdline *cl,
5761                 __rte_unused void *data)
5762 {
5763         struct cmd_show_bypass_config_result *res = parsed_result;
5764         portid_t port_id = res->port_id;
5765         int rc = -EINVAL;
5766 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
5767         uint32_t event_mode;
5768         uint32_t bypass_mode;
5769         uint32_t timeout = bypass_timeout;
5770         unsigned int i;
5771
5772         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5773                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5774         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5775                 {"UNKNOWN", "normal", "bypass", "isolate"};
5776         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5777                 "NONE",
5778                 "OS/board on",
5779                 "power supply on",
5780                 "OS/board off",
5781                 "power supply off",
5782                 "timeout"};
5783
5784         /* Display the bypass mode.*/
5785         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5786                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5787                 return;
5788         }
5789         else {
5790                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5791                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5792
5793                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5794         }
5795
5796         /* Display the bypass timeout.*/
5797         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5798                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5799
5800         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5801
5802         /* Display the bypass events and associated modes. */
5803         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5804
5805                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5806                         printf("\tFailed to get bypass mode for event = %s\n",
5807                                 events[i]);
5808                 } else {
5809                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5810                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5811
5812                         printf("\tbypass event: %-16s = %s\n", events[i],
5813                                 modes[event_mode]);
5814                 }
5815         }
5816 #endif
5817         if (rc != 0)
5818                 printf("\tFailed to get bypass configuration for port = %d\n",
5819                        port_id);
5820 }
5821
5822 cmdline_parse_token_string_t cmd_showbypass_config_show =
5823         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5824                         show, "show");
5825 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5826         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5827                         bypass, "bypass");
5828 cmdline_parse_token_string_t cmd_showbypass_config_config =
5829         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5830                         config, "config");
5831 cmdline_parse_token_num_t cmd_showbypass_config_port =
5832         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5833                                 port_id, UINT16);
5834
5835 cmdline_parse_inst_t cmd_show_bypass_config = {
5836         .f = cmd_show_bypass_config_parsed,
5837         .help_str = "show bypass config <port_id>: "
5838                     "Show the NIC bypass config for port_id",
5839         .data = NULL,
5840         .tokens = {
5841                 (void *)&cmd_showbypass_config_show,
5842                 (void *)&cmd_showbypass_config_bypass,
5843                 (void *)&cmd_showbypass_config_config,
5844                 (void *)&cmd_showbypass_config_port,
5845                 NULL,
5846         },
5847 };
5848
5849 #ifdef RTE_LIBRTE_PMD_BOND
5850 /* *** SET BONDING MODE *** */
5851 struct cmd_set_bonding_mode_result {
5852         cmdline_fixed_string_t set;
5853         cmdline_fixed_string_t bonding;
5854         cmdline_fixed_string_t mode;
5855         uint8_t value;
5856         portid_t port_id;
5857 };
5858
5859 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5860                 __rte_unused  struct cmdline *cl,
5861                 __rte_unused void *data)
5862 {
5863         struct cmd_set_bonding_mode_result *res = parsed_result;
5864         portid_t port_id = res->port_id;
5865
5866         /* Set the bonding mode for the relevant port. */
5867         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5868                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5869 }
5870
5871 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5872 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5873                 set, "set");
5874 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5875 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5876                 bonding, "bonding");
5877 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5878 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5879                 mode, "mode");
5880 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5881 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5882                 value, UINT8);
5883 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5884 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5885                 port_id, UINT16);
5886
5887 cmdline_parse_inst_t cmd_set_bonding_mode = {
5888                 .f = cmd_set_bonding_mode_parsed,
5889                 .help_str = "set bonding mode <mode_value> <port_id>: "
5890                         "Set the bonding mode for port_id",
5891                 .data = NULL,
5892                 .tokens = {
5893                                 (void *) &cmd_setbonding_mode_set,
5894                                 (void *) &cmd_setbonding_mode_bonding,
5895                                 (void *) &cmd_setbonding_mode_mode,
5896                                 (void *) &cmd_setbonding_mode_value,
5897                                 (void *) &cmd_setbonding_mode_port,
5898                                 NULL
5899                 }
5900 };
5901
5902 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5903 struct cmd_set_bonding_lacp_dedicated_queues_result {
5904         cmdline_fixed_string_t set;
5905         cmdline_fixed_string_t bonding;
5906         cmdline_fixed_string_t lacp;
5907         cmdline_fixed_string_t dedicated_queues;
5908         portid_t port_id;
5909         cmdline_fixed_string_t mode;
5910 };
5911
5912 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5913                 __rte_unused  struct cmdline *cl,
5914                 __rte_unused void *data)
5915 {
5916         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5917         portid_t port_id = res->port_id;
5918         struct rte_port *port;
5919
5920         port = &ports[port_id];
5921
5922         /** Check if the port is not started **/
5923         if (port->port_status != RTE_PORT_STOPPED) {
5924                 printf("Please stop port %d first\n", port_id);
5925                 return;
5926         }
5927
5928         if (!strcmp(res->mode, "enable")) {
5929                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5930                         printf("Dedicate queues for LACP control packets"
5931                                         " enabled\n");
5932                 else
5933                         printf("Enabling dedicate queues for LACP control "
5934                                         "packets on port %d failed\n", port_id);
5935         } else if (!strcmp(res->mode, "disable")) {
5936                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5937                         printf("Dedicated queues for LACP control packets "
5938                                         "disabled\n");
5939                 else
5940                         printf("Disabling dedicated queues for LACP control "
5941                                         "traffic on port %d failed\n", port_id);
5942         }
5943 }
5944
5945 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5946 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5947                 set, "set");
5948 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5949 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5950                 bonding, "bonding");
5951 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5952 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5953                 lacp, "lacp");
5954 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5955 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5956                 dedicated_queues, "dedicated_queues");
5957 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5958 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5959                 port_id, UINT16);
5960 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5961 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5962                 mode, "enable#disable");
5963
5964 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5965                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5966                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5967                         "enable|disable: "
5968                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5969                 .data = NULL,
5970                 .tokens = {
5971                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5972                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5973                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5974                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5975                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5976                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5977                         NULL
5978                 }
5979 };
5980
5981 /* *** SET BALANCE XMIT POLICY *** */
5982 struct cmd_set_bonding_balance_xmit_policy_result {
5983         cmdline_fixed_string_t set;
5984         cmdline_fixed_string_t bonding;
5985         cmdline_fixed_string_t balance_xmit_policy;
5986         portid_t port_id;
5987         cmdline_fixed_string_t policy;
5988 };
5989
5990 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5991                 __rte_unused  struct cmdline *cl,
5992                 __rte_unused void *data)
5993 {
5994         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5995         portid_t port_id = res->port_id;
5996         uint8_t policy;
5997
5998         if (!strcmp(res->policy, "l2")) {
5999                 policy = BALANCE_XMIT_POLICY_LAYER2;
6000         } else if (!strcmp(res->policy, "l23")) {
6001                 policy = BALANCE_XMIT_POLICY_LAYER23;
6002         } else if (!strcmp(res->policy, "l34")) {
6003                 policy = BALANCE_XMIT_POLICY_LAYER34;
6004         } else {
6005                 printf("\t Invalid xmit policy selection");
6006                 return;
6007         }
6008
6009         /* Set the bonding mode for the relevant port. */
6010         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
6011                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
6012                                 port_id);
6013         }
6014 }
6015
6016 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
6017 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6018                 set, "set");
6019 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6020 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6021                 bonding, "bonding");
6022 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6023 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6024                 balance_xmit_policy, "balance_xmit_policy");
6025 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6026 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6027                 port_id, UINT16);
6028 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6029 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6030                 policy, "l2#l23#l34");
6031
6032 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6033                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6034                 .help_str = "set bonding balance_xmit_policy <port_id> "
6035                         "l2|l23|l34: "
6036                         "Set the bonding balance_xmit_policy for port_id",
6037                 .data = NULL,
6038                 .tokens = {
6039                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6040                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6041                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6042                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6043                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6044                                 NULL
6045                 }
6046 };
6047
6048 /* *** SHOW NIC BONDING CONFIGURATION *** */
6049 struct cmd_show_bonding_config_result {
6050         cmdline_fixed_string_t show;
6051         cmdline_fixed_string_t bonding;
6052         cmdline_fixed_string_t config;
6053         portid_t port_id;
6054 };
6055
6056 static void cmd_show_bonding_config_parsed(void *parsed_result,
6057                 __rte_unused  struct cmdline *cl,
6058                 __rte_unused void *data)
6059 {
6060         struct cmd_show_bonding_config_result *res = parsed_result;
6061         int bonding_mode, agg_mode;
6062         portid_t slaves[RTE_MAX_ETHPORTS];
6063         int num_slaves, num_active_slaves;
6064         int primary_id;
6065         int i;
6066         portid_t port_id = res->port_id;
6067
6068         /* Display the bonding mode.*/
6069         bonding_mode = rte_eth_bond_mode_get(port_id);
6070         if (bonding_mode < 0) {
6071                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6072                 return;
6073         } else
6074                 printf("\tBonding mode: %d\n", bonding_mode);
6075
6076         if (bonding_mode == BONDING_MODE_BALANCE) {
6077                 int balance_xmit_policy;
6078
6079                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6080                 if (balance_xmit_policy < 0) {
6081                         printf("\tFailed to get balance xmit policy for port = %d\n",
6082                                         port_id);
6083                         return;
6084                 } else {
6085                         printf("\tBalance Xmit Policy: ");
6086
6087                         switch (balance_xmit_policy) {
6088                         case BALANCE_XMIT_POLICY_LAYER2:
6089                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6090                                 break;
6091                         case BALANCE_XMIT_POLICY_LAYER23:
6092                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6093                                 break;
6094                         case BALANCE_XMIT_POLICY_LAYER34:
6095                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6096                                 break;
6097                         }
6098                         printf("\n");
6099                 }
6100         }
6101
6102         if (bonding_mode == BONDING_MODE_8023AD) {
6103                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6104                 printf("\tIEEE802.3AD Aggregator Mode: ");
6105                 switch (agg_mode) {
6106                 case AGG_BANDWIDTH:
6107                         printf("bandwidth");
6108                         break;
6109                 case AGG_STABLE:
6110                         printf("stable");
6111                         break;
6112                 case AGG_COUNT:
6113                         printf("count");
6114                         break;
6115                 }
6116                 printf("\n");
6117         }
6118
6119         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6120
6121         if (num_slaves < 0) {
6122                 printf("\tFailed to get slave list for port = %d\n", port_id);
6123                 return;
6124         }
6125         if (num_slaves > 0) {
6126                 printf("\tSlaves (%d): [", num_slaves);
6127                 for (i = 0; i < num_slaves - 1; i++)
6128                         printf("%d ", slaves[i]);
6129
6130                 printf("%d]\n", slaves[num_slaves - 1]);
6131         } else {
6132                 printf("\tSlaves: []\n");
6133
6134         }
6135
6136         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6137                         RTE_MAX_ETHPORTS);
6138
6139         if (num_active_slaves < 0) {
6140                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6141                 return;
6142         }
6143         if (num_active_slaves > 0) {
6144                 printf("\tActive Slaves (%d): [", num_active_slaves);
6145                 for (i = 0; i < num_active_slaves - 1; i++)
6146                         printf("%d ", slaves[i]);
6147
6148                 printf("%d]\n", slaves[num_active_slaves - 1]);
6149
6150         } else {
6151                 printf("\tActive Slaves: []\n");
6152
6153         }
6154
6155         primary_id = rte_eth_bond_primary_get(port_id);
6156         if (primary_id < 0) {
6157                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6158                 return;
6159         } else
6160                 printf("\tPrimary: [%d]\n", primary_id);
6161
6162 }
6163
6164 cmdline_parse_token_string_t cmd_showbonding_config_show =
6165 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6166                 show, "show");
6167 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6168 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6169                 bonding, "bonding");
6170 cmdline_parse_token_string_t cmd_showbonding_config_config =
6171 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6172                 config, "config");
6173 cmdline_parse_token_num_t cmd_showbonding_config_port =
6174 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6175                 port_id, UINT16);
6176
6177 cmdline_parse_inst_t cmd_show_bonding_config = {
6178                 .f = cmd_show_bonding_config_parsed,
6179                 .help_str = "show bonding config <port_id>: "
6180                         "Show the bonding config for port_id",
6181                 .data = NULL,
6182                 .tokens = {
6183                                 (void *)&cmd_showbonding_config_show,
6184                                 (void *)&cmd_showbonding_config_bonding,
6185                                 (void *)&cmd_showbonding_config_config,
6186                                 (void *)&cmd_showbonding_config_port,
6187                                 NULL
6188                 }
6189 };
6190
6191 /* *** SET BONDING PRIMARY *** */
6192 struct cmd_set_bonding_primary_result {
6193         cmdline_fixed_string_t set;
6194         cmdline_fixed_string_t bonding;
6195         cmdline_fixed_string_t primary;
6196         portid_t slave_id;
6197         portid_t port_id;
6198 };
6199
6200 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6201                 __rte_unused  struct cmdline *cl,
6202                 __rte_unused void *data)
6203 {
6204         struct cmd_set_bonding_primary_result *res = parsed_result;
6205         portid_t master_port_id = res->port_id;
6206         portid_t slave_port_id = res->slave_id;
6207
6208         /* Set the primary slave for a bonded device. */
6209         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6210                 printf("\t Failed to set primary slave for port = %d.\n",
6211                                 master_port_id);
6212                 return;
6213         }
6214         init_port_config();
6215 }
6216
6217 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6218 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6219                 set, "set");
6220 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6221 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6222                 bonding, "bonding");
6223 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6224 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6225                 primary, "primary");
6226 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6227 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6228                 slave_id, UINT16);
6229 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6230 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6231                 port_id, UINT16);
6232
6233 cmdline_parse_inst_t cmd_set_bonding_primary = {
6234                 .f = cmd_set_bonding_primary_parsed,
6235                 .help_str = "set bonding primary <slave_id> <port_id>: "
6236                         "Set the primary slave for port_id",
6237                 .data = NULL,
6238                 .tokens = {
6239                                 (void *)&cmd_setbonding_primary_set,
6240                                 (void *)&cmd_setbonding_primary_bonding,
6241                                 (void *)&cmd_setbonding_primary_primary,
6242                                 (void *)&cmd_setbonding_primary_slave,
6243                                 (void *)&cmd_setbonding_primary_port,
6244                                 NULL
6245                 }
6246 };
6247
6248 /* *** ADD SLAVE *** */
6249 struct cmd_add_bonding_slave_result {
6250         cmdline_fixed_string_t add;
6251         cmdline_fixed_string_t bonding;
6252         cmdline_fixed_string_t slave;
6253         portid_t slave_id;
6254         portid_t port_id;
6255 };
6256
6257 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6258                 __rte_unused  struct cmdline *cl,
6259                 __rte_unused void *data)
6260 {
6261         struct cmd_add_bonding_slave_result *res = parsed_result;
6262         portid_t master_port_id = res->port_id;
6263         portid_t slave_port_id = res->slave_id;
6264
6265         /* add the slave for a bonded device. */
6266         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6267                 printf("\t Failed to add slave %d to master port = %d.\n",
6268                                 slave_port_id, master_port_id);
6269                 return;
6270         }
6271         init_port_config();
6272         set_port_slave_flag(slave_port_id);
6273 }
6274
6275 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6276 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6277                 add, "add");
6278 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6279 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6280                 bonding, "bonding");
6281 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6282 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6283                 slave, "slave");
6284 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6285 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6286                 slave_id, UINT16);
6287 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6288 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6289                 port_id, UINT16);
6290
6291 cmdline_parse_inst_t cmd_add_bonding_slave = {
6292                 .f = cmd_add_bonding_slave_parsed,
6293                 .help_str = "add bonding slave <slave_id> <port_id>: "
6294                         "Add a slave device to a bonded device",
6295                 .data = NULL,
6296                 .tokens = {
6297                                 (void *)&cmd_addbonding_slave_add,
6298                                 (void *)&cmd_addbonding_slave_bonding,
6299                                 (void *)&cmd_addbonding_slave_slave,
6300                                 (void *)&cmd_addbonding_slave_slaveid,
6301                                 (void *)&cmd_addbonding_slave_port,
6302                                 NULL
6303                 }
6304 };
6305
6306 /* *** REMOVE SLAVE *** */
6307 struct cmd_remove_bonding_slave_result {
6308         cmdline_fixed_string_t remove;
6309         cmdline_fixed_string_t bonding;
6310         cmdline_fixed_string_t slave;
6311         portid_t slave_id;
6312         portid_t port_id;
6313 };
6314
6315 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6316                 __rte_unused  struct cmdline *cl,
6317                 __rte_unused void *data)
6318 {
6319         struct cmd_remove_bonding_slave_result *res = parsed_result;
6320         portid_t master_port_id = res->port_id;
6321         portid_t slave_port_id = res->slave_id;
6322
6323         /* remove the slave from a bonded device. */
6324         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6325                 printf("\t Failed to remove slave %d from master port = %d.\n",
6326                                 slave_port_id, master_port_id);
6327                 return;
6328         }
6329         init_port_config();
6330         clear_port_slave_flag(slave_port_id);
6331 }
6332
6333 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6334                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6335                                 remove, "remove");
6336 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6337                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6338                                 bonding, "bonding");
6339 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6340                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6341                                 slave, "slave");
6342 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6343                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6344                                 slave_id, UINT16);
6345 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6346                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6347                                 port_id, UINT16);
6348
6349 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6350                 .f = cmd_remove_bonding_slave_parsed,
6351                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6352                         "Remove a slave device from a bonded device",
6353                 .data = NULL,
6354                 .tokens = {
6355                                 (void *)&cmd_removebonding_slave_remove,
6356                                 (void *)&cmd_removebonding_slave_bonding,
6357                                 (void *)&cmd_removebonding_slave_slave,
6358                                 (void *)&cmd_removebonding_slave_slaveid,
6359                                 (void *)&cmd_removebonding_slave_port,
6360                                 NULL
6361                 }
6362 };
6363
6364 /* *** CREATE BONDED DEVICE *** */
6365 struct cmd_create_bonded_device_result {
6366         cmdline_fixed_string_t create;
6367         cmdline_fixed_string_t bonded;
6368         cmdline_fixed_string_t device;
6369         uint8_t mode;
6370         uint8_t socket;
6371 };
6372
6373 static int bond_dev_num = 0;
6374
6375 static void cmd_create_bonded_device_parsed(void *parsed_result,
6376                 __rte_unused  struct cmdline *cl,
6377                 __rte_unused void *data)
6378 {
6379         struct cmd_create_bonded_device_result *res = parsed_result;
6380         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6381         int port_id;
6382         int ret;
6383
6384         if (test_done == 0) {
6385                 printf("Please stop forwarding first\n");
6386                 return;
6387         }
6388
6389         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6390                         bond_dev_num++);
6391
6392         /* Create a new bonded device. */
6393         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6394         if (port_id < 0) {
6395                 printf("\t Failed to create bonded device.\n");
6396                 return;
6397         } else {
6398                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6399                                 port_id);
6400
6401                 /* Update number of ports */
6402                 nb_ports = rte_eth_dev_count_avail();
6403                 reconfig(port_id, res->socket);
6404                 ret = rte_eth_promiscuous_enable(port_id);
6405                 if (ret != 0)
6406                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6407                                 port_id, rte_strerror(-ret));
6408
6409                 ports[port_id].need_setup = 0;
6410                 ports[port_id].port_status = RTE_PORT_STOPPED;
6411         }
6412
6413 }
6414
6415 cmdline_parse_token_string_t cmd_createbonded_device_create =
6416                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6417                                 create, "create");
6418 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6419                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6420                                 bonded, "bonded");
6421 cmdline_parse_token_string_t cmd_createbonded_device_device =
6422                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6423                                 device, "device");
6424 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6425                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6426                                 mode, UINT8);
6427 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6428                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6429                                 socket, UINT8);
6430
6431 cmdline_parse_inst_t cmd_create_bonded_device = {
6432                 .f = cmd_create_bonded_device_parsed,
6433                 .help_str = "create bonded device <mode> <socket>: "
6434                         "Create a new bonded device with specific bonding mode and socket",
6435                 .data = NULL,
6436                 .tokens = {
6437                                 (void *)&cmd_createbonded_device_create,
6438                                 (void *)&cmd_createbonded_device_bonded,
6439                                 (void *)&cmd_createbonded_device_device,
6440                                 (void *)&cmd_createbonded_device_mode,
6441                                 (void *)&cmd_createbonded_device_socket,
6442                                 NULL
6443                 }
6444 };
6445
6446 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6447 struct cmd_set_bond_mac_addr_result {
6448         cmdline_fixed_string_t set;
6449         cmdline_fixed_string_t bonding;
6450         cmdline_fixed_string_t mac_addr;
6451         uint16_t port_num;
6452         struct rte_ether_addr address;
6453 };
6454
6455 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6456                 __rte_unused  struct cmdline *cl,
6457                 __rte_unused void *data)
6458 {
6459         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6460         int ret;
6461
6462         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6463                 return;
6464
6465         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6466
6467         /* check the return value and print it if is < 0 */
6468         if (ret < 0)
6469                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6470 }
6471
6472 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6473                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6474 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6475                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6476                                 "bonding");
6477 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6478                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6479                                 "mac_addr");
6480 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6481                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6482                                 port_num, UINT16);
6483 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6484                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6485
6486 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6487                 .f = cmd_set_bond_mac_addr_parsed,
6488                 .data = (void *) 0,
6489                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6490                 .tokens = {
6491                                 (void *)&cmd_set_bond_mac_addr_set,
6492                                 (void *)&cmd_set_bond_mac_addr_bonding,
6493                                 (void *)&cmd_set_bond_mac_addr_mac,
6494                                 (void *)&cmd_set_bond_mac_addr_portnum,
6495                                 (void *)&cmd_set_bond_mac_addr_addr,
6496                                 NULL
6497                 }
6498 };
6499
6500
6501 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6502 struct cmd_set_bond_mon_period_result {
6503         cmdline_fixed_string_t set;
6504         cmdline_fixed_string_t bonding;
6505         cmdline_fixed_string_t mon_period;
6506         uint16_t port_num;
6507         uint32_t period_ms;
6508 };
6509
6510 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6511                 __rte_unused  struct cmdline *cl,
6512                 __rte_unused void *data)
6513 {
6514         struct cmd_set_bond_mon_period_result *res = parsed_result;
6515         int ret;
6516
6517         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
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_mon_period_set =
6525                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6526                                 set, "set");
6527 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6528                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6529                                 bonding, "bonding");
6530 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6531                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6532                                 mon_period,     "mon_period");
6533 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6534                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6535                                 port_num, UINT16);
6536 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6537                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6538                                 period_ms, UINT32);
6539
6540 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6541                 .f = cmd_set_bond_mon_period_parsed,
6542                 .data = (void *) 0,
6543                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6544                 .tokens = {
6545                                 (void *)&cmd_set_bond_mon_period_set,
6546                                 (void *)&cmd_set_bond_mon_period_bonding,
6547                                 (void *)&cmd_set_bond_mon_period_mon_period,
6548                                 (void *)&cmd_set_bond_mon_period_portnum,
6549                                 (void *)&cmd_set_bond_mon_period_period_ms,
6550                                 NULL
6551                 }
6552 };
6553
6554
6555
6556 struct cmd_set_bonding_agg_mode_policy_result {
6557         cmdline_fixed_string_t set;
6558         cmdline_fixed_string_t bonding;
6559         cmdline_fixed_string_t agg_mode;
6560         uint16_t port_num;
6561         cmdline_fixed_string_t policy;
6562 };
6563
6564
6565 static void
6566 cmd_set_bonding_agg_mode(void *parsed_result,
6567                 __rte_unused struct cmdline *cl,
6568                 __rte_unused void *data)
6569 {
6570         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6571         uint8_t policy = AGG_BANDWIDTH;
6572
6573         if (!strcmp(res->policy, "bandwidth"))
6574                 policy = AGG_BANDWIDTH;
6575         else if (!strcmp(res->policy, "stable"))
6576                 policy = AGG_STABLE;
6577         else if (!strcmp(res->policy, "count"))
6578                 policy = AGG_COUNT;
6579
6580         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6581 }
6582
6583
6584 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6585         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6586                                 set, "set");
6587 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6588         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6589                                 bonding, "bonding");
6590
6591 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6592         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6593                                 agg_mode, "agg_mode");
6594
6595 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6596         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6597                                 port_num, UINT16);
6598
6599 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6600         TOKEN_STRING_INITIALIZER(
6601                         struct cmd_set_bonding_balance_xmit_policy_result,
6602                 policy, "stable#bandwidth#count");
6603
6604 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6605         .f = cmd_set_bonding_agg_mode,
6606         .data = (void *) 0,
6607         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6608         .tokens = {
6609                         (void *)&cmd_set_bonding_agg_mode_set,
6610                         (void *)&cmd_set_bonding_agg_mode_bonding,
6611                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6612                         (void *)&cmd_set_bonding_agg_mode_portnum,
6613                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6614                         NULL
6615                 }
6616 };
6617
6618
6619 #endif /* RTE_LIBRTE_PMD_BOND */
6620
6621 /* *** SET FORWARDING MODE *** */
6622 struct cmd_set_fwd_mode_result {
6623         cmdline_fixed_string_t set;
6624         cmdline_fixed_string_t fwd;
6625         cmdline_fixed_string_t mode;
6626 };
6627
6628 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6629                                     __rte_unused struct cmdline *cl,
6630                                     __rte_unused void *data)
6631 {
6632         struct cmd_set_fwd_mode_result *res = parsed_result;
6633
6634         retry_enabled = 0;
6635         set_pkt_forwarding_mode(res->mode);
6636 }
6637
6638 cmdline_parse_token_string_t cmd_setfwd_set =
6639         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6640 cmdline_parse_token_string_t cmd_setfwd_fwd =
6641         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6642 cmdline_parse_token_string_t cmd_setfwd_mode =
6643         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6644                 "" /* defined at init */);
6645
6646 cmdline_parse_inst_t cmd_set_fwd_mode = {
6647         .f = cmd_set_fwd_mode_parsed,
6648         .data = NULL,
6649         .help_str = NULL, /* defined at init */
6650         .tokens = {
6651                 (void *)&cmd_setfwd_set,
6652                 (void *)&cmd_setfwd_fwd,
6653                 (void *)&cmd_setfwd_mode,
6654                 NULL,
6655         },
6656 };
6657
6658 static void cmd_set_fwd_mode_init(void)
6659 {
6660         char *modes, *c;
6661         static char token[128];
6662         static char help[256];
6663         cmdline_parse_token_string_t *token_struct;
6664
6665         modes = list_pkt_forwarding_modes();
6666         snprintf(help, sizeof(help), "set fwd %s: "
6667                 "Set packet forwarding mode", modes);
6668         cmd_set_fwd_mode.help_str = help;
6669
6670         /* string token separator is # */
6671         for (c = token; *modes != '\0'; modes++)
6672                 if (*modes == '|')
6673                         *c++ = '#';
6674                 else
6675                         *c++ = *modes;
6676         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6677         token_struct->string_data.str = token;
6678 }
6679
6680 /* *** SET RETRY FORWARDING MODE *** */
6681 struct cmd_set_fwd_retry_mode_result {
6682         cmdline_fixed_string_t set;
6683         cmdline_fixed_string_t fwd;
6684         cmdline_fixed_string_t mode;
6685         cmdline_fixed_string_t retry;
6686 };
6687
6688 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6689                             __rte_unused struct cmdline *cl,
6690                             __rte_unused void *data)
6691 {
6692         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6693
6694         retry_enabled = 1;
6695         set_pkt_forwarding_mode(res->mode);
6696 }
6697
6698 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6699         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6700                         set, "set");
6701 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6702         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6703                         fwd, "fwd");
6704 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6705         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6706                         mode,
6707                 "" /* defined at init */);
6708 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6709         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6710                         retry, "retry");
6711
6712 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6713         .f = cmd_set_fwd_retry_mode_parsed,
6714         .data = NULL,
6715         .help_str = NULL, /* defined at init */
6716         .tokens = {
6717                 (void *)&cmd_setfwd_retry_set,
6718                 (void *)&cmd_setfwd_retry_fwd,
6719                 (void *)&cmd_setfwd_retry_mode,
6720                 (void *)&cmd_setfwd_retry_retry,
6721                 NULL,
6722         },
6723 };
6724
6725 static void cmd_set_fwd_retry_mode_init(void)
6726 {
6727         char *modes, *c;
6728         static char token[128];
6729         static char help[256];
6730         cmdline_parse_token_string_t *token_struct;
6731
6732         modes = list_pkt_forwarding_retry_modes();
6733         snprintf(help, sizeof(help), "set fwd %s retry: "
6734                 "Set packet forwarding mode with retry", modes);
6735         cmd_set_fwd_retry_mode.help_str = help;
6736
6737         /* string token separator is # */
6738         for (c = token; *modes != '\0'; modes++)
6739                 if (*modes == '|')
6740                         *c++ = '#';
6741                 else
6742                         *c++ = *modes;
6743         token_struct = (cmdline_parse_token_string_t *)
6744                 cmd_set_fwd_retry_mode.tokens[2];
6745         token_struct->string_data.str = token;
6746 }
6747
6748 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6749 struct cmd_set_burst_tx_retry_result {
6750         cmdline_fixed_string_t set;
6751         cmdline_fixed_string_t burst;
6752         cmdline_fixed_string_t tx;
6753         cmdline_fixed_string_t delay;
6754         uint32_t time;
6755         cmdline_fixed_string_t retry;
6756         uint32_t retry_num;
6757 };
6758
6759 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6760                                         __rte_unused struct cmdline *cl,
6761                                         __rte_unused void *data)
6762 {
6763         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6764
6765         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6766                 && !strcmp(res->tx, "tx")) {
6767                 if (!strcmp(res->delay, "delay"))
6768                         burst_tx_delay_time = res->time;
6769                 if (!strcmp(res->retry, "retry"))
6770                         burst_tx_retry_num = res->retry_num;
6771         }
6772
6773 }
6774
6775 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6776         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6777 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6778         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6779                                  "burst");
6780 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6781         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6782 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6783         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6784 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6785         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6786 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6787         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6788 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6789         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6790
6791 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6792         .f = cmd_set_burst_tx_retry_parsed,
6793         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6794         .tokens = {
6795                 (void *)&cmd_set_burst_tx_retry_set,
6796                 (void *)&cmd_set_burst_tx_retry_burst,
6797                 (void *)&cmd_set_burst_tx_retry_tx,
6798                 (void *)&cmd_set_burst_tx_retry_delay,
6799                 (void *)&cmd_set_burst_tx_retry_time,
6800                 (void *)&cmd_set_burst_tx_retry_retry,
6801                 (void *)&cmd_set_burst_tx_retry_retry_num,
6802                 NULL,
6803         },
6804 };
6805
6806 /* *** SET PROMISC MODE *** */
6807 struct cmd_set_promisc_mode_result {
6808         cmdline_fixed_string_t set;
6809         cmdline_fixed_string_t promisc;
6810         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6811         uint16_t port_num;               /* valid if "allports" argument == 0 */
6812         cmdline_fixed_string_t mode;
6813 };
6814
6815 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6816                                         __rte_unused struct cmdline *cl,
6817                                         void *allports)
6818 {
6819         struct cmd_set_promisc_mode_result *res = parsed_result;
6820         int enable;
6821         portid_t i;
6822
6823         if (!strcmp(res->mode, "on"))
6824                 enable = 1;
6825         else
6826                 enable = 0;
6827
6828         /* all ports */
6829         if (allports) {
6830                 RTE_ETH_FOREACH_DEV(i)
6831                         eth_set_promisc_mode(i, enable);
6832         } else {
6833                 eth_set_promisc_mode(res->port_num, enable);
6834         }
6835 }
6836
6837 cmdline_parse_token_string_t cmd_setpromisc_set =
6838         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6839 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6840         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6841                                  "promisc");
6842 cmdline_parse_token_string_t cmd_setpromisc_portall =
6843         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6844                                  "all");
6845 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6846         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6847                               UINT16);
6848 cmdline_parse_token_string_t cmd_setpromisc_mode =
6849         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6850                                  "on#off");
6851
6852 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6853         .f = cmd_set_promisc_mode_parsed,
6854         .data = (void *)1,
6855         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6856         .tokens = {
6857                 (void *)&cmd_setpromisc_set,
6858                 (void *)&cmd_setpromisc_promisc,
6859                 (void *)&cmd_setpromisc_portall,
6860                 (void *)&cmd_setpromisc_mode,
6861                 NULL,
6862         },
6863 };
6864
6865 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6866         .f = cmd_set_promisc_mode_parsed,
6867         .data = (void *)0,
6868         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6869         .tokens = {
6870                 (void *)&cmd_setpromisc_set,
6871                 (void *)&cmd_setpromisc_promisc,
6872                 (void *)&cmd_setpromisc_portnum,
6873                 (void *)&cmd_setpromisc_mode,
6874                 NULL,
6875         },
6876 };
6877
6878 /* *** SET ALLMULTI MODE *** */
6879 struct cmd_set_allmulti_mode_result {
6880         cmdline_fixed_string_t set;
6881         cmdline_fixed_string_t allmulti;
6882         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6883         uint16_t port_num;               /* valid if "allports" argument == 0 */
6884         cmdline_fixed_string_t mode;
6885 };
6886
6887 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6888                                         __rte_unused struct cmdline *cl,
6889                                         void *allports)
6890 {
6891         struct cmd_set_allmulti_mode_result *res = parsed_result;
6892         int enable;
6893         portid_t i;
6894
6895         if (!strcmp(res->mode, "on"))
6896                 enable = 1;
6897         else
6898                 enable = 0;
6899
6900         /* all ports */
6901         if (allports) {
6902                 RTE_ETH_FOREACH_DEV(i) {
6903                         eth_set_allmulticast_mode(i, enable);
6904                 }
6905         }
6906         else {
6907                 eth_set_allmulticast_mode(res->port_num, enable);
6908         }
6909 }
6910
6911 cmdline_parse_token_string_t cmd_setallmulti_set =
6912         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6913 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6914         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6915                                  "allmulti");
6916 cmdline_parse_token_string_t cmd_setallmulti_portall =
6917         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6918                                  "all");
6919 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6920         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6921                               UINT16);
6922 cmdline_parse_token_string_t cmd_setallmulti_mode =
6923         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6924                                  "on#off");
6925
6926 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6927         .f = cmd_set_allmulti_mode_parsed,
6928         .data = (void *)1,
6929         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6930         .tokens = {
6931                 (void *)&cmd_setallmulti_set,
6932                 (void *)&cmd_setallmulti_allmulti,
6933                 (void *)&cmd_setallmulti_portall,
6934                 (void *)&cmd_setallmulti_mode,
6935                 NULL,
6936         },
6937 };
6938
6939 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6940         .f = cmd_set_allmulti_mode_parsed,
6941         .data = (void *)0,
6942         .help_str = "set allmulti <port_id> on|off: "
6943                 "Set allmulti mode on port_id",
6944         .tokens = {
6945                 (void *)&cmd_setallmulti_set,
6946                 (void *)&cmd_setallmulti_allmulti,
6947                 (void *)&cmd_setallmulti_portnum,
6948                 (void *)&cmd_setallmulti_mode,
6949                 NULL,
6950         },
6951 };
6952
6953 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6954 struct cmd_link_flow_ctrl_set_result {
6955         cmdline_fixed_string_t set;
6956         cmdline_fixed_string_t flow_ctrl;
6957         cmdline_fixed_string_t rx;
6958         cmdline_fixed_string_t rx_lfc_mode;
6959         cmdline_fixed_string_t tx;
6960         cmdline_fixed_string_t tx_lfc_mode;
6961         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6962         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6963         cmdline_fixed_string_t autoneg_str;
6964         cmdline_fixed_string_t autoneg;
6965         cmdline_fixed_string_t hw_str;
6966         uint32_t high_water;
6967         cmdline_fixed_string_t lw_str;
6968         uint32_t low_water;
6969         cmdline_fixed_string_t pt_str;
6970         uint16_t pause_time;
6971         cmdline_fixed_string_t xon_str;
6972         uint16_t send_xon;
6973         portid_t port_id;
6974 };
6975
6976 cmdline_parse_token_string_t cmd_lfc_set_set =
6977         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6978                                 set, "set");
6979 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6980         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6981                                 flow_ctrl, "flow_ctrl");
6982 cmdline_parse_token_string_t cmd_lfc_set_rx =
6983         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6984                                 rx, "rx");
6985 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6986         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6987                                 rx_lfc_mode, "on#off");
6988 cmdline_parse_token_string_t cmd_lfc_set_tx =
6989         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6990                                 tx, "tx");
6991 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6992         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6993                                 tx_lfc_mode, "on#off");
6994 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6995         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6996                                 hw_str, "high_water");
6997 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6998         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6999                                 high_water, UINT32);
7000 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
7001         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7002                                 lw_str, "low_water");
7003 cmdline_parse_token_num_t cmd_lfc_set_low_water =
7004         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7005                                 low_water, UINT32);
7006 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
7007         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7008                                 pt_str, "pause_time");
7009 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
7010         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7011                                 pause_time, UINT16);
7012 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
7013         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7014                                 xon_str, "send_xon");
7015 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
7016         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7017                                 send_xon, UINT16);
7018 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7019         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7020                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7021 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7022         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7023                                 mac_ctrl_frame_fwd_mode, "on#off");
7024 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7025         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7026                                 autoneg_str, "autoneg");
7027 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7028         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7029                                 autoneg, "on#off");
7030 cmdline_parse_token_num_t cmd_lfc_set_portid =
7031         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7032                                 port_id, UINT16);
7033
7034 /* forward declaration */
7035 static void
7036 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7037                               void *data);
7038
7039 cmdline_parse_inst_t cmd_link_flow_control_set = {
7040         .f = cmd_link_flow_ctrl_set_parsed,
7041         .data = NULL,
7042         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7043                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7044                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7045         .tokens = {
7046                 (void *)&cmd_lfc_set_set,
7047                 (void *)&cmd_lfc_set_flow_ctrl,
7048                 (void *)&cmd_lfc_set_rx,
7049                 (void *)&cmd_lfc_set_rx_mode,
7050                 (void *)&cmd_lfc_set_tx,
7051                 (void *)&cmd_lfc_set_tx_mode,
7052                 (void *)&cmd_lfc_set_high_water,
7053                 (void *)&cmd_lfc_set_low_water,
7054                 (void *)&cmd_lfc_set_pause_time,
7055                 (void *)&cmd_lfc_set_send_xon,
7056                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7057                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7058                 (void *)&cmd_lfc_set_autoneg_str,
7059                 (void *)&cmd_lfc_set_autoneg,
7060                 (void *)&cmd_lfc_set_portid,
7061                 NULL,
7062         },
7063 };
7064
7065 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7066         .f = cmd_link_flow_ctrl_set_parsed,
7067         .data = (void *)&cmd_link_flow_control_set_rx,
7068         .help_str = "set flow_ctrl rx on|off <port_id>: "
7069                 "Change rx flow control parameter",
7070         .tokens = {
7071                 (void *)&cmd_lfc_set_set,
7072                 (void *)&cmd_lfc_set_flow_ctrl,
7073                 (void *)&cmd_lfc_set_rx,
7074                 (void *)&cmd_lfc_set_rx_mode,
7075                 (void *)&cmd_lfc_set_portid,
7076                 NULL,
7077         },
7078 };
7079
7080 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7081         .f = cmd_link_flow_ctrl_set_parsed,
7082         .data = (void *)&cmd_link_flow_control_set_tx,
7083         .help_str = "set flow_ctrl tx on|off <port_id>: "
7084                 "Change tx flow control parameter",
7085         .tokens = {
7086                 (void *)&cmd_lfc_set_set,
7087                 (void *)&cmd_lfc_set_flow_ctrl,
7088                 (void *)&cmd_lfc_set_tx,
7089                 (void *)&cmd_lfc_set_tx_mode,
7090                 (void *)&cmd_lfc_set_portid,
7091                 NULL,
7092         },
7093 };
7094
7095 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7096         .f = cmd_link_flow_ctrl_set_parsed,
7097         .data = (void *)&cmd_link_flow_control_set_hw,
7098         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7099                 "Change high water flow control parameter",
7100         .tokens = {
7101                 (void *)&cmd_lfc_set_set,
7102                 (void *)&cmd_lfc_set_flow_ctrl,
7103                 (void *)&cmd_lfc_set_high_water_str,
7104                 (void *)&cmd_lfc_set_high_water,
7105                 (void *)&cmd_lfc_set_portid,
7106                 NULL,
7107         },
7108 };
7109
7110 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7111         .f = cmd_link_flow_ctrl_set_parsed,
7112         .data = (void *)&cmd_link_flow_control_set_lw,
7113         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7114                 "Change low water flow control parameter",
7115         .tokens = {
7116                 (void *)&cmd_lfc_set_set,
7117                 (void *)&cmd_lfc_set_flow_ctrl,
7118                 (void *)&cmd_lfc_set_low_water_str,
7119                 (void *)&cmd_lfc_set_low_water,
7120                 (void *)&cmd_lfc_set_portid,
7121                 NULL,
7122         },
7123 };
7124
7125 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7126         .f = cmd_link_flow_ctrl_set_parsed,
7127         .data = (void *)&cmd_link_flow_control_set_pt,
7128         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7129                 "Change pause time flow control parameter",
7130         .tokens = {
7131                 (void *)&cmd_lfc_set_set,
7132                 (void *)&cmd_lfc_set_flow_ctrl,
7133                 (void *)&cmd_lfc_set_pause_time_str,
7134                 (void *)&cmd_lfc_set_pause_time,
7135                 (void *)&cmd_lfc_set_portid,
7136                 NULL,
7137         },
7138 };
7139
7140 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7141         .f = cmd_link_flow_ctrl_set_parsed,
7142         .data = (void *)&cmd_link_flow_control_set_xon,
7143         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7144                 "Change send_xon flow control parameter",
7145         .tokens = {
7146                 (void *)&cmd_lfc_set_set,
7147                 (void *)&cmd_lfc_set_flow_ctrl,
7148                 (void *)&cmd_lfc_set_send_xon_str,
7149                 (void *)&cmd_lfc_set_send_xon,
7150                 (void *)&cmd_lfc_set_portid,
7151                 NULL,
7152         },
7153 };
7154
7155 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7156         .f = cmd_link_flow_ctrl_set_parsed,
7157         .data = (void *)&cmd_link_flow_control_set_macfwd,
7158         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7159                 "Change mac ctrl fwd flow control parameter",
7160         .tokens = {
7161                 (void *)&cmd_lfc_set_set,
7162                 (void *)&cmd_lfc_set_flow_ctrl,
7163                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7164                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7165                 (void *)&cmd_lfc_set_portid,
7166                 NULL,
7167         },
7168 };
7169
7170 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7171         .f = cmd_link_flow_ctrl_set_parsed,
7172         .data = (void *)&cmd_link_flow_control_set_autoneg,
7173         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7174                 "Change autoneg flow control parameter",
7175         .tokens = {
7176                 (void *)&cmd_lfc_set_set,
7177                 (void *)&cmd_lfc_set_flow_ctrl,
7178                 (void *)&cmd_lfc_set_autoneg_str,
7179                 (void *)&cmd_lfc_set_autoneg,
7180                 (void *)&cmd_lfc_set_portid,
7181                 NULL,
7182         },
7183 };
7184
7185 static void
7186 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7187                               __rte_unused struct cmdline *cl,
7188                               void *data)
7189 {
7190         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7191         cmdline_parse_inst_t *cmd = data;
7192         struct rte_eth_fc_conf fc_conf;
7193         int rx_fc_en = 0;
7194         int tx_fc_en = 0;
7195         int ret;
7196
7197         /*
7198          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7199          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7200          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7201          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7202          */
7203         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7204                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7205         };
7206
7207         /* Partial command line, retrieve current configuration */
7208         if (cmd) {
7209                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7210                 if (ret != 0) {
7211                         printf("cannot get current flow ctrl parameters, return"
7212                                "code = %d\n", ret);
7213                         return;
7214                 }
7215
7216                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7217                     (fc_conf.mode == RTE_FC_FULL))
7218                         rx_fc_en = 1;
7219                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7220                     (fc_conf.mode == RTE_FC_FULL))
7221                         tx_fc_en = 1;
7222         }
7223
7224         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7225                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7226
7227         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7228                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7229
7230         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7231
7232         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7233                 fc_conf.high_water = res->high_water;
7234
7235         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7236                 fc_conf.low_water = res->low_water;
7237
7238         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7239                 fc_conf.pause_time = res->pause_time;
7240
7241         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7242                 fc_conf.send_xon = res->send_xon;
7243
7244         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7245                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7246                         fc_conf.mac_ctrl_frame_fwd = 1;
7247                 else
7248                         fc_conf.mac_ctrl_frame_fwd = 0;
7249         }
7250
7251         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7252                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7253
7254         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7255         if (ret != 0)
7256                 printf("bad flow contrl parameter, return code = %d \n", ret);
7257 }
7258
7259 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7260 struct cmd_priority_flow_ctrl_set_result {
7261         cmdline_fixed_string_t set;
7262         cmdline_fixed_string_t pfc_ctrl;
7263         cmdline_fixed_string_t rx;
7264         cmdline_fixed_string_t rx_pfc_mode;
7265         cmdline_fixed_string_t tx;
7266         cmdline_fixed_string_t tx_pfc_mode;
7267         uint32_t high_water;
7268         uint32_t low_water;
7269         uint16_t pause_time;
7270         uint8_t  priority;
7271         portid_t port_id;
7272 };
7273
7274 static void
7275 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7276                        __rte_unused struct cmdline *cl,
7277                        __rte_unused void *data)
7278 {
7279         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7280         struct rte_eth_pfc_conf pfc_conf;
7281         int rx_fc_enable, tx_fc_enable;
7282         int ret;
7283
7284         /*
7285          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7286          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7287          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7288          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7289          */
7290         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7291                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7292         };
7293
7294         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7295         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7296         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7297         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7298         pfc_conf.fc.high_water = res->high_water;
7299         pfc_conf.fc.low_water  = res->low_water;
7300         pfc_conf.fc.pause_time = res->pause_time;
7301         pfc_conf.priority      = res->priority;
7302
7303         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7304         if (ret != 0)
7305                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7306 }
7307
7308 cmdline_parse_token_string_t cmd_pfc_set_set =
7309         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7310                                 set, "set");
7311 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7312         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7313                                 pfc_ctrl, "pfc_ctrl");
7314 cmdline_parse_token_string_t cmd_pfc_set_rx =
7315         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7316                                 rx, "rx");
7317 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7318         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7319                                 rx_pfc_mode, "on#off");
7320 cmdline_parse_token_string_t cmd_pfc_set_tx =
7321         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7322                                 tx, "tx");
7323 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7324         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7325                                 tx_pfc_mode, "on#off");
7326 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7327         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7328                                 high_water, UINT32);
7329 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7330         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7331                                 low_water, UINT32);
7332 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7333         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7334                                 pause_time, UINT16);
7335 cmdline_parse_token_num_t cmd_pfc_set_priority =
7336         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7337                                 priority, UINT8);
7338 cmdline_parse_token_num_t cmd_pfc_set_portid =
7339         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7340                                 port_id, UINT16);
7341
7342 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7343         .f = cmd_priority_flow_ctrl_set_parsed,
7344         .data = NULL,
7345         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7346                 "<pause_time> <priority> <port_id>: "
7347                 "Configure the Ethernet priority flow control",
7348         .tokens = {
7349                 (void *)&cmd_pfc_set_set,
7350                 (void *)&cmd_pfc_set_flow_ctrl,
7351                 (void *)&cmd_pfc_set_rx,
7352                 (void *)&cmd_pfc_set_rx_mode,
7353                 (void *)&cmd_pfc_set_tx,
7354                 (void *)&cmd_pfc_set_tx_mode,
7355                 (void *)&cmd_pfc_set_high_water,
7356                 (void *)&cmd_pfc_set_low_water,
7357                 (void *)&cmd_pfc_set_pause_time,
7358                 (void *)&cmd_pfc_set_priority,
7359                 (void *)&cmd_pfc_set_portid,
7360                 NULL,
7361         },
7362 };
7363
7364 /* *** RESET CONFIGURATION *** */
7365 struct cmd_reset_result {
7366         cmdline_fixed_string_t reset;
7367         cmdline_fixed_string_t def;
7368 };
7369
7370 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7371                              struct cmdline *cl,
7372                              __rte_unused void *data)
7373 {
7374         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7375         set_def_fwd_config();
7376 }
7377
7378 cmdline_parse_token_string_t cmd_reset_set =
7379         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7380 cmdline_parse_token_string_t cmd_reset_def =
7381         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7382                                  "default");
7383
7384 cmdline_parse_inst_t cmd_reset = {
7385         .f = cmd_reset_parsed,
7386         .data = NULL,
7387         .help_str = "set default: Reset default forwarding configuration",
7388         .tokens = {
7389                 (void *)&cmd_reset_set,
7390                 (void *)&cmd_reset_def,
7391                 NULL,
7392         },
7393 };
7394
7395 /* *** START FORWARDING *** */
7396 struct cmd_start_result {
7397         cmdline_fixed_string_t start;
7398 };
7399
7400 cmdline_parse_token_string_t cmd_start_start =
7401         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7402
7403 static void cmd_start_parsed(__rte_unused void *parsed_result,
7404                              __rte_unused struct cmdline *cl,
7405                              __rte_unused void *data)
7406 {
7407         start_packet_forwarding(0);
7408 }
7409
7410 cmdline_parse_inst_t cmd_start = {
7411         .f = cmd_start_parsed,
7412         .data = NULL,
7413         .help_str = "start: Start packet forwarding",
7414         .tokens = {
7415                 (void *)&cmd_start_start,
7416                 NULL,
7417         },
7418 };
7419
7420 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7421 struct cmd_start_tx_first_result {
7422         cmdline_fixed_string_t start;
7423         cmdline_fixed_string_t tx_first;
7424 };
7425
7426 static void
7427 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7428                           __rte_unused struct cmdline *cl,
7429                           __rte_unused void *data)
7430 {
7431         start_packet_forwarding(1);
7432 }
7433
7434 cmdline_parse_token_string_t cmd_start_tx_first_start =
7435         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7436                                  "start");
7437 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7438         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7439                                  tx_first, "tx_first");
7440
7441 cmdline_parse_inst_t cmd_start_tx_first = {
7442         .f = cmd_start_tx_first_parsed,
7443         .data = NULL,
7444         .help_str = "start tx_first: Start packet forwarding, "
7445                 "after sending 1 burst of packets",
7446         .tokens = {
7447                 (void *)&cmd_start_tx_first_start,
7448                 (void *)&cmd_start_tx_first_tx_first,
7449                 NULL,
7450         },
7451 };
7452
7453 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7454 struct cmd_start_tx_first_n_result {
7455         cmdline_fixed_string_t start;
7456         cmdline_fixed_string_t tx_first;
7457         uint32_t tx_num;
7458 };
7459
7460 static void
7461 cmd_start_tx_first_n_parsed(void *parsed_result,
7462                           __rte_unused struct cmdline *cl,
7463                           __rte_unused void *data)
7464 {
7465         struct cmd_start_tx_first_n_result *res = parsed_result;
7466
7467         start_packet_forwarding(res->tx_num);
7468 }
7469
7470 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7471         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7472                         start, "start");
7473 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7474         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7475                         tx_first, "tx_first");
7476 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7477         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7478                         tx_num, UINT32);
7479
7480 cmdline_parse_inst_t cmd_start_tx_first_n = {
7481         .f = cmd_start_tx_first_n_parsed,
7482         .data = NULL,
7483         .help_str = "start tx_first <num>: "
7484                 "packet forwarding, after sending <num> bursts of packets",
7485         .tokens = {
7486                 (void *)&cmd_start_tx_first_n_start,
7487                 (void *)&cmd_start_tx_first_n_tx_first,
7488                 (void *)&cmd_start_tx_first_n_tx_num,
7489                 NULL,
7490         },
7491 };
7492
7493 /* *** SET LINK UP *** */
7494 struct cmd_set_link_up_result {
7495         cmdline_fixed_string_t set;
7496         cmdline_fixed_string_t link_up;
7497         cmdline_fixed_string_t port;
7498         portid_t port_id;
7499 };
7500
7501 cmdline_parse_token_string_t cmd_set_link_up_set =
7502         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7503 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7504         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7505                                 "link-up");
7506 cmdline_parse_token_string_t cmd_set_link_up_port =
7507         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7508 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7509         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7510
7511 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7512                              __rte_unused struct cmdline *cl,
7513                              __rte_unused void *data)
7514 {
7515         struct cmd_set_link_up_result *res = parsed_result;
7516         dev_set_link_up(res->port_id);
7517 }
7518
7519 cmdline_parse_inst_t cmd_set_link_up = {
7520         .f = cmd_set_link_up_parsed,
7521         .data = NULL,
7522         .help_str = "set link-up port <port id>",
7523         .tokens = {
7524                 (void *)&cmd_set_link_up_set,
7525                 (void *)&cmd_set_link_up_link_up,
7526                 (void *)&cmd_set_link_up_port,
7527                 (void *)&cmd_set_link_up_port_id,
7528                 NULL,
7529         },
7530 };
7531
7532 /* *** SET LINK DOWN *** */
7533 struct cmd_set_link_down_result {
7534         cmdline_fixed_string_t set;
7535         cmdline_fixed_string_t link_down;
7536         cmdline_fixed_string_t port;
7537         portid_t port_id;
7538 };
7539
7540 cmdline_parse_token_string_t cmd_set_link_down_set =
7541         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7542 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7543         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7544                                 "link-down");
7545 cmdline_parse_token_string_t cmd_set_link_down_port =
7546         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7547 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7548         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7549
7550 static void cmd_set_link_down_parsed(
7551                                 __rte_unused void *parsed_result,
7552                                 __rte_unused struct cmdline *cl,
7553                                 __rte_unused void *data)
7554 {
7555         struct cmd_set_link_down_result *res = parsed_result;
7556         dev_set_link_down(res->port_id);
7557 }
7558
7559 cmdline_parse_inst_t cmd_set_link_down = {
7560         .f = cmd_set_link_down_parsed,
7561         .data = NULL,
7562         .help_str = "set link-down port <port id>",
7563         .tokens = {
7564                 (void *)&cmd_set_link_down_set,
7565                 (void *)&cmd_set_link_down_link_down,
7566                 (void *)&cmd_set_link_down_port,
7567                 (void *)&cmd_set_link_down_port_id,
7568                 NULL,
7569         },
7570 };
7571
7572 /* *** SHOW CFG *** */
7573 struct cmd_showcfg_result {
7574         cmdline_fixed_string_t show;
7575         cmdline_fixed_string_t cfg;
7576         cmdline_fixed_string_t what;
7577 };
7578
7579 static void cmd_showcfg_parsed(void *parsed_result,
7580                                __rte_unused struct cmdline *cl,
7581                                __rte_unused void *data)
7582 {
7583         struct cmd_showcfg_result *res = parsed_result;
7584         if (!strcmp(res->what, "rxtx"))
7585                 rxtx_config_display();
7586         else if (!strcmp(res->what, "cores"))
7587                 fwd_lcores_config_display();
7588         else if (!strcmp(res->what, "fwd"))
7589                 pkt_fwd_config_display(&cur_fwd_config);
7590         else if (!strcmp(res->what, "rxpkts"))
7591                 show_rx_pkt_segments();
7592         else if (!strcmp(res->what, "txpkts"))
7593                 show_tx_pkt_segments();
7594         else if (!strcmp(res->what, "txtimes"))
7595                 show_tx_pkt_times();
7596 }
7597
7598 cmdline_parse_token_string_t cmd_showcfg_show =
7599         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7600 cmdline_parse_token_string_t cmd_showcfg_port =
7601         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7602 cmdline_parse_token_string_t cmd_showcfg_what =
7603         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7604                                  "rxtx#cores#fwd#rxpkts#txpkts#txtimes");
7605
7606 cmdline_parse_inst_t cmd_showcfg = {
7607         .f = cmd_showcfg_parsed,
7608         .data = NULL,
7609         .help_str = "show config rxtx|cores|fwd|rxpkts|txpkts|txtimes",
7610         .tokens = {
7611                 (void *)&cmd_showcfg_show,
7612                 (void *)&cmd_showcfg_port,
7613                 (void *)&cmd_showcfg_what,
7614                 NULL,
7615         },
7616 };
7617
7618 /* *** SHOW ALL PORT INFO *** */
7619 struct cmd_showportall_result {
7620         cmdline_fixed_string_t show;
7621         cmdline_fixed_string_t port;
7622         cmdline_fixed_string_t what;
7623         cmdline_fixed_string_t all;
7624 };
7625
7626 static void cmd_showportall_parsed(void *parsed_result,
7627                                 __rte_unused struct cmdline *cl,
7628                                 __rte_unused void *data)
7629 {
7630         portid_t i;
7631
7632         struct cmd_showportall_result *res = parsed_result;
7633         if (!strcmp(res->show, "clear")) {
7634                 if (!strcmp(res->what, "stats"))
7635                         RTE_ETH_FOREACH_DEV(i)
7636                                 nic_stats_clear(i);
7637                 else if (!strcmp(res->what, "xstats"))
7638                         RTE_ETH_FOREACH_DEV(i)
7639                                 nic_xstats_clear(i);
7640         } else if (!strcmp(res->what, "info"))
7641                 RTE_ETH_FOREACH_DEV(i)
7642                         port_infos_display(i);
7643         else if (!strcmp(res->what, "summary")) {
7644                 port_summary_header_display();
7645                 RTE_ETH_FOREACH_DEV(i)
7646                         port_summary_display(i);
7647         }
7648         else if (!strcmp(res->what, "stats"))
7649                 RTE_ETH_FOREACH_DEV(i)
7650                         nic_stats_display(i);
7651         else if (!strcmp(res->what, "xstats"))
7652                 RTE_ETH_FOREACH_DEV(i)
7653                         nic_xstats_display(i);
7654         else if (!strcmp(res->what, "fdir"))
7655                 RTE_ETH_FOREACH_DEV(i)
7656                         fdir_get_infos(i);
7657         else if (!strcmp(res->what, "stat_qmap"))
7658                 RTE_ETH_FOREACH_DEV(i)
7659                         nic_stats_mapping_display(i);
7660         else if (!strcmp(res->what, "dcb_tc"))
7661                 RTE_ETH_FOREACH_DEV(i)
7662                         port_dcb_info_display(i);
7663         else if (!strcmp(res->what, "cap"))
7664                 RTE_ETH_FOREACH_DEV(i)
7665                         port_offload_cap_display(i);
7666 }
7667
7668 cmdline_parse_token_string_t cmd_showportall_show =
7669         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7670                                  "show#clear");
7671 cmdline_parse_token_string_t cmd_showportall_port =
7672         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7673 cmdline_parse_token_string_t cmd_showportall_what =
7674         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7675                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7676 cmdline_parse_token_string_t cmd_showportall_all =
7677         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7678 cmdline_parse_inst_t cmd_showportall = {
7679         .f = cmd_showportall_parsed,
7680         .data = NULL,
7681         .help_str = "show|clear port "
7682                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7683         .tokens = {
7684                 (void *)&cmd_showportall_show,
7685                 (void *)&cmd_showportall_port,
7686                 (void *)&cmd_showportall_what,
7687                 (void *)&cmd_showportall_all,
7688                 NULL,
7689         },
7690 };
7691
7692 /* *** SHOW PORT INFO *** */
7693 struct cmd_showport_result {
7694         cmdline_fixed_string_t show;
7695         cmdline_fixed_string_t port;
7696         cmdline_fixed_string_t what;
7697         uint16_t portnum;
7698 };
7699
7700 static void cmd_showport_parsed(void *parsed_result,
7701                                 __rte_unused struct cmdline *cl,
7702                                 __rte_unused void *data)
7703 {
7704         struct cmd_showport_result *res = parsed_result;
7705         if (!strcmp(res->show, "clear")) {
7706                 if (!strcmp(res->what, "stats"))
7707                         nic_stats_clear(res->portnum);
7708                 else if (!strcmp(res->what, "xstats"))
7709                         nic_xstats_clear(res->portnum);
7710         } else if (!strcmp(res->what, "info"))
7711                 port_infos_display(res->portnum);
7712         else if (!strcmp(res->what, "summary")) {
7713                 port_summary_header_display();
7714                 port_summary_display(res->portnum);
7715         }
7716         else if (!strcmp(res->what, "stats"))
7717                 nic_stats_display(res->portnum);
7718         else if (!strcmp(res->what, "xstats"))
7719                 nic_xstats_display(res->portnum);
7720         else if (!strcmp(res->what, "fdir"))
7721                  fdir_get_infos(res->portnum);
7722         else if (!strcmp(res->what, "stat_qmap"))
7723                 nic_stats_mapping_display(res->portnum);
7724         else if (!strcmp(res->what, "dcb_tc"))
7725                 port_dcb_info_display(res->portnum);
7726         else if (!strcmp(res->what, "cap"))
7727                 port_offload_cap_display(res->portnum);
7728 }
7729
7730 cmdline_parse_token_string_t cmd_showport_show =
7731         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7732                                  "show#clear");
7733 cmdline_parse_token_string_t cmd_showport_port =
7734         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7735 cmdline_parse_token_string_t cmd_showport_what =
7736         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7737                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7738 cmdline_parse_token_num_t cmd_showport_portnum =
7739         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7740
7741 cmdline_parse_inst_t cmd_showport = {
7742         .f = cmd_showport_parsed,
7743         .data = NULL,
7744         .help_str = "show|clear port "
7745                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7746                 "<port_id>",
7747         .tokens = {
7748                 (void *)&cmd_showport_show,
7749                 (void *)&cmd_showport_port,
7750                 (void *)&cmd_showport_what,
7751                 (void *)&cmd_showport_portnum,
7752                 NULL,
7753         },
7754 };
7755
7756 /* *** SHOW DEVICE INFO *** */
7757 struct cmd_showdevice_result {
7758         cmdline_fixed_string_t show;
7759         cmdline_fixed_string_t device;
7760         cmdline_fixed_string_t what;
7761         cmdline_fixed_string_t identifier;
7762 };
7763
7764 static void cmd_showdevice_parsed(void *parsed_result,
7765                                 __rte_unused struct cmdline *cl,
7766                                 __rte_unused void *data)
7767 {
7768         struct cmd_showdevice_result *res = parsed_result;
7769         if (!strcmp(res->what, "info")) {
7770                 if (!strcmp(res->identifier, "all"))
7771                         device_infos_display(NULL);
7772                 else
7773                         device_infos_display(res->identifier);
7774         }
7775 }
7776
7777 cmdline_parse_token_string_t cmd_showdevice_show =
7778         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7779                                  "show");
7780 cmdline_parse_token_string_t cmd_showdevice_device =
7781         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7782 cmdline_parse_token_string_t cmd_showdevice_what =
7783         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7784                                  "info");
7785 cmdline_parse_token_string_t cmd_showdevice_identifier =
7786         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7787                         identifier, NULL);
7788
7789 cmdline_parse_inst_t cmd_showdevice = {
7790         .f = cmd_showdevice_parsed,
7791         .data = NULL,
7792         .help_str = "show device info <identifier>|all",
7793         .tokens = {
7794                 (void *)&cmd_showdevice_show,
7795                 (void *)&cmd_showdevice_device,
7796                 (void *)&cmd_showdevice_what,
7797                 (void *)&cmd_showdevice_identifier,
7798                 NULL,
7799         },
7800 };
7801
7802 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7803 struct cmd_showeeprom_result {
7804         cmdline_fixed_string_t show;
7805         cmdline_fixed_string_t port;
7806         uint16_t portnum;
7807         cmdline_fixed_string_t type;
7808 };
7809
7810 static void cmd_showeeprom_parsed(void *parsed_result,
7811                 __rte_unused struct cmdline *cl,
7812                 __rte_unused void *data)
7813 {
7814         struct cmd_showeeprom_result *res = parsed_result;
7815
7816         if (!strcmp(res->type, "eeprom"))
7817                 port_eeprom_display(res->portnum);
7818         else if (!strcmp(res->type, "module_eeprom"))
7819                 port_module_eeprom_display(res->portnum);
7820         else
7821                 printf("Unknown argument\n");
7822 }
7823
7824 cmdline_parse_token_string_t cmd_showeeprom_show =
7825         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7826 cmdline_parse_token_string_t cmd_showeeprom_port =
7827         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7828 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7829         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7830 cmdline_parse_token_string_t cmd_showeeprom_type =
7831         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7832
7833 cmdline_parse_inst_t cmd_showeeprom = {
7834         .f = cmd_showeeprom_parsed,
7835         .data = NULL,
7836         .help_str = "show port <port_id> module_eeprom|eeprom",
7837         .tokens = {
7838                 (void *)&cmd_showeeprom_show,
7839                 (void *)&cmd_showeeprom_port,
7840                 (void *)&cmd_showeeprom_portnum,
7841                 (void *)&cmd_showeeprom_type,
7842                 NULL,
7843         },
7844 };
7845
7846 /* *** SHOW QUEUE INFO *** */
7847 struct cmd_showqueue_result {
7848         cmdline_fixed_string_t show;
7849         cmdline_fixed_string_t type;
7850         cmdline_fixed_string_t what;
7851         uint16_t portnum;
7852         uint16_t queuenum;
7853 };
7854
7855 static void
7856 cmd_showqueue_parsed(void *parsed_result,
7857         __rte_unused struct cmdline *cl,
7858         __rte_unused void *data)
7859 {
7860         struct cmd_showqueue_result *res = parsed_result;
7861
7862         if (!strcmp(res->type, "rxq"))
7863                 rx_queue_infos_display(res->portnum, res->queuenum);
7864         else if (!strcmp(res->type, "txq"))
7865                 tx_queue_infos_display(res->portnum, res->queuenum);
7866 }
7867
7868 cmdline_parse_token_string_t cmd_showqueue_show =
7869         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7870 cmdline_parse_token_string_t cmd_showqueue_type =
7871         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7872 cmdline_parse_token_string_t cmd_showqueue_what =
7873         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7874 cmdline_parse_token_num_t cmd_showqueue_portnum =
7875         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7876 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7877         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7878
7879 cmdline_parse_inst_t cmd_showqueue = {
7880         .f = cmd_showqueue_parsed,
7881         .data = NULL,
7882         .help_str = "show rxq|txq info <port_id> <queue_id>",
7883         .tokens = {
7884                 (void *)&cmd_showqueue_show,
7885                 (void *)&cmd_showqueue_type,
7886                 (void *)&cmd_showqueue_what,
7887                 (void *)&cmd_showqueue_portnum,
7888                 (void *)&cmd_showqueue_queuenum,
7889                 NULL,
7890         },
7891 };
7892
7893 /* show/clear fwd engine statistics */
7894 struct fwd_result {
7895         cmdline_fixed_string_t action;
7896         cmdline_fixed_string_t fwd;
7897         cmdline_fixed_string_t stats;
7898         cmdline_fixed_string_t all;
7899 };
7900
7901 cmdline_parse_token_string_t cmd_fwd_action =
7902         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7903 cmdline_parse_token_string_t cmd_fwd_fwd =
7904         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7905 cmdline_parse_token_string_t cmd_fwd_stats =
7906         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7907 cmdline_parse_token_string_t cmd_fwd_all =
7908         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7909
7910 static void
7911 cmd_showfwdall_parsed(void *parsed_result,
7912                       __rte_unused struct cmdline *cl,
7913                       __rte_unused void *data)
7914 {
7915         struct fwd_result *res = parsed_result;
7916
7917         if (!strcmp(res->action, "show"))
7918                 fwd_stats_display();
7919         else
7920                 fwd_stats_reset();
7921 }
7922
7923 static cmdline_parse_inst_t cmd_showfwdall = {
7924         .f = cmd_showfwdall_parsed,
7925         .data = NULL,
7926         .help_str = "show|clear fwd stats all",
7927         .tokens = {
7928                 (void *)&cmd_fwd_action,
7929                 (void *)&cmd_fwd_fwd,
7930                 (void *)&cmd_fwd_stats,
7931                 (void *)&cmd_fwd_all,
7932                 NULL,
7933         },
7934 };
7935
7936 /* *** READ PORT REGISTER *** */
7937 struct cmd_read_reg_result {
7938         cmdline_fixed_string_t read;
7939         cmdline_fixed_string_t reg;
7940         portid_t port_id;
7941         uint32_t reg_off;
7942 };
7943
7944 static void
7945 cmd_read_reg_parsed(void *parsed_result,
7946                     __rte_unused struct cmdline *cl,
7947                     __rte_unused void *data)
7948 {
7949         struct cmd_read_reg_result *res = parsed_result;
7950         port_reg_display(res->port_id, res->reg_off);
7951 }
7952
7953 cmdline_parse_token_string_t cmd_read_reg_read =
7954         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7955 cmdline_parse_token_string_t cmd_read_reg_reg =
7956         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7957 cmdline_parse_token_num_t cmd_read_reg_port_id =
7958         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7959 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7960         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7961
7962 cmdline_parse_inst_t cmd_read_reg = {
7963         .f = cmd_read_reg_parsed,
7964         .data = NULL,
7965         .help_str = "read reg <port_id> <reg_off>",
7966         .tokens = {
7967                 (void *)&cmd_read_reg_read,
7968                 (void *)&cmd_read_reg_reg,
7969                 (void *)&cmd_read_reg_port_id,
7970                 (void *)&cmd_read_reg_reg_off,
7971                 NULL,
7972         },
7973 };
7974
7975 /* *** READ PORT REGISTER BIT FIELD *** */
7976 struct cmd_read_reg_bit_field_result {
7977         cmdline_fixed_string_t read;
7978         cmdline_fixed_string_t regfield;
7979         portid_t port_id;
7980         uint32_t reg_off;
7981         uint8_t bit1_pos;
7982         uint8_t bit2_pos;
7983 };
7984
7985 static void
7986 cmd_read_reg_bit_field_parsed(void *parsed_result,
7987                               __rte_unused struct cmdline *cl,
7988                               __rte_unused void *data)
7989 {
7990         struct cmd_read_reg_bit_field_result *res = parsed_result;
7991         port_reg_bit_field_display(res->port_id, res->reg_off,
7992                                    res->bit1_pos, res->bit2_pos);
7993 }
7994
7995 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7996         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7997                                  "read");
7998 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7999         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
8000                                  regfield, "regfield");
8001 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
8002         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
8003                               UINT16);
8004 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
8005         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
8006                               UINT32);
8007 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
8008         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
8009                               UINT8);
8010 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
8011         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
8012                               UINT8);
8013
8014 cmdline_parse_inst_t cmd_read_reg_bit_field = {
8015         .f = cmd_read_reg_bit_field_parsed,
8016         .data = NULL,
8017         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8018         "Read register bit field between bit_x and bit_y included",
8019         .tokens = {
8020                 (void *)&cmd_read_reg_bit_field_read,
8021                 (void *)&cmd_read_reg_bit_field_regfield,
8022                 (void *)&cmd_read_reg_bit_field_port_id,
8023                 (void *)&cmd_read_reg_bit_field_reg_off,
8024                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8025                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8026                 NULL,
8027         },
8028 };
8029
8030 /* *** READ PORT REGISTER BIT *** */
8031 struct cmd_read_reg_bit_result {
8032         cmdline_fixed_string_t read;
8033         cmdline_fixed_string_t regbit;
8034         portid_t port_id;
8035         uint32_t reg_off;
8036         uint8_t bit_pos;
8037 };
8038
8039 static void
8040 cmd_read_reg_bit_parsed(void *parsed_result,
8041                         __rte_unused struct cmdline *cl,
8042                         __rte_unused void *data)
8043 {
8044         struct cmd_read_reg_bit_result *res = parsed_result;
8045         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8046 }
8047
8048 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8049         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8050 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8051         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8052                                  regbit, "regbit");
8053 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8054         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8055 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8056         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8057 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8058         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8059
8060 cmdline_parse_inst_t cmd_read_reg_bit = {
8061         .f = cmd_read_reg_bit_parsed,
8062         .data = NULL,
8063         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8064         .tokens = {
8065                 (void *)&cmd_read_reg_bit_read,
8066                 (void *)&cmd_read_reg_bit_regbit,
8067                 (void *)&cmd_read_reg_bit_port_id,
8068                 (void *)&cmd_read_reg_bit_reg_off,
8069                 (void *)&cmd_read_reg_bit_bit_pos,
8070                 NULL,
8071         },
8072 };
8073
8074 /* *** WRITE PORT REGISTER *** */
8075 struct cmd_write_reg_result {
8076         cmdline_fixed_string_t write;
8077         cmdline_fixed_string_t reg;
8078         portid_t port_id;
8079         uint32_t reg_off;
8080         uint32_t value;
8081 };
8082
8083 static void
8084 cmd_write_reg_parsed(void *parsed_result,
8085                      __rte_unused struct cmdline *cl,
8086                      __rte_unused void *data)
8087 {
8088         struct cmd_write_reg_result *res = parsed_result;
8089         port_reg_set(res->port_id, res->reg_off, res->value);
8090 }
8091
8092 cmdline_parse_token_string_t cmd_write_reg_write =
8093         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8094 cmdline_parse_token_string_t cmd_write_reg_reg =
8095         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8096 cmdline_parse_token_num_t cmd_write_reg_port_id =
8097         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8098 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8099         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8100 cmdline_parse_token_num_t cmd_write_reg_value =
8101         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8102
8103 cmdline_parse_inst_t cmd_write_reg = {
8104         .f = cmd_write_reg_parsed,
8105         .data = NULL,
8106         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8107         .tokens = {
8108                 (void *)&cmd_write_reg_write,
8109                 (void *)&cmd_write_reg_reg,
8110                 (void *)&cmd_write_reg_port_id,
8111                 (void *)&cmd_write_reg_reg_off,
8112                 (void *)&cmd_write_reg_value,
8113                 NULL,
8114         },
8115 };
8116
8117 /* *** WRITE PORT REGISTER BIT FIELD *** */
8118 struct cmd_write_reg_bit_field_result {
8119         cmdline_fixed_string_t write;
8120         cmdline_fixed_string_t regfield;
8121         portid_t port_id;
8122         uint32_t reg_off;
8123         uint8_t bit1_pos;
8124         uint8_t bit2_pos;
8125         uint32_t value;
8126 };
8127
8128 static void
8129 cmd_write_reg_bit_field_parsed(void *parsed_result,
8130                                __rte_unused struct cmdline *cl,
8131                                __rte_unused void *data)
8132 {
8133         struct cmd_write_reg_bit_field_result *res = parsed_result;
8134         port_reg_bit_field_set(res->port_id, res->reg_off,
8135                           res->bit1_pos, res->bit2_pos, res->value);
8136 }
8137
8138 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8139         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8140                                  "write");
8141 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8142         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8143                                  regfield, "regfield");
8144 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8145         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8146                               UINT16);
8147 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8148         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8149                               UINT32);
8150 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8151         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8152                               UINT8);
8153 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8154         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8155                               UINT8);
8156 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8157         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8158                               UINT32);
8159
8160 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8161         .f = cmd_write_reg_bit_field_parsed,
8162         .data = NULL,
8163         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8164                 "<reg_value>: "
8165                 "Set register bit field between bit_x and bit_y included",
8166         .tokens = {
8167                 (void *)&cmd_write_reg_bit_field_write,
8168                 (void *)&cmd_write_reg_bit_field_regfield,
8169                 (void *)&cmd_write_reg_bit_field_port_id,
8170                 (void *)&cmd_write_reg_bit_field_reg_off,
8171                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8172                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8173                 (void *)&cmd_write_reg_bit_field_value,
8174                 NULL,
8175         },
8176 };
8177
8178 /* *** WRITE PORT REGISTER BIT *** */
8179 struct cmd_write_reg_bit_result {
8180         cmdline_fixed_string_t write;
8181         cmdline_fixed_string_t regbit;
8182         portid_t port_id;
8183         uint32_t reg_off;
8184         uint8_t bit_pos;
8185         uint8_t value;
8186 };
8187
8188 static void
8189 cmd_write_reg_bit_parsed(void *parsed_result,
8190                          __rte_unused struct cmdline *cl,
8191                          __rte_unused void *data)
8192 {
8193         struct cmd_write_reg_bit_result *res = parsed_result;
8194         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8195 }
8196
8197 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8198         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8199                                  "write");
8200 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8201         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8202                                  regbit, "regbit");
8203 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8204         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8205 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8206         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8207 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8208         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8209 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8210         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8211
8212 cmdline_parse_inst_t cmd_write_reg_bit = {
8213         .f = cmd_write_reg_bit_parsed,
8214         .data = NULL,
8215         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8216                 "0 <= bit_x <= 31",
8217         .tokens = {
8218                 (void *)&cmd_write_reg_bit_write,
8219                 (void *)&cmd_write_reg_bit_regbit,
8220                 (void *)&cmd_write_reg_bit_port_id,
8221                 (void *)&cmd_write_reg_bit_reg_off,
8222                 (void *)&cmd_write_reg_bit_bit_pos,
8223                 (void *)&cmd_write_reg_bit_value,
8224                 NULL,
8225         },
8226 };
8227
8228 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8229 struct cmd_read_rxd_txd_result {
8230         cmdline_fixed_string_t read;
8231         cmdline_fixed_string_t rxd_txd;
8232         portid_t port_id;
8233         uint16_t queue_id;
8234         uint16_t desc_id;
8235 };
8236
8237 static void
8238 cmd_read_rxd_txd_parsed(void *parsed_result,
8239                         __rte_unused struct cmdline *cl,
8240                         __rte_unused void *data)
8241 {
8242         struct cmd_read_rxd_txd_result *res = parsed_result;
8243
8244         if (!strcmp(res->rxd_txd, "rxd"))
8245                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8246         else if (!strcmp(res->rxd_txd, "txd"))
8247                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8248 }
8249
8250 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8251         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8252 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8253         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8254                                  "rxd#txd");
8255 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8256         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8257 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8258         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8259 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8260         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8261
8262 cmdline_parse_inst_t cmd_read_rxd_txd = {
8263         .f = cmd_read_rxd_txd_parsed,
8264         .data = NULL,
8265         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8266         .tokens = {
8267                 (void *)&cmd_read_rxd_txd_read,
8268                 (void *)&cmd_read_rxd_txd_rxd_txd,
8269                 (void *)&cmd_read_rxd_txd_port_id,
8270                 (void *)&cmd_read_rxd_txd_queue_id,
8271                 (void *)&cmd_read_rxd_txd_desc_id,
8272                 NULL,
8273         },
8274 };
8275
8276 /* *** QUIT *** */
8277 struct cmd_quit_result {
8278         cmdline_fixed_string_t quit;
8279 };
8280
8281 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8282                             struct cmdline *cl,
8283                             __rte_unused void *data)
8284 {
8285         cmdline_quit(cl);
8286 }
8287
8288 cmdline_parse_token_string_t cmd_quit_quit =
8289         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8290
8291 cmdline_parse_inst_t cmd_quit = {
8292         .f = cmd_quit_parsed,
8293         .data = NULL,
8294         .help_str = "quit: Exit application",
8295         .tokens = {
8296                 (void *)&cmd_quit_quit,
8297                 NULL,
8298         },
8299 };
8300
8301 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8302 struct cmd_mac_addr_result {
8303         cmdline_fixed_string_t mac_addr_cmd;
8304         cmdline_fixed_string_t what;
8305         uint16_t port_num;
8306         struct rte_ether_addr address;
8307 };
8308
8309 static void cmd_mac_addr_parsed(void *parsed_result,
8310                 __rte_unused struct cmdline *cl,
8311                 __rte_unused void *data)
8312 {
8313         struct cmd_mac_addr_result *res = parsed_result;
8314         int ret;
8315
8316         if (strcmp(res->what, "add") == 0)
8317                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8318         else if (strcmp(res->what, "set") == 0)
8319                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8320                                                        &res->address);
8321         else
8322                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8323
8324         /* check the return value and print it if is < 0 */
8325         if(ret < 0)
8326                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8327
8328 }
8329
8330 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8331         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8332                                 "mac_addr");
8333 cmdline_parse_token_string_t cmd_mac_addr_what =
8334         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8335                                 "add#remove#set");
8336 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8337                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8338                                         UINT16);
8339 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8340                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8341
8342 cmdline_parse_inst_t cmd_mac_addr = {
8343         .f = cmd_mac_addr_parsed,
8344         .data = (void *)0,
8345         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8346                         "Add/Remove/Set MAC address on port_id",
8347         .tokens = {
8348                 (void *)&cmd_mac_addr_cmd,
8349                 (void *)&cmd_mac_addr_what,
8350                 (void *)&cmd_mac_addr_portnum,
8351                 (void *)&cmd_mac_addr_addr,
8352                 NULL,
8353         },
8354 };
8355
8356 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8357 struct cmd_eth_peer_result {
8358         cmdline_fixed_string_t set;
8359         cmdline_fixed_string_t eth_peer;
8360         portid_t port_id;
8361         cmdline_fixed_string_t peer_addr;
8362 };
8363
8364 static void cmd_set_eth_peer_parsed(void *parsed_result,
8365                         __rte_unused struct cmdline *cl,
8366                         __rte_unused void *data)
8367 {
8368                 struct cmd_eth_peer_result *res = parsed_result;
8369
8370                 if (test_done == 0) {
8371                         printf("Please stop forwarding first\n");
8372                         return;
8373                 }
8374                 if (!strcmp(res->eth_peer, "eth-peer")) {
8375                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8376                         fwd_config_setup();
8377                 }
8378 }
8379 cmdline_parse_token_string_t cmd_eth_peer_set =
8380         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8381 cmdline_parse_token_string_t cmd_eth_peer =
8382         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8383 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8384         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8385 cmdline_parse_token_string_t cmd_eth_peer_addr =
8386         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8387
8388 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8389         .f = cmd_set_eth_peer_parsed,
8390         .data = NULL,
8391         .help_str = "set eth-peer <port_id> <peer_mac>",
8392         .tokens = {
8393                 (void *)&cmd_eth_peer_set,
8394                 (void *)&cmd_eth_peer,
8395                 (void *)&cmd_eth_peer_port_id,
8396                 (void *)&cmd_eth_peer_addr,
8397                 NULL,
8398         },
8399 };
8400
8401 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8402 struct cmd_set_qmap_result {
8403         cmdline_fixed_string_t set;
8404         cmdline_fixed_string_t qmap;
8405         cmdline_fixed_string_t what;
8406         portid_t port_id;
8407         uint16_t queue_id;
8408         uint8_t map_value;
8409 };
8410
8411 static void
8412 cmd_set_qmap_parsed(void *parsed_result,
8413                        __rte_unused struct cmdline *cl,
8414                        __rte_unused void *data)
8415 {
8416         struct cmd_set_qmap_result *res = parsed_result;
8417         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8418
8419         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8420 }
8421
8422 cmdline_parse_token_string_t cmd_setqmap_set =
8423         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8424                                  set, "set");
8425 cmdline_parse_token_string_t cmd_setqmap_qmap =
8426         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8427                                  qmap, "stat_qmap");
8428 cmdline_parse_token_string_t cmd_setqmap_what =
8429         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8430                                  what, "tx#rx");
8431 cmdline_parse_token_num_t cmd_setqmap_portid =
8432         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8433                               port_id, UINT16);
8434 cmdline_parse_token_num_t cmd_setqmap_queueid =
8435         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8436                               queue_id, UINT16);
8437 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8438         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8439                               map_value, UINT8);
8440
8441 cmdline_parse_inst_t cmd_set_qmap = {
8442         .f = cmd_set_qmap_parsed,
8443         .data = NULL,
8444         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8445                 "Set statistics mapping value on tx|rx queue_id of port_id",
8446         .tokens = {
8447                 (void *)&cmd_setqmap_set,
8448                 (void *)&cmd_setqmap_qmap,
8449                 (void *)&cmd_setqmap_what,
8450                 (void *)&cmd_setqmap_portid,
8451                 (void *)&cmd_setqmap_queueid,
8452                 (void *)&cmd_setqmap_mapvalue,
8453                 NULL,
8454         },
8455 };
8456
8457 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8458 struct cmd_set_xstats_hide_zero_result {
8459         cmdline_fixed_string_t keyword;
8460         cmdline_fixed_string_t name;
8461         cmdline_fixed_string_t on_off;
8462 };
8463
8464 static void
8465 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8466                         __rte_unused struct cmdline *cl,
8467                         __rte_unused void *data)
8468 {
8469         struct cmd_set_xstats_hide_zero_result *res;
8470         uint16_t on_off = 0;
8471
8472         res = parsed_result;
8473         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8474         set_xstats_hide_zero(on_off);
8475 }
8476
8477 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8478         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8479                                  keyword, "set");
8480 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8481         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8482                                  name, "xstats-hide-zero");
8483 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8484         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8485                                  on_off, "on#off");
8486
8487 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8488         .f = cmd_set_xstats_hide_zero_parsed,
8489         .data = NULL,
8490         .help_str = "set xstats-hide-zero on|off",
8491         .tokens = {
8492                 (void *)&cmd_set_xstats_hide_zero_keyword,
8493                 (void *)&cmd_set_xstats_hide_zero_name,
8494                 (void *)&cmd_set_xstats_hide_zero_on_off,
8495                 NULL,
8496         },
8497 };
8498
8499 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8500 struct cmd_set_record_core_cycles_result {
8501         cmdline_fixed_string_t keyword;
8502         cmdline_fixed_string_t name;
8503         cmdline_fixed_string_t on_off;
8504 };
8505
8506 static void
8507 cmd_set_record_core_cycles_parsed(void *parsed_result,
8508                         __rte_unused struct cmdline *cl,
8509                         __rte_unused void *data)
8510 {
8511         struct cmd_set_record_core_cycles_result *res;
8512         uint16_t on_off = 0;
8513
8514         res = parsed_result;
8515         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8516         set_record_core_cycles(on_off);
8517 }
8518
8519 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8520         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8521                                  keyword, "set");
8522 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8523         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8524                                  name, "record-core-cycles");
8525 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8526         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8527                                  on_off, "on#off");
8528
8529 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8530         .f = cmd_set_record_core_cycles_parsed,
8531         .data = NULL,
8532         .help_str = "set record-core-cycles on|off",
8533         .tokens = {
8534                 (void *)&cmd_set_record_core_cycles_keyword,
8535                 (void *)&cmd_set_record_core_cycles_name,
8536                 (void *)&cmd_set_record_core_cycles_on_off,
8537                 NULL,
8538         },
8539 };
8540
8541 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8542 struct cmd_set_record_burst_stats_result {
8543         cmdline_fixed_string_t keyword;
8544         cmdline_fixed_string_t name;
8545         cmdline_fixed_string_t on_off;
8546 };
8547
8548 static void
8549 cmd_set_record_burst_stats_parsed(void *parsed_result,
8550                         __rte_unused struct cmdline *cl,
8551                         __rte_unused void *data)
8552 {
8553         struct cmd_set_record_burst_stats_result *res;
8554         uint16_t on_off = 0;
8555
8556         res = parsed_result;
8557         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8558         set_record_burst_stats(on_off);
8559 }
8560
8561 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8562         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8563                                  keyword, "set");
8564 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8565         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8566                                  name, "record-burst-stats");
8567 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8568         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8569                                  on_off, "on#off");
8570
8571 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8572         .f = cmd_set_record_burst_stats_parsed,
8573         .data = NULL,
8574         .help_str = "set record-burst-stats on|off",
8575         .tokens = {
8576                 (void *)&cmd_set_record_burst_stats_keyword,
8577                 (void *)&cmd_set_record_burst_stats_name,
8578                 (void *)&cmd_set_record_burst_stats_on_off,
8579                 NULL,
8580         },
8581 };
8582
8583 /* *** CONFIGURE UNICAST HASH TABLE *** */
8584 struct cmd_set_uc_hash_table {
8585         cmdline_fixed_string_t set;
8586         cmdline_fixed_string_t port;
8587         portid_t port_id;
8588         cmdline_fixed_string_t what;
8589         struct rte_ether_addr address;
8590         cmdline_fixed_string_t mode;
8591 };
8592
8593 static void
8594 cmd_set_uc_hash_parsed(void *parsed_result,
8595                        __rte_unused struct cmdline *cl,
8596                        __rte_unused void *data)
8597 {
8598         int ret=0;
8599         struct cmd_set_uc_hash_table *res = parsed_result;
8600
8601         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8602
8603         if (strcmp(res->what, "uta") == 0)
8604                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8605                                                 &res->address,(uint8_t)is_on);
8606         if (ret < 0)
8607                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8608
8609 }
8610
8611 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8612         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8613                                  set, "set");
8614 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8615         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8616                                  port, "port");
8617 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8618         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8619                               port_id, UINT16);
8620 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8621         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8622                                  what, "uta");
8623 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8624         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8625                                 address);
8626 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8627         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8628                                  mode, "on#off");
8629
8630 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8631         .f = cmd_set_uc_hash_parsed,
8632         .data = NULL,
8633         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8634         .tokens = {
8635                 (void *)&cmd_set_uc_hash_set,
8636                 (void *)&cmd_set_uc_hash_port,
8637                 (void *)&cmd_set_uc_hash_portid,
8638                 (void *)&cmd_set_uc_hash_what,
8639                 (void *)&cmd_set_uc_hash_mac,
8640                 (void *)&cmd_set_uc_hash_mode,
8641                 NULL,
8642         },
8643 };
8644
8645 struct cmd_set_uc_all_hash_table {
8646         cmdline_fixed_string_t set;
8647         cmdline_fixed_string_t port;
8648         portid_t port_id;
8649         cmdline_fixed_string_t what;
8650         cmdline_fixed_string_t value;
8651         cmdline_fixed_string_t mode;
8652 };
8653
8654 static void
8655 cmd_set_uc_all_hash_parsed(void *parsed_result,
8656                        __rte_unused struct cmdline *cl,
8657                        __rte_unused void *data)
8658 {
8659         int ret=0;
8660         struct cmd_set_uc_all_hash_table *res = parsed_result;
8661
8662         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8663
8664         if ((strcmp(res->what, "uta") == 0) &&
8665                 (strcmp(res->value, "all") == 0))
8666                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8667         if (ret < 0)
8668                 printf("bad unicast hash table parameter,"
8669                         "return code = %d \n", ret);
8670 }
8671
8672 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8673         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8674                                  set, "set");
8675 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8676         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8677                                  port, "port");
8678 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8679         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8680                               port_id, UINT16);
8681 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8682         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8683                                  what, "uta");
8684 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8685         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8686                                 value,"all");
8687 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8688         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8689                                  mode, "on#off");
8690
8691 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8692         .f = cmd_set_uc_all_hash_parsed,
8693         .data = NULL,
8694         .help_str = "set port <port_id> uta all on|off",
8695         .tokens = {
8696                 (void *)&cmd_set_uc_all_hash_set,
8697                 (void *)&cmd_set_uc_all_hash_port,
8698                 (void *)&cmd_set_uc_all_hash_portid,
8699                 (void *)&cmd_set_uc_all_hash_what,
8700                 (void *)&cmd_set_uc_all_hash_value,
8701                 (void *)&cmd_set_uc_all_hash_mode,
8702                 NULL,
8703         },
8704 };
8705
8706 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
8707 struct cmd_set_vf_macvlan_filter {
8708         cmdline_fixed_string_t set;
8709         cmdline_fixed_string_t port;
8710         portid_t port_id;
8711         cmdline_fixed_string_t vf;
8712         uint8_t vf_id;
8713         struct rte_ether_addr address;
8714         cmdline_fixed_string_t filter_type;
8715         cmdline_fixed_string_t mode;
8716 };
8717
8718 static void
8719 cmd_set_vf_macvlan_parsed(void *parsed_result,
8720                        __rte_unused struct cmdline *cl,
8721                        __rte_unused void *data)
8722 {
8723         int is_on, ret = 0;
8724         struct cmd_set_vf_macvlan_filter *res = parsed_result;
8725         struct rte_eth_mac_filter filter;
8726
8727         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
8728
8729         rte_memcpy(&filter.mac_addr, &res->address, RTE_ETHER_ADDR_LEN);
8730
8731         /* set VF MAC filter */
8732         filter.is_vf = 1;
8733
8734         /* set VF ID */
8735         filter.dst_id = res->vf_id;
8736
8737         if (!strcmp(res->filter_type, "exact-mac"))
8738                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
8739         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
8740                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
8741         else if (!strcmp(res->filter_type, "hashmac"))
8742                 filter.filter_type = RTE_MAC_HASH_MATCH;
8743         else if (!strcmp(res->filter_type, "hashmac-vlan"))
8744                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
8745
8746         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8747
8748         if (is_on)
8749                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8750                                         RTE_ETH_FILTER_MACVLAN,
8751                                         RTE_ETH_FILTER_ADD,
8752                                          &filter);
8753         else
8754                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8755                                         RTE_ETH_FILTER_MACVLAN,
8756                                         RTE_ETH_FILTER_DELETE,
8757                                         &filter);
8758
8759         if (ret < 0)
8760                 printf("bad set MAC hash parameter, return code = %d\n", ret);
8761
8762 }
8763
8764 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
8765         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8766                                  set, "set");
8767 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
8768         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8769                                  port, "port");
8770 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
8771         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8772                               port_id, UINT16);
8773 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
8774         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8775                                  vf, "vf");
8776 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
8777         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8778                                 vf_id, UINT8);
8779 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
8780         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8781                                 address);
8782 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
8783         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8784                                 filter_type, "exact-mac#exact-mac-vlan"
8785                                 "#hashmac#hashmac-vlan");
8786 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
8787         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
8788                                  mode, "on#off");
8789
8790 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
8791         .f = cmd_set_vf_macvlan_parsed,
8792         .data = NULL,
8793         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
8794                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
8795                 "Exact match rule: exact match of MAC or MAC and VLAN; "
8796                 "hash match rule: hash match of MAC and exact match of VLAN",
8797         .tokens = {
8798                 (void *)&cmd_set_vf_macvlan_set,
8799                 (void *)&cmd_set_vf_macvlan_port,
8800                 (void *)&cmd_set_vf_macvlan_portid,
8801                 (void *)&cmd_set_vf_macvlan_vf,
8802                 (void *)&cmd_set_vf_macvlan_vf_id,
8803                 (void *)&cmd_set_vf_macvlan_mac,
8804                 (void *)&cmd_set_vf_macvlan_filter_type,
8805                 (void *)&cmd_set_vf_macvlan_mode,
8806                 NULL,
8807         },
8808 };
8809
8810 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8811 struct cmd_set_vf_traffic {
8812         cmdline_fixed_string_t set;
8813         cmdline_fixed_string_t port;
8814         portid_t port_id;
8815         cmdline_fixed_string_t vf;
8816         uint8_t vf_id;
8817         cmdline_fixed_string_t what;
8818         cmdline_fixed_string_t mode;
8819 };
8820
8821 static void
8822 cmd_set_vf_traffic_parsed(void *parsed_result,
8823                        __rte_unused struct cmdline *cl,
8824                        __rte_unused void *data)
8825 {
8826         struct cmd_set_vf_traffic *res = parsed_result;
8827         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8828         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8829
8830         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8831 }
8832
8833 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8834         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8835                                  set, "set");
8836 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8837         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8838                                  port, "port");
8839 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8840         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8841                               port_id, UINT16);
8842 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8843         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8844                                  vf, "vf");
8845 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8846         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8847                               vf_id, UINT8);
8848 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8849         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8850                                  what, "tx#rx");
8851 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8852         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8853                                  mode, "on#off");
8854
8855 cmdline_parse_inst_t cmd_set_vf_traffic = {
8856         .f = cmd_set_vf_traffic_parsed,
8857         .data = NULL,
8858         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8859         .tokens = {
8860                 (void *)&cmd_setvf_traffic_set,
8861                 (void *)&cmd_setvf_traffic_port,
8862                 (void *)&cmd_setvf_traffic_portid,
8863                 (void *)&cmd_setvf_traffic_vf,
8864                 (void *)&cmd_setvf_traffic_vfid,
8865                 (void *)&cmd_setvf_traffic_what,
8866                 (void *)&cmd_setvf_traffic_mode,
8867                 NULL,
8868         },
8869 };
8870
8871 /* *** CONFIGURE VF RECEIVE MODE *** */
8872 struct cmd_set_vf_rxmode {
8873         cmdline_fixed_string_t set;
8874         cmdline_fixed_string_t port;
8875         portid_t port_id;
8876         cmdline_fixed_string_t vf;
8877         uint8_t vf_id;
8878         cmdline_fixed_string_t what;
8879         cmdline_fixed_string_t mode;
8880         cmdline_fixed_string_t on;
8881 };
8882
8883 static void
8884 cmd_set_vf_rxmode_parsed(void *parsed_result,
8885                        __rte_unused struct cmdline *cl,
8886                        __rte_unused void *data)
8887 {
8888         int ret = -ENOTSUP;
8889         uint16_t vf_rxmode = 0;
8890         struct cmd_set_vf_rxmode *res = parsed_result;
8891
8892         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8893         if (!strcmp(res->what,"rxmode")) {
8894                 if (!strcmp(res->mode, "AUPE"))
8895                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8896                 else if (!strcmp(res->mode, "ROPE"))
8897                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8898                 else if (!strcmp(res->mode, "BAM"))
8899                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8900                 else if (!strncmp(res->mode, "MPE",3))
8901                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8902         }
8903
8904         RTE_SET_USED(is_on);
8905
8906 #ifdef RTE_LIBRTE_IXGBE_PMD
8907         if (ret == -ENOTSUP)
8908                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8909                                                   vf_rxmode, (uint8_t)is_on);
8910 #endif
8911 #ifdef RTE_LIBRTE_BNXT_PMD
8912         if (ret == -ENOTSUP)
8913                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8914                                                  vf_rxmode, (uint8_t)is_on);
8915 #endif
8916         if (ret < 0)
8917                 printf("bad VF receive mode parameter, return code = %d \n",
8918                 ret);
8919 }
8920
8921 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8922         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8923                                  set, "set");
8924 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8925         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8926                                  port, "port");
8927 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8928         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8929                               port_id, UINT16);
8930 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8931         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8932                                  vf, "vf");
8933 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8934         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8935                               vf_id, UINT8);
8936 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8937         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8938                                  what, "rxmode");
8939 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8940         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8941                                  mode, "AUPE#ROPE#BAM#MPE");
8942 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8943         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8944                                  on, "on#off");
8945
8946 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8947         .f = cmd_set_vf_rxmode_parsed,
8948         .data = NULL,
8949         .help_str = "set port <port_id> vf <vf_id> rxmode "
8950                 "AUPE|ROPE|BAM|MPE on|off",
8951         .tokens = {
8952                 (void *)&cmd_set_vf_rxmode_set,
8953                 (void *)&cmd_set_vf_rxmode_port,
8954                 (void *)&cmd_set_vf_rxmode_portid,
8955                 (void *)&cmd_set_vf_rxmode_vf,
8956                 (void *)&cmd_set_vf_rxmode_vfid,
8957                 (void *)&cmd_set_vf_rxmode_what,
8958                 (void *)&cmd_set_vf_rxmode_mode,
8959                 (void *)&cmd_set_vf_rxmode_on,
8960                 NULL,
8961         },
8962 };
8963
8964 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8965 struct cmd_vf_mac_addr_result {
8966         cmdline_fixed_string_t mac_addr_cmd;
8967         cmdline_fixed_string_t what;
8968         cmdline_fixed_string_t port;
8969         uint16_t port_num;
8970         cmdline_fixed_string_t vf;
8971         uint8_t vf_num;
8972         struct rte_ether_addr address;
8973 };
8974
8975 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8976                 __rte_unused struct cmdline *cl,
8977                 __rte_unused void *data)
8978 {
8979         struct cmd_vf_mac_addr_result *res = parsed_result;
8980         int ret = -ENOTSUP;
8981
8982         if (strcmp(res->what, "add") != 0)
8983                 return;
8984
8985 #ifdef RTE_LIBRTE_I40E_PMD
8986         if (ret == -ENOTSUP)
8987                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8988                                                    &res->address);
8989 #endif
8990 #ifdef RTE_LIBRTE_BNXT_PMD
8991         if (ret == -ENOTSUP)
8992                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8993                                                 res->vf_num);
8994 #endif
8995
8996         if(ret < 0)
8997                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8998
8999 }
9000
9001 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
9002         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9003                                 mac_addr_cmd,"mac_addr");
9004 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
9005         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9006                                 what,"add");
9007 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
9008         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9009                                 port,"port");
9010 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
9011         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9012                                 port_num, UINT16);
9013 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
9014         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
9015                                 vf,"vf");
9016 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
9017         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
9018                                 vf_num, UINT8);
9019 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
9020         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
9021                                 address);
9022
9023 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
9024         .f = cmd_vf_mac_addr_parsed,
9025         .data = (void *)0,
9026         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
9027                 "Add MAC address filtering for a VF on port_id",
9028         .tokens = {
9029                 (void *)&cmd_vf_mac_addr_cmd,
9030                 (void *)&cmd_vf_mac_addr_what,
9031                 (void *)&cmd_vf_mac_addr_port,
9032                 (void *)&cmd_vf_mac_addr_portnum,
9033                 (void *)&cmd_vf_mac_addr_vf,
9034                 (void *)&cmd_vf_mac_addr_vfnum,
9035                 (void *)&cmd_vf_mac_addr_addr,
9036                 NULL,
9037         },
9038 };
9039
9040 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
9041 struct cmd_vf_rx_vlan_filter {
9042         cmdline_fixed_string_t rx_vlan;
9043         cmdline_fixed_string_t what;
9044         uint16_t vlan_id;
9045         cmdline_fixed_string_t port;
9046         portid_t port_id;
9047         cmdline_fixed_string_t vf;
9048         uint64_t vf_mask;
9049 };
9050
9051 static void
9052 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
9053                           __rte_unused struct cmdline *cl,
9054                           __rte_unused void *data)
9055 {
9056         struct cmd_vf_rx_vlan_filter *res = parsed_result;
9057         int ret = -ENOTSUP;
9058
9059         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
9060
9061 #ifdef RTE_LIBRTE_IXGBE_PMD
9062         if (ret == -ENOTSUP)
9063                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
9064                                 res->vlan_id, res->vf_mask, is_add);
9065 #endif
9066 #ifdef RTE_LIBRTE_I40E_PMD
9067         if (ret == -ENOTSUP)
9068                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
9069                                 res->vlan_id, res->vf_mask, is_add);
9070 #endif
9071 #ifdef RTE_LIBRTE_BNXT_PMD
9072         if (ret == -ENOTSUP)
9073                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
9074                                 res->vlan_id, res->vf_mask, is_add);
9075 #endif
9076
9077         switch (ret) {
9078         case 0:
9079                 break;
9080         case -EINVAL:
9081                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
9082                                 res->vlan_id, res->vf_mask);
9083                 break;
9084         case -ENODEV:
9085                 printf("invalid port_id %d\n", res->port_id);
9086                 break;
9087         case -ENOTSUP:
9088                 printf("function not implemented or supported\n");
9089                 break;
9090         default:
9091                 printf("programming error: (%s)\n", strerror(-ret));
9092         }
9093 }
9094
9095 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
9096         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9097                                  rx_vlan, "rx_vlan");
9098 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
9099         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9100                                  what, "add#rm");
9101 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
9102         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9103                               vlan_id, UINT16);
9104 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
9105         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9106                                  port, "port");
9107 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
9108         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9109                               port_id, UINT16);
9110 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
9111         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9112                                  vf, "vf");
9113 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
9114         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
9115                               vf_mask, UINT64);
9116
9117 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
9118         .f = cmd_vf_rx_vlan_filter_parsed,
9119         .data = NULL,
9120         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9121                 "(vf_mask = hexadecimal VF mask)",
9122         .tokens = {
9123                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9124                 (void *)&cmd_vf_rx_vlan_filter_what,
9125                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9126                 (void *)&cmd_vf_rx_vlan_filter_port,
9127                 (void *)&cmd_vf_rx_vlan_filter_portid,
9128                 (void *)&cmd_vf_rx_vlan_filter_vf,
9129                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9130                 NULL,
9131         },
9132 };
9133
9134 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9135 struct cmd_queue_rate_limit_result {
9136         cmdline_fixed_string_t set;
9137         cmdline_fixed_string_t port;
9138         uint16_t port_num;
9139         cmdline_fixed_string_t queue;
9140         uint8_t queue_num;
9141         cmdline_fixed_string_t rate;
9142         uint16_t rate_num;
9143 };
9144
9145 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9146                 __rte_unused struct cmdline *cl,
9147                 __rte_unused void *data)
9148 {
9149         struct cmd_queue_rate_limit_result *res = parsed_result;
9150         int ret = 0;
9151
9152         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9153                 && (strcmp(res->queue, "queue") == 0)
9154                 && (strcmp(res->rate, "rate") == 0))
9155                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9156                                         res->rate_num);
9157         if (ret < 0)
9158                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9159
9160 }
9161
9162 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9163         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9164                                 set, "set");
9165 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9166         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9167                                 port, "port");
9168 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9169         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9170                                 port_num, UINT16);
9171 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9172         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9173                                 queue, "queue");
9174 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9175         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9176                                 queue_num, UINT8);
9177 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9178         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9179                                 rate, "rate");
9180 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9181         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9182                                 rate_num, UINT16);
9183
9184 cmdline_parse_inst_t cmd_queue_rate_limit = {
9185         .f = cmd_queue_rate_limit_parsed,
9186         .data = (void *)0,
9187         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9188                 "Set rate limit for a queue on port_id",
9189         .tokens = {
9190                 (void *)&cmd_queue_rate_limit_set,
9191                 (void *)&cmd_queue_rate_limit_port,
9192                 (void *)&cmd_queue_rate_limit_portnum,
9193                 (void *)&cmd_queue_rate_limit_queue,
9194                 (void *)&cmd_queue_rate_limit_queuenum,
9195                 (void *)&cmd_queue_rate_limit_rate,
9196                 (void *)&cmd_queue_rate_limit_ratenum,
9197                 NULL,
9198         },
9199 };
9200
9201 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9202 struct cmd_vf_rate_limit_result {
9203         cmdline_fixed_string_t set;
9204         cmdline_fixed_string_t port;
9205         uint16_t port_num;
9206         cmdline_fixed_string_t vf;
9207         uint8_t vf_num;
9208         cmdline_fixed_string_t rate;
9209         uint16_t rate_num;
9210         cmdline_fixed_string_t q_msk;
9211         uint64_t q_msk_val;
9212 };
9213
9214 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9215                 __rte_unused struct cmdline *cl,
9216                 __rte_unused void *data)
9217 {
9218         struct cmd_vf_rate_limit_result *res = parsed_result;
9219         int ret = 0;
9220
9221         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9222                 && (strcmp(res->vf, "vf") == 0)
9223                 && (strcmp(res->rate, "rate") == 0)
9224                 && (strcmp(res->q_msk, "queue_mask") == 0))
9225                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9226                                         res->rate_num, res->q_msk_val);
9227         if (ret < 0)
9228                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9229
9230 }
9231
9232 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9233         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9234                                 set, "set");
9235 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9236         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9237                                 port, "port");
9238 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9239         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9240                                 port_num, UINT16);
9241 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9242         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9243                                 vf, "vf");
9244 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9245         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9246                                 vf_num, UINT8);
9247 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9248         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9249                                 rate, "rate");
9250 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9251         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9252                                 rate_num, UINT16);
9253 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9254         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9255                                 q_msk, "queue_mask");
9256 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9257         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9258                                 q_msk_val, UINT64);
9259
9260 cmdline_parse_inst_t cmd_vf_rate_limit = {
9261         .f = cmd_vf_rate_limit_parsed,
9262         .data = (void *)0,
9263         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9264                 "queue_mask <queue_mask_value>: "
9265                 "Set rate limit for queues of VF on port_id",
9266         .tokens = {
9267                 (void *)&cmd_vf_rate_limit_set,
9268                 (void *)&cmd_vf_rate_limit_port,
9269                 (void *)&cmd_vf_rate_limit_portnum,
9270                 (void *)&cmd_vf_rate_limit_vf,
9271                 (void *)&cmd_vf_rate_limit_vfnum,
9272                 (void *)&cmd_vf_rate_limit_rate,
9273                 (void *)&cmd_vf_rate_limit_ratenum,
9274                 (void *)&cmd_vf_rate_limit_q_msk,
9275                 (void *)&cmd_vf_rate_limit_q_msk_val,
9276                 NULL,
9277         },
9278 };
9279
9280 /* *** ADD TUNNEL FILTER OF A PORT *** */
9281 struct cmd_tunnel_filter_result {
9282         cmdline_fixed_string_t cmd;
9283         cmdline_fixed_string_t what;
9284         portid_t port_id;
9285         struct rte_ether_addr outer_mac;
9286         struct rte_ether_addr inner_mac;
9287         cmdline_ipaddr_t ip_value;
9288         uint16_t inner_vlan;
9289         cmdline_fixed_string_t tunnel_type;
9290         cmdline_fixed_string_t filter_type;
9291         uint32_t tenant_id;
9292         uint16_t queue_num;
9293 };
9294
9295 static void
9296 cmd_tunnel_filter_parsed(void *parsed_result,
9297                           __rte_unused struct cmdline *cl,
9298                           __rte_unused void *data)
9299 {
9300         struct cmd_tunnel_filter_result *res = parsed_result;
9301         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
9302         int ret = 0;
9303
9304         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
9305
9306         rte_ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
9307         rte_ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
9308         tunnel_filter_conf.inner_vlan = res->inner_vlan;
9309
9310         if (res->ip_value.family == AF_INET) {
9311                 tunnel_filter_conf.ip_addr.ipv4_addr =
9312                         res->ip_value.addr.ipv4.s_addr;
9313                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
9314         } else {
9315                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
9316                         &(res->ip_value.addr.ipv6),
9317                         sizeof(struct in6_addr));
9318                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
9319         }
9320
9321         if (!strcmp(res->filter_type, "imac-ivlan"))
9322                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
9323         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
9324                 tunnel_filter_conf.filter_type =
9325                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
9326         else if (!strcmp(res->filter_type, "imac-tenid"))
9327                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
9328         else if (!strcmp(res->filter_type, "imac"))
9329                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
9330         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
9331                 tunnel_filter_conf.filter_type =
9332                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
9333         else if (!strcmp(res->filter_type, "oip"))
9334                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
9335         else if (!strcmp(res->filter_type, "iip"))
9336                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
9337         else {
9338                 printf("The filter type is not supported");
9339                 return;
9340         }
9341
9342         if (!strcmp(res->tunnel_type, "vxlan"))
9343                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
9344         else if (!strcmp(res->tunnel_type, "vxlan-gpe"))
9345                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9346         else if (!strcmp(res->tunnel_type, "nvgre"))
9347                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
9348         else if (!strcmp(res->tunnel_type, "ipingre"))
9349                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
9350         else {
9351                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
9352                 return;
9353         }
9354
9355         tunnel_filter_conf.tenant_id = res->tenant_id;
9356         tunnel_filter_conf.queue_id = res->queue_num;
9357         if (!strcmp(res->what, "add"))
9358                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9359                                         RTE_ETH_FILTER_TUNNEL,
9360                                         RTE_ETH_FILTER_ADD,
9361                                         &tunnel_filter_conf);
9362         else
9363                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9364                                         RTE_ETH_FILTER_TUNNEL,
9365                                         RTE_ETH_FILTER_DELETE,
9366                                         &tunnel_filter_conf);
9367         if (ret < 0)
9368                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
9369                                 strerror(-ret));
9370
9371 }
9372 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
9373         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9374         cmd, "tunnel_filter");
9375 cmdline_parse_token_string_t cmd_tunnel_filter_what =
9376         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9377         what, "add#rm");
9378 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
9379         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9380         port_id, UINT16);
9381 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
9382         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9383         outer_mac);
9384 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
9385         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9386         inner_mac);
9387 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
9388         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9389         inner_vlan, UINT16);
9390 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
9391         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
9392         ip_value);
9393 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
9394         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9395         tunnel_type, "vxlan#nvgre#ipingre#vxlan-gpe");
9396
9397 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
9398         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
9399         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
9400                 "imac#omac-imac-tenid");
9401 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
9402         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9403         tenant_id, UINT32);
9404 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
9405         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
9406         queue_num, UINT16);
9407
9408 cmdline_parse_inst_t cmd_tunnel_filter = {
9409         .f = cmd_tunnel_filter_parsed,
9410         .data = (void *)0,
9411         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
9412                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
9413                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
9414                 "<queue_id>: Add/Rm tunnel filter of a port",
9415         .tokens = {
9416                 (void *)&cmd_tunnel_filter_cmd,
9417                 (void *)&cmd_tunnel_filter_what,
9418                 (void *)&cmd_tunnel_filter_port_id,
9419                 (void *)&cmd_tunnel_filter_outer_mac,
9420                 (void *)&cmd_tunnel_filter_inner_mac,
9421                 (void *)&cmd_tunnel_filter_ip_value,
9422                 (void *)&cmd_tunnel_filter_innner_vlan,
9423                 (void *)&cmd_tunnel_filter_tunnel_type,
9424                 (void *)&cmd_tunnel_filter_filter_type,
9425                 (void *)&cmd_tunnel_filter_tenant_id,
9426                 (void *)&cmd_tunnel_filter_queue_num,
9427                 NULL,
9428         },
9429 };
9430
9431 /* *** CONFIGURE TUNNEL UDP PORT *** */
9432 struct cmd_tunnel_udp_config {
9433         cmdline_fixed_string_t cmd;
9434         cmdline_fixed_string_t what;
9435         uint16_t udp_port;
9436         portid_t port_id;
9437 };
9438
9439 static void
9440 cmd_tunnel_udp_config_parsed(void *parsed_result,
9441                           __rte_unused struct cmdline *cl,
9442                           __rte_unused void *data)
9443 {
9444         struct cmd_tunnel_udp_config *res = parsed_result;
9445         struct rte_eth_udp_tunnel tunnel_udp;
9446         int ret;
9447
9448         tunnel_udp.udp_port = res->udp_port;
9449
9450         if (!strcmp(res->cmd, "rx_vxlan_port"))
9451                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9452
9453         if (!strcmp(res->what, "add"))
9454                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9455                                                       &tunnel_udp);
9456         else
9457                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9458                                                          &tunnel_udp);
9459
9460         if (ret < 0)
9461                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9462 }
9463
9464 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9465         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9466                                 cmd, "rx_vxlan_port");
9467 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9468         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9469                                 what, "add#rm");
9470 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9471         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9472                                 udp_port, UINT16);
9473 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9474         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9475                                 port_id, UINT16);
9476
9477 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9478         .f = cmd_tunnel_udp_config_parsed,
9479         .data = (void *)0,
9480         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9481                 "Add/Remove a tunneling UDP port filter",
9482         .tokens = {
9483                 (void *)&cmd_tunnel_udp_config_cmd,
9484                 (void *)&cmd_tunnel_udp_config_what,
9485                 (void *)&cmd_tunnel_udp_config_udp_port,
9486                 (void *)&cmd_tunnel_udp_config_port_id,
9487                 NULL,
9488         },
9489 };
9490
9491 struct cmd_config_tunnel_udp_port {
9492         cmdline_fixed_string_t port;
9493         cmdline_fixed_string_t config;
9494         portid_t port_id;
9495         cmdline_fixed_string_t udp_tunnel_port;
9496         cmdline_fixed_string_t action;
9497         cmdline_fixed_string_t tunnel_type;
9498         uint16_t udp_port;
9499 };
9500
9501 static void
9502 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9503                                __rte_unused struct cmdline *cl,
9504                                __rte_unused void *data)
9505 {
9506         struct cmd_config_tunnel_udp_port *res = parsed_result;
9507         struct rte_eth_udp_tunnel tunnel_udp;
9508         int ret = 0;
9509
9510         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9511                 return;
9512
9513         tunnel_udp.udp_port = res->udp_port;
9514
9515         if (!strcmp(res->tunnel_type, "vxlan")) {
9516                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9517         } else if (!strcmp(res->tunnel_type, "geneve")) {
9518                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9519         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9520                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9521         } else {
9522                 printf("Invalid tunnel type\n");
9523                 return;
9524         }
9525
9526         if (!strcmp(res->action, "add"))
9527                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9528                                                       &tunnel_udp);
9529         else
9530                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9531                                                          &tunnel_udp);
9532
9533         if (ret < 0)
9534                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9535 }
9536
9537 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9538         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9539                                  "port");
9540 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9541         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9542                                  "config");
9543 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9544         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9545                               UINT16);
9546 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9547         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9548                                  udp_tunnel_port,
9549                                  "udp_tunnel_port");
9550 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9551         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9552                                  "add#rm");
9553 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9554         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9555                                  "vxlan#geneve#vxlan-gpe");
9556 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9557         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9558                               UINT16);
9559
9560 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9561         .f = cmd_cfg_tunnel_udp_port_parsed,
9562         .data = NULL,
9563         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9564         .tokens = {
9565                 (void *)&cmd_config_tunnel_udp_port_port,
9566                 (void *)&cmd_config_tunnel_udp_port_config,
9567                 (void *)&cmd_config_tunnel_udp_port_port_id,
9568                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9569                 (void *)&cmd_config_tunnel_udp_port_action,
9570                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9571                 (void *)&cmd_config_tunnel_udp_port_value,
9572                 NULL,
9573         },
9574 };
9575
9576 /* *** GLOBAL CONFIG *** */
9577 struct cmd_global_config_result {
9578         cmdline_fixed_string_t cmd;
9579         portid_t port_id;
9580         cmdline_fixed_string_t cfg_type;
9581         uint8_t len;
9582 };
9583
9584 static void
9585 cmd_global_config_parsed(void *parsed_result,
9586                          __rte_unused struct cmdline *cl,
9587                          __rte_unused void *data)
9588 {
9589         struct cmd_global_config_result *res = parsed_result;
9590         struct rte_eth_global_cfg conf;
9591         int ret;
9592
9593         memset(&conf, 0, sizeof(conf));
9594         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9595         conf.cfg.gre_key_len = res->len;
9596         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9597                                       RTE_ETH_FILTER_SET, &conf);
9598 #ifdef RTE_LIBRTE_I40E_PMD
9599         if (ret == -ENOTSUP)
9600                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9601 #endif
9602         if (ret != 0)
9603                 printf("Global config error\n");
9604 }
9605
9606 cmdline_parse_token_string_t cmd_global_config_cmd =
9607         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9608                 "global_config");
9609 cmdline_parse_token_num_t cmd_global_config_port_id =
9610         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9611                                UINT16);
9612 cmdline_parse_token_string_t cmd_global_config_type =
9613         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9614                 cfg_type, "gre-key-len");
9615 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9616         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9617                 len, UINT8);
9618
9619 cmdline_parse_inst_t cmd_global_config = {
9620         .f = cmd_global_config_parsed,
9621         .data = (void *)NULL,
9622         .help_str = "global_config <port_id> gre-key-len <key_len>",
9623         .tokens = {
9624                 (void *)&cmd_global_config_cmd,
9625                 (void *)&cmd_global_config_port_id,
9626                 (void *)&cmd_global_config_type,
9627                 (void *)&cmd_global_config_gre_key_len,
9628                 NULL,
9629         },
9630 };
9631
9632 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9633 struct cmd_set_mirror_mask_result {
9634         cmdline_fixed_string_t set;
9635         cmdline_fixed_string_t port;
9636         portid_t port_id;
9637         cmdline_fixed_string_t mirror;
9638         uint8_t rule_id;
9639         cmdline_fixed_string_t what;
9640         cmdline_fixed_string_t value;
9641         cmdline_fixed_string_t dstpool;
9642         uint8_t dstpool_id;
9643         cmdline_fixed_string_t on;
9644 };
9645
9646 cmdline_parse_token_string_t cmd_mirror_mask_set =
9647         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9648                                 set, "set");
9649 cmdline_parse_token_string_t cmd_mirror_mask_port =
9650         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9651                                 port, "port");
9652 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9653         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9654                                 port_id, UINT16);
9655 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9656         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9657                                 mirror, "mirror-rule");
9658 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9659         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9660                                 rule_id, UINT8);
9661 cmdline_parse_token_string_t cmd_mirror_mask_what =
9662         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9663                                 what, "pool-mirror-up#pool-mirror-down"
9664                                       "#vlan-mirror");
9665 cmdline_parse_token_string_t cmd_mirror_mask_value =
9666         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9667                                 value, NULL);
9668 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9669         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9670                                 dstpool, "dst-pool");
9671 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9672         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9673                                 dstpool_id, UINT8);
9674 cmdline_parse_token_string_t cmd_mirror_mask_on =
9675         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9676                                 on, "on#off");
9677
9678 static void
9679 cmd_set_mirror_mask_parsed(void *parsed_result,
9680                        __rte_unused struct cmdline *cl,
9681                        __rte_unused void *data)
9682 {
9683         int ret,nb_item,i;
9684         struct cmd_set_mirror_mask_result *res = parsed_result;
9685         struct rte_eth_mirror_conf mr_conf;
9686
9687         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9688
9689         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9690
9691         mr_conf.dst_pool = res->dstpool_id;
9692
9693         if (!strcmp(res->what, "pool-mirror-up")) {
9694                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9695                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9696         } else if (!strcmp(res->what, "pool-mirror-down")) {
9697                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9698                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9699         } else if (!strcmp(res->what, "vlan-mirror")) {
9700                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9701                 nb_item = parse_item_list(res->value, "vlan",
9702                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9703                 if (nb_item <= 0)
9704                         return;
9705
9706                 for (i = 0; i < nb_item; i++) {
9707                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9708                                 printf("Invalid vlan_id: must be < 4096\n");
9709                                 return;
9710                         }
9711
9712                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9713                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9714                 }
9715         }
9716
9717         if (!strcmp(res->on, "on"))
9718                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9719                                                 res->rule_id, 1);
9720         else
9721                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9722                                                 res->rule_id, 0);
9723         if (ret < 0)
9724                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9725 }
9726
9727 cmdline_parse_inst_t cmd_set_mirror_mask = {
9728                 .f = cmd_set_mirror_mask_parsed,
9729                 .data = NULL,
9730                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9731                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9732                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9733                 .tokens = {
9734                         (void *)&cmd_mirror_mask_set,
9735                         (void *)&cmd_mirror_mask_port,
9736                         (void *)&cmd_mirror_mask_portid,
9737                         (void *)&cmd_mirror_mask_mirror,
9738                         (void *)&cmd_mirror_mask_ruleid,
9739                         (void *)&cmd_mirror_mask_what,
9740                         (void *)&cmd_mirror_mask_value,
9741                         (void *)&cmd_mirror_mask_dstpool,
9742                         (void *)&cmd_mirror_mask_poolid,
9743                         (void *)&cmd_mirror_mask_on,
9744                         NULL,
9745                 },
9746 };
9747
9748 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9749 struct cmd_set_mirror_link_result {
9750         cmdline_fixed_string_t set;
9751         cmdline_fixed_string_t port;
9752         portid_t port_id;
9753         cmdline_fixed_string_t mirror;
9754         uint8_t rule_id;
9755         cmdline_fixed_string_t what;
9756         cmdline_fixed_string_t dstpool;
9757         uint8_t dstpool_id;
9758         cmdline_fixed_string_t on;
9759 };
9760
9761 cmdline_parse_token_string_t cmd_mirror_link_set =
9762         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9763                                  set, "set");
9764 cmdline_parse_token_string_t cmd_mirror_link_port =
9765         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9766                                 port, "port");
9767 cmdline_parse_token_num_t cmd_mirror_link_portid =
9768         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9769                                 port_id, UINT16);
9770 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9771         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9772                                 mirror, "mirror-rule");
9773 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9774         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9775                             rule_id, UINT8);
9776 cmdline_parse_token_string_t cmd_mirror_link_what =
9777         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9778                                 what, "uplink-mirror#downlink-mirror");
9779 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9780         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9781                                 dstpool, "dst-pool");
9782 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9783         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9784                                 dstpool_id, UINT8);
9785 cmdline_parse_token_string_t cmd_mirror_link_on =
9786         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9787                                 on, "on#off");
9788
9789 static void
9790 cmd_set_mirror_link_parsed(void *parsed_result,
9791                        __rte_unused struct cmdline *cl,
9792                        __rte_unused void *data)
9793 {
9794         int ret;
9795         struct cmd_set_mirror_link_result *res = parsed_result;
9796         struct rte_eth_mirror_conf mr_conf;
9797
9798         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9799         if (!strcmp(res->what, "uplink-mirror"))
9800                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9801         else
9802                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9803
9804         mr_conf.dst_pool = res->dstpool_id;
9805
9806         if (!strcmp(res->on, "on"))
9807                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9808                                                 res->rule_id, 1);
9809         else
9810                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9811                                                 res->rule_id, 0);
9812
9813         /* check the return value and print it if is < 0 */
9814         if (ret < 0)
9815                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9816
9817 }
9818
9819 cmdline_parse_inst_t cmd_set_mirror_link = {
9820                 .f = cmd_set_mirror_link_parsed,
9821                 .data = NULL,
9822                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9823                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9824                 .tokens = {
9825                         (void *)&cmd_mirror_link_set,
9826                         (void *)&cmd_mirror_link_port,
9827                         (void *)&cmd_mirror_link_portid,
9828                         (void *)&cmd_mirror_link_mirror,
9829                         (void *)&cmd_mirror_link_ruleid,
9830                         (void *)&cmd_mirror_link_what,
9831                         (void *)&cmd_mirror_link_dstpool,
9832                         (void *)&cmd_mirror_link_poolid,
9833                         (void *)&cmd_mirror_link_on,
9834                         NULL,
9835                 },
9836 };
9837
9838 /* *** RESET VM MIRROR RULE *** */
9839 struct cmd_rm_mirror_rule_result {
9840         cmdline_fixed_string_t reset;
9841         cmdline_fixed_string_t port;
9842         portid_t port_id;
9843         cmdline_fixed_string_t mirror;
9844         uint8_t rule_id;
9845 };
9846
9847 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9848         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9849                                  reset, "reset");
9850 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9851         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9852                                 port, "port");
9853 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9854         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9855                                 port_id, UINT16);
9856 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9857         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9858                                 mirror, "mirror-rule");
9859 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9860         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9861                                 rule_id, UINT8);
9862
9863 static void
9864 cmd_reset_mirror_rule_parsed(void *parsed_result,
9865                        __rte_unused struct cmdline *cl,
9866                        __rte_unused void *data)
9867 {
9868         int ret;
9869         struct cmd_set_mirror_link_result *res = parsed_result;
9870         /* check rule_id */
9871         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9872         if(ret < 0)
9873                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9874 }
9875
9876 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9877                 .f = cmd_reset_mirror_rule_parsed,
9878                 .data = NULL,
9879                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9880                 .tokens = {
9881                         (void *)&cmd_rm_mirror_rule_reset,
9882                         (void *)&cmd_rm_mirror_rule_port,
9883                         (void *)&cmd_rm_mirror_rule_portid,
9884                         (void *)&cmd_rm_mirror_rule_mirror,
9885                         (void *)&cmd_rm_mirror_rule_ruleid,
9886                         NULL,
9887                 },
9888 };
9889
9890 /* ******************************************************************************** */
9891
9892 struct cmd_dump_result {
9893         cmdline_fixed_string_t dump;
9894 };
9895
9896 static void
9897 dump_struct_sizes(void)
9898 {
9899 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9900         DUMP_SIZE(struct rte_mbuf);
9901         DUMP_SIZE(struct rte_mempool);
9902         DUMP_SIZE(struct rte_ring);
9903 #undef DUMP_SIZE
9904 }
9905
9906
9907 /* Dump the socket memory statistics on console */
9908 static void
9909 dump_socket_mem(FILE *f)
9910 {
9911         struct rte_malloc_socket_stats socket_stats;
9912         unsigned int i;
9913         size_t total = 0;
9914         size_t alloc = 0;
9915         size_t free = 0;
9916         unsigned int n_alloc = 0;
9917         unsigned int n_free = 0;
9918         static size_t last_allocs;
9919         static size_t last_total;
9920
9921
9922         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9923                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9924                     !socket_stats.heap_totalsz_bytes)
9925                         continue;
9926                 total += socket_stats.heap_totalsz_bytes;
9927                 alloc += socket_stats.heap_allocsz_bytes;
9928                 free += socket_stats.heap_freesz_bytes;
9929                 n_alloc += socket_stats.alloc_count;
9930                 n_free += socket_stats.free_count;
9931                 fprintf(f,
9932                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9933                         i,
9934                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9935                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9936                         (double)socket_stats.heap_allocsz_bytes * 100 /
9937                         (double)socket_stats.heap_totalsz_bytes,
9938                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9939                         socket_stats.alloc_count,
9940                         socket_stats.free_count);
9941         }
9942         fprintf(f,
9943                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9944                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9945                 (double)alloc * 100 / (double)total,
9946                 (double)free / (1024 * 1024),
9947                 n_alloc, n_free);
9948         if (last_allocs)
9949                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9950                         ((double)total - (double)last_total) / (1024 * 1024),
9951                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9952         last_allocs = alloc;
9953         last_total = total;
9954 }
9955
9956 static void cmd_dump_parsed(void *parsed_result,
9957                             __rte_unused struct cmdline *cl,
9958                             __rte_unused void *data)
9959 {
9960         struct cmd_dump_result *res = parsed_result;
9961
9962         if (!strcmp(res->dump, "dump_physmem"))
9963                 rte_dump_physmem_layout(stdout);
9964         else if (!strcmp(res->dump, "dump_socket_mem"))
9965                 dump_socket_mem(stdout);
9966         else if (!strcmp(res->dump, "dump_memzone"))
9967                 rte_memzone_dump(stdout);
9968         else if (!strcmp(res->dump, "dump_struct_sizes"))
9969                 dump_struct_sizes();
9970         else if (!strcmp(res->dump, "dump_ring"))
9971                 rte_ring_list_dump(stdout);
9972         else if (!strcmp(res->dump, "dump_mempool"))
9973                 rte_mempool_list_dump(stdout);
9974         else if (!strcmp(res->dump, "dump_devargs"))
9975                 rte_devargs_dump(stdout);
9976         else if (!strcmp(res->dump, "dump_log_types"))
9977                 rte_log_dump(stdout);
9978 }
9979
9980 cmdline_parse_token_string_t cmd_dump_dump =
9981         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9982                 "dump_physmem#"
9983                 "dump_memzone#"
9984                 "dump_socket_mem#"
9985                 "dump_struct_sizes#"
9986                 "dump_ring#"
9987                 "dump_mempool#"
9988                 "dump_devargs#"
9989                 "dump_log_types");
9990
9991 cmdline_parse_inst_t cmd_dump = {
9992         .f = cmd_dump_parsed,  /* function to call */
9993         .data = NULL,      /* 2nd arg of func */
9994         .help_str = "Dump status",
9995         .tokens = {        /* token list, NULL terminated */
9996                 (void *)&cmd_dump_dump,
9997                 NULL,
9998         },
9999 };
10000
10001 /* ******************************************************************************** */
10002
10003 struct cmd_dump_one_result {
10004         cmdline_fixed_string_t dump;
10005         cmdline_fixed_string_t name;
10006 };
10007
10008 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
10009                                 __rte_unused void *data)
10010 {
10011         struct cmd_dump_one_result *res = parsed_result;
10012
10013         if (!strcmp(res->dump, "dump_ring")) {
10014                 struct rte_ring *r;
10015                 r = rte_ring_lookup(res->name);
10016                 if (r == NULL) {
10017                         cmdline_printf(cl, "Cannot find ring\n");
10018                         return;
10019                 }
10020                 rte_ring_dump(stdout, r);
10021         } else if (!strcmp(res->dump, "dump_mempool")) {
10022                 struct rte_mempool *mp;
10023                 mp = rte_mempool_lookup(res->name);
10024                 if (mp == NULL) {
10025                         cmdline_printf(cl, "Cannot find mempool\n");
10026                         return;
10027                 }
10028                 rte_mempool_dump(stdout, mp);
10029         }
10030 }
10031
10032 cmdline_parse_token_string_t cmd_dump_one_dump =
10033         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
10034                                  "dump_ring#dump_mempool");
10035
10036 cmdline_parse_token_string_t cmd_dump_one_name =
10037         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
10038
10039 cmdline_parse_inst_t cmd_dump_one = {
10040         .f = cmd_dump_one_parsed,  /* function to call */
10041         .data = NULL,      /* 2nd arg of func */
10042         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
10043         .tokens = {        /* token list, NULL terminated */
10044                 (void *)&cmd_dump_one_dump,
10045                 (void *)&cmd_dump_one_name,
10046                 NULL,
10047         },
10048 };
10049
10050 /* *** Add/Del syn filter *** */
10051 struct cmd_syn_filter_result {
10052         cmdline_fixed_string_t filter;
10053         portid_t port_id;
10054         cmdline_fixed_string_t ops;
10055         cmdline_fixed_string_t priority;
10056         cmdline_fixed_string_t high;
10057         cmdline_fixed_string_t queue;
10058         uint16_t queue_id;
10059 };
10060
10061 static void
10062 cmd_syn_filter_parsed(void *parsed_result,
10063                         __rte_unused struct cmdline *cl,
10064                         __rte_unused void *data)
10065 {
10066         struct cmd_syn_filter_result *res = parsed_result;
10067         struct rte_eth_syn_filter syn_filter;
10068         int ret = 0;
10069
10070         ret = rte_eth_dev_filter_supported(res->port_id,
10071                                         RTE_ETH_FILTER_SYN);
10072         if (ret < 0) {
10073                 printf("syn filter is not supported on port %u.\n",
10074                                 res->port_id);
10075                 return;
10076         }
10077
10078         memset(&syn_filter, 0, sizeof(syn_filter));
10079
10080         if (!strcmp(res->ops, "add")) {
10081                 if (!strcmp(res->high, "high"))
10082                         syn_filter.hig_pri = 1;
10083                 else
10084                         syn_filter.hig_pri = 0;
10085
10086                 syn_filter.queue = res->queue_id;
10087                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10088                                                 RTE_ETH_FILTER_SYN,
10089                                                 RTE_ETH_FILTER_ADD,
10090                                                 &syn_filter);
10091         } else
10092                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10093                                                 RTE_ETH_FILTER_SYN,
10094                                                 RTE_ETH_FILTER_DELETE,
10095                                                 &syn_filter);
10096
10097         if (ret < 0)
10098                 printf("syn filter programming error: (%s)\n",
10099                                 strerror(-ret));
10100 }
10101
10102 cmdline_parse_token_string_t cmd_syn_filter_filter =
10103         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10104         filter, "syn_filter");
10105 cmdline_parse_token_num_t cmd_syn_filter_port_id =
10106         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10107         port_id, UINT16);
10108 cmdline_parse_token_string_t cmd_syn_filter_ops =
10109         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10110         ops, "add#del");
10111 cmdline_parse_token_string_t cmd_syn_filter_priority =
10112         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10113                                 priority, "priority");
10114 cmdline_parse_token_string_t cmd_syn_filter_high =
10115         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10116                                 high, "high#low");
10117 cmdline_parse_token_string_t cmd_syn_filter_queue =
10118         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
10119                                 queue, "queue");
10120 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
10121         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
10122                                 queue_id, UINT16);
10123
10124 cmdline_parse_inst_t cmd_syn_filter = {
10125         .f = cmd_syn_filter_parsed,
10126         .data = NULL,
10127         .help_str = "syn_filter <port_id> add|del priority high|low queue "
10128                 "<queue_id>: Add/Delete syn filter",
10129         .tokens = {
10130                 (void *)&cmd_syn_filter_filter,
10131                 (void *)&cmd_syn_filter_port_id,
10132                 (void *)&cmd_syn_filter_ops,
10133                 (void *)&cmd_syn_filter_priority,
10134                 (void *)&cmd_syn_filter_high,
10135                 (void *)&cmd_syn_filter_queue,
10136                 (void *)&cmd_syn_filter_queue_id,
10137                 NULL,
10138         },
10139 };
10140
10141 /* *** queue region set *** */
10142 struct cmd_queue_region_result {
10143         cmdline_fixed_string_t set;
10144         cmdline_fixed_string_t port;
10145         portid_t port_id;
10146         cmdline_fixed_string_t cmd;
10147         cmdline_fixed_string_t region;
10148         uint8_t  region_id;
10149         cmdline_fixed_string_t queue_start_index;
10150         uint8_t  queue_id;
10151         cmdline_fixed_string_t queue_num;
10152         uint8_t  queue_num_value;
10153 };
10154
10155 static void
10156 cmd_queue_region_parsed(void *parsed_result,
10157                         __rte_unused struct cmdline *cl,
10158                         __rte_unused void *data)
10159 {
10160         struct cmd_queue_region_result *res = parsed_result;
10161         int ret = -ENOTSUP;
10162 #ifdef RTE_LIBRTE_I40E_PMD
10163         struct rte_pmd_i40e_queue_region_conf region_conf;
10164         enum rte_pmd_i40e_queue_region_op op_type;
10165 #endif
10166
10167         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10168                 return;
10169
10170 #ifdef RTE_LIBRTE_I40E_PMD
10171         memset(&region_conf, 0, sizeof(region_conf));
10172         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
10173         region_conf.region_id = res->region_id;
10174         region_conf.queue_num = res->queue_num_value;
10175         region_conf.queue_start_index = res->queue_id;
10176
10177         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10178                                 op_type, &region_conf);
10179 #endif
10180
10181         switch (ret) {
10182         case 0:
10183                 break;
10184         case -ENOTSUP:
10185                 printf("function not implemented or supported\n");
10186                 break;
10187         default:
10188                 printf("queue region config error: (%s)\n", strerror(-ret));
10189         }
10190 }
10191
10192 cmdline_parse_token_string_t cmd_queue_region_set =
10193 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10194                 set, "set");
10195 cmdline_parse_token_string_t cmd_queue_region_port =
10196         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
10197 cmdline_parse_token_num_t cmd_queue_region_port_id =
10198         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10199                                 port_id, UINT16);
10200 cmdline_parse_token_string_t cmd_queue_region_cmd =
10201         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10202                                  cmd, "queue-region");
10203 cmdline_parse_token_string_t cmd_queue_region_id =
10204         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10205                                 region, "region_id");
10206 cmdline_parse_token_num_t cmd_queue_region_index =
10207         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10208                                 region_id, UINT8);
10209 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
10210         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10211                                 queue_start_index, "queue_start_index");
10212 cmdline_parse_token_num_t cmd_queue_region_queue_id =
10213         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10214                                 queue_id, UINT8);
10215 cmdline_parse_token_string_t cmd_queue_region_queue_num =
10216         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
10217                                 queue_num, "queue_num");
10218 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
10219         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
10220                                 queue_num_value, UINT8);
10221
10222 cmdline_parse_inst_t cmd_queue_region = {
10223         .f = cmd_queue_region_parsed,
10224         .data = NULL,
10225         .help_str = "set port <port_id> queue-region region_id <value> "
10226                 "queue_start_index <value> queue_num <value>: Set a queue region",
10227         .tokens = {
10228                 (void *)&cmd_queue_region_set,
10229                 (void *)&cmd_queue_region_port,
10230                 (void *)&cmd_queue_region_port_id,
10231                 (void *)&cmd_queue_region_cmd,
10232                 (void *)&cmd_queue_region_id,
10233                 (void *)&cmd_queue_region_index,
10234                 (void *)&cmd_queue_region_queue_start_index,
10235                 (void *)&cmd_queue_region_queue_id,
10236                 (void *)&cmd_queue_region_queue_num,
10237                 (void *)&cmd_queue_region_queue_num_value,
10238                 NULL,
10239         },
10240 };
10241
10242 /* *** queue region and flowtype set *** */
10243 struct cmd_region_flowtype_result {
10244         cmdline_fixed_string_t set;
10245         cmdline_fixed_string_t port;
10246         portid_t port_id;
10247         cmdline_fixed_string_t cmd;
10248         cmdline_fixed_string_t region;
10249         uint8_t  region_id;
10250         cmdline_fixed_string_t flowtype;
10251         uint8_t  flowtype_id;
10252 };
10253
10254 static void
10255 cmd_region_flowtype_parsed(void *parsed_result,
10256                         __rte_unused struct cmdline *cl,
10257                         __rte_unused void *data)
10258 {
10259         struct cmd_region_flowtype_result *res = parsed_result;
10260         int ret = -ENOTSUP;
10261 #ifdef RTE_LIBRTE_I40E_PMD
10262         struct rte_pmd_i40e_queue_region_conf region_conf;
10263         enum rte_pmd_i40e_queue_region_op op_type;
10264 #endif
10265
10266         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10267                 return;
10268
10269 #ifdef RTE_LIBRTE_I40E_PMD
10270         memset(&region_conf, 0, sizeof(region_conf));
10271
10272         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
10273         region_conf.region_id = res->region_id;
10274         region_conf.hw_flowtype = res->flowtype_id;
10275
10276         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10277                         op_type, &region_conf);
10278 #endif
10279
10280         switch (ret) {
10281         case 0:
10282                 break;
10283         case -ENOTSUP:
10284                 printf("function not implemented or supported\n");
10285                 break;
10286         default:
10287                 printf("region flowtype config error: (%s)\n", strerror(-ret));
10288         }
10289 }
10290
10291 cmdline_parse_token_string_t cmd_region_flowtype_set =
10292 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10293                                 set, "set");
10294 cmdline_parse_token_string_t cmd_region_flowtype_port =
10295         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10296                                 port, "port");
10297 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
10298         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10299                                 port_id, UINT16);
10300 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
10301         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10302                                 cmd, "queue-region");
10303 cmdline_parse_token_string_t cmd_region_flowtype_index =
10304         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10305                                 region, "region_id");
10306 cmdline_parse_token_num_t cmd_region_flowtype_id =
10307         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10308                                 region_id, UINT8);
10309 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
10310         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
10311                                 flowtype, "flowtype");
10312 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
10313         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
10314                                 flowtype_id, UINT8);
10315 cmdline_parse_inst_t cmd_region_flowtype = {
10316         .f = cmd_region_flowtype_parsed,
10317         .data = NULL,
10318         .help_str = "set port <port_id> queue-region region_id <value> "
10319                 "flowtype <value>: Set a flowtype region index",
10320         .tokens = {
10321                 (void *)&cmd_region_flowtype_set,
10322                 (void *)&cmd_region_flowtype_port,
10323                 (void *)&cmd_region_flowtype_port_index,
10324                 (void *)&cmd_region_flowtype_cmd,
10325                 (void *)&cmd_region_flowtype_index,
10326                 (void *)&cmd_region_flowtype_id,
10327                 (void *)&cmd_region_flowtype_flow_index,
10328                 (void *)&cmd_region_flowtype_flow_id,
10329                 NULL,
10330         },
10331 };
10332
10333 /* *** User Priority (UP) to queue region (region_id) set *** */
10334 struct cmd_user_priority_region_result {
10335         cmdline_fixed_string_t set;
10336         cmdline_fixed_string_t port;
10337         portid_t port_id;
10338         cmdline_fixed_string_t cmd;
10339         cmdline_fixed_string_t user_priority;
10340         uint8_t  user_priority_id;
10341         cmdline_fixed_string_t region;
10342         uint8_t  region_id;
10343 };
10344
10345 static void
10346 cmd_user_priority_region_parsed(void *parsed_result,
10347                         __rte_unused struct cmdline *cl,
10348                         __rte_unused void *data)
10349 {
10350         struct cmd_user_priority_region_result *res = parsed_result;
10351         int ret = -ENOTSUP;
10352 #ifdef RTE_LIBRTE_I40E_PMD
10353         struct rte_pmd_i40e_queue_region_conf region_conf;
10354         enum rte_pmd_i40e_queue_region_op op_type;
10355 #endif
10356
10357         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10358                 return;
10359
10360 #ifdef RTE_LIBRTE_I40E_PMD
10361         memset(&region_conf, 0, sizeof(region_conf));
10362         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10363         region_conf.user_priority = res->user_priority_id;
10364         region_conf.region_id = res->region_id;
10365
10366         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10367                                 op_type, &region_conf);
10368 #endif
10369
10370         switch (ret) {
10371         case 0:
10372                 break;
10373         case -ENOTSUP:
10374                 printf("function not implemented or supported\n");
10375                 break;
10376         default:
10377                 printf("user_priority region config error: (%s)\n",
10378                                 strerror(-ret));
10379         }
10380 }
10381
10382 cmdline_parse_token_string_t cmd_user_priority_region_set =
10383         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10384                                 set, "set");
10385 cmdline_parse_token_string_t cmd_user_priority_region_port =
10386         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10387                                 port, "port");
10388 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10389         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10390                                 port_id, UINT16);
10391 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10392         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10393                                 cmd, "queue-region");
10394 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10395         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10396                                 user_priority, "UP");
10397 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10398         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10399                                 user_priority_id, UINT8);
10400 cmdline_parse_token_string_t cmd_user_priority_region_region =
10401         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10402                                 region, "region_id");
10403 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10404         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10405                                 region_id, UINT8);
10406
10407 cmdline_parse_inst_t cmd_user_priority_region = {
10408         .f = cmd_user_priority_region_parsed,
10409         .data = NULL,
10410         .help_str = "set port <port_id> queue-region UP <value> "
10411                 "region_id <value>: Set the mapping of User Priority (UP) "
10412                 "to queue region (region_id) ",
10413         .tokens = {
10414                 (void *)&cmd_user_priority_region_set,
10415                 (void *)&cmd_user_priority_region_port,
10416                 (void *)&cmd_user_priority_region_port_index,
10417                 (void *)&cmd_user_priority_region_cmd,
10418                 (void *)&cmd_user_priority_region_UP,
10419                 (void *)&cmd_user_priority_region_UP_id,
10420                 (void *)&cmd_user_priority_region_region,
10421                 (void *)&cmd_user_priority_region_region_id,
10422                 NULL,
10423         },
10424 };
10425
10426 /* *** flush all queue region related configuration *** */
10427 struct cmd_flush_queue_region_result {
10428         cmdline_fixed_string_t set;
10429         cmdline_fixed_string_t port;
10430         portid_t port_id;
10431         cmdline_fixed_string_t cmd;
10432         cmdline_fixed_string_t flush;
10433         cmdline_fixed_string_t what;
10434 };
10435
10436 static void
10437 cmd_flush_queue_region_parsed(void *parsed_result,
10438                         __rte_unused struct cmdline *cl,
10439                         __rte_unused void *data)
10440 {
10441         struct cmd_flush_queue_region_result *res = parsed_result;
10442         int ret = -ENOTSUP;
10443 #ifdef RTE_LIBRTE_I40E_PMD
10444         struct rte_pmd_i40e_queue_region_conf region_conf;
10445         enum rte_pmd_i40e_queue_region_op op_type;
10446 #endif
10447
10448         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10449                 return;
10450
10451 #ifdef RTE_LIBRTE_I40E_PMD
10452         memset(&region_conf, 0, sizeof(region_conf));
10453
10454         if (strcmp(res->what, "on") == 0)
10455                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10456         else
10457                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10458
10459         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10460                                 op_type, &region_conf);
10461 #endif
10462
10463         switch (ret) {
10464         case 0:
10465                 break;
10466         case -ENOTSUP:
10467                 printf("function not implemented or supported\n");
10468                 break;
10469         default:
10470                 printf("queue region config flush error: (%s)\n",
10471                                 strerror(-ret));
10472         }
10473 }
10474
10475 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10476         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10477                                 set, "set");
10478 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10479         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10480                                 port, "port");
10481 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10482         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10483                                 port_id, UINT16);
10484 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10485         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10486                                 cmd, "queue-region");
10487 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10488         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10489                                 flush, "flush");
10490 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10491         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10492                                 what, "on#off");
10493
10494 cmdline_parse_inst_t cmd_flush_queue_region = {
10495         .f = cmd_flush_queue_region_parsed,
10496         .data = NULL,
10497         .help_str = "set port <port_id> queue-region flush on|off"
10498                 ": flush all queue region related configuration",
10499         .tokens = {
10500                 (void *)&cmd_flush_queue_region_set,
10501                 (void *)&cmd_flush_queue_region_port,
10502                 (void *)&cmd_flush_queue_region_port_index,
10503                 (void *)&cmd_flush_queue_region_cmd,
10504                 (void *)&cmd_flush_queue_region_flush,
10505                 (void *)&cmd_flush_queue_region_what,
10506                 NULL,
10507         },
10508 };
10509
10510 /* *** get all queue region related configuration info *** */
10511 struct cmd_show_queue_region_info {
10512         cmdline_fixed_string_t show;
10513         cmdline_fixed_string_t port;
10514         portid_t port_id;
10515         cmdline_fixed_string_t cmd;
10516 };
10517
10518 static void
10519 cmd_show_queue_region_info_parsed(void *parsed_result,
10520                         __rte_unused struct cmdline *cl,
10521                         __rte_unused void *data)
10522 {
10523         struct cmd_show_queue_region_info *res = parsed_result;
10524         int ret = -ENOTSUP;
10525 #ifdef RTE_LIBRTE_I40E_PMD
10526         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10527         enum rte_pmd_i40e_queue_region_op op_type;
10528 #endif
10529
10530         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10531                 return;
10532
10533 #ifdef RTE_LIBRTE_I40E_PMD
10534         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10535
10536         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10537
10538         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10539                                         op_type, &rte_pmd_regions);
10540
10541         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10542 #endif
10543
10544         switch (ret) {
10545         case 0:
10546                 break;
10547         case -ENOTSUP:
10548                 printf("function not implemented or supported\n");
10549                 break;
10550         default:
10551                 printf("queue region config info show error: (%s)\n",
10552                                 strerror(-ret));
10553         }
10554 }
10555
10556 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10557 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10558                                 show, "show");
10559 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10560         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10561                                 port, "port");
10562 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10563         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10564                                 port_id, UINT16);
10565 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10566         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10567                                 cmd, "queue-region");
10568
10569 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10570         .f = cmd_show_queue_region_info_parsed,
10571         .data = NULL,
10572         .help_str = "show port <port_id> queue-region"
10573                 ": show all queue region related configuration info",
10574         .tokens = {
10575                 (void *)&cmd_show_queue_region_info_get,
10576                 (void *)&cmd_show_queue_region_info_port,
10577                 (void *)&cmd_show_queue_region_info_port_index,
10578                 (void *)&cmd_show_queue_region_info_cmd,
10579                 NULL,
10580         },
10581 };
10582
10583 /* *** ADD/REMOVE A 2tuple FILTER *** */
10584 struct cmd_2tuple_filter_result {
10585         cmdline_fixed_string_t filter;
10586         portid_t port_id;
10587         cmdline_fixed_string_t ops;
10588         cmdline_fixed_string_t dst_port;
10589         uint16_t dst_port_value;
10590         cmdline_fixed_string_t protocol;
10591         uint8_t protocol_value;
10592         cmdline_fixed_string_t mask;
10593         uint8_t  mask_value;
10594         cmdline_fixed_string_t tcp_flags;
10595         uint8_t tcp_flags_value;
10596         cmdline_fixed_string_t priority;
10597         uint8_t  priority_value;
10598         cmdline_fixed_string_t queue;
10599         uint16_t  queue_id;
10600 };
10601
10602 static void
10603 cmd_2tuple_filter_parsed(void *parsed_result,
10604                         __rte_unused struct cmdline *cl,
10605                         __rte_unused void *data)
10606 {
10607         struct rte_eth_ntuple_filter filter;
10608         struct cmd_2tuple_filter_result *res = parsed_result;
10609         int ret = 0;
10610
10611         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10612         if (ret < 0) {
10613                 printf("ntuple filter is not supported on port %u.\n",
10614                         res->port_id);
10615                 return;
10616         }
10617
10618         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10619
10620         filter.flags = RTE_2TUPLE_FLAGS;
10621         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10622         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10623         filter.proto = res->protocol_value;
10624         filter.priority = res->priority_value;
10625         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10626                 printf("nonzero tcp_flags is only meaningful"
10627                         " when protocol is TCP.\n");
10628                 return;
10629         }
10630         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10631                 printf("invalid TCP flags.\n");
10632                 return;
10633         }
10634
10635         if (res->tcp_flags_value != 0) {
10636                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10637                 filter.tcp_flags = res->tcp_flags_value;
10638         }
10639
10640         /* need convert to big endian. */
10641         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10642         filter.queue = res->queue_id;
10643
10644         if (!strcmp(res->ops, "add"))
10645                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10646                                 RTE_ETH_FILTER_NTUPLE,
10647                                 RTE_ETH_FILTER_ADD,
10648                                 &filter);
10649         else
10650                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10651                                 RTE_ETH_FILTER_NTUPLE,
10652                                 RTE_ETH_FILTER_DELETE,
10653                                 &filter);
10654         if (ret < 0)
10655                 printf("2tuple filter programming error: (%s)\n",
10656                         strerror(-ret));
10657
10658 }
10659
10660 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
10661         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10662                                  filter, "2tuple_filter");
10663 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
10664         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10665                                 port_id, UINT16);
10666 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
10667         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10668                                  ops, "add#del");
10669 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
10670         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10671                                 dst_port, "dst_port");
10672 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
10673         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10674                                 dst_port_value, UINT16);
10675 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
10676         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10677                                 protocol, "protocol");
10678 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
10679         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10680                                 protocol_value, UINT8);
10681 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
10682         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10683                                 mask, "mask");
10684 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
10685         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10686                                 mask_value, INT8);
10687 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
10688         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10689                                 tcp_flags, "tcp_flags");
10690 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
10691         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10692                                 tcp_flags_value, UINT8);
10693 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
10694         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10695                                 priority, "priority");
10696 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
10697         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10698                                 priority_value, UINT8);
10699 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
10700         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
10701                                 queue, "queue");
10702 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
10703         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
10704                                 queue_id, UINT16);
10705
10706 cmdline_parse_inst_t cmd_2tuple_filter = {
10707         .f = cmd_2tuple_filter_parsed,
10708         .data = NULL,
10709         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
10710                 "<value> mask <value> tcp_flags <value> priority <value> queue "
10711                 "<queue_id>: Add a 2tuple filter",
10712         .tokens = {
10713                 (void *)&cmd_2tuple_filter_filter,
10714                 (void *)&cmd_2tuple_filter_port_id,
10715                 (void *)&cmd_2tuple_filter_ops,
10716                 (void *)&cmd_2tuple_filter_dst_port,
10717                 (void *)&cmd_2tuple_filter_dst_port_value,
10718                 (void *)&cmd_2tuple_filter_protocol,
10719                 (void *)&cmd_2tuple_filter_protocol_value,
10720                 (void *)&cmd_2tuple_filter_mask,
10721                 (void *)&cmd_2tuple_filter_mask_value,
10722                 (void *)&cmd_2tuple_filter_tcp_flags,
10723                 (void *)&cmd_2tuple_filter_tcp_flags_value,
10724                 (void *)&cmd_2tuple_filter_priority,
10725                 (void *)&cmd_2tuple_filter_priority_value,
10726                 (void *)&cmd_2tuple_filter_queue,
10727                 (void *)&cmd_2tuple_filter_queue_id,
10728                 NULL,
10729         },
10730 };
10731
10732 /* *** ADD/REMOVE A 5tuple FILTER *** */
10733 struct cmd_5tuple_filter_result {
10734         cmdline_fixed_string_t filter;
10735         portid_t port_id;
10736         cmdline_fixed_string_t ops;
10737         cmdline_fixed_string_t dst_ip;
10738         cmdline_ipaddr_t dst_ip_value;
10739         cmdline_fixed_string_t src_ip;
10740         cmdline_ipaddr_t src_ip_value;
10741         cmdline_fixed_string_t dst_port;
10742         uint16_t dst_port_value;
10743         cmdline_fixed_string_t src_port;
10744         uint16_t src_port_value;
10745         cmdline_fixed_string_t protocol;
10746         uint8_t protocol_value;
10747         cmdline_fixed_string_t mask;
10748         uint8_t  mask_value;
10749         cmdline_fixed_string_t tcp_flags;
10750         uint8_t tcp_flags_value;
10751         cmdline_fixed_string_t priority;
10752         uint8_t  priority_value;
10753         cmdline_fixed_string_t queue;
10754         uint16_t  queue_id;
10755 };
10756
10757 static void
10758 cmd_5tuple_filter_parsed(void *parsed_result,
10759                         __rte_unused struct cmdline *cl,
10760                         __rte_unused void *data)
10761 {
10762         struct rte_eth_ntuple_filter filter;
10763         struct cmd_5tuple_filter_result *res = parsed_result;
10764         int ret = 0;
10765
10766         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
10767         if (ret < 0) {
10768                 printf("ntuple filter is not supported on port %u.\n",
10769                         res->port_id);
10770                 return;
10771         }
10772
10773         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
10774
10775         filter.flags = RTE_5TUPLE_FLAGS;
10776         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
10777         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
10778         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
10779         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
10780         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
10781         filter.proto = res->protocol_value;
10782         filter.priority = res->priority_value;
10783         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
10784                 printf("nonzero tcp_flags is only meaningful"
10785                         " when protocol is TCP.\n");
10786                 return;
10787         }
10788         if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
10789                 printf("invalid TCP flags.\n");
10790                 return;
10791         }
10792
10793         if (res->tcp_flags_value != 0) {
10794                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
10795                 filter.tcp_flags = res->tcp_flags_value;
10796         }
10797
10798         if (res->dst_ip_value.family == AF_INET)
10799                 /* no need to convert, already big endian. */
10800                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
10801         else {
10802                 if (filter.dst_ip_mask == 0) {
10803                         printf("can not support ipv6 involved compare.\n");
10804                         return;
10805                 }
10806                 filter.dst_ip = 0;
10807         }
10808
10809         if (res->src_ip_value.family == AF_INET)
10810                 /* no need to convert, already big endian. */
10811                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
10812         else {
10813                 if (filter.src_ip_mask == 0) {
10814                         printf("can not support ipv6 involved compare.\n");
10815                         return;
10816                 }
10817                 filter.src_ip = 0;
10818         }
10819         /* need convert to big endian. */
10820         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
10821         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
10822         filter.queue = res->queue_id;
10823
10824         if (!strcmp(res->ops, "add"))
10825                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10826                                 RTE_ETH_FILTER_NTUPLE,
10827                                 RTE_ETH_FILTER_ADD,
10828                                 &filter);
10829         else
10830                 ret = rte_eth_dev_filter_ctrl(res->port_id,
10831                                 RTE_ETH_FILTER_NTUPLE,
10832                                 RTE_ETH_FILTER_DELETE,
10833                                 &filter);
10834         if (ret < 0)
10835                 printf("5tuple filter programming error: (%s)\n",
10836                         strerror(-ret));
10837 }
10838
10839 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
10840         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10841                                  filter, "5tuple_filter");
10842 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
10843         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10844                                 port_id, UINT16);
10845 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
10846         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10847                                  ops, "add#del");
10848 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
10849         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10850                                 dst_ip, "dst_ip");
10851 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
10852         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10853                                 dst_ip_value);
10854 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
10855         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10856                                 src_ip, "src_ip");
10857 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
10858         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
10859                                 src_ip_value);
10860 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
10861         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10862                                 dst_port, "dst_port");
10863 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
10864         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10865                                 dst_port_value, UINT16);
10866 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
10867         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10868                                 src_port, "src_port");
10869 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
10870         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10871                                 src_port_value, UINT16);
10872 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
10873         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10874                                 protocol, "protocol");
10875 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
10876         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10877                                 protocol_value, UINT8);
10878 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
10879         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10880                                 mask, "mask");
10881 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
10882         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10883                                 mask_value, INT8);
10884 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
10885         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10886                                 tcp_flags, "tcp_flags");
10887 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
10888         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10889                                 tcp_flags_value, UINT8);
10890 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
10891         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10892                                 priority, "priority");
10893 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
10894         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10895                                 priority_value, UINT8);
10896 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
10897         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
10898                                 queue, "queue");
10899 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
10900         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
10901                                 queue_id, UINT16);
10902
10903 cmdline_parse_inst_t cmd_5tuple_filter = {
10904         .f = cmd_5tuple_filter_parsed,
10905         .data = NULL,
10906         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
10907                 "src_ip <value> dst_port <value> src_port <value> "
10908                 "protocol <value>  mask <value> tcp_flags <value> "
10909                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
10910         .tokens = {
10911                 (void *)&cmd_5tuple_filter_filter,
10912                 (void *)&cmd_5tuple_filter_port_id,
10913                 (void *)&cmd_5tuple_filter_ops,
10914                 (void *)&cmd_5tuple_filter_dst_ip,
10915                 (void *)&cmd_5tuple_filter_dst_ip_value,
10916                 (void *)&cmd_5tuple_filter_src_ip,
10917                 (void *)&cmd_5tuple_filter_src_ip_value,
10918                 (void *)&cmd_5tuple_filter_dst_port,
10919                 (void *)&cmd_5tuple_filter_dst_port_value,
10920                 (void *)&cmd_5tuple_filter_src_port,
10921                 (void *)&cmd_5tuple_filter_src_port_value,
10922                 (void *)&cmd_5tuple_filter_protocol,
10923                 (void *)&cmd_5tuple_filter_protocol_value,
10924                 (void *)&cmd_5tuple_filter_mask,
10925                 (void *)&cmd_5tuple_filter_mask_value,
10926                 (void *)&cmd_5tuple_filter_tcp_flags,
10927                 (void *)&cmd_5tuple_filter_tcp_flags_value,
10928                 (void *)&cmd_5tuple_filter_priority,
10929                 (void *)&cmd_5tuple_filter_priority_value,
10930                 (void *)&cmd_5tuple_filter_queue,
10931                 (void *)&cmd_5tuple_filter_queue_id,
10932                 NULL,
10933         },
10934 };
10935
10936 /* *** ADD/REMOVE A flex FILTER *** */
10937 struct cmd_flex_filter_result {
10938         cmdline_fixed_string_t filter;
10939         cmdline_fixed_string_t ops;
10940         portid_t port_id;
10941         cmdline_fixed_string_t len;
10942         uint8_t len_value;
10943         cmdline_fixed_string_t bytes;
10944         cmdline_fixed_string_t bytes_value;
10945         cmdline_fixed_string_t mask;
10946         cmdline_fixed_string_t mask_value;
10947         cmdline_fixed_string_t priority;
10948         uint8_t priority_value;
10949         cmdline_fixed_string_t queue;
10950         uint16_t queue_id;
10951 };
10952
10953 static int xdigit2val(unsigned char c)
10954 {
10955         int val;
10956         if (isdigit(c))
10957                 val = c - '0';
10958         else if (isupper(c))
10959                 val = c - 'A' + 10;
10960         else
10961                 val = c - 'a' + 10;
10962         return val;
10963 }
10964
10965 static void
10966 cmd_flex_filter_parsed(void *parsed_result,
10967                           __rte_unused struct cmdline *cl,
10968                           __rte_unused void *data)
10969 {
10970         int ret = 0;
10971         struct rte_eth_flex_filter filter;
10972         struct cmd_flex_filter_result *res = parsed_result;
10973         char *bytes_ptr, *mask_ptr;
10974         uint16_t len, i, j = 0;
10975         char c;
10976         int val;
10977         uint8_t byte = 0;
10978
10979         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
10980                 printf("the len exceed the max length 128\n");
10981                 return;
10982         }
10983         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
10984         filter.len = res->len_value;
10985         filter.priority = res->priority_value;
10986         filter.queue = res->queue_id;
10987         bytes_ptr = res->bytes_value;
10988         mask_ptr = res->mask_value;
10989
10990          /* translate bytes string to array. */
10991         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
10992                 (bytes_ptr[1] == 'X')))
10993                 bytes_ptr += 2;
10994         len = strnlen(bytes_ptr, res->len_value * 2);
10995         if (len == 0 || (len % 8 != 0)) {
10996                 printf("please check len and bytes input\n");
10997                 return;
10998         }
10999         for (i = 0; i < len; i++) {
11000                 c = bytes_ptr[i];
11001                 if (isxdigit(c) == 0) {
11002                         /* invalid characters. */
11003                         printf("invalid input\n");
11004                         return;
11005                 }
11006                 val = xdigit2val(c);
11007                 if (i % 2) {
11008                         byte |= val;
11009                         filter.bytes[j] = byte;
11010                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
11011                         j++;
11012                         byte = 0;
11013                 } else
11014                         byte |= val << 4;
11015         }
11016         printf("\n");
11017          /* translate mask string to uint8_t array. */
11018         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
11019                 (mask_ptr[1] == 'X')))
11020                 mask_ptr += 2;
11021         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
11022         if (len == 0) {
11023                 printf("invalid input\n");
11024                 return;
11025         }
11026         j = 0;
11027         byte = 0;
11028         for (i = 0; i < len; i++) {
11029                 c = mask_ptr[i];
11030                 if (isxdigit(c) == 0) {
11031                         /* invalid characters. */
11032                         printf("invalid input\n");
11033                         return;
11034                 }
11035                 val = xdigit2val(c);
11036                 if (i % 2) {
11037                         byte |= val;
11038                         filter.mask[j] = byte;
11039                         printf("mask[%d]:%02x ", j, filter.mask[j]);
11040                         j++;
11041                         byte = 0;
11042                 } else
11043                         byte |= val << 4;
11044         }
11045         printf("\n");
11046
11047         if (!strcmp(res->ops, "add"))
11048                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11049                                 RTE_ETH_FILTER_FLEXIBLE,
11050                                 RTE_ETH_FILTER_ADD,
11051                                 &filter);
11052         else
11053                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11054                                 RTE_ETH_FILTER_FLEXIBLE,
11055                                 RTE_ETH_FILTER_DELETE,
11056                                 &filter);
11057
11058         if (ret < 0)
11059                 printf("flex filter setting error: (%s)\n", strerror(-ret));
11060 }
11061
11062 cmdline_parse_token_string_t cmd_flex_filter_filter =
11063         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11064                                 filter, "flex_filter");
11065 cmdline_parse_token_num_t cmd_flex_filter_port_id =
11066         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11067                                 port_id, UINT16);
11068 cmdline_parse_token_string_t cmd_flex_filter_ops =
11069         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11070                                 ops, "add#del");
11071 cmdline_parse_token_string_t cmd_flex_filter_len =
11072         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11073                                 len, "len");
11074 cmdline_parse_token_num_t cmd_flex_filter_len_value =
11075         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11076                                 len_value, UINT8);
11077 cmdline_parse_token_string_t cmd_flex_filter_bytes =
11078         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11079                                 bytes, "bytes");
11080 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
11081         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11082                                 bytes_value, NULL);
11083 cmdline_parse_token_string_t cmd_flex_filter_mask =
11084         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11085                                 mask, "mask");
11086 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
11087         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11088                                 mask_value, NULL);
11089 cmdline_parse_token_string_t cmd_flex_filter_priority =
11090         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11091                                 priority, "priority");
11092 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
11093         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11094                                 priority_value, UINT8);
11095 cmdline_parse_token_string_t cmd_flex_filter_queue =
11096         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
11097                                 queue, "queue");
11098 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
11099         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
11100                                 queue_id, UINT16);
11101 cmdline_parse_inst_t cmd_flex_filter = {
11102         .f = cmd_flex_filter_parsed,
11103         .data = NULL,
11104         .help_str = "flex_filter <port_id> add|del len <value> bytes "
11105                 "<value> mask <value> priority <value> queue <queue_id>: "
11106                 "Add/Del a flex filter",
11107         .tokens = {
11108                 (void *)&cmd_flex_filter_filter,
11109                 (void *)&cmd_flex_filter_port_id,
11110                 (void *)&cmd_flex_filter_ops,
11111                 (void *)&cmd_flex_filter_len,
11112                 (void *)&cmd_flex_filter_len_value,
11113                 (void *)&cmd_flex_filter_bytes,
11114                 (void *)&cmd_flex_filter_bytes_value,
11115                 (void *)&cmd_flex_filter_mask,
11116                 (void *)&cmd_flex_filter_mask_value,
11117                 (void *)&cmd_flex_filter_priority,
11118                 (void *)&cmd_flex_filter_priority_value,
11119                 (void *)&cmd_flex_filter_queue,
11120                 (void *)&cmd_flex_filter_queue_id,
11121                 NULL,
11122         },
11123 };
11124
11125 /* *** Filters Control *** */
11126
11127 /* *** deal with ethertype filter *** */
11128 struct cmd_ethertype_filter_result {
11129         cmdline_fixed_string_t filter;
11130         portid_t port_id;
11131         cmdline_fixed_string_t ops;
11132         cmdline_fixed_string_t mac;
11133         struct rte_ether_addr mac_addr;
11134         cmdline_fixed_string_t ethertype;
11135         uint16_t ethertype_value;
11136         cmdline_fixed_string_t drop;
11137         cmdline_fixed_string_t queue;
11138         uint16_t  queue_id;
11139 };
11140
11141 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
11142         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11143                                  filter, "ethertype_filter");
11144 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
11145         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11146                               port_id, UINT16);
11147 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
11148         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11149                                  ops, "add#del");
11150 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
11151         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11152                                  mac, "mac_addr#mac_ignr");
11153 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
11154         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
11155                                      mac_addr);
11156 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
11157         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11158                                  ethertype, "ethertype");
11159 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
11160         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11161                               ethertype_value, UINT16);
11162 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
11163         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11164                                  drop, "drop#fwd");
11165 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
11166         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
11167                                  queue, "queue");
11168 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
11169         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
11170                               queue_id, UINT16);
11171
11172 static void
11173 cmd_ethertype_filter_parsed(void *parsed_result,
11174                           __rte_unused struct cmdline *cl,
11175                           __rte_unused void *data)
11176 {
11177         struct cmd_ethertype_filter_result *res = parsed_result;
11178         struct rte_eth_ethertype_filter filter;
11179         int ret = 0;
11180
11181         ret = rte_eth_dev_filter_supported(res->port_id,
11182                         RTE_ETH_FILTER_ETHERTYPE);
11183         if (ret < 0) {
11184                 printf("ethertype filter is not supported on port %u.\n",
11185                         res->port_id);
11186                 return;
11187         }
11188
11189         memset(&filter, 0, sizeof(filter));
11190         if (!strcmp(res->mac, "mac_addr")) {
11191                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
11192                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
11193                         sizeof(struct rte_ether_addr));
11194         }
11195         if (!strcmp(res->drop, "drop"))
11196                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
11197         filter.ether_type = res->ethertype_value;
11198         filter.queue = res->queue_id;
11199
11200         if (!strcmp(res->ops, "add"))
11201                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11202                                 RTE_ETH_FILTER_ETHERTYPE,
11203                                 RTE_ETH_FILTER_ADD,
11204                                 &filter);
11205         else
11206                 ret = rte_eth_dev_filter_ctrl(res->port_id,
11207                                 RTE_ETH_FILTER_ETHERTYPE,
11208                                 RTE_ETH_FILTER_DELETE,
11209                                 &filter);
11210         if (ret < 0)
11211                 printf("ethertype filter programming error: (%s)\n",
11212                         strerror(-ret));
11213 }
11214
11215 cmdline_parse_inst_t cmd_ethertype_filter = {
11216         .f = cmd_ethertype_filter_parsed,
11217         .data = NULL,
11218         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
11219                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
11220                 "Add or delete an ethertype filter entry",
11221         .tokens = {
11222                 (void *)&cmd_ethertype_filter_filter,
11223                 (void *)&cmd_ethertype_filter_port_id,
11224                 (void *)&cmd_ethertype_filter_ops,
11225                 (void *)&cmd_ethertype_filter_mac,
11226                 (void *)&cmd_ethertype_filter_mac_addr,
11227                 (void *)&cmd_ethertype_filter_ethertype,
11228                 (void *)&cmd_ethertype_filter_ethertype_value,
11229                 (void *)&cmd_ethertype_filter_drop,
11230                 (void *)&cmd_ethertype_filter_queue,
11231                 (void *)&cmd_ethertype_filter_queue_id,
11232                 NULL,
11233         },
11234 };
11235
11236 /* *** deal with flow director filter *** */
11237 struct cmd_flow_director_result {
11238         cmdline_fixed_string_t flow_director_filter;
11239         portid_t port_id;
11240         cmdline_fixed_string_t mode;
11241         cmdline_fixed_string_t mode_value;
11242         cmdline_fixed_string_t ops;
11243         cmdline_fixed_string_t flow;
11244         cmdline_fixed_string_t flow_type;
11245         cmdline_fixed_string_t ether;
11246         uint16_t ether_type;
11247         cmdline_fixed_string_t src;
11248         cmdline_ipaddr_t ip_src;
11249         uint16_t port_src;
11250         cmdline_fixed_string_t dst;
11251         cmdline_ipaddr_t ip_dst;
11252         uint16_t port_dst;
11253         cmdline_fixed_string_t verify_tag;
11254         uint32_t verify_tag_value;
11255         cmdline_fixed_string_t tos;
11256         uint8_t tos_value;
11257         cmdline_fixed_string_t proto;
11258         uint8_t proto_value;
11259         cmdline_fixed_string_t ttl;
11260         uint8_t ttl_value;
11261         cmdline_fixed_string_t vlan;
11262         uint16_t vlan_value;
11263         cmdline_fixed_string_t flexbytes;
11264         cmdline_fixed_string_t flexbytes_value;
11265         cmdline_fixed_string_t pf_vf;
11266         cmdline_fixed_string_t drop;
11267         cmdline_fixed_string_t queue;
11268         uint16_t  queue_id;
11269         cmdline_fixed_string_t fd_id;
11270         uint32_t  fd_id_value;
11271         cmdline_fixed_string_t mac;
11272         struct rte_ether_addr mac_addr;
11273         cmdline_fixed_string_t tunnel;
11274         cmdline_fixed_string_t tunnel_type;
11275         cmdline_fixed_string_t tunnel_id;
11276         uint32_t tunnel_id_value;
11277         cmdline_fixed_string_t packet;
11278         char filepath[];
11279 };
11280
11281 static inline int
11282 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
11283 {
11284         char s[256];
11285         const char *p, *p0 = q_arg;
11286         char *end;
11287         unsigned long int_fld;
11288         char *str_fld[max_num];
11289         int i;
11290         unsigned size;
11291         int ret = -1;
11292
11293         p = strchr(p0, '(');
11294         if (p == NULL)
11295                 return -1;
11296         ++p;
11297         p0 = strchr(p, ')');
11298         if (p0 == NULL)
11299                 return -1;
11300
11301         size = p0 - p;
11302         if (size >= sizeof(s))
11303                 return -1;
11304
11305         snprintf(s, sizeof(s), "%.*s", size, p);
11306         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11307         if (ret < 0 || ret > max_num)
11308                 return -1;
11309         for (i = 0; i < ret; i++) {
11310                 errno = 0;
11311                 int_fld = strtoul(str_fld[i], &end, 0);
11312                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
11313                         return -1;
11314                 flexbytes[i] = (uint8_t)int_fld;
11315         }
11316         return ret;
11317 }
11318
11319 static uint16_t
11320 str2flowtype(char *string)
11321 {
11322         uint8_t i = 0;
11323         static const struct {
11324                 char str[32];
11325                 uint16_t type;
11326         } flowtype_str[] = {
11327                 {"raw", RTE_ETH_FLOW_RAW},
11328                 {"ipv4", RTE_ETH_FLOW_IPV4},
11329                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11330                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11331                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11332                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11333                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11334                 {"ipv6", RTE_ETH_FLOW_IPV6},
11335                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11336                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11337                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11338                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11339                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11340                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11341         };
11342
11343         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
11344                 if (!strcmp(flowtype_str[i].str, string))
11345                         return flowtype_str[i].type;
11346         }
11347
11348         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
11349                 return (uint16_t)atoi(string);
11350
11351         return RTE_ETH_FLOW_UNKNOWN;
11352 }
11353
11354 static enum rte_eth_fdir_tunnel_type
11355 str2fdir_tunneltype(char *string)
11356 {
11357         uint8_t i = 0;
11358
11359         static const struct {
11360                 char str[32];
11361                 enum rte_eth_fdir_tunnel_type type;
11362         } tunneltype_str[] = {
11363                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
11364                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
11365         };
11366
11367         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
11368                 if (!strcmp(tunneltype_str[i].str, string))
11369                         return tunneltype_str[i].type;
11370         }
11371         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
11372 }
11373
11374 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
11375 do { \
11376         if ((ip_addr).family == AF_INET) \
11377                 (ip) = (ip_addr).addr.ipv4.s_addr; \
11378         else { \
11379                 printf("invalid parameter.\n"); \
11380                 return; \
11381         } \
11382 } while (0)
11383
11384 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
11385 do { \
11386         if ((ip_addr).family == AF_INET6) \
11387                 rte_memcpy(&(ip), \
11388                                  &((ip_addr).addr.ipv6), \
11389                                  sizeof(struct in6_addr)); \
11390         else { \
11391                 printf("invalid parameter.\n"); \
11392                 return; \
11393         } \
11394 } while (0)
11395
11396 static void
11397 cmd_flow_director_filter_parsed(void *parsed_result,
11398                           __rte_unused struct cmdline *cl,
11399                           __rte_unused void *data)
11400 {
11401         struct cmd_flow_director_result *res = parsed_result;
11402         struct rte_eth_fdir_filter entry;
11403         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
11404         char *end;
11405         unsigned long vf_id;
11406         int ret = 0;
11407
11408         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11409         if (ret < 0) {
11410                 printf("flow director is not supported on port %u.\n",
11411                         res->port_id);
11412                 return;
11413         }
11414         memset(flexbytes, 0, sizeof(flexbytes));
11415         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
11416
11417         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11418                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11419                         printf("Please set mode to MAC-VLAN.\n");
11420                         return;
11421                 }
11422         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11423                 if (strcmp(res->mode_value, "Tunnel")) {
11424                         printf("Please set mode to Tunnel.\n");
11425                         return;
11426                 }
11427         } else {
11428                 if (!strcmp(res->mode_value, "raw")) {
11429 #ifdef RTE_LIBRTE_I40E_PMD
11430                         struct rte_pmd_i40e_flow_type_mapping
11431                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
11432                         struct rte_pmd_i40e_pkt_template_conf conf;
11433                         uint16_t flow_type = str2flowtype(res->flow_type);
11434                         uint16_t i, port = res->port_id;
11435                         uint8_t add;
11436
11437                         memset(&conf, 0, sizeof(conf));
11438
11439                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
11440                                 printf("Invalid flow type specified.\n");
11441                                 return;
11442                         }
11443                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
11444                                                                  mapping);
11445                         if (ret)
11446                                 return;
11447                         if (mapping[flow_type].pctype == 0ULL) {
11448                                 printf("Invalid flow type specified.\n");
11449                                 return;
11450                         }
11451                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
11452                                 if (mapping[flow_type].pctype & (1ULL << i)) {
11453                                         conf.input.pctype = i;
11454                                         break;
11455                                 }
11456                         }
11457
11458                         conf.input.packet = open_file(res->filepath,
11459                                                 &conf.input.length);
11460                         if (!conf.input.packet)
11461                                 return;
11462                         if (!strcmp(res->drop, "drop"))
11463                                 conf.action.behavior =
11464                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
11465                         else
11466                                 conf.action.behavior =
11467                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
11468                         conf.action.report_status =
11469                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
11470                         conf.action.rx_queue = res->queue_id;
11471                         conf.soft_id = res->fd_id_value;
11472                         add  = strcmp(res->ops, "del") ? 1 : 0;
11473                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
11474                                                                         &conf,
11475                                                                         add);
11476                         if (ret < 0)
11477                                 printf("flow director config error: (%s)\n",
11478                                        strerror(-ret));
11479                         close_file(conf.input.packet);
11480 #endif
11481                         return;
11482                 } else if (strcmp(res->mode_value, "IP")) {
11483                         printf("Please set mode to IP or raw.\n");
11484                         return;
11485                 }
11486                 entry.input.flow_type = str2flowtype(res->flow_type);
11487         }
11488
11489         ret = parse_flexbytes(res->flexbytes_value,
11490                                         flexbytes,
11491                                         RTE_ETH_FDIR_MAX_FLEXLEN);
11492         if (ret < 0) {
11493                 printf("error: Cannot parse flexbytes input.\n");
11494                 return;
11495         }
11496
11497         switch (entry.input.flow_type) {
11498         case RTE_ETH_FLOW_FRAG_IPV4:
11499         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
11500                 entry.input.flow.ip4_flow.proto = res->proto_value;
11501                 /* fall-through */
11502         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
11503         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
11504                 IPV4_ADDR_TO_UINT(res->ip_dst,
11505                         entry.input.flow.ip4_flow.dst_ip);
11506                 IPV4_ADDR_TO_UINT(res->ip_src,
11507                         entry.input.flow.ip4_flow.src_ip);
11508                 entry.input.flow.ip4_flow.tos = res->tos_value;
11509                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11510                 /* need convert to big endian. */
11511                 entry.input.flow.udp4_flow.dst_port =
11512                                 rte_cpu_to_be_16(res->port_dst);
11513                 entry.input.flow.udp4_flow.src_port =
11514                                 rte_cpu_to_be_16(res->port_src);
11515                 break;
11516         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
11517                 IPV4_ADDR_TO_UINT(res->ip_dst,
11518                         entry.input.flow.sctp4_flow.ip.dst_ip);
11519                 IPV4_ADDR_TO_UINT(res->ip_src,
11520                         entry.input.flow.sctp4_flow.ip.src_ip);
11521                 entry.input.flow.ip4_flow.tos = res->tos_value;
11522                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
11523                 /* need convert to big endian. */
11524                 entry.input.flow.sctp4_flow.dst_port =
11525                                 rte_cpu_to_be_16(res->port_dst);
11526                 entry.input.flow.sctp4_flow.src_port =
11527                                 rte_cpu_to_be_16(res->port_src);
11528                 entry.input.flow.sctp4_flow.verify_tag =
11529                                 rte_cpu_to_be_32(res->verify_tag_value);
11530                 break;
11531         case RTE_ETH_FLOW_FRAG_IPV6:
11532         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
11533                 entry.input.flow.ipv6_flow.proto = res->proto_value;
11534                 /* fall-through */
11535         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
11536         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
11537                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11538                         entry.input.flow.ipv6_flow.dst_ip);
11539                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11540                         entry.input.flow.ipv6_flow.src_ip);
11541                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11542                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11543                 /* need convert to big endian. */
11544                 entry.input.flow.udp6_flow.dst_port =
11545                                 rte_cpu_to_be_16(res->port_dst);
11546                 entry.input.flow.udp6_flow.src_port =
11547                                 rte_cpu_to_be_16(res->port_src);
11548                 break;
11549         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
11550                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
11551                         entry.input.flow.sctp6_flow.ip.dst_ip);
11552                 IPV6_ADDR_TO_ARRAY(res->ip_src,
11553                         entry.input.flow.sctp6_flow.ip.src_ip);
11554                 entry.input.flow.ipv6_flow.tc = res->tos_value;
11555                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
11556                 /* need convert to big endian. */
11557                 entry.input.flow.sctp6_flow.dst_port =
11558                                 rte_cpu_to_be_16(res->port_dst);
11559                 entry.input.flow.sctp6_flow.src_port =
11560                                 rte_cpu_to_be_16(res->port_src);
11561                 entry.input.flow.sctp6_flow.verify_tag =
11562                                 rte_cpu_to_be_32(res->verify_tag_value);
11563                 break;
11564         case RTE_ETH_FLOW_L2_PAYLOAD:
11565                 entry.input.flow.l2_flow.ether_type =
11566                         rte_cpu_to_be_16(res->ether_type);
11567                 break;
11568         default:
11569                 break;
11570         }
11571
11572         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
11573                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
11574                                  &res->mac_addr,
11575                                  sizeof(struct rte_ether_addr));
11576
11577         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11578                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
11579                                  &res->mac_addr,
11580                                  sizeof(struct rte_ether_addr));
11581                 entry.input.flow.tunnel_flow.tunnel_type =
11582                         str2fdir_tunneltype(res->tunnel_type);
11583                 entry.input.flow.tunnel_flow.tunnel_id =
11584                         rte_cpu_to_be_32(res->tunnel_id_value);
11585         }
11586
11587         rte_memcpy(entry.input.flow_ext.flexbytes,
11588                    flexbytes,
11589                    RTE_ETH_FDIR_MAX_FLEXLEN);
11590
11591         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
11592
11593         entry.action.flex_off = 0;  /*use 0 by default */
11594         if (!strcmp(res->drop, "drop"))
11595                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
11596         else
11597                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
11598
11599         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
11600             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11601                 if (!strcmp(res->pf_vf, "pf"))
11602                         entry.input.flow_ext.is_vf = 0;
11603                 else if (!strncmp(res->pf_vf, "vf", 2)) {
11604                         struct rte_eth_dev_info dev_info;
11605
11606                         ret = eth_dev_info_get_print_err(res->port_id,
11607                                                 &dev_info);
11608                         if (ret != 0)
11609                                 return;
11610
11611                         errno = 0;
11612                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
11613                         if (errno != 0 || *end != '\0' ||
11614                             vf_id >= dev_info.max_vfs) {
11615                                 printf("invalid parameter %s.\n", res->pf_vf);
11616                                 return;
11617                         }
11618                         entry.input.flow_ext.is_vf = 1;
11619                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
11620                 } else {
11621                         printf("invalid parameter %s.\n", res->pf_vf);
11622                         return;
11623                 }
11624         }
11625
11626         /* set to report FD ID by default */
11627         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
11628         entry.action.rx_queue = res->queue_id;
11629         entry.soft_id = res->fd_id_value;
11630         if (!strcmp(res->ops, "add"))
11631                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11632                                              RTE_ETH_FILTER_ADD, &entry);
11633         else if (!strcmp(res->ops, "del"))
11634                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11635                                              RTE_ETH_FILTER_DELETE, &entry);
11636         else
11637                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11638                                              RTE_ETH_FILTER_UPDATE, &entry);
11639         if (ret < 0)
11640                 printf("flow director programming error: (%s)\n",
11641                         strerror(-ret));
11642 }
11643
11644 cmdline_parse_token_string_t cmd_flow_director_filter =
11645         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11646                                  flow_director_filter, "flow_director_filter");
11647 cmdline_parse_token_num_t cmd_flow_director_port_id =
11648         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11649                               port_id, UINT16);
11650 cmdline_parse_token_string_t cmd_flow_director_ops =
11651         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11652                                  ops, "add#del#update");
11653 cmdline_parse_token_string_t cmd_flow_director_flow =
11654         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11655                                  flow, "flow");
11656 cmdline_parse_token_string_t cmd_flow_director_flow_type =
11657         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11658                 flow_type, NULL);
11659 cmdline_parse_token_string_t cmd_flow_director_ether =
11660         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11661                                  ether, "ether");
11662 cmdline_parse_token_num_t cmd_flow_director_ether_type =
11663         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11664                               ether_type, UINT16);
11665 cmdline_parse_token_string_t cmd_flow_director_src =
11666         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11667                                  src, "src");
11668 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
11669         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11670                                  ip_src);
11671 cmdline_parse_token_num_t cmd_flow_director_port_src =
11672         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11673                               port_src, UINT16);
11674 cmdline_parse_token_string_t cmd_flow_director_dst =
11675         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11676                                  dst, "dst");
11677 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
11678         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
11679                                  ip_dst);
11680 cmdline_parse_token_num_t cmd_flow_director_port_dst =
11681         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11682                               port_dst, UINT16);
11683 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
11684         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11685                                   verify_tag, "verify_tag");
11686 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
11687         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11688                               verify_tag_value, UINT32);
11689 cmdline_parse_token_string_t cmd_flow_director_tos =
11690         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11691                                  tos, "tos");
11692 cmdline_parse_token_num_t cmd_flow_director_tos_value =
11693         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11694                               tos_value, UINT8);
11695 cmdline_parse_token_string_t cmd_flow_director_proto =
11696         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11697                                  proto, "proto");
11698 cmdline_parse_token_num_t cmd_flow_director_proto_value =
11699         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11700                               proto_value, UINT8);
11701 cmdline_parse_token_string_t cmd_flow_director_ttl =
11702         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11703                                  ttl, "ttl");
11704 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
11705         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11706                               ttl_value, UINT8);
11707 cmdline_parse_token_string_t cmd_flow_director_vlan =
11708         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11709                                  vlan, "vlan");
11710 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
11711         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11712                               vlan_value, UINT16);
11713 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
11714         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11715                                  flexbytes, "flexbytes");
11716 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
11717         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11718                               flexbytes_value, NULL);
11719 cmdline_parse_token_string_t cmd_flow_director_drop =
11720         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11721                                  drop, "drop#fwd");
11722 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
11723         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11724                               pf_vf, NULL);
11725 cmdline_parse_token_string_t cmd_flow_director_queue =
11726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11727                                  queue, "queue");
11728 cmdline_parse_token_num_t cmd_flow_director_queue_id =
11729         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11730                               queue_id, UINT16);
11731 cmdline_parse_token_string_t cmd_flow_director_fd_id =
11732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11733                                  fd_id, "fd_id");
11734 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
11735         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11736                               fd_id_value, UINT32);
11737
11738 cmdline_parse_token_string_t cmd_flow_director_mode =
11739         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11740                                  mode, "mode");
11741 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
11742         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11743                                  mode_value, "IP");
11744 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
11745         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11746                                  mode_value, "MAC-VLAN");
11747 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
11748         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11749                                  mode_value, "Tunnel");
11750 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
11751         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11752                                  mode_value, "raw");
11753 cmdline_parse_token_string_t cmd_flow_director_mac =
11754         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11755                                  mac, "mac");
11756 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
11757         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
11758                                     mac_addr);
11759 cmdline_parse_token_string_t cmd_flow_director_tunnel =
11760         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11761                                  tunnel, "tunnel");
11762 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
11763         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11764                                  tunnel_type, "NVGRE#VxLAN");
11765 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
11766         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11767                                  tunnel_id, "tunnel-id");
11768 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
11769         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
11770                               tunnel_id_value, UINT32);
11771 cmdline_parse_token_string_t cmd_flow_director_packet =
11772         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11773                                  packet, "packet");
11774 cmdline_parse_token_string_t cmd_flow_director_filepath =
11775         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
11776                                  filepath, NULL);
11777
11778 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
11779         .f = cmd_flow_director_filter_parsed,
11780         .data = NULL,
11781         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
11782                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
11783                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
11784                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
11785                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
11786                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
11787                 "fd_id <fd_id_value>: "
11788                 "Add or delete an ip flow director entry on NIC",
11789         .tokens = {
11790                 (void *)&cmd_flow_director_filter,
11791                 (void *)&cmd_flow_director_port_id,
11792                 (void *)&cmd_flow_director_mode,
11793                 (void *)&cmd_flow_director_mode_ip,
11794                 (void *)&cmd_flow_director_ops,
11795                 (void *)&cmd_flow_director_flow,
11796                 (void *)&cmd_flow_director_flow_type,
11797                 (void *)&cmd_flow_director_src,
11798                 (void *)&cmd_flow_director_ip_src,
11799                 (void *)&cmd_flow_director_dst,
11800                 (void *)&cmd_flow_director_ip_dst,
11801                 (void *)&cmd_flow_director_tos,
11802                 (void *)&cmd_flow_director_tos_value,
11803                 (void *)&cmd_flow_director_proto,
11804                 (void *)&cmd_flow_director_proto_value,
11805                 (void *)&cmd_flow_director_ttl,
11806                 (void *)&cmd_flow_director_ttl_value,
11807                 (void *)&cmd_flow_director_vlan,
11808                 (void *)&cmd_flow_director_vlan_value,
11809                 (void *)&cmd_flow_director_flexbytes,
11810                 (void *)&cmd_flow_director_flexbytes_value,
11811                 (void *)&cmd_flow_director_drop,
11812                 (void *)&cmd_flow_director_pf_vf,
11813                 (void *)&cmd_flow_director_queue,
11814                 (void *)&cmd_flow_director_queue_id,
11815                 (void *)&cmd_flow_director_fd_id,
11816                 (void *)&cmd_flow_director_fd_id_value,
11817                 NULL,
11818         },
11819 };
11820
11821 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
11822         .f = cmd_flow_director_filter_parsed,
11823         .data = NULL,
11824         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
11825                 "director entry on NIC",
11826         .tokens = {
11827                 (void *)&cmd_flow_director_filter,
11828                 (void *)&cmd_flow_director_port_id,
11829                 (void *)&cmd_flow_director_mode,
11830                 (void *)&cmd_flow_director_mode_ip,
11831                 (void *)&cmd_flow_director_ops,
11832                 (void *)&cmd_flow_director_flow,
11833                 (void *)&cmd_flow_director_flow_type,
11834                 (void *)&cmd_flow_director_src,
11835                 (void *)&cmd_flow_director_ip_src,
11836                 (void *)&cmd_flow_director_port_src,
11837                 (void *)&cmd_flow_director_dst,
11838                 (void *)&cmd_flow_director_ip_dst,
11839                 (void *)&cmd_flow_director_port_dst,
11840                 (void *)&cmd_flow_director_tos,
11841                 (void *)&cmd_flow_director_tos_value,
11842                 (void *)&cmd_flow_director_ttl,
11843                 (void *)&cmd_flow_director_ttl_value,
11844                 (void *)&cmd_flow_director_vlan,
11845                 (void *)&cmd_flow_director_vlan_value,
11846                 (void *)&cmd_flow_director_flexbytes,
11847                 (void *)&cmd_flow_director_flexbytes_value,
11848                 (void *)&cmd_flow_director_drop,
11849                 (void *)&cmd_flow_director_pf_vf,
11850                 (void *)&cmd_flow_director_queue,
11851                 (void *)&cmd_flow_director_queue_id,
11852                 (void *)&cmd_flow_director_fd_id,
11853                 (void *)&cmd_flow_director_fd_id_value,
11854                 NULL,
11855         },
11856 };
11857
11858 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
11859         .f = cmd_flow_director_filter_parsed,
11860         .data = NULL,
11861         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
11862                 "director entry on NIC",
11863         .tokens = {
11864                 (void *)&cmd_flow_director_filter,
11865                 (void *)&cmd_flow_director_port_id,
11866                 (void *)&cmd_flow_director_mode,
11867                 (void *)&cmd_flow_director_mode_ip,
11868                 (void *)&cmd_flow_director_ops,
11869                 (void *)&cmd_flow_director_flow,
11870                 (void *)&cmd_flow_director_flow_type,
11871                 (void *)&cmd_flow_director_src,
11872                 (void *)&cmd_flow_director_ip_src,
11873                 (void *)&cmd_flow_director_port_src,
11874                 (void *)&cmd_flow_director_dst,
11875                 (void *)&cmd_flow_director_ip_dst,
11876                 (void *)&cmd_flow_director_port_dst,
11877                 (void *)&cmd_flow_director_verify_tag,
11878                 (void *)&cmd_flow_director_verify_tag_value,
11879                 (void *)&cmd_flow_director_tos,
11880                 (void *)&cmd_flow_director_tos_value,
11881                 (void *)&cmd_flow_director_ttl,
11882                 (void *)&cmd_flow_director_ttl_value,
11883                 (void *)&cmd_flow_director_vlan,
11884                 (void *)&cmd_flow_director_vlan_value,
11885                 (void *)&cmd_flow_director_flexbytes,
11886                 (void *)&cmd_flow_director_flexbytes_value,
11887                 (void *)&cmd_flow_director_drop,
11888                 (void *)&cmd_flow_director_pf_vf,
11889                 (void *)&cmd_flow_director_queue,
11890                 (void *)&cmd_flow_director_queue_id,
11891                 (void *)&cmd_flow_director_fd_id,
11892                 (void *)&cmd_flow_director_fd_id_value,
11893                 NULL,
11894         },
11895 };
11896
11897 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
11898         .f = cmd_flow_director_filter_parsed,
11899         .data = NULL,
11900         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
11901                 "director entry on NIC",
11902         .tokens = {
11903                 (void *)&cmd_flow_director_filter,
11904                 (void *)&cmd_flow_director_port_id,
11905                 (void *)&cmd_flow_director_mode,
11906                 (void *)&cmd_flow_director_mode_ip,
11907                 (void *)&cmd_flow_director_ops,
11908                 (void *)&cmd_flow_director_flow,
11909                 (void *)&cmd_flow_director_flow_type,
11910                 (void *)&cmd_flow_director_ether,
11911                 (void *)&cmd_flow_director_ether_type,
11912                 (void *)&cmd_flow_director_flexbytes,
11913                 (void *)&cmd_flow_director_flexbytes_value,
11914                 (void *)&cmd_flow_director_drop,
11915                 (void *)&cmd_flow_director_pf_vf,
11916                 (void *)&cmd_flow_director_queue,
11917                 (void *)&cmd_flow_director_queue_id,
11918                 (void *)&cmd_flow_director_fd_id,
11919                 (void *)&cmd_flow_director_fd_id_value,
11920                 NULL,
11921         },
11922 };
11923
11924 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
11925         .f = cmd_flow_director_filter_parsed,
11926         .data = NULL,
11927         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
11928                 "director entry on NIC",
11929         .tokens = {
11930                 (void *)&cmd_flow_director_filter,
11931                 (void *)&cmd_flow_director_port_id,
11932                 (void *)&cmd_flow_director_mode,
11933                 (void *)&cmd_flow_director_mode_mac_vlan,
11934                 (void *)&cmd_flow_director_ops,
11935                 (void *)&cmd_flow_director_mac,
11936                 (void *)&cmd_flow_director_mac_addr,
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_queue,
11943                 (void *)&cmd_flow_director_queue_id,
11944                 (void *)&cmd_flow_director_fd_id,
11945                 (void *)&cmd_flow_director_fd_id_value,
11946                 NULL,
11947         },
11948 };
11949
11950 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
11951         .f = cmd_flow_director_filter_parsed,
11952         .data = NULL,
11953         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
11954                 "director entry on NIC",
11955         .tokens = {
11956                 (void *)&cmd_flow_director_filter,
11957                 (void *)&cmd_flow_director_port_id,
11958                 (void *)&cmd_flow_director_mode,
11959                 (void *)&cmd_flow_director_mode_tunnel,
11960                 (void *)&cmd_flow_director_ops,
11961                 (void *)&cmd_flow_director_mac,
11962                 (void *)&cmd_flow_director_mac_addr,
11963                 (void *)&cmd_flow_director_vlan,
11964                 (void *)&cmd_flow_director_vlan_value,
11965                 (void *)&cmd_flow_director_tunnel,
11966                 (void *)&cmd_flow_director_tunnel_type,
11967                 (void *)&cmd_flow_director_tunnel_id,
11968                 (void *)&cmd_flow_director_tunnel_id_value,
11969                 (void *)&cmd_flow_director_flexbytes,
11970                 (void *)&cmd_flow_director_flexbytes_value,
11971                 (void *)&cmd_flow_director_drop,
11972                 (void *)&cmd_flow_director_queue,
11973                 (void *)&cmd_flow_director_queue_id,
11974                 (void *)&cmd_flow_director_fd_id,
11975                 (void *)&cmd_flow_director_fd_id_value,
11976                 NULL,
11977         },
11978 };
11979
11980 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
11981         .f = cmd_flow_director_filter_parsed,
11982         .data = NULL,
11983         .help_str = "flow_director_filter ... : Add or delete a raw flow "
11984                 "director entry on NIC",
11985         .tokens = {
11986                 (void *)&cmd_flow_director_filter,
11987                 (void *)&cmd_flow_director_port_id,
11988                 (void *)&cmd_flow_director_mode,
11989                 (void *)&cmd_flow_director_mode_raw,
11990                 (void *)&cmd_flow_director_ops,
11991                 (void *)&cmd_flow_director_flow,
11992                 (void *)&cmd_flow_director_flow_type,
11993                 (void *)&cmd_flow_director_drop,
11994                 (void *)&cmd_flow_director_queue,
11995                 (void *)&cmd_flow_director_queue_id,
11996                 (void *)&cmd_flow_director_fd_id,
11997                 (void *)&cmd_flow_director_fd_id_value,
11998                 (void *)&cmd_flow_director_packet,
11999                 (void *)&cmd_flow_director_filepath,
12000                 NULL,
12001         },
12002 };
12003
12004 struct cmd_flush_flow_director_result {
12005         cmdline_fixed_string_t flush_flow_director;
12006         portid_t port_id;
12007 };
12008
12009 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
12010         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
12011                                  flush_flow_director, "flush_flow_director");
12012 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
12013         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
12014                               port_id, UINT16);
12015
12016 static void
12017 cmd_flush_flow_director_parsed(void *parsed_result,
12018                           __rte_unused struct cmdline *cl,
12019                           __rte_unused void *data)
12020 {
12021         struct cmd_flow_director_result *res = parsed_result;
12022         int ret = 0;
12023
12024         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
12025         if (ret < 0) {
12026                 printf("flow director is not supported on port %u.\n",
12027                         res->port_id);
12028                 return;
12029         }
12030
12031         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12032                         RTE_ETH_FILTER_FLUSH, NULL);
12033         if (ret < 0)
12034                 printf("flow director table flushing error: (%s)\n",
12035                         strerror(-ret));
12036 }
12037
12038 cmdline_parse_inst_t cmd_flush_flow_director = {
12039         .f = cmd_flush_flow_director_parsed,
12040         .data = NULL,
12041         .help_str = "flush_flow_director <port_id>: "
12042                 "Flush all flow director entries of a device on NIC",
12043         .tokens = {
12044                 (void *)&cmd_flush_flow_director_flush,
12045                 (void *)&cmd_flush_flow_director_port_id,
12046                 NULL,
12047         },
12048 };
12049
12050 /* *** deal with flow director mask *** */
12051 struct cmd_flow_director_mask_result {
12052         cmdline_fixed_string_t flow_director_mask;
12053         portid_t port_id;
12054         cmdline_fixed_string_t mode;
12055         cmdline_fixed_string_t mode_value;
12056         cmdline_fixed_string_t vlan;
12057         uint16_t vlan_mask;
12058         cmdline_fixed_string_t src_mask;
12059         cmdline_ipaddr_t ipv4_src;
12060         cmdline_ipaddr_t ipv6_src;
12061         uint16_t port_src;
12062         cmdline_fixed_string_t dst_mask;
12063         cmdline_ipaddr_t ipv4_dst;
12064         cmdline_ipaddr_t ipv6_dst;
12065         uint16_t port_dst;
12066         cmdline_fixed_string_t mac;
12067         uint8_t mac_addr_byte_mask;
12068         cmdline_fixed_string_t tunnel_id;
12069         uint32_t tunnel_id_mask;
12070         cmdline_fixed_string_t tunnel_type;
12071         uint8_t tunnel_type_mask;
12072 };
12073
12074 static void
12075 cmd_flow_director_mask_parsed(void *parsed_result,
12076                           __rte_unused struct cmdline *cl,
12077                           __rte_unused void *data)
12078 {
12079         struct cmd_flow_director_mask_result *res = parsed_result;
12080         struct rte_eth_fdir_masks *mask;
12081         struct rte_port *port;
12082
12083         port = &ports[res->port_id];
12084         /** Check if the port is not started **/
12085         if (port->port_status != RTE_PORT_STOPPED) {
12086                 printf("Please stop port %d first\n", res->port_id);
12087                 return;
12088         }
12089
12090         mask = &port->dev_conf.fdir_conf.mask;
12091
12092         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
12093                 if (strcmp(res->mode_value, "MAC-VLAN")) {
12094                         printf("Please set mode to MAC-VLAN.\n");
12095                         return;
12096                 }
12097
12098                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12099         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
12100                 if (strcmp(res->mode_value, "Tunnel")) {
12101                         printf("Please set mode to Tunnel.\n");
12102                         return;
12103                 }
12104
12105                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12106                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
12107                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
12108                 mask->tunnel_type_mask = res->tunnel_type_mask;
12109         } else {
12110                 if (strcmp(res->mode_value, "IP")) {
12111                         printf("Please set mode to IP.\n");
12112                         return;
12113                 }
12114
12115                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
12116                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
12117                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
12118                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
12119                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
12120                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
12121                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
12122         }
12123
12124         cmd_reconfig_device_queue(res->port_id, 1, 1);
12125 }
12126
12127 cmdline_parse_token_string_t cmd_flow_director_mask =
12128         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12129                                  flow_director_mask, "flow_director_mask");
12130 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
12131         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12132                               port_id, UINT16);
12133 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
12134         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12135                                  vlan, "vlan");
12136 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
12137         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12138                               vlan_mask, UINT16);
12139 cmdline_parse_token_string_t cmd_flow_director_mask_src =
12140         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12141                                  src_mask, "src_mask");
12142 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
12143         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12144                                  ipv4_src);
12145 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
12146         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12147                                  ipv6_src);
12148 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
12149         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12150                               port_src, UINT16);
12151 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
12152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12153                                  dst_mask, "dst_mask");
12154 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
12155         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12156                                  ipv4_dst);
12157 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
12158         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
12159                                  ipv6_dst);
12160 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
12161         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12162                               port_dst, UINT16);
12163
12164 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
12165         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12166                                  mode, "mode");
12167 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
12168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12169                                  mode_value, "IP");
12170 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
12171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12172                                  mode_value, "MAC-VLAN");
12173 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
12174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12175                                  mode_value, "Tunnel");
12176 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
12177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12178                                  mac, "mac");
12179 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
12180         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12181                               mac_addr_byte_mask, UINT8);
12182 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
12183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12184                                  tunnel_type, "tunnel-type");
12185 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
12186         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12187                               tunnel_type_mask, UINT8);
12188 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
12189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
12190                                  tunnel_id, "tunnel-id");
12191 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
12192         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
12193                               tunnel_id_mask, UINT32);
12194
12195 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
12196         .f = cmd_flow_director_mask_parsed,
12197         .data = NULL,
12198         .help_str = "flow_director_mask ... : "
12199                 "Set IP mode flow director's mask on NIC",
12200         .tokens = {
12201                 (void *)&cmd_flow_director_mask,
12202                 (void *)&cmd_flow_director_mask_port_id,
12203                 (void *)&cmd_flow_director_mask_mode,
12204                 (void *)&cmd_flow_director_mask_mode_ip,
12205                 (void *)&cmd_flow_director_mask_vlan,
12206                 (void *)&cmd_flow_director_mask_vlan_value,
12207                 (void *)&cmd_flow_director_mask_src,
12208                 (void *)&cmd_flow_director_mask_ipv4_src,
12209                 (void *)&cmd_flow_director_mask_ipv6_src,
12210                 (void *)&cmd_flow_director_mask_port_src,
12211                 (void *)&cmd_flow_director_mask_dst,
12212                 (void *)&cmd_flow_director_mask_ipv4_dst,
12213                 (void *)&cmd_flow_director_mask_ipv6_dst,
12214                 (void *)&cmd_flow_director_mask_port_dst,
12215                 NULL,
12216         },
12217 };
12218
12219 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
12220         .f = cmd_flow_director_mask_parsed,
12221         .data = NULL,
12222         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
12223                 "flow director's mask on NIC",
12224         .tokens = {
12225                 (void *)&cmd_flow_director_mask,
12226                 (void *)&cmd_flow_director_mask_port_id,
12227                 (void *)&cmd_flow_director_mask_mode,
12228                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
12229                 (void *)&cmd_flow_director_mask_vlan,
12230                 (void *)&cmd_flow_director_mask_vlan_value,
12231                 NULL,
12232         },
12233 };
12234
12235 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
12236         .f = cmd_flow_director_mask_parsed,
12237         .data = NULL,
12238         .help_str = "flow_director_mask ... : Set tunnel mode "
12239                 "flow director's mask on NIC",
12240         .tokens = {
12241                 (void *)&cmd_flow_director_mask,
12242                 (void *)&cmd_flow_director_mask_port_id,
12243                 (void *)&cmd_flow_director_mask_mode,
12244                 (void *)&cmd_flow_director_mask_mode_tunnel,
12245                 (void *)&cmd_flow_director_mask_vlan,
12246                 (void *)&cmd_flow_director_mask_vlan_value,
12247                 (void *)&cmd_flow_director_mask_mac,
12248                 (void *)&cmd_flow_director_mask_mac_value,
12249                 (void *)&cmd_flow_director_mask_tunnel_type,
12250                 (void *)&cmd_flow_director_mask_tunnel_type_value,
12251                 (void *)&cmd_flow_director_mask_tunnel_id,
12252                 (void *)&cmd_flow_director_mask_tunnel_id_value,
12253                 NULL,
12254         },
12255 };
12256
12257 /* *** deal with flow director mask on flexible payload *** */
12258 struct cmd_flow_director_flex_mask_result {
12259         cmdline_fixed_string_t flow_director_flexmask;
12260         portid_t port_id;
12261         cmdline_fixed_string_t flow;
12262         cmdline_fixed_string_t flow_type;
12263         cmdline_fixed_string_t mask;
12264 };
12265
12266 static void
12267 cmd_flow_director_flex_mask_parsed(void *parsed_result,
12268                           __rte_unused struct cmdline *cl,
12269                           __rte_unused void *data)
12270 {
12271         struct cmd_flow_director_flex_mask_result *res = parsed_result;
12272         struct rte_eth_fdir_info fdir_info;
12273         struct rte_eth_fdir_flex_mask flex_mask;
12274         struct rte_port *port;
12275         uint64_t flow_type_mask;
12276         uint16_t i;
12277         int ret;
12278
12279         port = &ports[res->port_id];
12280         /** Check if the port is not started **/
12281         if (port->port_status != RTE_PORT_STOPPED) {
12282                 printf("Please stop port %d first\n", res->port_id);
12283                 return;
12284         }
12285
12286         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
12287         ret = parse_flexbytes(res->mask,
12288                         flex_mask.mask,
12289                         RTE_ETH_FDIR_MAX_FLEXLEN);
12290         if (ret < 0) {
12291                 printf("error: Cannot parse mask input.\n");
12292                 return;
12293         }
12294
12295         memset(&fdir_info, 0, sizeof(fdir_info));
12296         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12297                                 RTE_ETH_FILTER_INFO, &fdir_info);
12298         if (ret < 0) {
12299                 printf("Cannot get FDir filter info\n");
12300                 return;
12301         }
12302
12303         if (!strcmp(res->flow_type, "none")) {
12304                 /* means don't specify the flow type */
12305                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
12306                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
12307                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
12308                                0, sizeof(struct rte_eth_fdir_flex_mask));
12309                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
12310                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
12311                                  &flex_mask,
12312                                  sizeof(struct rte_eth_fdir_flex_mask));
12313                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12314                 return;
12315         }
12316         flow_type_mask = fdir_info.flow_types_mask[0];
12317         if (!strcmp(res->flow_type, "all")) {
12318                 if (!flow_type_mask) {
12319                         printf("No flow type supported\n");
12320                         return;
12321                 }
12322                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
12323                         if (flow_type_mask & (1ULL << i)) {
12324                                 flex_mask.flow_type = i;
12325                                 fdir_set_flex_mask(res->port_id, &flex_mask);
12326                         }
12327                 }
12328                 cmd_reconfig_device_queue(res->port_id, 1, 1);
12329                 return;
12330         }
12331         flex_mask.flow_type = str2flowtype(res->flow_type);
12332         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
12333                 printf("Flow type %s not supported on port %d\n",
12334                                 res->flow_type, res->port_id);
12335                 return;
12336         }
12337         fdir_set_flex_mask(res->port_id, &flex_mask);
12338         cmd_reconfig_device_queue(res->port_id, 1, 1);
12339 }
12340
12341 cmdline_parse_token_string_t cmd_flow_director_flexmask =
12342         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12343                                  flow_director_flexmask,
12344                                  "flow_director_flex_mask");
12345 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
12346         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12347                               port_id, UINT16);
12348 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
12349         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12350                                  flow, "flow");
12351 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
12352         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12353                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
12354                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
12355 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
12356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
12357                                  mask, NULL);
12358
12359 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
12360         .f = cmd_flow_director_flex_mask_parsed,
12361         .data = NULL,
12362         .help_str = "flow_director_flex_mask ... : "
12363                 "Set flow director's flex mask on NIC",
12364         .tokens = {
12365                 (void *)&cmd_flow_director_flexmask,
12366                 (void *)&cmd_flow_director_flexmask_port_id,
12367                 (void *)&cmd_flow_director_flexmask_flow,
12368                 (void *)&cmd_flow_director_flexmask_flow_type,
12369                 (void *)&cmd_flow_director_flexmask_mask,
12370                 NULL,
12371         },
12372 };
12373
12374 /* *** deal with flow director flexible payload configuration *** */
12375 struct cmd_flow_director_flexpayload_result {
12376         cmdline_fixed_string_t flow_director_flexpayload;
12377         portid_t port_id;
12378         cmdline_fixed_string_t payload_layer;
12379         cmdline_fixed_string_t payload_cfg;
12380 };
12381
12382 static inline int
12383 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
12384 {
12385         char s[256];
12386         const char *p, *p0 = q_arg;
12387         char *end;
12388         unsigned long int_fld;
12389         char *str_fld[max_num];
12390         int i;
12391         unsigned size;
12392         int ret = -1;
12393
12394         p = strchr(p0, '(');
12395         if (p == NULL)
12396                 return -1;
12397         ++p;
12398         p0 = strchr(p, ')');
12399         if (p0 == NULL)
12400                 return -1;
12401
12402         size = p0 - p;
12403         if (size >= sizeof(s))
12404                 return -1;
12405
12406         snprintf(s, sizeof(s), "%.*s", size, p);
12407         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
12408         if (ret < 0 || ret > max_num)
12409                 return -1;
12410         for (i = 0; i < ret; i++) {
12411                 errno = 0;
12412                 int_fld = strtoul(str_fld[i], &end, 0);
12413                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
12414                         return -1;
12415                 offsets[i] = (uint16_t)int_fld;
12416         }
12417         return ret;
12418 }
12419
12420 static void
12421 cmd_flow_director_flxpld_parsed(void *parsed_result,
12422                           __rte_unused struct cmdline *cl,
12423                           __rte_unused void *data)
12424 {
12425         struct cmd_flow_director_flexpayload_result *res = parsed_result;
12426         struct rte_eth_flex_payload_cfg flex_cfg;
12427         struct rte_port *port;
12428         int ret = 0;
12429
12430         port = &ports[res->port_id];
12431         /** Check if the port is not started **/
12432         if (port->port_status != RTE_PORT_STOPPED) {
12433                 printf("Please stop port %d first\n", res->port_id);
12434                 return;
12435         }
12436
12437         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
12438
12439         if (!strcmp(res->payload_layer, "raw"))
12440                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
12441         else if (!strcmp(res->payload_layer, "l2"))
12442                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
12443         else if (!strcmp(res->payload_layer, "l3"))
12444                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
12445         else if (!strcmp(res->payload_layer, "l4"))
12446                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
12447
12448         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
12449                             RTE_ETH_FDIR_MAX_FLEXLEN);
12450         if (ret < 0) {
12451                 printf("error: Cannot parse flex payload input.\n");
12452                 return;
12453         }
12454
12455         fdir_set_flex_payload(res->port_id, &flex_cfg);
12456         cmd_reconfig_device_queue(res->port_id, 1, 1);
12457 }
12458
12459 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
12460         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12461                                  flow_director_flexpayload,
12462                                  "flow_director_flex_payload");
12463 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
12464         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12465                               port_id, UINT16);
12466 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
12467         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12468                                  payload_layer, "raw#l2#l3#l4");
12469 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
12470         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
12471                                  payload_cfg, NULL);
12472
12473 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
12474         .f = cmd_flow_director_flxpld_parsed,
12475         .data = NULL,
12476         .help_str = "flow_director_flexpayload ... : "
12477                 "Set flow director's flex payload on NIC",
12478         .tokens = {
12479                 (void *)&cmd_flow_director_flexpayload,
12480                 (void *)&cmd_flow_director_flexpayload_port_id,
12481                 (void *)&cmd_flow_director_flexpayload_payload_layer,
12482                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
12483                 NULL,
12484         },
12485 };
12486
12487 /* Generic flow interface command. */
12488 extern cmdline_parse_inst_t cmd_flow;
12489
12490 /* *** Classification Filters Control *** */
12491 /* *** Get symmetric hash enable per port *** */
12492 struct cmd_get_sym_hash_ena_per_port_result {
12493         cmdline_fixed_string_t get_sym_hash_ena_per_port;
12494         portid_t port_id;
12495 };
12496
12497 static void
12498 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
12499                                  __rte_unused struct cmdline *cl,
12500                                  __rte_unused void *data)
12501 {
12502         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
12503         struct rte_eth_hash_filter_info info;
12504         int ret;
12505
12506         if (rte_eth_dev_filter_supported(res->port_id,
12507                                 RTE_ETH_FILTER_HASH) < 0) {
12508                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12509                                                         res->port_id);
12510                 return;
12511         }
12512
12513         memset(&info, 0, sizeof(info));
12514         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12515         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12516                                                 RTE_ETH_FILTER_GET, &info);
12517
12518         if (ret < 0) {
12519                 printf("Cannot get symmetric hash enable per port "
12520                                         "on port %u\n", res->port_id);
12521                 return;
12522         }
12523
12524         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
12525                                 "enabled" : "disabled", res->port_id);
12526 }
12527
12528 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
12529         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12530                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
12531 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
12532         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
12533                 port_id, UINT16);
12534
12535 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
12536         .f = cmd_get_sym_hash_per_port_parsed,
12537         .data = NULL,
12538         .help_str = "get_sym_hash_ena_per_port <port_id>",
12539         .tokens = {
12540                 (void *)&cmd_get_sym_hash_ena_per_port_all,
12541                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
12542                 NULL,
12543         },
12544 };
12545
12546 /* *** Set symmetric hash enable per port *** */
12547 struct cmd_set_sym_hash_ena_per_port_result {
12548         cmdline_fixed_string_t set_sym_hash_ena_per_port;
12549         cmdline_fixed_string_t enable;
12550         portid_t port_id;
12551 };
12552
12553 static void
12554 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
12555                                  __rte_unused struct cmdline *cl,
12556                                  __rte_unused void *data)
12557 {
12558         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
12559         struct rte_eth_hash_filter_info info;
12560         int ret;
12561
12562         if (rte_eth_dev_filter_supported(res->port_id,
12563                                 RTE_ETH_FILTER_HASH) < 0) {
12564                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
12565                                                         res->port_id);
12566                 return;
12567         }
12568
12569         memset(&info, 0, sizeof(info));
12570         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
12571         if (!strcmp(res->enable, "enable"))
12572                 info.info.enable = 1;
12573         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12574                                         RTE_ETH_FILTER_SET, &info);
12575         if (ret < 0) {
12576                 printf("Cannot set symmetric hash enable per port on "
12577                                         "port %u\n", res->port_id);
12578                 return;
12579         }
12580         printf("Symmetric hash has been set to %s on port %u\n",
12581                                         res->enable, res->port_id);
12582 }
12583
12584 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
12585         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12586                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
12587 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
12588         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12589                 port_id, UINT16);
12590 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
12591         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
12592                 enable, "enable#disable");
12593
12594 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
12595         .f = cmd_set_sym_hash_per_port_parsed,
12596         .data = NULL,
12597         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
12598         .tokens = {
12599                 (void *)&cmd_set_sym_hash_ena_per_port_all,
12600                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
12601                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
12602                 NULL,
12603         },
12604 };
12605
12606 /* Get global config of hash function */
12607 struct cmd_get_hash_global_config_result {
12608         cmdline_fixed_string_t get_hash_global_config;
12609         portid_t port_id;
12610 };
12611
12612 static char *
12613 flowtype_to_str(uint16_t ftype)
12614 {
12615         uint16_t i;
12616         static struct {
12617                 char str[16];
12618                 uint16_t ftype;
12619         } ftype_table[] = {
12620                 {"ipv4", RTE_ETH_FLOW_IPV4},
12621                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
12622                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
12623                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
12624                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
12625                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
12626                 {"ipv6", RTE_ETH_FLOW_IPV6},
12627                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
12628                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
12629                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
12630                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
12631                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
12632                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
12633                 {"port", RTE_ETH_FLOW_PORT},
12634                 {"vxlan", RTE_ETH_FLOW_VXLAN},
12635                 {"geneve", RTE_ETH_FLOW_GENEVE},
12636                 {"nvgre", RTE_ETH_FLOW_NVGRE},
12637                 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
12638         };
12639
12640         for (i = 0; i < RTE_DIM(ftype_table); i++) {
12641                 if (ftype_table[i].ftype == ftype)
12642                         return ftype_table[i].str;
12643         }
12644
12645         return NULL;
12646 }
12647
12648 static void
12649 cmd_get_hash_global_config_parsed(void *parsed_result,
12650                                   __rte_unused struct cmdline *cl,
12651                                   __rte_unused void *data)
12652 {
12653         struct cmd_get_hash_global_config_result *res = parsed_result;
12654         struct rte_eth_hash_filter_info info;
12655         uint32_t idx, offset;
12656         uint16_t i;
12657         char *str;
12658         int ret;
12659
12660         if (rte_eth_dev_filter_supported(res->port_id,
12661                         RTE_ETH_FILTER_HASH) < 0) {
12662                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12663                                                         res->port_id);
12664                 return;
12665         }
12666
12667         memset(&info, 0, sizeof(info));
12668         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12669         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12670                                         RTE_ETH_FILTER_GET, &info);
12671         if (ret < 0) {
12672                 printf("Cannot get hash global configurations by port %d\n",
12673                                                         res->port_id);
12674                 return;
12675         }
12676
12677         switch (info.info.global_conf.hash_func) {
12678         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
12679                 printf("Hash function is Toeplitz\n");
12680                 break;
12681         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
12682                 printf("Hash function is Simple XOR\n");
12683                 break;
12684         case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
12685                 printf("Hash function is Symmetric Toeplitz\n");
12686                 break;
12687         default:
12688                 printf("Unknown hash function\n");
12689                 break;
12690         }
12691
12692         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
12693                 idx = i / UINT64_BIT;
12694                 offset = i % UINT64_BIT;
12695                 if (!(info.info.global_conf.valid_bit_mask[idx] &
12696                                                 (1ULL << offset)))
12697                         continue;
12698                 str = flowtype_to_str(i);
12699                 if (!str)
12700                         continue;
12701                 printf("Symmetric hash is %s globally for flow type %s "
12702                                                         "by port %d\n",
12703                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
12704                         (1ULL << offset)) ? "enabled" : "disabled"), str,
12705                                                         res->port_id);
12706         }
12707 }
12708
12709 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
12710         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
12711                 get_hash_global_config, "get_hash_global_config");
12712 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
12713         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
12714                 port_id, UINT16);
12715
12716 cmdline_parse_inst_t cmd_get_hash_global_config = {
12717         .f = cmd_get_hash_global_config_parsed,
12718         .data = NULL,
12719         .help_str = "get_hash_global_config <port_id>",
12720         .tokens = {
12721                 (void *)&cmd_get_hash_global_config_all,
12722                 (void *)&cmd_get_hash_global_config_port_id,
12723                 NULL,
12724         },
12725 };
12726
12727 /* Set global config of hash function */
12728 struct cmd_set_hash_global_config_result {
12729         cmdline_fixed_string_t set_hash_global_config;
12730         portid_t port_id;
12731         cmdline_fixed_string_t hash_func;
12732         cmdline_fixed_string_t flow_type;
12733         cmdline_fixed_string_t enable;
12734 };
12735
12736 static void
12737 cmd_set_hash_global_config_parsed(void *parsed_result,
12738                                   __rte_unused struct cmdline *cl,
12739                                   __rte_unused void *data)
12740 {
12741         struct cmd_set_hash_global_config_result *res = parsed_result;
12742         struct rte_eth_hash_filter_info info;
12743         uint32_t ftype, idx, offset;
12744         int ret;
12745
12746         if (rte_eth_dev_filter_supported(res->port_id,
12747                                 RTE_ETH_FILTER_HASH) < 0) {
12748                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
12749                                                         res->port_id);
12750                 return;
12751         }
12752         memset(&info, 0, sizeof(info));
12753         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
12754         if (!strcmp(res->hash_func, "toeplitz"))
12755                 info.info.global_conf.hash_func =
12756                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
12757         else if (!strcmp(res->hash_func, "simple_xor"))
12758                 info.info.global_conf.hash_func =
12759                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
12760         else if (!strcmp(res->hash_func, "symmetric_toeplitz"))
12761                 info.info.global_conf.hash_func =
12762                         RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
12763         else if (!strcmp(res->hash_func, "default"))
12764                 info.info.global_conf.hash_func =
12765                         RTE_ETH_HASH_FUNCTION_DEFAULT;
12766
12767         ftype = str2flowtype(res->flow_type);
12768         idx = ftype / UINT64_BIT;
12769         offset = ftype % UINT64_BIT;
12770         info.info.global_conf.valid_bit_mask[idx] |= (1ULL << offset);
12771         if (!strcmp(res->enable, "enable"))
12772                 info.info.global_conf.sym_hash_enable_mask[idx] |=
12773                                                 (1ULL << offset);
12774         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12775                                         RTE_ETH_FILTER_SET, &info);
12776         if (ret < 0)
12777                 printf("Cannot set global hash configurations by port %d\n",
12778                                                         res->port_id);
12779         else
12780                 printf("Global hash configurations have been set "
12781                         "successfully by port %d\n", res->port_id);
12782 }
12783
12784 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
12785         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12786                 set_hash_global_config, "set_hash_global_config");
12787 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
12788         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
12789                 port_id, UINT16);
12790 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
12791         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12792                 hash_func, "toeplitz#simple_xor#symmetric_toeplitz#default");
12793 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
12794         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12795                 flow_type,
12796                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
12797                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12798 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
12799         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
12800                 enable, "enable#disable");
12801
12802 cmdline_parse_inst_t cmd_set_hash_global_config = {
12803         .f = cmd_set_hash_global_config_parsed,
12804         .data = NULL,
12805         .help_str = "set_hash_global_config <port_id> "
12806                 "toeplitz|simple_xor|symmetric_toeplitz|default "
12807                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12808                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
12809                 "l2_payload enable|disable",
12810         .tokens = {
12811                 (void *)&cmd_set_hash_global_config_all,
12812                 (void *)&cmd_set_hash_global_config_port_id,
12813                 (void *)&cmd_set_hash_global_config_hash_func,
12814                 (void *)&cmd_set_hash_global_config_flow_type,
12815                 (void *)&cmd_set_hash_global_config_enable,
12816                 NULL,
12817         },
12818 };
12819
12820 /* Set hash input set */
12821 struct cmd_set_hash_input_set_result {
12822         cmdline_fixed_string_t set_hash_input_set;
12823         portid_t port_id;
12824         cmdline_fixed_string_t flow_type;
12825         cmdline_fixed_string_t inset_field;
12826         cmdline_fixed_string_t select;
12827 };
12828
12829 static enum rte_eth_input_set_field
12830 str2inset(char *string)
12831 {
12832         uint16_t i;
12833
12834         static const struct {
12835                 char str[32];
12836                 enum rte_eth_input_set_field inset;
12837         } inset_table[] = {
12838                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
12839                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
12840                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
12841                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
12842                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
12843                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
12844                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
12845                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
12846                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
12847                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
12848                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
12849                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
12850                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
12851                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12852                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12853                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12854                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12855                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12856                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12857                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
12858                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
12859                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
12860                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
12861                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
12862                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
12863                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
12864                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
12865                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
12866                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
12867                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
12868                 {"none", RTE_ETH_INPUT_SET_NONE},
12869         };
12870
12871         for (i = 0; i < RTE_DIM(inset_table); i++) {
12872                 if (!strcmp(string, inset_table[i].str))
12873                         return inset_table[i].inset;
12874         }
12875
12876         return RTE_ETH_INPUT_SET_UNKNOWN;
12877 }
12878
12879 static void
12880 cmd_set_hash_input_set_parsed(void *parsed_result,
12881                               __rte_unused struct cmdline *cl,
12882                               __rte_unused void *data)
12883 {
12884         struct cmd_set_hash_input_set_result *res = parsed_result;
12885         struct rte_eth_hash_filter_info info;
12886
12887         memset(&info, 0, sizeof(info));
12888         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
12889         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12890         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12891         info.info.input_set_conf.inset_size = 1;
12892         if (!strcmp(res->select, "select"))
12893                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12894         else if (!strcmp(res->select, "add"))
12895                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12896         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
12897                                 RTE_ETH_FILTER_SET, &info);
12898 }
12899
12900 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
12901         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12902                 set_hash_input_set, "set_hash_input_set");
12903 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
12904         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
12905                 port_id, UINT16);
12906 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
12907         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12908                 flow_type, NULL);
12909 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
12910         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12911                 inset_field,
12912                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12913                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
12914                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
12915                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
12916                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
12917                 "fld-8th#none");
12918 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
12919         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
12920                 select, "select#add");
12921
12922 cmdline_parse_inst_t cmd_set_hash_input_set = {
12923         .f = cmd_set_hash_input_set_parsed,
12924         .data = NULL,
12925         .help_str = "set_hash_input_set <port_id> "
12926         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
12927         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
12928         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
12929         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
12930         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
12931         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
12932         "fld-7th|fld-8th|none select|add",
12933         .tokens = {
12934                 (void *)&cmd_set_hash_input_set_cmd,
12935                 (void *)&cmd_set_hash_input_set_port_id,
12936                 (void *)&cmd_set_hash_input_set_flow_type,
12937                 (void *)&cmd_set_hash_input_set_field,
12938                 (void *)&cmd_set_hash_input_set_select,
12939                 NULL,
12940         },
12941 };
12942
12943 /* Set flow director input set */
12944 struct cmd_set_fdir_input_set_result {
12945         cmdline_fixed_string_t set_fdir_input_set;
12946         portid_t port_id;
12947         cmdline_fixed_string_t flow_type;
12948         cmdline_fixed_string_t inset_field;
12949         cmdline_fixed_string_t select;
12950 };
12951
12952 static void
12953 cmd_set_fdir_input_set_parsed(void *parsed_result,
12954         __rte_unused struct cmdline *cl,
12955         __rte_unused void *data)
12956 {
12957         struct cmd_set_fdir_input_set_result *res = parsed_result;
12958         struct rte_eth_fdir_filter_info info;
12959
12960         memset(&info, 0, sizeof(info));
12961         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
12962         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
12963         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
12964         info.info.input_set_conf.inset_size = 1;
12965         if (!strcmp(res->select, "select"))
12966                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
12967         else if (!strcmp(res->select, "add"))
12968                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
12969         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
12970                 RTE_ETH_FILTER_SET, &info);
12971 }
12972
12973 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
12974         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12975         set_fdir_input_set, "set_fdir_input_set");
12976 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
12977         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
12978         port_id, UINT16);
12979 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
12980         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12981         flow_type,
12982         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
12983         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
12984 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
12985         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12986         inset_field,
12987         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
12988         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
12989         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
12990         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
12991         "sctp-veri-tag#none");
12992 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
12993         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
12994         select, "select#add");
12995
12996 cmdline_parse_inst_t cmd_set_fdir_input_set = {
12997         .f = cmd_set_fdir_input_set_parsed,
12998         .data = NULL,
12999         .help_str = "set_fdir_input_set <port_id> "
13000         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
13001         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
13002         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
13003         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
13004         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
13005         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
13006         "sctp-veri-tag|none select|add",
13007         .tokens = {
13008                 (void *)&cmd_set_fdir_input_set_cmd,
13009                 (void *)&cmd_set_fdir_input_set_port_id,
13010                 (void *)&cmd_set_fdir_input_set_flow_type,
13011                 (void *)&cmd_set_fdir_input_set_field,
13012                 (void *)&cmd_set_fdir_input_set_select,
13013                 NULL,
13014         },
13015 };
13016
13017 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
13018 struct cmd_mcast_addr_result {
13019         cmdline_fixed_string_t mcast_addr_cmd;
13020         cmdline_fixed_string_t what;
13021         uint16_t port_num;
13022         struct rte_ether_addr mc_addr;
13023 };
13024
13025 static void cmd_mcast_addr_parsed(void *parsed_result,
13026                 __rte_unused struct cmdline *cl,
13027                 __rte_unused void *data)
13028 {
13029         struct cmd_mcast_addr_result *res = parsed_result;
13030
13031         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
13032                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
13033                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
13034                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
13035                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
13036                 return;
13037         }
13038         if (strcmp(res->what, "add") == 0)
13039                 mcast_addr_add(res->port_num, &res->mc_addr);
13040         else
13041                 mcast_addr_remove(res->port_num, &res->mc_addr);
13042 }
13043
13044 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
13045         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
13046                                  mcast_addr_cmd, "mcast_addr");
13047 cmdline_parse_token_string_t cmd_mcast_addr_what =
13048         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
13049                                  "add#remove");
13050 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
13051         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
13052 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
13053         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
13054
13055 cmdline_parse_inst_t cmd_mcast_addr = {
13056         .f = cmd_mcast_addr_parsed,
13057         .data = (void *)0,
13058         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
13059                 "Add/Remove multicast MAC address on port_id",
13060         .tokens = {
13061                 (void *)&cmd_mcast_addr_cmd,
13062                 (void *)&cmd_mcast_addr_what,
13063                 (void *)&cmd_mcast_addr_portnum,
13064                 (void *)&cmd_mcast_addr_addr,
13065                 NULL,
13066         },
13067 };
13068
13069 /* l2 tunnel config
13070  * only support E-tag now.
13071  */
13072
13073 /* Ether type config */
13074 struct cmd_config_l2_tunnel_eth_type_result {
13075         cmdline_fixed_string_t port;
13076         cmdline_fixed_string_t config;
13077         cmdline_fixed_string_t all;
13078         portid_t id;
13079         cmdline_fixed_string_t l2_tunnel;
13080         cmdline_fixed_string_t l2_tunnel_type;
13081         cmdline_fixed_string_t eth_type;
13082         uint16_t eth_type_val;
13083 };
13084
13085 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
13086         TOKEN_STRING_INITIALIZER
13087                 (struct cmd_config_l2_tunnel_eth_type_result,
13088                  port, "port");
13089 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
13090         TOKEN_STRING_INITIALIZER
13091                 (struct cmd_config_l2_tunnel_eth_type_result,
13092                  config, "config");
13093 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
13094         TOKEN_STRING_INITIALIZER
13095                 (struct cmd_config_l2_tunnel_eth_type_result,
13096                  all, "all");
13097 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
13098         TOKEN_NUM_INITIALIZER
13099                 (struct cmd_config_l2_tunnel_eth_type_result,
13100                  id, UINT16);
13101 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
13102         TOKEN_STRING_INITIALIZER
13103                 (struct cmd_config_l2_tunnel_eth_type_result,
13104                  l2_tunnel, "l2-tunnel");
13105 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
13106         TOKEN_STRING_INITIALIZER
13107                 (struct cmd_config_l2_tunnel_eth_type_result,
13108                  l2_tunnel_type, "E-tag");
13109 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
13110         TOKEN_STRING_INITIALIZER
13111                 (struct cmd_config_l2_tunnel_eth_type_result,
13112                  eth_type, "ether-type");
13113 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
13114         TOKEN_NUM_INITIALIZER
13115                 (struct cmd_config_l2_tunnel_eth_type_result,
13116                  eth_type_val, UINT16);
13117
13118 static enum rte_eth_tunnel_type
13119 str2fdir_l2_tunnel_type(char *string)
13120 {
13121         uint32_t i = 0;
13122
13123         static const struct {
13124                 char str[32];
13125                 enum rte_eth_tunnel_type type;
13126         } l2_tunnel_type_str[] = {
13127                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
13128         };
13129
13130         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
13131                 if (!strcmp(l2_tunnel_type_str[i].str, string))
13132                         return l2_tunnel_type_str[i].type;
13133         }
13134         return RTE_TUNNEL_TYPE_NONE;
13135 }
13136
13137 /* ether type config for all ports */
13138 static void
13139 cmd_config_l2_tunnel_eth_type_all_parsed
13140         (void *parsed_result,
13141          __rte_unused struct cmdline *cl,
13142          __rte_unused void *data)
13143 {
13144         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
13145         struct rte_eth_l2_tunnel_conf entry;
13146         portid_t pid;
13147
13148         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13149         entry.ether_type = res->eth_type_val;
13150
13151         RTE_ETH_FOREACH_DEV(pid) {
13152                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
13153         }
13154 }
13155
13156 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
13157         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
13158         .data = NULL,
13159         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
13160         .tokens = {
13161                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13162                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13163                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
13164                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13165                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13166                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13167                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13168                 NULL,
13169         },
13170 };
13171
13172 /* ether type config for a specific port */
13173 static void
13174 cmd_config_l2_tunnel_eth_type_specific_parsed(
13175         void *parsed_result,
13176         __rte_unused struct cmdline *cl,
13177         __rte_unused void *data)
13178 {
13179         struct cmd_config_l2_tunnel_eth_type_result *res =
13180                  parsed_result;
13181         struct rte_eth_l2_tunnel_conf entry;
13182
13183         if (port_id_is_invalid(res->id, ENABLED_WARN))
13184                 return;
13185
13186         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13187         entry.ether_type = res->eth_type_val;
13188
13189         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
13190 }
13191
13192 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
13193         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
13194         .data = NULL,
13195         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
13196         .tokens = {
13197                 (void *)&cmd_config_l2_tunnel_eth_type_port,
13198                 (void *)&cmd_config_l2_tunnel_eth_type_config,
13199                 (void *)&cmd_config_l2_tunnel_eth_type_id,
13200                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
13201                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
13202                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
13203                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
13204                 NULL,
13205         },
13206 };
13207
13208 /* Enable/disable l2 tunnel */
13209 struct cmd_config_l2_tunnel_en_dis_result {
13210         cmdline_fixed_string_t port;
13211         cmdline_fixed_string_t config;
13212         cmdline_fixed_string_t all;
13213         portid_t id;
13214         cmdline_fixed_string_t l2_tunnel;
13215         cmdline_fixed_string_t l2_tunnel_type;
13216         cmdline_fixed_string_t en_dis;
13217 };
13218
13219 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
13220         TOKEN_STRING_INITIALIZER
13221                 (struct cmd_config_l2_tunnel_en_dis_result,
13222                  port, "port");
13223 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
13224         TOKEN_STRING_INITIALIZER
13225                 (struct cmd_config_l2_tunnel_en_dis_result,
13226                  config, "config");
13227 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
13228         TOKEN_STRING_INITIALIZER
13229                 (struct cmd_config_l2_tunnel_en_dis_result,
13230                  all, "all");
13231 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
13232         TOKEN_NUM_INITIALIZER
13233                 (struct cmd_config_l2_tunnel_en_dis_result,
13234                  id, UINT16);
13235 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
13236         TOKEN_STRING_INITIALIZER
13237                 (struct cmd_config_l2_tunnel_en_dis_result,
13238                  l2_tunnel, "l2-tunnel");
13239 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
13240         TOKEN_STRING_INITIALIZER
13241                 (struct cmd_config_l2_tunnel_en_dis_result,
13242                  l2_tunnel_type, "E-tag");
13243 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
13244         TOKEN_STRING_INITIALIZER
13245                 (struct cmd_config_l2_tunnel_en_dis_result,
13246                  en_dis, "enable#disable");
13247
13248 /* enable/disable l2 tunnel for all ports */
13249 static void
13250 cmd_config_l2_tunnel_en_dis_all_parsed(
13251         void *parsed_result,
13252         __rte_unused struct cmdline *cl,
13253         __rte_unused void *data)
13254 {
13255         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
13256         struct rte_eth_l2_tunnel_conf entry;
13257         portid_t pid;
13258         uint8_t en;
13259
13260         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13261
13262         if (!strcmp("enable", res->en_dis))
13263                 en = 1;
13264         else
13265                 en = 0;
13266
13267         RTE_ETH_FOREACH_DEV(pid) {
13268                 rte_eth_dev_l2_tunnel_offload_set(pid,
13269                                                   &entry,
13270                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13271                                                   en);
13272         }
13273 }
13274
13275 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
13276         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
13277         .data = NULL,
13278         .help_str = "port config all l2-tunnel E-tag enable|disable",
13279         .tokens = {
13280                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13281                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13282                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
13283                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13284                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13285                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13286                 NULL,
13287         },
13288 };
13289
13290 /* enable/disable l2 tunnel for a port */
13291 static void
13292 cmd_config_l2_tunnel_en_dis_specific_parsed(
13293         void *parsed_result,
13294         __rte_unused struct cmdline *cl,
13295         __rte_unused void *data)
13296 {
13297         struct cmd_config_l2_tunnel_en_dis_result *res =
13298                 parsed_result;
13299         struct rte_eth_l2_tunnel_conf entry;
13300
13301         if (port_id_is_invalid(res->id, ENABLED_WARN))
13302                 return;
13303
13304         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
13305
13306         if (!strcmp("enable", res->en_dis))
13307                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13308                                                   &entry,
13309                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13310                                                   1);
13311         else
13312                 rte_eth_dev_l2_tunnel_offload_set(res->id,
13313                                                   &entry,
13314                                                   ETH_L2_TUNNEL_ENABLE_MASK,
13315                                                   0);
13316 }
13317
13318 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
13319         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
13320         .data = NULL,
13321         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
13322         .tokens = {
13323                 (void *)&cmd_config_l2_tunnel_en_dis_port,
13324                 (void *)&cmd_config_l2_tunnel_en_dis_config,
13325                 (void *)&cmd_config_l2_tunnel_en_dis_id,
13326                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
13327                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
13328                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
13329                 NULL,
13330         },
13331 };
13332
13333 /* E-tag configuration */
13334
13335 /* Common result structure for all E-tag configuration */
13336 struct cmd_config_e_tag_result {
13337         cmdline_fixed_string_t e_tag;
13338         cmdline_fixed_string_t set;
13339         cmdline_fixed_string_t insertion;
13340         cmdline_fixed_string_t stripping;
13341         cmdline_fixed_string_t forwarding;
13342         cmdline_fixed_string_t filter;
13343         cmdline_fixed_string_t add;
13344         cmdline_fixed_string_t del;
13345         cmdline_fixed_string_t on;
13346         cmdline_fixed_string_t off;
13347         cmdline_fixed_string_t on_off;
13348         cmdline_fixed_string_t port_tag_id;
13349         uint32_t port_tag_id_val;
13350         cmdline_fixed_string_t e_tag_id;
13351         uint16_t e_tag_id_val;
13352         cmdline_fixed_string_t dst_pool;
13353         uint8_t dst_pool_val;
13354         cmdline_fixed_string_t port;
13355         portid_t port_id;
13356         cmdline_fixed_string_t vf;
13357         uint8_t vf_id;
13358 };
13359
13360 /* Common CLI fields for all E-tag configuration */
13361 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
13362         TOKEN_STRING_INITIALIZER
13363                 (struct cmd_config_e_tag_result,
13364                  e_tag, "E-tag");
13365 cmdline_parse_token_string_t cmd_config_e_tag_set =
13366         TOKEN_STRING_INITIALIZER
13367                 (struct cmd_config_e_tag_result,
13368                  set, "set");
13369 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
13370         TOKEN_STRING_INITIALIZER
13371                 (struct cmd_config_e_tag_result,
13372                  insertion, "insertion");
13373 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
13374         TOKEN_STRING_INITIALIZER
13375                 (struct cmd_config_e_tag_result,
13376                  stripping, "stripping");
13377 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_config_e_tag_result,
13380                  forwarding, "forwarding");
13381 cmdline_parse_token_string_t cmd_config_e_tag_filter =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_config_e_tag_result,
13384                  filter, "filter");
13385 cmdline_parse_token_string_t cmd_config_e_tag_add =
13386         TOKEN_STRING_INITIALIZER
13387                 (struct cmd_config_e_tag_result,
13388                  add, "add");
13389 cmdline_parse_token_string_t cmd_config_e_tag_del =
13390         TOKEN_STRING_INITIALIZER
13391                 (struct cmd_config_e_tag_result,
13392                  del, "del");
13393 cmdline_parse_token_string_t cmd_config_e_tag_on =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_config_e_tag_result,
13396                  on, "on");
13397 cmdline_parse_token_string_t cmd_config_e_tag_off =
13398         TOKEN_STRING_INITIALIZER
13399                 (struct cmd_config_e_tag_result,
13400                  off, "off");
13401 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
13402         TOKEN_STRING_INITIALIZER
13403                 (struct cmd_config_e_tag_result,
13404                  on_off, "on#off");
13405 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
13406         TOKEN_STRING_INITIALIZER
13407                 (struct cmd_config_e_tag_result,
13408                  port_tag_id, "port-tag-id");
13409 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
13410         TOKEN_NUM_INITIALIZER
13411                 (struct cmd_config_e_tag_result,
13412                  port_tag_id_val, UINT32);
13413 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
13414         TOKEN_STRING_INITIALIZER
13415                 (struct cmd_config_e_tag_result,
13416                  e_tag_id, "e-tag-id");
13417 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
13418         TOKEN_NUM_INITIALIZER
13419                 (struct cmd_config_e_tag_result,
13420                  e_tag_id_val, UINT16);
13421 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
13422         TOKEN_STRING_INITIALIZER
13423                 (struct cmd_config_e_tag_result,
13424                  dst_pool, "dst-pool");
13425 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
13426         TOKEN_NUM_INITIALIZER
13427                 (struct cmd_config_e_tag_result,
13428                  dst_pool_val, UINT8);
13429 cmdline_parse_token_string_t cmd_config_e_tag_port =
13430         TOKEN_STRING_INITIALIZER
13431                 (struct cmd_config_e_tag_result,
13432                  port, "port");
13433 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
13434         TOKEN_NUM_INITIALIZER
13435                 (struct cmd_config_e_tag_result,
13436                  port_id, UINT16);
13437 cmdline_parse_token_string_t cmd_config_e_tag_vf =
13438         TOKEN_STRING_INITIALIZER
13439                 (struct cmd_config_e_tag_result,
13440                  vf, "vf");
13441 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
13442         TOKEN_NUM_INITIALIZER
13443                 (struct cmd_config_e_tag_result,
13444                  vf_id, UINT8);
13445
13446 /* E-tag insertion configuration */
13447 static void
13448 cmd_config_e_tag_insertion_en_parsed(
13449         void *parsed_result,
13450         __rte_unused struct cmdline *cl,
13451         __rte_unused void *data)
13452 {
13453         struct cmd_config_e_tag_result *res =
13454                 parsed_result;
13455         struct rte_eth_l2_tunnel_conf entry;
13456
13457         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13458                 return;
13459
13460         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13461         entry.tunnel_id = res->port_tag_id_val;
13462         entry.vf_id = res->vf_id;
13463         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13464                                           &entry,
13465                                           ETH_L2_TUNNEL_INSERTION_MASK,
13466                                           1);
13467 }
13468
13469 static void
13470 cmd_config_e_tag_insertion_dis_parsed(
13471         void *parsed_result,
13472         __rte_unused struct cmdline *cl,
13473         __rte_unused void *data)
13474 {
13475         struct cmd_config_e_tag_result *res =
13476                 parsed_result;
13477         struct rte_eth_l2_tunnel_conf entry;
13478
13479         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13480                 return;
13481
13482         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13483         entry.vf_id = res->vf_id;
13484
13485         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
13486                                           &entry,
13487                                           ETH_L2_TUNNEL_INSERTION_MASK,
13488                                           0);
13489 }
13490
13491 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
13492         .f = cmd_config_e_tag_insertion_en_parsed,
13493         .data = NULL,
13494         .help_str = "E-tag ... : E-tag insertion enable",
13495         .tokens = {
13496                 (void *)&cmd_config_e_tag_e_tag,
13497                 (void *)&cmd_config_e_tag_set,
13498                 (void *)&cmd_config_e_tag_insertion,
13499                 (void *)&cmd_config_e_tag_on,
13500                 (void *)&cmd_config_e_tag_port_tag_id,
13501                 (void *)&cmd_config_e_tag_port_tag_id_val,
13502                 (void *)&cmd_config_e_tag_port,
13503                 (void *)&cmd_config_e_tag_port_id,
13504                 (void *)&cmd_config_e_tag_vf,
13505                 (void *)&cmd_config_e_tag_vf_id,
13506                 NULL,
13507         },
13508 };
13509
13510 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
13511         .f = cmd_config_e_tag_insertion_dis_parsed,
13512         .data = NULL,
13513         .help_str = "E-tag ... : E-tag insertion disable",
13514         .tokens = {
13515                 (void *)&cmd_config_e_tag_e_tag,
13516                 (void *)&cmd_config_e_tag_set,
13517                 (void *)&cmd_config_e_tag_insertion,
13518                 (void *)&cmd_config_e_tag_off,
13519                 (void *)&cmd_config_e_tag_port,
13520                 (void *)&cmd_config_e_tag_port_id,
13521                 (void *)&cmd_config_e_tag_vf,
13522                 (void *)&cmd_config_e_tag_vf_id,
13523                 NULL,
13524         },
13525 };
13526
13527 /* E-tag stripping configuration */
13528 static void
13529 cmd_config_e_tag_stripping_parsed(
13530         void *parsed_result,
13531         __rte_unused struct cmdline *cl,
13532         __rte_unused void *data)
13533 {
13534         struct cmd_config_e_tag_result *res =
13535                 parsed_result;
13536         struct rte_eth_l2_tunnel_conf entry;
13537
13538         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13539                 return;
13540
13541         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13542
13543         if (!strcmp(res->on_off, "on"))
13544                 rte_eth_dev_l2_tunnel_offload_set
13545                         (res->port_id,
13546                          &entry,
13547                          ETH_L2_TUNNEL_STRIPPING_MASK,
13548                          1);
13549         else
13550                 rte_eth_dev_l2_tunnel_offload_set
13551                         (res->port_id,
13552                          &entry,
13553                          ETH_L2_TUNNEL_STRIPPING_MASK,
13554                          0);
13555 }
13556
13557 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
13558         .f = cmd_config_e_tag_stripping_parsed,
13559         .data = NULL,
13560         .help_str = "E-tag ... : E-tag stripping enable/disable",
13561         .tokens = {
13562                 (void *)&cmd_config_e_tag_e_tag,
13563                 (void *)&cmd_config_e_tag_set,
13564                 (void *)&cmd_config_e_tag_stripping,
13565                 (void *)&cmd_config_e_tag_on_off,
13566                 (void *)&cmd_config_e_tag_port,
13567                 (void *)&cmd_config_e_tag_port_id,
13568                 NULL,
13569         },
13570 };
13571
13572 /* E-tag forwarding configuration */
13573 static void
13574 cmd_config_e_tag_forwarding_parsed(
13575         void *parsed_result,
13576         __rte_unused struct cmdline *cl,
13577         __rte_unused void *data)
13578 {
13579         struct cmd_config_e_tag_result *res = parsed_result;
13580         struct rte_eth_l2_tunnel_conf entry;
13581
13582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13583                 return;
13584
13585         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13586
13587         if (!strcmp(res->on_off, "on"))
13588                 rte_eth_dev_l2_tunnel_offload_set
13589                         (res->port_id,
13590                          &entry,
13591                          ETH_L2_TUNNEL_FORWARDING_MASK,
13592                          1);
13593         else
13594                 rte_eth_dev_l2_tunnel_offload_set
13595                         (res->port_id,
13596                          &entry,
13597                          ETH_L2_TUNNEL_FORWARDING_MASK,
13598                          0);
13599 }
13600
13601 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
13602         .f = cmd_config_e_tag_forwarding_parsed,
13603         .data = NULL,
13604         .help_str = "E-tag ... : E-tag forwarding enable/disable",
13605         .tokens = {
13606                 (void *)&cmd_config_e_tag_e_tag,
13607                 (void *)&cmd_config_e_tag_set,
13608                 (void *)&cmd_config_e_tag_forwarding,
13609                 (void *)&cmd_config_e_tag_on_off,
13610                 (void *)&cmd_config_e_tag_port,
13611                 (void *)&cmd_config_e_tag_port_id,
13612                 NULL,
13613         },
13614 };
13615
13616 /* E-tag filter configuration */
13617 static void
13618 cmd_config_e_tag_filter_add_parsed(
13619         void *parsed_result,
13620         __rte_unused struct cmdline *cl,
13621         __rte_unused void *data)
13622 {
13623         struct cmd_config_e_tag_result *res = parsed_result;
13624         struct rte_eth_l2_tunnel_conf entry;
13625         int ret = 0;
13626
13627         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13628                 return;
13629
13630         if (res->e_tag_id_val > 0x3fff) {
13631                 printf("e-tag-id must be equal or less than 0x3fff.\n");
13632                 return;
13633         }
13634
13635         ret = rte_eth_dev_filter_supported(res->port_id,
13636                                            RTE_ETH_FILTER_L2_TUNNEL);
13637         if (ret < 0) {
13638                 printf("E-tag filter is not supported on port %u.\n",
13639                        res->port_id);
13640                 return;
13641         }
13642
13643         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13644         entry.tunnel_id = res->e_tag_id_val;
13645         entry.pool = res->dst_pool_val;
13646
13647         ret = rte_eth_dev_filter_ctrl(res->port_id,
13648                                       RTE_ETH_FILTER_L2_TUNNEL,
13649                                       RTE_ETH_FILTER_ADD,
13650                                       &entry);
13651         if (ret < 0)
13652                 printf("E-tag filter programming error: (%s)\n",
13653                        strerror(-ret));
13654 }
13655
13656 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
13657         .f = cmd_config_e_tag_filter_add_parsed,
13658         .data = NULL,
13659         .help_str = "E-tag ... : E-tag filter add",
13660         .tokens = {
13661                 (void *)&cmd_config_e_tag_e_tag,
13662                 (void *)&cmd_config_e_tag_set,
13663                 (void *)&cmd_config_e_tag_filter,
13664                 (void *)&cmd_config_e_tag_add,
13665                 (void *)&cmd_config_e_tag_e_tag_id,
13666                 (void *)&cmd_config_e_tag_e_tag_id_val,
13667                 (void *)&cmd_config_e_tag_dst_pool,
13668                 (void *)&cmd_config_e_tag_dst_pool_val,
13669                 (void *)&cmd_config_e_tag_port,
13670                 (void *)&cmd_config_e_tag_port_id,
13671                 NULL,
13672         },
13673 };
13674
13675 static void
13676 cmd_config_e_tag_filter_del_parsed(
13677         void *parsed_result,
13678         __rte_unused struct cmdline *cl,
13679         __rte_unused void *data)
13680 {
13681         struct cmd_config_e_tag_result *res = parsed_result;
13682         struct rte_eth_l2_tunnel_conf entry;
13683         int ret = 0;
13684
13685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13686                 return;
13687
13688         if (res->e_tag_id_val > 0x3fff) {
13689                 printf("e-tag-id must be less than 0x3fff.\n");
13690                 return;
13691         }
13692
13693         ret = rte_eth_dev_filter_supported(res->port_id,
13694                                            RTE_ETH_FILTER_L2_TUNNEL);
13695         if (ret < 0) {
13696                 printf("E-tag filter is not supported on port %u.\n",
13697                        res->port_id);
13698                 return;
13699         }
13700
13701         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
13702         entry.tunnel_id = res->e_tag_id_val;
13703
13704         ret = rte_eth_dev_filter_ctrl(res->port_id,
13705                                       RTE_ETH_FILTER_L2_TUNNEL,
13706                                       RTE_ETH_FILTER_DELETE,
13707                                       &entry);
13708         if (ret < 0)
13709                 printf("E-tag filter programming error: (%s)\n",
13710                        strerror(-ret));
13711 }
13712
13713 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
13714         .f = cmd_config_e_tag_filter_del_parsed,
13715         .data = NULL,
13716         .help_str = "E-tag ... : E-tag filter delete",
13717         .tokens = {
13718                 (void *)&cmd_config_e_tag_e_tag,
13719                 (void *)&cmd_config_e_tag_set,
13720                 (void *)&cmd_config_e_tag_filter,
13721                 (void *)&cmd_config_e_tag_del,
13722                 (void *)&cmd_config_e_tag_e_tag_id,
13723                 (void *)&cmd_config_e_tag_e_tag_id_val,
13724                 (void *)&cmd_config_e_tag_port,
13725                 (void *)&cmd_config_e_tag_port_id,
13726                 NULL,
13727         },
13728 };
13729
13730 /* vf vlan anti spoof configuration */
13731
13732 /* Common result structure for vf vlan anti spoof */
13733 struct cmd_vf_vlan_anti_spoof_result {
13734         cmdline_fixed_string_t set;
13735         cmdline_fixed_string_t vf;
13736         cmdline_fixed_string_t vlan;
13737         cmdline_fixed_string_t antispoof;
13738         portid_t port_id;
13739         uint32_t vf_id;
13740         cmdline_fixed_string_t on_off;
13741 };
13742
13743 /* Common CLI fields for vf vlan anti spoof enable disable */
13744 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_vf_vlan_anti_spoof_result,
13747                  set, "set");
13748 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_vf_vlan_anti_spoof_result,
13751                  vf, "vf");
13752 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
13753         TOKEN_STRING_INITIALIZER
13754                 (struct cmd_vf_vlan_anti_spoof_result,
13755                  vlan, "vlan");
13756 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
13757         TOKEN_STRING_INITIALIZER
13758                 (struct cmd_vf_vlan_anti_spoof_result,
13759                  antispoof, "antispoof");
13760 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
13761         TOKEN_NUM_INITIALIZER
13762                 (struct cmd_vf_vlan_anti_spoof_result,
13763                  port_id, UINT16);
13764 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
13765         TOKEN_NUM_INITIALIZER
13766                 (struct cmd_vf_vlan_anti_spoof_result,
13767                  vf_id, UINT32);
13768 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
13769         TOKEN_STRING_INITIALIZER
13770                 (struct cmd_vf_vlan_anti_spoof_result,
13771                  on_off, "on#off");
13772
13773 static void
13774 cmd_set_vf_vlan_anti_spoof_parsed(
13775         void *parsed_result,
13776         __rte_unused struct cmdline *cl,
13777         __rte_unused void *data)
13778 {
13779         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
13780         int ret = -ENOTSUP;
13781
13782         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13783
13784         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13785                 return;
13786
13787 #ifdef RTE_LIBRTE_IXGBE_PMD
13788         if (ret == -ENOTSUP)
13789                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
13790                                 res->vf_id, is_on);
13791 #endif
13792 #ifdef RTE_LIBRTE_I40E_PMD
13793         if (ret == -ENOTSUP)
13794                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
13795                                 res->vf_id, is_on);
13796 #endif
13797 #ifdef RTE_LIBRTE_BNXT_PMD
13798         if (ret == -ENOTSUP)
13799                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
13800                                 res->vf_id, is_on);
13801 #endif
13802
13803         switch (ret) {
13804         case 0:
13805                 break;
13806         case -EINVAL:
13807                 printf("invalid vf_id %d\n", res->vf_id);
13808                 break;
13809         case -ENODEV:
13810                 printf("invalid port_id %d\n", res->port_id);
13811                 break;
13812         case -ENOTSUP:
13813                 printf("function not implemented\n");
13814                 break;
13815         default:
13816                 printf("programming error: (%s)\n", strerror(-ret));
13817         }
13818 }
13819
13820 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
13821         .f = cmd_set_vf_vlan_anti_spoof_parsed,
13822         .data = NULL,
13823         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
13824         .tokens = {
13825                 (void *)&cmd_vf_vlan_anti_spoof_set,
13826                 (void *)&cmd_vf_vlan_anti_spoof_vf,
13827                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
13828                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
13829                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
13830                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
13831                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
13832                 NULL,
13833         },
13834 };
13835
13836 /* vf mac anti spoof configuration */
13837
13838 /* Common result structure for vf mac anti spoof */
13839 struct cmd_vf_mac_anti_spoof_result {
13840         cmdline_fixed_string_t set;
13841         cmdline_fixed_string_t vf;
13842         cmdline_fixed_string_t mac;
13843         cmdline_fixed_string_t antispoof;
13844         portid_t port_id;
13845         uint32_t vf_id;
13846         cmdline_fixed_string_t on_off;
13847 };
13848
13849 /* Common CLI fields for vf mac anti spoof enable disable */
13850 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
13851         TOKEN_STRING_INITIALIZER
13852                 (struct cmd_vf_mac_anti_spoof_result,
13853                  set, "set");
13854 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
13855         TOKEN_STRING_INITIALIZER
13856                 (struct cmd_vf_mac_anti_spoof_result,
13857                  vf, "vf");
13858 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
13859         TOKEN_STRING_INITIALIZER
13860                 (struct cmd_vf_mac_anti_spoof_result,
13861                  mac, "mac");
13862 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
13863         TOKEN_STRING_INITIALIZER
13864                 (struct cmd_vf_mac_anti_spoof_result,
13865                  antispoof, "antispoof");
13866 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
13867         TOKEN_NUM_INITIALIZER
13868                 (struct cmd_vf_mac_anti_spoof_result,
13869                  port_id, UINT16);
13870 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
13871         TOKEN_NUM_INITIALIZER
13872                 (struct cmd_vf_mac_anti_spoof_result,
13873                  vf_id, UINT32);
13874 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
13875         TOKEN_STRING_INITIALIZER
13876                 (struct cmd_vf_mac_anti_spoof_result,
13877                  on_off, "on#off");
13878
13879 static void
13880 cmd_set_vf_mac_anti_spoof_parsed(
13881         void *parsed_result,
13882         __rte_unused struct cmdline *cl,
13883         __rte_unused void *data)
13884 {
13885         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
13886         int ret = -ENOTSUP;
13887
13888         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13889
13890         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13891                 return;
13892
13893 #ifdef RTE_LIBRTE_IXGBE_PMD
13894         if (ret == -ENOTSUP)
13895                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
13896                         res->vf_id, is_on);
13897 #endif
13898 #ifdef RTE_LIBRTE_I40E_PMD
13899         if (ret == -ENOTSUP)
13900                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
13901                         res->vf_id, is_on);
13902 #endif
13903 #ifdef RTE_LIBRTE_BNXT_PMD
13904         if (ret == -ENOTSUP)
13905                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
13906                         res->vf_id, is_on);
13907 #endif
13908
13909         switch (ret) {
13910         case 0:
13911                 break;
13912         case -EINVAL:
13913                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13914                 break;
13915         case -ENODEV:
13916                 printf("invalid port_id %d\n", res->port_id);
13917                 break;
13918         case -ENOTSUP:
13919                 printf("function not implemented\n");
13920                 break;
13921         default:
13922                 printf("programming error: (%s)\n", strerror(-ret));
13923         }
13924 }
13925
13926 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
13927         .f = cmd_set_vf_mac_anti_spoof_parsed,
13928         .data = NULL,
13929         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
13930         .tokens = {
13931                 (void *)&cmd_vf_mac_anti_spoof_set,
13932                 (void *)&cmd_vf_mac_anti_spoof_vf,
13933                 (void *)&cmd_vf_mac_anti_spoof_mac,
13934                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
13935                 (void *)&cmd_vf_mac_anti_spoof_port_id,
13936                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
13937                 (void *)&cmd_vf_mac_anti_spoof_on_off,
13938                 NULL,
13939         },
13940 };
13941
13942 /* vf vlan strip queue configuration */
13943
13944 /* Common result structure for vf mac anti spoof */
13945 struct cmd_vf_vlan_stripq_result {
13946         cmdline_fixed_string_t set;
13947         cmdline_fixed_string_t vf;
13948         cmdline_fixed_string_t vlan;
13949         cmdline_fixed_string_t stripq;
13950         portid_t port_id;
13951         uint16_t vf_id;
13952         cmdline_fixed_string_t on_off;
13953 };
13954
13955 /* Common CLI fields for vf vlan strip enable disable */
13956 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
13957         TOKEN_STRING_INITIALIZER
13958                 (struct cmd_vf_vlan_stripq_result,
13959                  set, "set");
13960 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
13961         TOKEN_STRING_INITIALIZER
13962                 (struct cmd_vf_vlan_stripq_result,
13963                  vf, "vf");
13964 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
13965         TOKEN_STRING_INITIALIZER
13966                 (struct cmd_vf_vlan_stripq_result,
13967                  vlan, "vlan");
13968 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
13969         TOKEN_STRING_INITIALIZER
13970                 (struct cmd_vf_vlan_stripq_result,
13971                  stripq, "stripq");
13972 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
13973         TOKEN_NUM_INITIALIZER
13974                 (struct cmd_vf_vlan_stripq_result,
13975                  port_id, UINT16);
13976 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
13977         TOKEN_NUM_INITIALIZER
13978                 (struct cmd_vf_vlan_stripq_result,
13979                  vf_id, UINT16);
13980 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
13981         TOKEN_STRING_INITIALIZER
13982                 (struct cmd_vf_vlan_stripq_result,
13983                  on_off, "on#off");
13984
13985 static void
13986 cmd_set_vf_vlan_stripq_parsed(
13987         void *parsed_result,
13988         __rte_unused struct cmdline *cl,
13989         __rte_unused void *data)
13990 {
13991         struct cmd_vf_vlan_stripq_result *res = parsed_result;
13992         int ret = -ENOTSUP;
13993
13994         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13995
13996         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13997                 return;
13998
13999 #ifdef RTE_LIBRTE_IXGBE_PMD
14000         if (ret == -ENOTSUP)
14001                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
14002                         res->vf_id, is_on);
14003 #endif
14004 #ifdef RTE_LIBRTE_I40E_PMD
14005         if (ret == -ENOTSUP)
14006                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
14007                         res->vf_id, is_on);
14008 #endif
14009 #ifdef RTE_LIBRTE_BNXT_PMD
14010         if (ret == -ENOTSUP)
14011                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
14012                         res->vf_id, is_on);
14013 #endif
14014
14015         switch (ret) {
14016         case 0:
14017                 break;
14018         case -EINVAL:
14019                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14020                 break;
14021         case -ENODEV:
14022                 printf("invalid port_id %d\n", res->port_id);
14023                 break;
14024         case -ENOTSUP:
14025                 printf("function not implemented\n");
14026                 break;
14027         default:
14028                 printf("programming error: (%s)\n", strerror(-ret));
14029         }
14030 }
14031
14032 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
14033         .f = cmd_set_vf_vlan_stripq_parsed,
14034         .data = NULL,
14035         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
14036         .tokens = {
14037                 (void *)&cmd_vf_vlan_stripq_set,
14038                 (void *)&cmd_vf_vlan_stripq_vf,
14039                 (void *)&cmd_vf_vlan_stripq_vlan,
14040                 (void *)&cmd_vf_vlan_stripq_stripq,
14041                 (void *)&cmd_vf_vlan_stripq_port_id,
14042                 (void *)&cmd_vf_vlan_stripq_vf_id,
14043                 (void *)&cmd_vf_vlan_stripq_on_off,
14044                 NULL,
14045         },
14046 };
14047
14048 /* vf vlan insert configuration */
14049
14050 /* Common result structure for vf vlan insert */
14051 struct cmd_vf_vlan_insert_result {
14052         cmdline_fixed_string_t set;
14053         cmdline_fixed_string_t vf;
14054         cmdline_fixed_string_t vlan;
14055         cmdline_fixed_string_t insert;
14056         portid_t port_id;
14057         uint16_t vf_id;
14058         uint16_t vlan_id;
14059 };
14060
14061 /* Common CLI fields for vf vlan insert enable disable */
14062 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
14063         TOKEN_STRING_INITIALIZER
14064                 (struct cmd_vf_vlan_insert_result,
14065                  set, "set");
14066 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
14067         TOKEN_STRING_INITIALIZER
14068                 (struct cmd_vf_vlan_insert_result,
14069                  vf, "vf");
14070 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
14071         TOKEN_STRING_INITIALIZER
14072                 (struct cmd_vf_vlan_insert_result,
14073                  vlan, "vlan");
14074 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
14075         TOKEN_STRING_INITIALIZER
14076                 (struct cmd_vf_vlan_insert_result,
14077                  insert, "insert");
14078 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
14079         TOKEN_NUM_INITIALIZER
14080                 (struct cmd_vf_vlan_insert_result,
14081                  port_id, UINT16);
14082 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
14083         TOKEN_NUM_INITIALIZER
14084                 (struct cmd_vf_vlan_insert_result,
14085                  vf_id, UINT16);
14086 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
14087         TOKEN_NUM_INITIALIZER
14088                 (struct cmd_vf_vlan_insert_result,
14089                  vlan_id, UINT16);
14090
14091 static void
14092 cmd_set_vf_vlan_insert_parsed(
14093         void *parsed_result,
14094         __rte_unused struct cmdline *cl,
14095         __rte_unused void *data)
14096 {
14097         struct cmd_vf_vlan_insert_result *res = parsed_result;
14098         int ret = -ENOTSUP;
14099
14100         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14101                 return;
14102
14103 #ifdef RTE_LIBRTE_IXGBE_PMD
14104         if (ret == -ENOTSUP)
14105                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
14106                         res->vlan_id);
14107 #endif
14108 #ifdef RTE_LIBRTE_I40E_PMD
14109         if (ret == -ENOTSUP)
14110                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
14111                         res->vlan_id);
14112 #endif
14113 #ifdef RTE_LIBRTE_BNXT_PMD
14114         if (ret == -ENOTSUP)
14115                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
14116                         res->vlan_id);
14117 #endif
14118
14119         switch (ret) {
14120         case 0:
14121                 break;
14122         case -EINVAL:
14123                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
14124                 break;
14125         case -ENODEV:
14126                 printf("invalid port_id %d\n", res->port_id);
14127                 break;
14128         case -ENOTSUP:
14129                 printf("function not implemented\n");
14130                 break;
14131         default:
14132                 printf("programming error: (%s)\n", strerror(-ret));
14133         }
14134 }
14135
14136 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
14137         .f = cmd_set_vf_vlan_insert_parsed,
14138         .data = NULL,
14139         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
14140         .tokens = {
14141                 (void *)&cmd_vf_vlan_insert_set,
14142                 (void *)&cmd_vf_vlan_insert_vf,
14143                 (void *)&cmd_vf_vlan_insert_vlan,
14144                 (void *)&cmd_vf_vlan_insert_insert,
14145                 (void *)&cmd_vf_vlan_insert_port_id,
14146                 (void *)&cmd_vf_vlan_insert_vf_id,
14147                 (void *)&cmd_vf_vlan_insert_vlan_id,
14148                 NULL,
14149         },
14150 };
14151
14152 /* tx loopback configuration */
14153
14154 /* Common result structure for tx loopback */
14155 struct cmd_tx_loopback_result {
14156         cmdline_fixed_string_t set;
14157         cmdline_fixed_string_t tx;
14158         cmdline_fixed_string_t loopback;
14159         portid_t port_id;
14160         cmdline_fixed_string_t on_off;
14161 };
14162
14163 /* Common CLI fields for tx loopback enable disable */
14164 cmdline_parse_token_string_t cmd_tx_loopback_set =
14165         TOKEN_STRING_INITIALIZER
14166                 (struct cmd_tx_loopback_result,
14167                  set, "set");
14168 cmdline_parse_token_string_t cmd_tx_loopback_tx =
14169         TOKEN_STRING_INITIALIZER
14170                 (struct cmd_tx_loopback_result,
14171                  tx, "tx");
14172 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
14173         TOKEN_STRING_INITIALIZER
14174                 (struct cmd_tx_loopback_result,
14175                  loopback, "loopback");
14176 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
14177         TOKEN_NUM_INITIALIZER
14178                 (struct cmd_tx_loopback_result,
14179                  port_id, UINT16);
14180 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
14181         TOKEN_STRING_INITIALIZER
14182                 (struct cmd_tx_loopback_result,
14183                  on_off, "on#off");
14184
14185 static void
14186 cmd_set_tx_loopback_parsed(
14187         void *parsed_result,
14188         __rte_unused struct cmdline *cl,
14189         __rte_unused void *data)
14190 {
14191         struct cmd_tx_loopback_result *res = parsed_result;
14192         int ret = -ENOTSUP;
14193
14194         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14195
14196         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14197                 return;
14198
14199 #ifdef RTE_LIBRTE_IXGBE_PMD
14200         if (ret == -ENOTSUP)
14201                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
14202 #endif
14203 #ifdef RTE_LIBRTE_I40E_PMD
14204         if (ret == -ENOTSUP)
14205                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
14206 #endif
14207 #ifdef RTE_LIBRTE_BNXT_PMD
14208         if (ret == -ENOTSUP)
14209                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
14210 #endif
14211 #if defined RTE_LIBRTE_DPAA_BUS && defined RTE_LIBRTE_DPAA_PMD
14212         if (ret == -ENOTSUP)
14213                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
14214 #endif
14215
14216         switch (ret) {
14217         case 0:
14218                 break;
14219         case -EINVAL:
14220                 printf("invalid is_on %d\n", is_on);
14221                 break;
14222         case -ENODEV:
14223                 printf("invalid port_id %d\n", res->port_id);
14224                 break;
14225         case -ENOTSUP:
14226                 printf("function not implemented\n");
14227                 break;
14228         default:
14229                 printf("programming error: (%s)\n", strerror(-ret));
14230         }
14231 }
14232
14233 cmdline_parse_inst_t cmd_set_tx_loopback = {
14234         .f = cmd_set_tx_loopback_parsed,
14235         .data = NULL,
14236         .help_str = "set tx loopback <port_id> on|off",
14237         .tokens = {
14238                 (void *)&cmd_tx_loopback_set,
14239                 (void *)&cmd_tx_loopback_tx,
14240                 (void *)&cmd_tx_loopback_loopback,
14241                 (void *)&cmd_tx_loopback_port_id,
14242                 (void *)&cmd_tx_loopback_on_off,
14243                 NULL,
14244         },
14245 };
14246
14247 /* all queues drop enable configuration */
14248
14249 /* Common result structure for all queues drop enable */
14250 struct cmd_all_queues_drop_en_result {
14251         cmdline_fixed_string_t set;
14252         cmdline_fixed_string_t all;
14253         cmdline_fixed_string_t queues;
14254         cmdline_fixed_string_t drop;
14255         portid_t port_id;
14256         cmdline_fixed_string_t on_off;
14257 };
14258
14259 /* Common CLI fields for tx loopback enable disable */
14260 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
14261         TOKEN_STRING_INITIALIZER
14262                 (struct cmd_all_queues_drop_en_result,
14263                  set, "set");
14264 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
14265         TOKEN_STRING_INITIALIZER
14266                 (struct cmd_all_queues_drop_en_result,
14267                  all, "all");
14268 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
14269         TOKEN_STRING_INITIALIZER
14270                 (struct cmd_all_queues_drop_en_result,
14271                  queues, "queues");
14272 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
14273         TOKEN_STRING_INITIALIZER
14274                 (struct cmd_all_queues_drop_en_result,
14275                  drop, "drop");
14276 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
14277         TOKEN_NUM_INITIALIZER
14278                 (struct cmd_all_queues_drop_en_result,
14279                  port_id, UINT16);
14280 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
14281         TOKEN_STRING_INITIALIZER
14282                 (struct cmd_all_queues_drop_en_result,
14283                  on_off, "on#off");
14284
14285 static void
14286 cmd_set_all_queues_drop_en_parsed(
14287         void *parsed_result,
14288         __rte_unused struct cmdline *cl,
14289         __rte_unused void *data)
14290 {
14291         struct cmd_all_queues_drop_en_result *res = parsed_result;
14292         int ret = -ENOTSUP;
14293         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14294
14295         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14296                 return;
14297
14298 #ifdef RTE_LIBRTE_IXGBE_PMD
14299         if (ret == -ENOTSUP)
14300                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
14301 #endif
14302 #ifdef RTE_LIBRTE_BNXT_PMD
14303         if (ret == -ENOTSUP)
14304                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
14305 #endif
14306         switch (ret) {
14307         case 0:
14308                 break;
14309         case -EINVAL:
14310                 printf("invalid is_on %d\n", is_on);
14311                 break;
14312         case -ENODEV:
14313                 printf("invalid port_id %d\n", res->port_id);
14314                 break;
14315         case -ENOTSUP:
14316                 printf("function not implemented\n");
14317                 break;
14318         default:
14319                 printf("programming error: (%s)\n", strerror(-ret));
14320         }
14321 }
14322
14323 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
14324         .f = cmd_set_all_queues_drop_en_parsed,
14325         .data = NULL,
14326         .help_str = "set all queues drop <port_id> on|off",
14327         .tokens = {
14328                 (void *)&cmd_all_queues_drop_en_set,
14329                 (void *)&cmd_all_queues_drop_en_all,
14330                 (void *)&cmd_all_queues_drop_en_queues,
14331                 (void *)&cmd_all_queues_drop_en_drop,
14332                 (void *)&cmd_all_queues_drop_en_port_id,
14333                 (void *)&cmd_all_queues_drop_en_on_off,
14334                 NULL,
14335         },
14336 };
14337
14338 /* vf split drop enable configuration */
14339
14340 /* Common result structure for vf split drop enable */
14341 struct cmd_vf_split_drop_en_result {
14342         cmdline_fixed_string_t set;
14343         cmdline_fixed_string_t vf;
14344         cmdline_fixed_string_t split;
14345         cmdline_fixed_string_t drop;
14346         portid_t port_id;
14347         uint16_t vf_id;
14348         cmdline_fixed_string_t on_off;
14349 };
14350
14351 /* Common CLI fields for vf split drop enable disable */
14352 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
14353         TOKEN_STRING_INITIALIZER
14354                 (struct cmd_vf_split_drop_en_result,
14355                  set, "set");
14356 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
14357         TOKEN_STRING_INITIALIZER
14358                 (struct cmd_vf_split_drop_en_result,
14359                  vf, "vf");
14360 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
14361         TOKEN_STRING_INITIALIZER
14362                 (struct cmd_vf_split_drop_en_result,
14363                  split, "split");
14364 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
14365         TOKEN_STRING_INITIALIZER
14366                 (struct cmd_vf_split_drop_en_result,
14367                  drop, "drop");
14368 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
14369         TOKEN_NUM_INITIALIZER
14370                 (struct cmd_vf_split_drop_en_result,
14371                  port_id, UINT16);
14372 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
14373         TOKEN_NUM_INITIALIZER
14374                 (struct cmd_vf_split_drop_en_result,
14375                  vf_id, UINT16);
14376 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
14377         TOKEN_STRING_INITIALIZER
14378                 (struct cmd_vf_split_drop_en_result,
14379                  on_off, "on#off");
14380
14381 static void
14382 cmd_set_vf_split_drop_en_parsed(
14383         void *parsed_result,
14384         __rte_unused struct cmdline *cl,
14385         __rte_unused void *data)
14386 {
14387         struct cmd_vf_split_drop_en_result *res = parsed_result;
14388         int ret = -ENOTSUP;
14389         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
14390
14391         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14392                 return;
14393
14394 #ifdef RTE_LIBRTE_IXGBE_PMD
14395         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
14396                         is_on);
14397 #endif
14398         switch (ret) {
14399         case 0:
14400                 break;
14401         case -EINVAL:
14402                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
14403                 break;
14404         case -ENODEV:
14405                 printf("invalid port_id %d\n", res->port_id);
14406                 break;
14407         case -ENOTSUP:
14408                 printf("not supported on port %d\n", res->port_id);
14409                 break;
14410         default:
14411                 printf("programming error: (%s)\n", strerror(-ret));
14412         }
14413 }
14414
14415 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
14416         .f = cmd_set_vf_split_drop_en_parsed,
14417         .data = NULL,
14418         .help_str = "set vf split drop <port_id> <vf_id> on|off",
14419         .tokens = {
14420                 (void *)&cmd_vf_split_drop_en_set,
14421                 (void *)&cmd_vf_split_drop_en_vf,
14422                 (void *)&cmd_vf_split_drop_en_split,
14423                 (void *)&cmd_vf_split_drop_en_drop,
14424                 (void *)&cmd_vf_split_drop_en_port_id,
14425                 (void *)&cmd_vf_split_drop_en_vf_id,
14426                 (void *)&cmd_vf_split_drop_en_on_off,
14427                 NULL,
14428         },
14429 };
14430
14431 /* vf mac address configuration */
14432
14433 /* Common result structure for vf mac address */
14434 struct cmd_set_vf_mac_addr_result {
14435         cmdline_fixed_string_t set;
14436         cmdline_fixed_string_t vf;
14437         cmdline_fixed_string_t mac;
14438         cmdline_fixed_string_t addr;
14439         portid_t port_id;
14440         uint16_t vf_id;
14441         struct rte_ether_addr mac_addr;
14442
14443 };
14444
14445 /* Common CLI fields for vf split drop enable disable */
14446 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
14447         TOKEN_STRING_INITIALIZER
14448                 (struct cmd_set_vf_mac_addr_result,
14449                  set, "set");
14450 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
14451         TOKEN_STRING_INITIALIZER
14452                 (struct cmd_set_vf_mac_addr_result,
14453                  vf, "vf");
14454 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
14455         TOKEN_STRING_INITIALIZER
14456                 (struct cmd_set_vf_mac_addr_result,
14457                  mac, "mac");
14458 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
14459         TOKEN_STRING_INITIALIZER
14460                 (struct cmd_set_vf_mac_addr_result,
14461                  addr, "addr");
14462 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
14463         TOKEN_NUM_INITIALIZER
14464                 (struct cmd_set_vf_mac_addr_result,
14465                  port_id, UINT16);
14466 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
14467         TOKEN_NUM_INITIALIZER
14468                 (struct cmd_set_vf_mac_addr_result,
14469                  vf_id, UINT16);
14470 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
14471         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
14472                  mac_addr);
14473
14474 static void
14475 cmd_set_vf_mac_addr_parsed(
14476         void *parsed_result,
14477         __rte_unused struct cmdline *cl,
14478         __rte_unused void *data)
14479 {
14480         struct cmd_set_vf_mac_addr_result *res = parsed_result;
14481         int ret = -ENOTSUP;
14482
14483         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14484                 return;
14485
14486 #ifdef RTE_LIBRTE_IXGBE_PMD
14487         if (ret == -ENOTSUP)
14488                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
14489                                 &res->mac_addr);
14490 #endif
14491 #ifdef RTE_LIBRTE_I40E_PMD
14492         if (ret == -ENOTSUP)
14493                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
14494                                 &res->mac_addr);
14495 #endif
14496 #ifdef RTE_LIBRTE_BNXT_PMD
14497         if (ret == -ENOTSUP)
14498                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
14499                                 &res->mac_addr);
14500 #endif
14501
14502         switch (ret) {
14503         case 0:
14504                 break;
14505         case -EINVAL:
14506                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
14507                 break;
14508         case -ENODEV:
14509                 printf("invalid port_id %d\n", res->port_id);
14510                 break;
14511         case -ENOTSUP:
14512                 printf("function not implemented\n");
14513                 break;
14514         default:
14515                 printf("programming error: (%s)\n", strerror(-ret));
14516         }
14517 }
14518
14519 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
14520         .f = cmd_set_vf_mac_addr_parsed,
14521         .data = NULL,
14522         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
14523         .tokens = {
14524                 (void *)&cmd_set_vf_mac_addr_set,
14525                 (void *)&cmd_set_vf_mac_addr_vf,
14526                 (void *)&cmd_set_vf_mac_addr_mac,
14527                 (void *)&cmd_set_vf_mac_addr_addr,
14528                 (void *)&cmd_set_vf_mac_addr_port_id,
14529                 (void *)&cmd_set_vf_mac_addr_vf_id,
14530                 (void *)&cmd_set_vf_mac_addr_mac_addr,
14531                 NULL,
14532         },
14533 };
14534
14535 /* MACsec configuration */
14536
14537 /* Common result structure for MACsec offload enable */
14538 struct cmd_macsec_offload_on_result {
14539         cmdline_fixed_string_t set;
14540         cmdline_fixed_string_t macsec;
14541         cmdline_fixed_string_t offload;
14542         portid_t port_id;
14543         cmdline_fixed_string_t on;
14544         cmdline_fixed_string_t encrypt;
14545         cmdline_fixed_string_t en_on_off;
14546         cmdline_fixed_string_t replay_protect;
14547         cmdline_fixed_string_t rp_on_off;
14548 };
14549
14550 /* Common CLI fields for MACsec offload disable */
14551 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
14552         TOKEN_STRING_INITIALIZER
14553                 (struct cmd_macsec_offload_on_result,
14554                  set, "set");
14555 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
14556         TOKEN_STRING_INITIALIZER
14557                 (struct cmd_macsec_offload_on_result,
14558                  macsec, "macsec");
14559 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
14560         TOKEN_STRING_INITIALIZER
14561                 (struct cmd_macsec_offload_on_result,
14562                  offload, "offload");
14563 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
14564         TOKEN_NUM_INITIALIZER
14565                 (struct cmd_macsec_offload_on_result,
14566                  port_id, UINT16);
14567 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
14568         TOKEN_STRING_INITIALIZER
14569                 (struct cmd_macsec_offload_on_result,
14570                  on, "on");
14571 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
14572         TOKEN_STRING_INITIALIZER
14573                 (struct cmd_macsec_offload_on_result,
14574                  encrypt, "encrypt");
14575 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
14576         TOKEN_STRING_INITIALIZER
14577                 (struct cmd_macsec_offload_on_result,
14578                  en_on_off, "on#off");
14579 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
14580         TOKEN_STRING_INITIALIZER
14581                 (struct cmd_macsec_offload_on_result,
14582                  replay_protect, "replay-protect");
14583 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
14584         TOKEN_STRING_INITIALIZER
14585                 (struct cmd_macsec_offload_on_result,
14586                  rp_on_off, "on#off");
14587
14588 static void
14589 cmd_set_macsec_offload_on_parsed(
14590         void *parsed_result,
14591         __rte_unused struct cmdline *cl,
14592         __rte_unused void *data)
14593 {
14594         struct cmd_macsec_offload_on_result *res = parsed_result;
14595         int ret = -ENOTSUP;
14596         portid_t port_id = res->port_id;
14597         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
14598         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
14599         struct rte_eth_dev_info dev_info;
14600
14601         if (port_id_is_invalid(port_id, ENABLED_WARN))
14602                 return;
14603         if (!port_is_stopped(port_id)) {
14604                 printf("Please stop port %d first\n", port_id);
14605                 return;
14606         }
14607
14608         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14609         if (ret != 0)
14610                 return;
14611
14612         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14613 #ifdef RTE_LIBRTE_IXGBE_PMD
14614                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
14615 #endif
14616         }
14617         RTE_SET_USED(en);
14618         RTE_SET_USED(rp);
14619
14620         switch (ret) {
14621         case 0:
14622                 ports[port_id].dev_conf.txmode.offloads |=
14623                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
14624                 cmd_reconfig_device_queue(port_id, 1, 1);
14625                 break;
14626         case -ENODEV:
14627                 printf("invalid port_id %d\n", port_id);
14628                 break;
14629         case -ENOTSUP:
14630                 printf("not supported on port %d\n", port_id);
14631                 break;
14632         default:
14633                 printf("programming error: (%s)\n", strerror(-ret));
14634         }
14635 }
14636
14637 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
14638         .f = cmd_set_macsec_offload_on_parsed,
14639         .data = NULL,
14640         .help_str = "set macsec offload <port_id> on "
14641                 "encrypt on|off replay-protect on|off",
14642         .tokens = {
14643                 (void *)&cmd_macsec_offload_on_set,
14644                 (void *)&cmd_macsec_offload_on_macsec,
14645                 (void *)&cmd_macsec_offload_on_offload,
14646                 (void *)&cmd_macsec_offload_on_port_id,
14647                 (void *)&cmd_macsec_offload_on_on,
14648                 (void *)&cmd_macsec_offload_on_encrypt,
14649                 (void *)&cmd_macsec_offload_on_en_on_off,
14650                 (void *)&cmd_macsec_offload_on_replay_protect,
14651                 (void *)&cmd_macsec_offload_on_rp_on_off,
14652                 NULL,
14653         },
14654 };
14655
14656 /* Common result structure for MACsec offload disable */
14657 struct cmd_macsec_offload_off_result {
14658         cmdline_fixed_string_t set;
14659         cmdline_fixed_string_t macsec;
14660         cmdline_fixed_string_t offload;
14661         portid_t port_id;
14662         cmdline_fixed_string_t off;
14663 };
14664
14665 /* Common CLI fields for MACsec offload disable */
14666 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
14667         TOKEN_STRING_INITIALIZER
14668                 (struct cmd_macsec_offload_off_result,
14669                  set, "set");
14670 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
14671         TOKEN_STRING_INITIALIZER
14672                 (struct cmd_macsec_offload_off_result,
14673                  macsec, "macsec");
14674 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
14675         TOKEN_STRING_INITIALIZER
14676                 (struct cmd_macsec_offload_off_result,
14677                  offload, "offload");
14678 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
14679         TOKEN_NUM_INITIALIZER
14680                 (struct cmd_macsec_offload_off_result,
14681                  port_id, UINT16);
14682 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
14683         TOKEN_STRING_INITIALIZER
14684                 (struct cmd_macsec_offload_off_result,
14685                  off, "off");
14686
14687 static void
14688 cmd_set_macsec_offload_off_parsed(
14689         void *parsed_result,
14690         __rte_unused struct cmdline *cl,
14691         __rte_unused void *data)
14692 {
14693         struct cmd_macsec_offload_off_result *res = parsed_result;
14694         int ret = -ENOTSUP;
14695         struct rte_eth_dev_info dev_info;
14696         portid_t port_id = res->port_id;
14697
14698         if (port_id_is_invalid(port_id, ENABLED_WARN))
14699                 return;
14700         if (!port_is_stopped(port_id)) {
14701                 printf("Please stop port %d first\n", port_id);
14702                 return;
14703         }
14704
14705         ret = eth_dev_info_get_print_err(port_id, &dev_info);
14706         if (ret != 0)
14707                 return;
14708
14709         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
14710 #ifdef RTE_LIBRTE_IXGBE_PMD
14711                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
14712 #endif
14713         }
14714         switch (ret) {
14715         case 0:
14716                 ports[port_id].dev_conf.txmode.offloads &=
14717                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
14718                 cmd_reconfig_device_queue(port_id, 1, 1);
14719                 break;
14720         case -ENODEV:
14721                 printf("invalid port_id %d\n", port_id);
14722                 break;
14723         case -ENOTSUP:
14724                 printf("not supported on port %d\n", port_id);
14725                 break;
14726         default:
14727                 printf("programming error: (%s)\n", strerror(-ret));
14728         }
14729 }
14730
14731 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
14732         .f = cmd_set_macsec_offload_off_parsed,
14733         .data = NULL,
14734         .help_str = "set macsec offload <port_id> off",
14735         .tokens = {
14736                 (void *)&cmd_macsec_offload_off_set,
14737                 (void *)&cmd_macsec_offload_off_macsec,
14738                 (void *)&cmd_macsec_offload_off_offload,
14739                 (void *)&cmd_macsec_offload_off_port_id,
14740                 (void *)&cmd_macsec_offload_off_off,
14741                 NULL,
14742         },
14743 };
14744
14745 /* Common result structure for MACsec secure connection configure */
14746 struct cmd_macsec_sc_result {
14747         cmdline_fixed_string_t set;
14748         cmdline_fixed_string_t macsec;
14749         cmdline_fixed_string_t sc;
14750         cmdline_fixed_string_t tx_rx;
14751         portid_t port_id;
14752         struct rte_ether_addr mac;
14753         uint16_t pi;
14754 };
14755
14756 /* Common CLI fields for MACsec secure connection configure */
14757 cmdline_parse_token_string_t cmd_macsec_sc_set =
14758         TOKEN_STRING_INITIALIZER
14759                 (struct cmd_macsec_sc_result,
14760                  set, "set");
14761 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
14762         TOKEN_STRING_INITIALIZER
14763                 (struct cmd_macsec_sc_result,
14764                  macsec, "macsec");
14765 cmdline_parse_token_string_t cmd_macsec_sc_sc =
14766         TOKEN_STRING_INITIALIZER
14767                 (struct cmd_macsec_sc_result,
14768                  sc, "sc");
14769 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
14770         TOKEN_STRING_INITIALIZER
14771                 (struct cmd_macsec_sc_result,
14772                  tx_rx, "tx#rx");
14773 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
14774         TOKEN_NUM_INITIALIZER
14775                 (struct cmd_macsec_sc_result,
14776                  port_id, UINT16);
14777 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
14778         TOKEN_ETHERADDR_INITIALIZER
14779                 (struct cmd_macsec_sc_result,
14780                  mac);
14781 cmdline_parse_token_num_t cmd_macsec_sc_pi =
14782         TOKEN_NUM_INITIALIZER
14783                 (struct cmd_macsec_sc_result,
14784                  pi, UINT16);
14785
14786 static void
14787 cmd_set_macsec_sc_parsed(
14788         void *parsed_result,
14789         __rte_unused struct cmdline *cl,
14790         __rte_unused void *data)
14791 {
14792         struct cmd_macsec_sc_result *res = parsed_result;
14793         int ret = -ENOTSUP;
14794         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14795
14796 #ifdef RTE_LIBRTE_IXGBE_PMD
14797         ret = is_tx ?
14798                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
14799                                 res->mac.addr_bytes) :
14800                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
14801                                 res->mac.addr_bytes, res->pi);
14802 #endif
14803         RTE_SET_USED(is_tx);
14804
14805         switch (ret) {
14806         case 0:
14807                 break;
14808         case -ENODEV:
14809                 printf("invalid port_id %d\n", res->port_id);
14810                 break;
14811         case -ENOTSUP:
14812                 printf("not supported on port %d\n", res->port_id);
14813                 break;
14814         default:
14815                 printf("programming error: (%s)\n", strerror(-ret));
14816         }
14817 }
14818
14819 cmdline_parse_inst_t cmd_set_macsec_sc = {
14820         .f = cmd_set_macsec_sc_parsed,
14821         .data = NULL,
14822         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
14823         .tokens = {
14824                 (void *)&cmd_macsec_sc_set,
14825                 (void *)&cmd_macsec_sc_macsec,
14826                 (void *)&cmd_macsec_sc_sc,
14827                 (void *)&cmd_macsec_sc_tx_rx,
14828                 (void *)&cmd_macsec_sc_port_id,
14829                 (void *)&cmd_macsec_sc_mac,
14830                 (void *)&cmd_macsec_sc_pi,
14831                 NULL,
14832         },
14833 };
14834
14835 /* Common result structure for MACsec secure connection configure */
14836 struct cmd_macsec_sa_result {
14837         cmdline_fixed_string_t set;
14838         cmdline_fixed_string_t macsec;
14839         cmdline_fixed_string_t sa;
14840         cmdline_fixed_string_t tx_rx;
14841         portid_t port_id;
14842         uint8_t idx;
14843         uint8_t an;
14844         uint32_t pn;
14845         cmdline_fixed_string_t key;
14846 };
14847
14848 /* Common CLI fields for MACsec secure connection configure */
14849 cmdline_parse_token_string_t cmd_macsec_sa_set =
14850         TOKEN_STRING_INITIALIZER
14851                 (struct cmd_macsec_sa_result,
14852                  set, "set");
14853 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
14854         TOKEN_STRING_INITIALIZER
14855                 (struct cmd_macsec_sa_result,
14856                  macsec, "macsec");
14857 cmdline_parse_token_string_t cmd_macsec_sa_sa =
14858         TOKEN_STRING_INITIALIZER
14859                 (struct cmd_macsec_sa_result,
14860                  sa, "sa");
14861 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
14862         TOKEN_STRING_INITIALIZER
14863                 (struct cmd_macsec_sa_result,
14864                  tx_rx, "tx#rx");
14865 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
14866         TOKEN_NUM_INITIALIZER
14867                 (struct cmd_macsec_sa_result,
14868                  port_id, UINT16);
14869 cmdline_parse_token_num_t cmd_macsec_sa_idx =
14870         TOKEN_NUM_INITIALIZER
14871                 (struct cmd_macsec_sa_result,
14872                  idx, UINT8);
14873 cmdline_parse_token_num_t cmd_macsec_sa_an =
14874         TOKEN_NUM_INITIALIZER
14875                 (struct cmd_macsec_sa_result,
14876                  an, UINT8);
14877 cmdline_parse_token_num_t cmd_macsec_sa_pn =
14878         TOKEN_NUM_INITIALIZER
14879                 (struct cmd_macsec_sa_result,
14880                  pn, UINT32);
14881 cmdline_parse_token_string_t cmd_macsec_sa_key =
14882         TOKEN_STRING_INITIALIZER
14883                 (struct cmd_macsec_sa_result,
14884                  key, NULL);
14885
14886 static void
14887 cmd_set_macsec_sa_parsed(
14888         void *parsed_result,
14889         __rte_unused struct cmdline *cl,
14890         __rte_unused void *data)
14891 {
14892         struct cmd_macsec_sa_result *res = parsed_result;
14893         int ret = -ENOTSUP;
14894         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
14895         uint8_t key[16] = { 0 };
14896         uint8_t xdgt0;
14897         uint8_t xdgt1;
14898         int key_len;
14899         int i;
14900
14901         key_len = strlen(res->key) / 2;
14902         if (key_len > 16)
14903                 key_len = 16;
14904
14905         for (i = 0; i < key_len; i++) {
14906                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
14907                 if (xdgt0 == 0xFF)
14908                         return;
14909                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
14910                 if (xdgt1 == 0xFF)
14911                         return;
14912                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
14913         }
14914
14915 #ifdef RTE_LIBRTE_IXGBE_PMD
14916         ret = is_tx ?
14917                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
14918                         res->idx, res->an, res->pn, key) :
14919                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
14920                         res->idx, res->an, res->pn, key);
14921 #endif
14922         RTE_SET_USED(is_tx);
14923         RTE_SET_USED(key);
14924
14925         switch (ret) {
14926         case 0:
14927                 break;
14928         case -EINVAL:
14929                 printf("invalid idx %d or an %d\n", res->idx, res->an);
14930                 break;
14931         case -ENODEV:
14932                 printf("invalid port_id %d\n", res->port_id);
14933                 break;
14934         case -ENOTSUP:
14935                 printf("not supported on port %d\n", res->port_id);
14936                 break;
14937         default:
14938                 printf("programming error: (%s)\n", strerror(-ret));
14939         }
14940 }
14941
14942 cmdline_parse_inst_t cmd_set_macsec_sa = {
14943         .f = cmd_set_macsec_sa_parsed,
14944         .data = NULL,
14945         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
14946         .tokens = {
14947                 (void *)&cmd_macsec_sa_set,
14948                 (void *)&cmd_macsec_sa_macsec,
14949                 (void *)&cmd_macsec_sa_sa,
14950                 (void *)&cmd_macsec_sa_tx_rx,
14951                 (void *)&cmd_macsec_sa_port_id,
14952                 (void *)&cmd_macsec_sa_idx,
14953                 (void *)&cmd_macsec_sa_an,
14954                 (void *)&cmd_macsec_sa_pn,
14955                 (void *)&cmd_macsec_sa_key,
14956                 NULL,
14957         },
14958 };
14959
14960 /* VF unicast promiscuous mode configuration */
14961
14962 /* Common result structure for VF unicast promiscuous mode */
14963 struct cmd_vf_promisc_result {
14964         cmdline_fixed_string_t set;
14965         cmdline_fixed_string_t vf;
14966         cmdline_fixed_string_t promisc;
14967         portid_t port_id;
14968         uint32_t vf_id;
14969         cmdline_fixed_string_t on_off;
14970 };
14971
14972 /* Common CLI fields for VF unicast promiscuous mode enable disable */
14973 cmdline_parse_token_string_t cmd_vf_promisc_set =
14974         TOKEN_STRING_INITIALIZER
14975                 (struct cmd_vf_promisc_result,
14976                  set, "set");
14977 cmdline_parse_token_string_t cmd_vf_promisc_vf =
14978         TOKEN_STRING_INITIALIZER
14979                 (struct cmd_vf_promisc_result,
14980                  vf, "vf");
14981 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
14982         TOKEN_STRING_INITIALIZER
14983                 (struct cmd_vf_promisc_result,
14984                  promisc, "promisc");
14985 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
14986         TOKEN_NUM_INITIALIZER
14987                 (struct cmd_vf_promisc_result,
14988                  port_id, UINT16);
14989 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
14990         TOKEN_NUM_INITIALIZER
14991                 (struct cmd_vf_promisc_result,
14992                  vf_id, UINT32);
14993 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
14994         TOKEN_STRING_INITIALIZER
14995                 (struct cmd_vf_promisc_result,
14996                  on_off, "on#off");
14997
14998 static void
14999 cmd_set_vf_promisc_parsed(
15000         void *parsed_result,
15001         __rte_unused struct cmdline *cl,
15002         __rte_unused void *data)
15003 {
15004         struct cmd_vf_promisc_result *res = parsed_result;
15005         int ret = -ENOTSUP;
15006
15007         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15008
15009         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15010                 return;
15011
15012 #ifdef RTE_LIBRTE_I40E_PMD
15013         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
15014                                                   res->vf_id, is_on);
15015 #endif
15016
15017         switch (ret) {
15018         case 0:
15019                 break;
15020         case -EINVAL:
15021                 printf("invalid vf_id %d\n", res->vf_id);
15022                 break;
15023         case -ENODEV:
15024                 printf("invalid port_id %d\n", res->port_id);
15025                 break;
15026         case -ENOTSUP:
15027                 printf("function not implemented\n");
15028                 break;
15029         default:
15030                 printf("programming error: (%s)\n", strerror(-ret));
15031         }
15032 }
15033
15034 cmdline_parse_inst_t cmd_set_vf_promisc = {
15035         .f = cmd_set_vf_promisc_parsed,
15036         .data = NULL,
15037         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
15038                 "Set unicast promiscuous mode for a VF from the PF",
15039         .tokens = {
15040                 (void *)&cmd_vf_promisc_set,
15041                 (void *)&cmd_vf_promisc_vf,
15042                 (void *)&cmd_vf_promisc_promisc,
15043                 (void *)&cmd_vf_promisc_port_id,
15044                 (void *)&cmd_vf_promisc_vf_id,
15045                 (void *)&cmd_vf_promisc_on_off,
15046                 NULL,
15047         },
15048 };
15049
15050 /* VF multicast promiscuous mode configuration */
15051
15052 /* Common result structure for VF multicast promiscuous mode */
15053 struct cmd_vf_allmulti_result {
15054         cmdline_fixed_string_t set;
15055         cmdline_fixed_string_t vf;
15056         cmdline_fixed_string_t allmulti;
15057         portid_t port_id;
15058         uint32_t vf_id;
15059         cmdline_fixed_string_t on_off;
15060 };
15061
15062 /* Common CLI fields for VF multicast promiscuous mode enable disable */
15063 cmdline_parse_token_string_t cmd_vf_allmulti_set =
15064         TOKEN_STRING_INITIALIZER
15065                 (struct cmd_vf_allmulti_result,
15066                  set, "set");
15067 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
15068         TOKEN_STRING_INITIALIZER
15069                 (struct cmd_vf_allmulti_result,
15070                  vf, "vf");
15071 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
15072         TOKEN_STRING_INITIALIZER
15073                 (struct cmd_vf_allmulti_result,
15074                  allmulti, "allmulti");
15075 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
15076         TOKEN_NUM_INITIALIZER
15077                 (struct cmd_vf_allmulti_result,
15078                  port_id, UINT16);
15079 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
15080         TOKEN_NUM_INITIALIZER
15081                 (struct cmd_vf_allmulti_result,
15082                  vf_id, UINT32);
15083 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
15084         TOKEN_STRING_INITIALIZER
15085                 (struct cmd_vf_allmulti_result,
15086                  on_off, "on#off");
15087
15088 static void
15089 cmd_set_vf_allmulti_parsed(
15090         void *parsed_result,
15091         __rte_unused struct cmdline *cl,
15092         __rte_unused void *data)
15093 {
15094         struct cmd_vf_allmulti_result *res = parsed_result;
15095         int ret = -ENOTSUP;
15096
15097         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15098
15099         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15100                 return;
15101
15102 #ifdef RTE_LIBRTE_I40E_PMD
15103         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
15104                                                     res->vf_id, is_on);
15105 #endif
15106
15107         switch (ret) {
15108         case 0:
15109                 break;
15110         case -EINVAL:
15111                 printf("invalid vf_id %d\n", res->vf_id);
15112                 break;
15113         case -ENODEV:
15114                 printf("invalid port_id %d\n", res->port_id);
15115                 break;
15116         case -ENOTSUP:
15117                 printf("function not implemented\n");
15118                 break;
15119         default:
15120                 printf("programming error: (%s)\n", strerror(-ret));
15121         }
15122 }
15123
15124 cmdline_parse_inst_t cmd_set_vf_allmulti = {
15125         .f = cmd_set_vf_allmulti_parsed,
15126         .data = NULL,
15127         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
15128                 "Set multicast promiscuous mode for a VF from the PF",
15129         .tokens = {
15130                 (void *)&cmd_vf_allmulti_set,
15131                 (void *)&cmd_vf_allmulti_vf,
15132                 (void *)&cmd_vf_allmulti_allmulti,
15133                 (void *)&cmd_vf_allmulti_port_id,
15134                 (void *)&cmd_vf_allmulti_vf_id,
15135                 (void *)&cmd_vf_allmulti_on_off,
15136                 NULL,
15137         },
15138 };
15139
15140 /* vf broadcast mode configuration */
15141
15142 /* Common result structure for vf broadcast */
15143 struct cmd_set_vf_broadcast_result {
15144         cmdline_fixed_string_t set;
15145         cmdline_fixed_string_t vf;
15146         cmdline_fixed_string_t broadcast;
15147         portid_t port_id;
15148         uint16_t vf_id;
15149         cmdline_fixed_string_t on_off;
15150 };
15151
15152 /* Common CLI fields for vf broadcast enable disable */
15153 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
15154         TOKEN_STRING_INITIALIZER
15155                 (struct cmd_set_vf_broadcast_result,
15156                  set, "set");
15157 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
15158         TOKEN_STRING_INITIALIZER
15159                 (struct cmd_set_vf_broadcast_result,
15160                  vf, "vf");
15161 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
15162         TOKEN_STRING_INITIALIZER
15163                 (struct cmd_set_vf_broadcast_result,
15164                  broadcast, "broadcast");
15165 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
15166         TOKEN_NUM_INITIALIZER
15167                 (struct cmd_set_vf_broadcast_result,
15168                  port_id, UINT16);
15169 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
15170         TOKEN_NUM_INITIALIZER
15171                 (struct cmd_set_vf_broadcast_result,
15172                  vf_id, UINT16);
15173 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
15174         TOKEN_STRING_INITIALIZER
15175                 (struct cmd_set_vf_broadcast_result,
15176                  on_off, "on#off");
15177
15178 static void
15179 cmd_set_vf_broadcast_parsed(
15180         void *parsed_result,
15181         __rte_unused struct cmdline *cl,
15182         __rte_unused void *data)
15183 {
15184         struct cmd_set_vf_broadcast_result *res = parsed_result;
15185         int ret = -ENOTSUP;
15186
15187         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15188
15189         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15190                 return;
15191
15192 #ifdef RTE_LIBRTE_I40E_PMD
15193         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
15194                                             res->vf_id, is_on);
15195 #endif
15196
15197         switch (ret) {
15198         case 0:
15199                 break;
15200         case -EINVAL:
15201                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15202                 break;
15203         case -ENODEV:
15204                 printf("invalid port_id %d\n", res->port_id);
15205                 break;
15206         case -ENOTSUP:
15207                 printf("function not implemented\n");
15208                 break;
15209         default:
15210                 printf("programming error: (%s)\n", strerror(-ret));
15211         }
15212 }
15213
15214 cmdline_parse_inst_t cmd_set_vf_broadcast = {
15215         .f = cmd_set_vf_broadcast_parsed,
15216         .data = NULL,
15217         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
15218         .tokens = {
15219                 (void *)&cmd_set_vf_broadcast_set,
15220                 (void *)&cmd_set_vf_broadcast_vf,
15221                 (void *)&cmd_set_vf_broadcast_broadcast,
15222                 (void *)&cmd_set_vf_broadcast_port_id,
15223                 (void *)&cmd_set_vf_broadcast_vf_id,
15224                 (void *)&cmd_set_vf_broadcast_on_off,
15225                 NULL,
15226         },
15227 };
15228
15229 /* vf vlan tag configuration */
15230
15231 /* Common result structure for vf vlan tag */
15232 struct cmd_set_vf_vlan_tag_result {
15233         cmdline_fixed_string_t set;
15234         cmdline_fixed_string_t vf;
15235         cmdline_fixed_string_t vlan;
15236         cmdline_fixed_string_t tag;
15237         portid_t port_id;
15238         uint16_t vf_id;
15239         cmdline_fixed_string_t on_off;
15240 };
15241
15242 /* Common CLI fields for vf vlan tag enable disable */
15243 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
15244         TOKEN_STRING_INITIALIZER
15245                 (struct cmd_set_vf_vlan_tag_result,
15246                  set, "set");
15247 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
15248         TOKEN_STRING_INITIALIZER
15249                 (struct cmd_set_vf_vlan_tag_result,
15250                  vf, "vf");
15251 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
15252         TOKEN_STRING_INITIALIZER
15253                 (struct cmd_set_vf_vlan_tag_result,
15254                  vlan, "vlan");
15255 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
15256         TOKEN_STRING_INITIALIZER
15257                 (struct cmd_set_vf_vlan_tag_result,
15258                  tag, "tag");
15259 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
15260         TOKEN_NUM_INITIALIZER
15261                 (struct cmd_set_vf_vlan_tag_result,
15262                  port_id, UINT16);
15263 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
15264         TOKEN_NUM_INITIALIZER
15265                 (struct cmd_set_vf_vlan_tag_result,
15266                  vf_id, UINT16);
15267 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
15268         TOKEN_STRING_INITIALIZER
15269                 (struct cmd_set_vf_vlan_tag_result,
15270                  on_off, "on#off");
15271
15272 static void
15273 cmd_set_vf_vlan_tag_parsed(
15274         void *parsed_result,
15275         __rte_unused struct cmdline *cl,
15276         __rte_unused void *data)
15277 {
15278         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
15279         int ret = -ENOTSUP;
15280
15281         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
15282
15283         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15284                 return;
15285
15286 #ifdef RTE_LIBRTE_I40E_PMD
15287         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
15288                                            res->vf_id, is_on);
15289 #endif
15290
15291         switch (ret) {
15292         case 0:
15293                 break;
15294         case -EINVAL:
15295                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
15296                 break;
15297         case -ENODEV:
15298                 printf("invalid port_id %d\n", res->port_id);
15299                 break;
15300         case -ENOTSUP:
15301                 printf("function not implemented\n");
15302                 break;
15303         default:
15304                 printf("programming error: (%s)\n", strerror(-ret));
15305         }
15306 }
15307
15308 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
15309         .f = cmd_set_vf_vlan_tag_parsed,
15310         .data = NULL,
15311         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
15312         .tokens = {
15313                 (void *)&cmd_set_vf_vlan_tag_set,
15314                 (void *)&cmd_set_vf_vlan_tag_vf,
15315                 (void *)&cmd_set_vf_vlan_tag_vlan,
15316                 (void *)&cmd_set_vf_vlan_tag_tag,
15317                 (void *)&cmd_set_vf_vlan_tag_port_id,
15318                 (void *)&cmd_set_vf_vlan_tag_vf_id,
15319                 (void *)&cmd_set_vf_vlan_tag_on_off,
15320                 NULL,
15321         },
15322 };
15323
15324 /* Common definition of VF and TC TX bandwidth configuration */
15325 struct cmd_vf_tc_bw_result {
15326         cmdline_fixed_string_t set;
15327         cmdline_fixed_string_t vf;
15328         cmdline_fixed_string_t tc;
15329         cmdline_fixed_string_t tx;
15330         cmdline_fixed_string_t min_bw;
15331         cmdline_fixed_string_t max_bw;
15332         cmdline_fixed_string_t strict_link_prio;
15333         portid_t port_id;
15334         uint16_t vf_id;
15335         uint8_t tc_no;
15336         uint32_t bw;
15337         cmdline_fixed_string_t bw_list;
15338         uint8_t tc_map;
15339 };
15340
15341 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
15342         TOKEN_STRING_INITIALIZER
15343                 (struct cmd_vf_tc_bw_result,
15344                  set, "set");
15345 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
15346         TOKEN_STRING_INITIALIZER
15347                 (struct cmd_vf_tc_bw_result,
15348                  vf, "vf");
15349 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
15350         TOKEN_STRING_INITIALIZER
15351                 (struct cmd_vf_tc_bw_result,
15352                  tc, "tc");
15353 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
15354         TOKEN_STRING_INITIALIZER
15355                 (struct cmd_vf_tc_bw_result,
15356                  tx, "tx");
15357 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
15358         TOKEN_STRING_INITIALIZER
15359                 (struct cmd_vf_tc_bw_result,
15360                  strict_link_prio, "strict-link-priority");
15361 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
15362         TOKEN_STRING_INITIALIZER
15363                 (struct cmd_vf_tc_bw_result,
15364                  min_bw, "min-bandwidth");
15365 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
15366         TOKEN_STRING_INITIALIZER
15367                 (struct cmd_vf_tc_bw_result,
15368                  max_bw, "max-bandwidth");
15369 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
15370         TOKEN_NUM_INITIALIZER
15371                 (struct cmd_vf_tc_bw_result,
15372                  port_id, UINT16);
15373 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
15374         TOKEN_NUM_INITIALIZER
15375                 (struct cmd_vf_tc_bw_result,
15376                  vf_id, UINT16);
15377 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
15378         TOKEN_NUM_INITIALIZER
15379                 (struct cmd_vf_tc_bw_result,
15380                  tc_no, UINT8);
15381 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
15382         TOKEN_NUM_INITIALIZER
15383                 (struct cmd_vf_tc_bw_result,
15384                  bw, UINT32);
15385 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
15386         TOKEN_STRING_INITIALIZER
15387                 (struct cmd_vf_tc_bw_result,
15388                  bw_list, NULL);
15389 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
15390         TOKEN_NUM_INITIALIZER
15391                 (struct cmd_vf_tc_bw_result,
15392                  tc_map, UINT8);
15393
15394 /* VF max bandwidth setting */
15395 static void
15396 cmd_vf_max_bw_parsed(
15397         void *parsed_result,
15398         __rte_unused struct cmdline *cl,
15399         __rte_unused void *data)
15400 {
15401         struct cmd_vf_tc_bw_result *res = parsed_result;
15402         int ret = -ENOTSUP;
15403
15404         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15405                 return;
15406
15407 #ifdef RTE_LIBRTE_I40E_PMD
15408         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
15409                                          res->vf_id, res->bw);
15410 #endif
15411
15412         switch (ret) {
15413         case 0:
15414                 break;
15415         case -EINVAL:
15416                 printf("invalid vf_id %d or bandwidth %d\n",
15417                        res->vf_id, res->bw);
15418                 break;
15419         case -ENODEV:
15420                 printf("invalid port_id %d\n", res->port_id);
15421                 break;
15422         case -ENOTSUP:
15423                 printf("function not implemented\n");
15424                 break;
15425         default:
15426                 printf("programming error: (%s)\n", strerror(-ret));
15427         }
15428 }
15429
15430 cmdline_parse_inst_t cmd_vf_max_bw = {
15431         .f = cmd_vf_max_bw_parsed,
15432         .data = NULL,
15433         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
15434         .tokens = {
15435                 (void *)&cmd_vf_tc_bw_set,
15436                 (void *)&cmd_vf_tc_bw_vf,
15437                 (void *)&cmd_vf_tc_bw_tx,
15438                 (void *)&cmd_vf_tc_bw_max_bw,
15439                 (void *)&cmd_vf_tc_bw_port_id,
15440                 (void *)&cmd_vf_tc_bw_vf_id,
15441                 (void *)&cmd_vf_tc_bw_bw,
15442                 NULL,
15443         },
15444 };
15445
15446 static int
15447 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
15448                            uint8_t *tc_num,
15449                            char *str)
15450 {
15451         uint32_t size;
15452         const char *p, *p0 = str;
15453         char s[256];
15454         char *end;
15455         char *str_fld[16];
15456         uint16_t i;
15457         int ret;
15458
15459         p = strchr(p0, '(');
15460         if (p == NULL) {
15461                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15462                 return -1;
15463         }
15464         p++;
15465         p0 = strchr(p, ')');
15466         if (p0 == NULL) {
15467                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
15468                 return -1;
15469         }
15470         size = p0 - p;
15471         if (size >= sizeof(s)) {
15472                 printf("The string size exceeds the internal buffer size\n");
15473                 return -1;
15474         }
15475         snprintf(s, sizeof(s), "%.*s", size, p);
15476         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
15477         if (ret <= 0) {
15478                 printf("Failed to get the bandwidth list. ");
15479                 return -1;
15480         }
15481         *tc_num = ret;
15482         for (i = 0; i < ret; i++)
15483                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
15484
15485         return 0;
15486 }
15487
15488 /* TC min bandwidth setting */
15489 static void
15490 cmd_vf_tc_min_bw_parsed(
15491         void *parsed_result,
15492         __rte_unused struct cmdline *cl,
15493         __rte_unused void *data)
15494 {
15495         struct cmd_vf_tc_bw_result *res = parsed_result;
15496         uint8_t tc_num;
15497         uint8_t bw[16];
15498         int ret = -ENOTSUP;
15499
15500         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15501                 return;
15502
15503         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15504         if (ret)
15505                 return;
15506
15507 #ifdef RTE_LIBRTE_I40E_PMD
15508         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
15509                                               tc_num, bw);
15510 #endif
15511
15512         switch (ret) {
15513         case 0:
15514                 break;
15515         case -EINVAL:
15516                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
15517                 break;
15518         case -ENODEV:
15519                 printf("invalid port_id %d\n", res->port_id);
15520                 break;
15521         case -ENOTSUP:
15522                 printf("function not implemented\n");
15523                 break;
15524         default:
15525                 printf("programming error: (%s)\n", strerror(-ret));
15526         }
15527 }
15528
15529 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
15530         .f = cmd_vf_tc_min_bw_parsed,
15531         .data = NULL,
15532         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
15533                     " <bw1, bw2, ...>",
15534         .tokens = {
15535                 (void *)&cmd_vf_tc_bw_set,
15536                 (void *)&cmd_vf_tc_bw_vf,
15537                 (void *)&cmd_vf_tc_bw_tc,
15538                 (void *)&cmd_vf_tc_bw_tx,
15539                 (void *)&cmd_vf_tc_bw_min_bw,
15540                 (void *)&cmd_vf_tc_bw_port_id,
15541                 (void *)&cmd_vf_tc_bw_vf_id,
15542                 (void *)&cmd_vf_tc_bw_bw_list,
15543                 NULL,
15544         },
15545 };
15546
15547 static void
15548 cmd_tc_min_bw_parsed(
15549         void *parsed_result,
15550         __rte_unused struct cmdline *cl,
15551         __rte_unused void *data)
15552 {
15553         struct cmd_vf_tc_bw_result *res = parsed_result;
15554         struct rte_port *port;
15555         uint8_t tc_num;
15556         uint8_t bw[16];
15557         int ret = -ENOTSUP;
15558
15559         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15560                 return;
15561
15562         port = &ports[res->port_id];
15563         /** Check if the port is not started **/
15564         if (port->port_status != RTE_PORT_STOPPED) {
15565                 printf("Please stop port %d first\n", res->port_id);
15566                 return;
15567         }
15568
15569         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
15570         if (ret)
15571                 return;
15572
15573 #ifdef RTE_LIBRTE_IXGBE_PMD
15574         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
15575 #endif
15576
15577         switch (ret) {
15578         case 0:
15579                 break;
15580         case -EINVAL:
15581                 printf("invalid bandwidth\n");
15582                 break;
15583         case -ENODEV:
15584                 printf("invalid port_id %d\n", res->port_id);
15585                 break;
15586         case -ENOTSUP:
15587                 printf("function not implemented\n");
15588                 break;
15589         default:
15590                 printf("programming error: (%s)\n", strerror(-ret));
15591         }
15592 }
15593
15594 cmdline_parse_inst_t cmd_tc_min_bw = {
15595         .f = cmd_tc_min_bw_parsed,
15596         .data = NULL,
15597         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
15598         .tokens = {
15599                 (void *)&cmd_vf_tc_bw_set,
15600                 (void *)&cmd_vf_tc_bw_tc,
15601                 (void *)&cmd_vf_tc_bw_tx,
15602                 (void *)&cmd_vf_tc_bw_min_bw,
15603                 (void *)&cmd_vf_tc_bw_port_id,
15604                 (void *)&cmd_vf_tc_bw_bw_list,
15605                 NULL,
15606         },
15607 };
15608
15609 /* TC max bandwidth setting */
15610 static void
15611 cmd_vf_tc_max_bw_parsed(
15612         void *parsed_result,
15613         __rte_unused struct cmdline *cl,
15614         __rte_unused void *data)
15615 {
15616         struct cmd_vf_tc_bw_result *res = parsed_result;
15617         int ret = -ENOTSUP;
15618
15619         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15620                 return;
15621
15622 #ifdef RTE_LIBRTE_I40E_PMD
15623         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
15624                                             res->tc_no, res->bw);
15625 #endif
15626
15627         switch (ret) {
15628         case 0:
15629                 break;
15630         case -EINVAL:
15631                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
15632                        res->vf_id, res->tc_no, res->bw);
15633                 break;
15634         case -ENODEV:
15635                 printf("invalid port_id %d\n", res->port_id);
15636                 break;
15637         case -ENOTSUP:
15638                 printf("function not implemented\n");
15639                 break;
15640         default:
15641                 printf("programming error: (%s)\n", strerror(-ret));
15642         }
15643 }
15644
15645 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
15646         .f = cmd_vf_tc_max_bw_parsed,
15647         .data = NULL,
15648         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
15649                     " <bandwidth>",
15650         .tokens = {
15651                 (void *)&cmd_vf_tc_bw_set,
15652                 (void *)&cmd_vf_tc_bw_vf,
15653                 (void *)&cmd_vf_tc_bw_tc,
15654                 (void *)&cmd_vf_tc_bw_tx,
15655                 (void *)&cmd_vf_tc_bw_max_bw,
15656                 (void *)&cmd_vf_tc_bw_port_id,
15657                 (void *)&cmd_vf_tc_bw_vf_id,
15658                 (void *)&cmd_vf_tc_bw_tc_no,
15659                 (void *)&cmd_vf_tc_bw_bw,
15660                 NULL,
15661         },
15662 };
15663
15664 /** Set VXLAN encapsulation details */
15665 struct cmd_set_vxlan_result {
15666         cmdline_fixed_string_t set;
15667         cmdline_fixed_string_t vxlan;
15668         cmdline_fixed_string_t pos_token;
15669         cmdline_fixed_string_t ip_version;
15670         uint32_t vlan_present:1;
15671         uint32_t vni;
15672         uint16_t udp_src;
15673         uint16_t udp_dst;
15674         cmdline_ipaddr_t ip_src;
15675         cmdline_ipaddr_t ip_dst;
15676         uint16_t tci;
15677         uint8_t tos;
15678         uint8_t ttl;
15679         struct rte_ether_addr eth_src;
15680         struct rte_ether_addr eth_dst;
15681 };
15682
15683 cmdline_parse_token_string_t cmd_set_vxlan_set =
15684         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
15685 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
15686         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
15687 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
15688         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15689                                  "vxlan-tos-ttl");
15690 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
15691         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
15692                                  "vxlan-with-vlan");
15693 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
15694         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15695                                  "ip-version");
15696 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
15697         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
15698                                  "ipv4#ipv6");
15699 cmdline_parse_token_string_t cmd_set_vxlan_vni =
15700         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15701                                  "vni");
15702 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
15703         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
15704 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
15705         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15706                                  "udp-src");
15707 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
15708         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
15709 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
15710         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15711                                  "udp-dst");
15712 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
15713         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
15714 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
15715         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15716                                  "ip-tos");
15717 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
15718         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
15719 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
15720         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15721                                  "ip-ttl");
15722 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
15723         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
15724 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
15725         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15726                                  "ip-src");
15727 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
15728         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
15729 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
15730         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15731                                  "ip-dst");
15732 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
15733         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
15734 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
15735         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15736                                  "vlan-tci");
15737 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
15738         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
15739 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
15740         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15741                                  "eth-src");
15742 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
15743         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
15744 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
15745         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
15746                                  "eth-dst");
15747 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
15748         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
15749
15750 static void cmd_set_vxlan_parsed(void *parsed_result,
15751         __rte_unused struct cmdline *cl,
15752         __rte_unused void *data)
15753 {
15754         struct cmd_set_vxlan_result *res = parsed_result;
15755         union {
15756                 uint32_t vxlan_id;
15757                 uint8_t vni[4];
15758         } id = {
15759                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
15760         };
15761
15762         vxlan_encap_conf.select_tos_ttl = 0;
15763         if (strcmp(res->vxlan, "vxlan") == 0)
15764                 vxlan_encap_conf.select_vlan = 0;
15765         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
15766                 vxlan_encap_conf.select_vlan = 1;
15767         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
15768                 vxlan_encap_conf.select_vlan = 0;
15769                 vxlan_encap_conf.select_tos_ttl = 1;
15770         }
15771         if (strcmp(res->ip_version, "ipv4") == 0)
15772                 vxlan_encap_conf.select_ipv4 = 1;
15773         else if (strcmp(res->ip_version, "ipv6") == 0)
15774                 vxlan_encap_conf.select_ipv4 = 0;
15775         else
15776                 return;
15777         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
15778         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15779         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15780         vxlan_encap_conf.ip_tos = res->tos;
15781         vxlan_encap_conf.ip_ttl = res->ttl;
15782         if (vxlan_encap_conf.select_ipv4) {
15783                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
15784                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
15785         } else {
15786                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
15787                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
15788         }
15789         if (vxlan_encap_conf.select_vlan)
15790                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15791         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
15792                    RTE_ETHER_ADDR_LEN);
15793         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15794                    RTE_ETHER_ADDR_LEN);
15795 }
15796
15797 cmdline_parse_inst_t cmd_set_vxlan = {
15798         .f = cmd_set_vxlan_parsed,
15799         .data = NULL,
15800         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
15801                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
15802                 " eth-src <eth-src> eth-dst <eth-dst>",
15803         .tokens = {
15804                 (void *)&cmd_set_vxlan_set,
15805                 (void *)&cmd_set_vxlan_vxlan,
15806                 (void *)&cmd_set_vxlan_ip_version,
15807                 (void *)&cmd_set_vxlan_ip_version_value,
15808                 (void *)&cmd_set_vxlan_vni,
15809                 (void *)&cmd_set_vxlan_vni_value,
15810                 (void *)&cmd_set_vxlan_udp_src,
15811                 (void *)&cmd_set_vxlan_udp_src_value,
15812                 (void *)&cmd_set_vxlan_udp_dst,
15813                 (void *)&cmd_set_vxlan_udp_dst_value,
15814                 (void *)&cmd_set_vxlan_ip_src,
15815                 (void *)&cmd_set_vxlan_ip_src_value,
15816                 (void *)&cmd_set_vxlan_ip_dst,
15817                 (void *)&cmd_set_vxlan_ip_dst_value,
15818                 (void *)&cmd_set_vxlan_eth_src,
15819                 (void *)&cmd_set_vxlan_eth_src_value,
15820                 (void *)&cmd_set_vxlan_eth_dst,
15821                 (void *)&cmd_set_vxlan_eth_dst_value,
15822                 NULL,
15823         },
15824 };
15825
15826 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
15827         .f = cmd_set_vxlan_parsed,
15828         .data = NULL,
15829         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
15830                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
15831                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15832                 " eth-dst <eth-dst>",
15833         .tokens = {
15834                 (void *)&cmd_set_vxlan_set,
15835                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
15836                 (void *)&cmd_set_vxlan_ip_version,
15837                 (void *)&cmd_set_vxlan_ip_version_value,
15838                 (void *)&cmd_set_vxlan_vni,
15839                 (void *)&cmd_set_vxlan_vni_value,
15840                 (void *)&cmd_set_vxlan_udp_src,
15841                 (void *)&cmd_set_vxlan_udp_src_value,
15842                 (void *)&cmd_set_vxlan_udp_dst,
15843                 (void *)&cmd_set_vxlan_udp_dst_value,
15844                 (void *)&cmd_set_vxlan_ip_tos,
15845                 (void *)&cmd_set_vxlan_ip_tos_value,
15846                 (void *)&cmd_set_vxlan_ip_ttl,
15847                 (void *)&cmd_set_vxlan_ip_ttl_value,
15848                 (void *)&cmd_set_vxlan_ip_src,
15849                 (void *)&cmd_set_vxlan_ip_src_value,
15850                 (void *)&cmd_set_vxlan_ip_dst,
15851                 (void *)&cmd_set_vxlan_ip_dst_value,
15852                 (void *)&cmd_set_vxlan_eth_src,
15853                 (void *)&cmd_set_vxlan_eth_src_value,
15854                 (void *)&cmd_set_vxlan_eth_dst,
15855                 (void *)&cmd_set_vxlan_eth_dst_value,
15856                 NULL,
15857         },
15858 };
15859
15860 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
15861         .f = cmd_set_vxlan_parsed,
15862         .data = NULL,
15863         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
15864                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
15865                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
15866                 " <eth-dst>",
15867         .tokens = {
15868                 (void *)&cmd_set_vxlan_set,
15869                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
15870                 (void *)&cmd_set_vxlan_ip_version,
15871                 (void *)&cmd_set_vxlan_ip_version_value,
15872                 (void *)&cmd_set_vxlan_vni,
15873                 (void *)&cmd_set_vxlan_vni_value,
15874                 (void *)&cmd_set_vxlan_udp_src,
15875                 (void *)&cmd_set_vxlan_udp_src_value,
15876                 (void *)&cmd_set_vxlan_udp_dst,
15877                 (void *)&cmd_set_vxlan_udp_dst_value,
15878                 (void *)&cmd_set_vxlan_ip_src,
15879                 (void *)&cmd_set_vxlan_ip_src_value,
15880                 (void *)&cmd_set_vxlan_ip_dst,
15881                 (void *)&cmd_set_vxlan_ip_dst_value,
15882                 (void *)&cmd_set_vxlan_vlan,
15883                 (void *)&cmd_set_vxlan_vlan_value,
15884                 (void *)&cmd_set_vxlan_eth_src,
15885                 (void *)&cmd_set_vxlan_eth_src_value,
15886                 (void *)&cmd_set_vxlan_eth_dst,
15887                 (void *)&cmd_set_vxlan_eth_dst_value,
15888                 NULL,
15889         },
15890 };
15891
15892 /** Set NVGRE encapsulation details */
15893 struct cmd_set_nvgre_result {
15894         cmdline_fixed_string_t set;
15895         cmdline_fixed_string_t nvgre;
15896         cmdline_fixed_string_t pos_token;
15897         cmdline_fixed_string_t ip_version;
15898         uint32_t tni;
15899         cmdline_ipaddr_t ip_src;
15900         cmdline_ipaddr_t ip_dst;
15901         uint16_t tci;
15902         struct rte_ether_addr eth_src;
15903         struct rte_ether_addr eth_dst;
15904 };
15905
15906 cmdline_parse_token_string_t cmd_set_nvgre_set =
15907         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
15908 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
15909         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
15910 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
15911         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
15912                                  "nvgre-with-vlan");
15913 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
15914         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15915                                  "ip-version");
15916 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
15917         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
15918                                  "ipv4#ipv6");
15919 cmdline_parse_token_string_t cmd_set_nvgre_tni =
15920         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15921                                  "tni");
15922 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
15923         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
15924 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
15925         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15926                                  "ip-src");
15927 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
15928         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
15929 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
15930         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15931                                  "ip-dst");
15932 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
15933         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
15934 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
15935         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15936                                  "vlan-tci");
15937 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
15938         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
15939 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
15940         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15941                                  "eth-src");
15942 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
15943         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
15944 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
15945         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
15946                                  "eth-dst");
15947 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
15948         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
15949
15950 static void cmd_set_nvgre_parsed(void *parsed_result,
15951         __rte_unused struct cmdline *cl,
15952         __rte_unused void *data)
15953 {
15954         struct cmd_set_nvgre_result *res = parsed_result;
15955         union {
15956                 uint32_t nvgre_tni;
15957                 uint8_t tni[4];
15958         } id = {
15959                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
15960         };
15961
15962         if (strcmp(res->nvgre, "nvgre") == 0)
15963                 nvgre_encap_conf.select_vlan = 0;
15964         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
15965                 nvgre_encap_conf.select_vlan = 1;
15966         if (strcmp(res->ip_version, "ipv4") == 0)
15967                 nvgre_encap_conf.select_ipv4 = 1;
15968         else if (strcmp(res->ip_version, "ipv6") == 0)
15969                 nvgre_encap_conf.select_ipv4 = 0;
15970         else
15971                 return;
15972         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
15973         if (nvgre_encap_conf.select_ipv4) {
15974                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
15975                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
15976         } else {
15977                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
15978                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
15979         }
15980         if (nvgre_encap_conf.select_vlan)
15981                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15982         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
15983                    RTE_ETHER_ADDR_LEN);
15984         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15985                    RTE_ETHER_ADDR_LEN);
15986 }
15987
15988 cmdline_parse_inst_t cmd_set_nvgre = {
15989         .f = cmd_set_nvgre_parsed,
15990         .data = NULL,
15991         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
15992                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
15993                 " eth-dst <eth-dst>",
15994         .tokens = {
15995                 (void *)&cmd_set_nvgre_set,
15996                 (void *)&cmd_set_nvgre_nvgre,
15997                 (void *)&cmd_set_nvgre_ip_version,
15998                 (void *)&cmd_set_nvgre_ip_version_value,
15999                 (void *)&cmd_set_nvgre_tni,
16000                 (void *)&cmd_set_nvgre_tni_value,
16001                 (void *)&cmd_set_nvgre_ip_src,
16002                 (void *)&cmd_set_nvgre_ip_src_value,
16003                 (void *)&cmd_set_nvgre_ip_dst,
16004                 (void *)&cmd_set_nvgre_ip_dst_value,
16005                 (void *)&cmd_set_nvgre_eth_src,
16006                 (void *)&cmd_set_nvgre_eth_src_value,
16007                 (void *)&cmd_set_nvgre_eth_dst,
16008                 (void *)&cmd_set_nvgre_eth_dst_value,
16009                 NULL,
16010         },
16011 };
16012
16013 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
16014         .f = cmd_set_nvgre_parsed,
16015         .data = NULL,
16016         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
16017                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16018                 " eth-src <eth-src> eth-dst <eth-dst>",
16019         .tokens = {
16020                 (void *)&cmd_set_nvgre_set,
16021                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
16022                 (void *)&cmd_set_nvgre_ip_version,
16023                 (void *)&cmd_set_nvgre_ip_version_value,
16024                 (void *)&cmd_set_nvgre_tni,
16025                 (void *)&cmd_set_nvgre_tni_value,
16026                 (void *)&cmd_set_nvgre_ip_src,
16027                 (void *)&cmd_set_nvgre_ip_src_value,
16028                 (void *)&cmd_set_nvgre_ip_dst,
16029                 (void *)&cmd_set_nvgre_ip_dst_value,
16030                 (void *)&cmd_set_nvgre_vlan,
16031                 (void *)&cmd_set_nvgre_vlan_value,
16032                 (void *)&cmd_set_nvgre_eth_src,
16033                 (void *)&cmd_set_nvgre_eth_src_value,
16034                 (void *)&cmd_set_nvgre_eth_dst,
16035                 (void *)&cmd_set_nvgre_eth_dst_value,
16036                 NULL,
16037         },
16038 };
16039
16040 /** Set L2 encapsulation details */
16041 struct cmd_set_l2_encap_result {
16042         cmdline_fixed_string_t set;
16043         cmdline_fixed_string_t l2_encap;
16044         cmdline_fixed_string_t pos_token;
16045         cmdline_fixed_string_t ip_version;
16046         uint32_t vlan_present:1;
16047         uint16_t tci;
16048         struct rte_ether_addr eth_src;
16049         struct rte_ether_addr eth_dst;
16050 };
16051
16052 cmdline_parse_token_string_t cmd_set_l2_encap_set =
16053         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
16054 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
16055         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
16056 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
16057         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
16058                                  "l2_encap-with-vlan");
16059 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
16060         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16061                                  "ip-version");
16062 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
16063         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
16064                                  "ipv4#ipv6");
16065 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
16066         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16067                                  "vlan-tci");
16068 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
16069         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
16070 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
16071         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16072                                  "eth-src");
16073 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
16074         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
16075 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
16076         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
16077                                  "eth-dst");
16078 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
16079         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
16080
16081 static void cmd_set_l2_encap_parsed(void *parsed_result,
16082         __rte_unused struct cmdline *cl,
16083         __rte_unused void *data)
16084 {
16085         struct cmd_set_l2_encap_result *res = parsed_result;
16086
16087         if (strcmp(res->l2_encap, "l2_encap") == 0)
16088                 l2_encap_conf.select_vlan = 0;
16089         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
16090                 l2_encap_conf.select_vlan = 1;
16091         if (strcmp(res->ip_version, "ipv4") == 0)
16092                 l2_encap_conf.select_ipv4 = 1;
16093         else if (strcmp(res->ip_version, "ipv6") == 0)
16094                 l2_encap_conf.select_ipv4 = 0;
16095         else
16096                 return;
16097         if (l2_encap_conf.select_vlan)
16098                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16099         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
16100                    RTE_ETHER_ADDR_LEN);
16101         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16102                    RTE_ETHER_ADDR_LEN);
16103 }
16104
16105 cmdline_parse_inst_t cmd_set_l2_encap = {
16106         .f = cmd_set_l2_encap_parsed,
16107         .data = NULL,
16108         .help_str = "set l2_encap ip-version ipv4|ipv6"
16109                 " eth-src <eth-src> eth-dst <eth-dst>",
16110         .tokens = {
16111                 (void *)&cmd_set_l2_encap_set,
16112                 (void *)&cmd_set_l2_encap_l2_encap,
16113                 (void *)&cmd_set_l2_encap_ip_version,
16114                 (void *)&cmd_set_l2_encap_ip_version_value,
16115                 (void *)&cmd_set_l2_encap_eth_src,
16116                 (void *)&cmd_set_l2_encap_eth_src_value,
16117                 (void *)&cmd_set_l2_encap_eth_dst,
16118                 (void *)&cmd_set_l2_encap_eth_dst_value,
16119                 NULL,
16120         },
16121 };
16122
16123 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
16124         .f = cmd_set_l2_encap_parsed,
16125         .data = NULL,
16126         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
16127                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16128         .tokens = {
16129                 (void *)&cmd_set_l2_encap_set,
16130                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
16131                 (void *)&cmd_set_l2_encap_ip_version,
16132                 (void *)&cmd_set_l2_encap_ip_version_value,
16133                 (void *)&cmd_set_l2_encap_vlan,
16134                 (void *)&cmd_set_l2_encap_vlan_value,
16135                 (void *)&cmd_set_l2_encap_eth_src,
16136                 (void *)&cmd_set_l2_encap_eth_src_value,
16137                 (void *)&cmd_set_l2_encap_eth_dst,
16138                 (void *)&cmd_set_l2_encap_eth_dst_value,
16139                 NULL,
16140         },
16141 };
16142
16143 /** Set L2 decapsulation details */
16144 struct cmd_set_l2_decap_result {
16145         cmdline_fixed_string_t set;
16146         cmdline_fixed_string_t l2_decap;
16147         cmdline_fixed_string_t pos_token;
16148         uint32_t vlan_present:1;
16149 };
16150
16151 cmdline_parse_token_string_t cmd_set_l2_decap_set =
16152         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
16153 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
16154         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16155                                  "l2_decap");
16156 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
16157         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
16158                                  "l2_decap-with-vlan");
16159
16160 static void cmd_set_l2_decap_parsed(void *parsed_result,
16161         __rte_unused struct cmdline *cl,
16162         __rte_unused void *data)
16163 {
16164         struct cmd_set_l2_decap_result *res = parsed_result;
16165
16166         if (strcmp(res->l2_decap, "l2_decap") == 0)
16167                 l2_decap_conf.select_vlan = 0;
16168         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
16169                 l2_decap_conf.select_vlan = 1;
16170 }
16171
16172 cmdline_parse_inst_t cmd_set_l2_decap = {
16173         .f = cmd_set_l2_decap_parsed,
16174         .data = NULL,
16175         .help_str = "set l2_decap",
16176         .tokens = {
16177                 (void *)&cmd_set_l2_decap_set,
16178                 (void *)&cmd_set_l2_decap_l2_decap,
16179                 NULL,
16180         },
16181 };
16182
16183 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
16184         .f = cmd_set_l2_decap_parsed,
16185         .data = NULL,
16186         .help_str = "set l2_decap-with-vlan",
16187         .tokens = {
16188                 (void *)&cmd_set_l2_decap_set,
16189                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
16190                 NULL,
16191         },
16192 };
16193
16194 /** Set MPLSoGRE encapsulation details */
16195 struct cmd_set_mplsogre_encap_result {
16196         cmdline_fixed_string_t set;
16197         cmdline_fixed_string_t mplsogre;
16198         cmdline_fixed_string_t pos_token;
16199         cmdline_fixed_string_t ip_version;
16200         uint32_t vlan_present:1;
16201         uint32_t label;
16202         cmdline_ipaddr_t ip_src;
16203         cmdline_ipaddr_t ip_dst;
16204         uint16_t tci;
16205         struct rte_ether_addr eth_src;
16206         struct rte_ether_addr eth_dst;
16207 };
16208
16209 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
16210         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
16211                                  "set");
16212 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
16213         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
16214                                  "mplsogre_encap");
16215 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
16216         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16217                                  mplsogre, "mplsogre_encap-with-vlan");
16218 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
16219         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16220                                  pos_token, "ip-version");
16221 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
16222         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16223                                  ip_version, "ipv4#ipv6");
16224 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
16225         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16226                                  pos_token, "label");
16227 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
16228         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
16229                               UINT32);
16230 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
16231         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16232                                  pos_token, "ip-src");
16233 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
16234         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
16235 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
16236         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16237                                  pos_token, "ip-dst");
16238 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
16239         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
16240 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
16241         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16242                                  pos_token, "vlan-tci");
16243 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
16244         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
16245                               UINT16);
16246 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
16247         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16248                                  pos_token, "eth-src");
16249 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
16250         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16251                                     eth_src);
16252 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
16253         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16254                                  pos_token, "eth-dst");
16255 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
16256         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
16257                                     eth_dst);
16258
16259 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
16260         __rte_unused struct cmdline *cl,
16261         __rte_unused void *data)
16262 {
16263         struct cmd_set_mplsogre_encap_result *res = parsed_result;
16264         union {
16265                 uint32_t mplsogre_label;
16266                 uint8_t label[4];
16267         } id = {
16268                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
16269         };
16270
16271         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
16272                 mplsogre_encap_conf.select_vlan = 0;
16273         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
16274                 mplsogre_encap_conf.select_vlan = 1;
16275         if (strcmp(res->ip_version, "ipv4") == 0)
16276                 mplsogre_encap_conf.select_ipv4 = 1;
16277         else if (strcmp(res->ip_version, "ipv6") == 0)
16278                 mplsogre_encap_conf.select_ipv4 = 0;
16279         else
16280                 return;
16281         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
16282         if (mplsogre_encap_conf.select_ipv4) {
16283                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
16284                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
16285         } else {
16286                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
16287                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
16288         }
16289         if (mplsogre_encap_conf.select_vlan)
16290                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16291         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
16292                    RTE_ETHER_ADDR_LEN);
16293         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16294                    RTE_ETHER_ADDR_LEN);
16295 }
16296
16297 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
16298         .f = cmd_set_mplsogre_encap_parsed,
16299         .data = NULL,
16300         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
16301                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
16302                 " eth-dst <eth-dst>",
16303         .tokens = {
16304                 (void *)&cmd_set_mplsogre_encap_set,
16305                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
16306                 (void *)&cmd_set_mplsogre_encap_ip_version,
16307                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16308                 (void *)&cmd_set_mplsogre_encap_label,
16309                 (void *)&cmd_set_mplsogre_encap_label_value,
16310                 (void *)&cmd_set_mplsogre_encap_ip_src,
16311                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16312                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16313                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16314                 (void *)&cmd_set_mplsogre_encap_eth_src,
16315                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16316                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16317                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16318                 NULL,
16319         },
16320 };
16321
16322 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
16323         .f = cmd_set_mplsogre_encap_parsed,
16324         .data = NULL,
16325         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
16326                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
16327                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
16328         .tokens = {
16329                 (void *)&cmd_set_mplsogre_encap_set,
16330                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
16331                 (void *)&cmd_set_mplsogre_encap_ip_version,
16332                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
16333                 (void *)&cmd_set_mplsogre_encap_label,
16334                 (void *)&cmd_set_mplsogre_encap_label_value,
16335                 (void *)&cmd_set_mplsogre_encap_ip_src,
16336                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
16337                 (void *)&cmd_set_mplsogre_encap_ip_dst,
16338                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
16339                 (void *)&cmd_set_mplsogre_encap_vlan,
16340                 (void *)&cmd_set_mplsogre_encap_vlan_value,
16341                 (void *)&cmd_set_mplsogre_encap_eth_src,
16342                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
16343                 (void *)&cmd_set_mplsogre_encap_eth_dst,
16344                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
16345                 NULL,
16346         },
16347 };
16348
16349 /** Set MPLSoGRE decapsulation details */
16350 struct cmd_set_mplsogre_decap_result {
16351         cmdline_fixed_string_t set;
16352         cmdline_fixed_string_t mplsogre;
16353         cmdline_fixed_string_t pos_token;
16354         cmdline_fixed_string_t ip_version;
16355         uint32_t vlan_present:1;
16356 };
16357
16358 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
16359         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
16360                                  "set");
16361 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
16362         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
16363                                  "mplsogre_decap");
16364 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
16365         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16366                                  mplsogre, "mplsogre_decap-with-vlan");
16367 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
16368         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16369                                  pos_token, "ip-version");
16370 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
16371         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
16372                                  ip_version, "ipv4#ipv6");
16373
16374 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
16375         __rte_unused struct cmdline *cl,
16376         __rte_unused void *data)
16377 {
16378         struct cmd_set_mplsogre_decap_result *res = parsed_result;
16379
16380         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
16381                 mplsogre_decap_conf.select_vlan = 0;
16382         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
16383                 mplsogre_decap_conf.select_vlan = 1;
16384         if (strcmp(res->ip_version, "ipv4") == 0)
16385                 mplsogre_decap_conf.select_ipv4 = 1;
16386         else if (strcmp(res->ip_version, "ipv6") == 0)
16387                 mplsogre_decap_conf.select_ipv4 = 0;
16388 }
16389
16390 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
16391         .f = cmd_set_mplsogre_decap_parsed,
16392         .data = NULL,
16393         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
16394         .tokens = {
16395                 (void *)&cmd_set_mplsogre_decap_set,
16396                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
16397                 (void *)&cmd_set_mplsogre_decap_ip_version,
16398                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16399                 NULL,
16400         },
16401 };
16402
16403 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
16404         .f = cmd_set_mplsogre_decap_parsed,
16405         .data = NULL,
16406         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
16407         .tokens = {
16408                 (void *)&cmd_set_mplsogre_decap_set,
16409                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
16410                 (void *)&cmd_set_mplsogre_decap_ip_version,
16411                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
16412                 NULL,
16413         },
16414 };
16415
16416 /** Set MPLSoUDP encapsulation details */
16417 struct cmd_set_mplsoudp_encap_result {
16418         cmdline_fixed_string_t set;
16419         cmdline_fixed_string_t mplsoudp;
16420         cmdline_fixed_string_t pos_token;
16421         cmdline_fixed_string_t ip_version;
16422         uint32_t vlan_present:1;
16423         uint32_t label;
16424         uint16_t udp_src;
16425         uint16_t udp_dst;
16426         cmdline_ipaddr_t ip_src;
16427         cmdline_ipaddr_t ip_dst;
16428         uint16_t tci;
16429         struct rte_ether_addr eth_src;
16430         struct rte_ether_addr eth_dst;
16431 };
16432
16433 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
16434         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
16435                                  "set");
16436 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
16437         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
16438                                  "mplsoudp_encap");
16439 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
16440         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16441                                  mplsoudp, "mplsoudp_encap-with-vlan");
16442 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
16443         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16444                                  pos_token, "ip-version");
16445 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
16446         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16447                                  ip_version, "ipv4#ipv6");
16448 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
16449         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16450                                  pos_token, "label");
16451 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
16452         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
16453                               UINT32);
16454 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
16455         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16456                                  pos_token, "udp-src");
16457 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
16458         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
16459                               UINT16);
16460 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
16461         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16462                                  pos_token, "udp-dst");
16463 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
16464         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
16465                               UINT16);
16466 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
16467         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16468                                  pos_token, "ip-src");
16469 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
16470         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
16471 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
16472         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16473                                  pos_token, "ip-dst");
16474 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
16475         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
16476 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
16477         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16478                                  pos_token, "vlan-tci");
16479 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
16480         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
16481                               UINT16);
16482 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
16483         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16484                                  pos_token, "eth-src");
16485 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
16486         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16487                                     eth_src);
16488 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
16489         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16490                                  pos_token, "eth-dst");
16491 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
16492         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
16493                                     eth_dst);
16494
16495 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
16496         __rte_unused struct cmdline *cl,
16497         __rte_unused void *data)
16498 {
16499         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
16500         union {
16501                 uint32_t mplsoudp_label;
16502                 uint8_t label[4];
16503         } id = {
16504                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
16505         };
16506
16507         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
16508                 mplsoudp_encap_conf.select_vlan = 0;
16509         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
16510                 mplsoudp_encap_conf.select_vlan = 1;
16511         if (strcmp(res->ip_version, "ipv4") == 0)
16512                 mplsoudp_encap_conf.select_ipv4 = 1;
16513         else if (strcmp(res->ip_version, "ipv6") == 0)
16514                 mplsoudp_encap_conf.select_ipv4 = 0;
16515         else
16516                 return;
16517         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
16518         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
16519         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
16520         if (mplsoudp_encap_conf.select_ipv4) {
16521                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
16522                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
16523         } else {
16524                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
16525                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
16526         }
16527         if (mplsoudp_encap_conf.select_vlan)
16528                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
16529         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
16530                    RTE_ETHER_ADDR_LEN);
16531         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
16532                    RTE_ETHER_ADDR_LEN);
16533 }
16534
16535 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
16536         .f = cmd_set_mplsoudp_encap_parsed,
16537         .data = NULL,
16538         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
16539                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
16540                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
16541         .tokens = {
16542                 (void *)&cmd_set_mplsoudp_encap_set,
16543                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
16544                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16545                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16546                 (void *)&cmd_set_mplsoudp_encap_label,
16547                 (void *)&cmd_set_mplsoudp_encap_label_value,
16548                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16549                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16550                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16551                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16552                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16553                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16554                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16555                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16556                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16557                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16558                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16559                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16560                 NULL,
16561         },
16562 };
16563
16564 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
16565         .f = cmd_set_mplsoudp_encap_parsed,
16566         .data = NULL,
16567         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
16568                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
16569                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
16570                 " eth-src <eth-src> eth-dst <eth-dst>",
16571         .tokens = {
16572                 (void *)&cmd_set_mplsoudp_encap_set,
16573                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
16574                 (void *)&cmd_set_mplsoudp_encap_ip_version,
16575                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
16576                 (void *)&cmd_set_mplsoudp_encap_label,
16577                 (void *)&cmd_set_mplsoudp_encap_label_value,
16578                 (void *)&cmd_set_mplsoudp_encap_udp_src,
16579                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
16580                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
16581                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
16582                 (void *)&cmd_set_mplsoudp_encap_ip_src,
16583                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
16584                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
16585                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
16586                 (void *)&cmd_set_mplsoudp_encap_vlan,
16587                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
16588                 (void *)&cmd_set_mplsoudp_encap_eth_src,
16589                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
16590                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
16591                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
16592                 NULL,
16593         },
16594 };
16595
16596 /** Set MPLSoUDP decapsulation details */
16597 struct cmd_set_mplsoudp_decap_result {
16598         cmdline_fixed_string_t set;
16599         cmdline_fixed_string_t mplsoudp;
16600         cmdline_fixed_string_t pos_token;
16601         cmdline_fixed_string_t ip_version;
16602         uint32_t vlan_present:1;
16603 };
16604
16605 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
16606         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
16607                                  "set");
16608 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
16609         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
16610                                  "mplsoudp_decap");
16611 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
16612         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16613                                  mplsoudp, "mplsoudp_decap-with-vlan");
16614 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
16615         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16616                                  pos_token, "ip-version");
16617 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
16618         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
16619                                  ip_version, "ipv4#ipv6");
16620
16621 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
16622         __rte_unused struct cmdline *cl,
16623         __rte_unused void *data)
16624 {
16625         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
16626
16627         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
16628                 mplsoudp_decap_conf.select_vlan = 0;
16629         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
16630                 mplsoudp_decap_conf.select_vlan = 1;
16631         if (strcmp(res->ip_version, "ipv4") == 0)
16632                 mplsoudp_decap_conf.select_ipv4 = 1;
16633         else if (strcmp(res->ip_version, "ipv6") == 0)
16634                 mplsoudp_decap_conf.select_ipv4 = 0;
16635 }
16636
16637 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
16638         .f = cmd_set_mplsoudp_decap_parsed,
16639         .data = NULL,
16640         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
16641         .tokens = {
16642                 (void *)&cmd_set_mplsoudp_decap_set,
16643                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
16644                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16645                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16646                 NULL,
16647         },
16648 };
16649
16650 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
16651         .f = cmd_set_mplsoudp_decap_parsed,
16652         .data = NULL,
16653         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
16654         .tokens = {
16655                 (void *)&cmd_set_mplsoudp_decap_set,
16656                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
16657                 (void *)&cmd_set_mplsoudp_decap_ip_version,
16658                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
16659                 NULL,
16660         },
16661 };
16662
16663 /* Strict link priority scheduling mode setting */
16664 static void
16665 cmd_strict_link_prio_parsed(
16666         void *parsed_result,
16667         __rte_unused struct cmdline *cl,
16668         __rte_unused void *data)
16669 {
16670         struct cmd_vf_tc_bw_result *res = parsed_result;
16671         int ret = -ENOTSUP;
16672
16673         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16674                 return;
16675
16676 #ifdef RTE_LIBRTE_I40E_PMD
16677         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
16678 #endif
16679
16680         switch (ret) {
16681         case 0:
16682                 break;
16683         case -EINVAL:
16684                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
16685                 break;
16686         case -ENODEV:
16687                 printf("invalid port_id %d\n", res->port_id);
16688                 break;
16689         case -ENOTSUP:
16690                 printf("function not implemented\n");
16691                 break;
16692         default:
16693                 printf("programming error: (%s)\n", strerror(-ret));
16694         }
16695 }
16696
16697 cmdline_parse_inst_t cmd_strict_link_prio = {
16698         .f = cmd_strict_link_prio_parsed,
16699         .data = NULL,
16700         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
16701         .tokens = {
16702                 (void *)&cmd_vf_tc_bw_set,
16703                 (void *)&cmd_vf_tc_bw_tx,
16704                 (void *)&cmd_vf_tc_bw_strict_link_prio,
16705                 (void *)&cmd_vf_tc_bw_port_id,
16706                 (void *)&cmd_vf_tc_bw_tc_map,
16707                 NULL,
16708         },
16709 };
16710
16711 /* Load dynamic device personalization*/
16712 struct cmd_ddp_add_result {
16713         cmdline_fixed_string_t ddp;
16714         cmdline_fixed_string_t add;
16715         portid_t port_id;
16716         char filepath[];
16717 };
16718
16719 cmdline_parse_token_string_t cmd_ddp_add_ddp =
16720         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
16721 cmdline_parse_token_string_t cmd_ddp_add_add =
16722         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
16723 cmdline_parse_token_num_t cmd_ddp_add_port_id =
16724         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
16725 cmdline_parse_token_string_t cmd_ddp_add_filepath =
16726         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
16727
16728 static void
16729 cmd_ddp_add_parsed(
16730         void *parsed_result,
16731         __rte_unused struct cmdline *cl,
16732         __rte_unused void *data)
16733 {
16734         struct cmd_ddp_add_result *res = parsed_result;
16735         uint8_t *buff;
16736         uint32_t size;
16737         char *filepath;
16738         char *file_fld[2];
16739         int file_num;
16740         int ret = -ENOTSUP;
16741
16742         if (!all_ports_stopped()) {
16743                 printf("Please stop all ports first\n");
16744                 return;
16745         }
16746
16747         filepath = strdup(res->filepath);
16748         if (filepath == NULL) {
16749                 printf("Failed to allocate memory\n");
16750                 return;
16751         }
16752         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
16753
16754         buff = open_file(file_fld[0], &size);
16755         if (!buff) {
16756                 free((void *)filepath);
16757                 return;
16758         }
16759
16760 #ifdef RTE_LIBRTE_I40E_PMD
16761         if (ret == -ENOTSUP)
16762                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16763                                                buff, size,
16764                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
16765 #endif
16766
16767         if (ret == -EEXIST)
16768                 printf("Profile has already existed.\n");
16769         else if (ret < 0)
16770                 printf("Failed to load profile.\n");
16771         else if (file_num == 2)
16772                 save_file(file_fld[1], buff, size);
16773
16774         close_file(buff);
16775         free((void *)filepath);
16776 }
16777
16778 cmdline_parse_inst_t cmd_ddp_add = {
16779         .f = cmd_ddp_add_parsed,
16780         .data = NULL,
16781         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
16782         .tokens = {
16783                 (void *)&cmd_ddp_add_ddp,
16784                 (void *)&cmd_ddp_add_add,
16785                 (void *)&cmd_ddp_add_port_id,
16786                 (void *)&cmd_ddp_add_filepath,
16787                 NULL,
16788         },
16789 };
16790
16791 /* Delete dynamic device personalization*/
16792 struct cmd_ddp_del_result {
16793         cmdline_fixed_string_t ddp;
16794         cmdline_fixed_string_t del;
16795         portid_t port_id;
16796         char filepath[];
16797 };
16798
16799 cmdline_parse_token_string_t cmd_ddp_del_ddp =
16800         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
16801 cmdline_parse_token_string_t cmd_ddp_del_del =
16802         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
16803 cmdline_parse_token_num_t cmd_ddp_del_port_id =
16804         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
16805 cmdline_parse_token_string_t cmd_ddp_del_filepath =
16806         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
16807
16808 static void
16809 cmd_ddp_del_parsed(
16810         void *parsed_result,
16811         __rte_unused struct cmdline *cl,
16812         __rte_unused void *data)
16813 {
16814         struct cmd_ddp_del_result *res = parsed_result;
16815         uint8_t *buff;
16816         uint32_t size;
16817         int ret = -ENOTSUP;
16818
16819         if (!all_ports_stopped()) {
16820                 printf("Please stop all ports first\n");
16821                 return;
16822         }
16823
16824         buff = open_file(res->filepath, &size);
16825         if (!buff)
16826                 return;
16827
16828 #ifdef RTE_LIBRTE_I40E_PMD
16829         if (ret == -ENOTSUP)
16830                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
16831                                                buff, size,
16832                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
16833 #endif
16834
16835         if (ret == -EACCES)
16836                 printf("Profile does not exist.\n");
16837         else if (ret < 0)
16838                 printf("Failed to delete profile.\n");
16839
16840         close_file(buff);
16841 }
16842
16843 cmdline_parse_inst_t cmd_ddp_del = {
16844         .f = cmd_ddp_del_parsed,
16845         .data = NULL,
16846         .help_str = "ddp del <port_id> <backup_profile_path>",
16847         .tokens = {
16848                 (void *)&cmd_ddp_del_ddp,
16849                 (void *)&cmd_ddp_del_del,
16850                 (void *)&cmd_ddp_del_port_id,
16851                 (void *)&cmd_ddp_del_filepath,
16852                 NULL,
16853         },
16854 };
16855
16856 /* Get dynamic device personalization profile info */
16857 struct cmd_ddp_info_result {
16858         cmdline_fixed_string_t ddp;
16859         cmdline_fixed_string_t get;
16860         cmdline_fixed_string_t info;
16861         char filepath[];
16862 };
16863
16864 cmdline_parse_token_string_t cmd_ddp_info_ddp =
16865         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
16866 cmdline_parse_token_string_t cmd_ddp_info_get =
16867         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
16868 cmdline_parse_token_string_t cmd_ddp_info_info =
16869         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
16870 cmdline_parse_token_string_t cmd_ddp_info_filepath =
16871         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
16872
16873 static void
16874 cmd_ddp_info_parsed(
16875         void *parsed_result,
16876         __rte_unused struct cmdline *cl,
16877         __rte_unused void *data)
16878 {
16879         struct cmd_ddp_info_result *res = parsed_result;
16880         uint8_t *pkg;
16881         uint32_t pkg_size;
16882         int ret = -ENOTSUP;
16883 #ifdef RTE_LIBRTE_I40E_PMD
16884         uint32_t i, j, n;
16885         uint8_t *buff;
16886         uint32_t buff_size = 0;
16887         struct rte_pmd_i40e_profile_info info;
16888         uint32_t dev_num = 0;
16889         struct rte_pmd_i40e_ddp_device_id *devs;
16890         uint32_t proto_num = 0;
16891         struct rte_pmd_i40e_proto_info *proto = NULL;
16892         uint32_t pctype_num = 0;
16893         struct rte_pmd_i40e_ptype_info *pctype;
16894         uint32_t ptype_num = 0;
16895         struct rte_pmd_i40e_ptype_info *ptype;
16896         uint8_t proto_id;
16897
16898 #endif
16899
16900         pkg = open_file(res->filepath, &pkg_size);
16901         if (!pkg)
16902                 return;
16903
16904 #ifdef RTE_LIBRTE_I40E_PMD
16905         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16906                                 (uint8_t *)&info, sizeof(info),
16907                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
16908         if (!ret) {
16909                 printf("Global Track id:       0x%x\n", info.track_id);
16910                 printf("Global Version:        %d.%d.%d.%d\n",
16911                         info.version.major,
16912                         info.version.minor,
16913                         info.version.update,
16914                         info.version.draft);
16915                 printf("Global Package name:   %s\n\n", info.name);
16916         }
16917
16918         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16919                                 (uint8_t *)&info, sizeof(info),
16920                                 RTE_PMD_I40E_PKG_INFO_HEADER);
16921         if (!ret) {
16922                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
16923                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
16924                         info.version.major,
16925                         info.version.minor,
16926                         info.version.update,
16927                         info.version.draft);
16928                 printf("i40e Profile name:     %s\n\n", info.name);
16929         }
16930
16931         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16932                                 (uint8_t *)&buff_size, sizeof(buff_size),
16933                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
16934         if (!ret && buff_size) {
16935                 buff = (uint8_t *)malloc(buff_size);
16936                 if (buff) {
16937                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16938                                                 buff, buff_size,
16939                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
16940                         if (!ret)
16941                                 printf("Package Notes:\n%s\n\n", buff);
16942                         free(buff);
16943                 }
16944         }
16945
16946         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16947                                 (uint8_t *)&dev_num, sizeof(dev_num),
16948                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
16949         if (!ret && dev_num) {
16950                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
16951                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
16952                 if (devs) {
16953                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16954                                                 (uint8_t *)devs, buff_size,
16955                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
16956                         if (!ret) {
16957                                 printf("List of supported devices:\n");
16958                                 for (i = 0; i < dev_num; i++) {
16959                                         printf("  %04X:%04X %04X:%04X\n",
16960                                                 devs[i].vendor_dev_id >> 16,
16961                                                 devs[i].vendor_dev_id & 0xFFFF,
16962                                                 devs[i].sub_vendor_dev_id >> 16,
16963                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
16964                                 }
16965                                 printf("\n");
16966                         }
16967                         free(devs);
16968                 }
16969         }
16970
16971         /* get information about protocols and packet types */
16972         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16973                 (uint8_t *)&proto_num, sizeof(proto_num),
16974                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
16975         if (ret || !proto_num)
16976                 goto no_print_return;
16977
16978         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
16979         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
16980         if (!proto)
16981                 goto no_print_return;
16982
16983         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
16984                                         buff_size,
16985                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
16986         if (!ret) {
16987                 printf("List of used protocols:\n");
16988                 for (i = 0; i < proto_num; i++)
16989                         printf("  %2u: %s\n", proto[i].proto_id,
16990                                proto[i].name);
16991                 printf("\n");
16992         }
16993         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
16994                 (uint8_t *)&pctype_num, sizeof(pctype_num),
16995                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
16996         if (ret || !pctype_num)
16997                 goto no_print_pctypes;
16998
16999         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
17000         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
17001         if (!pctype)
17002                 goto no_print_pctypes;
17003
17004         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
17005                                         buff_size,
17006                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
17007         if (ret) {
17008                 free(pctype);
17009                 goto no_print_pctypes;
17010         }
17011
17012         printf("List of defined packet classification types:\n");
17013         for (i = 0; i < pctype_num; i++) {
17014                 printf("  %2u:", pctype[i].ptype_id);
17015                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17016                         proto_id = pctype[i].protocols[j];
17017                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17018                                 for (n = 0; n < proto_num; n++) {
17019                                         if (proto[n].proto_id == proto_id) {
17020                                                 printf(" %s", proto[n].name);
17021                                                 break;
17022                                         }
17023                                 }
17024                         }
17025                 }
17026                 printf("\n");
17027         }
17028         printf("\n");
17029         free(pctype);
17030
17031 no_print_pctypes:
17032
17033         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
17034                                         sizeof(ptype_num),
17035                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
17036         if (ret || !ptype_num)
17037                 goto no_print_return;
17038
17039         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
17040         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
17041         if (!ptype)
17042                 goto no_print_return;
17043
17044         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
17045                                         buff_size,
17046                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
17047         if (ret) {
17048                 free(ptype);
17049                 goto no_print_return;
17050         }
17051         printf("List of defined packet types:\n");
17052         for (i = 0; i < ptype_num; i++) {
17053                 printf("  %2u:", ptype[i].ptype_id);
17054                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
17055                         proto_id = ptype[i].protocols[j];
17056                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
17057                                 for (n = 0; n < proto_num; n++) {
17058                                         if (proto[n].proto_id == proto_id) {
17059                                                 printf(" %s", proto[n].name);
17060                                                 break;
17061                                         }
17062                                 }
17063                         }
17064                 }
17065                 printf("\n");
17066         }
17067         free(ptype);
17068         printf("\n");
17069
17070         ret = 0;
17071 no_print_return:
17072         if (proto)
17073                 free(proto);
17074 #endif
17075         if (ret == -ENOTSUP)
17076                 printf("Function not supported in PMD driver\n");
17077         close_file(pkg);
17078 }
17079
17080 cmdline_parse_inst_t cmd_ddp_get_info = {
17081         .f = cmd_ddp_info_parsed,
17082         .data = NULL,
17083         .help_str = "ddp get info <profile_path>",
17084         .tokens = {
17085                 (void *)&cmd_ddp_info_ddp,
17086                 (void *)&cmd_ddp_info_get,
17087                 (void *)&cmd_ddp_info_info,
17088                 (void *)&cmd_ddp_info_filepath,
17089                 NULL,
17090         },
17091 };
17092
17093 /* Get dynamic device personalization profile info list*/
17094 #define PROFILE_INFO_SIZE 48
17095 #define MAX_PROFILE_NUM 16
17096
17097 struct cmd_ddp_get_list_result {
17098         cmdline_fixed_string_t ddp;
17099         cmdline_fixed_string_t get;
17100         cmdline_fixed_string_t list;
17101         portid_t port_id;
17102 };
17103
17104 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
17105         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
17106 cmdline_parse_token_string_t cmd_ddp_get_list_get =
17107         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
17108 cmdline_parse_token_string_t cmd_ddp_get_list_list =
17109         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
17110 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
17111         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
17112
17113 static void
17114 cmd_ddp_get_list_parsed(
17115         __rte_unused void *parsed_result,
17116         __rte_unused struct cmdline *cl,
17117         __rte_unused void *data)
17118 {
17119 #ifdef RTE_LIBRTE_I40E_PMD
17120         struct cmd_ddp_get_list_result *res = parsed_result;
17121         struct rte_pmd_i40e_profile_list *p_list;
17122         struct rte_pmd_i40e_profile_info *p_info;
17123         uint32_t p_num;
17124         uint32_t size;
17125         uint32_t i;
17126 #endif
17127         int ret = -ENOTSUP;
17128
17129 #ifdef RTE_LIBRTE_I40E_PMD
17130         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
17131         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
17132         if (!p_list) {
17133                 printf("%s: Failed to malloc buffer\n", __func__);
17134                 return;
17135         }
17136
17137         if (ret == -ENOTSUP)
17138                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
17139                                                 (uint8_t *)p_list, size);
17140
17141         if (!ret) {
17142                 p_num = p_list->p_count;
17143                 printf("Profile number is: %d\n\n", p_num);
17144
17145                 for (i = 0; i < p_num; i++) {
17146                         p_info = &p_list->p_info[i];
17147                         printf("Profile %d:\n", i);
17148                         printf("Track id:     0x%x\n", p_info->track_id);
17149                         printf("Version:      %d.%d.%d.%d\n",
17150                                p_info->version.major,
17151                                p_info->version.minor,
17152                                p_info->version.update,
17153                                p_info->version.draft);
17154                         printf("Profile name: %s\n\n", p_info->name);
17155                 }
17156         }
17157
17158         free(p_list);
17159 #endif
17160
17161         if (ret < 0)
17162                 printf("Failed to get ddp list\n");
17163 }
17164
17165 cmdline_parse_inst_t cmd_ddp_get_list = {
17166         .f = cmd_ddp_get_list_parsed,
17167         .data = NULL,
17168         .help_str = "ddp get list <port_id>",
17169         .tokens = {
17170                 (void *)&cmd_ddp_get_list_ddp,
17171                 (void *)&cmd_ddp_get_list_get,
17172                 (void *)&cmd_ddp_get_list_list,
17173                 (void *)&cmd_ddp_get_list_port_id,
17174                 NULL,
17175         },
17176 };
17177
17178 /* Configure input set */
17179 struct cmd_cfg_input_set_result {
17180         cmdline_fixed_string_t port;
17181         cmdline_fixed_string_t cfg;
17182         portid_t port_id;
17183         cmdline_fixed_string_t pctype;
17184         uint8_t pctype_id;
17185         cmdline_fixed_string_t inset_type;
17186         cmdline_fixed_string_t opt;
17187         cmdline_fixed_string_t field;
17188         uint8_t field_idx;
17189 };
17190
17191 static void
17192 cmd_cfg_input_set_parsed(
17193         __rte_unused void *parsed_result,
17194         __rte_unused struct cmdline *cl,
17195         __rte_unused void *data)
17196 {
17197 #ifdef RTE_LIBRTE_I40E_PMD
17198         struct cmd_cfg_input_set_result *res = parsed_result;
17199         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17200         struct rte_pmd_i40e_inset inset;
17201 #endif
17202         int ret = -ENOTSUP;
17203
17204         if (!all_ports_stopped()) {
17205                 printf("Please stop all ports first\n");
17206                 return;
17207         }
17208
17209 #ifdef RTE_LIBRTE_I40E_PMD
17210         if (!strcmp(res->inset_type, "hash_inset"))
17211                 inset_type = INSET_HASH;
17212         else if (!strcmp(res->inset_type, "fdir_inset"))
17213                 inset_type = INSET_FDIR;
17214         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17215                 inset_type = INSET_FDIR_FLX;
17216         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
17217                                      &inset, inset_type);
17218         if (ret) {
17219                 printf("Failed to get input set.\n");
17220                 return;
17221         }
17222
17223         if (!strcmp(res->opt, "get")) {
17224                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
17225                                                    res->field_idx);
17226                 if (ret)
17227                         printf("Field index %d is enabled.\n", res->field_idx);
17228                 else
17229                         printf("Field index %d is disabled.\n", res->field_idx);
17230                 return;
17231         } else if (!strcmp(res->opt, "set"))
17232                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
17233                                                    res->field_idx);
17234         else if (!strcmp(res->opt, "clear"))
17235                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
17236                                                      res->field_idx);
17237         if (ret) {
17238                 printf("Failed to configure input set field.\n");
17239                 return;
17240         }
17241
17242         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17243                                      &inset, inset_type);
17244         if (ret) {
17245                 printf("Failed to set input set.\n");
17246                 return;
17247         }
17248 #endif
17249
17250         if (ret == -ENOTSUP)
17251                 printf("Function not supported\n");
17252 }
17253
17254 cmdline_parse_token_string_t cmd_cfg_input_set_port =
17255         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17256                                  port, "port");
17257 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
17258         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17259                                  cfg, "config");
17260 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
17261         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17262                               port_id, UINT16);
17263 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
17264         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17265                                  pctype, "pctype");
17266 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
17267         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17268                               pctype_id, UINT8);
17269 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
17270         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17271                                  inset_type,
17272                                  "hash_inset#fdir_inset#fdir_flx_inset");
17273 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
17274         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17275                                  opt, "get#set#clear");
17276 cmdline_parse_token_string_t cmd_cfg_input_set_field =
17277         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
17278                                  field, "field");
17279 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
17280         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
17281                               field_idx, UINT8);
17282
17283 cmdline_parse_inst_t cmd_cfg_input_set = {
17284         .f = cmd_cfg_input_set_parsed,
17285         .data = NULL,
17286         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17287                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
17288         .tokens = {
17289                 (void *)&cmd_cfg_input_set_port,
17290                 (void *)&cmd_cfg_input_set_cfg,
17291                 (void *)&cmd_cfg_input_set_port_id,
17292                 (void *)&cmd_cfg_input_set_pctype,
17293                 (void *)&cmd_cfg_input_set_pctype_id,
17294                 (void *)&cmd_cfg_input_set_inset_type,
17295                 (void *)&cmd_cfg_input_set_opt,
17296                 (void *)&cmd_cfg_input_set_field,
17297                 (void *)&cmd_cfg_input_set_field_idx,
17298                 NULL,
17299         },
17300 };
17301
17302 /* Clear input set */
17303 struct cmd_clear_input_set_result {
17304         cmdline_fixed_string_t port;
17305         cmdline_fixed_string_t cfg;
17306         portid_t port_id;
17307         cmdline_fixed_string_t pctype;
17308         uint8_t pctype_id;
17309         cmdline_fixed_string_t inset_type;
17310         cmdline_fixed_string_t clear;
17311         cmdline_fixed_string_t all;
17312 };
17313
17314 static void
17315 cmd_clear_input_set_parsed(
17316         __rte_unused void *parsed_result,
17317         __rte_unused struct cmdline *cl,
17318         __rte_unused void *data)
17319 {
17320 #ifdef RTE_LIBRTE_I40E_PMD
17321         struct cmd_clear_input_set_result *res = parsed_result;
17322         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
17323         struct rte_pmd_i40e_inset inset;
17324 #endif
17325         int ret = -ENOTSUP;
17326
17327         if (!all_ports_stopped()) {
17328                 printf("Please stop all ports first\n");
17329                 return;
17330         }
17331
17332 #ifdef RTE_LIBRTE_I40E_PMD
17333         if (!strcmp(res->inset_type, "hash_inset"))
17334                 inset_type = INSET_HASH;
17335         else if (!strcmp(res->inset_type, "fdir_inset"))
17336                 inset_type = INSET_FDIR;
17337         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
17338                 inset_type = INSET_FDIR_FLX;
17339
17340         memset(&inset, 0, sizeof(inset));
17341
17342         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
17343                                      &inset, inset_type);
17344         if (ret) {
17345                 printf("Failed to clear input set.\n");
17346                 return;
17347         }
17348
17349 #endif
17350
17351         if (ret == -ENOTSUP)
17352                 printf("Function not supported\n");
17353 }
17354
17355 cmdline_parse_token_string_t cmd_clear_input_set_port =
17356         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17357                                  port, "port");
17358 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
17359         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17360                                  cfg, "config");
17361 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
17362         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17363                               port_id, UINT16);
17364 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
17365         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17366                                  pctype, "pctype");
17367 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
17368         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
17369                               pctype_id, UINT8);
17370 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
17371         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17372                                  inset_type,
17373                                  "hash_inset#fdir_inset#fdir_flx_inset");
17374 cmdline_parse_token_string_t cmd_clear_input_set_clear =
17375         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17376                                  clear, "clear");
17377 cmdline_parse_token_string_t cmd_clear_input_set_all =
17378         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
17379                                  all, "all");
17380
17381 cmdline_parse_inst_t cmd_clear_input_set = {
17382         .f = cmd_clear_input_set_parsed,
17383         .data = NULL,
17384         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
17385                     "fdir_inset|fdir_flx_inset clear all",
17386         .tokens = {
17387                 (void *)&cmd_clear_input_set_port,
17388                 (void *)&cmd_clear_input_set_cfg,
17389                 (void *)&cmd_clear_input_set_port_id,
17390                 (void *)&cmd_clear_input_set_pctype,
17391                 (void *)&cmd_clear_input_set_pctype_id,
17392                 (void *)&cmd_clear_input_set_inset_type,
17393                 (void *)&cmd_clear_input_set_clear,
17394                 (void *)&cmd_clear_input_set_all,
17395                 NULL,
17396         },
17397 };
17398
17399 /* show vf stats */
17400
17401 /* Common result structure for show vf stats */
17402 struct cmd_show_vf_stats_result {
17403         cmdline_fixed_string_t show;
17404         cmdline_fixed_string_t vf;
17405         cmdline_fixed_string_t stats;
17406         portid_t port_id;
17407         uint16_t vf_id;
17408 };
17409
17410 /* Common CLI fields show vf stats*/
17411 cmdline_parse_token_string_t cmd_show_vf_stats_show =
17412         TOKEN_STRING_INITIALIZER
17413                 (struct cmd_show_vf_stats_result,
17414                  show, "show");
17415 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
17416         TOKEN_STRING_INITIALIZER
17417                 (struct cmd_show_vf_stats_result,
17418                  vf, "vf");
17419 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
17420         TOKEN_STRING_INITIALIZER
17421                 (struct cmd_show_vf_stats_result,
17422                  stats, "stats");
17423 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
17424         TOKEN_NUM_INITIALIZER
17425                 (struct cmd_show_vf_stats_result,
17426                  port_id, UINT16);
17427 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
17428         TOKEN_NUM_INITIALIZER
17429                 (struct cmd_show_vf_stats_result,
17430                  vf_id, UINT16);
17431
17432 static void
17433 cmd_show_vf_stats_parsed(
17434         void *parsed_result,
17435         __rte_unused struct cmdline *cl,
17436         __rte_unused void *data)
17437 {
17438         struct cmd_show_vf_stats_result *res = parsed_result;
17439         struct rte_eth_stats stats;
17440         int ret = -ENOTSUP;
17441         static const char *nic_stats_border = "########################";
17442
17443         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17444                 return;
17445
17446         memset(&stats, 0, sizeof(stats));
17447
17448 #ifdef RTE_LIBRTE_I40E_PMD
17449         if (ret == -ENOTSUP)
17450                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
17451                                                 res->vf_id,
17452                                                 &stats);
17453 #endif
17454 #ifdef RTE_LIBRTE_BNXT_PMD
17455         if (ret == -ENOTSUP)
17456                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
17457                                                 res->vf_id,
17458                                                 &stats);
17459 #endif
17460
17461         switch (ret) {
17462         case 0:
17463                 break;
17464         case -EINVAL:
17465                 printf("invalid vf_id %d\n", res->vf_id);
17466                 break;
17467         case -ENODEV:
17468                 printf("invalid port_id %d\n", res->port_id);
17469                 break;
17470         case -ENOTSUP:
17471                 printf("function not implemented\n");
17472                 break;
17473         default:
17474                 printf("programming error: (%s)\n", strerror(-ret));
17475         }
17476
17477         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
17478                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
17479
17480         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
17481                "%-"PRIu64"\n",
17482                stats.ipackets, stats.imissed, stats.ibytes);
17483         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
17484         printf("  RX-nombuf:  %-10"PRIu64"\n",
17485                stats.rx_nombuf);
17486         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
17487                "%-"PRIu64"\n",
17488                stats.opackets, stats.oerrors, stats.obytes);
17489
17490         printf("  %s############################%s\n",
17491                                nic_stats_border, nic_stats_border);
17492 }
17493
17494 cmdline_parse_inst_t cmd_show_vf_stats = {
17495         .f = cmd_show_vf_stats_parsed,
17496         .data = NULL,
17497         .help_str = "show vf stats <port_id> <vf_id>",
17498         .tokens = {
17499                 (void *)&cmd_show_vf_stats_show,
17500                 (void *)&cmd_show_vf_stats_vf,
17501                 (void *)&cmd_show_vf_stats_stats,
17502                 (void *)&cmd_show_vf_stats_port_id,
17503                 (void *)&cmd_show_vf_stats_vf_id,
17504                 NULL,
17505         },
17506 };
17507
17508 /* clear vf stats */
17509
17510 /* Common result structure for clear vf stats */
17511 struct cmd_clear_vf_stats_result {
17512         cmdline_fixed_string_t clear;
17513         cmdline_fixed_string_t vf;
17514         cmdline_fixed_string_t stats;
17515         portid_t port_id;
17516         uint16_t vf_id;
17517 };
17518
17519 /* Common CLI fields clear vf stats*/
17520 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
17521         TOKEN_STRING_INITIALIZER
17522                 (struct cmd_clear_vf_stats_result,
17523                  clear, "clear");
17524 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
17525         TOKEN_STRING_INITIALIZER
17526                 (struct cmd_clear_vf_stats_result,
17527                  vf, "vf");
17528 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
17529         TOKEN_STRING_INITIALIZER
17530                 (struct cmd_clear_vf_stats_result,
17531                  stats, "stats");
17532 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
17533         TOKEN_NUM_INITIALIZER
17534                 (struct cmd_clear_vf_stats_result,
17535                  port_id, UINT16);
17536 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
17537         TOKEN_NUM_INITIALIZER
17538                 (struct cmd_clear_vf_stats_result,
17539                  vf_id, UINT16);
17540
17541 static void
17542 cmd_clear_vf_stats_parsed(
17543         void *parsed_result,
17544         __rte_unused struct cmdline *cl,
17545         __rte_unused void *data)
17546 {
17547         struct cmd_clear_vf_stats_result *res = parsed_result;
17548         int ret = -ENOTSUP;
17549
17550         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17551                 return;
17552
17553 #ifdef RTE_LIBRTE_I40E_PMD
17554         if (ret == -ENOTSUP)
17555                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
17556                                                   res->vf_id);
17557 #endif
17558 #ifdef RTE_LIBRTE_BNXT_PMD
17559         if (ret == -ENOTSUP)
17560                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
17561                                                   res->vf_id);
17562 #endif
17563
17564         switch (ret) {
17565         case 0:
17566                 break;
17567         case -EINVAL:
17568                 printf("invalid vf_id %d\n", res->vf_id);
17569                 break;
17570         case -ENODEV:
17571                 printf("invalid port_id %d\n", res->port_id);
17572                 break;
17573         case -ENOTSUP:
17574                 printf("function not implemented\n");
17575                 break;
17576         default:
17577                 printf("programming error: (%s)\n", strerror(-ret));
17578         }
17579 }
17580
17581 cmdline_parse_inst_t cmd_clear_vf_stats = {
17582         .f = cmd_clear_vf_stats_parsed,
17583         .data = NULL,
17584         .help_str = "clear vf stats <port_id> <vf_id>",
17585         .tokens = {
17586                 (void *)&cmd_clear_vf_stats_clear,
17587                 (void *)&cmd_clear_vf_stats_vf,
17588                 (void *)&cmd_clear_vf_stats_stats,
17589                 (void *)&cmd_clear_vf_stats_port_id,
17590                 (void *)&cmd_clear_vf_stats_vf_id,
17591                 NULL,
17592         },
17593 };
17594
17595 /* port config pctype mapping reset */
17596
17597 /* Common result structure for port config pctype mapping reset */
17598 struct cmd_pctype_mapping_reset_result {
17599         cmdline_fixed_string_t port;
17600         cmdline_fixed_string_t config;
17601         portid_t port_id;
17602         cmdline_fixed_string_t pctype;
17603         cmdline_fixed_string_t mapping;
17604         cmdline_fixed_string_t reset;
17605 };
17606
17607 /* Common CLI fields for port config pctype mapping reset*/
17608 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
17609         TOKEN_STRING_INITIALIZER
17610                 (struct cmd_pctype_mapping_reset_result,
17611                  port, "port");
17612 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
17613         TOKEN_STRING_INITIALIZER
17614                 (struct cmd_pctype_mapping_reset_result,
17615                  config, "config");
17616 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
17617         TOKEN_NUM_INITIALIZER
17618                 (struct cmd_pctype_mapping_reset_result,
17619                  port_id, UINT16);
17620 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
17621         TOKEN_STRING_INITIALIZER
17622                 (struct cmd_pctype_mapping_reset_result,
17623                  pctype, "pctype");
17624 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
17625         TOKEN_STRING_INITIALIZER
17626                 (struct cmd_pctype_mapping_reset_result,
17627                  mapping, "mapping");
17628 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
17629         TOKEN_STRING_INITIALIZER
17630                 (struct cmd_pctype_mapping_reset_result,
17631                  reset, "reset");
17632
17633 static void
17634 cmd_pctype_mapping_reset_parsed(
17635         void *parsed_result,
17636         __rte_unused struct cmdline *cl,
17637         __rte_unused void *data)
17638 {
17639         struct cmd_pctype_mapping_reset_result *res = parsed_result;
17640         int ret = -ENOTSUP;
17641
17642         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17643                 return;
17644
17645 #ifdef RTE_LIBRTE_I40E_PMD
17646         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
17647 #endif
17648
17649         switch (ret) {
17650         case 0:
17651                 break;
17652         case -ENODEV:
17653                 printf("invalid port_id %d\n", res->port_id);
17654                 break;
17655         case -ENOTSUP:
17656                 printf("function not implemented\n");
17657                 break;
17658         default:
17659                 printf("programming error: (%s)\n", strerror(-ret));
17660         }
17661 }
17662
17663 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
17664         .f = cmd_pctype_mapping_reset_parsed,
17665         .data = NULL,
17666         .help_str = "port config <port_id> pctype mapping reset",
17667         .tokens = {
17668                 (void *)&cmd_pctype_mapping_reset_port,
17669                 (void *)&cmd_pctype_mapping_reset_config,
17670                 (void *)&cmd_pctype_mapping_reset_port_id,
17671                 (void *)&cmd_pctype_mapping_reset_pctype,
17672                 (void *)&cmd_pctype_mapping_reset_mapping,
17673                 (void *)&cmd_pctype_mapping_reset_reset,
17674                 NULL,
17675         },
17676 };
17677
17678 /* show port pctype mapping */
17679
17680 /* Common result structure for show port pctype mapping */
17681 struct cmd_pctype_mapping_get_result {
17682         cmdline_fixed_string_t show;
17683         cmdline_fixed_string_t port;
17684         portid_t port_id;
17685         cmdline_fixed_string_t pctype;
17686         cmdline_fixed_string_t mapping;
17687 };
17688
17689 /* Common CLI fields for pctype mapping get */
17690 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
17691         TOKEN_STRING_INITIALIZER
17692                 (struct cmd_pctype_mapping_get_result,
17693                  show, "show");
17694 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
17695         TOKEN_STRING_INITIALIZER
17696                 (struct cmd_pctype_mapping_get_result,
17697                  port, "port");
17698 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
17699         TOKEN_NUM_INITIALIZER
17700                 (struct cmd_pctype_mapping_get_result,
17701                  port_id, UINT16);
17702 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
17703         TOKEN_STRING_INITIALIZER
17704                 (struct cmd_pctype_mapping_get_result,
17705                  pctype, "pctype");
17706 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
17707         TOKEN_STRING_INITIALIZER
17708                 (struct cmd_pctype_mapping_get_result,
17709                  mapping, "mapping");
17710
17711 static void
17712 cmd_pctype_mapping_get_parsed(
17713         void *parsed_result,
17714         __rte_unused struct cmdline *cl,
17715         __rte_unused void *data)
17716 {
17717         struct cmd_pctype_mapping_get_result *res = parsed_result;
17718         int ret = -ENOTSUP;
17719 #ifdef RTE_LIBRTE_I40E_PMD
17720         struct rte_pmd_i40e_flow_type_mapping
17721                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
17722         int i, j, first_pctype;
17723 #endif
17724
17725         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17726                 return;
17727
17728 #ifdef RTE_LIBRTE_I40E_PMD
17729         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
17730 #endif
17731
17732         switch (ret) {
17733         case 0:
17734                 break;
17735         case -ENODEV:
17736                 printf("invalid port_id %d\n", res->port_id);
17737                 return;
17738         case -ENOTSUP:
17739                 printf("function not implemented\n");
17740                 return;
17741         default:
17742                 printf("programming error: (%s)\n", strerror(-ret));
17743                 return;
17744         }
17745
17746 #ifdef RTE_LIBRTE_I40E_PMD
17747         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
17748                 if (mapping[i].pctype != 0ULL) {
17749                         first_pctype = 1;
17750
17751                         printf("pctype: ");
17752                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
17753                                 if (mapping[i].pctype & (1ULL << j)) {
17754                                         printf(first_pctype ?
17755                                                "%02d" : ",%02d", j);
17756                                         first_pctype = 0;
17757                                 }
17758                         }
17759                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
17760                 }
17761         }
17762 #endif
17763 }
17764
17765 cmdline_parse_inst_t cmd_pctype_mapping_get = {
17766         .f = cmd_pctype_mapping_get_parsed,
17767         .data = NULL,
17768         .help_str = "show port <port_id> pctype mapping",
17769         .tokens = {
17770                 (void *)&cmd_pctype_mapping_get_show,
17771                 (void *)&cmd_pctype_mapping_get_port,
17772                 (void *)&cmd_pctype_mapping_get_port_id,
17773                 (void *)&cmd_pctype_mapping_get_pctype,
17774                 (void *)&cmd_pctype_mapping_get_mapping,
17775                 NULL,
17776         },
17777 };
17778
17779 /* port config pctype mapping update */
17780
17781 /* Common result structure for port config pctype mapping update */
17782 struct cmd_pctype_mapping_update_result {
17783         cmdline_fixed_string_t port;
17784         cmdline_fixed_string_t config;
17785         portid_t port_id;
17786         cmdline_fixed_string_t pctype;
17787         cmdline_fixed_string_t mapping;
17788         cmdline_fixed_string_t update;
17789         cmdline_fixed_string_t pctype_list;
17790         uint16_t flow_type;
17791 };
17792
17793 /* Common CLI fields for pctype mapping update*/
17794 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
17795         TOKEN_STRING_INITIALIZER
17796                 (struct cmd_pctype_mapping_update_result,
17797                  port, "port");
17798 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
17799         TOKEN_STRING_INITIALIZER
17800                 (struct cmd_pctype_mapping_update_result,
17801                  config, "config");
17802 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
17803         TOKEN_NUM_INITIALIZER
17804                 (struct cmd_pctype_mapping_update_result,
17805                  port_id, UINT16);
17806 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
17807         TOKEN_STRING_INITIALIZER
17808                 (struct cmd_pctype_mapping_update_result,
17809                  pctype, "pctype");
17810 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
17811         TOKEN_STRING_INITIALIZER
17812                 (struct cmd_pctype_mapping_update_result,
17813                  mapping, "mapping");
17814 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
17815         TOKEN_STRING_INITIALIZER
17816                 (struct cmd_pctype_mapping_update_result,
17817                  update, "update");
17818 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
17819         TOKEN_STRING_INITIALIZER
17820                 (struct cmd_pctype_mapping_update_result,
17821                  pctype_list, NULL);
17822 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
17823         TOKEN_NUM_INITIALIZER
17824                 (struct cmd_pctype_mapping_update_result,
17825                  flow_type, UINT16);
17826
17827 static void
17828 cmd_pctype_mapping_update_parsed(
17829         void *parsed_result,
17830         __rte_unused struct cmdline *cl,
17831         __rte_unused void *data)
17832 {
17833         struct cmd_pctype_mapping_update_result *res = parsed_result;
17834         int ret = -ENOTSUP;
17835 #ifdef RTE_LIBRTE_I40E_PMD
17836         struct rte_pmd_i40e_flow_type_mapping mapping;
17837         unsigned int i;
17838         unsigned int nb_item;
17839         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
17840 #endif
17841
17842         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17843                 return;
17844
17845 #ifdef RTE_LIBRTE_I40E_PMD
17846         nb_item = parse_item_list(res->pctype_list, "pctypes",
17847                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
17848         mapping.flow_type = res->flow_type;
17849         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
17850                 mapping.pctype |= (1ULL << pctype_list[i]);
17851         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
17852                                                 &mapping,
17853                                                 1,
17854                                                 0);
17855 #endif
17856
17857         switch (ret) {
17858         case 0:
17859                 break;
17860         case -EINVAL:
17861                 printf("invalid pctype or flow type\n");
17862                 break;
17863         case -ENODEV:
17864                 printf("invalid port_id %d\n", res->port_id);
17865                 break;
17866         case -ENOTSUP:
17867                 printf("function not implemented\n");
17868                 break;
17869         default:
17870                 printf("programming error: (%s)\n", strerror(-ret));
17871         }
17872 }
17873
17874 cmdline_parse_inst_t cmd_pctype_mapping_update = {
17875         .f = cmd_pctype_mapping_update_parsed,
17876         .data = NULL,
17877         .help_str = "port config <port_id> pctype mapping update"
17878         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
17879         .tokens = {
17880                 (void *)&cmd_pctype_mapping_update_port,
17881                 (void *)&cmd_pctype_mapping_update_config,
17882                 (void *)&cmd_pctype_mapping_update_port_id,
17883                 (void *)&cmd_pctype_mapping_update_pctype,
17884                 (void *)&cmd_pctype_mapping_update_mapping,
17885                 (void *)&cmd_pctype_mapping_update_update,
17886                 (void *)&cmd_pctype_mapping_update_pc_type,
17887                 (void *)&cmd_pctype_mapping_update_flow_type,
17888                 NULL,
17889         },
17890 };
17891
17892 /* ptype mapping get */
17893
17894 /* Common result structure for ptype mapping get */
17895 struct cmd_ptype_mapping_get_result {
17896         cmdline_fixed_string_t ptype;
17897         cmdline_fixed_string_t mapping;
17898         cmdline_fixed_string_t get;
17899         portid_t port_id;
17900         uint8_t valid_only;
17901 };
17902
17903 /* Common CLI fields for ptype mapping get */
17904 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
17905         TOKEN_STRING_INITIALIZER
17906                 (struct cmd_ptype_mapping_get_result,
17907                  ptype, "ptype");
17908 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
17909         TOKEN_STRING_INITIALIZER
17910                 (struct cmd_ptype_mapping_get_result,
17911                  mapping, "mapping");
17912 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
17913         TOKEN_STRING_INITIALIZER
17914                 (struct cmd_ptype_mapping_get_result,
17915                  get, "get");
17916 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
17917         TOKEN_NUM_INITIALIZER
17918                 (struct cmd_ptype_mapping_get_result,
17919                  port_id, UINT16);
17920 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
17921         TOKEN_NUM_INITIALIZER
17922                 (struct cmd_ptype_mapping_get_result,
17923                  valid_only, UINT8);
17924
17925 static void
17926 cmd_ptype_mapping_get_parsed(
17927         void *parsed_result,
17928         __rte_unused struct cmdline *cl,
17929         __rte_unused void *data)
17930 {
17931         struct cmd_ptype_mapping_get_result *res = parsed_result;
17932         int ret = -ENOTSUP;
17933 #ifdef RTE_LIBRTE_I40E_PMD
17934         int max_ptype_num = 256;
17935         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
17936         uint16_t count;
17937         int i;
17938 #endif
17939
17940         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17941                 return;
17942
17943 #ifdef RTE_LIBRTE_I40E_PMD
17944         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
17945                                         mapping,
17946                                         max_ptype_num,
17947                                         &count,
17948                                         res->valid_only);
17949 #endif
17950
17951         switch (ret) {
17952         case 0:
17953                 break;
17954         case -ENODEV:
17955                 printf("invalid port_id %d\n", res->port_id);
17956                 break;
17957         case -ENOTSUP:
17958                 printf("function not implemented\n");
17959                 break;
17960         default:
17961                 printf("programming error: (%s)\n", strerror(-ret));
17962         }
17963
17964 #ifdef RTE_LIBRTE_I40E_PMD
17965         if (!ret) {
17966                 for (i = 0; i < count; i++)
17967                         printf("%3d\t0x%08x\n",
17968                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
17969         }
17970 #endif
17971 }
17972
17973 cmdline_parse_inst_t cmd_ptype_mapping_get = {
17974         .f = cmd_ptype_mapping_get_parsed,
17975         .data = NULL,
17976         .help_str = "ptype mapping get <port_id> <valid_only>",
17977         .tokens = {
17978                 (void *)&cmd_ptype_mapping_get_ptype,
17979                 (void *)&cmd_ptype_mapping_get_mapping,
17980                 (void *)&cmd_ptype_mapping_get_get,
17981                 (void *)&cmd_ptype_mapping_get_port_id,
17982                 (void *)&cmd_ptype_mapping_get_valid_only,
17983                 NULL,
17984         },
17985 };
17986
17987 /* ptype mapping replace */
17988
17989 /* Common result structure for ptype mapping replace */
17990 struct cmd_ptype_mapping_replace_result {
17991         cmdline_fixed_string_t ptype;
17992         cmdline_fixed_string_t mapping;
17993         cmdline_fixed_string_t replace;
17994         portid_t port_id;
17995         uint32_t target;
17996         uint8_t mask;
17997         uint32_t pkt_type;
17998 };
17999
18000 /* Common CLI fields for ptype mapping replace */
18001 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
18002         TOKEN_STRING_INITIALIZER
18003                 (struct cmd_ptype_mapping_replace_result,
18004                  ptype, "ptype");
18005 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
18006         TOKEN_STRING_INITIALIZER
18007                 (struct cmd_ptype_mapping_replace_result,
18008                  mapping, "mapping");
18009 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
18010         TOKEN_STRING_INITIALIZER
18011                 (struct cmd_ptype_mapping_replace_result,
18012                  replace, "replace");
18013 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
18014         TOKEN_NUM_INITIALIZER
18015                 (struct cmd_ptype_mapping_replace_result,
18016                  port_id, UINT16);
18017 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
18018         TOKEN_NUM_INITIALIZER
18019                 (struct cmd_ptype_mapping_replace_result,
18020                  target, UINT32);
18021 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
18022         TOKEN_NUM_INITIALIZER
18023                 (struct cmd_ptype_mapping_replace_result,
18024                  mask, UINT8);
18025 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
18026         TOKEN_NUM_INITIALIZER
18027                 (struct cmd_ptype_mapping_replace_result,
18028                  pkt_type, UINT32);
18029
18030 static void
18031 cmd_ptype_mapping_replace_parsed(
18032         void *parsed_result,
18033         __rte_unused struct cmdline *cl,
18034         __rte_unused void *data)
18035 {
18036         struct cmd_ptype_mapping_replace_result *res = parsed_result;
18037         int ret = -ENOTSUP;
18038
18039         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18040                 return;
18041
18042 #ifdef RTE_LIBRTE_I40E_PMD
18043         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
18044                                         res->target,
18045                                         res->mask,
18046                                         res->pkt_type);
18047 #endif
18048
18049         switch (ret) {
18050         case 0:
18051                 break;
18052         case -EINVAL:
18053                 printf("invalid ptype 0x%8x or 0x%8x\n",
18054                                 res->target, res->pkt_type);
18055                 break;
18056         case -ENODEV:
18057                 printf("invalid port_id %d\n", res->port_id);
18058                 break;
18059         case -ENOTSUP:
18060                 printf("function not implemented\n");
18061                 break;
18062         default:
18063                 printf("programming error: (%s)\n", strerror(-ret));
18064         }
18065 }
18066
18067 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
18068         .f = cmd_ptype_mapping_replace_parsed,
18069         .data = NULL,
18070         .help_str =
18071                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
18072         .tokens = {
18073                 (void *)&cmd_ptype_mapping_replace_ptype,
18074                 (void *)&cmd_ptype_mapping_replace_mapping,
18075                 (void *)&cmd_ptype_mapping_replace_replace,
18076                 (void *)&cmd_ptype_mapping_replace_port_id,
18077                 (void *)&cmd_ptype_mapping_replace_target,
18078                 (void *)&cmd_ptype_mapping_replace_mask,
18079                 (void *)&cmd_ptype_mapping_replace_pkt_type,
18080                 NULL,
18081         },
18082 };
18083
18084 /* ptype mapping reset */
18085
18086 /* Common result structure for ptype mapping reset */
18087 struct cmd_ptype_mapping_reset_result {
18088         cmdline_fixed_string_t ptype;
18089         cmdline_fixed_string_t mapping;
18090         cmdline_fixed_string_t reset;
18091         portid_t port_id;
18092 };
18093
18094 /* Common CLI fields for ptype mapping reset*/
18095 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
18096         TOKEN_STRING_INITIALIZER
18097                 (struct cmd_ptype_mapping_reset_result,
18098                  ptype, "ptype");
18099 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
18100         TOKEN_STRING_INITIALIZER
18101                 (struct cmd_ptype_mapping_reset_result,
18102                  mapping, "mapping");
18103 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
18104         TOKEN_STRING_INITIALIZER
18105                 (struct cmd_ptype_mapping_reset_result,
18106                  reset, "reset");
18107 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
18108         TOKEN_NUM_INITIALIZER
18109                 (struct cmd_ptype_mapping_reset_result,
18110                  port_id, UINT16);
18111
18112 static void
18113 cmd_ptype_mapping_reset_parsed(
18114         void *parsed_result,
18115         __rte_unused struct cmdline *cl,
18116         __rte_unused void *data)
18117 {
18118         struct cmd_ptype_mapping_reset_result *res = parsed_result;
18119         int ret = -ENOTSUP;
18120
18121         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18122                 return;
18123
18124 #ifdef RTE_LIBRTE_I40E_PMD
18125         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
18126 #endif
18127
18128         switch (ret) {
18129         case 0:
18130                 break;
18131         case -ENODEV:
18132                 printf("invalid port_id %d\n", res->port_id);
18133                 break;
18134         case -ENOTSUP:
18135                 printf("function not implemented\n");
18136                 break;
18137         default:
18138                 printf("programming error: (%s)\n", strerror(-ret));
18139         }
18140 }
18141
18142 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
18143         .f = cmd_ptype_mapping_reset_parsed,
18144         .data = NULL,
18145         .help_str = "ptype mapping reset <port_id>",
18146         .tokens = {
18147                 (void *)&cmd_ptype_mapping_reset_ptype,
18148                 (void *)&cmd_ptype_mapping_reset_mapping,
18149                 (void *)&cmd_ptype_mapping_reset_reset,
18150                 (void *)&cmd_ptype_mapping_reset_port_id,
18151                 NULL,
18152         },
18153 };
18154
18155 /* ptype mapping update */
18156
18157 /* Common result structure for ptype mapping update */
18158 struct cmd_ptype_mapping_update_result {
18159         cmdline_fixed_string_t ptype;
18160         cmdline_fixed_string_t mapping;
18161         cmdline_fixed_string_t reset;
18162         portid_t port_id;
18163         uint8_t hw_ptype;
18164         uint32_t sw_ptype;
18165 };
18166
18167 /* Common CLI fields for ptype mapping update*/
18168 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
18169         TOKEN_STRING_INITIALIZER
18170                 (struct cmd_ptype_mapping_update_result,
18171                  ptype, "ptype");
18172 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
18173         TOKEN_STRING_INITIALIZER
18174                 (struct cmd_ptype_mapping_update_result,
18175                  mapping, "mapping");
18176 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
18177         TOKEN_STRING_INITIALIZER
18178                 (struct cmd_ptype_mapping_update_result,
18179                  reset, "update");
18180 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
18181         TOKEN_NUM_INITIALIZER
18182                 (struct cmd_ptype_mapping_update_result,
18183                  port_id, UINT16);
18184 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
18185         TOKEN_NUM_INITIALIZER
18186                 (struct cmd_ptype_mapping_update_result,
18187                  hw_ptype, UINT8);
18188 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
18189         TOKEN_NUM_INITIALIZER
18190                 (struct cmd_ptype_mapping_update_result,
18191                  sw_ptype, UINT32);
18192
18193 static void
18194 cmd_ptype_mapping_update_parsed(
18195         void *parsed_result,
18196         __rte_unused struct cmdline *cl,
18197         __rte_unused void *data)
18198 {
18199         struct cmd_ptype_mapping_update_result *res = parsed_result;
18200         int ret = -ENOTSUP;
18201 #ifdef RTE_LIBRTE_I40E_PMD
18202         struct rte_pmd_i40e_ptype_mapping mapping;
18203 #endif
18204         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
18205                 return;
18206
18207 #ifdef RTE_LIBRTE_I40E_PMD
18208         mapping.hw_ptype = res->hw_ptype;
18209         mapping.sw_ptype = res->sw_ptype;
18210         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
18211                                                 &mapping,
18212                                                 1,
18213                                                 0);
18214 #endif
18215
18216         switch (ret) {
18217         case 0:
18218                 break;
18219         case -EINVAL:
18220                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
18221                 break;
18222         case -ENODEV:
18223                 printf("invalid port_id %d\n", res->port_id);
18224                 break;
18225         case -ENOTSUP:
18226                 printf("function not implemented\n");
18227                 break;
18228         default:
18229                 printf("programming error: (%s)\n", strerror(-ret));
18230         }
18231 }
18232
18233 cmdline_parse_inst_t cmd_ptype_mapping_update = {
18234         .f = cmd_ptype_mapping_update_parsed,
18235         .data = NULL,
18236         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
18237         .tokens = {
18238                 (void *)&cmd_ptype_mapping_update_ptype,
18239                 (void *)&cmd_ptype_mapping_update_mapping,
18240                 (void *)&cmd_ptype_mapping_update_update,
18241                 (void *)&cmd_ptype_mapping_update_port_id,
18242                 (void *)&cmd_ptype_mapping_update_hw_ptype,
18243                 (void *)&cmd_ptype_mapping_update_sw_ptype,
18244                 NULL,
18245         },
18246 };
18247
18248 /* Common result structure for file commands */
18249 struct cmd_cmdfile_result {
18250         cmdline_fixed_string_t load;
18251         cmdline_fixed_string_t filename;
18252 };
18253
18254 /* Common CLI fields for file commands */
18255 cmdline_parse_token_string_t cmd_load_cmdfile =
18256         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
18257 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
18258         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
18259
18260 static void
18261 cmd_load_from_file_parsed(
18262         void *parsed_result,
18263         __rte_unused struct cmdline *cl,
18264         __rte_unused void *data)
18265 {
18266         struct cmd_cmdfile_result *res = parsed_result;
18267
18268         cmdline_read_from_file(res->filename);
18269 }
18270
18271 cmdline_parse_inst_t cmd_load_from_file = {
18272         .f = cmd_load_from_file_parsed,
18273         .data = NULL,
18274         .help_str = "load <filename>",
18275         .tokens = {
18276                 (void *)&cmd_load_cmdfile,
18277                 (void *)&cmd_load_cmdfile_filename,
18278                 NULL,
18279         },
18280 };
18281
18282 /* Get Rx offloads capabilities */
18283 struct cmd_rx_offload_get_capa_result {
18284         cmdline_fixed_string_t show;
18285         cmdline_fixed_string_t port;
18286         portid_t port_id;
18287         cmdline_fixed_string_t rx_offload;
18288         cmdline_fixed_string_t capabilities;
18289 };
18290
18291 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
18292         TOKEN_STRING_INITIALIZER
18293                 (struct cmd_rx_offload_get_capa_result,
18294                  show, "show");
18295 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
18296         TOKEN_STRING_INITIALIZER
18297                 (struct cmd_rx_offload_get_capa_result,
18298                  port, "port");
18299 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
18300         TOKEN_NUM_INITIALIZER
18301                 (struct cmd_rx_offload_get_capa_result,
18302                  port_id, UINT16);
18303 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
18304         TOKEN_STRING_INITIALIZER
18305                 (struct cmd_rx_offload_get_capa_result,
18306                  rx_offload, "rx_offload");
18307 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
18308         TOKEN_STRING_INITIALIZER
18309                 (struct cmd_rx_offload_get_capa_result,
18310                  capabilities, "capabilities");
18311
18312 static void
18313 print_rx_offloads(uint64_t offloads)
18314 {
18315         uint64_t single_offload;
18316         int begin;
18317         int end;
18318         int bit;
18319
18320         if (offloads == 0)
18321                 return;
18322
18323         begin = __builtin_ctzll(offloads);
18324         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18325
18326         single_offload = 1ULL << begin;
18327         for (bit = begin; bit < end; bit++) {
18328                 if (offloads & single_offload)
18329                         printf(" %s",
18330                                rte_eth_dev_rx_offload_name(single_offload));
18331                 single_offload <<= 1;
18332         }
18333 }
18334
18335 static void
18336 cmd_rx_offload_get_capa_parsed(
18337         void *parsed_result,
18338         __rte_unused struct cmdline *cl,
18339         __rte_unused void *data)
18340 {
18341         struct cmd_rx_offload_get_capa_result *res = parsed_result;
18342         struct rte_eth_dev_info dev_info;
18343         portid_t port_id = res->port_id;
18344         uint64_t queue_offloads;
18345         uint64_t port_offloads;
18346         int ret;
18347
18348         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18349         if (ret != 0)
18350                 return;
18351
18352         queue_offloads = dev_info.rx_queue_offload_capa;
18353         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
18354
18355         printf("Rx Offloading Capabilities of port %d :\n", port_id);
18356         printf("  Per Queue :");
18357         print_rx_offloads(queue_offloads);
18358
18359         printf("\n");
18360         printf("  Per Port  :");
18361         print_rx_offloads(port_offloads);
18362         printf("\n\n");
18363 }
18364
18365 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
18366         .f = cmd_rx_offload_get_capa_parsed,
18367         .data = NULL,
18368         .help_str = "show port <port_id> rx_offload capabilities",
18369         .tokens = {
18370                 (void *)&cmd_rx_offload_get_capa_show,
18371                 (void *)&cmd_rx_offload_get_capa_port,
18372                 (void *)&cmd_rx_offload_get_capa_port_id,
18373                 (void *)&cmd_rx_offload_get_capa_rx_offload,
18374                 (void *)&cmd_rx_offload_get_capa_capabilities,
18375                 NULL,
18376         }
18377 };
18378
18379 /* Get Rx offloads configuration */
18380 struct cmd_rx_offload_get_configuration_result {
18381         cmdline_fixed_string_t show;
18382         cmdline_fixed_string_t port;
18383         portid_t port_id;
18384         cmdline_fixed_string_t rx_offload;
18385         cmdline_fixed_string_t configuration;
18386 };
18387
18388 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
18389         TOKEN_STRING_INITIALIZER
18390                 (struct cmd_rx_offload_get_configuration_result,
18391                  show, "show");
18392 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
18393         TOKEN_STRING_INITIALIZER
18394                 (struct cmd_rx_offload_get_configuration_result,
18395                  port, "port");
18396 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
18397         TOKEN_NUM_INITIALIZER
18398                 (struct cmd_rx_offload_get_configuration_result,
18399                  port_id, UINT16);
18400 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
18401         TOKEN_STRING_INITIALIZER
18402                 (struct cmd_rx_offload_get_configuration_result,
18403                  rx_offload, "rx_offload");
18404 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
18405         TOKEN_STRING_INITIALIZER
18406                 (struct cmd_rx_offload_get_configuration_result,
18407                  configuration, "configuration");
18408
18409 static void
18410 cmd_rx_offload_get_configuration_parsed(
18411         void *parsed_result,
18412         __rte_unused struct cmdline *cl,
18413         __rte_unused void *data)
18414 {
18415         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
18416         struct rte_eth_dev_info dev_info;
18417         portid_t port_id = res->port_id;
18418         struct rte_port *port = &ports[port_id];
18419         uint64_t port_offloads;
18420         uint64_t queue_offloads;
18421         uint16_t nb_rx_queues;
18422         int q;
18423         int ret;
18424
18425         printf("Rx Offloading Configuration of port %d :\n", port_id);
18426
18427         port_offloads = port->dev_conf.rxmode.offloads;
18428         printf("  Port :");
18429         print_rx_offloads(port_offloads);
18430         printf("\n");
18431
18432         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18433         if (ret != 0)
18434                 return;
18435
18436         nb_rx_queues = dev_info.nb_rx_queues;
18437         for (q = 0; q < nb_rx_queues; q++) {
18438                 queue_offloads = port->rx_conf[q].offloads;
18439                 printf("  Queue[%2d] :", q);
18440                 print_rx_offloads(queue_offloads);
18441                 printf("\n");
18442         }
18443         printf("\n");
18444 }
18445
18446 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
18447         .f = cmd_rx_offload_get_configuration_parsed,
18448         .data = NULL,
18449         .help_str = "show port <port_id> rx_offload configuration",
18450         .tokens = {
18451                 (void *)&cmd_rx_offload_get_configuration_show,
18452                 (void *)&cmd_rx_offload_get_configuration_port,
18453                 (void *)&cmd_rx_offload_get_configuration_port_id,
18454                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
18455                 (void *)&cmd_rx_offload_get_configuration_configuration,
18456                 NULL,
18457         }
18458 };
18459
18460 /* Enable/Disable a per port offloading */
18461 struct cmd_config_per_port_rx_offload_result {
18462         cmdline_fixed_string_t port;
18463         cmdline_fixed_string_t config;
18464         portid_t port_id;
18465         cmdline_fixed_string_t rx_offload;
18466         cmdline_fixed_string_t offload;
18467         cmdline_fixed_string_t on_off;
18468 };
18469
18470 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
18471         TOKEN_STRING_INITIALIZER
18472                 (struct cmd_config_per_port_rx_offload_result,
18473                  port, "port");
18474 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
18475         TOKEN_STRING_INITIALIZER
18476                 (struct cmd_config_per_port_rx_offload_result,
18477                  config, "config");
18478 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
18479         TOKEN_NUM_INITIALIZER
18480                 (struct cmd_config_per_port_rx_offload_result,
18481                  port_id, UINT16);
18482 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
18483         TOKEN_STRING_INITIALIZER
18484                 (struct cmd_config_per_port_rx_offload_result,
18485                  rx_offload, "rx_offload");
18486 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
18487         TOKEN_STRING_INITIALIZER
18488                 (struct cmd_config_per_port_rx_offload_result,
18489                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18490                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18491                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18492                            "scatter#buffer_split#timestamp#security#"
18493                            "keep_crc#rss_hash");
18494 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
18495         TOKEN_STRING_INITIALIZER
18496                 (struct cmd_config_per_port_rx_offload_result,
18497                  on_off, "on#off");
18498
18499 static uint64_t
18500 search_rx_offload(const char *name)
18501 {
18502         uint64_t single_offload;
18503         const char *single_name;
18504         int found = 0;
18505         unsigned int bit;
18506
18507         single_offload = 1;
18508         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18509                 single_name = rte_eth_dev_rx_offload_name(single_offload);
18510                 if (!strcasecmp(single_name, name)) {
18511                         found = 1;
18512                         break;
18513                 }
18514                 single_offload <<= 1;
18515         }
18516
18517         if (found)
18518                 return single_offload;
18519
18520         return 0;
18521 }
18522
18523 static void
18524 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
18525                                 __rte_unused struct cmdline *cl,
18526                                 __rte_unused void *data)
18527 {
18528         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
18529         portid_t port_id = res->port_id;
18530         struct rte_eth_dev_info dev_info;
18531         struct rte_port *port = &ports[port_id];
18532         uint64_t single_offload;
18533         uint16_t nb_rx_queues;
18534         int q;
18535         int ret;
18536
18537         if (port->port_status != RTE_PORT_STOPPED) {
18538                 printf("Error: Can't config offload when Port %d "
18539                        "is not stopped\n", port_id);
18540                 return;
18541         }
18542
18543         single_offload = search_rx_offload(res->offload);
18544         if (single_offload == 0) {
18545                 printf("Unknown offload name: %s\n", res->offload);
18546                 return;
18547         }
18548
18549         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18550         if (ret != 0)
18551                 return;
18552
18553         nb_rx_queues = dev_info.nb_rx_queues;
18554         if (!strcmp(res->on_off, "on")) {
18555                 port->dev_conf.rxmode.offloads |= single_offload;
18556                 for (q = 0; q < nb_rx_queues; q++)
18557                         port->rx_conf[q].offloads |= single_offload;
18558         } else {
18559                 port->dev_conf.rxmode.offloads &= ~single_offload;
18560                 for (q = 0; q < nb_rx_queues; q++)
18561                         port->rx_conf[q].offloads &= ~single_offload;
18562         }
18563
18564         cmd_reconfig_device_queue(port_id, 1, 1);
18565 }
18566
18567 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
18568         .f = cmd_config_per_port_rx_offload_parsed,
18569         .data = NULL,
18570         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
18571                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18572                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18573                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18574                     "keep_crc|rss_hash on|off",
18575         .tokens = {
18576                 (void *)&cmd_config_per_port_rx_offload_result_port,
18577                 (void *)&cmd_config_per_port_rx_offload_result_config,
18578                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
18579                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
18580                 (void *)&cmd_config_per_port_rx_offload_result_offload,
18581                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
18582                 NULL,
18583         }
18584 };
18585
18586 /* Enable/Disable a per queue offloading */
18587 struct cmd_config_per_queue_rx_offload_result {
18588         cmdline_fixed_string_t port;
18589         portid_t port_id;
18590         cmdline_fixed_string_t rxq;
18591         uint16_t queue_id;
18592         cmdline_fixed_string_t rx_offload;
18593         cmdline_fixed_string_t offload;
18594         cmdline_fixed_string_t on_off;
18595 };
18596
18597 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
18598         TOKEN_STRING_INITIALIZER
18599                 (struct cmd_config_per_queue_rx_offload_result,
18600                  port, "port");
18601 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
18602         TOKEN_NUM_INITIALIZER
18603                 (struct cmd_config_per_queue_rx_offload_result,
18604                  port_id, UINT16);
18605 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
18606         TOKEN_STRING_INITIALIZER
18607                 (struct cmd_config_per_queue_rx_offload_result,
18608                  rxq, "rxq");
18609 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
18610         TOKEN_NUM_INITIALIZER
18611                 (struct cmd_config_per_queue_rx_offload_result,
18612                  queue_id, UINT16);
18613 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
18614         TOKEN_STRING_INITIALIZER
18615                 (struct cmd_config_per_queue_rx_offload_result,
18616                  rx_offload, "rx_offload");
18617 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
18618         TOKEN_STRING_INITIALIZER
18619                 (struct cmd_config_per_queue_rx_offload_result,
18620                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
18621                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
18622                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
18623                            "scatter#buffer_split#timestamp#security#keep_crc");
18624 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
18625         TOKEN_STRING_INITIALIZER
18626                 (struct cmd_config_per_queue_rx_offload_result,
18627                  on_off, "on#off");
18628
18629 static void
18630 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
18631                                 __rte_unused struct cmdline *cl,
18632                                 __rte_unused void *data)
18633 {
18634         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
18635         struct rte_eth_dev_info dev_info;
18636         portid_t port_id = res->port_id;
18637         uint16_t queue_id = res->queue_id;
18638         struct rte_port *port = &ports[port_id];
18639         uint64_t single_offload;
18640         int ret;
18641
18642         if (port->port_status != RTE_PORT_STOPPED) {
18643                 printf("Error: Can't config offload when Port %d "
18644                        "is not stopped\n", port_id);
18645                 return;
18646         }
18647
18648         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18649         if (ret != 0)
18650                 return;
18651
18652         if (queue_id >= dev_info.nb_rx_queues) {
18653                 printf("Error: input queue_id should be 0 ... "
18654                        "%d\n", dev_info.nb_rx_queues - 1);
18655                 return;
18656         }
18657
18658         single_offload = search_rx_offload(res->offload);
18659         if (single_offload == 0) {
18660                 printf("Unknown offload name: %s\n", res->offload);
18661                 return;
18662         }
18663
18664         if (!strcmp(res->on_off, "on"))
18665                 port->rx_conf[queue_id].offloads |= single_offload;
18666         else
18667                 port->rx_conf[queue_id].offloads &= ~single_offload;
18668
18669         cmd_reconfig_device_queue(port_id, 1, 1);
18670 }
18671
18672 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
18673         .f = cmd_config_per_queue_rx_offload_parsed,
18674         .data = NULL,
18675         .help_str = "port <port_id> rxq <queue_id> rx_offload "
18676                     "vlan_strip|ipv4_cksum|"
18677                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
18678                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
18679                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
18680                     "keep_crc on|off",
18681         .tokens = {
18682                 (void *)&cmd_config_per_queue_rx_offload_result_port,
18683                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
18684                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
18685                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
18686                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
18687                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
18688                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
18689                 NULL,
18690         }
18691 };
18692
18693 /* Get Tx offloads capabilities */
18694 struct cmd_tx_offload_get_capa_result {
18695         cmdline_fixed_string_t show;
18696         cmdline_fixed_string_t port;
18697         portid_t port_id;
18698         cmdline_fixed_string_t tx_offload;
18699         cmdline_fixed_string_t capabilities;
18700 };
18701
18702 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
18703         TOKEN_STRING_INITIALIZER
18704                 (struct cmd_tx_offload_get_capa_result,
18705                  show, "show");
18706 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
18707         TOKEN_STRING_INITIALIZER
18708                 (struct cmd_tx_offload_get_capa_result,
18709                  port, "port");
18710 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
18711         TOKEN_NUM_INITIALIZER
18712                 (struct cmd_tx_offload_get_capa_result,
18713                  port_id, UINT16);
18714 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
18715         TOKEN_STRING_INITIALIZER
18716                 (struct cmd_tx_offload_get_capa_result,
18717                  tx_offload, "tx_offload");
18718 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
18719         TOKEN_STRING_INITIALIZER
18720                 (struct cmd_tx_offload_get_capa_result,
18721                  capabilities, "capabilities");
18722
18723 static void
18724 print_tx_offloads(uint64_t offloads)
18725 {
18726         uint64_t single_offload;
18727         int begin;
18728         int end;
18729         int bit;
18730
18731         if (offloads == 0)
18732                 return;
18733
18734         begin = __builtin_ctzll(offloads);
18735         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
18736
18737         single_offload = 1ULL << begin;
18738         for (bit = begin; bit < end; bit++) {
18739                 if (offloads & single_offload)
18740                         printf(" %s",
18741                                rte_eth_dev_tx_offload_name(single_offload));
18742                 single_offload <<= 1;
18743         }
18744 }
18745
18746 static void
18747 cmd_tx_offload_get_capa_parsed(
18748         void *parsed_result,
18749         __rte_unused struct cmdline *cl,
18750         __rte_unused void *data)
18751 {
18752         struct cmd_tx_offload_get_capa_result *res = parsed_result;
18753         struct rte_eth_dev_info dev_info;
18754         portid_t port_id = res->port_id;
18755         uint64_t queue_offloads;
18756         uint64_t port_offloads;
18757         int ret;
18758
18759         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18760         if (ret != 0)
18761                 return;
18762
18763         queue_offloads = dev_info.tx_queue_offload_capa;
18764         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
18765
18766         printf("Tx Offloading Capabilities of port %d :\n", port_id);
18767         printf("  Per Queue :");
18768         print_tx_offloads(queue_offloads);
18769
18770         printf("\n");
18771         printf("  Per Port  :");
18772         print_tx_offloads(port_offloads);
18773         printf("\n\n");
18774 }
18775
18776 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
18777         .f = cmd_tx_offload_get_capa_parsed,
18778         .data = NULL,
18779         .help_str = "show port <port_id> tx_offload capabilities",
18780         .tokens = {
18781                 (void *)&cmd_tx_offload_get_capa_show,
18782                 (void *)&cmd_tx_offload_get_capa_port,
18783                 (void *)&cmd_tx_offload_get_capa_port_id,
18784                 (void *)&cmd_tx_offload_get_capa_tx_offload,
18785                 (void *)&cmd_tx_offload_get_capa_capabilities,
18786                 NULL,
18787         }
18788 };
18789
18790 /* Get Tx offloads configuration */
18791 struct cmd_tx_offload_get_configuration_result {
18792         cmdline_fixed_string_t show;
18793         cmdline_fixed_string_t port;
18794         portid_t port_id;
18795         cmdline_fixed_string_t tx_offload;
18796         cmdline_fixed_string_t configuration;
18797 };
18798
18799 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
18800         TOKEN_STRING_INITIALIZER
18801                 (struct cmd_tx_offload_get_configuration_result,
18802                  show, "show");
18803 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
18804         TOKEN_STRING_INITIALIZER
18805                 (struct cmd_tx_offload_get_configuration_result,
18806                  port, "port");
18807 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
18808         TOKEN_NUM_INITIALIZER
18809                 (struct cmd_tx_offload_get_configuration_result,
18810                  port_id, UINT16);
18811 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
18812         TOKEN_STRING_INITIALIZER
18813                 (struct cmd_tx_offload_get_configuration_result,
18814                  tx_offload, "tx_offload");
18815 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
18816         TOKEN_STRING_INITIALIZER
18817                 (struct cmd_tx_offload_get_configuration_result,
18818                  configuration, "configuration");
18819
18820 static void
18821 cmd_tx_offload_get_configuration_parsed(
18822         void *parsed_result,
18823         __rte_unused struct cmdline *cl,
18824         __rte_unused void *data)
18825 {
18826         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
18827         struct rte_eth_dev_info dev_info;
18828         portid_t port_id = res->port_id;
18829         struct rte_port *port = &ports[port_id];
18830         uint64_t port_offloads;
18831         uint64_t queue_offloads;
18832         uint16_t nb_tx_queues;
18833         int q;
18834         int ret;
18835
18836         printf("Tx Offloading Configuration of port %d :\n", port_id);
18837
18838         port_offloads = port->dev_conf.txmode.offloads;
18839         printf("  Port :");
18840         print_tx_offloads(port_offloads);
18841         printf("\n");
18842
18843         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18844         if (ret != 0)
18845                 return;
18846
18847         nb_tx_queues = dev_info.nb_tx_queues;
18848         for (q = 0; q < nb_tx_queues; q++) {
18849                 queue_offloads = port->tx_conf[q].offloads;
18850                 printf("  Queue[%2d] :", q);
18851                 print_tx_offloads(queue_offloads);
18852                 printf("\n");
18853         }
18854         printf("\n");
18855 }
18856
18857 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
18858         .f = cmd_tx_offload_get_configuration_parsed,
18859         .data = NULL,
18860         .help_str = "show port <port_id> tx_offload configuration",
18861         .tokens = {
18862                 (void *)&cmd_tx_offload_get_configuration_show,
18863                 (void *)&cmd_tx_offload_get_configuration_port,
18864                 (void *)&cmd_tx_offload_get_configuration_port_id,
18865                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
18866                 (void *)&cmd_tx_offload_get_configuration_configuration,
18867                 NULL,
18868         }
18869 };
18870
18871 /* Enable/Disable a per port offloading */
18872 struct cmd_config_per_port_tx_offload_result {
18873         cmdline_fixed_string_t port;
18874         cmdline_fixed_string_t config;
18875         portid_t port_id;
18876         cmdline_fixed_string_t tx_offload;
18877         cmdline_fixed_string_t offload;
18878         cmdline_fixed_string_t on_off;
18879 };
18880
18881 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
18882         TOKEN_STRING_INITIALIZER
18883                 (struct cmd_config_per_port_tx_offload_result,
18884                  port, "port");
18885 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
18886         TOKEN_STRING_INITIALIZER
18887                 (struct cmd_config_per_port_tx_offload_result,
18888                  config, "config");
18889 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
18890         TOKEN_NUM_INITIALIZER
18891                 (struct cmd_config_per_port_tx_offload_result,
18892                  port_id, UINT16);
18893 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
18894         TOKEN_STRING_INITIALIZER
18895                 (struct cmd_config_per_port_tx_offload_result,
18896                  tx_offload, "tx_offload");
18897 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
18898         TOKEN_STRING_INITIALIZER
18899                 (struct cmd_config_per_port_tx_offload_result,
18900                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
18901                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
18902                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
18903                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
18904                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
18905                           "send_on_timestamp");
18906 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
18907         TOKEN_STRING_INITIALIZER
18908                 (struct cmd_config_per_port_tx_offload_result,
18909                  on_off, "on#off");
18910
18911 static uint64_t
18912 search_tx_offload(const char *name)
18913 {
18914         uint64_t single_offload;
18915         const char *single_name;
18916         int found = 0;
18917         unsigned int bit;
18918
18919         single_offload = 1;
18920         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
18921                 single_name = rte_eth_dev_tx_offload_name(single_offload);
18922                 if (single_name == NULL)
18923                         break;
18924                 if (!strcasecmp(single_name, name)) {
18925                         found = 1;
18926                         break;
18927                 } else if (!strcasecmp(single_name, "UNKNOWN"))
18928                         break;
18929                 single_offload <<= 1;
18930         }
18931
18932         if (found)
18933                 return single_offload;
18934
18935         return 0;
18936 }
18937
18938 static void
18939 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
18940                                 __rte_unused struct cmdline *cl,
18941                                 __rte_unused void *data)
18942 {
18943         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
18944         portid_t port_id = res->port_id;
18945         struct rte_eth_dev_info dev_info;
18946         struct rte_port *port = &ports[port_id];
18947         uint64_t single_offload;
18948         uint16_t nb_tx_queues;
18949         int q;
18950         int ret;
18951
18952         if (port->port_status != RTE_PORT_STOPPED) {
18953                 printf("Error: Can't config offload when Port %d "
18954                        "is not stopped\n", port_id);
18955                 return;
18956         }
18957
18958         single_offload = search_tx_offload(res->offload);
18959         if (single_offload == 0) {
18960                 printf("Unknown offload name: %s\n", res->offload);
18961                 return;
18962         }
18963
18964         ret = eth_dev_info_get_print_err(port_id, &dev_info);
18965         if (ret != 0)
18966                 return;
18967
18968         nb_tx_queues = dev_info.nb_tx_queues;
18969         if (!strcmp(res->on_off, "on")) {
18970                 port->dev_conf.txmode.offloads |= single_offload;
18971                 for (q = 0; q < nb_tx_queues; q++)
18972                         port->tx_conf[q].offloads |= single_offload;
18973         } else {
18974                 port->dev_conf.txmode.offloads &= ~single_offload;
18975                 for (q = 0; q < nb_tx_queues; q++)
18976                         port->tx_conf[q].offloads &= ~single_offload;
18977         }
18978
18979         cmd_reconfig_device_queue(port_id, 1, 1);
18980 }
18981
18982 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
18983         .f = cmd_config_per_port_tx_offload_parsed,
18984         .data = NULL,
18985         .help_str = "port config <port_id> tx_offload "
18986                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
18987                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
18988                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
18989                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
18990                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
18991                     "send_on_timestamp on|off",
18992         .tokens = {
18993                 (void *)&cmd_config_per_port_tx_offload_result_port,
18994                 (void *)&cmd_config_per_port_tx_offload_result_config,
18995                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
18996                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
18997                 (void *)&cmd_config_per_port_tx_offload_result_offload,
18998                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
18999                 NULL,
19000         }
19001 };
19002
19003 /* Enable/Disable a per queue offloading */
19004 struct cmd_config_per_queue_tx_offload_result {
19005         cmdline_fixed_string_t port;
19006         portid_t port_id;
19007         cmdline_fixed_string_t txq;
19008         uint16_t queue_id;
19009         cmdline_fixed_string_t tx_offload;
19010         cmdline_fixed_string_t offload;
19011         cmdline_fixed_string_t on_off;
19012 };
19013
19014 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
19015         TOKEN_STRING_INITIALIZER
19016                 (struct cmd_config_per_queue_tx_offload_result,
19017                  port, "port");
19018 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
19019         TOKEN_NUM_INITIALIZER
19020                 (struct cmd_config_per_queue_tx_offload_result,
19021                  port_id, UINT16);
19022 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
19023         TOKEN_STRING_INITIALIZER
19024                 (struct cmd_config_per_queue_tx_offload_result,
19025                  txq, "txq");
19026 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
19027         TOKEN_NUM_INITIALIZER
19028                 (struct cmd_config_per_queue_tx_offload_result,
19029                  queue_id, UINT16);
19030 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
19031         TOKEN_STRING_INITIALIZER
19032                 (struct cmd_config_per_queue_tx_offload_result,
19033                  tx_offload, "tx_offload");
19034 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
19035         TOKEN_STRING_INITIALIZER
19036                 (struct cmd_config_per_queue_tx_offload_result,
19037                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
19038                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
19039                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
19040                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
19041                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
19042 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
19043         TOKEN_STRING_INITIALIZER
19044                 (struct cmd_config_per_queue_tx_offload_result,
19045                  on_off, "on#off");
19046
19047 static void
19048 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
19049                                 __rte_unused struct cmdline *cl,
19050                                 __rte_unused void *data)
19051 {
19052         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
19053         struct rte_eth_dev_info dev_info;
19054         portid_t port_id = res->port_id;
19055         uint16_t queue_id = res->queue_id;
19056         struct rte_port *port = &ports[port_id];
19057         uint64_t single_offload;
19058         int ret;
19059
19060         if (port->port_status != RTE_PORT_STOPPED) {
19061                 printf("Error: Can't config offload when Port %d "
19062                        "is not stopped\n", port_id);
19063                 return;
19064         }
19065
19066         ret = eth_dev_info_get_print_err(port_id, &dev_info);
19067         if (ret != 0)
19068                 return;
19069
19070         if (queue_id >= dev_info.nb_tx_queues) {
19071                 printf("Error: input queue_id should be 0 ... "
19072                        "%d\n", dev_info.nb_tx_queues - 1);
19073                 return;
19074         }
19075
19076         single_offload = search_tx_offload(res->offload);
19077         if (single_offload == 0) {
19078                 printf("Unknown offload name: %s\n", res->offload);
19079                 return;
19080         }
19081
19082         if (!strcmp(res->on_off, "on"))
19083                 port->tx_conf[queue_id].offloads |= single_offload;
19084         else
19085                 port->tx_conf[queue_id].offloads &= ~single_offload;
19086
19087         cmd_reconfig_device_queue(port_id, 1, 1);
19088 }
19089
19090 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
19091         .f = cmd_config_per_queue_tx_offload_parsed,
19092         .data = NULL,
19093         .help_str = "port <port_id> txq <queue_id> tx_offload "
19094                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
19095                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
19096                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
19097                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
19098                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
19099                     "on|off",
19100         .tokens = {
19101                 (void *)&cmd_config_per_queue_tx_offload_result_port,
19102                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
19103                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
19104                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
19105                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
19106                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
19107                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
19108                 NULL,
19109         }
19110 };
19111
19112 /* *** configure tx_metadata for specific port *** */
19113 struct cmd_config_tx_metadata_specific_result {
19114         cmdline_fixed_string_t port;
19115         cmdline_fixed_string_t keyword;
19116         uint16_t port_id;
19117         cmdline_fixed_string_t item;
19118         uint32_t value;
19119 };
19120
19121 static void
19122 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
19123                                 __rte_unused struct cmdline *cl,
19124                                 __rte_unused void *data)
19125 {
19126         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
19127
19128         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19129                 return;
19130         ports[res->port_id].tx_metadata = res->value;
19131         /* Add/remove callback to insert valid metadata in every Tx packet. */
19132         if (ports[res->port_id].tx_metadata)
19133                 add_tx_md_callback(res->port_id);
19134         else
19135                 remove_tx_md_callback(res->port_id);
19136         rte_flow_dynf_metadata_register();
19137 }
19138
19139 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
19140         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19141                         port, "port");
19142 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
19143         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19144                         keyword, "config");
19145 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
19146         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19147                         port_id, UINT16);
19148 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
19149         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19150                         item, "tx_metadata");
19151 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
19152         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
19153                         value, UINT32);
19154
19155 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
19156         .f = cmd_config_tx_metadata_specific_parsed,
19157         .data = NULL,
19158         .help_str = "port config <port_id> tx_metadata <value>",
19159         .tokens = {
19160                 (void *)&cmd_config_tx_metadata_specific_port,
19161                 (void *)&cmd_config_tx_metadata_specific_keyword,
19162                 (void *)&cmd_config_tx_metadata_specific_id,
19163                 (void *)&cmd_config_tx_metadata_specific_item,
19164                 (void *)&cmd_config_tx_metadata_specific_value,
19165                 NULL,
19166         },
19167 };
19168
19169 /* *** set dynf *** */
19170 struct cmd_config_tx_dynf_specific_result {
19171         cmdline_fixed_string_t port;
19172         cmdline_fixed_string_t keyword;
19173         uint16_t port_id;
19174         cmdline_fixed_string_t item;
19175         cmdline_fixed_string_t name;
19176         cmdline_fixed_string_t value;
19177 };
19178
19179 static void
19180 cmd_config_dynf_specific_parsed(void *parsed_result,
19181                                 __rte_unused struct cmdline *cl,
19182                                 __rte_unused void *data)
19183 {
19184         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
19185         struct rte_mbuf_dynflag desc_flag;
19186         int flag;
19187         uint64_t old_port_flags;
19188
19189         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
19190                 return;
19191         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
19192         if (flag <= 0) {
19193                 if (strlcpy(desc_flag.name, res->name,
19194                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
19195                         printf("Flag name too long\n");
19196                         return;
19197                 }
19198                 desc_flag.flags = 0;
19199                 flag = rte_mbuf_dynflag_register(&desc_flag);
19200                 if (flag < 0) {
19201                         printf("Can't register flag\n");
19202                         return;
19203                 }
19204                 strcpy(dynf_names[flag], desc_flag.name);
19205         }
19206         old_port_flags = ports[res->port_id].mbuf_dynf;
19207         if (!strcmp(res->value, "set")) {
19208                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
19209                 if (old_port_flags == 0)
19210                         add_tx_dynf_callback(res->port_id);
19211         } else {
19212                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
19213                 if (ports[res->port_id].mbuf_dynf == 0)
19214                         remove_tx_dynf_callback(res->port_id);
19215         }
19216 }
19217
19218 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
19219         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19220                         keyword, "port");
19221 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
19222         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19223                         keyword, "config");
19224 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
19225         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19226                         port_id, UINT16);
19227 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
19228         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19229                         item, "dynf");
19230 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
19231         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19232                         name, NULL);
19233 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
19234         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
19235                         value, "set#clear");
19236
19237 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
19238         .f = cmd_config_dynf_specific_parsed,
19239         .data = NULL,
19240         .help_str = "port config <port id> dynf <name> set|clear",
19241         .tokens = {
19242                 (void *)&cmd_config_tx_dynf_specific_port,
19243                 (void *)&cmd_config_tx_dynf_specific_keyword,
19244                 (void *)&cmd_config_tx_dynf_specific_port_id,
19245                 (void *)&cmd_config_tx_dynf_specific_item,
19246                 (void *)&cmd_config_tx_dynf_specific_name,
19247                 (void *)&cmd_config_tx_dynf_specific_value,
19248                 NULL,
19249         },
19250 };
19251
19252 /* *** display tx_metadata per port configuration *** */
19253 struct cmd_show_tx_metadata_result {
19254         cmdline_fixed_string_t cmd_show;
19255         cmdline_fixed_string_t cmd_port;
19256         cmdline_fixed_string_t cmd_keyword;
19257         portid_t cmd_pid;
19258 };
19259
19260 static void
19261 cmd_show_tx_metadata_parsed(void *parsed_result,
19262                 __rte_unused struct cmdline *cl,
19263                 __rte_unused void *data)
19264 {
19265         struct cmd_show_tx_metadata_result *res = parsed_result;
19266
19267         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19268                 printf("invalid port id %u\n", res->cmd_pid);
19269                 return;
19270         }
19271         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
19272                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
19273                        ports[res->cmd_pid].tx_metadata);
19274         }
19275 }
19276
19277 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
19278         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19279                         cmd_show, "show");
19280 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
19281         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19282                         cmd_port, "port");
19283 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
19284         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
19285                         cmd_pid, UINT16);
19286 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
19287         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
19288                         cmd_keyword, "tx_metadata");
19289
19290 cmdline_parse_inst_t cmd_show_tx_metadata = {
19291         .f = cmd_show_tx_metadata_parsed,
19292         .data = NULL,
19293         .help_str = "show port <port_id> tx_metadata",
19294         .tokens = {
19295                 (void *)&cmd_show_tx_metadata_show,
19296                 (void *)&cmd_show_tx_metadata_port,
19297                 (void *)&cmd_show_tx_metadata_pid,
19298                 (void *)&cmd_show_tx_metadata_keyword,
19299                 NULL,
19300         },
19301 };
19302
19303 /* *** show fec capability per port configuration *** */
19304 struct cmd_show_fec_capability_result {
19305         cmdline_fixed_string_t cmd_show;
19306         cmdline_fixed_string_t cmd_port;
19307         cmdline_fixed_string_t cmd_fec;
19308         cmdline_fixed_string_t cmd_keyword;
19309         portid_t cmd_pid;
19310 };
19311
19312 static void
19313 cmd_show_fec_capability_parsed(void *parsed_result,
19314                 __rte_unused struct cmdline *cl,
19315                 __rte_unused void *data)
19316 {
19317 #define FEC_CAP_NUM 2
19318         struct cmd_show_fec_capability_result *res = parsed_result;
19319         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
19320         unsigned int num = FEC_CAP_NUM;
19321         unsigned int ret_num;
19322         int ret;
19323
19324         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19325                 printf("Invalid port id %u\n", res->cmd_pid);
19326                 return;
19327         }
19328
19329         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
19330         if (ret == -ENOTSUP) {
19331                 printf("Function not implemented\n");
19332                 return;
19333         } else if (ret < 0) {
19334                 printf("Get FEC capability failed\n");
19335                 return;
19336         }
19337
19338         ret_num = (unsigned int)ret;
19339         show_fec_capability(ret_num, speed_fec_capa);
19340 }
19341
19342 cmdline_parse_token_string_t cmd_show_fec_capability_show =
19343         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19344                         cmd_show, "show");
19345 cmdline_parse_token_string_t cmd_show_fec_capability_port =
19346         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19347                         cmd_port, "port");
19348 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
19349         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
19350                         cmd_pid, UINT16);
19351 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
19352         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19353                         cmd_fec, "fec");
19354 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
19355         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
19356                         cmd_keyword, "capabilities");
19357
19358 cmdline_parse_inst_t cmd_show_capability = {
19359         .f = cmd_show_fec_capability_parsed,
19360         .data = NULL,
19361         .help_str = "show port <port_id> fec capabilities",
19362         .tokens = {
19363                 (void *)&cmd_show_fec_capability_show,
19364                 (void *)&cmd_show_fec_capability_port,
19365                 (void *)&cmd_show_fec_capability_pid,
19366                 (void *)&cmd_show_fec_capability_fec,
19367                 (void *)&cmd_show_fec_capability_keyword,
19368                 NULL,
19369         },
19370 };
19371
19372 /* *** show fec mode per port configuration *** */
19373 struct cmd_show_fec_metadata_result {
19374         cmdline_fixed_string_t cmd_show;
19375         cmdline_fixed_string_t cmd_port;
19376         cmdline_fixed_string_t cmd_keyword;
19377         portid_t cmd_pid;
19378 };
19379
19380 static void
19381 cmd_show_fec_mode_parsed(void *parsed_result,
19382                 __rte_unused struct cmdline *cl,
19383                 __rte_unused void *data)
19384 {
19385 #define FEC_NAME_SIZE 16
19386         struct cmd_show_fec_metadata_result *res = parsed_result;
19387         uint32_t mode;
19388         char buf[FEC_NAME_SIZE];
19389         int ret;
19390
19391         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19392                 printf("Invalid port id %u\n", res->cmd_pid);
19393                 return;
19394         }
19395         ret = rte_eth_fec_get(res->cmd_pid, &mode);
19396         if (ret == -ENOTSUP) {
19397                 printf("Function not implemented\n");
19398                 return;
19399         } else if (ret < 0) {
19400                 printf("Get FEC mode failed\n");
19401                 return;
19402         }
19403
19404         switch (mode) {
19405         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
19406                 strlcpy(buf, "off", sizeof(buf));
19407                 break;
19408         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
19409                 strlcpy(buf, "auto", sizeof(buf));
19410                 break;
19411         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
19412                 strlcpy(buf, "baser", sizeof(buf));
19413                 break;
19414         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
19415                 strlcpy(buf, "rs", sizeof(buf));
19416                 break;
19417         default:
19418                 return;
19419         }
19420
19421         printf("%s\n", buf);
19422 }
19423
19424 cmdline_parse_token_string_t cmd_show_fec_mode_show =
19425         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19426                         cmd_show, "show");
19427 cmdline_parse_token_string_t cmd_show_fec_mode_port =
19428         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19429                         cmd_port, "port");
19430 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
19431         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
19432                         cmd_pid, UINT16);
19433 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
19434         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
19435                         cmd_keyword, "fec_mode");
19436
19437 cmdline_parse_inst_t cmd_show_fec_mode = {
19438         .f = cmd_show_fec_mode_parsed,
19439         .data = NULL,
19440         .help_str = "show port <port_id> fec_mode",
19441         .tokens = {
19442                 (void *)&cmd_show_fec_mode_show,
19443                 (void *)&cmd_show_fec_mode_port,
19444                 (void *)&cmd_show_fec_mode_pid,
19445                 (void *)&cmd_show_fec_mode_keyword,
19446                 NULL,
19447         },
19448 };
19449
19450 /* *** set fec mode per port configuration *** */
19451 struct cmd_set_port_fec_mode {
19452         cmdline_fixed_string_t set;
19453         cmdline_fixed_string_t port;
19454         portid_t port_id;
19455         cmdline_fixed_string_t fec_mode;
19456         cmdline_fixed_string_t fec_value;
19457 };
19458
19459 /* Common CLI fields for set fec mode */
19460 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
19461         TOKEN_STRING_INITIALIZER
19462                 (struct cmd_set_port_fec_mode,
19463                  set, "set");
19464 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
19465         TOKEN_STRING_INITIALIZER
19466                 (struct cmd_set_port_fec_mode,
19467                  port, "port");
19468 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
19469         TOKEN_NUM_INITIALIZER
19470                 (struct cmd_set_port_fec_mode,
19471                  port_id, UINT16);
19472 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
19473         TOKEN_STRING_INITIALIZER
19474                 (struct cmd_set_port_fec_mode,
19475                  fec_mode, "fec_mode");
19476 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
19477         TOKEN_STRING_INITIALIZER
19478                 (struct cmd_set_port_fec_mode,
19479                  fec_value, NULL);
19480
19481 static void
19482 cmd_set_port_fec_mode_parsed(
19483         void *parsed_result,
19484         __rte_unused struct cmdline *cl,
19485         __rte_unused void *data)
19486 {
19487         struct cmd_set_port_fec_mode *res = parsed_result;
19488         uint16_t port_id = res->port_id;
19489         uint32_t mode;
19490         int ret;
19491
19492         ret = parse_fec_mode(res->fec_value, &mode);
19493         if (ret < 0) {
19494                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
19495                         port_id);
19496                 return;
19497         }
19498
19499         ret = rte_eth_fec_set(port_id, mode);
19500         if (ret == -ENOTSUP) {
19501                 printf("Function not implemented\n");
19502                 return;
19503         } else if (ret < 0) {
19504                 printf("Set FEC mode failed\n");
19505                 return;
19506         }
19507 }
19508
19509 cmdline_parse_inst_t cmd_set_fec_mode = {
19510         .f = cmd_set_port_fec_mode_parsed,
19511         .data = NULL,
19512         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
19513         .tokens = {
19514                 (void *)&cmd_set_port_fec_mode_set,
19515                 (void *)&cmd_set_port_fec_mode_port,
19516                 (void *)&cmd_set_port_fec_mode_port_id,
19517                 (void *)&cmd_set_port_fec_mode_str,
19518                 (void *)&cmd_set_port_fec_mode_value,
19519                 NULL,
19520         },
19521 };
19522
19523 /* show port supported ptypes */
19524
19525 /* Common result structure for show port ptypes */
19526 struct cmd_show_port_supported_ptypes_result {
19527         cmdline_fixed_string_t show;
19528         cmdline_fixed_string_t port;
19529         portid_t port_id;
19530         cmdline_fixed_string_t ptypes;
19531 };
19532
19533 /* Common CLI fields for show port ptypes */
19534 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
19535         TOKEN_STRING_INITIALIZER
19536                 (struct cmd_show_port_supported_ptypes_result,
19537                  show, "show");
19538 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
19539         TOKEN_STRING_INITIALIZER
19540                 (struct cmd_show_port_supported_ptypes_result,
19541                  port, "port");
19542 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
19543         TOKEN_NUM_INITIALIZER
19544                 (struct cmd_show_port_supported_ptypes_result,
19545                  port_id, UINT16);
19546 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
19547         TOKEN_STRING_INITIALIZER
19548                 (struct cmd_show_port_supported_ptypes_result,
19549                  ptypes, "ptypes");
19550
19551 static void
19552 cmd_show_port_supported_ptypes_parsed(
19553         void *parsed_result,
19554         __rte_unused struct cmdline *cl,
19555         __rte_unused void *data)
19556 {
19557 #define RSVD_PTYPE_MASK       0xf0000000
19558 #define MAX_PTYPES_PER_LAYER  16
19559 #define LTYPE_NAMESIZE        32
19560 #define PTYPE_NAMESIZE        256
19561         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
19562         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
19563         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
19564         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
19565         uint16_t port_id = res->port_id;
19566         int ret, i;
19567
19568         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
19569         if (ret < 0)
19570                 return;
19571
19572         while (ptype_mask != RSVD_PTYPE_MASK) {
19573
19574                 switch (ptype_mask) {
19575                 case RTE_PTYPE_L2_MASK:
19576                         strlcpy(ltype, "L2", sizeof(ltype));
19577                         break;
19578                 case RTE_PTYPE_L3_MASK:
19579                         strlcpy(ltype, "L3", sizeof(ltype));
19580                         break;
19581                 case RTE_PTYPE_L4_MASK:
19582                         strlcpy(ltype, "L4", sizeof(ltype));
19583                         break;
19584                 case RTE_PTYPE_TUNNEL_MASK:
19585                         strlcpy(ltype, "Tunnel", sizeof(ltype));
19586                         break;
19587                 case RTE_PTYPE_INNER_L2_MASK:
19588                         strlcpy(ltype, "Inner L2", sizeof(ltype));
19589                         break;
19590                 case RTE_PTYPE_INNER_L3_MASK:
19591                         strlcpy(ltype, "Inner L3", sizeof(ltype));
19592                         break;
19593                 case RTE_PTYPE_INNER_L4_MASK:
19594                         strlcpy(ltype, "Inner L4", sizeof(ltype));
19595                         break;
19596                 default:
19597                         return;
19598                 }
19599
19600                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
19601                                                        ptype_mask, ptypes,
19602                                                        MAX_PTYPES_PER_LAYER);
19603
19604                 if (ret > 0)
19605                         printf("Supported %s ptypes:\n", ltype);
19606                 else
19607                         printf("%s ptypes unsupported\n", ltype);
19608
19609                 for (i = 0; i < ret; ++i) {
19610                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
19611                         printf("%s\n", buf);
19612                 }
19613
19614                 ptype_mask <<= 4;
19615         }
19616 }
19617
19618 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
19619         .f = cmd_show_port_supported_ptypes_parsed,
19620         .data = NULL,
19621         .help_str = "show port <port_id> ptypes",
19622         .tokens = {
19623                 (void *)&cmd_show_port_supported_ptypes_show,
19624                 (void *)&cmd_show_port_supported_ptypes_port,
19625                 (void *)&cmd_show_port_supported_ptypes_port_id,
19626                 (void *)&cmd_show_port_supported_ptypes_ptypes,
19627                 NULL,
19628         },
19629 };
19630
19631 /* *** display rx/tx descriptor status *** */
19632 struct cmd_show_rx_tx_desc_status_result {
19633         cmdline_fixed_string_t cmd_show;
19634         cmdline_fixed_string_t cmd_port;
19635         cmdline_fixed_string_t cmd_keyword;
19636         cmdline_fixed_string_t cmd_desc;
19637         cmdline_fixed_string_t cmd_status;
19638         portid_t cmd_pid;
19639         portid_t cmd_qid;
19640         portid_t cmd_did;
19641 };
19642
19643 static void
19644 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
19645                 __rte_unused struct cmdline *cl,
19646                 __rte_unused void *data)
19647 {
19648         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
19649         int rc;
19650
19651         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
19652                 printf("invalid port id %u\n", res->cmd_pid);
19653                 return;
19654         }
19655
19656         if (!strcmp(res->cmd_keyword, "rxq")) {
19657                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
19658                                              res->cmd_did);
19659                 if (rc < 0) {
19660                         printf("Invalid queueid = %d\n", res->cmd_qid);
19661                         return;
19662                 }
19663                 if (rc == RTE_ETH_RX_DESC_AVAIL)
19664                         printf("Desc status = AVAILABLE\n");
19665                 else if (rc == RTE_ETH_RX_DESC_DONE)
19666                         printf("Desc status = DONE\n");
19667                 else
19668                         printf("Desc status = UNAVAILABLE\n");
19669         } else if (!strcmp(res->cmd_keyword, "txq")) {
19670                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
19671                                              res->cmd_did);
19672                 if (rc < 0) {
19673                         printf("Invalid queueid = %d\n", res->cmd_qid);
19674                         return;
19675                 }
19676                 if (rc == RTE_ETH_TX_DESC_FULL)
19677                         printf("Desc status = FULL\n");
19678                 else if (rc == RTE_ETH_TX_DESC_DONE)
19679                         printf("Desc status = DONE\n");
19680                 else
19681                         printf("Desc status = UNAVAILABLE\n");
19682         }
19683 }
19684
19685 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
19686         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19687                         cmd_show, "show");
19688 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
19689         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19690                         cmd_port, "port");
19691 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
19692         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19693                         cmd_pid, UINT16);
19694 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
19695         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19696                         cmd_keyword, "rxq#txq");
19697 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
19698         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19699                         cmd_qid, UINT16);
19700 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
19701         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19702                         cmd_desc, "desc");
19703 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
19704         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19705                         cmd_did, UINT16);
19706 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
19707         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
19708                         cmd_status, "status");
19709 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
19710         .f = cmd_show_rx_tx_desc_status_parsed,
19711         .data = NULL,
19712         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
19713                 "status",
19714         .tokens = {
19715                 (void *)&cmd_show_rx_tx_desc_status_show,
19716                 (void *)&cmd_show_rx_tx_desc_status_port,
19717                 (void *)&cmd_show_rx_tx_desc_status_pid,
19718                 (void *)&cmd_show_rx_tx_desc_status_keyword,
19719                 (void *)&cmd_show_rx_tx_desc_status_qid,
19720                 (void *)&cmd_show_rx_tx_desc_status_desc,
19721                 (void *)&cmd_show_rx_tx_desc_status_did,
19722                 (void *)&cmd_show_rx_tx_desc_status_status,
19723                 NULL,
19724         },
19725 };
19726
19727 /* Common result structure for set port ptypes */
19728 struct cmd_set_port_ptypes_result {
19729         cmdline_fixed_string_t set;
19730         cmdline_fixed_string_t port;
19731         portid_t port_id;
19732         cmdline_fixed_string_t ptype_mask;
19733         uint32_t mask;
19734 };
19735
19736 /* Common CLI fields for set port ptypes */
19737 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
19738         TOKEN_STRING_INITIALIZER
19739                 (struct cmd_set_port_ptypes_result,
19740                  set, "set");
19741 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
19742         TOKEN_STRING_INITIALIZER
19743                 (struct cmd_set_port_ptypes_result,
19744                  port, "port");
19745 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
19746         TOKEN_NUM_INITIALIZER
19747                 (struct cmd_set_port_ptypes_result,
19748                  port_id, UINT16);
19749 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
19750         TOKEN_STRING_INITIALIZER
19751                 (struct cmd_set_port_ptypes_result,
19752                  ptype_mask, "ptype_mask");
19753 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
19754         TOKEN_NUM_INITIALIZER
19755                 (struct cmd_set_port_ptypes_result,
19756                  mask, UINT32);
19757
19758 static void
19759 cmd_set_port_ptypes_parsed(
19760         void *parsed_result,
19761         __rte_unused struct cmdline *cl,
19762         __rte_unused void *data)
19763 {
19764         struct cmd_set_port_ptypes_result *res = parsed_result;
19765 #define PTYPE_NAMESIZE        256
19766         char ptype_name[PTYPE_NAMESIZE];
19767         uint16_t port_id = res->port_id;
19768         uint32_t ptype_mask = res->mask;
19769         int ret, i;
19770
19771         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
19772                                                NULL, 0);
19773         if (ret <= 0) {
19774                 printf("Port %d doesn't support any ptypes.\n", port_id);
19775                 return;
19776         }
19777
19778         uint32_t ptypes[ret];
19779
19780         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
19781         if (ret < 0) {
19782                 printf("Unable to set requested ptypes for Port %d\n", port_id);
19783                 return;
19784         }
19785
19786         printf("Successfully set following ptypes for Port %d\n", port_id);
19787         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
19788                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
19789                 printf("%s\n", ptype_name);
19790         }
19791
19792         clear_ptypes = false;
19793 }
19794
19795 cmdline_parse_inst_t cmd_set_port_ptypes = {
19796         .f = cmd_set_port_ptypes_parsed,
19797         .data = NULL,
19798         .help_str = "set port <port_id> ptype_mask <mask>",
19799         .tokens = {
19800                 (void *)&cmd_set_port_ptypes_set,
19801                 (void *)&cmd_set_port_ptypes_port,
19802                 (void *)&cmd_set_port_ptypes_port_id,
19803                 (void *)&cmd_set_port_ptypes_mask_str,
19804                 (void *)&cmd_set_port_ptypes_mask_u32,
19805                 NULL,
19806         },
19807 };
19808
19809 /* *** display mac addresses added to a port *** */
19810 struct cmd_showport_macs_result {
19811         cmdline_fixed_string_t cmd_show;
19812         cmdline_fixed_string_t cmd_port;
19813         cmdline_fixed_string_t cmd_keyword;
19814         portid_t cmd_pid;
19815 };
19816
19817 static void
19818 cmd_showport_macs_parsed(void *parsed_result,
19819                 __rte_unused struct cmdline *cl,
19820                 __rte_unused void *data)
19821 {
19822         struct cmd_showport_macs_result *res = parsed_result;
19823
19824         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
19825                 return;
19826
19827         if (!strcmp(res->cmd_keyword, "macs"))
19828                 show_macs(res->cmd_pid);
19829         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
19830                 show_mcast_macs(res->cmd_pid);
19831 }
19832
19833 cmdline_parse_token_string_t cmd_showport_macs_show =
19834         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19835                         cmd_show, "show");
19836 cmdline_parse_token_string_t cmd_showport_macs_port =
19837         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19838                         cmd_port, "port");
19839 cmdline_parse_token_num_t cmd_showport_macs_pid =
19840         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
19841                         cmd_pid, UINT16);
19842 cmdline_parse_token_string_t cmd_showport_macs_keyword =
19843         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
19844                         cmd_keyword, "macs#mcast_macs");
19845
19846 cmdline_parse_inst_t cmd_showport_macs = {
19847         .f = cmd_showport_macs_parsed,
19848         .data = NULL,
19849         .help_str = "show port <port_id> macs|mcast_macs",
19850         .tokens = {
19851                 (void *)&cmd_showport_macs_show,
19852                 (void *)&cmd_showport_macs_port,
19853                 (void *)&cmd_showport_macs_pid,
19854                 (void *)&cmd_showport_macs_keyword,
19855                 NULL,
19856         },
19857 };
19858
19859 /* ******************************************************************************** */
19860
19861 /* list of instructions */
19862 cmdline_parse_ctx_t main_ctx[] = {
19863         (cmdline_parse_inst_t *)&cmd_help_brief,
19864         (cmdline_parse_inst_t *)&cmd_help_long,
19865         (cmdline_parse_inst_t *)&cmd_quit,
19866         (cmdline_parse_inst_t *)&cmd_load_from_file,
19867         (cmdline_parse_inst_t *)&cmd_showport,
19868         (cmdline_parse_inst_t *)&cmd_showqueue,
19869         (cmdline_parse_inst_t *)&cmd_showeeprom,
19870         (cmdline_parse_inst_t *)&cmd_showportall,
19871         (cmdline_parse_inst_t *)&cmd_showdevice,
19872         (cmdline_parse_inst_t *)&cmd_showcfg,
19873         (cmdline_parse_inst_t *)&cmd_showfwdall,
19874         (cmdline_parse_inst_t *)&cmd_start,
19875         (cmdline_parse_inst_t *)&cmd_start_tx_first,
19876         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
19877         (cmdline_parse_inst_t *)&cmd_set_link_up,
19878         (cmdline_parse_inst_t *)&cmd_set_link_down,
19879         (cmdline_parse_inst_t *)&cmd_reset,
19880         (cmdline_parse_inst_t *)&cmd_set_numbers,
19881         (cmdline_parse_inst_t *)&cmd_set_log,
19882         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
19883         (cmdline_parse_inst_t *)&cmd_set_txpkts,
19884         (cmdline_parse_inst_t *)&cmd_set_txsplit,
19885         (cmdline_parse_inst_t *)&cmd_set_txtimes,
19886         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
19887         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
19888         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
19889         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
19890         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
19891         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
19892         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
19893         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
19894         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
19895         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
19896         (cmdline_parse_inst_t *)&cmd_set_link_check,
19897         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
19898         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
19899         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
19900         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
19901 #ifdef RTE_LIBRTE_PMD_BOND
19902         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
19903         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
19904         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
19905         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
19906         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
19907         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
19908         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
19909         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
19910         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
19911         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
19912         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
19913 #endif
19914         (cmdline_parse_inst_t *)&cmd_vlan_offload,
19915         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
19916         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
19917         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
19918         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
19919         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
19920         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
19921         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
19922         (cmdline_parse_inst_t *)&cmd_csum_set,
19923         (cmdline_parse_inst_t *)&cmd_csum_show,
19924         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
19925         (cmdline_parse_inst_t *)&cmd_tso_set,
19926         (cmdline_parse_inst_t *)&cmd_tso_show,
19927         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
19928         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
19929         (cmdline_parse_inst_t *)&cmd_gro_enable,
19930         (cmdline_parse_inst_t *)&cmd_gro_flush,
19931         (cmdline_parse_inst_t *)&cmd_gro_show,
19932         (cmdline_parse_inst_t *)&cmd_gso_enable,
19933         (cmdline_parse_inst_t *)&cmd_gso_size,
19934         (cmdline_parse_inst_t *)&cmd_gso_show,
19935         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
19936         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
19937         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
19938         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
19939         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
19940         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
19941         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
19942         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
19943         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
19944         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
19945         (cmdline_parse_inst_t *)&cmd_config_dcb,
19946         (cmdline_parse_inst_t *)&cmd_read_reg,
19947         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
19948         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
19949         (cmdline_parse_inst_t *)&cmd_write_reg,
19950         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
19951         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
19952         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
19953         (cmdline_parse_inst_t *)&cmd_stop,
19954         (cmdline_parse_inst_t *)&cmd_mac_addr,
19955         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
19956         (cmdline_parse_inst_t *)&cmd_set_qmap,
19957         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
19958         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
19959         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
19960         (cmdline_parse_inst_t *)&cmd_operate_port,
19961         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
19962         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
19963         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
19964         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
19965         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
19966         (cmdline_parse_inst_t *)&cmd_config_speed_all,
19967         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
19968         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
19969         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
19970         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
19971         (cmdline_parse_inst_t *)&cmd_config_mtu,
19972         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
19973         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
19974         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
19975         (cmdline_parse_inst_t *)&cmd_config_rss,
19976         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
19977         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
19978         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
19979         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
19980         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
19981         (cmdline_parse_inst_t *)&cmd_showport_reta,
19982         (cmdline_parse_inst_t *)&cmd_showport_macs,
19983         (cmdline_parse_inst_t *)&cmd_config_burst,
19984         (cmdline_parse_inst_t *)&cmd_config_thresh,
19985         (cmdline_parse_inst_t *)&cmd_config_threshold,
19986         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
19987         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
19988         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
19989         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
19990         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
19991         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
19992         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
19993         (cmdline_parse_inst_t *)&cmd_global_config,
19994         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
19995         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
19996         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
19997         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
19998         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
19999         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
20000         (cmdline_parse_inst_t *)&cmd_dump,
20001         (cmdline_parse_inst_t *)&cmd_dump_one,
20002         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
20003         (cmdline_parse_inst_t *)&cmd_syn_filter,
20004         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
20005         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
20006         (cmdline_parse_inst_t *)&cmd_flex_filter,
20007         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
20008         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
20009         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
20010         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
20011         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
20012         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
20013         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
20014         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
20015         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
20016         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
20017         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
20018         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
20019         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
20020         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
20021         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
20022         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
20023         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
20024         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
20025         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
20026         (cmdline_parse_inst_t *)&cmd_flow,
20027         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
20028         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
20029         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
20030         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
20031         (cmdline_parse_inst_t *)&cmd_create_port_meter,
20032         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
20033         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
20034         (cmdline_parse_inst_t *)&cmd_del_port_meter,
20035         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
20036         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
20037         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
20038         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
20039         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
20040         (cmdline_parse_inst_t *)&cmd_mcast_addr,
20041         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
20042         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
20043         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
20044         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
20045         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
20046         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
20047         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
20048         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
20049         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
20050         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
20051         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
20052         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
20053         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
20054         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
20055         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
20056         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
20057         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
20058         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
20059         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
20060         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
20061         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
20062         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
20063         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
20064         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
20065         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
20066         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
20067         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
20068         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
20069         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
20070         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
20071         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
20072         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
20073         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
20074         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
20075         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
20076         (cmdline_parse_inst_t *)&cmd_set_vxlan,
20077         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
20078         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
20079         (cmdline_parse_inst_t *)&cmd_set_nvgre,
20080         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
20081         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
20082         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
20083         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
20084         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
20085         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
20086         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
20087         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
20088         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
20089         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
20090         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
20091         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
20092         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
20093         (cmdline_parse_inst_t *)&cmd_ddp_add,
20094         (cmdline_parse_inst_t *)&cmd_ddp_del,
20095         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
20096         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
20097         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
20098         (cmdline_parse_inst_t *)&cmd_clear_input_set,
20099         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
20100         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
20101         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
20102         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
20103         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
20104         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
20105         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
20106         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
20107
20108         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
20109         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
20110         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
20111         (cmdline_parse_inst_t *)&cmd_queue_region,
20112         (cmdline_parse_inst_t *)&cmd_region_flowtype,
20113         (cmdline_parse_inst_t *)&cmd_user_priority_region,
20114         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
20115         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
20116         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
20117         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
20118         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
20119         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
20120         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
20121         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
20122         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
20123         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
20124         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
20125         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
20126         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
20127         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
20128         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
20129         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
20130         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
20131         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
20132         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
20133         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
20134         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
20135         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
20136         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
20137         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
20138         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
20139         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
20140         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
20141         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
20142         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
20143         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
20144         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
20145         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
20146         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
20147         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
20148 #ifdef RTE_LIBRTE_BPF
20149         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
20150         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
20151 #endif
20152         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
20153         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
20154         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
20155         (cmdline_parse_inst_t *)&cmd_set_raw,
20156         (cmdline_parse_inst_t *)&cmd_show_set_raw,
20157         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
20158         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
20159         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
20160         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
20161         (cmdline_parse_inst_t *)&cmd_show_capability,
20162         NULL,
20163 };
20164
20165 /* read cmdline commands from file */
20166 void
20167 cmdline_read_from_file(const char *filename)
20168 {
20169         struct cmdline *cl;
20170
20171         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
20172         if (cl == NULL) {
20173                 printf("Failed to create file based cmdline context: %s\n",
20174                        filename);
20175                 return;
20176         }
20177
20178         cmdline_interact(cl);
20179         cmdline_quit(cl);
20180
20181         cmdline_free(cl);
20182
20183         printf("Read CLI commands from %s\n", filename);
20184 }
20185
20186 /* prompt function, called from main on MASTER lcore */
20187 void
20188 prompt(void)
20189 {
20190         /* initialize non-constant commands */
20191         cmd_set_fwd_mode_init();
20192         cmd_set_fwd_retry_mode_init();
20193
20194         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
20195         if (testpmd_cl == NULL)
20196                 return;
20197         cmdline_interact(testpmd_cl);
20198         cmdline_stdin_exit(testpmd_cl);
20199 }
20200
20201 void
20202 prompt_exit(void)
20203 {
20204         if (testpmd_cl != NULL)
20205                 cmdline_quit(testpmd_cl);
20206 }
20207
20208 static void
20209 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
20210 {
20211         if (id == (portid_t)RTE_PORT_ALL) {
20212                 portid_t pid;
20213
20214                 RTE_ETH_FOREACH_DEV(pid) {
20215                         /* check if need_reconfig has been set to 1 */
20216                         if (ports[pid].need_reconfig == 0)
20217                                 ports[pid].need_reconfig = dev;
20218                         /* check if need_reconfig_queues has been set to 1 */
20219                         if (ports[pid].need_reconfig_queues == 0)
20220                                 ports[pid].need_reconfig_queues = queue;
20221                 }
20222         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
20223                 /* check if need_reconfig has been set to 1 */
20224                 if (ports[id].need_reconfig == 0)
20225                         ports[id].need_reconfig = dev;
20226                 /* check if need_reconfig_queues has been set to 1 */
20227                 if (ports[id].need_reconfig_queues == 0)
20228                         ports[id].need_reconfig_queues = queue;
20229         }
20230 }