ethdev: remove legacy HASH filter type support
[dpdk.git] / app / test-pmd / cmdline.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdarg.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <string.h>
11 #include <termios.h>
12 #include <unistd.h>
13 #include <inttypes.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #include <sys/queue.h>
18
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_log.h>
22 #include <rte_debug.h>
23 #include <rte_cycles.h>
24 #include <rte_memory.h>
25 #include <rte_memzone.h>
26 #include <rte_malloc.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_per_lcore.h>
30 #include <rte_lcore.h>
31 #include <rte_atomic.h>
32 #include <rte_branch_prediction.h>
33 #include <rte_ring.h>
34 #include <rte_mempool.h>
35 #include <rte_interrupts.h>
36 #include <rte_pci.h>
37 #include <rte_ether.h>
38 #include <rte_ethdev.h>
39 #include <rte_string_fns.h>
40 #include <rte_devargs.h>
41 #include <rte_flow.h>
42 #include <rte_gro.h>
43 #include <rte_mbuf_dyn.h>
44
45 #include <cmdline_rdline.h>
46 #include <cmdline_parse.h>
47 #include <cmdline_parse_num.h>
48 #include <cmdline_parse_string.h>
49 #include <cmdline_parse_ipaddr.h>
50 #include <cmdline_parse_etheraddr.h>
51 #include <cmdline_socket.h>
52 #include <cmdline.h>
53 #ifdef RTE_NET_BOND
54 #include <rte_eth_bond.h>
55 #include <rte_eth_bond_8023ad.h>
56 #endif
57 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
58 #include <rte_pmd_dpaa.h>
59 #endif
60 #ifdef RTE_NET_IXGBE
61 #include <rte_pmd_ixgbe.h>
62 #endif
63 #ifdef RTE_NET_I40E
64 #include <rte_pmd_i40e.h>
65 #endif
66 #ifdef RTE_NET_BNXT
67 #include <rte_pmd_bnxt.h>
68 #endif
69 #include "testpmd.h"
70 #include "cmdline_mtr.h"
71 #include "cmdline_tm.h"
72 #include "bpf_cmd.h"
73
74 static struct cmdline *testpmd_cl;
75
76 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
77
78 /* *** Help command with introduction. *** */
79 struct cmd_help_brief_result {
80         cmdline_fixed_string_t help;
81 };
82
83 static void cmd_help_brief_parsed(__rte_unused void *parsed_result,
84                                   struct cmdline *cl,
85                                   __rte_unused void *data)
86 {
87         cmdline_printf(
88                 cl,
89                 "\n"
90                 "Help is available for the following sections:\n\n"
91                 "    help control                    : Start and stop forwarding.\n"
92                 "    help display                    : Displaying port, stats and config "
93                 "information.\n"
94                 "    help config                     : Configuration information.\n"
95                 "    help ports                      : Configuring ports.\n"
96                 "    help registers                  : Reading and setting port registers.\n"
97                 "    help filters                    : Filters configuration help.\n"
98                 "    help traffic_management         : Traffic Management commands.\n"
99                 "    help devices                    : Device related cmds.\n"
100                 "    help all                        : All of the above sections.\n\n"
101         );
102
103 }
104
105 cmdline_parse_token_string_t cmd_help_brief_help =
106         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
107
108 cmdline_parse_inst_t cmd_help_brief = {
109         .f = cmd_help_brief_parsed,
110         .data = NULL,
111         .help_str = "help: Show help",
112         .tokens = {
113                 (void *)&cmd_help_brief_help,
114                 NULL,
115         },
116 };
117
118 /* *** Help command with help sections. *** */
119 struct cmd_help_long_result {
120         cmdline_fixed_string_t help;
121         cmdline_fixed_string_t section;
122 };
123
124 static void cmd_help_long_parsed(void *parsed_result,
125                                  struct cmdline *cl,
126                                  __rte_unused void *data)
127 {
128         int show_all = 0;
129         struct cmd_help_long_result *res = parsed_result;
130
131         if (!strcmp(res->section, "all"))
132                 show_all = 1;
133
134         if (show_all || !strcmp(res->section, "control")) {
135
136                 cmdline_printf(
137                         cl,
138                         "\n"
139                         "Control forwarding:\n"
140                         "-------------------\n\n"
141
142                         "start\n"
143                         "    Start packet forwarding with current configuration.\n\n"
144
145                         "start tx_first\n"
146                         "    Start packet forwarding with current config"
147                         " after sending one burst of packets.\n\n"
148
149                         "stop\n"
150                         "    Stop packet forwarding, and display accumulated"
151                         " statistics.\n\n"
152
153                         "quit\n"
154                         "    Quit to prompt.\n\n"
155                 );
156         }
157
158         if (show_all || !strcmp(res->section, "display")) {
159
160                 cmdline_printf(
161                         cl,
162                         "\n"
163                         "Display:\n"
164                         "--------\n\n"
165
166                         "show port (info|stats|summary|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
167                         "    Display information for port_id, or all.\n\n"
168
169                         "show port port_id (module_eeprom|eeprom)\n"
170                         "    Display the module EEPROM or EEPROM information for port_id.\n\n"
171
172                         "show port X rss reta (size) (mask0,mask1,...)\n"
173                         "    Display the rss redirection table entry indicated"
174                         " by masks on port X. size is used to indicate the"
175                         " hardware supported reta size\n\n"
176
177                         "show port (port_id) rss-hash [key]\n"
178                         "    Display the RSS hash functions and RSS hash key of port\n\n"
179
180                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
181                         "    Clear information for port_id, or all.\n\n"
182
183                         "show (rxq|txq) info (port_id) (queue_id)\n"
184                         "    Display information for configured RX/TX queue.\n\n"
185
186                         "show config (rxtx|cores|fwd|rxoffs|rxpkts|txpkts)\n"
187                         "    Display the given configuration.\n\n"
188
189                         "read rxd (port_id) (queue_id) (rxd_id)\n"
190                         "    Display an RX descriptor of a port RX queue.\n\n"
191
192                         "read txd (port_id) (queue_id) (txd_id)\n"
193                         "    Display a TX descriptor of a port TX queue.\n\n"
194
195                         "ddp get list (port_id)\n"
196                         "    Get ddp profile info list\n\n"
197
198                         "ddp get info (profile_path)\n"
199                         "    Get ddp profile information.\n\n"
200
201                         "show vf stats (port_id) (vf_id)\n"
202                         "    Display a VF's statistics.\n\n"
203
204                         "clear vf stats (port_id) (vf_id)\n"
205                         "    Reset a VF's statistics.\n\n"
206
207                         "show port (port_id) pctype mapping\n"
208                         "    Get flow ptype to pctype mapping on a port\n\n"
209
210                         "show port meter stats (port_id) (meter_id) (clear)\n"
211                         "    Get meter stats on a port\n\n"
212
213                         "show fwd stats all\n"
214                         "    Display statistics for all fwd engines.\n\n"
215
216                         "clear fwd stats all\n"
217                         "    Clear statistics for all fwd engines.\n\n"
218
219                         "show port (port_id) rx_offload capabilities\n"
220                         "    List all per queue and per port Rx offloading"
221                         " capabilities of a port\n\n"
222
223                         "show port (port_id) rx_offload configuration\n"
224                         "    List port level and all queue level"
225                         " Rx offloading configuration\n\n"
226
227                         "show port (port_id) tx_offload capabilities\n"
228                         "    List all per queue and per port"
229                         " Tx offloading capabilities of a port\n\n"
230
231                         "show port (port_id) tx_offload configuration\n"
232                         "    List port level and all queue level"
233                         " Tx offloading configuration\n\n"
234
235                         "show port (port_id) tx_metadata\n"
236                         "    Show Tx metadata value set"
237                         " for a specific port\n\n"
238
239                         "show port (port_id) ptypes\n"
240                         "    Show port supported ptypes"
241                         " for a specific port\n\n"
242
243                         "show device info (<identifier>|all)"
244                         "       Show general information about devices probed.\n\n"
245
246                         "show port (port_id) rxq|txq (queue_id) desc (desc_id) status"
247                         "       Show status of rx|tx descriptor.\n\n"
248
249                         "show port (port_id) macs|mcast_macs"
250                         "       Display list of mac addresses added to port.\n\n"
251
252                         "show port (port_id) fec capabilities"
253                         "       Show fec capabilities of a port.\n\n"
254
255                         "show port (port_id) fec_mode"
256                         "       Show fec mode of a port.\n\n"
257                 );
258         }
259
260         if (show_all || !strcmp(res->section, "config")) {
261                 cmdline_printf(
262                         cl,
263                         "\n"
264                         "Configuration:\n"
265                         "--------------\n"
266                         "Configuration changes only become active when"
267                         " forwarding is started/restarted.\n\n"
268
269                         "set default\n"
270                         "    Reset forwarding to the default configuration.\n\n"
271
272                         "set verbose (level)\n"
273                         "    Set the debug verbosity level X.\n\n"
274
275                         "set log global|(type) (level)\n"
276                         "    Set the log level.\n\n"
277
278                         "set nbport (num)\n"
279                         "    Set number of ports.\n\n"
280
281                         "set nbcore (num)\n"
282                         "    Set number of cores.\n\n"
283
284                         "set coremask (mask)\n"
285                         "    Set the forwarding cores hexadecimal mask.\n\n"
286
287                         "set portmask (mask)\n"
288                         "    Set the forwarding ports hexadecimal mask.\n\n"
289
290                         "set burst (num)\n"
291                         "    Set number of packets per burst.\n\n"
292
293                         "set burst tx delay (microseconds) retry (num)\n"
294                         "    Set the transmit delay time and number of retries,"
295                         " effective when retry is enabled.\n\n"
296
297                         "set rxoffs (x[,y]*)\n"
298                         "    Set the offset of each packet segment on"
299                         " receiving if split feature is engaged."
300                         " Affects only the queues configured with split"
301                         " offloads.\n\n"
302
303                         "set rxpkts (x[,y]*)\n"
304                         "    Set the length of each segment to scatter"
305                         " packets on receiving if split feature is engaged."
306                         " Affects only the queues configured with split"
307                         " offloads.\n\n"
308
309                         "set txpkts (x[,y]*)\n"
310                         "    Set the length of each segment of TXONLY"
311                         " and optionally CSUM packets.\n\n"
312
313                         "set txsplit (off|on|rand)\n"
314                         "    Set the split policy for the TX packets."
315                         " Right now only applicable for CSUM and TXONLY"
316                         " modes\n\n"
317
318                         "set txtimes (x, y)\n"
319                         "    Set the scheduling on timestamps"
320                         " timings for the TXONLY mode\n\n"
321
322                         "set corelist (x[,y]*)\n"
323                         "    Set the list of forwarding cores.\n\n"
324
325                         "set portlist (x[,y]*)\n"
326                         "    Set the list of forwarding ports.\n\n"
327
328                         "set port setup on (iterator|event)\n"
329                         "    Select how attached port is retrieved for setup.\n\n"
330
331                         "set tx loopback (port_id) (on|off)\n"
332                         "    Enable or disable tx loopback.\n\n"
333
334                         "set all queues drop (port_id) (on|off)\n"
335                         "    Set drop enable bit for all queues.\n\n"
336
337                         "set vf split drop (port_id) (vf_id) (on|off)\n"
338                         "    Set split drop enable bit for a VF from the PF.\n\n"
339
340                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
341                         "    Set MAC antispoof for a VF from the PF.\n\n"
342
343                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
344                         "    Enable MACsec offload.\n\n"
345
346                         "set macsec offload (port_id) off\n"
347                         "    Disable MACsec offload.\n\n"
348
349                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
350                         "    Configure MACsec secure connection (SC).\n\n"
351
352                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
353                         "    Configure MACsec secure association (SA).\n\n"
354
355                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
356                         "    Set VF broadcast for a VF from the PF.\n\n"
357
358                         "vlan set stripq (on|off) (port_id,queue_id)\n"
359                         "    Set the VLAN strip for a queue on a port.\n\n"
360
361                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
362                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
363
364                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
365                         "    Set VLAN insert for a VF from the PF.\n\n"
366
367                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
368                         "    Set VLAN antispoof for a VF from the PF.\n\n"
369
370                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
371                         "    Set VLAN tag for a VF from the PF.\n\n"
372
373                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
374                         "    Set a VF's max bandwidth(Mbps).\n\n"
375
376                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
377                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
378
379                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
380                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
381
382                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
383                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
384
385                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
386                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
387
388                         "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n"
389                         "    Set the VLAN strip or filter or qinq strip or extend\n\n"
390
391                         "vlan set (inner|outer) tpid (value) (port_id)\n"
392                         "    Set the VLAN TPID for Packet Filtering on"
393                         " a port\n\n"
394
395                         "rx_vlan add (vlan_id|all) (port_id)\n"
396                         "    Add a vlan_id, or all identifiers, to the set"
397                         " of VLAN identifiers filtered by port_id.\n\n"
398
399                         "rx_vlan rm (vlan_id|all) (port_id)\n"
400                         "    Remove a vlan_id, or all identifiers, from the set"
401                         " of VLAN identifiers filtered by port_id.\n\n"
402
403                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
404                         "    Add a vlan_id, to the set of VLAN identifiers"
405                         "filtered for VF(s) from port_id.\n\n"
406
407                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
408                         "    Remove a vlan_id, to the set of VLAN identifiers"
409                         "filtered for VF(s) from port_id.\n\n"
410
411                         "rx_vxlan_port add (udp_port) (port_id)\n"
412                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
413
414                         "rx_vxlan_port rm (udp_port) (port_id)\n"
415                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
416
417                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
418                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
419                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
420
421                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
422                         "    Set port based TX VLAN insertion.\n\n"
423
424                         "tx_vlan reset (port_id)\n"
425                         "    Disable hardware insertion of a VLAN header in"
426                         " packets sent on a port.\n\n"
427
428                         "csum set (ip|udp|tcp|sctp|outer-ip|outer-udp) (hw|sw) (port_id)\n"
429                         "    Select hardware or software calculation of the"
430                         " checksum when transmitting a packet using the"
431                         " csum forward engine.\n"
432                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
433                         "    outer-ip concerns the outer IP layer in"
434                         "    outer-udp concerns the outer UDP layer in"
435                         " case the packet is recognized as a tunnel packet by"
436                         " the forward engine (vxlan, gre and ipip are supported)\n"
437                         "    Please check the NIC datasheet for HW limits.\n\n"
438
439                         "csum parse-tunnel (on|off) (tx_port_id)\n"
440                         "    If disabled, treat tunnel packets as non-tunneled"
441                         " packets (treat inner headers as payload). The port\n"
442                         "    argument is the port used for TX in csum forward"
443                         " engine.\n\n"
444
445                         "csum show (port_id)\n"
446                         "    Display tx checksum offload configuration\n\n"
447
448                         "tso set (segsize) (portid)\n"
449                         "    Enable TCP Segmentation Offload in csum forward"
450                         " engine.\n"
451                         "    Please check the NIC datasheet for HW limits.\n\n"
452
453                         "tso show (portid)"
454                         "    Display the status of TCP Segmentation Offload.\n\n"
455
456                         "set port (port_id) gro on|off\n"
457                         "    Enable or disable Generic Receive Offload in"
458                         " csum forwarding engine.\n\n"
459
460                         "show port (port_id) gro\n"
461                         "    Display GRO configuration.\n\n"
462
463                         "set gro flush (cycles)\n"
464                         "    Set the cycle to flush GROed packets from"
465                         " reassembly tables.\n\n"
466
467                         "set port (port_id) gso (on|off)"
468                         "    Enable or disable Generic Segmentation Offload in"
469                         " csum forwarding engine.\n\n"
470
471                         "set gso segsz (length)\n"
472                         "    Set max packet length for output GSO segments,"
473                         " including packet header and payload.\n\n"
474
475                         "show port (port_id) gso\n"
476                         "    Show GSO configuration.\n\n"
477
478                         "set fwd (%s)\n"
479                         "    Set packet forwarding mode.\n\n"
480
481                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
482                         "    Add a MAC address on port_id.\n\n"
483
484                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
485                         "    Remove a MAC address from port_id.\n\n"
486
487                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
488                         "    Set the default MAC address for port_id.\n\n"
489
490                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
491                         "    Add a MAC address for a VF on the port.\n\n"
492
493                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
494                         "    Set the MAC address for a VF from the PF.\n\n"
495
496                         "set eth-peer (port_id) (peer_addr)\n"
497                         "    set the peer address for certain port.\n\n"
498
499                         "set port (port_id) uta (mac_address|all) (on|off)\n"
500                         "    Add/Remove a or all unicast hash filter(s)"
501                         "from port X.\n\n"
502
503                         "set promisc (port_id|all) (on|off)\n"
504                         "    Set the promiscuous mode on port_id, or all.\n\n"
505
506                         "set allmulti (port_id|all) (on|off)\n"
507                         "    Set the allmulti mode on port_id, or all.\n\n"
508
509                         "set vf promisc (port_id) (vf_id) (on|off)\n"
510                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
511
512                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
513                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
514
515                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
516                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
517                         " (on|off) autoneg (on|off) (port_id)\n"
518                         "set flow_ctrl rx (on|off) (portid)\n"
519                         "set flow_ctrl tx (on|off) (portid)\n"
520                         "set flow_ctrl high_water (high_water) (portid)\n"
521                         "set flow_ctrl low_water (low_water) (portid)\n"
522                         "set flow_ctrl pause_time (pause_time) (portid)\n"
523                         "set flow_ctrl send_xon (send_xon) (portid)\n"
524                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
525                         "set flow_ctrl autoneg (on|off) (port_id)\n"
526                         "    Set the link flow control parameter on a port.\n\n"
527
528                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
529                         " (low_water) (pause_time) (priority) (port_id)\n"
530                         "    Set the priority flow control parameter on a"
531                         " port.\n\n"
532
533                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
534                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
535                         " queue on port.\n"
536                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
537                         " on port 0 to mapping 5.\n\n"
538
539                         "set xstats-hide-zero on|off\n"
540                         "    Set the option to hide the zero values"
541                         " for xstats display.\n"
542
543                         "set record-core-cycles on|off\n"
544                         "    Set the option to enable measurement of CPU cycles.\n"
545
546                         "set record-burst-stats on|off\n"
547                         "    Set the option to enable display of RX and TX bursts.\n"
548
549                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
550                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
553                         "|MPE) (on|off)\n"
554                         "    AUPE:accepts untagged VLAN;"
555                         "ROPE:accept unicast hash\n\n"
556                         "    BAM:accepts broadcast packets;"
557                         "MPE:accepts all multicast packets\n\n"
558                         "    Enable/Disable a VF receive mode of a port\n\n"
559
560                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
561                         "    Set rate limit for a queue of a port\n\n"
562
563                         "set port (port_id) vf (vf_id) rate (rate_num) "
564                         "queue_mask (queue_mask_value)\n"
565                         "    Set rate limit for queues in VF of a port\n\n"
566
567                         "set port (port_id) mirror-rule (rule_id)"
568                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
569                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
570                         "   Set pool or vlan type mirror rule on a port.\n"
571                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
572                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
573                         " to pool 0.\n\n"
574
575                         "set port (port_id) mirror-rule (rule_id)"
576                         " (uplink-mirror|downlink-mirror) dst-pool"
577                         " (pool_id) (on|off)\n"
578                         "   Set uplink or downlink type mirror rule on a port.\n"
579                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
580                         " 0 on' enable mirror income traffic to pool 0.\n\n"
581
582                         "reset port (port_id) mirror-rule (rule_id)\n"
583                         "   Reset a mirror rule.\n\n"
584
585                         "set flush_rx (on|off)\n"
586                         "   Flush (default) or don't flush RX streams before"
587                         " forwarding. Mainly used with PCAP drivers.\n\n"
588
589                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
590                         "   Set the bypass mode for the lowest port on bypass enabled"
591                         " NIC.\n\n"
592
593                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
594                         "mode (normal|bypass|isolate) (port_id)\n"
595                         "   Set the event required to initiate specified bypass mode for"
596                         " the lowest port on a bypass enabled NIC where:\n"
597                         "       timeout   = enable bypass after watchdog timeout.\n"
598                         "       os_on     = enable bypass when OS/board is powered on.\n"
599                         "       os_off    = enable bypass when OS/board is powered off.\n"
600                         "       power_on  = enable bypass when power supply is turned on.\n"
601                         "       power_off = enable bypass when power supply is turned off."
602                         "\n\n"
603
604                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
605                         "   Set the bypass watchdog timeout to 'n' seconds"
606                         " where 0 = instant.\n\n"
607
608                         "show bypass config (port_id)\n"
609                         "   Show the bypass configuration for a bypass enabled NIC"
610                         " using the lowest port on the NIC.\n\n"
611
612 #ifdef RTE_NET_BOND
613                         "create bonded device (mode) (socket)\n"
614                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
615
616                         "add bonding slave (slave_id) (port_id)\n"
617                         "       Add a slave device to a bonded device.\n\n"
618
619                         "remove bonding slave (slave_id) (port_id)\n"
620                         "       Remove a slave device from a bonded device.\n\n"
621
622                         "set bonding mode (value) (port_id)\n"
623                         "       Set the bonding mode on a bonded device.\n\n"
624
625                         "set bonding primary (slave_id) (port_id)\n"
626                         "       Set the primary slave for a bonded device.\n\n"
627
628                         "show bonding config (port_id)\n"
629                         "       Show the bonding config for port_id.\n\n"
630
631                         "set bonding mac_addr (port_id) (address)\n"
632                         "       Set the MAC address of a bonded device.\n\n"
633
634                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
635                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
636
637                         "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
638                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
639
640                         "set bonding mon_period (port_id) (value)\n"
641                         "       Set the bonding link status monitoring polling period in ms.\n\n"
642
643                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
644                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
645
646 #endif
647                         "set link-up port (port_id)\n"
648                         "       Set link up for a port.\n\n"
649
650                         "set link-down port (port_id)\n"
651                         "       Set link down for a port.\n\n"
652
653                         "E-tag set insertion on port-tag-id (value)"
654                         " port (port_id) vf (vf_id)\n"
655                         "    Enable E-tag insertion for a VF on a port\n\n"
656
657                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
658                         "    Disable E-tag insertion for a VF on a port\n\n"
659
660                         "E-tag set stripping (on|off) port (port_id)\n"
661                         "    Enable/disable E-tag stripping on a port\n\n"
662
663                         "E-tag set forwarding (on|off) port (port_id)\n"
664                         "    Enable/disable E-tag based forwarding"
665                         " on a port\n\n"
666
667                         "E-tag set filter add e-tag-id (value) dst-pool"
668                         " (pool_id) port (port_id)\n"
669                         "    Add an E-tag forwarding filter on a port\n\n"
670
671                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
672                         "    Delete an E-tag forwarding filter on a port\n\n"
673
674                         "ddp add (port_id) (profile_path[,backup_profile_path])\n"
675                         "    Load a profile package on a port\n\n"
676
677                         "ddp del (port_id) (backup_profile_path)\n"
678                         "    Delete a profile package from a port\n\n"
679
680                         "ptype mapping get (port_id) (valid_only)\n"
681                         "    Get ptype mapping on a port\n\n"
682
683                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
684                         "    Replace target with the pkt_type in ptype mapping\n\n"
685
686                         "ptype mapping reset (port_id)\n"
687                         "    Reset ptype mapping on a port\n\n"
688
689                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
690                         "    Update a ptype mapping item on a port\n\n"
691
692                         "set port (port_id) ptype_mask (ptype_mask)\n"
693                         "    set packet types classification for a specific port\n\n"
694
695                         "set port (port_id) queue-region region_id (value) "
696                         "queue_start_index (value) queue_num (value)\n"
697                         "    Set a queue region on a port\n\n"
698
699                         "set port (port_id) queue-region region_id (value) "
700                         "flowtype (value)\n"
701                         "    Set a flowtype region index on a port\n\n"
702
703                         "set port (port_id) queue-region UP (value) region_id (value)\n"
704                         "    Set the mapping of User Priority to "
705                         "queue region on a port\n\n"
706
707                         "set port (port_id) queue-region flush (on|off)\n"
708                         "    flush all queue region related configuration\n\n"
709
710                         "show port meter cap (port_id)\n"
711                         "    Show port meter capability information\n\n"
712
713                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
714                         "    meter profile add - srtcm rfc 2697\n\n"
715
716                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
717                         "    meter profile add - trtcm rfc 2698\n\n"
718
719                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
720                         "    meter profile add - trtcm rfc 4115\n\n"
721
722                         "del port meter profile (port_id) (profile_id)\n"
723                         "    meter profile delete\n\n"
724
725                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
726                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
727                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
728                         "(dscp_tbl_entry63)]\n"
729                         "    meter create\n\n"
730
731                         "enable port meter (port_id) (mtr_id)\n"
732                         "    meter enable\n\n"
733
734                         "disable port meter (port_id) (mtr_id)\n"
735                         "    meter disable\n\n"
736
737                         "del port meter (port_id) (mtr_id)\n"
738                         "    meter delete\n\n"
739
740                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
741                         "    meter update meter profile\n\n"
742
743                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
744                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
745                         "    update meter dscp table entries\n\n"
746
747                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
748                         "(action0) [(action1) (action2)]\n"
749                         "    meter update policer action\n\n"
750
751                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
752                         "    meter update stats\n\n"
753
754                         "show port (port_id) queue-region\n"
755                         "    show all queue region related configuration info\n\n"
756
757                         "set port (port_id) fec_mode auto|off|rs|baser\n"
758                         "    set fec mode for a specific port\n\n"
759
760                         , list_pkt_forwarding_modes()
761                 );
762         }
763
764         if (show_all || !strcmp(res->section, "ports")) {
765
766                 cmdline_printf(
767                         cl,
768                         "\n"
769                         "Port Operations:\n"
770                         "----------------\n\n"
771
772                         "port start (port_id|all)\n"
773                         "    Start all ports or port_id.\n\n"
774
775                         "port stop (port_id|all)\n"
776                         "    Stop all ports or port_id.\n\n"
777
778                         "port close (port_id|all)\n"
779                         "    Close all ports or port_id.\n\n"
780
781                         "port reset (port_id|all)\n"
782                         "    Reset all ports or port_id.\n\n"
783
784                         "port attach (ident)\n"
785                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
786
787                         "port detach (port_id)\n"
788                         "    Detach physical or virtual dev by port_id\n\n"
789
790                         "port config (port_id|all)"
791                         " speed (10|100|1000|10000|25000|40000|50000|100000|200000|auto)"
792                         " duplex (half|full|auto)\n"
793                         "    Set speed and duplex for all ports or port_id\n\n"
794
795                         "port config (port_id|all) loopback (mode)\n"
796                         "    Set loopback mode for all ports or port_id\n\n"
797
798                         "port config all (rxq|txq|rxd|txd) (value)\n"
799                         "    Set number for rxq/txq/rxd/txd.\n\n"
800
801                         "port config all max-pkt-len (value)\n"
802                         "    Set the max packet length.\n\n"
803
804                         "port config all max-lro-pkt-size (value)\n"
805                         "    Set the max LRO aggregated packet size.\n\n"
806
807                         "port config all drop-en (on|off)\n"
808                         "    Enable or disable packet drop on all RX queues of all ports when no "
809                         "receive buffers available.\n\n"
810
811                         "port config all rss (all|default|ip|tcp|udp|sctp|"
812                         "ether|port|vxlan|geneve|nvgre|vxlan-gpe|none|level-default|"
813                         "level-outer|level-inner|<flowtype_id>)\n"
814                         "    Set the RSS mode.\n\n"
815
816                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
817                         "    Set the RSS redirection table.\n\n"
818
819                         "port config (port_id) dcb vt (on|off) (traffic_class)"
820                         " pfc (on|off)\n"
821                         "    Set the DCB mode.\n\n"
822
823                         "port config all burst (value)\n"
824                         "    Set the number of packets per burst.\n\n"
825
826                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
827                         " (value)\n"
828                         "    Set the ring prefetch/host/writeback threshold"
829                         " for tx/rx queue.\n\n"
830
831                         "port config all (txfreet|txrst|rxfreet) (value)\n"
832                         "    Set free threshold for rx/tx, or set"
833                         " tx rs bit threshold.\n\n"
834                         "port config mtu X value\n"
835                         "    Set the MTU of port X to a given value\n\n"
836
837                         "port config (port_id) (rxq|txq) (queue_id) ring_size (value)\n"
838                         "    Set a rx/tx queue's ring size configuration, the new"
839                         " value will take effect after command that (re-)start the port"
840                         " or command that setup the specific queue\n\n"
841
842                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
843                         "    Start/stop a rx/tx queue of port X. Only take effect"
844                         " when port X is started\n\n"
845
846                         "port (port_id) (rxq|txq) (queue_id) deferred_start (on|off)\n"
847                         "    Switch on/off a deferred start of port X rx/tx queue. Only"
848                         " take effect when port X is stopped.\n\n"
849
850                         "port (port_id) (rxq|txq) (queue_id) setup\n"
851                         "    Setup a rx/tx queue of port X.\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867
868                         "port config (port_id) pctype (pctype_id) hash_inset|"
869                         "fdir_inset|fdir_flx_inset get|set|clear field\n"
870                         " (field_idx)\n"
871                         "    Configure RSS|FDIR|FDIR_FLX input set for some pctype\n\n"
872
873                         "port config (port_id) pctype (pctype_id) hash_inset|"
874                         "fdir_inset|fdir_flx_inset clear all"
875                         "    Clear RSS|FDIR|FDIR_FLX input set completely for some pctype\n\n"
876
877                         "port config (port_id) udp_tunnel_port add|rm vxlan|geneve (udp_port)\n\n"
878                         "    Add/remove UDP tunnel port for tunneling offload\n\n"
879
880                         "port config <port_id> rx_offload vlan_strip|"
881                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
882                         "outer_ipv4_cksum|macsec_strip|header_split|"
883                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
884                         "buffer_split|timestamp|security|keep_crc on|off\n"
885                         "     Enable or disable a per port Rx offloading"
886                         " on all Rx queues of a port\n\n"
887
888                         "port (port_id) rxq (queue_id) rx_offload vlan_strip|"
889                         "ipv4_cksum|udp_cksum|tcp_cksum|tcp_lro|qinq_strip|"
890                         "outer_ipv4_cksum|macsec_strip|header_split|"
891                         "vlan_filter|vlan_extend|jumbo_frame|scatter|"
892                         "buffer_split|timestamp|security|keep_crc on|off\n"
893                         "    Enable or disable a per queue Rx offloading"
894                         " only on a specific Rx queue\n\n"
895
896                         "port config (port_id) tx_offload vlan_insert|"
897                         "ipv4_cksum|udp_cksum|tcp_cksum|sctp_cksum|tcp_tso|"
898                         "udp_tso|outer_ipv4_cksum|qinq_insert|vxlan_tnl_tso|"
899                         "gre_tnl_tso|ipip_tnl_tso|geneve_tnl_tso|"
900                         "macsec_insert|mt_lockfree|multi_segs|mbuf_fast_free|"
901                         "security on|off\n"
902                         "    Enable or disable a per port Tx offloading"
903                         " on all Tx queues of a port\n\n"
904
905                         "port (port_id) txq (queue_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|macsec_insert"
909                         "|mt_lockfree|multi_segs|mbuf_fast_free|security"
910                         " on|off\n"
911                         "    Enable or disable a per queue Tx offloading"
912                         " only on a specific Tx queue\n\n"
913
914                         "bpf-load rx|tx (port) (queue) (J|M|B) (file_name)\n"
915                         "    Load an eBPF program as a callback"
916                         " for particular RX/TX queue\n\n"
917
918                         "bpf-unload rx|tx (port) (queue)\n"
919                         "    Unload previously loaded eBPF program"
920                         " for particular RX/TX queue\n\n"
921
922                         "port config (port_id) tx_metadata (value)\n"
923                         "    Set Tx metadata value per port. Testpmd will add this value"
924                         " to any Tx packet sent from this port\n\n"
925
926                         "port config (port_id) dynf (name) set|clear\n"
927                         "    Register a dynf and Set/clear this flag on Tx. "
928                         "Testpmd will set this value to any Tx packet "
929                         "sent from this port\n\n"
930                 );
931         }
932
933         if (show_all || !strcmp(res->section, "registers")) {
934
935                 cmdline_printf(
936                         cl,
937                         "\n"
938                         "Registers:\n"
939                         "----------\n\n"
940
941                         "read reg (port_id) (address)\n"
942                         "    Display value of a port register.\n\n"
943
944                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
945                         "    Display a port register bit field.\n\n"
946
947                         "read regbit (port_id) (address) (bit_x)\n"
948                         "    Display a single port register bit.\n\n"
949
950                         "write reg (port_id) (address) (value)\n"
951                         "    Set value of a port register.\n\n"
952
953                         "write regfield (port_id) (address) (bit_x) (bit_y)"
954                         " (value)\n"
955                         "    Set bit field of a port register.\n\n"
956
957                         "write regbit (port_id) (address) (bit_x) (value)\n"
958                         "    Set single bit value of a port register.\n\n"
959                 );
960         }
961         if (show_all || !strcmp(res->section, "filters")) {
962
963                 cmdline_printf(
964                         cl,
965                         "\n"
966                         "filters:\n"
967                         "--------\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
971                         " src (src_ip_address) dst (dst_ip_address)"
972                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
973                         " vlan (vlan_value) flexbytes (flexbytes_value)"
974                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
975                         " fd_id (fd_id_value)\n"
976                         "    Add/Del an IP type flow director filter.\n\n"
977
978                         "flow_director_filter (port_id) mode IP (add|del|update)"
979                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
980                         " src (src_ip_address) (src_port)"
981                         " dst (dst_ip_address) (dst_port)"
982                         " tos (tos_value) ttl (ttl_value)"
983                         " vlan (vlan_value) flexbytes (flexbytes_value)"
984                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
985                         " fd_id (fd_id_value)\n"
986                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
987
988                         "flow_director_filter (port_id) mode IP (add|del|update)"
989                         " flow (ipv4-sctp|ipv6-sctp)"
990                         " src (src_ip_address) (src_port)"
991                         " dst (dst_ip_address) (dst_port)"
992                         " tag (verification_tag) "
993                         " tos (tos_value) ttl (ttl_value)"
994                         " vlan (vlan_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a SCTP type flow director filter.\n\n"
998
999                         "flow_director_filter (port_id) mode IP (add|del|update)"
1000                         " flow l2_payload ether (ethertype)"
1001                         " flexbytes (flexbytes_value) (drop|fwd)"
1002                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
1003                         "    Add/Del a l2 payload type flow director filter.\n\n"
1004
1005                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
1006                         " mac (mac_address) vlan (vlan_value)"
1007                         " flexbytes (flexbytes_value) (drop|fwd)"
1008                         " queue (queue_id) fd_id (fd_id_value)\n"
1009                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
1010
1011                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
1012                         " mac (mac_address) vlan (vlan_value)"
1013                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
1014                         " flexbytes (flexbytes_value) (drop|fwd)"
1015                         " queue (queue_id) fd_id (fd_id_value)\n"
1016                         "    Add/Del a Tunnel flow director filter.\n\n"
1017
1018                         "flow_director_filter (port_id) mode raw (add|del|update)"
1019                         " flow (flow_id) (drop|fwd) queue (queue_id)"
1020                         " fd_id (fd_id_value) packet (packet file name)\n"
1021                         "    Add/Del a raw type flow director filter.\n\n"
1022
1023                         "flush_flow_director (port_id)\n"
1024                         "    Flush all flow director entries of a device.\n\n"
1025
1026                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1027                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1028                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1029                         "    Set flow director IP mask.\n\n"
1030
1031                         "flow_director_mask (port_id) mode MAC-VLAN"
1032                         " vlan (vlan_value)\n"
1033                         "    Set flow director MAC-VLAN mask.\n\n"
1034
1035                         "flow_director_mask (port_id) mode Tunnel"
1036                         " vlan (vlan_value) mac (mac_value)"
1037                         " tunnel-type (tunnel_type_value)"
1038                         " tunnel-id (tunnel_id_value)\n"
1039                         "    Set flow director Tunnel mask.\n\n"
1040
1041                         "flow_director_flex_mask (port_id)"
1042                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1043                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1044                         " (mask)\n"
1045                         "    Configure mask of flex payload.\n\n"
1046
1047                         "flow_director_flex_payload (port_id)"
1048                         " (raw|l2|l3|l4) (config)\n"
1049                         "    Configure flex payload selection.\n\n"
1050
1051                         "set_fdir_input_set (port_id) "
1052                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1053                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1054                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1055                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1056                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1057                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1058                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1059                         " (select|add)\n"
1060                         "    Set the input set for FDir.\n\n"
1061
1062                         "flow validate {port_id}"
1063                         " [group {group_id}] [priority {level}]"
1064                         " [ingress] [egress]"
1065                         " pattern {item} [/ {item} [...]] / end"
1066                         " actions {action} [/ {action} [...]] / end\n"
1067                         "    Check whether a flow rule can be created.\n\n"
1068
1069                         "flow create {port_id}"
1070                         " [group {group_id}] [priority {level}]"
1071                         " [ingress] [egress]"
1072                         " pattern {item} [/ {item} [...]] / end"
1073                         " actions {action} [/ {action} [...]] / end\n"
1074                         "    Create a flow rule.\n\n"
1075
1076                         "flow destroy {port_id} rule {rule_id} [...]\n"
1077                         "    Destroy specific flow rules.\n\n"
1078
1079                         "flow flush {port_id}\n"
1080                         "    Destroy all flow rules.\n\n"
1081
1082                         "flow query {port_id} {rule_id} {action}\n"
1083                         "    Query an existing flow rule.\n\n"
1084
1085                         "flow list {port_id} [group {group_id}] [...]\n"
1086                         "    List existing flow rules sorted by priority,"
1087                         " filtered by group identifiers.\n\n"
1088
1089                         "flow isolate {port_id} {boolean}\n"
1090                         "    Restrict ingress traffic to the defined"
1091                         " flow rules\n\n"
1092
1093                         "flow aged {port_id} [destroy]\n"
1094                         "    List and destroy aged flows"
1095                         " flow rules\n\n"
1096
1097                         "flow shared_action {port_id} create"
1098                         " [action_id {shared_action_id}]"
1099                         " [ingress] [egress]"
1100                         " action {action} / end\n"
1101                         "    Create shared action.\n\n"
1102
1103                         "flow shared_action {port_id} update"
1104                         " {shared_action_id} action {action} / end\n"
1105                         "    Update shared action.\n\n"
1106
1107                         "flow shared_action {port_id} destroy"
1108                         " action_id {shared_action_id} [...]\n"
1109                         "    Destroy specific shared actions.\n\n"
1110
1111                         "flow shared_action {port_id} query"
1112                         " {shared_action_id}\n"
1113                         "    Query an existing shared action.\n\n"
1114
1115                         "set vxlan ip-version (ipv4|ipv6) vni (vni) udp-src"
1116                         " (udp-src) udp-dst (udp-dst) ip-src (ip-src) ip-dst"
1117                         " (ip-dst) eth-src (eth-src) eth-dst (eth-dst)\n"
1118                         "       Configure the VXLAN encapsulation for flows.\n\n"
1119
1120                         "set vxlan-with-vlan ip-version (ipv4|ipv6) vni (vni)"
1121                         " udp-src (udp-src) udp-dst (udp-dst) ip-src (ip-src)"
1122                         " ip-dst (ip-dst) vlan-tci (vlan-tci) eth-src (eth-src)"
1123                         " eth-dst (eth-dst)\n"
1124                         "       Configure the VXLAN encapsulation for flows.\n\n"
1125
1126                         "set vxlan-tos-ttl ip-version (ipv4|ipv6) vni (vni) udp-src"
1127                         " (udp-src) udp-dst (udp-dst) ip-tos (ip-tos) ip-ttl (ip-ttl)"
1128                         " ip-src (ip-src) ip-dst (ip-dst) eth-src (eth-src)"
1129                         " eth-dst (eth-dst)\n"
1130                         "       Configure the VXLAN encapsulation for flows.\n\n"
1131
1132                         "set nvgre ip-version (ipv4|ipv6) tni (tni) ip-src"
1133                         " (ip-src) ip-dst (ip-dst) eth-src (eth-src) eth-dst"
1134                         " (eth-dst)\n"
1135                         "       Configure the NVGRE encapsulation for flows.\n\n"
1136
1137                         "set nvgre-with-vlan ip-version (ipv4|ipv6) tni (tni)"
1138                         " ip-src (ip-src) ip-dst (ip-dst) vlan-tci (vlan-tci)"
1139                         " eth-src (eth-src) eth-dst (eth-dst)\n"
1140                         "       Configure the NVGRE encapsulation for flows.\n\n"
1141
1142                         "set raw_encap {flow items}\n"
1143                         "       Configure the encapsulation with raw data.\n\n"
1144
1145                         "set raw_decap {flow items}\n"
1146                         "       Configure the decapsulation with raw data.\n\n"
1147
1148                 );
1149         }
1150
1151         if (show_all || !strcmp(res->section, "traffic_management")) {
1152                 cmdline_printf(
1153                         cl,
1154                         "\n"
1155                         "Traffic Management:\n"
1156                         "--------------\n"
1157                         "show port tm cap (port_id)\n"
1158                         "       Display the port TM capability.\n\n"
1159
1160                         "show port tm level cap (port_id) (level_id)\n"
1161                         "       Display the port TM hierarchical level capability.\n\n"
1162
1163                         "show port tm node cap (port_id) (node_id)\n"
1164                         "       Display the port TM node capability.\n\n"
1165
1166                         "show port tm node type (port_id) (node_id)\n"
1167                         "       Display the port TM node type.\n\n"
1168
1169                         "show port tm node stats (port_id) (node_id) (clear)\n"
1170                         "       Display the port TM node stats.\n\n"
1171
1172                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
1173                         " (cmit_tb_rate) (cmit_tb_size) (peak_tb_rate) (peak_tb_size)"
1174                         " (packet_length_adjust) (packet_mode)\n"
1175                         "       Add port tm node private shaper profile.\n\n"
1176
1177                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
1178                         "       Delete port tm node private shaper profile.\n\n"
1179
1180                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
1181                         " (shaper_profile_id)\n"
1182                         "       Add/update port tm node shared shaper.\n\n"
1183
1184                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
1185                         "       Delete port tm node shared shaper.\n\n"
1186
1187                         "set port tm node shaper profile (port_id) (node_id)"
1188                         " (shaper_profile_id)\n"
1189                         "       Set port tm node shaper profile.\n\n"
1190
1191                         "add port tm node wred profile (port_id) (wred_profile_id)"
1192                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
1193                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
1194                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
1195                         "       Add port tm node wred profile.\n\n"
1196
1197                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
1198                         "       Delete port tm node wred profile.\n\n"
1199
1200                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
1201                         " (priority) (weight) (level_id) (shaper_profile_id)"
1202                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1203                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1204                         "       Add port tm nonleaf node.\n\n"
1205
1206                         "add port tm nonleaf node pktmode (port_id) (node_id) (parent_node_id)"
1207                         " (priority) (weight) (level_id) (shaper_profile_id)"
1208                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
1209                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1210                         "       Add port tm nonleaf node with pkt mode enabled.\n\n"
1211
1212                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
1213                         " (priority) (weight) (level_id) (shaper_profile_id)"
1214                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
1215                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
1216                         "       Add port tm leaf node.\n\n"
1217
1218                         "del port tm node (port_id) (node_id)\n"
1219                         "       Delete port tm node.\n\n"
1220
1221                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
1222                         " (priority) (weight)\n"
1223                         "       Set port tm node parent.\n\n"
1224
1225                         "suspend port tm node (port_id) (node_id)"
1226                         "       Suspend tm node.\n\n"
1227
1228                         "resume port tm node (port_id) (node_id)"
1229                         "       Resume tm node.\n\n"
1230
1231                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
1232                         "       Commit tm hierarchy.\n\n"
1233
1234                         "set port tm mark ip_ecn (port) (green) (yellow)"
1235                         " (red)\n"
1236                         "    Enables/Disables the traffic management marking"
1237                         " for IP ECN (Explicit Congestion Notification)"
1238                         " packets on a given port\n\n"
1239
1240                         "set port tm mark ip_dscp (port) (green) (yellow)"
1241                         " (red)\n"
1242                         "    Enables/Disables the traffic management marking"
1243                         " on the port for IP dscp packets\n\n"
1244
1245                         "set port tm mark vlan_dei (port) (green) (yellow)"
1246                         " (red)\n"
1247                         "    Enables/Disables the traffic management marking"
1248                         " on the port for VLAN packets with DEI enabled\n\n"
1249                 );
1250         }
1251
1252         if (show_all || !strcmp(res->section, "devices")) {
1253                 cmdline_printf(
1254                         cl,
1255                         "\n"
1256                         "Device Operations:\n"
1257                         "--------------\n"
1258                         "device detach (identifier)\n"
1259                         "       Detach device by identifier.\n\n"
1260                 );
1261         }
1262
1263 }
1264
1265 cmdline_parse_token_string_t cmd_help_long_help =
1266         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1267
1268 cmdline_parse_token_string_t cmd_help_long_section =
1269         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1270                         "all#control#display#config#"
1271                         "ports#registers#filters#traffic_management#devices");
1272
1273 cmdline_parse_inst_t cmd_help_long = {
1274         .f = cmd_help_long_parsed,
1275         .data = NULL,
1276         .help_str = "help all|control|display|config|ports|register|"
1277                 "filters|traffic_management|devices: "
1278                 "Show help",
1279         .tokens = {
1280                 (void *)&cmd_help_long_help,
1281                 (void *)&cmd_help_long_section,
1282                 NULL,
1283         },
1284 };
1285
1286
1287 /* *** start/stop/close all ports *** */
1288 struct cmd_operate_port_result {
1289         cmdline_fixed_string_t keyword;
1290         cmdline_fixed_string_t name;
1291         cmdline_fixed_string_t value;
1292 };
1293
1294 static void cmd_operate_port_parsed(void *parsed_result,
1295                                 __rte_unused struct cmdline *cl,
1296                                 __rte_unused void *data)
1297 {
1298         struct cmd_operate_port_result *res = parsed_result;
1299
1300         if (!strcmp(res->name, "start"))
1301                 start_port(RTE_PORT_ALL);
1302         else if (!strcmp(res->name, "stop"))
1303                 stop_port(RTE_PORT_ALL);
1304         else if (!strcmp(res->name, "close"))
1305                 close_port(RTE_PORT_ALL);
1306         else if (!strcmp(res->name, "reset"))
1307                 reset_port(RTE_PORT_ALL);
1308         else
1309                 printf("Unknown parameter\n");
1310 }
1311
1312 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1313         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1314                                                                 "port");
1315 cmdline_parse_token_string_t cmd_operate_port_all_port =
1316         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1317                                                 "start#stop#close#reset");
1318 cmdline_parse_token_string_t cmd_operate_port_all_all =
1319         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1320
1321 cmdline_parse_inst_t cmd_operate_port = {
1322         .f = cmd_operate_port_parsed,
1323         .data = NULL,
1324         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1325         .tokens = {
1326                 (void *)&cmd_operate_port_all_cmd,
1327                 (void *)&cmd_operate_port_all_port,
1328                 (void *)&cmd_operate_port_all_all,
1329                 NULL,
1330         },
1331 };
1332
1333 /* *** start/stop/close specific port *** */
1334 struct cmd_operate_specific_port_result {
1335         cmdline_fixed_string_t keyword;
1336         cmdline_fixed_string_t name;
1337         uint8_t value;
1338 };
1339
1340 static void cmd_operate_specific_port_parsed(void *parsed_result,
1341                         __rte_unused struct cmdline *cl,
1342                                 __rte_unused void *data)
1343 {
1344         struct cmd_operate_specific_port_result *res = parsed_result;
1345
1346         if (!strcmp(res->name, "start"))
1347                 start_port(res->value);
1348         else if (!strcmp(res->name, "stop"))
1349                 stop_port(res->value);
1350         else if (!strcmp(res->name, "close"))
1351                 close_port(res->value);
1352         else if (!strcmp(res->name, "reset"))
1353                 reset_port(res->value);
1354         else
1355                 printf("Unknown parameter\n");
1356 }
1357
1358 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1359         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1360                                                         keyword, "port");
1361 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1362         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1363                                                 name, "start#stop#close#reset");
1364 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1365         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1366                                                         value, UINT8);
1367
1368 cmdline_parse_inst_t cmd_operate_specific_port = {
1369         .f = cmd_operate_specific_port_parsed,
1370         .data = NULL,
1371         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1372         .tokens = {
1373                 (void *)&cmd_operate_specific_port_cmd,
1374                 (void *)&cmd_operate_specific_port_port,
1375                 (void *)&cmd_operate_specific_port_id,
1376                 NULL,
1377         },
1378 };
1379
1380 /* *** enable port setup (after attach) via iterator or event *** */
1381 struct cmd_set_port_setup_on_result {
1382         cmdline_fixed_string_t set;
1383         cmdline_fixed_string_t port;
1384         cmdline_fixed_string_t setup;
1385         cmdline_fixed_string_t on;
1386         cmdline_fixed_string_t mode;
1387 };
1388
1389 static void cmd_set_port_setup_on_parsed(void *parsed_result,
1390                                 __rte_unused struct cmdline *cl,
1391                                 __rte_unused void *data)
1392 {
1393         struct cmd_set_port_setup_on_result *res = parsed_result;
1394
1395         if (strcmp(res->mode, "event") == 0)
1396                 setup_on_probe_event = true;
1397         else if (strcmp(res->mode, "iterator") == 0)
1398                 setup_on_probe_event = false;
1399         else
1400                 printf("Unknown mode\n");
1401 }
1402
1403 cmdline_parse_token_string_t cmd_set_port_setup_on_set =
1404         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1405                         set, "set");
1406 cmdline_parse_token_string_t cmd_set_port_setup_on_port =
1407         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1408                         port, "port");
1409 cmdline_parse_token_string_t cmd_set_port_setup_on_setup =
1410         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1411                         setup, "setup");
1412 cmdline_parse_token_string_t cmd_set_port_setup_on_on =
1413         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1414                         on, "on");
1415 cmdline_parse_token_string_t cmd_set_port_setup_on_mode =
1416         TOKEN_STRING_INITIALIZER(struct cmd_set_port_setup_on_result,
1417                         mode, "iterator#event");
1418
1419 cmdline_parse_inst_t cmd_set_port_setup_on = {
1420         .f = cmd_set_port_setup_on_parsed,
1421         .data = NULL,
1422         .help_str = "set port setup on iterator|event",
1423         .tokens = {
1424                 (void *)&cmd_set_port_setup_on_set,
1425                 (void *)&cmd_set_port_setup_on_port,
1426                 (void *)&cmd_set_port_setup_on_setup,
1427                 (void *)&cmd_set_port_setup_on_on,
1428                 (void *)&cmd_set_port_setup_on_mode,
1429                 NULL,
1430         },
1431 };
1432
1433 /* *** attach a specified port *** */
1434 struct cmd_operate_attach_port_result {
1435         cmdline_fixed_string_t port;
1436         cmdline_fixed_string_t keyword;
1437         cmdline_multi_string_t identifier;
1438 };
1439
1440 static void cmd_operate_attach_port_parsed(void *parsed_result,
1441                                 __rte_unused struct cmdline *cl,
1442                                 __rte_unused void *data)
1443 {
1444         struct cmd_operate_attach_port_result *res = parsed_result;
1445
1446         if (!strcmp(res->keyword, "attach"))
1447                 attach_port(res->identifier);
1448         else
1449                 printf("Unknown parameter\n");
1450 }
1451
1452 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1453         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1454                         port, "port");
1455 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1456         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1457                         keyword, "attach");
1458 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1459         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1460                         identifier, TOKEN_STRING_MULTI);
1461
1462 cmdline_parse_inst_t cmd_operate_attach_port = {
1463         .f = cmd_operate_attach_port_parsed,
1464         .data = NULL,
1465         .help_str = "port attach <identifier>: "
1466                 "(identifier: pci address or virtual dev name)",
1467         .tokens = {
1468                 (void *)&cmd_operate_attach_port_port,
1469                 (void *)&cmd_operate_attach_port_keyword,
1470                 (void *)&cmd_operate_attach_port_identifier,
1471                 NULL,
1472         },
1473 };
1474
1475 /* *** detach a specified port *** */
1476 struct cmd_operate_detach_port_result {
1477         cmdline_fixed_string_t port;
1478         cmdline_fixed_string_t keyword;
1479         portid_t port_id;
1480 };
1481
1482 static void cmd_operate_detach_port_parsed(void *parsed_result,
1483                                 __rte_unused struct cmdline *cl,
1484                                 __rte_unused void *data)
1485 {
1486         struct cmd_operate_detach_port_result *res = parsed_result;
1487
1488         if (!strcmp(res->keyword, "detach")) {
1489                 RTE_ETH_VALID_PORTID_OR_RET(res->port_id);
1490                 detach_port_device(res->port_id);
1491         } else {
1492                 printf("Unknown parameter\n");
1493         }
1494 }
1495
1496 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1497         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1498                         port, "port");
1499 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1500         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1501                         keyword, "detach");
1502 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1503         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1504                         port_id, UINT16);
1505
1506 cmdline_parse_inst_t cmd_operate_detach_port = {
1507         .f = cmd_operate_detach_port_parsed,
1508         .data = NULL,
1509         .help_str = "port detach <port_id>",
1510         .tokens = {
1511                 (void *)&cmd_operate_detach_port_port,
1512                 (void *)&cmd_operate_detach_port_keyword,
1513                 (void *)&cmd_operate_detach_port_port_id,
1514                 NULL,
1515         },
1516 };
1517
1518 /* *** detach device by identifier *** */
1519 struct cmd_operate_detach_device_result {
1520         cmdline_fixed_string_t device;
1521         cmdline_fixed_string_t keyword;
1522         cmdline_fixed_string_t identifier;
1523 };
1524
1525 static void cmd_operate_detach_device_parsed(void *parsed_result,
1526                                 __rte_unused struct cmdline *cl,
1527                                 __rte_unused void *data)
1528 {
1529         struct cmd_operate_detach_device_result *res = parsed_result;
1530
1531         if (!strcmp(res->keyword, "detach"))
1532                 detach_devargs(res->identifier);
1533         else
1534                 printf("Unknown parameter\n");
1535 }
1536
1537 cmdline_parse_token_string_t cmd_operate_detach_device_device =
1538         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1539                         device, "device");
1540 cmdline_parse_token_string_t cmd_operate_detach_device_keyword =
1541         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1542                         keyword, "detach");
1543 cmdline_parse_token_string_t cmd_operate_detach_device_identifier =
1544         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_device_result,
1545                         identifier, NULL);
1546
1547 cmdline_parse_inst_t cmd_operate_detach_device = {
1548         .f = cmd_operate_detach_device_parsed,
1549         .data = NULL,
1550         .help_str = "device detach <identifier>:"
1551                 "(identifier: pci address or virtual dev name)",
1552         .tokens = {
1553                 (void *)&cmd_operate_detach_device_device,
1554                 (void *)&cmd_operate_detach_device_keyword,
1555                 (void *)&cmd_operate_detach_device_identifier,
1556                 NULL,
1557         },
1558 };
1559 /* *** configure speed for all ports *** */
1560 struct cmd_config_speed_all {
1561         cmdline_fixed_string_t port;
1562         cmdline_fixed_string_t keyword;
1563         cmdline_fixed_string_t all;
1564         cmdline_fixed_string_t item1;
1565         cmdline_fixed_string_t item2;
1566         cmdline_fixed_string_t value1;
1567         cmdline_fixed_string_t value2;
1568 };
1569
1570 static int
1571 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1572 {
1573
1574         int duplex;
1575
1576         if (!strcmp(duplexstr, "half")) {
1577                 duplex = ETH_LINK_HALF_DUPLEX;
1578         } else if (!strcmp(duplexstr, "full")) {
1579                 duplex = ETH_LINK_FULL_DUPLEX;
1580         } else if (!strcmp(duplexstr, "auto")) {
1581                 duplex = ETH_LINK_FULL_DUPLEX;
1582         } else {
1583                 printf("Unknown duplex parameter\n");
1584                 return -1;
1585         }
1586
1587         if (!strcmp(speedstr, "10")) {
1588                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1589                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1590         } else if (!strcmp(speedstr, "100")) {
1591                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1592                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1593         } else {
1594                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1595                         printf("Invalid speed/duplex parameters\n");
1596                         return -1;
1597                 }
1598                 if (!strcmp(speedstr, "1000")) {
1599                         *speed = ETH_LINK_SPEED_1G;
1600                 } else if (!strcmp(speedstr, "10000")) {
1601                         *speed = ETH_LINK_SPEED_10G;
1602                 } else if (!strcmp(speedstr, "25000")) {
1603                         *speed = ETH_LINK_SPEED_25G;
1604                 } else if (!strcmp(speedstr, "40000")) {
1605                         *speed = ETH_LINK_SPEED_40G;
1606                 } else if (!strcmp(speedstr, "50000")) {
1607                         *speed = ETH_LINK_SPEED_50G;
1608                 } else if (!strcmp(speedstr, "100000")) {
1609                         *speed = ETH_LINK_SPEED_100G;
1610                 } else if (!strcmp(speedstr, "200000")) {
1611                         *speed = ETH_LINK_SPEED_200G;
1612                 } else if (!strcmp(speedstr, "auto")) {
1613                         *speed = ETH_LINK_SPEED_AUTONEG;
1614                 } else {
1615                         printf("Unknown speed parameter\n");
1616                         return -1;
1617                 }
1618         }
1619
1620         return 0;
1621 }
1622
1623 static void
1624 cmd_config_speed_all_parsed(void *parsed_result,
1625                         __rte_unused struct cmdline *cl,
1626                         __rte_unused void *data)
1627 {
1628         struct cmd_config_speed_all *res = parsed_result;
1629         uint32_t link_speed;
1630         portid_t pid;
1631
1632         if (!all_ports_stopped()) {
1633                 printf("Please stop all ports first\n");
1634                 return;
1635         }
1636
1637         if (parse_and_check_speed_duplex(res->value1, res->value2,
1638                         &link_speed) < 0)
1639                 return;
1640
1641         RTE_ETH_FOREACH_DEV(pid) {
1642                 ports[pid].dev_conf.link_speeds = link_speed;
1643         }
1644
1645         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1646 }
1647
1648 cmdline_parse_token_string_t cmd_config_speed_all_port =
1649         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1650 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1651         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1652                                                         "config");
1653 cmdline_parse_token_string_t cmd_config_speed_all_all =
1654         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1655 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1656         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1657 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1658         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1659                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1660 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1661         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1662 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1663         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1664                                                 "half#full#auto");
1665
1666 cmdline_parse_inst_t cmd_config_speed_all = {
1667         .f = cmd_config_speed_all_parsed,
1668         .data = NULL,
1669         .help_str = "port config all speed "
1670                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1671                                                         "half|full|auto",
1672         .tokens = {
1673                 (void *)&cmd_config_speed_all_port,
1674                 (void *)&cmd_config_speed_all_keyword,
1675                 (void *)&cmd_config_speed_all_all,
1676                 (void *)&cmd_config_speed_all_item1,
1677                 (void *)&cmd_config_speed_all_value1,
1678                 (void *)&cmd_config_speed_all_item2,
1679                 (void *)&cmd_config_speed_all_value2,
1680                 NULL,
1681         },
1682 };
1683
1684 /* *** configure speed for specific port *** */
1685 struct cmd_config_speed_specific {
1686         cmdline_fixed_string_t port;
1687         cmdline_fixed_string_t keyword;
1688         portid_t id;
1689         cmdline_fixed_string_t item1;
1690         cmdline_fixed_string_t item2;
1691         cmdline_fixed_string_t value1;
1692         cmdline_fixed_string_t value2;
1693 };
1694
1695 static void
1696 cmd_config_speed_specific_parsed(void *parsed_result,
1697                                 __rte_unused struct cmdline *cl,
1698                                 __rte_unused void *data)
1699 {
1700         struct cmd_config_speed_specific *res = parsed_result;
1701         uint32_t link_speed;
1702
1703         if (!all_ports_stopped()) {
1704                 printf("Please stop all ports first\n");
1705                 return;
1706         }
1707
1708         if (port_id_is_invalid(res->id, ENABLED_WARN))
1709                 return;
1710
1711         if (parse_and_check_speed_duplex(res->value1, res->value2,
1712                         &link_speed) < 0)
1713                 return;
1714
1715         ports[res->id].dev_conf.link_speeds = link_speed;
1716
1717         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1718 }
1719
1720
1721 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1722         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1723                                                                 "port");
1724 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1725         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1726                                                                 "config");
1727 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1728         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT16);
1729 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1730         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1731                                                                 "speed");
1732 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1734                                 "10#100#1000#10000#25000#40000#50000#100000#200000#auto");
1735 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1736         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1737                                                                 "duplex");
1738 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1739         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1740                                                         "half#full#auto");
1741
1742 cmdline_parse_inst_t cmd_config_speed_specific = {
1743         .f = cmd_config_speed_specific_parsed,
1744         .data = NULL,
1745         .help_str = "port config <port_id> speed "
1746                 "10|100|1000|10000|25000|40000|50000|100000|200000|auto duplex "
1747                                                         "half|full|auto",
1748         .tokens = {
1749                 (void *)&cmd_config_speed_specific_port,
1750                 (void *)&cmd_config_speed_specific_keyword,
1751                 (void *)&cmd_config_speed_specific_id,
1752                 (void *)&cmd_config_speed_specific_item1,
1753                 (void *)&cmd_config_speed_specific_value1,
1754                 (void *)&cmd_config_speed_specific_item2,
1755                 (void *)&cmd_config_speed_specific_value2,
1756                 NULL,
1757         },
1758 };
1759
1760 /* *** configure loopback for all ports *** */
1761 struct cmd_config_loopback_all {
1762         cmdline_fixed_string_t port;
1763         cmdline_fixed_string_t keyword;
1764         cmdline_fixed_string_t all;
1765         cmdline_fixed_string_t item;
1766         uint32_t mode;
1767 };
1768
1769 static void
1770 cmd_config_loopback_all_parsed(void *parsed_result,
1771                         __rte_unused struct cmdline *cl,
1772                         __rte_unused void *data)
1773 {
1774         struct cmd_config_loopback_all *res = parsed_result;
1775         portid_t pid;
1776
1777         if (!all_ports_stopped()) {
1778                 printf("Please stop all ports first\n");
1779                 return;
1780         }
1781
1782         RTE_ETH_FOREACH_DEV(pid) {
1783                 ports[pid].dev_conf.lpbk_mode = res->mode;
1784         }
1785
1786         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1787 }
1788
1789 cmdline_parse_token_string_t cmd_config_loopback_all_port =
1790         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
1791 cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
1792         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
1793                                                         "config");
1794 cmdline_parse_token_string_t cmd_config_loopback_all_all =
1795         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
1796 cmdline_parse_token_string_t cmd_config_loopback_all_item =
1797         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
1798                                                         "loopback");
1799 cmdline_parse_token_num_t cmd_config_loopback_all_mode =
1800         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
1801
1802 cmdline_parse_inst_t cmd_config_loopback_all = {
1803         .f = cmd_config_loopback_all_parsed,
1804         .data = NULL,
1805         .help_str = "port config all loopback <mode>",
1806         .tokens = {
1807                 (void *)&cmd_config_loopback_all_port,
1808                 (void *)&cmd_config_loopback_all_keyword,
1809                 (void *)&cmd_config_loopback_all_all,
1810                 (void *)&cmd_config_loopback_all_item,
1811                 (void *)&cmd_config_loopback_all_mode,
1812                 NULL,
1813         },
1814 };
1815
1816 /* *** configure loopback for specific port *** */
1817 struct cmd_config_loopback_specific {
1818         cmdline_fixed_string_t port;
1819         cmdline_fixed_string_t keyword;
1820         uint16_t port_id;
1821         cmdline_fixed_string_t item;
1822         uint32_t mode;
1823 };
1824
1825 static void
1826 cmd_config_loopback_specific_parsed(void *parsed_result,
1827                                 __rte_unused struct cmdline *cl,
1828                                 __rte_unused void *data)
1829 {
1830         struct cmd_config_loopback_specific *res = parsed_result;
1831
1832         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
1833                 return;
1834
1835         if (!port_is_stopped(res->port_id)) {
1836                 printf("Please stop port %u first\n", res->port_id);
1837                 return;
1838         }
1839
1840         ports[res->port_id].dev_conf.lpbk_mode = res->mode;
1841
1842         cmd_reconfig_device_queue(res->port_id, 1, 1);
1843 }
1844
1845
1846 cmdline_parse_token_string_t cmd_config_loopback_specific_port =
1847         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
1848                                                                 "port");
1849 cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
1850         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
1851                                                                 "config");
1852 cmdline_parse_token_num_t cmd_config_loopback_specific_id =
1853         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
1854                                                                 UINT16);
1855 cmdline_parse_token_string_t cmd_config_loopback_specific_item =
1856         TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
1857                                                                 "loopback");
1858 cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
1859         TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
1860                               UINT32);
1861
1862 cmdline_parse_inst_t cmd_config_loopback_specific = {
1863         .f = cmd_config_loopback_specific_parsed,
1864         .data = NULL,
1865         .help_str = "port config <port_id> loopback <mode>",
1866         .tokens = {
1867                 (void *)&cmd_config_loopback_specific_port,
1868                 (void *)&cmd_config_loopback_specific_keyword,
1869                 (void *)&cmd_config_loopback_specific_id,
1870                 (void *)&cmd_config_loopback_specific_item,
1871                 (void *)&cmd_config_loopback_specific_mode,
1872                 NULL,
1873         },
1874 };
1875
1876 /* *** configure txq/rxq, txd/rxd *** */
1877 struct cmd_config_rx_tx {
1878         cmdline_fixed_string_t port;
1879         cmdline_fixed_string_t keyword;
1880         cmdline_fixed_string_t all;
1881         cmdline_fixed_string_t name;
1882         uint16_t value;
1883 };
1884
1885 static void
1886 cmd_config_rx_tx_parsed(void *parsed_result,
1887                         __rte_unused struct cmdline *cl,
1888                         __rte_unused void *data)
1889 {
1890         struct cmd_config_rx_tx *res = parsed_result;
1891
1892         if (!all_ports_stopped()) {
1893                 printf("Please stop all ports first\n");
1894                 return;
1895         }
1896         if (!strcmp(res->name, "rxq")) {
1897                 if (!res->value && !nb_txq) {
1898                         printf("Warning: Either rx or tx queues should be non zero\n");
1899                         return;
1900                 }
1901                 if (check_nb_rxq(res->value) != 0)
1902                         return;
1903                 nb_rxq = res->value;
1904         }
1905         else if (!strcmp(res->name, "txq")) {
1906                 if (!res->value && !nb_rxq) {
1907                         printf("Warning: Either rx or tx queues should be non zero\n");
1908                         return;
1909                 }
1910                 if (check_nb_txq(res->value) != 0)
1911                         return;
1912                 nb_txq = res->value;
1913         }
1914         else if (!strcmp(res->name, "rxd")) {
1915                 if (check_nb_rxd(res->value) != 0)
1916                         return;
1917                 nb_rxd = res->value;
1918         } else if (!strcmp(res->name, "txd")) {
1919                 if (check_nb_txd(res->value) != 0)
1920                         return;
1921
1922                 nb_txd = res->value;
1923         } else {
1924                 printf("Unknown parameter\n");
1925                 return;
1926         }
1927
1928         fwd_config_setup();
1929
1930         init_port_config();
1931
1932         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1933 }
1934
1935 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1936         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1937 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1938         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1939 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1940         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1941 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1942         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1943                                                 "rxq#txq#rxd#txd");
1944 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1945         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1946
1947 cmdline_parse_inst_t cmd_config_rx_tx = {
1948         .f = cmd_config_rx_tx_parsed,
1949         .data = NULL,
1950         .help_str = "port config all rxq|txq|rxd|txd <value>",
1951         .tokens = {
1952                 (void *)&cmd_config_rx_tx_port,
1953                 (void *)&cmd_config_rx_tx_keyword,
1954                 (void *)&cmd_config_rx_tx_all,
1955                 (void *)&cmd_config_rx_tx_name,
1956                 (void *)&cmd_config_rx_tx_value,
1957                 NULL,
1958         },
1959 };
1960
1961 /* *** config max packet length *** */
1962 struct cmd_config_max_pkt_len_result {
1963         cmdline_fixed_string_t port;
1964         cmdline_fixed_string_t keyword;
1965         cmdline_fixed_string_t all;
1966         cmdline_fixed_string_t name;
1967         uint32_t value;
1968 };
1969
1970 static void
1971 cmd_config_max_pkt_len_parsed(void *parsed_result,
1972                                 __rte_unused struct cmdline *cl,
1973                                 __rte_unused void *data)
1974 {
1975         struct cmd_config_max_pkt_len_result *res = parsed_result;
1976         portid_t pid;
1977
1978         if (!all_ports_stopped()) {
1979                 printf("Please stop all ports first\n");
1980                 return;
1981         }
1982
1983         RTE_ETH_FOREACH_DEV(pid) {
1984                 struct rte_port *port = &ports[pid];
1985                 uint64_t rx_offloads = port->dev_conf.rxmode.offloads;
1986
1987                 if (!strcmp(res->name, "max-pkt-len")) {
1988                         if (res->value < RTE_ETHER_MIN_LEN) {
1989                                 printf("max-pkt-len can not be less than %d\n",
1990                                                 RTE_ETHER_MIN_LEN);
1991                                 return;
1992                         }
1993                         if (res->value == port->dev_conf.rxmode.max_rx_pkt_len)
1994                                 return;
1995
1996                         port->dev_conf.rxmode.max_rx_pkt_len = res->value;
1997                         if (res->value > RTE_ETHER_MAX_LEN)
1998                                 rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1999                         else
2000                                 rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
2001                         port->dev_conf.rxmode.offloads = rx_offloads;
2002                 } else {
2003                         printf("Unknown parameter\n");
2004                         return;
2005                 }
2006         }
2007
2008         init_port_config();
2009
2010         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2011 }
2012
2013 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
2014         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
2015                                                                 "port");
2016 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
2017         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
2018                                                                 "config");
2019 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
2020         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
2021                                                                 "all");
2022 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
2023         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
2024                                                                 "max-pkt-len");
2025 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
2026         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
2027                                                                 UINT32);
2028
2029 cmdline_parse_inst_t cmd_config_max_pkt_len = {
2030         .f = cmd_config_max_pkt_len_parsed,
2031         .data = NULL,
2032         .help_str = "port config all max-pkt-len <value>",
2033         .tokens = {
2034                 (void *)&cmd_config_max_pkt_len_port,
2035                 (void *)&cmd_config_max_pkt_len_keyword,
2036                 (void *)&cmd_config_max_pkt_len_all,
2037                 (void *)&cmd_config_max_pkt_len_name,
2038                 (void *)&cmd_config_max_pkt_len_value,
2039                 NULL,
2040         },
2041 };
2042
2043 /* *** config max LRO aggregated packet size *** */
2044 struct cmd_config_max_lro_pkt_size_result {
2045         cmdline_fixed_string_t port;
2046         cmdline_fixed_string_t keyword;
2047         cmdline_fixed_string_t all;
2048         cmdline_fixed_string_t name;
2049         uint32_t value;
2050 };
2051
2052 static void
2053 cmd_config_max_lro_pkt_size_parsed(void *parsed_result,
2054                                 __rte_unused struct cmdline *cl,
2055                                 __rte_unused void *data)
2056 {
2057         struct cmd_config_max_lro_pkt_size_result *res = parsed_result;
2058         portid_t pid;
2059
2060         if (!all_ports_stopped()) {
2061                 printf("Please stop all ports first\n");
2062                 return;
2063         }
2064
2065         RTE_ETH_FOREACH_DEV(pid) {
2066                 struct rte_port *port = &ports[pid];
2067
2068                 if (!strcmp(res->name, "max-lro-pkt-size")) {
2069                         if (res->value ==
2070                                         port->dev_conf.rxmode.max_lro_pkt_size)
2071                                 return;
2072
2073                         port->dev_conf.rxmode.max_lro_pkt_size = res->value;
2074                 } else {
2075                         printf("Unknown parameter\n");
2076                         return;
2077                 }
2078         }
2079
2080         init_port_config();
2081
2082         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2083 }
2084
2085 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_port =
2086         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2087                                  port, "port");
2088 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_keyword =
2089         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2090                                  keyword, "config");
2091 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_all =
2092         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2093                                  all, "all");
2094 cmdline_parse_token_string_t cmd_config_max_lro_pkt_size_name =
2095         TOKEN_STRING_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2096                                  name, "max-lro-pkt-size");
2097 cmdline_parse_token_num_t cmd_config_max_lro_pkt_size_value =
2098         TOKEN_NUM_INITIALIZER(struct cmd_config_max_lro_pkt_size_result,
2099                               value, UINT32);
2100
2101 cmdline_parse_inst_t cmd_config_max_lro_pkt_size = {
2102         .f = cmd_config_max_lro_pkt_size_parsed,
2103         .data = NULL,
2104         .help_str = "port config all max-lro-pkt-size <value>",
2105         .tokens = {
2106                 (void *)&cmd_config_max_lro_pkt_size_port,
2107                 (void *)&cmd_config_max_lro_pkt_size_keyword,
2108                 (void *)&cmd_config_max_lro_pkt_size_all,
2109                 (void *)&cmd_config_max_lro_pkt_size_name,
2110                 (void *)&cmd_config_max_lro_pkt_size_value,
2111                 NULL,
2112         },
2113 };
2114
2115 /* *** configure port MTU *** */
2116 struct cmd_config_mtu_result {
2117         cmdline_fixed_string_t port;
2118         cmdline_fixed_string_t keyword;
2119         cmdline_fixed_string_t mtu;
2120         portid_t port_id;
2121         uint16_t value;
2122 };
2123
2124 static void
2125 cmd_config_mtu_parsed(void *parsed_result,
2126                       __rte_unused struct cmdline *cl,
2127                       __rte_unused void *data)
2128 {
2129         struct cmd_config_mtu_result *res = parsed_result;
2130
2131         if (res->value < RTE_ETHER_MIN_LEN) {
2132                 printf("mtu cannot be less than %d\n", RTE_ETHER_MIN_LEN);
2133                 return;
2134         }
2135         port_mtu_set(res->port_id, res->value);
2136 }
2137
2138 cmdline_parse_token_string_t cmd_config_mtu_port =
2139         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
2140                                  "port");
2141 cmdline_parse_token_string_t cmd_config_mtu_keyword =
2142         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2143                                  "config");
2144 cmdline_parse_token_string_t cmd_config_mtu_mtu =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
2146                                  "mtu");
2147 cmdline_parse_token_num_t cmd_config_mtu_port_id =
2148         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
2149 cmdline_parse_token_num_t cmd_config_mtu_value =
2150         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
2151
2152 cmdline_parse_inst_t cmd_config_mtu = {
2153         .f = cmd_config_mtu_parsed,
2154         .data = NULL,
2155         .help_str = "port config mtu <port_id> <value>",
2156         .tokens = {
2157                 (void *)&cmd_config_mtu_port,
2158                 (void *)&cmd_config_mtu_keyword,
2159                 (void *)&cmd_config_mtu_mtu,
2160                 (void *)&cmd_config_mtu_port_id,
2161                 (void *)&cmd_config_mtu_value,
2162                 NULL,
2163         },
2164 };
2165
2166 /* *** configure rx mode *** */
2167 struct cmd_config_rx_mode_flag {
2168         cmdline_fixed_string_t port;
2169         cmdline_fixed_string_t keyword;
2170         cmdline_fixed_string_t all;
2171         cmdline_fixed_string_t name;
2172         cmdline_fixed_string_t value;
2173 };
2174
2175 static void
2176 cmd_config_rx_mode_flag_parsed(void *parsed_result,
2177                                 __rte_unused struct cmdline *cl,
2178                                 __rte_unused void *data)
2179 {
2180         struct cmd_config_rx_mode_flag *res = parsed_result;
2181
2182         if (!all_ports_stopped()) {
2183                 printf("Please stop all ports first\n");
2184                 return;
2185         }
2186
2187         if (!strcmp(res->name, "drop-en")) {
2188                 if (!strcmp(res->value, "on"))
2189                         rx_drop_en = 1;
2190                 else if (!strcmp(res->value, "off"))
2191                         rx_drop_en = 0;
2192                 else {
2193                         printf("Unknown parameter\n");
2194                         return;
2195                 }
2196         } else {
2197                 printf("Unknown parameter\n");
2198                 return;
2199         }
2200
2201         init_port_config();
2202
2203         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2204 }
2205
2206 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
2207         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
2208 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
2209         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
2210                                                                 "config");
2211 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
2212         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
2213 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
2214         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
2215                                         "drop-en");
2216 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
2218                                                         "on#off");
2219
2220 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
2221         .f = cmd_config_rx_mode_flag_parsed,
2222         .data = NULL,
2223         .help_str = "port config all drop-en on|off",
2224         .tokens = {
2225                 (void *)&cmd_config_rx_mode_flag_port,
2226                 (void *)&cmd_config_rx_mode_flag_keyword,
2227                 (void *)&cmd_config_rx_mode_flag_all,
2228                 (void *)&cmd_config_rx_mode_flag_name,
2229                 (void *)&cmd_config_rx_mode_flag_value,
2230                 NULL,
2231         },
2232 };
2233
2234 /* *** configure rss *** */
2235 struct cmd_config_rss {
2236         cmdline_fixed_string_t port;
2237         cmdline_fixed_string_t keyword;
2238         cmdline_fixed_string_t all;
2239         cmdline_fixed_string_t name;
2240         cmdline_fixed_string_t value;
2241 };
2242
2243 static void
2244 cmd_config_rss_parsed(void *parsed_result,
2245                         __rte_unused struct cmdline *cl,
2246                         __rte_unused void *data)
2247 {
2248         struct cmd_config_rss *res = parsed_result;
2249         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
2250         struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
2251         int use_default = 0;
2252         int all_updated = 1;
2253         int diag;
2254         uint16_t i;
2255         int ret;
2256
2257         if (!strcmp(res->value, "all"))
2258                 rss_conf.rss_hf = ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP |
2259                         ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_SCTP |
2260                         ETH_RSS_L2_PAYLOAD | ETH_RSS_L2TPV3 | ETH_RSS_ESP |
2261                         ETH_RSS_AH | ETH_RSS_PFCP | ETH_RSS_GTPU;
2262         else if (!strcmp(res->value, "eth"))
2263                 rss_conf.rss_hf = ETH_RSS_ETH;
2264         else if (!strcmp(res->value, "vlan"))
2265                 rss_conf.rss_hf = ETH_RSS_VLAN;
2266         else if (!strcmp(res->value, "ip"))
2267                 rss_conf.rss_hf = ETH_RSS_IP;
2268         else if (!strcmp(res->value, "udp"))
2269                 rss_conf.rss_hf = ETH_RSS_UDP;
2270         else if (!strcmp(res->value, "tcp"))
2271                 rss_conf.rss_hf = ETH_RSS_TCP;
2272         else if (!strcmp(res->value, "sctp"))
2273                 rss_conf.rss_hf = ETH_RSS_SCTP;
2274         else if (!strcmp(res->value, "ether"))
2275                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
2276         else if (!strcmp(res->value, "port"))
2277                 rss_conf.rss_hf = ETH_RSS_PORT;
2278         else if (!strcmp(res->value, "vxlan"))
2279                 rss_conf.rss_hf = ETH_RSS_VXLAN;
2280         else if (!strcmp(res->value, "geneve"))
2281                 rss_conf.rss_hf = ETH_RSS_GENEVE;
2282         else if (!strcmp(res->value, "nvgre"))
2283                 rss_conf.rss_hf = ETH_RSS_NVGRE;
2284         else if (!strcmp(res->value, "l3-pre32"))
2285                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
2286         else if (!strcmp(res->value, "l3-pre40"))
2287                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
2288         else if (!strcmp(res->value, "l3-pre48"))
2289                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
2290         else if (!strcmp(res->value, "l3-pre56"))
2291                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
2292         else if (!strcmp(res->value, "l3-pre64"))
2293                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
2294         else if (!strcmp(res->value, "l3-pre96"))
2295                 rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
2296         else if (!strcmp(res->value, "l3-src-only"))
2297                 rss_conf.rss_hf = ETH_RSS_L3_SRC_ONLY;
2298         else if (!strcmp(res->value, "l3-dst-only"))
2299                 rss_conf.rss_hf = ETH_RSS_L3_DST_ONLY;
2300         else if (!strcmp(res->value, "l4-src-only"))
2301                 rss_conf.rss_hf = ETH_RSS_L4_SRC_ONLY;
2302         else if (!strcmp(res->value, "l4-dst-only"))
2303                 rss_conf.rss_hf = ETH_RSS_L4_DST_ONLY;
2304         else if (!strcmp(res->value, "l2-src-only"))
2305                 rss_conf.rss_hf = ETH_RSS_L2_SRC_ONLY;
2306         else if (!strcmp(res->value, "l2-dst-only"))
2307                 rss_conf.rss_hf = ETH_RSS_L2_DST_ONLY;
2308         else if (!strcmp(res->value, "l2tpv3"))
2309                 rss_conf.rss_hf = ETH_RSS_L2TPV3;
2310         else if (!strcmp(res->value, "esp"))
2311                 rss_conf.rss_hf = ETH_RSS_ESP;
2312         else if (!strcmp(res->value, "ah"))
2313                 rss_conf.rss_hf = ETH_RSS_AH;
2314         else if (!strcmp(res->value, "pfcp"))
2315                 rss_conf.rss_hf = ETH_RSS_PFCP;
2316         else if (!strcmp(res->value, "pppoe"))
2317                 rss_conf.rss_hf = ETH_RSS_PPPOE;
2318         else if (!strcmp(res->value, "gtpu"))
2319                 rss_conf.rss_hf = ETH_RSS_GTPU;
2320         else if (!strcmp(res->value, "none"))
2321                 rss_conf.rss_hf = 0;
2322         else if (!strcmp(res->value, "level-default")) {
2323                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2324                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_PMD_DEFAULT);
2325         } else if (!strcmp(res->value, "level-outer")) {
2326                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2327                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_OUTERMOST);
2328         } else if (!strcmp(res->value, "level-inner")) {
2329                 rss_hf &= (~ETH_RSS_LEVEL_MASK);
2330                 rss_conf.rss_hf = (rss_hf | ETH_RSS_LEVEL_INNERMOST);
2331         } else if (!strcmp(res->value, "default"))
2332                 use_default = 1;
2333         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
2334                                                 atoi(res->value) < 64)
2335                 rss_conf.rss_hf = 1ULL << atoi(res->value);
2336         else {
2337                 printf("Unknown parameter\n");
2338                 return;
2339         }
2340         rss_conf.rss_key = NULL;
2341         /* Update global configuration for RSS types. */
2342         RTE_ETH_FOREACH_DEV(i) {
2343                 struct rte_eth_rss_conf local_rss_conf;
2344
2345                 ret = eth_dev_info_get_print_err(i, &dev_info);
2346                 if (ret != 0)
2347                         return;
2348
2349                 if (use_default)
2350                         rss_conf.rss_hf = dev_info.flow_type_rss_offloads;
2351
2352                 local_rss_conf = rss_conf;
2353                 local_rss_conf.rss_hf = rss_conf.rss_hf &
2354                         dev_info.flow_type_rss_offloads;
2355                 if (local_rss_conf.rss_hf != rss_conf.rss_hf) {
2356                         printf("Port %u modified RSS hash function based on hardware support,"
2357                                 "requested:%#"PRIx64" configured:%#"PRIx64"\n",
2358                                 i, rss_conf.rss_hf, local_rss_conf.rss_hf);
2359                 }
2360                 diag = rte_eth_dev_rss_hash_update(i, &local_rss_conf);
2361                 if (diag < 0) {
2362                         all_updated = 0;
2363                         printf("Configuration of RSS hash at ethernet port %d "
2364                                 "failed with error (%d): %s.\n",
2365                                 i, -diag, strerror(-diag));
2366                 }
2367         }
2368         if (all_updated && !use_default) {
2369                 rss_hf = rss_conf.rss_hf;
2370                 printf("rss_hf %#"PRIx64"\n", rss_hf);
2371         }
2372 }
2373
2374 cmdline_parse_token_string_t cmd_config_rss_port =
2375         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
2376 cmdline_parse_token_string_t cmd_config_rss_keyword =
2377         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
2378 cmdline_parse_token_string_t cmd_config_rss_all =
2379         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
2380 cmdline_parse_token_string_t cmd_config_rss_name =
2381         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
2382 cmdline_parse_token_string_t cmd_config_rss_value =
2383         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
2384
2385 cmdline_parse_inst_t cmd_config_rss = {
2386         .f = cmd_config_rss_parsed,
2387         .data = NULL,
2388         .help_str = "port config all rss "
2389                 "all|default|eth|vlan|ip|tcp|udp|sctp|ether|port|vxlan|geneve|"
2390                 "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|none|level-default|"
2391                 "level-outer|level-inner|<flowtype_id>",
2392         .tokens = {
2393                 (void *)&cmd_config_rss_port,
2394                 (void *)&cmd_config_rss_keyword,
2395                 (void *)&cmd_config_rss_all,
2396                 (void *)&cmd_config_rss_name,
2397                 (void *)&cmd_config_rss_value,
2398                 NULL,
2399         },
2400 };
2401
2402 /* *** configure rss hash key *** */
2403 struct cmd_config_rss_hash_key {
2404         cmdline_fixed_string_t port;
2405         cmdline_fixed_string_t config;
2406         portid_t port_id;
2407         cmdline_fixed_string_t rss_hash_key;
2408         cmdline_fixed_string_t rss_type;
2409         cmdline_fixed_string_t key;
2410 };
2411
2412 static uint8_t
2413 hexa_digit_to_value(char hexa_digit)
2414 {
2415         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
2416                 return (uint8_t) (hexa_digit - '0');
2417         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
2418                 return (uint8_t) ((hexa_digit - 'a') + 10);
2419         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
2420                 return (uint8_t) ((hexa_digit - 'A') + 10);
2421         /* Invalid hexa digit */
2422         return 0xFF;
2423 }
2424
2425 static uint8_t
2426 parse_and_check_key_hexa_digit(char *key, int idx)
2427 {
2428         uint8_t hexa_v;
2429
2430         hexa_v = hexa_digit_to_value(key[idx]);
2431         if (hexa_v == 0xFF)
2432                 printf("invalid key: character %c at position %d is not a "
2433                        "valid hexa digit\n", key[idx], idx);
2434         return hexa_v;
2435 }
2436
2437 static void
2438 cmd_config_rss_hash_key_parsed(void *parsed_result,
2439                                __rte_unused struct cmdline *cl,
2440                                __rte_unused void *data)
2441 {
2442         struct cmd_config_rss_hash_key *res = parsed_result;
2443         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
2444         uint8_t xdgt0;
2445         uint8_t xdgt1;
2446         int i;
2447         struct rte_eth_dev_info dev_info;
2448         uint8_t hash_key_size;
2449         uint32_t key_len;
2450         int ret;
2451
2452         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2453         if (ret != 0)
2454                 return;
2455
2456         if (dev_info.hash_key_size > 0 &&
2457                         dev_info.hash_key_size <= sizeof(hash_key))
2458                 hash_key_size = dev_info.hash_key_size;
2459         else {
2460                 printf("dev_info did not provide a valid hash key size\n");
2461                 return;
2462         }
2463         /* Check the length of the RSS hash key */
2464         key_len = strlen(res->key);
2465         if (key_len != (hash_key_size * 2)) {
2466                 printf("key length: %d invalid - key must be a string of %d"
2467                            " hexa-decimal numbers\n",
2468                            (int) key_len, hash_key_size * 2);
2469                 return;
2470         }
2471         /* Translate RSS hash key into binary representation */
2472         for (i = 0; i < hash_key_size; i++) {
2473                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2474                 if (xdgt0 == 0xFF)
2475                         return;
2476                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2477                 if (xdgt1 == 0xFF)
2478                         return;
2479                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2480         }
2481         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2482                         hash_key_size);
2483 }
2484
2485 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2486         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2487 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2488         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2489                                  "config");
2490 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2491         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2492 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2493         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2494                                  rss_hash_key, "rss-hash-key");
2495 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2496         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2497                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2498                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2499                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2500                                  "ipv6-tcp-ex#ipv6-udp-ex#"
2501                                  "l3-src-only#l3-dst-only#l4-src-only#l4-dst-only#"
2502                                  "l2-src-only#l2-dst-only#s-vlan#c-vlan#"
2503                                  "l2tpv3#esp#ah#pfcp#pppoe#gtpu");
2504 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2505         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2506
2507 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2508         .f = cmd_config_rss_hash_key_parsed,
2509         .data = NULL,
2510         .help_str = "port config <port_id> rss-hash-key "
2511                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2512                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2513                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
2514                 "l3-src-only|l3-dst-only|l4-src-only|l4-dst-only|"
2515                 "l2-src-only|l2-dst-only|s-vlan|c-vlan|"
2516                 "l2tpv3|esp|ah|pfcp|pppoe|gtpu "
2517                 "<string of hex digits (variable length, NIC dependent)>",
2518         .tokens = {
2519                 (void *)&cmd_config_rss_hash_key_port,
2520                 (void *)&cmd_config_rss_hash_key_config,
2521                 (void *)&cmd_config_rss_hash_key_port_id,
2522                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2523                 (void *)&cmd_config_rss_hash_key_rss_type,
2524                 (void *)&cmd_config_rss_hash_key_value,
2525                 NULL,
2526         },
2527 };
2528
2529 /* *** configure port rxq/txq ring size *** */
2530 struct cmd_config_rxtx_ring_size {
2531         cmdline_fixed_string_t port;
2532         cmdline_fixed_string_t config;
2533         portid_t portid;
2534         cmdline_fixed_string_t rxtxq;
2535         uint16_t qid;
2536         cmdline_fixed_string_t rsize;
2537         uint16_t size;
2538 };
2539
2540 static void
2541 cmd_config_rxtx_ring_size_parsed(void *parsed_result,
2542                                  __rte_unused struct cmdline *cl,
2543                                  __rte_unused void *data)
2544 {
2545         struct cmd_config_rxtx_ring_size *res = parsed_result;
2546         struct rte_port *port;
2547         uint8_t isrx;
2548
2549         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2550                 return;
2551
2552         if (res->portid == (portid_t)RTE_PORT_ALL) {
2553                 printf("Invalid port id\n");
2554                 return;
2555         }
2556
2557         port = &ports[res->portid];
2558
2559         if (!strcmp(res->rxtxq, "rxq"))
2560                 isrx = 1;
2561         else if (!strcmp(res->rxtxq, "txq"))
2562                 isrx = 0;
2563         else {
2564                 printf("Unknown parameter\n");
2565                 return;
2566         }
2567
2568         if (isrx && rx_queue_id_is_invalid(res->qid))
2569                 return;
2570         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2571                 return;
2572
2573         if (isrx && res->size != 0 && res->size <= rx_free_thresh) {
2574                 printf("Invalid rx ring_size, must > rx_free_thresh: %d\n",
2575                        rx_free_thresh);
2576                 return;
2577         }
2578
2579         if (isrx)
2580                 port->nb_rx_desc[res->qid] = res->size;
2581         else
2582                 port->nb_tx_desc[res->qid] = res->size;
2583
2584         cmd_reconfig_device_queue(res->portid, 0, 1);
2585 }
2586
2587 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_port =
2588         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2589                                  port, "port");
2590 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_config =
2591         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2592                                  config, "config");
2593 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_portid =
2594         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2595                                  portid, UINT16);
2596 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rxtxq =
2597         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2598                                  rxtxq, "rxq#txq");
2599 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_qid =
2600         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2601                               qid, UINT16);
2602 cmdline_parse_token_string_t cmd_config_rxtx_ring_size_rsize =
2603         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_ring_size,
2604                                  rsize, "ring_size");
2605 cmdline_parse_token_num_t cmd_config_rxtx_ring_size_size =
2606         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_ring_size,
2607                               size, UINT16);
2608
2609 cmdline_parse_inst_t cmd_config_rxtx_ring_size = {
2610         .f = cmd_config_rxtx_ring_size_parsed,
2611         .data = NULL,
2612         .help_str = "port config <port_id> rxq|txq <queue_id> ring_size <value>",
2613         .tokens = {
2614                 (void *)&cmd_config_rxtx_ring_size_port,
2615                 (void *)&cmd_config_rxtx_ring_size_config,
2616                 (void *)&cmd_config_rxtx_ring_size_portid,
2617                 (void *)&cmd_config_rxtx_ring_size_rxtxq,
2618                 (void *)&cmd_config_rxtx_ring_size_qid,
2619                 (void *)&cmd_config_rxtx_ring_size_rsize,
2620                 (void *)&cmd_config_rxtx_ring_size_size,
2621                 NULL,
2622         },
2623 };
2624
2625 /* *** configure port rxq/txq start/stop *** */
2626 struct cmd_config_rxtx_queue {
2627         cmdline_fixed_string_t port;
2628         portid_t portid;
2629         cmdline_fixed_string_t rxtxq;
2630         uint16_t qid;
2631         cmdline_fixed_string_t opname;
2632 };
2633
2634 static void
2635 cmd_config_rxtx_queue_parsed(void *parsed_result,
2636                         __rte_unused struct cmdline *cl,
2637                         __rte_unused void *data)
2638 {
2639         struct cmd_config_rxtx_queue *res = parsed_result;
2640         uint8_t isrx;
2641         uint8_t isstart;
2642         int ret = 0;
2643
2644         if (test_done == 0) {
2645                 printf("Please stop forwarding first\n");
2646                 return;
2647         }
2648
2649         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2650                 return;
2651
2652         if (port_is_started(res->portid) != 1) {
2653                 printf("Please start port %u first\n", res->portid);
2654                 return;
2655         }
2656
2657         if (!strcmp(res->rxtxq, "rxq"))
2658                 isrx = 1;
2659         else if (!strcmp(res->rxtxq, "txq"))
2660                 isrx = 0;
2661         else {
2662                 printf("Unknown parameter\n");
2663                 return;
2664         }
2665
2666         if (isrx && rx_queue_id_is_invalid(res->qid))
2667                 return;
2668         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2669                 return;
2670
2671         if (!strcmp(res->opname, "start"))
2672                 isstart = 1;
2673         else if (!strcmp(res->opname, "stop"))
2674                 isstart = 0;
2675         else {
2676                 printf("Unknown parameter\n");
2677                 return;
2678         }
2679
2680         if (isstart && isrx)
2681                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2682         else if (!isstart && isrx)
2683                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2684         else if (isstart && !isrx)
2685                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2686         else
2687                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2688
2689         if (ret == -ENOTSUP)
2690                 printf("Function not supported in PMD driver\n");
2691 }
2692
2693 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2694         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2695 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2696         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2697 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2698         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2699 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2700         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2701 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2702         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2703                                                 "start#stop");
2704
2705 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2706         .f = cmd_config_rxtx_queue_parsed,
2707         .data = NULL,
2708         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2709         .tokens = {
2710                 (void *)&cmd_config_rxtx_queue_port,
2711                 (void *)&cmd_config_rxtx_queue_portid,
2712                 (void *)&cmd_config_rxtx_queue_rxtxq,
2713                 (void *)&cmd_config_rxtx_queue_qid,
2714                 (void *)&cmd_config_rxtx_queue_opname,
2715                 NULL,
2716         },
2717 };
2718
2719 /* *** configure port rxq/txq deferred start on/off *** */
2720 struct cmd_config_deferred_start_rxtx_queue {
2721         cmdline_fixed_string_t port;
2722         portid_t port_id;
2723         cmdline_fixed_string_t rxtxq;
2724         uint16_t qid;
2725         cmdline_fixed_string_t opname;
2726         cmdline_fixed_string_t state;
2727 };
2728
2729 static void
2730 cmd_config_deferred_start_rxtx_queue_parsed(void *parsed_result,
2731                         __rte_unused struct cmdline *cl,
2732                         __rte_unused void *data)
2733 {
2734         struct cmd_config_deferred_start_rxtx_queue *res = parsed_result;
2735         struct rte_port *port;
2736         uint8_t isrx;
2737         uint8_t ison;
2738         uint8_t needreconfig = 0;
2739
2740         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
2741                 return;
2742
2743         if (port_is_started(res->port_id) != 0) {
2744                 printf("Please stop port %u first\n", res->port_id);
2745                 return;
2746         }
2747
2748         port = &ports[res->port_id];
2749
2750         isrx = !strcmp(res->rxtxq, "rxq");
2751
2752         if (isrx && rx_queue_id_is_invalid(res->qid))
2753                 return;
2754         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2755                 return;
2756
2757         ison = !strcmp(res->state, "on");
2758
2759         if (isrx && port->rx_conf[res->qid].rx_deferred_start != ison) {
2760                 port->rx_conf[res->qid].rx_deferred_start = ison;
2761                 needreconfig = 1;
2762         } else if (!isrx && port->tx_conf[res->qid].tx_deferred_start != ison) {
2763                 port->tx_conf[res->qid].tx_deferred_start = ison;
2764                 needreconfig = 1;
2765         }
2766
2767         if (needreconfig)
2768                 cmd_reconfig_device_queue(res->port_id, 0, 1);
2769 }
2770
2771 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_port =
2772         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2773                                                 port, "port");
2774 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_port_id =
2775         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2776                                                 port_id, UINT16);
2777 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_rxtxq =
2778         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2779                                                 rxtxq, "rxq#txq");
2780 cmdline_parse_token_num_t cmd_config_deferred_start_rxtx_queue_qid =
2781         TOKEN_NUM_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2782                                                 qid, UINT16);
2783 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_opname =
2784         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2785                                                 opname, "deferred_start");
2786 cmdline_parse_token_string_t cmd_config_deferred_start_rxtx_queue_state =
2787         TOKEN_STRING_INITIALIZER(struct cmd_config_deferred_start_rxtx_queue,
2788                                                 state, "on#off");
2789
2790 cmdline_parse_inst_t cmd_config_deferred_start_rxtx_queue = {
2791         .f = cmd_config_deferred_start_rxtx_queue_parsed,
2792         .data = NULL,
2793         .help_str = "port <port_id> rxq|txq <queue_id> deferred_start on|off",
2794         .tokens = {
2795                 (void *)&cmd_config_deferred_start_rxtx_queue_port,
2796                 (void *)&cmd_config_deferred_start_rxtx_queue_port_id,
2797                 (void *)&cmd_config_deferred_start_rxtx_queue_rxtxq,
2798                 (void *)&cmd_config_deferred_start_rxtx_queue_qid,
2799                 (void *)&cmd_config_deferred_start_rxtx_queue_opname,
2800                 (void *)&cmd_config_deferred_start_rxtx_queue_state,
2801                 NULL,
2802         },
2803 };
2804
2805 /* *** configure port rxq/txq setup *** */
2806 struct cmd_setup_rxtx_queue {
2807         cmdline_fixed_string_t port;
2808         portid_t portid;
2809         cmdline_fixed_string_t rxtxq;
2810         uint16_t qid;
2811         cmdline_fixed_string_t setup;
2812 };
2813
2814 /* Common CLI fields for queue setup */
2815 cmdline_parse_token_string_t cmd_setup_rxtx_queue_port =
2816         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, port, "port");
2817 cmdline_parse_token_num_t cmd_setup_rxtx_queue_portid =
2818         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, portid, UINT16);
2819 cmdline_parse_token_string_t cmd_setup_rxtx_queue_rxtxq =
2820         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, rxtxq, "rxq#txq");
2821 cmdline_parse_token_num_t cmd_setup_rxtx_queue_qid =
2822         TOKEN_NUM_INITIALIZER(struct cmd_setup_rxtx_queue, qid, UINT16);
2823 cmdline_parse_token_string_t cmd_setup_rxtx_queue_setup =
2824         TOKEN_STRING_INITIALIZER(struct cmd_setup_rxtx_queue, setup, "setup");
2825
2826 static void
2827 cmd_setup_rxtx_queue_parsed(
2828         void *parsed_result,
2829         __rte_unused struct cmdline *cl,
2830         __rte_unused void *data)
2831 {
2832         struct cmd_setup_rxtx_queue *res = parsed_result;
2833         struct rte_port *port;
2834         struct rte_mempool *mp;
2835         unsigned int socket_id;
2836         uint8_t isrx = 0;
2837         int ret;
2838
2839         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2840                 return;
2841
2842         if (res->portid == (portid_t)RTE_PORT_ALL) {
2843                 printf("Invalid port id\n");
2844                 return;
2845         }
2846
2847         if (!strcmp(res->rxtxq, "rxq"))
2848                 isrx = 1;
2849         else if (!strcmp(res->rxtxq, "txq"))
2850                 isrx = 0;
2851         else {
2852                 printf("Unknown parameter\n");
2853                 return;
2854         }
2855
2856         if (isrx && rx_queue_id_is_invalid(res->qid)) {
2857                 printf("Invalid rx queue\n");
2858                 return;
2859         } else if (!isrx && tx_queue_id_is_invalid(res->qid)) {
2860                 printf("Invalid tx queue\n");
2861                 return;
2862         }
2863
2864         port = &ports[res->portid];
2865         if (isrx) {
2866                 socket_id = rxring_numa[res->portid];
2867                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2868                         socket_id = port->socket_id;
2869
2870                 mp = mbuf_pool_find(socket_id, 0);
2871                 if (mp == NULL) {
2872                         printf("Failed to setup RX queue: "
2873                                 "No mempool allocation"
2874                                 " on the socket %d\n",
2875                                 rxring_numa[res->portid]);
2876                         return;
2877                 }
2878                 ret = rx_queue_setup(res->portid,
2879                                      res->qid,
2880                                      port->nb_rx_desc[res->qid],
2881                                      socket_id,
2882                                      &port->rx_conf[res->qid],
2883                                      mp);
2884                 if (ret)
2885                         printf("Failed to setup RX queue\n");
2886         } else {
2887                 socket_id = txring_numa[res->portid];
2888                 if (!numa_support || socket_id == NUMA_NO_CONFIG)
2889                         socket_id = port->socket_id;
2890
2891                 ret = rte_eth_tx_queue_setup(res->portid,
2892                                              res->qid,
2893                                              port->nb_tx_desc[res->qid],
2894                                              socket_id,
2895                                              &port->tx_conf[res->qid]);
2896                 if (ret)
2897                         printf("Failed to setup TX queue\n");
2898         }
2899 }
2900
2901 cmdline_parse_inst_t cmd_setup_rxtx_queue = {
2902         .f = cmd_setup_rxtx_queue_parsed,
2903         .data = NULL,
2904         .help_str = "port <port_id> rxq|txq <queue_idx> setup",
2905         .tokens = {
2906                 (void *)&cmd_setup_rxtx_queue_port,
2907                 (void *)&cmd_setup_rxtx_queue_portid,
2908                 (void *)&cmd_setup_rxtx_queue_rxtxq,
2909                 (void *)&cmd_setup_rxtx_queue_qid,
2910                 (void *)&cmd_setup_rxtx_queue_setup,
2911                 NULL,
2912         },
2913 };
2914
2915
2916 /* *** Configure RSS RETA *** */
2917 struct cmd_config_rss_reta {
2918         cmdline_fixed_string_t port;
2919         cmdline_fixed_string_t keyword;
2920         portid_t port_id;
2921         cmdline_fixed_string_t name;
2922         cmdline_fixed_string_t list_name;
2923         cmdline_fixed_string_t list_of_items;
2924 };
2925
2926 static int
2927 parse_reta_config(const char *str,
2928                   struct rte_eth_rss_reta_entry64 *reta_conf,
2929                   uint16_t nb_entries)
2930 {
2931         int i;
2932         unsigned size;
2933         uint16_t hash_index, idx, shift;
2934         uint16_t nb_queue;
2935         char s[256];
2936         const char *p, *p0 = str;
2937         char *end;
2938         enum fieldnames {
2939                 FLD_HASH_INDEX = 0,
2940                 FLD_QUEUE,
2941                 _NUM_FLD
2942         };
2943         unsigned long int_fld[_NUM_FLD];
2944         char *str_fld[_NUM_FLD];
2945
2946         while ((p = strchr(p0,'(')) != NULL) {
2947                 ++p;
2948                 if((p0 = strchr(p,')')) == NULL)
2949                         return -1;
2950
2951                 size = p0 - p;
2952                 if(size >= sizeof(s))
2953                         return -1;
2954
2955                 snprintf(s, sizeof(s), "%.*s", size, p);
2956                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2957                         return -1;
2958                 for (i = 0; i < _NUM_FLD; i++) {
2959                         errno = 0;
2960                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2961                         if (errno != 0 || end == str_fld[i] ||
2962                                         int_fld[i] > 65535)
2963                                 return -1;
2964                 }
2965
2966                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2967                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2968
2969                 if (hash_index >= nb_entries) {
2970                         printf("Invalid RETA hash index=%d\n", hash_index);
2971                         return -1;
2972                 }
2973
2974                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2975                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2976                 reta_conf[idx].mask |= (1ULL << shift);
2977                 reta_conf[idx].reta[shift] = nb_queue;
2978         }
2979
2980         return 0;
2981 }
2982
2983 static void
2984 cmd_set_rss_reta_parsed(void *parsed_result,
2985                         __rte_unused struct cmdline *cl,
2986                         __rte_unused void *data)
2987 {
2988         int ret;
2989         struct rte_eth_dev_info dev_info;
2990         struct rte_eth_rss_reta_entry64 reta_conf[8];
2991         struct cmd_config_rss_reta *res = parsed_result;
2992
2993         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
2994         if (ret != 0)
2995                 return;
2996
2997         if (dev_info.reta_size == 0) {
2998                 printf("Redirection table size is 0 which is "
2999                                         "invalid for RSS\n");
3000                 return;
3001         } else
3002                 printf("The reta size of port %d is %u\n",
3003                         res->port_id, dev_info.reta_size);
3004         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
3005                 printf("Currently do not support more than %u entries of "
3006                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
3007                 return;
3008         }
3009
3010         memset(reta_conf, 0, sizeof(reta_conf));
3011         if (!strcmp(res->list_name, "reta")) {
3012                 if (parse_reta_config(res->list_of_items, reta_conf,
3013                                                 dev_info.reta_size)) {
3014                         printf("Invalid RSS Redirection Table "
3015                                         "config entered\n");
3016                         return;
3017                 }
3018                 ret = rte_eth_dev_rss_reta_update(res->port_id,
3019                                 reta_conf, dev_info.reta_size);
3020                 if (ret != 0)
3021                         printf("Bad redirection table parameter, "
3022                                         "return code = %d \n", ret);
3023         }
3024 }
3025
3026 cmdline_parse_token_string_t cmd_config_rss_reta_port =
3027         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
3028 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
3029         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
3030 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
3031         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
3032 cmdline_parse_token_string_t cmd_config_rss_reta_name =
3033         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
3034 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
3035         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
3036 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
3037         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
3038                                  NULL);
3039 cmdline_parse_inst_t cmd_config_rss_reta = {
3040         .f = cmd_set_rss_reta_parsed,
3041         .data = NULL,
3042         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
3043         .tokens = {
3044                 (void *)&cmd_config_rss_reta_port,
3045                 (void *)&cmd_config_rss_reta_keyword,
3046                 (void *)&cmd_config_rss_reta_port_id,
3047                 (void *)&cmd_config_rss_reta_name,
3048                 (void *)&cmd_config_rss_reta_list_name,
3049                 (void *)&cmd_config_rss_reta_list_of_items,
3050                 NULL,
3051         },
3052 };
3053
3054 /* *** SHOW PORT RETA INFO *** */
3055 struct cmd_showport_reta {
3056         cmdline_fixed_string_t show;
3057         cmdline_fixed_string_t port;
3058         portid_t port_id;
3059         cmdline_fixed_string_t rss;
3060         cmdline_fixed_string_t reta;
3061         uint16_t size;
3062         cmdline_fixed_string_t list_of_items;
3063 };
3064
3065 static int
3066 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
3067                            uint16_t nb_entries,
3068                            char *str)
3069 {
3070         uint32_t size;
3071         const char *p, *p0 = str;
3072         char s[256];
3073         char *end;
3074         char *str_fld[8];
3075         uint16_t i;
3076         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
3077                         RTE_RETA_GROUP_SIZE;
3078         int ret;
3079
3080         p = strchr(p0, '(');
3081         if (p == NULL)
3082                 return -1;
3083         p++;
3084         p0 = strchr(p, ')');
3085         if (p0 == NULL)
3086                 return -1;
3087         size = p0 - p;
3088         if (size >= sizeof(s)) {
3089                 printf("The string size exceeds the internal buffer size\n");
3090                 return -1;
3091         }
3092         snprintf(s, sizeof(s), "%.*s", size, p);
3093         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
3094         if (ret <= 0 || ret != num) {
3095                 printf("The bits of masks do not match the number of "
3096                                         "reta entries: %u\n", num);
3097                 return -1;
3098         }
3099         for (i = 0; i < ret; i++)
3100                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
3101
3102         return 0;
3103 }
3104
3105 static void
3106 cmd_showport_reta_parsed(void *parsed_result,
3107                          __rte_unused struct cmdline *cl,
3108                          __rte_unused void *data)
3109 {
3110         struct cmd_showport_reta *res = parsed_result;
3111         struct rte_eth_rss_reta_entry64 reta_conf[8];
3112         struct rte_eth_dev_info dev_info;
3113         uint16_t max_reta_size;
3114         int ret;
3115
3116         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
3117         if (ret != 0)
3118                 return;
3119
3120         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
3121         if (res->size == 0 || res->size > max_reta_size) {
3122                 printf("Invalid redirection table size: %u (1-%u)\n",
3123                         res->size, max_reta_size);
3124                 return;
3125         }
3126
3127         memset(reta_conf, 0, sizeof(reta_conf));
3128         if (showport_parse_reta_config(reta_conf, res->size,
3129                                 res->list_of_items) < 0) {
3130                 printf("Invalid string: %s for reta masks\n",
3131                                         res->list_of_items);
3132                 return;
3133         }
3134         port_rss_reta_info(res->port_id, reta_conf, res->size);
3135 }
3136
3137 cmdline_parse_token_string_t cmd_showport_reta_show =
3138         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
3139 cmdline_parse_token_string_t cmd_showport_reta_port =
3140         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
3141 cmdline_parse_token_num_t cmd_showport_reta_port_id =
3142         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
3143 cmdline_parse_token_string_t cmd_showport_reta_rss =
3144         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
3145 cmdline_parse_token_string_t cmd_showport_reta_reta =
3146         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
3147 cmdline_parse_token_num_t cmd_showport_reta_size =
3148         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
3149 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
3150         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
3151                                         list_of_items, NULL);
3152
3153 cmdline_parse_inst_t cmd_showport_reta = {
3154         .f = cmd_showport_reta_parsed,
3155         .data = NULL,
3156         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
3157         .tokens = {
3158                 (void *)&cmd_showport_reta_show,
3159                 (void *)&cmd_showport_reta_port,
3160                 (void *)&cmd_showport_reta_port_id,
3161                 (void *)&cmd_showport_reta_rss,
3162                 (void *)&cmd_showport_reta_reta,
3163                 (void *)&cmd_showport_reta_size,
3164                 (void *)&cmd_showport_reta_list_of_items,
3165                 NULL,
3166         },
3167 };
3168
3169 /* *** Show RSS hash configuration *** */
3170 struct cmd_showport_rss_hash {
3171         cmdline_fixed_string_t show;
3172         cmdline_fixed_string_t port;
3173         portid_t port_id;
3174         cmdline_fixed_string_t rss_hash;
3175         cmdline_fixed_string_t rss_type;
3176         cmdline_fixed_string_t key; /* optional argument */
3177 };
3178
3179 static void cmd_showport_rss_hash_parsed(void *parsed_result,
3180                                 __rte_unused struct cmdline *cl,
3181                                 void *show_rss_key)
3182 {
3183         struct cmd_showport_rss_hash *res = parsed_result;
3184
3185         port_rss_hash_conf_show(res->port_id, show_rss_key != NULL);
3186 }
3187
3188 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
3189         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
3190 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
3191         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
3192 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
3193         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
3194 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
3195         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
3196                                  "rss-hash");
3197 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
3198         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
3199
3200 cmdline_parse_inst_t cmd_showport_rss_hash = {
3201         .f = cmd_showport_rss_hash_parsed,
3202         .data = NULL,
3203         .help_str = "show port <port_id> rss-hash",
3204         .tokens = {
3205                 (void *)&cmd_showport_rss_hash_show,
3206                 (void *)&cmd_showport_rss_hash_port,
3207                 (void *)&cmd_showport_rss_hash_port_id,
3208                 (void *)&cmd_showport_rss_hash_rss_hash,
3209                 NULL,
3210         },
3211 };
3212
3213 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
3214         .f = cmd_showport_rss_hash_parsed,
3215         .data = (void *)1,
3216         .help_str = "show port <port_id> rss-hash key",
3217         .tokens = {
3218                 (void *)&cmd_showport_rss_hash_show,
3219                 (void *)&cmd_showport_rss_hash_port,
3220                 (void *)&cmd_showport_rss_hash_port_id,
3221                 (void *)&cmd_showport_rss_hash_rss_hash,
3222                 (void *)&cmd_showport_rss_hash_rss_key,
3223                 NULL,
3224         },
3225 };
3226
3227 /* *** Configure DCB *** */
3228 struct cmd_config_dcb {
3229         cmdline_fixed_string_t port;
3230         cmdline_fixed_string_t config;
3231         portid_t port_id;
3232         cmdline_fixed_string_t dcb;
3233         cmdline_fixed_string_t vt;
3234         cmdline_fixed_string_t vt_en;
3235         uint8_t num_tcs;
3236         cmdline_fixed_string_t pfc;
3237         cmdline_fixed_string_t pfc_en;
3238 };
3239
3240 static void
3241 cmd_config_dcb_parsed(void *parsed_result,
3242                         __rte_unused struct cmdline *cl,
3243                         __rte_unused void *data)
3244 {
3245         struct cmd_config_dcb *res = parsed_result;
3246         portid_t port_id = res->port_id;
3247         struct rte_port *port;
3248         uint8_t pfc_en;
3249         int ret;
3250
3251         port = &ports[port_id];
3252         /** Check if the port is not started **/
3253         if (port->port_status != RTE_PORT_STOPPED) {
3254                 printf("Please stop port %d first\n", port_id);
3255                 return;
3256         }
3257
3258         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
3259                 printf("The invalid number of traffic class,"
3260                         " only 4 or 8 allowed.\n");
3261                 return;
3262         }
3263
3264         if (nb_fwd_lcores < res->num_tcs) {
3265                 printf("nb_cores shouldn't be less than number of TCs.\n");
3266                 return;
3267         }
3268         if (!strncmp(res->pfc_en, "on", 2))
3269                 pfc_en = 1;
3270         else
3271                 pfc_en = 0;
3272
3273         /* DCB in VT mode */
3274         if (!strncmp(res->vt_en, "on", 2))
3275                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
3276                                 (enum rte_eth_nb_tcs)res->num_tcs,
3277                                 pfc_en);
3278         else
3279                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
3280                                 (enum rte_eth_nb_tcs)res->num_tcs,
3281                                 pfc_en);
3282
3283
3284         if (ret != 0) {
3285                 printf("Cannot initialize network ports.\n");
3286                 return;
3287         }
3288
3289         cmd_reconfig_device_queue(port_id, 1, 1);
3290 }
3291
3292 cmdline_parse_token_string_t cmd_config_dcb_port =
3293         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
3294 cmdline_parse_token_string_t cmd_config_dcb_config =
3295         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
3296 cmdline_parse_token_num_t cmd_config_dcb_port_id =
3297         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
3298 cmdline_parse_token_string_t cmd_config_dcb_dcb =
3299         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
3300 cmdline_parse_token_string_t cmd_config_dcb_vt =
3301         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
3302 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
3303         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
3304 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
3305         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
3306 cmdline_parse_token_string_t cmd_config_dcb_pfc=
3307         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
3308 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
3309         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
3310
3311 cmdline_parse_inst_t cmd_config_dcb = {
3312         .f = cmd_config_dcb_parsed,
3313         .data = NULL,
3314         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
3315         .tokens = {
3316                 (void *)&cmd_config_dcb_port,
3317                 (void *)&cmd_config_dcb_config,
3318                 (void *)&cmd_config_dcb_port_id,
3319                 (void *)&cmd_config_dcb_dcb,
3320                 (void *)&cmd_config_dcb_vt,
3321                 (void *)&cmd_config_dcb_vt_en,
3322                 (void *)&cmd_config_dcb_num_tcs,
3323                 (void *)&cmd_config_dcb_pfc,
3324                 (void *)&cmd_config_dcb_pfc_en,
3325                 NULL,
3326         },
3327 };
3328
3329 /* *** configure number of packets per burst *** */
3330 struct cmd_config_burst {
3331         cmdline_fixed_string_t port;
3332         cmdline_fixed_string_t keyword;
3333         cmdline_fixed_string_t all;
3334         cmdline_fixed_string_t name;
3335         uint16_t value;
3336 };
3337
3338 static void
3339 cmd_config_burst_parsed(void *parsed_result,
3340                         __rte_unused struct cmdline *cl,
3341                         __rte_unused void *data)
3342 {
3343         struct cmd_config_burst *res = parsed_result;
3344         struct rte_eth_dev_info dev_info;
3345         uint16_t rec_nb_pkts;
3346         int ret;
3347
3348         if (!all_ports_stopped()) {
3349                 printf("Please stop all ports first\n");
3350                 return;
3351         }
3352
3353         if (!strcmp(res->name, "burst")) {
3354                 if (res->value == 0) {
3355                         /* If user gives a value of zero, query the PMD for
3356                          * its recommended Rx burst size. Testpmd uses a single
3357                          * size for all ports, so assume all ports are the same
3358                          * NIC model and use the values from Port 0.
3359                          */
3360                         ret = eth_dev_info_get_print_err(0, &dev_info);
3361                         if (ret != 0)
3362                                 return;
3363
3364                         rec_nb_pkts = dev_info.default_rxportconf.burst_size;
3365
3366                         if (rec_nb_pkts == 0) {
3367                                 printf("PMD does not recommend a burst size.\n"
3368                                         "User provided value must be between"
3369                                         " 1 and %d\n", MAX_PKT_BURST);
3370                                 return;
3371                         } else if (rec_nb_pkts > MAX_PKT_BURST) {
3372                                 printf("PMD recommended burst size of %d"
3373                                         " exceeds maximum value of %d\n",
3374                                         rec_nb_pkts, MAX_PKT_BURST);
3375                                 return;
3376                         }
3377                         printf("Using PMD-provided burst value of %d\n",
3378                                 rec_nb_pkts);
3379                         nb_pkt_per_burst = rec_nb_pkts;
3380                 } else if (res->value > MAX_PKT_BURST) {
3381                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
3382                         return;
3383                 } else
3384                         nb_pkt_per_burst = res->value;
3385         } else {
3386                 printf("Unknown parameter\n");
3387                 return;
3388         }
3389
3390         init_port_config();
3391
3392         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3393 }
3394
3395 cmdline_parse_token_string_t cmd_config_burst_port =
3396         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
3397 cmdline_parse_token_string_t cmd_config_burst_keyword =
3398         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
3399 cmdline_parse_token_string_t cmd_config_burst_all =
3400         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
3401 cmdline_parse_token_string_t cmd_config_burst_name =
3402         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
3403 cmdline_parse_token_num_t cmd_config_burst_value =
3404         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
3405
3406 cmdline_parse_inst_t cmd_config_burst = {
3407         .f = cmd_config_burst_parsed,
3408         .data = NULL,
3409         .help_str = "port config all burst <value>",
3410         .tokens = {
3411                 (void *)&cmd_config_burst_port,
3412                 (void *)&cmd_config_burst_keyword,
3413                 (void *)&cmd_config_burst_all,
3414                 (void *)&cmd_config_burst_name,
3415                 (void *)&cmd_config_burst_value,
3416                 NULL,
3417         },
3418 };
3419
3420 /* *** configure rx/tx queues *** */
3421 struct cmd_config_thresh {
3422         cmdline_fixed_string_t port;
3423         cmdline_fixed_string_t keyword;
3424         cmdline_fixed_string_t all;
3425         cmdline_fixed_string_t name;
3426         uint8_t value;
3427 };
3428
3429 static void
3430 cmd_config_thresh_parsed(void *parsed_result,
3431                         __rte_unused struct cmdline *cl,
3432                         __rte_unused void *data)
3433 {
3434         struct cmd_config_thresh *res = parsed_result;
3435
3436         if (!all_ports_stopped()) {
3437                 printf("Please stop all ports first\n");
3438                 return;
3439         }
3440
3441         if (!strcmp(res->name, "txpt"))
3442                 tx_pthresh = res->value;
3443         else if(!strcmp(res->name, "txht"))
3444                 tx_hthresh = res->value;
3445         else if(!strcmp(res->name, "txwt"))
3446                 tx_wthresh = res->value;
3447         else if(!strcmp(res->name, "rxpt"))
3448                 rx_pthresh = res->value;
3449         else if(!strcmp(res->name, "rxht"))
3450                 rx_hthresh = res->value;
3451         else if(!strcmp(res->name, "rxwt"))
3452                 rx_wthresh = res->value;
3453         else {
3454                 printf("Unknown parameter\n");
3455                 return;
3456         }
3457
3458         init_port_config();
3459
3460         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3461 }
3462
3463 cmdline_parse_token_string_t cmd_config_thresh_port =
3464         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
3465 cmdline_parse_token_string_t cmd_config_thresh_keyword =
3466         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
3467 cmdline_parse_token_string_t cmd_config_thresh_all =
3468         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
3469 cmdline_parse_token_string_t cmd_config_thresh_name =
3470         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
3471                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
3472 cmdline_parse_token_num_t cmd_config_thresh_value =
3473         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
3474
3475 cmdline_parse_inst_t cmd_config_thresh = {
3476         .f = cmd_config_thresh_parsed,
3477         .data = NULL,
3478         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
3479         .tokens = {
3480                 (void *)&cmd_config_thresh_port,
3481                 (void *)&cmd_config_thresh_keyword,
3482                 (void *)&cmd_config_thresh_all,
3483                 (void *)&cmd_config_thresh_name,
3484                 (void *)&cmd_config_thresh_value,
3485                 NULL,
3486         },
3487 };
3488
3489 /* *** configure free/rs threshold *** */
3490 struct cmd_config_threshold {
3491         cmdline_fixed_string_t port;
3492         cmdline_fixed_string_t keyword;
3493         cmdline_fixed_string_t all;
3494         cmdline_fixed_string_t name;
3495         uint16_t value;
3496 };
3497
3498 static void
3499 cmd_config_threshold_parsed(void *parsed_result,
3500                         __rte_unused struct cmdline *cl,
3501                         __rte_unused void *data)
3502 {
3503         struct cmd_config_threshold *res = parsed_result;
3504
3505         if (!all_ports_stopped()) {
3506                 printf("Please stop all ports first\n");
3507                 return;
3508         }
3509
3510         if (!strcmp(res->name, "txfreet"))
3511                 tx_free_thresh = res->value;
3512         else if (!strcmp(res->name, "txrst"))
3513                 tx_rs_thresh = res->value;
3514         else if (!strcmp(res->name, "rxfreet"))
3515                 rx_free_thresh = res->value;
3516         else {
3517                 printf("Unknown parameter\n");
3518                 return;
3519         }
3520
3521         init_port_config();
3522
3523         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3524 }
3525
3526 cmdline_parse_token_string_t cmd_config_threshold_port =
3527         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
3528 cmdline_parse_token_string_t cmd_config_threshold_keyword =
3529         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
3530                                                                 "config");
3531 cmdline_parse_token_string_t cmd_config_threshold_all =
3532         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
3533 cmdline_parse_token_string_t cmd_config_threshold_name =
3534         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
3535                                                 "txfreet#txrst#rxfreet");
3536 cmdline_parse_token_num_t cmd_config_threshold_value =
3537         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
3538
3539 cmdline_parse_inst_t cmd_config_threshold = {
3540         .f = cmd_config_threshold_parsed,
3541         .data = NULL,
3542         .help_str = "port config all txfreet|txrst|rxfreet <value>",
3543         .tokens = {
3544                 (void *)&cmd_config_threshold_port,
3545                 (void *)&cmd_config_threshold_keyword,
3546                 (void *)&cmd_config_threshold_all,
3547                 (void *)&cmd_config_threshold_name,
3548                 (void *)&cmd_config_threshold_value,
3549                 NULL,
3550         },
3551 };
3552
3553 /* *** stop *** */
3554 struct cmd_stop_result {
3555         cmdline_fixed_string_t stop;
3556 };
3557
3558 static void cmd_stop_parsed(__rte_unused void *parsed_result,
3559                             __rte_unused struct cmdline *cl,
3560                             __rte_unused void *data)
3561 {
3562         stop_packet_forwarding();
3563 }
3564
3565 cmdline_parse_token_string_t cmd_stop_stop =
3566         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
3567
3568 cmdline_parse_inst_t cmd_stop = {
3569         .f = cmd_stop_parsed,
3570         .data = NULL,
3571         .help_str = "stop: Stop packet forwarding",
3572         .tokens = {
3573                 (void *)&cmd_stop_stop,
3574                 NULL,
3575         },
3576 };
3577
3578 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
3579
3580 unsigned int
3581 parse_item_list(char* str, const char* item_name, unsigned int max_items,
3582                 unsigned int *parsed_items, int check_unique_values)
3583 {
3584         unsigned int nb_item;
3585         unsigned int value;
3586         unsigned int i;
3587         unsigned int j;
3588         int value_ok;
3589         char c;
3590
3591         /*
3592          * First parse all items in the list and store their value.
3593          */
3594         value = 0;
3595         nb_item = 0;
3596         value_ok = 0;
3597         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
3598                 c = str[i];
3599                 if ((c >= '0') && (c <= '9')) {
3600                         value = (unsigned int) (value * 10 + (c - '0'));
3601                         value_ok = 1;
3602                         continue;
3603                 }
3604                 if (c != ',') {
3605                         printf("character %c is not a decimal digit\n", c);
3606                         return 0;
3607                 }
3608                 if (! value_ok) {
3609                         printf("No valid value before comma\n");
3610                         return 0;
3611                 }
3612                 if (nb_item < max_items) {
3613                         parsed_items[nb_item] = value;
3614                         value_ok = 0;
3615                         value = 0;
3616                 }
3617                 nb_item++;
3618         }
3619         if (nb_item >= max_items) {
3620                 printf("Number of %s = %u > %u (maximum items)\n",
3621                        item_name, nb_item + 1, max_items);
3622                 return 0;
3623         }
3624         parsed_items[nb_item++] = value;
3625         if (! check_unique_values)
3626                 return nb_item;
3627
3628         /*
3629          * Then, check that all values in the list are differents.
3630          * No optimization here...
3631          */
3632         for (i = 0; i < nb_item; i++) {
3633                 for (j = i + 1; j < nb_item; j++) {
3634                         if (parsed_items[j] == parsed_items[i]) {
3635                                 printf("duplicated %s %u at index %u and %u\n",
3636                                        item_name, parsed_items[i], i, j);
3637                                 return 0;
3638                         }
3639                 }
3640         }
3641         return nb_item;
3642 }
3643
3644 struct cmd_set_list_result {
3645         cmdline_fixed_string_t cmd_keyword;
3646         cmdline_fixed_string_t list_name;
3647         cmdline_fixed_string_t list_of_items;
3648 };
3649
3650 static void cmd_set_list_parsed(void *parsed_result,
3651                                 __rte_unused struct cmdline *cl,
3652                                 __rte_unused void *data)
3653 {
3654         struct cmd_set_list_result *res;
3655         union {
3656                 unsigned int lcorelist[RTE_MAX_LCORE];
3657                 unsigned int portlist[RTE_MAX_ETHPORTS];
3658         } parsed_items;
3659         unsigned int nb_item;
3660
3661         if (test_done == 0) {
3662                 printf("Please stop forwarding first\n");
3663                 return;
3664         }
3665
3666         res = parsed_result;
3667         if (!strcmp(res->list_name, "corelist")) {
3668                 nb_item = parse_item_list(res->list_of_items, "core",
3669                                           RTE_MAX_LCORE,
3670                                           parsed_items.lcorelist, 1);
3671                 if (nb_item > 0) {
3672                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
3673                         fwd_config_setup();
3674                 }
3675                 return;
3676         }
3677         if (!strcmp(res->list_name, "portlist")) {
3678                 nb_item = parse_item_list(res->list_of_items, "port",
3679                                           RTE_MAX_ETHPORTS,
3680                                           parsed_items.portlist, 1);
3681                 if (nb_item > 0) {
3682                         set_fwd_ports_list(parsed_items.portlist, nb_item);
3683                         fwd_config_setup();
3684                 }
3685         }
3686 }
3687
3688 cmdline_parse_token_string_t cmd_set_list_keyword =
3689         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
3690                                  "set");
3691 cmdline_parse_token_string_t cmd_set_list_name =
3692         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
3693                                  "corelist#portlist");
3694 cmdline_parse_token_string_t cmd_set_list_of_items =
3695         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
3696                                  NULL);
3697
3698 cmdline_parse_inst_t cmd_set_fwd_list = {
3699         .f = cmd_set_list_parsed,
3700         .data = NULL,
3701         .help_str = "set corelist|portlist <list0[,list1]*>",
3702         .tokens = {
3703                 (void *)&cmd_set_list_keyword,
3704                 (void *)&cmd_set_list_name,
3705                 (void *)&cmd_set_list_of_items,
3706                 NULL,
3707         },
3708 };
3709
3710 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
3711
3712 struct cmd_setmask_result {
3713         cmdline_fixed_string_t set;
3714         cmdline_fixed_string_t mask;
3715         uint64_t hexavalue;
3716 };
3717
3718 static void cmd_set_mask_parsed(void *parsed_result,
3719                                 __rte_unused struct cmdline *cl,
3720                                 __rte_unused void *data)
3721 {
3722         struct cmd_setmask_result *res = parsed_result;
3723
3724         if (test_done == 0) {
3725                 printf("Please stop forwarding first\n");
3726                 return;
3727         }
3728         if (!strcmp(res->mask, "coremask")) {
3729                 set_fwd_lcores_mask(res->hexavalue);
3730                 fwd_config_setup();
3731         } else if (!strcmp(res->mask, "portmask")) {
3732                 set_fwd_ports_mask(res->hexavalue);
3733                 fwd_config_setup();
3734         }
3735 }
3736
3737 cmdline_parse_token_string_t cmd_setmask_set =
3738         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
3739 cmdline_parse_token_string_t cmd_setmask_mask =
3740         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
3741                                  "coremask#portmask");
3742 cmdline_parse_token_num_t cmd_setmask_value =
3743         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
3744
3745 cmdline_parse_inst_t cmd_set_fwd_mask = {
3746         .f = cmd_set_mask_parsed,
3747         .data = NULL,
3748         .help_str = "set coremask|portmask <hexadecimal value>",
3749         .tokens = {
3750                 (void *)&cmd_setmask_set,
3751                 (void *)&cmd_setmask_mask,
3752                 (void *)&cmd_setmask_value,
3753                 NULL,
3754         },
3755 };
3756
3757 /*
3758  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
3759  */
3760 struct cmd_set_result {
3761         cmdline_fixed_string_t set;
3762         cmdline_fixed_string_t what;
3763         uint16_t value;
3764 };
3765
3766 static void cmd_set_parsed(void *parsed_result,
3767                            __rte_unused struct cmdline *cl,
3768                            __rte_unused void *data)
3769 {
3770         struct cmd_set_result *res = parsed_result;
3771         if (!strcmp(res->what, "nbport")) {
3772                 set_fwd_ports_number(res->value);
3773                 fwd_config_setup();
3774         } else if (!strcmp(res->what, "nbcore")) {
3775                 set_fwd_lcores_number(res->value);
3776                 fwd_config_setup();
3777         } else if (!strcmp(res->what, "burst"))
3778                 set_nb_pkt_per_burst(res->value);
3779         else if (!strcmp(res->what, "verbose"))
3780                 set_verbose_level(res->value);
3781 }
3782
3783 cmdline_parse_token_string_t cmd_set_set =
3784         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3785 cmdline_parse_token_string_t cmd_set_what =
3786         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3787                                  "nbport#nbcore#burst#verbose");
3788 cmdline_parse_token_num_t cmd_set_value =
3789         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3790
3791 cmdline_parse_inst_t cmd_set_numbers = {
3792         .f = cmd_set_parsed,
3793         .data = NULL,
3794         .help_str = "set nbport|nbcore|burst|verbose <value>",
3795         .tokens = {
3796                 (void *)&cmd_set_set,
3797                 (void *)&cmd_set_what,
3798                 (void *)&cmd_set_value,
3799                 NULL,
3800         },
3801 };
3802
3803 /* *** SET LOG LEVEL CONFIGURATION *** */
3804
3805 struct cmd_set_log_result {
3806         cmdline_fixed_string_t set;
3807         cmdline_fixed_string_t log;
3808         cmdline_fixed_string_t type;
3809         uint32_t level;
3810 };
3811
3812 static void
3813 cmd_set_log_parsed(void *parsed_result,
3814                    __rte_unused struct cmdline *cl,
3815                    __rte_unused void *data)
3816 {
3817         struct cmd_set_log_result *res;
3818         int ret;
3819
3820         res = parsed_result;
3821         if (!strcmp(res->type, "global"))
3822                 rte_log_set_global_level(res->level);
3823         else {
3824                 ret = rte_log_set_level_regexp(res->type, res->level);
3825                 if (ret < 0)
3826                         printf("Unable to set log level\n");
3827         }
3828 }
3829
3830 cmdline_parse_token_string_t cmd_set_log_set =
3831         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set");
3832 cmdline_parse_token_string_t cmd_set_log_log =
3833         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log");
3834 cmdline_parse_token_string_t cmd_set_log_type =
3835         TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL);
3836 cmdline_parse_token_num_t cmd_set_log_level =
3837         TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32);
3838
3839 cmdline_parse_inst_t cmd_set_log = {
3840         .f = cmd_set_log_parsed,
3841         .data = NULL,
3842         .help_str = "set log global|<type> <level>",
3843         .tokens = {
3844                 (void *)&cmd_set_log_set,
3845                 (void *)&cmd_set_log_log,
3846                 (void *)&cmd_set_log_type,
3847                 (void *)&cmd_set_log_level,
3848                 NULL,
3849         },
3850 };
3851
3852 /* *** SET SEGMENT OFFSETS OF RX PACKETS SPLIT *** */
3853
3854 struct cmd_set_rxoffs_result {
3855         cmdline_fixed_string_t cmd_keyword;
3856         cmdline_fixed_string_t rxoffs;
3857         cmdline_fixed_string_t seg_offsets;
3858 };
3859
3860 static void
3861 cmd_set_rxoffs_parsed(void *parsed_result,
3862                       __rte_unused struct cmdline *cl,
3863                       __rte_unused void *data)
3864 {
3865         struct cmd_set_rxoffs_result *res;
3866         unsigned int seg_offsets[MAX_SEGS_BUFFER_SPLIT];
3867         unsigned int nb_segs;
3868
3869         res = parsed_result;
3870         nb_segs = parse_item_list(res->seg_offsets, "segment offsets",
3871                                   MAX_SEGS_BUFFER_SPLIT, seg_offsets, 0);
3872         if (nb_segs > 0)
3873                 set_rx_pkt_offsets(seg_offsets, nb_segs);
3874 }
3875
3876 cmdline_parse_token_string_t cmd_set_rxoffs_keyword =
3877         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3878                                  cmd_keyword, "set");
3879 cmdline_parse_token_string_t cmd_set_rxoffs_name =
3880         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3881                                  rxoffs, "rxoffs");
3882 cmdline_parse_token_string_t cmd_set_rxoffs_offsets =
3883         TOKEN_STRING_INITIALIZER(struct cmd_set_rxoffs_result,
3884                                  seg_offsets, NULL);
3885
3886 cmdline_parse_inst_t cmd_set_rxoffs = {
3887         .f = cmd_set_rxoffs_parsed,
3888         .data = NULL,
3889         .help_str = "set rxoffs <len0[,len1]*>",
3890         .tokens = {
3891                 (void *)&cmd_set_rxoffs_keyword,
3892                 (void *)&cmd_set_rxoffs_name,
3893                 (void *)&cmd_set_rxoffs_offsets,
3894                 NULL,
3895         },
3896 };
3897
3898 /* *** SET SEGMENT LENGTHS OF RX PACKETS SPLIT *** */
3899
3900 struct cmd_set_rxpkts_result {
3901         cmdline_fixed_string_t cmd_keyword;
3902         cmdline_fixed_string_t rxpkts;
3903         cmdline_fixed_string_t seg_lengths;
3904 };
3905
3906 static void
3907 cmd_set_rxpkts_parsed(void *parsed_result,
3908                       __rte_unused struct cmdline *cl,
3909                       __rte_unused void *data)
3910 {
3911         struct cmd_set_rxpkts_result *res;
3912         unsigned int seg_lengths[MAX_SEGS_BUFFER_SPLIT];
3913         unsigned int nb_segs;
3914
3915         res = parsed_result;
3916         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3917                                   MAX_SEGS_BUFFER_SPLIT, seg_lengths, 0);
3918         if (nb_segs > 0)
3919                 set_rx_pkt_segments(seg_lengths, nb_segs);
3920 }
3921
3922 cmdline_parse_token_string_t cmd_set_rxpkts_keyword =
3923         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3924                                  cmd_keyword, "set");
3925 cmdline_parse_token_string_t cmd_set_rxpkts_name =
3926         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3927                                  rxpkts, "rxpkts");
3928 cmdline_parse_token_string_t cmd_set_rxpkts_lengths =
3929         TOKEN_STRING_INITIALIZER(struct cmd_set_rxpkts_result,
3930                                  seg_lengths, NULL);
3931
3932 cmdline_parse_inst_t cmd_set_rxpkts = {
3933         .f = cmd_set_rxpkts_parsed,
3934         .data = NULL,
3935         .help_str = "set rxpkts <len0[,len1]*>",
3936         .tokens = {
3937                 (void *)&cmd_set_rxpkts_keyword,
3938                 (void *)&cmd_set_rxpkts_name,
3939                 (void *)&cmd_set_rxpkts_lengths,
3940                 NULL,
3941         },
3942 };
3943
3944 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3945
3946 struct cmd_set_txpkts_result {
3947         cmdline_fixed_string_t cmd_keyword;
3948         cmdline_fixed_string_t txpkts;
3949         cmdline_fixed_string_t seg_lengths;
3950 };
3951
3952 static void
3953 cmd_set_txpkts_parsed(void *parsed_result,
3954                       __rte_unused struct cmdline *cl,
3955                       __rte_unused void *data)
3956 {
3957         struct cmd_set_txpkts_result *res;
3958         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3959         unsigned int nb_segs;
3960
3961         res = parsed_result;
3962         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3963                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3964         if (nb_segs > 0)
3965                 set_tx_pkt_segments(seg_lengths, nb_segs);
3966 }
3967
3968 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3969         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3970                                  cmd_keyword, "set");
3971 cmdline_parse_token_string_t cmd_set_txpkts_name =
3972         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3973                                  txpkts, "txpkts");
3974 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3975         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3976                                  seg_lengths, NULL);
3977
3978 cmdline_parse_inst_t cmd_set_txpkts = {
3979         .f = cmd_set_txpkts_parsed,
3980         .data = NULL,
3981         .help_str = "set txpkts <len0[,len1]*>",
3982         .tokens = {
3983                 (void *)&cmd_set_txpkts_keyword,
3984                 (void *)&cmd_set_txpkts_name,
3985                 (void *)&cmd_set_txpkts_lengths,
3986                 NULL,
3987         },
3988 };
3989
3990 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3991
3992 struct cmd_set_txsplit_result {
3993         cmdline_fixed_string_t cmd_keyword;
3994         cmdline_fixed_string_t txsplit;
3995         cmdline_fixed_string_t mode;
3996 };
3997
3998 static void
3999 cmd_set_txsplit_parsed(void *parsed_result,
4000                       __rte_unused struct cmdline *cl,
4001                       __rte_unused void *data)
4002 {
4003         struct cmd_set_txsplit_result *res;
4004
4005         res = parsed_result;
4006         set_tx_pkt_split(res->mode);
4007 }
4008
4009 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
4010         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4011                                  cmd_keyword, "set");
4012 cmdline_parse_token_string_t cmd_set_txsplit_name =
4013         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4014                                  txsplit, "txsplit");
4015 cmdline_parse_token_string_t cmd_set_txsplit_mode =
4016         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
4017                                  mode, NULL);
4018
4019 cmdline_parse_inst_t cmd_set_txsplit = {
4020         .f = cmd_set_txsplit_parsed,
4021         .data = NULL,
4022         .help_str = "set txsplit on|off|rand",
4023         .tokens = {
4024                 (void *)&cmd_set_txsplit_keyword,
4025                 (void *)&cmd_set_txsplit_name,
4026                 (void *)&cmd_set_txsplit_mode,
4027                 NULL,
4028         },
4029 };
4030
4031 /* *** SET TIMES FOR TXONLY PACKETS SCHEDULING ON TIMESTAMPS *** */
4032
4033 struct cmd_set_txtimes_result {
4034         cmdline_fixed_string_t cmd_keyword;
4035         cmdline_fixed_string_t txtimes;
4036         cmdline_fixed_string_t tx_times;
4037 };
4038
4039 static void
4040 cmd_set_txtimes_parsed(void *parsed_result,
4041                        __rte_unused struct cmdline *cl,
4042                        __rte_unused void *data)
4043 {
4044         struct cmd_set_txtimes_result *res;
4045         unsigned int tx_times[2] = {0, 0};
4046         unsigned int n_times;
4047
4048         res = parsed_result;
4049         n_times = parse_item_list(res->tx_times, "tx times",
4050                                   2, tx_times, 0);
4051         if (n_times == 2)
4052                 set_tx_pkt_times(tx_times);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_set_txtimes_keyword =
4056         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4057                                  cmd_keyword, "set");
4058 cmdline_parse_token_string_t cmd_set_txtimes_name =
4059         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4060                                  txtimes, "txtimes");
4061 cmdline_parse_token_string_t cmd_set_txtimes_value =
4062         TOKEN_STRING_INITIALIZER(struct cmd_set_txtimes_result,
4063                                  tx_times, NULL);
4064
4065 cmdline_parse_inst_t cmd_set_txtimes = {
4066         .f = cmd_set_txtimes_parsed,
4067         .data = NULL,
4068         .help_str = "set txtimes <inter_burst>,<intra_burst>",
4069         .tokens = {
4070                 (void *)&cmd_set_txtimes_keyword,
4071                 (void *)&cmd_set_txtimes_name,
4072                 (void *)&cmd_set_txtimes_value,
4073                 NULL,
4074         },
4075 };
4076
4077 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
4078 struct cmd_rx_vlan_filter_all_result {
4079         cmdline_fixed_string_t rx_vlan;
4080         cmdline_fixed_string_t what;
4081         cmdline_fixed_string_t all;
4082         portid_t port_id;
4083 };
4084
4085 static void
4086 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
4087                               __rte_unused struct cmdline *cl,
4088                               __rte_unused void *data)
4089 {
4090         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
4091
4092         if (!strcmp(res->what, "add"))
4093                 rx_vlan_all_filter_set(res->port_id, 1);
4094         else
4095                 rx_vlan_all_filter_set(res->port_id, 0);
4096 }
4097
4098 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
4099         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4100                                  rx_vlan, "rx_vlan");
4101 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
4102         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4103                                  what, "add#rm");
4104 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
4105         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4106                                  all, "all");
4107 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
4108         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
4109                               port_id, UINT16);
4110
4111 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
4112         .f = cmd_rx_vlan_filter_all_parsed,
4113         .data = NULL,
4114         .help_str = "rx_vlan add|rm all <port_id>: "
4115                 "Add/Remove all identifiers to/from the set of VLAN "
4116                 "identifiers filtered by a port",
4117         .tokens = {
4118                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
4119                 (void *)&cmd_rx_vlan_filter_all_what,
4120                 (void *)&cmd_rx_vlan_filter_all_all,
4121                 (void *)&cmd_rx_vlan_filter_all_portid,
4122                 NULL,
4123         },
4124 };
4125
4126 /* *** VLAN OFFLOAD SET ON A PORT *** */
4127 struct cmd_vlan_offload_result {
4128         cmdline_fixed_string_t vlan;
4129         cmdline_fixed_string_t set;
4130         cmdline_fixed_string_t vlan_type;
4131         cmdline_fixed_string_t what;
4132         cmdline_fixed_string_t on;
4133         cmdline_fixed_string_t port_id;
4134 };
4135
4136 static void
4137 cmd_vlan_offload_parsed(void *parsed_result,
4138                           __rte_unused struct cmdline *cl,
4139                           __rte_unused void *data)
4140 {
4141         int on;
4142         struct cmd_vlan_offload_result *res = parsed_result;
4143         char *str;
4144         int i, len = 0;
4145         portid_t port_id = 0;
4146         unsigned int tmp;
4147
4148         str = res->port_id;
4149         len = strnlen(str, STR_TOKEN_SIZE);
4150         i = 0;
4151         /* Get port_id first */
4152         while(i < len){
4153                 if(str[i] == ',')
4154                         break;
4155
4156                 i++;
4157         }
4158         str[i]='\0';
4159         tmp = strtoul(str, NULL, 0);
4160         /* If port_id greater that what portid_t can represent, return */
4161         if(tmp >= RTE_MAX_ETHPORTS)
4162                 return;
4163         port_id = (portid_t)tmp;
4164
4165         if (!strcmp(res->on, "on"))
4166                 on = 1;
4167         else
4168                 on = 0;
4169
4170         if (!strcmp(res->what, "strip"))
4171                 rx_vlan_strip_set(port_id,  on);
4172         else if(!strcmp(res->what, "stripq")){
4173                 uint16_t queue_id = 0;
4174
4175                 /* No queue_id, return */
4176                 if(i + 1 >= len) {
4177                         printf("must specify (port,queue_id)\n");
4178                         return;
4179                 }
4180                 tmp = strtoul(str + i + 1, NULL, 0);
4181                 /* If queue_id greater that what 16-bits can represent, return */
4182                 if(tmp > 0xffff)
4183                         return;
4184
4185                 queue_id = (uint16_t)tmp;
4186                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
4187         }
4188         else if (!strcmp(res->what, "filter"))
4189                 rx_vlan_filter_set(port_id, on);
4190         else if (!strcmp(res->what, "qinq_strip"))
4191                 rx_vlan_qinq_strip_set(port_id, on);
4192         else
4193                 vlan_extend_set(port_id, on);
4194
4195         return;
4196 }
4197
4198 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
4199         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4200                                  vlan, "vlan");
4201 cmdline_parse_token_string_t cmd_vlan_offload_set =
4202         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4203                                  set, "set");
4204 cmdline_parse_token_string_t cmd_vlan_offload_what =
4205         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4206                                 what, "strip#filter#qinq_strip#extend#stripq");
4207 cmdline_parse_token_string_t cmd_vlan_offload_on =
4208         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4209                               on, "on#off");
4210 cmdline_parse_token_string_t cmd_vlan_offload_portid =
4211         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
4212                               port_id, NULL);
4213
4214 cmdline_parse_inst_t cmd_vlan_offload = {
4215         .f = cmd_vlan_offload_parsed,
4216         .data = NULL,
4217         .help_str = "vlan set strip|filter|qinq_strip|extend|stripq on|off "
4218                 "<port_id[,queue_id]>: "
4219                 "Strip/Filter/QinQ for rx side Extend for both rx/tx sides",
4220         .tokens = {
4221                 (void *)&cmd_vlan_offload_vlan,
4222                 (void *)&cmd_vlan_offload_set,
4223                 (void *)&cmd_vlan_offload_what,
4224                 (void *)&cmd_vlan_offload_on,
4225                 (void *)&cmd_vlan_offload_portid,
4226                 NULL,
4227         },
4228 };
4229
4230 /* *** VLAN TPID SET ON A PORT *** */
4231 struct cmd_vlan_tpid_result {
4232         cmdline_fixed_string_t vlan;
4233         cmdline_fixed_string_t set;
4234         cmdline_fixed_string_t vlan_type;
4235         cmdline_fixed_string_t what;
4236         uint16_t tp_id;
4237         portid_t port_id;
4238 };
4239
4240 static void
4241 cmd_vlan_tpid_parsed(void *parsed_result,
4242                           __rte_unused struct cmdline *cl,
4243                           __rte_unused void *data)
4244 {
4245         struct cmd_vlan_tpid_result *res = parsed_result;
4246         enum rte_vlan_type vlan_type;
4247
4248         if (!strcmp(res->vlan_type, "inner"))
4249                 vlan_type = ETH_VLAN_TYPE_INNER;
4250         else if (!strcmp(res->vlan_type, "outer"))
4251                 vlan_type = ETH_VLAN_TYPE_OUTER;
4252         else {
4253                 printf("Unknown vlan type\n");
4254                 return;
4255         }
4256         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
4257 }
4258
4259 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
4260         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4261                                  vlan, "vlan");
4262 cmdline_parse_token_string_t cmd_vlan_tpid_set =
4263         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4264                                  set, "set");
4265 cmdline_parse_token_string_t cmd_vlan_type =
4266         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4267                                  vlan_type, "inner#outer");
4268 cmdline_parse_token_string_t cmd_vlan_tpid_what =
4269         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
4270                                  what, "tpid");
4271 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
4272         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4273                               tp_id, UINT16);
4274 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
4275         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
4276                               port_id, UINT16);
4277
4278 cmdline_parse_inst_t cmd_vlan_tpid = {
4279         .f = cmd_vlan_tpid_parsed,
4280         .data = NULL,
4281         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
4282                 "Set the VLAN Ether type",
4283         .tokens = {
4284                 (void *)&cmd_vlan_tpid_vlan,
4285                 (void *)&cmd_vlan_tpid_set,
4286                 (void *)&cmd_vlan_type,
4287                 (void *)&cmd_vlan_tpid_what,
4288                 (void *)&cmd_vlan_tpid_tpid,
4289                 (void *)&cmd_vlan_tpid_portid,
4290                 NULL,
4291         },
4292 };
4293
4294 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
4295 struct cmd_rx_vlan_filter_result {
4296         cmdline_fixed_string_t rx_vlan;
4297         cmdline_fixed_string_t what;
4298         uint16_t vlan_id;
4299         portid_t port_id;
4300 };
4301
4302 static void
4303 cmd_rx_vlan_filter_parsed(void *parsed_result,
4304                           __rte_unused struct cmdline *cl,
4305                           __rte_unused void *data)
4306 {
4307         struct cmd_rx_vlan_filter_result *res = parsed_result;
4308
4309         if (!strcmp(res->what, "add"))
4310                 rx_vft_set(res->port_id, res->vlan_id, 1);
4311         else
4312                 rx_vft_set(res->port_id, res->vlan_id, 0);
4313 }
4314
4315 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
4316         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4317                                  rx_vlan, "rx_vlan");
4318 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
4319         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
4320                                  what, "add#rm");
4321 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
4322         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4323                               vlan_id, UINT16);
4324 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
4325         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
4326                               port_id, UINT16);
4327
4328 cmdline_parse_inst_t cmd_rx_vlan_filter = {
4329         .f = cmd_rx_vlan_filter_parsed,
4330         .data = NULL,
4331         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
4332                 "Add/Remove a VLAN identifier to/from the set of VLAN "
4333                 "identifiers filtered by a port",
4334         .tokens = {
4335                 (void *)&cmd_rx_vlan_filter_rx_vlan,
4336                 (void *)&cmd_rx_vlan_filter_what,
4337                 (void *)&cmd_rx_vlan_filter_vlanid,
4338                 (void *)&cmd_rx_vlan_filter_portid,
4339                 NULL,
4340         },
4341 };
4342
4343 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4344 struct cmd_tx_vlan_set_result {
4345         cmdline_fixed_string_t tx_vlan;
4346         cmdline_fixed_string_t set;
4347         portid_t port_id;
4348         uint16_t vlan_id;
4349 };
4350
4351 static void
4352 cmd_tx_vlan_set_parsed(void *parsed_result,
4353                        __rte_unused struct cmdline *cl,
4354                        __rte_unused void *data)
4355 {
4356         struct cmd_tx_vlan_set_result *res = parsed_result;
4357
4358         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4359                 return;
4360
4361         if (!port_is_stopped(res->port_id)) {
4362                 printf("Please stop port %d first\n", res->port_id);
4363                 return;
4364         }
4365
4366         tx_vlan_set(res->port_id, res->vlan_id);
4367
4368         cmd_reconfig_device_queue(res->port_id, 1, 1);
4369 }
4370
4371 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
4372         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4373                                  tx_vlan, "tx_vlan");
4374 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
4375         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
4376                                  set, "set");
4377 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
4378         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4379                               port_id, UINT16);
4380 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
4381         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
4382                               vlan_id, UINT16);
4383
4384 cmdline_parse_inst_t cmd_tx_vlan_set = {
4385         .f = cmd_tx_vlan_set_parsed,
4386         .data = NULL,
4387         .help_str = "tx_vlan set <port_id> <vlan_id>: "
4388                 "Enable hardware insertion of a single VLAN header "
4389                 "with a given TAG Identifier in packets sent on a port",
4390         .tokens = {
4391                 (void *)&cmd_tx_vlan_set_tx_vlan,
4392                 (void *)&cmd_tx_vlan_set_set,
4393                 (void *)&cmd_tx_vlan_set_portid,
4394                 (void *)&cmd_tx_vlan_set_vlanid,
4395                 NULL,
4396         },
4397 };
4398
4399 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
4400 struct cmd_tx_vlan_set_qinq_result {
4401         cmdline_fixed_string_t tx_vlan;
4402         cmdline_fixed_string_t set;
4403         portid_t port_id;
4404         uint16_t vlan_id;
4405         uint16_t vlan_id_outer;
4406 };
4407
4408 static void
4409 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
4410                             __rte_unused struct cmdline *cl,
4411                             __rte_unused void *data)
4412 {
4413         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
4414
4415         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4416                 return;
4417
4418         if (!port_is_stopped(res->port_id)) {
4419                 printf("Please stop port %d first\n", res->port_id);
4420                 return;
4421         }
4422
4423         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
4424
4425         cmd_reconfig_device_queue(res->port_id, 1, 1);
4426 }
4427
4428 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
4429         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4430                 tx_vlan, "tx_vlan");
4431 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
4432         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4433                 set, "set");
4434 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
4435         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4436                 port_id, UINT16);
4437 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
4438         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4439                 vlan_id, UINT16);
4440 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
4441         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
4442                 vlan_id_outer, UINT16);
4443
4444 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
4445         .f = cmd_tx_vlan_set_qinq_parsed,
4446         .data = NULL,
4447         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
4448                 "Enable hardware insertion of double VLAN header "
4449                 "with given TAG Identifiers in packets sent on a port",
4450         .tokens = {
4451                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
4452                 (void *)&cmd_tx_vlan_set_qinq_set,
4453                 (void *)&cmd_tx_vlan_set_qinq_portid,
4454                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
4455                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
4456                 NULL,
4457         },
4458 };
4459
4460 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
4461 struct cmd_tx_vlan_set_pvid_result {
4462         cmdline_fixed_string_t tx_vlan;
4463         cmdline_fixed_string_t set;
4464         cmdline_fixed_string_t pvid;
4465         portid_t port_id;
4466         uint16_t vlan_id;
4467         cmdline_fixed_string_t mode;
4468 };
4469
4470 static void
4471 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
4472                             __rte_unused struct cmdline *cl,
4473                             __rte_unused void *data)
4474 {
4475         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
4476
4477         if (strcmp(res->mode, "on") == 0)
4478                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
4479         else
4480                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
4481 }
4482
4483 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
4484         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4485                                  tx_vlan, "tx_vlan");
4486 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
4487         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4488                                  set, "set");
4489 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
4490         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4491                                  pvid, "pvid");
4492 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
4493         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4494                              port_id, UINT16);
4495 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
4496         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4497                               vlan_id, UINT16);
4498 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
4499         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
4500                                  mode, "on#off");
4501
4502 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
4503         .f = cmd_tx_vlan_set_pvid_parsed,
4504         .data = NULL,
4505         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
4506         .tokens = {
4507                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
4508                 (void *)&cmd_tx_vlan_set_pvid_set,
4509                 (void *)&cmd_tx_vlan_set_pvid_pvid,
4510                 (void *)&cmd_tx_vlan_set_pvid_port_id,
4511                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
4512                 (void *)&cmd_tx_vlan_set_pvid_mode,
4513                 NULL,
4514         },
4515 };
4516
4517 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
4518 struct cmd_tx_vlan_reset_result {
4519         cmdline_fixed_string_t tx_vlan;
4520         cmdline_fixed_string_t reset;
4521         portid_t port_id;
4522 };
4523
4524 static void
4525 cmd_tx_vlan_reset_parsed(void *parsed_result,
4526                          __rte_unused struct cmdline *cl,
4527                          __rte_unused void *data)
4528 {
4529         struct cmd_tx_vlan_reset_result *res = parsed_result;
4530
4531         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4532                 return;
4533
4534         if (!port_is_stopped(res->port_id)) {
4535                 printf("Please stop port %d first\n", res->port_id);
4536                 return;
4537         }
4538
4539         tx_vlan_reset(res->port_id);
4540
4541         cmd_reconfig_device_queue(res->port_id, 1, 1);
4542 }
4543
4544 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
4545         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4546                                  tx_vlan, "tx_vlan");
4547 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
4548         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
4549                                  reset, "reset");
4550 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
4551         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
4552                               port_id, UINT16);
4553
4554 cmdline_parse_inst_t cmd_tx_vlan_reset = {
4555         .f = cmd_tx_vlan_reset_parsed,
4556         .data = NULL,
4557         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
4558                 "VLAN header in packets sent on a port",
4559         .tokens = {
4560                 (void *)&cmd_tx_vlan_reset_tx_vlan,
4561                 (void *)&cmd_tx_vlan_reset_reset,
4562                 (void *)&cmd_tx_vlan_reset_portid,
4563                 NULL,
4564         },
4565 };
4566
4567
4568 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
4569 struct cmd_csum_result {
4570         cmdline_fixed_string_t csum;
4571         cmdline_fixed_string_t mode;
4572         cmdline_fixed_string_t proto;
4573         cmdline_fixed_string_t hwsw;
4574         portid_t port_id;
4575 };
4576
4577 static void
4578 csum_show(int port_id)
4579 {
4580         struct rte_eth_dev_info dev_info;
4581         uint64_t tx_offloads;
4582         int ret;
4583
4584         tx_offloads = ports[port_id].dev_conf.txmode.offloads;
4585         printf("Parse tunnel is %s\n",
4586                 (ports[port_id].parse_tunnel) ? "on" : "off");
4587         printf("IP checksum offload is %s\n",
4588                 (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "hw" : "sw");
4589         printf("UDP checksum offload is %s\n",
4590                 (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
4591         printf("TCP checksum offload is %s\n",
4592                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
4593         printf("SCTP checksum offload is %s\n",
4594                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
4595         printf("Outer-Ip checksum offload is %s\n",
4596                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ? "hw" : "sw");
4597         printf("Outer-Udp checksum offload is %s\n",
4598                 (tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) ? "hw" : "sw");
4599
4600         /* display warnings if configuration is not supported by the NIC */
4601         ret = eth_dev_info_get_print_err(port_id, &dev_info);
4602         if (ret != 0)
4603                 return;
4604
4605         if ((tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) &&
4606                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
4607                 printf("Warning: hardware IP checksum enabled but not "
4608                         "supported by port %d\n", port_id);
4609         }
4610         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) &&
4611                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
4612                 printf("Warning: hardware UDP checksum enabled but not "
4613                         "supported by port %d\n", port_id);
4614         }
4615         if ((tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) &&
4616                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
4617                 printf("Warning: hardware TCP checksum enabled but not "
4618                         "supported by port %d\n", port_id);
4619         }
4620         if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
4621                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
4622                 printf("Warning: hardware SCTP checksum enabled but not "
4623                         "supported by port %d\n", port_id);
4624         }
4625         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) &&
4626                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
4627                 printf("Warning: hardware outer IP checksum enabled but not "
4628                         "supported by port %d\n", port_id);
4629         }
4630         if ((tx_offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) &&
4631                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)
4632                         == 0) {
4633                 printf("Warning: hardware outer UDP checksum enabled but not "
4634                         "supported by port %d\n", port_id);
4635         }
4636 }
4637
4638 static void
4639 cmd_config_queue_tx_offloads(struct rte_port *port)
4640 {
4641         int k;
4642
4643         /* Apply queue tx offloads configuration */
4644         for (k = 0; k < port->dev_info.max_rx_queues; k++)
4645                 port->tx_conf[k].offloads =
4646                         port->dev_conf.txmode.offloads;
4647 }
4648
4649 static void
4650 cmd_csum_parsed(void *parsed_result,
4651                        __rte_unused struct cmdline *cl,
4652                        __rte_unused void *data)
4653 {
4654         struct cmd_csum_result *res = parsed_result;
4655         int hw = 0;
4656         uint64_t csum_offloads = 0;
4657         struct rte_eth_dev_info dev_info;
4658         int ret;
4659
4660         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
4661                 printf("invalid port %d\n", res->port_id);
4662                 return;
4663         }
4664         if (!port_is_stopped(res->port_id)) {
4665                 printf("Please stop port %d first\n", res->port_id);
4666                 return;
4667         }
4668
4669         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4670         if (ret != 0)
4671                 return;
4672
4673         if (!strcmp(res->mode, "set")) {
4674
4675                 if (!strcmp(res->hwsw, "hw"))
4676                         hw = 1;
4677
4678                 if (!strcmp(res->proto, "ip")) {
4679                         if (hw == 0 || (dev_info.tx_offload_capa &
4680                                                 DEV_TX_OFFLOAD_IPV4_CKSUM)) {
4681                                 csum_offloads |= DEV_TX_OFFLOAD_IPV4_CKSUM;
4682                         } else {
4683                                 printf("IP checksum offload is not supported "
4684                                        "by port %u\n", res->port_id);
4685                         }
4686                 } else if (!strcmp(res->proto, "udp")) {
4687                         if (hw == 0 || (dev_info.tx_offload_capa &
4688                                                 DEV_TX_OFFLOAD_UDP_CKSUM)) {
4689                                 csum_offloads |= DEV_TX_OFFLOAD_UDP_CKSUM;
4690                         } else {
4691                                 printf("UDP checksum offload is not supported "
4692                                        "by port %u\n", res->port_id);
4693                         }
4694                 } else if (!strcmp(res->proto, "tcp")) {
4695                         if (hw == 0 || (dev_info.tx_offload_capa &
4696                                                 DEV_TX_OFFLOAD_TCP_CKSUM)) {
4697                                 csum_offloads |= DEV_TX_OFFLOAD_TCP_CKSUM;
4698                         } else {
4699                                 printf("TCP checksum offload is not supported "
4700                                        "by port %u\n", res->port_id);
4701                         }
4702                 } else if (!strcmp(res->proto, "sctp")) {
4703                         if (hw == 0 || (dev_info.tx_offload_capa &
4704                                                 DEV_TX_OFFLOAD_SCTP_CKSUM)) {
4705                                 csum_offloads |= DEV_TX_OFFLOAD_SCTP_CKSUM;
4706                         } else {
4707                                 printf("SCTP checksum offload is not supported "
4708                                        "by port %u\n", res->port_id);
4709                         }
4710                 } else if (!strcmp(res->proto, "outer-ip")) {
4711                         if (hw == 0 || (dev_info.tx_offload_capa &
4712                                         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM)) {
4713                                 csum_offloads |=
4714                                                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
4715                         } else {
4716                                 printf("Outer IP checksum offload is not "
4717                                        "supported by port %u\n", res->port_id);
4718                         }
4719                 } else if (!strcmp(res->proto, "outer-udp")) {
4720                         if (hw == 0 || (dev_info.tx_offload_capa &
4721                                         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
4722                                 csum_offloads |=
4723                                                 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM;
4724                         } else {
4725                                 printf("Outer UDP checksum offload is not "
4726                                        "supported by port %u\n", res->port_id);
4727                         }
4728                 }
4729
4730                 if (hw) {
4731                         ports[res->port_id].dev_conf.txmode.offloads |=
4732                                                         csum_offloads;
4733                 } else {
4734                         ports[res->port_id].dev_conf.txmode.offloads &=
4735                                                         (~csum_offloads);
4736                 }
4737                 cmd_config_queue_tx_offloads(&ports[res->port_id]);
4738         }
4739         csum_show(res->port_id);
4740
4741         cmd_reconfig_device_queue(res->port_id, 1, 1);
4742 }
4743
4744 cmdline_parse_token_string_t cmd_csum_csum =
4745         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4746                                 csum, "csum");
4747 cmdline_parse_token_string_t cmd_csum_mode =
4748         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4749                                 mode, "set");
4750 cmdline_parse_token_string_t cmd_csum_proto =
4751         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4752                                 proto, "ip#tcp#udp#sctp#outer-ip#outer-udp");
4753 cmdline_parse_token_string_t cmd_csum_hwsw =
4754         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4755                                 hwsw, "hw#sw");
4756 cmdline_parse_token_num_t cmd_csum_portid =
4757         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
4758                                 port_id, UINT16);
4759
4760 cmdline_parse_inst_t cmd_csum_set = {
4761         .f = cmd_csum_parsed,
4762         .data = NULL,
4763         .help_str = "csum set ip|tcp|udp|sctp|outer-ip|outer-udp hw|sw <port_id>: "
4764                 "Enable/Disable hardware calculation of L3/L4 checksum when "
4765                 "using csum forward engine",
4766         .tokens = {
4767                 (void *)&cmd_csum_csum,
4768                 (void *)&cmd_csum_mode,
4769                 (void *)&cmd_csum_proto,
4770                 (void *)&cmd_csum_hwsw,
4771                 (void *)&cmd_csum_portid,
4772                 NULL,
4773         },
4774 };
4775
4776 cmdline_parse_token_string_t cmd_csum_mode_show =
4777         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
4778                                 mode, "show");
4779
4780 cmdline_parse_inst_t cmd_csum_show = {
4781         .f = cmd_csum_parsed,
4782         .data = NULL,
4783         .help_str = "csum show <port_id>: Show checksum offload configuration",
4784         .tokens = {
4785                 (void *)&cmd_csum_csum,
4786                 (void *)&cmd_csum_mode_show,
4787                 (void *)&cmd_csum_portid,
4788                 NULL,
4789         },
4790 };
4791
4792 /* Enable/disable tunnel parsing */
4793 struct cmd_csum_tunnel_result {
4794         cmdline_fixed_string_t csum;
4795         cmdline_fixed_string_t parse;
4796         cmdline_fixed_string_t onoff;
4797         portid_t port_id;
4798 };
4799
4800 static void
4801 cmd_csum_tunnel_parsed(void *parsed_result,
4802                        __rte_unused struct cmdline *cl,
4803                        __rte_unused void *data)
4804 {
4805         struct cmd_csum_tunnel_result *res = parsed_result;
4806
4807         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4808                 return;
4809
4810         if (!strcmp(res->onoff, "on"))
4811                 ports[res->port_id].parse_tunnel = 1;
4812         else
4813                 ports[res->port_id].parse_tunnel = 0;
4814
4815         csum_show(res->port_id);
4816 }
4817
4818 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
4819         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4820                                 csum, "csum");
4821 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
4822         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4823                                 parse, "parse-tunnel");
4824 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
4825         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
4826                                 onoff, "on#off");
4827 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
4828         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
4829                                 port_id, UINT16);
4830
4831 cmdline_parse_inst_t cmd_csum_tunnel = {
4832         .f = cmd_csum_tunnel_parsed,
4833         .data = NULL,
4834         .help_str = "csum parse-tunnel on|off <port_id>: "
4835                 "Enable/Disable parsing of tunnels for csum engine",
4836         .tokens = {
4837                 (void *)&cmd_csum_tunnel_csum,
4838                 (void *)&cmd_csum_tunnel_parse,
4839                 (void *)&cmd_csum_tunnel_onoff,
4840                 (void *)&cmd_csum_tunnel_portid,
4841                 NULL,
4842         },
4843 };
4844
4845 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
4846 struct cmd_tso_set_result {
4847         cmdline_fixed_string_t tso;
4848         cmdline_fixed_string_t mode;
4849         uint16_t tso_segsz;
4850         portid_t port_id;
4851 };
4852
4853 static void
4854 cmd_tso_set_parsed(void *parsed_result,
4855                        __rte_unused struct cmdline *cl,
4856                        __rte_unused void *data)
4857 {
4858         struct cmd_tso_set_result *res = parsed_result;
4859         struct rte_eth_dev_info dev_info;
4860         int ret;
4861
4862         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
4863                 return;
4864         if (!port_is_stopped(res->port_id)) {
4865                 printf("Please stop port %d first\n", res->port_id);
4866                 return;
4867         }
4868
4869         if (!strcmp(res->mode, "set"))
4870                 ports[res->port_id].tso_segsz = res->tso_segsz;
4871
4872         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4873         if (ret != 0)
4874                 return;
4875
4876         if ((ports[res->port_id].tso_segsz != 0) &&
4877                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4878                 printf("Error: TSO is not supported by port %d\n",
4879                        res->port_id);
4880                 return;
4881         }
4882
4883         if (ports[res->port_id].tso_segsz == 0) {
4884                 ports[res->port_id].dev_conf.txmode.offloads &=
4885                                                 ~DEV_TX_OFFLOAD_TCP_TSO;
4886                 printf("TSO for non-tunneled packets is disabled\n");
4887         } else {
4888                 ports[res->port_id].dev_conf.txmode.offloads |=
4889                                                 DEV_TX_OFFLOAD_TCP_TSO;
4890                 printf("TSO segment size for non-tunneled packets is %d\n",
4891                         ports[res->port_id].tso_segsz);
4892         }
4893         cmd_config_queue_tx_offloads(&ports[res->port_id]);
4894
4895         /* display warnings if configuration is not supported by the NIC */
4896         ret = eth_dev_info_get_print_err(res->port_id, &dev_info);
4897         if (ret != 0)
4898                 return;
4899
4900         if ((ports[res->port_id].tso_segsz != 0) &&
4901                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
4902                 printf("Warning: TSO enabled but not "
4903                         "supported by port %d\n", res->port_id);
4904         }
4905
4906         cmd_reconfig_device_queue(res->port_id, 1, 1);
4907 }
4908
4909 cmdline_parse_token_string_t cmd_tso_set_tso =
4910         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4911                                 tso, "tso");
4912 cmdline_parse_token_string_t cmd_tso_set_mode =
4913         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4914                                 mode, "set");
4915 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
4916         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4917                                 tso_segsz, UINT16);
4918 cmdline_parse_token_num_t cmd_tso_set_portid =
4919         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
4920                                 port_id, UINT16);
4921
4922 cmdline_parse_inst_t cmd_tso_set = {
4923         .f = cmd_tso_set_parsed,
4924         .data = NULL,
4925         .help_str = "tso set <tso_segsz> <port_id>: "
4926                 "Set TSO segment size of non-tunneled packets for csum engine "
4927                 "(0 to disable)",
4928         .tokens = {
4929                 (void *)&cmd_tso_set_tso,
4930                 (void *)&cmd_tso_set_mode,
4931                 (void *)&cmd_tso_set_tso_segsz,
4932                 (void *)&cmd_tso_set_portid,
4933                 NULL,
4934         },
4935 };
4936
4937 cmdline_parse_token_string_t cmd_tso_show_mode =
4938         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
4939                                 mode, "show");
4940
4941
4942 cmdline_parse_inst_t cmd_tso_show = {
4943         .f = cmd_tso_set_parsed,
4944         .data = NULL,
4945         .help_str = "tso show <port_id>: "
4946                 "Show TSO segment size of non-tunneled packets for csum engine",
4947         .tokens = {
4948                 (void *)&cmd_tso_set_tso,
4949                 (void *)&cmd_tso_show_mode,
4950                 (void *)&cmd_tso_set_portid,
4951                 NULL,
4952         },
4953 };
4954
4955 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
4956 struct cmd_tunnel_tso_set_result {
4957         cmdline_fixed_string_t tso;
4958         cmdline_fixed_string_t mode;
4959         uint16_t tso_segsz;
4960         portid_t port_id;
4961 };
4962
4963 static struct rte_eth_dev_info
4964 check_tunnel_tso_nic_support(portid_t port_id)
4965 {
4966         struct rte_eth_dev_info dev_info;
4967
4968         if (eth_dev_info_get_print_err(port_id, &dev_info) != 0)
4969                 return dev_info;
4970
4971         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
4972                 printf("Warning: VXLAN TUNNEL TSO not supported therefore "
4973                        "not enabled for port %d\n", port_id);
4974         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
4975                 printf("Warning: GRE TUNNEL TSO not supported therefore "
4976                        "not enabled for port %d\n", port_id);
4977         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
4978                 printf("Warning: IPIP TUNNEL TSO not supported therefore "
4979                        "not enabled for port %d\n", port_id);
4980         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
4981                 printf("Warning: GENEVE TUNNEL TSO not supported therefore "
4982                        "not enabled for port %d\n", port_id);
4983         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO))
4984                 printf("Warning: IP TUNNEL TSO not supported therefore "
4985                        "not enabled for port %d\n", port_id);
4986         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO))
4987                 printf("Warning: UDP TUNNEL TSO not supported therefore "
4988                        "not enabled for port %d\n", port_id);
4989         return dev_info;
4990 }
4991
4992 static void
4993 cmd_tunnel_tso_set_parsed(void *parsed_result,
4994                           __rte_unused struct cmdline *cl,
4995                           __rte_unused void *data)
4996 {
4997         struct cmd_tunnel_tso_set_result *res = parsed_result;
4998         struct rte_eth_dev_info dev_info;
4999
5000         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
5001                 return;
5002         if (!port_is_stopped(res->port_id)) {
5003                 printf("Please stop port %d first\n", res->port_id);
5004                 return;
5005         }
5006
5007         if (!strcmp(res->mode, "set"))
5008                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
5009
5010         dev_info = check_tunnel_tso_nic_support(res->port_id);
5011         if (ports[res->port_id].tunnel_tso_segsz == 0) {
5012                 ports[res->port_id].dev_conf.txmode.offloads &=
5013                         ~(DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5014                           DEV_TX_OFFLOAD_GRE_TNL_TSO |
5015                           DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5016                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5017                           DEV_TX_OFFLOAD_IP_TNL_TSO |
5018                           DEV_TX_OFFLOAD_UDP_TNL_TSO);
5019                 printf("TSO for tunneled packets is disabled\n");
5020         } else {
5021                 uint64_t tso_offloads = (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
5022                                          DEV_TX_OFFLOAD_GRE_TNL_TSO |
5023                                          DEV_TX_OFFLOAD_IPIP_TNL_TSO |
5024                                          DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
5025                                          DEV_TX_OFFLOAD_IP_TNL_TSO |
5026                                          DEV_TX_OFFLOAD_UDP_TNL_TSO);
5027
5028                 ports[res->port_id].dev_conf.txmode.offloads |=
5029                         (tso_offloads & dev_info.tx_offload_capa);
5030                 printf("TSO segment size for tunneled packets is %d\n",
5031                         ports[res->port_id].tunnel_tso_segsz);
5032
5033                 /* Below conditions are needed to make it work:
5034                  * (1) tunnel TSO is supported by the NIC;
5035                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
5036                  * are recognized;
5037                  * (3) for tunneled pkts with outer L3 of IPv4,
5038                  * "csum set outer-ip" must be set to hw, because after tso,
5039                  * total_len of outer IP header is changed, and the checksum
5040                  * of outer IP header calculated by sw should be wrong; that
5041                  * is not necessary for IPv6 tunneled pkts because there's no
5042                  * checksum in IP header anymore.
5043                  */
5044
5045                 if (!ports[res->port_id].parse_tunnel)
5046                         printf("Warning: csum parse_tunnel must be set "
5047                                 "so that tunneled packets are recognized\n");
5048                 if (!(ports[res->port_id].dev_conf.txmode.offloads &
5049                       DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM))
5050                         printf("Warning: csum set outer-ip must be set to hw "
5051                                 "if outer L3 is IPv4; not necessary for IPv6\n");
5052         }
5053
5054         cmd_config_queue_tx_offloads(&ports[res->port_id]);
5055         cmd_reconfig_device_queue(res->port_id, 1, 1);
5056 }
5057
5058 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
5059         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5060                                 tso, "tunnel_tso");
5061 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
5062         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5063                                 mode, "set");
5064 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
5065         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5066                                 tso_segsz, UINT16);
5067 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
5068         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
5069                                 port_id, UINT16);
5070
5071 cmdline_parse_inst_t cmd_tunnel_tso_set = {
5072         .f = cmd_tunnel_tso_set_parsed,
5073         .data = NULL,
5074         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
5075                 "Set TSO segment size of tunneled packets for csum engine "
5076                 "(0 to disable)",
5077         .tokens = {
5078                 (void *)&cmd_tunnel_tso_set_tso,
5079                 (void *)&cmd_tunnel_tso_set_mode,
5080                 (void *)&cmd_tunnel_tso_set_tso_segsz,
5081                 (void *)&cmd_tunnel_tso_set_portid,
5082                 NULL,
5083         },
5084 };
5085
5086 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
5087         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
5088                                 mode, "show");
5089
5090
5091 cmdline_parse_inst_t cmd_tunnel_tso_show = {
5092         .f = cmd_tunnel_tso_set_parsed,
5093         .data = NULL,
5094         .help_str = "tunnel_tso show <port_id> "
5095                 "Show TSO segment size of tunneled packets for csum engine",
5096         .tokens = {
5097                 (void *)&cmd_tunnel_tso_set_tso,
5098                 (void *)&cmd_tunnel_tso_show_mode,
5099                 (void *)&cmd_tunnel_tso_set_portid,
5100                 NULL,
5101         },
5102 };
5103
5104 /* *** SET GRO FOR A PORT *** */
5105 struct cmd_gro_enable_result {
5106         cmdline_fixed_string_t cmd_set;
5107         cmdline_fixed_string_t cmd_port;
5108         cmdline_fixed_string_t cmd_keyword;
5109         cmdline_fixed_string_t cmd_onoff;
5110         portid_t cmd_pid;
5111 };
5112
5113 static void
5114 cmd_gro_enable_parsed(void *parsed_result,
5115                 __rte_unused struct cmdline *cl,
5116                 __rte_unused void *data)
5117 {
5118         struct cmd_gro_enable_result *res;
5119
5120         res = parsed_result;
5121         if (!strcmp(res->cmd_keyword, "gro"))
5122                 setup_gro(res->cmd_onoff, res->cmd_pid);
5123 }
5124
5125 cmdline_parse_token_string_t cmd_gro_enable_set =
5126         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5127                         cmd_set, "set");
5128 cmdline_parse_token_string_t cmd_gro_enable_port =
5129         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5130                         cmd_keyword, "port");
5131 cmdline_parse_token_num_t cmd_gro_enable_pid =
5132         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
5133                         cmd_pid, UINT16);
5134 cmdline_parse_token_string_t cmd_gro_enable_keyword =
5135         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5136                         cmd_keyword, "gro");
5137 cmdline_parse_token_string_t cmd_gro_enable_onoff =
5138         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
5139                         cmd_onoff, "on#off");
5140
5141 cmdline_parse_inst_t cmd_gro_enable = {
5142         .f = cmd_gro_enable_parsed,
5143         .data = NULL,
5144         .help_str = "set port <port_id> gro on|off",
5145         .tokens = {
5146                 (void *)&cmd_gro_enable_set,
5147                 (void *)&cmd_gro_enable_port,
5148                 (void *)&cmd_gro_enable_pid,
5149                 (void *)&cmd_gro_enable_keyword,
5150                 (void *)&cmd_gro_enable_onoff,
5151                 NULL,
5152         },
5153 };
5154
5155 /* *** DISPLAY GRO CONFIGURATION *** */
5156 struct cmd_gro_show_result {
5157         cmdline_fixed_string_t cmd_show;
5158         cmdline_fixed_string_t cmd_port;
5159         cmdline_fixed_string_t cmd_keyword;
5160         portid_t cmd_pid;
5161 };
5162
5163 static void
5164 cmd_gro_show_parsed(void *parsed_result,
5165                 __rte_unused struct cmdline *cl,
5166                 __rte_unused void *data)
5167 {
5168         struct cmd_gro_show_result *res;
5169
5170         res = parsed_result;
5171         if (!strcmp(res->cmd_keyword, "gro"))
5172                 show_gro(res->cmd_pid);
5173 }
5174
5175 cmdline_parse_token_string_t cmd_gro_show_show =
5176         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5177                         cmd_show, "show");
5178 cmdline_parse_token_string_t cmd_gro_show_port =
5179         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5180                         cmd_port, "port");
5181 cmdline_parse_token_num_t cmd_gro_show_pid =
5182         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
5183                         cmd_pid, UINT16);
5184 cmdline_parse_token_string_t cmd_gro_show_keyword =
5185         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
5186                         cmd_keyword, "gro");
5187
5188 cmdline_parse_inst_t cmd_gro_show = {
5189         .f = cmd_gro_show_parsed,
5190         .data = NULL,
5191         .help_str = "show port <port_id> gro",
5192         .tokens = {
5193                 (void *)&cmd_gro_show_show,
5194                 (void *)&cmd_gro_show_port,
5195                 (void *)&cmd_gro_show_pid,
5196                 (void *)&cmd_gro_show_keyword,
5197                 NULL,
5198         },
5199 };
5200
5201 /* *** SET FLUSH CYCLES FOR GRO *** */
5202 struct cmd_gro_flush_result {
5203         cmdline_fixed_string_t cmd_set;
5204         cmdline_fixed_string_t cmd_keyword;
5205         cmdline_fixed_string_t cmd_flush;
5206         uint8_t cmd_cycles;
5207 };
5208
5209 static void
5210 cmd_gro_flush_parsed(void *parsed_result,
5211                 __rte_unused struct cmdline *cl,
5212                 __rte_unused void *data)
5213 {
5214         struct cmd_gro_flush_result *res;
5215
5216         res = parsed_result;
5217         if ((!strcmp(res->cmd_keyword, "gro")) &&
5218                         (!strcmp(res->cmd_flush, "flush")))
5219                 setup_gro_flush_cycles(res->cmd_cycles);
5220 }
5221
5222 cmdline_parse_token_string_t cmd_gro_flush_set =
5223         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5224                         cmd_set, "set");
5225 cmdline_parse_token_string_t cmd_gro_flush_keyword =
5226         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5227                         cmd_keyword, "gro");
5228 cmdline_parse_token_string_t cmd_gro_flush_flush =
5229         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
5230                         cmd_flush, "flush");
5231 cmdline_parse_token_num_t cmd_gro_flush_cycles =
5232         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
5233                         cmd_cycles, UINT8);
5234
5235 cmdline_parse_inst_t cmd_gro_flush = {
5236         .f = cmd_gro_flush_parsed,
5237         .data = NULL,
5238         .help_str = "set gro flush <cycles>",
5239         .tokens = {
5240                 (void *)&cmd_gro_flush_set,
5241                 (void *)&cmd_gro_flush_keyword,
5242                 (void *)&cmd_gro_flush_flush,
5243                 (void *)&cmd_gro_flush_cycles,
5244                 NULL,
5245         },
5246 };
5247
5248 /* *** ENABLE/DISABLE GSO *** */
5249 struct cmd_gso_enable_result {
5250         cmdline_fixed_string_t cmd_set;
5251         cmdline_fixed_string_t cmd_port;
5252         cmdline_fixed_string_t cmd_keyword;
5253         cmdline_fixed_string_t cmd_mode;
5254         portid_t cmd_pid;
5255 };
5256
5257 static void
5258 cmd_gso_enable_parsed(void *parsed_result,
5259                 __rte_unused struct cmdline *cl,
5260                 __rte_unused void *data)
5261 {
5262         struct cmd_gso_enable_result *res;
5263
5264         res = parsed_result;
5265         if (!strcmp(res->cmd_keyword, "gso"))
5266                 setup_gso(res->cmd_mode, res->cmd_pid);
5267 }
5268
5269 cmdline_parse_token_string_t cmd_gso_enable_set =
5270         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5271                         cmd_set, "set");
5272 cmdline_parse_token_string_t cmd_gso_enable_port =
5273         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5274                         cmd_port, "port");
5275 cmdline_parse_token_string_t cmd_gso_enable_keyword =
5276         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5277                         cmd_keyword, "gso");
5278 cmdline_parse_token_string_t cmd_gso_enable_mode =
5279         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
5280                         cmd_mode, "on#off");
5281 cmdline_parse_token_num_t cmd_gso_enable_pid =
5282         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
5283                         cmd_pid, UINT16);
5284
5285 cmdline_parse_inst_t cmd_gso_enable = {
5286         .f = cmd_gso_enable_parsed,
5287         .data = NULL,
5288         .help_str = "set port <port_id> gso on|off",
5289         .tokens = {
5290                 (void *)&cmd_gso_enable_set,
5291                 (void *)&cmd_gso_enable_port,
5292                 (void *)&cmd_gso_enable_pid,
5293                 (void *)&cmd_gso_enable_keyword,
5294                 (void *)&cmd_gso_enable_mode,
5295                 NULL,
5296         },
5297 };
5298
5299 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
5300 struct cmd_gso_size_result {
5301         cmdline_fixed_string_t cmd_set;
5302         cmdline_fixed_string_t cmd_keyword;
5303         cmdline_fixed_string_t cmd_segsz;
5304         uint16_t cmd_size;
5305 };
5306
5307 static void
5308 cmd_gso_size_parsed(void *parsed_result,
5309                        __rte_unused struct cmdline *cl,
5310                        __rte_unused void *data)
5311 {
5312         struct cmd_gso_size_result *res = parsed_result;
5313
5314         if (test_done == 0) {
5315                 printf("Before setting GSO segsz, please first"
5316                                 " stop forwarding\n");
5317                 return;
5318         }
5319
5320         if (!strcmp(res->cmd_keyword, "gso") &&
5321                         !strcmp(res->cmd_segsz, "segsz")) {
5322                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
5323                         printf("gso_size should be larger than %zu."
5324                                         " Please input a legal value\n",
5325                                         RTE_GSO_SEG_SIZE_MIN);
5326                 else
5327                         gso_max_segment_size = res->cmd_size;
5328         }
5329 }
5330
5331 cmdline_parse_token_string_t cmd_gso_size_set =
5332         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5333                                 cmd_set, "set");
5334 cmdline_parse_token_string_t cmd_gso_size_keyword =
5335         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5336                                 cmd_keyword, "gso");
5337 cmdline_parse_token_string_t cmd_gso_size_segsz =
5338         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
5339                                 cmd_segsz, "segsz");
5340 cmdline_parse_token_num_t cmd_gso_size_size =
5341         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
5342                                 cmd_size, UINT16);
5343
5344 cmdline_parse_inst_t cmd_gso_size = {
5345         .f = cmd_gso_size_parsed,
5346         .data = NULL,
5347         .help_str = "set gso segsz <length>",
5348         .tokens = {
5349                 (void *)&cmd_gso_size_set,
5350                 (void *)&cmd_gso_size_keyword,
5351                 (void *)&cmd_gso_size_segsz,
5352                 (void *)&cmd_gso_size_size,
5353                 NULL,
5354         },
5355 };
5356
5357 /* *** SHOW GSO CONFIGURATION *** */
5358 struct cmd_gso_show_result {
5359         cmdline_fixed_string_t cmd_show;
5360         cmdline_fixed_string_t cmd_port;
5361         cmdline_fixed_string_t cmd_keyword;
5362         portid_t cmd_pid;
5363 };
5364
5365 static void
5366 cmd_gso_show_parsed(void *parsed_result,
5367                        __rte_unused struct cmdline *cl,
5368                        __rte_unused void *data)
5369 {
5370         struct cmd_gso_show_result *res = parsed_result;
5371
5372         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
5373                 printf("invalid port id %u\n", res->cmd_pid);
5374                 return;
5375         }
5376         if (!strcmp(res->cmd_keyword, "gso")) {
5377                 if (gso_ports[res->cmd_pid].enable) {
5378                         printf("Max GSO'd packet size: %uB\n"
5379                                         "Supported GSO types: TCP/IPv4, "
5380                                         "UDP/IPv4, VxLAN with inner "
5381                                         "TCP/IPv4 packet, GRE with inner "
5382                                         "TCP/IPv4 packet\n",
5383                                         gso_max_segment_size);
5384                 } else
5385                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
5386         }
5387 }
5388
5389 cmdline_parse_token_string_t cmd_gso_show_show =
5390 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5391                 cmd_show, "show");
5392 cmdline_parse_token_string_t cmd_gso_show_port =
5393 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5394                 cmd_port, "port");
5395 cmdline_parse_token_string_t cmd_gso_show_keyword =
5396         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
5397                                 cmd_keyword, "gso");
5398 cmdline_parse_token_num_t cmd_gso_show_pid =
5399         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
5400                                 cmd_pid, UINT16);
5401
5402 cmdline_parse_inst_t cmd_gso_show = {
5403         .f = cmd_gso_show_parsed,
5404         .data = NULL,
5405         .help_str = "show port <port_id> gso",
5406         .tokens = {
5407                 (void *)&cmd_gso_show_show,
5408                 (void *)&cmd_gso_show_port,
5409                 (void *)&cmd_gso_show_pid,
5410                 (void *)&cmd_gso_show_keyword,
5411                 NULL,
5412         },
5413 };
5414
5415 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
5416 struct cmd_set_flush_rx {
5417         cmdline_fixed_string_t set;
5418         cmdline_fixed_string_t flush_rx;
5419         cmdline_fixed_string_t mode;
5420 };
5421
5422 static void
5423 cmd_set_flush_rx_parsed(void *parsed_result,
5424                 __rte_unused struct cmdline *cl,
5425                 __rte_unused void *data)
5426 {
5427         struct cmd_set_flush_rx *res = parsed_result;
5428         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5429 }
5430
5431 cmdline_parse_token_string_t cmd_setflushrx_set =
5432         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5433                         set, "set");
5434 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
5435         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5436                         flush_rx, "flush_rx");
5437 cmdline_parse_token_string_t cmd_setflushrx_mode =
5438         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
5439                         mode, "on#off");
5440
5441
5442 cmdline_parse_inst_t cmd_set_flush_rx = {
5443         .f = cmd_set_flush_rx_parsed,
5444         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
5445         .data = NULL,
5446         .tokens = {
5447                 (void *)&cmd_setflushrx_set,
5448                 (void *)&cmd_setflushrx_flush_rx,
5449                 (void *)&cmd_setflushrx_mode,
5450                 NULL,
5451         },
5452 };
5453
5454 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
5455 struct cmd_set_link_check {
5456         cmdline_fixed_string_t set;
5457         cmdline_fixed_string_t link_check;
5458         cmdline_fixed_string_t mode;
5459 };
5460
5461 static void
5462 cmd_set_link_check_parsed(void *parsed_result,
5463                 __rte_unused struct cmdline *cl,
5464                 __rte_unused void *data)
5465 {
5466         struct cmd_set_link_check *res = parsed_result;
5467         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
5468 }
5469
5470 cmdline_parse_token_string_t cmd_setlinkcheck_set =
5471         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5472                         set, "set");
5473 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
5474         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5475                         link_check, "link_check");
5476 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
5477         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
5478                         mode, "on#off");
5479
5480
5481 cmdline_parse_inst_t cmd_set_link_check = {
5482         .f = cmd_set_link_check_parsed,
5483         .help_str = "set link_check on|off: Enable/Disable link status check "
5484                     "when starting/stopping a port",
5485         .data = NULL,
5486         .tokens = {
5487                 (void *)&cmd_setlinkcheck_set,
5488                 (void *)&cmd_setlinkcheck_link_check,
5489                 (void *)&cmd_setlinkcheck_mode,
5490                 NULL,
5491         },
5492 };
5493
5494 /* *** SET NIC BYPASS MODE *** */
5495 struct cmd_set_bypass_mode_result {
5496         cmdline_fixed_string_t set;
5497         cmdline_fixed_string_t bypass;
5498         cmdline_fixed_string_t mode;
5499         cmdline_fixed_string_t value;
5500         portid_t port_id;
5501 };
5502
5503 static void
5504 cmd_set_bypass_mode_parsed(void *parsed_result,
5505                 __rte_unused struct cmdline *cl,
5506                 __rte_unused void *data)
5507 {
5508         struct cmd_set_bypass_mode_result *res = parsed_result;
5509         portid_t port_id = res->port_id;
5510         int32_t rc = -EINVAL;
5511
5512 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5513         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5514
5515         if (!strcmp(res->value, "bypass"))
5516                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5517         else if (!strcmp(res->value, "isolate"))
5518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5519         else
5520                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5521
5522         /* Set the bypass mode for the relevant port. */
5523         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
5524 #endif
5525         if (rc != 0)
5526                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
5527 }
5528
5529 cmdline_parse_token_string_t cmd_setbypass_mode_set =
5530         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5531                         set, "set");
5532 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
5533         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5534                         bypass, "bypass");
5535 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
5536         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5537                         mode, "mode");
5538 cmdline_parse_token_string_t cmd_setbypass_mode_value =
5539         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
5540                         value, "normal#bypass#isolate");
5541 cmdline_parse_token_num_t cmd_setbypass_mode_port =
5542         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
5543                                 port_id, UINT16);
5544
5545 cmdline_parse_inst_t cmd_set_bypass_mode = {
5546         .f = cmd_set_bypass_mode_parsed,
5547         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
5548                     "Set the NIC bypass mode for port_id",
5549         .data = NULL,
5550         .tokens = {
5551                 (void *)&cmd_setbypass_mode_set,
5552                 (void *)&cmd_setbypass_mode_bypass,
5553                 (void *)&cmd_setbypass_mode_mode,
5554                 (void *)&cmd_setbypass_mode_value,
5555                 (void *)&cmd_setbypass_mode_port,
5556                 NULL,
5557         },
5558 };
5559
5560 /* *** SET NIC BYPASS EVENT *** */
5561 struct cmd_set_bypass_event_result {
5562         cmdline_fixed_string_t set;
5563         cmdline_fixed_string_t bypass;
5564         cmdline_fixed_string_t event;
5565         cmdline_fixed_string_t event_value;
5566         cmdline_fixed_string_t mode;
5567         cmdline_fixed_string_t mode_value;
5568         portid_t port_id;
5569 };
5570
5571 static void
5572 cmd_set_bypass_event_parsed(void *parsed_result,
5573                 __rte_unused struct cmdline *cl,
5574                 __rte_unused void *data)
5575 {
5576         int32_t rc = -EINVAL;
5577         struct cmd_set_bypass_event_result *res = parsed_result;
5578         portid_t port_id = res->port_id;
5579
5580 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5581         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5582         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5583
5584         if (!strcmp(res->event_value, "timeout"))
5585                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
5586         else if (!strcmp(res->event_value, "os_on"))
5587                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
5588         else if (!strcmp(res->event_value, "os_off"))
5589                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
5590         else if (!strcmp(res->event_value, "power_on"))
5591                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
5592         else if (!strcmp(res->event_value, "power_off"))
5593                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
5594         else
5595                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
5596
5597         if (!strcmp(res->mode_value, "bypass"))
5598                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
5599         else if (!strcmp(res->mode_value, "isolate"))
5600                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
5601         else
5602                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
5603
5604         /* Set the watchdog timeout. */
5605         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
5606
5607                 rc = -EINVAL;
5608                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
5609                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
5610                                                            bypass_timeout);
5611                 }
5612                 if (rc != 0) {
5613                         printf("Failed to set timeout value %u "
5614                         "for port %d, errto code: %d.\n",
5615                         bypass_timeout, port_id, rc);
5616                 }
5617         }
5618
5619         /* Set the bypass event to transition to bypass mode. */
5620         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
5621                                               bypass_mode);
5622 #endif
5623
5624         if (rc != 0)
5625                 printf("\t Failed to set bypass event for port = %d.\n",
5626                        port_id);
5627 }
5628
5629 cmdline_parse_token_string_t cmd_setbypass_event_set =
5630         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5631                         set, "set");
5632 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
5633         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5634                         bypass, "bypass");
5635 cmdline_parse_token_string_t cmd_setbypass_event_event =
5636         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5637                         event, "event");
5638 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
5639         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5640                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
5641 cmdline_parse_token_string_t cmd_setbypass_event_mode =
5642         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5643                         mode, "mode");
5644 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
5645         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
5646                         mode_value, "normal#bypass#isolate");
5647 cmdline_parse_token_num_t cmd_setbypass_event_port =
5648         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
5649                                 port_id, UINT16);
5650
5651 cmdline_parse_inst_t cmd_set_bypass_event = {
5652         .f = cmd_set_bypass_event_parsed,
5653         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
5654                 "power_off mode normal|bypass|isolate <port_id>: "
5655                 "Set the NIC bypass event mode for port_id",
5656         .data = NULL,
5657         .tokens = {
5658                 (void *)&cmd_setbypass_event_set,
5659                 (void *)&cmd_setbypass_event_bypass,
5660                 (void *)&cmd_setbypass_event_event,
5661                 (void *)&cmd_setbypass_event_event_value,
5662                 (void *)&cmd_setbypass_event_mode,
5663                 (void *)&cmd_setbypass_event_mode_value,
5664                 (void *)&cmd_setbypass_event_port,
5665                 NULL,
5666         },
5667 };
5668
5669
5670 /* *** SET NIC BYPASS TIMEOUT *** */
5671 struct cmd_set_bypass_timeout_result {
5672         cmdline_fixed_string_t set;
5673         cmdline_fixed_string_t bypass;
5674         cmdline_fixed_string_t timeout;
5675         cmdline_fixed_string_t value;
5676 };
5677
5678 static void
5679 cmd_set_bypass_timeout_parsed(void *parsed_result,
5680                 __rte_unused struct cmdline *cl,
5681                 __rte_unused void *data)
5682 {
5683         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
5684
5685 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5686         if (!strcmp(res->value, "1.5"))
5687                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
5688         else if (!strcmp(res->value, "2"))
5689                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
5690         else if (!strcmp(res->value, "3"))
5691                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
5692         else if (!strcmp(res->value, "4"))
5693                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
5694         else if (!strcmp(res->value, "8"))
5695                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
5696         else if (!strcmp(res->value, "16"))
5697                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
5698         else if (!strcmp(res->value, "32"))
5699                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
5700         else
5701                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5702 #endif
5703 }
5704
5705 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
5706         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5707                         set, "set");
5708 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
5709         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5710                         bypass, "bypass");
5711 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
5712         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5713                         timeout, "timeout");
5714 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
5715         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
5716                         value, "0#1.5#2#3#4#8#16#32");
5717
5718 cmdline_parse_inst_t cmd_set_bypass_timeout = {
5719         .f = cmd_set_bypass_timeout_parsed,
5720         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
5721                 "Set the NIC bypass watchdog timeout in seconds",
5722         .data = NULL,
5723         .tokens = {
5724                 (void *)&cmd_setbypass_timeout_set,
5725                 (void *)&cmd_setbypass_timeout_bypass,
5726                 (void *)&cmd_setbypass_timeout_timeout,
5727                 (void *)&cmd_setbypass_timeout_value,
5728                 NULL,
5729         },
5730 };
5731
5732 /* *** SHOW NIC BYPASS MODE *** */
5733 struct cmd_show_bypass_config_result {
5734         cmdline_fixed_string_t show;
5735         cmdline_fixed_string_t bypass;
5736         cmdline_fixed_string_t config;
5737         portid_t port_id;
5738 };
5739
5740 static void
5741 cmd_show_bypass_config_parsed(void *parsed_result,
5742                 __rte_unused struct cmdline *cl,
5743                 __rte_unused void *data)
5744 {
5745         struct cmd_show_bypass_config_result *res = parsed_result;
5746         portid_t port_id = res->port_id;
5747         int rc = -EINVAL;
5748 #if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
5749         uint32_t event_mode;
5750         uint32_t bypass_mode;
5751         uint32_t timeout = bypass_timeout;
5752         unsigned int i;
5753
5754         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
5755                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
5756         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
5757                 {"UNKNOWN", "normal", "bypass", "isolate"};
5758         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
5759                 "NONE",
5760                 "OS/board on",
5761                 "power supply on",
5762                 "OS/board off",
5763                 "power supply off",
5764                 "timeout"};
5765
5766         /* Display the bypass mode.*/
5767         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
5768                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
5769                 return;
5770         }
5771         else {
5772                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
5773                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5774
5775                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
5776         }
5777
5778         /* Display the bypass timeout.*/
5779         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
5780                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
5781
5782         printf("\tbypass timeout = %s\n", timeouts[timeout]);
5783
5784         /* Display the bypass events and associated modes. */
5785         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) {
5786
5787                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
5788                         printf("\tFailed to get bypass mode for event = %s\n",
5789                                 events[i]);
5790                 } else {
5791                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
5792                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
5793
5794                         printf("\tbypass event: %-16s = %s\n", events[i],
5795                                 modes[event_mode]);
5796                 }
5797         }
5798 #endif
5799         if (rc != 0)
5800                 printf("\tFailed to get bypass configuration for port = %d\n",
5801                        port_id);
5802 }
5803
5804 cmdline_parse_token_string_t cmd_showbypass_config_show =
5805         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5806                         show, "show");
5807 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
5808         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5809                         bypass, "bypass");
5810 cmdline_parse_token_string_t cmd_showbypass_config_config =
5811         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
5812                         config, "config");
5813 cmdline_parse_token_num_t cmd_showbypass_config_port =
5814         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
5815                                 port_id, UINT16);
5816
5817 cmdline_parse_inst_t cmd_show_bypass_config = {
5818         .f = cmd_show_bypass_config_parsed,
5819         .help_str = "show bypass config <port_id>: "
5820                     "Show the NIC bypass config for port_id",
5821         .data = NULL,
5822         .tokens = {
5823                 (void *)&cmd_showbypass_config_show,
5824                 (void *)&cmd_showbypass_config_bypass,
5825                 (void *)&cmd_showbypass_config_config,
5826                 (void *)&cmd_showbypass_config_port,
5827                 NULL,
5828         },
5829 };
5830
5831 #ifdef RTE_NET_BOND
5832 /* *** SET BONDING MODE *** */
5833 struct cmd_set_bonding_mode_result {
5834         cmdline_fixed_string_t set;
5835         cmdline_fixed_string_t bonding;
5836         cmdline_fixed_string_t mode;
5837         uint8_t value;
5838         portid_t port_id;
5839 };
5840
5841 static void cmd_set_bonding_mode_parsed(void *parsed_result,
5842                 __rte_unused  struct cmdline *cl,
5843                 __rte_unused void *data)
5844 {
5845         struct cmd_set_bonding_mode_result *res = parsed_result;
5846         portid_t port_id = res->port_id;
5847
5848         /* Set the bonding mode for the relevant port. */
5849         if (0 != rte_eth_bond_mode_set(port_id, res->value))
5850                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
5851 }
5852
5853 cmdline_parse_token_string_t cmd_setbonding_mode_set =
5854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5855                 set, "set");
5856 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
5857 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5858                 bonding, "bonding");
5859 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
5860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
5861                 mode, "mode");
5862 cmdline_parse_token_num_t cmd_setbonding_mode_value =
5863 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5864                 value, UINT8);
5865 cmdline_parse_token_num_t cmd_setbonding_mode_port =
5866 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
5867                 port_id, UINT16);
5868
5869 cmdline_parse_inst_t cmd_set_bonding_mode = {
5870                 .f = cmd_set_bonding_mode_parsed,
5871                 .help_str = "set bonding mode <mode_value> <port_id>: "
5872                         "Set the bonding mode for port_id",
5873                 .data = NULL,
5874                 .tokens = {
5875                                 (void *) &cmd_setbonding_mode_set,
5876                                 (void *) &cmd_setbonding_mode_bonding,
5877                                 (void *) &cmd_setbonding_mode_mode,
5878                                 (void *) &cmd_setbonding_mode_value,
5879                                 (void *) &cmd_setbonding_mode_port,
5880                                 NULL
5881                 }
5882 };
5883
5884 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
5885 struct cmd_set_bonding_lacp_dedicated_queues_result {
5886         cmdline_fixed_string_t set;
5887         cmdline_fixed_string_t bonding;
5888         cmdline_fixed_string_t lacp;
5889         cmdline_fixed_string_t dedicated_queues;
5890         portid_t port_id;
5891         cmdline_fixed_string_t mode;
5892 };
5893
5894 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
5895                 __rte_unused  struct cmdline *cl,
5896                 __rte_unused void *data)
5897 {
5898         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
5899         portid_t port_id = res->port_id;
5900         struct rte_port *port;
5901
5902         port = &ports[port_id];
5903
5904         /** Check if the port is not started **/
5905         if (port->port_status != RTE_PORT_STOPPED) {
5906                 printf("Please stop port %d first\n", port_id);
5907                 return;
5908         }
5909
5910         if (!strcmp(res->mode, "enable")) {
5911                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
5912                         printf("Dedicate queues for LACP control packets"
5913                                         " enabled\n");
5914                 else
5915                         printf("Enabling dedicate queues for LACP control "
5916                                         "packets on port %d failed\n", port_id);
5917         } else if (!strcmp(res->mode, "disable")) {
5918                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
5919                         printf("Dedicated queues for LACP control packets "
5920                                         "disabled\n");
5921                 else
5922                         printf("Disabling dedicated queues for LACP control "
5923                                         "traffic on port %d failed\n", port_id);
5924         }
5925 }
5926
5927 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
5928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5929                 set, "set");
5930 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
5931 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5932                 bonding, "bonding");
5933 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
5934 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5935                 lacp, "lacp");
5936 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
5937 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5938                 dedicated_queues, "dedicated_queues");
5939 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
5940 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5941                 port_id, UINT16);
5942 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
5943 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
5944                 mode, "enable#disable");
5945
5946 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
5947                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
5948                 .help_str = "set bonding lacp dedicated_queues <port_id> "
5949                         "enable|disable: "
5950                         "Enable/disable dedicated queues for LACP control traffic for port_id",
5951                 .data = NULL,
5952                 .tokens = {
5953                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
5954                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
5955                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
5956                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
5957                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
5958                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
5959                         NULL
5960                 }
5961 };
5962
5963 /* *** SET BALANCE XMIT POLICY *** */
5964 struct cmd_set_bonding_balance_xmit_policy_result {
5965         cmdline_fixed_string_t set;
5966         cmdline_fixed_string_t bonding;
5967         cmdline_fixed_string_t balance_xmit_policy;
5968         portid_t port_id;
5969         cmdline_fixed_string_t policy;
5970 };
5971
5972 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
5973                 __rte_unused  struct cmdline *cl,
5974                 __rte_unused void *data)
5975 {
5976         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
5977         portid_t port_id = res->port_id;
5978         uint8_t policy;
5979
5980         if (!strcmp(res->policy, "l2")) {
5981                 policy = BALANCE_XMIT_POLICY_LAYER2;
5982         } else if (!strcmp(res->policy, "l23")) {
5983                 policy = BALANCE_XMIT_POLICY_LAYER23;
5984         } else if (!strcmp(res->policy, "l34")) {
5985                 policy = BALANCE_XMIT_POLICY_LAYER34;
5986         } else {
5987                 printf("\t Invalid xmit policy selection");
5988                 return;
5989         }
5990
5991         /* Set the bonding mode for the relevant port. */
5992         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
5993                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
5994                                 port_id);
5995         }
5996 }
5997
5998 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
5999 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6000                 set, "set");
6001 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
6002 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6003                 bonding, "bonding");
6004 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
6005 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6006                 balance_xmit_policy, "balance_xmit_policy");
6007 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
6008 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6009                 port_id, UINT16);
6010 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
6011 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
6012                 policy, "l2#l23#l34");
6013
6014 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
6015                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
6016                 .help_str = "set bonding balance_xmit_policy <port_id> "
6017                         "l2|l23|l34: "
6018                         "Set the bonding balance_xmit_policy for port_id",
6019                 .data = NULL,
6020                 .tokens = {
6021                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
6022                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
6023                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
6024                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
6025                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
6026                                 NULL
6027                 }
6028 };
6029
6030 /* *** SHOW NIC BONDING CONFIGURATION *** */
6031 struct cmd_show_bonding_config_result {
6032         cmdline_fixed_string_t show;
6033         cmdline_fixed_string_t bonding;
6034         cmdline_fixed_string_t config;
6035         portid_t port_id;
6036 };
6037
6038 static void cmd_show_bonding_config_parsed(void *parsed_result,
6039                 __rte_unused  struct cmdline *cl,
6040                 __rte_unused void *data)
6041 {
6042         struct cmd_show_bonding_config_result *res = parsed_result;
6043         int bonding_mode, agg_mode;
6044         portid_t slaves[RTE_MAX_ETHPORTS];
6045         int num_slaves, num_active_slaves;
6046         int primary_id;
6047         int i;
6048         portid_t port_id = res->port_id;
6049
6050         /* Display the bonding mode.*/
6051         bonding_mode = rte_eth_bond_mode_get(port_id);
6052         if (bonding_mode < 0) {
6053                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
6054                 return;
6055         } else
6056                 printf("\tBonding mode: %d\n", bonding_mode);
6057
6058         if (bonding_mode == BONDING_MODE_BALANCE) {
6059                 int balance_xmit_policy;
6060
6061                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
6062                 if (balance_xmit_policy < 0) {
6063                         printf("\tFailed to get balance xmit policy for port = %d\n",
6064                                         port_id);
6065                         return;
6066                 } else {
6067                         printf("\tBalance Xmit Policy: ");
6068
6069                         switch (balance_xmit_policy) {
6070                         case BALANCE_XMIT_POLICY_LAYER2:
6071                                 printf("BALANCE_XMIT_POLICY_LAYER2");
6072                                 break;
6073                         case BALANCE_XMIT_POLICY_LAYER23:
6074                                 printf("BALANCE_XMIT_POLICY_LAYER23");
6075                                 break;
6076                         case BALANCE_XMIT_POLICY_LAYER34:
6077                                 printf("BALANCE_XMIT_POLICY_LAYER34");
6078                                 break;
6079                         }
6080                         printf("\n");
6081                 }
6082         }
6083
6084         if (bonding_mode == BONDING_MODE_8023AD) {
6085                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
6086                 printf("\tIEEE802.3AD Aggregator Mode: ");
6087                 switch (agg_mode) {
6088                 case AGG_BANDWIDTH:
6089                         printf("bandwidth");
6090                         break;
6091                 case AGG_STABLE:
6092                         printf("stable");
6093                         break;
6094                 case AGG_COUNT:
6095                         printf("count");
6096                         break;
6097                 }
6098                 printf("\n");
6099         }
6100
6101         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
6102
6103         if (num_slaves < 0) {
6104                 printf("\tFailed to get slave list for port = %d\n", port_id);
6105                 return;
6106         }
6107         if (num_slaves > 0) {
6108                 printf("\tSlaves (%d): [", num_slaves);
6109                 for (i = 0; i < num_slaves - 1; i++)
6110                         printf("%d ", slaves[i]);
6111
6112                 printf("%d]\n", slaves[num_slaves - 1]);
6113         } else {
6114                 printf("\tSlaves: []\n");
6115
6116         }
6117
6118         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
6119                         RTE_MAX_ETHPORTS);
6120
6121         if (num_active_slaves < 0) {
6122                 printf("\tFailed to get active slave list for port = %d\n", port_id);
6123                 return;
6124         }
6125         if (num_active_slaves > 0) {
6126                 printf("\tActive Slaves (%d): [", num_active_slaves);
6127                 for (i = 0; i < num_active_slaves - 1; i++)
6128                         printf("%d ", slaves[i]);
6129
6130                 printf("%d]\n", slaves[num_active_slaves - 1]);
6131
6132         } else {
6133                 printf("\tActive Slaves: []\n");
6134
6135         }
6136
6137         primary_id = rte_eth_bond_primary_get(port_id);
6138         if (primary_id < 0) {
6139                 printf("\tFailed to get primary slave for port = %d\n", port_id);
6140                 return;
6141         } else
6142                 printf("\tPrimary: [%d]\n", primary_id);
6143
6144 }
6145
6146 cmdline_parse_token_string_t cmd_showbonding_config_show =
6147 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6148                 show, "show");
6149 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
6150 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6151                 bonding, "bonding");
6152 cmdline_parse_token_string_t cmd_showbonding_config_config =
6153 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
6154                 config, "config");
6155 cmdline_parse_token_num_t cmd_showbonding_config_port =
6156 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
6157                 port_id, UINT16);
6158
6159 cmdline_parse_inst_t cmd_show_bonding_config = {
6160                 .f = cmd_show_bonding_config_parsed,
6161                 .help_str = "show bonding config <port_id>: "
6162                         "Show the bonding config for port_id",
6163                 .data = NULL,
6164                 .tokens = {
6165                                 (void *)&cmd_showbonding_config_show,
6166                                 (void *)&cmd_showbonding_config_bonding,
6167                                 (void *)&cmd_showbonding_config_config,
6168                                 (void *)&cmd_showbonding_config_port,
6169                                 NULL
6170                 }
6171 };
6172
6173 /* *** SET BONDING PRIMARY *** */
6174 struct cmd_set_bonding_primary_result {
6175         cmdline_fixed_string_t set;
6176         cmdline_fixed_string_t bonding;
6177         cmdline_fixed_string_t primary;
6178         portid_t slave_id;
6179         portid_t port_id;
6180 };
6181
6182 static void cmd_set_bonding_primary_parsed(void *parsed_result,
6183                 __rte_unused  struct cmdline *cl,
6184                 __rte_unused void *data)
6185 {
6186         struct cmd_set_bonding_primary_result *res = parsed_result;
6187         portid_t master_port_id = res->port_id;
6188         portid_t slave_port_id = res->slave_id;
6189
6190         /* Set the primary slave for a bonded device. */
6191         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
6192                 printf("\t Failed to set primary slave for port = %d.\n",
6193                                 master_port_id);
6194                 return;
6195         }
6196         init_port_config();
6197 }
6198
6199 cmdline_parse_token_string_t cmd_setbonding_primary_set =
6200 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6201                 set, "set");
6202 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
6203 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6204                 bonding, "bonding");
6205 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
6206 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
6207                 primary, "primary");
6208 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
6209 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6210                 slave_id, UINT16);
6211 cmdline_parse_token_num_t cmd_setbonding_primary_port =
6212 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
6213                 port_id, UINT16);
6214
6215 cmdline_parse_inst_t cmd_set_bonding_primary = {
6216                 .f = cmd_set_bonding_primary_parsed,
6217                 .help_str = "set bonding primary <slave_id> <port_id>: "
6218                         "Set the primary slave for port_id",
6219                 .data = NULL,
6220                 .tokens = {
6221                                 (void *)&cmd_setbonding_primary_set,
6222                                 (void *)&cmd_setbonding_primary_bonding,
6223                                 (void *)&cmd_setbonding_primary_primary,
6224                                 (void *)&cmd_setbonding_primary_slave,
6225                                 (void *)&cmd_setbonding_primary_port,
6226                                 NULL
6227                 }
6228 };
6229
6230 /* *** ADD SLAVE *** */
6231 struct cmd_add_bonding_slave_result {
6232         cmdline_fixed_string_t add;
6233         cmdline_fixed_string_t bonding;
6234         cmdline_fixed_string_t slave;
6235         portid_t slave_id;
6236         portid_t port_id;
6237 };
6238
6239 static void cmd_add_bonding_slave_parsed(void *parsed_result,
6240                 __rte_unused  struct cmdline *cl,
6241                 __rte_unused void *data)
6242 {
6243         struct cmd_add_bonding_slave_result *res = parsed_result;
6244         portid_t master_port_id = res->port_id;
6245         portid_t slave_port_id = res->slave_id;
6246
6247         /* add the slave for a bonded device. */
6248         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
6249                 printf("\t Failed to add slave %d to master port = %d.\n",
6250                                 slave_port_id, master_port_id);
6251                 return;
6252         }
6253         init_port_config();
6254         set_port_slave_flag(slave_port_id);
6255 }
6256
6257 cmdline_parse_token_string_t cmd_addbonding_slave_add =
6258 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6259                 add, "add");
6260 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
6261 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6262                 bonding, "bonding");
6263 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
6264 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
6265                 slave, "slave");
6266 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
6267 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6268                 slave_id, UINT16);
6269 cmdline_parse_token_num_t cmd_addbonding_slave_port =
6270 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
6271                 port_id, UINT16);
6272
6273 cmdline_parse_inst_t cmd_add_bonding_slave = {
6274                 .f = cmd_add_bonding_slave_parsed,
6275                 .help_str = "add bonding slave <slave_id> <port_id>: "
6276                         "Add a slave device to a bonded device",
6277                 .data = NULL,
6278                 .tokens = {
6279                                 (void *)&cmd_addbonding_slave_add,
6280                                 (void *)&cmd_addbonding_slave_bonding,
6281                                 (void *)&cmd_addbonding_slave_slave,
6282                                 (void *)&cmd_addbonding_slave_slaveid,
6283                                 (void *)&cmd_addbonding_slave_port,
6284                                 NULL
6285                 }
6286 };
6287
6288 /* *** REMOVE SLAVE *** */
6289 struct cmd_remove_bonding_slave_result {
6290         cmdline_fixed_string_t remove;
6291         cmdline_fixed_string_t bonding;
6292         cmdline_fixed_string_t slave;
6293         portid_t slave_id;
6294         portid_t port_id;
6295 };
6296
6297 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
6298                 __rte_unused  struct cmdline *cl,
6299                 __rte_unused void *data)
6300 {
6301         struct cmd_remove_bonding_slave_result *res = parsed_result;
6302         portid_t master_port_id = res->port_id;
6303         portid_t slave_port_id = res->slave_id;
6304
6305         /* remove the slave from a bonded device. */
6306         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
6307                 printf("\t Failed to remove slave %d from master port = %d.\n",
6308                                 slave_port_id, master_port_id);
6309                 return;
6310         }
6311         init_port_config();
6312         clear_port_slave_flag(slave_port_id);
6313 }
6314
6315 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
6316                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6317                                 remove, "remove");
6318 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
6319                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6320                                 bonding, "bonding");
6321 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
6322                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
6323                                 slave, "slave");
6324 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
6325                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6326                                 slave_id, UINT16);
6327 cmdline_parse_token_num_t cmd_removebonding_slave_port =
6328                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
6329                                 port_id, UINT16);
6330
6331 cmdline_parse_inst_t cmd_remove_bonding_slave = {
6332                 .f = cmd_remove_bonding_slave_parsed,
6333                 .help_str = "remove bonding slave <slave_id> <port_id>: "
6334                         "Remove a slave device from a bonded device",
6335                 .data = NULL,
6336                 .tokens = {
6337                                 (void *)&cmd_removebonding_slave_remove,
6338                                 (void *)&cmd_removebonding_slave_bonding,
6339                                 (void *)&cmd_removebonding_slave_slave,
6340                                 (void *)&cmd_removebonding_slave_slaveid,
6341                                 (void *)&cmd_removebonding_slave_port,
6342                                 NULL
6343                 }
6344 };
6345
6346 /* *** CREATE BONDED DEVICE *** */
6347 struct cmd_create_bonded_device_result {
6348         cmdline_fixed_string_t create;
6349         cmdline_fixed_string_t bonded;
6350         cmdline_fixed_string_t device;
6351         uint8_t mode;
6352         uint8_t socket;
6353 };
6354
6355 static int bond_dev_num = 0;
6356
6357 static void cmd_create_bonded_device_parsed(void *parsed_result,
6358                 __rte_unused  struct cmdline *cl,
6359                 __rte_unused void *data)
6360 {
6361         struct cmd_create_bonded_device_result *res = parsed_result;
6362         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
6363         int port_id;
6364         int ret;
6365
6366         if (test_done == 0) {
6367                 printf("Please stop forwarding first\n");
6368                 return;
6369         }
6370
6371         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
6372                         bond_dev_num++);
6373
6374         /* Create a new bonded device. */
6375         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
6376         if (port_id < 0) {
6377                 printf("\t Failed to create bonded device.\n");
6378                 return;
6379         } else {
6380                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
6381                                 port_id);
6382
6383                 /* Update number of ports */
6384                 nb_ports = rte_eth_dev_count_avail();
6385                 reconfig(port_id, res->socket);
6386                 ret = rte_eth_promiscuous_enable(port_id);
6387                 if (ret != 0)
6388                         printf("Failed to enable promiscuous mode for port %u: %s - ignore\n",
6389                                 port_id, rte_strerror(-ret));
6390
6391                 ports[port_id].need_setup = 0;
6392                 ports[port_id].port_status = RTE_PORT_STOPPED;
6393         }
6394
6395 }
6396
6397 cmdline_parse_token_string_t cmd_createbonded_device_create =
6398                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6399                                 create, "create");
6400 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
6401                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6402                                 bonded, "bonded");
6403 cmdline_parse_token_string_t cmd_createbonded_device_device =
6404                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
6405                                 device, "device");
6406 cmdline_parse_token_num_t cmd_createbonded_device_mode =
6407                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6408                                 mode, UINT8);
6409 cmdline_parse_token_num_t cmd_createbonded_device_socket =
6410                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
6411                                 socket, UINT8);
6412
6413 cmdline_parse_inst_t cmd_create_bonded_device = {
6414                 .f = cmd_create_bonded_device_parsed,
6415                 .help_str = "create bonded device <mode> <socket>: "
6416                         "Create a new bonded device with specific bonding mode and socket",
6417                 .data = NULL,
6418                 .tokens = {
6419                                 (void *)&cmd_createbonded_device_create,
6420                                 (void *)&cmd_createbonded_device_bonded,
6421                                 (void *)&cmd_createbonded_device_device,
6422                                 (void *)&cmd_createbonded_device_mode,
6423                                 (void *)&cmd_createbonded_device_socket,
6424                                 NULL
6425                 }
6426 };
6427
6428 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
6429 struct cmd_set_bond_mac_addr_result {
6430         cmdline_fixed_string_t set;
6431         cmdline_fixed_string_t bonding;
6432         cmdline_fixed_string_t mac_addr;
6433         uint16_t port_num;
6434         struct rte_ether_addr address;
6435 };
6436
6437 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
6438                 __rte_unused  struct cmdline *cl,
6439                 __rte_unused void *data)
6440 {
6441         struct cmd_set_bond_mac_addr_result *res = parsed_result;
6442         int ret;
6443
6444         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
6445                 return;
6446
6447         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
6448
6449         /* check the return value and print it if is < 0 */
6450         if (ret < 0)
6451                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6452 }
6453
6454 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
6455                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
6456 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
6457                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
6458                                 "bonding");
6459 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
6460                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
6461                                 "mac_addr");
6462 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
6463                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
6464                                 port_num, UINT16);
6465 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
6466                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
6467
6468 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
6469                 .f = cmd_set_bond_mac_addr_parsed,
6470                 .data = (void *) 0,
6471                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
6472                 .tokens = {
6473                                 (void *)&cmd_set_bond_mac_addr_set,
6474                                 (void *)&cmd_set_bond_mac_addr_bonding,
6475                                 (void *)&cmd_set_bond_mac_addr_mac,
6476                                 (void *)&cmd_set_bond_mac_addr_portnum,
6477                                 (void *)&cmd_set_bond_mac_addr_addr,
6478                                 NULL
6479                 }
6480 };
6481
6482
6483 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
6484 struct cmd_set_bond_mon_period_result {
6485         cmdline_fixed_string_t set;
6486         cmdline_fixed_string_t bonding;
6487         cmdline_fixed_string_t mon_period;
6488         uint16_t port_num;
6489         uint32_t period_ms;
6490 };
6491
6492 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
6493                 __rte_unused  struct cmdline *cl,
6494                 __rte_unused void *data)
6495 {
6496         struct cmd_set_bond_mon_period_result *res = parsed_result;
6497         int ret;
6498
6499         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
6500
6501         /* check the return value and print it if is < 0 */
6502         if (ret < 0)
6503                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
6504 }
6505
6506 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
6507                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6508                                 set, "set");
6509 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
6510                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6511                                 bonding, "bonding");
6512 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
6513                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
6514                                 mon_period,     "mon_period");
6515 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
6516                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6517                                 port_num, UINT16);
6518 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
6519                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
6520                                 period_ms, UINT32);
6521
6522 cmdline_parse_inst_t cmd_set_bond_mon_period = {
6523                 .f = cmd_set_bond_mon_period_parsed,
6524                 .data = (void *) 0,
6525                 .help_str = "set bonding mon_period <port_id> <period_ms>",
6526                 .tokens = {
6527                                 (void *)&cmd_set_bond_mon_period_set,
6528                                 (void *)&cmd_set_bond_mon_period_bonding,
6529                                 (void *)&cmd_set_bond_mon_period_mon_period,
6530                                 (void *)&cmd_set_bond_mon_period_portnum,
6531                                 (void *)&cmd_set_bond_mon_period_period_ms,
6532                                 NULL
6533                 }
6534 };
6535
6536
6537
6538 struct cmd_set_bonding_agg_mode_policy_result {
6539         cmdline_fixed_string_t set;
6540         cmdline_fixed_string_t bonding;
6541         cmdline_fixed_string_t agg_mode;
6542         uint16_t port_num;
6543         cmdline_fixed_string_t policy;
6544 };
6545
6546
6547 static void
6548 cmd_set_bonding_agg_mode(void *parsed_result,
6549                 __rte_unused struct cmdline *cl,
6550                 __rte_unused void *data)
6551 {
6552         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
6553         uint8_t policy = AGG_BANDWIDTH;
6554
6555         if (!strcmp(res->policy, "bandwidth"))
6556                 policy = AGG_BANDWIDTH;
6557         else if (!strcmp(res->policy, "stable"))
6558                 policy = AGG_STABLE;
6559         else if (!strcmp(res->policy, "count"))
6560                 policy = AGG_COUNT;
6561
6562         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
6563 }
6564
6565
6566 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
6567         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6568                                 set, "set");
6569 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
6570         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6571                                 bonding, "bonding");
6572
6573 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
6574         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6575                                 agg_mode, "agg_mode");
6576
6577 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
6578         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
6579                                 port_num, UINT16);
6580
6581 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
6582         TOKEN_STRING_INITIALIZER(
6583                         struct cmd_set_bonding_balance_xmit_policy_result,
6584                 policy, "stable#bandwidth#count");
6585
6586 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
6587         .f = cmd_set_bonding_agg_mode,
6588         .data = (void *) 0,
6589         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
6590         .tokens = {
6591                         (void *)&cmd_set_bonding_agg_mode_set,
6592                         (void *)&cmd_set_bonding_agg_mode_bonding,
6593                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
6594                         (void *)&cmd_set_bonding_agg_mode_portnum,
6595                         (void *)&cmd_set_bonding_agg_mode_policy_string,
6596                         NULL
6597                 }
6598 };
6599
6600
6601 #endif /* RTE_NET_BOND */
6602
6603 /* *** SET FORWARDING MODE *** */
6604 struct cmd_set_fwd_mode_result {
6605         cmdline_fixed_string_t set;
6606         cmdline_fixed_string_t fwd;
6607         cmdline_fixed_string_t mode;
6608 };
6609
6610 static void cmd_set_fwd_mode_parsed(void *parsed_result,
6611                                     __rte_unused struct cmdline *cl,
6612                                     __rte_unused void *data)
6613 {
6614         struct cmd_set_fwd_mode_result *res = parsed_result;
6615
6616         retry_enabled = 0;
6617         set_pkt_forwarding_mode(res->mode);
6618 }
6619
6620 cmdline_parse_token_string_t cmd_setfwd_set =
6621         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
6622 cmdline_parse_token_string_t cmd_setfwd_fwd =
6623         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
6624 cmdline_parse_token_string_t cmd_setfwd_mode =
6625         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
6626                 "" /* defined at init */);
6627
6628 cmdline_parse_inst_t cmd_set_fwd_mode = {
6629         .f = cmd_set_fwd_mode_parsed,
6630         .data = NULL,
6631         .help_str = NULL, /* defined at init */
6632         .tokens = {
6633                 (void *)&cmd_setfwd_set,
6634                 (void *)&cmd_setfwd_fwd,
6635                 (void *)&cmd_setfwd_mode,
6636                 NULL,
6637         },
6638 };
6639
6640 static void cmd_set_fwd_mode_init(void)
6641 {
6642         char *modes, *c;
6643         static char token[128];
6644         static char help[256];
6645         cmdline_parse_token_string_t *token_struct;
6646
6647         modes = list_pkt_forwarding_modes();
6648         snprintf(help, sizeof(help), "set fwd %s: "
6649                 "Set packet forwarding mode", modes);
6650         cmd_set_fwd_mode.help_str = help;
6651
6652         /* string token separator is # */
6653         for (c = token; *modes != '\0'; modes++)
6654                 if (*modes == '|')
6655                         *c++ = '#';
6656                 else
6657                         *c++ = *modes;
6658         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
6659         token_struct->string_data.str = token;
6660 }
6661
6662 /* *** SET RETRY FORWARDING MODE *** */
6663 struct cmd_set_fwd_retry_mode_result {
6664         cmdline_fixed_string_t set;
6665         cmdline_fixed_string_t fwd;
6666         cmdline_fixed_string_t mode;
6667         cmdline_fixed_string_t retry;
6668 };
6669
6670 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
6671                             __rte_unused struct cmdline *cl,
6672                             __rte_unused void *data)
6673 {
6674         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
6675
6676         retry_enabled = 1;
6677         set_pkt_forwarding_mode(res->mode);
6678 }
6679
6680 cmdline_parse_token_string_t cmd_setfwd_retry_set =
6681         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6682                         set, "set");
6683 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
6684         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6685                         fwd, "fwd");
6686 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
6687         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6688                         mode,
6689                 "" /* defined at init */);
6690 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
6691         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
6692                         retry, "retry");
6693
6694 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
6695         .f = cmd_set_fwd_retry_mode_parsed,
6696         .data = NULL,
6697         .help_str = NULL, /* defined at init */
6698         .tokens = {
6699                 (void *)&cmd_setfwd_retry_set,
6700                 (void *)&cmd_setfwd_retry_fwd,
6701                 (void *)&cmd_setfwd_retry_mode,
6702                 (void *)&cmd_setfwd_retry_retry,
6703                 NULL,
6704         },
6705 };
6706
6707 static void cmd_set_fwd_retry_mode_init(void)
6708 {
6709         char *modes, *c;
6710         static char token[128];
6711         static char help[256];
6712         cmdline_parse_token_string_t *token_struct;
6713
6714         modes = list_pkt_forwarding_retry_modes();
6715         snprintf(help, sizeof(help), "set fwd %s retry: "
6716                 "Set packet forwarding mode with retry", modes);
6717         cmd_set_fwd_retry_mode.help_str = help;
6718
6719         /* string token separator is # */
6720         for (c = token; *modes != '\0'; modes++)
6721                 if (*modes == '|')
6722                         *c++ = '#';
6723                 else
6724                         *c++ = *modes;
6725         token_struct = (cmdline_parse_token_string_t *)
6726                 cmd_set_fwd_retry_mode.tokens[2];
6727         token_struct->string_data.str = token;
6728 }
6729
6730 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
6731 struct cmd_set_burst_tx_retry_result {
6732         cmdline_fixed_string_t set;
6733         cmdline_fixed_string_t burst;
6734         cmdline_fixed_string_t tx;
6735         cmdline_fixed_string_t delay;
6736         uint32_t time;
6737         cmdline_fixed_string_t retry;
6738         uint32_t retry_num;
6739 };
6740
6741 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
6742                                         __rte_unused struct cmdline *cl,
6743                                         __rte_unused void *data)
6744 {
6745         struct cmd_set_burst_tx_retry_result *res = parsed_result;
6746
6747         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
6748                 && !strcmp(res->tx, "tx")) {
6749                 if (!strcmp(res->delay, "delay"))
6750                         burst_tx_delay_time = res->time;
6751                 if (!strcmp(res->retry, "retry"))
6752                         burst_tx_retry_num = res->retry_num;
6753         }
6754
6755 }
6756
6757 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
6758         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
6759 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
6760         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
6761                                  "burst");
6762 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
6763         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
6764 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
6765         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
6766 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
6767         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
6768 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
6769         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
6770 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
6771         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
6772
6773 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
6774         .f = cmd_set_burst_tx_retry_parsed,
6775         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
6776         .tokens = {
6777                 (void *)&cmd_set_burst_tx_retry_set,
6778                 (void *)&cmd_set_burst_tx_retry_burst,
6779                 (void *)&cmd_set_burst_tx_retry_tx,
6780                 (void *)&cmd_set_burst_tx_retry_delay,
6781                 (void *)&cmd_set_burst_tx_retry_time,
6782                 (void *)&cmd_set_burst_tx_retry_retry,
6783                 (void *)&cmd_set_burst_tx_retry_retry_num,
6784                 NULL,
6785         },
6786 };
6787
6788 /* *** SET PROMISC MODE *** */
6789 struct cmd_set_promisc_mode_result {
6790         cmdline_fixed_string_t set;
6791         cmdline_fixed_string_t promisc;
6792         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6793         uint16_t port_num;               /* valid if "allports" argument == 0 */
6794         cmdline_fixed_string_t mode;
6795 };
6796
6797 static void cmd_set_promisc_mode_parsed(void *parsed_result,
6798                                         __rte_unused struct cmdline *cl,
6799                                         void *allports)
6800 {
6801         struct cmd_set_promisc_mode_result *res = parsed_result;
6802         int enable;
6803         portid_t i;
6804
6805         if (!strcmp(res->mode, "on"))
6806                 enable = 1;
6807         else
6808                 enable = 0;
6809
6810         /* all ports */
6811         if (allports) {
6812                 RTE_ETH_FOREACH_DEV(i)
6813                         eth_set_promisc_mode(i, enable);
6814         } else {
6815                 eth_set_promisc_mode(res->port_num, enable);
6816         }
6817 }
6818
6819 cmdline_parse_token_string_t cmd_setpromisc_set =
6820         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
6821 cmdline_parse_token_string_t cmd_setpromisc_promisc =
6822         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
6823                                  "promisc");
6824 cmdline_parse_token_string_t cmd_setpromisc_portall =
6825         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
6826                                  "all");
6827 cmdline_parse_token_num_t cmd_setpromisc_portnum =
6828         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
6829                               UINT16);
6830 cmdline_parse_token_string_t cmd_setpromisc_mode =
6831         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
6832                                  "on#off");
6833
6834 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
6835         .f = cmd_set_promisc_mode_parsed,
6836         .data = (void *)1,
6837         .help_str = "set promisc all on|off: Set promisc mode for all ports",
6838         .tokens = {
6839                 (void *)&cmd_setpromisc_set,
6840                 (void *)&cmd_setpromisc_promisc,
6841                 (void *)&cmd_setpromisc_portall,
6842                 (void *)&cmd_setpromisc_mode,
6843                 NULL,
6844         },
6845 };
6846
6847 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
6848         .f = cmd_set_promisc_mode_parsed,
6849         .data = (void *)0,
6850         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
6851         .tokens = {
6852                 (void *)&cmd_setpromisc_set,
6853                 (void *)&cmd_setpromisc_promisc,
6854                 (void *)&cmd_setpromisc_portnum,
6855                 (void *)&cmd_setpromisc_mode,
6856                 NULL,
6857         },
6858 };
6859
6860 /* *** SET ALLMULTI MODE *** */
6861 struct cmd_set_allmulti_mode_result {
6862         cmdline_fixed_string_t set;
6863         cmdline_fixed_string_t allmulti;
6864         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
6865         uint16_t port_num;               /* valid if "allports" argument == 0 */
6866         cmdline_fixed_string_t mode;
6867 };
6868
6869 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
6870                                         __rte_unused struct cmdline *cl,
6871                                         void *allports)
6872 {
6873         struct cmd_set_allmulti_mode_result *res = parsed_result;
6874         int enable;
6875         portid_t i;
6876
6877         if (!strcmp(res->mode, "on"))
6878                 enable = 1;
6879         else
6880                 enable = 0;
6881
6882         /* all ports */
6883         if (allports) {
6884                 RTE_ETH_FOREACH_DEV(i) {
6885                         eth_set_allmulticast_mode(i, enable);
6886                 }
6887         }
6888         else {
6889                 eth_set_allmulticast_mode(res->port_num, enable);
6890         }
6891 }
6892
6893 cmdline_parse_token_string_t cmd_setallmulti_set =
6894         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
6895 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
6896         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
6897                                  "allmulti");
6898 cmdline_parse_token_string_t cmd_setallmulti_portall =
6899         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
6900                                  "all");
6901 cmdline_parse_token_num_t cmd_setallmulti_portnum =
6902         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
6903                               UINT16);
6904 cmdline_parse_token_string_t cmd_setallmulti_mode =
6905         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
6906                                  "on#off");
6907
6908 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
6909         .f = cmd_set_allmulti_mode_parsed,
6910         .data = (void *)1,
6911         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
6912         .tokens = {
6913                 (void *)&cmd_setallmulti_set,
6914                 (void *)&cmd_setallmulti_allmulti,
6915                 (void *)&cmd_setallmulti_portall,
6916                 (void *)&cmd_setallmulti_mode,
6917                 NULL,
6918         },
6919 };
6920
6921 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
6922         .f = cmd_set_allmulti_mode_parsed,
6923         .data = (void *)0,
6924         .help_str = "set allmulti <port_id> on|off: "
6925                 "Set allmulti mode on port_id",
6926         .tokens = {
6927                 (void *)&cmd_setallmulti_set,
6928                 (void *)&cmd_setallmulti_allmulti,
6929                 (void *)&cmd_setallmulti_portnum,
6930                 (void *)&cmd_setallmulti_mode,
6931                 NULL,
6932         },
6933 };
6934
6935 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
6936 struct cmd_link_flow_ctrl_set_result {
6937         cmdline_fixed_string_t set;
6938         cmdline_fixed_string_t flow_ctrl;
6939         cmdline_fixed_string_t rx;
6940         cmdline_fixed_string_t rx_lfc_mode;
6941         cmdline_fixed_string_t tx;
6942         cmdline_fixed_string_t tx_lfc_mode;
6943         cmdline_fixed_string_t mac_ctrl_frame_fwd;
6944         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
6945         cmdline_fixed_string_t autoneg_str;
6946         cmdline_fixed_string_t autoneg;
6947         cmdline_fixed_string_t hw_str;
6948         uint32_t high_water;
6949         cmdline_fixed_string_t lw_str;
6950         uint32_t low_water;
6951         cmdline_fixed_string_t pt_str;
6952         uint16_t pause_time;
6953         cmdline_fixed_string_t xon_str;
6954         uint16_t send_xon;
6955         portid_t port_id;
6956 };
6957
6958 cmdline_parse_token_string_t cmd_lfc_set_set =
6959         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6960                                 set, "set");
6961 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
6962         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6963                                 flow_ctrl, "flow_ctrl");
6964 cmdline_parse_token_string_t cmd_lfc_set_rx =
6965         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6966                                 rx, "rx");
6967 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
6968         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6969                                 rx_lfc_mode, "on#off");
6970 cmdline_parse_token_string_t cmd_lfc_set_tx =
6971         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6972                                 tx, "tx");
6973 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
6974         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6975                                 tx_lfc_mode, "on#off");
6976 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
6977         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6978                                 hw_str, "high_water");
6979 cmdline_parse_token_num_t cmd_lfc_set_high_water =
6980         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6981                                 high_water, UINT32);
6982 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
6983         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6984                                 lw_str, "low_water");
6985 cmdline_parse_token_num_t cmd_lfc_set_low_water =
6986         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6987                                 low_water, UINT32);
6988 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
6989         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6990                                 pt_str, "pause_time");
6991 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
6992         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6993                                 pause_time, UINT16);
6994 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
6995         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6996                                 xon_str, "send_xon");
6997 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
6998         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
6999                                 send_xon, UINT16);
7000 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
7001         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7002                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
7003 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
7004         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7005                                 mac_ctrl_frame_fwd_mode, "on#off");
7006 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
7007         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7008                                 autoneg_str, "autoneg");
7009 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
7010         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7011                                 autoneg, "on#off");
7012 cmdline_parse_token_num_t cmd_lfc_set_portid =
7013         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
7014                                 port_id, UINT16);
7015
7016 /* forward declaration */
7017 static void
7018 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
7019                               void *data);
7020
7021 cmdline_parse_inst_t cmd_link_flow_control_set = {
7022         .f = cmd_link_flow_ctrl_set_parsed,
7023         .data = NULL,
7024         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
7025                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
7026                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
7027         .tokens = {
7028                 (void *)&cmd_lfc_set_set,
7029                 (void *)&cmd_lfc_set_flow_ctrl,
7030                 (void *)&cmd_lfc_set_rx,
7031                 (void *)&cmd_lfc_set_rx_mode,
7032                 (void *)&cmd_lfc_set_tx,
7033                 (void *)&cmd_lfc_set_tx_mode,
7034                 (void *)&cmd_lfc_set_high_water,
7035                 (void *)&cmd_lfc_set_low_water,
7036                 (void *)&cmd_lfc_set_pause_time,
7037                 (void *)&cmd_lfc_set_send_xon,
7038                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7039                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7040                 (void *)&cmd_lfc_set_autoneg_str,
7041                 (void *)&cmd_lfc_set_autoneg,
7042                 (void *)&cmd_lfc_set_portid,
7043                 NULL,
7044         },
7045 };
7046
7047 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
7048         .f = cmd_link_flow_ctrl_set_parsed,
7049         .data = (void *)&cmd_link_flow_control_set_rx,
7050         .help_str = "set flow_ctrl rx on|off <port_id>: "
7051                 "Change rx flow control parameter",
7052         .tokens = {
7053                 (void *)&cmd_lfc_set_set,
7054                 (void *)&cmd_lfc_set_flow_ctrl,
7055                 (void *)&cmd_lfc_set_rx,
7056                 (void *)&cmd_lfc_set_rx_mode,
7057                 (void *)&cmd_lfc_set_portid,
7058                 NULL,
7059         },
7060 };
7061
7062 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
7063         .f = cmd_link_flow_ctrl_set_parsed,
7064         .data = (void *)&cmd_link_flow_control_set_tx,
7065         .help_str = "set flow_ctrl tx on|off <port_id>: "
7066                 "Change tx flow control parameter",
7067         .tokens = {
7068                 (void *)&cmd_lfc_set_set,
7069                 (void *)&cmd_lfc_set_flow_ctrl,
7070                 (void *)&cmd_lfc_set_tx,
7071                 (void *)&cmd_lfc_set_tx_mode,
7072                 (void *)&cmd_lfc_set_portid,
7073                 NULL,
7074         },
7075 };
7076
7077 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
7078         .f = cmd_link_flow_ctrl_set_parsed,
7079         .data = (void *)&cmd_link_flow_control_set_hw,
7080         .help_str = "set flow_ctrl high_water <value> <port_id>: "
7081                 "Change high water flow control parameter",
7082         .tokens = {
7083                 (void *)&cmd_lfc_set_set,
7084                 (void *)&cmd_lfc_set_flow_ctrl,
7085                 (void *)&cmd_lfc_set_high_water_str,
7086                 (void *)&cmd_lfc_set_high_water,
7087                 (void *)&cmd_lfc_set_portid,
7088                 NULL,
7089         },
7090 };
7091
7092 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
7093         .f = cmd_link_flow_ctrl_set_parsed,
7094         .data = (void *)&cmd_link_flow_control_set_lw,
7095         .help_str = "set flow_ctrl low_water <value> <port_id>: "
7096                 "Change low water flow control parameter",
7097         .tokens = {
7098                 (void *)&cmd_lfc_set_set,
7099                 (void *)&cmd_lfc_set_flow_ctrl,
7100                 (void *)&cmd_lfc_set_low_water_str,
7101                 (void *)&cmd_lfc_set_low_water,
7102                 (void *)&cmd_lfc_set_portid,
7103                 NULL,
7104         },
7105 };
7106
7107 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
7108         .f = cmd_link_flow_ctrl_set_parsed,
7109         .data = (void *)&cmd_link_flow_control_set_pt,
7110         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
7111                 "Change pause time flow control parameter",
7112         .tokens = {
7113                 (void *)&cmd_lfc_set_set,
7114                 (void *)&cmd_lfc_set_flow_ctrl,
7115                 (void *)&cmd_lfc_set_pause_time_str,
7116                 (void *)&cmd_lfc_set_pause_time,
7117                 (void *)&cmd_lfc_set_portid,
7118                 NULL,
7119         },
7120 };
7121
7122 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
7123         .f = cmd_link_flow_ctrl_set_parsed,
7124         .data = (void *)&cmd_link_flow_control_set_xon,
7125         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
7126                 "Change send_xon flow control parameter",
7127         .tokens = {
7128                 (void *)&cmd_lfc_set_set,
7129                 (void *)&cmd_lfc_set_flow_ctrl,
7130                 (void *)&cmd_lfc_set_send_xon_str,
7131                 (void *)&cmd_lfc_set_send_xon,
7132                 (void *)&cmd_lfc_set_portid,
7133                 NULL,
7134         },
7135 };
7136
7137 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
7138         .f = cmd_link_flow_ctrl_set_parsed,
7139         .data = (void *)&cmd_link_flow_control_set_macfwd,
7140         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
7141                 "Change mac ctrl fwd flow control parameter",
7142         .tokens = {
7143                 (void *)&cmd_lfc_set_set,
7144                 (void *)&cmd_lfc_set_flow_ctrl,
7145                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
7146                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
7147                 (void *)&cmd_lfc_set_portid,
7148                 NULL,
7149         },
7150 };
7151
7152 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
7153         .f = cmd_link_flow_ctrl_set_parsed,
7154         .data = (void *)&cmd_link_flow_control_set_autoneg,
7155         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
7156                 "Change autoneg flow control parameter",
7157         .tokens = {
7158                 (void *)&cmd_lfc_set_set,
7159                 (void *)&cmd_lfc_set_flow_ctrl,
7160                 (void *)&cmd_lfc_set_autoneg_str,
7161                 (void *)&cmd_lfc_set_autoneg,
7162                 (void *)&cmd_lfc_set_portid,
7163                 NULL,
7164         },
7165 };
7166
7167 static void
7168 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
7169                               __rte_unused struct cmdline *cl,
7170                               void *data)
7171 {
7172         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
7173         cmdline_parse_inst_t *cmd = data;
7174         struct rte_eth_fc_conf fc_conf;
7175         int rx_fc_en = 0;
7176         int tx_fc_en = 0;
7177         int ret;
7178
7179         /*
7180          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7181          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7182          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7183          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7184          */
7185         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
7186                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7187         };
7188
7189         /* Partial command line, retrieve current configuration */
7190         if (cmd) {
7191                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
7192                 if (ret != 0) {
7193                         printf("cannot get current flow ctrl parameters, return"
7194                                "code = %d\n", ret);
7195                         return;
7196                 }
7197
7198                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
7199                     (fc_conf.mode == RTE_FC_FULL))
7200                         rx_fc_en = 1;
7201                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
7202                     (fc_conf.mode == RTE_FC_FULL))
7203                         tx_fc_en = 1;
7204         }
7205
7206         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
7207                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
7208
7209         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
7210                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
7211
7212         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
7213
7214         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
7215                 fc_conf.high_water = res->high_water;
7216
7217         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
7218                 fc_conf.low_water = res->low_water;
7219
7220         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
7221                 fc_conf.pause_time = res->pause_time;
7222
7223         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
7224                 fc_conf.send_xon = res->send_xon;
7225
7226         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
7227                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
7228                         fc_conf.mac_ctrl_frame_fwd = 1;
7229                 else
7230                         fc_conf.mac_ctrl_frame_fwd = 0;
7231         }
7232
7233         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
7234                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
7235
7236         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
7237         if (ret != 0)
7238                 printf("bad flow contrl parameter, return code = %d \n", ret);
7239 }
7240
7241 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
7242 struct cmd_priority_flow_ctrl_set_result {
7243         cmdline_fixed_string_t set;
7244         cmdline_fixed_string_t pfc_ctrl;
7245         cmdline_fixed_string_t rx;
7246         cmdline_fixed_string_t rx_pfc_mode;
7247         cmdline_fixed_string_t tx;
7248         cmdline_fixed_string_t tx_pfc_mode;
7249         uint32_t high_water;
7250         uint32_t low_water;
7251         uint16_t pause_time;
7252         uint8_t  priority;
7253         portid_t port_id;
7254 };
7255
7256 static void
7257 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
7258                        __rte_unused struct cmdline *cl,
7259                        __rte_unused void *data)
7260 {
7261         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
7262         struct rte_eth_pfc_conf pfc_conf;
7263         int rx_fc_enable, tx_fc_enable;
7264         int ret;
7265
7266         /*
7267          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
7268          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
7269          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
7270          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
7271          */
7272         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
7273                 {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
7274         };
7275
7276         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_conf));
7277         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
7278         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
7279         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
7280         pfc_conf.fc.high_water = res->high_water;
7281         pfc_conf.fc.low_water  = res->low_water;
7282         pfc_conf.fc.pause_time = res->pause_time;
7283         pfc_conf.priority      = res->priority;
7284
7285         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
7286         if (ret != 0)
7287                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
7288 }
7289
7290 cmdline_parse_token_string_t cmd_pfc_set_set =
7291         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7292                                 set, "set");
7293 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
7294         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7295                                 pfc_ctrl, "pfc_ctrl");
7296 cmdline_parse_token_string_t cmd_pfc_set_rx =
7297         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7298                                 rx, "rx");
7299 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
7300         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7301                                 rx_pfc_mode, "on#off");
7302 cmdline_parse_token_string_t cmd_pfc_set_tx =
7303         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7304                                 tx, "tx");
7305 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
7306         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7307                                 tx_pfc_mode, "on#off");
7308 cmdline_parse_token_num_t cmd_pfc_set_high_water =
7309         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7310                                 high_water, UINT32);
7311 cmdline_parse_token_num_t cmd_pfc_set_low_water =
7312         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7313                                 low_water, UINT32);
7314 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
7315         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7316                                 pause_time, UINT16);
7317 cmdline_parse_token_num_t cmd_pfc_set_priority =
7318         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7319                                 priority, UINT8);
7320 cmdline_parse_token_num_t cmd_pfc_set_portid =
7321         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
7322                                 port_id, UINT16);
7323
7324 cmdline_parse_inst_t cmd_priority_flow_control_set = {
7325         .f = cmd_priority_flow_ctrl_set_parsed,
7326         .data = NULL,
7327         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
7328                 "<pause_time> <priority> <port_id>: "
7329                 "Configure the Ethernet priority flow control",
7330         .tokens = {
7331                 (void *)&cmd_pfc_set_set,
7332                 (void *)&cmd_pfc_set_flow_ctrl,
7333                 (void *)&cmd_pfc_set_rx,
7334                 (void *)&cmd_pfc_set_rx_mode,
7335                 (void *)&cmd_pfc_set_tx,
7336                 (void *)&cmd_pfc_set_tx_mode,
7337                 (void *)&cmd_pfc_set_high_water,
7338                 (void *)&cmd_pfc_set_low_water,
7339                 (void *)&cmd_pfc_set_pause_time,
7340                 (void *)&cmd_pfc_set_priority,
7341                 (void *)&cmd_pfc_set_portid,
7342                 NULL,
7343         },
7344 };
7345
7346 /* *** RESET CONFIGURATION *** */
7347 struct cmd_reset_result {
7348         cmdline_fixed_string_t reset;
7349         cmdline_fixed_string_t def;
7350 };
7351
7352 static void cmd_reset_parsed(__rte_unused void *parsed_result,
7353                              struct cmdline *cl,
7354                              __rte_unused void *data)
7355 {
7356         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
7357         set_def_fwd_config();
7358 }
7359
7360 cmdline_parse_token_string_t cmd_reset_set =
7361         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
7362 cmdline_parse_token_string_t cmd_reset_def =
7363         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
7364                                  "default");
7365
7366 cmdline_parse_inst_t cmd_reset = {
7367         .f = cmd_reset_parsed,
7368         .data = NULL,
7369         .help_str = "set default: Reset default forwarding configuration",
7370         .tokens = {
7371                 (void *)&cmd_reset_set,
7372                 (void *)&cmd_reset_def,
7373                 NULL,
7374         },
7375 };
7376
7377 /* *** START FORWARDING *** */
7378 struct cmd_start_result {
7379         cmdline_fixed_string_t start;
7380 };
7381
7382 cmdline_parse_token_string_t cmd_start_start =
7383         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
7384
7385 static void cmd_start_parsed(__rte_unused void *parsed_result,
7386                              __rte_unused struct cmdline *cl,
7387                              __rte_unused void *data)
7388 {
7389         start_packet_forwarding(0);
7390 }
7391
7392 cmdline_parse_inst_t cmd_start = {
7393         .f = cmd_start_parsed,
7394         .data = NULL,
7395         .help_str = "start: Start packet forwarding",
7396         .tokens = {
7397                 (void *)&cmd_start_start,
7398                 NULL,
7399         },
7400 };
7401
7402 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
7403 struct cmd_start_tx_first_result {
7404         cmdline_fixed_string_t start;
7405         cmdline_fixed_string_t tx_first;
7406 };
7407
7408 static void
7409 cmd_start_tx_first_parsed(__rte_unused void *parsed_result,
7410                           __rte_unused struct cmdline *cl,
7411                           __rte_unused void *data)
7412 {
7413         start_packet_forwarding(1);
7414 }
7415
7416 cmdline_parse_token_string_t cmd_start_tx_first_start =
7417         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
7418                                  "start");
7419 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
7420         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
7421                                  tx_first, "tx_first");
7422
7423 cmdline_parse_inst_t cmd_start_tx_first = {
7424         .f = cmd_start_tx_first_parsed,
7425         .data = NULL,
7426         .help_str = "start tx_first: Start packet forwarding, "
7427                 "after sending 1 burst of packets",
7428         .tokens = {
7429                 (void *)&cmd_start_tx_first_start,
7430                 (void *)&cmd_start_tx_first_tx_first,
7431                 NULL,
7432         },
7433 };
7434
7435 /* *** START FORWARDING WITH N TX BURST FIRST *** */
7436 struct cmd_start_tx_first_n_result {
7437         cmdline_fixed_string_t start;
7438         cmdline_fixed_string_t tx_first;
7439         uint32_t tx_num;
7440 };
7441
7442 static void
7443 cmd_start_tx_first_n_parsed(void *parsed_result,
7444                           __rte_unused struct cmdline *cl,
7445                           __rte_unused void *data)
7446 {
7447         struct cmd_start_tx_first_n_result *res = parsed_result;
7448
7449         start_packet_forwarding(res->tx_num);
7450 }
7451
7452 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
7453         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7454                         start, "start");
7455 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
7456         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
7457                         tx_first, "tx_first");
7458 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
7459         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
7460                         tx_num, UINT32);
7461
7462 cmdline_parse_inst_t cmd_start_tx_first_n = {
7463         .f = cmd_start_tx_first_n_parsed,
7464         .data = NULL,
7465         .help_str = "start tx_first <num>: "
7466                 "packet forwarding, after sending <num> bursts of packets",
7467         .tokens = {
7468                 (void *)&cmd_start_tx_first_n_start,
7469                 (void *)&cmd_start_tx_first_n_tx_first,
7470                 (void *)&cmd_start_tx_first_n_tx_num,
7471                 NULL,
7472         },
7473 };
7474
7475 /* *** SET LINK UP *** */
7476 struct cmd_set_link_up_result {
7477         cmdline_fixed_string_t set;
7478         cmdline_fixed_string_t link_up;
7479         cmdline_fixed_string_t port;
7480         portid_t port_id;
7481 };
7482
7483 cmdline_parse_token_string_t cmd_set_link_up_set =
7484         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
7485 cmdline_parse_token_string_t cmd_set_link_up_link_up =
7486         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
7487                                 "link-up");
7488 cmdline_parse_token_string_t cmd_set_link_up_port =
7489         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
7490 cmdline_parse_token_num_t cmd_set_link_up_port_id =
7491         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
7492
7493 static void cmd_set_link_up_parsed(__rte_unused void *parsed_result,
7494                              __rte_unused struct cmdline *cl,
7495                              __rte_unused void *data)
7496 {
7497         struct cmd_set_link_up_result *res = parsed_result;
7498         dev_set_link_up(res->port_id);
7499 }
7500
7501 cmdline_parse_inst_t cmd_set_link_up = {
7502         .f = cmd_set_link_up_parsed,
7503         .data = NULL,
7504         .help_str = "set link-up port <port id>",
7505         .tokens = {
7506                 (void *)&cmd_set_link_up_set,
7507                 (void *)&cmd_set_link_up_link_up,
7508                 (void *)&cmd_set_link_up_port,
7509                 (void *)&cmd_set_link_up_port_id,
7510                 NULL,
7511         },
7512 };
7513
7514 /* *** SET LINK DOWN *** */
7515 struct cmd_set_link_down_result {
7516         cmdline_fixed_string_t set;
7517         cmdline_fixed_string_t link_down;
7518         cmdline_fixed_string_t port;
7519         portid_t port_id;
7520 };
7521
7522 cmdline_parse_token_string_t cmd_set_link_down_set =
7523         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
7524 cmdline_parse_token_string_t cmd_set_link_down_link_down =
7525         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
7526                                 "link-down");
7527 cmdline_parse_token_string_t cmd_set_link_down_port =
7528         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
7529 cmdline_parse_token_num_t cmd_set_link_down_port_id =
7530         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
7531
7532 static void cmd_set_link_down_parsed(
7533                                 __rte_unused void *parsed_result,
7534                                 __rte_unused struct cmdline *cl,
7535                                 __rte_unused void *data)
7536 {
7537         struct cmd_set_link_down_result *res = parsed_result;
7538         dev_set_link_down(res->port_id);
7539 }
7540
7541 cmdline_parse_inst_t cmd_set_link_down = {
7542         .f = cmd_set_link_down_parsed,
7543         .data = NULL,
7544         .help_str = "set link-down port <port id>",
7545         .tokens = {
7546                 (void *)&cmd_set_link_down_set,
7547                 (void *)&cmd_set_link_down_link_down,
7548                 (void *)&cmd_set_link_down_port,
7549                 (void *)&cmd_set_link_down_port_id,
7550                 NULL,
7551         },
7552 };
7553
7554 /* *** SHOW CFG *** */
7555 struct cmd_showcfg_result {
7556         cmdline_fixed_string_t show;
7557         cmdline_fixed_string_t cfg;
7558         cmdline_fixed_string_t what;
7559 };
7560
7561 static void cmd_showcfg_parsed(void *parsed_result,
7562                                __rte_unused struct cmdline *cl,
7563                                __rte_unused void *data)
7564 {
7565         struct cmd_showcfg_result *res = parsed_result;
7566         if (!strcmp(res->what, "rxtx"))
7567                 rxtx_config_display();
7568         else if (!strcmp(res->what, "cores"))
7569                 fwd_lcores_config_display();
7570         else if (!strcmp(res->what, "fwd"))
7571                 pkt_fwd_config_display(&cur_fwd_config);
7572         else if (!strcmp(res->what, "rxoffs"))
7573                 show_rx_pkt_offsets();
7574         else if (!strcmp(res->what, "rxpkts"))
7575                 show_rx_pkt_segments();
7576         else if (!strcmp(res->what, "txpkts"))
7577                 show_tx_pkt_segments();
7578         else if (!strcmp(res->what, "txtimes"))
7579                 show_tx_pkt_times();
7580 }
7581
7582 cmdline_parse_token_string_t cmd_showcfg_show =
7583         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
7584 cmdline_parse_token_string_t cmd_showcfg_port =
7585         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
7586 cmdline_parse_token_string_t cmd_showcfg_what =
7587         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
7588                                  "rxtx#cores#fwd#rxoffs#rxpkts#txpkts#txtimes");
7589
7590 cmdline_parse_inst_t cmd_showcfg = {
7591         .f = cmd_showcfg_parsed,
7592         .data = NULL,
7593         .help_str = "show config rxtx|cores|fwd|rxoffs|rxpkts|txpkts|txtimes",
7594         .tokens = {
7595                 (void *)&cmd_showcfg_show,
7596                 (void *)&cmd_showcfg_port,
7597                 (void *)&cmd_showcfg_what,
7598                 NULL,
7599         },
7600 };
7601
7602 /* *** SHOW ALL PORT INFO *** */
7603 struct cmd_showportall_result {
7604         cmdline_fixed_string_t show;
7605         cmdline_fixed_string_t port;
7606         cmdline_fixed_string_t what;
7607         cmdline_fixed_string_t all;
7608 };
7609
7610 static void cmd_showportall_parsed(void *parsed_result,
7611                                 __rte_unused struct cmdline *cl,
7612                                 __rte_unused void *data)
7613 {
7614         portid_t i;
7615
7616         struct cmd_showportall_result *res = parsed_result;
7617         if (!strcmp(res->show, "clear")) {
7618                 if (!strcmp(res->what, "stats"))
7619                         RTE_ETH_FOREACH_DEV(i)
7620                                 nic_stats_clear(i);
7621                 else if (!strcmp(res->what, "xstats"))
7622                         RTE_ETH_FOREACH_DEV(i)
7623                                 nic_xstats_clear(i);
7624         } else if (!strcmp(res->what, "info"))
7625                 RTE_ETH_FOREACH_DEV(i)
7626                         port_infos_display(i);
7627         else if (!strcmp(res->what, "summary")) {
7628                 port_summary_header_display();
7629                 RTE_ETH_FOREACH_DEV(i)
7630                         port_summary_display(i);
7631         }
7632         else if (!strcmp(res->what, "stats"))
7633                 RTE_ETH_FOREACH_DEV(i)
7634                         nic_stats_display(i);
7635         else if (!strcmp(res->what, "xstats"))
7636                 RTE_ETH_FOREACH_DEV(i)
7637                         nic_xstats_display(i);
7638         else if (!strcmp(res->what, "fdir"))
7639                 RTE_ETH_FOREACH_DEV(i)
7640                         fdir_get_infos(i);
7641         else if (!strcmp(res->what, "stat_qmap"))
7642                 RTE_ETH_FOREACH_DEV(i)
7643                         nic_stats_mapping_display(i);
7644         else if (!strcmp(res->what, "dcb_tc"))
7645                 RTE_ETH_FOREACH_DEV(i)
7646                         port_dcb_info_display(i);
7647         else if (!strcmp(res->what, "cap"))
7648                 RTE_ETH_FOREACH_DEV(i)
7649                         port_offload_cap_display(i);
7650 }
7651
7652 cmdline_parse_token_string_t cmd_showportall_show =
7653         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
7654                                  "show#clear");
7655 cmdline_parse_token_string_t cmd_showportall_port =
7656         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
7657 cmdline_parse_token_string_t cmd_showportall_what =
7658         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
7659                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7660 cmdline_parse_token_string_t cmd_showportall_all =
7661         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
7662 cmdline_parse_inst_t cmd_showportall = {
7663         .f = cmd_showportall_parsed,
7664         .data = NULL,
7665         .help_str = "show|clear port "
7666                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
7667         .tokens = {
7668                 (void *)&cmd_showportall_show,
7669                 (void *)&cmd_showportall_port,
7670                 (void *)&cmd_showportall_what,
7671                 (void *)&cmd_showportall_all,
7672                 NULL,
7673         },
7674 };
7675
7676 /* *** SHOW PORT INFO *** */
7677 struct cmd_showport_result {
7678         cmdline_fixed_string_t show;
7679         cmdline_fixed_string_t port;
7680         cmdline_fixed_string_t what;
7681         uint16_t portnum;
7682 };
7683
7684 static void cmd_showport_parsed(void *parsed_result,
7685                                 __rte_unused struct cmdline *cl,
7686                                 __rte_unused void *data)
7687 {
7688         struct cmd_showport_result *res = parsed_result;
7689         if (!strcmp(res->show, "clear")) {
7690                 if (!strcmp(res->what, "stats"))
7691                         nic_stats_clear(res->portnum);
7692                 else if (!strcmp(res->what, "xstats"))
7693                         nic_xstats_clear(res->portnum);
7694         } else if (!strcmp(res->what, "info"))
7695                 port_infos_display(res->portnum);
7696         else if (!strcmp(res->what, "summary")) {
7697                 port_summary_header_display();
7698                 port_summary_display(res->portnum);
7699         }
7700         else if (!strcmp(res->what, "stats"))
7701                 nic_stats_display(res->portnum);
7702         else if (!strcmp(res->what, "xstats"))
7703                 nic_xstats_display(res->portnum);
7704         else if (!strcmp(res->what, "fdir"))
7705                  fdir_get_infos(res->portnum);
7706         else if (!strcmp(res->what, "stat_qmap"))
7707                 nic_stats_mapping_display(res->portnum);
7708         else if (!strcmp(res->what, "dcb_tc"))
7709                 port_dcb_info_display(res->portnum);
7710         else if (!strcmp(res->what, "cap"))
7711                 port_offload_cap_display(res->portnum);
7712 }
7713
7714 cmdline_parse_token_string_t cmd_showport_show =
7715         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
7716                                  "show#clear");
7717 cmdline_parse_token_string_t cmd_showport_port =
7718         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
7719 cmdline_parse_token_string_t cmd_showport_what =
7720         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
7721                                  "info#summary#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
7722 cmdline_parse_token_num_t cmd_showport_portnum =
7723         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
7724
7725 cmdline_parse_inst_t cmd_showport = {
7726         .f = cmd_showport_parsed,
7727         .data = NULL,
7728         .help_str = "show|clear port "
7729                 "info|summary|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
7730                 "<port_id>",
7731         .tokens = {
7732                 (void *)&cmd_showport_show,
7733                 (void *)&cmd_showport_port,
7734                 (void *)&cmd_showport_what,
7735                 (void *)&cmd_showport_portnum,
7736                 NULL,
7737         },
7738 };
7739
7740 /* *** SHOW DEVICE INFO *** */
7741 struct cmd_showdevice_result {
7742         cmdline_fixed_string_t show;
7743         cmdline_fixed_string_t device;
7744         cmdline_fixed_string_t what;
7745         cmdline_fixed_string_t identifier;
7746 };
7747
7748 static void cmd_showdevice_parsed(void *parsed_result,
7749                                 __rte_unused struct cmdline *cl,
7750                                 __rte_unused void *data)
7751 {
7752         struct cmd_showdevice_result *res = parsed_result;
7753         if (!strcmp(res->what, "info")) {
7754                 if (!strcmp(res->identifier, "all"))
7755                         device_infos_display(NULL);
7756                 else
7757                         device_infos_display(res->identifier);
7758         }
7759 }
7760
7761 cmdline_parse_token_string_t cmd_showdevice_show =
7762         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, show,
7763                                  "show");
7764 cmdline_parse_token_string_t cmd_showdevice_device =
7765         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, device, "device");
7766 cmdline_parse_token_string_t cmd_showdevice_what =
7767         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, what,
7768                                  "info");
7769 cmdline_parse_token_string_t cmd_showdevice_identifier =
7770         TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result,
7771                         identifier, NULL);
7772
7773 cmdline_parse_inst_t cmd_showdevice = {
7774         .f = cmd_showdevice_parsed,
7775         .data = NULL,
7776         .help_str = "show device info <identifier>|all",
7777         .tokens = {
7778                 (void *)&cmd_showdevice_show,
7779                 (void *)&cmd_showdevice_device,
7780                 (void *)&cmd_showdevice_what,
7781                 (void *)&cmd_showdevice_identifier,
7782                 NULL,
7783         },
7784 };
7785
7786 /* *** SHOW MODULE EEPROM/EEPROM port INFO *** */
7787 struct cmd_showeeprom_result {
7788         cmdline_fixed_string_t show;
7789         cmdline_fixed_string_t port;
7790         uint16_t portnum;
7791         cmdline_fixed_string_t type;
7792 };
7793
7794 static void cmd_showeeprom_parsed(void *parsed_result,
7795                 __rte_unused struct cmdline *cl,
7796                 __rte_unused void *data)
7797 {
7798         struct cmd_showeeprom_result *res = parsed_result;
7799
7800         if (!strcmp(res->type, "eeprom"))
7801                 port_eeprom_display(res->portnum);
7802         else if (!strcmp(res->type, "module_eeprom"))
7803                 port_module_eeprom_display(res->portnum);
7804         else
7805                 printf("Unknown argument\n");
7806 }
7807
7808 cmdline_parse_token_string_t cmd_showeeprom_show =
7809         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, show, "show");
7810 cmdline_parse_token_string_t cmd_showeeprom_port =
7811         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, port, "port");
7812 cmdline_parse_token_num_t cmd_showeeprom_portnum =
7813         TOKEN_NUM_INITIALIZER(struct cmd_showeeprom_result, portnum, UINT16);
7814 cmdline_parse_token_string_t cmd_showeeprom_type =
7815         TOKEN_STRING_INITIALIZER(struct cmd_showeeprom_result, type, "module_eeprom#eeprom");
7816
7817 cmdline_parse_inst_t cmd_showeeprom = {
7818         .f = cmd_showeeprom_parsed,
7819         .data = NULL,
7820         .help_str = "show port <port_id> module_eeprom|eeprom",
7821         .tokens = {
7822                 (void *)&cmd_showeeprom_show,
7823                 (void *)&cmd_showeeprom_port,
7824                 (void *)&cmd_showeeprom_portnum,
7825                 (void *)&cmd_showeeprom_type,
7826                 NULL,
7827         },
7828 };
7829
7830 /* *** SHOW QUEUE INFO *** */
7831 struct cmd_showqueue_result {
7832         cmdline_fixed_string_t show;
7833         cmdline_fixed_string_t type;
7834         cmdline_fixed_string_t what;
7835         uint16_t portnum;
7836         uint16_t queuenum;
7837 };
7838
7839 static void
7840 cmd_showqueue_parsed(void *parsed_result,
7841         __rte_unused struct cmdline *cl,
7842         __rte_unused void *data)
7843 {
7844         struct cmd_showqueue_result *res = parsed_result;
7845
7846         if (!strcmp(res->type, "rxq"))
7847                 rx_queue_infos_display(res->portnum, res->queuenum);
7848         else if (!strcmp(res->type, "txq"))
7849                 tx_queue_infos_display(res->portnum, res->queuenum);
7850 }
7851
7852 cmdline_parse_token_string_t cmd_showqueue_show =
7853         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
7854 cmdline_parse_token_string_t cmd_showqueue_type =
7855         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
7856 cmdline_parse_token_string_t cmd_showqueue_what =
7857         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
7858 cmdline_parse_token_num_t cmd_showqueue_portnum =
7859         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
7860 cmdline_parse_token_num_t cmd_showqueue_queuenum =
7861         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
7862
7863 cmdline_parse_inst_t cmd_showqueue = {
7864         .f = cmd_showqueue_parsed,
7865         .data = NULL,
7866         .help_str = "show rxq|txq info <port_id> <queue_id>",
7867         .tokens = {
7868                 (void *)&cmd_showqueue_show,
7869                 (void *)&cmd_showqueue_type,
7870                 (void *)&cmd_showqueue_what,
7871                 (void *)&cmd_showqueue_portnum,
7872                 (void *)&cmd_showqueue_queuenum,
7873                 NULL,
7874         },
7875 };
7876
7877 /* show/clear fwd engine statistics */
7878 struct fwd_result {
7879         cmdline_fixed_string_t action;
7880         cmdline_fixed_string_t fwd;
7881         cmdline_fixed_string_t stats;
7882         cmdline_fixed_string_t all;
7883 };
7884
7885 cmdline_parse_token_string_t cmd_fwd_action =
7886         TOKEN_STRING_INITIALIZER(struct fwd_result, action, "show#clear");
7887 cmdline_parse_token_string_t cmd_fwd_fwd =
7888         TOKEN_STRING_INITIALIZER(struct fwd_result, fwd, "fwd");
7889 cmdline_parse_token_string_t cmd_fwd_stats =
7890         TOKEN_STRING_INITIALIZER(struct fwd_result, stats, "stats");
7891 cmdline_parse_token_string_t cmd_fwd_all =
7892         TOKEN_STRING_INITIALIZER(struct fwd_result, all, "all");
7893
7894 static void
7895 cmd_showfwdall_parsed(void *parsed_result,
7896                       __rte_unused struct cmdline *cl,
7897                       __rte_unused void *data)
7898 {
7899         struct fwd_result *res = parsed_result;
7900
7901         if (!strcmp(res->action, "show"))
7902                 fwd_stats_display();
7903         else
7904                 fwd_stats_reset();
7905 }
7906
7907 static cmdline_parse_inst_t cmd_showfwdall = {
7908         .f = cmd_showfwdall_parsed,
7909         .data = NULL,
7910         .help_str = "show|clear fwd stats all",
7911         .tokens = {
7912                 (void *)&cmd_fwd_action,
7913                 (void *)&cmd_fwd_fwd,
7914                 (void *)&cmd_fwd_stats,
7915                 (void *)&cmd_fwd_all,
7916                 NULL,
7917         },
7918 };
7919
7920 /* *** READ PORT REGISTER *** */
7921 struct cmd_read_reg_result {
7922         cmdline_fixed_string_t read;
7923         cmdline_fixed_string_t reg;
7924         portid_t port_id;
7925         uint32_t reg_off;
7926 };
7927
7928 static void
7929 cmd_read_reg_parsed(void *parsed_result,
7930                     __rte_unused struct cmdline *cl,
7931                     __rte_unused void *data)
7932 {
7933         struct cmd_read_reg_result *res = parsed_result;
7934         port_reg_display(res->port_id, res->reg_off);
7935 }
7936
7937 cmdline_parse_token_string_t cmd_read_reg_read =
7938         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
7939 cmdline_parse_token_string_t cmd_read_reg_reg =
7940         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
7941 cmdline_parse_token_num_t cmd_read_reg_port_id =
7942         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
7943 cmdline_parse_token_num_t cmd_read_reg_reg_off =
7944         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
7945
7946 cmdline_parse_inst_t cmd_read_reg = {
7947         .f = cmd_read_reg_parsed,
7948         .data = NULL,
7949         .help_str = "read reg <port_id> <reg_off>",
7950         .tokens = {
7951                 (void *)&cmd_read_reg_read,
7952                 (void *)&cmd_read_reg_reg,
7953                 (void *)&cmd_read_reg_port_id,
7954                 (void *)&cmd_read_reg_reg_off,
7955                 NULL,
7956         },
7957 };
7958
7959 /* *** READ PORT REGISTER BIT FIELD *** */
7960 struct cmd_read_reg_bit_field_result {
7961         cmdline_fixed_string_t read;
7962         cmdline_fixed_string_t regfield;
7963         portid_t port_id;
7964         uint32_t reg_off;
7965         uint8_t bit1_pos;
7966         uint8_t bit2_pos;
7967 };
7968
7969 static void
7970 cmd_read_reg_bit_field_parsed(void *parsed_result,
7971                               __rte_unused struct cmdline *cl,
7972                               __rte_unused void *data)
7973 {
7974         struct cmd_read_reg_bit_field_result *res = parsed_result;
7975         port_reg_bit_field_display(res->port_id, res->reg_off,
7976                                    res->bit1_pos, res->bit2_pos);
7977 }
7978
7979 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
7980         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
7981                                  "read");
7982 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
7983         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
7984                                  regfield, "regfield");
7985 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
7986         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
7987                               UINT16);
7988 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
7989         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
7990                               UINT32);
7991 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
7992         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
7993                               UINT8);
7994 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
7995         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
7996                               UINT8);
7997
7998 cmdline_parse_inst_t cmd_read_reg_bit_field = {
7999         .f = cmd_read_reg_bit_field_parsed,
8000         .data = NULL,
8001         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
8002         "Read register bit field between bit_x and bit_y included",
8003         .tokens = {
8004                 (void *)&cmd_read_reg_bit_field_read,
8005                 (void *)&cmd_read_reg_bit_field_regfield,
8006                 (void *)&cmd_read_reg_bit_field_port_id,
8007                 (void *)&cmd_read_reg_bit_field_reg_off,
8008                 (void *)&cmd_read_reg_bit_field_bit1_pos,
8009                 (void *)&cmd_read_reg_bit_field_bit2_pos,
8010                 NULL,
8011         },
8012 };
8013
8014 /* *** READ PORT REGISTER BIT *** */
8015 struct cmd_read_reg_bit_result {
8016         cmdline_fixed_string_t read;
8017         cmdline_fixed_string_t regbit;
8018         portid_t port_id;
8019         uint32_t reg_off;
8020         uint8_t bit_pos;
8021 };
8022
8023 static void
8024 cmd_read_reg_bit_parsed(void *parsed_result,
8025                         __rte_unused struct cmdline *cl,
8026                         __rte_unused void *data)
8027 {
8028         struct cmd_read_reg_bit_result *res = parsed_result;
8029         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
8030 }
8031
8032 cmdline_parse_token_string_t cmd_read_reg_bit_read =
8033         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
8034 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
8035         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
8036                                  regbit, "regbit");
8037 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
8038         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
8039 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
8040         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
8041 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
8042         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
8043
8044 cmdline_parse_inst_t cmd_read_reg_bit = {
8045         .f = cmd_read_reg_bit_parsed,
8046         .data = NULL,
8047         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
8048         .tokens = {
8049                 (void *)&cmd_read_reg_bit_read,
8050                 (void *)&cmd_read_reg_bit_regbit,
8051                 (void *)&cmd_read_reg_bit_port_id,
8052                 (void *)&cmd_read_reg_bit_reg_off,
8053                 (void *)&cmd_read_reg_bit_bit_pos,
8054                 NULL,
8055         },
8056 };
8057
8058 /* *** WRITE PORT REGISTER *** */
8059 struct cmd_write_reg_result {
8060         cmdline_fixed_string_t write;
8061         cmdline_fixed_string_t reg;
8062         portid_t port_id;
8063         uint32_t reg_off;
8064         uint32_t value;
8065 };
8066
8067 static void
8068 cmd_write_reg_parsed(void *parsed_result,
8069                      __rte_unused struct cmdline *cl,
8070                      __rte_unused void *data)
8071 {
8072         struct cmd_write_reg_result *res = parsed_result;
8073         port_reg_set(res->port_id, res->reg_off, res->value);
8074 }
8075
8076 cmdline_parse_token_string_t cmd_write_reg_write =
8077         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
8078 cmdline_parse_token_string_t cmd_write_reg_reg =
8079         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
8080 cmdline_parse_token_num_t cmd_write_reg_port_id =
8081         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
8082 cmdline_parse_token_num_t cmd_write_reg_reg_off =
8083         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
8084 cmdline_parse_token_num_t cmd_write_reg_value =
8085         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
8086
8087 cmdline_parse_inst_t cmd_write_reg = {
8088         .f = cmd_write_reg_parsed,
8089         .data = NULL,
8090         .help_str = "write reg <port_id> <reg_off> <reg_value>",
8091         .tokens = {
8092                 (void *)&cmd_write_reg_write,
8093                 (void *)&cmd_write_reg_reg,
8094                 (void *)&cmd_write_reg_port_id,
8095                 (void *)&cmd_write_reg_reg_off,
8096                 (void *)&cmd_write_reg_value,
8097                 NULL,
8098         },
8099 };
8100
8101 /* *** WRITE PORT REGISTER BIT FIELD *** */
8102 struct cmd_write_reg_bit_field_result {
8103         cmdline_fixed_string_t write;
8104         cmdline_fixed_string_t regfield;
8105         portid_t port_id;
8106         uint32_t reg_off;
8107         uint8_t bit1_pos;
8108         uint8_t bit2_pos;
8109         uint32_t value;
8110 };
8111
8112 static void
8113 cmd_write_reg_bit_field_parsed(void *parsed_result,
8114                                __rte_unused struct cmdline *cl,
8115                                __rte_unused void *data)
8116 {
8117         struct cmd_write_reg_bit_field_result *res = parsed_result;
8118         port_reg_bit_field_set(res->port_id, res->reg_off,
8119                           res->bit1_pos, res->bit2_pos, res->value);
8120 }
8121
8122 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
8123         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
8124                                  "write");
8125 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
8126         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
8127                                  regfield, "regfield");
8128 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
8129         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
8130                               UINT16);
8131 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
8132         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
8133                               UINT32);
8134 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
8135         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
8136                               UINT8);
8137 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
8138         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
8139                               UINT8);
8140 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
8141         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
8142                               UINT32);
8143
8144 cmdline_parse_inst_t cmd_write_reg_bit_field = {
8145         .f = cmd_write_reg_bit_field_parsed,
8146         .data = NULL,
8147         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
8148                 "<reg_value>: "
8149                 "Set register bit field between bit_x and bit_y included",
8150         .tokens = {
8151                 (void *)&cmd_write_reg_bit_field_write,
8152                 (void *)&cmd_write_reg_bit_field_regfield,
8153                 (void *)&cmd_write_reg_bit_field_port_id,
8154                 (void *)&cmd_write_reg_bit_field_reg_off,
8155                 (void *)&cmd_write_reg_bit_field_bit1_pos,
8156                 (void *)&cmd_write_reg_bit_field_bit2_pos,
8157                 (void *)&cmd_write_reg_bit_field_value,
8158                 NULL,
8159         },
8160 };
8161
8162 /* *** WRITE PORT REGISTER BIT *** */
8163 struct cmd_write_reg_bit_result {
8164         cmdline_fixed_string_t write;
8165         cmdline_fixed_string_t regbit;
8166         portid_t port_id;
8167         uint32_t reg_off;
8168         uint8_t bit_pos;
8169         uint8_t value;
8170 };
8171
8172 static void
8173 cmd_write_reg_bit_parsed(void *parsed_result,
8174                          __rte_unused struct cmdline *cl,
8175                          __rte_unused void *data)
8176 {
8177         struct cmd_write_reg_bit_result *res = parsed_result;
8178         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
8179 }
8180
8181 cmdline_parse_token_string_t cmd_write_reg_bit_write =
8182         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
8183                                  "write");
8184 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
8185         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
8186                                  regbit, "regbit");
8187 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
8188         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
8189 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
8190         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
8191 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
8192         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
8193 cmdline_parse_token_num_t cmd_write_reg_bit_value =
8194         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
8195
8196 cmdline_parse_inst_t cmd_write_reg_bit = {
8197         .f = cmd_write_reg_bit_parsed,
8198         .data = NULL,
8199         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
8200                 "0 <= bit_x <= 31",
8201         .tokens = {
8202                 (void *)&cmd_write_reg_bit_write,
8203                 (void *)&cmd_write_reg_bit_regbit,
8204                 (void *)&cmd_write_reg_bit_port_id,
8205                 (void *)&cmd_write_reg_bit_reg_off,
8206                 (void *)&cmd_write_reg_bit_bit_pos,
8207                 (void *)&cmd_write_reg_bit_value,
8208                 NULL,
8209         },
8210 };
8211
8212 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
8213 struct cmd_read_rxd_txd_result {
8214         cmdline_fixed_string_t read;
8215         cmdline_fixed_string_t rxd_txd;
8216         portid_t port_id;
8217         uint16_t queue_id;
8218         uint16_t desc_id;
8219 };
8220
8221 static void
8222 cmd_read_rxd_txd_parsed(void *parsed_result,
8223                         __rte_unused struct cmdline *cl,
8224                         __rte_unused void *data)
8225 {
8226         struct cmd_read_rxd_txd_result *res = parsed_result;
8227
8228         if (!strcmp(res->rxd_txd, "rxd"))
8229                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8230         else if (!strcmp(res->rxd_txd, "txd"))
8231                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
8232 }
8233
8234 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
8235         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
8236 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
8237         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
8238                                  "rxd#txd");
8239 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
8240         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
8241 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
8242         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
8243 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
8244         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
8245
8246 cmdline_parse_inst_t cmd_read_rxd_txd = {
8247         .f = cmd_read_rxd_txd_parsed,
8248         .data = NULL,
8249         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
8250         .tokens = {
8251                 (void *)&cmd_read_rxd_txd_read,
8252                 (void *)&cmd_read_rxd_txd_rxd_txd,
8253                 (void *)&cmd_read_rxd_txd_port_id,
8254                 (void *)&cmd_read_rxd_txd_queue_id,
8255                 (void *)&cmd_read_rxd_txd_desc_id,
8256                 NULL,
8257         },
8258 };
8259
8260 /* *** QUIT *** */
8261 struct cmd_quit_result {
8262         cmdline_fixed_string_t quit;
8263 };
8264
8265 static void cmd_quit_parsed(__rte_unused void *parsed_result,
8266                             struct cmdline *cl,
8267                             __rte_unused void *data)
8268 {
8269         cmdline_quit(cl);
8270 }
8271
8272 cmdline_parse_token_string_t cmd_quit_quit =
8273         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
8274
8275 cmdline_parse_inst_t cmd_quit = {
8276         .f = cmd_quit_parsed,
8277         .data = NULL,
8278         .help_str = "quit: Exit application",
8279         .tokens = {
8280                 (void *)&cmd_quit_quit,
8281                 NULL,
8282         },
8283 };
8284
8285 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
8286 struct cmd_mac_addr_result {
8287         cmdline_fixed_string_t mac_addr_cmd;
8288         cmdline_fixed_string_t what;
8289         uint16_t port_num;
8290         struct rte_ether_addr address;
8291 };
8292
8293 static void cmd_mac_addr_parsed(void *parsed_result,
8294                 __rte_unused struct cmdline *cl,
8295                 __rte_unused void *data)
8296 {
8297         struct cmd_mac_addr_result *res = parsed_result;
8298         int ret;
8299
8300         if (strcmp(res->what, "add") == 0)
8301                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
8302         else if (strcmp(res->what, "set") == 0)
8303                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
8304                                                        &res->address);
8305         else
8306                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
8307
8308         /* check the return value and print it if is < 0 */
8309         if(ret < 0)
8310                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
8311
8312 }
8313
8314 cmdline_parse_token_string_t cmd_mac_addr_cmd =
8315         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
8316                                 "mac_addr");
8317 cmdline_parse_token_string_t cmd_mac_addr_what =
8318         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
8319                                 "add#remove#set");
8320 cmdline_parse_token_num_t cmd_mac_addr_portnum =
8321                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
8322                                         UINT16);
8323 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
8324                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
8325
8326 cmdline_parse_inst_t cmd_mac_addr = {
8327         .f = cmd_mac_addr_parsed,
8328         .data = (void *)0,
8329         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
8330                         "Add/Remove/Set MAC address on port_id",
8331         .tokens = {
8332                 (void *)&cmd_mac_addr_cmd,
8333                 (void *)&cmd_mac_addr_what,
8334                 (void *)&cmd_mac_addr_portnum,
8335                 (void *)&cmd_mac_addr_addr,
8336                 NULL,
8337         },
8338 };
8339
8340 /* *** SET THE PEER ADDRESS FOR CERTAIN PORT *** */
8341 struct cmd_eth_peer_result {
8342         cmdline_fixed_string_t set;
8343         cmdline_fixed_string_t eth_peer;
8344         portid_t port_id;
8345         cmdline_fixed_string_t peer_addr;
8346 };
8347
8348 static void cmd_set_eth_peer_parsed(void *parsed_result,
8349                         __rte_unused struct cmdline *cl,
8350                         __rte_unused void *data)
8351 {
8352                 struct cmd_eth_peer_result *res = parsed_result;
8353
8354                 if (test_done == 0) {
8355                         printf("Please stop forwarding first\n");
8356                         return;
8357                 }
8358                 if (!strcmp(res->eth_peer, "eth-peer")) {
8359                         set_fwd_eth_peer(res->port_id, res->peer_addr);
8360                         fwd_config_setup();
8361                 }
8362 }
8363 cmdline_parse_token_string_t cmd_eth_peer_set =
8364         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, set, "set");
8365 cmdline_parse_token_string_t cmd_eth_peer =
8366         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, eth_peer, "eth-peer");
8367 cmdline_parse_token_num_t cmd_eth_peer_port_id =
8368         TOKEN_NUM_INITIALIZER(struct cmd_eth_peer_result, port_id, UINT16);
8369 cmdline_parse_token_string_t cmd_eth_peer_addr =
8370         TOKEN_STRING_INITIALIZER(struct cmd_eth_peer_result, peer_addr, NULL);
8371
8372 cmdline_parse_inst_t cmd_set_fwd_eth_peer = {
8373         .f = cmd_set_eth_peer_parsed,
8374         .data = NULL,
8375         .help_str = "set eth-peer <port_id> <peer_mac>",
8376         .tokens = {
8377                 (void *)&cmd_eth_peer_set,
8378                 (void *)&cmd_eth_peer,
8379                 (void *)&cmd_eth_peer_port_id,
8380                 (void *)&cmd_eth_peer_addr,
8381                 NULL,
8382         },
8383 };
8384
8385 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
8386 struct cmd_set_qmap_result {
8387         cmdline_fixed_string_t set;
8388         cmdline_fixed_string_t qmap;
8389         cmdline_fixed_string_t what;
8390         portid_t port_id;
8391         uint16_t queue_id;
8392         uint8_t map_value;
8393 };
8394
8395 static void
8396 cmd_set_qmap_parsed(void *parsed_result,
8397                        __rte_unused struct cmdline *cl,
8398                        __rte_unused void *data)
8399 {
8400         struct cmd_set_qmap_result *res = parsed_result;
8401         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
8402
8403         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
8404 }
8405
8406 cmdline_parse_token_string_t cmd_setqmap_set =
8407         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8408                                  set, "set");
8409 cmdline_parse_token_string_t cmd_setqmap_qmap =
8410         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8411                                  qmap, "stat_qmap");
8412 cmdline_parse_token_string_t cmd_setqmap_what =
8413         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
8414                                  what, "tx#rx");
8415 cmdline_parse_token_num_t cmd_setqmap_portid =
8416         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8417                               port_id, UINT16);
8418 cmdline_parse_token_num_t cmd_setqmap_queueid =
8419         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8420                               queue_id, UINT16);
8421 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
8422         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
8423                               map_value, UINT8);
8424
8425 cmdline_parse_inst_t cmd_set_qmap = {
8426         .f = cmd_set_qmap_parsed,
8427         .data = NULL,
8428         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
8429                 "Set statistics mapping value on tx|rx queue_id of port_id",
8430         .tokens = {
8431                 (void *)&cmd_setqmap_set,
8432                 (void *)&cmd_setqmap_qmap,
8433                 (void *)&cmd_setqmap_what,
8434                 (void *)&cmd_setqmap_portid,
8435                 (void *)&cmd_setqmap_queueid,
8436                 (void *)&cmd_setqmap_mapvalue,
8437                 NULL,
8438         },
8439 };
8440
8441 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
8442 struct cmd_set_xstats_hide_zero_result {
8443         cmdline_fixed_string_t keyword;
8444         cmdline_fixed_string_t name;
8445         cmdline_fixed_string_t on_off;
8446 };
8447
8448 static void
8449 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
8450                         __rte_unused struct cmdline *cl,
8451                         __rte_unused void *data)
8452 {
8453         struct cmd_set_xstats_hide_zero_result *res;
8454         uint16_t on_off = 0;
8455
8456         res = parsed_result;
8457         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8458         set_xstats_hide_zero(on_off);
8459 }
8460
8461 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
8462         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8463                                  keyword, "set");
8464 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
8465         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8466                                  name, "xstats-hide-zero");
8467 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
8468         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
8469                                  on_off, "on#off");
8470
8471 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
8472         .f = cmd_set_xstats_hide_zero_parsed,
8473         .data = NULL,
8474         .help_str = "set xstats-hide-zero on|off",
8475         .tokens = {
8476                 (void *)&cmd_set_xstats_hide_zero_keyword,
8477                 (void *)&cmd_set_xstats_hide_zero_name,
8478                 (void *)&cmd_set_xstats_hide_zero_on_off,
8479                 NULL,
8480         },
8481 };
8482
8483 /* *** SET OPTION TO ENABLE MEASUREMENT OF CPU CYCLES *** */
8484 struct cmd_set_record_core_cycles_result {
8485         cmdline_fixed_string_t keyword;
8486         cmdline_fixed_string_t name;
8487         cmdline_fixed_string_t on_off;
8488 };
8489
8490 static void
8491 cmd_set_record_core_cycles_parsed(void *parsed_result,
8492                         __rte_unused struct cmdline *cl,
8493                         __rte_unused void *data)
8494 {
8495         struct cmd_set_record_core_cycles_result *res;
8496         uint16_t on_off = 0;
8497
8498         res = parsed_result;
8499         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8500         set_record_core_cycles(on_off);
8501 }
8502
8503 cmdline_parse_token_string_t cmd_set_record_core_cycles_keyword =
8504         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8505                                  keyword, "set");
8506 cmdline_parse_token_string_t cmd_set_record_core_cycles_name =
8507         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8508                                  name, "record-core-cycles");
8509 cmdline_parse_token_string_t cmd_set_record_core_cycles_on_off =
8510         TOKEN_STRING_INITIALIZER(struct cmd_set_record_core_cycles_result,
8511                                  on_off, "on#off");
8512
8513 cmdline_parse_inst_t cmd_set_record_core_cycles = {
8514         .f = cmd_set_record_core_cycles_parsed,
8515         .data = NULL,
8516         .help_str = "set record-core-cycles on|off",
8517         .tokens = {
8518                 (void *)&cmd_set_record_core_cycles_keyword,
8519                 (void *)&cmd_set_record_core_cycles_name,
8520                 (void *)&cmd_set_record_core_cycles_on_off,
8521                 NULL,
8522         },
8523 };
8524
8525 /* *** SET OPTION TO ENABLE DISPLAY OF RX AND TX BURSTS *** */
8526 struct cmd_set_record_burst_stats_result {
8527         cmdline_fixed_string_t keyword;
8528         cmdline_fixed_string_t name;
8529         cmdline_fixed_string_t on_off;
8530 };
8531
8532 static void
8533 cmd_set_record_burst_stats_parsed(void *parsed_result,
8534                         __rte_unused struct cmdline *cl,
8535                         __rte_unused void *data)
8536 {
8537         struct cmd_set_record_burst_stats_result *res;
8538         uint16_t on_off = 0;
8539
8540         res = parsed_result;
8541         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
8542         set_record_burst_stats(on_off);
8543 }
8544
8545 cmdline_parse_token_string_t cmd_set_record_burst_stats_keyword =
8546         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8547                                  keyword, "set");
8548 cmdline_parse_token_string_t cmd_set_record_burst_stats_name =
8549         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8550                                  name, "record-burst-stats");
8551 cmdline_parse_token_string_t cmd_set_record_burst_stats_on_off =
8552         TOKEN_STRING_INITIALIZER(struct cmd_set_record_burst_stats_result,
8553                                  on_off, "on#off");
8554
8555 cmdline_parse_inst_t cmd_set_record_burst_stats = {
8556         .f = cmd_set_record_burst_stats_parsed,
8557         .data = NULL,
8558         .help_str = "set record-burst-stats on|off",
8559         .tokens = {
8560                 (void *)&cmd_set_record_burst_stats_keyword,
8561                 (void *)&cmd_set_record_burst_stats_name,
8562                 (void *)&cmd_set_record_burst_stats_on_off,
8563                 NULL,
8564         },
8565 };
8566
8567 /* *** CONFIGURE UNICAST HASH TABLE *** */
8568 struct cmd_set_uc_hash_table {
8569         cmdline_fixed_string_t set;
8570         cmdline_fixed_string_t port;
8571         portid_t port_id;
8572         cmdline_fixed_string_t what;
8573         struct rte_ether_addr address;
8574         cmdline_fixed_string_t mode;
8575 };
8576
8577 static void
8578 cmd_set_uc_hash_parsed(void *parsed_result,
8579                        __rte_unused struct cmdline *cl,
8580                        __rte_unused void *data)
8581 {
8582         int ret=0;
8583         struct cmd_set_uc_hash_table *res = parsed_result;
8584
8585         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8586
8587         if (strcmp(res->what, "uta") == 0)
8588                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
8589                                                 &res->address,(uint8_t)is_on);
8590         if (ret < 0)
8591                 printf("bad unicast hash table parameter, return code = %d \n", ret);
8592
8593 }
8594
8595 cmdline_parse_token_string_t cmd_set_uc_hash_set =
8596         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8597                                  set, "set");
8598 cmdline_parse_token_string_t cmd_set_uc_hash_port =
8599         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8600                                  port, "port");
8601 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
8602         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
8603                               port_id, UINT16);
8604 cmdline_parse_token_string_t cmd_set_uc_hash_what =
8605         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8606                                  what, "uta");
8607 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
8608         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
8609                                 address);
8610 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
8611         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
8612                                  mode, "on#off");
8613
8614 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
8615         .f = cmd_set_uc_hash_parsed,
8616         .data = NULL,
8617         .help_str = "set port <port_id> uta <mac_addr> on|off)",
8618         .tokens = {
8619                 (void *)&cmd_set_uc_hash_set,
8620                 (void *)&cmd_set_uc_hash_port,
8621                 (void *)&cmd_set_uc_hash_portid,
8622                 (void *)&cmd_set_uc_hash_what,
8623                 (void *)&cmd_set_uc_hash_mac,
8624                 (void *)&cmd_set_uc_hash_mode,
8625                 NULL,
8626         },
8627 };
8628
8629 struct cmd_set_uc_all_hash_table {
8630         cmdline_fixed_string_t set;
8631         cmdline_fixed_string_t port;
8632         portid_t port_id;
8633         cmdline_fixed_string_t what;
8634         cmdline_fixed_string_t value;
8635         cmdline_fixed_string_t mode;
8636 };
8637
8638 static void
8639 cmd_set_uc_all_hash_parsed(void *parsed_result,
8640                        __rte_unused struct cmdline *cl,
8641                        __rte_unused void *data)
8642 {
8643         int ret=0;
8644         struct cmd_set_uc_all_hash_table *res = parsed_result;
8645
8646         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8647
8648         if ((strcmp(res->what, "uta") == 0) &&
8649                 (strcmp(res->value, "all") == 0))
8650                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
8651         if (ret < 0)
8652                 printf("bad unicast hash table parameter,"
8653                         "return code = %d \n", ret);
8654 }
8655
8656 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
8657         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8658                                  set, "set");
8659 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
8660         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8661                                  port, "port");
8662 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
8663         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
8664                               port_id, UINT16);
8665 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
8666         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8667                                  what, "uta");
8668 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
8669         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8670                                 value,"all");
8671 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
8672         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
8673                                  mode, "on#off");
8674
8675 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
8676         .f = cmd_set_uc_all_hash_parsed,
8677         .data = NULL,
8678         .help_str = "set port <port_id> uta all on|off",
8679         .tokens = {
8680                 (void *)&cmd_set_uc_all_hash_set,
8681                 (void *)&cmd_set_uc_all_hash_port,
8682                 (void *)&cmd_set_uc_all_hash_portid,
8683                 (void *)&cmd_set_uc_all_hash_what,
8684                 (void *)&cmd_set_uc_all_hash_value,
8685                 (void *)&cmd_set_uc_all_hash_mode,
8686                 NULL,
8687         },
8688 };
8689
8690 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
8691 struct cmd_set_vf_traffic {
8692         cmdline_fixed_string_t set;
8693         cmdline_fixed_string_t port;
8694         portid_t port_id;
8695         cmdline_fixed_string_t vf;
8696         uint8_t vf_id;
8697         cmdline_fixed_string_t what;
8698         cmdline_fixed_string_t mode;
8699 };
8700
8701 static void
8702 cmd_set_vf_traffic_parsed(void *parsed_result,
8703                        __rte_unused struct cmdline *cl,
8704                        __rte_unused void *data)
8705 {
8706         struct cmd_set_vf_traffic *res = parsed_result;
8707         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
8708         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
8709
8710         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
8711 }
8712
8713 cmdline_parse_token_string_t cmd_setvf_traffic_set =
8714         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8715                                  set, "set");
8716 cmdline_parse_token_string_t cmd_setvf_traffic_port =
8717         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8718                                  port, "port");
8719 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
8720         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8721                               port_id, UINT16);
8722 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
8723         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8724                                  vf, "vf");
8725 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
8726         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
8727                               vf_id, UINT8);
8728 cmdline_parse_token_string_t cmd_setvf_traffic_what =
8729         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8730                                  what, "tx#rx");
8731 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
8732         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
8733                                  mode, "on#off");
8734
8735 cmdline_parse_inst_t cmd_set_vf_traffic = {
8736         .f = cmd_set_vf_traffic_parsed,
8737         .data = NULL,
8738         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
8739         .tokens = {
8740                 (void *)&cmd_setvf_traffic_set,
8741                 (void *)&cmd_setvf_traffic_port,
8742                 (void *)&cmd_setvf_traffic_portid,
8743                 (void *)&cmd_setvf_traffic_vf,
8744                 (void *)&cmd_setvf_traffic_vfid,
8745                 (void *)&cmd_setvf_traffic_what,
8746                 (void *)&cmd_setvf_traffic_mode,
8747                 NULL,
8748         },
8749 };
8750
8751 /* *** CONFIGURE VF RECEIVE MODE *** */
8752 struct cmd_set_vf_rxmode {
8753         cmdline_fixed_string_t set;
8754         cmdline_fixed_string_t port;
8755         portid_t port_id;
8756         cmdline_fixed_string_t vf;
8757         uint8_t vf_id;
8758         cmdline_fixed_string_t what;
8759         cmdline_fixed_string_t mode;
8760         cmdline_fixed_string_t on;
8761 };
8762
8763 static void
8764 cmd_set_vf_rxmode_parsed(void *parsed_result,
8765                        __rte_unused struct cmdline *cl,
8766                        __rte_unused void *data)
8767 {
8768         int ret = -ENOTSUP;
8769         uint16_t vf_rxmode = 0;
8770         struct cmd_set_vf_rxmode *res = parsed_result;
8771
8772         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
8773         if (!strcmp(res->what,"rxmode")) {
8774                 if (!strcmp(res->mode, "AUPE"))
8775                         vf_rxmode |= ETH_VMDQ_ACCEPT_UNTAG;
8776                 else if (!strcmp(res->mode, "ROPE"))
8777                         vf_rxmode |= ETH_VMDQ_ACCEPT_HASH_UC;
8778                 else if (!strcmp(res->mode, "BAM"))
8779                         vf_rxmode |= ETH_VMDQ_ACCEPT_BROADCAST;
8780                 else if (!strncmp(res->mode, "MPE",3))
8781                         vf_rxmode |= ETH_VMDQ_ACCEPT_MULTICAST;
8782         }
8783
8784         RTE_SET_USED(is_on);
8785
8786 #ifdef RTE_NET_IXGBE
8787         if (ret == -ENOTSUP)
8788                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
8789                                                   vf_rxmode, (uint8_t)is_on);
8790 #endif
8791 #ifdef RTE_NET_BNXT
8792         if (ret == -ENOTSUP)
8793                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
8794                                                  vf_rxmode, (uint8_t)is_on);
8795 #endif
8796         if (ret < 0)
8797                 printf("bad VF receive mode parameter, return code = %d \n",
8798                 ret);
8799 }
8800
8801 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
8802         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8803                                  set, "set");
8804 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
8805         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8806                                  port, "port");
8807 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
8808         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8809                               port_id, UINT16);
8810 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
8811         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8812                                  vf, "vf");
8813 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
8814         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
8815                               vf_id, UINT8);
8816 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
8817         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8818                                  what, "rxmode");
8819 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
8820         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8821                                  mode, "AUPE#ROPE#BAM#MPE");
8822 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
8823         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
8824                                  on, "on#off");
8825
8826 cmdline_parse_inst_t cmd_set_vf_rxmode = {
8827         .f = cmd_set_vf_rxmode_parsed,
8828         .data = NULL,
8829         .help_str = "set port <port_id> vf <vf_id> rxmode "
8830                 "AUPE|ROPE|BAM|MPE on|off",
8831         .tokens = {
8832                 (void *)&cmd_set_vf_rxmode_set,
8833                 (void *)&cmd_set_vf_rxmode_port,
8834                 (void *)&cmd_set_vf_rxmode_portid,
8835                 (void *)&cmd_set_vf_rxmode_vf,
8836                 (void *)&cmd_set_vf_rxmode_vfid,
8837                 (void *)&cmd_set_vf_rxmode_what,
8838                 (void *)&cmd_set_vf_rxmode_mode,
8839                 (void *)&cmd_set_vf_rxmode_on,
8840                 NULL,
8841         },
8842 };
8843
8844 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
8845 struct cmd_vf_mac_addr_result {
8846         cmdline_fixed_string_t mac_addr_cmd;
8847         cmdline_fixed_string_t what;
8848         cmdline_fixed_string_t port;
8849         uint16_t port_num;
8850         cmdline_fixed_string_t vf;
8851         uint8_t vf_num;
8852         struct rte_ether_addr address;
8853 };
8854
8855 static void cmd_vf_mac_addr_parsed(void *parsed_result,
8856                 __rte_unused struct cmdline *cl,
8857                 __rte_unused void *data)
8858 {
8859         struct cmd_vf_mac_addr_result *res = parsed_result;
8860         int ret = -ENOTSUP;
8861
8862         if (strcmp(res->what, "add") != 0)
8863                 return;
8864
8865 #ifdef RTE_NET_I40E
8866         if (ret == -ENOTSUP)
8867                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
8868                                                    &res->address);
8869 #endif
8870 #ifdef RTE_NET_BNXT
8871         if (ret == -ENOTSUP)
8872                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
8873                                                 res->vf_num);
8874 #endif
8875
8876         if(ret < 0)
8877                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
8878
8879 }
8880
8881 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
8882         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8883                                 mac_addr_cmd,"mac_addr");
8884 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
8885         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8886                                 what,"add");
8887 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
8888         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8889                                 port,"port");
8890 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
8891         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8892                                 port_num, UINT16);
8893 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
8894         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
8895                                 vf,"vf");
8896 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
8897         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
8898                                 vf_num, UINT8);
8899 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
8900         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
8901                                 address);
8902
8903 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
8904         .f = cmd_vf_mac_addr_parsed,
8905         .data = (void *)0,
8906         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
8907                 "Add MAC address filtering for a VF on port_id",
8908         .tokens = {
8909                 (void *)&cmd_vf_mac_addr_cmd,
8910                 (void *)&cmd_vf_mac_addr_what,
8911                 (void *)&cmd_vf_mac_addr_port,
8912                 (void *)&cmd_vf_mac_addr_portnum,
8913                 (void *)&cmd_vf_mac_addr_vf,
8914                 (void *)&cmd_vf_mac_addr_vfnum,
8915                 (void *)&cmd_vf_mac_addr_addr,
8916                 NULL,
8917         },
8918 };
8919
8920 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
8921 struct cmd_vf_rx_vlan_filter {
8922         cmdline_fixed_string_t rx_vlan;
8923         cmdline_fixed_string_t what;
8924         uint16_t vlan_id;
8925         cmdline_fixed_string_t port;
8926         portid_t port_id;
8927         cmdline_fixed_string_t vf;
8928         uint64_t vf_mask;
8929 };
8930
8931 static void
8932 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
8933                           __rte_unused struct cmdline *cl,
8934                           __rte_unused void *data)
8935 {
8936         struct cmd_vf_rx_vlan_filter *res = parsed_result;
8937         int ret = -ENOTSUP;
8938
8939         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
8940
8941 #ifdef RTE_NET_IXGBE
8942         if (ret == -ENOTSUP)
8943                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
8944                                 res->vlan_id, res->vf_mask, is_add);
8945 #endif
8946 #ifdef RTE_NET_I40E
8947         if (ret == -ENOTSUP)
8948                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
8949                                 res->vlan_id, res->vf_mask, is_add);
8950 #endif
8951 #ifdef RTE_NET_BNXT
8952         if (ret == -ENOTSUP)
8953                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
8954                                 res->vlan_id, res->vf_mask, is_add);
8955 #endif
8956
8957         switch (ret) {
8958         case 0:
8959                 break;
8960         case -EINVAL:
8961                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
8962                                 res->vlan_id, res->vf_mask);
8963                 break;
8964         case -ENODEV:
8965                 printf("invalid port_id %d\n", res->port_id);
8966                 break;
8967         case -ENOTSUP:
8968                 printf("function not implemented or supported\n");
8969                 break;
8970         default:
8971                 printf("programming error: (%s)\n", strerror(-ret));
8972         }
8973 }
8974
8975 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
8976         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8977                                  rx_vlan, "rx_vlan");
8978 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
8979         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8980                                  what, "add#rm");
8981 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
8982         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8983                               vlan_id, UINT16);
8984 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
8985         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8986                                  port, "port");
8987 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
8988         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8989                               port_id, UINT16);
8990 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
8991         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8992                                  vf, "vf");
8993 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
8994         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
8995                               vf_mask, UINT64);
8996
8997 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
8998         .f = cmd_vf_rx_vlan_filter_parsed,
8999         .data = NULL,
9000         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
9001                 "(vf_mask = hexadecimal VF mask)",
9002         .tokens = {
9003                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
9004                 (void *)&cmd_vf_rx_vlan_filter_what,
9005                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
9006                 (void *)&cmd_vf_rx_vlan_filter_port,
9007                 (void *)&cmd_vf_rx_vlan_filter_portid,
9008                 (void *)&cmd_vf_rx_vlan_filter_vf,
9009                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
9010                 NULL,
9011         },
9012 };
9013
9014 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
9015 struct cmd_queue_rate_limit_result {
9016         cmdline_fixed_string_t set;
9017         cmdline_fixed_string_t port;
9018         uint16_t port_num;
9019         cmdline_fixed_string_t queue;
9020         uint8_t queue_num;
9021         cmdline_fixed_string_t rate;
9022         uint16_t rate_num;
9023 };
9024
9025 static void cmd_queue_rate_limit_parsed(void *parsed_result,
9026                 __rte_unused struct cmdline *cl,
9027                 __rte_unused void *data)
9028 {
9029         struct cmd_queue_rate_limit_result *res = parsed_result;
9030         int ret = 0;
9031
9032         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9033                 && (strcmp(res->queue, "queue") == 0)
9034                 && (strcmp(res->rate, "rate") == 0))
9035                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
9036                                         res->rate_num);
9037         if (ret < 0)
9038                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
9039
9040 }
9041
9042 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
9043         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9044                                 set, "set");
9045 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
9046         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9047                                 port, "port");
9048 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
9049         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9050                                 port_num, UINT16);
9051 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
9052         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9053                                 queue, "queue");
9054 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
9055         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9056                                 queue_num, UINT8);
9057 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
9058         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
9059                                 rate, "rate");
9060 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
9061         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
9062                                 rate_num, UINT16);
9063
9064 cmdline_parse_inst_t cmd_queue_rate_limit = {
9065         .f = cmd_queue_rate_limit_parsed,
9066         .data = (void *)0,
9067         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
9068                 "Set rate limit for a queue on port_id",
9069         .tokens = {
9070                 (void *)&cmd_queue_rate_limit_set,
9071                 (void *)&cmd_queue_rate_limit_port,
9072                 (void *)&cmd_queue_rate_limit_portnum,
9073                 (void *)&cmd_queue_rate_limit_queue,
9074                 (void *)&cmd_queue_rate_limit_queuenum,
9075                 (void *)&cmd_queue_rate_limit_rate,
9076                 (void *)&cmd_queue_rate_limit_ratenum,
9077                 NULL,
9078         },
9079 };
9080
9081 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
9082 struct cmd_vf_rate_limit_result {
9083         cmdline_fixed_string_t set;
9084         cmdline_fixed_string_t port;
9085         uint16_t port_num;
9086         cmdline_fixed_string_t vf;
9087         uint8_t vf_num;
9088         cmdline_fixed_string_t rate;
9089         uint16_t rate_num;
9090         cmdline_fixed_string_t q_msk;
9091         uint64_t q_msk_val;
9092 };
9093
9094 static void cmd_vf_rate_limit_parsed(void *parsed_result,
9095                 __rte_unused struct cmdline *cl,
9096                 __rte_unused void *data)
9097 {
9098         struct cmd_vf_rate_limit_result *res = parsed_result;
9099         int ret = 0;
9100
9101         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
9102                 && (strcmp(res->vf, "vf") == 0)
9103                 && (strcmp(res->rate, "rate") == 0)
9104                 && (strcmp(res->q_msk, "queue_mask") == 0))
9105                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
9106                                         res->rate_num, res->q_msk_val);
9107         if (ret < 0)
9108                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
9109
9110 }
9111
9112 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
9113         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9114                                 set, "set");
9115 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
9116         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9117                                 port, "port");
9118 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
9119         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9120                                 port_num, UINT16);
9121 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
9122         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9123                                 vf, "vf");
9124 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
9125         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9126                                 vf_num, UINT8);
9127 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
9128         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9129                                 rate, "rate");
9130 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
9131         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9132                                 rate_num, UINT16);
9133 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
9134         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
9135                                 q_msk, "queue_mask");
9136 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
9137         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
9138                                 q_msk_val, UINT64);
9139
9140 cmdline_parse_inst_t cmd_vf_rate_limit = {
9141         .f = cmd_vf_rate_limit_parsed,
9142         .data = (void *)0,
9143         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
9144                 "queue_mask <queue_mask_value>: "
9145                 "Set rate limit for queues of VF on port_id",
9146         .tokens = {
9147                 (void *)&cmd_vf_rate_limit_set,
9148                 (void *)&cmd_vf_rate_limit_port,
9149                 (void *)&cmd_vf_rate_limit_portnum,
9150                 (void *)&cmd_vf_rate_limit_vf,
9151                 (void *)&cmd_vf_rate_limit_vfnum,
9152                 (void *)&cmd_vf_rate_limit_rate,
9153                 (void *)&cmd_vf_rate_limit_ratenum,
9154                 (void *)&cmd_vf_rate_limit_q_msk,
9155                 (void *)&cmd_vf_rate_limit_q_msk_val,
9156                 NULL,
9157         },
9158 };
9159
9160 /* *** CONFIGURE TUNNEL UDP PORT *** */
9161 struct cmd_tunnel_udp_config {
9162         cmdline_fixed_string_t cmd;
9163         cmdline_fixed_string_t what;
9164         uint16_t udp_port;
9165         portid_t port_id;
9166 };
9167
9168 static void
9169 cmd_tunnel_udp_config_parsed(void *parsed_result,
9170                           __rte_unused struct cmdline *cl,
9171                           __rte_unused void *data)
9172 {
9173         struct cmd_tunnel_udp_config *res = parsed_result;
9174         struct rte_eth_udp_tunnel tunnel_udp;
9175         int ret;
9176
9177         tunnel_udp.udp_port = res->udp_port;
9178
9179         if (!strcmp(res->cmd, "rx_vxlan_port"))
9180                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9181
9182         if (!strcmp(res->what, "add"))
9183                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9184                                                       &tunnel_udp);
9185         else
9186                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9187                                                          &tunnel_udp);
9188
9189         if (ret < 0)
9190                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
9191 }
9192
9193 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
9194         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9195                                 cmd, "rx_vxlan_port");
9196 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
9197         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
9198                                 what, "add#rm");
9199 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
9200         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9201                                 udp_port, UINT16);
9202 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
9203         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
9204                                 port_id, UINT16);
9205
9206 cmdline_parse_inst_t cmd_tunnel_udp_config = {
9207         .f = cmd_tunnel_udp_config_parsed,
9208         .data = (void *)0,
9209         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
9210                 "Add/Remove a tunneling UDP port filter",
9211         .tokens = {
9212                 (void *)&cmd_tunnel_udp_config_cmd,
9213                 (void *)&cmd_tunnel_udp_config_what,
9214                 (void *)&cmd_tunnel_udp_config_udp_port,
9215                 (void *)&cmd_tunnel_udp_config_port_id,
9216                 NULL,
9217         },
9218 };
9219
9220 struct cmd_config_tunnel_udp_port {
9221         cmdline_fixed_string_t port;
9222         cmdline_fixed_string_t config;
9223         portid_t port_id;
9224         cmdline_fixed_string_t udp_tunnel_port;
9225         cmdline_fixed_string_t action;
9226         cmdline_fixed_string_t tunnel_type;
9227         uint16_t udp_port;
9228 };
9229
9230 static void
9231 cmd_cfg_tunnel_udp_port_parsed(void *parsed_result,
9232                                __rte_unused struct cmdline *cl,
9233                                __rte_unused void *data)
9234 {
9235         struct cmd_config_tunnel_udp_port *res = parsed_result;
9236         struct rte_eth_udp_tunnel tunnel_udp;
9237         int ret = 0;
9238
9239         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9240                 return;
9241
9242         tunnel_udp.udp_port = res->udp_port;
9243
9244         if (!strcmp(res->tunnel_type, "vxlan")) {
9245                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
9246         } else if (!strcmp(res->tunnel_type, "geneve")) {
9247                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_GENEVE;
9248         } else if (!strcmp(res->tunnel_type, "vxlan-gpe")) {
9249                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN_GPE;
9250         } else {
9251                 printf("Invalid tunnel type\n");
9252                 return;
9253         }
9254
9255         if (!strcmp(res->action, "add"))
9256                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
9257                                                       &tunnel_udp);
9258         else
9259                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
9260                                                          &tunnel_udp);
9261
9262         if (ret < 0)
9263                 printf("udp tunneling port add error: (%s)\n", strerror(-ret));
9264 }
9265
9266 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_port =
9267         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, port,
9268                                  "port");
9269 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_config =
9270         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, config,
9271                                  "config");
9272 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_port_id =
9273         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, port_id,
9274                               UINT16);
9275 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_port =
9276         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port,
9277                                  udp_tunnel_port,
9278                                  "udp_tunnel_port");
9279 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_action =
9280         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, action,
9281                                  "add#rm");
9282 cmdline_parse_token_string_t cmd_config_tunnel_udp_port_tunnel_type =
9283         TOKEN_STRING_INITIALIZER(struct cmd_config_tunnel_udp_port, tunnel_type,
9284                                  "vxlan#geneve#vxlan-gpe");
9285 cmdline_parse_token_num_t cmd_config_tunnel_udp_port_value =
9286         TOKEN_NUM_INITIALIZER(struct cmd_config_tunnel_udp_port, udp_port,
9287                               UINT16);
9288
9289 cmdline_parse_inst_t cmd_cfg_tunnel_udp_port = {
9290         .f = cmd_cfg_tunnel_udp_port_parsed,
9291         .data = NULL,
9292         .help_str = "port config <port_id> udp_tunnel_port add|rm vxlan|geneve|vxlan-gpe <udp_port>",
9293         .tokens = {
9294                 (void *)&cmd_config_tunnel_udp_port_port,
9295                 (void *)&cmd_config_tunnel_udp_port_config,
9296                 (void *)&cmd_config_tunnel_udp_port_port_id,
9297                 (void *)&cmd_config_tunnel_udp_port_tunnel_port,
9298                 (void *)&cmd_config_tunnel_udp_port_action,
9299                 (void *)&cmd_config_tunnel_udp_port_tunnel_type,
9300                 (void *)&cmd_config_tunnel_udp_port_value,
9301                 NULL,
9302         },
9303 };
9304
9305 /* *** GLOBAL CONFIG *** */
9306 struct cmd_global_config_result {
9307         cmdline_fixed_string_t cmd;
9308         portid_t port_id;
9309         cmdline_fixed_string_t cfg_type;
9310         uint8_t len;
9311 };
9312
9313 static void
9314 cmd_global_config_parsed(void *parsed_result,
9315                          __rte_unused struct cmdline *cl,
9316                          __rte_unused void *data)
9317 {
9318         struct cmd_global_config_result *res = parsed_result;
9319         struct rte_eth_global_cfg conf;
9320         int ret;
9321
9322         memset(&conf, 0, sizeof(conf));
9323         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
9324         conf.cfg.gre_key_len = res->len;
9325         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
9326                                       RTE_ETH_FILTER_SET, &conf);
9327 #ifdef RTE_NET_I40E
9328         if (ret == -ENOTSUP)
9329                 ret = rte_pmd_i40e_set_gre_key_len(res->port_id, res->len);
9330 #endif
9331         if (ret != 0)
9332                 printf("Global config error\n");
9333 }
9334
9335 cmdline_parse_token_string_t cmd_global_config_cmd =
9336         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
9337                 "global_config");
9338 cmdline_parse_token_num_t cmd_global_config_port_id =
9339         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
9340                                UINT16);
9341 cmdline_parse_token_string_t cmd_global_config_type =
9342         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
9343                 cfg_type, "gre-key-len");
9344 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
9345         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
9346                 len, UINT8);
9347
9348 cmdline_parse_inst_t cmd_global_config = {
9349         .f = cmd_global_config_parsed,
9350         .data = (void *)NULL,
9351         .help_str = "global_config <port_id> gre-key-len <key_len>",
9352         .tokens = {
9353                 (void *)&cmd_global_config_cmd,
9354                 (void *)&cmd_global_config_port_id,
9355                 (void *)&cmd_global_config_type,
9356                 (void *)&cmd_global_config_gre_key_len,
9357                 NULL,
9358         },
9359 };
9360
9361 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
9362 struct cmd_set_mirror_mask_result {
9363         cmdline_fixed_string_t set;
9364         cmdline_fixed_string_t port;
9365         portid_t port_id;
9366         cmdline_fixed_string_t mirror;
9367         uint8_t rule_id;
9368         cmdline_fixed_string_t what;
9369         cmdline_fixed_string_t value;
9370         cmdline_fixed_string_t dstpool;
9371         uint8_t dstpool_id;
9372         cmdline_fixed_string_t on;
9373 };
9374
9375 cmdline_parse_token_string_t cmd_mirror_mask_set =
9376         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9377                                 set, "set");
9378 cmdline_parse_token_string_t cmd_mirror_mask_port =
9379         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9380                                 port, "port");
9381 cmdline_parse_token_num_t cmd_mirror_mask_portid =
9382         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9383                                 port_id, UINT16);
9384 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
9385         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9386                                 mirror, "mirror-rule");
9387 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
9388         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9389                                 rule_id, UINT8);
9390 cmdline_parse_token_string_t cmd_mirror_mask_what =
9391         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9392                                 what, "pool-mirror-up#pool-mirror-down"
9393                                       "#vlan-mirror");
9394 cmdline_parse_token_string_t cmd_mirror_mask_value =
9395         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9396                                 value, NULL);
9397 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
9398         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9399                                 dstpool, "dst-pool");
9400 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
9401         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
9402                                 dstpool_id, UINT8);
9403 cmdline_parse_token_string_t cmd_mirror_mask_on =
9404         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
9405                                 on, "on#off");
9406
9407 static void
9408 cmd_set_mirror_mask_parsed(void *parsed_result,
9409                        __rte_unused struct cmdline *cl,
9410                        __rte_unused void *data)
9411 {
9412         int ret,nb_item,i;
9413         struct cmd_set_mirror_mask_result *res = parsed_result;
9414         struct rte_eth_mirror_conf mr_conf;
9415
9416         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9417
9418         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
9419
9420         mr_conf.dst_pool = res->dstpool_id;
9421
9422         if (!strcmp(res->what, "pool-mirror-up")) {
9423                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9424                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
9425         } else if (!strcmp(res->what, "pool-mirror-down")) {
9426                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
9427                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
9428         } else if (!strcmp(res->what, "vlan-mirror")) {
9429                 mr_conf.rule_type = ETH_MIRROR_VLAN;
9430                 nb_item = parse_item_list(res->value, "vlan",
9431                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
9432                 if (nb_item <= 0)
9433                         return;
9434
9435                 for (i = 0; i < nb_item; i++) {
9436                         if (vlan_list[i] > RTE_ETHER_MAX_VLAN_ID) {
9437                                 printf("Invalid vlan_id: must be < 4096\n");
9438                                 return;
9439                         }
9440
9441                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
9442                         mr_conf.vlan.vlan_mask |= 1ULL << i;
9443                 }
9444         }
9445
9446         if (!strcmp(res->on, "on"))
9447                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9448                                                 res->rule_id, 1);
9449         else
9450                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9451                                                 res->rule_id, 0);
9452         if (ret < 0)
9453                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9454 }
9455
9456 cmdline_parse_inst_t cmd_set_mirror_mask = {
9457                 .f = cmd_set_mirror_mask_parsed,
9458                 .data = NULL,
9459                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9460                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
9461                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
9462                 .tokens = {
9463                         (void *)&cmd_mirror_mask_set,
9464                         (void *)&cmd_mirror_mask_port,
9465                         (void *)&cmd_mirror_mask_portid,
9466                         (void *)&cmd_mirror_mask_mirror,
9467                         (void *)&cmd_mirror_mask_ruleid,
9468                         (void *)&cmd_mirror_mask_what,
9469                         (void *)&cmd_mirror_mask_value,
9470                         (void *)&cmd_mirror_mask_dstpool,
9471                         (void *)&cmd_mirror_mask_poolid,
9472                         (void *)&cmd_mirror_mask_on,
9473                         NULL,
9474                 },
9475 };
9476
9477 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
9478 struct cmd_set_mirror_link_result {
9479         cmdline_fixed_string_t set;
9480         cmdline_fixed_string_t port;
9481         portid_t port_id;
9482         cmdline_fixed_string_t mirror;
9483         uint8_t rule_id;
9484         cmdline_fixed_string_t what;
9485         cmdline_fixed_string_t dstpool;
9486         uint8_t dstpool_id;
9487         cmdline_fixed_string_t on;
9488 };
9489
9490 cmdline_parse_token_string_t cmd_mirror_link_set =
9491         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9492                                  set, "set");
9493 cmdline_parse_token_string_t cmd_mirror_link_port =
9494         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9495                                 port, "port");
9496 cmdline_parse_token_num_t cmd_mirror_link_portid =
9497         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9498                                 port_id, UINT16);
9499 cmdline_parse_token_string_t cmd_mirror_link_mirror =
9500         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9501                                 mirror, "mirror-rule");
9502 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
9503         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9504                             rule_id, UINT8);
9505 cmdline_parse_token_string_t cmd_mirror_link_what =
9506         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9507                                 what, "uplink-mirror#downlink-mirror");
9508 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
9509         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9510                                 dstpool, "dst-pool");
9511 cmdline_parse_token_num_t cmd_mirror_link_poolid =
9512         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
9513                                 dstpool_id, UINT8);
9514 cmdline_parse_token_string_t cmd_mirror_link_on =
9515         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
9516                                 on, "on#off");
9517
9518 static void
9519 cmd_set_mirror_link_parsed(void *parsed_result,
9520                        __rte_unused struct cmdline *cl,
9521                        __rte_unused void *data)
9522 {
9523         int ret;
9524         struct cmd_set_mirror_link_result *res = parsed_result;
9525         struct rte_eth_mirror_conf mr_conf;
9526
9527         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
9528         if (!strcmp(res->what, "uplink-mirror"))
9529                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
9530         else
9531                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
9532
9533         mr_conf.dst_pool = res->dstpool_id;
9534
9535         if (!strcmp(res->on, "on"))
9536                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9537                                                 res->rule_id, 1);
9538         else
9539                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
9540                                                 res->rule_id, 0);
9541
9542         /* check the return value and print it if is < 0 */
9543         if (ret < 0)
9544                 printf("mirror rule add error: (%s)\n", strerror(-ret));
9545
9546 }
9547
9548 cmdline_parse_inst_t cmd_set_mirror_link = {
9549                 .f = cmd_set_mirror_link_parsed,
9550                 .data = NULL,
9551                 .help_str = "set port <port_id> mirror-rule <rule_id> "
9552                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
9553                 .tokens = {
9554                         (void *)&cmd_mirror_link_set,
9555                         (void *)&cmd_mirror_link_port,
9556                         (void *)&cmd_mirror_link_portid,
9557                         (void *)&cmd_mirror_link_mirror,
9558                         (void *)&cmd_mirror_link_ruleid,
9559                         (void *)&cmd_mirror_link_what,
9560                         (void *)&cmd_mirror_link_dstpool,
9561                         (void *)&cmd_mirror_link_poolid,
9562                         (void *)&cmd_mirror_link_on,
9563                         NULL,
9564                 },
9565 };
9566
9567 /* *** RESET VM MIRROR RULE *** */
9568 struct cmd_rm_mirror_rule_result {
9569         cmdline_fixed_string_t reset;
9570         cmdline_fixed_string_t port;
9571         portid_t port_id;
9572         cmdline_fixed_string_t mirror;
9573         uint8_t rule_id;
9574 };
9575
9576 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
9577         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9578                                  reset, "reset");
9579 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
9580         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9581                                 port, "port");
9582 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
9583         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9584                                 port_id, UINT16);
9585 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
9586         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
9587                                 mirror, "mirror-rule");
9588 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
9589         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
9590                                 rule_id, UINT8);
9591
9592 static void
9593 cmd_reset_mirror_rule_parsed(void *parsed_result,
9594                        __rte_unused struct cmdline *cl,
9595                        __rte_unused void *data)
9596 {
9597         int ret;
9598         struct cmd_set_mirror_link_result *res = parsed_result;
9599         /* check rule_id */
9600         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
9601         if(ret < 0)
9602                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
9603 }
9604
9605 cmdline_parse_inst_t cmd_reset_mirror_rule = {
9606                 .f = cmd_reset_mirror_rule_parsed,
9607                 .data = NULL,
9608                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
9609                 .tokens = {
9610                         (void *)&cmd_rm_mirror_rule_reset,
9611                         (void *)&cmd_rm_mirror_rule_port,
9612                         (void *)&cmd_rm_mirror_rule_portid,
9613                         (void *)&cmd_rm_mirror_rule_mirror,
9614                         (void *)&cmd_rm_mirror_rule_ruleid,
9615                         NULL,
9616                 },
9617 };
9618
9619 /* ******************************************************************************** */
9620
9621 struct cmd_dump_result {
9622         cmdline_fixed_string_t dump;
9623 };
9624
9625 static void
9626 dump_struct_sizes(void)
9627 {
9628 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
9629         DUMP_SIZE(struct rte_mbuf);
9630         DUMP_SIZE(struct rte_mempool);
9631         DUMP_SIZE(struct rte_ring);
9632 #undef DUMP_SIZE
9633 }
9634
9635
9636 /* Dump the socket memory statistics on console */
9637 static void
9638 dump_socket_mem(FILE *f)
9639 {
9640         struct rte_malloc_socket_stats socket_stats;
9641         unsigned int i;
9642         size_t total = 0;
9643         size_t alloc = 0;
9644         size_t free = 0;
9645         unsigned int n_alloc = 0;
9646         unsigned int n_free = 0;
9647         static size_t last_allocs;
9648         static size_t last_total;
9649
9650
9651         for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
9652                 if (rte_malloc_get_socket_stats(i, &socket_stats) ||
9653                     !socket_stats.heap_totalsz_bytes)
9654                         continue;
9655                 total += socket_stats.heap_totalsz_bytes;
9656                 alloc += socket_stats.heap_allocsz_bytes;
9657                 free += socket_stats.heap_freesz_bytes;
9658                 n_alloc += socket_stats.alloc_count;
9659                 n_free += socket_stats.free_count;
9660                 fprintf(f,
9661                         "Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9662                         i,
9663                         (double)socket_stats.heap_totalsz_bytes / (1024 * 1024),
9664                         (double)socket_stats.heap_allocsz_bytes / (1024 * 1024),
9665                         (double)socket_stats.heap_allocsz_bytes * 100 /
9666                         (double)socket_stats.heap_totalsz_bytes,
9667                         (double)socket_stats.heap_freesz_bytes / (1024 * 1024),
9668                         socket_stats.alloc_count,
9669                         socket_stats.free_count);
9670         }
9671         fprintf(f,
9672                 "Total   : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n",
9673                 (double)total / (1024 * 1024), (double)alloc / (1024 * 1024),
9674                 (double)alloc * 100 / (double)total,
9675                 (double)free / (1024 * 1024),
9676                 n_alloc, n_free);
9677         if (last_allocs)
9678                 fprintf(stdout, "Memory total change: %.6lf(M), allocation change: %.6lf(M)\n",
9679                         ((double)total - (double)last_total) / (1024 * 1024),
9680                         (double)(alloc - (double)last_allocs) / 1024 / 1024);
9681         last_allocs = alloc;
9682         last_total = total;
9683 }
9684
9685 static void cmd_dump_parsed(void *parsed_result,
9686                             __rte_unused struct cmdline *cl,
9687                             __rte_unused void *data)
9688 {
9689         struct cmd_dump_result *res = parsed_result;
9690
9691         if (!strcmp(res->dump, "dump_physmem"))
9692                 rte_dump_physmem_layout(stdout);
9693         else if (!strcmp(res->dump, "dump_socket_mem"))
9694                 dump_socket_mem(stdout);
9695         else if (!strcmp(res->dump, "dump_memzone"))
9696                 rte_memzone_dump(stdout);
9697         else if (!strcmp(res->dump, "dump_struct_sizes"))
9698                 dump_struct_sizes();
9699         else if (!strcmp(res->dump, "dump_ring"))
9700                 rte_ring_list_dump(stdout);
9701         else if (!strcmp(res->dump, "dump_mempool"))
9702                 rte_mempool_list_dump(stdout);
9703         else if (!strcmp(res->dump, "dump_devargs"))
9704                 rte_devargs_dump(stdout);
9705         else if (!strcmp(res->dump, "dump_log_types"))
9706                 rte_log_dump(stdout);
9707 }
9708
9709 cmdline_parse_token_string_t cmd_dump_dump =
9710         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
9711                 "dump_physmem#"
9712                 "dump_memzone#"
9713                 "dump_socket_mem#"
9714                 "dump_struct_sizes#"
9715                 "dump_ring#"
9716                 "dump_mempool#"
9717                 "dump_devargs#"
9718                 "dump_log_types");
9719
9720 cmdline_parse_inst_t cmd_dump = {
9721         .f = cmd_dump_parsed,  /* function to call */
9722         .data = NULL,      /* 2nd arg of func */
9723         .help_str = "Dump status",
9724         .tokens = {        /* token list, NULL terminated */
9725                 (void *)&cmd_dump_dump,
9726                 NULL,
9727         },
9728 };
9729
9730 /* ******************************************************************************** */
9731
9732 struct cmd_dump_one_result {
9733         cmdline_fixed_string_t dump;
9734         cmdline_fixed_string_t name;
9735 };
9736
9737 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
9738                                 __rte_unused void *data)
9739 {
9740         struct cmd_dump_one_result *res = parsed_result;
9741
9742         if (!strcmp(res->dump, "dump_ring")) {
9743                 struct rte_ring *r;
9744                 r = rte_ring_lookup(res->name);
9745                 if (r == NULL) {
9746                         cmdline_printf(cl, "Cannot find ring\n");
9747                         return;
9748                 }
9749                 rte_ring_dump(stdout, r);
9750         } else if (!strcmp(res->dump, "dump_mempool")) {
9751                 struct rte_mempool *mp;
9752                 mp = rte_mempool_lookup(res->name);
9753                 if (mp == NULL) {
9754                         cmdline_printf(cl, "Cannot find mempool\n");
9755                         return;
9756                 }
9757                 rte_mempool_dump(stdout, mp);
9758         }
9759 }
9760
9761 cmdline_parse_token_string_t cmd_dump_one_dump =
9762         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
9763                                  "dump_ring#dump_mempool");
9764
9765 cmdline_parse_token_string_t cmd_dump_one_name =
9766         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
9767
9768 cmdline_parse_inst_t cmd_dump_one = {
9769         .f = cmd_dump_one_parsed,  /* function to call */
9770         .data = NULL,      /* 2nd arg of func */
9771         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
9772         .tokens = {        /* token list, NULL terminated */
9773                 (void *)&cmd_dump_one_dump,
9774                 (void *)&cmd_dump_one_name,
9775                 NULL,
9776         },
9777 };
9778
9779 /* *** queue region set *** */
9780 struct cmd_queue_region_result {
9781         cmdline_fixed_string_t set;
9782         cmdline_fixed_string_t port;
9783         portid_t port_id;
9784         cmdline_fixed_string_t cmd;
9785         cmdline_fixed_string_t region;
9786         uint8_t  region_id;
9787         cmdline_fixed_string_t queue_start_index;
9788         uint8_t  queue_id;
9789         cmdline_fixed_string_t queue_num;
9790         uint8_t  queue_num_value;
9791 };
9792
9793 static void
9794 cmd_queue_region_parsed(void *parsed_result,
9795                         __rte_unused struct cmdline *cl,
9796                         __rte_unused void *data)
9797 {
9798         struct cmd_queue_region_result *res = parsed_result;
9799         int ret = -ENOTSUP;
9800 #ifdef RTE_NET_I40E
9801         struct rte_pmd_i40e_queue_region_conf region_conf;
9802         enum rte_pmd_i40e_queue_region_op op_type;
9803 #endif
9804
9805         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9806                 return;
9807
9808 #ifdef RTE_NET_I40E
9809         memset(&region_conf, 0, sizeof(region_conf));
9810         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
9811         region_conf.region_id = res->region_id;
9812         region_conf.queue_num = res->queue_num_value;
9813         region_conf.queue_start_index = res->queue_id;
9814
9815         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9816                                 op_type, &region_conf);
9817 #endif
9818
9819         switch (ret) {
9820         case 0:
9821                 break;
9822         case -ENOTSUP:
9823                 printf("function not implemented or supported\n");
9824                 break;
9825         default:
9826                 printf("queue region config error: (%s)\n", strerror(-ret));
9827         }
9828 }
9829
9830 cmdline_parse_token_string_t cmd_queue_region_set =
9831 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9832                 set, "set");
9833 cmdline_parse_token_string_t cmd_queue_region_port =
9834         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
9835 cmdline_parse_token_num_t cmd_queue_region_port_id =
9836         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9837                                 port_id, UINT16);
9838 cmdline_parse_token_string_t cmd_queue_region_cmd =
9839         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9840                                  cmd, "queue-region");
9841 cmdline_parse_token_string_t cmd_queue_region_id =
9842         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9843                                 region, "region_id");
9844 cmdline_parse_token_num_t cmd_queue_region_index =
9845         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9846                                 region_id, UINT8);
9847 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
9848         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9849                                 queue_start_index, "queue_start_index");
9850 cmdline_parse_token_num_t cmd_queue_region_queue_id =
9851         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9852                                 queue_id, UINT8);
9853 cmdline_parse_token_string_t cmd_queue_region_queue_num =
9854         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
9855                                 queue_num, "queue_num");
9856 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
9857         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
9858                                 queue_num_value, UINT8);
9859
9860 cmdline_parse_inst_t cmd_queue_region = {
9861         .f = cmd_queue_region_parsed,
9862         .data = NULL,
9863         .help_str = "set port <port_id> queue-region region_id <value> "
9864                 "queue_start_index <value> queue_num <value>: Set a queue region",
9865         .tokens = {
9866                 (void *)&cmd_queue_region_set,
9867                 (void *)&cmd_queue_region_port,
9868                 (void *)&cmd_queue_region_port_id,
9869                 (void *)&cmd_queue_region_cmd,
9870                 (void *)&cmd_queue_region_id,
9871                 (void *)&cmd_queue_region_index,
9872                 (void *)&cmd_queue_region_queue_start_index,
9873                 (void *)&cmd_queue_region_queue_id,
9874                 (void *)&cmd_queue_region_queue_num,
9875                 (void *)&cmd_queue_region_queue_num_value,
9876                 NULL,
9877         },
9878 };
9879
9880 /* *** queue region and flowtype set *** */
9881 struct cmd_region_flowtype_result {
9882         cmdline_fixed_string_t set;
9883         cmdline_fixed_string_t port;
9884         portid_t port_id;
9885         cmdline_fixed_string_t cmd;
9886         cmdline_fixed_string_t region;
9887         uint8_t  region_id;
9888         cmdline_fixed_string_t flowtype;
9889         uint8_t  flowtype_id;
9890 };
9891
9892 static void
9893 cmd_region_flowtype_parsed(void *parsed_result,
9894                         __rte_unused struct cmdline *cl,
9895                         __rte_unused void *data)
9896 {
9897         struct cmd_region_flowtype_result *res = parsed_result;
9898         int ret = -ENOTSUP;
9899 #ifdef RTE_NET_I40E
9900         struct rte_pmd_i40e_queue_region_conf region_conf;
9901         enum rte_pmd_i40e_queue_region_op op_type;
9902 #endif
9903
9904         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9905                 return;
9906
9907 #ifdef RTE_NET_I40E
9908         memset(&region_conf, 0, sizeof(region_conf));
9909
9910         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
9911         region_conf.region_id = res->region_id;
9912         region_conf.hw_flowtype = res->flowtype_id;
9913
9914         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9915                         op_type, &region_conf);
9916 #endif
9917
9918         switch (ret) {
9919         case 0:
9920                 break;
9921         case -ENOTSUP:
9922                 printf("function not implemented or supported\n");
9923                 break;
9924         default:
9925                 printf("region flowtype config error: (%s)\n", strerror(-ret));
9926         }
9927 }
9928
9929 cmdline_parse_token_string_t cmd_region_flowtype_set =
9930 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9931                                 set, "set");
9932 cmdline_parse_token_string_t cmd_region_flowtype_port =
9933         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9934                                 port, "port");
9935 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
9936         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9937                                 port_id, UINT16);
9938 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
9939         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9940                                 cmd, "queue-region");
9941 cmdline_parse_token_string_t cmd_region_flowtype_index =
9942         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9943                                 region, "region_id");
9944 cmdline_parse_token_num_t cmd_region_flowtype_id =
9945         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9946                                 region_id, UINT8);
9947 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
9948         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
9949                                 flowtype, "flowtype");
9950 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
9951         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
9952                                 flowtype_id, UINT8);
9953 cmdline_parse_inst_t cmd_region_flowtype = {
9954         .f = cmd_region_flowtype_parsed,
9955         .data = NULL,
9956         .help_str = "set port <port_id> queue-region region_id <value> "
9957                 "flowtype <value>: Set a flowtype region index",
9958         .tokens = {
9959                 (void *)&cmd_region_flowtype_set,
9960                 (void *)&cmd_region_flowtype_port,
9961                 (void *)&cmd_region_flowtype_port_index,
9962                 (void *)&cmd_region_flowtype_cmd,
9963                 (void *)&cmd_region_flowtype_index,
9964                 (void *)&cmd_region_flowtype_id,
9965                 (void *)&cmd_region_flowtype_flow_index,
9966                 (void *)&cmd_region_flowtype_flow_id,
9967                 NULL,
9968         },
9969 };
9970
9971 /* *** User Priority (UP) to queue region (region_id) set *** */
9972 struct cmd_user_priority_region_result {
9973         cmdline_fixed_string_t set;
9974         cmdline_fixed_string_t port;
9975         portid_t port_id;
9976         cmdline_fixed_string_t cmd;
9977         cmdline_fixed_string_t user_priority;
9978         uint8_t  user_priority_id;
9979         cmdline_fixed_string_t region;
9980         uint8_t  region_id;
9981 };
9982
9983 static void
9984 cmd_user_priority_region_parsed(void *parsed_result,
9985                         __rte_unused struct cmdline *cl,
9986                         __rte_unused void *data)
9987 {
9988         struct cmd_user_priority_region_result *res = parsed_result;
9989         int ret = -ENOTSUP;
9990 #ifdef RTE_NET_I40E
9991         struct rte_pmd_i40e_queue_region_conf region_conf;
9992         enum rte_pmd_i40e_queue_region_op op_type;
9993 #endif
9994
9995         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9996                 return;
9997
9998 #ifdef RTE_NET_I40E
9999         memset(&region_conf, 0, sizeof(region_conf));
10000         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
10001         region_conf.user_priority = res->user_priority_id;
10002         region_conf.region_id = res->region_id;
10003
10004         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10005                                 op_type, &region_conf);
10006 #endif
10007
10008         switch (ret) {
10009         case 0:
10010                 break;
10011         case -ENOTSUP:
10012                 printf("function not implemented or supported\n");
10013                 break;
10014         default:
10015                 printf("user_priority region config error: (%s)\n",
10016                                 strerror(-ret));
10017         }
10018 }
10019
10020 cmdline_parse_token_string_t cmd_user_priority_region_set =
10021         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10022                                 set, "set");
10023 cmdline_parse_token_string_t cmd_user_priority_region_port =
10024         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10025                                 port, "port");
10026 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
10027         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10028                                 port_id, UINT16);
10029 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
10030         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10031                                 cmd, "queue-region");
10032 cmdline_parse_token_string_t cmd_user_priority_region_UP =
10033         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10034                                 user_priority, "UP");
10035 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
10036         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10037                                 user_priority_id, UINT8);
10038 cmdline_parse_token_string_t cmd_user_priority_region_region =
10039         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
10040                                 region, "region_id");
10041 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
10042         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
10043                                 region_id, UINT8);
10044
10045 cmdline_parse_inst_t cmd_user_priority_region = {
10046         .f = cmd_user_priority_region_parsed,
10047         .data = NULL,
10048         .help_str = "set port <port_id> queue-region UP <value> "
10049                 "region_id <value>: Set the mapping of User Priority (UP) "
10050                 "to queue region (region_id) ",
10051         .tokens = {
10052                 (void *)&cmd_user_priority_region_set,
10053                 (void *)&cmd_user_priority_region_port,
10054                 (void *)&cmd_user_priority_region_port_index,
10055                 (void *)&cmd_user_priority_region_cmd,
10056                 (void *)&cmd_user_priority_region_UP,
10057                 (void *)&cmd_user_priority_region_UP_id,
10058                 (void *)&cmd_user_priority_region_region,
10059                 (void *)&cmd_user_priority_region_region_id,
10060                 NULL,
10061         },
10062 };
10063
10064 /* *** flush all queue region related configuration *** */
10065 struct cmd_flush_queue_region_result {
10066         cmdline_fixed_string_t set;
10067         cmdline_fixed_string_t port;
10068         portid_t port_id;
10069         cmdline_fixed_string_t cmd;
10070         cmdline_fixed_string_t flush;
10071         cmdline_fixed_string_t what;
10072 };
10073
10074 static void
10075 cmd_flush_queue_region_parsed(void *parsed_result,
10076                         __rte_unused struct cmdline *cl,
10077                         __rte_unused void *data)
10078 {
10079         struct cmd_flush_queue_region_result *res = parsed_result;
10080         int ret = -ENOTSUP;
10081 #ifdef RTE_NET_I40E
10082         struct rte_pmd_i40e_queue_region_conf region_conf;
10083         enum rte_pmd_i40e_queue_region_op op_type;
10084 #endif
10085
10086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10087                 return;
10088
10089 #ifdef RTE_NET_I40E
10090         memset(&region_conf, 0, sizeof(region_conf));
10091
10092         if (strcmp(res->what, "on") == 0)
10093                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
10094         else
10095                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
10096
10097         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10098                                 op_type, &region_conf);
10099 #endif
10100
10101         switch (ret) {
10102         case 0:
10103                 break;
10104         case -ENOTSUP:
10105                 printf("function not implemented or supported\n");
10106                 break;
10107         default:
10108                 printf("queue region config flush error: (%s)\n",
10109                                 strerror(-ret));
10110         }
10111 }
10112
10113 cmdline_parse_token_string_t cmd_flush_queue_region_set =
10114         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10115                                 set, "set");
10116 cmdline_parse_token_string_t cmd_flush_queue_region_port =
10117         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10118                                 port, "port");
10119 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
10120         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
10121                                 port_id, UINT16);
10122 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
10123         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10124                                 cmd, "queue-region");
10125 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
10126         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10127                                 flush, "flush");
10128 cmdline_parse_token_string_t cmd_flush_queue_region_what =
10129         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
10130                                 what, "on#off");
10131
10132 cmdline_parse_inst_t cmd_flush_queue_region = {
10133         .f = cmd_flush_queue_region_parsed,
10134         .data = NULL,
10135         .help_str = "set port <port_id> queue-region flush on|off"
10136                 ": flush all queue region related configuration",
10137         .tokens = {
10138                 (void *)&cmd_flush_queue_region_set,
10139                 (void *)&cmd_flush_queue_region_port,
10140                 (void *)&cmd_flush_queue_region_port_index,
10141                 (void *)&cmd_flush_queue_region_cmd,
10142                 (void *)&cmd_flush_queue_region_flush,
10143                 (void *)&cmd_flush_queue_region_what,
10144                 NULL,
10145         },
10146 };
10147
10148 /* *** get all queue region related configuration info *** */
10149 struct cmd_show_queue_region_info {
10150         cmdline_fixed_string_t show;
10151         cmdline_fixed_string_t port;
10152         portid_t port_id;
10153         cmdline_fixed_string_t cmd;
10154 };
10155
10156 static void
10157 cmd_show_queue_region_info_parsed(void *parsed_result,
10158                         __rte_unused struct cmdline *cl,
10159                         __rte_unused void *data)
10160 {
10161         struct cmd_show_queue_region_info *res = parsed_result;
10162         int ret = -ENOTSUP;
10163 #ifdef RTE_NET_I40E
10164         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
10165         enum rte_pmd_i40e_queue_region_op op_type;
10166 #endif
10167
10168         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
10169                 return;
10170
10171 #ifdef RTE_NET_I40E
10172         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
10173
10174         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
10175
10176         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
10177                                         op_type, &rte_pmd_regions);
10178
10179         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
10180 #endif
10181
10182         switch (ret) {
10183         case 0:
10184                 break;
10185         case -ENOTSUP:
10186                 printf("function not implemented or supported\n");
10187                 break;
10188         default:
10189                 printf("queue region config info show error: (%s)\n",
10190                                 strerror(-ret));
10191         }
10192 }
10193
10194 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
10195 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10196                                 show, "show");
10197 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
10198         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10199                                 port, "port");
10200 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
10201         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
10202                                 port_id, UINT16);
10203 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
10204         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
10205                                 cmd, "queue-region");
10206
10207 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
10208         .f = cmd_show_queue_region_info_parsed,
10209         .data = NULL,
10210         .help_str = "show port <port_id> queue-region"
10211                 ": show all queue region related configuration info",
10212         .tokens = {
10213                 (void *)&cmd_show_queue_region_info_get,
10214                 (void *)&cmd_show_queue_region_info_port,
10215                 (void *)&cmd_show_queue_region_info_port_index,
10216                 (void *)&cmd_show_queue_region_info_cmd,
10217                 NULL,
10218         },
10219 };
10220
10221 /* *** Filters Control *** */
10222
10223 /* *** deal with flow director filter *** */
10224 struct cmd_flow_director_result {
10225         cmdline_fixed_string_t flow_director_filter;
10226         portid_t port_id;
10227         cmdline_fixed_string_t mode;
10228         cmdline_fixed_string_t mode_value;
10229         cmdline_fixed_string_t ops;
10230         cmdline_fixed_string_t flow;
10231         cmdline_fixed_string_t flow_type;
10232         cmdline_fixed_string_t ether;
10233         uint16_t ether_type;
10234         cmdline_fixed_string_t src;
10235         cmdline_ipaddr_t ip_src;
10236         uint16_t port_src;
10237         cmdline_fixed_string_t dst;
10238         cmdline_ipaddr_t ip_dst;
10239         uint16_t port_dst;
10240         cmdline_fixed_string_t verify_tag;
10241         uint32_t verify_tag_value;
10242         cmdline_fixed_string_t tos;
10243         uint8_t tos_value;
10244         cmdline_fixed_string_t proto;
10245         uint8_t proto_value;
10246         cmdline_fixed_string_t ttl;
10247         uint8_t ttl_value;
10248         cmdline_fixed_string_t vlan;
10249         uint16_t vlan_value;
10250         cmdline_fixed_string_t flexbytes;
10251         cmdline_fixed_string_t flexbytes_value;
10252         cmdline_fixed_string_t pf_vf;
10253         cmdline_fixed_string_t drop;
10254         cmdline_fixed_string_t queue;
10255         uint16_t  queue_id;
10256         cmdline_fixed_string_t fd_id;
10257         uint32_t  fd_id_value;
10258         cmdline_fixed_string_t mac;
10259         struct rte_ether_addr mac_addr;
10260         cmdline_fixed_string_t tunnel;
10261         cmdline_fixed_string_t tunnel_type;
10262         cmdline_fixed_string_t tunnel_id;
10263         uint32_t tunnel_id_value;
10264         cmdline_fixed_string_t packet;
10265         char filepath[];
10266 };
10267
10268 static inline int
10269 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
10270 {
10271         char s[256];
10272         const char *p, *p0 = q_arg;
10273         char *end;
10274         unsigned long int_fld;
10275         char *str_fld[max_num];
10276         int i;
10277         unsigned size;
10278         int ret = -1;
10279
10280         p = strchr(p0, '(');
10281         if (p == NULL)
10282                 return -1;
10283         ++p;
10284         p0 = strchr(p, ')');
10285         if (p0 == NULL)
10286                 return -1;
10287
10288         size = p0 - p;
10289         if (size >= sizeof(s))
10290                 return -1;
10291
10292         snprintf(s, sizeof(s), "%.*s", size, p);
10293         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10294         if (ret < 0 || ret > max_num)
10295                 return -1;
10296         for (i = 0; i < ret; i++) {
10297                 errno = 0;
10298                 int_fld = strtoul(str_fld[i], &end, 0);
10299                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
10300                         return -1;
10301                 flexbytes[i] = (uint8_t)int_fld;
10302         }
10303         return ret;
10304 }
10305
10306 static uint16_t
10307 str2flowtype(char *string)
10308 {
10309         uint8_t i = 0;
10310         static const struct {
10311                 char str[32];
10312                 uint16_t type;
10313         } flowtype_str[] = {
10314                 {"raw", RTE_ETH_FLOW_RAW},
10315                 {"ipv4", RTE_ETH_FLOW_IPV4},
10316                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
10317                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
10318                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
10319                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
10320                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
10321                 {"ipv6", RTE_ETH_FLOW_IPV6},
10322                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
10323                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
10324                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
10325                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
10326                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
10327                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
10328         };
10329
10330         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
10331                 if (!strcmp(flowtype_str[i].str, string))
10332                         return flowtype_str[i].type;
10333         }
10334
10335         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
10336                 return (uint16_t)atoi(string);
10337
10338         return RTE_ETH_FLOW_UNKNOWN;
10339 }
10340
10341 static enum rte_eth_fdir_tunnel_type
10342 str2fdir_tunneltype(char *string)
10343 {
10344         uint8_t i = 0;
10345
10346         static const struct {
10347                 char str[32];
10348                 enum rte_eth_fdir_tunnel_type type;
10349         } tunneltype_str[] = {
10350                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
10351                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
10352         };
10353
10354         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
10355                 if (!strcmp(tunneltype_str[i].str, string))
10356                         return tunneltype_str[i].type;
10357         }
10358         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
10359 }
10360
10361 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
10362 do { \
10363         if ((ip_addr).family == AF_INET) \
10364                 (ip) = (ip_addr).addr.ipv4.s_addr; \
10365         else { \
10366                 printf("invalid parameter.\n"); \
10367                 return; \
10368         } \
10369 } while (0)
10370
10371 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
10372 do { \
10373         if ((ip_addr).family == AF_INET6) \
10374                 rte_memcpy(&(ip), \
10375                                  &((ip_addr).addr.ipv6), \
10376                                  sizeof(struct in6_addr)); \
10377         else { \
10378                 printf("invalid parameter.\n"); \
10379                 return; \
10380         } \
10381 } while (0)
10382
10383 static void
10384 cmd_flow_director_filter_parsed(void *parsed_result,
10385                           __rte_unused struct cmdline *cl,
10386                           __rte_unused void *data)
10387 {
10388         struct cmd_flow_director_result *res = parsed_result;
10389         struct rte_eth_fdir_filter entry;
10390         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
10391         char *end;
10392         unsigned long vf_id;
10393         int ret = 0;
10394
10395         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10396         if (ret < 0) {
10397                 printf("flow director is not supported on port %u.\n",
10398                         res->port_id);
10399                 return;
10400         }
10401         memset(flexbytes, 0, sizeof(flexbytes));
10402         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
10403
10404         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10405                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10406                         printf("Please set mode to MAC-VLAN.\n");
10407                         return;
10408                 }
10409         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10410                 if (strcmp(res->mode_value, "Tunnel")) {
10411                         printf("Please set mode to Tunnel.\n");
10412                         return;
10413                 }
10414         } else {
10415                 if (!strcmp(res->mode_value, "raw")) {
10416 #ifdef RTE_NET_I40E
10417                         struct rte_pmd_i40e_flow_type_mapping
10418                                         mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
10419                         struct rte_pmd_i40e_pkt_template_conf conf;
10420                         uint16_t flow_type = str2flowtype(res->flow_type);
10421                         uint16_t i, port = res->port_id;
10422                         uint8_t add;
10423
10424                         memset(&conf, 0, sizeof(conf));
10425
10426                         if (flow_type == RTE_ETH_FLOW_UNKNOWN) {
10427                                 printf("Invalid flow type specified.\n");
10428                                 return;
10429                         }
10430                         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id,
10431                                                                  mapping);
10432                         if (ret)
10433                                 return;
10434                         if (mapping[flow_type].pctype == 0ULL) {
10435                                 printf("Invalid flow type specified.\n");
10436                                 return;
10437                         }
10438                         for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) {
10439                                 if (mapping[flow_type].pctype & (1ULL << i)) {
10440                                         conf.input.pctype = i;
10441                                         break;
10442                                 }
10443                         }
10444
10445                         conf.input.packet = open_file(res->filepath,
10446                                                 &conf.input.length);
10447                         if (!conf.input.packet)
10448                                 return;
10449                         if (!strcmp(res->drop, "drop"))
10450                                 conf.action.behavior =
10451                                         RTE_PMD_I40E_PKT_TEMPLATE_REJECT;
10452                         else
10453                                 conf.action.behavior =
10454                                         RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT;
10455                         conf.action.report_status =
10456                                         RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID;
10457                         conf.action.rx_queue = res->queue_id;
10458                         conf.soft_id = res->fd_id_value;
10459                         add  = strcmp(res->ops, "del") ? 1 : 0;
10460                         ret = rte_pmd_i40e_flow_add_del_packet_template(port,
10461                                                                         &conf,
10462                                                                         add);
10463                         if (ret < 0)
10464                                 printf("flow director config error: (%s)\n",
10465                                        strerror(-ret));
10466                         close_file(conf.input.packet);
10467 #endif
10468                         return;
10469                 } else if (strcmp(res->mode_value, "IP")) {
10470                         printf("Please set mode to IP or raw.\n");
10471                         return;
10472                 }
10473                 entry.input.flow_type = str2flowtype(res->flow_type);
10474         }
10475
10476         ret = parse_flexbytes(res->flexbytes_value,
10477                                         flexbytes,
10478                                         RTE_ETH_FDIR_MAX_FLEXLEN);
10479         if (ret < 0) {
10480                 printf("error: Cannot parse flexbytes input.\n");
10481                 return;
10482         }
10483
10484         switch (entry.input.flow_type) {
10485         case RTE_ETH_FLOW_FRAG_IPV4:
10486         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
10487                 entry.input.flow.ip4_flow.proto = res->proto_value;
10488                 /* fall-through */
10489         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
10490         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
10491                 IPV4_ADDR_TO_UINT(res->ip_dst,
10492                         entry.input.flow.ip4_flow.dst_ip);
10493                 IPV4_ADDR_TO_UINT(res->ip_src,
10494                         entry.input.flow.ip4_flow.src_ip);
10495                 entry.input.flow.ip4_flow.tos = res->tos_value;
10496                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10497                 /* need convert to big endian. */
10498                 entry.input.flow.udp4_flow.dst_port =
10499                                 rte_cpu_to_be_16(res->port_dst);
10500                 entry.input.flow.udp4_flow.src_port =
10501                                 rte_cpu_to_be_16(res->port_src);
10502                 break;
10503         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
10504                 IPV4_ADDR_TO_UINT(res->ip_dst,
10505                         entry.input.flow.sctp4_flow.ip.dst_ip);
10506                 IPV4_ADDR_TO_UINT(res->ip_src,
10507                         entry.input.flow.sctp4_flow.ip.src_ip);
10508                 entry.input.flow.ip4_flow.tos = res->tos_value;
10509                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
10510                 /* need convert to big endian. */
10511                 entry.input.flow.sctp4_flow.dst_port =
10512                                 rte_cpu_to_be_16(res->port_dst);
10513                 entry.input.flow.sctp4_flow.src_port =
10514                                 rte_cpu_to_be_16(res->port_src);
10515                 entry.input.flow.sctp4_flow.verify_tag =
10516                                 rte_cpu_to_be_32(res->verify_tag_value);
10517                 break;
10518         case RTE_ETH_FLOW_FRAG_IPV6:
10519         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
10520                 entry.input.flow.ipv6_flow.proto = res->proto_value;
10521                 /* fall-through */
10522         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
10523         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
10524                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10525                         entry.input.flow.ipv6_flow.dst_ip);
10526                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10527                         entry.input.flow.ipv6_flow.src_ip);
10528                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10529                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10530                 /* need convert to big endian. */
10531                 entry.input.flow.udp6_flow.dst_port =
10532                                 rte_cpu_to_be_16(res->port_dst);
10533                 entry.input.flow.udp6_flow.src_port =
10534                                 rte_cpu_to_be_16(res->port_src);
10535                 break;
10536         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10537                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10538                         entry.input.flow.sctp6_flow.ip.dst_ip);
10539                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10540                         entry.input.flow.sctp6_flow.ip.src_ip);
10541                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10542                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10543                 /* need convert to big endian. */
10544                 entry.input.flow.sctp6_flow.dst_port =
10545                                 rte_cpu_to_be_16(res->port_dst);
10546                 entry.input.flow.sctp6_flow.src_port =
10547                                 rte_cpu_to_be_16(res->port_src);
10548                 entry.input.flow.sctp6_flow.verify_tag =
10549                                 rte_cpu_to_be_32(res->verify_tag_value);
10550                 break;
10551         case RTE_ETH_FLOW_L2_PAYLOAD:
10552                 entry.input.flow.l2_flow.ether_type =
10553                         rte_cpu_to_be_16(res->ether_type);
10554                 break;
10555         default:
10556                 break;
10557         }
10558
10559         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10560                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10561                                  &res->mac_addr,
10562                                  sizeof(struct rte_ether_addr));
10563
10564         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10565                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10566                                  &res->mac_addr,
10567                                  sizeof(struct rte_ether_addr));
10568                 entry.input.flow.tunnel_flow.tunnel_type =
10569                         str2fdir_tunneltype(res->tunnel_type);
10570                 entry.input.flow.tunnel_flow.tunnel_id =
10571                         rte_cpu_to_be_32(res->tunnel_id_value);
10572         }
10573
10574         rte_memcpy(entry.input.flow_ext.flexbytes,
10575                    flexbytes,
10576                    RTE_ETH_FDIR_MAX_FLEXLEN);
10577
10578         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10579
10580         entry.action.flex_off = 0;  /*use 0 by default */
10581         if (!strcmp(res->drop, "drop"))
10582                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10583         else
10584                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10585
10586         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10587             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10588                 if (!strcmp(res->pf_vf, "pf"))
10589                         entry.input.flow_ext.is_vf = 0;
10590                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10591                         struct rte_eth_dev_info dev_info;
10592
10593                         ret = eth_dev_info_get_print_err(res->port_id,
10594                                                 &dev_info);
10595                         if (ret != 0)
10596                                 return;
10597
10598                         errno = 0;
10599                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10600                         if (errno != 0 || *end != '\0' ||
10601                             vf_id >= dev_info.max_vfs) {
10602                                 printf("invalid parameter %s.\n", res->pf_vf);
10603                                 return;
10604                         }
10605                         entry.input.flow_ext.is_vf = 1;
10606                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10607                 } else {
10608                         printf("invalid parameter %s.\n", res->pf_vf);
10609                         return;
10610                 }
10611         }
10612
10613         /* set to report FD ID by default */
10614         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10615         entry.action.rx_queue = res->queue_id;
10616         entry.soft_id = res->fd_id_value;
10617         if (!strcmp(res->ops, "add"))
10618                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10619                                              RTE_ETH_FILTER_ADD, &entry);
10620         else if (!strcmp(res->ops, "del"))
10621                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10622                                              RTE_ETH_FILTER_DELETE, &entry);
10623         else
10624                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10625                                              RTE_ETH_FILTER_UPDATE, &entry);
10626         if (ret < 0)
10627                 printf("flow director programming error: (%s)\n",
10628                         strerror(-ret));
10629 }
10630
10631 cmdline_parse_token_string_t cmd_flow_director_filter =
10632         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10633                                  flow_director_filter, "flow_director_filter");
10634 cmdline_parse_token_num_t cmd_flow_director_port_id =
10635         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10636                               port_id, UINT16);
10637 cmdline_parse_token_string_t cmd_flow_director_ops =
10638         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10639                                  ops, "add#del#update");
10640 cmdline_parse_token_string_t cmd_flow_director_flow =
10641         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10642                                  flow, "flow");
10643 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10644         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10645                 flow_type, NULL);
10646 cmdline_parse_token_string_t cmd_flow_director_ether =
10647         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10648                                  ether, "ether");
10649 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10650         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10651                               ether_type, UINT16);
10652 cmdline_parse_token_string_t cmd_flow_director_src =
10653         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10654                                  src, "src");
10655 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10656         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10657                                  ip_src);
10658 cmdline_parse_token_num_t cmd_flow_director_port_src =
10659         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10660                               port_src, UINT16);
10661 cmdline_parse_token_string_t cmd_flow_director_dst =
10662         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10663                                  dst, "dst");
10664 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10665         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10666                                  ip_dst);
10667 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10668         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10669                               port_dst, UINT16);
10670 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10671         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10672                                   verify_tag, "verify_tag");
10673 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10674         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10675                               verify_tag_value, UINT32);
10676 cmdline_parse_token_string_t cmd_flow_director_tos =
10677         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10678                                  tos, "tos");
10679 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10680         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10681                               tos_value, UINT8);
10682 cmdline_parse_token_string_t cmd_flow_director_proto =
10683         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10684                                  proto, "proto");
10685 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10686         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10687                               proto_value, UINT8);
10688 cmdline_parse_token_string_t cmd_flow_director_ttl =
10689         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10690                                  ttl, "ttl");
10691 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10692         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10693                               ttl_value, UINT8);
10694 cmdline_parse_token_string_t cmd_flow_director_vlan =
10695         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10696                                  vlan, "vlan");
10697 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10698         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10699                               vlan_value, UINT16);
10700 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10701         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10702                                  flexbytes, "flexbytes");
10703 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10704         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10705                               flexbytes_value, NULL);
10706 cmdline_parse_token_string_t cmd_flow_director_drop =
10707         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10708                                  drop, "drop#fwd");
10709 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10710         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10711                               pf_vf, NULL);
10712 cmdline_parse_token_string_t cmd_flow_director_queue =
10713         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10714                                  queue, "queue");
10715 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10716         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10717                               queue_id, UINT16);
10718 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10719         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10720                                  fd_id, "fd_id");
10721 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10722         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10723                               fd_id_value, UINT32);
10724
10725 cmdline_parse_token_string_t cmd_flow_director_mode =
10726         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10727                                  mode, "mode");
10728 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10729         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10730                                  mode_value, "IP");
10731 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10732         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10733                                  mode_value, "MAC-VLAN");
10734 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10735         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10736                                  mode_value, "Tunnel");
10737 cmdline_parse_token_string_t cmd_flow_director_mode_raw =
10738         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10739                                  mode_value, "raw");
10740 cmdline_parse_token_string_t cmd_flow_director_mac =
10741         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10742                                  mac, "mac");
10743 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10744         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10745                                     mac_addr);
10746 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10747         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10748                                  tunnel, "tunnel");
10749 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10751                                  tunnel_type, "NVGRE#VxLAN");
10752 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10753         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10754                                  tunnel_id, "tunnel-id");
10755 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10756         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10757                               tunnel_id_value, UINT32);
10758 cmdline_parse_token_string_t cmd_flow_director_packet =
10759         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10760                                  packet, "packet");
10761 cmdline_parse_token_string_t cmd_flow_director_filepath =
10762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10763                                  filepath, NULL);
10764
10765 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10766         .f = cmd_flow_director_filter_parsed,
10767         .data = NULL,
10768         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10769                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10770                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10771                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10772                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10773                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10774                 "fd_id <fd_id_value>: "
10775                 "Add or delete an ip flow director entry on NIC",
10776         .tokens = {
10777                 (void *)&cmd_flow_director_filter,
10778                 (void *)&cmd_flow_director_port_id,
10779                 (void *)&cmd_flow_director_mode,
10780                 (void *)&cmd_flow_director_mode_ip,
10781                 (void *)&cmd_flow_director_ops,
10782                 (void *)&cmd_flow_director_flow,
10783                 (void *)&cmd_flow_director_flow_type,
10784                 (void *)&cmd_flow_director_src,
10785                 (void *)&cmd_flow_director_ip_src,
10786                 (void *)&cmd_flow_director_dst,
10787                 (void *)&cmd_flow_director_ip_dst,
10788                 (void *)&cmd_flow_director_tos,
10789                 (void *)&cmd_flow_director_tos_value,
10790                 (void *)&cmd_flow_director_proto,
10791                 (void *)&cmd_flow_director_proto_value,
10792                 (void *)&cmd_flow_director_ttl,
10793                 (void *)&cmd_flow_director_ttl_value,
10794                 (void *)&cmd_flow_director_vlan,
10795                 (void *)&cmd_flow_director_vlan_value,
10796                 (void *)&cmd_flow_director_flexbytes,
10797                 (void *)&cmd_flow_director_flexbytes_value,
10798                 (void *)&cmd_flow_director_drop,
10799                 (void *)&cmd_flow_director_pf_vf,
10800                 (void *)&cmd_flow_director_queue,
10801                 (void *)&cmd_flow_director_queue_id,
10802                 (void *)&cmd_flow_director_fd_id,
10803                 (void *)&cmd_flow_director_fd_id_value,
10804                 NULL,
10805         },
10806 };
10807
10808 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10809         .f = cmd_flow_director_filter_parsed,
10810         .data = NULL,
10811         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10812                 "director entry on NIC",
10813         .tokens = {
10814                 (void *)&cmd_flow_director_filter,
10815                 (void *)&cmd_flow_director_port_id,
10816                 (void *)&cmd_flow_director_mode,
10817                 (void *)&cmd_flow_director_mode_ip,
10818                 (void *)&cmd_flow_director_ops,
10819                 (void *)&cmd_flow_director_flow,
10820                 (void *)&cmd_flow_director_flow_type,
10821                 (void *)&cmd_flow_director_src,
10822                 (void *)&cmd_flow_director_ip_src,
10823                 (void *)&cmd_flow_director_port_src,
10824                 (void *)&cmd_flow_director_dst,
10825                 (void *)&cmd_flow_director_ip_dst,
10826                 (void *)&cmd_flow_director_port_dst,
10827                 (void *)&cmd_flow_director_tos,
10828                 (void *)&cmd_flow_director_tos_value,
10829                 (void *)&cmd_flow_director_ttl,
10830                 (void *)&cmd_flow_director_ttl_value,
10831                 (void *)&cmd_flow_director_vlan,
10832                 (void *)&cmd_flow_director_vlan_value,
10833                 (void *)&cmd_flow_director_flexbytes,
10834                 (void *)&cmd_flow_director_flexbytes_value,
10835                 (void *)&cmd_flow_director_drop,
10836                 (void *)&cmd_flow_director_pf_vf,
10837                 (void *)&cmd_flow_director_queue,
10838                 (void *)&cmd_flow_director_queue_id,
10839                 (void *)&cmd_flow_director_fd_id,
10840                 (void *)&cmd_flow_director_fd_id_value,
10841                 NULL,
10842         },
10843 };
10844
10845 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10846         .f = cmd_flow_director_filter_parsed,
10847         .data = NULL,
10848         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10849                 "director entry on NIC",
10850         .tokens = {
10851                 (void *)&cmd_flow_director_filter,
10852                 (void *)&cmd_flow_director_port_id,
10853                 (void *)&cmd_flow_director_mode,
10854                 (void *)&cmd_flow_director_mode_ip,
10855                 (void *)&cmd_flow_director_ops,
10856                 (void *)&cmd_flow_director_flow,
10857                 (void *)&cmd_flow_director_flow_type,
10858                 (void *)&cmd_flow_director_src,
10859                 (void *)&cmd_flow_director_ip_src,
10860                 (void *)&cmd_flow_director_port_src,
10861                 (void *)&cmd_flow_director_dst,
10862                 (void *)&cmd_flow_director_ip_dst,
10863                 (void *)&cmd_flow_director_port_dst,
10864                 (void *)&cmd_flow_director_verify_tag,
10865                 (void *)&cmd_flow_director_verify_tag_value,
10866                 (void *)&cmd_flow_director_tos,
10867                 (void *)&cmd_flow_director_tos_value,
10868                 (void *)&cmd_flow_director_ttl,
10869                 (void *)&cmd_flow_director_ttl_value,
10870                 (void *)&cmd_flow_director_vlan,
10871                 (void *)&cmd_flow_director_vlan_value,
10872                 (void *)&cmd_flow_director_flexbytes,
10873                 (void *)&cmd_flow_director_flexbytes_value,
10874                 (void *)&cmd_flow_director_drop,
10875                 (void *)&cmd_flow_director_pf_vf,
10876                 (void *)&cmd_flow_director_queue,
10877                 (void *)&cmd_flow_director_queue_id,
10878                 (void *)&cmd_flow_director_fd_id,
10879                 (void *)&cmd_flow_director_fd_id_value,
10880                 NULL,
10881         },
10882 };
10883
10884 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10885         .f = cmd_flow_director_filter_parsed,
10886         .data = NULL,
10887         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10888                 "director entry on NIC",
10889         .tokens = {
10890                 (void *)&cmd_flow_director_filter,
10891                 (void *)&cmd_flow_director_port_id,
10892                 (void *)&cmd_flow_director_mode,
10893                 (void *)&cmd_flow_director_mode_ip,
10894                 (void *)&cmd_flow_director_ops,
10895                 (void *)&cmd_flow_director_flow,
10896                 (void *)&cmd_flow_director_flow_type,
10897                 (void *)&cmd_flow_director_ether,
10898                 (void *)&cmd_flow_director_ether_type,
10899                 (void *)&cmd_flow_director_flexbytes,
10900                 (void *)&cmd_flow_director_flexbytes_value,
10901                 (void *)&cmd_flow_director_drop,
10902                 (void *)&cmd_flow_director_pf_vf,
10903                 (void *)&cmd_flow_director_queue,
10904                 (void *)&cmd_flow_director_queue_id,
10905                 (void *)&cmd_flow_director_fd_id,
10906                 (void *)&cmd_flow_director_fd_id_value,
10907                 NULL,
10908         },
10909 };
10910
10911 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10912         .f = cmd_flow_director_filter_parsed,
10913         .data = NULL,
10914         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10915                 "director entry on NIC",
10916         .tokens = {
10917                 (void *)&cmd_flow_director_filter,
10918                 (void *)&cmd_flow_director_port_id,
10919                 (void *)&cmd_flow_director_mode,
10920                 (void *)&cmd_flow_director_mode_mac_vlan,
10921                 (void *)&cmd_flow_director_ops,
10922                 (void *)&cmd_flow_director_mac,
10923                 (void *)&cmd_flow_director_mac_addr,
10924                 (void *)&cmd_flow_director_vlan,
10925                 (void *)&cmd_flow_director_vlan_value,
10926                 (void *)&cmd_flow_director_flexbytes,
10927                 (void *)&cmd_flow_director_flexbytes_value,
10928                 (void *)&cmd_flow_director_drop,
10929                 (void *)&cmd_flow_director_queue,
10930                 (void *)&cmd_flow_director_queue_id,
10931                 (void *)&cmd_flow_director_fd_id,
10932                 (void *)&cmd_flow_director_fd_id_value,
10933                 NULL,
10934         },
10935 };
10936
10937 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10938         .f = cmd_flow_director_filter_parsed,
10939         .data = NULL,
10940         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10941                 "director entry on NIC",
10942         .tokens = {
10943                 (void *)&cmd_flow_director_filter,
10944                 (void *)&cmd_flow_director_port_id,
10945                 (void *)&cmd_flow_director_mode,
10946                 (void *)&cmd_flow_director_mode_tunnel,
10947                 (void *)&cmd_flow_director_ops,
10948                 (void *)&cmd_flow_director_mac,
10949                 (void *)&cmd_flow_director_mac_addr,
10950                 (void *)&cmd_flow_director_vlan,
10951                 (void *)&cmd_flow_director_vlan_value,
10952                 (void *)&cmd_flow_director_tunnel,
10953                 (void *)&cmd_flow_director_tunnel_type,
10954                 (void *)&cmd_flow_director_tunnel_id,
10955                 (void *)&cmd_flow_director_tunnel_id_value,
10956                 (void *)&cmd_flow_director_flexbytes,
10957                 (void *)&cmd_flow_director_flexbytes_value,
10958                 (void *)&cmd_flow_director_drop,
10959                 (void *)&cmd_flow_director_queue,
10960                 (void *)&cmd_flow_director_queue_id,
10961                 (void *)&cmd_flow_director_fd_id,
10962                 (void *)&cmd_flow_director_fd_id_value,
10963                 NULL,
10964         },
10965 };
10966
10967 cmdline_parse_inst_t cmd_add_del_raw_flow_director = {
10968         .f = cmd_flow_director_filter_parsed,
10969         .data = NULL,
10970         .help_str = "flow_director_filter ... : Add or delete a raw flow "
10971                 "director entry on NIC",
10972         .tokens = {
10973                 (void *)&cmd_flow_director_filter,
10974                 (void *)&cmd_flow_director_port_id,
10975                 (void *)&cmd_flow_director_mode,
10976                 (void *)&cmd_flow_director_mode_raw,
10977                 (void *)&cmd_flow_director_ops,
10978                 (void *)&cmd_flow_director_flow,
10979                 (void *)&cmd_flow_director_flow_type,
10980                 (void *)&cmd_flow_director_drop,
10981                 (void *)&cmd_flow_director_queue,
10982                 (void *)&cmd_flow_director_queue_id,
10983                 (void *)&cmd_flow_director_fd_id,
10984                 (void *)&cmd_flow_director_fd_id_value,
10985                 (void *)&cmd_flow_director_packet,
10986                 (void *)&cmd_flow_director_filepath,
10987                 NULL,
10988         },
10989 };
10990
10991 struct cmd_flush_flow_director_result {
10992         cmdline_fixed_string_t flush_flow_director;
10993         portid_t port_id;
10994 };
10995
10996 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10997         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10998                                  flush_flow_director, "flush_flow_director");
10999 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
11000         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
11001                               port_id, UINT16);
11002
11003 static void
11004 cmd_flush_flow_director_parsed(void *parsed_result,
11005                           __rte_unused struct cmdline *cl,
11006                           __rte_unused void *data)
11007 {
11008         struct cmd_flow_director_result *res = parsed_result;
11009         int ret = 0;
11010
11011         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
11012         if (ret < 0) {
11013                 printf("flow director is not supported on port %u.\n",
11014                         res->port_id);
11015                 return;
11016         }
11017
11018         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11019                         RTE_ETH_FILTER_FLUSH, NULL);
11020         if (ret < 0)
11021                 printf("flow director table flushing error: (%s)\n",
11022                         strerror(-ret));
11023 }
11024
11025 cmdline_parse_inst_t cmd_flush_flow_director = {
11026         .f = cmd_flush_flow_director_parsed,
11027         .data = NULL,
11028         .help_str = "flush_flow_director <port_id>: "
11029                 "Flush all flow director entries of a device on NIC",
11030         .tokens = {
11031                 (void *)&cmd_flush_flow_director_flush,
11032                 (void *)&cmd_flush_flow_director_port_id,
11033                 NULL,
11034         },
11035 };
11036
11037 /* *** deal with flow director mask *** */
11038 struct cmd_flow_director_mask_result {
11039         cmdline_fixed_string_t flow_director_mask;
11040         portid_t port_id;
11041         cmdline_fixed_string_t mode;
11042         cmdline_fixed_string_t mode_value;
11043         cmdline_fixed_string_t vlan;
11044         uint16_t vlan_mask;
11045         cmdline_fixed_string_t src_mask;
11046         cmdline_ipaddr_t ipv4_src;
11047         cmdline_ipaddr_t ipv6_src;
11048         uint16_t port_src;
11049         cmdline_fixed_string_t dst_mask;
11050         cmdline_ipaddr_t ipv4_dst;
11051         cmdline_ipaddr_t ipv6_dst;
11052         uint16_t port_dst;
11053         cmdline_fixed_string_t mac;
11054         uint8_t mac_addr_byte_mask;
11055         cmdline_fixed_string_t tunnel_id;
11056         uint32_t tunnel_id_mask;
11057         cmdline_fixed_string_t tunnel_type;
11058         uint8_t tunnel_type_mask;
11059 };
11060
11061 static void
11062 cmd_flow_director_mask_parsed(void *parsed_result,
11063                           __rte_unused struct cmdline *cl,
11064                           __rte_unused void *data)
11065 {
11066         struct cmd_flow_director_mask_result *res = parsed_result;
11067         struct rte_eth_fdir_masks *mask;
11068         struct rte_port *port;
11069
11070         port = &ports[res->port_id];
11071         /** Check if the port is not started **/
11072         if (port->port_status != RTE_PORT_STOPPED) {
11073                 printf("Please stop port %d first\n", res->port_id);
11074                 return;
11075         }
11076
11077         mask = &port->dev_conf.fdir_conf.mask;
11078
11079         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
11080                 if (strcmp(res->mode_value, "MAC-VLAN")) {
11081                         printf("Please set mode to MAC-VLAN.\n");
11082                         return;
11083                 }
11084
11085                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11086         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
11087                 if (strcmp(res->mode_value, "Tunnel")) {
11088                         printf("Please set mode to Tunnel.\n");
11089                         return;
11090                 }
11091
11092                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11093                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
11094                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
11095                 mask->tunnel_type_mask = res->tunnel_type_mask;
11096         } else {
11097                 if (strcmp(res->mode_value, "IP")) {
11098                         printf("Please set mode to IP.\n");
11099                         return;
11100                 }
11101
11102                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
11103                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
11104                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
11105                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
11106                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
11107                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
11108                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
11109         }
11110
11111         cmd_reconfig_device_queue(res->port_id, 1, 1);
11112 }
11113
11114 cmdline_parse_token_string_t cmd_flow_director_mask =
11115         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11116                                  flow_director_mask, "flow_director_mask");
11117 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
11118         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11119                               port_id, UINT16);
11120 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
11121         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11122                                  vlan, "vlan");
11123 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
11124         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11125                               vlan_mask, UINT16);
11126 cmdline_parse_token_string_t cmd_flow_director_mask_src =
11127         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11128                                  src_mask, "src_mask");
11129 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
11130         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11131                                  ipv4_src);
11132 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
11133         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11134                                  ipv6_src);
11135 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
11136         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11137                               port_src, UINT16);
11138 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
11139         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11140                                  dst_mask, "dst_mask");
11141 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
11142         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11143                                  ipv4_dst);
11144 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
11145         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
11146                                  ipv6_dst);
11147 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
11148         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11149                               port_dst, UINT16);
11150
11151 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
11152         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11153                                  mode, "mode");
11154 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
11155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11156                                  mode_value, "IP");
11157 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
11158         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11159                                  mode_value, "MAC-VLAN");
11160 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
11161         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11162                                  mode_value, "Tunnel");
11163 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
11164         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11165                                  mac, "mac");
11166 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
11167         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11168                               mac_addr_byte_mask, UINT8);
11169 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
11170         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11171                                  tunnel_type, "tunnel-type");
11172 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
11173         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11174                               tunnel_type_mask, UINT8);
11175 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
11176         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
11177                                  tunnel_id, "tunnel-id");
11178 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
11179         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
11180                               tunnel_id_mask, UINT32);
11181
11182 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
11183         .f = cmd_flow_director_mask_parsed,
11184         .data = NULL,
11185         .help_str = "flow_director_mask ... : "
11186                 "Set IP mode flow director's mask on NIC",
11187         .tokens = {
11188                 (void *)&cmd_flow_director_mask,
11189                 (void *)&cmd_flow_director_mask_port_id,
11190                 (void *)&cmd_flow_director_mask_mode,
11191                 (void *)&cmd_flow_director_mask_mode_ip,
11192                 (void *)&cmd_flow_director_mask_vlan,
11193                 (void *)&cmd_flow_director_mask_vlan_value,
11194                 (void *)&cmd_flow_director_mask_src,
11195                 (void *)&cmd_flow_director_mask_ipv4_src,
11196                 (void *)&cmd_flow_director_mask_ipv6_src,
11197                 (void *)&cmd_flow_director_mask_port_src,
11198                 (void *)&cmd_flow_director_mask_dst,
11199                 (void *)&cmd_flow_director_mask_ipv4_dst,
11200                 (void *)&cmd_flow_director_mask_ipv6_dst,
11201                 (void *)&cmd_flow_director_mask_port_dst,
11202                 NULL,
11203         },
11204 };
11205
11206 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
11207         .f = cmd_flow_director_mask_parsed,
11208         .data = NULL,
11209         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
11210                 "flow director's mask on NIC",
11211         .tokens = {
11212                 (void *)&cmd_flow_director_mask,
11213                 (void *)&cmd_flow_director_mask_port_id,
11214                 (void *)&cmd_flow_director_mask_mode,
11215                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
11216                 (void *)&cmd_flow_director_mask_vlan,
11217                 (void *)&cmd_flow_director_mask_vlan_value,
11218                 NULL,
11219         },
11220 };
11221
11222 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
11223         .f = cmd_flow_director_mask_parsed,
11224         .data = NULL,
11225         .help_str = "flow_director_mask ... : Set tunnel mode "
11226                 "flow director's mask on NIC",
11227         .tokens = {
11228                 (void *)&cmd_flow_director_mask,
11229                 (void *)&cmd_flow_director_mask_port_id,
11230                 (void *)&cmd_flow_director_mask_mode,
11231                 (void *)&cmd_flow_director_mask_mode_tunnel,
11232                 (void *)&cmd_flow_director_mask_vlan,
11233                 (void *)&cmd_flow_director_mask_vlan_value,
11234                 (void *)&cmd_flow_director_mask_mac,
11235                 (void *)&cmd_flow_director_mask_mac_value,
11236                 (void *)&cmd_flow_director_mask_tunnel_type,
11237                 (void *)&cmd_flow_director_mask_tunnel_type_value,
11238                 (void *)&cmd_flow_director_mask_tunnel_id,
11239                 (void *)&cmd_flow_director_mask_tunnel_id_value,
11240                 NULL,
11241         },
11242 };
11243
11244 /* *** deal with flow director mask on flexible payload *** */
11245 struct cmd_flow_director_flex_mask_result {
11246         cmdline_fixed_string_t flow_director_flexmask;
11247         portid_t port_id;
11248         cmdline_fixed_string_t flow;
11249         cmdline_fixed_string_t flow_type;
11250         cmdline_fixed_string_t mask;
11251 };
11252
11253 static void
11254 cmd_flow_director_flex_mask_parsed(void *parsed_result,
11255                           __rte_unused struct cmdline *cl,
11256                           __rte_unused void *data)
11257 {
11258         struct cmd_flow_director_flex_mask_result *res = parsed_result;
11259         struct rte_eth_fdir_info fdir_info;
11260         struct rte_eth_fdir_flex_mask flex_mask;
11261         struct rte_port *port;
11262         uint64_t flow_type_mask;
11263         uint16_t i;
11264         int ret;
11265
11266         port = &ports[res->port_id];
11267         /** Check if the port is not started **/
11268         if (port->port_status != RTE_PORT_STOPPED) {
11269                 printf("Please stop port %d first\n", res->port_id);
11270                 return;
11271         }
11272
11273         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
11274         ret = parse_flexbytes(res->mask,
11275                         flex_mask.mask,
11276                         RTE_ETH_FDIR_MAX_FLEXLEN);
11277         if (ret < 0) {
11278                 printf("error: Cannot parse mask input.\n");
11279                 return;
11280         }
11281
11282         memset(&fdir_info, 0, sizeof(fdir_info));
11283         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11284                                 RTE_ETH_FILTER_INFO, &fdir_info);
11285         if (ret < 0) {
11286                 printf("Cannot get FDir filter info\n");
11287                 return;
11288         }
11289
11290         if (!strcmp(res->flow_type, "none")) {
11291                 /* means don't specify the flow type */
11292                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
11293                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
11294                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
11295                                0, sizeof(struct rte_eth_fdir_flex_mask));
11296                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
11297                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
11298                                  &flex_mask,
11299                                  sizeof(struct rte_eth_fdir_flex_mask));
11300                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11301                 return;
11302         }
11303         flow_type_mask = fdir_info.flow_types_mask[0];
11304         if (!strcmp(res->flow_type, "all")) {
11305                 if (!flow_type_mask) {
11306                         printf("No flow type supported\n");
11307                         return;
11308                 }
11309                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
11310                         if (flow_type_mask & (1ULL << i)) {
11311                                 flex_mask.flow_type = i;
11312                                 fdir_set_flex_mask(res->port_id, &flex_mask);
11313                         }
11314                 }
11315                 cmd_reconfig_device_queue(res->port_id, 1, 1);
11316                 return;
11317         }
11318         flex_mask.flow_type = str2flowtype(res->flow_type);
11319         if (!(flow_type_mask & (1ULL << flex_mask.flow_type))) {
11320                 printf("Flow type %s not supported on port %d\n",
11321                                 res->flow_type, res->port_id);
11322                 return;
11323         }
11324         fdir_set_flex_mask(res->port_id, &flex_mask);
11325         cmd_reconfig_device_queue(res->port_id, 1, 1);
11326 }
11327
11328 cmdline_parse_token_string_t cmd_flow_director_flexmask =
11329         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11330                                  flow_director_flexmask,
11331                                  "flow_director_flex_mask");
11332 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
11333         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11334                               port_id, UINT16);
11335 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
11336         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11337                                  flow, "flow");
11338 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
11339         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11340                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
11341                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
11342 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
11343         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
11344                                  mask, NULL);
11345
11346 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
11347         .f = cmd_flow_director_flex_mask_parsed,
11348         .data = NULL,
11349         .help_str = "flow_director_flex_mask ... : "
11350                 "Set flow director's flex mask on NIC",
11351         .tokens = {
11352                 (void *)&cmd_flow_director_flexmask,
11353                 (void *)&cmd_flow_director_flexmask_port_id,
11354                 (void *)&cmd_flow_director_flexmask_flow,
11355                 (void *)&cmd_flow_director_flexmask_flow_type,
11356                 (void *)&cmd_flow_director_flexmask_mask,
11357                 NULL,
11358         },
11359 };
11360
11361 /* *** deal with flow director flexible payload configuration *** */
11362 struct cmd_flow_director_flexpayload_result {
11363         cmdline_fixed_string_t flow_director_flexpayload;
11364         portid_t port_id;
11365         cmdline_fixed_string_t payload_layer;
11366         cmdline_fixed_string_t payload_cfg;
11367 };
11368
11369 static inline int
11370 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
11371 {
11372         char s[256];
11373         const char *p, *p0 = q_arg;
11374         char *end;
11375         unsigned long int_fld;
11376         char *str_fld[max_num];
11377         int i;
11378         unsigned size;
11379         int ret = -1;
11380
11381         p = strchr(p0, '(');
11382         if (p == NULL)
11383                 return -1;
11384         ++p;
11385         p0 = strchr(p, ')');
11386         if (p0 == NULL)
11387                 return -1;
11388
11389         size = p0 - p;
11390         if (size >= sizeof(s))
11391                 return -1;
11392
11393         snprintf(s, sizeof(s), "%.*s", size, p);
11394         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
11395         if (ret < 0 || ret > max_num)
11396                 return -1;
11397         for (i = 0; i < ret; i++) {
11398                 errno = 0;
11399                 int_fld = strtoul(str_fld[i], &end, 0);
11400                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
11401                         return -1;
11402                 offsets[i] = (uint16_t)int_fld;
11403         }
11404         return ret;
11405 }
11406
11407 static void
11408 cmd_flow_director_flxpld_parsed(void *parsed_result,
11409                           __rte_unused struct cmdline *cl,
11410                           __rte_unused void *data)
11411 {
11412         struct cmd_flow_director_flexpayload_result *res = parsed_result;
11413         struct rte_eth_flex_payload_cfg flex_cfg;
11414         struct rte_port *port;
11415         int ret = 0;
11416
11417         port = &ports[res->port_id];
11418         /** Check if the port is not started **/
11419         if (port->port_status != RTE_PORT_STOPPED) {
11420                 printf("Please stop port %d first\n", res->port_id);
11421                 return;
11422         }
11423
11424         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
11425
11426         if (!strcmp(res->payload_layer, "raw"))
11427                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
11428         else if (!strcmp(res->payload_layer, "l2"))
11429                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
11430         else if (!strcmp(res->payload_layer, "l3"))
11431                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
11432         else if (!strcmp(res->payload_layer, "l4"))
11433                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
11434
11435         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
11436                             RTE_ETH_FDIR_MAX_FLEXLEN);
11437         if (ret < 0) {
11438                 printf("error: Cannot parse flex payload input.\n");
11439                 return;
11440         }
11441
11442         fdir_set_flex_payload(res->port_id, &flex_cfg);
11443         cmd_reconfig_device_queue(res->port_id, 1, 1);
11444 }
11445
11446 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
11447         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11448                                  flow_director_flexpayload,
11449                                  "flow_director_flex_payload");
11450 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
11451         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11452                               port_id, UINT16);
11453 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
11454         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11455                                  payload_layer, "raw#l2#l3#l4");
11456 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
11457         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
11458                                  payload_cfg, NULL);
11459
11460 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
11461         .f = cmd_flow_director_flxpld_parsed,
11462         .data = NULL,
11463         .help_str = "flow_director_flexpayload ... : "
11464                 "Set flow director's flex payload on NIC",
11465         .tokens = {
11466                 (void *)&cmd_flow_director_flexpayload,
11467                 (void *)&cmd_flow_director_flexpayload_port_id,
11468                 (void *)&cmd_flow_director_flexpayload_payload_layer,
11469                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
11470                 NULL,
11471         },
11472 };
11473
11474 /* Generic flow interface command. */
11475 extern cmdline_parse_inst_t cmd_flow;
11476
11477 /* *** Classification Filters Control *** */
11478
11479 static enum rte_eth_input_set_field
11480 str2inset(char *string)
11481 {
11482         uint16_t i;
11483
11484         static const struct {
11485                 char str[32];
11486                 enum rte_eth_input_set_field inset;
11487         } inset_table[] = {
11488                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11489                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11490                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11491                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11492                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11493                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11494                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11495                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11496                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11497                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11498                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11499                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11500                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11501                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11502                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11503                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11504                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11505                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11506                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11507                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11508                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11509                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11510                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11511                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11512                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11513                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11514                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11515                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11516                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11517                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11518                 {"none", RTE_ETH_INPUT_SET_NONE},
11519         };
11520
11521         for (i = 0; i < RTE_DIM(inset_table); i++) {
11522                 if (!strcmp(string, inset_table[i].str))
11523                         return inset_table[i].inset;
11524         }
11525
11526         return RTE_ETH_INPUT_SET_UNKNOWN;
11527 }
11528
11529 /* Set flow director input set */
11530 struct cmd_set_fdir_input_set_result {
11531         cmdline_fixed_string_t set_fdir_input_set;
11532         portid_t port_id;
11533         cmdline_fixed_string_t flow_type;
11534         cmdline_fixed_string_t inset_field;
11535         cmdline_fixed_string_t select;
11536 };
11537
11538 static void
11539 cmd_set_fdir_input_set_parsed(void *parsed_result,
11540         __rte_unused struct cmdline *cl,
11541         __rte_unused void *data)
11542 {
11543         struct cmd_set_fdir_input_set_result *res = parsed_result;
11544         struct rte_eth_fdir_filter_info info;
11545
11546         memset(&info, 0, sizeof(info));
11547         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11548         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11549         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11550         info.info.input_set_conf.inset_size = 1;
11551         if (!strcmp(res->select, "select"))
11552                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11553         else if (!strcmp(res->select, "add"))
11554                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11555         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11556                 RTE_ETH_FILTER_SET, &info);
11557 }
11558
11559 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11560         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11561         set_fdir_input_set, "set_fdir_input_set");
11562 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11563         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11564         port_id, UINT16);
11565 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11566         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11567         flow_type,
11568         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11569         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11570 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11571         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11572         inset_field,
11573         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11574         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11575         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11576         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11577         "sctp-veri-tag#none");
11578 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11579         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11580         select, "select#add");
11581
11582 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11583         .f = cmd_set_fdir_input_set_parsed,
11584         .data = NULL,
11585         .help_str = "set_fdir_input_set <port_id> "
11586         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11587         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11588         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11589         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11590         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11591         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11592         "sctp-veri-tag|none select|add",
11593         .tokens = {
11594                 (void *)&cmd_set_fdir_input_set_cmd,
11595                 (void *)&cmd_set_fdir_input_set_port_id,
11596                 (void *)&cmd_set_fdir_input_set_flow_type,
11597                 (void *)&cmd_set_fdir_input_set_field,
11598                 (void *)&cmd_set_fdir_input_set_select,
11599                 NULL,
11600         },
11601 };
11602
11603 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11604 struct cmd_mcast_addr_result {
11605         cmdline_fixed_string_t mcast_addr_cmd;
11606         cmdline_fixed_string_t what;
11607         uint16_t port_num;
11608         struct rte_ether_addr mc_addr;
11609 };
11610
11611 static void cmd_mcast_addr_parsed(void *parsed_result,
11612                 __rte_unused struct cmdline *cl,
11613                 __rte_unused void *data)
11614 {
11615         struct cmd_mcast_addr_result *res = parsed_result;
11616
11617         if (!rte_is_multicast_ether_addr(&res->mc_addr)) {
11618                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11619                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11620                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11621                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11622                 return;
11623         }
11624         if (strcmp(res->what, "add") == 0)
11625                 mcast_addr_add(res->port_num, &res->mc_addr);
11626         else
11627                 mcast_addr_remove(res->port_num, &res->mc_addr);
11628 }
11629
11630 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11631         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11632                                  mcast_addr_cmd, "mcast_addr");
11633 cmdline_parse_token_string_t cmd_mcast_addr_what =
11634         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11635                                  "add#remove");
11636 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11637         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11638 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11639         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11640
11641 cmdline_parse_inst_t cmd_mcast_addr = {
11642         .f = cmd_mcast_addr_parsed,
11643         .data = (void *)0,
11644         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11645                 "Add/Remove multicast MAC address on port_id",
11646         .tokens = {
11647                 (void *)&cmd_mcast_addr_cmd,
11648                 (void *)&cmd_mcast_addr_what,
11649                 (void *)&cmd_mcast_addr_portnum,
11650                 (void *)&cmd_mcast_addr_addr,
11651                 NULL,
11652         },
11653 };
11654
11655 /* l2 tunnel config
11656  * only support E-tag now.
11657  */
11658
11659 /* Ether type config */
11660 struct cmd_config_l2_tunnel_eth_type_result {
11661         cmdline_fixed_string_t port;
11662         cmdline_fixed_string_t config;
11663         cmdline_fixed_string_t all;
11664         portid_t id;
11665         cmdline_fixed_string_t l2_tunnel;
11666         cmdline_fixed_string_t l2_tunnel_type;
11667         cmdline_fixed_string_t eth_type;
11668         uint16_t eth_type_val;
11669 };
11670
11671 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11672         TOKEN_STRING_INITIALIZER
11673                 (struct cmd_config_l2_tunnel_eth_type_result,
11674                  port, "port");
11675 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11676         TOKEN_STRING_INITIALIZER
11677                 (struct cmd_config_l2_tunnel_eth_type_result,
11678                  config, "config");
11679 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11680         TOKEN_STRING_INITIALIZER
11681                 (struct cmd_config_l2_tunnel_eth_type_result,
11682                  all, "all");
11683 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11684         TOKEN_NUM_INITIALIZER
11685                 (struct cmd_config_l2_tunnel_eth_type_result,
11686                  id, UINT16);
11687 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11688         TOKEN_STRING_INITIALIZER
11689                 (struct cmd_config_l2_tunnel_eth_type_result,
11690                  l2_tunnel, "l2-tunnel");
11691 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11692         TOKEN_STRING_INITIALIZER
11693                 (struct cmd_config_l2_tunnel_eth_type_result,
11694                  l2_tunnel_type, "E-tag");
11695 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11696         TOKEN_STRING_INITIALIZER
11697                 (struct cmd_config_l2_tunnel_eth_type_result,
11698                  eth_type, "ether-type");
11699 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11700         TOKEN_NUM_INITIALIZER
11701                 (struct cmd_config_l2_tunnel_eth_type_result,
11702                  eth_type_val, UINT16);
11703
11704 static enum rte_eth_tunnel_type
11705 str2fdir_l2_tunnel_type(char *string)
11706 {
11707         uint32_t i = 0;
11708
11709         static const struct {
11710                 char str[32];
11711                 enum rte_eth_tunnel_type type;
11712         } l2_tunnel_type_str[] = {
11713                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11714         };
11715
11716         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11717                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11718                         return l2_tunnel_type_str[i].type;
11719         }
11720         return RTE_TUNNEL_TYPE_NONE;
11721 }
11722
11723 /* ether type config for all ports */
11724 static void
11725 cmd_config_l2_tunnel_eth_type_all_parsed
11726         (void *parsed_result,
11727          __rte_unused struct cmdline *cl,
11728          __rte_unused void *data)
11729 {
11730         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11731         struct rte_eth_l2_tunnel_conf entry;
11732         portid_t pid;
11733
11734         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11735         entry.ether_type = res->eth_type_val;
11736
11737         RTE_ETH_FOREACH_DEV(pid) {
11738                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11739         }
11740 }
11741
11742 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11743         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11744         .data = NULL,
11745         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11746         .tokens = {
11747                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11748                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11749                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11750                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11751                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11752                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11753                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11754                 NULL,
11755         },
11756 };
11757
11758 /* ether type config for a specific port */
11759 static void
11760 cmd_config_l2_tunnel_eth_type_specific_parsed(
11761         void *parsed_result,
11762         __rte_unused struct cmdline *cl,
11763         __rte_unused void *data)
11764 {
11765         struct cmd_config_l2_tunnel_eth_type_result *res =
11766                  parsed_result;
11767         struct rte_eth_l2_tunnel_conf entry;
11768
11769         if (port_id_is_invalid(res->id, ENABLED_WARN))
11770                 return;
11771
11772         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11773         entry.ether_type = res->eth_type_val;
11774
11775         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11776 }
11777
11778 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11779         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11780         .data = NULL,
11781         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11782         .tokens = {
11783                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11784                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11785                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11786                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11787                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11788                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11789                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11790                 NULL,
11791         },
11792 };
11793
11794 /* Enable/disable l2 tunnel */
11795 struct cmd_config_l2_tunnel_en_dis_result {
11796         cmdline_fixed_string_t port;
11797         cmdline_fixed_string_t config;
11798         cmdline_fixed_string_t all;
11799         portid_t id;
11800         cmdline_fixed_string_t l2_tunnel;
11801         cmdline_fixed_string_t l2_tunnel_type;
11802         cmdline_fixed_string_t en_dis;
11803 };
11804
11805 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_config_l2_tunnel_en_dis_result,
11808                  port, "port");
11809 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_config_l2_tunnel_en_dis_result,
11812                  config, "config");
11813 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_config_l2_tunnel_en_dis_result,
11816                  all, "all");
11817 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11818         TOKEN_NUM_INITIALIZER
11819                 (struct cmd_config_l2_tunnel_en_dis_result,
11820                  id, UINT16);
11821 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_config_l2_tunnel_en_dis_result,
11824                  l2_tunnel, "l2-tunnel");
11825 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11826         TOKEN_STRING_INITIALIZER
11827                 (struct cmd_config_l2_tunnel_en_dis_result,
11828                  l2_tunnel_type, "E-tag");
11829 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_config_l2_tunnel_en_dis_result,
11832                  en_dis, "enable#disable");
11833
11834 /* enable/disable l2 tunnel for all ports */
11835 static void
11836 cmd_config_l2_tunnel_en_dis_all_parsed(
11837         void *parsed_result,
11838         __rte_unused struct cmdline *cl,
11839         __rte_unused void *data)
11840 {
11841         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11842         struct rte_eth_l2_tunnel_conf entry;
11843         portid_t pid;
11844         uint8_t en;
11845
11846         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11847
11848         if (!strcmp("enable", res->en_dis))
11849                 en = 1;
11850         else
11851                 en = 0;
11852
11853         RTE_ETH_FOREACH_DEV(pid) {
11854                 rte_eth_dev_l2_tunnel_offload_set(pid,
11855                                                   &entry,
11856                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11857                                                   en);
11858         }
11859 }
11860
11861 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11862         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11863         .data = NULL,
11864         .help_str = "port config all l2-tunnel E-tag enable|disable",
11865         .tokens = {
11866                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11867                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11868                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11869                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11870                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11871                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11872                 NULL,
11873         },
11874 };
11875
11876 /* enable/disable l2 tunnel for a port */
11877 static void
11878 cmd_config_l2_tunnel_en_dis_specific_parsed(
11879         void *parsed_result,
11880         __rte_unused struct cmdline *cl,
11881         __rte_unused void *data)
11882 {
11883         struct cmd_config_l2_tunnel_en_dis_result *res =
11884                 parsed_result;
11885         struct rte_eth_l2_tunnel_conf entry;
11886
11887         if (port_id_is_invalid(res->id, ENABLED_WARN))
11888                 return;
11889
11890         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11891
11892         if (!strcmp("enable", res->en_dis))
11893                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11894                                                   &entry,
11895                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11896                                                   1);
11897         else
11898                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11899                                                   &entry,
11900                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11901                                                   0);
11902 }
11903
11904 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11905         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11906         .data = NULL,
11907         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11908         .tokens = {
11909                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11910                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11911                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11912                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11913                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11914                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11915                 NULL,
11916         },
11917 };
11918
11919 /* E-tag configuration */
11920
11921 /* Common result structure for all E-tag configuration */
11922 struct cmd_config_e_tag_result {
11923         cmdline_fixed_string_t e_tag;
11924         cmdline_fixed_string_t set;
11925         cmdline_fixed_string_t insertion;
11926         cmdline_fixed_string_t stripping;
11927         cmdline_fixed_string_t forwarding;
11928         cmdline_fixed_string_t filter;
11929         cmdline_fixed_string_t add;
11930         cmdline_fixed_string_t del;
11931         cmdline_fixed_string_t on;
11932         cmdline_fixed_string_t off;
11933         cmdline_fixed_string_t on_off;
11934         cmdline_fixed_string_t port_tag_id;
11935         uint32_t port_tag_id_val;
11936         cmdline_fixed_string_t e_tag_id;
11937         uint16_t e_tag_id_val;
11938         cmdline_fixed_string_t dst_pool;
11939         uint8_t dst_pool_val;
11940         cmdline_fixed_string_t port;
11941         portid_t port_id;
11942         cmdline_fixed_string_t vf;
11943         uint8_t vf_id;
11944 };
11945
11946 /* Common CLI fields for all E-tag configuration */
11947 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11948         TOKEN_STRING_INITIALIZER
11949                 (struct cmd_config_e_tag_result,
11950                  e_tag, "E-tag");
11951 cmdline_parse_token_string_t cmd_config_e_tag_set =
11952         TOKEN_STRING_INITIALIZER
11953                 (struct cmd_config_e_tag_result,
11954                  set, "set");
11955 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11956         TOKEN_STRING_INITIALIZER
11957                 (struct cmd_config_e_tag_result,
11958                  insertion, "insertion");
11959 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11960         TOKEN_STRING_INITIALIZER
11961                 (struct cmd_config_e_tag_result,
11962                  stripping, "stripping");
11963 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11964         TOKEN_STRING_INITIALIZER
11965                 (struct cmd_config_e_tag_result,
11966                  forwarding, "forwarding");
11967 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11968         TOKEN_STRING_INITIALIZER
11969                 (struct cmd_config_e_tag_result,
11970                  filter, "filter");
11971 cmdline_parse_token_string_t cmd_config_e_tag_add =
11972         TOKEN_STRING_INITIALIZER
11973                 (struct cmd_config_e_tag_result,
11974                  add, "add");
11975 cmdline_parse_token_string_t cmd_config_e_tag_del =
11976         TOKEN_STRING_INITIALIZER
11977                 (struct cmd_config_e_tag_result,
11978                  del, "del");
11979 cmdline_parse_token_string_t cmd_config_e_tag_on =
11980         TOKEN_STRING_INITIALIZER
11981                 (struct cmd_config_e_tag_result,
11982                  on, "on");
11983 cmdline_parse_token_string_t cmd_config_e_tag_off =
11984         TOKEN_STRING_INITIALIZER
11985                 (struct cmd_config_e_tag_result,
11986                  off, "off");
11987 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11988         TOKEN_STRING_INITIALIZER
11989                 (struct cmd_config_e_tag_result,
11990                  on_off, "on#off");
11991 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11992         TOKEN_STRING_INITIALIZER
11993                 (struct cmd_config_e_tag_result,
11994                  port_tag_id, "port-tag-id");
11995 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11996         TOKEN_NUM_INITIALIZER
11997                 (struct cmd_config_e_tag_result,
11998                  port_tag_id_val, UINT32);
11999 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
12000         TOKEN_STRING_INITIALIZER
12001                 (struct cmd_config_e_tag_result,
12002                  e_tag_id, "e-tag-id");
12003 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
12004         TOKEN_NUM_INITIALIZER
12005                 (struct cmd_config_e_tag_result,
12006                  e_tag_id_val, UINT16);
12007 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
12008         TOKEN_STRING_INITIALIZER
12009                 (struct cmd_config_e_tag_result,
12010                  dst_pool, "dst-pool");
12011 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
12012         TOKEN_NUM_INITIALIZER
12013                 (struct cmd_config_e_tag_result,
12014                  dst_pool_val, UINT8);
12015 cmdline_parse_token_string_t cmd_config_e_tag_port =
12016         TOKEN_STRING_INITIALIZER
12017                 (struct cmd_config_e_tag_result,
12018                  port, "port");
12019 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
12020         TOKEN_NUM_INITIALIZER
12021                 (struct cmd_config_e_tag_result,
12022                  port_id, UINT16);
12023 cmdline_parse_token_string_t cmd_config_e_tag_vf =
12024         TOKEN_STRING_INITIALIZER
12025                 (struct cmd_config_e_tag_result,
12026                  vf, "vf");
12027 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
12028         TOKEN_NUM_INITIALIZER
12029                 (struct cmd_config_e_tag_result,
12030                  vf_id, UINT8);
12031
12032 /* E-tag insertion configuration */
12033 static void
12034 cmd_config_e_tag_insertion_en_parsed(
12035         void *parsed_result,
12036         __rte_unused struct cmdline *cl,
12037         __rte_unused void *data)
12038 {
12039         struct cmd_config_e_tag_result *res =
12040                 parsed_result;
12041         struct rte_eth_l2_tunnel_conf entry;
12042
12043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12044                 return;
12045
12046         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12047         entry.tunnel_id = res->port_tag_id_val;
12048         entry.vf_id = res->vf_id;
12049         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12050                                           &entry,
12051                                           ETH_L2_TUNNEL_INSERTION_MASK,
12052                                           1);
12053 }
12054
12055 static void
12056 cmd_config_e_tag_insertion_dis_parsed(
12057         void *parsed_result,
12058         __rte_unused struct cmdline *cl,
12059         __rte_unused void *data)
12060 {
12061         struct cmd_config_e_tag_result *res =
12062                 parsed_result;
12063         struct rte_eth_l2_tunnel_conf entry;
12064
12065         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12066                 return;
12067
12068         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12069         entry.vf_id = res->vf_id;
12070
12071         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
12072                                           &entry,
12073                                           ETH_L2_TUNNEL_INSERTION_MASK,
12074                                           0);
12075 }
12076
12077 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
12078         .f = cmd_config_e_tag_insertion_en_parsed,
12079         .data = NULL,
12080         .help_str = "E-tag ... : E-tag insertion enable",
12081         .tokens = {
12082                 (void *)&cmd_config_e_tag_e_tag,
12083                 (void *)&cmd_config_e_tag_set,
12084                 (void *)&cmd_config_e_tag_insertion,
12085                 (void *)&cmd_config_e_tag_on,
12086                 (void *)&cmd_config_e_tag_port_tag_id,
12087                 (void *)&cmd_config_e_tag_port_tag_id_val,
12088                 (void *)&cmd_config_e_tag_port,
12089                 (void *)&cmd_config_e_tag_port_id,
12090                 (void *)&cmd_config_e_tag_vf,
12091                 (void *)&cmd_config_e_tag_vf_id,
12092                 NULL,
12093         },
12094 };
12095
12096 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
12097         .f = cmd_config_e_tag_insertion_dis_parsed,
12098         .data = NULL,
12099         .help_str = "E-tag ... : E-tag insertion disable",
12100         .tokens = {
12101                 (void *)&cmd_config_e_tag_e_tag,
12102                 (void *)&cmd_config_e_tag_set,
12103                 (void *)&cmd_config_e_tag_insertion,
12104                 (void *)&cmd_config_e_tag_off,
12105                 (void *)&cmd_config_e_tag_port,
12106                 (void *)&cmd_config_e_tag_port_id,
12107                 (void *)&cmd_config_e_tag_vf,
12108                 (void *)&cmd_config_e_tag_vf_id,
12109                 NULL,
12110         },
12111 };
12112
12113 /* E-tag stripping configuration */
12114 static void
12115 cmd_config_e_tag_stripping_parsed(
12116         void *parsed_result,
12117         __rte_unused struct cmdline *cl,
12118         __rte_unused void *data)
12119 {
12120         struct cmd_config_e_tag_result *res =
12121                 parsed_result;
12122         struct rte_eth_l2_tunnel_conf entry;
12123
12124         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12125                 return;
12126
12127         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12128
12129         if (!strcmp(res->on_off, "on"))
12130                 rte_eth_dev_l2_tunnel_offload_set
12131                         (res->port_id,
12132                          &entry,
12133                          ETH_L2_TUNNEL_STRIPPING_MASK,
12134                          1);
12135         else
12136                 rte_eth_dev_l2_tunnel_offload_set
12137                         (res->port_id,
12138                          &entry,
12139                          ETH_L2_TUNNEL_STRIPPING_MASK,
12140                          0);
12141 }
12142
12143 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
12144         .f = cmd_config_e_tag_stripping_parsed,
12145         .data = NULL,
12146         .help_str = "E-tag ... : E-tag stripping enable/disable",
12147         .tokens = {
12148                 (void *)&cmd_config_e_tag_e_tag,
12149                 (void *)&cmd_config_e_tag_set,
12150                 (void *)&cmd_config_e_tag_stripping,
12151                 (void *)&cmd_config_e_tag_on_off,
12152                 (void *)&cmd_config_e_tag_port,
12153                 (void *)&cmd_config_e_tag_port_id,
12154                 NULL,
12155         },
12156 };
12157
12158 /* E-tag forwarding configuration */
12159 static void
12160 cmd_config_e_tag_forwarding_parsed(
12161         void *parsed_result,
12162         __rte_unused struct cmdline *cl,
12163         __rte_unused void *data)
12164 {
12165         struct cmd_config_e_tag_result *res = parsed_result;
12166         struct rte_eth_l2_tunnel_conf entry;
12167
12168         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12169                 return;
12170
12171         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12172
12173         if (!strcmp(res->on_off, "on"))
12174                 rte_eth_dev_l2_tunnel_offload_set
12175                         (res->port_id,
12176                          &entry,
12177                          ETH_L2_TUNNEL_FORWARDING_MASK,
12178                          1);
12179         else
12180                 rte_eth_dev_l2_tunnel_offload_set
12181                         (res->port_id,
12182                          &entry,
12183                          ETH_L2_TUNNEL_FORWARDING_MASK,
12184                          0);
12185 }
12186
12187 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12188         .f = cmd_config_e_tag_forwarding_parsed,
12189         .data = NULL,
12190         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12191         .tokens = {
12192                 (void *)&cmd_config_e_tag_e_tag,
12193                 (void *)&cmd_config_e_tag_set,
12194                 (void *)&cmd_config_e_tag_forwarding,
12195                 (void *)&cmd_config_e_tag_on_off,
12196                 (void *)&cmd_config_e_tag_port,
12197                 (void *)&cmd_config_e_tag_port_id,
12198                 NULL,
12199         },
12200 };
12201
12202 /* E-tag filter configuration */
12203 static void
12204 cmd_config_e_tag_filter_add_parsed(
12205         void *parsed_result,
12206         __rte_unused struct cmdline *cl,
12207         __rte_unused void *data)
12208 {
12209         struct cmd_config_e_tag_result *res = parsed_result;
12210         struct rte_eth_l2_tunnel_conf entry;
12211         int ret = 0;
12212
12213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12214                 return;
12215
12216         if (res->e_tag_id_val > 0x3fff) {
12217                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12218                 return;
12219         }
12220
12221         ret = rte_eth_dev_filter_supported(res->port_id,
12222                                            RTE_ETH_FILTER_L2_TUNNEL);
12223         if (ret < 0) {
12224                 printf("E-tag filter is not supported on port %u.\n",
12225                        res->port_id);
12226                 return;
12227         }
12228
12229         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12230         entry.tunnel_id = res->e_tag_id_val;
12231         entry.pool = res->dst_pool_val;
12232
12233         ret = rte_eth_dev_filter_ctrl(res->port_id,
12234                                       RTE_ETH_FILTER_L2_TUNNEL,
12235                                       RTE_ETH_FILTER_ADD,
12236                                       &entry);
12237         if (ret < 0)
12238                 printf("E-tag filter programming error: (%s)\n",
12239                        strerror(-ret));
12240 }
12241
12242 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12243         .f = cmd_config_e_tag_filter_add_parsed,
12244         .data = NULL,
12245         .help_str = "E-tag ... : E-tag filter add",
12246         .tokens = {
12247                 (void *)&cmd_config_e_tag_e_tag,
12248                 (void *)&cmd_config_e_tag_set,
12249                 (void *)&cmd_config_e_tag_filter,
12250                 (void *)&cmd_config_e_tag_add,
12251                 (void *)&cmd_config_e_tag_e_tag_id,
12252                 (void *)&cmd_config_e_tag_e_tag_id_val,
12253                 (void *)&cmd_config_e_tag_dst_pool,
12254                 (void *)&cmd_config_e_tag_dst_pool_val,
12255                 (void *)&cmd_config_e_tag_port,
12256                 (void *)&cmd_config_e_tag_port_id,
12257                 NULL,
12258         },
12259 };
12260
12261 static void
12262 cmd_config_e_tag_filter_del_parsed(
12263         void *parsed_result,
12264         __rte_unused struct cmdline *cl,
12265         __rte_unused void *data)
12266 {
12267         struct cmd_config_e_tag_result *res = parsed_result;
12268         struct rte_eth_l2_tunnel_conf entry;
12269         int ret = 0;
12270
12271         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12272                 return;
12273
12274         if (res->e_tag_id_val > 0x3fff) {
12275                 printf("e-tag-id must be less than 0x3fff.\n");
12276                 return;
12277         }
12278
12279         ret = rte_eth_dev_filter_supported(res->port_id,
12280                                            RTE_ETH_FILTER_L2_TUNNEL);
12281         if (ret < 0) {
12282                 printf("E-tag filter is not supported on port %u.\n",
12283                        res->port_id);
12284                 return;
12285         }
12286
12287         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12288         entry.tunnel_id = res->e_tag_id_val;
12289
12290         ret = rte_eth_dev_filter_ctrl(res->port_id,
12291                                       RTE_ETH_FILTER_L2_TUNNEL,
12292                                       RTE_ETH_FILTER_DELETE,
12293                                       &entry);
12294         if (ret < 0)
12295                 printf("E-tag filter programming error: (%s)\n",
12296                        strerror(-ret));
12297 }
12298
12299 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12300         .f = cmd_config_e_tag_filter_del_parsed,
12301         .data = NULL,
12302         .help_str = "E-tag ... : E-tag filter delete",
12303         .tokens = {
12304                 (void *)&cmd_config_e_tag_e_tag,
12305                 (void *)&cmd_config_e_tag_set,
12306                 (void *)&cmd_config_e_tag_filter,
12307                 (void *)&cmd_config_e_tag_del,
12308                 (void *)&cmd_config_e_tag_e_tag_id,
12309                 (void *)&cmd_config_e_tag_e_tag_id_val,
12310                 (void *)&cmd_config_e_tag_port,
12311                 (void *)&cmd_config_e_tag_port_id,
12312                 NULL,
12313         },
12314 };
12315
12316 /* vf vlan anti spoof configuration */
12317
12318 /* Common result structure for vf vlan anti spoof */
12319 struct cmd_vf_vlan_anti_spoof_result {
12320         cmdline_fixed_string_t set;
12321         cmdline_fixed_string_t vf;
12322         cmdline_fixed_string_t vlan;
12323         cmdline_fixed_string_t antispoof;
12324         portid_t port_id;
12325         uint32_t vf_id;
12326         cmdline_fixed_string_t on_off;
12327 };
12328
12329 /* Common CLI fields for vf vlan anti spoof enable disable */
12330 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12331         TOKEN_STRING_INITIALIZER
12332                 (struct cmd_vf_vlan_anti_spoof_result,
12333                  set, "set");
12334 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12335         TOKEN_STRING_INITIALIZER
12336                 (struct cmd_vf_vlan_anti_spoof_result,
12337                  vf, "vf");
12338 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12339         TOKEN_STRING_INITIALIZER
12340                 (struct cmd_vf_vlan_anti_spoof_result,
12341                  vlan, "vlan");
12342 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12343         TOKEN_STRING_INITIALIZER
12344                 (struct cmd_vf_vlan_anti_spoof_result,
12345                  antispoof, "antispoof");
12346 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12347         TOKEN_NUM_INITIALIZER
12348                 (struct cmd_vf_vlan_anti_spoof_result,
12349                  port_id, UINT16);
12350 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12351         TOKEN_NUM_INITIALIZER
12352                 (struct cmd_vf_vlan_anti_spoof_result,
12353                  vf_id, UINT32);
12354 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12355         TOKEN_STRING_INITIALIZER
12356                 (struct cmd_vf_vlan_anti_spoof_result,
12357                  on_off, "on#off");
12358
12359 static void
12360 cmd_set_vf_vlan_anti_spoof_parsed(
12361         void *parsed_result,
12362         __rte_unused struct cmdline *cl,
12363         __rte_unused void *data)
12364 {
12365         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12366         int ret = -ENOTSUP;
12367
12368         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12369
12370         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12371                 return;
12372
12373 #ifdef RTE_NET_IXGBE
12374         if (ret == -ENOTSUP)
12375                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12376                                 res->vf_id, is_on);
12377 #endif
12378 #ifdef RTE_NET_I40E
12379         if (ret == -ENOTSUP)
12380                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12381                                 res->vf_id, is_on);
12382 #endif
12383 #ifdef RTE_NET_BNXT
12384         if (ret == -ENOTSUP)
12385                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12386                                 res->vf_id, is_on);
12387 #endif
12388
12389         switch (ret) {
12390         case 0:
12391                 break;
12392         case -EINVAL:
12393                 printf("invalid vf_id %d\n", res->vf_id);
12394                 break;
12395         case -ENODEV:
12396                 printf("invalid port_id %d\n", res->port_id);
12397                 break;
12398         case -ENOTSUP:
12399                 printf("function not implemented\n");
12400                 break;
12401         default:
12402                 printf("programming error: (%s)\n", strerror(-ret));
12403         }
12404 }
12405
12406 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12407         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12408         .data = NULL,
12409         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12410         .tokens = {
12411                 (void *)&cmd_vf_vlan_anti_spoof_set,
12412                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12413                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12414                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12415                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12416                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12417                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12418                 NULL,
12419         },
12420 };
12421
12422 /* vf mac anti spoof configuration */
12423
12424 /* Common result structure for vf mac anti spoof */
12425 struct cmd_vf_mac_anti_spoof_result {
12426         cmdline_fixed_string_t set;
12427         cmdline_fixed_string_t vf;
12428         cmdline_fixed_string_t mac;
12429         cmdline_fixed_string_t antispoof;
12430         portid_t port_id;
12431         uint32_t vf_id;
12432         cmdline_fixed_string_t on_off;
12433 };
12434
12435 /* Common CLI fields for vf mac anti spoof enable disable */
12436 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12437         TOKEN_STRING_INITIALIZER
12438                 (struct cmd_vf_mac_anti_spoof_result,
12439                  set, "set");
12440 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12441         TOKEN_STRING_INITIALIZER
12442                 (struct cmd_vf_mac_anti_spoof_result,
12443                  vf, "vf");
12444 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12445         TOKEN_STRING_INITIALIZER
12446                 (struct cmd_vf_mac_anti_spoof_result,
12447                  mac, "mac");
12448 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12449         TOKEN_STRING_INITIALIZER
12450                 (struct cmd_vf_mac_anti_spoof_result,
12451                  antispoof, "antispoof");
12452 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12453         TOKEN_NUM_INITIALIZER
12454                 (struct cmd_vf_mac_anti_spoof_result,
12455                  port_id, UINT16);
12456 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12457         TOKEN_NUM_INITIALIZER
12458                 (struct cmd_vf_mac_anti_spoof_result,
12459                  vf_id, UINT32);
12460 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12461         TOKEN_STRING_INITIALIZER
12462                 (struct cmd_vf_mac_anti_spoof_result,
12463                  on_off, "on#off");
12464
12465 static void
12466 cmd_set_vf_mac_anti_spoof_parsed(
12467         void *parsed_result,
12468         __rte_unused struct cmdline *cl,
12469         __rte_unused void *data)
12470 {
12471         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12472         int ret = -ENOTSUP;
12473
12474         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12475
12476         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12477                 return;
12478
12479 #ifdef RTE_NET_IXGBE
12480         if (ret == -ENOTSUP)
12481                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12482                         res->vf_id, is_on);
12483 #endif
12484 #ifdef RTE_NET_I40E
12485         if (ret == -ENOTSUP)
12486                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12487                         res->vf_id, is_on);
12488 #endif
12489 #ifdef RTE_NET_BNXT
12490         if (ret == -ENOTSUP)
12491                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12492                         res->vf_id, is_on);
12493 #endif
12494
12495         switch (ret) {
12496         case 0:
12497                 break;
12498         case -EINVAL:
12499                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12500                 break;
12501         case -ENODEV:
12502                 printf("invalid port_id %d\n", res->port_id);
12503                 break;
12504         case -ENOTSUP:
12505                 printf("function not implemented\n");
12506                 break;
12507         default:
12508                 printf("programming error: (%s)\n", strerror(-ret));
12509         }
12510 }
12511
12512 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12513         .f = cmd_set_vf_mac_anti_spoof_parsed,
12514         .data = NULL,
12515         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12516         .tokens = {
12517                 (void *)&cmd_vf_mac_anti_spoof_set,
12518                 (void *)&cmd_vf_mac_anti_spoof_vf,
12519                 (void *)&cmd_vf_mac_anti_spoof_mac,
12520                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12521                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12522                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12523                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12524                 NULL,
12525         },
12526 };
12527
12528 /* vf vlan strip queue configuration */
12529
12530 /* Common result structure for vf mac anti spoof */
12531 struct cmd_vf_vlan_stripq_result {
12532         cmdline_fixed_string_t set;
12533         cmdline_fixed_string_t vf;
12534         cmdline_fixed_string_t vlan;
12535         cmdline_fixed_string_t stripq;
12536         portid_t port_id;
12537         uint16_t vf_id;
12538         cmdline_fixed_string_t on_off;
12539 };
12540
12541 /* Common CLI fields for vf vlan strip enable disable */
12542 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12543         TOKEN_STRING_INITIALIZER
12544                 (struct cmd_vf_vlan_stripq_result,
12545                  set, "set");
12546 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12547         TOKEN_STRING_INITIALIZER
12548                 (struct cmd_vf_vlan_stripq_result,
12549                  vf, "vf");
12550 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12551         TOKEN_STRING_INITIALIZER
12552                 (struct cmd_vf_vlan_stripq_result,
12553                  vlan, "vlan");
12554 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12555         TOKEN_STRING_INITIALIZER
12556                 (struct cmd_vf_vlan_stripq_result,
12557                  stripq, "stripq");
12558 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12559         TOKEN_NUM_INITIALIZER
12560                 (struct cmd_vf_vlan_stripq_result,
12561                  port_id, UINT16);
12562 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12563         TOKEN_NUM_INITIALIZER
12564                 (struct cmd_vf_vlan_stripq_result,
12565                  vf_id, UINT16);
12566 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12567         TOKEN_STRING_INITIALIZER
12568                 (struct cmd_vf_vlan_stripq_result,
12569                  on_off, "on#off");
12570
12571 static void
12572 cmd_set_vf_vlan_stripq_parsed(
12573         void *parsed_result,
12574         __rte_unused struct cmdline *cl,
12575         __rte_unused void *data)
12576 {
12577         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12578         int ret = -ENOTSUP;
12579
12580         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12581
12582         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12583                 return;
12584
12585 #ifdef RTE_NET_IXGBE
12586         if (ret == -ENOTSUP)
12587                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12588                         res->vf_id, is_on);
12589 #endif
12590 #ifdef RTE_NET_I40E
12591         if (ret == -ENOTSUP)
12592                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12593                         res->vf_id, is_on);
12594 #endif
12595 #ifdef RTE_NET_BNXT
12596         if (ret == -ENOTSUP)
12597                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12598                         res->vf_id, is_on);
12599 #endif
12600
12601         switch (ret) {
12602         case 0:
12603                 break;
12604         case -EINVAL:
12605                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12606                 break;
12607         case -ENODEV:
12608                 printf("invalid port_id %d\n", res->port_id);
12609                 break;
12610         case -ENOTSUP:
12611                 printf("function not implemented\n");
12612                 break;
12613         default:
12614                 printf("programming error: (%s)\n", strerror(-ret));
12615         }
12616 }
12617
12618 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12619         .f = cmd_set_vf_vlan_stripq_parsed,
12620         .data = NULL,
12621         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12622         .tokens = {
12623                 (void *)&cmd_vf_vlan_stripq_set,
12624                 (void *)&cmd_vf_vlan_stripq_vf,
12625                 (void *)&cmd_vf_vlan_stripq_vlan,
12626                 (void *)&cmd_vf_vlan_stripq_stripq,
12627                 (void *)&cmd_vf_vlan_stripq_port_id,
12628                 (void *)&cmd_vf_vlan_stripq_vf_id,
12629                 (void *)&cmd_vf_vlan_stripq_on_off,
12630                 NULL,
12631         },
12632 };
12633
12634 /* vf vlan insert configuration */
12635
12636 /* Common result structure for vf vlan insert */
12637 struct cmd_vf_vlan_insert_result {
12638         cmdline_fixed_string_t set;
12639         cmdline_fixed_string_t vf;
12640         cmdline_fixed_string_t vlan;
12641         cmdline_fixed_string_t insert;
12642         portid_t port_id;
12643         uint16_t vf_id;
12644         uint16_t vlan_id;
12645 };
12646
12647 /* Common CLI fields for vf vlan insert enable disable */
12648 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12649         TOKEN_STRING_INITIALIZER
12650                 (struct cmd_vf_vlan_insert_result,
12651                  set, "set");
12652 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12653         TOKEN_STRING_INITIALIZER
12654                 (struct cmd_vf_vlan_insert_result,
12655                  vf, "vf");
12656 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12657         TOKEN_STRING_INITIALIZER
12658                 (struct cmd_vf_vlan_insert_result,
12659                  vlan, "vlan");
12660 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12661         TOKEN_STRING_INITIALIZER
12662                 (struct cmd_vf_vlan_insert_result,
12663                  insert, "insert");
12664 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12665         TOKEN_NUM_INITIALIZER
12666                 (struct cmd_vf_vlan_insert_result,
12667                  port_id, UINT16);
12668 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12669         TOKEN_NUM_INITIALIZER
12670                 (struct cmd_vf_vlan_insert_result,
12671                  vf_id, UINT16);
12672 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12673         TOKEN_NUM_INITIALIZER
12674                 (struct cmd_vf_vlan_insert_result,
12675                  vlan_id, UINT16);
12676
12677 static void
12678 cmd_set_vf_vlan_insert_parsed(
12679         void *parsed_result,
12680         __rte_unused struct cmdline *cl,
12681         __rte_unused void *data)
12682 {
12683         struct cmd_vf_vlan_insert_result *res = parsed_result;
12684         int ret = -ENOTSUP;
12685
12686         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12687                 return;
12688
12689 #ifdef RTE_NET_IXGBE
12690         if (ret == -ENOTSUP)
12691                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12692                         res->vlan_id);
12693 #endif
12694 #ifdef RTE_NET_I40E
12695         if (ret == -ENOTSUP)
12696                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12697                         res->vlan_id);
12698 #endif
12699 #ifdef RTE_NET_BNXT
12700         if (ret == -ENOTSUP)
12701                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12702                         res->vlan_id);
12703 #endif
12704
12705         switch (ret) {
12706         case 0:
12707                 break;
12708         case -EINVAL:
12709                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12710                 break;
12711         case -ENODEV:
12712                 printf("invalid port_id %d\n", res->port_id);
12713                 break;
12714         case -ENOTSUP:
12715                 printf("function not implemented\n");
12716                 break;
12717         default:
12718                 printf("programming error: (%s)\n", strerror(-ret));
12719         }
12720 }
12721
12722 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12723         .f = cmd_set_vf_vlan_insert_parsed,
12724         .data = NULL,
12725         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12726         .tokens = {
12727                 (void *)&cmd_vf_vlan_insert_set,
12728                 (void *)&cmd_vf_vlan_insert_vf,
12729                 (void *)&cmd_vf_vlan_insert_vlan,
12730                 (void *)&cmd_vf_vlan_insert_insert,
12731                 (void *)&cmd_vf_vlan_insert_port_id,
12732                 (void *)&cmd_vf_vlan_insert_vf_id,
12733                 (void *)&cmd_vf_vlan_insert_vlan_id,
12734                 NULL,
12735         },
12736 };
12737
12738 /* tx loopback configuration */
12739
12740 /* Common result structure for tx loopback */
12741 struct cmd_tx_loopback_result {
12742         cmdline_fixed_string_t set;
12743         cmdline_fixed_string_t tx;
12744         cmdline_fixed_string_t loopback;
12745         portid_t port_id;
12746         cmdline_fixed_string_t on_off;
12747 };
12748
12749 /* Common CLI fields for tx loopback enable disable */
12750 cmdline_parse_token_string_t cmd_tx_loopback_set =
12751         TOKEN_STRING_INITIALIZER
12752                 (struct cmd_tx_loopback_result,
12753                  set, "set");
12754 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12755         TOKEN_STRING_INITIALIZER
12756                 (struct cmd_tx_loopback_result,
12757                  tx, "tx");
12758 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12759         TOKEN_STRING_INITIALIZER
12760                 (struct cmd_tx_loopback_result,
12761                  loopback, "loopback");
12762 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12763         TOKEN_NUM_INITIALIZER
12764                 (struct cmd_tx_loopback_result,
12765                  port_id, UINT16);
12766 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12767         TOKEN_STRING_INITIALIZER
12768                 (struct cmd_tx_loopback_result,
12769                  on_off, "on#off");
12770
12771 static void
12772 cmd_set_tx_loopback_parsed(
12773         void *parsed_result,
12774         __rte_unused struct cmdline *cl,
12775         __rte_unused void *data)
12776 {
12777         struct cmd_tx_loopback_result *res = parsed_result;
12778         int ret = -ENOTSUP;
12779
12780         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12781
12782         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12783                 return;
12784
12785 #ifdef RTE_NET_IXGBE
12786         if (ret == -ENOTSUP)
12787                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12788 #endif
12789 #ifdef RTE_NET_I40E
12790         if (ret == -ENOTSUP)
12791                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12792 #endif
12793 #ifdef RTE_NET_BNXT
12794         if (ret == -ENOTSUP)
12795                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12796 #endif
12797 #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA
12798         if (ret == -ENOTSUP)
12799                 ret = rte_pmd_dpaa_set_tx_loopback(res->port_id, is_on);
12800 #endif
12801
12802         switch (ret) {
12803         case 0:
12804                 break;
12805         case -EINVAL:
12806                 printf("invalid is_on %d\n", is_on);
12807                 break;
12808         case -ENODEV:
12809                 printf("invalid port_id %d\n", res->port_id);
12810                 break;
12811         case -ENOTSUP:
12812                 printf("function not implemented\n");
12813                 break;
12814         default:
12815                 printf("programming error: (%s)\n", strerror(-ret));
12816         }
12817 }
12818
12819 cmdline_parse_inst_t cmd_set_tx_loopback = {
12820         .f = cmd_set_tx_loopback_parsed,
12821         .data = NULL,
12822         .help_str = "set tx loopback <port_id> on|off",
12823         .tokens = {
12824                 (void *)&cmd_tx_loopback_set,
12825                 (void *)&cmd_tx_loopback_tx,
12826                 (void *)&cmd_tx_loopback_loopback,
12827                 (void *)&cmd_tx_loopback_port_id,
12828                 (void *)&cmd_tx_loopback_on_off,
12829                 NULL,
12830         },
12831 };
12832
12833 /* all queues drop enable configuration */
12834
12835 /* Common result structure for all queues drop enable */
12836 struct cmd_all_queues_drop_en_result {
12837         cmdline_fixed_string_t set;
12838         cmdline_fixed_string_t all;
12839         cmdline_fixed_string_t queues;
12840         cmdline_fixed_string_t drop;
12841         portid_t port_id;
12842         cmdline_fixed_string_t on_off;
12843 };
12844
12845 /* Common CLI fields for tx loopback enable disable */
12846 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12847         TOKEN_STRING_INITIALIZER
12848                 (struct cmd_all_queues_drop_en_result,
12849                  set, "set");
12850 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12851         TOKEN_STRING_INITIALIZER
12852                 (struct cmd_all_queues_drop_en_result,
12853                  all, "all");
12854 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12855         TOKEN_STRING_INITIALIZER
12856                 (struct cmd_all_queues_drop_en_result,
12857                  queues, "queues");
12858 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_all_queues_drop_en_result,
12861                  drop, "drop");
12862 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12863         TOKEN_NUM_INITIALIZER
12864                 (struct cmd_all_queues_drop_en_result,
12865                  port_id, UINT16);
12866 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_all_queues_drop_en_result,
12869                  on_off, "on#off");
12870
12871 static void
12872 cmd_set_all_queues_drop_en_parsed(
12873         void *parsed_result,
12874         __rte_unused struct cmdline *cl,
12875         __rte_unused void *data)
12876 {
12877         struct cmd_all_queues_drop_en_result *res = parsed_result;
12878         int ret = -ENOTSUP;
12879         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12880
12881         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12882                 return;
12883
12884 #ifdef RTE_NET_IXGBE
12885         if (ret == -ENOTSUP)
12886                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12887 #endif
12888 #ifdef RTE_NET_BNXT
12889         if (ret == -ENOTSUP)
12890                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12891 #endif
12892         switch (ret) {
12893         case 0:
12894                 break;
12895         case -EINVAL:
12896                 printf("invalid is_on %d\n", is_on);
12897                 break;
12898         case -ENODEV:
12899                 printf("invalid port_id %d\n", res->port_id);
12900                 break;
12901         case -ENOTSUP:
12902                 printf("function not implemented\n");
12903                 break;
12904         default:
12905                 printf("programming error: (%s)\n", strerror(-ret));
12906         }
12907 }
12908
12909 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12910         .f = cmd_set_all_queues_drop_en_parsed,
12911         .data = NULL,
12912         .help_str = "set all queues drop <port_id> on|off",
12913         .tokens = {
12914                 (void *)&cmd_all_queues_drop_en_set,
12915                 (void *)&cmd_all_queues_drop_en_all,
12916                 (void *)&cmd_all_queues_drop_en_queues,
12917                 (void *)&cmd_all_queues_drop_en_drop,
12918                 (void *)&cmd_all_queues_drop_en_port_id,
12919                 (void *)&cmd_all_queues_drop_en_on_off,
12920                 NULL,
12921         },
12922 };
12923
12924 /* vf split drop enable configuration */
12925
12926 /* Common result structure for vf split drop enable */
12927 struct cmd_vf_split_drop_en_result {
12928         cmdline_fixed_string_t set;
12929         cmdline_fixed_string_t vf;
12930         cmdline_fixed_string_t split;
12931         cmdline_fixed_string_t drop;
12932         portid_t port_id;
12933         uint16_t vf_id;
12934         cmdline_fixed_string_t on_off;
12935 };
12936
12937 /* Common CLI fields for vf split drop enable disable */
12938 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12939         TOKEN_STRING_INITIALIZER
12940                 (struct cmd_vf_split_drop_en_result,
12941                  set, "set");
12942 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12943         TOKEN_STRING_INITIALIZER
12944                 (struct cmd_vf_split_drop_en_result,
12945                  vf, "vf");
12946 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12947         TOKEN_STRING_INITIALIZER
12948                 (struct cmd_vf_split_drop_en_result,
12949                  split, "split");
12950 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12951         TOKEN_STRING_INITIALIZER
12952                 (struct cmd_vf_split_drop_en_result,
12953                  drop, "drop");
12954 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12955         TOKEN_NUM_INITIALIZER
12956                 (struct cmd_vf_split_drop_en_result,
12957                  port_id, UINT16);
12958 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12959         TOKEN_NUM_INITIALIZER
12960                 (struct cmd_vf_split_drop_en_result,
12961                  vf_id, UINT16);
12962 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12963         TOKEN_STRING_INITIALIZER
12964                 (struct cmd_vf_split_drop_en_result,
12965                  on_off, "on#off");
12966
12967 static void
12968 cmd_set_vf_split_drop_en_parsed(
12969         void *parsed_result,
12970         __rte_unused struct cmdline *cl,
12971         __rte_unused void *data)
12972 {
12973         struct cmd_vf_split_drop_en_result *res = parsed_result;
12974         int ret = -ENOTSUP;
12975         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12976
12977         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12978                 return;
12979
12980 #ifdef RTE_NET_IXGBE
12981         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12982                         is_on);
12983 #endif
12984         switch (ret) {
12985         case 0:
12986                 break;
12987         case -EINVAL:
12988                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12989                 break;
12990         case -ENODEV:
12991                 printf("invalid port_id %d\n", res->port_id);
12992                 break;
12993         case -ENOTSUP:
12994                 printf("not supported on port %d\n", res->port_id);
12995                 break;
12996         default:
12997                 printf("programming error: (%s)\n", strerror(-ret));
12998         }
12999 }
13000
13001 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
13002         .f = cmd_set_vf_split_drop_en_parsed,
13003         .data = NULL,
13004         .help_str = "set vf split drop <port_id> <vf_id> on|off",
13005         .tokens = {
13006                 (void *)&cmd_vf_split_drop_en_set,
13007                 (void *)&cmd_vf_split_drop_en_vf,
13008                 (void *)&cmd_vf_split_drop_en_split,
13009                 (void *)&cmd_vf_split_drop_en_drop,
13010                 (void *)&cmd_vf_split_drop_en_port_id,
13011                 (void *)&cmd_vf_split_drop_en_vf_id,
13012                 (void *)&cmd_vf_split_drop_en_on_off,
13013                 NULL,
13014         },
13015 };
13016
13017 /* vf mac address configuration */
13018
13019 /* Common result structure for vf mac address */
13020 struct cmd_set_vf_mac_addr_result {
13021         cmdline_fixed_string_t set;
13022         cmdline_fixed_string_t vf;
13023         cmdline_fixed_string_t mac;
13024         cmdline_fixed_string_t addr;
13025         portid_t port_id;
13026         uint16_t vf_id;
13027         struct rte_ether_addr mac_addr;
13028
13029 };
13030
13031 /* Common CLI fields for vf split drop enable disable */
13032 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
13033         TOKEN_STRING_INITIALIZER
13034                 (struct cmd_set_vf_mac_addr_result,
13035                  set, "set");
13036 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
13037         TOKEN_STRING_INITIALIZER
13038                 (struct cmd_set_vf_mac_addr_result,
13039                  vf, "vf");
13040 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
13041         TOKEN_STRING_INITIALIZER
13042                 (struct cmd_set_vf_mac_addr_result,
13043                  mac, "mac");
13044 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
13045         TOKEN_STRING_INITIALIZER
13046                 (struct cmd_set_vf_mac_addr_result,
13047                  addr, "addr");
13048 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
13049         TOKEN_NUM_INITIALIZER
13050                 (struct cmd_set_vf_mac_addr_result,
13051                  port_id, UINT16);
13052 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
13053         TOKEN_NUM_INITIALIZER
13054                 (struct cmd_set_vf_mac_addr_result,
13055                  vf_id, UINT16);
13056 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
13057         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
13058                  mac_addr);
13059
13060 static void
13061 cmd_set_vf_mac_addr_parsed(
13062         void *parsed_result,
13063         __rte_unused struct cmdline *cl,
13064         __rte_unused void *data)
13065 {
13066         struct cmd_set_vf_mac_addr_result *res = parsed_result;
13067         int ret = -ENOTSUP;
13068
13069         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13070                 return;
13071
13072 #ifdef RTE_NET_IXGBE
13073         if (ret == -ENOTSUP)
13074                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
13075                                 &res->mac_addr);
13076 #endif
13077 #ifdef RTE_NET_I40E
13078         if (ret == -ENOTSUP)
13079                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
13080                                 &res->mac_addr);
13081 #endif
13082 #ifdef RTE_NET_BNXT
13083         if (ret == -ENOTSUP)
13084                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
13085                                 &res->mac_addr);
13086 #endif
13087
13088         switch (ret) {
13089         case 0:
13090                 break;
13091         case -EINVAL:
13092                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
13093                 break;
13094         case -ENODEV:
13095                 printf("invalid port_id %d\n", res->port_id);
13096                 break;
13097         case -ENOTSUP:
13098                 printf("function not implemented\n");
13099                 break;
13100         default:
13101                 printf("programming error: (%s)\n", strerror(-ret));
13102         }
13103 }
13104
13105 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
13106         .f = cmd_set_vf_mac_addr_parsed,
13107         .data = NULL,
13108         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
13109         .tokens = {
13110                 (void *)&cmd_set_vf_mac_addr_set,
13111                 (void *)&cmd_set_vf_mac_addr_vf,
13112                 (void *)&cmd_set_vf_mac_addr_mac,
13113                 (void *)&cmd_set_vf_mac_addr_addr,
13114                 (void *)&cmd_set_vf_mac_addr_port_id,
13115                 (void *)&cmd_set_vf_mac_addr_vf_id,
13116                 (void *)&cmd_set_vf_mac_addr_mac_addr,
13117                 NULL,
13118         },
13119 };
13120
13121 /* MACsec configuration */
13122
13123 /* Common result structure for MACsec offload enable */
13124 struct cmd_macsec_offload_on_result {
13125         cmdline_fixed_string_t set;
13126         cmdline_fixed_string_t macsec;
13127         cmdline_fixed_string_t offload;
13128         portid_t port_id;
13129         cmdline_fixed_string_t on;
13130         cmdline_fixed_string_t encrypt;
13131         cmdline_fixed_string_t en_on_off;
13132         cmdline_fixed_string_t replay_protect;
13133         cmdline_fixed_string_t rp_on_off;
13134 };
13135
13136 /* Common CLI fields for MACsec offload disable */
13137 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
13138         TOKEN_STRING_INITIALIZER
13139                 (struct cmd_macsec_offload_on_result,
13140                  set, "set");
13141 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
13142         TOKEN_STRING_INITIALIZER
13143                 (struct cmd_macsec_offload_on_result,
13144                  macsec, "macsec");
13145 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
13146         TOKEN_STRING_INITIALIZER
13147                 (struct cmd_macsec_offload_on_result,
13148                  offload, "offload");
13149 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
13150         TOKEN_NUM_INITIALIZER
13151                 (struct cmd_macsec_offload_on_result,
13152                  port_id, UINT16);
13153 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
13154         TOKEN_STRING_INITIALIZER
13155                 (struct cmd_macsec_offload_on_result,
13156                  on, "on");
13157 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
13158         TOKEN_STRING_INITIALIZER
13159                 (struct cmd_macsec_offload_on_result,
13160                  encrypt, "encrypt");
13161 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13162         TOKEN_STRING_INITIALIZER
13163                 (struct cmd_macsec_offload_on_result,
13164                  en_on_off, "on#off");
13165 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13166         TOKEN_STRING_INITIALIZER
13167                 (struct cmd_macsec_offload_on_result,
13168                  replay_protect, "replay-protect");
13169 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13170         TOKEN_STRING_INITIALIZER
13171                 (struct cmd_macsec_offload_on_result,
13172                  rp_on_off, "on#off");
13173
13174 static void
13175 cmd_set_macsec_offload_on_parsed(
13176         void *parsed_result,
13177         __rte_unused struct cmdline *cl,
13178         __rte_unused void *data)
13179 {
13180         struct cmd_macsec_offload_on_result *res = parsed_result;
13181         int ret = -ENOTSUP;
13182         portid_t port_id = res->port_id;
13183         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13184         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13185         struct rte_eth_dev_info dev_info;
13186
13187         if (port_id_is_invalid(port_id, ENABLED_WARN))
13188                 return;
13189         if (!port_is_stopped(port_id)) {
13190                 printf("Please stop port %d first\n", port_id);
13191                 return;
13192         }
13193
13194         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13195         if (ret != 0)
13196                 return;
13197
13198         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13199 #ifdef RTE_NET_IXGBE
13200                 ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13201 #endif
13202         }
13203         RTE_SET_USED(en);
13204         RTE_SET_USED(rp);
13205
13206         switch (ret) {
13207         case 0:
13208                 ports[port_id].dev_conf.txmode.offloads |=
13209                                                 DEV_TX_OFFLOAD_MACSEC_INSERT;
13210                 cmd_reconfig_device_queue(port_id, 1, 1);
13211                 break;
13212         case -ENODEV:
13213                 printf("invalid port_id %d\n", port_id);
13214                 break;
13215         case -ENOTSUP:
13216                 printf("not supported on port %d\n", port_id);
13217                 break;
13218         default:
13219                 printf("programming error: (%s)\n", strerror(-ret));
13220         }
13221 }
13222
13223 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13224         .f = cmd_set_macsec_offload_on_parsed,
13225         .data = NULL,
13226         .help_str = "set macsec offload <port_id> on "
13227                 "encrypt on|off replay-protect on|off",
13228         .tokens = {
13229                 (void *)&cmd_macsec_offload_on_set,
13230                 (void *)&cmd_macsec_offload_on_macsec,
13231                 (void *)&cmd_macsec_offload_on_offload,
13232                 (void *)&cmd_macsec_offload_on_port_id,
13233                 (void *)&cmd_macsec_offload_on_on,
13234                 (void *)&cmd_macsec_offload_on_encrypt,
13235                 (void *)&cmd_macsec_offload_on_en_on_off,
13236                 (void *)&cmd_macsec_offload_on_replay_protect,
13237                 (void *)&cmd_macsec_offload_on_rp_on_off,
13238                 NULL,
13239         },
13240 };
13241
13242 /* Common result structure for MACsec offload disable */
13243 struct cmd_macsec_offload_off_result {
13244         cmdline_fixed_string_t set;
13245         cmdline_fixed_string_t macsec;
13246         cmdline_fixed_string_t offload;
13247         portid_t port_id;
13248         cmdline_fixed_string_t off;
13249 };
13250
13251 /* Common CLI fields for MACsec offload disable */
13252 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13253         TOKEN_STRING_INITIALIZER
13254                 (struct cmd_macsec_offload_off_result,
13255                  set, "set");
13256 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13257         TOKEN_STRING_INITIALIZER
13258                 (struct cmd_macsec_offload_off_result,
13259                  macsec, "macsec");
13260 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13261         TOKEN_STRING_INITIALIZER
13262                 (struct cmd_macsec_offload_off_result,
13263                  offload, "offload");
13264 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13265         TOKEN_NUM_INITIALIZER
13266                 (struct cmd_macsec_offload_off_result,
13267                  port_id, UINT16);
13268 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_macsec_offload_off_result,
13271                  off, "off");
13272
13273 static void
13274 cmd_set_macsec_offload_off_parsed(
13275         void *parsed_result,
13276         __rte_unused struct cmdline *cl,
13277         __rte_unused void *data)
13278 {
13279         struct cmd_macsec_offload_off_result *res = parsed_result;
13280         int ret = -ENOTSUP;
13281         struct rte_eth_dev_info dev_info;
13282         portid_t port_id = res->port_id;
13283
13284         if (port_id_is_invalid(port_id, ENABLED_WARN))
13285                 return;
13286         if (!port_is_stopped(port_id)) {
13287                 printf("Please stop port %d first\n", port_id);
13288                 return;
13289         }
13290
13291         ret = eth_dev_info_get_print_err(port_id, &dev_info);
13292         if (ret != 0)
13293                 return;
13294
13295         if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
13296 #ifdef RTE_NET_IXGBE
13297                 ret = rte_pmd_ixgbe_macsec_disable(port_id);
13298 #endif
13299         }
13300         switch (ret) {
13301         case 0:
13302                 ports[port_id].dev_conf.txmode.offloads &=
13303                                                 ~DEV_TX_OFFLOAD_MACSEC_INSERT;
13304                 cmd_reconfig_device_queue(port_id, 1, 1);
13305                 break;
13306         case -ENODEV:
13307                 printf("invalid port_id %d\n", port_id);
13308                 break;
13309         case -ENOTSUP:
13310                 printf("not supported on port %d\n", port_id);
13311                 break;
13312         default:
13313                 printf("programming error: (%s)\n", strerror(-ret));
13314         }
13315 }
13316
13317 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13318         .f = cmd_set_macsec_offload_off_parsed,
13319         .data = NULL,
13320         .help_str = "set macsec offload <port_id> off",
13321         .tokens = {
13322                 (void *)&cmd_macsec_offload_off_set,
13323                 (void *)&cmd_macsec_offload_off_macsec,
13324                 (void *)&cmd_macsec_offload_off_offload,
13325                 (void *)&cmd_macsec_offload_off_port_id,
13326                 (void *)&cmd_macsec_offload_off_off,
13327                 NULL,
13328         },
13329 };
13330
13331 /* Common result structure for MACsec secure connection configure */
13332 struct cmd_macsec_sc_result {
13333         cmdline_fixed_string_t set;
13334         cmdline_fixed_string_t macsec;
13335         cmdline_fixed_string_t sc;
13336         cmdline_fixed_string_t tx_rx;
13337         portid_t port_id;
13338         struct rte_ether_addr mac;
13339         uint16_t pi;
13340 };
13341
13342 /* Common CLI fields for MACsec secure connection configure */
13343 cmdline_parse_token_string_t cmd_macsec_sc_set =
13344         TOKEN_STRING_INITIALIZER
13345                 (struct cmd_macsec_sc_result,
13346                  set, "set");
13347 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13348         TOKEN_STRING_INITIALIZER
13349                 (struct cmd_macsec_sc_result,
13350                  macsec, "macsec");
13351 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13352         TOKEN_STRING_INITIALIZER
13353                 (struct cmd_macsec_sc_result,
13354                  sc, "sc");
13355 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13356         TOKEN_STRING_INITIALIZER
13357                 (struct cmd_macsec_sc_result,
13358                  tx_rx, "tx#rx");
13359 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13360         TOKEN_NUM_INITIALIZER
13361                 (struct cmd_macsec_sc_result,
13362                  port_id, UINT16);
13363 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13364         TOKEN_ETHERADDR_INITIALIZER
13365                 (struct cmd_macsec_sc_result,
13366                  mac);
13367 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13368         TOKEN_NUM_INITIALIZER
13369                 (struct cmd_macsec_sc_result,
13370                  pi, UINT16);
13371
13372 static void
13373 cmd_set_macsec_sc_parsed(
13374         void *parsed_result,
13375         __rte_unused struct cmdline *cl,
13376         __rte_unused void *data)
13377 {
13378         struct cmd_macsec_sc_result *res = parsed_result;
13379         int ret = -ENOTSUP;
13380         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13381
13382 #ifdef RTE_NET_IXGBE
13383         ret = is_tx ?
13384                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13385                                 res->mac.addr_bytes) :
13386                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13387                                 res->mac.addr_bytes, res->pi);
13388 #endif
13389         RTE_SET_USED(is_tx);
13390
13391         switch (ret) {
13392         case 0:
13393                 break;
13394         case -ENODEV:
13395                 printf("invalid port_id %d\n", res->port_id);
13396                 break;
13397         case -ENOTSUP:
13398                 printf("not supported on port %d\n", res->port_id);
13399                 break;
13400         default:
13401                 printf("programming error: (%s)\n", strerror(-ret));
13402         }
13403 }
13404
13405 cmdline_parse_inst_t cmd_set_macsec_sc = {
13406         .f = cmd_set_macsec_sc_parsed,
13407         .data = NULL,
13408         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13409         .tokens = {
13410                 (void *)&cmd_macsec_sc_set,
13411                 (void *)&cmd_macsec_sc_macsec,
13412                 (void *)&cmd_macsec_sc_sc,
13413                 (void *)&cmd_macsec_sc_tx_rx,
13414                 (void *)&cmd_macsec_sc_port_id,
13415                 (void *)&cmd_macsec_sc_mac,
13416                 (void *)&cmd_macsec_sc_pi,
13417                 NULL,
13418         },
13419 };
13420
13421 /* Common result structure for MACsec secure connection configure */
13422 struct cmd_macsec_sa_result {
13423         cmdline_fixed_string_t set;
13424         cmdline_fixed_string_t macsec;
13425         cmdline_fixed_string_t sa;
13426         cmdline_fixed_string_t tx_rx;
13427         portid_t port_id;
13428         uint8_t idx;
13429         uint8_t an;
13430         uint32_t pn;
13431         cmdline_fixed_string_t key;
13432 };
13433
13434 /* Common CLI fields for MACsec secure connection configure */
13435 cmdline_parse_token_string_t cmd_macsec_sa_set =
13436         TOKEN_STRING_INITIALIZER
13437                 (struct cmd_macsec_sa_result,
13438                  set, "set");
13439 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13440         TOKEN_STRING_INITIALIZER
13441                 (struct cmd_macsec_sa_result,
13442                  macsec, "macsec");
13443 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13444         TOKEN_STRING_INITIALIZER
13445                 (struct cmd_macsec_sa_result,
13446                  sa, "sa");
13447 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13448         TOKEN_STRING_INITIALIZER
13449                 (struct cmd_macsec_sa_result,
13450                  tx_rx, "tx#rx");
13451 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13452         TOKEN_NUM_INITIALIZER
13453                 (struct cmd_macsec_sa_result,
13454                  port_id, UINT16);
13455 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13456         TOKEN_NUM_INITIALIZER
13457                 (struct cmd_macsec_sa_result,
13458                  idx, UINT8);
13459 cmdline_parse_token_num_t cmd_macsec_sa_an =
13460         TOKEN_NUM_INITIALIZER
13461                 (struct cmd_macsec_sa_result,
13462                  an, UINT8);
13463 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13464         TOKEN_NUM_INITIALIZER
13465                 (struct cmd_macsec_sa_result,
13466                  pn, UINT32);
13467 cmdline_parse_token_string_t cmd_macsec_sa_key =
13468         TOKEN_STRING_INITIALIZER
13469                 (struct cmd_macsec_sa_result,
13470                  key, NULL);
13471
13472 static void
13473 cmd_set_macsec_sa_parsed(
13474         void *parsed_result,
13475         __rte_unused struct cmdline *cl,
13476         __rte_unused void *data)
13477 {
13478         struct cmd_macsec_sa_result *res = parsed_result;
13479         int ret = -ENOTSUP;
13480         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13481         uint8_t key[16] = { 0 };
13482         uint8_t xdgt0;
13483         uint8_t xdgt1;
13484         int key_len;
13485         int i;
13486
13487         key_len = strlen(res->key) / 2;
13488         if (key_len > 16)
13489                 key_len = 16;
13490
13491         for (i = 0; i < key_len; i++) {
13492                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13493                 if (xdgt0 == 0xFF)
13494                         return;
13495                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13496                 if (xdgt1 == 0xFF)
13497                         return;
13498                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13499         }
13500
13501 #ifdef RTE_NET_IXGBE
13502         ret = is_tx ?
13503                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13504                         res->idx, res->an, res->pn, key) :
13505                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13506                         res->idx, res->an, res->pn, key);
13507 #endif
13508         RTE_SET_USED(is_tx);
13509         RTE_SET_USED(key);
13510
13511         switch (ret) {
13512         case 0:
13513                 break;
13514         case -EINVAL:
13515                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13516                 break;
13517         case -ENODEV:
13518                 printf("invalid port_id %d\n", res->port_id);
13519                 break;
13520         case -ENOTSUP:
13521                 printf("not supported on port %d\n", res->port_id);
13522                 break;
13523         default:
13524                 printf("programming error: (%s)\n", strerror(-ret));
13525         }
13526 }
13527
13528 cmdline_parse_inst_t cmd_set_macsec_sa = {
13529         .f = cmd_set_macsec_sa_parsed,
13530         .data = NULL,
13531         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13532         .tokens = {
13533                 (void *)&cmd_macsec_sa_set,
13534                 (void *)&cmd_macsec_sa_macsec,
13535                 (void *)&cmd_macsec_sa_sa,
13536                 (void *)&cmd_macsec_sa_tx_rx,
13537                 (void *)&cmd_macsec_sa_port_id,
13538                 (void *)&cmd_macsec_sa_idx,
13539                 (void *)&cmd_macsec_sa_an,
13540                 (void *)&cmd_macsec_sa_pn,
13541                 (void *)&cmd_macsec_sa_key,
13542                 NULL,
13543         },
13544 };
13545
13546 /* VF unicast promiscuous mode configuration */
13547
13548 /* Common result structure for VF unicast promiscuous mode */
13549 struct cmd_vf_promisc_result {
13550         cmdline_fixed_string_t set;
13551         cmdline_fixed_string_t vf;
13552         cmdline_fixed_string_t promisc;
13553         portid_t port_id;
13554         uint32_t vf_id;
13555         cmdline_fixed_string_t on_off;
13556 };
13557
13558 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13559 cmdline_parse_token_string_t cmd_vf_promisc_set =
13560         TOKEN_STRING_INITIALIZER
13561                 (struct cmd_vf_promisc_result,
13562                  set, "set");
13563 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13564         TOKEN_STRING_INITIALIZER
13565                 (struct cmd_vf_promisc_result,
13566                  vf, "vf");
13567 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13568         TOKEN_STRING_INITIALIZER
13569                 (struct cmd_vf_promisc_result,
13570                  promisc, "promisc");
13571 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13572         TOKEN_NUM_INITIALIZER
13573                 (struct cmd_vf_promisc_result,
13574                  port_id, UINT16);
13575 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13576         TOKEN_NUM_INITIALIZER
13577                 (struct cmd_vf_promisc_result,
13578                  vf_id, UINT32);
13579 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13580         TOKEN_STRING_INITIALIZER
13581                 (struct cmd_vf_promisc_result,
13582                  on_off, "on#off");
13583
13584 static void
13585 cmd_set_vf_promisc_parsed(
13586         void *parsed_result,
13587         __rte_unused struct cmdline *cl,
13588         __rte_unused void *data)
13589 {
13590         struct cmd_vf_promisc_result *res = parsed_result;
13591         int ret = -ENOTSUP;
13592
13593         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13594
13595         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13596                 return;
13597
13598 #ifdef RTE_NET_I40E
13599         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13600                                                   res->vf_id, is_on);
13601 #endif
13602
13603         switch (ret) {
13604         case 0:
13605                 break;
13606         case -EINVAL:
13607                 printf("invalid vf_id %d\n", res->vf_id);
13608                 break;
13609         case -ENODEV:
13610                 printf("invalid port_id %d\n", res->port_id);
13611                 break;
13612         case -ENOTSUP:
13613                 printf("function not implemented\n");
13614                 break;
13615         default:
13616                 printf("programming error: (%s)\n", strerror(-ret));
13617         }
13618 }
13619
13620 cmdline_parse_inst_t cmd_set_vf_promisc = {
13621         .f = cmd_set_vf_promisc_parsed,
13622         .data = NULL,
13623         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13624                 "Set unicast promiscuous mode for a VF from the PF",
13625         .tokens = {
13626                 (void *)&cmd_vf_promisc_set,
13627                 (void *)&cmd_vf_promisc_vf,
13628                 (void *)&cmd_vf_promisc_promisc,
13629                 (void *)&cmd_vf_promisc_port_id,
13630                 (void *)&cmd_vf_promisc_vf_id,
13631                 (void *)&cmd_vf_promisc_on_off,
13632                 NULL,
13633         },
13634 };
13635
13636 /* VF multicast promiscuous mode configuration */
13637
13638 /* Common result structure for VF multicast promiscuous mode */
13639 struct cmd_vf_allmulti_result {
13640         cmdline_fixed_string_t set;
13641         cmdline_fixed_string_t vf;
13642         cmdline_fixed_string_t allmulti;
13643         portid_t port_id;
13644         uint32_t vf_id;
13645         cmdline_fixed_string_t on_off;
13646 };
13647
13648 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13649 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13650         TOKEN_STRING_INITIALIZER
13651                 (struct cmd_vf_allmulti_result,
13652                  set, "set");
13653 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13654         TOKEN_STRING_INITIALIZER
13655                 (struct cmd_vf_allmulti_result,
13656                  vf, "vf");
13657 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13658         TOKEN_STRING_INITIALIZER
13659                 (struct cmd_vf_allmulti_result,
13660                  allmulti, "allmulti");
13661 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13662         TOKEN_NUM_INITIALIZER
13663                 (struct cmd_vf_allmulti_result,
13664                  port_id, UINT16);
13665 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13666         TOKEN_NUM_INITIALIZER
13667                 (struct cmd_vf_allmulti_result,
13668                  vf_id, UINT32);
13669 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13670         TOKEN_STRING_INITIALIZER
13671                 (struct cmd_vf_allmulti_result,
13672                  on_off, "on#off");
13673
13674 static void
13675 cmd_set_vf_allmulti_parsed(
13676         void *parsed_result,
13677         __rte_unused struct cmdline *cl,
13678         __rte_unused void *data)
13679 {
13680         struct cmd_vf_allmulti_result *res = parsed_result;
13681         int ret = -ENOTSUP;
13682
13683         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13684
13685         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13686                 return;
13687
13688 #ifdef RTE_NET_I40E
13689         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13690                                                     res->vf_id, is_on);
13691 #endif
13692
13693         switch (ret) {
13694         case 0:
13695                 break;
13696         case -EINVAL:
13697                 printf("invalid vf_id %d\n", res->vf_id);
13698                 break;
13699         case -ENODEV:
13700                 printf("invalid port_id %d\n", res->port_id);
13701                 break;
13702         case -ENOTSUP:
13703                 printf("function not implemented\n");
13704                 break;
13705         default:
13706                 printf("programming error: (%s)\n", strerror(-ret));
13707         }
13708 }
13709
13710 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13711         .f = cmd_set_vf_allmulti_parsed,
13712         .data = NULL,
13713         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13714                 "Set multicast promiscuous mode for a VF from the PF",
13715         .tokens = {
13716                 (void *)&cmd_vf_allmulti_set,
13717                 (void *)&cmd_vf_allmulti_vf,
13718                 (void *)&cmd_vf_allmulti_allmulti,
13719                 (void *)&cmd_vf_allmulti_port_id,
13720                 (void *)&cmd_vf_allmulti_vf_id,
13721                 (void *)&cmd_vf_allmulti_on_off,
13722                 NULL,
13723         },
13724 };
13725
13726 /* vf broadcast mode configuration */
13727
13728 /* Common result structure for vf broadcast */
13729 struct cmd_set_vf_broadcast_result {
13730         cmdline_fixed_string_t set;
13731         cmdline_fixed_string_t vf;
13732         cmdline_fixed_string_t broadcast;
13733         portid_t port_id;
13734         uint16_t vf_id;
13735         cmdline_fixed_string_t on_off;
13736 };
13737
13738 /* Common CLI fields for vf broadcast enable disable */
13739 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13740         TOKEN_STRING_INITIALIZER
13741                 (struct cmd_set_vf_broadcast_result,
13742                  set, "set");
13743 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13744         TOKEN_STRING_INITIALIZER
13745                 (struct cmd_set_vf_broadcast_result,
13746                  vf, "vf");
13747 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13748         TOKEN_STRING_INITIALIZER
13749                 (struct cmd_set_vf_broadcast_result,
13750                  broadcast, "broadcast");
13751 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13752         TOKEN_NUM_INITIALIZER
13753                 (struct cmd_set_vf_broadcast_result,
13754                  port_id, UINT16);
13755 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13756         TOKEN_NUM_INITIALIZER
13757                 (struct cmd_set_vf_broadcast_result,
13758                  vf_id, UINT16);
13759 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13760         TOKEN_STRING_INITIALIZER
13761                 (struct cmd_set_vf_broadcast_result,
13762                  on_off, "on#off");
13763
13764 static void
13765 cmd_set_vf_broadcast_parsed(
13766         void *parsed_result,
13767         __rte_unused struct cmdline *cl,
13768         __rte_unused void *data)
13769 {
13770         struct cmd_set_vf_broadcast_result *res = parsed_result;
13771         int ret = -ENOTSUP;
13772
13773         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13774
13775         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13776                 return;
13777
13778 #ifdef RTE_NET_I40E
13779         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13780                                             res->vf_id, is_on);
13781 #endif
13782
13783         switch (ret) {
13784         case 0:
13785                 break;
13786         case -EINVAL:
13787                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13788                 break;
13789         case -ENODEV:
13790                 printf("invalid port_id %d\n", res->port_id);
13791                 break;
13792         case -ENOTSUP:
13793                 printf("function not implemented\n");
13794                 break;
13795         default:
13796                 printf("programming error: (%s)\n", strerror(-ret));
13797         }
13798 }
13799
13800 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13801         .f = cmd_set_vf_broadcast_parsed,
13802         .data = NULL,
13803         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13804         .tokens = {
13805                 (void *)&cmd_set_vf_broadcast_set,
13806                 (void *)&cmd_set_vf_broadcast_vf,
13807                 (void *)&cmd_set_vf_broadcast_broadcast,
13808                 (void *)&cmd_set_vf_broadcast_port_id,
13809                 (void *)&cmd_set_vf_broadcast_vf_id,
13810                 (void *)&cmd_set_vf_broadcast_on_off,
13811                 NULL,
13812         },
13813 };
13814
13815 /* vf vlan tag configuration */
13816
13817 /* Common result structure for vf vlan tag */
13818 struct cmd_set_vf_vlan_tag_result {
13819         cmdline_fixed_string_t set;
13820         cmdline_fixed_string_t vf;
13821         cmdline_fixed_string_t vlan;
13822         cmdline_fixed_string_t tag;
13823         portid_t port_id;
13824         uint16_t vf_id;
13825         cmdline_fixed_string_t on_off;
13826 };
13827
13828 /* Common CLI fields for vf vlan tag enable disable */
13829 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13830         TOKEN_STRING_INITIALIZER
13831                 (struct cmd_set_vf_vlan_tag_result,
13832                  set, "set");
13833 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13834         TOKEN_STRING_INITIALIZER
13835                 (struct cmd_set_vf_vlan_tag_result,
13836                  vf, "vf");
13837 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13838         TOKEN_STRING_INITIALIZER
13839                 (struct cmd_set_vf_vlan_tag_result,
13840                  vlan, "vlan");
13841 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13842         TOKEN_STRING_INITIALIZER
13843                 (struct cmd_set_vf_vlan_tag_result,
13844                  tag, "tag");
13845 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13846         TOKEN_NUM_INITIALIZER
13847                 (struct cmd_set_vf_vlan_tag_result,
13848                  port_id, UINT16);
13849 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13850         TOKEN_NUM_INITIALIZER
13851                 (struct cmd_set_vf_vlan_tag_result,
13852                  vf_id, UINT16);
13853 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13854         TOKEN_STRING_INITIALIZER
13855                 (struct cmd_set_vf_vlan_tag_result,
13856                  on_off, "on#off");
13857
13858 static void
13859 cmd_set_vf_vlan_tag_parsed(
13860         void *parsed_result,
13861         __rte_unused struct cmdline *cl,
13862         __rte_unused void *data)
13863 {
13864         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13865         int ret = -ENOTSUP;
13866
13867         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13868
13869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13870                 return;
13871
13872 #ifdef RTE_NET_I40E
13873         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13874                                            res->vf_id, is_on);
13875 #endif
13876
13877         switch (ret) {
13878         case 0:
13879                 break;
13880         case -EINVAL:
13881                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13882                 break;
13883         case -ENODEV:
13884                 printf("invalid port_id %d\n", res->port_id);
13885                 break;
13886         case -ENOTSUP:
13887                 printf("function not implemented\n");
13888                 break;
13889         default:
13890                 printf("programming error: (%s)\n", strerror(-ret));
13891         }
13892 }
13893
13894 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13895         .f = cmd_set_vf_vlan_tag_parsed,
13896         .data = NULL,
13897         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13898         .tokens = {
13899                 (void *)&cmd_set_vf_vlan_tag_set,
13900                 (void *)&cmd_set_vf_vlan_tag_vf,
13901                 (void *)&cmd_set_vf_vlan_tag_vlan,
13902                 (void *)&cmd_set_vf_vlan_tag_tag,
13903                 (void *)&cmd_set_vf_vlan_tag_port_id,
13904                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13905                 (void *)&cmd_set_vf_vlan_tag_on_off,
13906                 NULL,
13907         },
13908 };
13909
13910 /* Common definition of VF and TC TX bandwidth configuration */
13911 struct cmd_vf_tc_bw_result {
13912         cmdline_fixed_string_t set;
13913         cmdline_fixed_string_t vf;
13914         cmdline_fixed_string_t tc;
13915         cmdline_fixed_string_t tx;
13916         cmdline_fixed_string_t min_bw;
13917         cmdline_fixed_string_t max_bw;
13918         cmdline_fixed_string_t strict_link_prio;
13919         portid_t port_id;
13920         uint16_t vf_id;
13921         uint8_t tc_no;
13922         uint32_t bw;
13923         cmdline_fixed_string_t bw_list;
13924         uint8_t tc_map;
13925 };
13926
13927 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13928         TOKEN_STRING_INITIALIZER
13929                 (struct cmd_vf_tc_bw_result,
13930                  set, "set");
13931 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13932         TOKEN_STRING_INITIALIZER
13933                 (struct cmd_vf_tc_bw_result,
13934                  vf, "vf");
13935 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13936         TOKEN_STRING_INITIALIZER
13937                 (struct cmd_vf_tc_bw_result,
13938                  tc, "tc");
13939 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13940         TOKEN_STRING_INITIALIZER
13941                 (struct cmd_vf_tc_bw_result,
13942                  tx, "tx");
13943 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13944         TOKEN_STRING_INITIALIZER
13945                 (struct cmd_vf_tc_bw_result,
13946                  strict_link_prio, "strict-link-priority");
13947 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13948         TOKEN_STRING_INITIALIZER
13949                 (struct cmd_vf_tc_bw_result,
13950                  min_bw, "min-bandwidth");
13951 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13952         TOKEN_STRING_INITIALIZER
13953                 (struct cmd_vf_tc_bw_result,
13954                  max_bw, "max-bandwidth");
13955 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13956         TOKEN_NUM_INITIALIZER
13957                 (struct cmd_vf_tc_bw_result,
13958                  port_id, UINT16);
13959 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13960         TOKEN_NUM_INITIALIZER
13961                 (struct cmd_vf_tc_bw_result,
13962                  vf_id, UINT16);
13963 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13964         TOKEN_NUM_INITIALIZER
13965                 (struct cmd_vf_tc_bw_result,
13966                  tc_no, UINT8);
13967 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13968         TOKEN_NUM_INITIALIZER
13969                 (struct cmd_vf_tc_bw_result,
13970                  bw, UINT32);
13971 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13972         TOKEN_STRING_INITIALIZER
13973                 (struct cmd_vf_tc_bw_result,
13974                  bw_list, NULL);
13975 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13976         TOKEN_NUM_INITIALIZER
13977                 (struct cmd_vf_tc_bw_result,
13978                  tc_map, UINT8);
13979
13980 /* VF max bandwidth setting */
13981 static void
13982 cmd_vf_max_bw_parsed(
13983         void *parsed_result,
13984         __rte_unused struct cmdline *cl,
13985         __rte_unused void *data)
13986 {
13987         struct cmd_vf_tc_bw_result *res = parsed_result;
13988         int ret = -ENOTSUP;
13989
13990         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13991                 return;
13992
13993 #ifdef RTE_NET_I40E
13994         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13995                                          res->vf_id, res->bw);
13996 #endif
13997
13998         switch (ret) {
13999         case 0:
14000                 break;
14001         case -EINVAL:
14002                 printf("invalid vf_id %d or bandwidth %d\n",
14003                        res->vf_id, res->bw);
14004                 break;
14005         case -ENODEV:
14006                 printf("invalid port_id %d\n", res->port_id);
14007                 break;
14008         case -ENOTSUP:
14009                 printf("function not implemented\n");
14010                 break;
14011         default:
14012                 printf("programming error: (%s)\n", strerror(-ret));
14013         }
14014 }
14015
14016 cmdline_parse_inst_t cmd_vf_max_bw = {
14017         .f = cmd_vf_max_bw_parsed,
14018         .data = NULL,
14019         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
14020         .tokens = {
14021                 (void *)&cmd_vf_tc_bw_set,
14022                 (void *)&cmd_vf_tc_bw_vf,
14023                 (void *)&cmd_vf_tc_bw_tx,
14024                 (void *)&cmd_vf_tc_bw_max_bw,
14025                 (void *)&cmd_vf_tc_bw_port_id,
14026                 (void *)&cmd_vf_tc_bw_vf_id,
14027                 (void *)&cmd_vf_tc_bw_bw,
14028                 NULL,
14029         },
14030 };
14031
14032 static int
14033 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
14034                            uint8_t *tc_num,
14035                            char *str)
14036 {
14037         uint32_t size;
14038         const char *p, *p0 = str;
14039         char s[256];
14040         char *end;
14041         char *str_fld[16];
14042         uint16_t i;
14043         int ret;
14044
14045         p = strchr(p0, '(');
14046         if (p == NULL) {
14047                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14048                 return -1;
14049         }
14050         p++;
14051         p0 = strchr(p, ')');
14052         if (p0 == NULL) {
14053                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
14054                 return -1;
14055         }
14056         size = p0 - p;
14057         if (size >= sizeof(s)) {
14058                 printf("The string size exceeds the internal buffer size\n");
14059                 return -1;
14060         }
14061         snprintf(s, sizeof(s), "%.*s", size, p);
14062         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
14063         if (ret <= 0) {
14064                 printf("Failed to get the bandwidth list. ");
14065                 return -1;
14066         }
14067         *tc_num = ret;
14068         for (i = 0; i < ret; i++)
14069                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
14070
14071         return 0;
14072 }
14073
14074 /* TC min bandwidth setting */
14075 static void
14076 cmd_vf_tc_min_bw_parsed(
14077         void *parsed_result,
14078         __rte_unused struct cmdline *cl,
14079         __rte_unused void *data)
14080 {
14081         struct cmd_vf_tc_bw_result *res = parsed_result;
14082         uint8_t tc_num;
14083         uint8_t bw[16];
14084         int ret = -ENOTSUP;
14085
14086         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14087                 return;
14088
14089         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14090         if (ret)
14091                 return;
14092
14093 #ifdef RTE_NET_I40E
14094         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
14095                                               tc_num, bw);
14096 #endif
14097
14098         switch (ret) {
14099         case 0:
14100                 break;
14101         case -EINVAL:
14102                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
14103                 break;
14104         case -ENODEV:
14105                 printf("invalid port_id %d\n", res->port_id);
14106                 break;
14107         case -ENOTSUP:
14108                 printf("function not implemented\n");
14109                 break;
14110         default:
14111                 printf("programming error: (%s)\n", strerror(-ret));
14112         }
14113 }
14114
14115 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
14116         .f = cmd_vf_tc_min_bw_parsed,
14117         .data = NULL,
14118         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
14119                     " <bw1, bw2, ...>",
14120         .tokens = {
14121                 (void *)&cmd_vf_tc_bw_set,
14122                 (void *)&cmd_vf_tc_bw_vf,
14123                 (void *)&cmd_vf_tc_bw_tc,
14124                 (void *)&cmd_vf_tc_bw_tx,
14125                 (void *)&cmd_vf_tc_bw_min_bw,
14126                 (void *)&cmd_vf_tc_bw_port_id,
14127                 (void *)&cmd_vf_tc_bw_vf_id,
14128                 (void *)&cmd_vf_tc_bw_bw_list,
14129                 NULL,
14130         },
14131 };
14132
14133 static void
14134 cmd_tc_min_bw_parsed(
14135         void *parsed_result,
14136         __rte_unused struct cmdline *cl,
14137         __rte_unused void *data)
14138 {
14139         struct cmd_vf_tc_bw_result *res = parsed_result;
14140         struct rte_port *port;
14141         uint8_t tc_num;
14142         uint8_t bw[16];
14143         int ret = -ENOTSUP;
14144
14145         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14146                 return;
14147
14148         port = &ports[res->port_id];
14149         /** Check if the port is not started **/
14150         if (port->port_status != RTE_PORT_STOPPED) {
14151                 printf("Please stop port %d first\n", res->port_id);
14152                 return;
14153         }
14154
14155         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
14156         if (ret)
14157                 return;
14158
14159 #ifdef RTE_NET_IXGBE
14160         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
14161 #endif
14162
14163         switch (ret) {
14164         case 0:
14165                 break;
14166         case -EINVAL:
14167                 printf("invalid bandwidth\n");
14168                 break;
14169         case -ENODEV:
14170                 printf("invalid port_id %d\n", res->port_id);
14171                 break;
14172         case -ENOTSUP:
14173                 printf("function not implemented\n");
14174                 break;
14175         default:
14176                 printf("programming error: (%s)\n", strerror(-ret));
14177         }
14178 }
14179
14180 cmdline_parse_inst_t cmd_tc_min_bw = {
14181         .f = cmd_tc_min_bw_parsed,
14182         .data = NULL,
14183         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
14184         .tokens = {
14185                 (void *)&cmd_vf_tc_bw_set,
14186                 (void *)&cmd_vf_tc_bw_tc,
14187                 (void *)&cmd_vf_tc_bw_tx,
14188                 (void *)&cmd_vf_tc_bw_min_bw,
14189                 (void *)&cmd_vf_tc_bw_port_id,
14190                 (void *)&cmd_vf_tc_bw_bw_list,
14191                 NULL,
14192         },
14193 };
14194
14195 /* TC max bandwidth setting */
14196 static void
14197 cmd_vf_tc_max_bw_parsed(
14198         void *parsed_result,
14199         __rte_unused struct cmdline *cl,
14200         __rte_unused void *data)
14201 {
14202         struct cmd_vf_tc_bw_result *res = parsed_result;
14203         int ret = -ENOTSUP;
14204
14205         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14206                 return;
14207
14208 #ifdef RTE_NET_I40E
14209         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14210                                             res->tc_no, res->bw);
14211 #endif
14212
14213         switch (ret) {
14214         case 0:
14215                 break;
14216         case -EINVAL:
14217                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14218                        res->vf_id, res->tc_no, res->bw);
14219                 break;
14220         case -ENODEV:
14221                 printf("invalid port_id %d\n", res->port_id);
14222                 break;
14223         case -ENOTSUP:
14224                 printf("function not implemented\n");
14225                 break;
14226         default:
14227                 printf("programming error: (%s)\n", strerror(-ret));
14228         }
14229 }
14230
14231 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14232         .f = cmd_vf_tc_max_bw_parsed,
14233         .data = NULL,
14234         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14235                     " <bandwidth>",
14236         .tokens = {
14237                 (void *)&cmd_vf_tc_bw_set,
14238                 (void *)&cmd_vf_tc_bw_vf,
14239                 (void *)&cmd_vf_tc_bw_tc,
14240                 (void *)&cmd_vf_tc_bw_tx,
14241                 (void *)&cmd_vf_tc_bw_max_bw,
14242                 (void *)&cmd_vf_tc_bw_port_id,
14243                 (void *)&cmd_vf_tc_bw_vf_id,
14244                 (void *)&cmd_vf_tc_bw_tc_no,
14245                 (void *)&cmd_vf_tc_bw_bw,
14246                 NULL,
14247         },
14248 };
14249
14250 /** Set VXLAN encapsulation details */
14251 struct cmd_set_vxlan_result {
14252         cmdline_fixed_string_t set;
14253         cmdline_fixed_string_t vxlan;
14254         cmdline_fixed_string_t pos_token;
14255         cmdline_fixed_string_t ip_version;
14256         uint32_t vlan_present:1;
14257         uint32_t vni;
14258         uint16_t udp_src;
14259         uint16_t udp_dst;
14260         cmdline_ipaddr_t ip_src;
14261         cmdline_ipaddr_t ip_dst;
14262         uint16_t tci;
14263         uint8_t tos;
14264         uint8_t ttl;
14265         struct rte_ether_addr eth_src;
14266         struct rte_ether_addr eth_dst;
14267 };
14268
14269 cmdline_parse_token_string_t cmd_set_vxlan_set =
14270         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, set, "set");
14271 cmdline_parse_token_string_t cmd_set_vxlan_vxlan =
14272         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan, "vxlan");
14273 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_tos_ttl =
14274         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14275                                  "vxlan-tos-ttl");
14276 cmdline_parse_token_string_t cmd_set_vxlan_vxlan_with_vlan =
14277         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, vxlan,
14278                                  "vxlan-with-vlan");
14279 cmdline_parse_token_string_t cmd_set_vxlan_ip_version =
14280         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14281                                  "ip-version");
14282 cmdline_parse_token_string_t cmd_set_vxlan_ip_version_value =
14283         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, ip_version,
14284                                  "ipv4#ipv6");
14285 cmdline_parse_token_string_t cmd_set_vxlan_vni =
14286         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14287                                  "vni");
14288 cmdline_parse_token_num_t cmd_set_vxlan_vni_value =
14289         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, vni, UINT32);
14290 cmdline_parse_token_string_t cmd_set_vxlan_udp_src =
14291         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14292                                  "udp-src");
14293 cmdline_parse_token_num_t cmd_set_vxlan_udp_src_value =
14294         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_src, UINT16);
14295 cmdline_parse_token_string_t cmd_set_vxlan_udp_dst =
14296         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14297                                  "udp-dst");
14298 cmdline_parse_token_num_t cmd_set_vxlan_udp_dst_value =
14299         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, udp_dst, UINT16);
14300 cmdline_parse_token_string_t cmd_set_vxlan_ip_tos =
14301         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14302                                  "ip-tos");
14303 cmdline_parse_token_num_t cmd_set_vxlan_ip_tos_value =
14304         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tos, UINT8);
14305 cmdline_parse_token_string_t cmd_set_vxlan_ip_ttl =
14306         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14307                                  "ip-ttl");
14308 cmdline_parse_token_num_t cmd_set_vxlan_ip_ttl_value =
14309         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, ttl, UINT8);
14310 cmdline_parse_token_string_t cmd_set_vxlan_ip_src =
14311         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14312                                  "ip-src");
14313 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_src_value =
14314         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_src);
14315 cmdline_parse_token_string_t cmd_set_vxlan_ip_dst =
14316         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14317                                  "ip-dst");
14318 cmdline_parse_token_ipaddr_t cmd_set_vxlan_ip_dst_value =
14319         TOKEN_IPADDR_INITIALIZER(struct cmd_set_vxlan_result, ip_dst);
14320 cmdline_parse_token_string_t cmd_set_vxlan_vlan =
14321         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14322                                  "vlan-tci");
14323 cmdline_parse_token_num_t cmd_set_vxlan_vlan_value =
14324         TOKEN_NUM_INITIALIZER(struct cmd_set_vxlan_result, tci, UINT16);
14325 cmdline_parse_token_string_t cmd_set_vxlan_eth_src =
14326         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14327                                  "eth-src");
14328 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_src_value =
14329         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_src);
14330 cmdline_parse_token_string_t cmd_set_vxlan_eth_dst =
14331         TOKEN_STRING_INITIALIZER(struct cmd_set_vxlan_result, pos_token,
14332                                  "eth-dst");
14333 cmdline_parse_token_etheraddr_t cmd_set_vxlan_eth_dst_value =
14334         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vxlan_result, eth_dst);
14335
14336 static void cmd_set_vxlan_parsed(void *parsed_result,
14337         __rte_unused struct cmdline *cl,
14338         __rte_unused void *data)
14339 {
14340         struct cmd_set_vxlan_result *res = parsed_result;
14341         union {
14342                 uint32_t vxlan_id;
14343                 uint8_t vni[4];
14344         } id = {
14345                 .vxlan_id = rte_cpu_to_be_32(res->vni) & RTE_BE32(0x00ffffff),
14346         };
14347
14348         vxlan_encap_conf.select_tos_ttl = 0;
14349         if (strcmp(res->vxlan, "vxlan") == 0)
14350                 vxlan_encap_conf.select_vlan = 0;
14351         else if (strcmp(res->vxlan, "vxlan-with-vlan") == 0)
14352                 vxlan_encap_conf.select_vlan = 1;
14353         else if (strcmp(res->vxlan, "vxlan-tos-ttl") == 0) {
14354                 vxlan_encap_conf.select_vlan = 0;
14355                 vxlan_encap_conf.select_tos_ttl = 1;
14356         }
14357         if (strcmp(res->ip_version, "ipv4") == 0)
14358                 vxlan_encap_conf.select_ipv4 = 1;
14359         else if (strcmp(res->ip_version, "ipv6") == 0)
14360                 vxlan_encap_conf.select_ipv4 = 0;
14361         else
14362                 return;
14363         rte_memcpy(vxlan_encap_conf.vni, &id.vni[1], 3);
14364         vxlan_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
14365         vxlan_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
14366         vxlan_encap_conf.ip_tos = res->tos;
14367         vxlan_encap_conf.ip_ttl = res->ttl;
14368         if (vxlan_encap_conf.select_ipv4) {
14369                 IPV4_ADDR_TO_UINT(res->ip_src, vxlan_encap_conf.ipv4_src);
14370                 IPV4_ADDR_TO_UINT(res->ip_dst, vxlan_encap_conf.ipv4_dst);
14371         } else {
14372                 IPV6_ADDR_TO_ARRAY(res->ip_src, vxlan_encap_conf.ipv6_src);
14373                 IPV6_ADDR_TO_ARRAY(res->ip_dst, vxlan_encap_conf.ipv6_dst);
14374         }
14375         if (vxlan_encap_conf.select_vlan)
14376                 vxlan_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14377         rte_memcpy(vxlan_encap_conf.eth_src, res->eth_src.addr_bytes,
14378                    RTE_ETHER_ADDR_LEN);
14379         rte_memcpy(vxlan_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14380                    RTE_ETHER_ADDR_LEN);
14381 }
14382
14383 cmdline_parse_inst_t cmd_set_vxlan = {
14384         .f = cmd_set_vxlan_parsed,
14385         .data = NULL,
14386         .help_str = "set vxlan ip-version ipv4|ipv6 vni <vni> udp-src"
14387                 " <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst <ip-dst>"
14388                 " eth-src <eth-src> eth-dst <eth-dst>",
14389         .tokens = {
14390                 (void *)&cmd_set_vxlan_set,
14391                 (void *)&cmd_set_vxlan_vxlan,
14392                 (void *)&cmd_set_vxlan_ip_version,
14393                 (void *)&cmd_set_vxlan_ip_version_value,
14394                 (void *)&cmd_set_vxlan_vni,
14395                 (void *)&cmd_set_vxlan_vni_value,
14396                 (void *)&cmd_set_vxlan_udp_src,
14397                 (void *)&cmd_set_vxlan_udp_src_value,
14398                 (void *)&cmd_set_vxlan_udp_dst,
14399                 (void *)&cmd_set_vxlan_udp_dst_value,
14400                 (void *)&cmd_set_vxlan_ip_src,
14401                 (void *)&cmd_set_vxlan_ip_src_value,
14402                 (void *)&cmd_set_vxlan_ip_dst,
14403                 (void *)&cmd_set_vxlan_ip_dst_value,
14404                 (void *)&cmd_set_vxlan_eth_src,
14405                 (void *)&cmd_set_vxlan_eth_src_value,
14406                 (void *)&cmd_set_vxlan_eth_dst,
14407                 (void *)&cmd_set_vxlan_eth_dst_value,
14408                 NULL,
14409         },
14410 };
14411
14412 cmdline_parse_inst_t cmd_set_vxlan_tos_ttl = {
14413         .f = cmd_set_vxlan_parsed,
14414         .data = NULL,
14415         .help_str = "set vxlan-tos-ttl ip-version ipv4|ipv6 vni <vni> udp-src"
14416                 " <udp-src> udp-dst <udp-dst> ip-tos <ip-tos> ip-ttl <ip-ttl>"
14417                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14418                 " eth-dst <eth-dst>",
14419         .tokens = {
14420                 (void *)&cmd_set_vxlan_set,
14421                 (void *)&cmd_set_vxlan_vxlan_tos_ttl,
14422                 (void *)&cmd_set_vxlan_ip_version,
14423                 (void *)&cmd_set_vxlan_ip_version_value,
14424                 (void *)&cmd_set_vxlan_vni,
14425                 (void *)&cmd_set_vxlan_vni_value,
14426                 (void *)&cmd_set_vxlan_udp_src,
14427                 (void *)&cmd_set_vxlan_udp_src_value,
14428                 (void *)&cmd_set_vxlan_udp_dst,
14429                 (void *)&cmd_set_vxlan_udp_dst_value,
14430                 (void *)&cmd_set_vxlan_ip_tos,
14431                 (void *)&cmd_set_vxlan_ip_tos_value,
14432                 (void *)&cmd_set_vxlan_ip_ttl,
14433                 (void *)&cmd_set_vxlan_ip_ttl_value,
14434                 (void *)&cmd_set_vxlan_ip_src,
14435                 (void *)&cmd_set_vxlan_ip_src_value,
14436                 (void *)&cmd_set_vxlan_ip_dst,
14437                 (void *)&cmd_set_vxlan_ip_dst_value,
14438                 (void *)&cmd_set_vxlan_eth_src,
14439                 (void *)&cmd_set_vxlan_eth_src_value,
14440                 (void *)&cmd_set_vxlan_eth_dst,
14441                 (void *)&cmd_set_vxlan_eth_dst_value,
14442                 NULL,
14443         },
14444 };
14445
14446 cmdline_parse_inst_t cmd_set_vxlan_with_vlan = {
14447         .f = cmd_set_vxlan_parsed,
14448         .data = NULL,
14449         .help_str = "set vxlan-with-vlan ip-version ipv4|ipv6 vni <vni>"
14450                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src> ip-dst"
14451                 " <ip-dst> vlan-tci <vlan-tci> eth-src <eth-src> eth-dst"
14452                 " <eth-dst>",
14453         .tokens = {
14454                 (void *)&cmd_set_vxlan_set,
14455                 (void *)&cmd_set_vxlan_vxlan_with_vlan,
14456                 (void *)&cmd_set_vxlan_ip_version,
14457                 (void *)&cmd_set_vxlan_ip_version_value,
14458                 (void *)&cmd_set_vxlan_vni,
14459                 (void *)&cmd_set_vxlan_vni_value,
14460                 (void *)&cmd_set_vxlan_udp_src,
14461                 (void *)&cmd_set_vxlan_udp_src_value,
14462                 (void *)&cmd_set_vxlan_udp_dst,
14463                 (void *)&cmd_set_vxlan_udp_dst_value,
14464                 (void *)&cmd_set_vxlan_ip_src,
14465                 (void *)&cmd_set_vxlan_ip_src_value,
14466                 (void *)&cmd_set_vxlan_ip_dst,
14467                 (void *)&cmd_set_vxlan_ip_dst_value,
14468                 (void *)&cmd_set_vxlan_vlan,
14469                 (void *)&cmd_set_vxlan_vlan_value,
14470                 (void *)&cmd_set_vxlan_eth_src,
14471                 (void *)&cmd_set_vxlan_eth_src_value,
14472                 (void *)&cmd_set_vxlan_eth_dst,
14473                 (void *)&cmd_set_vxlan_eth_dst_value,
14474                 NULL,
14475         },
14476 };
14477
14478 /** Set NVGRE encapsulation details */
14479 struct cmd_set_nvgre_result {
14480         cmdline_fixed_string_t set;
14481         cmdline_fixed_string_t nvgre;
14482         cmdline_fixed_string_t pos_token;
14483         cmdline_fixed_string_t ip_version;
14484         uint32_t tni;
14485         cmdline_ipaddr_t ip_src;
14486         cmdline_ipaddr_t ip_dst;
14487         uint16_t tci;
14488         struct rte_ether_addr eth_src;
14489         struct rte_ether_addr eth_dst;
14490 };
14491
14492 cmdline_parse_token_string_t cmd_set_nvgre_set =
14493         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, set, "set");
14494 cmdline_parse_token_string_t cmd_set_nvgre_nvgre =
14495         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre, "nvgre");
14496 cmdline_parse_token_string_t cmd_set_nvgre_nvgre_with_vlan =
14497         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, nvgre,
14498                                  "nvgre-with-vlan");
14499 cmdline_parse_token_string_t cmd_set_nvgre_ip_version =
14500         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14501                                  "ip-version");
14502 cmdline_parse_token_string_t cmd_set_nvgre_ip_version_value =
14503         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, ip_version,
14504                                  "ipv4#ipv6");
14505 cmdline_parse_token_string_t cmd_set_nvgre_tni =
14506         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14507                                  "tni");
14508 cmdline_parse_token_num_t cmd_set_nvgre_tni_value =
14509         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tni, UINT32);
14510 cmdline_parse_token_string_t cmd_set_nvgre_ip_src =
14511         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14512                                  "ip-src");
14513 cmdline_parse_token_num_t cmd_set_nvgre_ip_src_value =
14514         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_src);
14515 cmdline_parse_token_string_t cmd_set_nvgre_ip_dst =
14516         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14517                                  "ip-dst");
14518 cmdline_parse_token_ipaddr_t cmd_set_nvgre_ip_dst_value =
14519         TOKEN_IPADDR_INITIALIZER(struct cmd_set_nvgre_result, ip_dst);
14520 cmdline_parse_token_string_t cmd_set_nvgre_vlan =
14521         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14522                                  "vlan-tci");
14523 cmdline_parse_token_num_t cmd_set_nvgre_vlan_value =
14524         TOKEN_NUM_INITIALIZER(struct cmd_set_nvgre_result, tci, UINT16);
14525 cmdline_parse_token_string_t cmd_set_nvgre_eth_src =
14526         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14527                                  "eth-src");
14528 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_src_value =
14529         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_src);
14530 cmdline_parse_token_string_t cmd_set_nvgre_eth_dst =
14531         TOKEN_STRING_INITIALIZER(struct cmd_set_nvgre_result, pos_token,
14532                                  "eth-dst");
14533 cmdline_parse_token_etheraddr_t cmd_set_nvgre_eth_dst_value =
14534         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_nvgre_result, eth_dst);
14535
14536 static void cmd_set_nvgre_parsed(void *parsed_result,
14537         __rte_unused struct cmdline *cl,
14538         __rte_unused void *data)
14539 {
14540         struct cmd_set_nvgre_result *res = parsed_result;
14541         union {
14542                 uint32_t nvgre_tni;
14543                 uint8_t tni[4];
14544         } id = {
14545                 .nvgre_tni = rte_cpu_to_be_32(res->tni) & RTE_BE32(0x00ffffff),
14546         };
14547
14548         if (strcmp(res->nvgre, "nvgre") == 0)
14549                 nvgre_encap_conf.select_vlan = 0;
14550         else if (strcmp(res->nvgre, "nvgre-with-vlan") == 0)
14551                 nvgre_encap_conf.select_vlan = 1;
14552         if (strcmp(res->ip_version, "ipv4") == 0)
14553                 nvgre_encap_conf.select_ipv4 = 1;
14554         else if (strcmp(res->ip_version, "ipv6") == 0)
14555                 nvgre_encap_conf.select_ipv4 = 0;
14556         else
14557                 return;
14558         rte_memcpy(nvgre_encap_conf.tni, &id.tni[1], 3);
14559         if (nvgre_encap_conf.select_ipv4) {
14560                 IPV4_ADDR_TO_UINT(res->ip_src, nvgre_encap_conf.ipv4_src);
14561                 IPV4_ADDR_TO_UINT(res->ip_dst, nvgre_encap_conf.ipv4_dst);
14562         } else {
14563                 IPV6_ADDR_TO_ARRAY(res->ip_src, nvgre_encap_conf.ipv6_src);
14564                 IPV6_ADDR_TO_ARRAY(res->ip_dst, nvgre_encap_conf.ipv6_dst);
14565         }
14566         if (nvgre_encap_conf.select_vlan)
14567                 nvgre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14568         rte_memcpy(nvgre_encap_conf.eth_src, res->eth_src.addr_bytes,
14569                    RTE_ETHER_ADDR_LEN);
14570         rte_memcpy(nvgre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14571                    RTE_ETHER_ADDR_LEN);
14572 }
14573
14574 cmdline_parse_inst_t cmd_set_nvgre = {
14575         .f = cmd_set_nvgre_parsed,
14576         .data = NULL,
14577         .help_str = "set nvgre ip-version <ipv4|ipv6> tni <tni> ip-src"
14578                 " <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14579                 " eth-dst <eth-dst>",
14580         .tokens = {
14581                 (void *)&cmd_set_nvgre_set,
14582                 (void *)&cmd_set_nvgre_nvgre,
14583                 (void *)&cmd_set_nvgre_ip_version,
14584                 (void *)&cmd_set_nvgre_ip_version_value,
14585                 (void *)&cmd_set_nvgre_tni,
14586                 (void *)&cmd_set_nvgre_tni_value,
14587                 (void *)&cmd_set_nvgre_ip_src,
14588                 (void *)&cmd_set_nvgre_ip_src_value,
14589                 (void *)&cmd_set_nvgre_ip_dst,
14590                 (void *)&cmd_set_nvgre_ip_dst_value,
14591                 (void *)&cmd_set_nvgre_eth_src,
14592                 (void *)&cmd_set_nvgre_eth_src_value,
14593                 (void *)&cmd_set_nvgre_eth_dst,
14594                 (void *)&cmd_set_nvgre_eth_dst_value,
14595                 NULL,
14596         },
14597 };
14598
14599 cmdline_parse_inst_t cmd_set_nvgre_with_vlan = {
14600         .f = cmd_set_nvgre_parsed,
14601         .data = NULL,
14602         .help_str = "set nvgre-with-vlan ip-version <ipv4|ipv6> tni <tni>"
14603                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
14604                 " eth-src <eth-src> eth-dst <eth-dst>",
14605         .tokens = {
14606                 (void *)&cmd_set_nvgre_set,
14607                 (void *)&cmd_set_nvgre_nvgre_with_vlan,
14608                 (void *)&cmd_set_nvgre_ip_version,
14609                 (void *)&cmd_set_nvgre_ip_version_value,
14610                 (void *)&cmd_set_nvgre_tni,
14611                 (void *)&cmd_set_nvgre_tni_value,
14612                 (void *)&cmd_set_nvgre_ip_src,
14613                 (void *)&cmd_set_nvgre_ip_src_value,
14614                 (void *)&cmd_set_nvgre_ip_dst,
14615                 (void *)&cmd_set_nvgre_ip_dst_value,
14616                 (void *)&cmd_set_nvgre_vlan,
14617                 (void *)&cmd_set_nvgre_vlan_value,
14618                 (void *)&cmd_set_nvgre_eth_src,
14619                 (void *)&cmd_set_nvgre_eth_src_value,
14620                 (void *)&cmd_set_nvgre_eth_dst,
14621                 (void *)&cmd_set_nvgre_eth_dst_value,
14622                 NULL,
14623         },
14624 };
14625
14626 /** Set L2 encapsulation details */
14627 struct cmd_set_l2_encap_result {
14628         cmdline_fixed_string_t set;
14629         cmdline_fixed_string_t l2_encap;
14630         cmdline_fixed_string_t pos_token;
14631         cmdline_fixed_string_t ip_version;
14632         uint32_t vlan_present:1;
14633         uint16_t tci;
14634         struct rte_ether_addr eth_src;
14635         struct rte_ether_addr eth_dst;
14636 };
14637
14638 cmdline_parse_token_string_t cmd_set_l2_encap_set =
14639         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, set, "set");
14640 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap =
14641         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap, "l2_encap");
14642 cmdline_parse_token_string_t cmd_set_l2_encap_l2_encap_with_vlan =
14643         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, l2_encap,
14644                                  "l2_encap-with-vlan");
14645 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version =
14646         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14647                                  "ip-version");
14648 cmdline_parse_token_string_t cmd_set_l2_encap_ip_version_value =
14649         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, ip_version,
14650                                  "ipv4#ipv6");
14651 cmdline_parse_token_string_t cmd_set_l2_encap_vlan =
14652         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14653                                  "vlan-tci");
14654 cmdline_parse_token_num_t cmd_set_l2_encap_vlan_value =
14655         TOKEN_NUM_INITIALIZER(struct cmd_set_l2_encap_result, tci, UINT16);
14656 cmdline_parse_token_string_t cmd_set_l2_encap_eth_src =
14657         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14658                                  "eth-src");
14659 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_src_value =
14660         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_src);
14661 cmdline_parse_token_string_t cmd_set_l2_encap_eth_dst =
14662         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_encap_result, pos_token,
14663                                  "eth-dst");
14664 cmdline_parse_token_etheraddr_t cmd_set_l2_encap_eth_dst_value =
14665         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_l2_encap_result, eth_dst);
14666
14667 static void cmd_set_l2_encap_parsed(void *parsed_result,
14668         __rte_unused struct cmdline *cl,
14669         __rte_unused void *data)
14670 {
14671         struct cmd_set_l2_encap_result *res = parsed_result;
14672
14673         if (strcmp(res->l2_encap, "l2_encap") == 0)
14674                 l2_encap_conf.select_vlan = 0;
14675         else if (strcmp(res->l2_encap, "l2_encap-with-vlan") == 0)
14676                 l2_encap_conf.select_vlan = 1;
14677         if (strcmp(res->ip_version, "ipv4") == 0)
14678                 l2_encap_conf.select_ipv4 = 1;
14679         else if (strcmp(res->ip_version, "ipv6") == 0)
14680                 l2_encap_conf.select_ipv4 = 0;
14681         else
14682                 return;
14683         if (l2_encap_conf.select_vlan)
14684                 l2_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14685         rte_memcpy(l2_encap_conf.eth_src, res->eth_src.addr_bytes,
14686                    RTE_ETHER_ADDR_LEN);
14687         rte_memcpy(l2_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14688                    RTE_ETHER_ADDR_LEN);
14689 }
14690
14691 cmdline_parse_inst_t cmd_set_l2_encap = {
14692         .f = cmd_set_l2_encap_parsed,
14693         .data = NULL,
14694         .help_str = "set l2_encap ip-version ipv4|ipv6"
14695                 " eth-src <eth-src> eth-dst <eth-dst>",
14696         .tokens = {
14697                 (void *)&cmd_set_l2_encap_set,
14698                 (void *)&cmd_set_l2_encap_l2_encap,
14699                 (void *)&cmd_set_l2_encap_ip_version,
14700                 (void *)&cmd_set_l2_encap_ip_version_value,
14701                 (void *)&cmd_set_l2_encap_eth_src,
14702                 (void *)&cmd_set_l2_encap_eth_src_value,
14703                 (void *)&cmd_set_l2_encap_eth_dst,
14704                 (void *)&cmd_set_l2_encap_eth_dst_value,
14705                 NULL,
14706         },
14707 };
14708
14709 cmdline_parse_inst_t cmd_set_l2_encap_with_vlan = {
14710         .f = cmd_set_l2_encap_parsed,
14711         .data = NULL,
14712         .help_str = "set l2_encap-with-vlan ip-version ipv4|ipv6"
14713                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14714         .tokens = {
14715                 (void *)&cmd_set_l2_encap_set,
14716                 (void *)&cmd_set_l2_encap_l2_encap_with_vlan,
14717                 (void *)&cmd_set_l2_encap_ip_version,
14718                 (void *)&cmd_set_l2_encap_ip_version_value,
14719                 (void *)&cmd_set_l2_encap_vlan,
14720                 (void *)&cmd_set_l2_encap_vlan_value,
14721                 (void *)&cmd_set_l2_encap_eth_src,
14722                 (void *)&cmd_set_l2_encap_eth_src_value,
14723                 (void *)&cmd_set_l2_encap_eth_dst,
14724                 (void *)&cmd_set_l2_encap_eth_dst_value,
14725                 NULL,
14726         },
14727 };
14728
14729 /** Set L2 decapsulation details */
14730 struct cmd_set_l2_decap_result {
14731         cmdline_fixed_string_t set;
14732         cmdline_fixed_string_t l2_decap;
14733         cmdline_fixed_string_t pos_token;
14734         uint32_t vlan_present:1;
14735 };
14736
14737 cmdline_parse_token_string_t cmd_set_l2_decap_set =
14738         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, set, "set");
14739 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap =
14740         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14741                                  "l2_decap");
14742 cmdline_parse_token_string_t cmd_set_l2_decap_l2_decap_with_vlan =
14743         TOKEN_STRING_INITIALIZER(struct cmd_set_l2_decap_result, l2_decap,
14744                                  "l2_decap-with-vlan");
14745
14746 static void cmd_set_l2_decap_parsed(void *parsed_result,
14747         __rte_unused struct cmdline *cl,
14748         __rte_unused void *data)
14749 {
14750         struct cmd_set_l2_decap_result *res = parsed_result;
14751
14752         if (strcmp(res->l2_decap, "l2_decap") == 0)
14753                 l2_decap_conf.select_vlan = 0;
14754         else if (strcmp(res->l2_decap, "l2_decap-with-vlan") == 0)
14755                 l2_decap_conf.select_vlan = 1;
14756 }
14757
14758 cmdline_parse_inst_t cmd_set_l2_decap = {
14759         .f = cmd_set_l2_decap_parsed,
14760         .data = NULL,
14761         .help_str = "set l2_decap",
14762         .tokens = {
14763                 (void *)&cmd_set_l2_decap_set,
14764                 (void *)&cmd_set_l2_decap_l2_decap,
14765                 NULL,
14766         },
14767 };
14768
14769 cmdline_parse_inst_t cmd_set_l2_decap_with_vlan = {
14770         .f = cmd_set_l2_decap_parsed,
14771         .data = NULL,
14772         .help_str = "set l2_decap-with-vlan",
14773         .tokens = {
14774                 (void *)&cmd_set_l2_decap_set,
14775                 (void *)&cmd_set_l2_decap_l2_decap_with_vlan,
14776                 NULL,
14777         },
14778 };
14779
14780 /** Set MPLSoGRE encapsulation details */
14781 struct cmd_set_mplsogre_encap_result {
14782         cmdline_fixed_string_t set;
14783         cmdline_fixed_string_t mplsogre;
14784         cmdline_fixed_string_t pos_token;
14785         cmdline_fixed_string_t ip_version;
14786         uint32_t vlan_present:1;
14787         uint32_t label;
14788         cmdline_ipaddr_t ip_src;
14789         cmdline_ipaddr_t ip_dst;
14790         uint16_t tci;
14791         struct rte_ether_addr eth_src;
14792         struct rte_ether_addr eth_dst;
14793 };
14794
14795 cmdline_parse_token_string_t cmd_set_mplsogre_encap_set =
14796         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, set,
14797                                  "set");
14798 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap =
14799         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result, mplsogre,
14800                                  "mplsogre_encap");
14801 cmdline_parse_token_string_t cmd_set_mplsogre_encap_mplsogre_encap_with_vlan =
14802         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14803                                  mplsogre, "mplsogre_encap-with-vlan");
14804 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version =
14805         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14806                                  pos_token, "ip-version");
14807 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_version_value =
14808         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14809                                  ip_version, "ipv4#ipv6");
14810 cmdline_parse_token_string_t cmd_set_mplsogre_encap_label =
14811         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14812                                  pos_token, "label");
14813 cmdline_parse_token_num_t cmd_set_mplsogre_encap_label_value =
14814         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, label,
14815                               UINT32);
14816 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_src =
14817         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14818                                  pos_token, "ip-src");
14819 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_src_value =
14820         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_src);
14821 cmdline_parse_token_string_t cmd_set_mplsogre_encap_ip_dst =
14822         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14823                                  pos_token, "ip-dst");
14824 cmdline_parse_token_ipaddr_t cmd_set_mplsogre_encap_ip_dst_value =
14825         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result, ip_dst);
14826 cmdline_parse_token_string_t cmd_set_mplsogre_encap_vlan =
14827         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14828                                  pos_token, "vlan-tci");
14829 cmdline_parse_token_num_t cmd_set_mplsogre_encap_vlan_value =
14830         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsogre_encap_result, tci,
14831                               UINT16);
14832 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_src =
14833         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14834                                  pos_token, "eth-src");
14835 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_src_value =
14836         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14837                                     eth_src);
14838 cmdline_parse_token_string_t cmd_set_mplsogre_encap_eth_dst =
14839         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14840                                  pos_token, "eth-dst");
14841 cmdline_parse_token_etheraddr_t cmd_set_mplsogre_encap_eth_dst_value =
14842         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsogre_encap_result,
14843                                     eth_dst);
14844
14845 static void cmd_set_mplsogre_encap_parsed(void *parsed_result,
14846         __rte_unused struct cmdline *cl,
14847         __rte_unused void *data)
14848 {
14849         struct cmd_set_mplsogre_encap_result *res = parsed_result;
14850         union {
14851                 uint32_t mplsogre_label;
14852                 uint8_t label[4];
14853         } id = {
14854                 .mplsogre_label = rte_cpu_to_be_32(res->label<<12),
14855         };
14856
14857         if (strcmp(res->mplsogre, "mplsogre_encap") == 0)
14858                 mplsogre_encap_conf.select_vlan = 0;
14859         else if (strcmp(res->mplsogre, "mplsogre_encap-with-vlan") == 0)
14860                 mplsogre_encap_conf.select_vlan = 1;
14861         if (strcmp(res->ip_version, "ipv4") == 0)
14862                 mplsogre_encap_conf.select_ipv4 = 1;
14863         else if (strcmp(res->ip_version, "ipv6") == 0)
14864                 mplsogre_encap_conf.select_ipv4 = 0;
14865         else
14866                 return;
14867         rte_memcpy(mplsogre_encap_conf.label, &id.label, 3);
14868         if (mplsogre_encap_conf.select_ipv4) {
14869                 IPV4_ADDR_TO_UINT(res->ip_src, mplsogre_encap_conf.ipv4_src);
14870                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsogre_encap_conf.ipv4_dst);
14871         } else {
14872                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsogre_encap_conf.ipv6_src);
14873                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsogre_encap_conf.ipv6_dst);
14874         }
14875         if (mplsogre_encap_conf.select_vlan)
14876                 mplsogre_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
14877         rte_memcpy(mplsogre_encap_conf.eth_src, res->eth_src.addr_bytes,
14878                    RTE_ETHER_ADDR_LEN);
14879         rte_memcpy(mplsogre_encap_conf.eth_dst, res->eth_dst.addr_bytes,
14880                    RTE_ETHER_ADDR_LEN);
14881 }
14882
14883 cmdline_parse_inst_t cmd_set_mplsogre_encap = {
14884         .f = cmd_set_mplsogre_encap_parsed,
14885         .data = NULL,
14886         .help_str = "set mplsogre_encap ip-version ipv4|ipv6 label <label>"
14887                 " ip-src <ip-src> ip-dst <ip-dst> eth-src <eth-src>"
14888                 " eth-dst <eth-dst>",
14889         .tokens = {
14890                 (void *)&cmd_set_mplsogre_encap_set,
14891                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap,
14892                 (void *)&cmd_set_mplsogre_encap_ip_version,
14893                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14894                 (void *)&cmd_set_mplsogre_encap_label,
14895                 (void *)&cmd_set_mplsogre_encap_label_value,
14896                 (void *)&cmd_set_mplsogre_encap_ip_src,
14897                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14898                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14899                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14900                 (void *)&cmd_set_mplsogre_encap_eth_src,
14901                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14902                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14903                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14904                 NULL,
14905         },
14906 };
14907
14908 cmdline_parse_inst_t cmd_set_mplsogre_encap_with_vlan = {
14909         .f = cmd_set_mplsogre_encap_parsed,
14910         .data = NULL,
14911         .help_str = "set mplsogre_encap-with-vlan ip-version ipv4|ipv6"
14912                 " label <label> ip-src <ip-src> ip-dst <ip-dst>"
14913                 " vlan-tci <vlan-tci> eth-src <eth-src> eth-dst <eth-dst>",
14914         .tokens = {
14915                 (void *)&cmd_set_mplsogre_encap_set,
14916                 (void *)&cmd_set_mplsogre_encap_mplsogre_encap_with_vlan,
14917                 (void *)&cmd_set_mplsogre_encap_ip_version,
14918                 (void *)&cmd_set_mplsogre_encap_ip_version_value,
14919                 (void *)&cmd_set_mplsogre_encap_label,
14920                 (void *)&cmd_set_mplsogre_encap_label_value,
14921                 (void *)&cmd_set_mplsogre_encap_ip_src,
14922                 (void *)&cmd_set_mplsogre_encap_ip_src_value,
14923                 (void *)&cmd_set_mplsogre_encap_ip_dst,
14924                 (void *)&cmd_set_mplsogre_encap_ip_dst_value,
14925                 (void *)&cmd_set_mplsogre_encap_vlan,
14926                 (void *)&cmd_set_mplsogre_encap_vlan_value,
14927                 (void *)&cmd_set_mplsogre_encap_eth_src,
14928                 (void *)&cmd_set_mplsogre_encap_eth_src_value,
14929                 (void *)&cmd_set_mplsogre_encap_eth_dst,
14930                 (void *)&cmd_set_mplsogre_encap_eth_dst_value,
14931                 NULL,
14932         },
14933 };
14934
14935 /** Set MPLSoGRE decapsulation details */
14936 struct cmd_set_mplsogre_decap_result {
14937         cmdline_fixed_string_t set;
14938         cmdline_fixed_string_t mplsogre;
14939         cmdline_fixed_string_t pos_token;
14940         cmdline_fixed_string_t ip_version;
14941         uint32_t vlan_present:1;
14942 };
14943
14944 cmdline_parse_token_string_t cmd_set_mplsogre_decap_set =
14945         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, set,
14946                                  "set");
14947 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap =
14948         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result, mplsogre,
14949                                  "mplsogre_decap");
14950 cmdline_parse_token_string_t cmd_set_mplsogre_decap_mplsogre_decap_with_vlan =
14951         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14952                                  mplsogre, "mplsogre_decap-with-vlan");
14953 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version =
14954         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14955                                  pos_token, "ip-version");
14956 cmdline_parse_token_string_t cmd_set_mplsogre_decap_ip_version_value =
14957         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsogre_decap_result,
14958                                  ip_version, "ipv4#ipv6");
14959
14960 static void cmd_set_mplsogre_decap_parsed(void *parsed_result,
14961         __rte_unused struct cmdline *cl,
14962         __rte_unused void *data)
14963 {
14964         struct cmd_set_mplsogre_decap_result *res = parsed_result;
14965
14966         if (strcmp(res->mplsogre, "mplsogre_decap") == 0)
14967                 mplsogre_decap_conf.select_vlan = 0;
14968         else if (strcmp(res->mplsogre, "mplsogre_decap-with-vlan") == 0)
14969                 mplsogre_decap_conf.select_vlan = 1;
14970         if (strcmp(res->ip_version, "ipv4") == 0)
14971                 mplsogre_decap_conf.select_ipv4 = 1;
14972         else if (strcmp(res->ip_version, "ipv6") == 0)
14973                 mplsogre_decap_conf.select_ipv4 = 0;
14974 }
14975
14976 cmdline_parse_inst_t cmd_set_mplsogre_decap = {
14977         .f = cmd_set_mplsogre_decap_parsed,
14978         .data = NULL,
14979         .help_str = "set mplsogre_decap ip-version ipv4|ipv6",
14980         .tokens = {
14981                 (void *)&cmd_set_mplsogre_decap_set,
14982                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap,
14983                 (void *)&cmd_set_mplsogre_decap_ip_version,
14984                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14985                 NULL,
14986         },
14987 };
14988
14989 cmdline_parse_inst_t cmd_set_mplsogre_decap_with_vlan = {
14990         .f = cmd_set_mplsogre_decap_parsed,
14991         .data = NULL,
14992         .help_str = "set mplsogre_decap-with-vlan ip-version ipv4|ipv6",
14993         .tokens = {
14994                 (void *)&cmd_set_mplsogre_decap_set,
14995                 (void *)&cmd_set_mplsogre_decap_mplsogre_decap_with_vlan,
14996                 (void *)&cmd_set_mplsogre_decap_ip_version,
14997                 (void *)&cmd_set_mplsogre_decap_ip_version_value,
14998                 NULL,
14999         },
15000 };
15001
15002 /** Set MPLSoUDP encapsulation details */
15003 struct cmd_set_mplsoudp_encap_result {
15004         cmdline_fixed_string_t set;
15005         cmdline_fixed_string_t mplsoudp;
15006         cmdline_fixed_string_t pos_token;
15007         cmdline_fixed_string_t ip_version;
15008         uint32_t vlan_present:1;
15009         uint32_t label;
15010         uint16_t udp_src;
15011         uint16_t udp_dst;
15012         cmdline_ipaddr_t ip_src;
15013         cmdline_ipaddr_t ip_dst;
15014         uint16_t tci;
15015         struct rte_ether_addr eth_src;
15016         struct rte_ether_addr eth_dst;
15017 };
15018
15019 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_set =
15020         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, set,
15021                                  "set");
15022 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap =
15023         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result, mplsoudp,
15024                                  "mplsoudp_encap");
15025 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan =
15026         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15027                                  mplsoudp, "mplsoudp_encap-with-vlan");
15028 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version =
15029         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15030                                  pos_token, "ip-version");
15031 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_version_value =
15032         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15033                                  ip_version, "ipv4#ipv6");
15034 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_label =
15035         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15036                                  pos_token, "label");
15037 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_label_value =
15038         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, label,
15039                               UINT32);
15040 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_src =
15041         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15042                                  pos_token, "udp-src");
15043 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_src_value =
15044         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_src,
15045                               UINT16);
15046 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_udp_dst =
15047         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15048                                  pos_token, "udp-dst");
15049 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_udp_dst_value =
15050         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, udp_dst,
15051                               UINT16);
15052 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_src =
15053         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15054                                  pos_token, "ip-src");
15055 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_src_value =
15056         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_src);
15057 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_ip_dst =
15058         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15059                                  pos_token, "ip-dst");
15060 cmdline_parse_token_ipaddr_t cmd_set_mplsoudp_encap_ip_dst_value =
15061         TOKEN_IPADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result, ip_dst);
15062 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_vlan =
15063         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15064                                  pos_token, "vlan-tci");
15065 cmdline_parse_token_num_t cmd_set_mplsoudp_encap_vlan_value =
15066         TOKEN_NUM_INITIALIZER(struct cmd_set_mplsoudp_encap_result, tci,
15067                               UINT16);
15068 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_src =
15069         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15070                                  pos_token, "eth-src");
15071 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_src_value =
15072         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15073                                     eth_src);
15074 cmdline_parse_token_string_t cmd_set_mplsoudp_encap_eth_dst =
15075         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15076                                  pos_token, "eth-dst");
15077 cmdline_parse_token_etheraddr_t cmd_set_mplsoudp_encap_eth_dst_value =
15078         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_mplsoudp_encap_result,
15079                                     eth_dst);
15080
15081 static void cmd_set_mplsoudp_encap_parsed(void *parsed_result,
15082         __rte_unused struct cmdline *cl,
15083         __rte_unused void *data)
15084 {
15085         struct cmd_set_mplsoudp_encap_result *res = parsed_result;
15086         union {
15087                 uint32_t mplsoudp_label;
15088                 uint8_t label[4];
15089         } id = {
15090                 .mplsoudp_label = rte_cpu_to_be_32(res->label<<12),
15091         };
15092
15093         if (strcmp(res->mplsoudp, "mplsoudp_encap") == 0)
15094                 mplsoudp_encap_conf.select_vlan = 0;
15095         else if (strcmp(res->mplsoudp, "mplsoudp_encap-with-vlan") == 0)
15096                 mplsoudp_encap_conf.select_vlan = 1;
15097         if (strcmp(res->ip_version, "ipv4") == 0)
15098                 mplsoudp_encap_conf.select_ipv4 = 1;
15099         else if (strcmp(res->ip_version, "ipv6") == 0)
15100                 mplsoudp_encap_conf.select_ipv4 = 0;
15101         else
15102                 return;
15103         rte_memcpy(mplsoudp_encap_conf.label, &id.label, 3);
15104         mplsoudp_encap_conf.udp_src = rte_cpu_to_be_16(res->udp_src);
15105         mplsoudp_encap_conf.udp_dst = rte_cpu_to_be_16(res->udp_dst);
15106         if (mplsoudp_encap_conf.select_ipv4) {
15107                 IPV4_ADDR_TO_UINT(res->ip_src, mplsoudp_encap_conf.ipv4_src);
15108                 IPV4_ADDR_TO_UINT(res->ip_dst, mplsoudp_encap_conf.ipv4_dst);
15109         } else {
15110                 IPV6_ADDR_TO_ARRAY(res->ip_src, mplsoudp_encap_conf.ipv6_src);
15111                 IPV6_ADDR_TO_ARRAY(res->ip_dst, mplsoudp_encap_conf.ipv6_dst);
15112         }
15113         if (mplsoudp_encap_conf.select_vlan)
15114                 mplsoudp_encap_conf.vlan_tci = rte_cpu_to_be_16(res->tci);
15115         rte_memcpy(mplsoudp_encap_conf.eth_src, res->eth_src.addr_bytes,
15116                    RTE_ETHER_ADDR_LEN);
15117         rte_memcpy(mplsoudp_encap_conf.eth_dst, res->eth_dst.addr_bytes,
15118                    RTE_ETHER_ADDR_LEN);
15119 }
15120
15121 cmdline_parse_inst_t cmd_set_mplsoudp_encap = {
15122         .f = cmd_set_mplsoudp_encap_parsed,
15123         .data = NULL,
15124         .help_str = "set mplsoudp_encap ip-version ipv4|ipv6 label <label>"
15125                 " udp-src <udp-src> udp-dst <udp-dst> ip-src <ip-src>"
15126                 " ip-dst <ip-dst> eth-src <eth-src> eth-dst <eth-dst>",
15127         .tokens = {
15128                 (void *)&cmd_set_mplsoudp_encap_set,
15129                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap,
15130                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15131                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15132                 (void *)&cmd_set_mplsoudp_encap_label,
15133                 (void *)&cmd_set_mplsoudp_encap_label_value,
15134                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15135                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15136                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15137                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15138                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15139                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15140                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15141                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15142                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15143                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15144                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15145                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15146                 NULL,
15147         },
15148 };
15149
15150 cmdline_parse_inst_t cmd_set_mplsoudp_encap_with_vlan = {
15151         .f = cmd_set_mplsoudp_encap_parsed,
15152         .data = NULL,
15153         .help_str = "set mplsoudp_encap-with-vlan ip-version ipv4|ipv6"
15154                 " label <label> udp-src <udp-src> udp-dst <udp-dst>"
15155                 " ip-src <ip-src> ip-dst <ip-dst> vlan-tci <vlan-tci>"
15156                 " eth-src <eth-src> eth-dst <eth-dst>",
15157         .tokens = {
15158                 (void *)&cmd_set_mplsoudp_encap_set,
15159                 (void *)&cmd_set_mplsoudp_encap_mplsoudp_encap_with_vlan,
15160                 (void *)&cmd_set_mplsoudp_encap_ip_version,
15161                 (void *)&cmd_set_mplsoudp_encap_ip_version_value,
15162                 (void *)&cmd_set_mplsoudp_encap_label,
15163                 (void *)&cmd_set_mplsoudp_encap_label_value,
15164                 (void *)&cmd_set_mplsoudp_encap_udp_src,
15165                 (void *)&cmd_set_mplsoudp_encap_udp_src_value,
15166                 (void *)&cmd_set_mplsoudp_encap_udp_dst,
15167                 (void *)&cmd_set_mplsoudp_encap_udp_dst_value,
15168                 (void *)&cmd_set_mplsoudp_encap_ip_src,
15169                 (void *)&cmd_set_mplsoudp_encap_ip_src_value,
15170                 (void *)&cmd_set_mplsoudp_encap_ip_dst,
15171                 (void *)&cmd_set_mplsoudp_encap_ip_dst_value,
15172                 (void *)&cmd_set_mplsoudp_encap_vlan,
15173                 (void *)&cmd_set_mplsoudp_encap_vlan_value,
15174                 (void *)&cmd_set_mplsoudp_encap_eth_src,
15175                 (void *)&cmd_set_mplsoudp_encap_eth_src_value,
15176                 (void *)&cmd_set_mplsoudp_encap_eth_dst,
15177                 (void *)&cmd_set_mplsoudp_encap_eth_dst_value,
15178                 NULL,
15179         },
15180 };
15181
15182 /** Set MPLSoUDP decapsulation details */
15183 struct cmd_set_mplsoudp_decap_result {
15184         cmdline_fixed_string_t set;
15185         cmdline_fixed_string_t mplsoudp;
15186         cmdline_fixed_string_t pos_token;
15187         cmdline_fixed_string_t ip_version;
15188         uint32_t vlan_present:1;
15189 };
15190
15191 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_set =
15192         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, set,
15193                                  "set");
15194 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap =
15195         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result, mplsoudp,
15196                                  "mplsoudp_decap");
15197 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan =
15198         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15199                                  mplsoudp, "mplsoudp_decap-with-vlan");
15200 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version =
15201         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15202                                  pos_token, "ip-version");
15203 cmdline_parse_token_string_t cmd_set_mplsoudp_decap_ip_version_value =
15204         TOKEN_STRING_INITIALIZER(struct cmd_set_mplsoudp_decap_result,
15205                                  ip_version, "ipv4#ipv6");
15206
15207 static void cmd_set_mplsoudp_decap_parsed(void *parsed_result,
15208         __rte_unused struct cmdline *cl,
15209         __rte_unused void *data)
15210 {
15211         struct cmd_set_mplsoudp_decap_result *res = parsed_result;
15212
15213         if (strcmp(res->mplsoudp, "mplsoudp_decap") == 0)
15214                 mplsoudp_decap_conf.select_vlan = 0;
15215         else if (strcmp(res->mplsoudp, "mplsoudp_decap-with-vlan") == 0)
15216                 mplsoudp_decap_conf.select_vlan = 1;
15217         if (strcmp(res->ip_version, "ipv4") == 0)
15218                 mplsoudp_decap_conf.select_ipv4 = 1;
15219         else if (strcmp(res->ip_version, "ipv6") == 0)
15220                 mplsoudp_decap_conf.select_ipv4 = 0;
15221 }
15222
15223 cmdline_parse_inst_t cmd_set_mplsoudp_decap = {
15224         .f = cmd_set_mplsoudp_decap_parsed,
15225         .data = NULL,
15226         .help_str = "set mplsoudp_decap ip-version ipv4|ipv6",
15227         .tokens = {
15228                 (void *)&cmd_set_mplsoudp_decap_set,
15229                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap,
15230                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15231                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15232                 NULL,
15233         },
15234 };
15235
15236 cmdline_parse_inst_t cmd_set_mplsoudp_decap_with_vlan = {
15237         .f = cmd_set_mplsoudp_decap_parsed,
15238         .data = NULL,
15239         .help_str = "set mplsoudp_decap-with-vlan ip-version ipv4|ipv6",
15240         .tokens = {
15241                 (void *)&cmd_set_mplsoudp_decap_set,
15242                 (void *)&cmd_set_mplsoudp_decap_mplsoudp_decap_with_vlan,
15243                 (void *)&cmd_set_mplsoudp_decap_ip_version,
15244                 (void *)&cmd_set_mplsoudp_decap_ip_version_value,
15245                 NULL,
15246         },
15247 };
15248
15249 /* Strict link priority scheduling mode setting */
15250 static void
15251 cmd_strict_link_prio_parsed(
15252         void *parsed_result,
15253         __rte_unused struct cmdline *cl,
15254         __rte_unused void *data)
15255 {
15256         struct cmd_vf_tc_bw_result *res = parsed_result;
15257         int ret = -ENOTSUP;
15258
15259         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15260                 return;
15261
15262 #ifdef RTE_NET_I40E
15263         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
15264 #endif
15265
15266         switch (ret) {
15267         case 0:
15268                 break;
15269         case -EINVAL:
15270                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
15271                 break;
15272         case -ENODEV:
15273                 printf("invalid port_id %d\n", res->port_id);
15274                 break;
15275         case -ENOTSUP:
15276                 printf("function not implemented\n");
15277                 break;
15278         default:
15279                 printf("programming error: (%s)\n", strerror(-ret));
15280         }
15281 }
15282
15283 cmdline_parse_inst_t cmd_strict_link_prio = {
15284         .f = cmd_strict_link_prio_parsed,
15285         .data = NULL,
15286         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
15287         .tokens = {
15288                 (void *)&cmd_vf_tc_bw_set,
15289                 (void *)&cmd_vf_tc_bw_tx,
15290                 (void *)&cmd_vf_tc_bw_strict_link_prio,
15291                 (void *)&cmd_vf_tc_bw_port_id,
15292                 (void *)&cmd_vf_tc_bw_tc_map,
15293                 NULL,
15294         },
15295 };
15296
15297 /* Load dynamic device personalization*/
15298 struct cmd_ddp_add_result {
15299         cmdline_fixed_string_t ddp;
15300         cmdline_fixed_string_t add;
15301         portid_t port_id;
15302         char filepath[];
15303 };
15304
15305 cmdline_parse_token_string_t cmd_ddp_add_ddp =
15306         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
15307 cmdline_parse_token_string_t cmd_ddp_add_add =
15308         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
15309 cmdline_parse_token_num_t cmd_ddp_add_port_id =
15310         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
15311 cmdline_parse_token_string_t cmd_ddp_add_filepath =
15312         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
15313
15314 static void
15315 cmd_ddp_add_parsed(
15316         void *parsed_result,
15317         __rte_unused struct cmdline *cl,
15318         __rte_unused void *data)
15319 {
15320         struct cmd_ddp_add_result *res = parsed_result;
15321         uint8_t *buff;
15322         uint32_t size;
15323         char *filepath;
15324         char *file_fld[2];
15325         int file_num;
15326         int ret = -ENOTSUP;
15327
15328         if (!all_ports_stopped()) {
15329                 printf("Please stop all ports first\n");
15330                 return;
15331         }
15332
15333         filepath = strdup(res->filepath);
15334         if (filepath == NULL) {
15335                 printf("Failed to allocate memory\n");
15336                 return;
15337         }
15338         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
15339
15340         buff = open_file(file_fld[0], &size);
15341         if (!buff) {
15342                 free((void *)filepath);
15343                 return;
15344         }
15345
15346 #ifdef RTE_NET_I40E
15347         if (ret == -ENOTSUP)
15348                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15349                                                buff, size,
15350                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
15351 #endif
15352
15353         if (ret == -EEXIST)
15354                 printf("Profile has already existed.\n");
15355         else if (ret < 0)
15356                 printf("Failed to load profile.\n");
15357         else if (file_num == 2)
15358                 save_file(file_fld[1], buff, size);
15359
15360         close_file(buff);
15361         free((void *)filepath);
15362 }
15363
15364 cmdline_parse_inst_t cmd_ddp_add = {
15365         .f = cmd_ddp_add_parsed,
15366         .data = NULL,
15367         .help_str = "ddp add <port_id> <profile_path[,backup_profile_path]>",
15368         .tokens = {
15369                 (void *)&cmd_ddp_add_ddp,
15370                 (void *)&cmd_ddp_add_add,
15371                 (void *)&cmd_ddp_add_port_id,
15372                 (void *)&cmd_ddp_add_filepath,
15373                 NULL,
15374         },
15375 };
15376
15377 /* Delete dynamic device personalization*/
15378 struct cmd_ddp_del_result {
15379         cmdline_fixed_string_t ddp;
15380         cmdline_fixed_string_t del;
15381         portid_t port_id;
15382         char filepath[];
15383 };
15384
15385 cmdline_parse_token_string_t cmd_ddp_del_ddp =
15386         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
15387 cmdline_parse_token_string_t cmd_ddp_del_del =
15388         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
15389 cmdline_parse_token_num_t cmd_ddp_del_port_id =
15390         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
15391 cmdline_parse_token_string_t cmd_ddp_del_filepath =
15392         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
15393
15394 static void
15395 cmd_ddp_del_parsed(
15396         void *parsed_result,
15397         __rte_unused struct cmdline *cl,
15398         __rte_unused void *data)
15399 {
15400         struct cmd_ddp_del_result *res = parsed_result;
15401         uint8_t *buff;
15402         uint32_t size;
15403         int ret = -ENOTSUP;
15404
15405         if (!all_ports_stopped()) {
15406                 printf("Please stop all ports first\n");
15407                 return;
15408         }
15409
15410         buff = open_file(res->filepath, &size);
15411         if (!buff)
15412                 return;
15413
15414 #ifdef RTE_NET_I40E
15415         if (ret == -ENOTSUP)
15416                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
15417                                                buff, size,
15418                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
15419 #endif
15420
15421         if (ret == -EACCES)
15422                 printf("Profile does not exist.\n");
15423         else if (ret < 0)
15424                 printf("Failed to delete profile.\n");
15425
15426         close_file(buff);
15427 }
15428
15429 cmdline_parse_inst_t cmd_ddp_del = {
15430         .f = cmd_ddp_del_parsed,
15431         .data = NULL,
15432         .help_str = "ddp del <port_id> <backup_profile_path>",
15433         .tokens = {
15434                 (void *)&cmd_ddp_del_ddp,
15435                 (void *)&cmd_ddp_del_del,
15436                 (void *)&cmd_ddp_del_port_id,
15437                 (void *)&cmd_ddp_del_filepath,
15438                 NULL,
15439         },
15440 };
15441
15442 /* Get dynamic device personalization profile info */
15443 struct cmd_ddp_info_result {
15444         cmdline_fixed_string_t ddp;
15445         cmdline_fixed_string_t get;
15446         cmdline_fixed_string_t info;
15447         char filepath[];
15448 };
15449
15450 cmdline_parse_token_string_t cmd_ddp_info_ddp =
15451         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
15452 cmdline_parse_token_string_t cmd_ddp_info_get =
15453         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
15454 cmdline_parse_token_string_t cmd_ddp_info_info =
15455         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
15456 cmdline_parse_token_string_t cmd_ddp_info_filepath =
15457         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
15458
15459 static void
15460 cmd_ddp_info_parsed(
15461         void *parsed_result,
15462         __rte_unused struct cmdline *cl,
15463         __rte_unused void *data)
15464 {
15465         struct cmd_ddp_info_result *res = parsed_result;
15466         uint8_t *pkg;
15467         uint32_t pkg_size;
15468         int ret = -ENOTSUP;
15469 #ifdef RTE_NET_I40E
15470         uint32_t i, j, n;
15471         uint8_t *buff;
15472         uint32_t buff_size = 0;
15473         struct rte_pmd_i40e_profile_info info;
15474         uint32_t dev_num = 0;
15475         struct rte_pmd_i40e_ddp_device_id *devs;
15476         uint32_t proto_num = 0;
15477         struct rte_pmd_i40e_proto_info *proto = NULL;
15478         uint32_t pctype_num = 0;
15479         struct rte_pmd_i40e_ptype_info *pctype;
15480         uint32_t ptype_num = 0;
15481         struct rte_pmd_i40e_ptype_info *ptype;
15482         uint8_t proto_id;
15483
15484 #endif
15485
15486         pkg = open_file(res->filepath, &pkg_size);
15487         if (!pkg)
15488                 return;
15489
15490 #ifdef RTE_NET_I40E
15491         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15492                                 (uint8_t *)&info, sizeof(info),
15493                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
15494         if (!ret) {
15495                 printf("Global Track id:       0x%x\n", info.track_id);
15496                 printf("Global Version:        %d.%d.%d.%d\n",
15497                         info.version.major,
15498                         info.version.minor,
15499                         info.version.update,
15500                         info.version.draft);
15501                 printf("Global Package name:   %s\n\n", info.name);
15502         }
15503
15504         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15505                                 (uint8_t *)&info, sizeof(info),
15506                                 RTE_PMD_I40E_PKG_INFO_HEADER);
15507         if (!ret) {
15508                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
15509                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
15510                         info.version.major,
15511                         info.version.minor,
15512                         info.version.update,
15513                         info.version.draft);
15514                 printf("i40e Profile name:     %s\n\n", info.name);
15515         }
15516
15517         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15518                                 (uint8_t *)&buff_size, sizeof(buff_size),
15519                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
15520         if (!ret && buff_size) {
15521                 buff = (uint8_t *)malloc(buff_size);
15522                 if (buff) {
15523                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15524                                                 buff, buff_size,
15525                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
15526                         if (!ret)
15527                                 printf("Package Notes:\n%s\n\n", buff);
15528                         free(buff);
15529                 }
15530         }
15531
15532         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15533                                 (uint8_t *)&dev_num, sizeof(dev_num),
15534                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
15535         if (!ret && dev_num) {
15536                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
15537                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
15538                 if (devs) {
15539                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15540                                                 (uint8_t *)devs, buff_size,
15541                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
15542                         if (!ret) {
15543                                 printf("List of supported devices:\n");
15544                                 for (i = 0; i < dev_num; i++) {
15545                                         printf("  %04X:%04X %04X:%04X\n",
15546                                                 devs[i].vendor_dev_id >> 16,
15547                                                 devs[i].vendor_dev_id & 0xFFFF,
15548                                                 devs[i].sub_vendor_dev_id >> 16,
15549                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
15550                                 }
15551                                 printf("\n");
15552                         }
15553                         free(devs);
15554                 }
15555         }
15556
15557         /* get information about protocols and packet types */
15558         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15559                 (uint8_t *)&proto_num, sizeof(proto_num),
15560                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
15561         if (ret || !proto_num)
15562                 goto no_print_return;
15563
15564         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
15565         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
15566         if (!proto)
15567                 goto no_print_return;
15568
15569         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
15570                                         buff_size,
15571                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
15572         if (!ret) {
15573                 printf("List of used protocols:\n");
15574                 for (i = 0; i < proto_num; i++)
15575                         printf("  %2u: %s\n", proto[i].proto_id,
15576                                proto[i].name);
15577                 printf("\n");
15578         }
15579         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
15580                 (uint8_t *)&pctype_num, sizeof(pctype_num),
15581                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
15582         if (ret || !pctype_num)
15583                 goto no_print_pctypes;
15584
15585         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15586         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15587         if (!pctype)
15588                 goto no_print_pctypes;
15589
15590         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
15591                                         buff_size,
15592                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
15593         if (ret) {
15594                 free(pctype);
15595                 goto no_print_pctypes;
15596         }
15597
15598         printf("List of defined packet classification types:\n");
15599         for (i = 0; i < pctype_num; i++) {
15600                 printf("  %2u:", pctype[i].ptype_id);
15601                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15602                         proto_id = pctype[i].protocols[j];
15603                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15604                                 for (n = 0; n < proto_num; n++) {
15605                                         if (proto[n].proto_id == proto_id) {
15606                                                 printf(" %s", proto[n].name);
15607                                                 break;
15608                                         }
15609                                 }
15610                         }
15611                 }
15612                 printf("\n");
15613         }
15614         printf("\n");
15615         free(pctype);
15616
15617 no_print_pctypes:
15618
15619         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
15620                                         sizeof(ptype_num),
15621                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
15622         if (ret || !ptype_num)
15623                 goto no_print_return;
15624
15625         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
15626         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
15627         if (!ptype)
15628                 goto no_print_return;
15629
15630         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
15631                                         buff_size,
15632                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
15633         if (ret) {
15634                 free(ptype);
15635                 goto no_print_return;
15636         }
15637         printf("List of defined packet types:\n");
15638         for (i = 0; i < ptype_num; i++) {
15639                 printf("  %2u:", ptype[i].ptype_id);
15640                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
15641                         proto_id = ptype[i].protocols[j];
15642                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
15643                                 for (n = 0; n < proto_num; n++) {
15644                                         if (proto[n].proto_id == proto_id) {
15645                                                 printf(" %s", proto[n].name);
15646                                                 break;
15647                                         }
15648                                 }
15649                         }
15650                 }
15651                 printf("\n");
15652         }
15653         free(ptype);
15654         printf("\n");
15655
15656         ret = 0;
15657 no_print_return:
15658         if (proto)
15659                 free(proto);
15660 #endif
15661         if (ret == -ENOTSUP)
15662                 printf("Function not supported in PMD driver\n");
15663         close_file(pkg);
15664 }
15665
15666 cmdline_parse_inst_t cmd_ddp_get_info = {
15667         .f = cmd_ddp_info_parsed,
15668         .data = NULL,
15669         .help_str = "ddp get info <profile_path>",
15670         .tokens = {
15671                 (void *)&cmd_ddp_info_ddp,
15672                 (void *)&cmd_ddp_info_get,
15673                 (void *)&cmd_ddp_info_info,
15674                 (void *)&cmd_ddp_info_filepath,
15675                 NULL,
15676         },
15677 };
15678
15679 /* Get dynamic device personalization profile info list*/
15680 #define PROFILE_INFO_SIZE 48
15681 #define MAX_PROFILE_NUM 16
15682
15683 struct cmd_ddp_get_list_result {
15684         cmdline_fixed_string_t ddp;
15685         cmdline_fixed_string_t get;
15686         cmdline_fixed_string_t list;
15687         portid_t port_id;
15688 };
15689
15690 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
15691         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
15692 cmdline_parse_token_string_t cmd_ddp_get_list_get =
15693         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
15694 cmdline_parse_token_string_t cmd_ddp_get_list_list =
15695         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
15696 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
15697         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
15698
15699 static void
15700 cmd_ddp_get_list_parsed(
15701         __rte_unused void *parsed_result,
15702         __rte_unused struct cmdline *cl,
15703         __rte_unused void *data)
15704 {
15705 #ifdef RTE_NET_I40E
15706         struct cmd_ddp_get_list_result *res = parsed_result;
15707         struct rte_pmd_i40e_profile_list *p_list;
15708         struct rte_pmd_i40e_profile_info *p_info;
15709         uint32_t p_num;
15710         uint32_t size;
15711         uint32_t i;
15712 #endif
15713         int ret = -ENOTSUP;
15714
15715 #ifdef RTE_NET_I40E
15716         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
15717         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
15718         if (!p_list) {
15719                 printf("%s: Failed to malloc buffer\n", __func__);
15720                 return;
15721         }
15722
15723         if (ret == -ENOTSUP)
15724                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
15725                                                 (uint8_t *)p_list, size);
15726
15727         if (!ret) {
15728                 p_num = p_list->p_count;
15729                 printf("Profile number is: %d\n\n", p_num);
15730
15731                 for (i = 0; i < p_num; i++) {
15732                         p_info = &p_list->p_info[i];
15733                         printf("Profile %d:\n", i);
15734                         printf("Track id:     0x%x\n", p_info->track_id);
15735                         printf("Version:      %d.%d.%d.%d\n",
15736                                p_info->version.major,
15737                                p_info->version.minor,
15738                                p_info->version.update,
15739                                p_info->version.draft);
15740                         printf("Profile name: %s\n\n", p_info->name);
15741                 }
15742         }
15743
15744         free(p_list);
15745 #endif
15746
15747         if (ret < 0)
15748                 printf("Failed to get ddp list\n");
15749 }
15750
15751 cmdline_parse_inst_t cmd_ddp_get_list = {
15752         .f = cmd_ddp_get_list_parsed,
15753         .data = NULL,
15754         .help_str = "ddp get list <port_id>",
15755         .tokens = {
15756                 (void *)&cmd_ddp_get_list_ddp,
15757                 (void *)&cmd_ddp_get_list_get,
15758                 (void *)&cmd_ddp_get_list_list,
15759                 (void *)&cmd_ddp_get_list_port_id,
15760                 NULL,
15761         },
15762 };
15763
15764 /* Configure input set */
15765 struct cmd_cfg_input_set_result {
15766         cmdline_fixed_string_t port;
15767         cmdline_fixed_string_t cfg;
15768         portid_t port_id;
15769         cmdline_fixed_string_t pctype;
15770         uint8_t pctype_id;
15771         cmdline_fixed_string_t inset_type;
15772         cmdline_fixed_string_t opt;
15773         cmdline_fixed_string_t field;
15774         uint8_t field_idx;
15775 };
15776
15777 static void
15778 cmd_cfg_input_set_parsed(
15779         __rte_unused void *parsed_result,
15780         __rte_unused struct cmdline *cl,
15781         __rte_unused void *data)
15782 {
15783 #ifdef RTE_NET_I40E
15784         struct cmd_cfg_input_set_result *res = parsed_result;
15785         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15786         struct rte_pmd_i40e_inset inset;
15787 #endif
15788         int ret = -ENOTSUP;
15789
15790         if (!all_ports_stopped()) {
15791                 printf("Please stop all ports first\n");
15792                 return;
15793         }
15794
15795 #ifdef RTE_NET_I40E
15796         if (!strcmp(res->inset_type, "hash_inset"))
15797                 inset_type = INSET_HASH;
15798         else if (!strcmp(res->inset_type, "fdir_inset"))
15799                 inset_type = INSET_FDIR;
15800         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15801                 inset_type = INSET_FDIR_FLX;
15802         ret = rte_pmd_i40e_inset_get(res->port_id, res->pctype_id,
15803                                      &inset, inset_type);
15804         if (ret) {
15805                 printf("Failed to get input set.\n");
15806                 return;
15807         }
15808
15809         if (!strcmp(res->opt, "get")) {
15810                 ret = rte_pmd_i40e_inset_field_get(inset.inset,
15811                                                    res->field_idx);
15812                 if (ret)
15813                         printf("Field index %d is enabled.\n", res->field_idx);
15814                 else
15815                         printf("Field index %d is disabled.\n", res->field_idx);
15816                 return;
15817         } else if (!strcmp(res->opt, "set"))
15818                 ret = rte_pmd_i40e_inset_field_set(&inset.inset,
15819                                                    res->field_idx);
15820         else if (!strcmp(res->opt, "clear"))
15821                 ret = rte_pmd_i40e_inset_field_clear(&inset.inset,
15822                                                      res->field_idx);
15823         if (ret) {
15824                 printf("Failed to configure input set field.\n");
15825                 return;
15826         }
15827
15828         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15829                                      &inset, inset_type);
15830         if (ret) {
15831                 printf("Failed to set input set.\n");
15832                 return;
15833         }
15834 #endif
15835
15836         if (ret == -ENOTSUP)
15837                 printf("Function not supported\n");
15838 }
15839
15840 cmdline_parse_token_string_t cmd_cfg_input_set_port =
15841         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15842                                  port, "port");
15843 cmdline_parse_token_string_t cmd_cfg_input_set_cfg =
15844         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15845                                  cfg, "config");
15846 cmdline_parse_token_num_t cmd_cfg_input_set_port_id =
15847         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15848                               port_id, UINT16);
15849 cmdline_parse_token_string_t cmd_cfg_input_set_pctype =
15850         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15851                                  pctype, "pctype");
15852 cmdline_parse_token_num_t cmd_cfg_input_set_pctype_id =
15853         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15854                               pctype_id, UINT8);
15855 cmdline_parse_token_string_t cmd_cfg_input_set_inset_type =
15856         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15857                                  inset_type,
15858                                  "hash_inset#fdir_inset#fdir_flx_inset");
15859 cmdline_parse_token_string_t cmd_cfg_input_set_opt =
15860         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15861                                  opt, "get#set#clear");
15862 cmdline_parse_token_string_t cmd_cfg_input_set_field =
15863         TOKEN_STRING_INITIALIZER(struct cmd_cfg_input_set_result,
15864                                  field, "field");
15865 cmdline_parse_token_num_t cmd_cfg_input_set_field_idx =
15866         TOKEN_NUM_INITIALIZER(struct cmd_cfg_input_set_result,
15867                               field_idx, UINT8);
15868
15869 cmdline_parse_inst_t cmd_cfg_input_set = {
15870         .f = cmd_cfg_input_set_parsed,
15871         .data = NULL,
15872         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15873                     "fdir_inset|fdir_flx_inset get|set|clear field <field_idx>",
15874         .tokens = {
15875                 (void *)&cmd_cfg_input_set_port,
15876                 (void *)&cmd_cfg_input_set_cfg,
15877                 (void *)&cmd_cfg_input_set_port_id,
15878                 (void *)&cmd_cfg_input_set_pctype,
15879                 (void *)&cmd_cfg_input_set_pctype_id,
15880                 (void *)&cmd_cfg_input_set_inset_type,
15881                 (void *)&cmd_cfg_input_set_opt,
15882                 (void *)&cmd_cfg_input_set_field,
15883                 (void *)&cmd_cfg_input_set_field_idx,
15884                 NULL,
15885         },
15886 };
15887
15888 /* Clear input set */
15889 struct cmd_clear_input_set_result {
15890         cmdline_fixed_string_t port;
15891         cmdline_fixed_string_t cfg;
15892         portid_t port_id;
15893         cmdline_fixed_string_t pctype;
15894         uint8_t pctype_id;
15895         cmdline_fixed_string_t inset_type;
15896         cmdline_fixed_string_t clear;
15897         cmdline_fixed_string_t all;
15898 };
15899
15900 static void
15901 cmd_clear_input_set_parsed(
15902         __rte_unused void *parsed_result,
15903         __rte_unused struct cmdline *cl,
15904         __rte_unused void *data)
15905 {
15906 #ifdef RTE_NET_I40E
15907         struct cmd_clear_input_set_result *res = parsed_result;
15908         enum rte_pmd_i40e_inset_type inset_type = INSET_NONE;
15909         struct rte_pmd_i40e_inset inset;
15910 #endif
15911         int ret = -ENOTSUP;
15912
15913         if (!all_ports_stopped()) {
15914                 printf("Please stop all ports first\n");
15915                 return;
15916         }
15917
15918 #ifdef RTE_NET_I40E
15919         if (!strcmp(res->inset_type, "hash_inset"))
15920                 inset_type = INSET_HASH;
15921         else if (!strcmp(res->inset_type, "fdir_inset"))
15922                 inset_type = INSET_FDIR;
15923         else if (!strcmp(res->inset_type, "fdir_flx_inset"))
15924                 inset_type = INSET_FDIR_FLX;
15925
15926         memset(&inset, 0, sizeof(inset));
15927
15928         ret = rte_pmd_i40e_inset_set(res->port_id, res->pctype_id,
15929                                      &inset, inset_type);
15930         if (ret) {
15931                 printf("Failed to clear input set.\n");
15932                 return;
15933         }
15934
15935 #endif
15936
15937         if (ret == -ENOTSUP)
15938                 printf("Function not supported\n");
15939 }
15940
15941 cmdline_parse_token_string_t cmd_clear_input_set_port =
15942         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15943                                  port, "port");
15944 cmdline_parse_token_string_t cmd_clear_input_set_cfg =
15945         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15946                                  cfg, "config");
15947 cmdline_parse_token_num_t cmd_clear_input_set_port_id =
15948         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15949                               port_id, UINT16);
15950 cmdline_parse_token_string_t cmd_clear_input_set_pctype =
15951         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15952                                  pctype, "pctype");
15953 cmdline_parse_token_num_t cmd_clear_input_set_pctype_id =
15954         TOKEN_NUM_INITIALIZER(struct cmd_clear_input_set_result,
15955                               pctype_id, UINT8);
15956 cmdline_parse_token_string_t cmd_clear_input_set_inset_type =
15957         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15958                                  inset_type,
15959                                  "hash_inset#fdir_inset#fdir_flx_inset");
15960 cmdline_parse_token_string_t cmd_clear_input_set_clear =
15961         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15962                                  clear, "clear");
15963 cmdline_parse_token_string_t cmd_clear_input_set_all =
15964         TOKEN_STRING_INITIALIZER(struct cmd_clear_input_set_result,
15965                                  all, "all");
15966
15967 cmdline_parse_inst_t cmd_clear_input_set = {
15968         .f = cmd_clear_input_set_parsed,
15969         .data = NULL,
15970         .help_str = "port config <port_id> pctype <pctype_id> hash_inset|"
15971                     "fdir_inset|fdir_flx_inset clear all",
15972         .tokens = {
15973                 (void *)&cmd_clear_input_set_port,
15974                 (void *)&cmd_clear_input_set_cfg,
15975                 (void *)&cmd_clear_input_set_port_id,
15976                 (void *)&cmd_clear_input_set_pctype,
15977                 (void *)&cmd_clear_input_set_pctype_id,
15978                 (void *)&cmd_clear_input_set_inset_type,
15979                 (void *)&cmd_clear_input_set_clear,
15980                 (void *)&cmd_clear_input_set_all,
15981                 NULL,
15982         },
15983 };
15984
15985 /* show vf stats */
15986
15987 /* Common result structure for show vf stats */
15988 struct cmd_show_vf_stats_result {
15989         cmdline_fixed_string_t show;
15990         cmdline_fixed_string_t vf;
15991         cmdline_fixed_string_t stats;
15992         portid_t port_id;
15993         uint16_t vf_id;
15994 };
15995
15996 /* Common CLI fields show vf stats*/
15997 cmdline_parse_token_string_t cmd_show_vf_stats_show =
15998         TOKEN_STRING_INITIALIZER
15999                 (struct cmd_show_vf_stats_result,
16000                  show, "show");
16001 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
16002         TOKEN_STRING_INITIALIZER
16003                 (struct cmd_show_vf_stats_result,
16004                  vf, "vf");
16005 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
16006         TOKEN_STRING_INITIALIZER
16007                 (struct cmd_show_vf_stats_result,
16008                  stats, "stats");
16009 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
16010         TOKEN_NUM_INITIALIZER
16011                 (struct cmd_show_vf_stats_result,
16012                  port_id, UINT16);
16013 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
16014         TOKEN_NUM_INITIALIZER
16015                 (struct cmd_show_vf_stats_result,
16016                  vf_id, UINT16);
16017
16018 static void
16019 cmd_show_vf_stats_parsed(
16020         void *parsed_result,
16021         __rte_unused struct cmdline *cl,
16022         __rte_unused void *data)
16023 {
16024         struct cmd_show_vf_stats_result *res = parsed_result;
16025         struct rte_eth_stats stats;
16026         int ret = -ENOTSUP;
16027         static const char *nic_stats_border = "########################";
16028
16029         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16030                 return;
16031
16032         memset(&stats, 0, sizeof(stats));
16033
16034 #ifdef RTE_NET_I40E
16035         if (ret == -ENOTSUP)
16036                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
16037                                                 res->vf_id,
16038                                                 &stats);
16039 #endif
16040 #ifdef RTE_NET_BNXT
16041         if (ret == -ENOTSUP)
16042                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
16043                                                 res->vf_id,
16044                                                 &stats);
16045 #endif
16046
16047         switch (ret) {
16048         case 0:
16049                 break;
16050         case -EINVAL:
16051                 printf("invalid vf_id %d\n", res->vf_id);
16052                 break;
16053         case -ENODEV:
16054                 printf("invalid port_id %d\n", res->port_id);
16055                 break;
16056         case -ENOTSUP:
16057                 printf("function not implemented\n");
16058                 break;
16059         default:
16060                 printf("programming error: (%s)\n", strerror(-ret));
16061         }
16062
16063         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
16064                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
16065
16066         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
16067                "%-"PRIu64"\n",
16068                stats.ipackets, stats.imissed, stats.ibytes);
16069         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
16070         printf("  RX-nombuf:  %-10"PRIu64"\n",
16071                stats.rx_nombuf);
16072         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
16073                "%-"PRIu64"\n",
16074                stats.opackets, stats.oerrors, stats.obytes);
16075
16076         printf("  %s############################%s\n",
16077                                nic_stats_border, nic_stats_border);
16078 }
16079
16080 cmdline_parse_inst_t cmd_show_vf_stats = {
16081         .f = cmd_show_vf_stats_parsed,
16082         .data = NULL,
16083         .help_str = "show vf stats <port_id> <vf_id>",
16084         .tokens = {
16085                 (void *)&cmd_show_vf_stats_show,
16086                 (void *)&cmd_show_vf_stats_vf,
16087                 (void *)&cmd_show_vf_stats_stats,
16088                 (void *)&cmd_show_vf_stats_port_id,
16089                 (void *)&cmd_show_vf_stats_vf_id,
16090                 NULL,
16091         },
16092 };
16093
16094 /* clear vf stats */
16095
16096 /* Common result structure for clear vf stats */
16097 struct cmd_clear_vf_stats_result {
16098         cmdline_fixed_string_t clear;
16099         cmdline_fixed_string_t vf;
16100         cmdline_fixed_string_t stats;
16101         portid_t port_id;
16102         uint16_t vf_id;
16103 };
16104
16105 /* Common CLI fields clear vf stats*/
16106 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
16107         TOKEN_STRING_INITIALIZER
16108                 (struct cmd_clear_vf_stats_result,
16109                  clear, "clear");
16110 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
16111         TOKEN_STRING_INITIALIZER
16112                 (struct cmd_clear_vf_stats_result,
16113                  vf, "vf");
16114 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
16115         TOKEN_STRING_INITIALIZER
16116                 (struct cmd_clear_vf_stats_result,
16117                  stats, "stats");
16118 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
16119         TOKEN_NUM_INITIALIZER
16120                 (struct cmd_clear_vf_stats_result,
16121                  port_id, UINT16);
16122 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
16123         TOKEN_NUM_INITIALIZER
16124                 (struct cmd_clear_vf_stats_result,
16125                  vf_id, UINT16);
16126
16127 static void
16128 cmd_clear_vf_stats_parsed(
16129         void *parsed_result,
16130         __rte_unused struct cmdline *cl,
16131         __rte_unused void *data)
16132 {
16133         struct cmd_clear_vf_stats_result *res = parsed_result;
16134         int ret = -ENOTSUP;
16135
16136         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16137                 return;
16138
16139 #ifdef RTE_NET_I40E
16140         if (ret == -ENOTSUP)
16141                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
16142                                                   res->vf_id);
16143 #endif
16144 #ifdef RTE_NET_BNXT
16145         if (ret == -ENOTSUP)
16146                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
16147                                                   res->vf_id);
16148 #endif
16149
16150         switch (ret) {
16151         case 0:
16152                 break;
16153         case -EINVAL:
16154                 printf("invalid vf_id %d\n", res->vf_id);
16155                 break;
16156         case -ENODEV:
16157                 printf("invalid port_id %d\n", res->port_id);
16158                 break;
16159         case -ENOTSUP:
16160                 printf("function not implemented\n");
16161                 break;
16162         default:
16163                 printf("programming error: (%s)\n", strerror(-ret));
16164         }
16165 }
16166
16167 cmdline_parse_inst_t cmd_clear_vf_stats = {
16168         .f = cmd_clear_vf_stats_parsed,
16169         .data = NULL,
16170         .help_str = "clear vf stats <port_id> <vf_id>",
16171         .tokens = {
16172                 (void *)&cmd_clear_vf_stats_clear,
16173                 (void *)&cmd_clear_vf_stats_vf,
16174                 (void *)&cmd_clear_vf_stats_stats,
16175                 (void *)&cmd_clear_vf_stats_port_id,
16176                 (void *)&cmd_clear_vf_stats_vf_id,
16177                 NULL,
16178         },
16179 };
16180
16181 /* port config pctype mapping reset */
16182
16183 /* Common result structure for port config pctype mapping reset */
16184 struct cmd_pctype_mapping_reset_result {
16185         cmdline_fixed_string_t port;
16186         cmdline_fixed_string_t config;
16187         portid_t port_id;
16188         cmdline_fixed_string_t pctype;
16189         cmdline_fixed_string_t mapping;
16190         cmdline_fixed_string_t reset;
16191 };
16192
16193 /* Common CLI fields for port config pctype mapping reset*/
16194 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
16195         TOKEN_STRING_INITIALIZER
16196                 (struct cmd_pctype_mapping_reset_result,
16197                  port, "port");
16198 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
16199         TOKEN_STRING_INITIALIZER
16200                 (struct cmd_pctype_mapping_reset_result,
16201                  config, "config");
16202 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
16203         TOKEN_NUM_INITIALIZER
16204                 (struct cmd_pctype_mapping_reset_result,
16205                  port_id, UINT16);
16206 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
16207         TOKEN_STRING_INITIALIZER
16208                 (struct cmd_pctype_mapping_reset_result,
16209                  pctype, "pctype");
16210 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
16211         TOKEN_STRING_INITIALIZER
16212                 (struct cmd_pctype_mapping_reset_result,
16213                  mapping, "mapping");
16214 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
16215         TOKEN_STRING_INITIALIZER
16216                 (struct cmd_pctype_mapping_reset_result,
16217                  reset, "reset");
16218
16219 static void
16220 cmd_pctype_mapping_reset_parsed(
16221         void *parsed_result,
16222         __rte_unused struct cmdline *cl,
16223         __rte_unused void *data)
16224 {
16225         struct cmd_pctype_mapping_reset_result *res = parsed_result;
16226         int ret = -ENOTSUP;
16227
16228         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16229                 return;
16230
16231 #ifdef RTE_NET_I40E
16232         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
16233 #endif
16234
16235         switch (ret) {
16236         case 0:
16237                 break;
16238         case -ENODEV:
16239                 printf("invalid port_id %d\n", res->port_id);
16240                 break;
16241         case -ENOTSUP:
16242                 printf("function not implemented\n");
16243                 break;
16244         default:
16245                 printf("programming error: (%s)\n", strerror(-ret));
16246         }
16247 }
16248
16249 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
16250         .f = cmd_pctype_mapping_reset_parsed,
16251         .data = NULL,
16252         .help_str = "port config <port_id> pctype mapping reset",
16253         .tokens = {
16254                 (void *)&cmd_pctype_mapping_reset_port,
16255                 (void *)&cmd_pctype_mapping_reset_config,
16256                 (void *)&cmd_pctype_mapping_reset_port_id,
16257                 (void *)&cmd_pctype_mapping_reset_pctype,
16258                 (void *)&cmd_pctype_mapping_reset_mapping,
16259                 (void *)&cmd_pctype_mapping_reset_reset,
16260                 NULL,
16261         },
16262 };
16263
16264 /* show port pctype mapping */
16265
16266 /* Common result structure for show port pctype mapping */
16267 struct cmd_pctype_mapping_get_result {
16268         cmdline_fixed_string_t show;
16269         cmdline_fixed_string_t port;
16270         portid_t port_id;
16271         cmdline_fixed_string_t pctype;
16272         cmdline_fixed_string_t mapping;
16273 };
16274
16275 /* Common CLI fields for pctype mapping get */
16276 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
16277         TOKEN_STRING_INITIALIZER
16278                 (struct cmd_pctype_mapping_get_result,
16279                  show, "show");
16280 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
16281         TOKEN_STRING_INITIALIZER
16282                 (struct cmd_pctype_mapping_get_result,
16283                  port, "port");
16284 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
16285         TOKEN_NUM_INITIALIZER
16286                 (struct cmd_pctype_mapping_get_result,
16287                  port_id, UINT16);
16288 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
16289         TOKEN_STRING_INITIALIZER
16290                 (struct cmd_pctype_mapping_get_result,
16291                  pctype, "pctype");
16292 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
16293         TOKEN_STRING_INITIALIZER
16294                 (struct cmd_pctype_mapping_get_result,
16295                  mapping, "mapping");
16296
16297 static void
16298 cmd_pctype_mapping_get_parsed(
16299         void *parsed_result,
16300         __rte_unused struct cmdline *cl,
16301         __rte_unused void *data)
16302 {
16303         struct cmd_pctype_mapping_get_result *res = parsed_result;
16304         int ret = -ENOTSUP;
16305 #ifdef RTE_NET_I40E
16306         struct rte_pmd_i40e_flow_type_mapping
16307                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
16308         int i, j, first_pctype;
16309 #endif
16310
16311         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16312                 return;
16313
16314 #ifdef RTE_NET_I40E
16315         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
16316 #endif
16317
16318         switch (ret) {
16319         case 0:
16320                 break;
16321         case -ENODEV:
16322                 printf("invalid port_id %d\n", res->port_id);
16323                 return;
16324         case -ENOTSUP:
16325                 printf("function not implemented\n");
16326                 return;
16327         default:
16328                 printf("programming error: (%s)\n", strerror(-ret));
16329                 return;
16330         }
16331
16332 #ifdef RTE_NET_I40E
16333         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
16334                 if (mapping[i].pctype != 0ULL) {
16335                         first_pctype = 1;
16336
16337                         printf("pctype: ");
16338                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
16339                                 if (mapping[i].pctype & (1ULL << j)) {
16340                                         printf(first_pctype ?
16341                                                "%02d" : ",%02d", j);
16342                                         first_pctype = 0;
16343                                 }
16344                         }
16345                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
16346                 }
16347         }
16348 #endif
16349 }
16350
16351 cmdline_parse_inst_t cmd_pctype_mapping_get = {
16352         .f = cmd_pctype_mapping_get_parsed,
16353         .data = NULL,
16354         .help_str = "show port <port_id> pctype mapping",
16355         .tokens = {
16356                 (void *)&cmd_pctype_mapping_get_show,
16357                 (void *)&cmd_pctype_mapping_get_port,
16358                 (void *)&cmd_pctype_mapping_get_port_id,
16359                 (void *)&cmd_pctype_mapping_get_pctype,
16360                 (void *)&cmd_pctype_mapping_get_mapping,
16361                 NULL,
16362         },
16363 };
16364
16365 /* port config pctype mapping update */
16366
16367 /* Common result structure for port config pctype mapping update */
16368 struct cmd_pctype_mapping_update_result {
16369         cmdline_fixed_string_t port;
16370         cmdline_fixed_string_t config;
16371         portid_t port_id;
16372         cmdline_fixed_string_t pctype;
16373         cmdline_fixed_string_t mapping;
16374         cmdline_fixed_string_t update;
16375         cmdline_fixed_string_t pctype_list;
16376         uint16_t flow_type;
16377 };
16378
16379 /* Common CLI fields for pctype mapping update*/
16380 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
16381         TOKEN_STRING_INITIALIZER
16382                 (struct cmd_pctype_mapping_update_result,
16383                  port, "port");
16384 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
16385         TOKEN_STRING_INITIALIZER
16386                 (struct cmd_pctype_mapping_update_result,
16387                  config, "config");
16388 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
16389         TOKEN_NUM_INITIALIZER
16390                 (struct cmd_pctype_mapping_update_result,
16391                  port_id, UINT16);
16392 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
16393         TOKEN_STRING_INITIALIZER
16394                 (struct cmd_pctype_mapping_update_result,
16395                  pctype, "pctype");
16396 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
16397         TOKEN_STRING_INITIALIZER
16398                 (struct cmd_pctype_mapping_update_result,
16399                  mapping, "mapping");
16400 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
16401         TOKEN_STRING_INITIALIZER
16402                 (struct cmd_pctype_mapping_update_result,
16403                  update, "update");
16404 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
16405         TOKEN_STRING_INITIALIZER
16406                 (struct cmd_pctype_mapping_update_result,
16407                  pctype_list, NULL);
16408 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
16409         TOKEN_NUM_INITIALIZER
16410                 (struct cmd_pctype_mapping_update_result,
16411                  flow_type, UINT16);
16412
16413 static void
16414 cmd_pctype_mapping_update_parsed(
16415         void *parsed_result,
16416         __rte_unused struct cmdline *cl,
16417         __rte_unused void *data)
16418 {
16419         struct cmd_pctype_mapping_update_result *res = parsed_result;
16420         int ret = -ENOTSUP;
16421 #ifdef RTE_NET_I40E
16422         struct rte_pmd_i40e_flow_type_mapping mapping;
16423         unsigned int i;
16424         unsigned int nb_item;
16425         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
16426 #endif
16427
16428         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16429                 return;
16430
16431 #ifdef RTE_NET_I40E
16432         nb_item = parse_item_list(res->pctype_list, "pctypes",
16433                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
16434         mapping.flow_type = res->flow_type;
16435         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
16436                 mapping.pctype |= (1ULL << pctype_list[i]);
16437         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
16438                                                 &mapping,
16439                                                 1,
16440                                                 0);
16441 #endif
16442
16443         switch (ret) {
16444         case 0:
16445                 break;
16446         case -EINVAL:
16447                 printf("invalid pctype or flow type\n");
16448                 break;
16449         case -ENODEV:
16450                 printf("invalid port_id %d\n", res->port_id);
16451                 break;
16452         case -ENOTSUP:
16453                 printf("function not implemented\n");
16454                 break;
16455         default:
16456                 printf("programming error: (%s)\n", strerror(-ret));
16457         }
16458 }
16459
16460 cmdline_parse_inst_t cmd_pctype_mapping_update = {
16461         .f = cmd_pctype_mapping_update_parsed,
16462         .data = NULL,
16463         .help_str = "port config <port_id> pctype mapping update"
16464         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
16465         .tokens = {
16466                 (void *)&cmd_pctype_mapping_update_port,
16467                 (void *)&cmd_pctype_mapping_update_config,
16468                 (void *)&cmd_pctype_mapping_update_port_id,
16469                 (void *)&cmd_pctype_mapping_update_pctype,
16470                 (void *)&cmd_pctype_mapping_update_mapping,
16471                 (void *)&cmd_pctype_mapping_update_update,
16472                 (void *)&cmd_pctype_mapping_update_pc_type,
16473                 (void *)&cmd_pctype_mapping_update_flow_type,
16474                 NULL,
16475         },
16476 };
16477
16478 /* ptype mapping get */
16479
16480 /* Common result structure for ptype mapping get */
16481 struct cmd_ptype_mapping_get_result {
16482         cmdline_fixed_string_t ptype;
16483         cmdline_fixed_string_t mapping;
16484         cmdline_fixed_string_t get;
16485         portid_t port_id;
16486         uint8_t valid_only;
16487 };
16488
16489 /* Common CLI fields for ptype mapping get */
16490 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
16491         TOKEN_STRING_INITIALIZER
16492                 (struct cmd_ptype_mapping_get_result,
16493                  ptype, "ptype");
16494 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
16495         TOKEN_STRING_INITIALIZER
16496                 (struct cmd_ptype_mapping_get_result,
16497                  mapping, "mapping");
16498 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
16499         TOKEN_STRING_INITIALIZER
16500                 (struct cmd_ptype_mapping_get_result,
16501                  get, "get");
16502 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
16503         TOKEN_NUM_INITIALIZER
16504                 (struct cmd_ptype_mapping_get_result,
16505                  port_id, UINT16);
16506 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
16507         TOKEN_NUM_INITIALIZER
16508                 (struct cmd_ptype_mapping_get_result,
16509                  valid_only, UINT8);
16510
16511 static void
16512 cmd_ptype_mapping_get_parsed(
16513         void *parsed_result,
16514         __rte_unused struct cmdline *cl,
16515         __rte_unused void *data)
16516 {
16517         struct cmd_ptype_mapping_get_result *res = parsed_result;
16518         int ret = -ENOTSUP;
16519 #ifdef RTE_NET_I40E
16520         int max_ptype_num = 256;
16521         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
16522         uint16_t count;
16523         int i;
16524 #endif
16525
16526         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16527                 return;
16528
16529 #ifdef RTE_NET_I40E
16530         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
16531                                         mapping,
16532                                         max_ptype_num,
16533                                         &count,
16534                                         res->valid_only);
16535 #endif
16536
16537         switch (ret) {
16538         case 0:
16539                 break;
16540         case -ENODEV:
16541                 printf("invalid port_id %d\n", res->port_id);
16542                 break;
16543         case -ENOTSUP:
16544                 printf("function not implemented\n");
16545                 break;
16546         default:
16547                 printf("programming error: (%s)\n", strerror(-ret));
16548         }
16549
16550 #ifdef RTE_NET_I40E
16551         if (!ret) {
16552                 for (i = 0; i < count; i++)
16553                         printf("%3d\t0x%08x\n",
16554                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
16555         }
16556 #endif
16557 }
16558
16559 cmdline_parse_inst_t cmd_ptype_mapping_get = {
16560         .f = cmd_ptype_mapping_get_parsed,
16561         .data = NULL,
16562         .help_str = "ptype mapping get <port_id> <valid_only>",
16563         .tokens = {
16564                 (void *)&cmd_ptype_mapping_get_ptype,
16565                 (void *)&cmd_ptype_mapping_get_mapping,
16566                 (void *)&cmd_ptype_mapping_get_get,
16567                 (void *)&cmd_ptype_mapping_get_port_id,
16568                 (void *)&cmd_ptype_mapping_get_valid_only,
16569                 NULL,
16570         },
16571 };
16572
16573 /* ptype mapping replace */
16574
16575 /* Common result structure for ptype mapping replace */
16576 struct cmd_ptype_mapping_replace_result {
16577         cmdline_fixed_string_t ptype;
16578         cmdline_fixed_string_t mapping;
16579         cmdline_fixed_string_t replace;
16580         portid_t port_id;
16581         uint32_t target;
16582         uint8_t mask;
16583         uint32_t pkt_type;
16584 };
16585
16586 /* Common CLI fields for ptype mapping replace */
16587 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
16588         TOKEN_STRING_INITIALIZER
16589                 (struct cmd_ptype_mapping_replace_result,
16590                  ptype, "ptype");
16591 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
16592         TOKEN_STRING_INITIALIZER
16593                 (struct cmd_ptype_mapping_replace_result,
16594                  mapping, "mapping");
16595 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
16596         TOKEN_STRING_INITIALIZER
16597                 (struct cmd_ptype_mapping_replace_result,
16598                  replace, "replace");
16599 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
16600         TOKEN_NUM_INITIALIZER
16601                 (struct cmd_ptype_mapping_replace_result,
16602                  port_id, UINT16);
16603 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
16604         TOKEN_NUM_INITIALIZER
16605                 (struct cmd_ptype_mapping_replace_result,
16606                  target, UINT32);
16607 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
16608         TOKEN_NUM_INITIALIZER
16609                 (struct cmd_ptype_mapping_replace_result,
16610                  mask, UINT8);
16611 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
16612         TOKEN_NUM_INITIALIZER
16613                 (struct cmd_ptype_mapping_replace_result,
16614                  pkt_type, UINT32);
16615
16616 static void
16617 cmd_ptype_mapping_replace_parsed(
16618         void *parsed_result,
16619         __rte_unused struct cmdline *cl,
16620         __rte_unused void *data)
16621 {
16622         struct cmd_ptype_mapping_replace_result *res = parsed_result;
16623         int ret = -ENOTSUP;
16624
16625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16626                 return;
16627
16628 #ifdef RTE_NET_I40E
16629         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
16630                                         res->target,
16631                                         res->mask,
16632                                         res->pkt_type);
16633 #endif
16634
16635         switch (ret) {
16636         case 0:
16637                 break;
16638         case -EINVAL:
16639                 printf("invalid ptype 0x%8x or 0x%8x\n",
16640                                 res->target, res->pkt_type);
16641                 break;
16642         case -ENODEV:
16643                 printf("invalid port_id %d\n", res->port_id);
16644                 break;
16645         case -ENOTSUP:
16646                 printf("function not implemented\n");
16647                 break;
16648         default:
16649                 printf("programming error: (%s)\n", strerror(-ret));
16650         }
16651 }
16652
16653 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
16654         .f = cmd_ptype_mapping_replace_parsed,
16655         .data = NULL,
16656         .help_str =
16657                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
16658         .tokens = {
16659                 (void *)&cmd_ptype_mapping_replace_ptype,
16660                 (void *)&cmd_ptype_mapping_replace_mapping,
16661                 (void *)&cmd_ptype_mapping_replace_replace,
16662                 (void *)&cmd_ptype_mapping_replace_port_id,
16663                 (void *)&cmd_ptype_mapping_replace_target,
16664                 (void *)&cmd_ptype_mapping_replace_mask,
16665                 (void *)&cmd_ptype_mapping_replace_pkt_type,
16666                 NULL,
16667         },
16668 };
16669
16670 /* ptype mapping reset */
16671
16672 /* Common result structure for ptype mapping reset */
16673 struct cmd_ptype_mapping_reset_result {
16674         cmdline_fixed_string_t ptype;
16675         cmdline_fixed_string_t mapping;
16676         cmdline_fixed_string_t reset;
16677         portid_t port_id;
16678 };
16679
16680 /* Common CLI fields for ptype mapping reset*/
16681 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
16682         TOKEN_STRING_INITIALIZER
16683                 (struct cmd_ptype_mapping_reset_result,
16684                  ptype, "ptype");
16685 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
16686         TOKEN_STRING_INITIALIZER
16687                 (struct cmd_ptype_mapping_reset_result,
16688                  mapping, "mapping");
16689 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
16690         TOKEN_STRING_INITIALIZER
16691                 (struct cmd_ptype_mapping_reset_result,
16692                  reset, "reset");
16693 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
16694         TOKEN_NUM_INITIALIZER
16695                 (struct cmd_ptype_mapping_reset_result,
16696                  port_id, UINT16);
16697
16698 static void
16699 cmd_ptype_mapping_reset_parsed(
16700         void *parsed_result,
16701         __rte_unused struct cmdline *cl,
16702         __rte_unused void *data)
16703 {
16704         struct cmd_ptype_mapping_reset_result *res = parsed_result;
16705         int ret = -ENOTSUP;
16706
16707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16708                 return;
16709
16710 #ifdef RTE_NET_I40E
16711         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
16712 #endif
16713
16714         switch (ret) {
16715         case 0:
16716                 break;
16717         case -ENODEV:
16718                 printf("invalid port_id %d\n", res->port_id);
16719                 break;
16720         case -ENOTSUP:
16721                 printf("function not implemented\n");
16722                 break;
16723         default:
16724                 printf("programming error: (%s)\n", strerror(-ret));
16725         }
16726 }
16727
16728 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
16729         .f = cmd_ptype_mapping_reset_parsed,
16730         .data = NULL,
16731         .help_str = "ptype mapping reset <port_id>",
16732         .tokens = {
16733                 (void *)&cmd_ptype_mapping_reset_ptype,
16734                 (void *)&cmd_ptype_mapping_reset_mapping,
16735                 (void *)&cmd_ptype_mapping_reset_reset,
16736                 (void *)&cmd_ptype_mapping_reset_port_id,
16737                 NULL,
16738         },
16739 };
16740
16741 /* ptype mapping update */
16742
16743 /* Common result structure for ptype mapping update */
16744 struct cmd_ptype_mapping_update_result {
16745         cmdline_fixed_string_t ptype;
16746         cmdline_fixed_string_t mapping;
16747         cmdline_fixed_string_t reset;
16748         portid_t port_id;
16749         uint8_t hw_ptype;
16750         uint32_t sw_ptype;
16751 };
16752
16753 /* Common CLI fields for ptype mapping update*/
16754 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
16755         TOKEN_STRING_INITIALIZER
16756                 (struct cmd_ptype_mapping_update_result,
16757                  ptype, "ptype");
16758 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
16759         TOKEN_STRING_INITIALIZER
16760                 (struct cmd_ptype_mapping_update_result,
16761                  mapping, "mapping");
16762 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
16763         TOKEN_STRING_INITIALIZER
16764                 (struct cmd_ptype_mapping_update_result,
16765                  reset, "update");
16766 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
16767         TOKEN_NUM_INITIALIZER
16768                 (struct cmd_ptype_mapping_update_result,
16769                  port_id, UINT16);
16770 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
16771         TOKEN_NUM_INITIALIZER
16772                 (struct cmd_ptype_mapping_update_result,
16773                  hw_ptype, UINT8);
16774 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
16775         TOKEN_NUM_INITIALIZER
16776                 (struct cmd_ptype_mapping_update_result,
16777                  sw_ptype, UINT32);
16778
16779 static void
16780 cmd_ptype_mapping_update_parsed(
16781         void *parsed_result,
16782         __rte_unused struct cmdline *cl,
16783         __rte_unused void *data)
16784 {
16785         struct cmd_ptype_mapping_update_result *res = parsed_result;
16786         int ret = -ENOTSUP;
16787 #ifdef RTE_NET_I40E
16788         struct rte_pmd_i40e_ptype_mapping mapping;
16789 #endif
16790         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
16791                 return;
16792
16793 #ifdef RTE_NET_I40E
16794         mapping.hw_ptype = res->hw_ptype;
16795         mapping.sw_ptype = res->sw_ptype;
16796         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
16797                                                 &mapping,
16798                                                 1,
16799                                                 0);
16800 #endif
16801
16802         switch (ret) {
16803         case 0:
16804                 break;
16805         case -EINVAL:
16806                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
16807                 break;
16808         case -ENODEV:
16809                 printf("invalid port_id %d\n", res->port_id);
16810                 break;
16811         case -ENOTSUP:
16812                 printf("function not implemented\n");
16813                 break;
16814         default:
16815                 printf("programming error: (%s)\n", strerror(-ret));
16816         }
16817 }
16818
16819 cmdline_parse_inst_t cmd_ptype_mapping_update = {
16820         .f = cmd_ptype_mapping_update_parsed,
16821         .data = NULL,
16822         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
16823         .tokens = {
16824                 (void *)&cmd_ptype_mapping_update_ptype,
16825                 (void *)&cmd_ptype_mapping_update_mapping,
16826                 (void *)&cmd_ptype_mapping_update_update,
16827                 (void *)&cmd_ptype_mapping_update_port_id,
16828                 (void *)&cmd_ptype_mapping_update_hw_ptype,
16829                 (void *)&cmd_ptype_mapping_update_sw_ptype,
16830                 NULL,
16831         },
16832 };
16833
16834 /* Common result structure for file commands */
16835 struct cmd_cmdfile_result {
16836         cmdline_fixed_string_t load;
16837         cmdline_fixed_string_t filename;
16838 };
16839
16840 /* Common CLI fields for file commands */
16841 cmdline_parse_token_string_t cmd_load_cmdfile =
16842         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
16843 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
16844         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
16845
16846 static void
16847 cmd_load_from_file_parsed(
16848         void *parsed_result,
16849         __rte_unused struct cmdline *cl,
16850         __rte_unused void *data)
16851 {
16852         struct cmd_cmdfile_result *res = parsed_result;
16853
16854         cmdline_read_from_file(res->filename);
16855 }
16856
16857 cmdline_parse_inst_t cmd_load_from_file = {
16858         .f = cmd_load_from_file_parsed,
16859         .data = NULL,
16860         .help_str = "load <filename>",
16861         .tokens = {
16862                 (void *)&cmd_load_cmdfile,
16863                 (void *)&cmd_load_cmdfile_filename,
16864                 NULL,
16865         },
16866 };
16867
16868 /* Get Rx offloads capabilities */
16869 struct cmd_rx_offload_get_capa_result {
16870         cmdline_fixed_string_t show;
16871         cmdline_fixed_string_t port;
16872         portid_t port_id;
16873         cmdline_fixed_string_t rx_offload;
16874         cmdline_fixed_string_t capabilities;
16875 };
16876
16877 cmdline_parse_token_string_t cmd_rx_offload_get_capa_show =
16878         TOKEN_STRING_INITIALIZER
16879                 (struct cmd_rx_offload_get_capa_result,
16880                  show, "show");
16881 cmdline_parse_token_string_t cmd_rx_offload_get_capa_port =
16882         TOKEN_STRING_INITIALIZER
16883                 (struct cmd_rx_offload_get_capa_result,
16884                  port, "port");
16885 cmdline_parse_token_num_t cmd_rx_offload_get_capa_port_id =
16886         TOKEN_NUM_INITIALIZER
16887                 (struct cmd_rx_offload_get_capa_result,
16888                  port_id, UINT16);
16889 cmdline_parse_token_string_t cmd_rx_offload_get_capa_rx_offload =
16890         TOKEN_STRING_INITIALIZER
16891                 (struct cmd_rx_offload_get_capa_result,
16892                  rx_offload, "rx_offload");
16893 cmdline_parse_token_string_t cmd_rx_offload_get_capa_capabilities =
16894         TOKEN_STRING_INITIALIZER
16895                 (struct cmd_rx_offload_get_capa_result,
16896                  capabilities, "capabilities");
16897
16898 static void
16899 print_rx_offloads(uint64_t offloads)
16900 {
16901         uint64_t single_offload;
16902         int begin;
16903         int end;
16904         int bit;
16905
16906         if (offloads == 0)
16907                 return;
16908
16909         begin = __builtin_ctzll(offloads);
16910         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
16911
16912         single_offload = 1ULL << begin;
16913         for (bit = begin; bit < end; bit++) {
16914                 if (offloads & single_offload)
16915                         printf(" %s",
16916                                rte_eth_dev_rx_offload_name(single_offload));
16917                 single_offload <<= 1;
16918         }
16919 }
16920
16921 static void
16922 cmd_rx_offload_get_capa_parsed(
16923         void *parsed_result,
16924         __rte_unused struct cmdline *cl,
16925         __rte_unused void *data)
16926 {
16927         struct cmd_rx_offload_get_capa_result *res = parsed_result;
16928         struct rte_eth_dev_info dev_info;
16929         portid_t port_id = res->port_id;
16930         uint64_t queue_offloads;
16931         uint64_t port_offloads;
16932         int ret;
16933
16934         ret = eth_dev_info_get_print_err(port_id, &dev_info);
16935         if (ret != 0)
16936                 return;
16937
16938         queue_offloads = dev_info.rx_queue_offload_capa;
16939         port_offloads = dev_info.rx_offload_capa ^ queue_offloads;
16940
16941         printf("Rx Offloading Capabilities of port %d :\n", port_id);
16942         printf("  Per Queue :");
16943         print_rx_offloads(queue_offloads);
16944
16945         printf("\n");
16946         printf("  Per Port  :");
16947         print_rx_offloads(port_offloads);
16948         printf("\n\n");
16949 }
16950
16951 cmdline_parse_inst_t cmd_rx_offload_get_capa = {
16952         .f = cmd_rx_offload_get_capa_parsed,
16953         .data = NULL,
16954         .help_str = "show port <port_id> rx_offload capabilities",
16955         .tokens = {
16956                 (void *)&cmd_rx_offload_get_capa_show,
16957                 (void *)&cmd_rx_offload_get_capa_port,
16958                 (void *)&cmd_rx_offload_get_capa_port_id,
16959                 (void *)&cmd_rx_offload_get_capa_rx_offload,
16960                 (void *)&cmd_rx_offload_get_capa_capabilities,
16961                 NULL,
16962         }
16963 };
16964
16965 /* Get Rx offloads configuration */
16966 struct cmd_rx_offload_get_configuration_result {
16967         cmdline_fixed_string_t show;
16968         cmdline_fixed_string_t port;
16969         portid_t port_id;
16970         cmdline_fixed_string_t rx_offload;
16971         cmdline_fixed_string_t configuration;
16972 };
16973
16974 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_show =
16975         TOKEN_STRING_INITIALIZER
16976                 (struct cmd_rx_offload_get_configuration_result,
16977                  show, "show");
16978 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_port =
16979         TOKEN_STRING_INITIALIZER
16980                 (struct cmd_rx_offload_get_configuration_result,
16981                  port, "port");
16982 cmdline_parse_token_num_t cmd_rx_offload_get_configuration_port_id =
16983         TOKEN_NUM_INITIALIZER
16984                 (struct cmd_rx_offload_get_configuration_result,
16985                  port_id, UINT16);
16986 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_rx_offload =
16987         TOKEN_STRING_INITIALIZER
16988                 (struct cmd_rx_offload_get_configuration_result,
16989                  rx_offload, "rx_offload");
16990 cmdline_parse_token_string_t cmd_rx_offload_get_configuration_configuration =
16991         TOKEN_STRING_INITIALIZER
16992                 (struct cmd_rx_offload_get_configuration_result,
16993                  configuration, "configuration");
16994
16995 static void
16996 cmd_rx_offload_get_configuration_parsed(
16997         void *parsed_result,
16998         __rte_unused struct cmdline *cl,
16999         __rte_unused void *data)
17000 {
17001         struct cmd_rx_offload_get_configuration_result *res = parsed_result;
17002         struct rte_eth_dev_info dev_info;
17003         portid_t port_id = res->port_id;
17004         struct rte_port *port = &ports[port_id];
17005         uint64_t port_offloads;
17006         uint64_t queue_offloads;
17007         uint16_t nb_rx_queues;
17008         int q;
17009         int ret;
17010
17011         printf("Rx Offloading Configuration of port %d :\n", port_id);
17012
17013         port_offloads = port->dev_conf.rxmode.offloads;
17014         printf("  Port :");
17015         print_rx_offloads(port_offloads);
17016         printf("\n");
17017
17018         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17019         if (ret != 0)
17020                 return;
17021
17022         nb_rx_queues = dev_info.nb_rx_queues;
17023         for (q = 0; q < nb_rx_queues; q++) {
17024                 queue_offloads = port->rx_conf[q].offloads;
17025                 printf("  Queue[%2d] :", q);
17026                 print_rx_offloads(queue_offloads);
17027                 printf("\n");
17028         }
17029         printf("\n");
17030 }
17031
17032 cmdline_parse_inst_t cmd_rx_offload_get_configuration = {
17033         .f = cmd_rx_offload_get_configuration_parsed,
17034         .data = NULL,
17035         .help_str = "show port <port_id> rx_offload configuration",
17036         .tokens = {
17037                 (void *)&cmd_rx_offload_get_configuration_show,
17038                 (void *)&cmd_rx_offload_get_configuration_port,
17039                 (void *)&cmd_rx_offload_get_configuration_port_id,
17040                 (void *)&cmd_rx_offload_get_configuration_rx_offload,
17041                 (void *)&cmd_rx_offload_get_configuration_configuration,
17042                 NULL,
17043         }
17044 };
17045
17046 /* Enable/Disable a per port offloading */
17047 struct cmd_config_per_port_rx_offload_result {
17048         cmdline_fixed_string_t port;
17049         cmdline_fixed_string_t config;
17050         portid_t port_id;
17051         cmdline_fixed_string_t rx_offload;
17052         cmdline_fixed_string_t offload;
17053         cmdline_fixed_string_t on_off;
17054 };
17055
17056 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_port =
17057         TOKEN_STRING_INITIALIZER
17058                 (struct cmd_config_per_port_rx_offload_result,
17059                  port, "port");
17060 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_config =
17061         TOKEN_STRING_INITIALIZER
17062                 (struct cmd_config_per_port_rx_offload_result,
17063                  config, "config");
17064 cmdline_parse_token_num_t cmd_config_per_port_rx_offload_result_port_id =
17065         TOKEN_NUM_INITIALIZER
17066                 (struct cmd_config_per_port_rx_offload_result,
17067                  port_id, UINT16);
17068 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_rx_offload =
17069         TOKEN_STRING_INITIALIZER
17070                 (struct cmd_config_per_port_rx_offload_result,
17071                  rx_offload, "rx_offload");
17072 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_offload =
17073         TOKEN_STRING_INITIALIZER
17074                 (struct cmd_config_per_port_rx_offload_result,
17075                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17076                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17077                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17078                            "scatter#buffer_split#timestamp#security#"
17079                            "keep_crc#rss_hash");
17080 cmdline_parse_token_string_t cmd_config_per_port_rx_offload_result_on_off =
17081         TOKEN_STRING_INITIALIZER
17082                 (struct cmd_config_per_port_rx_offload_result,
17083                  on_off, "on#off");
17084
17085 static uint64_t
17086 search_rx_offload(const char *name)
17087 {
17088         uint64_t single_offload;
17089         const char *single_name;
17090         int found = 0;
17091         unsigned int bit;
17092
17093         single_offload = 1;
17094         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17095                 single_name = rte_eth_dev_rx_offload_name(single_offload);
17096                 if (!strcasecmp(single_name, name)) {
17097                         found = 1;
17098                         break;
17099                 }
17100                 single_offload <<= 1;
17101         }
17102
17103         if (found)
17104                 return single_offload;
17105
17106         return 0;
17107 }
17108
17109 static void
17110 cmd_config_per_port_rx_offload_parsed(void *parsed_result,
17111                                 __rte_unused struct cmdline *cl,
17112                                 __rte_unused void *data)
17113 {
17114         struct cmd_config_per_port_rx_offload_result *res = parsed_result;
17115         portid_t port_id = res->port_id;
17116         struct rte_eth_dev_info dev_info;
17117         struct rte_port *port = &ports[port_id];
17118         uint64_t single_offload;
17119         uint16_t nb_rx_queues;
17120         int q;
17121         int ret;
17122
17123         if (port->port_status != RTE_PORT_STOPPED) {
17124                 printf("Error: Can't config offload when Port %d "
17125                        "is not stopped\n", port_id);
17126                 return;
17127         }
17128
17129         single_offload = search_rx_offload(res->offload);
17130         if (single_offload == 0) {
17131                 printf("Unknown offload name: %s\n", res->offload);
17132                 return;
17133         }
17134
17135         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17136         if (ret != 0)
17137                 return;
17138
17139         nb_rx_queues = dev_info.nb_rx_queues;
17140         if (!strcmp(res->on_off, "on")) {
17141                 port->dev_conf.rxmode.offloads |= single_offload;
17142                 for (q = 0; q < nb_rx_queues; q++)
17143                         port->rx_conf[q].offloads |= single_offload;
17144         } else {
17145                 port->dev_conf.rxmode.offloads &= ~single_offload;
17146                 for (q = 0; q < nb_rx_queues; q++)
17147                         port->rx_conf[q].offloads &= ~single_offload;
17148         }
17149
17150         cmd_reconfig_device_queue(port_id, 1, 1);
17151 }
17152
17153 cmdline_parse_inst_t cmd_config_per_port_rx_offload = {
17154         .f = cmd_config_per_port_rx_offload_parsed,
17155         .data = NULL,
17156         .help_str = "port config <port_id> rx_offload vlan_strip|ipv4_cksum|"
17157                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17158                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17159                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
17160                     "keep_crc|rss_hash on|off",
17161         .tokens = {
17162                 (void *)&cmd_config_per_port_rx_offload_result_port,
17163                 (void *)&cmd_config_per_port_rx_offload_result_config,
17164                 (void *)&cmd_config_per_port_rx_offload_result_port_id,
17165                 (void *)&cmd_config_per_port_rx_offload_result_rx_offload,
17166                 (void *)&cmd_config_per_port_rx_offload_result_offload,
17167                 (void *)&cmd_config_per_port_rx_offload_result_on_off,
17168                 NULL,
17169         }
17170 };
17171
17172 /* Enable/Disable a per queue offloading */
17173 struct cmd_config_per_queue_rx_offload_result {
17174         cmdline_fixed_string_t port;
17175         portid_t port_id;
17176         cmdline_fixed_string_t rxq;
17177         uint16_t queue_id;
17178         cmdline_fixed_string_t rx_offload;
17179         cmdline_fixed_string_t offload;
17180         cmdline_fixed_string_t on_off;
17181 };
17182
17183 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_port =
17184         TOKEN_STRING_INITIALIZER
17185                 (struct cmd_config_per_queue_rx_offload_result,
17186                  port, "port");
17187 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_port_id =
17188         TOKEN_NUM_INITIALIZER
17189                 (struct cmd_config_per_queue_rx_offload_result,
17190                  port_id, UINT16);
17191 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxq =
17192         TOKEN_STRING_INITIALIZER
17193                 (struct cmd_config_per_queue_rx_offload_result,
17194                  rxq, "rxq");
17195 cmdline_parse_token_num_t cmd_config_per_queue_rx_offload_result_queue_id =
17196         TOKEN_NUM_INITIALIZER
17197                 (struct cmd_config_per_queue_rx_offload_result,
17198                  queue_id, UINT16);
17199 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_rxoffload =
17200         TOKEN_STRING_INITIALIZER
17201                 (struct cmd_config_per_queue_rx_offload_result,
17202                  rx_offload, "rx_offload");
17203 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_offload =
17204         TOKEN_STRING_INITIALIZER
17205                 (struct cmd_config_per_queue_rx_offload_result,
17206                  offload, "vlan_strip#ipv4_cksum#udp_cksum#tcp_cksum#tcp_lro#"
17207                            "qinq_strip#outer_ipv4_cksum#macsec_strip#"
17208                            "header_split#vlan_filter#vlan_extend#jumbo_frame#"
17209                            "scatter#buffer_split#timestamp#security#keep_crc");
17210 cmdline_parse_token_string_t cmd_config_per_queue_rx_offload_result_on_off =
17211         TOKEN_STRING_INITIALIZER
17212                 (struct cmd_config_per_queue_rx_offload_result,
17213                  on_off, "on#off");
17214
17215 static void
17216 cmd_config_per_queue_rx_offload_parsed(void *parsed_result,
17217                                 __rte_unused struct cmdline *cl,
17218                                 __rte_unused void *data)
17219 {
17220         struct cmd_config_per_queue_rx_offload_result *res = parsed_result;
17221         struct rte_eth_dev_info dev_info;
17222         portid_t port_id = res->port_id;
17223         uint16_t queue_id = res->queue_id;
17224         struct rte_port *port = &ports[port_id];
17225         uint64_t single_offload;
17226         int ret;
17227
17228         if (port->port_status != RTE_PORT_STOPPED) {
17229                 printf("Error: Can't config offload when Port %d "
17230                        "is not stopped\n", port_id);
17231                 return;
17232         }
17233
17234         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17235         if (ret != 0)
17236                 return;
17237
17238         if (queue_id >= dev_info.nb_rx_queues) {
17239                 printf("Error: input queue_id should be 0 ... "
17240                        "%d\n", dev_info.nb_rx_queues - 1);
17241                 return;
17242         }
17243
17244         single_offload = search_rx_offload(res->offload);
17245         if (single_offload == 0) {
17246                 printf("Unknown offload name: %s\n", res->offload);
17247                 return;
17248         }
17249
17250         if (!strcmp(res->on_off, "on"))
17251                 port->rx_conf[queue_id].offloads |= single_offload;
17252         else
17253                 port->rx_conf[queue_id].offloads &= ~single_offload;
17254
17255         cmd_reconfig_device_queue(port_id, 1, 1);
17256 }
17257
17258 cmdline_parse_inst_t cmd_config_per_queue_rx_offload = {
17259         .f = cmd_config_per_queue_rx_offload_parsed,
17260         .data = NULL,
17261         .help_str = "port <port_id> rxq <queue_id> rx_offload "
17262                     "vlan_strip|ipv4_cksum|"
17263                     "udp_cksum|tcp_cksum|tcp_lro|qinq_strip|outer_ipv4_cksum|"
17264                     "macsec_strip|header_split|vlan_filter|vlan_extend|"
17265                     "jumbo_frame|scatter|buffer_split|timestamp|security|"
17266                     "keep_crc on|off",
17267         .tokens = {
17268                 (void *)&cmd_config_per_queue_rx_offload_result_port,
17269                 (void *)&cmd_config_per_queue_rx_offload_result_port_id,
17270                 (void *)&cmd_config_per_queue_rx_offload_result_rxq,
17271                 (void *)&cmd_config_per_queue_rx_offload_result_queue_id,
17272                 (void *)&cmd_config_per_queue_rx_offload_result_rxoffload,
17273                 (void *)&cmd_config_per_queue_rx_offload_result_offload,
17274                 (void *)&cmd_config_per_queue_rx_offload_result_on_off,
17275                 NULL,
17276         }
17277 };
17278
17279 /* Get Tx offloads capabilities */
17280 struct cmd_tx_offload_get_capa_result {
17281         cmdline_fixed_string_t show;
17282         cmdline_fixed_string_t port;
17283         portid_t port_id;
17284         cmdline_fixed_string_t tx_offload;
17285         cmdline_fixed_string_t capabilities;
17286 };
17287
17288 cmdline_parse_token_string_t cmd_tx_offload_get_capa_show =
17289         TOKEN_STRING_INITIALIZER
17290                 (struct cmd_tx_offload_get_capa_result,
17291                  show, "show");
17292 cmdline_parse_token_string_t cmd_tx_offload_get_capa_port =
17293         TOKEN_STRING_INITIALIZER
17294                 (struct cmd_tx_offload_get_capa_result,
17295                  port, "port");
17296 cmdline_parse_token_num_t cmd_tx_offload_get_capa_port_id =
17297         TOKEN_NUM_INITIALIZER
17298                 (struct cmd_tx_offload_get_capa_result,
17299                  port_id, UINT16);
17300 cmdline_parse_token_string_t cmd_tx_offload_get_capa_tx_offload =
17301         TOKEN_STRING_INITIALIZER
17302                 (struct cmd_tx_offload_get_capa_result,
17303                  tx_offload, "tx_offload");
17304 cmdline_parse_token_string_t cmd_tx_offload_get_capa_capabilities =
17305         TOKEN_STRING_INITIALIZER
17306                 (struct cmd_tx_offload_get_capa_result,
17307                  capabilities, "capabilities");
17308
17309 static void
17310 print_tx_offloads(uint64_t offloads)
17311 {
17312         uint64_t single_offload;
17313         int begin;
17314         int end;
17315         int bit;
17316
17317         if (offloads == 0)
17318                 return;
17319
17320         begin = __builtin_ctzll(offloads);
17321         end = sizeof(offloads) * CHAR_BIT - __builtin_clzll(offloads);
17322
17323         single_offload = 1ULL << begin;
17324         for (bit = begin; bit < end; bit++) {
17325                 if (offloads & single_offload)
17326                         printf(" %s",
17327                                rte_eth_dev_tx_offload_name(single_offload));
17328                 single_offload <<= 1;
17329         }
17330 }
17331
17332 static void
17333 cmd_tx_offload_get_capa_parsed(
17334         void *parsed_result,
17335         __rte_unused struct cmdline *cl,
17336         __rte_unused void *data)
17337 {
17338         struct cmd_tx_offload_get_capa_result *res = parsed_result;
17339         struct rte_eth_dev_info dev_info;
17340         portid_t port_id = res->port_id;
17341         uint64_t queue_offloads;
17342         uint64_t port_offloads;
17343         int ret;
17344
17345         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17346         if (ret != 0)
17347                 return;
17348
17349         queue_offloads = dev_info.tx_queue_offload_capa;
17350         port_offloads = dev_info.tx_offload_capa ^ queue_offloads;
17351
17352         printf("Tx Offloading Capabilities of port %d :\n", port_id);
17353         printf("  Per Queue :");
17354         print_tx_offloads(queue_offloads);
17355
17356         printf("\n");
17357         printf("  Per Port  :");
17358         print_tx_offloads(port_offloads);
17359         printf("\n\n");
17360 }
17361
17362 cmdline_parse_inst_t cmd_tx_offload_get_capa = {
17363         .f = cmd_tx_offload_get_capa_parsed,
17364         .data = NULL,
17365         .help_str = "show port <port_id> tx_offload capabilities",
17366         .tokens = {
17367                 (void *)&cmd_tx_offload_get_capa_show,
17368                 (void *)&cmd_tx_offload_get_capa_port,
17369                 (void *)&cmd_tx_offload_get_capa_port_id,
17370                 (void *)&cmd_tx_offload_get_capa_tx_offload,
17371                 (void *)&cmd_tx_offload_get_capa_capabilities,
17372                 NULL,
17373         }
17374 };
17375
17376 /* Get Tx offloads configuration */
17377 struct cmd_tx_offload_get_configuration_result {
17378         cmdline_fixed_string_t show;
17379         cmdline_fixed_string_t port;
17380         portid_t port_id;
17381         cmdline_fixed_string_t tx_offload;
17382         cmdline_fixed_string_t configuration;
17383 };
17384
17385 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_show =
17386         TOKEN_STRING_INITIALIZER
17387                 (struct cmd_tx_offload_get_configuration_result,
17388                  show, "show");
17389 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_port =
17390         TOKEN_STRING_INITIALIZER
17391                 (struct cmd_tx_offload_get_configuration_result,
17392                  port, "port");
17393 cmdline_parse_token_num_t cmd_tx_offload_get_configuration_port_id =
17394         TOKEN_NUM_INITIALIZER
17395                 (struct cmd_tx_offload_get_configuration_result,
17396                  port_id, UINT16);
17397 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_tx_offload =
17398         TOKEN_STRING_INITIALIZER
17399                 (struct cmd_tx_offload_get_configuration_result,
17400                  tx_offload, "tx_offload");
17401 cmdline_parse_token_string_t cmd_tx_offload_get_configuration_configuration =
17402         TOKEN_STRING_INITIALIZER
17403                 (struct cmd_tx_offload_get_configuration_result,
17404                  configuration, "configuration");
17405
17406 static void
17407 cmd_tx_offload_get_configuration_parsed(
17408         void *parsed_result,
17409         __rte_unused struct cmdline *cl,
17410         __rte_unused void *data)
17411 {
17412         struct cmd_tx_offload_get_configuration_result *res = parsed_result;
17413         struct rte_eth_dev_info dev_info;
17414         portid_t port_id = res->port_id;
17415         struct rte_port *port = &ports[port_id];
17416         uint64_t port_offloads;
17417         uint64_t queue_offloads;
17418         uint16_t nb_tx_queues;
17419         int q;
17420         int ret;
17421
17422         printf("Tx Offloading Configuration of port %d :\n", port_id);
17423
17424         port_offloads = port->dev_conf.txmode.offloads;
17425         printf("  Port :");
17426         print_tx_offloads(port_offloads);
17427         printf("\n");
17428
17429         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17430         if (ret != 0)
17431                 return;
17432
17433         nb_tx_queues = dev_info.nb_tx_queues;
17434         for (q = 0; q < nb_tx_queues; q++) {
17435                 queue_offloads = port->tx_conf[q].offloads;
17436                 printf("  Queue[%2d] :", q);
17437                 print_tx_offloads(queue_offloads);
17438                 printf("\n");
17439         }
17440         printf("\n");
17441 }
17442
17443 cmdline_parse_inst_t cmd_tx_offload_get_configuration = {
17444         .f = cmd_tx_offload_get_configuration_parsed,
17445         .data = NULL,
17446         .help_str = "show port <port_id> tx_offload configuration",
17447         .tokens = {
17448                 (void *)&cmd_tx_offload_get_configuration_show,
17449                 (void *)&cmd_tx_offload_get_configuration_port,
17450                 (void *)&cmd_tx_offload_get_configuration_port_id,
17451                 (void *)&cmd_tx_offload_get_configuration_tx_offload,
17452                 (void *)&cmd_tx_offload_get_configuration_configuration,
17453                 NULL,
17454         }
17455 };
17456
17457 /* Enable/Disable a per port offloading */
17458 struct cmd_config_per_port_tx_offload_result {
17459         cmdline_fixed_string_t port;
17460         cmdline_fixed_string_t config;
17461         portid_t port_id;
17462         cmdline_fixed_string_t tx_offload;
17463         cmdline_fixed_string_t offload;
17464         cmdline_fixed_string_t on_off;
17465 };
17466
17467 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_port =
17468         TOKEN_STRING_INITIALIZER
17469                 (struct cmd_config_per_port_tx_offload_result,
17470                  port, "port");
17471 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_config =
17472         TOKEN_STRING_INITIALIZER
17473                 (struct cmd_config_per_port_tx_offload_result,
17474                  config, "config");
17475 cmdline_parse_token_num_t cmd_config_per_port_tx_offload_result_port_id =
17476         TOKEN_NUM_INITIALIZER
17477                 (struct cmd_config_per_port_tx_offload_result,
17478                  port_id, UINT16);
17479 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_tx_offload =
17480         TOKEN_STRING_INITIALIZER
17481                 (struct cmd_config_per_port_tx_offload_result,
17482                  tx_offload, "tx_offload");
17483 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_offload =
17484         TOKEN_STRING_INITIALIZER
17485                 (struct cmd_config_per_port_tx_offload_result,
17486                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17487                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17488                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17489                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17490                           "mt_lockfree#multi_segs#mbuf_fast_free#security#"
17491                           "send_on_timestamp");
17492 cmdline_parse_token_string_t cmd_config_per_port_tx_offload_result_on_off =
17493         TOKEN_STRING_INITIALIZER
17494                 (struct cmd_config_per_port_tx_offload_result,
17495                  on_off, "on#off");
17496
17497 static uint64_t
17498 search_tx_offload(const char *name)
17499 {
17500         uint64_t single_offload;
17501         const char *single_name;
17502         int found = 0;
17503         unsigned int bit;
17504
17505         single_offload = 1;
17506         for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
17507                 single_name = rte_eth_dev_tx_offload_name(single_offload);
17508                 if (single_name == NULL)
17509                         break;
17510                 if (!strcasecmp(single_name, name)) {
17511                         found = 1;
17512                         break;
17513                 } else if (!strcasecmp(single_name, "UNKNOWN"))
17514                         break;
17515                 single_offload <<= 1;
17516         }
17517
17518         if (found)
17519                 return single_offload;
17520
17521         return 0;
17522 }
17523
17524 static void
17525 cmd_config_per_port_tx_offload_parsed(void *parsed_result,
17526                                 __rte_unused struct cmdline *cl,
17527                                 __rte_unused void *data)
17528 {
17529         struct cmd_config_per_port_tx_offload_result *res = parsed_result;
17530         portid_t port_id = res->port_id;
17531         struct rte_eth_dev_info dev_info;
17532         struct rte_port *port = &ports[port_id];
17533         uint64_t single_offload;
17534         uint16_t nb_tx_queues;
17535         int q;
17536         int ret;
17537
17538         if (port->port_status != RTE_PORT_STOPPED) {
17539                 printf("Error: Can't config offload when Port %d "
17540                        "is not stopped\n", port_id);
17541                 return;
17542         }
17543
17544         single_offload = search_tx_offload(res->offload);
17545         if (single_offload == 0) {
17546                 printf("Unknown offload name: %s\n", res->offload);
17547                 return;
17548         }
17549
17550         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17551         if (ret != 0)
17552                 return;
17553
17554         nb_tx_queues = dev_info.nb_tx_queues;
17555         if (!strcmp(res->on_off, "on")) {
17556                 port->dev_conf.txmode.offloads |= single_offload;
17557                 for (q = 0; q < nb_tx_queues; q++)
17558                         port->tx_conf[q].offloads |= single_offload;
17559         } else {
17560                 port->dev_conf.txmode.offloads &= ~single_offload;
17561                 for (q = 0; q < nb_tx_queues; q++)
17562                         port->tx_conf[q].offloads &= ~single_offload;
17563         }
17564
17565         cmd_reconfig_device_queue(port_id, 1, 1);
17566 }
17567
17568 cmdline_parse_inst_t cmd_config_per_port_tx_offload = {
17569         .f = cmd_config_per_port_tx_offload_parsed,
17570         .data = NULL,
17571         .help_str = "port config <port_id> tx_offload "
17572                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17573                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17574                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17575                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17576                     "mt_lockfree|multi_segs|mbuf_fast_free|security|"
17577                     "send_on_timestamp on|off",
17578         .tokens = {
17579                 (void *)&cmd_config_per_port_tx_offload_result_port,
17580                 (void *)&cmd_config_per_port_tx_offload_result_config,
17581                 (void *)&cmd_config_per_port_tx_offload_result_port_id,
17582                 (void *)&cmd_config_per_port_tx_offload_result_tx_offload,
17583                 (void *)&cmd_config_per_port_tx_offload_result_offload,
17584                 (void *)&cmd_config_per_port_tx_offload_result_on_off,
17585                 NULL,
17586         }
17587 };
17588
17589 /* Enable/Disable a per queue offloading */
17590 struct cmd_config_per_queue_tx_offload_result {
17591         cmdline_fixed_string_t port;
17592         portid_t port_id;
17593         cmdline_fixed_string_t txq;
17594         uint16_t queue_id;
17595         cmdline_fixed_string_t tx_offload;
17596         cmdline_fixed_string_t offload;
17597         cmdline_fixed_string_t on_off;
17598 };
17599
17600 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_port =
17601         TOKEN_STRING_INITIALIZER
17602                 (struct cmd_config_per_queue_tx_offload_result,
17603                  port, "port");
17604 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_port_id =
17605         TOKEN_NUM_INITIALIZER
17606                 (struct cmd_config_per_queue_tx_offload_result,
17607                  port_id, UINT16);
17608 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txq =
17609         TOKEN_STRING_INITIALIZER
17610                 (struct cmd_config_per_queue_tx_offload_result,
17611                  txq, "txq");
17612 cmdline_parse_token_num_t cmd_config_per_queue_tx_offload_result_queue_id =
17613         TOKEN_NUM_INITIALIZER
17614                 (struct cmd_config_per_queue_tx_offload_result,
17615                  queue_id, UINT16);
17616 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_txoffload =
17617         TOKEN_STRING_INITIALIZER
17618                 (struct cmd_config_per_queue_tx_offload_result,
17619                  tx_offload, "tx_offload");
17620 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_offload =
17621         TOKEN_STRING_INITIALIZER
17622                 (struct cmd_config_per_queue_tx_offload_result,
17623                  offload, "vlan_insert#ipv4_cksum#udp_cksum#tcp_cksum#"
17624                           "sctp_cksum#tcp_tso#udp_tso#outer_ipv4_cksum#"
17625                           "qinq_insert#vxlan_tnl_tso#gre_tnl_tso#"
17626                           "ipip_tnl_tso#geneve_tnl_tso#macsec_insert#"
17627                           "mt_lockfree#multi_segs#mbuf_fast_free#security");
17628 cmdline_parse_token_string_t cmd_config_per_queue_tx_offload_result_on_off =
17629         TOKEN_STRING_INITIALIZER
17630                 (struct cmd_config_per_queue_tx_offload_result,
17631                  on_off, "on#off");
17632
17633 static void
17634 cmd_config_per_queue_tx_offload_parsed(void *parsed_result,
17635                                 __rte_unused struct cmdline *cl,
17636                                 __rte_unused void *data)
17637 {
17638         struct cmd_config_per_queue_tx_offload_result *res = parsed_result;
17639         struct rte_eth_dev_info dev_info;
17640         portid_t port_id = res->port_id;
17641         uint16_t queue_id = res->queue_id;
17642         struct rte_port *port = &ports[port_id];
17643         uint64_t single_offload;
17644         int ret;
17645
17646         if (port->port_status != RTE_PORT_STOPPED) {
17647                 printf("Error: Can't config offload when Port %d "
17648                        "is not stopped\n", port_id);
17649                 return;
17650         }
17651
17652         ret = eth_dev_info_get_print_err(port_id, &dev_info);
17653         if (ret != 0)
17654                 return;
17655
17656         if (queue_id >= dev_info.nb_tx_queues) {
17657                 printf("Error: input queue_id should be 0 ... "
17658                        "%d\n", dev_info.nb_tx_queues - 1);
17659                 return;
17660         }
17661
17662         single_offload = search_tx_offload(res->offload);
17663         if (single_offload == 0) {
17664                 printf("Unknown offload name: %s\n", res->offload);
17665                 return;
17666         }
17667
17668         if (!strcmp(res->on_off, "on"))
17669                 port->tx_conf[queue_id].offloads |= single_offload;
17670         else
17671                 port->tx_conf[queue_id].offloads &= ~single_offload;
17672
17673         cmd_reconfig_device_queue(port_id, 1, 1);
17674 }
17675
17676 cmdline_parse_inst_t cmd_config_per_queue_tx_offload = {
17677         .f = cmd_config_per_queue_tx_offload_parsed,
17678         .data = NULL,
17679         .help_str = "port <port_id> txq <queue_id> tx_offload "
17680                     "vlan_insert|ipv4_cksum|udp_cksum|tcp_cksum|"
17681                     "sctp_cksum|tcp_tso|udp_tso|outer_ipv4_cksum|"
17682                     "qinq_insert|vxlan_tnl_tso|gre_tnl_tso|"
17683                     "ipip_tnl_tso|geneve_tnl_tso|macsec_insert|"
17684                     "mt_lockfree|multi_segs|mbuf_fast_free|security "
17685                     "on|off",
17686         .tokens = {
17687                 (void *)&cmd_config_per_queue_tx_offload_result_port,
17688                 (void *)&cmd_config_per_queue_tx_offload_result_port_id,
17689                 (void *)&cmd_config_per_queue_tx_offload_result_txq,
17690                 (void *)&cmd_config_per_queue_tx_offload_result_queue_id,
17691                 (void *)&cmd_config_per_queue_tx_offload_result_txoffload,
17692                 (void *)&cmd_config_per_queue_tx_offload_result_offload,
17693                 (void *)&cmd_config_per_queue_tx_offload_result_on_off,
17694                 NULL,
17695         }
17696 };
17697
17698 /* *** configure tx_metadata for specific port *** */
17699 struct cmd_config_tx_metadata_specific_result {
17700         cmdline_fixed_string_t port;
17701         cmdline_fixed_string_t keyword;
17702         uint16_t port_id;
17703         cmdline_fixed_string_t item;
17704         uint32_t value;
17705 };
17706
17707 static void
17708 cmd_config_tx_metadata_specific_parsed(void *parsed_result,
17709                                 __rte_unused struct cmdline *cl,
17710                                 __rte_unused void *data)
17711 {
17712         struct cmd_config_tx_metadata_specific_result *res = parsed_result;
17713
17714         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17715                 return;
17716         ports[res->port_id].tx_metadata = res->value;
17717         /* Add/remove callback to insert valid metadata in every Tx packet. */
17718         if (ports[res->port_id].tx_metadata)
17719                 add_tx_md_callback(res->port_id);
17720         else
17721                 remove_tx_md_callback(res->port_id);
17722         rte_flow_dynf_metadata_register();
17723 }
17724
17725 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_port =
17726         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17727                         port, "port");
17728 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_keyword =
17729         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17730                         keyword, "config");
17731 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_id =
17732         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17733                         port_id, UINT16);
17734 cmdline_parse_token_string_t cmd_config_tx_metadata_specific_item =
17735         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17736                         item, "tx_metadata");
17737 cmdline_parse_token_num_t cmd_config_tx_metadata_specific_value =
17738         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_metadata_specific_result,
17739                         value, UINT32);
17740
17741 cmdline_parse_inst_t cmd_config_tx_metadata_specific = {
17742         .f = cmd_config_tx_metadata_specific_parsed,
17743         .data = NULL,
17744         .help_str = "port config <port_id> tx_metadata <value>",
17745         .tokens = {
17746                 (void *)&cmd_config_tx_metadata_specific_port,
17747                 (void *)&cmd_config_tx_metadata_specific_keyword,
17748                 (void *)&cmd_config_tx_metadata_specific_id,
17749                 (void *)&cmd_config_tx_metadata_specific_item,
17750                 (void *)&cmd_config_tx_metadata_specific_value,
17751                 NULL,
17752         },
17753 };
17754
17755 /* *** set dynf *** */
17756 struct cmd_config_tx_dynf_specific_result {
17757         cmdline_fixed_string_t port;
17758         cmdline_fixed_string_t keyword;
17759         uint16_t port_id;
17760         cmdline_fixed_string_t item;
17761         cmdline_fixed_string_t name;
17762         cmdline_fixed_string_t value;
17763 };
17764
17765 static void
17766 cmd_config_dynf_specific_parsed(void *parsed_result,
17767                                 __rte_unused struct cmdline *cl,
17768                                 __rte_unused void *data)
17769 {
17770         struct cmd_config_tx_dynf_specific_result *res = parsed_result;
17771         struct rte_mbuf_dynflag desc_flag;
17772         int flag;
17773         uint64_t old_port_flags;
17774
17775         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
17776                 return;
17777         flag = rte_mbuf_dynflag_lookup(res->name, NULL);
17778         if (flag <= 0) {
17779                 if (strlcpy(desc_flag.name, res->name,
17780                             RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
17781                         printf("Flag name too long\n");
17782                         return;
17783                 }
17784                 desc_flag.flags = 0;
17785                 flag = rte_mbuf_dynflag_register(&desc_flag);
17786                 if (flag < 0) {
17787                         printf("Can't register flag\n");
17788                         return;
17789                 }
17790                 strcpy(dynf_names[flag], desc_flag.name);
17791         }
17792         old_port_flags = ports[res->port_id].mbuf_dynf;
17793         if (!strcmp(res->value, "set")) {
17794                 ports[res->port_id].mbuf_dynf |= 1UL << flag;
17795                 if (old_port_flags == 0)
17796                         add_tx_dynf_callback(res->port_id);
17797         } else {
17798                 ports[res->port_id].mbuf_dynf &= ~(1UL << flag);
17799                 if (ports[res->port_id].mbuf_dynf == 0)
17800                         remove_tx_dynf_callback(res->port_id);
17801         }
17802 }
17803
17804 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_port =
17805         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17806                         keyword, "port");
17807 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_keyword =
17808         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17809                         keyword, "config");
17810 cmdline_parse_token_num_t cmd_config_tx_dynf_specific_port_id =
17811         TOKEN_NUM_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17812                         port_id, UINT16);
17813 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_item =
17814         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17815                         item, "dynf");
17816 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_name =
17817         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17818                         name, NULL);
17819 cmdline_parse_token_string_t cmd_config_tx_dynf_specific_value =
17820         TOKEN_STRING_INITIALIZER(struct cmd_config_tx_dynf_specific_result,
17821                         value, "set#clear");
17822
17823 cmdline_parse_inst_t cmd_config_tx_dynf_specific = {
17824         .f = cmd_config_dynf_specific_parsed,
17825         .data = NULL,
17826         .help_str = "port config <port id> dynf <name> set|clear",
17827         .tokens = {
17828                 (void *)&cmd_config_tx_dynf_specific_port,
17829                 (void *)&cmd_config_tx_dynf_specific_keyword,
17830                 (void *)&cmd_config_tx_dynf_specific_port_id,
17831                 (void *)&cmd_config_tx_dynf_specific_item,
17832                 (void *)&cmd_config_tx_dynf_specific_name,
17833                 (void *)&cmd_config_tx_dynf_specific_value,
17834                 NULL,
17835         },
17836 };
17837
17838 /* *** display tx_metadata per port configuration *** */
17839 struct cmd_show_tx_metadata_result {
17840         cmdline_fixed_string_t cmd_show;
17841         cmdline_fixed_string_t cmd_port;
17842         cmdline_fixed_string_t cmd_keyword;
17843         portid_t cmd_pid;
17844 };
17845
17846 static void
17847 cmd_show_tx_metadata_parsed(void *parsed_result,
17848                 __rte_unused struct cmdline *cl,
17849                 __rte_unused void *data)
17850 {
17851         struct cmd_show_tx_metadata_result *res = parsed_result;
17852
17853         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17854                 printf("invalid port id %u\n", res->cmd_pid);
17855                 return;
17856         }
17857         if (!strcmp(res->cmd_keyword, "tx_metadata")) {
17858                 printf("Port %u tx_metadata: %u\n", res->cmd_pid,
17859                        ports[res->cmd_pid].tx_metadata);
17860         }
17861 }
17862
17863 cmdline_parse_token_string_t cmd_show_tx_metadata_show =
17864         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17865                         cmd_show, "show");
17866 cmdline_parse_token_string_t cmd_show_tx_metadata_port =
17867         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17868                         cmd_port, "port");
17869 cmdline_parse_token_num_t cmd_show_tx_metadata_pid =
17870         TOKEN_NUM_INITIALIZER(struct cmd_show_tx_metadata_result,
17871                         cmd_pid, UINT16);
17872 cmdline_parse_token_string_t cmd_show_tx_metadata_keyword =
17873         TOKEN_STRING_INITIALIZER(struct cmd_show_tx_metadata_result,
17874                         cmd_keyword, "tx_metadata");
17875
17876 cmdline_parse_inst_t cmd_show_tx_metadata = {
17877         .f = cmd_show_tx_metadata_parsed,
17878         .data = NULL,
17879         .help_str = "show port <port_id> tx_metadata",
17880         .tokens = {
17881                 (void *)&cmd_show_tx_metadata_show,
17882                 (void *)&cmd_show_tx_metadata_port,
17883                 (void *)&cmd_show_tx_metadata_pid,
17884                 (void *)&cmd_show_tx_metadata_keyword,
17885                 NULL,
17886         },
17887 };
17888
17889 /* *** show fec capability per port configuration *** */
17890 struct cmd_show_fec_capability_result {
17891         cmdline_fixed_string_t cmd_show;
17892         cmdline_fixed_string_t cmd_port;
17893         cmdline_fixed_string_t cmd_fec;
17894         cmdline_fixed_string_t cmd_keyword;
17895         portid_t cmd_pid;
17896 };
17897
17898 static void
17899 cmd_show_fec_capability_parsed(void *parsed_result,
17900                 __rte_unused struct cmdline *cl,
17901                 __rte_unused void *data)
17902 {
17903 #define FEC_CAP_NUM 2
17904         struct cmd_show_fec_capability_result *res = parsed_result;
17905         struct rte_eth_fec_capa speed_fec_capa[FEC_CAP_NUM];
17906         unsigned int num = FEC_CAP_NUM;
17907         unsigned int ret_num;
17908         int ret;
17909
17910         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17911                 printf("Invalid port id %u\n", res->cmd_pid);
17912                 return;
17913         }
17914
17915         ret = rte_eth_fec_get_capability(res->cmd_pid, speed_fec_capa, num);
17916         if (ret == -ENOTSUP) {
17917                 printf("Function not implemented\n");
17918                 return;
17919         } else if (ret < 0) {
17920                 printf("Get FEC capability failed\n");
17921                 return;
17922         }
17923
17924         ret_num = (unsigned int)ret;
17925         show_fec_capability(ret_num, speed_fec_capa);
17926 }
17927
17928 cmdline_parse_token_string_t cmd_show_fec_capability_show =
17929         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17930                         cmd_show, "show");
17931 cmdline_parse_token_string_t cmd_show_fec_capability_port =
17932         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17933                         cmd_port, "port");
17934 cmdline_parse_token_num_t cmd_show_fec_capability_pid =
17935         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
17936                         cmd_pid, UINT16);
17937 cmdline_parse_token_string_t cmd_show_fec_capability_fec =
17938         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17939                         cmd_fec, "fec");
17940 cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
17941         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
17942                         cmd_keyword, "capabilities");
17943
17944 cmdline_parse_inst_t cmd_show_capability = {
17945         .f = cmd_show_fec_capability_parsed,
17946         .data = NULL,
17947         .help_str = "show port <port_id> fec capabilities",
17948         .tokens = {
17949                 (void *)&cmd_show_fec_capability_show,
17950                 (void *)&cmd_show_fec_capability_port,
17951                 (void *)&cmd_show_fec_capability_pid,
17952                 (void *)&cmd_show_fec_capability_fec,
17953                 (void *)&cmd_show_fec_capability_keyword,
17954                 NULL,
17955         },
17956 };
17957
17958 /* *** show fec mode per port configuration *** */
17959 struct cmd_show_fec_metadata_result {
17960         cmdline_fixed_string_t cmd_show;
17961         cmdline_fixed_string_t cmd_port;
17962         cmdline_fixed_string_t cmd_keyword;
17963         portid_t cmd_pid;
17964 };
17965
17966 static void
17967 cmd_show_fec_mode_parsed(void *parsed_result,
17968                 __rte_unused struct cmdline *cl,
17969                 __rte_unused void *data)
17970 {
17971 #define FEC_NAME_SIZE 16
17972         struct cmd_show_fec_metadata_result *res = parsed_result;
17973         uint32_t mode;
17974         char buf[FEC_NAME_SIZE];
17975         int ret;
17976
17977         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
17978                 printf("Invalid port id %u\n", res->cmd_pid);
17979                 return;
17980         }
17981         ret = rte_eth_fec_get(res->cmd_pid, &mode);
17982         if (ret == -ENOTSUP) {
17983                 printf("Function not implemented\n");
17984                 return;
17985         } else if (ret < 0) {
17986                 printf("Get FEC mode failed\n");
17987                 return;
17988         }
17989
17990         switch (mode) {
17991         case RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC):
17992                 strlcpy(buf, "off", sizeof(buf));
17993                 break;
17994         case RTE_ETH_FEC_MODE_CAPA_MASK(AUTO):
17995                 strlcpy(buf, "auto", sizeof(buf));
17996                 break;
17997         case RTE_ETH_FEC_MODE_CAPA_MASK(BASER):
17998                 strlcpy(buf, "baser", sizeof(buf));
17999                 break;
18000         case RTE_ETH_FEC_MODE_CAPA_MASK(RS):
18001                 strlcpy(buf, "rs", sizeof(buf));
18002                 break;
18003         default:
18004                 return;
18005         }
18006
18007         printf("%s\n", buf);
18008 }
18009
18010 cmdline_parse_token_string_t cmd_show_fec_mode_show =
18011         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18012                         cmd_show, "show");
18013 cmdline_parse_token_string_t cmd_show_fec_mode_port =
18014         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18015                         cmd_port, "port");
18016 cmdline_parse_token_num_t cmd_show_fec_mode_pid =
18017         TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
18018                         cmd_pid, UINT16);
18019 cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
18020         TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
18021                         cmd_keyword, "fec_mode");
18022
18023 cmdline_parse_inst_t cmd_show_fec_mode = {
18024         .f = cmd_show_fec_mode_parsed,
18025         .data = NULL,
18026         .help_str = "show port <port_id> fec_mode",
18027         .tokens = {
18028                 (void *)&cmd_show_fec_mode_show,
18029                 (void *)&cmd_show_fec_mode_port,
18030                 (void *)&cmd_show_fec_mode_pid,
18031                 (void *)&cmd_show_fec_mode_keyword,
18032                 NULL,
18033         },
18034 };
18035
18036 /* *** set fec mode per port configuration *** */
18037 struct cmd_set_port_fec_mode {
18038         cmdline_fixed_string_t set;
18039         cmdline_fixed_string_t port;
18040         portid_t port_id;
18041         cmdline_fixed_string_t fec_mode;
18042         cmdline_fixed_string_t fec_value;
18043 };
18044
18045 /* Common CLI fields for set fec mode */
18046 cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
18047         TOKEN_STRING_INITIALIZER
18048                 (struct cmd_set_port_fec_mode,
18049                  set, "set");
18050 cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
18051         TOKEN_STRING_INITIALIZER
18052                 (struct cmd_set_port_fec_mode,
18053                  port, "port");
18054 cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
18055         TOKEN_NUM_INITIALIZER
18056                 (struct cmd_set_port_fec_mode,
18057                  port_id, UINT16);
18058 cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
18059         TOKEN_STRING_INITIALIZER
18060                 (struct cmd_set_port_fec_mode,
18061                  fec_mode, "fec_mode");
18062 cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
18063         TOKEN_STRING_INITIALIZER
18064                 (struct cmd_set_port_fec_mode,
18065                  fec_value, NULL);
18066
18067 static void
18068 cmd_set_port_fec_mode_parsed(
18069         void *parsed_result,
18070         __rte_unused struct cmdline *cl,
18071         __rte_unused void *data)
18072 {
18073         struct cmd_set_port_fec_mode *res = parsed_result;
18074         uint16_t port_id = res->port_id;
18075         uint32_t mode;
18076         int ret;
18077
18078         ret = parse_fec_mode(res->fec_value, &mode);
18079         if (ret < 0) {
18080                 printf("Unknown fec mode: %s for Port %d\n", res->fec_value,
18081                         port_id);
18082                 return;
18083         }
18084
18085         ret = rte_eth_fec_set(port_id, mode);
18086         if (ret == -ENOTSUP) {
18087                 printf("Function not implemented\n");
18088                 return;
18089         } else if (ret < 0) {
18090                 printf("Set FEC mode failed\n");
18091                 return;
18092         }
18093 }
18094
18095 cmdline_parse_inst_t cmd_set_fec_mode = {
18096         .f = cmd_set_port_fec_mode_parsed,
18097         .data = NULL,
18098         .help_str = "set port <port_id> fec_mode auto|off|rs|baser",
18099         .tokens = {
18100                 (void *)&cmd_set_port_fec_mode_set,
18101                 (void *)&cmd_set_port_fec_mode_port,
18102                 (void *)&cmd_set_port_fec_mode_port_id,
18103                 (void *)&cmd_set_port_fec_mode_str,
18104                 (void *)&cmd_set_port_fec_mode_value,
18105                 NULL,
18106         },
18107 };
18108
18109 /* show port supported ptypes */
18110
18111 /* Common result structure for show port ptypes */
18112 struct cmd_show_port_supported_ptypes_result {
18113         cmdline_fixed_string_t show;
18114         cmdline_fixed_string_t port;
18115         portid_t port_id;
18116         cmdline_fixed_string_t ptypes;
18117 };
18118
18119 /* Common CLI fields for show port ptypes */
18120 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_show =
18121         TOKEN_STRING_INITIALIZER
18122                 (struct cmd_show_port_supported_ptypes_result,
18123                  show, "show");
18124 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_port =
18125         TOKEN_STRING_INITIALIZER
18126                 (struct cmd_show_port_supported_ptypes_result,
18127                  port, "port");
18128 cmdline_parse_token_num_t cmd_show_port_supported_ptypes_port_id =
18129         TOKEN_NUM_INITIALIZER
18130                 (struct cmd_show_port_supported_ptypes_result,
18131                  port_id, UINT16);
18132 cmdline_parse_token_string_t cmd_show_port_supported_ptypes_ptypes =
18133         TOKEN_STRING_INITIALIZER
18134                 (struct cmd_show_port_supported_ptypes_result,
18135                  ptypes, "ptypes");
18136
18137 static void
18138 cmd_show_port_supported_ptypes_parsed(
18139         void *parsed_result,
18140         __rte_unused struct cmdline *cl,
18141         __rte_unused void *data)
18142 {
18143 #define RSVD_PTYPE_MASK       0xf0000000
18144 #define MAX_PTYPES_PER_LAYER  16
18145 #define LTYPE_NAMESIZE        32
18146 #define PTYPE_NAMESIZE        256
18147         struct cmd_show_port_supported_ptypes_result *res = parsed_result;
18148         char buf[PTYPE_NAMESIZE], ltype[LTYPE_NAMESIZE];
18149         uint32_t ptype_mask = RTE_PTYPE_L2_MASK;
18150         uint32_t ptypes[MAX_PTYPES_PER_LAYER];
18151         uint16_t port_id = res->port_id;
18152         int ret, i;
18153
18154         ret = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, NULL, 0);
18155         if (ret < 0)
18156                 return;
18157
18158         while (ptype_mask != RSVD_PTYPE_MASK) {
18159
18160                 switch (ptype_mask) {
18161                 case RTE_PTYPE_L2_MASK:
18162                         strlcpy(ltype, "L2", sizeof(ltype));
18163                         break;
18164                 case RTE_PTYPE_L3_MASK:
18165                         strlcpy(ltype, "L3", sizeof(ltype));
18166                         break;
18167                 case RTE_PTYPE_L4_MASK:
18168                         strlcpy(ltype, "L4", sizeof(ltype));
18169                         break;
18170                 case RTE_PTYPE_TUNNEL_MASK:
18171                         strlcpy(ltype, "Tunnel", sizeof(ltype));
18172                         break;
18173                 case RTE_PTYPE_INNER_L2_MASK:
18174                         strlcpy(ltype, "Inner L2", sizeof(ltype));
18175                         break;
18176                 case RTE_PTYPE_INNER_L3_MASK:
18177                         strlcpy(ltype, "Inner L3", sizeof(ltype));
18178                         break;
18179                 case RTE_PTYPE_INNER_L4_MASK:
18180                         strlcpy(ltype, "Inner L4", sizeof(ltype));
18181                         break;
18182                 default:
18183                         return;
18184                 }
18185
18186                 ret = rte_eth_dev_get_supported_ptypes(res->port_id,
18187                                                        ptype_mask, ptypes,
18188                                                        MAX_PTYPES_PER_LAYER);
18189
18190                 if (ret > 0)
18191                         printf("Supported %s ptypes:\n", ltype);
18192                 else
18193                         printf("%s ptypes unsupported\n", ltype);
18194
18195                 for (i = 0; i < ret; ++i) {
18196                         rte_get_ptype_name(ptypes[i], buf, sizeof(buf));
18197                         printf("%s\n", buf);
18198                 }
18199
18200                 ptype_mask <<= 4;
18201         }
18202 }
18203
18204 cmdline_parse_inst_t cmd_show_port_supported_ptypes = {
18205         .f = cmd_show_port_supported_ptypes_parsed,
18206         .data = NULL,
18207         .help_str = "show port <port_id> ptypes",
18208         .tokens = {
18209                 (void *)&cmd_show_port_supported_ptypes_show,
18210                 (void *)&cmd_show_port_supported_ptypes_port,
18211                 (void *)&cmd_show_port_supported_ptypes_port_id,
18212                 (void *)&cmd_show_port_supported_ptypes_ptypes,
18213                 NULL,
18214         },
18215 };
18216
18217 /* *** display rx/tx descriptor status *** */
18218 struct cmd_show_rx_tx_desc_status_result {
18219         cmdline_fixed_string_t cmd_show;
18220         cmdline_fixed_string_t cmd_port;
18221         cmdline_fixed_string_t cmd_keyword;
18222         cmdline_fixed_string_t cmd_desc;
18223         cmdline_fixed_string_t cmd_status;
18224         portid_t cmd_pid;
18225         portid_t cmd_qid;
18226         portid_t cmd_did;
18227 };
18228
18229 static void
18230 cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
18231                 __rte_unused struct cmdline *cl,
18232                 __rte_unused void *data)
18233 {
18234         struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
18235         int rc;
18236
18237         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
18238                 printf("invalid port id %u\n", res->cmd_pid);
18239                 return;
18240         }
18241
18242         if (!strcmp(res->cmd_keyword, "rxq")) {
18243                 rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
18244                                              res->cmd_did);
18245                 if (rc < 0) {
18246                         printf("Invalid queueid = %d\n", res->cmd_qid);
18247                         return;
18248                 }
18249                 if (rc == RTE_ETH_RX_DESC_AVAIL)
18250                         printf("Desc status = AVAILABLE\n");
18251                 else if (rc == RTE_ETH_RX_DESC_DONE)
18252                         printf("Desc status = DONE\n");
18253                 else
18254                         printf("Desc status = UNAVAILABLE\n");
18255         } else if (!strcmp(res->cmd_keyword, "txq")) {
18256                 rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
18257                                              res->cmd_did);
18258                 if (rc < 0) {
18259                         printf("Invalid queueid = %d\n", res->cmd_qid);
18260                         return;
18261                 }
18262                 if (rc == RTE_ETH_TX_DESC_FULL)
18263                         printf("Desc status = FULL\n");
18264                 else if (rc == RTE_ETH_TX_DESC_DONE)
18265                         printf("Desc status = DONE\n");
18266                 else
18267                         printf("Desc status = UNAVAILABLE\n");
18268         }
18269 }
18270
18271 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_show =
18272         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18273                         cmd_show, "show");
18274 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_port =
18275         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18276                         cmd_port, "port");
18277 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_pid =
18278         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18279                         cmd_pid, UINT16);
18280 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_keyword =
18281         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18282                         cmd_keyword, "rxq#txq");
18283 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_qid =
18284         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18285                         cmd_qid, UINT16);
18286 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_desc =
18287         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18288                         cmd_desc, "desc");
18289 cmdline_parse_token_num_t cmd_show_rx_tx_desc_status_did =
18290         TOKEN_NUM_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18291                         cmd_did, UINT16);
18292 cmdline_parse_token_string_t cmd_show_rx_tx_desc_status_status =
18293         TOKEN_STRING_INITIALIZER(struct cmd_show_rx_tx_desc_status_result,
18294                         cmd_status, "status");
18295 cmdline_parse_inst_t cmd_show_rx_tx_desc_status = {
18296         .f = cmd_show_rx_tx_desc_status_parsed,
18297         .data = NULL,
18298         .help_str = "show port <port_id> rxq|txq <queue_id> desc <desc_id> "
18299                 "status",
18300         .tokens = {
18301                 (void *)&cmd_show_rx_tx_desc_status_show,
18302                 (void *)&cmd_show_rx_tx_desc_status_port,
18303                 (void *)&cmd_show_rx_tx_desc_status_pid,
18304                 (void *)&cmd_show_rx_tx_desc_status_keyword,
18305                 (void *)&cmd_show_rx_tx_desc_status_qid,
18306                 (void *)&cmd_show_rx_tx_desc_status_desc,
18307                 (void *)&cmd_show_rx_tx_desc_status_did,
18308                 (void *)&cmd_show_rx_tx_desc_status_status,
18309                 NULL,
18310         },
18311 };
18312
18313 /* Common result structure for set port ptypes */
18314 struct cmd_set_port_ptypes_result {
18315         cmdline_fixed_string_t set;
18316         cmdline_fixed_string_t port;
18317         portid_t port_id;
18318         cmdline_fixed_string_t ptype_mask;
18319         uint32_t mask;
18320 };
18321
18322 /* Common CLI fields for set port ptypes */
18323 cmdline_parse_token_string_t cmd_set_port_ptypes_set =
18324         TOKEN_STRING_INITIALIZER
18325                 (struct cmd_set_port_ptypes_result,
18326                  set, "set");
18327 cmdline_parse_token_string_t cmd_set_port_ptypes_port =
18328         TOKEN_STRING_INITIALIZER
18329                 (struct cmd_set_port_ptypes_result,
18330                  port, "port");
18331 cmdline_parse_token_num_t cmd_set_port_ptypes_port_id =
18332         TOKEN_NUM_INITIALIZER
18333                 (struct cmd_set_port_ptypes_result,
18334                  port_id, UINT16);
18335 cmdline_parse_token_string_t cmd_set_port_ptypes_mask_str =
18336         TOKEN_STRING_INITIALIZER
18337                 (struct cmd_set_port_ptypes_result,
18338                  ptype_mask, "ptype_mask");
18339 cmdline_parse_token_num_t cmd_set_port_ptypes_mask_u32 =
18340         TOKEN_NUM_INITIALIZER
18341                 (struct cmd_set_port_ptypes_result,
18342                  mask, UINT32);
18343
18344 static void
18345 cmd_set_port_ptypes_parsed(
18346         void *parsed_result,
18347         __rte_unused struct cmdline *cl,
18348         __rte_unused void *data)
18349 {
18350         struct cmd_set_port_ptypes_result *res = parsed_result;
18351 #define PTYPE_NAMESIZE        256
18352         char ptype_name[PTYPE_NAMESIZE];
18353         uint16_t port_id = res->port_id;
18354         uint32_t ptype_mask = res->mask;
18355         int ret, i;
18356
18357         ret = rte_eth_dev_get_supported_ptypes(port_id, RTE_PTYPE_ALL_MASK,
18358                                                NULL, 0);
18359         if (ret <= 0) {
18360                 printf("Port %d doesn't support any ptypes.\n", port_id);
18361                 return;
18362         }
18363
18364         uint32_t ptypes[ret];
18365
18366         ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
18367         if (ret < 0) {
18368                 printf("Unable to set requested ptypes for Port %d\n", port_id);
18369                 return;
18370         }
18371
18372         printf("Successfully set following ptypes for Port %d\n", port_id);
18373         for (i = 0; i < ret && ptypes[i] != RTE_PTYPE_UNKNOWN; i++) {
18374                 rte_get_ptype_name(ptypes[i], ptype_name, sizeof(ptype_name));
18375                 printf("%s\n", ptype_name);
18376         }
18377
18378         clear_ptypes = false;
18379 }
18380
18381 cmdline_parse_inst_t cmd_set_port_ptypes = {
18382         .f = cmd_set_port_ptypes_parsed,
18383         .data = NULL,
18384         .help_str = "set port <port_id> ptype_mask <mask>",
18385         .tokens = {
18386                 (void *)&cmd_set_port_ptypes_set,
18387                 (void *)&cmd_set_port_ptypes_port,
18388                 (void *)&cmd_set_port_ptypes_port_id,
18389                 (void *)&cmd_set_port_ptypes_mask_str,
18390                 (void *)&cmd_set_port_ptypes_mask_u32,
18391                 NULL,
18392         },
18393 };
18394
18395 /* *** display mac addresses added to a port *** */
18396 struct cmd_showport_macs_result {
18397         cmdline_fixed_string_t cmd_show;
18398         cmdline_fixed_string_t cmd_port;
18399         cmdline_fixed_string_t cmd_keyword;
18400         portid_t cmd_pid;
18401 };
18402
18403 static void
18404 cmd_showport_macs_parsed(void *parsed_result,
18405                 __rte_unused struct cmdline *cl,
18406                 __rte_unused void *data)
18407 {
18408         struct cmd_showport_macs_result *res = parsed_result;
18409
18410         if (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
18411                 return;
18412
18413         if (!strcmp(res->cmd_keyword, "macs"))
18414                 show_macs(res->cmd_pid);
18415         else if (!strcmp(res->cmd_keyword, "mcast_macs"))
18416                 show_mcast_macs(res->cmd_pid);
18417 }
18418
18419 cmdline_parse_token_string_t cmd_showport_macs_show =
18420         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18421                         cmd_show, "show");
18422 cmdline_parse_token_string_t cmd_showport_macs_port =
18423         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18424                         cmd_port, "port");
18425 cmdline_parse_token_num_t cmd_showport_macs_pid =
18426         TOKEN_NUM_INITIALIZER(struct cmd_showport_macs_result,
18427                         cmd_pid, UINT16);
18428 cmdline_parse_token_string_t cmd_showport_macs_keyword =
18429         TOKEN_STRING_INITIALIZER(struct cmd_showport_macs_result,
18430                         cmd_keyword, "macs#mcast_macs");
18431
18432 cmdline_parse_inst_t cmd_showport_macs = {
18433         .f = cmd_showport_macs_parsed,
18434         .data = NULL,
18435         .help_str = "show port <port_id> macs|mcast_macs",
18436         .tokens = {
18437                 (void *)&cmd_showport_macs_show,
18438                 (void *)&cmd_showport_macs_port,
18439                 (void *)&cmd_showport_macs_pid,
18440                 (void *)&cmd_showport_macs_keyword,
18441                 NULL,
18442         },
18443 };
18444
18445 /* ******************************************************************************** */
18446
18447 /* list of instructions */
18448 cmdline_parse_ctx_t main_ctx[] = {
18449         (cmdline_parse_inst_t *)&cmd_help_brief,
18450         (cmdline_parse_inst_t *)&cmd_help_long,
18451         (cmdline_parse_inst_t *)&cmd_quit,
18452         (cmdline_parse_inst_t *)&cmd_load_from_file,
18453         (cmdline_parse_inst_t *)&cmd_showport,
18454         (cmdline_parse_inst_t *)&cmd_showqueue,
18455         (cmdline_parse_inst_t *)&cmd_showeeprom,
18456         (cmdline_parse_inst_t *)&cmd_showportall,
18457         (cmdline_parse_inst_t *)&cmd_showdevice,
18458         (cmdline_parse_inst_t *)&cmd_showcfg,
18459         (cmdline_parse_inst_t *)&cmd_showfwdall,
18460         (cmdline_parse_inst_t *)&cmd_start,
18461         (cmdline_parse_inst_t *)&cmd_start_tx_first,
18462         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
18463         (cmdline_parse_inst_t *)&cmd_set_link_up,
18464         (cmdline_parse_inst_t *)&cmd_set_link_down,
18465         (cmdline_parse_inst_t *)&cmd_reset,
18466         (cmdline_parse_inst_t *)&cmd_set_numbers,
18467         (cmdline_parse_inst_t *)&cmd_set_log,
18468         (cmdline_parse_inst_t *)&cmd_set_rxoffs,
18469         (cmdline_parse_inst_t *)&cmd_set_rxpkts,
18470         (cmdline_parse_inst_t *)&cmd_set_txpkts,
18471         (cmdline_parse_inst_t *)&cmd_set_txsplit,
18472         (cmdline_parse_inst_t *)&cmd_set_txtimes,
18473         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
18474         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
18475         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
18476         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
18477         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
18478         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
18479         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
18480         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
18481         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
18482         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
18483         (cmdline_parse_inst_t *)&cmd_set_link_check,
18484         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
18485         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
18486         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
18487         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
18488 #ifdef RTE_NET_BOND
18489         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
18490         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
18491         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
18492         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
18493         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
18494         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
18495         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
18496         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
18497         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
18498         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
18499         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
18500 #endif
18501         (cmdline_parse_inst_t *)&cmd_vlan_offload,
18502         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
18503         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
18504         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
18505         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
18506         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
18507         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
18508         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
18509         (cmdline_parse_inst_t *)&cmd_csum_set,
18510         (cmdline_parse_inst_t *)&cmd_csum_show,
18511         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
18512         (cmdline_parse_inst_t *)&cmd_tso_set,
18513         (cmdline_parse_inst_t *)&cmd_tso_show,
18514         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
18515         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
18516         (cmdline_parse_inst_t *)&cmd_gro_enable,
18517         (cmdline_parse_inst_t *)&cmd_gro_flush,
18518         (cmdline_parse_inst_t *)&cmd_gro_show,
18519         (cmdline_parse_inst_t *)&cmd_gso_enable,
18520         (cmdline_parse_inst_t *)&cmd_gso_size,
18521         (cmdline_parse_inst_t *)&cmd_gso_show,
18522         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
18523         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
18524         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
18525         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
18526         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
18527         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
18528         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
18529         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
18530         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
18531         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
18532         (cmdline_parse_inst_t *)&cmd_config_dcb,
18533         (cmdline_parse_inst_t *)&cmd_read_reg,
18534         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
18535         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
18536         (cmdline_parse_inst_t *)&cmd_write_reg,
18537         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
18538         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
18539         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
18540         (cmdline_parse_inst_t *)&cmd_stop,
18541         (cmdline_parse_inst_t *)&cmd_mac_addr,
18542         (cmdline_parse_inst_t *)&cmd_set_fwd_eth_peer,
18543         (cmdline_parse_inst_t *)&cmd_set_qmap,
18544         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
18545         (cmdline_parse_inst_t *)&cmd_set_record_core_cycles,
18546         (cmdline_parse_inst_t *)&cmd_set_record_burst_stats,
18547         (cmdline_parse_inst_t *)&cmd_operate_port,
18548         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
18549         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
18550         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
18551         (cmdline_parse_inst_t *)&cmd_operate_detach_device,
18552         (cmdline_parse_inst_t *)&cmd_set_port_setup_on,
18553         (cmdline_parse_inst_t *)&cmd_config_speed_all,
18554         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
18555         (cmdline_parse_inst_t *)&cmd_config_loopback_all,
18556         (cmdline_parse_inst_t *)&cmd_config_loopback_specific,
18557         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
18558         (cmdline_parse_inst_t *)&cmd_config_mtu,
18559         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
18560         (cmdline_parse_inst_t *)&cmd_config_max_lro_pkt_size,
18561         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
18562         (cmdline_parse_inst_t *)&cmd_config_rss,
18563         (cmdline_parse_inst_t *)&cmd_config_rxtx_ring_size,
18564         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
18565         (cmdline_parse_inst_t *)&cmd_config_deferred_start_rxtx_queue,
18566         (cmdline_parse_inst_t *)&cmd_setup_rxtx_queue,
18567         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
18568         (cmdline_parse_inst_t *)&cmd_showport_reta,
18569         (cmdline_parse_inst_t *)&cmd_showport_macs,
18570         (cmdline_parse_inst_t *)&cmd_config_burst,
18571         (cmdline_parse_inst_t *)&cmd_config_thresh,
18572         (cmdline_parse_inst_t *)&cmd_config_threshold,
18573         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
18574         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
18575         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
18576         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
18577         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
18578         (cmdline_parse_inst_t *)&cmd_global_config,
18579         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
18580         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
18581         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
18582         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
18583         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
18584         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
18585         (cmdline_parse_inst_t *)&cmd_dump,
18586         (cmdline_parse_inst_t *)&cmd_dump_one,
18587         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
18588         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
18589         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
18590         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
18591         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
18592         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
18593         (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director,
18594         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
18595         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
18596         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
18597         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
18598         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
18599         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
18600         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
18601         (cmdline_parse_inst_t *)&cmd_flow,
18602         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
18603         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
18604         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
18605         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
18606         (cmdline_parse_inst_t *)&cmd_create_port_meter,
18607         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
18608         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
18609         (cmdline_parse_inst_t *)&cmd_del_port_meter,
18610         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
18611         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
18612         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
18613         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
18614         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
18615         (cmdline_parse_inst_t *)&cmd_mcast_addr,
18616         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
18617         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
18618         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
18619         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
18620         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
18621         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
18622         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
18623         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
18624         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
18625         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
18626         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
18627         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
18628         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
18629         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
18630         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
18631         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
18632         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
18633         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
18634         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
18635         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
18636         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
18637         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
18638         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
18639         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
18640         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
18641         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
18642         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
18643         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
18644         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
18645         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
18646         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
18647         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
18648         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
18649         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
18650         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
18651         (cmdline_parse_inst_t *)&cmd_set_vxlan,
18652         (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl,
18653         (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan,
18654         (cmdline_parse_inst_t *)&cmd_set_nvgre,
18655         (cmdline_parse_inst_t *)&cmd_set_nvgre_with_vlan,
18656         (cmdline_parse_inst_t *)&cmd_set_l2_encap,
18657         (cmdline_parse_inst_t *)&cmd_set_l2_encap_with_vlan,
18658         (cmdline_parse_inst_t *)&cmd_set_l2_decap,
18659         (cmdline_parse_inst_t *)&cmd_set_l2_decap_with_vlan,
18660         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap,
18661         (cmdline_parse_inst_t *)&cmd_set_mplsogre_encap_with_vlan,
18662         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap,
18663         (cmdline_parse_inst_t *)&cmd_set_mplsogre_decap_with_vlan,
18664         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap,
18665         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_encap_with_vlan,
18666         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap,
18667         (cmdline_parse_inst_t *)&cmd_set_mplsoudp_decap_with_vlan,
18668         (cmdline_parse_inst_t *)&cmd_ddp_add,
18669         (cmdline_parse_inst_t *)&cmd_ddp_del,
18670         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
18671         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
18672         (cmdline_parse_inst_t *)&cmd_cfg_input_set,
18673         (cmdline_parse_inst_t *)&cmd_clear_input_set,
18674         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
18675         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
18676         (cmdline_parse_inst_t *)&cmd_show_port_supported_ptypes,
18677         (cmdline_parse_inst_t *)&cmd_set_port_ptypes,
18678         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
18679         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
18680         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
18681         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
18682
18683         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
18684         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
18685         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
18686         (cmdline_parse_inst_t *)&cmd_queue_region,
18687         (cmdline_parse_inst_t *)&cmd_region_flowtype,
18688         (cmdline_parse_inst_t *)&cmd_user_priority_region,
18689         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
18690         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
18691         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
18692         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
18693         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
18694         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
18695         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
18696         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
18697         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
18698         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
18699         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
18700         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
18701         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
18702         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
18703         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
18704         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node_pmode,
18705         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
18706         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
18707         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
18708         (cmdline_parse_inst_t *)&cmd_suspend_port_tm_node,
18709         (cmdline_parse_inst_t *)&cmd_resume_port_tm_node,
18710         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
18711         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_ecn,
18712         (cmdline_parse_inst_t *)&cmd_port_tm_mark_ip_dscp,
18713         (cmdline_parse_inst_t *)&cmd_port_tm_mark_vlan_dei,
18714         (cmdline_parse_inst_t *)&cmd_cfg_tunnel_udp_port,
18715         (cmdline_parse_inst_t *)&cmd_rx_offload_get_capa,
18716         (cmdline_parse_inst_t *)&cmd_rx_offload_get_configuration,
18717         (cmdline_parse_inst_t *)&cmd_config_per_port_rx_offload,
18718         (cmdline_parse_inst_t *)&cmd_config_per_queue_rx_offload,
18719         (cmdline_parse_inst_t *)&cmd_tx_offload_get_capa,
18720         (cmdline_parse_inst_t *)&cmd_tx_offload_get_configuration,
18721         (cmdline_parse_inst_t *)&cmd_config_per_port_tx_offload,
18722         (cmdline_parse_inst_t *)&cmd_config_per_queue_tx_offload,
18723 #ifdef RTE_LIB_BPF
18724         (cmdline_parse_inst_t *)&cmd_operate_bpf_ld_parse,
18725         (cmdline_parse_inst_t *)&cmd_operate_bpf_unld_parse,
18726 #endif
18727         (cmdline_parse_inst_t *)&cmd_config_tx_metadata_specific,
18728         (cmdline_parse_inst_t *)&cmd_show_tx_metadata,
18729         (cmdline_parse_inst_t *)&cmd_show_rx_tx_desc_status,
18730         (cmdline_parse_inst_t *)&cmd_set_raw,
18731         (cmdline_parse_inst_t *)&cmd_show_set_raw,
18732         (cmdline_parse_inst_t *)&cmd_show_set_raw_all,
18733         (cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
18734         (cmdline_parse_inst_t *)&cmd_show_fec_mode,
18735         (cmdline_parse_inst_t *)&cmd_set_fec_mode,
18736         (cmdline_parse_inst_t *)&cmd_show_capability,
18737         NULL,
18738 };
18739
18740 /* read cmdline commands from file */
18741 void
18742 cmdline_read_from_file(const char *filename)
18743 {
18744         struct cmdline *cl;
18745
18746         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
18747         if (cl == NULL) {
18748                 printf("Failed to create file based cmdline context: %s\n",
18749                        filename);
18750                 return;
18751         }
18752
18753         cmdline_interact(cl);
18754         cmdline_quit(cl);
18755
18756         cmdline_free(cl);
18757
18758         printf("Read CLI commands from %s\n", filename);
18759 }
18760
18761 /* prompt function, called from main on MAIN lcore */
18762 void
18763 prompt(void)
18764 {
18765         /* initialize non-constant commands */
18766         cmd_set_fwd_mode_init();
18767         cmd_set_fwd_retry_mode_init();
18768
18769         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
18770         if (testpmd_cl == NULL)
18771                 return;
18772         cmdline_interact(testpmd_cl);
18773         cmdline_stdin_exit(testpmd_cl);
18774 }
18775
18776 void
18777 prompt_exit(void)
18778 {
18779         if (testpmd_cl != NULL)
18780                 cmdline_quit(testpmd_cl);
18781 }
18782
18783 static void
18784 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
18785 {
18786         if (id == (portid_t)RTE_PORT_ALL) {
18787                 portid_t pid;
18788
18789                 RTE_ETH_FOREACH_DEV(pid) {
18790                         /* check if need_reconfig has been set to 1 */
18791                         if (ports[pid].need_reconfig == 0)
18792                                 ports[pid].need_reconfig = dev;
18793                         /* check if need_reconfig_queues has been set to 1 */
18794                         if (ports[pid].need_reconfig_queues == 0)
18795                                 ports[pid].need_reconfig_queues = queue;
18796                 }
18797         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
18798                 /* check if need_reconfig has been set to 1 */
18799                 if (ports[id].need_reconfig == 0)
18800                         ports[id].need_reconfig = dev;
18801                 /* check if need_reconfig_queues has been set to 1 */
18802                 if (ports[id].need_reconfig_queues == 0)
18803                         ports[id].need_reconfig_queues = queue;
18804         }
18805 }